1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _FRM_GROUPMANAGER_HXX_ 29*cdf0e10cSrcweir #define _FRM_GROUPMANAGER_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XContainerListener.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp> 37*cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 38*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 39*cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 40*cdf0e10cSrcweir #include <comphelper/types.hxx> 41*cdf0e10cSrcweir using namespace comphelper; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir /*======================================================================== 44*cdf0e10cSrcweir Funktionsweise GroupManager: 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir Der GroupManager horcht an der starform, ob FormComponents eingefuegt oder entfernt 47*cdf0e10cSrcweir werden. Zusaetzlich horcht er bei den FormComponents an den Properties 48*cdf0e10cSrcweir "Name" und "TabIndex". Mit diesen Infos aktualisiert er seine Gruppen. 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir Der GroupManager verwaltet eine Gruppe, in der alle Controls nach TabIndex 51*cdf0e10cSrcweir geordnet sind, und ein Array von Gruppen, in dem jede FormComponent noch 52*cdf0e10cSrcweir einmal einer Gruppe dem Namen nach zugeordnet wird. 53*cdf0e10cSrcweir Die einzelnen Gruppen werden ueber eine Map aktiviert, wenn sie mehr als 54*cdf0e10cSrcweir ein Element besitzen. 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir Die Gruppen verwalten intern die FormComponents in zwei Arrays. In dem 57*cdf0e10cSrcweir GroupCompArray werden die Components nach TabIndex und Einfuegepostion 58*cdf0e10cSrcweir sortiert. Da auf dieses Array ueber die FormComponent zugegriffen 59*cdf0e10cSrcweir wird, gibt es noch das GroupCompAccessArray, in dem die FormComponents 60*cdf0e10cSrcweir nach ihrer Speicheradresse sortiert sind. Jedes Element des 61*cdf0e10cSrcweir GroupCompAccessArrays ist mit einem Element des GroupCompArrays verpointert. 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir ========================================================================*/ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //......................................................................... 66*cdf0e10cSrcweir namespace frm 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir //......................................................................... 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //======================================================================== 71*cdf0e10cSrcweir template <class ELEMENT, class LESS_COMPARE> 72*cdf0e10cSrcweir sal_Int32 insert_sorted(::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, const LESS_COMPARE& _rCompareOp) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir typename ::std::vector<ELEMENT>::iterator aInsertPos = lower_bound( 75*cdf0e10cSrcweir _rArray.begin(), 76*cdf0e10cSrcweir _rArray.end(), 77*cdf0e10cSrcweir _rNewElement, 78*cdf0e10cSrcweir _rCompareOp 79*cdf0e10cSrcweir ); 80*cdf0e10cSrcweir aInsertPos = _rArray.insert(aInsertPos, _rNewElement); 81*cdf0e10cSrcweir return aInsertPos - _rArray.begin(); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir template <class ELEMENT, class LESS_COMPARE> 85*cdf0e10cSrcweir sal_Bool seek_entry(const ::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, sal_Int32& nPos, const LESS_COMPARE& _rCompareOp) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir typename ::std::vector<ELEMENT>::const_iterator aExistentPos = lower_bound( 88*cdf0e10cSrcweir _rArray.begin(), 89*cdf0e10cSrcweir _rArray.end(), 90*cdf0e10cSrcweir _rNewElement, 91*cdf0e10cSrcweir _rCompareOp 92*cdf0e10cSrcweir ); 93*cdf0e10cSrcweir if ((aExistentPos != _rArray.end()) && (*aExistentPos == _rNewElement)) 94*cdf0e10cSrcweir { // we have a valid "lower or equal" element and it's really "equal" 95*cdf0e10cSrcweir nPos = aExistentPos - _rArray.begin(); 96*cdf0e10cSrcweir return sal_True; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir nPos = -1; 99*cdf0e10cSrcweir return sal_False; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir //======================================================================== 103*cdf0e10cSrcweir class OGroupComp 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir ::rtl::OUString m_aName; 106*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xComponent; 107*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> m_xControlModel; 108*cdf0e10cSrcweir sal_Int32 m_nPos; 109*cdf0e10cSrcweir sal_Int16 m_nTabIndex; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir friend class OGroupCompLess; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir public: 114*cdf0e10cSrcweir OGroupComp(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement, sal_Int32 nInsertPos ); 115*cdf0e10cSrcweir OGroupComp(const OGroupComp& _rSource); 116*cdf0e10cSrcweir OGroupComp(); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir sal_Bool operator==( const OGroupComp& rComp ) const; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir inline const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetComponent() const { return m_xComponent; } 121*cdf0e10cSrcweir inline const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& GetControlModel() const { return m_xControlModel; } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir sal_Int32 GetPos() const { return m_nPos; } 124*cdf0e10cSrcweir sal_Int16 GetTabIndex() const { return m_nTabIndex; } 125*cdf0e10cSrcweir ::rtl::OUString GetName() const { return m_aName; } 126*cdf0e10cSrcweir }; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir DECLARE_STL_VECTOR(OGroupComp, OGroupCompArr); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir //======================================================================== 131*cdf0e10cSrcweir class OGroupComp; 132*cdf0e10cSrcweir class OGroupCompAcc 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xComponent; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir OGroupComp m_aGroupComp; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir friend class OGroupCompAccLess; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir public: 141*cdf0e10cSrcweir OGroupCompAcc(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement, const OGroupComp& _rGroupComp ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir sal_Bool operator==( const OGroupCompAcc& rCompAcc ) const; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir inline const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetComponent() const { return m_xComponent; } 146*cdf0e10cSrcweir const OGroupComp& GetGroupComponent() const { return m_aGroupComp; } 147*cdf0e10cSrcweir }; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir DECLARE_STL_VECTOR(OGroupCompAcc, OGroupCompAccArr); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir //======================================================================== 152*cdf0e10cSrcweir class OGroup 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir OGroupCompArr m_aCompArray; 155*cdf0e10cSrcweir OGroupCompAccArr m_aCompAccArray; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir ::rtl::OUString m_aGroupName; 158*cdf0e10cSrcweir sal_uInt16 m_nInsertPos; // Die Einfugeposition der GroupComps wird von der Gruppe bestimmt. 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir friend class OGroupLess; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir public: 163*cdf0e10cSrcweir OGroup( const ::rtl::OUString& rGroupName ); 164*cdf0e10cSrcweir #ifdef DBG_UTIL 165*cdf0e10cSrcweir OGroup( const OGroup& _rSource ); // just to ensure the DBG_CTOR call 166*cdf0e10cSrcweir #endif 167*cdf0e10cSrcweir virtual ~OGroup(); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir sal_Bool operator==( const OGroup& rGroup ) const; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir ::rtl::OUString GetGroupName() const { return m_aGroupName; } 172*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> > GetControlModels() const; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir void InsertComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement ); 175*cdf0e10cSrcweir void RemoveComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement ); 176*cdf0e10cSrcweir sal_uInt16 Count() const { return sal::static_int_cast< sal_uInt16 >(m_aCompArray.size()); } 177*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetObject( sal_uInt16 nP ) const 178*cdf0e10cSrcweir { return m_aCompArray[nP].GetComponent(); } 179*cdf0e10cSrcweir }; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir DECLARE_STL_USTRINGACCESS_MAP(OGroup, OGroupArr); 182*cdf0e10cSrcweir DECLARE_STL_VECTOR(OGroupArr::iterator, OActiveGroups); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //======================================================================== 185*cdf0e10cSrcweir class OGroupManager : public ::cppu::WeakImplHelper2< ::com::sun::star::beans::XPropertyChangeListener, ::com::sun::star::container::XContainerListener> 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir OGroup* m_pCompGroup; // Alle Components nach TabIndizes sortiert 188*cdf0e10cSrcweir OGroupArr m_aGroupArr; // Alle Components nach Gruppen sortiert 189*cdf0e10cSrcweir OActiveGroups m_aActiveGroupMap; // In dieser Map werden die Indizes aller Gruppen gehalten, 190*cdf0e10cSrcweir // die mehr als 1 Element haben 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer > 193*cdf0e10cSrcweir m_xContainer; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // Helper functions 196*cdf0e10cSrcweir void InsertElement( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement ); 197*cdf0e10cSrcweir void RemoveElement( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement ); 198*cdf0e10cSrcweir void removeFromGroupMap(const ::rtl::OUString& _sGroupName,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xSet); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir public: 201*cdf0e10cSrcweir OGroupManager(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& _rxContainer); 202*cdf0e10cSrcweir virtual ~OGroupManager(); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // ::com::sun::star::lang::XEventListener 205*cdf0e10cSrcweir virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // ::com::sun::star::beans::XPropertyChangeListener 208*cdf0e10cSrcweir virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw ( ::com::sun::star::uno::RuntimeException); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // ::com::sun::star::container::XContainerListener 211*cdf0e10cSrcweir virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& _rEvent) throw ( ::com::sun::star::uno::RuntimeException); 212*cdf0e10cSrcweir virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& _rEvent) throw ( ::com::sun::star::uno::RuntimeException); 213*cdf0e10cSrcweir virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& _rEvent) throw ( ::com::sun::star::uno::RuntimeException); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // Other functions 216*cdf0e10cSrcweir sal_Int32 getGroupCount(); 217*cdf0e10cSrcweir void getGroup(sal_Int32 nGroup, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> >& _rGroup, ::rtl::OUString& Name); 218*cdf0e10cSrcweir void getGroupByName(const ::rtl::OUString& Name, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> >& _rGroup); 219*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> > getControlModels(); 220*cdf0e10cSrcweir }; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir //......................................................................... 224*cdf0e10cSrcweir } // namespace frm 225*cdf0e10cSrcweir //......................................................................... 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir #endif // _FRM_GROUPMANAGER_HXX_ 228*cdf0e10cSrcweir 229