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