LibreOffice Module extensions (master) 1
propcontroller.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include "composeduiupdate.hxx"
23#include "proplinelistener.hxx"
25#include "browserview.hxx"
26
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>
40#include <comphelper/uno3.hxx>
43#include <vcl/weld.hxx>
44
45#include <map>
46#include <memory>
47#include <unordered_map>
48#include <vector>
49
50namespace pcr
51{
52 class OPropertyEditor;
53 struct OLineDescriptor;
54
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
63
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.
73 {
74 private:
75 typedef std::multimap< sal_Int32, css::beans::Property > OrderedPropertyMap;
76 typedef std::vector< css::uno::Reference< css::uno::XInterface > >
78
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;
82
85 // meta data about the properties
86 std::unique_ptr<weld::Builder> m_xBuilder;
87 std::unique_ptr<OPropertyBrowserView> m_xPropView;
88
91
92 typedef css::uno::Reference< css::inspection::XPropertyHandler >
94 typedef std::vector< PropertyHandlerRef > PropertyHandlerArray;
95 typedef std::unordered_map< OUString, PropertyHandlerRef >
97 typedef std::unordered_multimap< OUString, PropertyHandlerRef >
102
103 std::unique_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer;
104
106 css::uno::Reference< css::inspection::XObjectInspectorModel >
114
115 typedef std::unordered_map< OUString, sal_uInt16 > HashString2Int16;
117
122
123 protected:
125
126 // XServiceInfo
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;
130
131 // XController
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;
139
140 // XComponent
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;
144
145 // XFocusListener
146 virtual void SAL_CALL focusGained( const css::awt::FocusEvent& _rSource ) override;
147 virtual void SAL_CALL focusLost( const css::awt::FocusEvent& _rSource ) override;
148
149 // XEventListener
150 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
151
152 // XLayoutConstrains
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;
156
157 // XPropertyChangeListener
158 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& _rEvent ) override;
159
162 virtual css::uno::Reference< css::inspection::XPropertyControl > SAL_CALL createPropertyControl( ::sal_Int16 ControlType, sal_Bool CreateReadOnly ) override;
163
164 public:
166 const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
167
168 protected:
169 virtual ~OPropertyBrowserController() override;
170
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;
174
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;
178
179 // IPropertyExistenceCheck
180 virtual bool hasPropertyByName( const OUString& _rName ) override;
181
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;
193
194 // XObjectInspector
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;
199
200 // XDispatchProvider
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;
203
204 // XInitialization
205 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
206
207 private:
208 void UpdateUI();
209
212
213 // stop the inspection
214 void stopInspection( bool _bCommitModified );
215
216 bool haveView() const { return bool(m_xPropView); }
217 OPropertyEditor& getPropertyBox() { return m_xPropView->getPropertyBox(); }
218
219 // does the inspection of the objects as indicated by our model
220 void doInspection();
221
222 // bind the browser to m_xIntrospecteeAsProperty
224
227 void getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
228
236 void impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const css::uno::Any& _rNewValue, const css::uno::Any& _rOldValue, bool _bFirstTimeInit ) const;
237
241 bool impl_isActuatingProperty_nothrow( const OUString& _rPropertyName ) const
242 {
243 return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
244 }
245
255 css::uno::Any
256 impl_getPropertyValue_throw( const OUString& _rPropertyName );
257
259 bool suspendPropertyHandlers_nothrow( bool _bSuspend );
260
262 bool suspendAll_nothrow();
263
267
271
273 void describePropertyLine( const css::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor );
274
280 bool impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = nullptr );
281
282 void Construct(const css::uno::Reference<css::awt::XWindow>& rContainerWindow, std::unique_ptr<weld::Builder> xBuilder);
283
293 PropertyHandlerRef const &
294 impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const;
295
300 bool
301 impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const;
302
310 void
312
320 sal_uInt16
321 impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const;
322
326
329 void impl_bindToNewModel_nothrow( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _rxInspectorModel );
330
337
347 bool impl_isReadOnlyModel_throw() const;
348
351 void impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
352
353 private:
354 DECL_LINK(OnPageActivation, LinkParamNone*, void);
355
356 private:
357 // constructors
358 void createWithModel( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _rxModel );
359 };
360
361
362} // namespace pcr
363
364
365/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
non-UNO version of the XPropertyControlObserver
callback for a ComposedPropertyUIUpdate checking a given property for existence
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &_rEvent) override
virtual void SAL_CALL registerControlObserver(const css::uno::Reference< css::inspection::XPropertyControlObserver > &Observer) override
virtual void Clicked(const OUString &_rName, bool _bPrimary) override
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &URL, const OUString &TargetFrameName, ::sal_Int32 SearchFlags) override
virtual void SAL_CALL enablePropertyUI(const OUString &_rPropertyName, sal_Bool _bEnable) override
virtual void SAL_CALL setHelpSectionText(const OUString &HelpText) override
void impl_buildCategories_throw()
builds up m_aPageIds from InspectorModel::describeCategories, and insert all the respective tab pages...
::comphelper::OInterfaceContainerHelper2 m_aDisposeListeners
bool impl_isReadOnlyModel_throw() const
determines whether the view should be readonly.
::comphelper::OInterfaceContainerHelper2 m_aControlObservers
virtual void SAL_CALL focusLost(const css::awt::FocusEvent &_rSource) override
void impl_toggleInspecteeListening_nothrow(bool _bOn)
adds or removes ourself as XEventListener to/from all our inspectees
virtual void SAL_CALL setInspectorModel(const css::uno::Reference< css::inspection::XObjectInspectorModel > &_inspectormodel) override
css::uno::Reference< css::inspection::XObjectInspectorModel > m_xModel
our InspectorModel
DECL_LINK(OnPageActivation, LinkParamNone *, void)
std::multimap< sal_Int32, css::beans::Property > OrderedPropertyMap
virtual css::uno::Reference< css::inspection::XPropertyControl > SAL_CALL getPropertyControl(const OUString &_rPropertyName) override
std::vector< PropertyHandlerRef > PropertyHandlerArray
void impl_initializeView_nothrow()
initializes our view, as indicated by the model's view-relevant properties
PropertyHandlerMultiRepository m_aDependencyHandlers
css::uno::Reference< css::uno::XComponentContext > m_xContext
OUString m_sCommittingProperty
the property we're just committing
std::unordered_map< OUString, PropertyHandlerRef > PropertyHandlerRepository
sal_uInt16 impl_getPageIdForCategory_nothrow(const OUString &_rCategoryName) const
retrieves the id of the tab page which represents a given category.
void Construct(const css::uno::Reference< css::awt::XWindow > &rContainerWindow, std::unique_ptr< weld::Builder > xBuilder)
void stopInspection(bool _bCommitModified)
void impl_rebindToInspectee_nothrow(InterfaceArray &&_rObjects)
bool suspendPropertyHandlers_nothrow(bool _bSuspend)
calls XPropertyHandler::suspend for all our property handlers
bool suspendAll_nothrow()
suspends the complete inspector
virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > &xModel) override
std::unique_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer
virtual void SAL_CALL revokeControlObserver(const css::uno::Reference< css::inspection::XPropertyControlObserver > &Observer) override
PropertyHandlerRef m_xInteractiveHandler
virtual css::awt::Size SAL_CALL getPreferredSize() override
virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override
virtual void SAL_CALL dispose() override
bool impl_hasPropertyHandlerFor_nothrow(const OUString &_rPropertyName) const
determines whether we have a handler for the given property
virtual void SAL_CALL focusGained(const css::awt::FocusEvent &_rSource) override
void getPropertyHandlers(const InterfaceArray &_rObjects, PropertyHandlerArray &_rHandlers)
retrieves special property handlers for our introspectee
void impl_bindToNewModel_nothrow(const css::uno::Reference< css::inspection::XObjectInspectorModel > &_rxInspectorModel)
binds the instance to a new model
virtual css::uno::Any SAL_CALL getViewData() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
std::unique_ptr< OPropertyBrowserView > m_xPropView
virtual void Commit(const OUString &_rName, const css::uno::Any &_rVal) override
virtual void SAL_CALL restoreViewData(const css::uno::Any &Data) override
virtual void SAL_CALL hidePropertyUI(const OUString &_rPropertyName) override
std::unordered_multimap< OUString, PropertyHandlerRef > PropertyHandlerMultiRepository
InterfaceArray m_aInspectedObjects
the object(s) we're currently inspecting
std::unique_ptr< weld::Builder > m_xBuilder
virtual css::awt::Size SAL_CALL getMinimumSize() override
void createWithModel(const css::uno::Reference< css::inspection::XObjectInspectorModel > &_rxModel)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
void describePropertyLine(const css::beans::Property &_rPropertyName, OLineDescriptor &_rDescriptor)
describes the UI for the given property
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::Any impl_getPropertyValue_throw(const OUString &_rPropertyName)
retrieves the value of the given property, by asking the appropriate XPropertyHandler
OPropertyEditor & getPropertyBox()
void selectPageFromViewData()
selects a page according to our current view data
virtual void SAL_CALL attachFrame(const css::uno::Reference< css::frame::XFrame > &xFrame) override
PropertyHandlerRepository m_aPropertyHandlers
virtual void SAL_CALL showCategory(const OUString &_rCategory, sal_Bool _bShow) override
virtual bool hasPropertyByName(const OUString &_rName) override
virtual void valueChanged(const css::uno::Reference< css::inspection::XPropertyControl > &Control) override
std::vector< css::uno::Reference< css::uno::XInterface > > InterfaceArray
virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel() override
virtual css::uno::Reference< css::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() override
virtual void SAL_CALL showPropertyUI(const OUString &_rPropertyName) override
virtual css::uno::Reference< css::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() override
virtual void SAL_CALL inspect(const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > &Objects) override
virtual void SAL_CALL rebuildPropertyUI(const OUString &_rPropertyName) override
virtual css::uno::Reference< css::inspection::XPropertyControl > SAL_CALL createPropertyControl(::sal_Int16 ControlType, sal_Bool CreateReadOnly) override
XPropertyControlFactory.
OrderedPropertyMap m_aProperties
the properties of the currently inspected object(s)
void impl_startOrStopModelListening_nothrow(bool _bDoListen) const
starts or stops listening at the model
void updateViewDataFromActivePage()
updates our view data from the currently active page
virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override
css::uno::Reference< css::inspection::XPropertyHandler > PropertyHandlerRef
PropertyHandlerRef const & impl_getHandlerForProperty_throw(const OUString &_rPropertyName) const
retrieves the property handler for a given property name
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &Requests) override
void impl_broadcastPropertyChange_nothrow(const OUString &_rPropertyName, const css::uno::Any &_rNewValue, const css::uno::Any &_rOldValue, bool _bFirstTimeInit) const
called when a property changed, to broadcast any handlers which might have registered for this proper...
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual css::awt::Size SAL_CALL calcAdjustedSize(const css::awt::Size &rNewSize) override
bool impl_isActuatingProperty_nothrow(const OUString &_rPropertyName) const
determines whether the given property is an actuating property, that is, at least one handler express...
std::unordered_map< OUString, sal_uInt16 > HashString2Int16
css::uno::Reference< css::frame::XFrame > m_xFrame
virtual void SAL_CALL enablePropertyUIElements(const OUString &_rPropertyName, ::sal_Int16 _nElements, sal_Bool _bEnable) override
bool impl_findObjectProperty_nothrow(const OUString &_rName, OrderedPropertyMap::const_iterator *_pProperty=nullptr)
retrieves the position of the property given by name in m_aProperties
css::uno::Reference< css::awt::XWindow > m_xView
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
std::vector< css::uno::Reference< css::uno::XInterface > > InterfaceArray
a property handler for any virtual string properties
Definition: browserline.cxx:39
::cppu::WeakImplHelper< css::lang::XServiceInfo, css::awt::XFocusListener, css::awt::XLayoutConstrains, css::beans::XPropertyChangeListener, css::inspection::XPropertyControlFactory, css::inspection::XObjectInspector, css::lang::XInitialization > OPropertyBrowserController_Base
ControlType
unsigned char sal_Bool
#define DECLARE_XINTERFACE()