Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _FRM_GROUPMANAGER_HXX_
30 : : #define _FRM_GROUPMANAGER_HXX_
31 : :
32 : : #include <com/sun/star/sdbc/XRowSet.hpp>
33 : : #include <com/sun/star/awt/XControlModel.hpp>
34 : : #include <com/sun/star/beans/XPropertySet.hpp>
35 : : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
36 : : #include <com/sun/star/container/XContainerListener.hpp>
37 : : #include <com/sun/star/container/XContainer.hpp>
38 : : #include <cppuhelper/implbase2.hxx>
39 : : #include <comphelper/stl_types.hxx>
40 : : #include <comphelper/types.hxx>
41 : :
42 : : #include <algorithm>
43 : :
44 : : using namespace comphelper;
45 : :
46 : : /*========================================================================
47 : : Funktionsweise GroupManager:
48 : :
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.
52 : :
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.
58 : :
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.
65 : :
66 : : ========================================================================*/
67 : :
68 : : //.........................................................................
69 : : namespace frm
70 : : {
71 : : //.........................................................................
72 : :
73 : : //========================================================================
74 : : template <class ELEMENT, class LESS_COMPARE>
75 : 5320 : sal_Int32 insert_sorted(::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, const LESS_COMPARE& _rCompareOp)
76 : : {
77 : : typename ::std::vector<ELEMENT>::iterator aInsertPos = ::std::lower_bound(
78 : : _rArray.begin(),
79 : : _rArray.end(),
80 : : _rNewElement,
81 : : _rCompareOp
82 [ + - ][ + - ]: 5320 : );
83 [ + - ][ + - ]: 5320 : aInsertPos = _rArray.insert(aInsertPos, _rNewElement);
84 [ + - ][ + - ]: 5320 : return aInsertPos - _rArray.begin();
85 : : }
86 : :
87 : : template <class ELEMENT, class LESS_COMPARE>
88 : 4936 : sal_Bool seek_entry(const ::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, sal_Int32& nPos, const LESS_COMPARE& _rCompareOp)
89 : : {
90 : : typename ::std::vector<ELEMENT>::const_iterator aExistentPos = ::std::lower_bound(
91 : : _rArray.begin(),
92 : : _rArray.end(),
93 : : _rNewElement,
94 : : _rCompareOp
95 [ + - ][ + - ]: 4936 : );
96 [ + - ][ + - ]: 4936 : if ((aExistentPos != _rArray.end()) && (*aExistentPos == _rNewElement))
[ + - ][ + - ]
[ + - # # ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
[ + - # # ]
97 : : { // we have a valid "lower or equal" element and it's really "equal"
98 [ + - ][ + - ]: 4936 : nPos = aExistentPos - _rArray.begin();
99 : 4936 : return sal_True;
100 : : }
101 : 0 : nPos = -1;
102 : 4936 : return sal_False;
103 : : }
104 : :
105 : : //========================================================================
106 : 20728 : class OGroupComp
107 : : {
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;
113 : :
114 : : friend class OGroupCompLess;
115 : :
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();
120 : :
121 : : sal_Bool operator==( const OGroupComp& rComp ) const;
122 : :
123 : 2 : inline const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetComponent() const { return m_xComponent; }
124 : 159 : inline const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& GetControlModel() const { return m_xControlModel; }
125 : :
126 : 5829 : sal_Int32 GetPos() const { return m_nPos; }
127 : 6985 : sal_Int16 GetTabIndex() const { return m_nTabIndex; }
128 : : ::rtl::OUString GetName() const { return m_aName; }
129 : : };
130 : :
131 : : DECLARE_STL_VECTOR(OGroupComp, OGroupCompArr);
132 : :
133 : : //========================================================================
134 : : class OGroupComp;
135 [ + - ][ + - ]: 14580 : class OGroupCompAcc
136 : : {
137 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xComponent;
138 : :
139 : : OGroupComp m_aGroupComp;
140 : :
141 : : friend class OGroupCompAccLess;
142 : :
143 : : public:
144 : : OGroupCompAcc(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement, const OGroupComp& _rGroupComp );
145 : :
146 : : sal_Bool operator==( const OGroupCompAcc& rCompAcc ) const;
147 : :
148 : 2468 : inline const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetComponent() const { return m_xComponent; }
149 : 2468 : const OGroupComp& GetGroupComponent() const { return m_aGroupComp; }
150 : : };
151 : :
152 : : DECLARE_STL_VECTOR(OGroupCompAcc, OGroupCompAccArr);
153 : :
154 : : //========================================================================
155 [ + - ]: 1852 : class OGroup
156 : : {
157 : : OGroupCompArr m_aCompArray;
158 : : OGroupCompAccArr m_aCompAccArray;
159 : :
160 : : ::rtl::OUString m_aGroupName;
161 : : sal_uInt16 m_nInsertPos; // Die Einfugeposition der GroupComps wird von der Gruppe bestimmt.
162 : :
163 : : friend class OGroupLess;
164 : :
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();
171 : :
172 : : sal_Bool operator==( const OGroup& rGroup ) const;
173 : :
174 : 6 : ::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;
176 : :
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 : 3894 : sal_uInt16 Count() const { return sal::static_int_cast< sal_uInt16 >(m_aCompArray.size()); }
180 : 2 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetObject( sal_uInt16 nP ) const
181 : 2 : { return m_aCompArray[nP].GetComponent(); }
182 : : };
183 : :
184 : : DECLARE_STL_USTRINGACCESS_MAP(OGroup, OGroupArr);
185 : : DECLARE_STL_VECTOR(OGroupArr::iterator, OActiveGroups);
186 : :
187 : : //========================================================================
188 : : class OGroupManager : public ::cppu::WeakImplHelper2< ::com::sun::star::beans::XPropertyChangeListener, ::com::sun::star::container::XContainerListener>
189 : : {
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
194 : :
195 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >
196 : : m_xContainer;
197 : :
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);
202 : :
203 : : public:
204 : : OGroupManager(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& _rxContainer);
205 : : virtual ~OGroupManager();
206 : :
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);
209 : :
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);
212 : :
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);
217 : :
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();
223 : :
224 : : static ::rtl::OUString GetGroupName( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xComponent );
225 : : };
226 : :
227 : :
228 : : //.........................................................................
229 : : } // namespace frm
230 : : //.........................................................................
231 : :
232 : : #endif // _FRM_GROUPMANAGER_HXX_
233 : :
234 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|