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