Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / propctrlr / propcontroller.hxx
blobd74d3e915bf67b301e2a4bbbe78f921b753229e3
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 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/implbase.hxx>
56 #include <comphelper/broadcasthelper.hxx>
58 #include <map>
59 #include <memory>
60 #include <unordered_map>
61 #include <vector>
63 namespace vcl { class Window; }
66 namespace pcr
70 class OPropertyEditor;
71 struct OLineDescriptor;
73 typedef ::cppu::WeakImplHelper < css::lang::XServiceInfo
74 , css::awt::XFocusListener
75 , css::awt::XLayoutConstrains
76 , css::beans::XPropertyChangeListener
77 , css::inspection::XPropertyControlFactory
78 , css::inspection::XObjectInspector
79 , css::lang::XInitialization
80 > OPropertyBrowserController_Base;
82 class OPropertyBrowserController
83 :public ::comphelper::OMutexAndBroadcastHelper
84 ,public OPropertyBrowserController_Base
85 ,public css::inspection::XObjectInspectorUI
86 // that's intentionally *not* part of the OPropertyBrowserController_Base
87 // We do not want this to be available in queryInterface, getTypes, and the like.
88 ,public IPropertyLineListener
89 ,public IPropertyControlObserver
90 ,public IPropertyExistenceCheck
92 private:
93 typedef std::multimap< sal_Int32, css::beans::Property > OrderedPropertyMap;
94 typedef std::vector< css::uno::Reference< css::uno::XInterface > >
95 InterfaceArray;
97 protected:
98 css::uno::Reference< css::uno::XComponentContext > m_xContext;
100 private:
101 css::uno::Reference< css::frame::XFrame > m_xFrame;
102 css::uno::Reference< css::awt::XWindow > m_xView;
104 ::comphelper::OInterfaceContainerHelper2 m_aDisposeListeners;
105 ::comphelper::OInterfaceContainerHelper2 m_aControlObservers;
106 // meta data about the properties
107 VclPtr<OPropertyBrowserView> m_pView;
109 OUString m_sPageSelection;
110 OUString m_sLastValidPageSelection;
112 typedef css::uno::Reference< css::inspection::XPropertyHandler >
113 PropertyHandlerRef;
114 typedef std::vector< PropertyHandlerRef > PropertyHandlerArray;
115 typedef std::unordered_map< OUString, PropertyHandlerRef, OUStringHash >
116 PropertyHandlerRepository;
117 typedef std::unordered_multimap< OUString, PropertyHandlerRef, OUStringHash >
118 PropertyHandlerMultiRepository;
119 PropertyHandlerRepository m_aPropertyHandlers;
120 PropertyHandlerMultiRepository m_aDependencyHandlers;
121 PropertyHandlerRef m_xInteractiveHandler;
123 std::unique_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer;
125 /// our InspectorModel
126 css::uno::Reference< css::inspection::XObjectInspectorModel >
127 m_xModel;
128 /// the object(s) we're currently inspecting
129 InterfaceArray m_aInspectedObjects;
130 /// the properties of the currently inspected object(s)
131 OrderedPropertyMap m_aProperties;
132 /// the property we're just committing
133 OUString m_sCommittingProperty;
135 typedef std::unordered_map< OUString, sal_uInt16, OUStringHash > HashString2Int16;
136 HashString2Int16 m_aPageIds;
138 bool m_bContainerFocusListening;
139 bool m_bSuspendingPropertyHandlers;
140 bool m_bConstructed;
141 bool m_bBindingIntrospectee;
143 protected:
144 DECLARE_XINTERFACE()
146 // XServiceInfo
147 virtual OUString SAL_CALL getImplementationName( ) override;
148 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
149 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
151 // XController
152 virtual void SAL_CALL attachFrame( const css::uno::Reference< css::frame::XFrame >& xFrame ) override;
153 virtual sal_Bool SAL_CALL attachModel( const css::uno::Reference< css::frame::XModel >& xModel ) override;
154 virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) override;
155 virtual css::uno::Any SAL_CALL getViewData( ) override;
156 virtual void SAL_CALL restoreViewData( const css::uno::Any& Data ) override;
157 virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel( ) override;
158 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame( ) override;
160 // XComponent
161 virtual void SAL_CALL dispose( ) override;
162 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
163 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
165 // XFocusListener
166 virtual void SAL_CALL focusGained( const css::awt::FocusEvent& _rSource ) override;
167 virtual void SAL_CALL focusLost( const css::awt::FocusEvent& _rSource ) override;
169 // XEventListener
170 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
172 // XLayoutConstrains
173 virtual css::awt::Size SAL_CALL getMinimumSize( ) override;
174 virtual css::awt::Size SAL_CALL getPreferredSize( ) override;
175 virtual css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override;
177 // XPropertyChangeListener
178 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& _rEvent ) override;
180 /** XPropertyControlFactory
182 virtual css::uno::Reference< css::inspection::XPropertyControl > SAL_CALL createPropertyControl( ::sal_Int16 ControlType, sal_Bool CreateReadOnly ) override;
184 public:
185 explicit OPropertyBrowserController(
186 const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
188 protected:
189 virtual ~OPropertyBrowserController() override;
191 public:
192 // XServiceInfo - static versions
193 /// @throws css::uno::RuntimeException
194 static OUString getImplementationName_static( );
195 /// @throws css::uno::RuntimeException
196 static css::uno::Sequence< OUString > getSupportedServiceNames_static( );
197 static css::uno::Reference< css::uno::XInterface > SAL_CALL
198 Create(const css::uno::Reference< css::uno::XComponentContext >&);
200 protected:
201 // IPropertyLineListener
202 virtual void Clicked( const OUString& _rName, bool _bPrimary ) override;
203 virtual void Commit( const OUString& _rName, const css::uno::Any& _rVal ) override;
205 // IPropertyControlObserver
206 virtual void focusGained( const css::uno::Reference< css::inspection::XPropertyControl >& Control ) override;
207 virtual void valueChanged( const css::uno::Reference< css::inspection::XPropertyControl >& Control ) override;
209 // IPropertyExistenceCheck
210 virtual bool SAL_CALL hasPropertyByName( const OUString& _rName ) override;
212 // XObjectInspectorUI
213 virtual void SAL_CALL enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) override;
214 virtual void SAL_CALL enablePropertyUIElements( const OUString& _rPropertyName, ::sal_Int16 _nElements, sal_Bool _bEnable ) override;
215 virtual void SAL_CALL rebuildPropertyUI( const OUString& _rPropertyName ) override;
216 virtual void SAL_CALL showPropertyUI( const OUString& _rPropertyName ) override;
217 virtual void SAL_CALL hidePropertyUI( const OUString& _rPropertyName ) override;
218 virtual void SAL_CALL showCategory( const OUString& _rCategory, sal_Bool _bShow ) override;
219 virtual css::uno::Reference< css::inspection::XPropertyControl > SAL_CALL getPropertyControl( const OUString& _rPropertyName ) override;
220 virtual void SAL_CALL registerControlObserver( const css::uno::Reference< css::inspection::XPropertyControlObserver >& Observer ) override;
221 virtual void SAL_CALL revokeControlObserver( const css::uno::Reference< css::inspection::XPropertyControlObserver >& Observer ) override;
222 virtual void SAL_CALL setHelpSectionText( const OUString& HelpText ) override;
224 // XObjectInspector
225 virtual css::uno::Reference< css::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() override;
226 virtual void SAL_CALL setInspectorModel( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _inspectormodel ) override;
227 virtual css::uno::Reference< css::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() override;
228 virtual void SAL_CALL inspect( const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >& Objects ) override;
230 // XDispatchProvider
231 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch( const css::util::URL& URL, const OUString& TargetFrameName, ::sal_Int32 SearchFlags ) override;
232 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& Requests ) override;
234 // XInitialization
235 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
237 private:
238 void UpdateUI();
240 void startContainerWindowListening();
241 void stopContainerWindowListening();
243 // stop the inspection
244 void stopInspection( bool _bCommitModified );
246 bool haveView() const { return nullptr != m_pView; }
247 OPropertyEditor& getPropertyBox() { return m_pView->getPropertyBox(); }
249 // does the inspection of the objects as indicated by our model
250 void doInspection();
252 // bind the browser to m_xIntrospecteeAsProperty
253 void impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects );
255 /** retrieves special property handlers for our introspectee
257 void getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
259 /** called when a property changed, to broadcast any handlers which might have
260 registered for this property
262 @param _bFirstTimeInit
263 if set to <FALSE/>, this is a real change in the property value, not just a call
264 for purposes of initialization.
266 void impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const css::uno::Any& _rNewValue, const css::uno::Any& _rOldValue, bool _bFirstTimeInit ) const;
268 /** determines whether the given property is an actuating property, that is, at least one
269 handler expressed interest in changes to this property's value.
271 bool impl_isActuatingProperty_nothrow( const OUString& _rPropertyName ) const
273 return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
276 /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
277 @param _rPropertyName
278 the name whose handler is to be obtained. Must be the name of a property
279 for which a handler is registered.
280 @throws
281 RuntimeException if there is no handler for the given property
282 @return
283 the value of this property
285 css::uno::Any
286 impl_getPropertyValue_throw( const OUString& _rPropertyName );
288 /// calls XPropertyHandler::suspend for all our property handlers
289 bool suspendPropertyHandlers_nothrow( bool _bSuspend );
291 /// suspends the complete inspector
292 bool suspendAll_nothrow();
294 /** selects a page according to our current view data
296 void selectPageFromViewData();
298 /** updates our view data from the currently active page
300 void updateViewDataFromActivePage();
302 /// describes the UI for the given property
303 void describePropertyLine( const css::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor );
305 /** retrieves the position of the property given by name in m_aProperties
306 @return
307 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
308 not <NULL/> contains the iterator pointing to this property.
310 bool impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = nullptr );
312 bool Construct(vcl::Window* _pParentWin);
314 /** retrieves the property handler for a given property name
315 @param _rPropertyName
316 the name whose handler is to be obtained. Must be the name of a property
317 for which a handler is registered.
318 @throws
319 RuntimeException if there is no handler for the given property
320 @return
321 the handler which is responsible for the given property
323 PropertyHandlerRef
324 impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const;
326 /** determines whether we have a handler for the given property
327 @param _rPropertyName
328 the name of the property for which the existence of a handler should be checked
330 bool
331 impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const;
333 /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
334 respective tab pages into our view
335 @precond
336 m_aPageIds is empty
337 @throws css::uno::RuntimeException
338 if one of the callees of this method throws this exception
340 void
341 impl_buildCategories_throw();
343 /** retrieves the id of the tab page which represents a given category.
344 @param _rCategoryName
345 the programmatic name of a category.
346 @return
347 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
348 is no tab page for the given category
350 sal_uInt16
351 impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const;
353 /** adds or removes ourself as XEventListener to/from all our inspectees
355 void impl_toggleInspecteeListening_nothrow( bool _bOn );
357 /** binds the instance to a new model
359 void impl_bindToNewModel_nothrow( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _rxInspectorModel );
361 /** initializes our view, as indicated by the model's view-relevant properties
363 It's allowed to call this method when no model exists, yet. In this case, nothing
364 happens.
366 void impl_initializeView_nothrow();
368 /** determines whether the view should be readonly.
370 Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
371 If there is no model, <FALSE/> is returned.
373 @throws css::uno::RuntimeException
374 in case asking the model for its IsReadOnly attribute throws a css::uno::RuntimeException
375 itself.
377 bool impl_isReadOnlyModel_throw() const;
379 /** starts or stops listening at the model
381 void impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
383 private:
384 DECL_LINK(OnPageActivation, LinkParamNone*, void);
386 private:
387 // constructors
388 void createWithModel( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _rxModel );
392 } // namespace pcr
395 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_PROPCONTROLLER_HXX
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */