bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / propcontroller.hxx
blob0dbbe5cffe930e7d1ebf842bbaa1167aa0f80cd6
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/sdbc/XRowSet.hpp>
40 #include <com/sun/star/uno/Sequence.hxx>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XEventListener.hpp>
43 #include <com/sun/star/sdbc/XConnection.hpp>
44 #include <com/sun/star/awt/XLayoutConstrains.hpp>
45 #include <com/sun/star/awt/XControlContainer.hpp>
46 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
47 #include <com/sun/star/inspection/XObjectInspector.hpp>
48 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
49 #include <com/sun/star/inspection/XPropertyHandler.hpp>
50 #include <com/sun/star/lang/XInitialization.hpp>
51 #include <connectivity/dbtools.hxx>
52 #include <cppuhelper/interfacecontainer.hxx>
53 #include <cppuhelper/implbase.hxx>
54 #include <comphelper/broadcasthelper.hxx>
56 #include <map>
57 #include <memory>
58 #include <unordered_map>
59 #include <vector>
61 namespace vcl { class Window; }
64 namespace pcr
68 class OPropertyEditor;
69 struct OLineDescriptor;
71 typedef ::cppu::WeakImplHelper < css::lang::XServiceInfo
72 , css::awt::XFocusListener
73 , css::awt::XLayoutConstrains
74 , css::beans::XPropertyChangeListener
75 , css::inspection::XPropertyControlFactory
76 , css::inspection::XObjectInspector
77 , css::lang::XInitialization
78 > OPropertyBrowserController_Base;
80 class OPropertyBrowserController
81 :public ::comphelper::OMutexAndBroadcastHelper
82 ,public OPropertyBrowserController_Base
83 ,public css::inspection::XObjectInspectorUI
84 // that's intentionally *not* part of the OPropertyBrowserController_Base
85 // We do not want this to be available in queryInterface, getTypes, and the like.
86 ,public IPropertyLineListener
87 ,public IPropertyControlObserver
88 ,public IPropertyExistenceCheck
90 private:
91 typedef std::multimap< sal_Int32, css::beans::Property > OrderedPropertyMap;
92 typedef std::vector< css::uno::Reference< css::uno::XInterface > >
93 InterfaceArray;
95 protected:
96 css::uno::Reference< css::uno::XComponentContext > m_xContext;
98 private:
99 css::uno::Reference< css::frame::XFrame > m_xFrame;
100 css::uno::Reference< css::awt::XWindow > m_xView;
102 ::comphelper::OInterfaceContainerHelper2 m_aDisposeListeners;
103 ::comphelper::OInterfaceContainerHelper2 m_aControlObservers;
104 // meta data about the properties
105 VclPtr<OPropertyBrowserView> m_pView;
107 OUString m_sPageSelection;
108 OUString m_sLastValidPageSelection;
110 typedef css::uno::Reference< css::inspection::XPropertyHandler >
111 PropertyHandlerRef;
112 typedef std::vector< PropertyHandlerRef > PropertyHandlerArray;
113 typedef std::unordered_map< OUString, PropertyHandlerRef >
114 PropertyHandlerRepository;
115 typedef std::unordered_multimap< OUString, PropertyHandlerRef >
116 PropertyHandlerMultiRepository;
117 PropertyHandlerRepository m_aPropertyHandlers;
118 PropertyHandlerMultiRepository m_aDependencyHandlers;
119 PropertyHandlerRef m_xInteractiveHandler;
121 std::unique_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer;
123 /// our InspectorModel
124 css::uno::Reference< css::inspection::XObjectInspectorModel >
125 m_xModel;
126 /// the object(s) we're currently inspecting
127 InterfaceArray m_aInspectedObjects;
128 /// the properties of the currently inspected object(s)
129 OrderedPropertyMap m_aProperties;
130 /// the property we're just committing
131 OUString m_sCommittingProperty;
133 typedef std::unordered_map< OUString, sal_uInt16 > HashString2Int16;
134 HashString2Int16 m_aPageIds;
136 bool m_bContainerFocusListening;
137 bool m_bSuspendingPropertyHandlers;
138 bool m_bConstructed;
139 bool m_bBindingIntrospectee;
141 protected:
142 DECLARE_XINTERFACE()
144 // XServiceInfo
145 virtual OUString SAL_CALL getImplementationName( ) override;
146 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
147 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
149 // XController
150 virtual void SAL_CALL attachFrame( const css::uno::Reference< css::frame::XFrame >& xFrame ) override;
151 virtual sal_Bool SAL_CALL attachModel( const css::uno::Reference< css::frame::XModel >& xModel ) override;
152 virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) override;
153 virtual css::uno::Any SAL_CALL getViewData( ) override;
154 virtual void SAL_CALL restoreViewData( const css::uno::Any& Data ) override;
155 virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel( ) override;
156 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame( ) override;
158 // XComponent
159 virtual void SAL_CALL dispose( ) override;
160 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
161 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
163 // XFocusListener
164 virtual void SAL_CALL focusGained( const css::awt::FocusEvent& _rSource ) override;
165 virtual void SAL_CALL focusLost( const css::awt::FocusEvent& _rSource ) override;
167 // XEventListener
168 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
170 // XLayoutConstrains
171 virtual css::awt::Size SAL_CALL getMinimumSize( ) override;
172 virtual css::awt::Size SAL_CALL getPreferredSize( ) override;
173 virtual css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override;
175 // XPropertyChangeListener
176 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& _rEvent ) override;
178 /** XPropertyControlFactory
180 virtual css::uno::Reference< css::inspection::XPropertyControl > SAL_CALL createPropertyControl( ::sal_Int16 ControlType, sal_Bool CreateReadOnly ) override;
182 public:
183 explicit OPropertyBrowserController(
184 const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
186 protected:
187 virtual ~OPropertyBrowserController() override;
189 public:
190 // XServiceInfo - static versions
191 /// @throws css::uno::RuntimeException
192 static OUString getImplementationName_static( );
193 /// @throws css::uno::RuntimeException
194 static css::uno::Sequence< OUString > getSupportedServiceNames_static( );
195 static css::uno::Reference< css::uno::XInterface >
196 Create(const css::uno::Reference< css::uno::XComponentContext >&);
198 protected:
199 // IPropertyLineListener
200 virtual void Clicked( const OUString& _rName, bool _bPrimary ) override;
201 virtual void Commit( const OUString& _rName, const css::uno::Any& _rVal ) override;
203 // IPropertyControlObserver
204 virtual void focusGained( const css::uno::Reference< css::inspection::XPropertyControl >& Control ) override;
205 virtual void valueChanged( const css::uno::Reference< css::inspection::XPropertyControl >& Control ) override;
207 // IPropertyExistenceCheck
208 virtual bool hasPropertyByName( const OUString& _rName ) override;
210 // XObjectInspectorUI
211 virtual void SAL_CALL enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) override;
212 virtual void SAL_CALL enablePropertyUIElements( const OUString& _rPropertyName, ::sal_Int16 _nElements, sal_Bool _bEnable ) override;
213 virtual void SAL_CALL rebuildPropertyUI( const OUString& _rPropertyName ) override;
214 virtual void SAL_CALL showPropertyUI( const OUString& _rPropertyName ) override;
215 virtual void SAL_CALL hidePropertyUI( const OUString& _rPropertyName ) override;
216 virtual void SAL_CALL showCategory( const OUString& _rCategory, sal_Bool _bShow ) override;
217 virtual css::uno::Reference< css::inspection::XPropertyControl > SAL_CALL getPropertyControl( const OUString& _rPropertyName ) override;
218 virtual void SAL_CALL registerControlObserver( const css::uno::Reference< css::inspection::XPropertyControlObserver >& Observer ) override;
219 virtual void SAL_CALL revokeControlObserver( const css::uno::Reference< css::inspection::XPropertyControlObserver >& Observer ) override;
220 virtual void SAL_CALL setHelpSectionText( const OUString& HelpText ) override;
222 // XObjectInspector
223 virtual css::uno::Reference< css::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() override;
224 virtual void SAL_CALL setInspectorModel( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _inspectormodel ) override;
225 virtual css::uno::Reference< css::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() override;
226 virtual void SAL_CALL inspect( const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > >& Objects ) override;
228 // XDispatchProvider
229 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch( const css::util::URL& URL, const OUString& TargetFrameName, ::sal_Int32 SearchFlags ) override;
230 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& Requests ) override;
232 // XInitialization
233 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
235 private:
236 void UpdateUI();
238 void startContainerWindowListening();
239 void stopContainerWindowListening();
241 // stop the inspection
242 void stopInspection( bool _bCommitModified );
244 bool haveView() const { return nullptr != m_pView; }
245 OPropertyEditor& getPropertyBox() { return m_pView->getPropertyBox(); }
247 // does the inspection of the objects as indicated by our model
248 void doInspection();
250 // bind the browser to m_xIntrospecteeAsProperty
251 void impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects );
253 /** retrieves special property handlers for our introspectee
255 void getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
257 /** called when a property changed, to broadcast any handlers which might have
258 registered for this property
260 @param _bFirstTimeInit
261 if set to <FALSE/>, this is a real change in the property value, not just a call
262 for purposes of initialization.
264 void impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const css::uno::Any& _rNewValue, const css::uno::Any& _rOldValue, bool _bFirstTimeInit ) const;
266 /** determines whether the given property is an actuating property, that is, at least one
267 handler expressed interest in changes to this property's value.
269 bool impl_isActuatingProperty_nothrow( const OUString& _rPropertyName ) const
271 return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
274 /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
275 @param _rPropertyName
276 the name whose handler is to be obtained. Must be the name of a property
277 for which a handler is registered.
278 @throws
279 RuntimeException if there is no handler for the given property
280 @return
281 the value of this property
283 css::uno::Any
284 impl_getPropertyValue_throw( const OUString& _rPropertyName );
286 /// calls XPropertyHandler::suspend for all our property handlers
287 bool suspendPropertyHandlers_nothrow( bool _bSuspend );
289 /// suspends the complete inspector
290 bool suspendAll_nothrow();
292 /** selects a page according to our current view data
294 void selectPageFromViewData();
296 /** updates our view data from the currently active page
298 void updateViewDataFromActivePage();
300 /// describes the UI for the given property
301 void describePropertyLine( const css::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor );
303 /** retrieves the position of the property given by name in m_aProperties
304 @return
305 <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
306 not <NULL/> contains the iterator pointing to this property.
308 bool impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = nullptr );
310 void Construct(vcl::Window* _pParentWin);
312 /** retrieves the property handler for a given property name
313 @param _rPropertyName
314 the name whose handler is to be obtained. Must be the name of a property
315 for which a handler is registered.
316 @throws
317 RuntimeException if there is no handler for the given property
318 @return
319 the handler which is responsible for the given property
321 PropertyHandlerRef const &
322 impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const;
324 /** determines whether we have a handler for the given property
325 @param _rPropertyName
326 the name of the property for which the existence of a handler should be checked
328 bool
329 impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const;
331 /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
332 respective tab pages into our view
333 @precond
334 m_aPageIds is empty
335 @throws css::uno::RuntimeException
336 if one of the callees of this method throws this exception
338 void
339 impl_buildCategories_throw();
341 /** retrieves the id of the tab page which represents a given category.
342 @param _rCategoryName
343 the programmatic name of a category.
344 @return
345 the id of the tab page, or <code>(sal_uInt16)-1</code> if there
346 is no tab page for the given category
348 sal_uInt16
349 impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const;
351 /** adds or removes ourself as XEventListener to/from all our inspectees
353 void impl_toggleInspecteeListening_nothrow( bool _bOn );
355 /** binds the instance to a new model
357 void impl_bindToNewModel_nothrow( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _rxInspectorModel );
359 /** initializes our view, as indicated by the model's view-relevant properties
361 It's allowed to call this method when no model exists, yet. In this case, nothing
362 happens.
364 void impl_initializeView_nothrow();
366 /** determines whether the view should be readonly.
368 Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
369 If there is no model, <FALSE/> is returned.
371 @throws css::uno::RuntimeException
372 in case asking the model for its IsReadOnly attribute throws a css::uno::RuntimeException
373 itself.
375 bool impl_isReadOnlyModel_throw() const;
377 /** starts or stops listening at the model
379 void impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
381 private:
382 DECL_LINK(OnPageActivation, LinkParamNone*, void);
384 private:
385 // constructors
386 void createWithModel( const css::uno::Reference< css::inspection::XObjectInspectorModel >& _rxModel );
390 } // namespace pcr
393 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_PROPCONTROLLER_HXX
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */