Bump for 3.6-28
[LibreOffice.git] / extensions / source / propctrlr / propcontroller.hxx
blob70bcba95ad90a54d79f0bc05c3f7eb4c040517f0
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/XControlContainer.hpp>
59 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
60 #include <com/sun/star/inspection/XObjectInspector.hpp>
61 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
62 #include <com/sun/star/inspection/XPropertyHandler.hpp>
63 #include <com/sun/star/lang/XInitialization.hpp>
64 /** === end UNO includes === **/
65 #include <connectivity/dbtools.hxx>
66 #include <cppuhelper/interfacecontainer.hxx>
67 #include <cppuhelper/implbase7.hxx>
68 #include <comphelper/broadcasthelper.hxx>
70 #include <map>
71 #include <boost/unordered_map.hpp>
72 #include <vector>
73 #include <memory>
75 class SvNumberFormatsSupplierObj;
76 class Font;
77 class Window;
78 class SfxItemSet;
80 //............................................................................
81 namespace pcr
83 //............................................................................
85 class OPropertyEditor;
86 struct OLineDescriptor;
88 #if OSL_DEBUG_LEVEL > 0
89 const char* CheckPropertyBrowserInvariants( const void* pVoid );
90 // for dignostics with DBG_CHKTHIS
91 #endif
92 DBG_NAMEEX( OPropertyBrowserController )
94 //========================================================================
95 //= OPropertyBrowserController
96 //========================================================================
97 // #95343#------------------------------------------------------------------------------------
98 typedef ::cppu::WeakImplHelper7 < ::com::sun::star::lang::XServiceInfo
99 , ::com::sun::star::awt::XFocusListener
100 , ::com::sun::star::awt::XLayoutConstrains
101 , ::com::sun::star::beans::XPropertyChangeListener
102 , ::com::sun::star::inspection::XPropertyControlFactory
103 , ::com::sun::star::inspection::XObjectInspector
104 , ::com::sun::star::lang::XInitialization
105 > OPropertyBrowserController_Base;
107 class OPropertyBrowserController
108 :public ::comphelper::OMutexAndBroadcastHelper
109 ,public OPropertyBrowserController_Base
110 ,public ::com::sun::star::inspection::XObjectInspectorUI
111 // that's intentionally *not* part of the OPropertyBrowserController_Base
112 // We do not want this to be available in queryInterface, getTypes, and the like.
113 ,public IPropertyLineListener
114 ,public IPropertyControlObserver
115 ,public IPropertyExistenceCheck
117 private:
118 typedef ::std::map< sal_Int32, ::com::sun::star::beans::Property > OrderedPropertyMap;
119 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
120 InterfaceArray;
122 protected:
123 ComponentContext m_aContext;
125 private:
126 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
127 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xView;
129 ::cppu::OInterfaceContainerHelper m_aDisposeListeners;
130 ::cppu::OInterfaceContainerHelper m_aControlObservers;
131 // meta data about the properties
132 OPropertyBrowserView* m_pView;
134 ::rtl::OUString m_sPageSelection;
135 ::rtl::OUString m_sLastValidPageSelection;
137 typedef ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >
138 PropertyHandlerRef;
139 typedef ::std::vector< PropertyHandlerRef > PropertyHandlerArray;
140 typedef ::boost::unordered_map< ::rtl::OUString, PropertyHandlerRef, ::rtl::OUStringHash >
141 PropertyHandlerRepository;
142 typedef ::boost::unordered_multimap< ::rtl::OUString, PropertyHandlerRef, ::rtl::OUStringHash >
143 PropertyHandlerMultiRepository;
144 PropertyHandlerRepository m_aPropertyHandlers;
145 PropertyHandlerMultiRepository m_aDependencyHandlers;
146 PropertyHandlerRef m_xInteractiveHandler;
148 ::std::auto_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer;
150 /// our InspectorModel
151 ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >
152 m_xModel;
153 /// the object(s) we're currently inspecting
154 InterfaceArray m_aInspectedObjects;
155 /// the properties of the currently inspected object(s)
156 OrderedPropertyMap m_aProperties;
157 /// the property we're just committing
158 ::rtl::OUString m_sCommittingProperty;
160 typedef ::boost::unordered_map< ::rtl::OUString, sal_uInt16, ::rtl::OUStringHash > HashString2Int16;
161 HashString2Int16 m_aPageIds;
163 bool m_bContainerFocusListening;
164 bool m_bSuspendingPropertyHandlers;
165 bool m_bConstructed;
166 bool m_bBindingIntrospectee;
168 protected:
169 DECLARE_XINTERFACE()
171 // XServiceInfo
172 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
173 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
174 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
176 // XController
177 virtual void SAL_CALL attachFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) throw(::com::sun::star::uno::RuntimeException);
178 virtual sal_Bool SAL_CALL attachModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ) throw(::com::sun::star::uno::RuntimeException);
179 virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) throw(::com::sun::star::uno::RuntimeException);
180 virtual ::com::sun::star::uno::Any SAL_CALL getViewData( ) throw(::com::sun::star::uno::RuntimeException);
181 virtual void SAL_CALL restoreViewData( const ::com::sun::star::uno::Any& Data ) throw(::com::sun::star::uno::RuntimeException);
182 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel( ) throw(::com::sun::star::uno::RuntimeException);
183 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL getFrame( ) throw(::com::sun::star::uno::RuntimeException);
185 // XComponent
186 virtual void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException);
187 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
188 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
190 // XFocusListener
191 virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
192 virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
194 // XEventListener
195 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
197 // XLayoutConstrains #95343# ----------------
198 virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize( ) throw (::com::sun::star::uno::RuntimeException);
199 virtual ::com::sun::star::awt::Size SAL_CALL getPreferredSize( ) throw (::com::sun::star::uno::RuntimeException);
200 virtual ::com::sun::star::awt::Size SAL_CALL calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (::com::sun::star::uno::RuntimeException);
202 // XPropertyChangeListener
203 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
205 /** XPropertyControlFactory
207 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);
209 public:
210 OPropertyBrowserController(
211 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
213 protected:
214 virtual ~OPropertyBrowserController();
216 public:
217 // XServiceInfo - static versions
218 static ::rtl::OUString getImplementationName_static( ) throw(::com::sun::star::uno::RuntimeException);
219 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static( ) throw(::com::sun::star::uno::RuntimeException);
220 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
221 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
223 protected:
224 // IPropertyLineListener
225 virtual void Clicked( const ::rtl::OUString& _rName, sal_Bool _bPrimary );
226 virtual void Commit( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rVal );
228 // IPropertyControlObserver
229 virtual void focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
230 virtual void valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
232 // IPropertyExistenceCheck
233 virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& _rName ) throw (::com::sun::star::uno::RuntimeException);
235 // XObjectInspectorUI
236 virtual void SAL_CALL enablePropertyUI( const ::rtl::OUString& _rPropertyName, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
237 virtual void SAL_CALL enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
238 virtual void SAL_CALL rebuildPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
239 virtual void SAL_CALL showPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
240 virtual void SAL_CALL hidePropertyUI( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
241 virtual void SAL_CALL showCategory( const ::rtl::OUString& _rCategory, ::sal_Bool _bShow ) throw (::com::sun::star::uno::RuntimeException);
242 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > SAL_CALL getPropertyControl( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
243 virtual void SAL_CALL registerControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
244 virtual void SAL_CALL revokeControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
245 virtual void SAL_CALL setHelpSectionText( const ::rtl::OUString& HelpText ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
247 // XObjectInspector
248 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() throw (::com::sun::star::uno::RuntimeException);
249 virtual void SAL_CALL setInspectorModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _inspectormodel ) throw (::com::sun::star::uno::RuntimeException);
250 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() throw (::com::sun::star::uno::RuntimeException);
251 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);
253 // XDispatchProvider
254 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);
255 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);
257 // XInitialization
258 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);
260 private:
261 void UpdateUI();
263 void startContainerWindowListening();
264 void stopContainerWindowListening();
266 // stop the inspection
267 void stopInspection( bool _bCommitModified );
269 sal_Bool haveView() const { return NULL != m_pView; }
270 OPropertyEditor& getPropertyBox() { return m_pView->getPropertyBox(); }
272 // does the inspection of the objects as indicated by our model
273 void doInspection();
275 // bind the browser to m_xIntrospecteeAsProperty
276 void impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects );
278 /** retrieves special property handlers for our introspectee
280 void getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
282 /** called when a property changed, to broadcast any handlers which might have
283 registered for this property
285 @param _bFirstTimeInit
286 if set to <FALSE/>, this is a real change in the property value, not just a call
287 for purposes of initialization.
289 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;
291 /** determines whether the given property is an actuating property, that is, at least one
292 handler expressed interest in changes to this property's value.
294 inline bool impl_isActuatingProperty_nothrow( const ::rtl::OUString& _rPropertyName ) const
296 return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
299 sal_uInt32 GetPropertyPos(const ::rtl::OUString& _rPropName);
301 /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
302 @param _rPropertyName
303 the name whose handler is to be obtained. Must be the name of a property
304 for which a handler is registered.
305 @throws
306 RuntimeException if there is no handler for the given property
307 @return
308 the value of this property
310 ::com::sun::star::uno::Any
311 impl_getPropertyValue_throw( const ::rtl::OUString& _rPropertyName );
313 /// calls XPropertyHandler::suspend for all our property handlers
314 sal_Bool suspendPropertyHandlers_nothrow( sal_Bool _bSuspend );
316 /// suspends the complete inspector
317 sal_Bool suspendAll_nothrow();
319 /** selects a page according to our current view data
321 void selectPageFromViewData();
323 /** updates our view data from the currently active page
325 void updateViewDataFromActivePage();
327 /// describes the UI for the given property
328 void describePropertyLine( const ::com::sun::star::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor )
329 SAL_THROW((::com::sun::star::uno::Exception));
331 /** retrieves the position of the property given by name in m_aProperties
332 @return
333 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
334 not <NULL/> contains the iterator pointing to this property.
336 bool impl_findObjectProperty_nothrow( const ::rtl::OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = NULL );
338 sal_Bool Construct(Window* _pParentWin);
340 /** retrieves the property handler for a given property name
341 @param _rPropertyName
342 the name whose handler is to be obtained. Must be the name of a property
343 for which a handler is registered.
344 @throws
345 RuntimeException if there is no handler for the given property
346 @return
347 the handler which is responsible for the given property
349 PropertyHandlerRef
350 impl_getHandlerForProperty_throw( const ::rtl::OUString& _rPropertyName ) const;
352 /** determines whether we have a handler for the given property
353 @param _rPropertyName
354 the name of the property for which the existence of a handler should be checked
356 bool
357 impl_hasPropertyHandlerFor_nothrow( const ::rtl::OUString& _rPropertyName ) const;
359 /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
360 respective tab pages into our view
361 @precond
362 m_aPageIds is empty
363 @throws ::com::sun::star::uno::RuntimeException
364 if one of the callees of this method throws this exception
366 void
367 impl_buildCategories_throw();
369 /** retrieves the id of the tab page which represents a given category.
370 @param _rCategoryName
371 the programmatic name of a category.
372 @return
373 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
374 is no tab page for the given category
376 sal_uInt16
377 impl_getPageIdForCategory_nothrow( const ::rtl::OUString& _rCategoryName ) const;
379 /** adds or removes ourself as XEventListener to/from all our inspectees
381 void impl_toggleInspecteeListening_nothrow( bool _bOn );
383 /** binds the instance to a new model
385 void impl_bindToNewModel_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxInspectorModel );
387 /** initializes our view, as indicated by the model's view-relevant properties
389 It's allowed to call this method when no model exists, yet. In this case, nothing
390 happens.
392 void impl_initializeView_nothrow();
394 /** determines whether the view should be readonly.
396 Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
397 If there is no model, <FALSE/> is returned.
399 @throws ::com::sun::star::uno::RuntimeException
400 in case asking the model for its IsReadOnly attribute throws a ::com::sun::star::uno::RuntimeException
401 itself.
403 bool impl_isReadOnlyModel_throw() const;
405 /** updates our view so that it is read-only, as indicated by the model property
406 @see impl_isReadOnlyModel_throw
408 void impl_updateReadOnlyView_nothrow();
410 /** starts or stops listening at the model
412 void impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
414 private:
415 DECL_LINK(OnPageActivation, void*);
417 private:
418 // constructors
419 void createDefault();
420 void createWithModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxModel );
423 //............................................................................
424 } // namespace pcr
425 //............................................................................
427 #endif // _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */