xref: /trunk/main/extensions/source/propctrlr/propcontroller.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 diagnostics 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(  );
171         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
172         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  );
173 
174         // XController
175         virtual void SAL_CALL attachFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame );
176         virtual sal_Bool SAL_CALL attachModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel );
177         virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend );
178         virtual ::com::sun::star::uno::Any SAL_CALL getViewData(  );
179         virtual void SAL_CALL restoreViewData( const ::com::sun::star::uno::Any& Data );
180         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel(  );
181         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL getFrame(  );
182 
183         // XComponent
184         virtual void SAL_CALL dispose(  );
185         virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener );
186         virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener );
187 
188         // XFocusListener
189         virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& _rSource );
190         virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& _rSource );
191 
192         // XEventListener
193         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source );
194 
195         // XLayoutConstrains #95343# ----------------
196         virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize(  );
197         virtual ::com::sun::star::awt::Size SAL_CALL getPreferredSize(  );
198         virtual ::com::sun::star::awt::Size SAL_CALL calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize );
199 
200         // XPropertyChangeListener
201         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent );
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 );
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(  );
217         static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(  );
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 );
232 
233         // XObjectInspectorUI
234         virtual void SAL_CALL enablePropertyUI( const ::rtl::OUString& _rPropertyName, ::sal_Bool _bEnable );
235         virtual void SAL_CALL enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable );
236         virtual void SAL_CALL rebuildPropertyUI( const ::rtl::OUString& _rPropertyName );
237         virtual void SAL_CALL showPropertyUI( const ::rtl::OUString& _rPropertyName );
238         virtual void SAL_CALL hidePropertyUI( const ::rtl::OUString& _rPropertyName );
239         virtual void SAL_CALL showCategory( const ::rtl::OUString& _rCategory, ::sal_Bool _bShow );
240         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > SAL_CALL getPropertyControl( const ::rtl::OUString& _rPropertyName );
241         virtual void SAL_CALL registerControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer );
242         virtual void SAL_CALL revokeControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer );
243         virtual void SAL_CALL setHelpSectionText( const ::rtl::OUString& HelpText );
244 
245         // XObjectInspector
246         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel();
247         virtual void SAL_CALL setInspectorModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _inspectormodel );
248         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI();
249         virtual void SAL_CALL inspect( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >& Objects );
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 );
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 );
254 
255         // XInitialization
256         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments );
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 
328         /** retrieves the position of the property given by name in m_aProperties
329             @return
330                 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
331                 not <NULL/> contains the iterator pointing to this property.
332         */
333         bool impl_findObjectProperty_nothrow( const ::rtl::OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = NULL );
334 
335         sal_Bool Construct(Window* _pParentWin);
336 
337         /** retrieves the property handler for a given property name
338             @param  _rPropertyName
339                 the name whose handler is to be obtained. Must be the name of a property
340                 for which a handler is registered.
341             @throws
342                 RuntimeException if there is no handler for the given property
343             @return
344                 the handler which is responsible for the given property
345         */
346         PropertyHandlerRef
347             impl_getHandlerForProperty_throw( const ::rtl::OUString& _rPropertyName ) const;
348 
349         /** determines whether we have a handler for the given property
350             @param _rPropertyName
351                 the name of the property for which the existence of a handler should be checked
352         */
353         bool
354             impl_hasPropertyHandlerFor_nothrow( const ::rtl::OUString& _rPropertyName ) const;
355 
356         /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
357             respective tab pages into our view
358             @precond
359                 m_aPageIds is empty
360             @throws ::com::sun::star::uno::RuntimeException
361                 if one of the callees of this method throws this exception
362         */
363         void
364             impl_buildCategories_throw();
365 
366         /** retrieves the id of the tab page which represents a given category.
367             @param  _rCategoryName
368                 the programmatic name of a category.
369             @return
370                 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
371                 is no tab page for the given category
372         */
373         sal_uInt16
374             impl_getPageIdForCategory_nothrow( const ::rtl::OUString& _rCategoryName ) const;
375 
376         /** adds or removes ourself as XEventListener to/from all our inspectees
377         */
378         void    impl_toggleInspecteeListening_nothrow( bool _bOn );
379 
380         /** binds the instance to a new model
381         */
382         void    impl_bindToNewModel_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxInspectorModel );
383 
384         /** initializes our view, as indicated by the model's view-relevant properties
385 
386             It's allowed to call this method when no model exists, yet. In this case, nothing
387             happens.
388         */
389         void    impl_initializeView_nothrow();
390 
391         /** determines whether the view should be readonly.
392 
393             Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
394             If there is no model, <FALSE/> is returned.
395 
396             @throws ::com::sun::star::uno::RuntimeException
397                 in case asking the model for its IsReadOnly attribute throws a ::com::sun::star::uno::RuntimeException
398                 itself.
399         */
400         bool    impl_isReadOnlyModel_throw() const;
401 
402         /** updates our view so that it is read-only, as indicated by the model property
403             @see impl_isReadOnlyModel_throw
404         */
405         void    impl_updateReadOnlyView_nothrow();
406 
407         /** starts or stops listening at the model
408         */
409         void    impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
410 
411     private:
412         DECL_LINK(OnPageActivation, void*);
413 
414     private:
415         // constructors
416         void    createDefault();
417         void    createWithModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxModel );
418     };
419 
420 //............................................................................
421 } // namespace pcr
422 //............................................................................
423 
424 #endif // _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
425