nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / component / GroupManager.hxx
blobd3734b751d281b94983b5643fe5fafe6d3e986ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 INCLUDED_FORMS_SOURCE_COMPONENT_GROUPMANAGER_HXX
21 #define INCLUDED_FORMS_SOURCE_COMPONENT_GROUPMANAGER_HXX
23 #include <com/sun/star/awt/XControlModel.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
26 #include <com/sun/star/container/XContainerListener.hpp>
27 #include <com/sun/star/container/XContainer.hpp>
28 #include <cppuhelper/implbase.hxx>
30 #include <map>
31 #include <memory>
32 #include <vector>
35 * The GroupManager listens at the StarForm for FormComponent insertion and removal as well as
36 * its properties "Name" and "TabIndex" and updates its Group using this information.
38 * The GroupManager manages a Group in which all Controls are sorted by TabIndex.
39 * It also manages an array of Groups, in which each FormComponent is assigned a
40 * Group according to its name.
41 * Each Group is activated using a Map, if they contain more than one element.
43 * The Groups manage the FormComponents internally using two arrays.
44 * In the GroupCompArray the Components are sorted by TabIndex and insertion position.
45 * Because this array is accessed via the FormComponent, we also have the GroupCompAccessArray
46 * in which the FormComponents are sorted by their storage address.
47 * Every element of the GroupCompArray has a pointer to the GroupCompArray.
49 namespace frm
53 template <class ELEMENT, class LESS_COMPARE>
54 sal_Int32 insert_sorted(::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, const LESS_COMPARE& _rCompareOp)
56 typename ::std::vector<ELEMENT>::iterator aInsertPos = ::std::lower_bound(
57 _rArray.begin(),
58 _rArray.end(),
59 _rNewElement,
60 _rCompareOp
62 aInsertPos = _rArray.insert(aInsertPos, _rNewElement);
63 return aInsertPos - _rArray.begin();
66 template <class ELEMENT, class LESS_COMPARE>
67 bool seek_entry(const ::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, sal_Int32& nPos, const LESS_COMPARE& _rCompareOp)
69 typename ::std::vector<ELEMENT>::const_iterator aExistentPos = ::std::lower_bound(
70 _rArray.begin(),
71 _rArray.end(),
72 _rNewElement,
73 _rCompareOp
75 if ((aExistentPos != _rArray.end()) && (*aExistentPos == _rNewElement))
76 { // we have a valid "lower or equal" element and it's really "equal"
77 nPos = aExistentPos - _rArray.begin();
78 return true;
80 nPos = -1;
81 return false;
85 class OGroupComp
87 css::uno::Reference< css::beans::XPropertySet> m_xComponent;
88 css::uno::Reference< css::awt::XControlModel> m_xControlModel;
89 sal_Int32 m_nPos;
90 sal_Int16 m_nTabIndex;
92 friend class OGroupCompLess;
94 public:
95 OGroupComp(const css::uno::Reference< css::beans::XPropertySet>& rxElement, sal_Int32 nInsertPos );
96 OGroupComp();
98 bool operator==( const OGroupComp& rComp ) const;
100 const css::uno::Reference< css::beans::XPropertySet>& GetComponent() const { return m_xComponent; }
101 const css::uno::Reference< css::awt::XControlModel>& GetControlModel() const { return m_xControlModel; }
103 sal_Int32 GetPos() const { return m_nPos; }
104 sal_Int16 GetTabIndex() const { return m_nTabIndex; }
108 class OGroupComp;
109 class OGroupCompAcc
111 css::uno::Reference< css::beans::XPropertySet> m_xComponent;
113 OGroupComp m_aGroupComp;
115 friend class OGroupCompAccLess;
117 public:
118 OGroupCompAcc(const css::uno::Reference< css::beans::XPropertySet>& rxElement, const OGroupComp& _rGroupComp );
120 bool operator==( const OGroupCompAcc& rCompAcc ) const;
122 const OGroupComp& GetGroupComponent() const { return m_aGroupComp; }
125 class OGroup final
127 std::vector<OGroupComp> m_aCompArray;
128 std::vector<OGroupCompAcc> m_aCompAccArray;
130 OUString m_aGroupName;
131 sal_uInt16 m_nInsertPos; // The insertion position of the GroupComps is determined by the Group
133 friend class OGroupLess;
135 public:
136 explicit OGroup(const OUString& rGroupName);
138 const OUString& GetGroupName() const { return m_aGroupName; }
139 css::uno::Sequence< css::uno::Reference< css::awt::XControlModel> > GetControlModels() const;
141 void InsertComponent( const css::uno::Reference< css::beans::XPropertySet>& rxElement );
142 void RemoveComponent( const css::uno::Reference< css::beans::XPropertySet>& rxElement );
143 sal_uInt16 Count() const { return sal::static_int_cast< sal_uInt16 >(m_aCompArray.size()); }
144 const css::uno::Reference< css::beans::XPropertySet>& GetObject( sal_uInt16 nP ) const
145 { return m_aCompArray[nP].GetComponent(); }
148 typedef std::map<OUString, OGroup> OGroupArr;
149 typedef std::vector<OGroupArr::iterator> OActiveGroups;
152 class OGroupManager : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener, css::container::XContainerListener>
154 std::unique_ptr<OGroup>
155 m_pCompGroup; // Sort all Components by TabIndices
156 OGroupArr m_aGroupArr; // Sort all Components by group
157 OActiveGroups m_aActiveGroupMap; // This map contains all indices of all groups with more than 1 element
159 css::uno::Reference< css::container::XContainer >
160 m_xContainer;
162 // Helper functions
163 void InsertElement( const css::uno::Reference< css::beans::XPropertySet>& rxElement );
164 void RemoveElement( const css::uno::Reference< css::beans::XPropertySet>& rxElement );
165 void removeFromGroupMap(const OUString& _sGroupName,const css::uno::Reference< css::beans::XPropertySet>& _xSet);
167 public:
168 explicit OGroupManager(const css::uno::Reference< css::container::XContainer >& _rxContainer);
169 virtual ~OGroupManager() override;
171 // css::lang::XEventListener
172 virtual void SAL_CALL disposing(const css::lang::EventObject& _rSource) override;
174 // css::beans::XPropertyChangeListener
175 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
177 // css::container::XContainerListener
178 virtual void SAL_CALL elementInserted(const css::container::ContainerEvent& _rEvent) override;
179 virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent& _rEvent) override;
180 virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent& _rEvent) override;
182 // Other functions
183 sal_Int32 getGroupCount() const;
184 void getGroup(sal_Int32 nGroup, css::uno::Sequence< css::uno::Reference< css::awt::XControlModel> >& _rGroup, OUString& Name);
185 void getGroupByName(const OUString& Name, css::uno::Sequence< css::uno::Reference< css::awt::XControlModel> >& _rGroup);
186 css::uno::Sequence< css::uno::Reference< css::awt::XControlModel> > getControlModels() const;
188 static OUString GetGroupName( const css::uno::Reference< css::beans::XPropertySet>& xComponent );
192 } // namespace frm
195 #endif // INCLUDED_FORMS_SOURCE_COMPONENT_GROUPMANAGER_HXX
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */