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