1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _FRM_GROUPMANAGER_HXX_
21 #define _FRM_GROUPMANAGER_HXX_
23 #include <com/sun/star/sdbc/XRowSet.hpp>
24 #include <com/sun/star/awt/XControlModel.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
27 #include <com/sun/star/container/XContainerListener.hpp>
28 #include <com/sun/star/container/XContainer.hpp>
29 #include <cppuhelper/implbase2.hxx>
30 #include <comphelper/stl_types.hxx>
31 #include <comphelper/types.hxx>
35 using namespace comphelper
;
37 /*========================================================================
38 Funktionsweise GroupManager:
40 Der GroupManager horcht an der starform, ob FormComponents eingefuegt oder entfernt
41 werden. Zusaetzlich horcht er bei den FormComponents an den Properties
42 "Name" und "TabIndex". Mit diesen Infos aktualisiert er seine Gruppen.
44 Der GroupManager verwaltet eine Gruppe, in der alle Controls nach TabIndex
45 geordnet sind, und ein Array von Gruppen, in dem jede FormComponent noch
46 einmal einer Gruppe dem Namen nach zugeordnet wird.
47 Die einzelnen Gruppen werden ueber eine Map aktiviert, wenn sie mehr als
50 Die Gruppen verwalten intern die FormComponents in zwei Arrays. In dem
51 GroupCompArray werden die Components nach TabIndex und Einfuegepostion
52 sortiert. Da auf dieses Array ueber die FormComponent zugegriffen
53 wird, gibt es noch das GroupCompAccessArray, in dem die FormComponents
54 nach ihrer Speicheradresse sortiert sind. Jedes Element des
55 GroupCompAccessArrays ist mit einem Element des GroupCompArrays verpointert.
57 ========================================================================*/
59 //.........................................................................
62 //.........................................................................
64 //========================================================================
65 template <class ELEMENT
, class LESS_COMPARE
>
66 sal_Int32
insert_sorted(::std::vector
<ELEMENT
>& _rArray
, const ELEMENT
& _rNewElement
, const LESS_COMPARE
& _rCompareOp
)
68 typename ::std::vector
<ELEMENT
>::iterator aInsertPos
= ::std::lower_bound(
74 aInsertPos
= _rArray
.insert(aInsertPos
, _rNewElement
);
75 return aInsertPos
- _rArray
.begin();
78 template <class ELEMENT
, class LESS_COMPARE
>
79 sal_Bool
seek_entry(const ::std::vector
<ELEMENT
>& _rArray
, const ELEMENT
& _rNewElement
, sal_Int32
& nPos
, const LESS_COMPARE
& _rCompareOp
)
81 typename ::std::vector
<ELEMENT
>::const_iterator aExistentPos
= ::std::lower_bound(
87 if ((aExistentPos
!= _rArray
.end()) && (*aExistentPos
== _rNewElement
))
88 { // we have a valid "lower or equal" element and it's really "equal"
89 nPos
= aExistentPos
- _rArray
.begin();
96 //========================================================================
100 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xComponent
;
101 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
> m_xControlModel
;
103 sal_Int16 m_nTabIndex
;
105 friend class OGroupCompLess
;
108 OGroupComp(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& rxElement
, sal_Int32 nInsertPos
);
109 OGroupComp(const OGroupComp
& _rSource
);
112 sal_Bool
operator==( const OGroupComp
& rComp
) const;
114 inline const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& GetComponent() const { return m_xComponent
; }
115 inline const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
>& GetControlModel() const { return m_xControlModel
; }
117 sal_Int32
GetPos() const { return m_nPos
; }
118 sal_Int16
GetTabIndex() const { return m_nTabIndex
; }
119 OUString
GetName() const { return m_aName
; }
122 DECLARE_STL_VECTOR(OGroupComp
, OGroupCompArr
);
124 //========================================================================
128 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xComponent
;
130 OGroupComp m_aGroupComp
;
132 friend class OGroupCompAccLess
;
135 OGroupCompAcc(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& rxElement
, const OGroupComp
& _rGroupComp
);
137 sal_Bool
operator==( const OGroupCompAcc
& rCompAcc
) const;
139 inline const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& GetComponent() const { return m_xComponent
; }
140 const OGroupComp
& GetGroupComponent() const { return m_aGroupComp
; }
143 DECLARE_STL_VECTOR(OGroupCompAcc
, OGroupCompAccArr
);
145 //========================================================================
148 OGroupCompArr m_aCompArray
;
149 OGroupCompAccArr m_aCompAccArray
;
151 OUString m_aGroupName
;
152 sal_uInt16 m_nInsertPos
; // Die Einfugeposition der GroupComps wird von der Gruppe bestimmt.
154 friend class OGroupLess
;
157 OGroup( const OUString
& rGroupName
);
159 OGroup( const OGroup
& _rSource
); // just to ensure the DBG_CTOR call
163 sal_Bool
operator==( const OGroup
& rGroup
) const;
165 OUString
GetGroupName() const { return m_aGroupName
; }
166 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
> > GetControlModels() const;
168 void InsertComponent( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& rxElement
);
169 void RemoveComponent( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& rxElement
);
170 sal_uInt16
Count() const { return sal::static_int_cast
< sal_uInt16
>(m_aCompArray
.size()); }
171 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& GetObject( sal_uInt16 nP
) const
172 { return m_aCompArray
[nP
].GetComponent(); }
175 DECLARE_STL_USTRINGACCESS_MAP(OGroup
, OGroupArr
);
176 DECLARE_STL_VECTOR(OGroupArr::iterator
, OActiveGroups
);
178 //========================================================================
179 class OGroupManager
: public ::cppu::WeakImplHelper2
< ::com::sun::star::beans::XPropertyChangeListener
, ::com::sun::star::container::XContainerListener
>
181 OGroup
* m_pCompGroup
; // Alle Components nach TabIndizes sortiert
182 OGroupArr m_aGroupArr
; // Alle Components nach Gruppen sortiert
183 OActiveGroups m_aActiveGroupMap
; // In dieser Map werden die Indizes aller Gruppen gehalten,
184 // die mehr als 1 Element haben
186 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainer
>
190 void InsertElement( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& rxElement
);
191 void RemoveElement( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& rxElement
);
192 void removeFromGroupMap(const OUString
& _sGroupName
,const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xSet
);
195 OGroupManager(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainer
>& _rxContainer
);
196 virtual ~OGroupManager();
198 // ::com::sun::star::lang::XEventListener
199 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& _rSource
) throw(::com::sun::star::uno::RuntimeException
);
201 // ::com::sun::star::beans::XPropertyChangeListener
202 virtual void SAL_CALL
propertyChange(const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw ( ::com::sun::star::uno::RuntimeException
);
204 // ::com::sun::star::container::XContainerListener
205 virtual void SAL_CALL
elementInserted(const ::com::sun::star::container::ContainerEvent
& _rEvent
) throw ( ::com::sun::star::uno::RuntimeException
);
206 virtual void SAL_CALL
elementRemoved(const ::com::sun::star::container::ContainerEvent
& _rEvent
) throw ( ::com::sun::star::uno::RuntimeException
);
207 virtual void SAL_CALL
elementReplaced(const ::com::sun::star::container::ContainerEvent
& _rEvent
) throw ( ::com::sun::star::uno::RuntimeException
);
210 sal_Int32
getGroupCount();
211 void getGroup(sal_Int32 nGroup
, ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
> >& _rGroup
, OUString
& Name
);
212 void getGroupByName(const OUString
& Name
, ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
> >& _rGroup
);
213 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
> > getControlModels();
215 static OUString
GetGroupName( ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xComponent
);
219 //.........................................................................
221 //.........................................................................
223 #endif // _FRM_GROUPMANAGER_HXX_
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */