update credits
[LibreOffice.git] / extensions / source / propctrlr / propcontroller.hxx
blob0aaf5356b834b88d3402cb9b7a4696e460792528
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
21 #define _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
23 #include "composeduiupdate.hxx"
24 #include "formbrowsertools.hxx"
25 #include "formmetadata.hxx"
26 #include "proplinelistener.hxx"
27 #include "propcontrolobserver.hxx"
28 #include "browserview.hxx"
29 #include "modulepcr.hxx"
30 #include "propertyinfo.hxx"
31 #include "pcrcomponentcontext.hxx"
33 #include <com/sun/star/awt/XFocusListener.hpp>
34 #include <com/sun/star/beans/XPropertyState.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/form/XForm.hpp>
40 #include <com/sun/star/script/XEventAttacherManager.hpp>
41 #include <com/sun/star/sdbc/XRowSet.hpp>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/frame/XController.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/lang/XEventListener.hpp>
46 #include <com/sun/star/sdbc/XConnection.hpp>
47 #include <com/sun/star/awt/XLayoutConstrains.hpp>
48 #include <com/sun/star/awt/XControlContainer.hpp>
49 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
50 #include <com/sun/star/inspection/XObjectInspector.hpp>
51 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
52 #include <com/sun/star/inspection/XPropertyHandler.hpp>
53 #include <com/sun/star/lang/XInitialization.hpp>
54 #include <connectivity/dbtools.hxx>
55 #include <cppuhelper/interfacecontainer.hxx>
56 #include <cppuhelper/implbase7.hxx>
57 #include <comphelper/broadcasthelper.hxx>
59 #include <map>
60 #include <boost/unordered_map.hpp>
61 #include <vector>
62 #include <memory>
64 class Window;
66 //............................................................................
67 namespace pcr
69 //............................................................................
71 class OPropertyEditor;
72 struct OLineDescriptor;
74 #if OSL_DEBUG_LEVEL > 0
75 const char* CheckPropertyBrowserInvariants( const void* pVoid );
76 // for dignostics with DBG_CHKTHIS
77 #endif
78 DBG_NAMEEX( OPropertyBrowserController )
80 //========================================================================
81 //= OPropertyBrowserController
82 //========================================================================
83 // #95343#------------------------------------------------------------------------------------
84 typedef ::cppu::WeakImplHelper7 < ::com::sun::star::lang::XServiceInfo
85 , ::com::sun::star::awt::XFocusListener
86 , ::com::sun::star::awt::XLayoutConstrains
87 , ::com::sun::star::beans::XPropertyChangeListener
88 , ::com::sun::star::inspection::XPropertyControlFactory
89 , ::com::sun::star::inspection::XObjectInspector
90 , ::com::sun::star::lang::XInitialization
91 > OPropertyBrowserController_Base;
93 class OPropertyBrowserController
94 :public ::comphelper::OMutexAndBroadcastHelper
95 ,public OPropertyBrowserController_Base
96 ,public ::com::sun::star::inspection::XObjectInspectorUI
97 // that's intentionally *not* part of the OPropertyBrowserController_Base
98 // We do not want this to be available in queryInterface, getTypes, and the like.
99 ,public IPropertyLineListener
100 ,public IPropertyControlObserver
101 ,public IPropertyExistenceCheck
103 private:
104 typedef ::std::multimap< sal_Int32, ::com::sun::star::beans::Property > OrderedPropertyMap;
105 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
106 InterfaceArray;
108 protected:
109 ComponentContext m_aContext;
111 private:
112 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
113 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xView;
115 ::cppu::OInterfaceContainerHelper m_aDisposeListeners;
116 ::cppu::OInterfaceContainerHelper m_aControlObservers;
117 // meta data about the properties
118 OPropertyBrowserView* m_pView;
120 OUString m_sPageSelection;
121 OUString m_sLastValidPageSelection;
123 typedef ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >
124 PropertyHandlerRef;
125 typedef ::std::vector< PropertyHandlerRef > PropertyHandlerArray;
126 typedef ::boost::unordered_map< OUString, PropertyHandlerRef, OUStringHash >
127 PropertyHandlerRepository;
128 typedef ::boost::unordered_multimap< OUString, PropertyHandlerRef, OUStringHash >
129 PropertyHandlerMultiRepository;
130 PropertyHandlerRepository m_aPropertyHandlers;
131 PropertyHandlerMultiRepository m_aDependencyHandlers;
132 PropertyHandlerRef m_xInteractiveHandler;
134 ::std::auto_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer;
136 /// our InspectorModel
137 ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >
138 m_xModel;
139 /// the object(s) we're currently inspecting
140 InterfaceArray m_aInspectedObjects;
141 /// the properties of the currently inspected object(s)
142 OrderedPropertyMap m_aProperties;
143 /// the property we're just committing
144 OUString m_sCommittingProperty;
146 typedef ::boost::unordered_map< OUString, sal_uInt16, OUStringHash > HashString2Int16;
147 HashString2Int16 m_aPageIds;
149 bool m_bContainerFocusListening;
150 bool m_bSuspendingPropertyHandlers;
151 bool m_bConstructed;
152 bool m_bBindingIntrospectee;
154 protected:
155 DECLARE_XINTERFACE()
157 // XServiceInfo
158 virtual OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
159 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
160 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
162 // XController
163 virtual void SAL_CALL attachFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) throw(::com::sun::star::uno::RuntimeException);
164 virtual sal_Bool SAL_CALL attachModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ) throw(::com::sun::star::uno::RuntimeException);
165 virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) throw(::com::sun::star::uno::RuntimeException);
166 virtual ::com::sun::star::uno::Any SAL_CALL getViewData( ) throw(::com::sun::star::uno::RuntimeException);
167 virtual void SAL_CALL restoreViewData( const ::com::sun::star::uno::Any& Data ) throw(::com::sun::star::uno::RuntimeException);
168 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel( ) throw(::com::sun::star::uno::RuntimeException);
169 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL getFrame( ) throw(::com::sun::star::uno::RuntimeException);
171 // XComponent
172 virtual void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException);
173 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
174 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
176 // XFocusListener
177 virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
178 virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
180 // XEventListener
181 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
183 // XLayoutConstrains #95343# ----------------
184 virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize( ) throw (::com::sun::star::uno::RuntimeException);
185 virtual ::com::sun::star::awt::Size SAL_CALL getPreferredSize( ) throw (::com::sun::star::uno::RuntimeException);
186 virtual ::com::sun::star::awt::Size SAL_CALL calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (::com::sun::star::uno::RuntimeException);
188 // XPropertyChangeListener
189 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
191 /** XPropertyControlFactory
193 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);
195 public:
196 OPropertyBrowserController(
197 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
199 protected:
200 virtual ~OPropertyBrowserController();
202 public:
203 // XServiceInfo - static versions
204 static OUString getImplementationName_static( ) throw(::com::sun::star::uno::RuntimeException);
205 static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_static( ) throw(::com::sun::star::uno::RuntimeException);
206 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
207 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
209 protected:
210 // IPropertyLineListener
211 virtual void Clicked( const OUString& _rName, sal_Bool _bPrimary );
212 virtual void Commit( const OUString& _rName, const ::com::sun::star::uno::Any& _rVal );
214 // IPropertyControlObserver
215 virtual void focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
216 virtual void valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
218 // IPropertyExistenceCheck
219 virtual ::sal_Bool SAL_CALL hasPropertyByName( const OUString& _rName ) throw (::com::sun::star::uno::RuntimeException);
221 // XObjectInspectorUI
222 virtual void SAL_CALL enablePropertyUI( const OUString& _rPropertyName, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
223 virtual void SAL_CALL enablePropertyUIElements( const OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
224 virtual void SAL_CALL rebuildPropertyUI( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
225 virtual void SAL_CALL showPropertyUI( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
226 virtual void SAL_CALL hidePropertyUI( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
227 virtual void SAL_CALL showCategory( const OUString& _rCategory, ::sal_Bool _bShow ) throw (::com::sun::star::uno::RuntimeException);
228 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > SAL_CALL getPropertyControl( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
229 virtual void SAL_CALL registerControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
230 virtual void SAL_CALL revokeControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
231 virtual void SAL_CALL setHelpSectionText( const OUString& HelpText ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
233 // XObjectInspector
234 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() throw (::com::sun::star::uno::RuntimeException);
235 virtual void SAL_CALL setInspectorModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _inspectormodel ) throw (::com::sun::star::uno::RuntimeException);
236 virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() throw (::com::sun::star::uno::RuntimeException);
237 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);
239 // XDispatchProvider
240 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL queryDispatch( const ::com::sun::star::util::URL& URL, const OUString& TargetFrameName, ::sal_Int32 SearchFlags ) throw (::com::sun::star::uno::RuntimeException);
241 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);
243 // XInitialization
244 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);
246 private:
247 void UpdateUI();
249 void startContainerWindowListening();
250 void stopContainerWindowListening();
252 // stop the inspection
253 void stopInspection( bool _bCommitModified );
255 sal_Bool haveView() const { return NULL != m_pView; }
256 OPropertyEditor& getPropertyBox() { return m_pView->getPropertyBox(); }
258 // does the inspection of the objects as indicated by our model
259 void doInspection();
261 // bind the browser to m_xIntrospecteeAsProperty
262 void impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects );
264 /** retrieves special property handlers for our introspectee
266 void getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
268 /** called when a property changed, to broadcast any handlers which might have
269 registered for this property
271 @param _bFirstTimeInit
272 if set to <FALSE/>, this is a real change in the property value, not just a call
273 for purposes of initialization.
275 void impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rNewValue, const ::com::sun::star::uno::Any& _rOldValue, bool _bFirstTimeInit ) const;
277 /** determines whether the given property is an actuating property, that is, at least one
278 handler expressed interest in changes to this property's value.
280 inline bool impl_isActuatingProperty_nothrow( const OUString& _rPropertyName ) const
282 return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
285 sal_uInt32 GetPropertyPos(const OUString& _rPropName);
287 /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
288 @param _rPropertyName
289 the name whose handler is to be obtained. Must be the name of a property
290 for which a handler is registered.
291 @throws
292 RuntimeException if there is no handler for the given property
293 @return
294 the value of this property
296 ::com::sun::star::uno::Any
297 impl_getPropertyValue_throw( const OUString& _rPropertyName );
299 /// calls XPropertyHandler::suspend for all our property handlers
300 sal_Bool suspendPropertyHandlers_nothrow( sal_Bool _bSuspend );
302 /// suspends the complete inspector
303 sal_Bool suspendAll_nothrow();
305 /** selects a page according to our current view data
307 void selectPageFromViewData();
309 /** updates our view data from the currently active page
311 void updateViewDataFromActivePage();
313 /// describes the UI for the given property
314 void describePropertyLine( const ::com::sun::star::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor )
315 SAL_THROW((::com::sun::star::uno::Exception));
317 /** retrieves the position of the property given by name in m_aProperties
318 @return
319 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
320 not <NULL/> contains the iterator pointing to this property.
322 bool impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = NULL );
324 sal_Bool Construct(Window* _pParentWin);
326 /** retrieves the property handler for a given property name
327 @param _rPropertyName
328 the name whose handler is to be obtained. Must be the name of a property
329 for which a handler is registered.
330 @throws
331 RuntimeException if there is no handler for the given property
332 @return
333 the handler which is responsible for the given property
335 PropertyHandlerRef
336 impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const;
338 /** determines whether we have a handler for the given property
339 @param _rPropertyName
340 the name of the property for which the existence of a handler should be checked
342 bool
343 impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const;
345 /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
346 respective tab pages into our view
347 @precond
348 m_aPageIds is empty
349 @throws ::com::sun::star::uno::RuntimeException
350 if one of the callees of this method throws this exception
352 void
353 impl_buildCategories_throw();
355 /** retrieves the id of the tab page which represents a given category.
356 @param _rCategoryName
357 the programmatic name of a category.
358 @return
359 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
360 is no tab page for the given category
362 sal_uInt16
363 impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const;
365 /** adds or removes ourself as XEventListener to/from all our inspectees
367 void impl_toggleInspecteeListening_nothrow( bool _bOn );
369 /** binds the instance to a new model
371 void impl_bindToNewModel_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxInspectorModel );
373 /** initializes our view, as indicated by the model's view-relevant properties
375 It's allowed to call this method when no model exists, yet. In this case, nothing
376 happens.
378 void impl_initializeView_nothrow();
380 /** determines whether the view should be readonly.
382 Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
383 If there is no model, <FALSE/> is returned.
385 @throws ::com::sun::star::uno::RuntimeException
386 in case asking the model for its IsReadOnly attribute throws a ::com::sun::star::uno::RuntimeException
387 itself.
389 bool impl_isReadOnlyModel_throw() const;
391 /** updates our view so that it is read-only, as indicated by the model property
392 @see impl_isReadOnlyModel_throw
394 void impl_updateReadOnlyView_nothrow();
396 /** starts or stops listening at the model
398 void impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
400 private:
401 DECL_LINK(OnPageActivation, void*);
403 private:
404 // constructors
405 void createDefault();
406 void createWithModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxModel );
409 //............................................................................
410 } // namespace pcr
411 //............................................................................
413 #endif // _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */