1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef TOOLKIT_CONTROL_MODEL_CONTAINERBASE_HXX
25 #define TOOLKIT_CONTROL_MODEL_CONTAINERBASE_HXX
26 
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/container/XContainer.hpp>
29 #include <com/sun/star/awt/XTabControllerModel.hpp>
30 #include <com/sun/star/util/XChangesNotifier.hpp>
31 #include <com/sun/star/util/XChangesListener.hpp>
32 #include <com/sun/star/util/XModifyListener.hpp>
33 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
34 #include <com/sun/star/resource/XStringResourceResolver.hpp>
35 #include <cppuhelper/implbase8.hxx>
36 #include <cppuhelper/implbase2.hxx>
37 #include <toolkit/helper/listenermultiplexer.hxx>
38 #include <toolkit/controls/unocontrolmodel.hxx>
39 #include <toolkit/controls/unocontrolcontainer.hxx>
40 #include <cppuhelper/propshlp.hxx>
41 #include <cppuhelper/basemutex.hxx>
42 #include <com/sun/star/graphic/XGraphic.hpp>
43 #include <com/sun/star/awt/tab/XTabPageModel.hpp>
44 #include <com/sun/star/uno/XComponentContext.hpp>
45 #include <com/sun/star/lang/XInitialization.hpp>
46 //	----------------------------------------------------
47 //	class ControlModelContainerBase
48 //	----------------------------------------------------
49 typedef UnoControlModel		ControlModel_Base;
50 typedef ::cppu::AggImplInheritanceHelper8	<	ControlModel_Base
51                             ,   ::com::sun::star::lang::XMultiServiceFactory
52 							,	::com::sun::star::container::XContainer
53 							,	::com::sun::star::container::XNameContainer
54 							,	::com::sun::star::awt::XTabControllerModel
55 							,	::com::sun::star::util::XChangesNotifier
56 							,	::com::sun::star::beans::XPropertyChangeListener
57 							,   ::com::sun::star::awt::tab::XTabPageModel
58 							,	::com::sun::star::lang::XInitialization
59 							>	ControlModelContainer_IBase;
60 
61 class ControlModelContainerBase :	public ControlModelContainer_IBase
62 {
63 public:
64     // would like to make this typedef private, too, but the Forte 7 compiler does have
65     // problems with this .....
66 	typedef ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >, ::rtl::OUString >
67 														UnoControlModelHolder;
68 private:
69 	typedef ::std::list< UnoControlModelHolder >		UnoControlModelHolderList;
70 
71 	// for grouping control models (XTabControllerModel::getGroupXXX)
72 	typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >
73 														ModelGroup;
74 	typedef	::std::vector< ModelGroup >					AllGroups;
75 
76 	friend struct CloneControlModel;
77 	friend struct FindControlModel;
78 	friend struct CompareControlModel;
79 
80 protected:
81 	ContainerListenerMultiplexer		maContainerListeners;
82 	::cppu::OInterfaceContainerHelper	maChangeListeners;
83 	UnoControlModelHolderList			maModels;
84 
85 	AllGroups							maGroups;
86 	sal_Bool							mbGroupsUpToDate;
87 
88 	bool									m_bEnabled;
89 	::rtl::OUString							m_sTitle;
90 	::rtl::OUString							m_sImageURL;
91 	::rtl::OUString							m_sTooltip;
92 	sal_Int16								m_nTabPageId;
93 
94     void	Clone_Impl(ControlModelContainerBase& _rClone) const;
95 
96 protected:
97 	::com::sun::star::uno::Any			ImplGetDefaultValue( sal_uInt16 nPropId ) const;
98 	::cppu::IPropertyArrayHelper&		SAL_CALL getInfoHelper();
99 
100 	UnoControlModelHolderList::iterator			ImplFindElement( const ::rtl::OUString& rName );
101 
102 public:
103 						ControlModelContainerBase( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
104 						ControlModelContainerBase( const ControlModelContainerBase& rModel );
105 						~ControlModelContainerBase();
106 
107 	UnoControlModel*	Clone() const;
108 
109 	// ::com::sun::star::container::XContainer
110     void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
111     void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
112 
113 	// ::com::sun::star::container::XElementAcces
114 	::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
115 	sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
116 
117 	// ::com::sun::star::container::XNameContainer, XNameReplace, XNameAccess
118 	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);
119 	::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);
120 	::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException);
121 	sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
122 	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);
123 	void SAL_CALL removeByName( const ::rtl::OUString& Name ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
124 
125 	// ::com::sun::star::beans::XMultiPropertySet
126 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
127 
128 	// ::com::sun::star::lang::XMultiServiceFactory
129     ::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);
130     ::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);
131     ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
132 
133 	// XComponent
134 	void SAL_CALL dispose(  ) throw(::com::sun::star::uno::RuntimeException);
135 
136 	// XTabControllerModel
137     virtual sal_Bool SAL_CALL getGroupControl(  ) throw (::com::sun::star::uno::RuntimeException);
138     virtual void SAL_CALL setGroupControl( sal_Bool GroupControl ) throw (::com::sun::star::uno::RuntimeException);
139     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);
140     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);
141     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);
142     virtual sal_Int32 SAL_CALL getGroupCount(  ) throw (::com::sun::star::uno::RuntimeException);
143     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);
144     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);
145 
146 	// XChangesNotifier
147     virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
148     virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
149 
150 	// XPropertyChangeListener
151     virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
152 
153 	// XEventListener
154     using cppu::OPropertySetHelper::disposing;
155     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& evt ) throw (::com::sun::star::uno::RuntimeException);
156 
157 	// XServiceInfo
158 	DECLIMPL_SERVICEINFO_DERIVED(ControlModelContainerBase, ControlModel_Base, "toolkit.ControlModelContainerBase" )
159 
160 	// XInitialization
161 	virtual void SAL_CALL initialize (const com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rArguments)
162 			throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
163 
164 	// ::com::sun::star::awt::tab::XTabPageModel
165 	virtual ::sal_Int16 SAL_CALL getTabPageID() throw (::com::sun::star::uno::RuntimeException);
166     virtual ::sal_Bool SAL_CALL getEnabled() throw (::com::sun::star::uno::RuntimeException);
167     virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (::com::sun::star::uno::RuntimeException);
168     virtual ::rtl::OUString SAL_CALL getTitle() throw (::com::sun::star::uno::RuntimeException);
169     virtual void SAL_CALL setTitle( const ::rtl::OUString& _title ) throw (::com::sun::star::uno::RuntimeException);
170     virtual ::rtl::OUString SAL_CALL getImageURL() throw (::com::sun::star::uno::RuntimeException);
171     virtual void SAL_CALL setImageURL( const ::rtl::OUString& _imageurl ) throw (::com::sun::star::uno::RuntimeException);
172     virtual ::rtl::OUString SAL_CALL getToolTip() throw (::com::sun::star::uno::RuntimeException);
173     virtual void SAL_CALL setToolTip( const ::rtl::OUString& _tooltip ) throw (::com::sun::star::uno::RuntimeException);
174 
175 protected:
176 	void startControlListening( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxChildModel );
177 	void stopControlListening( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxChildModel );
178 
179 	void implNotifyTabModelChange( const ::rtl::OUString& _rAccessor );
180 
181 	void implUpdateGroupStructure();
182 };
183 
184 class ResourceListener  :public ::com::sun::star::util::XModifyListener,
185                          public ::cppu::OWeakObject,
186                          public ::cppu::BaseMutex
187 {
188     public:
189         ResourceListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& xListener );
190         virtual ~ResourceListener();
191 
192         void startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver  >& rResource );
193         void stopListening();
194 
195         // XInterface
196 		virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
197 		virtual void SAL_CALL acquire() throw ();
198 		virtual void SAL_CALL release() throw ();
199 
200         // XModifyListener
201         virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
202 
203         // XEventListener
204         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
205 
206     private:
207         ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver > m_xResource;
208         ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >             m_xListener;
209         bool                                                                                    m_bListening;
210 };
211 
212 typedef ::cppu::AggImplInheritanceHelper2	< UnoControlContainer
213                             ,   ::com::sun::star::container::XContainerListener
214 							,	::com::sun::star::util::XChangesListener
215 							>	ContainerControl_IBase;
216 
217 class ControlContainerBase : public ContainerControl_IBase
218 {
219 protected:
220     bool                                                                        mbSizeModified;
221     bool                                                                        mbPosModified;
222     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController >	mxTabController;
223 	::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > mxListener;
224 
225     void		ImplInsertControl( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxModel, const ::rtl::OUString& rName );
226     void		ImplRemoveControl( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxModel );
227     virtual void		ImplSetPosSize( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& rxCtrl );
228     void        ImplUpdateResourceResolver();
229     void        ImplStartListingForResourceEvents();
230 	::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > Impl_getGraphicFromURL_nothrow( const ::rtl::OUString& _rURL );
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 	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 protected:
257     virtual void ImplModelPropertiesChanged( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyChangeEvent >& rEvents ) throw(::com::sun::star::uno::RuntimeException);
258 	virtual void removingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
259 	virtual void addingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
260 };
261 #endif
262