1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propcontroller.cxx,v $
10 * $Revision: 1.41.66.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "propcontroller.hxx"
34 #include "pcrstrings.hxx"
35 #include "standardcontrol.hxx"
36 #include "linedescriptor.hxx"
37 #ifndef EXTENSIONS_PROPRESID_HRC
38 #include "propresid.hrc"
40 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
41 #include "formresid.hrc"
43 #include "propertyeditor.hxx"
44 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
45 #include "modulepcr.hxx"
47 #include "formstrings.hxx"
48 #include "formmetadata.hxx"
49 #include "formbrowsertools.hxx"
50 #include "propertycomposer.hxx"
52 /** === begin UNO includes === **/
53 #include <com/sun/star/awt/XWindow.hpp>
54 #include <com/sun/star/util/XCloseable.hpp>
55 #include <com/sun/star/inspection/PropertyControlType.hpp>
56 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
57 /** === end UNO includes === **/
58 #include <tools/debug.hxx>
59 #include <tools/diagnose_ex.h>
60 #include <comphelper/types.hxx>
61 #include <comphelper/extract.hxx>
62 #include <toolkit/awt/vclxwindow.hxx>
63 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
64 #include <toolkit/unohlp.hxx>
66 #include <comphelper/property.hxx>
67 #include <vcl/msgbox.hxx>
68 #include <vcl/svapp.hxx>
69 #include <vos/mutex.hxx>
70 #include <cppuhelper/component_context.hxx>
71 #include <cppuhelper/exc_hlp.hxx>
76 //------------------------------------------------------------------------
77 // !!! outside the namespace !!!
78 extern "C" void SAL_CALL
createRegistryInfo_OPropertyBrowserController()
80 ::pcr::OAutoRegistration
< ::pcr::OPropertyBrowserController
> aAutoRegistration
;
83 //............................................................................
86 //............................................................................
88 using namespace ::com::sun::star
;
89 using namespace ::com::sun::star::uno
;
90 using namespace ::com::sun::star::awt
;
91 using namespace ::com::sun::star::form
;
92 using namespace ::com::sun::star::beans
;
93 using namespace ::com::sun::star::script
;
94 using namespace ::com::sun::star::lang
;
95 using namespace ::com::sun::star::container
;
96 using namespace ::com::sun::star::frame
;
97 using namespace ::com::sun::star::util
;
98 using namespace ::com::sun::star::inspection
;
99 using namespace ::com::sun::star::ucb
;
100 using namespace ::comphelper
;
102 #define THISREF() static_cast< XController* >(this)
104 //========================================================================
105 //= OPropertyBrowserController
106 //========================================================================
107 DBG_NAME(OPropertyBrowserController
)
108 //------------------------------------------------------------------------
109 OPropertyBrowserController::OPropertyBrowserController( const Reference
< XComponentContext
>& _rxContext
)
110 :m_aContext(_rxContext
)
111 ,m_aDisposeListeners( m_aMutex
)
112 ,m_aControlObservers( m_aMutex
)
114 ,m_bContainerFocusListening( false )
115 ,m_bSuspendingPropertyHandlers( false )
116 ,m_bConstructed( false )
117 ,m_bBindingIntrospectee( false )
119 DBG_CTOR(OPropertyBrowserController
,NULL
);
122 //------------------------------------------------------------------------
123 OPropertyBrowserController::~OPropertyBrowserController()
125 // stop listening for property changes
127 stopInspection( true );
128 DBG_DTOR(OPropertyBrowserController
,NULL
);
131 //------------------------------------------------------------------------
132 IMPLEMENT_FORWARD_REFCOUNT( OPropertyBrowserController
, OPropertyBrowserController_Base
)
134 //------------------------------------------------------------------------
135 Any SAL_CALL
OPropertyBrowserController::queryInterface( const Type
& _rType
) throw (RuntimeException
)
137 Any aReturn
= OPropertyBrowserController_Base::queryInterface( _rType
);
138 if ( !aReturn
.hasValue() )
139 aReturn
= ::cppu::queryInterface(
141 static_cast< XObjectInspectorUI
* >( this )
146 //------------------------------------------------------------------------
147 void OPropertyBrowserController::startContainerWindowListening()
149 if (m_bContainerFocusListening
)
154 Reference
< XWindow
> xContainerWindow
= m_xFrame
->getContainerWindow();
155 if (xContainerWindow
.is())
157 xContainerWindow
->addFocusListener(this);
158 m_bContainerFocusListening
= sal_True
;
162 DBG_ASSERT(m_bContainerFocusListening
, "OPropertyBrowserController::startContainerWindowListening: unable to start listening (inconsistence)!");
165 //------------------------------------------------------------------------
166 void OPropertyBrowserController::stopContainerWindowListening()
168 if (!m_bContainerFocusListening
)
173 Reference
< XWindow
> xContainerWindow
= m_xFrame
->getContainerWindow();
174 if (xContainerWindow
.is())
176 xContainerWindow
->removeFocusListener(this);
177 m_bContainerFocusListening
= sal_False
;
181 DBG_ASSERT(!m_bContainerFocusListening
, "OPropertyBrowserController::stopContainerWindowListening: unable to stop listening (inconsistence)!");
184 //--------------------------------------------------------------------
185 Reference
< XObjectInspectorModel
> SAL_CALL
OPropertyBrowserController::getInspectorModel() throw (RuntimeException
)
190 //--------------------------------------------------------------------
191 void OPropertyBrowserController::impl_initializeView_nothrow()
193 OSL_PRECOND( haveView(), "OPropertyBrowserController::impl_initializeView_nothrow: not to be called when we have no view!" );
197 if ( !m_xModel
.is() )
203 getPropertyBox().EnableHelpSection( m_xModel
->getHasHelpSection() );
204 getPropertyBox().SetHelpLineLimites( m_xModel
->getMinHelpTextLines(), m_xModel
->getMaxHelpTextLines() );
206 catch( const Exception
& )
208 DBG_UNHANDLED_EXCEPTION();
212 //--------------------------------------------------------------------
213 void OPropertyBrowserController::impl_updateReadOnlyView_nothrow()
215 // this is a huge cudgel, admitted.
216 // The problem is that in case we were previously read-only, all our controls
217 // were created read-only, too. We cannot simply switch them to not-read-only.
218 // Even if they had an API for this, we do not know whether they were
219 // originally created read-only, or if they are read-only just because
221 impl_rebindToInspectee_nothrow( m_aInspectedObjects
);
224 //--------------------------------------------------------------------
225 bool OPropertyBrowserController::impl_isReadOnlyModel_throw() const
227 if ( !m_xModel
.is() )
230 return m_xModel
->getIsReadOnly();
233 //--------------------------------------------------------------------
234 void OPropertyBrowserController::impl_startOrStopModelListening_nothrow( bool _bDoListen
) const
238 Reference
< XPropertySet
> xModelProperties( m_xModel
, UNO_QUERY
);
239 if ( !xModelProperties
.is() )
240 // okay, so the model doesn't want to change its properties
241 // dynamically - fine with us
244 void (SAL_CALL
XPropertySet::*pListenerOperation
)( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& )
245 = _bDoListen
? &XPropertySet::addPropertyChangeListener
: &XPropertySet::removePropertyChangeListener
;
247 (xModelProperties
.get()->*pListenerOperation
)(
248 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ),
249 const_cast< OPropertyBrowserController
* >( this )
252 catch( const Exception
& )
254 DBG_UNHANDLED_EXCEPTION();
258 //--------------------------------------------------------------------
259 void OPropertyBrowserController::impl_bindToNewModel_nothrow( const Reference
< XObjectInspectorModel
>& _rxInspectorModel
)
261 impl_startOrStopModelListening_nothrow( false );
262 m_xModel
= _rxInspectorModel
;
263 impl_startOrStopModelListening_nothrow( true );
265 // initialize the view, if we already have one
267 impl_initializeView_nothrow();
269 // inspect again, if we already have inspectees
270 if ( !m_aInspectedObjects
.empty() )
271 impl_rebindToInspectee_nothrow( m_aInspectedObjects
);
274 //--------------------------------------------------------------------
275 void SAL_CALL
OPropertyBrowserController::setInspectorModel( const Reference
< XObjectInspectorModel
>& _inspectorModel
) throw (RuntimeException
)
277 ::osl::MutexGuard
aGuard( m_aMutex
);
279 if ( m_xModel
== _inspectorModel
)
282 impl_bindToNewModel_nothrow( _inspectorModel
);
285 //--------------------------------------------------------------------
286 Reference
< XObjectInspectorUI
> SAL_CALL
OPropertyBrowserController::getInspectorUI() throw (RuntimeException
)
288 // we're derived from this interface, though we do not expose it in queryInterface and getTypes.
292 //--------------------------------------------------------------------
293 void SAL_CALL
OPropertyBrowserController::inspect( const Sequence
< Reference
< XInterface
> >& _rObjects
) throw (com::sun::star::util::VetoException
, RuntimeException
)
295 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
296 ::osl::MutexGuard
aGuard( m_aMutex
);
298 if ( m_bSuspendingPropertyHandlers
|| !suspendAll_nothrow() )
299 { // we already are trying to suspend the component (this is somewhere up the stack)
300 // OR one of our property handlers raised a veto against closing. Well, we *need* to close
301 // it in order to inspect another object.
302 throw VetoException();
304 if ( m_bBindingIntrospectee
)
305 throw VetoException();
307 m_bBindingIntrospectee
= true;
308 impl_rebindToInspectee_nothrow( InterfaceArray( _rObjects
.getConstArray(), _rObjects
.getConstArray() + _rObjects
.getLength() ) );
309 m_bBindingIntrospectee
= false;
313 //--------------------------------------------------------------------
314 Reference
< XDispatch
> SAL_CALL
OPropertyBrowserController::queryDispatch( const URL
& /*URL*/, const ::rtl::OUString
& /*TargetFrameName*/, ::sal_Int32
/*SearchFlags*/ ) throw (RuntimeException
)
316 // we don't have any dispatches at all, right now
317 return Reference
< XDispatch
>();
320 //--------------------------------------------------------------------
321 Sequence
< Reference
< XDispatch
> > SAL_CALL
OPropertyBrowserController::queryDispatches( const Sequence
< DispatchDescriptor
>& Requests
) throw (RuntimeException
)
323 Sequence
< Reference
< XDispatch
> > aReturn
;
324 sal_Int32 nLen
= Requests
.getLength();
325 aReturn
.realloc( nLen
);
327 Reference
< XDispatch
>* pReturn
= aReturn
.getArray();
328 const Reference
< XDispatch
>* pReturnEnd
= aReturn
.getArray() + nLen
;
329 const DispatchDescriptor
* pDescripts
= Requests
.getConstArray();
331 for ( ; pReturn
!= pReturnEnd
; ++ pReturn
, ++pDescripts
)
332 *pReturn
= queryDispatch( pDescripts
->FeatureURL
, pDescripts
->FrameName
, pDescripts
->SearchFlags
);
337 //------------------------------------------------------------------------
338 void SAL_CALL
OPropertyBrowserController::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
)
340 if ( m_bConstructed
)
341 throw AlreadyInitializedException();
343 StlSyntaxSequence
< Any
> arguments( _arguments
);
344 if ( arguments
.empty() )
345 { // constructor: "createDefault()"
350 Reference
< XObjectInspectorModel
> xModel
;
351 if ( arguments
.size() == 1 )
352 { // constructor: "createWithModel( XObjectInspectorModel )"
353 if ( !( arguments
[0] >>= xModel
) )
354 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 );
355 createWithModel( xModel
);
359 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 );
362 //------------------------------------------------------------------------
363 void OPropertyBrowserController::createDefault()
365 m_bConstructed
= true;
368 //------------------------------------------------------------------------
369 void OPropertyBrowserController::createWithModel( const Reference
< XObjectInspectorModel
>& _rxModel
)
371 osl_incrementInterlockedCount( &m_refCount
);
373 setInspectorModel( _rxModel
);
375 osl_decrementInterlockedCount( &m_refCount
);
377 m_bConstructed
= true;
380 //------------------------------------------------------------------------
381 void SAL_CALL
OPropertyBrowserController::attachFrame( const Reference
< XFrame
>& _rxFrame
) throw(RuntimeException
)
383 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
384 ::osl::MutexGuard
aGuard( m_aMutex
);
386 if (_rxFrame
.is() && haveView())
387 throw RuntimeException(::rtl::OUString::createFromAscii("Unable to attach to a second frame."),*this);
389 // revoke as focus listener from the old container window
390 stopContainerWindowListening();
396 // TODO: this construction perhaps should be done outside. Don't know the exact meaning of attachFrame.
397 // Maybe it is intended to only announce the frame to the controller, and the instance doing this
398 // announcement is responsible for calling setComponent, too.
399 Reference
< XWindow
> xContainerWindow
= m_xFrame
->getContainerWindow();
400 VCLXWindow
* pContainerWindow
= VCLXWindow::GetImplementation(xContainerWindow
);
401 Window
* pParentWin
= pContainerWindow
? pContainerWindow
->GetWindow() : NULL
;
403 throw RuntimeException(::rtl::OUString::createFromAscii("The frame is invalid. Unable to extract the container window."),*this);
405 if ( Construct( pParentWin
) )
409 m_xFrame
->setComponent( VCLUnoHelper::GetInterface( m_pView
), this );
411 catch( const Exception
& )
413 OSL_ENSURE( sal_False
, "OPropertyBrowserController::attachFrame: caught an exception!" );
417 startContainerWindowListening();
422 //------------------------------------------------------------------------
423 sal_Bool SAL_CALL
OPropertyBrowserController::attachModel( const Reference
< XModel
>& _rxModel
) throw(RuntimeException
)
425 Reference
< XObjectInspectorModel
> xModel( _rxModel
, UNO_QUERY
);
429 setInspectorModel( xModel
);
430 return getInspectorModel() == _rxModel
;
433 //------------------------------------------------------------------------
434 sal_Bool
OPropertyBrowserController::suspendAll_nothrow()
436 // if there is a handle inside its "onInteractivePropertySelection" method,
438 // Normally, we could expect every handler to do this itself, but being
439 // realistic, it's safer to handle this here in general.
440 if ( m_xInteractiveHandler
.is() )
443 m_bSuspendingPropertyHandlers
= true;
444 sal_Bool bHandlerVeto
= !suspendPropertyHandlers_nothrow( sal_True
);
445 m_bSuspendingPropertyHandlers
= false;
452 //------------------------------------------------------------------------
453 sal_Bool
OPropertyBrowserController::suspendPropertyHandlers_nothrow( sal_Bool _bSuspend
)
455 PropertyHandlerArray aAllHandlers
; // will contain every handler exactly once
456 for ( PropertyHandlerRepository::const_iterator handler
= m_aPropertyHandlers
.begin();
457 handler
!= m_aPropertyHandlers
.end();
461 if ( ::std::find( aAllHandlers
.begin(), aAllHandlers
.end(), handler
->second
) != aAllHandlers
.end() )
462 // already visited this particular handler (m_aPropertyHandlers usually contains
463 // the same handler more than once)
465 aAllHandlers
.push_back( handler
->second
);
468 for ( PropertyHandlerArray::iterator loop
= aAllHandlers
.begin();
469 loop
!= aAllHandlers
.end();
475 if ( !(*loop
)->suspend( _bSuspend
) )
477 // if we're not suspending, but reactivating, ignore the error
480 catch( const Exception
& )
482 OSL_ENSURE( sal_False
, "OPropertyBrowserController::suspendPropertyHandlers_nothrow: caught an exception!" );
488 //------------------------------------------------------------------------
489 sal_Bool SAL_CALL
OPropertyBrowserController::suspend( sal_Bool _bSuspend
) throw(RuntimeException
)
491 ::osl::MutexGuard
aGuard( m_aMutex
);
492 OSL_ENSURE( haveView(), "OPropertyBrowserController::suspend: don't have a view anymore!" );
495 { // this means a "suspend" is to be "revoked"
496 suspendPropertyHandlers_nothrow( sal_False
);
497 // we ourself cannot revoke our suspend
501 if ( !suspendAll_nothrow() )
504 // commit the editor's content
506 getPropertyBox().CommitModified();
509 stopContainerWindowListening();
515 //------------------------------------------------------------------------
516 Any SAL_CALL
OPropertyBrowserController::getViewData( ) throw(RuntimeException
)
518 return makeAny( m_sPageSelection
);
521 //------------------------------------------------------------------------
522 void SAL_CALL
OPropertyBrowserController::restoreViewData( const Any
& Data
) throw(RuntimeException
)
524 ::rtl::OUString sPageSelection
;
525 if ( ( Data
>>= sPageSelection
) && sPageSelection
.getLength() )
527 m_sPageSelection
= sPageSelection
;
528 selectPageFromViewData();
532 //------------------------------------------------------------------------
533 Reference
< XModel
> SAL_CALL
OPropertyBrowserController::getModel( ) throw(RuntimeException
)
536 return Reference
< XModel
>();
539 //------------------------------------------------------------------------
540 Reference
< XFrame
> SAL_CALL
OPropertyBrowserController::getFrame( ) throw(RuntimeException
)
545 //------------------------------------------------------------------------
546 void SAL_CALL
OPropertyBrowserController::dispose( ) throw(RuntimeException
)
548 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
550 // stop inspecting the current object
551 stopInspection( false );
553 // say our dispose listeners goodbye
554 ::com::sun::star::lang::EventObject aEvt
;
555 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >(this);
556 m_aDisposeListeners
.disposeAndClear(aEvt
);
557 m_aControlObservers
.disposeAndClear(aEvt
);
559 // don't delete explicitly (this is done by the frame we reside in)
562 Reference
< XComponent
> xViewAsComp( m_xView
, UNO_QUERY
);
563 if ( xViewAsComp
.is() )
564 xViewAsComp
->removeEventListener( static_cast< XPropertyChangeListener
* >( this ) );
567 m_aInspectedObjects
.clear();
568 impl_bindToNewModel_nothrow( NULL
);
571 //------------------------------------------------------------------------
572 void SAL_CALL
OPropertyBrowserController::addEventListener( const Reference
< XEventListener
>& _rxListener
) throw(RuntimeException
)
574 m_aDisposeListeners
.addInterface(_rxListener
);
577 //------------------------------------------------------------------------
578 void SAL_CALL
OPropertyBrowserController::removeEventListener( const Reference
< XEventListener
>& _rxListener
) throw(RuntimeException
)
580 m_aDisposeListeners
.removeInterface(_rxListener
);
583 //------------------------------------------------------------------------
584 ::rtl::OUString SAL_CALL
OPropertyBrowserController::getImplementationName( ) throw(RuntimeException
)
586 return getImplementationName_static();
589 //------------------------------------------------------------------------
590 sal_Bool SAL_CALL
OPropertyBrowserController::supportsService( const ::rtl::OUString
& ServiceName
) throw(RuntimeException
)
592 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
593 const ::rtl::OUString
* pArray
= aSupported
.getConstArray();
594 for (sal_Int32 i
= 0; i
< aSupported
.getLength(); ++i
, ++pArray
)
595 if (pArray
->equals(ServiceName
))
600 //------------------------------------------------------------------------
601 Sequence
< ::rtl::OUString
> SAL_CALL
OPropertyBrowserController::getSupportedServiceNames( ) throw(RuntimeException
)
603 return getSupportedServiceNames_static();
606 //------------------------------------------------------------------------
607 ::rtl::OUString
OPropertyBrowserController::getImplementationName_static( ) throw(RuntimeException
)
609 return ::rtl::OUString::createFromAscii("org.openoffice.comp.extensions.ObjectInspector");
612 //------------------------------------------------------------------------
613 Sequence
< ::rtl::OUString
> OPropertyBrowserController::getSupportedServiceNames_static( ) throw(RuntimeException
)
615 Sequence
< ::rtl::OUString
> aSupported(1);
616 aSupported
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.inspection.ObjectInspector" );
620 //------------------------------------------------------------------------
621 Reference
< XInterface
> SAL_CALL
OPropertyBrowserController::Create(const Reference
< XComponentContext
>& _rxContext
)
623 return *(new OPropertyBrowserController( _rxContext
) );
626 //------------------------------------------------------------------------
627 void SAL_CALL
OPropertyBrowserController::focusGained( const FocusEvent
& _rSource
) throw (RuntimeException
)
629 Reference
< XWindow
> xSourceWindow(_rSource
.Source
, UNO_QUERY
);
630 Reference
< XWindow
> xContainerWindow
;
632 xContainerWindow
= m_xFrame
->getContainerWindow();
634 if ( xContainerWindow
.get() == xSourceWindow
.get() )
635 { // our container window got the focus
637 getPropertyBox().GrabFocus();
641 //------------------------------------------------------------------------
642 void SAL_CALL
OPropertyBrowserController::focusLost( const FocusEvent
& /*_rSource*/ ) throw (RuntimeException
)
647 //------------------------------------------------------------------------
648 void SAL_CALL
OPropertyBrowserController::disposing( const EventObject
& _rSource
) throw(RuntimeException
)
650 if ( m_xView
.is() && ( m_xView
== _rSource
.Source
) )
656 for ( InterfaceArray::iterator loop
= m_aInspectedObjects
.begin();
657 loop
!= m_aInspectedObjects
.end();
661 if ( *loop
== _rSource
.Source
)
663 m_aInspectedObjects
.erase( loop
);
669 //------------------------------------------------------------------------
670 IMPL_LINK(OPropertyBrowserController
, OnPageActivation
, void*, EMPTYARG
)
672 updateViewDataFromActivePage();
676 //------------------------------------------------------------------------
677 void OPropertyBrowserController::updateViewDataFromActivePage()
682 ::rtl::OUString sOldSelection
= m_sPageSelection
;
683 m_sPageSelection
= ::rtl::OUString();
685 const sal_uInt16 nCurrentPage
= m_pView
->getActivaPage();
686 if ( (sal_uInt16
)-1 != nCurrentPage
)
688 for ( HashString2Int16::const_iterator pageId
= m_aPageIds
.begin();
689 pageId
!= m_aPageIds
.end();
693 if ( nCurrentPage
== pageId
->second
)
695 m_sPageSelection
= pageId
->first
;
701 if ( m_sPageSelection
.getLength() )
702 m_sLastValidPageSelection
= m_sPageSelection
;
703 else if ( sOldSelection
.getLength() )
704 m_sLastValidPageSelection
= sOldSelection
;
707 //------------------------------------------------------------------------
708 sal_uInt16
OPropertyBrowserController::impl_getPageIdForCategory_nothrow( const ::rtl::OUString
& _rCategoryName
) const
710 sal_uInt16 nPageId
= (sal_uInt16
)-1;
711 HashString2Int16::const_iterator pagePos
= m_aPageIds
.find( _rCategoryName
);
712 if ( pagePos
!= m_aPageIds
.end() )
713 nPageId
= pagePos
->second
;
717 //------------------------------------------------------------------------
718 void OPropertyBrowserController::selectPageFromViewData()
720 sal_uInt16 nNewPage
= impl_getPageIdForCategory_nothrow( m_sPageSelection
);
722 if ( haveView() && ( nNewPage
!= (sal_uInt16
)-1 ) )
723 m_pView
->activatePage( nNewPage
);
726 updateViewDataFromActivePage();
729 //------------------------------------------------------------------------
730 sal_Bool
OPropertyBrowserController::Construct(Window
* _pParentWin
)
732 DBG_ASSERT(!haveView(), "OPropertyBrowserController::Construct: already have a view!");
733 DBG_ASSERT(_pParentWin
, "OPropertyBrowserController::Construct: invalid parent window!");
735 m_pView
= new OPropertyBrowserView(m_aContext
.getLegacyServiceFactory(), _pParentWin
);
736 m_pView
->setPageActivationHandler(LINK(this, OPropertyBrowserController
, OnPageActivation
));
738 // add as dispose listener for our view. The view is disposed by the frame we're plugged into,
739 // and this disposal _deletes_ the view, so it would be deadly if we use our m_pView member
741 m_xView
= VCLUnoHelper::GetInterface(m_pView
);
742 Reference
< XComponent
> xViewAsComp(m_xView
, UNO_QUERY
);
743 if (xViewAsComp
.is())
744 xViewAsComp
->addEventListener( static_cast< XPropertyChangeListener
* >( this ) );
746 getPropertyBox().SetLineListener(this);
747 getPropertyBox().SetControlObserver(this);
748 impl_initializeView_nothrow();
755 //------------------------------------------------------------------------
756 void SAL_CALL
OPropertyBrowserController::propertyChange( const PropertyChangeEvent
& _rEvent
) throw (RuntimeException
)
758 if ( _rEvent
.Source
== m_xModel
)
760 if ( _rEvent
.PropertyName
.equalsAscii( "IsReadOnly" ) )
761 impl_updateReadOnlyView_nothrow();
765 if ( m_sCommittingProperty
== _rEvent
.PropertyName
)
771 Any
aNewValue( _rEvent
.NewValue
);
772 if ( impl_hasPropertyHandlerFor_nothrow( _rEvent
.PropertyName
) )
774 // forward the new value to the property box, to reflect the change in the UI
775 aNewValue
= impl_getPropertyValue_throw( _rEvent
.PropertyName
);
777 // check whether the state is ambiguous. This is interesting in case we display the properties
778 // for multiple objects at once: In this case, we'll get a notification from one of the objects,
779 // but need to care for the "composed" value, which can be "ambiguous".
780 PropertyHandlerRef
xHandler( impl_getHandlerForProperty_throw( _rEvent
.PropertyName
), UNO_SET_THROW
);
781 PropertyState
ePropertyState( xHandler
->getPropertyState( _rEvent
.PropertyName
) );
782 bool bAmbiguousValue
= ( PropertyState_AMBIGUOUS_VALUE
== ePropertyState
);
784 getPropertyBox().SetPropertyValue( _rEvent
.PropertyName
, aNewValue
, bAmbiguousValue
);
787 // if it's a actuating property, then update the UI for any dependent
789 if ( impl_isActuatingProperty_nothrow( _rEvent
.PropertyName
) )
790 impl_broadcastPropertyChange_nothrow( _rEvent
.PropertyName
, aNewValue
, _rEvent
.OldValue
, false );
793 //------------------------------------------------------------------------
794 Reference
< XPropertyControl
> SAL_CALL
OPropertyBrowserController::createPropertyControl( ::sal_Int16 ControlType
, ::sal_Bool _CreateReadOnly
) throw (IllegalArgumentException
, RuntimeException
)
796 ::osl::MutexGuard
aGuard( m_aMutex
);
798 Reference
< XPropertyControl
> xControl
;
800 // default winbits: a border only
801 WinBits nWinBits
= WB_BORDER
;
804 _CreateReadOnly
|= (sal_Bool
)impl_isReadOnlyModel_throw();
805 if ( _CreateReadOnly
)
806 nWinBits
|= WB_READONLY
;
808 switch ( ControlType
)
810 case PropertyControlType::StringListField
:
811 xControl
= new OMultilineEditControl( &getPropertyBox(), eStringList
, nWinBits
| WB_DROPDOWN
| WB_TABSTOP
);
814 case PropertyControlType::MultiLineTextField
:
815 xControl
= new OMultilineEditControl( &getPropertyBox(), eMultiLineText
, nWinBits
| WB_DROPDOWN
| WB_TABSTOP
);
818 case PropertyControlType::ListBox
:
819 xControl
= new OListboxControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
822 case PropertyControlType::ComboBox
:
823 xControl
= new OComboboxControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
826 case PropertyControlType::TextField
:
827 xControl
= new OEditControl( &getPropertyBox(), sal_False
, nWinBits
| WB_TABSTOP
);
830 case PropertyControlType::CharacterField
:
831 xControl
= new OEditControl( &getPropertyBox(), sal_True
, nWinBits
| WB_TABSTOP
);
834 case PropertyControlType::NumericField
:
835 xControl
= new ONumericControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_SPIN
| WB_REPEAT
);
838 case PropertyControlType::DateTimeField
:
839 xControl
= new ODateTimeControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
);
842 case PropertyControlType::DateField
:
843 xControl
= new ODateControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_SPIN
| WB_REPEAT
);
846 case PropertyControlType::TimeField
:
847 xControl
= new OTimeControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_SPIN
| WB_REPEAT
);
850 case PropertyControlType::ColorListBox
:
851 xControl
= new OColorControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
854 case PropertyControlType::HyperlinkField
:
855 xControl
= new OHyperlinkControl( &getPropertyBox(), nWinBits
| WB_TABSTOP
| WB_DROPDOWN
);
859 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
865 //------------------------------------------------------------------------
866 void OPropertyBrowserController::impl_toggleInspecteeListening_nothrow( bool _bOn
)
868 for ( InterfaceArray::const_iterator loop
= m_aInspectedObjects
.begin();
869 loop
!= m_aInspectedObjects
.end();
875 Reference
< XComponent
> xComp( *loop
, UNO_QUERY
);
879 xComp
->addEventListener( static_cast< XPropertyChangeListener
* >( this ) );
881 xComp
->removeEventListener( static_cast< XPropertyChangeListener
* >( this ) );
884 catch( const Exception
& )
886 DBG_UNHANDLED_EXCEPTION();
891 //------------------------------------------------------------------------
892 void OPropertyBrowserController::stopInspection( bool _bCommitModified
)
896 if ( _bCommitModified
)
897 // commit the editor's content
898 getPropertyBox().CommitModified();
900 // hide the property box so that it does not flicker
901 getPropertyBox().Hide();
903 // clear the property box
904 getPropertyBox().ClearAll();
907 // destroy the view first
911 for ( HashString2Int16::const_iterator erase
= m_aPageIds
.begin();
912 erase
!= m_aPageIds
.end();
915 getPropertyBox().RemovePage( erase
->second
);
916 clearContainer( m_aPageIds
);
919 clearContainer( m_aProperties
);
921 // de-register as dispose-listener from our inspected objects
922 impl_toggleInspecteeListening_nothrow( false );
924 // handlers are obsolete, so is our "composer" for their UI requests
925 if ( m_pUIRequestComposer
.get() )
926 m_pUIRequestComposer
->dispose();
927 m_pUIRequestComposer
.reset( NULL
);
929 // clean up the property handlers
930 PropertyHandlerArray aAllHandlers
; // will contain every handler exactly once
931 for ( PropertyHandlerRepository::const_iterator aHandler
= m_aPropertyHandlers
.begin();
932 aHandler
!= m_aPropertyHandlers
.end();
935 if ( ::std::find( aAllHandlers
.begin(), aAllHandlers
.end(), aHandler
->second
) == aAllHandlers
.end() )
936 aAllHandlers
.push_back( aHandler
->second
);
938 for ( PropertyHandlerArray::iterator loop
= aAllHandlers
.begin();
939 loop
!= aAllHandlers
.end();
945 (*loop
)->removePropertyChangeListener( this );
948 catch( const DisposedException
& )
951 catch( const Exception
& )
953 DBG_UNHANDLED_EXCEPTION();
957 clearContainer( m_aPropertyHandlers
);
958 clearContainer( m_aDependencyHandlers
);
961 //------------------------------------------------------------------------
962 bool OPropertyBrowserController::impl_hasPropertyHandlerFor_nothrow( const ::rtl::OUString
& _rPropertyName
) const
964 PropertyHandlerRepository::const_iterator handlerPos
= m_aPropertyHandlers
.find( _rPropertyName
);
965 return ( handlerPos
!= m_aPropertyHandlers
.end() );
968 //------------------------------------------------------------------------
969 OPropertyBrowserController::PropertyHandlerRef
OPropertyBrowserController::impl_getHandlerForProperty_throw( const ::rtl::OUString
& _rPropertyName
) const
971 PropertyHandlerRepository::const_iterator handlerPos
= m_aPropertyHandlers
.find( _rPropertyName
);
972 if ( handlerPos
== m_aPropertyHandlers
.end() )
973 throw RuntimeException();
974 return handlerPos
->second
;
977 //------------------------------------------------------------------------
978 Any
OPropertyBrowserController::impl_getPropertyValue_throw( const ::rtl::OUString
& _rPropertyName
)
980 PropertyHandlerRef handler
= impl_getHandlerForProperty_throw( _rPropertyName
);
981 return handler
->getPropertyValue( _rPropertyName
);
984 //------------------------------------------------------------------------
985 void OPropertyBrowserController::impl_rebindToInspectee_nothrow( const InterfaceArray
& _rObjects
)
989 // stop inspecting the old object(s)
990 stopInspection( true );
992 // inspect the new object(s)
993 m_aInspectedObjects
= _rObjects
;
996 // update the user interface
1002 DBG_ERROR("OPropertyBrowserController::impl_rebindToInspectee_nothrow: caught an exception !");
1006 //------------------------------------------------------------------------
1007 void OPropertyBrowserController::doInspection()
1011 //////////////////////////////////////////////////////////////////////
1012 // obtain the properties of the object
1013 ::std::vector
< Property
> aProperties
;
1015 PropertyHandlerArray aPropertyHandlers
;
1016 getPropertyHandlers( m_aInspectedObjects
, aPropertyHandlers
);
1018 PropertyHandlerArray::iterator
aHandler( aPropertyHandlers
.begin() );
1019 while ( aHandler
!= aPropertyHandlers
.end() )
1021 DBG_ASSERT( aHandler
->get(), "OPropertyBrowserController::doInspection: invalid handler!" );
1023 StlSyntaxSequence
< Property
> aThisHandlersProperties
= (*aHandler
)->getSupportedProperties();
1025 if ( aThisHandlersProperties
.empty() )
1027 // this handler doesn't know anything about the current inspectee -> ignore it
1028 (*aHandler
)->dispose();
1029 aHandler
= aPropertyHandlers
.erase( aHandler
);
1033 // append these properties to our "all properties" array
1034 aProperties
.reserve( aProperties
.size() + aThisHandlersProperties
.size() );
1035 for ( StlSyntaxSequence
< Property
>::const_iterator copyProperty
= aThisHandlersProperties
.begin();
1036 copyProperty
!= aThisHandlersProperties
.end();
1040 ::std::vector
< Property
>::const_iterator previous
= ::std::find_if(
1041 aProperties
.begin(),
1043 FindPropertyByName( copyProperty
->Name
)
1045 if ( previous
== aProperties
.end() )
1047 aProperties
.push_back( *copyProperty
);
1051 // there already was another (previous) handler which supported this property.
1052 // Don't add it to aProperties, again.
1054 // Also, ensure that handlers which previously expressed interest in *changes*
1055 // of this property are not notified.
1056 // This is 'cause we have a new handler which is responsible for this property,
1057 // which means it can give it a completely different meaning than the previous
1058 // handler for this property is prepared for.
1059 ::std::pair
< PropertyHandlerMultiRepository::iterator
, PropertyHandlerMultiRepository::iterator
>
1060 aDepHandlers
= m_aDependencyHandlers
.equal_range( copyProperty
->Name
);
1061 m_aDependencyHandlers
.erase( aDepHandlers
.first
, aDepHandlers
.second
);
1064 // determine the superseded properties
1065 StlSyntaxSequence
< ::rtl::OUString
> aSupersededByThisHandler
= (*aHandler
)->getSupersededProperties();
1066 for ( StlSyntaxSequence
< ::rtl::OUString
>::const_iterator superseded
= aSupersededByThisHandler
.begin();
1067 superseded
!= aSupersededByThisHandler
.end();
1071 ::std::vector
< Property
>::iterator existent
= ::std::find_if(
1072 aProperties
.begin(),
1074 FindPropertyByName( *superseded
)
1076 if ( existent
!= aProperties
.end() )
1077 // one of the properties superseded by this handler was supported by a previous
1079 aProperties
.erase( existent
);
1082 // be notified of changes which this handler is responsible for
1083 (*aHandler
)->addPropertyChangeListener( this );
1085 // remember this handler for every of the properties which it is responsible
1087 for ( StlSyntaxSequence
< Property
>::const_iterator remember
= aThisHandlersProperties
.begin();
1088 remember
!= aThisHandlersProperties
.end();
1092 m_aPropertyHandlers
[ remember
->Name
] = *aHandler
;
1093 // note that this implies that if two handlers support the same property,
1097 // see if the handler expresses interest in any actuating properties
1098 StlSyntaxSequence
< ::rtl::OUString
> aInterestingActuations
= (*aHandler
)->getActuatingProperties();
1099 for ( StlSyntaxSequence
< ::rtl::OUString
>::const_iterator aLoop
= aInterestingActuations
.begin();
1100 aLoop
!= aInterestingActuations
.end();
1104 m_aDependencyHandlers
.insert( PropertyHandlerMultiRepository::value_type(
1105 *aLoop
, *aHandler
) );
1111 // create a new composer for UI requests coming from the handlers
1112 m_pUIRequestComposer
.reset( new ComposedPropertyUIUpdate( getInspectorUI(), this ) );
1114 // sort the properties by relative position, as indicated by the model
1115 for ( ::std::vector
< Property
>::const_iterator sourceProps
= aProperties
.begin();
1116 sourceProps
!= aProperties
.end();
1120 sal_Int32 nRelativePropertyOrder
= sourceProps
- aProperties
.begin();
1121 if ( m_xModel
.is() )
1122 nRelativePropertyOrder
= m_xModel
->getPropertyOrderIndex( sourceProps
->Name
);
1123 while ( m_aProperties
.find( nRelativePropertyOrder
) != m_aProperties
.end() )
1124 ++nRelativePropertyOrder
;
1125 m_aProperties
[ nRelativePropertyOrder
] = *sourceProps
;
1128 // be notified when one of our inspectees dies
1129 impl_toggleInspecteeListening_nothrow( true );
1133 DBG_ERROR("OPropertyBrowserController::doInspection : caught an exception !");
1137 //------------------------------------------------------------------------
1138 ::com::sun::star::awt::Size SAL_CALL
OPropertyBrowserController::getMinimumSize() throw (::com::sun::star::uno::RuntimeException
)
1140 ::com::sun::star::awt::Size aSize
;
1142 return m_pView
->getMinimumSize();
1147 //------------------------------------------------------------------------
1148 ::com::sun::star::awt::Size SAL_CALL
OPropertyBrowserController::getPreferredSize() throw (::com::sun::star::uno::RuntimeException
)
1150 return getMinimumSize();
1153 //------------------------------------------------------------------------
1154 ::com::sun::star::awt::Size SAL_CALL
OPropertyBrowserController::calcAdjustedSize( const ::com::sun::star::awt::Size
& _rNewSize
) throw (::com::sun::star::uno::RuntimeException
)
1156 awt::Size aMinSize
= getMinimumSize( );
1157 awt::Size
aAdjustedSize( _rNewSize
);
1158 if ( aAdjustedSize
.Width
< aMinSize
.Width
)
1159 aAdjustedSize
.Width
= aMinSize
.Width
;
1160 if ( aAdjustedSize
.Height
< aMinSize
.Height
)
1161 aAdjustedSize
.Height
= aMinSize
.Height
;
1162 return aAdjustedSize
;
1165 //------------------------------------------------------------------------
1166 void OPropertyBrowserController::describePropertyLine( const Property
& _rProperty
, OLineDescriptor
& _rDescriptor
) SAL_THROW((Exception
))
1170 PropertyHandlerRepository::const_iterator handler
= m_aPropertyHandlers
.find( _rProperty
.Name
);
1171 if ( handler
== m_aPropertyHandlers
.end() )
1172 throw RuntimeException(); // caught below
1174 _rDescriptor
.assignFrom( handler
->second
->describePropertyLine( _rProperty
.Name
, this ) );
1176 //////////////////////////////////////////////////////////////////////
1178 _rDescriptor
.xPropertyHandler
= handler
->second
;
1179 _rDescriptor
.sName
= _rProperty
.Name
;
1180 _rDescriptor
.aValue
= _rDescriptor
.xPropertyHandler
->getPropertyValue( _rProperty
.Name
);
1182 if ( !_rDescriptor
.DisplayName
.getLength() )
1185 ::rtl::OString
sMessage( "OPropertyBrowserController::describePropertyLine: handler did not provide a display name for '" );
1186 sMessage
+= ::rtl::OString( _rProperty
.Name
.getStr(), _rProperty
.Name
.getLength(), RTL_TEXTENCODING_ASCII_US
);
1187 sMessage
+= ::rtl::OString( "'!" );
1188 DBG_ASSERT( _rDescriptor
.DisplayName
.getLength(), sMessage
);
1190 _rDescriptor
.DisplayName
= _rProperty
.Name
;
1193 PropertyState
ePropertyState( _rDescriptor
.xPropertyHandler
->getPropertyState( _rProperty
.Name
) );
1194 if ( PropertyState_AMBIGUOUS_VALUE
== ePropertyState
)
1196 _rDescriptor
.bUnknownValue
= true;
1197 _rDescriptor
.aValue
.clear();
1200 _rDescriptor
.bReadOnly
= impl_isReadOnlyModel_throw();
1202 catch( const Exception
& )
1204 OSL_ENSURE( sal_False
, "OPropertyBrowserController::describePropertyLine: caught an exception!" );
1208 //------------------------------------------------------------------------
1209 void OPropertyBrowserController::impl_buildCategories_throw()
1211 OSL_PRECOND( m_aPageIds
.empty(), "OPropertyBrowserController::impl_buildCategories_throw: duplicate call!" );
1213 StlSyntaxSequence
< PropertyCategoryDescriptor
> aCategories
;
1214 if ( m_xModel
.is() )
1215 aCategories
= m_xModel
->describeCategories();
1217 for ( StlSyntaxSequence
< PropertyCategoryDescriptor
>::const_iterator category
= aCategories
.begin();
1218 category
!= aCategories
.end();
1222 OSL_ENSURE( m_aPageIds
.find( category
->ProgrammaticName
) == m_aPageIds
.end(),
1223 "OPropertyBrowserController::impl_buildCategories_throw: duplicate programmatic name!" );
1225 m_aPageIds
[ category
->ProgrammaticName
] =
1226 getPropertyBox().AppendPage( category
->UIName
, HelpIdUrl::getHelpId( category
->HelpURL
) );
1230 //------------------------------------------------------------------------
1231 void OPropertyBrowserController::UpdateUI()
1236 // too early, will return later
1239 getPropertyBox().DisableUpdate();
1241 sal_Bool bHaveFocus
= getPropertyBox().HasChildPathFocus();
1243 // create our tab pages
1244 impl_buildCategories_throw();
1245 // (and allow for pages to be actually unused)
1246 ::std::set
< sal_uInt16
> aUsedPages
;
1248 // when building the UI below, remember which properties are actuating,
1249 // to allow for a initial actuatinPropertyChanged call
1250 ::std::vector
< ::rtl::OUString
> aActuatingProperties
;
1251 ::std::vector
< Any
> aActuatingPropertyValues
;
1253 // ask the handlers to describe the property UI, and insert the resulting
1254 // entries into our list boxes
1255 OrderedPropertyMap::const_iterator
property( m_aProperties
.begin() );
1256 for ( ; property
!= m_aProperties
.end(); ++property
)
1258 OLineDescriptor aDescriptor
;
1259 describePropertyLine( property
->second
, aDescriptor
);
1261 bool bIsActuatingProperty
= impl_isActuatingProperty_nothrow( property
->second
.Name
);
1263 #if OSL_DEBUG_LEVEL > 0
1264 if ( !aDescriptor
.Category
.getLength() )
1266 ::rtl::OString
sMessage( "OPropertyBrowserController::UpdateUI: empty category provided for property '" );
1267 sMessage
+= ::rtl::OString( property
->second
.Name
.getStr(), property
->second
.Name
.getLength(), osl_getThreadTextEncoding() );
1269 OSL_ENSURE( false, sMessage
);
1272 // finally insert this property control
1273 sal_uInt16 nTargetPageId
= impl_getPageIdForCategory_nothrow( aDescriptor
.Category
);
1274 if ( nTargetPageId
== (sal_uInt16
)-1 )
1276 // this category does not yet exist. This is allowed, as an inspector model might be lazy, and not provide
1277 // any category information of its own. In this case, we have a fallback ...
1278 m_aPageIds
[ aDescriptor
.Category
] =
1279 getPropertyBox().AppendPage( aDescriptor
.Category
, SmartId() );
1280 nTargetPageId
= impl_getPageIdForCategory_nothrow( aDescriptor
.Category
);
1283 getPropertyBox().InsertEntry( aDescriptor
, nTargetPageId
);
1284 aUsedPages
.insert( nTargetPageId
);
1286 // if it's an actuating property, remember it
1287 if ( bIsActuatingProperty
)
1289 aActuatingProperties
.push_back( property
->second
.Name
);
1290 aActuatingPropertyValues
.push_back( impl_getPropertyValue_throw( property
->second
.Name
) );
1294 // update any dependencies for the actuating properties which we encountered
1296 ::std::vector
< ::rtl::OUString
>::const_iterator aProperty
= aActuatingProperties
.begin();
1297 ::std::vector
< Any
>::const_iterator aPropertyValue
= aActuatingPropertyValues
.begin();
1298 for ( ; aProperty
!= aActuatingProperties
.end(); ++aProperty
, ++aPropertyValue
)
1299 impl_broadcastPropertyChange_nothrow( *aProperty
, *aPropertyValue
, *aPropertyValue
, true );
1302 // remove any unused pages (which we did not encounter properties for)
1303 HashString2Int16 aSurvivingPageIds
;
1304 for ( HashString2Int16::iterator pageId
= m_aPageIds
.begin();
1305 pageId
!= m_aPageIds
.end();
1309 if ( aUsedPages
.find( pageId
->second
) == aUsedPages
.end() )
1310 getPropertyBox().RemovePage( pageId
->second
);
1312 aSurvivingPageIds
.insert( *pageId
);
1314 m_aPageIds
.swap( aSurvivingPageIds
);
1317 getPropertyBox().Show();
1318 getPropertyBox().EnableUpdate();
1320 getPropertyBox().GrabFocus();
1322 // activate the first page
1323 if ( !m_aPageIds
.empty() )
1325 Sequence
< PropertyCategoryDescriptor
> aCategories( m_xModel
->describeCategories() );
1326 if ( aCategories
.getLength() )
1327 m_pView
->activatePage( m_aPageIds
[ aCategories
[0].ProgrammaticName
] );
1329 // allowed: if we default-created the pages ...
1330 m_pView
->activatePage( m_aPageIds
.begin()->second
);
1333 // activate the previously active page (if possible)
1334 if ( m_sLastValidPageSelection
.getLength() )
1335 m_sPageSelection
= m_sLastValidPageSelection
;
1336 selectPageFromViewData();
1338 catch( const Exception
& )
1340 DBG_UNHANDLED_EXCEPTION();
1344 //------------------------------------------------------------------------
1345 void OPropertyBrowserController::Clicked( const ::rtl::OUString
& _rName
, sal_Bool _bPrimary
)
1349 // since the browse buttons do not get the focus when clicked with the mouse,
1350 // we need to commit the changes in the current property field
1351 getPropertyBox().CommitModified();
1353 PropertyHandlerRepository::const_iterator handler
= m_aPropertyHandlers
.find( _rName
);
1354 DBG_ASSERT( handler
!= m_aPropertyHandlers
.end(), "OPropertyBrowserController::Clicked: a property without handler? This will crash!" );
1356 ComposedUIAutoFireGuard
aAutoFireGuard( *m_pUIRequestComposer
);
1359 m_xInteractiveHandler
= handler
->second
;
1360 InteractiveSelectionResult eResult
=
1361 handler
->second
->onInteractivePropertySelection( _rName
, _bPrimary
, aData
,
1362 m_pUIRequestComposer
->getUIForPropertyHandler( handler
->second
) );
1366 case InteractiveSelectionResult_Cancelled
:
1367 case InteractiveSelectionResult_Success
:
1368 // okay, nothing to do
1370 case InteractiveSelectionResult_ObtainedValue
:
1371 handler
->second
->setPropertyValue( _rName
, aData
);
1373 case InteractiveSelectionResult_Pending
:
1374 // also okay, we expect that the handler has disabled the UI as necessary
1377 OSL_ENSURE( false, "OPropertyBrowserController::Clicked: unknown result value!" );
1383 DBG_UNHANDLED_EXCEPTION();
1385 m_xInteractiveHandler
= NULL
;
1388 //------------------------------------------------------------------------
1389 sal_Bool SAL_CALL
OPropertyBrowserController::hasPropertyByName( const ::rtl::OUString
& _rName
) throw (RuntimeException
)
1391 for ( OrderedPropertyMap::const_iterator search
= m_aProperties
.begin();
1392 search
!= m_aProperties
.end();
1395 if ( search
->second
.Name
== _rName
)
1400 //------------------------------------------------------------------------
1401 void OPropertyBrowserController::Commit( const ::rtl::OUString
& rName
, const Any
& _rValue
)
1405 rtl::OUString sPlcHolder
= String( PcrRes( RID_EMBED_IMAGE_PLACEHOLDER
) );
1406 bool bIsPlaceHolderValue
= false;
1408 if ( rName
.equals( PROPERTY_IMAGE_URL
) )
1410 // if the prop value is the PlaceHolder
1414 if ( sVal
.equals( sPlcHolder
) )
1415 bIsPlaceHolderValue
= true;
1417 m_sCommittingProperty
= rName
;
1419 bool bIsActuatingProperty
= impl_isActuatingProperty_nothrow( rName
);
1422 if ( bIsActuatingProperty
)
1423 aOldValue
= impl_getPropertyValue_throw( rName
);
1425 // do we have a dedicated handler for this property, which we can delegate some tasks to?
1426 PropertyHandlerRef handler
= impl_getHandlerForProperty_throw( rName
);
1428 //////////////////////////////////////////////////////////////////////
1429 // set the value ( only if it's not a placeholder )
1430 if ( !bIsPlaceHolderValue
)
1431 handler
->setPropertyValue( rName
, _rValue
);
1433 //////////////////////////////////////////////////////////////////////
1434 // re-retrieve the value
1435 Any aNormalizedValue
= handler
->getPropertyValue( rName
);
1437 // care for any inter-property dependencies
1438 if ( bIsActuatingProperty
)
1439 impl_broadcastPropertyChange_nothrow( rName
, aNormalizedValue
, aOldValue
, false );
1441 // and display it again. This ensures proper formatting
1442 getPropertyBox().SetPropertyValue( rName
, aNormalizedValue
, false );
1444 catch(PropertyVetoException
& eVetoException
)
1446 InfoBox(m_pView
, eVetoException
.Message
).Execute();
1447 PropertyHandlerRef handler
= impl_getHandlerForProperty_throw( rName
);
1448 Any aNormalizedValue
= handler
->getPropertyValue( rName
);
1449 getPropertyBox().SetPropertyValue( rName
, aNormalizedValue
, false );
1453 DBG_ERROR("OPropertyBrowserController::Commit : caught an exception !");
1456 m_sCommittingProperty
= ::rtl::OUString();
1459 //--------------------------------------------------------------------
1464 //--------------------------------------------------------------------
1465 void OPropertyBrowserController::focusGained( const Reference
< XPropertyControl
>& _Control
)
1467 m_aControlObservers
.notifyEach( &XPropertyControlObserver::focusGained
, _Control
);
1470 //--------------------------------------------------------------------
1471 void OPropertyBrowserController::valueChanged( const Reference
< XPropertyControl
>& _Control
)
1473 m_aControlObservers
.notifyEach( &XPropertyControlObserver::valueChanged
, _Control
);
1476 //------------------------------------------------------------------------
1479 Reference
< XPropertyHandler
> lcl_createHandler( const ComponentContext
& _rContext
, const Any
& _rFactoryDescriptor
)
1481 Reference
< XPropertyHandler
> xHandler
;
1483 ::rtl::OUString sServiceName
;
1484 Reference
< XSingleServiceFactory
> xServiceFac
;
1485 Reference
< XSingleComponentFactory
> xComponentFac
;
1487 if ( _rFactoryDescriptor
>>= sServiceName
)
1488 _rContext
.createComponent( sServiceName
, xHandler
);
1489 else if ( _rFactoryDescriptor
>>= xServiceFac
)
1490 xHandler
= xHandler
.query( xServiceFac
->createInstance() );
1491 else if ( _rFactoryDescriptor
>>= xComponentFac
)
1492 xHandler
= xHandler
.query( xComponentFac
->createInstanceWithContext( _rContext
.getUNOContext() ) );
1493 OSL_ENSURE(xHandler
.is(),"lcl_createHandler: Can not create handler");
1498 //------------------------------------------------------------------------
1499 void OPropertyBrowserController::getPropertyHandlers( const InterfaceArray
& _rObjects
, PropertyHandlerArray
& _rHandlers
)
1501 _rHandlers
.resize( 0 );
1502 if ( _rObjects
.empty() )
1505 // create a component context for the handlers, containing some information about where
1507 Reference
< XComponentContext
> xHandlerContext( m_aContext
.getUNOContext() );
1509 // if our own creator did not pass a dialog parent window, use our own view for this
1510 Reference
< XWindow
> xParentWindow( m_aContext
.getContextValueByAsciiName( "DialogParentWindow" ), UNO_QUERY
);
1511 if ( !xParentWindow
.is() )
1513 ::cppu::ContextEntry_Init aHandlerContextInfo
[] =
1515 ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogParentWindow" ) ), makeAny( VCLUnoHelper::GetInterface( m_pView
) ) )
1517 xHandlerContext
= ::cppu::createComponentContext(
1518 aHandlerContextInfo
, sizeof( aHandlerContextInfo
) / sizeof( aHandlerContextInfo
[0] ),
1519 m_aContext
.getUNOContext() );
1522 Sequence
< Any
> aHandlerFactories
;
1523 if ( m_xModel
.is() )
1524 aHandlerFactories
= m_xModel
->getHandlerFactories();
1526 const Any
* pHandlerFactory
= aHandlerFactories
.getConstArray();
1527 const Any
* pHandlerFactoryEnd
= aHandlerFactories
.getConstArray() + aHandlerFactories
.getLength();
1529 while ( pHandlerFactory
!= pHandlerFactoryEnd
)
1531 if ( _rObjects
.size() == 1 )
1532 { // we're inspecting only one object -> one handler
1533 Reference
< XPropertyHandler
> xHandler( lcl_createHandler( m_aContext
, *pHandlerFactory
) );
1534 if ( xHandler
.is() )
1536 xHandler
->inspect( _rObjects
[0] );
1537 _rHandlers
.push_back( xHandler
);
1542 // create a single handler for every single object
1543 ::std::vector
< Reference
< XPropertyHandler
> > aSingleHandlers( _rObjects
.size() );
1544 ::std::vector
< Reference
< XPropertyHandler
> >::iterator pHandler
= aSingleHandlers
.begin();
1546 InterfaceArray::const_iterator pObject
= _rObjects
.begin();
1547 InterfaceArray::const_iterator pObjectEnd
= _rObjects
.end();
1549 for ( ; pObject
!= pObjectEnd
; ++pObject
)
1551 *pHandler
= lcl_createHandler( m_aContext
, *pHandlerFactory
);
1552 if ( pHandler
->is() )
1554 (*pHandler
)->inspect( *pObject
);
1558 aSingleHandlers
.resize( pHandler
- aSingleHandlers
.begin() );
1560 // then create a handler which composes information out of those single handlers
1561 if ( !aSingleHandlers
.empty() )
1562 _rHandlers
.push_back( new PropertyComposer( aSingleHandlers
) );
1568 // note that the handlers will not be used by our caller, if they indicate that there are no
1569 // properties they feel responsible for
1572 //------------------------------------------------------------------------
1573 bool OPropertyBrowserController::impl_findObjectProperty_nothrow( const ::rtl::OUString
& _rName
, OrderedPropertyMap::const_iterator
* _pProperty
)
1575 OrderedPropertyMap::const_iterator search
= m_aProperties
.begin();
1576 for ( ; search
!= m_aProperties
.end(); ++search
)
1577 if ( search
->second
.Name
== _rName
)
1580 *_pProperty
= search
;
1581 return ( search
!= m_aProperties
.end() );
1584 //------------------------------------------------------------------------
1585 void OPropertyBrowserController::rebuildPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1587 ::osl::MutexGuard
aGuard( m_aMutex
);
1589 throw RuntimeException();
1591 OrderedPropertyMap::const_iterator propertyPos
;
1592 if ( !impl_findObjectProperty_nothrow( _rPropertyName
, &propertyPos
) )
1595 OLineDescriptor aDescriptor
;
1598 describePropertyLine( propertyPos
->second
, aDescriptor
);
1600 catch( const Exception
& )
1602 OSL_ENSURE( sal_False
, "OPropertyBrowserController::rebuildPropertyUI: caught an exception!" );
1605 getPropertyBox().ChangeEntry( aDescriptor
);
1608 //------------------------------------------------------------------------
1609 void OPropertyBrowserController::enablePropertyUI( const ::rtl::OUString
& _rPropertyName
, sal_Bool _bEnable
) throw (RuntimeException
)
1611 ::osl::MutexGuard
aGuard( m_aMutex
);
1613 throw RuntimeException();
1615 if ( !impl_findObjectProperty_nothrow( _rPropertyName
) )
1618 getPropertyBox().EnablePropertyLine( _rPropertyName
, _bEnable
);
1621 //------------------------------------------------------------------------
1622 void OPropertyBrowserController::enablePropertyUIElements( const ::rtl::OUString
& _rPropertyName
, sal_Int16 _nElements
, sal_Bool _bEnable
) throw (RuntimeException
)
1624 ::osl::MutexGuard
aGuard( m_aMutex
);
1626 throw RuntimeException();
1628 if ( !impl_findObjectProperty_nothrow( _rPropertyName
) )
1631 getPropertyBox().EnablePropertyControls( _rPropertyName
, _nElements
, _bEnable
);
1634 //------------------------------------------------------------------------
1635 void OPropertyBrowserController::showPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1637 ::osl::MutexGuard
aGuard( m_aMutex
);
1639 throw RuntimeException();
1641 // look up the property in our object properties
1642 OrderedPropertyMap::const_iterator propertyPos
;
1643 if ( !impl_findObjectProperty_nothrow( _rPropertyName
, &propertyPos
) )
1646 if ( getPropertyBox().GetPropertyPos( _rPropertyName
) != LISTBOX_ENTRY_NOTFOUND
)
1648 rebuildPropertyUI( _rPropertyName
);
1652 OLineDescriptor aDescriptor
;
1653 describePropertyLine( propertyPos
->second
, aDescriptor
);
1655 // look for the position to insert the property
1657 // side note: The methods GetPropertyPos and InsertEntry of the OPropertyEditor work
1658 // only on the current page. This implies that it's impossible to use this method here
1659 // to show property lines which are *not* on the current page.
1660 // This is sufficient for now, but should be changed in the future.
1662 // by definition, the properties in m_aProperties are in the order in which they appear in the UI
1663 // So all we need is a predecessor of pProperty in m_aProperties
1664 sal_uInt16 nUIPos
= LISTBOX_ENTRY_NOTFOUND
;
1667 if ( propertyPos
!= m_aProperties
.begin() )
1669 nUIPos
= getPropertyBox().GetPropertyPos( propertyPos
->second
.Name
);
1671 while ( ( nUIPos
== LISTBOX_ENTRY_NOTFOUND
) && ( propertyPos
!= m_aProperties
.begin() ) );
1673 if ( nUIPos
== LISTBOX_ENTRY_NOTFOUND
)
1674 // insert at the very top
1677 // insert right after the predecessor we found
1680 getPropertyBox().InsertEntry(
1681 aDescriptor
, impl_getPageIdForCategory_nothrow( aDescriptor
.Category
), nUIPos
);
1684 //------------------------------------------------------------------------
1685 void OPropertyBrowserController::hidePropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1687 ::osl::MutexGuard
aGuard( m_aMutex
);
1689 throw RuntimeException();
1691 if ( !impl_findObjectProperty_nothrow( _rPropertyName
) )
1694 getPropertyBox().RemoveEntry( _rPropertyName
);
1697 //------------------------------------------------------------------------
1698 void OPropertyBrowserController::showCategory( const ::rtl::OUString
& _rCategory
, sal_Bool _bShow
) throw (RuntimeException
)
1700 ::osl::MutexGuard
aGuard( m_aMutex
);
1702 throw RuntimeException();
1704 sal_uInt16 nPageId
= impl_getPageIdForCategory_nothrow( _rCategory
);
1705 OSL_ENSURE( nPageId
!= (sal_uInt16
)-1, "OPropertyBrowserController::showCategory: invalid category!" );
1707 getPropertyBox().ShowPropertyPage( nPageId
, _bShow
);
1710 //------------------------------------------------------------------------
1711 Reference
< XPropertyControl
> SAL_CALL
OPropertyBrowserController::getPropertyControl( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
1713 ::osl::MutexGuard
aGuard( m_aMutex
);
1715 throw RuntimeException();
1717 Reference
< XPropertyControl
> xControl( getPropertyBox().GetPropertyControl( _rPropertyName
) );
1721 //--------------------------------------------------------------------
1722 void SAL_CALL
OPropertyBrowserController::registerControlObserver( const Reference
< XPropertyControlObserver
>& _Observer
) throw (RuntimeException
)
1724 m_aControlObservers
.addInterface( _Observer
);
1727 //--------------------------------------------------------------------
1728 void SAL_CALL
OPropertyBrowserController::revokeControlObserver( const Reference
< XPropertyControlObserver
>& _Observer
) throw (RuntimeException
)
1730 m_aControlObservers
.removeInterface( _Observer
);
1733 //------------------------------------------------------------------------
1734 void SAL_CALL
OPropertyBrowserController::setHelpSectionText( const ::rtl::OUString
& _rHelpText
) throw (NoSupportException
, RuntimeException
)
1736 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
1737 ::osl::MutexGuard
aGuard( m_aMutex
);
1740 throw DisposedException();
1742 if ( !getPropertyBox().HasHelpSection() )
1743 throw NoSupportException();
1745 getPropertyBox().SetHelpText( _rHelpText
);
1748 //------------------------------------------------------------------------
1749 void OPropertyBrowserController::impl_broadcastPropertyChange_nothrow( const ::rtl::OUString
& _rPropertyName
, const Any
& _rNewValue
, const Any
& _rOldValue
, bool _bFirstTimeInit
) const
1751 // are there one or more handlers which are interested in the actuation?
1752 ::std::pair
< PropertyHandlerMultiRepository::const_iterator
, PropertyHandlerMultiRepository::const_iterator
> aInterestedHandlers
=
1753 m_aDependencyHandlers
.equal_range( _rPropertyName
);
1754 if ( aInterestedHandlers
.first
== aInterestedHandlers
.second
)
1755 // none of our handlers is interested in this
1758 ComposedUIAutoFireGuard
aAutoFireGuard( *m_pUIRequestComposer
);
1761 // collect the responses from all interested handlers
1762 PropertyHandlerMultiRepository::const_iterator handler
= aInterestedHandlers
.first
;
1763 while ( handler
!= aInterestedHandlers
.second
)
1765 handler
->second
->actuatingPropertyChanged( _rPropertyName
, _rNewValue
, _rOldValue
,
1766 m_pUIRequestComposer
->getUIForPropertyHandler( handler
->second
),
1771 catch( const Exception
& )
1773 DBG_UNHANDLED_EXCEPTION();
1777 //............................................................................
1779 //............................................................................