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 _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
25 #define _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
26 
27 #include "composeduiupdate.hxx"
28 #include "formbrowsertools.hxx"
29 #include "formmetadata.hxx"
30 #include "proplinelistener.hxx"
31 #include "propcontrolobserver.hxx"
32 #include "browserview.hxx"
33 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPCR_HXX_
34 #include "modulepcr.hxx"
35 #endif
36 #include "propertyinfo.hxx"
37 #include "pcrcomponentcontext.hxx"
38 
39 /** === begin UNO includes === **/
40 #include <com/sun/star/awt/XFocusListener.hpp>
41 #include <com/sun/star/beans/XPropertyState.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <com/sun/star/uno/XComponentContext.hpp>
46 #include <com/sun/star/form/XForm.hpp>
47 #include <com/sun/star/script/XEventAttacherManager.hpp>
48 #include <com/sun/star/sdbc/XRowSet.hpp>
49 #include <com/sun/star/uno/Sequence.hxx>
50 #include <com/sun/star/frame/XController.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/lang/XEventListener.hpp>
53 #include <com/sun/star/sdbc/XConnection.hpp>
54 #include <com/sun/star/awt/XLayoutConstrains.hpp>
55 #include <com/sun/star/awt/XLayoutConstrains.hpp>
56 #include <com/sun/star/awt/XControlContainer.hpp>
57 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
58 #include <com/sun/star/inspection/XObjectInspector.hpp>
59 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
60 #include <com/sun/star/inspection/XPropertyHandler.hpp>
61 #include <com/sun/star/lang/XInitialization.hpp>
62 /** === end UNO includes === **/
63 #include <connectivity/dbtools.hxx>
64 #include <cppuhelper/interfacecontainer.hxx>
65 #include <cppuhelper/implbase7.hxx>
66 #include <comphelper/broadcasthelper.hxx>
67 
68 #include <map>
69 #include <hash_map>
70 #include <vector>
71 #include <memory>
72 
73 class SvNumberFormatsSupplierObj;
74 class Font;
75 class Window;
76 class SfxItemSet;
77 
78 //............................................................................
79 namespace pcr
80 {
81 //............................................................................
82 
83 	class OPropertyEditor;
84 	struct OLineDescriptor;
85 
86 #if OSL_DEBUG_LEVEL > 0
87     const char* CheckPropertyBrowserInvariants( const void* pVoid );
88         // for dignostics with DBG_CHKTHIS
89 #endif
90     DBG_NAMEEX( OPropertyBrowserController )
91 
92     //========================================================================
93 	//= OPropertyBrowserController
94 	//========================================================================
95 	// #95343#------------------------------------------------------------------------------------
96 	typedef ::cppu::WeakImplHelper7 <	::com::sun::star::lang::XServiceInfo
97 									,	::com::sun::star::awt::XFocusListener
98 									,	::com::sun::star::awt::XLayoutConstrains
99 									,	::com::sun::star::beans::XPropertyChangeListener
100                                     ,   ::com::sun::star::inspection::XPropertyControlFactory
101                                     ,   ::com::sun::star::inspection::XObjectInspector
102                                     ,   ::com::sun::star::lang::XInitialization
103 									>	OPropertyBrowserController_Base;
104 
105 	class OPropertyBrowserController
106                 :public ::comphelper::OMutexAndBroadcastHelper
107 				,public OPropertyBrowserController_Base
108                 ,public ::com::sun::star::inspection::XObjectInspectorUI
109                     // that's intentionally *not* part of the OPropertyBrowserController_Base
110                     // We do not want this to be available in queryInterface, getTypes, and the like.
111                 ,public IPropertyLineListener
112                 ,public IPropertyControlObserver
113                 ,public IPropertyExistenceCheck
114 	{
115     private:
116         typedef ::std::map< sal_Int32, ::com::sun::star::beans::Property >  OrderedPropertyMap;
117         typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
118                                                                             InterfaceArray;
119 
120     protected:
121 		ComponentContext                                                    m_aContext;
122 
123     private:
124 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
125 		::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >  m_xView;
126 
127 		::cppu::OInterfaceContainerHelper   m_aDisposeListeners;
128         ::cppu::OInterfaceContainerHelper   m_aControlObservers;
129 		// meta data about the properties
130         OPropertyBrowserView*               m_pView;
131 
132 		::rtl::OUString		                m_sPageSelection;
133 		::rtl::OUString		                m_sLastValidPageSelection;
134 
135         typedef ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >
136                                                         PropertyHandlerRef;
137         typedef ::std::vector< PropertyHandlerRef >     PropertyHandlerArray;
138         typedef ::std::hash_map< ::rtl::OUString, PropertyHandlerRef, ::rtl::OUStringHash >
139                                                         PropertyHandlerRepository;
140         typedef ::std::hash_multimap< ::rtl::OUString, PropertyHandlerRef, ::rtl::OUStringHash >
141                                                         PropertyHandlerMultiRepository;
142         PropertyHandlerRepository                       m_aPropertyHandlers;
143         PropertyHandlerMultiRepository                  m_aDependencyHandlers;
144         PropertyHandlerRef                              m_xInteractiveHandler;
145 
146         ::std::auto_ptr< ComposedPropertyUIUpdate >     m_pUIRequestComposer;
147 
148         /// our InspectorModel
149         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >
150                                                         m_xModel;
151         /// the object(s) we're currently inspecting
152         InterfaceArray                                  m_aInspectedObjects;
153 		/// the properties of the currently inspected object(s)
154         OrderedPropertyMap                              m_aProperties;
155         /// the property we're just committing
156         ::rtl::OUString                                 m_sCommittingProperty;
157 
158         typedef ::std::hash_map< ::rtl::OUString, sal_uInt16, ::rtl::OUStringHash >     HashString2Int16;
159         HashString2Int16                                m_aPageIds;
160 
161 		bool        m_bContainerFocusListening;
162         bool        m_bSuspendingPropertyHandlers;
163         bool        m_bConstructed;
164         bool        m_bBindingIntrospectee;
165 
166 	protected:
167         DECLARE_XINTERFACE()
168 
169 		// XServiceInfo
170 		virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
171 		virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
172 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
173 
174 		// XController
175 		virtual void SAL_CALL attachFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) throw(::com::sun::star::uno::RuntimeException);
176 		virtual sal_Bool SAL_CALL attachModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ) throw(::com::sun::star::uno::RuntimeException);
177 		virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) throw(::com::sun::star::uno::RuntimeException);
178 		virtual ::com::sun::star::uno::Any SAL_CALL getViewData(  ) throw(::com::sun::star::uno::RuntimeException);
179 		virtual void SAL_CALL restoreViewData( const ::com::sun::star::uno::Any& Data ) throw(::com::sun::star::uno::RuntimeException);
180 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel(  ) throw(::com::sun::star::uno::RuntimeException);
181 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL getFrame(  ) throw(::com::sun::star::uno::RuntimeException);
182 
183 		// XComponent
184 		virtual void SAL_CALL dispose(  ) throw(::com::sun::star::uno::RuntimeException);
185 		virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
186 		virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
187 
188 		// XFocusListener
189 		virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
190 		virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
191 
192 		// XEventListener
193 	    virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
194 
195 		// XLayoutConstrains #95343# ----------------
196 		virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize(  ) throw (::com::sun::star::uno::RuntimeException);
197 		virtual ::com::sun::star::awt::Size SAL_CALL getPreferredSize(  ) throw (::com::sun::star::uno::RuntimeException);
198 		virtual ::com::sun::star::awt::Size SAL_CALL calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (::com::sun::star::uno::RuntimeException);
199 
200         // XPropertyChangeListener
201         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
202 
203         /** XPropertyControlFactory
204         */
205         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > SAL_CALL createPropertyControl( ::sal_Int16 ControlType, ::sal_Bool CreateReadOnly ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
206 
207     public:
208 		OPropertyBrowserController(
209 			const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
210 
211     protected:
212 		virtual ~OPropertyBrowserController();
213 
214     public:
215 		// XServiceInfo - static versions
216 		static ::rtl::OUString getImplementationName_static(  ) throw(::com::sun::star::uno::RuntimeException);
217 		static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(  ) throw(::com::sun::star::uno::RuntimeException);
218 		static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
219 						Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
220 
221     protected:
222 		// IPropertyLineListener
223         virtual void	Clicked(	const ::rtl::OUString& _rName, sal_Bool _bPrimary );
224         virtual void	Commit(		const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rVal );
225 
226         // IPropertyControlObserver
227         virtual void    focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
228         virtual void    valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
229 
230         // IPropertyExistenceCheck
231         virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& _rName ) throw (::com::sun::star::uno::RuntimeException);
232 
233         // XObjectInspectorUI
234         virtual void SAL_CALL enablePropertyUI( const ::rtl::OUString& _rPropertyName, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
235         virtual void SAL_CALL enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
236         virtual void SAL_CALL rebuildPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
237         virtual void SAL_CALL showPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
238         virtual void SAL_CALL hidePropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
239         virtual void SAL_CALL showCategory( const ::rtl::OUString& _rCategory, ::sal_Bool _bShow ) throw (::com::sun::star::uno::RuntimeException);
240         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > SAL_CALL getPropertyControl( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
241         virtual void SAL_CALL registerControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
242         virtual void SAL_CALL revokeControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
243         virtual void SAL_CALL setHelpSectionText( const ::rtl::OUString& HelpText ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
244 
245         // XObjectInspector
246         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() throw (::com::sun::star::uno::RuntimeException);
247         virtual void SAL_CALL setInspectorModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _inspectormodel ) throw (::com::sun::star::uno::RuntimeException);
248         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() throw (::com::sun::star::uno::RuntimeException);
249         virtual void SAL_CALL inspect( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >& Objects ) throw (::com::sun::star::util::VetoException, ::com::sun::star::uno::RuntimeException);
250 
251         // XDispatchProvider
252         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL queryDispatch( const ::com::sun::star::util::URL& URL, const ::rtl::OUString& TargetFrameName, ::sal_Int32 SearchFlags ) throw (::com::sun::star::uno::RuntimeException);
253         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL queryDispatches( const ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchDescriptor >& Requests ) throw (::com::sun::star::uno::RuntimeException);
254 
255         // XInitialization
256         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
257 
258     private:
259         void UpdateUI();
260 
261 		void startContainerWindowListening();
262 		void stopContainerWindowListening();
263 
264 		// stop the inspection
265 		void stopInspection( bool _bCommitModified );
266 
haveView() const267 		sal_Bool haveView() const { return NULL != m_pView; }
getPropertyBox()268         OPropertyEditor&    getPropertyBox() { return m_pView->getPropertyBox(); }
269 
270 		// does the inspection of the objects as indicated by our model
271 		void doInspection();
272 
273 		// bind the browser to m_xIntrospecteeAsProperty
274         void    impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects );
275 
276         /** retrieves special property handlers for our introspectee
277         */
278         void    getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
279 
280         /** called when a property changed, to broadcast any handlers which might have
281             registered for this property
282 
283             @param _bFirstTimeInit
284                 if set to <FALSE/>, this is a real change in the property value, not just a call
285                 for purposes of initialization.
286         */
287         void    impl_broadcastPropertyChange_nothrow( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rNewValue, const ::com::sun::star::uno::Any& _rOldValue, bool _bFirstTimeInit ) const;
288 
289         /** determines whether the given property is an actuating property, that is, at least one
290             handler expressed interest in changes to this property's value.
291         */
impl_isActuatingProperty_nothrow(const::rtl::OUString & _rPropertyName) const292         inline bool impl_isActuatingProperty_nothrow( const ::rtl::OUString& _rPropertyName ) const
293         {
294             return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
295         }
296 
297 		sal_uInt32      GetPropertyPos(const ::rtl::OUString& _rPropName);
298 
299         /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
300             @param  _rPropertyName
301                 the name whose handler is to be obtained. Must be the name of a property
302                 for which a handler is registered.
303             @throws
304                 RuntimeException if there is no handler for the given property
305             @return
306                 the value of this property
307         */
308         ::com::sun::star::uno::Any
309                         impl_getPropertyValue_throw( const ::rtl::OUString& _rPropertyName );
310 
311         /// calls XPropertyHandler::suspend for all our property handlers
312         sal_Bool    suspendPropertyHandlers_nothrow( sal_Bool _bSuspend );
313 
314         /// suspends the complete inspector
315         sal_Bool    suspendAll_nothrow();
316 
317         /** selects a page according to our current view data
318         */
319         void selectPageFromViewData();
320 
321         /** updates our view data from the currently active page
322         */
323 		void updateViewDataFromActivePage();
324 
325         /// describes the UI for the given property
326         void describePropertyLine( const ::com::sun::star::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor )
327             SAL_THROW((::com::sun::star::uno::Exception));
328 
329         /** retrieves the position of the property given by name in m_aProperties
330             @return
331                 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
332                 not <NULL/> contains the iterator pointing to this property.
333         */
334         bool impl_findObjectProperty_nothrow( const ::rtl::OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = NULL );
335 
336 		sal_Bool Construct(Window* _pParentWin);
337 
338         /** retrieves the property handler for a given property name
339             @param  _rPropertyName
340                 the name whose handler is to be obtained. Must be the name of a property
341                 for which a handler is registered.
342             @throws
343                 RuntimeException if there is no handler for the given property
344             @return
345                 the handler which is responsible for the given property
346         */
347         PropertyHandlerRef
348             impl_getHandlerForProperty_throw( const ::rtl::OUString& _rPropertyName ) const;
349 
350         /** determines whether we have a handler for the given property
351             @param _rPropertyName
352                 the name of the property for which the existence of a handler should be checked
353         */
354         bool
355             impl_hasPropertyHandlerFor_nothrow( const ::rtl::OUString& _rPropertyName ) const;
356 
357         /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
358             respective tab pages into our view
359             @precond
360                 m_aPageIds is empty
361             @throws ::com::sun::star::uno::RuntimeException
362                 if one of the callees of this method throws this exception
363         */
364         void
365             impl_buildCategories_throw();
366 
367         /** retrieves the id of the tab page which represents a given category.
368             @param  _rCategoryName
369                 the programmatic name of a category.
370             @return
371                 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
372                 is no tab page for the given category
373         */
374         sal_uInt16
375             impl_getPageIdForCategory_nothrow( const ::rtl::OUString& _rCategoryName ) const;
376 
377         /** adds or removes ourself as XEventListener to/from all our inspectees
378         */
379         void    impl_toggleInspecteeListening_nothrow( bool _bOn );
380 
381         /** binds the instance to a new model
382         */
383         void    impl_bindToNewModel_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxInspectorModel );
384 
385         /** initializes our view, as indicated by the model's view-relevant properties
386 
387             It's allowed to call this method when no model exists, yet. In this case, nothing
388             happens.
389         */
390         void    impl_initializeView_nothrow();
391 
392         /** determines whether the view should be readonly.
393 
394             Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
395             If there is no model, <FALSE/> is returned.
396 
397             @throws ::com::sun::star::uno::RuntimeException
398                 in case asking the model for its IsReadOnly attribute throws a ::com::sun::star::uno::RuntimeException
399                 itself.
400         */
401         bool    impl_isReadOnlyModel_throw() const;
402 
403         /** updates our view so that it is read-only, as indicated by the model property
404             @see impl_isReadOnlyModel_throw
405         */
406         void    impl_updateReadOnlyView_nothrow();
407 
408         /** starts or stops listening at the model
409         */
410         void    impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
411 
412 	private:
413 		DECL_LINK(OnPageActivation, void*);
414 
415     private:
416         // constructors
417         void    createDefault();
418         void    createWithModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxModel );
419 	};
420 
421 //............................................................................
422 } // namespace pcr
423 //............................................................................
424 
425 #endif // _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
426 
427