1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "propcontroller.hxx"
30 #include "pcrstrings.hxx"
31 #include "standardcontrol.hxx"
32 #include "linedescriptor.hxx"
33 #include "propresid.hrc"
34 #include "formresid.hrc"
35 #include "propertyeditor.hxx"
36 #include "modulepcr.hxx"
37 #include "formstrings.hxx"
38 #include "formmetadata.hxx"
39 #include "formbrowsertools.hxx"
40 #include "propertycomposer.hxx"
42 /** === begin UNO includes === **/
43 #include <com/sun/star/awt/XWindow.hpp>
44 #include <com/sun/star/util/XCloseable.hpp>
45 #include <com/sun/star/inspection/PropertyControlType.hpp>
46 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
47 /** === end UNO includes === **/
48 #include <tools/debug.hxx>
49 #include <tools/diagnose_ex.h>
50 #include <comphelper/types.hxx>
51 #include <comphelper/extract.hxx>
52 #include <toolkit/awt/vclxwindow.hxx>
53 #include <toolkit/unohlp.hxx>
54 #include <comphelper/property.hxx>
55 #include <vcl/msgbox.hxx>
56 #include <vcl/svapp.hxx>
57 #include <osl/mutex.hxx>
58 #include <cppuhelper/component_context.hxx>
59 #include <cppuhelper/exc_hlp.hxx>
63 #include <sal/macros.h>
65 //------------------------------------------------------------------------
66 // !!! outside the namespace !!!
67 extern "C" void SAL_CALL
createRegistryInfo_OPropertyBrowserController()
69 ::pcr::OAutoRegistration
< ::pcr::OPropertyBrowserController
> aAutoRegistration
;
72 //............................................................................
75 //............................................................................
77 using namespace ::com::sun::star
;
78 using namespace ::com::sun::star::uno
;
79 using namespace ::com::sun::star::awt
;
80 using namespace ::com::sun::star::form
;
81 using namespace ::com::sun::star::beans
;
82 using namespace ::com::sun::star::script
;
83 using namespace ::com::sun::star::lang
;
84 using namespace ::com::sun::star::container
;
85 using namespace ::com::sun::star::frame
;
86 using namespace ::com::sun::star::util
;
87 using namespace ::com::sun::star::inspection
;
88 using namespace ::com::sun::star::ucb
;
89 using namespace ::comphelper
;
91 #define THISREF() static_cast< XController* >(this)
93 //========================================================================
94 //= OPropertyBrowserController
95 //========================================================================
96 DBG_NAME(OPropertyBrowserController
)
97 //------------------------------------------------------------------------
98 OPropertyBrowserController::OPropertyBrowserController( const Reference
< XComponentContext
>& _rxContext
)
99 :m_aContext(_rxContext
)
100 ,m_aDisposeListeners( m_aMutex
)
101 ,m_aControlObservers( m_aMutex
)
103 ,m_bContainerFocusListening( false )
104 ,m_bSuspendingPropertyHandlers( false )
105 ,m_bConstructed( false )
106 ,m_bBindingIntrospectee( false )
108 DBG_CTOR(OPropertyBrowserController
,NULL
);
111 //------------------------------------------------------------------------
112 OPropertyBrowserController::~OPropertyBrowserController()
114 // stop listening for property changes
116 stopInspection( true );
117 DBG_DTOR(OPropertyBrowserController
,NULL
);
120 //------------------------------------------------------------------------
121 IMPLEMENT_FORWARD_REFCOUNT( OPropertyBrowserController
, OPropertyBrowserController_Base
)
123 //------------------------------------------------------------------------
124 Any SAL_CALL
OPropertyBrowserController::queryInterface( const Type
& _rType
) throw (RuntimeException
)
126 Any aReturn
= OPropertyBrowserController_Base::queryInterface( _rType
);
127 if ( !aReturn
.hasValue() )
128 aReturn
= ::cppu::queryInterface(
130 static_cast< XObjectInspectorUI
* >( this )
135 //------------------------------------------------------------------------
136 void OPropertyBrowserController::startContainerWindowListening()
138 if (m_bContainerFocusListening
)
143 Reference
< XWindow
> xContainerWindow
= m_xFrame
->getContainerWindow();
144 if (xContainerWindow
.is())
146 xContainerWindow
->addFocusListener(this);
147 m_bContainerFocusListening
= sal_True
;
151 DBG_ASSERT(m_bContainerFocusListening
, "OPropertyBrowserController::startContainerWindowListening: unable to start listening (inconsistence)!");
154 //------------------------------------------------------------------------
155 void OPropertyBrowserController::stopContainerWindowListening()
157 if (!m_bContainerFocusListening
)
162 Reference
< XWindow
> xContainerWindow
= m_xFrame
->getContainerWindow();
163 if (xContainerWindow
.is())
165 xContainerWindow
->removeFocusListener(this);
166 m_bContainerFocusListening
= sal_False
;
170 DBG_ASSERT(!m_bContainerFocusListening
, "OPropertyBrowserController::stopContainerWindowListening: unable to stop listening (inconsistence)!");
173 //--------------------------------------------------------------------
174 Reference
< XObjectInspectorModel
> SAL_CALL
OPropertyBrowserController::getInspectorModel() throw (RuntimeException
)
179 //--------------------------------------------------------------------
180 void OPropertyBrowserController::impl_initializeView_nothrow()
182 OSL_PRECOND( haveView(), "OPropertyBrowserController::impl_initializeView_nothrow: not to be called when we have no view!" );
186 if ( !m_xModel
.is() )
192 getPropertyBox().EnableHelpSection( m_xModel
->getHasHelpSection() );
193 getPropertyBox().SetHelpLineLimites( m_xModel
->getMinHelpTextLines(), m_xModel
->getMaxHelpTextLines() );
195 catch( const Exception
& )
197 DBG_UNHANDLED_EXCEPTION();
201 //--------------------------------------------------------------------
202 void OPropertyBrowserController::impl_updateReadOnlyView_nothrow()
204 // this is a huge cudgel, admitted.
205 // The problem is that in case we were previously read-only, all our controls
206 // were created read-only, too. We cannot simply switch them to not-read-only.
207 // Even if they had an API for this, we do not know whether they were
208 // originally created read-only, or if they are read-only just because
210 impl_rebindToInspectee_nothrow( m_aInspectedObjects
);
213 //--------------------------------------------------------------------
214 bool OPropertyBrowserController::impl_isReadOnlyModel_throw() const
216 if ( !m_xModel
.is() )
219 return m_xModel
->getIsReadOnly();
222 //--------------------------------------------------------------------
223 void OPropertyBrowserController::impl_startOrStopModelListening_nothrow( bool _bDoListen
) const
227 Reference
< XPropertySet
> xModelProperties( m_xModel
, UNO_QUERY
);
228 if ( !xModelProperties
.is() )
229 // okay, so the model doesn't want to change its properties
230 // dynamically - fine with us
233 void (SAL_CALL
XPropertySet::*pListenerOperation
)( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& )
234 = _bDoListen
? &XPropertySet::addPropertyChangeListener
: &XPropertySet::removePropertyChangeListener
;
236 (xModelProperties
.get()->*pListenerOperation
)(
237 ::rtl::OUString( "IsReadOnly" ),
238 const_cast< OPropertyBrowserController
* >( this )
241 catch( const Exception
& )
243 DBG_UNHANDLED_EXCEPTION();
247 //--------------------------------------------------------------------
248 void OPropertyBrowserController::impl_bindToNewModel_nothrow( const Reference
< XObjectInspectorModel
>& _rxInspectorModel
)
250 impl_startOrStopModelListening_nothrow( false );
251 m_xModel
= _rxInspectorModel
;
252 impl_startOrStopModelListening_nothrow( true );
254 // initialize the view, if we already have one
256 impl_initializeView_nothrow();
258 // inspect again, if we already have inspectees
259 if ( !m_aInspectedObjects
.empty() )
260 impl_rebindToInspectee_nothrow( m_aInspectedObjects
);
263 //--------------------------------------------------------------------
264 void SAL_CALL
OPropertyBrowserController::setInspectorModel( const Reference
< XObjectInspectorModel
>& _inspectorModel
) throw (RuntimeException
)
266 ::osl::MutexGuard
aGuard( m_aMutex
);
268 if ( m_xModel
== _inspectorModel
)
271 impl_bindToNewModel_nothrow( _inspectorModel
);
274 //--------------------------------------------------------------------
275 Reference
< XObjectInspectorUI
> SAL_CALL
OPropertyBrowserController::getInspectorUI() throw (RuntimeException
)
277 // we're derived from this interface, though we do not expose it in queryInterface and getTypes.
281 //--------------------------------------------------------------------
282 void SAL_CALL
OPropertyBrowserController::inspect( const Sequence
< Reference
< XInterface
> >& _rObjects
) throw (com::sun::star::util::VetoException
, RuntimeException
)
284 SolarMutexGuard aSolarGuard
;
285 ::osl::MutexGuard
aGuard( m_aMutex
);
287 if ( m_bSuspendingPropertyHandlers
|| !suspendAll_nothrow() )
288 { // we already are trying to suspend the component (this is somewhere up the stack)
289 // OR one of our property handlers raised a veto against closing. Well, we *need* to close
290 // it in order to inspect another object.
291 throw VetoException();
293 if ( m_bBindingIntrospectee
)
294 throw VetoException();
296 m_bBindingIntrospectee
= true;
297 impl_rebindToInspectee_nothrow( InterfaceArray( _rObjects
.getConstArray(), _rObjects
.getConstArray() + _rObjects
.getLength() ) );
298 m_bBindingIntrospectee
= false;
302 //--------------------------------------------------------------------
303 Reference
< XDispatch
> SAL_CALL
OPropertyBrowserController::queryDispatch( const URL
& /*URL*/, const ::rtl::OUString
& /*TargetFrameName*/, ::sal_Int32
/*SearchFlags*/ ) throw (RuntimeException
)
305 // we don't have any dispatches at all, right now
306 return Reference
< XDispatch
>();
309 //--------------------------------------------------------------------
310 Sequence
< Reference
< XDispatch
> > SAL_CALL
OPropertyBrowserController::queryDispatches( const Sequence
< DispatchDescriptor
>& Requests
) throw (RuntimeException
)
312 Sequence
< Reference
< XDispatch
> > aReturn
;
313 sal_Int32 nLen
= Requests
.getLength();
314 aReturn
.realloc( nLen
);
316 Reference
< XDispatch
>* pReturn
= aReturn
.getArray();
317 const Reference
< XDispatch
>* pReturnEnd
= aReturn
.getArray() + nLen
;
318 const DispatchDescriptor
* pDescripts
= Requests
.getConstArray();
320 for ( ; pReturn
!= pReturnEnd
; ++ pReturn
, ++pDescripts
)
321 *pReturn
= queryDispatch( pDescripts
->FeatureURL
, pDescripts
->FrameName
, pDescripts
->SearchFlags
);
326 //------------------------------------------------------------------------
327 void SAL_CALL
OPropertyBrowserController::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
)
329 if ( m_bConstructed
)
330 throw AlreadyInitializedException();
332 StlSyntaxSequence
< Any
> arguments( _arguments
);
333 if ( arguments
.empty() )
334 { // constructor: "createDefault()"
339 Reference
< XObjectInspectorModel
> xModel
;
340 if ( arguments
.size() == 1 )
341 { // constructor: "createWithModel( XObjectInspectorModel )"
342 if ( !( arguments
[0] >>= xModel
) )
343 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 );
344 createWithModel( xModel
);
348 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 );
351 //------------------------------------------------------------------------
352 void OPropertyBrowserController::createDefault()
354 m_bConstructed
= true;
357 //------------------------------------------------------------------------
358 void OPropertyBrowserController::createWithModel( const Reference
< XObjectInspectorModel
>& _rxModel
)
360 osl_incrementInterlockedCount( &m_refCount
);
362 setInspectorModel( _rxModel
);
364 osl_decrementInterlockedCount( &m_refCount
);
366 m_bConstructed
= true;
369 //------------------------------------------------------------------------
370 void SAL_CALL
OPropertyBrowserController::attachFrame( const Reference
< XFrame
>& _rxFrame
) throw(RuntimeException
)
372 SolarMutexGuard aSolarGuard
;
373 ::osl::MutexGuard
aGuard( m_aMutex
);
375 if (_rxFrame
.is() && haveView())
376 throw RuntimeException(::rtl::OUString("Unable to attach to a second frame."),*this);
378 // revoke as focus listener from the old container window
379 stopContainerWindowListening();
385 // TODO: this construction perhaps should be done outside. Don't know the exact meaning of attachFrame.
386 // Maybe it is intended to only announce the frame to the controller, and the instance doing this
387 // announcement is responsible for calling setComponent, too.
388 Reference
< XWindow
> xContainerWindow
= m_xFrame
->getContainerWindow();
389 VCLXWindow
* pContainerWindow
= VCLXWindow::GetImplementation(xContainerWindow
);
390 Window
* pParentWin
= pContainerWindow
? pContainerWindow
->GetWindow() : NULL
;
392 throw RuntimeException(::rtl::OUString("The frame is invalid. Unable to extract the container window."),*this);
394 if ( Construct( pParentWin
) )
398 m_xFrame
->setComponent( VCLUnoHelper::GetInterface( m_pView
), this );
400 catch( const Exception
& )
402 OSL_FAIL( "OPropertyBrowserController::attachFrame: caught an exception!" );
406 startContainerWindowListening();
411 //------------------------------------------------------------------------
412 sal_Bool SAL_CALL
OPropertyBrowserController::attachModel( const Reference
< XModel
>& _rxModel
) throw(RuntimeException
)
414 Reference
< XObjectInspectorModel
> xModel( _rxModel
, UNO_QUERY
);
418 setInspectorModel( xModel
);
419 return getInspectorModel() == _rxModel
;
422 //------------------------------------------------------------------------
423 sal_Bool
OPropertyBrowserController::suspendAll_nothrow()
425 // if there is a handle inside its "onInteractivePropertySelection" method,
427 // Normally, we could expect every handler to do this itself, but being
428 // realistic, it's safer to handle this here in general.
429 if ( m_xInteractiveHandler
.is() )
432 m_bSuspendingPropertyHandlers
= true;
433 sal_Bool bHandlerVeto
= !suspendPropertyHandlers_nothrow( sal_True
);
434 m_bSuspendingPropertyHandlers
= false;
441 //------------------------------------------------------------------------
442 sal_Bool
OPropertyBrowserController::suspendPropertyHandlers_nothrow( sal_Bool _bSuspend
)
444 PropertyHandlerArray aAllHandlers
; // will contain every handler exactly once
445 for ( PropertyHandlerRepository::const_iterator handler
= m_aPropertyHandlers
.begin();
446 handler
!= m_aPropertyHandlers
.end();
450 if ( ::std::find( aAllHandlers
.begin(), aAllHandlers
.end(), handler
->second
) != aAllHandlers
.end() )
451 // already visited this particular handler (m_aPropertyHandlers usually contains
452 // the same handler more than once)
454 aAllHandlers
.push_back( handler
->second
);
457 for ( PropertyHandlerArray::iterator loop
= aAllHandlers
.begin();
458 loop
!= aAllHandlers
.end();
464 if ( !(*loop
)->suspend( _bSuspend
) )
466 // if we're not suspending, but reactivating, ignore the error
469 catch( const Exception
& )
471 OSL_FAIL( "OPropertyBrowserController::suspendPropertyHandlers_nothrow: caught an exception!" );
477 //------------------------------------------------------------------------
478 sal_Bool SAL_CALL
OPropertyBrowserController::suspend( sal_Bool _bSuspend
) throw(RuntimeException
)
480 ::osl::MutexGuard
aGuard( m_aMutex
);
481 OSL_ENSURE( haveView(), "OPropertyBrowserController::suspend: don't have a view anymore!" );
484 { // this means a "suspend" is to be "revoked"
485 suspendPropertyHandlers_nothrow( sal_False
);
486 // we ourself cannot revoke our suspend
490 if ( !suspendAll_nothrow() )
493 // commit the editor's content
495 getPropertyBox().CommitModified();
498 stopContainerWindowListening();
504 //------------------------------------------------------------------------
505 Any SAL_CALL
OPropertyBrowserController::getViewData( ) throw(RuntimeException
)
507 return makeAny( m_sPageSelection
);
510 //------------------------------------------------------------------------
511 void SAL_CALL
OPropertyBrowserController::restoreViewData( const Any
& Data
) throw(RuntimeException
)
513 ::rtl::OUString sPageSelection
;
514 if ( ( Data
>>= sPageSelection
) && !sPageSelection
.isEmpty() )
516 m_sPageSelection
= sPageSelection
;
517 selectPageFromViewData();
521 //------------------------------------------------------------------------
522 Reference
< XModel
> SAL_CALL
OPropertyBrowserController::getModel( ) throw(RuntimeException
)
525 return Reference
< XModel
>();
528 //------------------------------------------------------------------------
529 Reference
< XFrame
> SAL_CALL
OPropertyBrowserController::getFrame( ) throw(RuntimeException
)
534 //------------------------------------------------------------------------
535 void SAL_CALL
OPropertyBrowserController::dispose( ) throw(RuntimeException
)
537 SolarMutexGuard aSolarGuard
;
539 // stop inspecting the current object
540 stopInspection( false );
542 // say our dispose listeners goodbye
543 ::com::sun::star::lang::EventObject aEvt
;
544 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >(this);
545 m_aDisposeListeners
.disposeAndClear(aEvt
);
546 m_aControlObservers
.disposeAndClear(aEvt
);
548 // don't delete explicitly (this is done by the frame we reside in)
551 Reference
< XComponent
> xViewAsComp( m_xView
, UNO_QUERY
);
552 if ( xViewAsComp
.is() )
553 xViewAsComp
->removeEventListener( static_cast< XPropertyChangeListener
* >( this ) );
556 m_aInspectedObjects
.clear();
557 impl_bindToNewModel_nothrow( NULL
);
560 //------------------------------------------------------------------------
561 void SAL_CALL
OPropertyBrowserController::addEventListener( const Reference
< XEventListener
>& _rxListener
) throw(RuntimeException
)
563 m_aDisposeListeners
.addInterface(_rxListener
);
566 //------------------------------------------------------------------------
567 void SAL_CALL
OPropertyBrowserController::removeEventListener( const Reference
< XEventListener
>& _rxListener
) throw(RuntimeException
)
569 m_aDisposeListeners
.removeInterface(_rxListener
);
572 //------------------------------------------------------------------------
573 ::rtl::OUString SAL_CALL
OPropertyBrowserController::getImplementationName( ) throw(RuntimeException
)
575 return getImplementationName_static();
578 //------------------------------------------------------------------------
579 sal_Bool SAL_CALL
OPropertyBrowserController::supportsService( const ::rtl::OUString
& ServiceName
) throw(RuntimeException
)
581 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
582 const ::rtl::OUString
* pArray
= aSupported
.getConstArray();
583 for (sal_Int32 i
= 0; i
< aSupported
.getLength(); ++i
, ++pArray
)
584 if (pArray
->equals(ServiceName
))
589 //------------------------------------------------------------------------
590 Sequence
< ::rtl::OUString
> SAL_CALL
OPropertyBrowserController::getSupportedServiceNames( ) throw(RuntimeException
)
592 return getSupportedServiceNames_static();
595 //------------------------------------------------------------------------
596 ::rtl::OUString
OPropertyBrowserController::getImplementationName_static( ) throw(RuntimeException
)
598 return ::rtl::OUString("org.openoffice.comp.extensions.ObjectInspector");
601 //------------------------------------------------------------------------
602 Sequence
< ::rtl::OUString
> OPropertyBrowserController::getSupportedServiceNames_static( ) throw(RuntimeException
)
604 Sequence
< ::rtl::OUString
> aSupported(1);
605 aSupported
[0] = ::rtl::OUString("com.sun.star.inspection.ObjectInspector");
609 //------------------------------------------------------------------------
610 Reference
< XInterface
> SAL_CALL
OPropertyBrowserController::Create(const Reference
< XComponentContext
>& _rxContext
)
612 return *(new OPropertyBrowserController( _rxContext
) );
615 //------------------------------------------------------------------------
616 void SAL_CALL
OPropertyBrowserController::focusGained( const FocusEvent
& _rSource
) throw (RuntimeException
)
618 Reference
< XWindow
> xSourceWindow(_rSource
.Source
, UNO_QUERY
);
619 Reference
< XWindow
> xContainerWindow
;
621 xContainerWindow
= m_xFrame
->getContainerWindow();
623 if ( xContainerWindow
.get() == xSourceWindow
.get() )
624 { // our container window got the focus
626 getPropertyBox().GrabFocus();
630 //------------------------------------------------------------------------
631 void SAL_CALL
OPropertyBrowserController::focusLost( const FocusEvent
& /*_rSource*/ ) throw (RuntimeException
)
636 //------------------------------------------------------------------------
637 void SAL_CALL
OPropertyBrowserController::disposing( const EventObject
& _rSource
) throw(RuntimeException
)
639 if ( m_xView
.is() && ( m_xView
== _rSource
.Source
) )
645 for ( InterfaceArray::iterator loop
= m_aInspectedObjects
.begin();
646 loop
!= m_aInspectedObjects
.end();
650 if ( *loop
== _rSource
.Source
)
652 m_aInspectedObjects
.erase( loop
);
658 //------------------------------------------------------------------------
659 IMPL_LINK_NOARG(OPropertyBrowserController
, OnPageActivation
)
661 updateViewDataFromActivePage();
665 //------------------------------------------------------------------------
666 void OPropertyBrowserController::updateViewDataFromActivePage()
671 ::rtl::OUString sOldSelection
= m_sPageSelection
;
672 m_sPageSelection
= ::rtl::OUString();
674 const sal_uInt16 nCurrentPage
= m_pView
->getActivaPage();
675 if ( (sal_uInt16
)-1 != nCurrentPage
)
677 for ( HashString2Int16::const_iterator pageId
= m_aPageIds
.begin();
678 pageId
!= m_aPageIds
.end();
682 if ( nCurrentPage
== pageId
->second
)
684 m_sPageSelection
= pageId
->first
;
690 if ( !m_sPageSelection
.isEmpty() )
691 m_sLastValidPageSelection
= m_sPageSelection
;
692 else if ( !sOldSelection
.isEmpty() )
693 m_sLastValidPageSelection
= sOldSelection
;
696 //------------------------------------------------------------------------
697 sal_uInt16
OPropertyBrowserController::impl_getPageIdForCategory_nothrow( const ::rtl::OUString
& _rCategoryName
) const
699 sal_uInt16 nPageId
= (sal_uInt16
)-1;
700 HashString2Int16::const_iterator pagePos
= m_aPageIds
.find( _rCategoryName
);
701 if ( pagePos
!= m_aPageIds
.end() )
702 nPageId
= pagePos
->second
;
706 //------------------------------------------------------------------------
707 void OPropertyBrowserController::selectPageFromViewData()
709 sal_uInt16 nNewPage
= impl_getPageIdForCategory_nothrow( m_sPageSelection
);
711 if ( haveView() && ( nNewPage
!= (sal_uInt16
)-1 ) )
712 m_pView
->activatePage( nNewPage
);
715 updateViewDataFromActivePage();
718 //------------------------------------------------------------------------
719 sal_Bool
OPropertyBrowserController::Construct(Window
* _pParentWin
)
721 DBG_ASSERT(!haveView(), "OPropertyBrowserController::Construct: already have a view!");
722 DBG_ASSERT(_pParentWin
, "OPropertyBrowserController::Construct: invalid parent window!");
724 m_pView
= new OPropertyBrowserView(m_aContext
.getLegacyServiceFactory(), _pParentWin
);
725 m_pView
->setPageActivationHandler(LINK(this, OPropertyBrowserController
, OnPageActivation
));
727 // add as dispose listener for our view. The view is disposed by the frame we're plugged into,
728 // and this disposal _deletes_ the view, so it would be deadly if we use our m_pView member
730 m_xView
= VCLUnoHelper::GetInterface(m_pView
);
731 Reference
< XComponent
> xViewAsComp(m_xView
, UNO_QUERY
);
732 if (xViewAsComp
.is())
733 xViewAsComp
->addEventListener( static_cast< XPropertyChangeListener
* >( this ) );
735 getPropertyBox().SetLineListener(this);
736 getPropertyBox().SetControlObserver(this);
737 impl_initializeView_nothrow();
744 //------------------------------------------------------------------------
745 void SAL_CALL
OPropertyBrowserController::propertyChange( const PropertyChangeEvent
& _rEvent
) throw (RuntimeException
)
747 if ( _rEvent
.Source
== m_xModel
)
749 if ( _rEvent
.PropertyName
== "IsReadOnly" )
750 impl_updateReadOnlyView_nothrow();
754 if ( m_sCommittingProperty
== _rEvent
.PropertyName
)
760 Any
aNewValue( _rEvent
.NewValue
);
761 if ( impl_hasPropertyHandlerFor_nothrow( _rEvent
.PropertyName
) )
763 // forward the new value to the property box, to reflect the change in the UI
764 aNewValue
= impl_getPropertyValue_throw( _rEvent
.PropertyName
);
766 // check whether the state is ambiguous. This is interesting in case we display the properties
767 // for multiple objects at once: In this case, we'll get a notification from one of the objects,
768 // but need to care for the "composed" value, which can be "ambiguous".
769 PropertyHandlerRef
xHandler( impl_getHandlerForProperty_throw( _rEvent
.PropertyName
), UNO_SET_THROW
);
770 PropertyState
ePropertyState( xHandler
->getPropertyState( _rEvent
.PropertyName
) );
771 bool bAmbiguousValue
= ( PropertyState_AMBIGUOUS_VALUE
== ePropertyState
);
773 getPropertyBox().SetPropertyValue( _rEvent
.PropertyName
, aNewValue
, bAmbiguousValue
);
776 // if it's a actuating property, then update the UI for any dependent
778 if ( impl_isActuatingProperty_nothrow( _rEvent
.PropertyName
) )
779 impl_broadcastPropertyChange_nothrow( _rEvent
.PropertyName
, aNewValue
, _rEvent
.OldValue
, false );
782 //------------------------------------------------------------------------
783 Reference
< XPropertyControl
> SAL_CALL
OPropertyBrowserController::createPropertyControl( ::sal_Int16 ControlType
, ::sal_Bool _CreateReadOnly
) throw (IllegalArgumentException
, RuntimeException
)
785 ::osl::MutexGuard
aGuard( m_aMutex
);
787 Reference
< XPropertyControl
> xControl
;
789 // default winbits: a border only
790 WinBits nWinBits
= WB_BORDER
;
793 _CreateReadOnly
|= (sal_Bool
)impl_isReadOnlyModel_throw();
794 if ( _CreateReadOnly
)
795 nWinBits
|= WB_READONLY
;
797 switch ( ControlType
)
799 case PropertyControlType::StringListField
:
800 xControl
= new OMultilineEditControl( &getPropertyBox(), eStringList
, nWinBits
| WB_DROPDOWN
| WB_TABSTOP
);
803 case PropertyControlType::MultiLineTextField
:
804 xControl
= new OMultilineEditControl( &getPropertyBox(), eMultiLineText
, nWinBits
| WB_DROPDOWN
| WB_TABSTOP
);
807 case PropertyControlType::ListBox
:
808 xControl
= new OListboxControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
811 case PropertyControlType::ComboBox
:
812 xControl
= new OComboboxControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
815 case PropertyControlType::TextField
:
816 xControl
= new OEditControl( &getPropertyBox(), sal_False
, nWinBits
| WB_TABSTOP
);
819 case PropertyControlType::CharacterField
:
820 xControl
= new OEditControl( &getPropertyBox(), sal_True
, nWinBits
| WB_TABSTOP
);
823 case PropertyControlType::NumericField
:
824 xControl
= new ONumericControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_SPIN
| WB_REPEAT
);
827 case PropertyControlType::DateTimeField
:
828 xControl
= new ODateTimeControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
);
831 case PropertyControlType::DateField
:
832 xControl
= new ODateControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_SPIN
| WB_REPEAT
);
835 case PropertyControlType::TimeField
:
836 xControl
= new OTimeControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_SPIN
| WB_REPEAT
);
839 case PropertyControlType::ColorListBox
:
840 xControl
= new OColorControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
843 case PropertyControlType::HyperlinkField
:
844 xControl
= new OHyperlinkControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
848 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
854 //------------------------------------------------------------------------
855 void OPropertyBrowserController::impl_toggleInspecteeListening_nothrow( bool _bOn
)
857 for ( InterfaceArray::const_iterator loop
= m_aInspectedObjects
.begin();
858 loop
!= m_aInspectedObjects
.end();
864 Reference
< XComponent
> xComp( *loop
, UNO_QUERY
);
868 xComp
->addEventListener( static_cast< XPropertyChangeListener
* >( this ) );
870 xComp
->removeEventListener( static_cast< XPropertyChangeListener
* >( this ) );
873 catch( const Exception
& )
875 DBG_UNHANDLED_EXCEPTION();
880 //------------------------------------------------------------------------
881 void OPropertyBrowserController::stopInspection( bool _bCommitModified
)
885 if ( _bCommitModified
)
886 // commit the editor's content
887 getPropertyBox().CommitModified();
889 // hide the property box so that it does not flicker
890 getPropertyBox().Hide();
892 // clear the property box
893 getPropertyBox().ClearAll();
896 // destroy the view first
900 for ( HashString2Int16::const_iterator erase
= m_aPageIds
.begin();
901 erase
!= m_aPageIds
.end();
904 getPropertyBox().RemovePage( erase
->second
);
905 clearContainer( m_aPageIds
);
908 clearContainer( m_aProperties
);
910 // de-register as dispose-listener from our inspected objects
911 impl_toggleInspecteeListening_nothrow( false );
913 // handlers are obsolete, so is our "composer" for their UI requests
914 if ( m_pUIRequestComposer
.get() )
915 m_pUIRequestComposer
->dispose();
916 m_pUIRequestComposer
.reset( NULL
);
918 // clean up the property handlers
919 PropertyHandlerArray aAllHandlers
; // will contain every handler exactly once
920 for ( PropertyHandlerRepository::const_iterator aHandler
= m_aPropertyHandlers
.begin();
921 aHandler
!= m_aPropertyHandlers
.end();
924 if ( ::std::find( aAllHandlers
.begin(), aAllHandlers
.end(), aHandler
->second
) == aAllHandlers
.end() )
925 aAllHandlers
.push_back( aHandler
->second
);
927 for ( PropertyHandlerArray::iterator loop
= aAllHandlers
.begin();
928 loop
!= aAllHandlers
.end();
934 (*loop
)->removePropertyChangeListener( this );
937 catch( const DisposedException
& )
940 catch( const Exception
& )
942 DBG_UNHANDLED_EXCEPTION();
946 clearContainer( m_aPropertyHandlers
);
947 clearContainer( m_aDependencyHandlers
);
950 //------------------------------------------------------------------------
951 bool OPropertyBrowserController::impl_hasPropertyHandlerFor_nothrow( const ::rtl::OUString
& _rPropertyName
) const
953 PropertyHandlerRepository::const_iterator handlerPos
= m_aPropertyHandlers
.find( _rPropertyName
);
954 return ( handlerPos
!= m_aPropertyHandlers
.end() );
957 //------------------------------------------------------------------------
958 OPropertyBrowserController::PropertyHandlerRef
OPropertyBrowserController::impl_getHandlerForProperty_throw( const ::rtl::OUString
& _rPropertyName
) const
960 PropertyHandlerRepository::const_iterator handlerPos
= m_aPropertyHandlers
.find( _rPropertyName
);
961 if ( handlerPos
== m_aPropertyHandlers
.end() )
962 throw RuntimeException();
963 return handlerPos
->second
;
966 //------------------------------------------------------------------------
967 Any
OPropertyBrowserController::impl_getPropertyValue_throw( const ::rtl::OUString
& _rPropertyName
)
969 PropertyHandlerRef handler
= impl_getHandlerForProperty_throw( _rPropertyName
);
970 return handler
->getPropertyValue( _rPropertyName
);
973 //------------------------------------------------------------------------
974 void OPropertyBrowserController::impl_rebindToInspectee_nothrow( const InterfaceArray
& _rObjects
)
978 // stop inspecting the old object(s)
979 stopInspection( true );
981 // inspect the new object(s)
982 m_aInspectedObjects
= _rObjects
;
985 // update the user interface
989 catch(const Exception
&)
991 OSL_FAIL("OPropertyBrowserController::impl_rebindToInspectee_nothrow: caught an exception !");
995 //------------------------------------------------------------------------
996 void OPropertyBrowserController::doInspection()
1000 //////////////////////////////////////////////////////////////////////
1001 // obtain the properties of the object
1002 ::std::vector
< Property
> aProperties
;
1004 PropertyHandlerArray aPropertyHandlers
;
1005 getPropertyHandlers( m_aInspectedObjects
, aPropertyHandlers
);
1007 PropertyHandlerArray::iterator
aHandler( aPropertyHandlers
.begin() );
1008 while ( aHandler
!= aPropertyHandlers
.end() )
1010 DBG_ASSERT( aHandler
->get(), "OPropertyBrowserController::doInspection: invalid handler!" );
1012 StlSyntaxSequence
< Property
> aThisHandlersProperties
= (*aHandler
)->getSupportedProperties();
1014 if ( aThisHandlersProperties
.empty() )
1016 // this handler doesn't know anything about the current inspectee -> ignore it
1017 (*aHandler
)->dispose();
1018 aHandler
= aPropertyHandlers
.erase( aHandler
);
1022 // append these properties to our "all properties" array
1023 aProperties
.reserve( aProperties
.size() + aThisHandlersProperties
.size() );
1024 for ( StlSyntaxSequence
< Property
>::const_iterator copyProperty
= aThisHandlersProperties
.begin();
1025 copyProperty
!= aThisHandlersProperties
.end();
1029 ::std::vector
< Property
>::const_iterator previous
= ::std::find_if(
1030 aProperties
.begin(),
1032 FindPropertyByName( copyProperty
->Name
)
1034 if ( previous
== aProperties
.end() )
1036 aProperties
.push_back( *copyProperty
);
1040 // there already was another (previous) handler which supported this property.
1041 // Don't add it to aProperties, again.
1043 // Also, ensure that handlers which previously expressed interest in *changes*
1044 // of this property are not notified.
1045 // This is 'cause we have a new handler which is responsible for this property,
1046 // which means it can give it a completely different meaning than the previous
1047 // handler for this property is prepared for.
1048 ::std::pair
< PropertyHandlerMultiRepository::iterator
, PropertyHandlerMultiRepository::iterator
>
1049 aDepHandlers
= m_aDependencyHandlers
.equal_range( copyProperty
->Name
);
1050 m_aDependencyHandlers
.erase( aDepHandlers
.first
, aDepHandlers
.second
);
1053 // determine the superseded properties
1054 StlSyntaxSequence
< ::rtl::OUString
> aSupersededByThisHandler
= (*aHandler
)->getSupersededProperties();
1055 for ( StlSyntaxSequence
< ::rtl::OUString
>::const_iterator superseded
= aSupersededByThisHandler
.begin();
1056 superseded
!= aSupersededByThisHandler
.end();
1060 ::std::vector
< Property
>::iterator existent
= ::std::find_if(
1061 aProperties
.begin(),
1063 FindPropertyByName( *superseded
)
1065 if ( existent
!= aProperties
.end() )
1066 // one of the properties superseded by this handler was supported by a previous
1068 aProperties
.erase( existent
);
1071 // be notified of changes which this handler is responsible for
1072 (*aHandler
)->addPropertyChangeListener( this );
1074 // remember this handler for every of the properties which it is responsible
1076 for ( StlSyntaxSequence
< Property
>::const_iterator remember
= aThisHandlersProperties
.begin();
1077 remember
!= aThisHandlersProperties
.end();
1081 m_aPropertyHandlers
[ remember
->Name
] = *aHandler
;
1082 // note that this implies that if two handlers support the same property,
1086 // see if the handler expresses interest in any actuating properties
1087 StlSyntaxSequence
< ::rtl::OUString
> aInterestingActuations
= (*aHandler
)->getActuatingProperties();
1088 for ( StlSyntaxSequence
< ::rtl::OUString
>::const_iterator aLoop
= aInterestingActuations
.begin();
1089 aLoop
!= aInterestingActuations
.end();
1093 m_aDependencyHandlers
.insert( PropertyHandlerMultiRepository::value_type(
1094 *aLoop
, *aHandler
) );
1100 // create a new composer for UI requests coming from the handlers
1101 m_pUIRequestComposer
.reset( new ComposedPropertyUIUpdate( getInspectorUI(), this ) );
1103 // sort the properties by relative position, as indicated by the model
1104 for ( ::std::vector
< Property
>::const_iterator sourceProps
= aProperties
.begin();
1105 sourceProps
!= aProperties
.end();
1109 sal_Int32 nRelativePropertyOrder
= sourceProps
- aProperties
.begin();
1110 if ( m_xModel
.is() )
1111 nRelativePropertyOrder
= m_xModel
->getPropertyOrderIndex( sourceProps
->Name
);
1112 while ( m_aProperties
.find( nRelativePropertyOrder
) != m_aProperties
.end() )
1113 ++nRelativePropertyOrder
;
1114 m_aProperties
[ nRelativePropertyOrder
] = *sourceProps
;
1117 // be notified when one of our inspectees dies
1118 impl_toggleInspecteeListening_nothrow( true );
1120 catch(const Exception
&)
1122 OSL_FAIL("OPropertyBrowserController::doInspection : caught an exception !");
1126 //------------------------------------------------------------------------
1127 ::com::sun::star::awt::Size SAL_CALL
OPropertyBrowserController::getMinimumSize() throw (::com::sun::star::uno::RuntimeException
)
1129 ::com::sun::star::awt::Size aSize
;
1131 return m_pView
->getMinimumSize();
1136 //------------------------------------------------------------------------
1137 ::com::sun::star::awt::Size SAL_CALL
OPropertyBrowserController::getPreferredSize() throw (::com::sun::star::uno::RuntimeException
)
1139 return getMinimumSize();
1142 //------------------------------------------------------------------------
1143 ::com::sun::star::awt::Size SAL_CALL
OPropertyBrowserController::calcAdjustedSize( const ::com::sun::star::awt::Size
& _rNewSize
) throw (::com::sun::star::uno::RuntimeException
)
1145 awt::Size aMinSize
= getMinimumSize( );
1146 awt::Size
aAdjustedSize( _rNewSize
);
1147 if ( aAdjustedSize
.Width
< aMinSize
.Width
)
1148 aAdjustedSize
.Width
= aMinSize
.Width
;
1149 if ( aAdjustedSize
.Height
< aMinSize
.Height
)
1150 aAdjustedSize
.Height
= aMinSize
.Height
;
1151 return aAdjustedSize
;
1154 //------------------------------------------------------------------------
1155 void OPropertyBrowserController::describePropertyLine( const Property
& _rProperty
, OLineDescriptor
& _rDescriptor
) SAL_THROW((Exception
))
1159 PropertyHandlerRepository::const_iterator handler
= m_aPropertyHandlers
.find( _rProperty
.Name
);
1160 if ( handler
== m_aPropertyHandlers
.end() )
1161 throw RuntimeException(); // caught below
1163 _rDescriptor
.assignFrom( handler
->second
->describePropertyLine( _rProperty
.Name
, this ) );
1165 //////////////////////////////////////////////////////////////////////
1167 _rDescriptor
.xPropertyHandler
= handler
->second
;
1168 _rDescriptor
.sName
= _rProperty
.Name
;
1169 _rDescriptor
.aValue
= _rDescriptor
.xPropertyHandler
->getPropertyValue( _rProperty
.Name
);
1171 if ( _rDescriptor
.DisplayName
.isEmpty() )
1174 ::rtl::OString
sMessage( "OPropertyBrowserController::describePropertyLine: handler did not provide a display name for '" );
1175 sMessage
+= ::rtl::OString( _rProperty
.Name
.getStr(), _rProperty
.Name
.getLength(), RTL_TEXTENCODING_ASCII_US
);
1176 sMessage
+= ::rtl::OString( "'!" );
1177 DBG_ASSERT( !_rDescriptor
.DisplayName
.isEmpty(), sMessage
.getStr() );
1179 _rDescriptor
.DisplayName
= _rProperty
.Name
;
1182 PropertyState
ePropertyState( _rDescriptor
.xPropertyHandler
->getPropertyState( _rProperty
.Name
) );
1183 if ( PropertyState_AMBIGUOUS_VALUE
== ePropertyState
)
1185 _rDescriptor
.bUnknownValue
= true;
1186 _rDescriptor
.aValue
.clear();
1189 _rDescriptor
.bReadOnly
= impl_isReadOnlyModel_throw();
1191 catch( const Exception
& )
1193 OSL_FAIL( "OPropertyBrowserController::describePropertyLine: caught an exception!" );
1197 //------------------------------------------------------------------------
1198 void OPropertyBrowserController::impl_buildCategories_throw()
1200 OSL_PRECOND( m_aPageIds
.empty(), "OPropertyBrowserController::impl_buildCategories_throw: duplicate call!" );
1202 StlSyntaxSequence
< PropertyCategoryDescriptor
> aCategories
;
1203 if ( m_xModel
.is() )
1204 aCategories
= m_xModel
->describeCategories();
1206 for ( StlSyntaxSequence
< PropertyCategoryDescriptor
>::const_iterator category
= aCategories
.begin();
1207 category
!= aCategories
.end();
1211 OSL_ENSURE( m_aPageIds
.find( category
->ProgrammaticName
) == m_aPageIds
.end(),
1212 "OPropertyBrowserController::impl_buildCategories_throw: duplicate programmatic name!" );
1214 m_aPageIds
[ category
->ProgrammaticName
] =
1215 getPropertyBox().AppendPage( category
->UIName
, HelpIdUrl::getHelpId( category
->HelpURL
) );
1219 //------------------------------------------------------------------------
1220 void OPropertyBrowserController::UpdateUI()
1225 // too early, will return later
1228 getPropertyBox().DisableUpdate();
1230 sal_Bool bHaveFocus
= getPropertyBox().HasChildPathFocus();
1232 // create our tab pages
1233 impl_buildCategories_throw();
1234 // (and allow for pages to be actually unused)
1235 ::std::set
< sal_uInt16
> aUsedPages
;
1237 // when building the UI below, remember which properties are actuating,
1238 // to allow for a initial actuatinPropertyChanged call
1239 ::std::vector
< ::rtl::OUString
> aActuatingProperties
;
1240 ::std::vector
< Any
> aActuatingPropertyValues
;
1242 // ask the handlers to describe the property UI, and insert the resulting
1243 // entries into our list boxes
1244 OrderedPropertyMap::const_iterator
property( m_aProperties
.begin() );
1245 for ( ; property
!= m_aProperties
.end(); ++property
)
1247 OLineDescriptor aDescriptor
;
1248 describePropertyLine( property
->second
, aDescriptor
);
1250 bool bIsActuatingProperty
= impl_isActuatingProperty_nothrow( property
->second
.Name
);
1252 #if OSL_DEBUG_LEVEL > 0
1253 if ( aDescriptor
.Category
.isEmpty() )
1255 ::rtl::OString
sMessage( "OPropertyBrowserController::UpdateUI: empty category provided for property '" );
1256 sMessage
+= ::rtl::OString( property
->second
.Name
.getStr(), property
->second
.Name
.getLength(), osl_getThreadTextEncoding() );
1258 OSL_FAIL( sMessage
.getStr() );
1261 // finally insert this property control
1262 sal_uInt16 nTargetPageId
= impl_getPageIdForCategory_nothrow( aDescriptor
.Category
);
1263 if ( nTargetPageId
== (sal_uInt16
)-1 )
1265 // this category does not yet exist. This is allowed, as an inspector model might be lazy, and not provide
1266 // any category information of its own. In this case, we have a fallback ...
1267 m_aPageIds
[ aDescriptor
.Category
] =
1268 getPropertyBox().AppendPage( aDescriptor
.Category
, rtl::OString() );
1269 nTargetPageId
= impl_getPageIdForCategory_nothrow( aDescriptor
.Category
);
1272 getPropertyBox().InsertEntry( aDescriptor
, nTargetPageId
);
1273 aUsedPages
.insert( nTargetPageId
);
1275 // if it's an actuating property, remember it
1276 if ( bIsActuatingProperty
)
1278 aActuatingProperties
.push_back( property
->second
.Name
);
1279 aActuatingPropertyValues
.push_back( impl_getPropertyValue_throw( property
->second
.Name
) );
1283 // update any dependencies for the actuating properties which we encountered
1285 ::std::vector
< ::rtl::OUString
>::const_iterator aProperty
= aActuatingProperties
.begin();
1286 ::std::vector
< Any
>::const_iterator aPropertyValue
= aActuatingPropertyValues
.begin();
1287 for ( ; aProperty
!= aActuatingProperties
.end(); ++aProperty
, ++aPropertyValue
)
1288 impl_broadcastPropertyChange_nothrow( *aProperty
, *aPropertyValue
, *aPropertyValue
, true );
1291 // remove any unused pages (which we did not encounter properties for)
1292 HashString2Int16 aSurvivingPageIds
;
1293 for ( HashString2Int16::iterator pageId
= m_aPageIds
.begin();
1294 pageId
!= m_aPageIds
.end();
1298 if ( aUsedPages
.find( pageId
->second
) == aUsedPages
.end() )
1299 getPropertyBox().RemovePage( pageId
->second
);
1301 aSurvivingPageIds
.insert( *pageId
);
1303 m_aPageIds
.swap( aSurvivingPageIds
);
1306 getPropertyBox().Show();
1307 getPropertyBox().EnableUpdate();
1309 getPropertyBox().GrabFocus();
1311 // activate the first page
1312 if ( !m_aPageIds
.empty() )
1314 Sequence
< PropertyCategoryDescriptor
> aCategories( m_xModel
->describeCategories() );
1315 if ( aCategories
.getLength() )
1316 m_pView
->activatePage( m_aPageIds
[ aCategories
[0].ProgrammaticName
] );
1318 // allowed: if we default-created the pages ...
1319 m_pView
->activatePage( m_aPageIds
.begin()->second
);
1322 // activate the previously active page (if possible)
1323 if ( !m_sLastValidPageSelection
.isEmpty() )
1324 m_sPageSelection
= m_sLastValidPageSelection
;
1325 selectPageFromViewData();
1327 catch( const Exception
& )
1329 DBG_UNHANDLED_EXCEPTION();
1333 //------------------------------------------------------------------------
1334 void OPropertyBrowserController::Clicked( const ::rtl::OUString
& _rName
, sal_Bool _bPrimary
)
1338 // since the browse buttons do not get the focus when clicked with the mouse,
1339 // we need to commit the changes in the current property field
1340 getPropertyBox().CommitModified();
1342 PropertyHandlerRepository::const_iterator handler
= m_aPropertyHandlers
.find( _rName
);
1343 DBG_ASSERT( handler
!= m_aPropertyHandlers
.end(), "OPropertyBrowserController::Clicked: a property without handler? This will crash!" );
1345 ComposedUIAutoFireGuard
aAutoFireGuard( *m_pUIRequestComposer
);
1348 m_xInteractiveHandler
= handler
->second
;
1349 InteractiveSelectionResult eResult
=
1350 handler
->second
->onInteractivePropertySelection( _rName
, _bPrimary
, aData
,
1351 m_pUIRequestComposer
->getUIForPropertyHandler( handler
->second
) );
1355 case InteractiveSelectionResult_Cancelled
:
1356 case InteractiveSelectionResult_Success
:
1357 // okay, nothing to do
1359 case InteractiveSelectionResult_ObtainedValue
:
1360 handler
->second
->setPropertyValue( _rName
, aData
);
1362 case InteractiveSelectionResult_Pending
:
1363 // also okay, we expect that the handler has disabled the UI as necessary
1366 OSL_FAIL( "OPropertyBrowserController::Clicked: unknown result value!" );
1370 catch (const Exception
&)
1372 DBG_UNHANDLED_EXCEPTION();
1374 m_xInteractiveHandler
= NULL
;
1377 //------------------------------------------------------------------------
1378 sal_Bool SAL_CALL
OPropertyBrowserController::hasPropertyByName( const ::rtl::OUString
& _rName
) throw (RuntimeException
)
1380 for ( OrderedPropertyMap::const_iterator search
= m_aProperties
.begin();
1381 search
!= m_aProperties
.end();
1384 if ( search
->second
.Name
== _rName
)
1389 //------------------------------------------------------------------------
1390 void OPropertyBrowserController::Commit( const ::rtl::OUString
& rName
, const Any
& _rValue
)
1394 rtl::OUString sPlcHolder
= String( PcrRes( RID_EMBED_IMAGE_PLACEHOLDER
) );
1395 bool bIsPlaceHolderValue
= false;
1397 if ( rName
.equals( PROPERTY_IMAGE_URL
) )
1399 // if the prop value is the PlaceHolder
1403 if ( sVal
.equals( sPlcHolder
) )
1404 bIsPlaceHolderValue
= true;
1406 m_sCommittingProperty
= rName
;
1408 bool bIsActuatingProperty
= impl_isActuatingProperty_nothrow( rName
);
1411 if ( bIsActuatingProperty
)
1412 aOldValue
= impl_getPropertyValue_throw( rName
);
1414 // do we have a dedicated handler for this property, which we can delegate some tasks to?
1415 PropertyHandlerRef handler
= impl_getHandlerForProperty_throw( rName
);
1417 //////////////////////////////////////////////////////////////////////
1418 // set the value ( only if it's not a placeholder )
1419 if ( !bIsPlaceHolderValue
)
1420 handler
->setPropertyValue( rName
, _rValue
);
1422 //////////////////////////////////////////////////////////////////////
1423 // re-retrieve the value
1424 Any aNormalizedValue
= handler
->getPropertyValue( rName
);
1426 // care for any inter-property dependencies
1427 if ( bIsActuatingProperty
)
1428 impl_broadcastPropertyChange_nothrow( rName
, aNormalizedValue
, aOldValue
, false );
1430 // and display it again. This ensures proper formatting
1431 getPropertyBox().SetPropertyValue( rName
, aNormalizedValue
, false );
1433 catch(const PropertyVetoException
& eVetoException
)
1435 InfoBox(m_pView
, eVetoException
.Message
).Execute();
1436 PropertyHandlerRef handler
= impl_getHandlerForProperty_throw( rName
);
1437 Any aNormalizedValue
= handler
->getPropertyValue( rName
);
1438 getPropertyBox().SetPropertyValue( rName
, aNormalizedValue
, false );
1440 catch(const Exception
&)
1442 OSL_FAIL("OPropertyBrowserController::Commit : caught an exception !");
1445 m_sCommittingProperty
= ::rtl::OUString();
1448 //--------------------------------------------------------------------
1453 //--------------------------------------------------------------------
1454 void OPropertyBrowserController::focusGained( const Reference
< XPropertyControl
>& _Control
)
1456 m_aControlObservers
.notifyEach( &XPropertyControlObserver::focusGained
, _Control
);
1459 //--------------------------------------------------------------------
1460 void OPropertyBrowserController::valueChanged( const Reference
< XPropertyControl
>& _Control
)
1462 m_aControlObservers
.notifyEach( &XPropertyControlObserver::valueChanged
, _Control
);
1465 //------------------------------------------------------------------------
1468 Reference
< XPropertyHandler
> lcl_createHandler( const ComponentContext
& _rContext
, const Any
& _rFactoryDescriptor
)
1470 Reference
< XPropertyHandler
> xHandler
;
1472 ::rtl::OUString sServiceName
;
1473 Reference
< XSingleServiceFactory
> xServiceFac
;
1474 Reference
< XSingleComponentFactory
> xComponentFac
;
1476 if ( _rFactoryDescriptor
>>= sServiceName
)
1477 _rContext
.createComponent( sServiceName
, xHandler
);
1478 else if ( _rFactoryDescriptor
>>= xServiceFac
)
1479 xHandler
= xHandler
.query( xServiceFac
->createInstance() );
1480 else if ( _rFactoryDescriptor
>>= xComponentFac
)
1481 xHandler
= xHandler
.query( xComponentFac
->createInstanceWithContext( _rContext
.getUNOContext() ) );
1482 OSL_ENSURE(xHandler
.is(),"lcl_createHandler: Can not create handler");
1487 //------------------------------------------------------------------------
1488 void OPropertyBrowserController::getPropertyHandlers( const InterfaceArray
& _rObjects
, PropertyHandlerArray
& _rHandlers
)
1490 _rHandlers
.resize( 0 );
1491 if ( _rObjects
.empty() )
1494 // create a component context for the handlers, containing some information about where
1496 Reference
< XComponentContext
> xHandlerContext( m_aContext
.getUNOContext() );
1498 // if our own creator did not pass a dialog parent window, use our own view for this
1499 Reference
< XWindow
> xParentWindow( m_aContext
.getContextValueByAsciiName( "DialogParentWindow" ), UNO_QUERY
);
1500 if ( !xParentWindow
.is() )
1502 ::cppu::ContextEntry_Init aHandlerContextInfo
[] =
1504 ::cppu::ContextEntry_Init( ::rtl::OUString( "DialogParentWindow" ), makeAny( VCLUnoHelper::GetInterface( m_pView
) ) )
1506 xHandlerContext
= ::cppu::createComponentContext(
1507 aHandlerContextInfo
, SAL_N_ELEMENTS( aHandlerContextInfo
),
1508 m_aContext
.getUNOContext() );
1511 Sequence
< Any
> aHandlerFactories
;
1512 if ( m_xModel
.is() )
1513 aHandlerFactories
= m_xModel
->getHandlerFactories();
1515 const Any
* pHandlerFactory
= aHandlerFactories
.getConstArray();
1516 const Any
* pHandlerFactoryEnd
= aHandlerFactories
.getConstArray() + aHandlerFactories
.getLength();
1518 while ( pHandlerFactory
!= pHandlerFactoryEnd
)
1520 if ( _rObjects
.size() == 1 )
1521 { // we're inspecting only one object -> one handler
1522 Reference
< XPropertyHandler
> xHandler( lcl_createHandler( m_aContext
, *pHandlerFactory
) );
1523 if ( xHandler
.is() )
1525 xHandler
->inspect( _rObjects
[0] );
1526 _rHandlers
.push_back( xHandler
);
1531 // create a single handler for every single object
1532 ::std::vector
< Reference
< XPropertyHandler
> > aSingleHandlers( _rObjects
.size() );
1533 ::std::vector
< Reference
< XPropertyHandler
> >::iterator pHandler
= aSingleHandlers
.begin();
1535 InterfaceArray::const_iterator pObject
= _rObjects
.begin();
1536 InterfaceArray::const_iterator pObjectEnd
= _rObjects
.end();
1538 for ( ; pObject
!= pObjectEnd
; ++pObject
)
1540 *pHandler
= lcl_createHandler( m_aContext
, *pHandlerFactory
);
1541 if ( pHandler
->is() )
1543 (*pHandler
)->inspect( *pObject
);
1547 aSingleHandlers
.resize( pHandler
- aSingleHandlers
.begin() );
1549 // then create a handler which composes information out of those single handlers
1550 if ( !aSingleHandlers
.empty() )
1551 _rHandlers
.push_back( new PropertyComposer( aSingleHandlers
) );
1557 // note that the handlers will not be used by our caller, if they indicate that there are no
1558 // properties they feel responsible for
1561 //------------------------------------------------------------------------
1562 bool OPropertyBrowserController::impl_findObjectProperty_nothrow( const ::rtl::OUString
& _rName
, OrderedPropertyMap::const_iterator
* _pProperty
)
1564 OrderedPropertyMap::const_iterator search
= m_aProperties
.begin();
1565 for ( ; search
!= m_aProperties
.end(); ++search
)
1566 if ( search
->second
.Name
== _rName
)
1569 *_pProperty
= search
;
1570 return ( search
!= m_aProperties
.end() );
1573 //------------------------------------------------------------------------
1574 void OPropertyBrowserController::rebuildPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1576 ::osl::MutexGuard
aGuard( m_aMutex
);
1578 throw RuntimeException();
1580 OrderedPropertyMap::const_iterator propertyPos
;
1581 if ( !impl_findObjectProperty_nothrow( _rPropertyName
, &propertyPos
) )
1584 OLineDescriptor aDescriptor
;
1587 describePropertyLine( propertyPos
->second
, aDescriptor
);
1589 catch( const Exception
& )
1591 OSL_FAIL( "OPropertyBrowserController::rebuildPropertyUI: caught an exception!" );
1594 getPropertyBox().ChangeEntry( aDescriptor
);
1597 //------------------------------------------------------------------------
1598 void OPropertyBrowserController::enablePropertyUI( const ::rtl::OUString
& _rPropertyName
, sal_Bool _bEnable
) throw (RuntimeException
)
1600 ::osl::MutexGuard
aGuard( m_aMutex
);
1602 throw RuntimeException();
1604 if ( !impl_findObjectProperty_nothrow( _rPropertyName
) )
1607 getPropertyBox().EnablePropertyLine( _rPropertyName
, _bEnable
);
1610 //------------------------------------------------------------------------
1611 void OPropertyBrowserController::enablePropertyUIElements( const ::rtl::OUString
& _rPropertyName
, sal_Int16 _nElements
, sal_Bool _bEnable
) throw (RuntimeException
)
1613 ::osl::MutexGuard
aGuard( m_aMutex
);
1615 throw RuntimeException();
1617 if ( !impl_findObjectProperty_nothrow( _rPropertyName
) )
1620 getPropertyBox().EnablePropertyControls( _rPropertyName
, _nElements
, _bEnable
);
1623 //------------------------------------------------------------------------
1624 void OPropertyBrowserController::showPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1626 ::osl::MutexGuard
aGuard( m_aMutex
);
1628 throw RuntimeException();
1630 // look up the property in our object properties
1631 OrderedPropertyMap::const_iterator propertyPos
;
1632 if ( !impl_findObjectProperty_nothrow( _rPropertyName
, &propertyPos
) )
1635 if ( getPropertyBox().GetPropertyPos( _rPropertyName
) != LISTBOX_ENTRY_NOTFOUND
)
1637 rebuildPropertyUI( _rPropertyName
);
1641 OLineDescriptor aDescriptor
;
1642 describePropertyLine( propertyPos
->second
, aDescriptor
);
1644 // look for the position to insert the property
1646 // side note: The methods GetPropertyPos and InsertEntry of the OPropertyEditor work
1647 // only on the current page. This implies that it's impossible to use this method here
1648 // to show property lines which are *not* on the current page.
1649 // This is sufficient for now, but should be changed in the future.
1651 // by definition, the properties in m_aProperties are in the order in which they appear in the UI
1652 // So all we need is a predecessor of pProperty in m_aProperties
1653 sal_uInt16 nUIPos
= LISTBOX_ENTRY_NOTFOUND
;
1656 if ( propertyPos
!= m_aProperties
.begin() )
1658 nUIPos
= getPropertyBox().GetPropertyPos( propertyPos
->second
.Name
);
1660 while ( ( nUIPos
== LISTBOX_ENTRY_NOTFOUND
) && ( propertyPos
!= m_aProperties
.begin() ) );
1662 if ( nUIPos
== LISTBOX_ENTRY_NOTFOUND
)
1663 // insert at the very top
1666 // insert right after the predecessor we found
1669 getPropertyBox().InsertEntry(
1670 aDescriptor
, impl_getPageIdForCategory_nothrow( aDescriptor
.Category
), nUIPos
);
1673 //------------------------------------------------------------------------
1674 void OPropertyBrowserController::hidePropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1676 ::osl::MutexGuard
aGuard( m_aMutex
);
1678 throw RuntimeException();
1680 if ( !impl_findObjectProperty_nothrow( _rPropertyName
) )
1683 getPropertyBox().RemoveEntry( _rPropertyName
);
1686 //------------------------------------------------------------------------
1687 void OPropertyBrowserController::showCategory( const ::rtl::OUString
& _rCategory
, sal_Bool _bShow
) throw (RuntimeException
)
1689 ::osl::MutexGuard
aGuard( m_aMutex
);
1691 throw RuntimeException();
1693 sal_uInt16 nPageId
= impl_getPageIdForCategory_nothrow( _rCategory
);
1694 OSL_ENSURE( nPageId
!= (sal_uInt16
)-1, "OPropertyBrowserController::showCategory: invalid category!" );
1696 getPropertyBox().ShowPropertyPage( nPageId
, _bShow
);
1699 //------------------------------------------------------------------------
1700 Reference
< XPropertyControl
> SAL_CALL
OPropertyBrowserController::getPropertyControl( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1702 ::osl::MutexGuard
aGuard( m_aMutex
);
1704 throw RuntimeException();
1706 Reference
< XPropertyControl
> xControl( getPropertyBox().GetPropertyControl( _rPropertyName
) );
1710 //--------------------------------------------------------------------
1711 void SAL_CALL
OPropertyBrowserController::registerControlObserver( const Reference
< XPropertyControlObserver
>& _Observer
) throw (RuntimeException
)
1713 m_aControlObservers
.addInterface( _Observer
);
1716 //--------------------------------------------------------------------
1717 void SAL_CALL
OPropertyBrowserController::revokeControlObserver( const Reference
< XPropertyControlObserver
>& _Observer
) throw (RuntimeException
)
1719 m_aControlObservers
.removeInterface( _Observer
);
1722 //------------------------------------------------------------------------
1723 void SAL_CALL
OPropertyBrowserController::setHelpSectionText( const ::rtl::OUString
& _rHelpText
) throw (NoSupportException
, RuntimeException
)
1725 SolarMutexGuard aSolarGuard
;
1726 ::osl::MutexGuard
aGuard( m_aMutex
);
1729 throw DisposedException();
1731 if ( !getPropertyBox().HasHelpSection() )
1732 throw NoSupportException();
1734 getPropertyBox().SetHelpText( _rHelpText
);
1737 //------------------------------------------------------------------------
1738 void OPropertyBrowserController::impl_broadcastPropertyChange_nothrow( const ::rtl::OUString
& _rPropertyName
, const Any
& _rNewValue
, const Any
& _rOldValue
, bool _bFirstTimeInit
) const
1740 // are there one or more handlers which are interested in the actuation?
1741 ::std::pair
< PropertyHandlerMultiRepository::const_iterator
, PropertyHandlerMultiRepository::const_iterator
> aInterestedHandlers
=
1742 m_aDependencyHandlers
.equal_range( _rPropertyName
);
1743 if ( aInterestedHandlers
.first
== aInterestedHandlers
.second
)
1744 // none of our handlers is interested in this
1747 ComposedUIAutoFireGuard
aAutoFireGuard( *m_pUIRequestComposer
);
1750 // collect the responses from all interested handlers
1751 PropertyHandlerMultiRepository::const_iterator handler
= aInterestedHandlers
.first
;
1752 while ( handler
!= aInterestedHandlers
.second
)
1754 handler
->second
->actuatingPropertyChanged( _rPropertyName
, _rNewValue
, _rOldValue
,
1755 m_pUIRequestComposer
->getUIForPropertyHandler( handler
->second
),
1760 catch( const Exception
& )
1762 DBG_UNHANDLED_EXCEPTION();
1766 //............................................................................
1768 //............................................................................
1771 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */