merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / extensions / source / propctrlr / propcontroller.hxx
blob6535ce6d3ca8829804bc3836e7b19d9615b67b3e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
30 #define _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
32 #include "composeduiupdate.hxx"
33 #include "formbrowsertools.hxx"
34 #include "formmetadata.hxx"
35 #include "proplinelistener.hxx"
36 #include "propcontrolobserver.hxx"
37 #include "browserview.hxx"
38 #include "modulepcr.hxx"
39 #include "propertyinfo.hxx"
40 #include "pcrcomponentcontext.hxx"
42 /** === begin UNO includes === **/
43 #include <com/sun/star/awt/XFocusListener.hpp>
44 #include <com/sun/star/beans/XPropertyState.hpp>
45 #include <com/sun/star/beans/XPropertySet.hpp>
46 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #include <com/sun/star/uno/XComponentContext.hpp>
49 #include <com/sun/star/form/XForm.hpp>
50 #include <com/sun/star/script/XEventAttacherManager.hpp>
51 #include <com/sun/star/sdbc/XRowSet.hpp>
52 #include <com/sun/star/uno/Sequence.hxx>
53 #include <com/sun/star/frame/XController.hpp>
54 #include <com/sun/star/lang/XServiceInfo.hpp>
55 #include <com/sun/star/lang/XEventListener.hpp>
56 #include <com/sun/star/sdbc/XConnection.hpp>
57 #include <com/sun/star/awt/XLayoutConstrains.hpp>
58 #include <com/sun/star/awt/XLayoutConstrains.hpp>
59 #include <com/sun/star/awt/XControlContainer.hpp>
60 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
61 #include <com/sun/star/inspection/XObjectInspector.hpp>
62 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
63 #include <com/sun/star/inspection/XPropertyHandler.hpp>
64 #include <com/sun/star/lang/XInitialization.hpp>
65 /** === end UNO includes === **/
66 #include <connectivity/dbtools.hxx>
67 #include <cppuhelper/interfacecontainer.hxx>
68 #include <cppuhelper/implbase7.hxx>
69 #include <comphelper/broadcasthelper.hxx>
71 #include <map>
72 #include <hash_map>
73 #include <vector>
74 #include <memory>
76 class SvNumberFormatsSupplierObj;
77 class Font;
78 class Window;
79 class SfxItemSet;
81 //............................................................................
82 namespace pcr
84 //............................................................................
86 class OPropertyEditor;
87 struct OLineDescriptor;
89 #if OSL_DEBUG_LEVEL > 0
90 const char* CheckPropertyBrowserInvariants( const void* pVoid );
91 // for dignostics with DBG_CHKTHIS
92 #endif
93 DBG_NAMEEX( OPropertyBrowserController )
95 //========================================================================
96 //= OPropertyBrowserController
97 //========================================================================
98 // #95343#------------------------------------------------------------------------------------
99 typedef ::cppu::WeakImplHelper7 < ::com::sun::star::lang::XServiceInfo
100 , ::com::sun::star::awt::XFocusListener
101 , ::com::sun::star::awt::XLayoutConstrains
102 , ::com::sun::star::beans::XPropertyChangeListener
103 , ::com::sun::star::inspection::XPropertyControlFactory
104 , ::com::sun::star::inspection::XObjectInspector
105 , ::com::sun::star::lang::XInitialization
106 > OPropertyBrowserController_Base;
108 class OPropertyBrowserController
109 :public ::comphelper::OMutexAndBroadcastHelper
110 ,public OPropertyBrowserController_Base
111 ,public ::com::sun::star::inspection::XObjectInspectorUI
112 // that's intentionally *not* part of the OPropertyBrowserController_Base
113 // We do not want this to be available in queryInterface, getTypes, and the like.
114 ,public IPropertyLineListener
115 ,public IPropertyControlObserver
116 ,public IPropertyExistenceCheck
118 private:
119 typedef ::std::map< sal_Int32, ::com::sun::star::beans::Property > OrderedPropertyMap;
120 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
121 InterfaceArray;
123 protected:
124 ComponentContext m_aContext;
126 private:
127 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
128 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xView;
130 ::cppu::OInterfaceContainerHelper m_aDisposeListeners;
131 ::cppu::OInterfaceContainerHelper m_aControlObservers;
132 // meta data about the properties
133 OPropertyBrowserView* m_pView;
135 ::rtl::OUString m_sPageSelection;
136 ::rtl::OUString m_sLastValidPageSelection;
138 typedef ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >
139 PropertyHandlerRef;
140 typedef ::std::vector< PropertyHandlerRef > PropertyHandlerArray;
141 typedef ::std::hash_map< ::rtl::OUString, PropertyHandlerRef, ::rtl::OUStringHash >
142 PropertyHandlerRepository;
143 typedef ::std::hash_multimap< ::rtl::OUString, PropertyHandlerRef, ::rtl::OUStringHash >
144 PropertyHandlerMultiRepository;
145 PropertyHandlerRepository m_aPropertyHandlers;
146 PropertyHandlerMultiRepository m_aDependencyHandlers;
147 PropertyHandlerRef m_xInteractiveHandler;
149 ::std::auto_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer;
151 /// our InspectorModel
152 ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >
153 m_xModel;
154 /// the object(s) we're currently inspecting
155 InterfaceArray m_aInspectedObjects;
156 /// the properties of the currently inspected object(s)
157 OrderedPropertyMap m_aProperties;
158 /// the property we're just committing
159 ::rtl::OUString m_sCommittingProperty;
161 typedef ::std::hash_map< ::rtl::OUString, sal_uInt16, ::rtl::OUStringHash > HashString2Int16;
162 HashString2Int16 m_aPageIds;
164 bool m_bContainerFocusListening;
165 bool m_bSuspendingPropertyHandlers;
166 bool m_bConstructed;
167 bool m_bBindingIntrospectee;
169 protected:
170 DECLARE_XINTERFACE()
172 // XServiceInfo
173 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
174 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
175 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
177 // XController
178 virtual void SAL_CALL attachFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) throw(::com::sun::star::uno::RuntimeException);
179 virtual sal_Bool SAL_CALL attachModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ) throw(::com::sun::star::uno::RuntimeException);
180 virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) throw(::com::sun::star::uno::RuntimeException);
181 virtual ::com::sun::star::uno::Any SAL_CALL getViewData( ) throw(::com::sun::star::uno::RuntimeException);
182 virtual void SAL_CALL restoreViewData( const ::com::sun::star::uno::Any& Data ) throw(::com::sun::star::uno::RuntimeException);
183 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel( ) throw(::com::sun::star::uno::RuntimeException);
184 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL getFrame( ) throw(::com::sun::star::uno::RuntimeException);
186 // XComponent
187 virtual void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException);
188 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
189 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
191 // XFocusListener
192 virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
193 virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
195 // XEventListener
196 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
198 // XLayoutConstrains #95343# ----------------
199 virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize( ) throw (::com::sun::star::uno::RuntimeException);
200 virtual ::com::sun::star::awt::Size SAL_CALL getPreferredSize( ) throw (::com::sun::star::uno::RuntimeException);
201 virtual ::com::sun::star::awt::Size SAL_CALL calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (::com::sun::star::uno::RuntimeException);
203 // XPropertyChangeListener
204 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
206 /** XPropertyControlFactory
208 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);
210 public:
211 OPropertyBrowserController(
212 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
214 protected:
215 virtual ~OPropertyBrowserController();
217 public:
218 // XServiceInfo - static versions
219 static ::rtl::OUString getImplementationName_static( ) throw(::com::sun::star::uno::RuntimeException);
220 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static( ) throw(::com::sun::star::uno::RuntimeException);
221 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
222 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
224 protected:
225 // IPropertyLineListener
226 virtual void Clicked( const ::rtl::OUString& _rName, sal_Bool _bPrimary );
227 virtual void Commit( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rVal );
229 // IPropertyControlObserver
230 virtual void focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
231 virtual void valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
233 // IPropertyExistenceCheck
234 virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& _rName ) throw (::com::sun::star::uno::RuntimeException);
236 // XObjectInspectorUI
237 virtual void SAL_CALL enablePropertyUI( const ::rtl::OUString& _rPropertyName, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
238 virtual void SAL_CALL enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
239 virtual void SAL_CALL rebuildPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
240 virtual void SAL_CALL showPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
241 virtual void SAL_CALL hidePropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
242 virtual void SAL_CALL showCategory( const ::rtl::OUString& _rCategory, ::sal_Bool _bShow ) throw (::com::sun::star::uno::RuntimeException);
243 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > SAL_CALL getPropertyControl( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
244 virtual void SAL_CALL registerControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
245 virtual void SAL_CALL revokeControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
246 virtual void SAL_CALL setHelpSectionText( const ::rtl::OUString& HelpText ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
248 // XObjectInspector
249 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() throw (::com::sun::star::uno::RuntimeException);
250 virtual void SAL_CALL setInspectorModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _inspectormodel ) throw (::com::sun::star::uno::RuntimeException);
251 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() throw (::com::sun::star::uno::RuntimeException);
252 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);
254 // XDispatchProvider
255 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);
256 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);
258 // XInitialization
259 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);
261 private:
262 void UpdateUI();
264 void startContainerWindowListening();
265 void stopContainerWindowListening();
267 // stop the inspection
268 void stopInspection( bool _bCommitModified );
270 sal_Bool haveView() const { return NULL != m_pView; }
271 OPropertyEditor& getPropertyBox() { return m_pView->getPropertyBox(); }
273 // does the inspection of the objects as indicated by our model
274 void doInspection();
276 // bind the browser to m_xIntrospecteeAsProperty
277 void impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects );
279 /** retrieves special property handlers for our introspectee
281 void getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
283 /** called when a property changed, to broadcast any handlers which might have
284 registered for this property
286 @param _bFirstTimeInit
287 if set to <FALSE/>, this is a real change in the property value, not just a call
288 for purposes of initialization.
290 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;
292 /** determines whether the given property is an actuating property, that is, at least one
293 handler expressed interest in changes to this property's value.
295 inline bool impl_isActuatingProperty_nothrow( const ::rtl::OUString& _rPropertyName ) const
297 return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
300 sal_uInt32 GetPropertyPos(const ::rtl::OUString& _rPropName);
302 /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
303 @param _rPropertyName
304 the name whose handler is to be obtained. Must be the name of a property
305 for which a handler is registered.
306 @throws
307 RuntimeException if there is no handler for the given property
308 @return
309 the value of this property
311 ::com::sun::star::uno::Any
312 impl_getPropertyValue_throw( const ::rtl::OUString& _rPropertyName );
314 /// calls XPropertyHandler::suspend for all our property handlers
315 sal_Bool suspendPropertyHandlers_nothrow( sal_Bool _bSuspend );
317 /// suspends the complete inspector
318 sal_Bool suspendAll_nothrow();
320 /** selects a page according to our current view data
322 void selectPageFromViewData();
324 /** updates our view data from the currently active page
326 void updateViewDataFromActivePage();
328 /// describes the UI for the given property
329 void describePropertyLine( const ::com::sun::star::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor )
330 SAL_THROW((::com::sun::star::uno::Exception));
332 /** retrieves the position of the property given by name in m_aProperties
333 @return
334 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
335 not <NULL/> contains the iterator pointing to this property.
337 bool impl_findObjectProperty_nothrow( const ::rtl::OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = NULL );
339 sal_Bool Construct(Window* _pParentWin);
341 /** retrieves the property handler for a given property name
342 @param _rPropertyName
343 the name whose handler is to be obtained. Must be the name of a property
344 for which a handler is registered.
345 @throws
346 RuntimeException if there is no handler for the given property
347 @return
348 the handler which is responsible for the given property
350 PropertyHandlerRef
351 impl_getHandlerForProperty_throw( const ::rtl::OUString& _rPropertyName ) const;
353 /** determines whether we have a handler for the given property
354 @param _rPropertyName
355 the name of the property for which the existence of a handler should be checked
357 bool
358 impl_hasPropertyHandlerFor_nothrow( const ::rtl::OUString& _rPropertyName ) const;
360 /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
361 respective tab pages into our view
362 @precond
363 m_aPageIds is empty
364 @throws ::com::sun::star::uno::RuntimeException
365 if one of the callees of this method throws this exception
367 void
368 impl_buildCategories_throw();
370 /** retrieves the id of the tab page which represents a given category.
371 @param _rCategoryName
372 the programmatic name of a category.
373 @return
374 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
375 is no tab page for the given category
377 sal_uInt16
378 impl_getPageIdForCategory_nothrow( const ::rtl::OUString& _rCategoryName ) const;
380 /** adds or removes ourself as XEventListener to/from all our inspectees
382 void impl_toggleInspecteeListening_nothrow( bool _bOn );
384 /** binds the instance to a new model
386 void impl_bindToNewModel_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxInspectorModel );
388 /** initializes our view, as indicated by the model's view-relevant properties
390 It's allowed to call this method when no model exists, yet. In this case, nothing
391 happens.
393 void impl_initializeView_nothrow();
395 /** determines whether the view should be readonly.
397 Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
398 If there is no model, <FALSE/> is returned.
400 @throws ::com::sun::star::uno::RuntimeException
401 in case asking the model for its IsReadOnly attribute throws a ::com::sun::star::uno::RuntimeException
402 itself.
404 bool impl_isReadOnlyModel_throw() const;
406 /** updates our view so that it is read-only, as indicated by the model property
407 @see impl_isReadOnlyModel_throw
409 void impl_updateReadOnlyView_nothrow();
411 /** starts or stops listening at the model
413 void impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
415 private:
416 DECL_LINK(OnPageActivation, void*);
418 private:
419 // constructors
420 void createDefault();
421 void createWithModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxModel );
424 //............................................................................
425 } // namespace pcr
426 //............................................................................
428 #endif // _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */