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 .
22 #include "composeduiupdate.hxx"
23 #include "proplinelistener.hxx"
24 #include "propcontrolobserver.hxx"
25 #include "browserview.hxx"
27 #include <com/sun/star/awt/XFocusListener.hpp>
28 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XEventListener.hpp>
33 #include <com/sun/star/awt/XLayoutConstrains.hpp>
34 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
35 #include <com/sun/star/inspection/XObjectInspector.hpp>
36 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
37 #include <com/sun/star/inspection/XPropertyHandler.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <comphelper/interfacecontainer2.hxx>
40 #include <comphelper/uno3.hxx>
41 #include <cppuhelper/implbase.hxx>
42 #include <comphelper/broadcasthelper.hxx>
43 #include <vcl/weld.hxx>
47 #include <unordered_map>
52 class OPropertyEditor
;
53 struct OLineDescriptor
;
55 typedef ::cppu::WeakImplHelper
< css::lang::XServiceInfo
56 , css::awt::XFocusListener
57 , css::awt::XLayoutConstrains
58 , css::beans::XPropertyChangeListener
59 , css::inspection::XPropertyControlFactory
60 , css::inspection::XObjectInspector
61 , css::lang::XInitialization
62 > OPropertyBrowserController_Base
;
64 class OPropertyBrowserController
65 :public ::comphelper::OMutexAndBroadcastHelper
66 ,public OPropertyBrowserController_Base
67 ,public css::inspection::XObjectInspectorUI
68 // that's intentionally *not* part of the OPropertyBrowserController_Base
69 // We do not want this to be available in queryInterface, getTypes, and the like.
70 ,public IPropertyLineListener
71 ,public IPropertyControlObserver
72 ,public IPropertyExistenceCheck
75 typedef std::multimap
< sal_Int32
, css::beans::Property
> OrderedPropertyMap
;
76 typedef std::vector
< css::uno::Reference
< css::uno::XInterface
> >
79 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
80 css::uno::Reference
< css::frame::XFrame
> m_xFrame
;
81 css::uno::Reference
< css::awt::XWindow
> m_xView
;
83 ::comphelper::OInterfaceContainerHelper2 m_aDisposeListeners
;
84 ::comphelper::OInterfaceContainerHelper2 m_aControlObservers
;
85 // meta data about the properties
86 std::unique_ptr
<weld::Builder
> m_xBuilder
;
87 std::unique_ptr
<OPropertyBrowserView
> m_xPropView
;
89 OUString m_sPageSelection
;
90 OUString m_sLastValidPageSelection
;
92 typedef css::uno::Reference
< css::inspection::XPropertyHandler
>
94 typedef std::vector
< PropertyHandlerRef
> PropertyHandlerArray
;
95 typedef std::unordered_map
< OUString
, PropertyHandlerRef
>
96 PropertyHandlerRepository
;
97 typedef std::unordered_multimap
< OUString
, PropertyHandlerRef
>
98 PropertyHandlerMultiRepository
;
99 PropertyHandlerRepository m_aPropertyHandlers
;
100 PropertyHandlerMultiRepository m_aDependencyHandlers
;
101 PropertyHandlerRef m_xInteractiveHandler
;
103 std::unique_ptr
< ComposedPropertyUIUpdate
> m_pUIRequestComposer
;
105 /// our InspectorModel
106 css::uno::Reference
< css::inspection::XObjectInspectorModel
>
108 /// the object(s) we're currently inspecting
109 InterfaceArray m_aInspectedObjects
;
110 /// the properties of the currently inspected object(s)
111 OrderedPropertyMap m_aProperties
;
112 /// the property we're just committing
113 OUString m_sCommittingProperty
;
115 typedef std::unordered_map
< OUString
, sal_uInt16
> HashString2Int16
;
116 HashString2Int16 m_aPageIds
;
118 bool m_bContainerFocusListening
;
119 bool m_bSuspendingPropertyHandlers
;
121 bool m_bBindingIntrospectee
;
127 virtual OUString SAL_CALL
getImplementationName( ) override
;
128 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
129 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
132 virtual void SAL_CALL
attachFrame( const css::uno::Reference
< css::frame::XFrame
>& xFrame
) override
;
133 virtual sal_Bool SAL_CALL
attachModel( const css::uno::Reference
< css::frame::XModel
>& xModel
) override
;
134 virtual sal_Bool SAL_CALL
suspend( sal_Bool bSuspend
) override
;
135 virtual css::uno::Any SAL_CALL
getViewData( ) override
;
136 virtual void SAL_CALL
restoreViewData( const css::uno::Any
& Data
) override
;
137 virtual css::uno::Reference
< css::frame::XModel
> SAL_CALL
getModel( ) override
;
138 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
getFrame( ) override
;
141 virtual void SAL_CALL
dispose( ) override
;
142 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
143 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
146 virtual void SAL_CALL
focusGained( const css::awt::FocusEvent
& _rSource
) override
;
147 virtual void SAL_CALL
focusLost( const css::awt::FocusEvent
& _rSource
) override
;
150 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
153 virtual css::awt::Size SAL_CALL
getMinimumSize( ) override
;
154 virtual css::awt::Size SAL_CALL
getPreferredSize( ) override
;
155 virtual css::awt::Size SAL_CALL
calcAdjustedSize( const css::awt::Size
& rNewSize
) override
;
157 // XPropertyChangeListener
158 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& _rEvent
) override
;
160 /** XPropertyControlFactory
162 virtual css::uno::Reference
< css::inspection::XPropertyControl
> SAL_CALL
createPropertyControl( ::sal_Int16 ControlType
, sal_Bool CreateReadOnly
) override
;
165 explicit OPropertyBrowserController(
166 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
169 virtual ~OPropertyBrowserController() override
;
171 // IPropertyLineListener
172 virtual void Clicked( const OUString
& _rName
, bool _bPrimary
) override
;
173 virtual void Commit( const OUString
& _rName
, const css::uno::Any
& _rVal
) override
;
175 // IPropertyControlObserver
176 virtual void focusGained( const css::uno::Reference
< css::inspection::XPropertyControl
>& Control
) override
;
177 virtual void valueChanged( const css::uno::Reference
< css::inspection::XPropertyControl
>& Control
) override
;
179 // IPropertyExistenceCheck
180 virtual bool hasPropertyByName( const OUString
& _rName
) override
;
182 // XObjectInspectorUI
183 virtual void SAL_CALL
enablePropertyUI( const OUString
& _rPropertyName
, sal_Bool _bEnable
) override
;
184 virtual void SAL_CALL
enablePropertyUIElements( const OUString
& _rPropertyName
, ::sal_Int16 _nElements
, sal_Bool _bEnable
) override
;
185 virtual void SAL_CALL
rebuildPropertyUI( const OUString
& _rPropertyName
) override
;
186 virtual void SAL_CALL
showPropertyUI( const OUString
& _rPropertyName
) override
;
187 virtual void SAL_CALL
hidePropertyUI( const OUString
& _rPropertyName
) override
;
188 virtual void SAL_CALL
showCategory( const OUString
& _rCategory
, sal_Bool _bShow
) override
;
189 virtual css::uno::Reference
< css::inspection::XPropertyControl
> SAL_CALL
getPropertyControl( const OUString
& _rPropertyName
) override
;
190 virtual void SAL_CALL
registerControlObserver( const css::uno::Reference
< css::inspection::XPropertyControlObserver
>& Observer
) override
;
191 virtual void SAL_CALL
revokeControlObserver( const css::uno::Reference
< css::inspection::XPropertyControlObserver
>& Observer
) override
;
192 virtual void SAL_CALL
setHelpSectionText( const OUString
& HelpText
) override
;
195 virtual css::uno::Reference
< css::inspection::XObjectInspectorModel
> SAL_CALL
getInspectorModel() override
;
196 virtual void SAL_CALL
setInspectorModel( const css::uno::Reference
< css::inspection::XObjectInspectorModel
>& _inspectormodel
) override
;
197 virtual css::uno::Reference
< css::inspection::XObjectInspectorUI
> SAL_CALL
getInspectorUI() override
;
198 virtual void SAL_CALL
inspect( const css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> >& Objects
) override
;
201 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch( const css::util::URL
& URL
, const OUString
& TargetFrameName
, ::sal_Int32 SearchFlags
) override
;
202 virtual css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& Requests
) override
;
205 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
210 void startContainerWindowListening();
211 void stopContainerWindowListening();
213 // stop the inspection
214 void stopInspection( bool _bCommitModified
);
216 bool haveView() const { return bool(m_xPropView
); }
217 OPropertyEditor
& getPropertyBox() { return m_xPropView
->getPropertyBox(); }
219 // does the inspection of the objects as indicated by our model
222 // bind the browser to m_xIntrospecteeAsProperty
223 void impl_rebindToInspectee_nothrow( InterfaceArray
&& _rObjects
);
225 /** retrieves special property handlers for our introspectee
227 void getPropertyHandlers( const InterfaceArray
& _rObjects
, PropertyHandlerArray
& _rHandlers
);
229 /** called when a property changed, to broadcast any handlers which might have
230 registered for this property
232 @param _bFirstTimeInit
233 if set to <FALSE/>, this is a real change in the property value, not just a call
234 for purposes of initialization.
236 void impl_broadcastPropertyChange_nothrow( const OUString
& _rPropertyName
, const css::uno::Any
& _rNewValue
, const css::uno::Any
& _rOldValue
, bool _bFirstTimeInit
) const;
238 /** determines whether the given property is an actuating property, that is, at least one
239 handler expressed interest in changes to this property's value.
241 bool impl_isActuatingProperty_nothrow( const OUString
& _rPropertyName
) const
243 return ( m_aDependencyHandlers
.find( _rPropertyName
) != m_aDependencyHandlers
.end() );
246 /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
247 @param _rPropertyName
248 the name whose handler is to be obtained. Must be the name of a property
249 for which a handler is registered.
251 RuntimeException if there is no handler for the given property
253 the value of this property
256 impl_getPropertyValue_throw( const OUString
& _rPropertyName
);
258 /// calls XPropertyHandler::suspend for all our property handlers
259 bool suspendPropertyHandlers_nothrow( bool _bSuspend
);
261 /// suspends the complete inspector
262 bool suspendAll_nothrow();
264 /** selects a page according to our current view data
266 void selectPageFromViewData();
268 /** updates our view data from the currently active page
270 void updateViewDataFromActivePage();
272 /// describes the UI for the given property
273 void describePropertyLine( const css::beans::Property
& _rPropertyName
, OLineDescriptor
& _rDescriptor
);
275 /** retrieves the position of the property given by name in m_aProperties
277 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
278 not <NULL/> contains the iterator pointing to this property.
280 bool impl_findObjectProperty_nothrow( const OUString
& _rName
, OrderedPropertyMap::const_iterator
* _pProperty
= nullptr );
282 void Construct(const css::uno::Reference
<css::awt::XWindow
>& rContainerWindow
, std::unique_ptr
<weld::Builder
> xBuilder
);
284 /** retrieves the property handler for a given property name
285 @param _rPropertyName
286 the name whose handler is to be obtained. Must be the name of a property
287 for which a handler is registered.
289 RuntimeException if there is no handler for the given property
291 the handler which is responsible for the given property
293 PropertyHandlerRef
const &
294 impl_getHandlerForProperty_throw( const OUString
& _rPropertyName
) const;
296 /** determines whether we have a handler for the given property
297 @param _rPropertyName
298 the name of the property for which the existence of a handler should be checked
301 impl_hasPropertyHandlerFor_nothrow( const OUString
& _rPropertyName
) const;
303 /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
304 respective tab pages into our view
307 @throws css::uno::RuntimeException
308 if one of the callees of this method throws this exception
311 impl_buildCategories_throw();
313 /** retrieves the id of the tab page which represents a given category.
314 @param _rCategoryName
315 the programmatic name of a category.
317 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
318 is no tab page for the given category
321 impl_getPageIdForCategory_nothrow( const OUString
& _rCategoryName
) const;
323 /** adds or removes ourself as XEventListener to/from all our inspectees
325 void impl_toggleInspecteeListening_nothrow( bool _bOn
);
327 /** binds the instance to a new model
329 void impl_bindToNewModel_nothrow( const css::uno::Reference
< css::inspection::XObjectInspectorModel
>& _rxInspectorModel
);
331 /** initializes our view, as indicated by the model's view-relevant properties
333 It's allowed to call this method when no model exists, yet. In this case, nothing
336 void impl_initializeView_nothrow();
338 /** determines whether the view should be readonly.
340 Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
341 If there is no model, <FALSE/> is returned.
343 @throws css::uno::RuntimeException
344 in case asking the model for its IsReadOnly attribute throws a css::uno::RuntimeException
347 bool impl_isReadOnlyModel_throw() const;
349 /** starts or stops listening at the model
351 void impl_startOrStopModelListening_nothrow( bool _bDoListen
) const;
354 DECL_LINK(OnPageActivation
, LinkParamNone
*, void);
358 void createWithModel( const css::uno::Reference
< css::inspection::XObjectInspectorModel
>& _rxModel
);
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */