Line data Source code
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 : #ifndef _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
21 : #define _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
22 :
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"
31 :
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>
57 :
58 : #include <map>
59 : #include <boost/unordered_map.hpp>
60 : #include <vector>
61 : #include <memory>
62 :
63 : class Window;
64 :
65 : //............................................................................
66 : namespace pcr
67 : {
68 : //............................................................................
69 :
70 : class OPropertyEditor;
71 : struct OLineDescriptor;
72 :
73 : #if OSL_DEBUG_LEVEL > 0
74 : const char* CheckPropertyBrowserInvariants( const void* pVoid );
75 : // for dignostics with DBG_CHKTHIS
76 : #endif
77 : DBG_NAMEEX( OPropertyBrowserController )
78 :
79 : //========================================================================
80 : //= OPropertyBrowserController
81 : //========================================================================
82 : // #95343#------------------------------------------------------------------------------------
83 : typedef ::cppu::WeakImplHelper7 < ::com::sun::star::lang::XServiceInfo
84 : , ::com::sun::star::awt::XFocusListener
85 : , ::com::sun::star::awt::XLayoutConstrains
86 : , ::com::sun::star::beans::XPropertyChangeListener
87 : , ::com::sun::star::inspection::XPropertyControlFactory
88 : , ::com::sun::star::inspection::XObjectInspector
89 : , ::com::sun::star::lang::XInitialization
90 : > OPropertyBrowserController_Base;
91 :
92 : class OPropertyBrowserController
93 : :public ::comphelper::OMutexAndBroadcastHelper
94 : ,public OPropertyBrowserController_Base
95 : ,public ::com::sun::star::inspection::XObjectInspectorUI
96 : // that's intentionally *not* part of the OPropertyBrowserController_Base
97 : // We do not want this to be available in queryInterface, getTypes, and the like.
98 : ,public IPropertyLineListener
99 : ,public IPropertyControlObserver
100 : ,public IPropertyExistenceCheck
101 : {
102 : private:
103 : typedef ::std::multimap< sal_Int32, ::com::sun::star::beans::Property > OrderedPropertyMap;
104 : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >
105 : InterfaceArray;
106 :
107 : protected:
108 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
109 :
110 : private:
111 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
112 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xView;
113 :
114 : ::cppu::OInterfaceContainerHelper m_aDisposeListeners;
115 : ::cppu::OInterfaceContainerHelper m_aControlObservers;
116 : // meta data about the properties
117 : OPropertyBrowserView* m_pView;
118 :
119 : OUString m_sPageSelection;
120 : OUString m_sLastValidPageSelection;
121 :
122 : typedef ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >
123 : PropertyHandlerRef;
124 : typedef ::std::vector< PropertyHandlerRef > PropertyHandlerArray;
125 : typedef ::boost::unordered_map< OUString, PropertyHandlerRef, OUStringHash >
126 : PropertyHandlerRepository;
127 : typedef ::boost::unordered_multimap< OUString, PropertyHandlerRef, OUStringHash >
128 : PropertyHandlerMultiRepository;
129 : PropertyHandlerRepository m_aPropertyHandlers;
130 : PropertyHandlerMultiRepository m_aDependencyHandlers;
131 : PropertyHandlerRef m_xInteractiveHandler;
132 :
133 : ::std::auto_ptr< ComposedPropertyUIUpdate > m_pUIRequestComposer;
134 :
135 : /// our InspectorModel
136 : ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >
137 : m_xModel;
138 : /// the object(s) we're currently inspecting
139 : InterfaceArray m_aInspectedObjects;
140 : /// the properties of the currently inspected object(s)
141 : OrderedPropertyMap m_aProperties;
142 : /// the property we're just committing
143 : OUString m_sCommittingProperty;
144 :
145 : typedef ::boost::unordered_map< OUString, sal_uInt16, OUStringHash > HashString2Int16;
146 : HashString2Int16 m_aPageIds;
147 :
148 : bool m_bContainerFocusListening;
149 : bool m_bSuspendingPropertyHandlers;
150 : bool m_bConstructed;
151 : bool m_bBindingIntrospectee;
152 :
153 : protected:
154 : DECLARE_XINTERFACE()
155 :
156 : // XServiceInfo
157 : virtual OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
158 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
159 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
160 :
161 : // XController
162 : virtual void SAL_CALL attachFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) throw(::com::sun::star::uno::RuntimeException);
163 : virtual sal_Bool SAL_CALL attachModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ) throw(::com::sun::star::uno::RuntimeException);
164 : virtual sal_Bool SAL_CALL suspend( sal_Bool bSuspend ) throw(::com::sun::star::uno::RuntimeException);
165 : virtual ::com::sun::star::uno::Any SAL_CALL getViewData( ) throw(::com::sun::star::uno::RuntimeException);
166 : virtual void SAL_CALL restoreViewData( const ::com::sun::star::uno::Any& Data ) throw(::com::sun::star::uno::RuntimeException);
167 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel( ) throw(::com::sun::star::uno::RuntimeException);
168 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL getFrame( ) throw(::com::sun::star::uno::RuntimeException);
169 :
170 : // XComponent
171 : virtual void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException);
172 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
173 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
174 :
175 : // XFocusListener
176 : virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
177 : virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
178 :
179 : // XEventListener
180 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
181 :
182 : // XLayoutConstrains #95343# ----------------
183 : virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize( ) throw (::com::sun::star::uno::RuntimeException);
184 : virtual ::com::sun::star::awt::Size SAL_CALL getPreferredSize( ) throw (::com::sun::star::uno::RuntimeException);
185 : virtual ::com::sun::star::awt::Size SAL_CALL calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (::com::sun::star::uno::RuntimeException);
186 :
187 : // XPropertyChangeListener
188 : virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
189 :
190 : /** XPropertyControlFactory
191 : */
192 : 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);
193 :
194 : public:
195 : OPropertyBrowserController(
196 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
197 :
198 : protected:
199 : virtual ~OPropertyBrowserController();
200 :
201 : public:
202 : // XServiceInfo - static versions
203 : static OUString getImplementationName_static( ) throw(::com::sun::star::uno::RuntimeException);
204 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_static( ) throw(::com::sun::star::uno::RuntimeException);
205 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
206 : Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
207 :
208 : protected:
209 : // IPropertyLineListener
210 : virtual void Clicked( const OUString& _rName, sal_Bool _bPrimary );
211 : virtual void Commit( const OUString& _rName, const ::com::sun::star::uno::Any& _rVal );
212 :
213 : // IPropertyControlObserver
214 : virtual void focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
215 : virtual void valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _Control );
216 :
217 : // IPropertyExistenceCheck
218 : virtual ::sal_Bool SAL_CALL hasPropertyByName( const OUString& _rName ) throw (::com::sun::star::uno::RuntimeException);
219 :
220 : // XObjectInspectorUI
221 : virtual void SAL_CALL enablePropertyUI( const OUString& _rPropertyName, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
222 : virtual void SAL_CALL enablePropertyUIElements( const OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable ) throw (::com::sun::star::uno::RuntimeException);
223 : virtual void SAL_CALL rebuildPropertyUI( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
224 : virtual void SAL_CALL showPropertyUI( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
225 : virtual void SAL_CALL hidePropertyUI( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
226 : virtual void SAL_CALL showCategory( const OUString& _rCategory, ::sal_Bool _bShow ) throw (::com::sun::star::uno::RuntimeException);
227 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > SAL_CALL getPropertyControl( const OUString& _rPropertyName ) throw (::com::sun::star::uno::RuntimeException);
228 : virtual void SAL_CALL registerControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
229 : virtual void SAL_CALL revokeControlObserver( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlObserver >& _Observer ) throw (::com::sun::star::uno::RuntimeException);
230 : virtual void SAL_CALL setHelpSectionText( const OUString& HelpText ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
231 :
232 : // XObjectInspector
233 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel > SAL_CALL getInspectorModel() throw (::com::sun::star::uno::RuntimeException);
234 : virtual void SAL_CALL setInspectorModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _inspectormodel ) throw (::com::sun::star::uno::RuntimeException);
235 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > SAL_CALL getInspectorUI() throw (::com::sun::star::uno::RuntimeException);
236 : 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);
237 :
238 : // XDispatchProvider
239 : 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);
240 : 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);
241 :
242 : // XInitialization
243 : 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);
244 :
245 : private:
246 : void UpdateUI();
247 :
248 : void startContainerWindowListening();
249 : void stopContainerWindowListening();
250 :
251 : // stop the inspection
252 : void stopInspection( bool _bCommitModified );
253 :
254 52 : sal_Bool haveView() const { return NULL != m_pView; }
255 22 : OPropertyEditor& getPropertyBox() { return m_pView->getPropertyBox(); }
256 :
257 : // does the inspection of the objects as indicated by our model
258 : void doInspection();
259 :
260 : // bind the browser to m_xIntrospecteeAsProperty
261 : void impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects );
262 :
263 : /** retrieves special property handlers for our introspectee
264 : */
265 : void getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers );
266 :
267 : /** called when a property changed, to broadcast any handlers which might have
268 : registered for this property
269 :
270 : @param _bFirstTimeInit
271 : if set to <FALSE/>, this is a real change in the property value, not just a call
272 : for purposes of initialization.
273 : */
274 : void impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rNewValue, const ::com::sun::star::uno::Any& _rOldValue, bool _bFirstTimeInit ) const;
275 :
276 : /** determines whether the given property is an actuating property, that is, at least one
277 : handler expressed interest in changes to this property's value.
278 : */
279 0 : inline bool impl_isActuatingProperty_nothrow( const OUString& _rPropertyName ) const
280 : {
281 0 : return ( m_aDependencyHandlers.find( _rPropertyName ) != m_aDependencyHandlers.end() );
282 : }
283 :
284 : sal_uInt32 GetPropertyPos(const OUString& _rPropName);
285 :
286 : /** retrieves the value of the given property, by asking the appropriate XPropertyHandler
287 : @param _rPropertyName
288 : the name whose handler is to be obtained. Must be the name of a property
289 : for which a handler is registered.
290 : @throws
291 : RuntimeException if there is no handler for the given property
292 : @return
293 : the value of this property
294 : */
295 : ::com::sun::star::uno::Any
296 : impl_getPropertyValue_throw( const OUString& _rPropertyName );
297 :
298 : /// calls XPropertyHandler::suspend for all our property handlers
299 : sal_Bool suspendPropertyHandlers_nothrow( sal_Bool _bSuspend );
300 :
301 : /// suspends the complete inspector
302 : sal_Bool suspendAll_nothrow();
303 :
304 : /** selects a page according to our current view data
305 : */
306 : void selectPageFromViewData();
307 :
308 : /** updates our view data from the currently active page
309 : */
310 : void updateViewDataFromActivePage();
311 :
312 : /// describes the UI for the given property
313 : void describePropertyLine( const ::com::sun::star::beans::Property& _rPropertyName, OLineDescriptor& _rDescriptor )
314 : SAL_THROW((::com::sun::star::uno::Exception));
315 :
316 : /** retrieves the position of the property given by name in m_aProperties
317 : @return
318 : <TRUE/> if and only if the property could be found. In this case, <arg>_pProperty</arg> (if
319 : not <NULL/> contains the iterator pointing to this property.
320 : */
321 : bool impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty = NULL );
322 :
323 : sal_Bool Construct(Window* _pParentWin);
324 :
325 : /** retrieves the property handler for a given property name
326 : @param _rPropertyName
327 : the name whose handler is to be obtained. Must be the name of a property
328 : for which a handler is registered.
329 : @throws
330 : RuntimeException if there is no handler for the given property
331 : @return
332 : the handler which is responsible for the given property
333 : */
334 : PropertyHandlerRef
335 : impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const;
336 :
337 : /** determines whether we have a handler for the given property
338 : @param _rPropertyName
339 : the name of the property for which the existence of a handler should be checked
340 : */
341 : bool
342 : impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const;
343 :
344 : /** builds up m_aPageIds from InspectorModel::describeCategories, and insert all the
345 : respective tab pages into our view
346 : @precond
347 : m_aPageIds is empty
348 : @throws ::com::sun::star::uno::RuntimeException
349 : if one of the callees of this method throws this exception
350 : */
351 : void
352 : impl_buildCategories_throw();
353 :
354 : /** retrieves the id of the tab page which represents a given category.
355 : @param _rCategoryName
356 : the programmatic name of a category.
357 : @return
358 : the id of the tab page, or <code>(sal_uInt16)-1</code> if there
359 : is no tab page for the given category
360 : */
361 : sal_uInt16
362 : impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const;
363 :
364 : /** adds or removes ourself as XEventListener to/from all our inspectees
365 : */
366 : void impl_toggleInspecteeListening_nothrow( bool _bOn );
367 :
368 : /** binds the instance to a new model
369 : */
370 : void impl_bindToNewModel_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxInspectorModel );
371 :
372 : /** initializes our view, as indicated by the model's view-relevant properties
373 :
374 : It's allowed to call this method when no model exists, yet. In this case, nothing
375 : happens.
376 : */
377 : void impl_initializeView_nothrow();
378 :
379 : /** determines whether the view should be readonly.
380 :
381 : Effectively, this means that the method simply checks the IsReadOnly attribute of the model.
382 : If there is no model, <FALSE/> is returned.
383 :
384 : @throws ::com::sun::star::uno::RuntimeException
385 : in case asking the model for its IsReadOnly attribute throws a ::com::sun::star::uno::RuntimeException
386 : itself.
387 : */
388 : bool impl_isReadOnlyModel_throw() const;
389 :
390 : /** updates our view so that it is read-only, as indicated by the model property
391 : @see impl_isReadOnlyModel_throw
392 : */
393 : void impl_updateReadOnlyView_nothrow();
394 :
395 : /** starts or stops listening at the model
396 : */
397 : void impl_startOrStopModelListening_nothrow( bool _bDoListen ) const;
398 :
399 : private:
400 : DECL_LINK(OnPageActivation, void*);
401 :
402 : private:
403 : // constructors
404 : void createDefault();
405 : void createWithModel( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorModel >& _rxModel );
406 : };
407 :
408 : //............................................................................
409 : } // namespace pcr
410 : //............................................................................
411 :
412 : #endif // _EXTENSIONS_PROPCTRLR_PROPCONTROLLER_HXX_
413 :
414 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|