Version 24.2.2.2, tag libreoffice-24.2.2.2
[LibreOffice.git] / toolkit / inc / controls / controlmodelcontainerbase.hxx
blobae414346c78fbff2b0e2de1a2de90eb912730ddd
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 #pragma once
22 #include <com/sun/star/container/XNameContainer.hpp>
23 #include <com/sun/star/container/XContainer.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/awt/XTabControllerModel.hpp>
26 #include <com/sun/star/util/XChangesNotifier.hpp>
27 #include <com/sun/star/util/XChangesListener.hpp>
28 #include <com/sun/star/util/XModifyListener.hpp>
29 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
30 #include <cppuhelper/implbase8.hxx>
31 #include <cppuhelper/implbase3.hxx>
32 #include <cppuhelper/weak.hxx>
33 #include <toolkit/helper/listenermultiplexer.hxx>
34 #include <toolkit/controls/unocontrolmodel.hxx>
35 #include <controls/unocontrolcontainer.hxx>
36 #include <cppuhelper/propshlp.hxx>
37 #include <com/sun/star/awt/tab/XTabPageModel.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <comphelper/interfacecontainer4.hxx>
40 #include <mutex>
41 #include <vector>
43 namespace com::sun::star::resource { class XStringResourceResolver; }
44 namespace com::sun::star::uno { class XComponentContext; }
47 typedef UnoControlModel ControlModel_Base;
48 typedef ::cppu::AggImplInheritanceHelper8 < ControlModel_Base
49 , css::lang::XMultiServiceFactory
50 , css::container::XContainer
51 , css::container::XNameContainer
52 , css::awt::XTabControllerModel
53 , css::util::XChangesNotifier
54 , css::beans::XPropertyChangeListener
55 , css::awt::tab::XTabPageModel
56 , css::lang::XInitialization
57 > ControlModelContainer_IBase;
59 class ControlModelContainerBase : public ControlModelContainer_IBase
61 public:
62 enum ChildOperation { Insert = 0, Remove };
63 // would like to make this typedef private, too, but the Forte 7 compiler does have
64 // problems with this...
65 typedef ::std::pair< css::uno::Reference< css::awt::XControlModel >, OUString >
66 UnoControlModelHolder;
67 private:
68 typedef ::std::vector< UnoControlModelHolder > UnoControlModelHolderVector;
70 public:
71 // for grouping control models (XTabControllerModel::getGroupXXX)
72 typedef ::std::vector< css::uno::Reference< css::awt::XControlModel > >
73 ModelGroup;
74 typedef ::std::vector< ModelGroup > AllGroups;
76 friend struct CloneControlModel;
77 friend struct CompareControlModel;
79 protected:
80 ContainerListenerMultiplexer maContainerListeners;
81 ::comphelper::OInterfaceContainerHelper4<css::util::XChangesListener> maChangeListeners;
82 UnoControlModelHolderVector maModels;
84 AllGroups maGroups;
85 bool mbGroupsUpToDate;
87 OUString m_sImageURL;
88 OUString m_sTooltip;
89 sal_Int16 m_nTabPageId;
91 void Clone_Impl(ControlModelContainerBase& _rClone) const;
92 protected:
93 css::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const override;
94 ::cppu::IPropertyArrayHelper& getInfoHelper() override;
96 UnoControlModelHolderVector::iterator ImplFindElement( std::u16string_view rName );
98 /// @throws css::lang::IllegalArgumentException
99 /// @throws css::container::ElementExistException
100 /// @throws css::lang::WrappedTargetException
101 /// @throws css::uno::RuntimeException
102 void updateUserFormChildren( const css::uno::Reference< css::container::XNameContainer >& xAllChildren, const OUString& aName, ChildOperation Operation, const css::uno::Reference< css::awt::XControlModel >& xTarget );
103 public:
104 ControlModelContainerBase( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
105 ControlModelContainerBase( const ControlModelContainerBase& rModel );
106 virtual ~ControlModelContainerBase() override;
108 rtl::Reference<UnoControlModel> Clone() const override;
110 // css::container::XContainer
111 void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
112 void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
114 // css::container::XElementAccess
115 css::uno::Type SAL_CALL getElementType( ) override;
116 sal_Bool SAL_CALL hasElements( ) override;
118 // css::container::XNameContainer, XNameReplace, XNameAccess
119 void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
120 css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
121 css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
122 sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
123 void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
124 void SAL_CALL removeByName( const OUString& Name ) override;
126 // css::beans::XMultiPropertySet
127 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
129 // css::lang::XMultiServiceFactory
130 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const OUString& aServiceSpecifier ) override;
131 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) override;
132 css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames( ) override;
134 // XComponent
135 void SAL_CALL dispose( ) override;
137 // XTabControllerModel
138 virtual sal_Bool SAL_CALL getGroupControl( ) override;
139 virtual void SAL_CALL setGroupControl( sal_Bool GroupControl ) override;
140 virtual void SAL_CALL setControlModels( const css::uno::Sequence< css::uno::Reference< css::awt::XControlModel > >& Controls ) override;
141 virtual css::uno::Sequence< css::uno::Reference< css::awt::XControlModel > > SAL_CALL getControlModels( ) override;
142 virtual void SAL_CALL setGroup( const css::uno::Sequence< css::uno::Reference< css::awt::XControlModel > >& Group, const OUString& GroupName ) override;
143 virtual sal_Int32 SAL_CALL getGroupCount( ) override;
144 virtual void SAL_CALL getGroup( sal_Int32 nGroup, css::uno::Sequence< css::uno::Reference< css::awt::XControlModel > >& Group, OUString& Name ) override;
145 virtual void SAL_CALL getGroupByName( const OUString& Name, css::uno::Sequence< css::uno::Reference< css::awt::XControlModel > >& Group ) override;
147 // XChangesNotifier
148 virtual void SAL_CALL addChangesListener( const css::uno::Reference< css::util::XChangesListener >& aListener ) override;
149 virtual void SAL_CALL removeChangesListener( const css::uno::Reference< css::util::XChangesListener >& aListener ) override;
151 // XPropertyChangeListener
152 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
154 // XEventListener
155 using comphelper::OPropertySetHelper::disposing;
156 virtual void SAL_CALL disposing( const css::lang::EventObject& evt ) override;
158 // XServiceInfo
159 DECLIMPL_SERVICEINFO_DERIVED(ControlModelContainerBase, ControlModel_Base, "toolkit.ControlModelContainerBase" )
161 // XInitialization
162 virtual void SAL_CALL initialize (const css::uno::Sequence<css::uno::Any>& rArguments) override;
164 // css::awt::tab::XTabPageModel
165 virtual ::sal_Int16 SAL_CALL getTabPageID() override;
166 virtual sal_Bool SAL_CALL getEnabled() override;
167 virtual void SAL_CALL setEnabled( sal_Bool _enabled ) override;
168 virtual OUString SAL_CALL getTitle() override;
169 virtual void SAL_CALL setTitle( const OUString& _title ) override;
170 virtual OUString SAL_CALL getImageURL() override;
171 virtual void SAL_CALL setImageURL( const OUString& _imageurl ) override;
172 virtual OUString SAL_CALL getToolTip() override;
173 virtual void SAL_CALL setToolTip( const OUString& _tooltip ) override;
175 protected:
176 void startControlListening( const css::uno::Reference< css::awt::XControlModel >& _rxChildModel );
177 void stopControlListening( const css::uno::Reference< css::awt::XControlModel >& _rxChildModel );
179 void implNotifyTabModelChange( const OUString& _rAccessor );
181 void implUpdateGroupStructure();
184 class ResourceListener final : public css::util::XModifyListener,
185 public ::cppu::OWeakObject
187 public:
188 ResourceListener( const css::uno::Reference< css::util::XModifyListener >& xListener );
189 virtual ~ResourceListener() override;
191 void startListening( const css::uno::Reference< css::resource::XStringResourceResolver >& rResource );
192 void stopListening();
194 // XInterface
195 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
196 virtual void SAL_CALL acquire() noexcept override;
197 virtual void SAL_CALL release() noexcept override;
199 // XModifyListener
200 virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
202 // XEventListener
203 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
205 private:
206 std::mutex m_aMutex;
207 css::uno::Reference< css::resource::XStringResourceResolver > m_xResource;
208 css::uno::Reference< css::util::XModifyListener > m_xListener;
209 bool m_bListening;
212 typedef ::cppu::AggImplInheritanceHelper3 < UnoControlContainer
213 , css::container::XContainerListener
214 , css::util::XChangesListener
215 , css::util::XModifyListener
216 > ControlContainer_IBase;
218 class ControlContainerBase : public ControlContainer_IBase
220 protected:
221 css::uno::Reference< css::uno::XComponentContext > m_xContext;
222 bool mbSizeModified;
223 bool mbPosModified;
224 css::uno::Reference< css::awt::XTabController > mxTabController;
225 css::uno::Reference< css::util::XModifyListener > mxListener;
227 void ImplInsertControl( css::uno::Reference< css::awt::XControlModel > const & rxModel, const OUString& rName );
228 void ImplRemoveControl( css::uno::Reference< css::awt::XControlModel > const & rxModel );
229 virtual void ImplSetPosSize( css::uno::Reference< css::awt::XControl >& rxCtrl );
230 void ImplUpdateResourceResolver();
231 void ImplStartListingForResourceEvents();
233 #ifdef _MSC_VER
234 // just implemented to let the various FooImplInheritanceHelper compile
235 ControlContainerBase();
236 #endif
238 public:
239 ControlContainerBase( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
240 virtual ~ControlContainerBase() override;
242 DECLIMPL_SERVICEINFO_DERIVED( ControlContainerBase, UnoControlBase, "toolkit.ControlContainerBase" )
244 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
245 void SAL_CALL dispose() override;
247 void SAL_CALL createPeer( const css::uno::Reference< css::awt::XToolkit >& Toolkit, const css::uno::Reference< css::awt::XWindowPeer >& Parent ) override;
249 // css::container::XContainerListener
250 void SAL_CALL elementInserted( const css::container::ContainerEvent& Event ) override;
251 void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) override;
252 void SAL_CALL elementReplaced( const css::container::ContainerEvent& Event ) override;
254 // XChangesListener
255 virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& Event ) override;
257 // css::awt::XControl
258 sal_Bool SAL_CALL setModel( const css::uno::Reference< css::awt::XControlModel >& Model ) override;
259 void SAL_CALL setDesignMode( sal_Bool bOn ) override;
260 // XModifyListener
261 // Using a dummy/no-op implementation here, not sure if every container control needs
262 // to implement this, certainly Dialog does, lets see about others
263 virtual void SAL_CALL modified( const css::lang::EventObject& ) override {}
264 protected:
265 virtual void ImplModelPropertiesChanged( const css::uno::Sequence< css::beans::PropertyChangeEvent >& rEvents ) override;
266 virtual void removingControl( const css::uno::Reference< css::awt::XControl >& _rxControl ) override;
267 virtual void addingControl( const css::uno::Reference< css::awt::XControl >& _rxControl ) override;
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */