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