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 .
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 <rtl/ref.hxx>
44 namespace com::sun::star::resource
{ class XStringResourceResolver
; }
45 namespace com::sun::star::uno
{ class XComponentContext
; }
46 class StdTabController
;
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
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
;
69 typedef ::std::vector
< UnoControlModelHolder
> UnoControlModelHolderVector
;
72 // for grouping control models (XTabControllerModel::getGroupXXX)
73 typedef ::std::vector
< css::uno::Reference
< css::awt::XControlModel
> >
75 typedef ::std::vector
< ModelGroup
> AllGroups
;
77 friend struct CloneControlModel
;
78 friend struct CompareControlModel
;
81 ContainerListenerMultiplexer maContainerListeners
;
82 ::comphelper::OInterfaceContainerHelper4
<css::util::XChangesListener
> maChangeListeners
;
83 UnoControlModelHolderVector maModels
;
86 bool mbGroupsUpToDate
;
90 sal_Int16 m_nTabPageId
;
92 void Clone_Impl(ControlModelContainerBase
& _rClone
) const;
94 css::uno::Any
ImplGetDefaultValue( sal_uInt16 nPropId
) const override
;
95 ::cppu::IPropertyArrayHelper
& getInfoHelper() override
;
97 UnoControlModelHolderVector::iterator
ImplFindElement( std::u16string_view rName
);
99 /// @throws css::lang::IllegalArgumentException
100 /// @throws css::container::ElementExistException
101 /// @throws css::lang::WrappedTargetException
102 /// @throws css::uno::RuntimeException
103 void updateUserFormChildren( const css::uno::Reference
< css::container::XNameContainer
>& xAllChildren
, const OUString
& aName
, ChildOperation Operation
, const css::uno::Reference
< css::awt::XControlModel
>& xTarget
);
105 ControlModelContainerBase( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
106 ControlModelContainerBase( const ControlModelContainerBase
& rModel
);
107 virtual ~ControlModelContainerBase() override
;
109 rtl::Reference
<UnoControlModel
> Clone() const override
;
111 // css::container::XContainer
112 void SAL_CALL
addContainerListener( const css::uno::Reference
< css::container::XContainerListener
>& xListener
) override
;
113 void SAL_CALL
removeContainerListener( const css::uno::Reference
< css::container::XContainerListener
>& xListener
) override
;
115 // css::container::XElementAccess
116 css::uno::Type SAL_CALL
getElementType( ) override
;
117 sal_Bool SAL_CALL
hasElements( ) override
;
119 // css::container::XNameContainer, XNameReplace, XNameAccess
120 void SAL_CALL
replaceByName( const OUString
& aName
, const css::uno::Any
& aElement
) override
;
121 css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
122 css::uno::Sequence
< OUString
> SAL_CALL
getElementNames( ) override
;
123 sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
124 void SAL_CALL
insertByName( const OUString
& aName
, const css::uno::Any
& aElement
) override
;
125 void SAL_CALL
removeByName( const OUString
& Name
) override
;
127 // css::beans::XMultiPropertySet
128 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
130 // css::lang::XMultiServiceFactory
131 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance( const OUString
& aServiceSpecifier
) override
;
132 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const OUString
& ServiceSpecifier
, const css::uno::Sequence
< css::uno::Any
>& Arguments
) override
;
133 css::uno::Sequence
< OUString
> SAL_CALL
getAvailableServiceNames( ) override
;
136 void SAL_CALL
dispose( ) override
;
138 // XTabControllerModel
139 virtual sal_Bool SAL_CALL
getGroupControl( ) override
;
140 virtual void SAL_CALL
setGroupControl( sal_Bool GroupControl
) override
;
141 virtual void SAL_CALL
setControlModels( const css::uno::Sequence
< css::uno::Reference
< css::awt::XControlModel
> >& Controls
) override
;
142 virtual css::uno::Sequence
< css::uno::Reference
< css::awt::XControlModel
> > SAL_CALL
getControlModels( ) override
;
143 virtual void SAL_CALL
setGroup( const css::uno::Sequence
< css::uno::Reference
< css::awt::XControlModel
> >& Group
, const OUString
& GroupName
) override
;
144 virtual sal_Int32 SAL_CALL
getGroupCount( ) override
;
145 virtual void SAL_CALL
getGroup( sal_Int32 nGroup
, css::uno::Sequence
< css::uno::Reference
< css::awt::XControlModel
> >& Group
, OUString
& Name
) override
;
146 virtual void SAL_CALL
getGroupByName( const OUString
& Name
, css::uno::Sequence
< css::uno::Reference
< css::awt::XControlModel
> >& Group
) override
;
149 virtual void SAL_CALL
addChangesListener( const css::uno::Reference
< css::util::XChangesListener
>& aListener
) override
;
150 virtual void SAL_CALL
removeChangesListener( const css::uno::Reference
< css::util::XChangesListener
>& aListener
) override
;
152 // XPropertyChangeListener
153 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& evt
) override
;
156 using comphelper::OPropertySetHelper::disposing
;
157 virtual void SAL_CALL
disposing( const css::lang::EventObject
& evt
) override
;
160 DECLIMPL_SERVICEINFO_DERIVED(ControlModelContainerBase
, ControlModel_Base
, "toolkit.ControlModelContainerBase" )
163 virtual void SAL_CALL
initialize (const css::uno::Sequence
<css::uno::Any
>& rArguments
) override
;
165 // css::awt::tab::XTabPageModel
166 virtual ::sal_Int16 SAL_CALL
getTabPageID() override
;
167 virtual sal_Bool SAL_CALL
getEnabled() override
;
168 virtual void SAL_CALL
setEnabled( sal_Bool _enabled
) override
;
169 virtual OUString SAL_CALL
getTitle() override
;
170 virtual void SAL_CALL
setTitle( const OUString
& _title
) override
;
171 virtual OUString SAL_CALL
getImageURL() override
;
172 virtual void SAL_CALL
setImageURL( const OUString
& _imageurl
) override
;
173 virtual OUString SAL_CALL
getToolTip() override
;
174 virtual void SAL_CALL
setToolTip( const OUString
& _tooltip
) override
;
177 void startControlListening( const css::uno::Reference
< css::awt::XControlModel
>& _rxChildModel
);
178 void stopControlListening( const css::uno::Reference
< css::awt::XControlModel
>& _rxChildModel
);
180 void implNotifyTabModelChange( const OUString
& _rAccessor
);
182 void implUpdateGroupStructure();
185 class ResourceListener final
: public css::util::XModifyListener
,
186 public ::cppu::OWeakObject
189 ResourceListener( const css::uno::Reference
< css::util::XModifyListener
>& xListener
);
190 virtual ~ResourceListener() override
;
192 void startListening( const css::uno::Reference
< css::resource::XStringResourceResolver
>& rResource
);
193 void stopListening();
196 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) override
;
197 virtual void SAL_CALL
acquire() noexcept override
;
198 virtual void SAL_CALL
release() noexcept override
;
201 virtual void SAL_CALL
modified( const css::lang::EventObject
& aEvent
) override
;
204 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
208 css::uno::Reference
< css::resource::XStringResourceResolver
> m_xResource
;
209 css::uno::Reference
< css::util::XModifyListener
> m_xListener
;
213 typedef ::cppu::AggImplInheritanceHelper3
< UnoControlContainer
214 , css::container::XContainerListener
215 , css::util::XChangesListener
216 , css::util::XModifyListener
217 > ControlContainer_IBase
;
219 class ControlContainerBase
: public ControlContainer_IBase
222 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
225 rtl::Reference
< StdTabController
> mxTabController
;
226 rtl::Reference
< ResourceListener
> mxListener
;
228 void ImplInsertControl( css::uno::Reference
< css::awt::XControlModel
> const & rxModel
, const OUString
& rName
);
229 void ImplRemoveControl( css::uno::Reference
< css::awt::XControlModel
> const & rxModel
);
230 virtual void ImplSetPosSize( css::uno::Reference
< css::awt::XControl
>& rxCtrl
);
231 void ImplUpdateResourceResolver();
232 void ImplStartListingForResourceEvents();
235 // just implemented to let the various FooImplInheritanceHelper compile
236 ControlContainerBase();
240 ControlContainerBase( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
241 virtual ~ControlContainerBase() override
;
243 DECLIMPL_SERVICEINFO_DERIVED( ControlContainerBase
, UnoControlBase
, "toolkit.ControlContainerBase" )
245 void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
246 void SAL_CALL
dispose() override
;
248 void SAL_CALL
createPeer( const css::uno::Reference
< css::awt::XToolkit
>& Toolkit
, const css::uno::Reference
< css::awt::XWindowPeer
>& Parent
) override
;
250 // css::container::XContainerListener
251 void SAL_CALL
elementInserted( const css::container::ContainerEvent
& Event
) override
;
252 void SAL_CALL
elementRemoved( const css::container::ContainerEvent
& Event
) override
;
253 void SAL_CALL
elementReplaced( const css::container::ContainerEvent
& Event
) override
;
256 virtual void SAL_CALL
changesOccurred( const css::util::ChangesEvent
& Event
) override
;
258 // css::awt::XControl
259 sal_Bool SAL_CALL
setModel( const css::uno::Reference
< css::awt::XControlModel
>& Model
) override
;
260 void SAL_CALL
setDesignMode( sal_Bool bOn
) override
;
262 // Using a dummy/no-op implementation here, not sure if every container control needs
263 // to implement this, certainly Dialog does, let's see about others
264 virtual void SAL_CALL
modified( const css::lang::EventObject
& ) override
{}
266 virtual void ImplModelPropertiesChanged( const css::uno::Sequence
< css::beans::PropertyChangeEvent
>& rEvents
) override
;
267 virtual void removingControl( const css::uno::Reference
< css::awt::XControl
>& _rxControl
) override
;
268 virtual void addingControl( const css::uno::Reference
< css::awt::XControl
>& _rxControl
) override
;
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */