Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef TOOLKIT_CONTROL_MODEL_CONTAINERBASE_HXX
21 : #define TOOLKIT_CONTROL_MODEL_CONTAINERBASE_HXX
22 :
23 : #include <com/sun/star/container/XNameContainer.hpp>
24 : #include <com/sun/star/container/XContainer.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 <com/sun/star/resource/XStringResourceResolver.hpp>
31 : #include <cppuhelper/implbase8.hxx>
32 : #include <cppuhelper/implbase3.hxx>
33 : #include <toolkit/helper/listenermultiplexer.hxx>
34 : #include <toolkit/controls/unocontrolmodel.hxx>
35 : #include <toolkit/controls/unocontrolcontainer.hxx>
36 : #include <cppuhelper/propshlp.hxx>
37 : #include <cppuhelper/basemutex.hxx>
38 : #include <com/sun/star/graphic/XGraphic.hpp>
39 : #include <com/sun/star/awt/tab/XTabPageModel.hpp>
40 : #include <com/sun/star/uno/XComponentContext.hpp>
41 : #include <com/sun/star/lang/XInitialization.hpp>
42 : #include <tools/gen.hxx>
43 : // ----------------------------------------------------
44 : // class ControlModelContainerBase
45 : // ----------------------------------------------------
46 : typedef UnoControlModel ControlModel_Base;
47 : typedef ::cppu::AggImplInheritanceHelper8 < ControlModel_Base
48 : , ::com::sun::star::lang::XMultiServiceFactory
49 : , ::com::sun::star::container::XContainer
50 : , ::com::sun::star::container::XNameContainer
51 : , ::com::sun::star::awt::XTabControllerModel
52 : , ::com::sun::star::util::XChangesNotifier
53 : , ::com::sun::star::beans::XPropertyChangeListener
54 : , ::com::sun::star::awt::tab::XTabPageModel
55 : , ::com::sun::star::lang::XInitialization
56 : > ControlModelContainer_IBase;
57 :
58 : class ControlModelContainerBase : public ControlModelContainer_IBase
59 : {
60 : public:
61 : enum ChildOperation { Insert = 0, Remove };
62 : // would like to make this typedef private, too, but the Forte 7 compiler does have
63 : // problems with this .....
64 : typedef ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >, ::rtl::OUString >
65 : UnoControlModelHolder;
66 : private:
67 : typedef ::std::list< UnoControlModelHolder > UnoControlModelHolderList;
68 :
69 : public:
70 : // for grouping control models (XTabControllerModel::getGroupXXX)
71 : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >
72 : ModelGroup;
73 : typedef ::std::vector< ModelGroup > AllGroups;
74 :
75 : friend struct CloneControlModel;
76 : friend struct FindControlModel;
77 : friend struct CompareControlModel;
78 :
79 : protected:
80 : ContainerListenerMultiplexer maContainerListeners;
81 : ::cppu::OInterfaceContainerHelper maChangeListeners;
82 : UnoControlModelHolderList maModels;
83 :
84 : AllGroups maGroups;
85 : sal_Bool mbGroupsUpToDate;
86 :
87 : bool m_bEnabled;
88 : ::rtl::OUString m_sTitle;
89 : ::rtl::OUString m_sImageURL;
90 : ::rtl::OUString m_sTooltip;
91 : sal_Int16 m_nTabPageId;
92 :
93 : void Clone_Impl(ControlModelContainerBase& _rClone) const;
94 : protected:
95 : ::com::sun::star::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const;
96 : ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
97 :
98 : UnoControlModelHolderList::iterator ImplFindElement( const ::rtl::OUString& rName );
99 :
100 : void updateUserFormChildren( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xAllChildren, const rtl::OUString& aName, ChildOperation Operation, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& xTarget ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
101 : public:
102 : ControlModelContainerBase( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
103 : ControlModelContainerBase( const ControlModelContainerBase& rModel );
104 : ~ControlModelContainerBase();
105 :
106 : UnoControlModel* Clone() const;
107 :
108 : // ::com::sun::star::container::XContainer
109 : void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
110 : void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
111 :
112 : // ::com::sun::star::container::XElementAcces
113 : ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
114 : sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
115 :
116 : // ::com::sun::star::container::XNameContainer, XNameReplace, XNameAccess
117 : void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
118 : ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
119 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException);
120 : sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
121 : void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
122 : void SAL_CALL removeByName( const ::rtl::OUString& Name ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
123 :
124 : // ::com::sun::star::beans::XMultiPropertySet
125 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
126 :
127 : // ::com::sun::star::lang::XMultiServiceFactory
128 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
129 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
130 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
131 :
132 : // XComponent
133 : void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException);
134 :
135 : // XTabControllerModel
136 : virtual sal_Bool SAL_CALL getGroupControl( ) throw (::com::sun::star::uno::RuntimeException);
137 : virtual void SAL_CALL setGroupControl( sal_Bool GroupControl ) throw (::com::sun::star::uno::RuntimeException);
138 : virtual void SAL_CALL setControlModels( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Controls ) throw (::com::sun::star::uno::RuntimeException);
139 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > SAL_CALL getControlModels( ) throw (::com::sun::star::uno::RuntimeException);
140 : virtual void SAL_CALL setGroup( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Group, const ::rtl::OUString& GroupName ) throw (::com::sun::star::uno::RuntimeException);
141 : virtual sal_Int32 SAL_CALL getGroupCount( ) throw (::com::sun::star::uno::RuntimeException);
142 : virtual void SAL_CALL getGroup( sal_Int32 nGroup, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Group, ::rtl::OUString& Name ) throw (::com::sun::star::uno::RuntimeException);
143 : virtual void SAL_CALL getGroupByName( const ::rtl::OUString& Name, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Group ) throw (::com::sun::star::uno::RuntimeException);
144 :
145 : // XChangesNotifier
146 : virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
147 : virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
148 :
149 : // XPropertyChangeListener
150 : virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
151 :
152 : // XEventListener
153 : using cppu::OPropertySetHelper::disposing;
154 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& evt ) throw (::com::sun::star::uno::RuntimeException);
155 :
156 : // XServiceInfo
157 0 : DECLIMPL_SERVICEINFO_DERIVED(ControlModelContainerBase, ControlModel_Base, "toolkit.ControlModelContainerBase" )
158 :
159 : // XInitialization
160 : virtual void SAL_CALL initialize (const com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rArguments)
161 : throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
162 :
163 : // ::com::sun::star::awt::tab::XTabPageModel
164 : virtual ::sal_Int16 SAL_CALL getTabPageID() throw (::com::sun::star::uno::RuntimeException);
165 : virtual ::sal_Bool SAL_CALL getEnabled() throw (::com::sun::star::uno::RuntimeException);
166 : virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (::com::sun::star::uno::RuntimeException);
167 : virtual ::rtl::OUString SAL_CALL getTitle() throw (::com::sun::star::uno::RuntimeException);
168 : virtual void SAL_CALL setTitle( const ::rtl::OUString& _title ) throw (::com::sun::star::uno::RuntimeException);
169 : virtual ::rtl::OUString SAL_CALL getImageURL() throw (::com::sun::star::uno::RuntimeException);
170 : virtual void SAL_CALL setImageURL( const ::rtl::OUString& _imageurl ) throw (::com::sun::star::uno::RuntimeException);
171 : virtual ::rtl::OUString SAL_CALL getToolTip() throw (::com::sun::star::uno::RuntimeException);
172 : virtual void SAL_CALL setToolTip( const ::rtl::OUString& _tooltip ) throw (::com::sun::star::uno::RuntimeException);
173 :
174 : protected:
175 : void startControlListening( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxChildModel );
176 : void stopControlListening( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxChildModel );
177 :
178 : void implNotifyTabModelChange( const ::rtl::OUString& _rAccessor );
179 :
180 : void implUpdateGroupStructure();
181 : };
182 :
183 : class ResourceListener :public ::com::sun::star::util::XModifyListener,
184 : public ::cppu::OWeakObject,
185 : public ::cppu::BaseMutex
186 : {
187 : public:
188 : ResourceListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& xListener );
189 : virtual ~ResourceListener();
190 :
191 : void startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver >& rResource );
192 : void stopListening();
193 :
194 : // XInterface
195 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
196 : virtual void SAL_CALL acquire() throw ();
197 : virtual void SAL_CALL release() throw ();
198 :
199 : // XModifyListener
200 : virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
201 :
202 : // XEventListener
203 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
204 :
205 : private:
206 : ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver > m_xResource;
207 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xListener;
208 : bool m_bListening;
209 : };
210 :
211 : typedef ::cppu::AggImplInheritanceHelper3 < UnoControlContainer
212 : , ::com::sun::star::container::XContainerListener
213 : , ::com::sun::star::util::XChangesListener
214 : , ::com::sun::star::util::XModifyListener
215 : > ContainerControl_IBase;
216 :
217 : class ControlContainerBase : public ContainerControl_IBase
218 : {
219 : ::Size ImplGetSizePixel( const ::Size& inSize );
220 : protected:
221 : bool mbSizeModified;
222 : bool mbPosModified;
223 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController > mxTabController;
224 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > mxListener;
225 :
226 : void ImplInsertControl( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxModel, const ::rtl::OUString& rName );
227 : void ImplRemoveControl( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxModel );
228 : virtual void ImplSetPosSize( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& rxCtrl );
229 : void ImplUpdateResourceResolver();
230 : void ImplStartListingForResourceEvents();
231 :
232 : ControlContainerBase();
233 :
234 : public:
235 : ControlContainerBase( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
236 : ~ControlContainerBase();
237 :
238 0 : DECLIMPL_SERVICEINFO_DERIVED( ControlContainerBase, UnoControlBase, "toolkit.ControlContainerBase" )
239 :
240 : void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
241 : void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
242 :
243 : void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& Toolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& Parent ) throw(::com::sun::star::uno::RuntimeException);
244 :
245 : // ::com::sun::star::container::XContainerListener
246 : void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
247 : void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
248 : void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
249 :
250 : // XChangesListener
251 : virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
252 :
253 : // ::com::sun::star::awt::XControl
254 : sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& Model ) throw(::com::sun::star::uno::RuntimeException);
255 : void SAL_CALL setDesignMode( sal_Bool bOn ) throw(::com::sun::star::uno::RuntimeException);
256 : // XModifyListener
257 : // Using a dummy/no-op implementation here, not sure if every container control needs
258 : // to implement this, certainly Dialog does, lets see about others
259 0 : virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException) {}
260 : protected:
261 : virtual void ImplModelPropertiesChanged( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyChangeEvent >& rEvents ) throw(::com::sun::star::uno::RuntimeException);
262 : virtual void removingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
263 : virtual void addingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
264 : };
265 : #endif
266 :
267 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|