1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_PROPCONTROLLER_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_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"
32 #include <com/sun/star/awt/XFocusListener.hpp>
33 #include <com/sun/star/beans/XPropertyState.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/form/XForm.hpp>
39 #include <com/sun/star/script/XEventAttacherManager.hpp>
40 #include <com/sun/star/sdbc/XRowSet.hpp>
41 #include <com/sun/star/uno/Sequence.hxx>
42 #include <com/sun/star/frame/XController.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/lang/XEventListener.hpp>
45 #include <com/sun/star/sdbc/XConnection.hpp>
46 #include <com/sun/star/awt/XLayoutConstrains.hpp>
47 #include <com/sun/star/awt/XControlContainer.hpp>
48 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
49 #include <com/sun/star/inspection/XObjectInspector.hpp>
50 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
51 #include <com/sun/star/inspection/XPropertyHandler.hpp>
52 #include <com/sun/star/lang/XInitialization.hpp>
53 #include <connectivity/dbtools.hxx>
54 #include <cppuhelper/interfacecontainer.hxx>
55 #include <cppuhelper/implbase7.hxx>
56 #include <comphelper/broadcasthelper.hxx>
60 #include <unordered_map>
63 namespace vcl
{ class Window
; }
70 class OPropertyEditor
;
71 struct OLineDescriptor
;
73 // #95343#------------------------------------------------------------------------------------
74 typedef ::cppu::WeakImplHelper7
< ::com::sun::star::lang::XServiceInfo
75 , ::com::sun::star::awt::XFocusListener
76 , ::com::sun::star::awt::XLayoutConstrains
77 , ::com::sun::star::beans::XPropertyChangeListener
78 , ::com::sun::star::inspection::XPropertyControlFactory
79 , ::com::sun::star::inspection::XObjectInspector
80 , ::com::sun::star::lang::XInitialization
81 > OPropertyBrowserController_Base
;
83 class OPropertyBrowserController
84 :public ::comphelper::OMutexAndBroadcastHelper
85 ,public OPropertyBrowserController_Base
86 ,public ::com::sun::star::inspection::XObjectInspectorUI
87 // that's intentionally *not* part of the OPropertyBrowserController_Base
88 // We do not want this to be available in queryInterface, getTypes, and the like.
89 ,public IPropertyLineListener
90 ,public IPropertyControlObserver
91 ,public IPropertyExistenceCheck
94 typedef ::std::multimap
< sal_Int32
, ::com::sun::star::beans::Property
> OrderedPropertyMap
;
95 typedef ::std::vector
< ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> >
99 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
102 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> m_xFrame
;
103 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> m_xView
;
105 ::cppu::OInterfaceContainerHelper m_aDisposeListeners
;
106 ::cppu::OInterfaceContainerHelper m_aControlObservers
;
107 // meta data about the properties
108 VclPtr
<OPropertyBrowserView
> m_pView
;
110 OUString m_sPageSelection
;
111 OUString m_sLastValidPageSelection
;
113 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyHandler
>
115 typedef ::std::vector
< PropertyHandlerRef
> PropertyHandlerArray
;
116 typedef std::unordered_map
< OUString
, PropertyHandlerRef
, OUStringHash
>
117 PropertyHandlerRepository
;
118 typedef std::unordered_multimap
< OUString
, PropertyHandlerRef
, OUStringHash
>
119 PropertyHandlerMultiRepository
;
120 PropertyHandlerRepository m_aPropertyHandlers
;
121 PropertyHandlerMultiRepository m_aDependencyHandlers
;
122 PropertyHandlerRef m_xInteractiveHandler
;
124 ::std::unique_ptr
< ComposedPropertyUIUpdate
> m_pUIRequestComposer
;
126 /// our InspectorModel
127 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorModel
>
129 /// the object(s) we're currently inspecting
130 InterfaceArray m_aInspectedObjects
;
131 /// the properties of the currently inspected object(s)
132 OrderedPropertyMap m_aProperties
;
133 /// the property we're just committing
134 OUString m_sCommittingProperty
;
136 typedef std::unordered_map
< OUString
, sal_uInt16
, OUStringHash
> HashString2Int16
;
137 HashString2Int16 m_aPageIds
;
139 bool m_bContainerFocusListening
;
140 bool m_bSuspendingPropertyHandlers
;
142 bool m_bBindingIntrospectee
;
148 virtual OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
149 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
150 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
153 virtual void SAL_CALL
attachFrame( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
154 virtual sal_Bool SAL_CALL
attachModel( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& xModel
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
155 virtual sal_Bool SAL_CALL
suspend( sal_Bool bSuspend
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
156 virtual ::com::sun::star::uno::Any SAL_CALL
getViewData( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
157 virtual void SAL_CALL
restoreViewData( const ::com::sun::star::uno::Any
& Data
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
158 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> SAL_CALL
getModel( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
159 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> SAL_CALL
getFrame( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
162 virtual void SAL_CALL
dispose( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
163 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
164 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& aListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
167 virtual void SAL_CALL
focusGained( const ::com::sun::star::awt::FocusEvent
& _rSource
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
168 virtual void SAL_CALL
focusLost( const ::com::sun::star::awt::FocusEvent
& _rSource
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
171 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
173 // XLayoutConstrains #95343# ----------------
174 virtual ::com::sun::star::awt::Size SAL_CALL
getMinimumSize( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
175 virtual ::com::sun::star::awt::Size SAL_CALL
getPreferredSize( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
176 virtual ::com::sun::star::awt::Size SAL_CALL
calcAdjustedSize( const ::com::sun::star::awt::Size
& aNewSize
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
178 // XPropertyChangeListener
179 virtual void SAL_CALL
propertyChange( const ::com::sun::star::beans::PropertyChangeEvent
& _rEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
181 /** XPropertyControlFactory
183 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
, std::exception
) SAL_OVERRIDE
;
186 OPropertyBrowserController(
187 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
190 virtual ~OPropertyBrowserController();
193 // XServiceInfo - static versions
194 static OUString
getImplementationName_static( ) throw(::com::sun::star::uno::RuntimeException
);
195 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_static( ) throw(::com::sun::star::uno::RuntimeException
);
196 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
197 Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
200 // IPropertyLineListener
201 virtual void Clicked( const OUString
& _rName
, bool _bPrimary
) SAL_OVERRIDE
;
202 virtual void Commit( const OUString
& _rName
, const ::com::sun::star::uno::Any
& _rVal
) SAL_OVERRIDE
;
204 // IPropertyControlObserver
205 virtual void focusGained( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControl
>& _Control
) SAL_OVERRIDE
;
206 virtual void valueChanged( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControl
>& _Control
) SAL_OVERRIDE
;
208 // IPropertyExistenceCheck
209 virtual bool SAL_CALL
hasPropertyByName( const OUString
& _rName
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
211 // XObjectInspectorUI
212 virtual void SAL_CALL
enablePropertyUI( const OUString
& _rPropertyName
, sal_Bool _bEnable
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
213 virtual void SAL_CALL
enablePropertyUIElements( const OUString
& _rPropertyName
, ::sal_Int16 _nElements
, sal_Bool _bEnable
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
214 virtual void SAL_CALL
rebuildPropertyUI( const OUString
& _rPropertyName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
215 virtual void SAL_CALL
showPropertyUI( const OUString
& _rPropertyName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
216 virtual void SAL_CALL
hidePropertyUI( const OUString
& _rPropertyName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
217 virtual void SAL_CALL
showCategory( const OUString
& _rCategory
, sal_Bool _bShow
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
218 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControl
> SAL_CALL
getPropertyControl( const OUString
& _rPropertyName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
219 virtual void SAL_CALL
registerControlObserver( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlObserver
>& _Observer
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
220 virtual void SAL_CALL
revokeControlObserver( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlObserver
>& _Observer
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
221 virtual void SAL_CALL
setHelpSectionText( const OUString
& HelpText
) throw (::com::sun::star::lang::NoSupportException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
224 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorModel
> SAL_CALL
getInspectorModel() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
225 virtual void SAL_CALL
setInspectorModel( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorModel
>& _inspectormodel
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
226 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorUI
> SAL_CALL
getInspectorUI() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
227 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
, std::exception
) SAL_OVERRIDE
;
230 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
, std::exception
) SAL_OVERRIDE
;
231 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
, std::exception
) SAL_OVERRIDE
;
234 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
, std::exception
) SAL_OVERRIDE
;
239 void startContainerWindowListening();
240 void stopContainerWindowListening();
242 // stop the inspection
243 void stopInspection( bool _bCommitModified
);
245 bool haveView() const { return nullptr != m_pView
; }
246 OPropertyEditor
& getPropertyBox() { return m_pView
->getPropertyBox(); }
248 // does the inspection of the objects as indicated by our model
251 // bind the browser to m_xIntrospecteeAsProperty
252 void impl_rebindToInspectee_nothrow( const InterfaceArray
& _rObjects
);
254 /** retrieves special property handlers for our introspectee
256 void getPropertyHandlers( const InterfaceArray
& _rObjects
, PropertyHandlerArray
& _rHandlers
);
258 /** called when a property changed, to broadcast any handlers which might have
259 registered for this property
261 @param _bFirstTimeInit
262 if set to <FALSE/>, this is a real change in the property value, not just a call
263 for purposes of initialization.
265 void impl_broadcastPropertyChange_nothrow( const OUString
& _rPropertyName
, const ::com::sun::star::uno::Any
& _rNewValue
, const ::com::sun::star::uno::Any
& _rOldValue
, bool _bFirstTimeInit
) const;
267 /** determines whether the given property is an actuating property, that is, at least one
268 handler expressed interest in changes to this property's value.
270 inline bool impl_isActuatingProperty_nothrow( const OUString
& _rPropertyName
) const
272 return ( m_aDependencyHandlers
.find( _rPropertyName
) != m_aDependencyHandlers
.end() );
275 sal_uInt32
GetPropertyPos(const OUString
& _rPropName
);
277 /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
278 @param _rPropertyName
279 the name whose handler is to be obtained. Must be the name of a property
280 for which a handler is registered.
282 RuntimeException if there is no handler for the given property
284 the value of this property
286 ::com::sun::star::uno::Any
287 impl_getPropertyValue_throw( const OUString
& _rPropertyName
);
289 /// calls XPropertyHandler::suspend for all our property handlers
290 bool suspendPropertyHandlers_nothrow( bool _bSuspend
);
292 /// suspends the complete inspector
293 bool suspendAll_nothrow();
295 /** selects a page according to our current view data
297 void selectPageFromViewData();
299 /** updates our view data from the currently active page
301 void updateViewDataFromActivePage();
303 /// describes the UI for the given property
304 void describePropertyLine( const ::com::sun::star::beans::Property
& _rPropertyName
, OLineDescriptor
& _rDescriptor
);
306 /** retrieves the position of the property given by name in m_aProperties
308 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
309 not <NULL/> contains the iterator pointing to this property.
311 bool impl_findObjectProperty_nothrow( const OUString
& _rName
, OrderedPropertyMap::const_iterator
* _pProperty
= NULL
);
313 bool Construct(vcl::Window
* _pParentWin
);
315 /** retrieves the property handler for a given property name
316 @param _rPropertyName
317 the name whose handler is to be obtained. Must be the name of a property
318 for which a handler is registered.
320 RuntimeException if there is no handler for the given property
322 the handler which is responsible for the given property
325 impl_getHandlerForProperty_throw( const OUString
& _rPropertyName
) const;
327 /** determines whether we have a handler for the given property
328 @param _rPropertyName
329 the name of the property for which the existence of a handler should be checked
332 impl_hasPropertyHandlerFor_nothrow( const OUString
& _rPropertyName
) const;
334 /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
335 respective tab pages into our view
338 @throws ::com::sun::star::uno::RuntimeException
339 if one of the callees of this method throws this exception
342 impl_buildCategories_throw();
344 /** retrieves the id of the tab page which represents a given category.
345 @param _rCategoryName
346 the programmatic name of a category.
348 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
349 is no tab page for the given category
352 impl_getPageIdForCategory_nothrow( const OUString
& _rCategoryName
) const;
354 /** adds or removes ourself as XEventListener to/from all our inspectees
356 void impl_toggleInspecteeListening_nothrow( bool _bOn
);
358 /** binds the instance to a new model
360 void impl_bindToNewModel_nothrow( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorModel
>& _rxInspectorModel
);
362 /** initializes our view, as indicated by the model's view-relevant properties
364 It's allowed to call this method when no model exists, yet. In this case, nothing
367 void impl_initializeView_nothrow();
369 /** determines whether the view should be readonly.
371 Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
372 If there is no model, <FALSE/> is returned.
374 @throws ::com::sun::star::uno::RuntimeException
375 in case asking the model for its IsReadOnly attribute throws a ::com::sun::star::uno::RuntimeException
378 bool impl_isReadOnlyModel_throw() const;
380 /** updates our view so that it is read-only, as indicated by the model property
381 @see impl_isReadOnlyModel_throw
383 void impl_updateReadOnlyView_nothrow();
385 /** starts or stops listening at the model
387 void impl_startOrStopModelListening_nothrow( bool _bDoListen
) const;
390 DECL_LINK(OnPageActivation
, void*);
394 void createDefault();
395 void createWithModel( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorModel
>& _rxModel
);
402 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_PROPCONTROLLER_HXX
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */