update credits
[LibreOffice.git] / extensions / source / propctrlr / propcontroller.cxx
blob6c628a1c82503e9144f1a6ec585939b07f73c78c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "propcontroller.hxx"
21 #include "pcrstrings.hxx"
22 #include "standardcontrol.hxx"
23 #include "linedescriptor.hxx"
24 #include "propresid.hrc"
25 #include "formresid.hrc"
26 #include "propertyeditor.hxx"
27 #include "modulepcr.hxx"
28 #include "formstrings.hxx"
29 #include "formmetadata.hxx"
30 #include "formbrowsertools.hxx"
31 #include "propertycomposer.hxx"
33 #include <com/sun/star/awt/XWindow.hpp>
34 #include <com/sun/star/util/XCloseable.hpp>
35 #include <com/sun/star/inspection/PropertyControlType.hpp>
36 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
37 #include <tools/debug.hxx>
38 #include <tools/diagnose_ex.h>
39 #include <comphelper/types.hxx>
40 #include <comphelper/extract.hxx>
41 #include <toolkit/awt/vclxwindow.hxx>
42 #include <toolkit/unohlp.hxx>
43 #include <comphelper/property.hxx>
44 #include <vcl/msgbox.hxx>
45 #include <vcl/svapp.hxx>
46 #include <osl/mutex.hxx>
47 #include <cppuhelper/component_context.hxx>
48 #include <cppuhelper/exc_hlp.hxx>
50 #include <algorithm>
51 #include <functional>
52 #include <sal/macros.h>
54 //------------------------------------------------------------------------
55 // !!! outside the namespace !!!
56 extern "C" void SAL_CALL createRegistryInfo_OPropertyBrowserController()
58 ::pcr::OAutoRegistration< ::pcr::OPropertyBrowserController > aAutoRegistration;
61 //............................................................................
62 namespace pcr
64 //............................................................................
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::awt;
69 using namespace ::com::sun::star::form;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::script;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::container;
74 using namespace ::com::sun::star::frame;
75 using namespace ::com::sun::star::util;
76 using namespace ::com::sun::star::inspection;
77 using namespace ::com::sun::star::ucb;
78 using namespace ::comphelper;
80 //========================================================================
81 //= OPropertyBrowserController
82 //========================================================================
83 DBG_NAME(OPropertyBrowserController)
84 //------------------------------------------------------------------------
85 OPropertyBrowserController::OPropertyBrowserController( const Reference< XComponentContext >& _rxContext )
86 :m_aContext(_rxContext)
87 ,m_aDisposeListeners( m_aMutex )
88 ,m_aControlObservers( m_aMutex )
89 ,m_pView(NULL)
90 ,m_bContainerFocusListening( false )
91 ,m_bSuspendingPropertyHandlers( false )
92 ,m_bConstructed( false )
93 ,m_bBindingIntrospectee( false )
95 DBG_CTOR(OPropertyBrowserController,NULL);
98 //------------------------------------------------------------------------
99 OPropertyBrowserController::~OPropertyBrowserController()
101 // stop listening for property changes
102 acquire();
103 stopInspection( true );
104 DBG_DTOR(OPropertyBrowserController,NULL);
107 //------------------------------------------------------------------------
108 IMPLEMENT_FORWARD_REFCOUNT( OPropertyBrowserController, OPropertyBrowserController_Base )
110 //------------------------------------------------------------------------
111 Any SAL_CALL OPropertyBrowserController::queryInterface( const Type& _rType ) throw (RuntimeException)
113 Any aReturn = OPropertyBrowserController_Base::queryInterface( _rType );
114 if ( !aReturn.hasValue() )
115 aReturn = ::cppu::queryInterface(
116 _rType,
117 static_cast< XObjectInspectorUI* >( this )
119 return aReturn;
122 //------------------------------------------------------------------------
123 void OPropertyBrowserController::startContainerWindowListening()
125 if (m_bContainerFocusListening)
126 return;
128 if (m_xFrame.is())
130 Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
131 if (xContainerWindow.is())
133 xContainerWindow->addFocusListener(this);
134 m_bContainerFocusListening = sal_True;
138 DBG_ASSERT(m_bContainerFocusListening, "OPropertyBrowserController::startContainerWindowListening: unable to start listening (inconsistence)!");
141 //------------------------------------------------------------------------
142 void OPropertyBrowserController::stopContainerWindowListening()
144 if (!m_bContainerFocusListening)
145 return;
147 if (m_xFrame.is())
149 Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
150 if (xContainerWindow.is())
152 xContainerWindow->removeFocusListener(this);
153 m_bContainerFocusListening = sal_False;
157 DBG_ASSERT(!m_bContainerFocusListening, "OPropertyBrowserController::stopContainerWindowListening: unable to stop listening (inconsistence)!");
160 //--------------------------------------------------------------------
161 Reference< XObjectInspectorModel > SAL_CALL OPropertyBrowserController::getInspectorModel() throw (RuntimeException)
163 return m_xModel;
166 //--------------------------------------------------------------------
167 void OPropertyBrowserController::impl_initializeView_nothrow()
169 OSL_PRECOND( haveView(), "OPropertyBrowserController::impl_initializeView_nothrow: not to be called when we have no view!" );
170 if ( !haveView() )
171 return;
173 if ( !m_xModel.is() )
174 // allowed
175 return;
179 getPropertyBox().EnableHelpSection( m_xModel->getHasHelpSection() );
180 getPropertyBox().SetHelpLineLimites( m_xModel->getMinHelpTextLines(), m_xModel->getMaxHelpTextLines() );
182 catch( const Exception& )
184 DBG_UNHANDLED_EXCEPTION();
188 //--------------------------------------------------------------------
189 void OPropertyBrowserController::impl_updateReadOnlyView_nothrow()
191 // this is a huge cudgel, admitted.
192 // The problem is that in case we were previously read-only, all our controls
193 // were created read-only, too. We cannot simply switch them to not-read-only.
194 // Even if they had an API for this, we do not know whether they were
195 // originally created read-only, or if they are read-only just because
196 // the model was.
197 impl_rebindToInspectee_nothrow( m_aInspectedObjects );
200 //--------------------------------------------------------------------
201 bool OPropertyBrowserController::impl_isReadOnlyModel_throw() const
203 if ( !m_xModel.is() )
204 return false;
206 return m_xModel->getIsReadOnly();
209 //--------------------------------------------------------------------
210 void OPropertyBrowserController::impl_startOrStopModelListening_nothrow( bool _bDoListen ) const
214 Reference< XPropertySet > xModelProperties( m_xModel, UNO_QUERY );
215 if ( !xModelProperties.is() )
216 // okay, so the model doesn't want to change its properties
217 // dynamically - fine with us
218 return;
220 void (SAL_CALL XPropertySet::*pListenerOperation)( const OUString&, const Reference< XPropertyChangeListener >& )
221 = _bDoListen ? &XPropertySet::addPropertyChangeListener : &XPropertySet::removePropertyChangeListener;
223 (xModelProperties.get()->*pListenerOperation)(
224 OUString( "IsReadOnly" ),
225 const_cast< OPropertyBrowserController* >( this )
228 catch( const Exception& )
230 DBG_UNHANDLED_EXCEPTION();
234 //--------------------------------------------------------------------
235 void OPropertyBrowserController::impl_bindToNewModel_nothrow( const Reference< XObjectInspectorModel >& _rxInspectorModel )
237 impl_startOrStopModelListening_nothrow( false );
238 m_xModel = _rxInspectorModel;
239 impl_startOrStopModelListening_nothrow( true );
241 // initialize the view, if we already have one
242 if ( haveView() )
243 impl_initializeView_nothrow();
245 // inspect again, if we already have inspectees
246 if ( !m_aInspectedObjects.empty() )
247 impl_rebindToInspectee_nothrow( m_aInspectedObjects );
250 //--------------------------------------------------------------------
251 void SAL_CALL OPropertyBrowserController::setInspectorModel( const Reference< XObjectInspectorModel >& _inspectorModel ) throw (RuntimeException)
253 ::osl::MutexGuard aGuard( m_aMutex );
255 if ( m_xModel == _inspectorModel )
256 return;
258 impl_bindToNewModel_nothrow( _inspectorModel );
261 //--------------------------------------------------------------------
262 Reference< XObjectInspectorUI > SAL_CALL OPropertyBrowserController::getInspectorUI() throw (RuntimeException)
264 // we're derived from this interface, though we do not expose it in queryInterface and getTypes.
265 return this;
268 //--------------------------------------------------------------------
269 void SAL_CALL OPropertyBrowserController::inspect( const Sequence< Reference< XInterface > >& _rObjects ) throw (com::sun::star::util::VetoException, RuntimeException)
271 SolarMutexGuard aSolarGuard;
272 ::osl::MutexGuard aGuard( m_aMutex );
274 if ( m_bSuspendingPropertyHandlers || !suspendAll_nothrow() )
275 { // we already are trying to suspend the component (this is somewhere up the stack)
276 // OR one of our property handlers raised a veto against closing. Well, we *need* to close
277 // it in order to inspect another object.
278 throw VetoException();
280 if ( m_bBindingIntrospectee )
281 throw VetoException();
283 m_bBindingIntrospectee = true;
284 impl_rebindToInspectee_nothrow( InterfaceArray( _rObjects.getConstArray(), _rObjects.getConstArray() + _rObjects.getLength() ) );
285 m_bBindingIntrospectee = false;
289 //--------------------------------------------------------------------
290 Reference< XDispatch > SAL_CALL OPropertyBrowserController::queryDispatch( const URL& /*URL*/, const OUString& /*TargetFrameName*/, ::sal_Int32 /*SearchFlags*/ ) throw (RuntimeException)
292 // we don't have any dispatches at all, right now
293 return Reference< XDispatch >();
296 //--------------------------------------------------------------------
297 Sequence< Reference< XDispatch > > SAL_CALL OPropertyBrowserController::queryDispatches( const Sequence< DispatchDescriptor >& Requests ) throw (RuntimeException)
299 Sequence< Reference< XDispatch > > aReturn;
300 sal_Int32 nLen = Requests.getLength();
301 aReturn.realloc( nLen );
303 Reference< XDispatch >* pReturn = aReturn.getArray();
304 const Reference< XDispatch >* pReturnEnd = aReturn.getArray() + nLen;
305 const DispatchDescriptor* pDescripts = Requests.getConstArray();
307 for ( ; pReturn != pReturnEnd; ++ pReturn, ++pDescripts )
308 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
310 return aReturn;
313 //------------------------------------------------------------------------
314 void SAL_CALL OPropertyBrowserController::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
316 if ( m_bConstructed )
317 throw AlreadyInitializedException();
319 StlSyntaxSequence< Any > arguments( _arguments );
320 if ( arguments.empty() )
321 { // constructor: "createDefault()"
322 createDefault();
323 return;
326 Reference< XObjectInspectorModel > xModel;
327 if ( arguments.size() == 1 )
328 { // constructor: "createWithModel( XObjectInspectorModel )"
329 if ( !( arguments[0] >>= xModel ) )
330 throw IllegalArgumentException( OUString(), *this, 0 );
331 createWithModel( xModel );
332 return;
335 throw IllegalArgumentException( OUString(), *this, 0 );
338 //------------------------------------------------------------------------
339 void OPropertyBrowserController::createDefault()
341 m_bConstructed = true;
344 //------------------------------------------------------------------------
345 void OPropertyBrowserController::createWithModel( const Reference< XObjectInspectorModel >& _rxModel )
347 osl_atomic_increment( &m_refCount );
349 setInspectorModel( _rxModel );
351 osl_atomic_decrement( &m_refCount );
353 m_bConstructed = true;
356 //------------------------------------------------------------------------
357 void SAL_CALL OPropertyBrowserController::attachFrame( const Reference< XFrame >& _rxFrame ) throw(RuntimeException)
359 SolarMutexGuard aSolarGuard;
360 ::osl::MutexGuard aGuard( m_aMutex );
362 if (_rxFrame.is() && haveView())
363 throw RuntimeException(OUString("Unable to attach to a second frame."),*this);
365 // revoke as focus listener from the old container window
366 stopContainerWindowListening();
368 m_xFrame = _rxFrame;
369 if (!m_xFrame.is())
370 return;
372 // TODO: this construction perhaps should be done outside. Don't know the exact meaning of attachFrame.
373 // Maybe it is intended to only announce the frame to the controller, and the instance doing this
374 // announcement is responsible for calling setComponent, too.
375 Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
376 VCLXWindow* pContainerWindow = VCLXWindow::GetImplementation(xContainerWindow);
377 Window* pParentWin = pContainerWindow ? pContainerWindow->GetWindow() : NULL;
378 if (!pParentWin)
379 throw RuntimeException(OUString("The frame is invalid. Unable to extract the container window."),*this);
381 if ( Construct( pParentWin ) )
385 m_xFrame->setComponent( VCLUnoHelper::GetInterface( m_pView ), this );
387 catch( const Exception& )
389 OSL_FAIL( "OPropertyBrowserController::attachFrame: caught an exception!" );
393 startContainerWindowListening();
395 UpdateUI();
398 //------------------------------------------------------------------------
399 sal_Bool SAL_CALL OPropertyBrowserController::attachModel( const Reference< XModel >& _rxModel ) throw(RuntimeException)
401 Reference< XObjectInspectorModel > xModel( _rxModel, UNO_QUERY );
402 if ( !xModel.is() )
403 return false;
405 setInspectorModel( xModel );
406 return getInspectorModel() == _rxModel;
409 //------------------------------------------------------------------------
410 sal_Bool OPropertyBrowserController::suspendAll_nothrow()
412 // if there is a handle inside its "onInteractivePropertySelection" method,
413 // then veto
414 // Normally, we could expect every handler to do this itself, but being
415 // realistic, it's safer to handle this here in general.
416 if ( m_xInteractiveHandler.is() )
417 return sal_False;
419 m_bSuspendingPropertyHandlers = true;
420 sal_Bool bHandlerVeto = !suspendPropertyHandlers_nothrow( sal_True );
421 m_bSuspendingPropertyHandlers = false;
422 if ( bHandlerVeto )
423 return sal_False;
425 return sal_True;
428 //------------------------------------------------------------------------
429 sal_Bool OPropertyBrowserController::suspendPropertyHandlers_nothrow( sal_Bool _bSuspend )
431 PropertyHandlerArray aAllHandlers; // will contain every handler exactly once
432 for ( PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.begin();
433 handler != m_aPropertyHandlers.end();
434 ++handler
437 if ( ::std::find( aAllHandlers.begin(), aAllHandlers.end(), handler->second ) != aAllHandlers.end() )
438 // already visited this particular handler (m_aPropertyHandlers usually contains
439 // the same handler more than once)
440 continue;
441 aAllHandlers.push_back( handler->second );
444 for ( PropertyHandlerArray::iterator loop = aAllHandlers.begin();
445 loop != aAllHandlers.end();
446 ++loop
451 if ( !(*loop)->suspend( _bSuspend ) )
452 if ( _bSuspend )
453 // if we're not suspending, but reactivating, ignore the error
454 return sal_False;
456 catch( const Exception& )
458 OSL_FAIL( "OPropertyBrowserController::suspendPropertyHandlers_nothrow: caught an exception!" );
461 return sal_True;
464 //------------------------------------------------------------------------
465 sal_Bool SAL_CALL OPropertyBrowserController::suspend( sal_Bool _bSuspend ) throw(RuntimeException)
467 ::osl::MutexGuard aGuard( m_aMutex );
468 OSL_ENSURE( haveView(), "OPropertyBrowserController::suspend: don't have a view anymore!" );
470 if ( !_bSuspend )
471 { // this means a "suspend" is to be "revoked"
472 suspendPropertyHandlers_nothrow( sal_False );
473 // we ourself cannot revoke our suspend
474 return sal_False;
477 if ( !suspendAll_nothrow() )
478 return sal_False;
480 // commit the editor's content
481 if ( haveView() )
482 getPropertyBox().CommitModified();
484 // stop listening
485 stopContainerWindowListening();
487 // outtahere
488 return sal_True;
491 //------------------------------------------------------------------------
492 Any SAL_CALL OPropertyBrowserController::getViewData( ) throw(RuntimeException)
494 return makeAny( m_sPageSelection );
497 //------------------------------------------------------------------------
498 void SAL_CALL OPropertyBrowserController::restoreViewData( const Any& Data ) throw(RuntimeException)
500 OUString sPageSelection;
501 if ( ( Data >>= sPageSelection ) && !sPageSelection.isEmpty() )
503 m_sPageSelection = sPageSelection;
504 selectPageFromViewData();
508 //------------------------------------------------------------------------
509 Reference< XModel > SAL_CALL OPropertyBrowserController::getModel( ) throw(RuntimeException)
511 // have no model
512 return Reference< XModel >();
515 //------------------------------------------------------------------------
516 Reference< XFrame > SAL_CALL OPropertyBrowserController::getFrame( ) throw(RuntimeException)
518 return m_xFrame;
521 //------------------------------------------------------------------------
522 void SAL_CALL OPropertyBrowserController::dispose( ) throw(RuntimeException)
524 SolarMutexGuard aSolarGuard;
526 // stop inspecting the current object
527 stopInspection( false );
529 // say our dispose listeners goodbye
530 ::com::sun::star::lang::EventObject aEvt;
531 aEvt.Source = static_cast< ::cppu::OWeakObject* >(this);
532 m_aDisposeListeners.disposeAndClear(aEvt);
533 m_aControlObservers.disposeAndClear(aEvt);
535 // don't delete explicitly (this is done by the frame we reside in)
536 m_pView = NULL;
538 Reference< XComponent > xViewAsComp( m_xView, UNO_QUERY );
539 if ( xViewAsComp.is() )
540 xViewAsComp->removeEventListener( static_cast< XPropertyChangeListener* >( this ) );
541 m_xView.clear( );
543 m_aInspectedObjects.clear();
544 impl_bindToNewModel_nothrow( NULL );
547 //------------------------------------------------------------------------
548 void SAL_CALL OPropertyBrowserController::addEventListener( const Reference< XEventListener >& _rxListener ) throw(RuntimeException)
550 m_aDisposeListeners.addInterface(_rxListener);
553 //------------------------------------------------------------------------
554 void SAL_CALL OPropertyBrowserController::removeEventListener( const Reference< XEventListener >& _rxListener ) throw(RuntimeException)
556 m_aDisposeListeners.removeInterface(_rxListener);
559 //------------------------------------------------------------------------
560 OUString SAL_CALL OPropertyBrowserController::getImplementationName( ) throw(RuntimeException)
562 return getImplementationName_static();
565 //------------------------------------------------------------------------
566 sal_Bool SAL_CALL OPropertyBrowserController::supportsService( const OUString& ServiceName ) throw(RuntimeException)
568 Sequence< OUString > aSupported(getSupportedServiceNames());
569 const OUString* pArray = aSupported.getConstArray();
570 for (sal_Int32 i = 0; i < aSupported.getLength(); ++i, ++pArray)
571 if (pArray->equals(ServiceName))
572 return sal_True;
573 return sal_False;
576 //------------------------------------------------------------------------
577 Sequence< OUString > SAL_CALL OPropertyBrowserController::getSupportedServiceNames( ) throw(RuntimeException)
579 return getSupportedServiceNames_static();
582 //------------------------------------------------------------------------
583 OUString OPropertyBrowserController::getImplementationName_static( ) throw(RuntimeException)
585 return OUString("org.openoffice.comp.extensions.ObjectInspector");
588 //------------------------------------------------------------------------
589 Sequence< OUString > OPropertyBrowserController::getSupportedServiceNames_static( ) throw(RuntimeException)
591 Sequence< OUString > aSupported(1);
592 aSupported[0] = OUString("com.sun.star.inspection.ObjectInspector");
593 return aSupported;
596 //------------------------------------------------------------------------
597 Reference< XInterface > SAL_CALL OPropertyBrowserController::Create(const Reference< XComponentContext >& _rxContext)
599 return *(new OPropertyBrowserController( _rxContext ) );
602 //------------------------------------------------------------------------
603 void SAL_CALL OPropertyBrowserController::focusGained( const FocusEvent& _rSource ) throw (RuntimeException)
605 Reference< XWindow > xSourceWindow(_rSource.Source, UNO_QUERY);
606 Reference< XWindow > xContainerWindow;
607 if (m_xFrame.is())
608 xContainerWindow = m_xFrame->getContainerWindow();
610 if ( xContainerWindow.get() == xSourceWindow.get() )
611 { // our container window got the focus
612 if ( haveView() )
613 getPropertyBox().GrabFocus();
617 //------------------------------------------------------------------------
618 void SAL_CALL OPropertyBrowserController::focusLost( const FocusEvent& /*_rSource*/ ) throw (RuntimeException)
620 // not interested in
623 //------------------------------------------------------------------------
624 void SAL_CALL OPropertyBrowserController::disposing( const EventObject& _rSource ) throw(RuntimeException)
626 if ( m_xView.is() && ( m_xView == _rSource.Source ) )
628 m_xView = NULL;
629 m_pView = NULL;
632 for ( InterfaceArray::iterator loop = m_aInspectedObjects.begin();
633 loop != m_aInspectedObjects.end();
634 ++loop
637 if ( *loop == _rSource.Source )
639 m_aInspectedObjects.erase( loop );
640 break;
645 //------------------------------------------------------------------------
646 IMPL_LINK_NOARG(OPropertyBrowserController, OnPageActivation)
648 updateViewDataFromActivePage();
649 return 0L;
652 //------------------------------------------------------------------------
653 void OPropertyBrowserController::updateViewDataFromActivePage()
655 if (!haveView())
656 return;
658 OUString sOldSelection = m_sPageSelection;
659 m_sPageSelection = OUString();
661 const sal_uInt16 nCurrentPage = m_pView->getActivaPage();
662 if ( (sal_uInt16)-1 != nCurrentPage )
664 for ( HashString2Int16::const_iterator pageId = m_aPageIds.begin();
665 pageId != m_aPageIds.end();
666 ++pageId
669 if ( nCurrentPage == pageId->second )
671 m_sPageSelection = pageId->first;
672 break;
677 if ( !m_sPageSelection.isEmpty() )
678 m_sLastValidPageSelection = m_sPageSelection;
679 else if ( !sOldSelection.isEmpty() )
680 m_sLastValidPageSelection = sOldSelection;
683 //------------------------------------------------------------------------
684 sal_uInt16 OPropertyBrowserController::impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const
686 sal_uInt16 nPageId = (sal_uInt16)-1;
687 HashString2Int16::const_iterator pagePos = m_aPageIds.find( _rCategoryName );
688 if ( pagePos != m_aPageIds.end() )
689 nPageId = pagePos->second;
690 return nPageId;
693 //------------------------------------------------------------------------
694 void OPropertyBrowserController::selectPageFromViewData()
696 sal_uInt16 nNewPage = impl_getPageIdForCategory_nothrow( m_sPageSelection );
698 if ( haveView() && ( nNewPage != (sal_uInt16)-1 ) )
699 m_pView->activatePage( nNewPage );
701 // just in case ...
702 updateViewDataFromActivePage();
705 //------------------------------------------------------------------------
706 sal_Bool OPropertyBrowserController::Construct(Window* _pParentWin)
708 DBG_ASSERT(!haveView(), "OPropertyBrowserController::Construct: already have a view!");
709 DBG_ASSERT(_pParentWin, "OPropertyBrowserController::Construct: invalid parent window!");
711 m_pView = new OPropertyBrowserView(m_aContext.getLegacyServiceFactory(), _pParentWin);
712 m_pView->setPageActivationHandler(LINK(this, OPropertyBrowserController, OnPageActivation));
714 // add as dispose listener for our view. The view is disposed by the frame we're plugged into,
715 // and this disposal _deletes_ the view, so it would be deadly if we use our m_pView member
716 // after that
717 m_xView = VCLUnoHelper::GetInterface(m_pView);
718 Reference< XComponent > xViewAsComp(m_xView, UNO_QUERY);
719 if (xViewAsComp.is())
720 xViewAsComp->addEventListener( static_cast< XPropertyChangeListener* >( this ) );
722 getPropertyBox().SetLineListener(this);
723 getPropertyBox().SetControlObserver(this);
724 impl_initializeView_nothrow();
726 m_pView->Show();
728 return sal_True;
731 //------------------------------------------------------------------------
732 void SAL_CALL OPropertyBrowserController::propertyChange( const PropertyChangeEvent& _rEvent ) throw (RuntimeException)
734 if ( _rEvent.Source == m_xModel )
736 if ( _rEvent.PropertyName == "IsReadOnly" )
737 impl_updateReadOnlyView_nothrow();
738 return;
741 if ( m_sCommittingProperty == _rEvent.PropertyName )
742 return;
744 if ( !haveView() )
745 return;
747 Any aNewValue( _rEvent.NewValue );
748 if ( impl_hasPropertyHandlerFor_nothrow( _rEvent.PropertyName ) )
750 // forward the new value to the property box, to reflect the change in the UI
751 aNewValue = impl_getPropertyValue_throw( _rEvent.PropertyName );
753 // check whether the state is ambiguous. This is interesting in case we display the properties
754 // for multiple objects at once: In this case, we'll get a notification from one of the objects,
755 // but need to care for the "composed" value, which can be "ambiguous".
756 PropertyHandlerRef xHandler( impl_getHandlerForProperty_throw( _rEvent.PropertyName ), UNO_SET_THROW );
757 PropertyState ePropertyState( xHandler->getPropertyState( _rEvent.PropertyName ) );
758 bool bAmbiguousValue = ( PropertyState_AMBIGUOUS_VALUE == ePropertyState );
760 getPropertyBox().SetPropertyValue( _rEvent.PropertyName, aNewValue, bAmbiguousValue );
763 // if it's a actuating property, then update the UI for any dependent
764 // properties
765 if ( impl_isActuatingProperty_nothrow( _rEvent.PropertyName ) )
766 impl_broadcastPropertyChange_nothrow( _rEvent.PropertyName, aNewValue, _rEvent.OldValue, false );
769 //------------------------------------------------------------------------
770 Reference< XPropertyControl > SAL_CALL OPropertyBrowserController::createPropertyControl( ::sal_Int16 ControlType, ::sal_Bool _CreateReadOnly ) throw (IllegalArgumentException, RuntimeException)
772 ::osl::MutexGuard aGuard( m_aMutex );
774 Reference< XPropertyControl > xControl;
776 // default winbits: a border only
777 WinBits nWinBits = WB_BORDER;
779 // read-only-ness
780 _CreateReadOnly |= (sal_Bool)impl_isReadOnlyModel_throw();
781 if ( _CreateReadOnly )
782 nWinBits |= WB_READONLY;
784 switch ( ControlType )
786 case PropertyControlType::StringListField:
787 xControl = new OMultilineEditControl( &getPropertyBox(), eStringList, nWinBits | WB_DROPDOWN | WB_TABSTOP );
788 break;
790 case PropertyControlType::MultiLineTextField:
791 xControl = new OMultilineEditControl( &getPropertyBox(), eMultiLineText, nWinBits | WB_DROPDOWN | WB_TABSTOP );
792 break;
794 case PropertyControlType::ListBox:
795 xControl = new OListboxControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN);
796 break;
798 case PropertyControlType::ComboBox:
799 xControl = new OComboboxControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN);
800 break;
802 case PropertyControlType::TextField:
803 xControl = new OEditControl( &getPropertyBox(), sal_False, nWinBits | WB_TABSTOP );
804 break;
806 case PropertyControlType::CharacterField:
807 xControl = new OEditControl( &getPropertyBox(), sal_True, nWinBits | WB_TABSTOP );
808 break;
810 case PropertyControlType::NumericField:
811 xControl = new ONumericControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
812 break;
814 case PropertyControlType::DateTimeField:
815 xControl = new ODateTimeControl( &getPropertyBox(), nWinBits | WB_TABSTOP );
816 break;
818 case PropertyControlType::DateField:
819 xControl = new ODateControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
820 break;
822 case PropertyControlType::TimeField:
823 xControl = new OTimeControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
824 break;
826 case PropertyControlType::ColorListBox:
827 xControl = new OColorControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN );
828 break;
830 case PropertyControlType::HyperlinkField:
831 xControl = new OHyperlinkControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN );
832 break;
834 default:
835 throw IllegalArgumentException( OUString(), *this, 1 );
838 return xControl;
841 //------------------------------------------------------------------------
842 void OPropertyBrowserController::impl_toggleInspecteeListening_nothrow( bool _bOn )
844 for ( InterfaceArray::const_iterator loop = m_aInspectedObjects.begin();
845 loop != m_aInspectedObjects.end();
846 ++loop
851 Reference< XComponent > xComp( *loop, UNO_QUERY );
852 if ( xComp.is() )
854 if ( _bOn )
855 xComp->addEventListener( static_cast< XPropertyChangeListener* >( this ) );
856 else
857 xComp->removeEventListener( static_cast< XPropertyChangeListener* >( this ) );
860 catch( const Exception& )
862 DBG_UNHANDLED_EXCEPTION();
867 //------------------------------------------------------------------------
868 void OPropertyBrowserController::stopInspection( bool _bCommitModified )
870 if ( haveView() )
872 if ( _bCommitModified )
873 // commit the editor's content
874 getPropertyBox().CommitModified();
876 // hide the property box so that it does not flicker
877 getPropertyBox().Hide();
879 // clear the property box
880 getPropertyBox().ClearAll();
883 // destroy the view first
884 if ( haveView() )
886 // remove the pages
887 for ( HashString2Int16::const_iterator erase = m_aPageIds.begin();
888 erase != m_aPageIds.end();
889 ++erase
891 getPropertyBox().RemovePage( erase->second );
892 clearContainer( m_aPageIds );
895 clearContainer( m_aProperties );
897 // de-register as dispose-listener from our inspected objects
898 impl_toggleInspecteeListening_nothrow( false );
900 // handlers are obsolete, so is our "composer" for their UI requests
901 if ( m_pUIRequestComposer.get() )
902 m_pUIRequestComposer->dispose();
903 m_pUIRequestComposer.reset( NULL );
905 // clean up the property handlers
906 PropertyHandlerArray aAllHandlers; // will contain every handler exactly once
907 for ( PropertyHandlerRepository::const_iterator aHandler = m_aPropertyHandlers.begin();
908 aHandler != m_aPropertyHandlers.end();
909 ++aHandler
911 if ( ::std::find( aAllHandlers.begin(), aAllHandlers.end(), aHandler->second ) == aAllHandlers.end() )
912 aAllHandlers.push_back( aHandler->second );
914 for ( PropertyHandlerArray::iterator loop = aAllHandlers.begin();
915 loop != aAllHandlers.end();
916 ++loop
921 (*loop)->removePropertyChangeListener( this );
922 (*loop)->dispose();
924 catch( const DisposedException& )
927 catch( const Exception& )
929 DBG_UNHANDLED_EXCEPTION();
933 clearContainer( m_aPropertyHandlers );
934 clearContainer( m_aDependencyHandlers );
937 //------------------------------------------------------------------------
938 bool OPropertyBrowserController::impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const
940 PropertyHandlerRepository::const_iterator handlerPos = m_aPropertyHandlers.find( _rPropertyName );
941 return ( handlerPos != m_aPropertyHandlers.end() );
944 //------------------------------------------------------------------------
945 OPropertyBrowserController::PropertyHandlerRef OPropertyBrowserController::impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const
947 PropertyHandlerRepository::const_iterator handlerPos = m_aPropertyHandlers.find( _rPropertyName );
948 if ( handlerPos == m_aPropertyHandlers.end() )
949 throw RuntimeException();
950 return handlerPos->second;
953 //------------------------------------------------------------------------
954 Any OPropertyBrowserController::impl_getPropertyValue_throw( const OUString& _rPropertyName )
956 PropertyHandlerRef handler = impl_getHandlerForProperty_throw( _rPropertyName );
957 return handler->getPropertyValue( _rPropertyName );
960 //------------------------------------------------------------------------
961 void OPropertyBrowserController::impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects )
965 // stop inspecting the old object(s)
966 stopInspection( true );
968 // inspect the new object(s)
969 m_aInspectedObjects = _rObjects;
970 doInspection();
972 // update the user interface
973 UpdateUI();
976 catch(const Exception&)
978 OSL_FAIL("OPropertyBrowserController::impl_rebindToInspectee_nothrow: caught an exception !");
982 //------------------------------------------------------------------------
983 void OPropertyBrowserController::doInspection()
987 //////////////////////////////////////////////////////////////////////
988 // obtain the properties of the object
989 ::std::vector< Property > aProperties;
991 PropertyHandlerArray aPropertyHandlers;
992 getPropertyHandlers( m_aInspectedObjects, aPropertyHandlers );
994 PropertyHandlerArray::iterator aHandler( aPropertyHandlers.begin() );
995 while ( aHandler != aPropertyHandlers.end() )
997 DBG_ASSERT( aHandler->get(), "OPropertyBrowserController::doInspection: invalid handler!" );
999 StlSyntaxSequence< Property > aThisHandlersProperties = (*aHandler)->getSupportedProperties();
1001 if ( aThisHandlersProperties.empty() )
1003 // this handler doesn't know anything about the current inspectee -> ignore it
1004 (*aHandler)->dispose();
1005 aHandler = aPropertyHandlers.erase( aHandler );
1006 continue;
1009 // append these properties to our "all properties" array
1010 aProperties.reserve( aProperties.size() + aThisHandlersProperties.size() );
1011 for ( StlSyntaxSequence< Property >::const_iterator copyProperty = aThisHandlersProperties.begin();
1012 copyProperty != aThisHandlersProperties.end();
1013 ++copyProperty
1016 ::std::vector< Property >::const_iterator previous = ::std::find_if(
1017 aProperties.begin(),
1018 aProperties.end(),
1019 FindPropertyByName( copyProperty->Name )
1021 if ( previous == aProperties.end() )
1023 aProperties.push_back( *copyProperty );
1024 continue;
1027 // there already was another (previous) handler which supported this property.
1028 // Don't add it to aProperties, again.
1030 // Also, ensure that handlers which previously expressed interest in *changes*
1031 // of this property are not notified.
1032 // This is 'cause we have a new handler which is responsible for this property,
1033 // which means it can give it a completely different meaning than the previous
1034 // handler for this property is prepared for.
1035 ::std::pair< PropertyHandlerMultiRepository::iterator, PropertyHandlerMultiRepository::iterator >
1036 aDepHandlers = m_aDependencyHandlers.equal_range( copyProperty->Name );
1037 m_aDependencyHandlers.erase( aDepHandlers.first, aDepHandlers.second );
1040 // determine the superseded properties
1041 StlSyntaxSequence< OUString > aSupersededByThisHandler = (*aHandler)->getSupersededProperties();
1042 for ( StlSyntaxSequence< OUString >::const_iterator superseded = aSupersededByThisHandler.begin();
1043 superseded != aSupersededByThisHandler.end();
1044 ++superseded
1047 ::std::vector< Property >::iterator existent = ::std::find_if(
1048 aProperties.begin(),
1049 aProperties.end(),
1050 FindPropertyByName( *superseded )
1052 if ( existent != aProperties.end() )
1053 // one of the properties superseded by this handler was supported by a previous
1054 // one -> erase
1055 aProperties.erase( existent );
1058 // be notified of changes which this handler is responsible for
1059 (*aHandler)->addPropertyChangeListener( this );
1061 // remember this handler for every of the properties which it is responsible
1062 // for
1063 for ( StlSyntaxSequence< Property >::const_iterator remember = aThisHandlersProperties.begin();
1064 remember != aThisHandlersProperties.end();
1065 ++remember
1068 m_aPropertyHandlers[ remember->Name ] = *aHandler;
1069 // note that this implies that if two handlers support the same property,
1070 // the latter wins
1073 // see if the handler expresses interest in any actuating properties
1074 StlSyntaxSequence< OUString > aInterestingActuations = (*aHandler)->getActuatingProperties();
1075 for ( StlSyntaxSequence< OUString >::const_iterator aLoop = aInterestingActuations.begin();
1076 aLoop != aInterestingActuations.end();
1077 ++aLoop
1080 m_aDependencyHandlers.insert( PropertyHandlerMultiRepository::value_type(
1081 *aLoop, *aHandler ) );
1084 ++aHandler;
1087 // create a new composer for UI requests coming from the handlers
1088 m_pUIRequestComposer.reset( new ComposedPropertyUIUpdate( getInspectorUI(), this ) );
1090 // sort the properties by relative position, as indicated by the model
1091 for ( ::std::vector< Property >::const_iterator sourceProps = aProperties.begin();
1092 sourceProps != aProperties.end();
1093 ++sourceProps
1096 sal_Int32 nRelativePropertyOrder = sourceProps - aProperties.begin();
1097 if ( m_xModel.is() )
1098 nRelativePropertyOrder = m_xModel->getPropertyOrderIndex( sourceProps->Name );
1099 m_aProperties.insert(OrderedPropertyMap::value_type(nRelativePropertyOrder, *sourceProps));
1102 // be notified when one of our inspectees dies
1103 impl_toggleInspecteeListening_nothrow( true );
1105 catch(const Exception&)
1107 OSL_FAIL("OPropertyBrowserController::doInspection : caught an exception !");
1111 //------------------------------------------------------------------------
1112 ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::getMinimumSize() throw (::com::sun::star::uno::RuntimeException)
1114 ::com::sun::star::awt::Size aSize;
1115 if( m_pView )
1116 return m_pView->getMinimumSize();
1117 else
1118 return aSize;
1121 //------------------------------------------------------------------------
1122 ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::getPreferredSize() throw (::com::sun::star::uno::RuntimeException)
1124 return getMinimumSize();
1127 //------------------------------------------------------------------------
1128 ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::calcAdjustedSize( const ::com::sun::star::awt::Size& _rNewSize ) throw (::com::sun::star::uno::RuntimeException)
1130 awt::Size aMinSize = getMinimumSize( );
1131 awt::Size aAdjustedSize( _rNewSize );
1132 if ( aAdjustedSize.Width < aMinSize.Width )
1133 aAdjustedSize.Width = aMinSize.Width;
1134 if ( aAdjustedSize.Height < aMinSize.Height )
1135 aAdjustedSize.Height = aMinSize.Height;
1136 return aAdjustedSize;
1139 //------------------------------------------------------------------------
1140 void OPropertyBrowserController::describePropertyLine( const Property& _rProperty, OLineDescriptor& _rDescriptor ) SAL_THROW((Exception))
1144 PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.find( _rProperty.Name );
1145 if ( handler == m_aPropertyHandlers.end() )
1146 throw RuntimeException(); // caught below
1148 _rDescriptor.assignFrom( handler->second->describePropertyLine( _rProperty.Name, this ) );
1150 //////////////////////////////////////////////////////////////////////
1152 _rDescriptor.xPropertyHandler = handler->second;
1153 _rDescriptor.sName = _rProperty.Name;
1154 _rDescriptor.aValue = _rDescriptor.xPropertyHandler->getPropertyValue( _rProperty.Name );
1156 if ( _rDescriptor.DisplayName.isEmpty() )
1158 #ifdef DBG_UTIL
1159 OString sMessage( "OPropertyBrowserController::describePropertyLine: handler did not provide a display name for '" );
1160 sMessage += OString( _rProperty.Name.getStr(), _rProperty.Name.getLength(), RTL_TEXTENCODING_ASCII_US );
1161 sMessage += OString( "'!" );
1162 DBG_ASSERT( !_rDescriptor.DisplayName.isEmpty(), sMessage.getStr() );
1163 #endif
1164 _rDescriptor.DisplayName = _rProperty.Name;
1167 PropertyState ePropertyState( _rDescriptor.xPropertyHandler->getPropertyState( _rProperty.Name ) );
1168 if ( PropertyState_AMBIGUOUS_VALUE == ePropertyState )
1170 _rDescriptor.bUnknownValue = true;
1171 _rDescriptor.aValue.clear();
1174 _rDescriptor.bReadOnly = impl_isReadOnlyModel_throw();
1176 catch( const Exception& )
1178 OSL_FAIL( "OPropertyBrowserController::describePropertyLine: caught an exception!" );
1182 //------------------------------------------------------------------------
1183 void OPropertyBrowserController::impl_buildCategories_throw()
1185 OSL_PRECOND( m_aPageIds.empty(), "OPropertyBrowserController::impl_buildCategories_throw: duplicate call!" );
1187 StlSyntaxSequence< PropertyCategoryDescriptor > aCategories;
1188 if ( m_xModel.is() )
1189 aCategories = m_xModel->describeCategories();
1191 for ( StlSyntaxSequence< PropertyCategoryDescriptor >::const_iterator category = aCategories.begin();
1192 category != aCategories.end();
1193 ++category
1196 OSL_ENSURE( m_aPageIds.find( category->ProgrammaticName ) == m_aPageIds.end(),
1197 "OPropertyBrowserController::impl_buildCategories_throw: duplicate programmatic name!" );
1199 m_aPageIds[ category->ProgrammaticName ] =
1200 getPropertyBox().AppendPage( category->UIName, HelpIdUrl::getHelpId( category->HelpURL ) );
1204 //------------------------------------------------------------------------
1205 void OPropertyBrowserController::UpdateUI()
1209 if ( !haveView() )
1210 // too early, will return later
1211 return;
1213 getPropertyBox().DisableUpdate();
1215 sal_Bool bHaveFocus = getPropertyBox().HasChildPathFocus();
1217 // create our tab pages
1218 impl_buildCategories_throw();
1219 // (and allow for pages to be actually unused)
1220 ::std::set< sal_uInt16 > aUsedPages;
1222 // when building the UI below, remember which properties are actuating,
1223 // to allow for a initial actuatinPropertyChanged call
1224 ::std::vector< OUString > aActuatingProperties;
1225 ::std::vector< Any > aActuatingPropertyValues;
1227 // ask the handlers to describe the property UI, and insert the resulting
1228 // entries into our list boxes
1229 OrderedPropertyMap::const_iterator property( m_aProperties.begin() );
1230 for ( ; property != m_aProperties.end(); ++property )
1232 OLineDescriptor aDescriptor;
1233 describePropertyLine( property->second, aDescriptor );
1235 bool bIsActuatingProperty = impl_isActuatingProperty_nothrow( property->second.Name );
1237 #if OSL_DEBUG_LEVEL > 0
1238 if ( aDescriptor.Category.isEmpty() )
1240 OString sMessage( "OPropertyBrowserController::UpdateUI: empty category provided for property '" );
1241 sMessage += OString( property->second.Name.getStr(), property->second.Name.getLength(), osl_getThreadTextEncoding() );
1242 sMessage += "'!";
1243 OSL_FAIL( sMessage.getStr() );
1245 #endif
1246 // finally insert this property control
1247 sal_uInt16 nTargetPageId = impl_getPageIdForCategory_nothrow( aDescriptor.Category );
1248 if ( nTargetPageId == (sal_uInt16)-1 )
1250 // this category does not yet exist. This is allowed, as an inspector model might be lazy, and not provide
1251 // any category information of its own. In this case, we have a fallback ...
1252 m_aPageIds[ aDescriptor.Category ] =
1253 getPropertyBox().AppendPage( aDescriptor.Category, OString() );
1254 nTargetPageId = impl_getPageIdForCategory_nothrow( aDescriptor.Category );
1257 getPropertyBox().InsertEntry( aDescriptor, nTargetPageId );
1258 aUsedPages.insert( nTargetPageId );
1260 // if it's an actuating property, remember it
1261 if ( bIsActuatingProperty )
1263 aActuatingProperties.push_back( property->second.Name );
1264 aActuatingPropertyValues.push_back( impl_getPropertyValue_throw( property->second.Name ) );
1268 // update any dependencies for the actuating properties which we encountered
1270 ::std::vector< OUString >::const_iterator aProperty = aActuatingProperties.begin();
1271 ::std::vector< Any >::const_iterator aPropertyValue = aActuatingPropertyValues.begin();
1272 for ( ; aProperty != aActuatingProperties.end(); ++aProperty, ++aPropertyValue )
1273 impl_broadcastPropertyChange_nothrow( *aProperty, *aPropertyValue, *aPropertyValue, true );
1276 // remove any unused pages (which we did not encounter properties for)
1277 HashString2Int16 aSurvivingPageIds;
1278 for ( HashString2Int16::iterator pageId = m_aPageIds.begin();
1279 pageId != m_aPageIds.end();
1280 ++pageId
1283 if ( aUsedPages.find( pageId->second ) == aUsedPages.end() )
1284 getPropertyBox().RemovePage( pageId->second );
1285 else
1286 aSurvivingPageIds.insert( *pageId );
1288 m_aPageIds.swap( aSurvivingPageIds );
1291 getPropertyBox().Show();
1292 getPropertyBox().EnableUpdate();
1293 if ( bHaveFocus )
1294 getPropertyBox().GrabFocus();
1296 // activate the first page
1297 if ( !m_aPageIds.empty() )
1299 Sequence< PropertyCategoryDescriptor > aCategories( m_xModel->describeCategories() );
1300 if ( aCategories.getLength() )
1301 m_pView->activatePage( m_aPageIds[ aCategories[0].ProgrammaticName ] );
1302 else
1303 // allowed: if we default-created the pages ...
1304 m_pView->activatePage( m_aPageIds.begin()->second );
1307 // activate the previously active page (if possible)
1308 if ( !m_sLastValidPageSelection.isEmpty() )
1309 m_sPageSelection = m_sLastValidPageSelection;
1310 selectPageFromViewData();
1312 catch( const Exception& )
1314 DBG_UNHANDLED_EXCEPTION();
1318 //------------------------------------------------------------------------
1319 void OPropertyBrowserController::Clicked( const OUString& _rName, sal_Bool _bPrimary )
1323 // since the browse buttons do not get the focus when clicked with the mouse,
1324 // we need to commit the changes in the current property field
1325 getPropertyBox().CommitModified();
1327 PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.find( _rName );
1328 DBG_ASSERT( handler != m_aPropertyHandlers.end(), "OPropertyBrowserController::Clicked: a property without handler? This will crash!" );
1330 ComposedUIAutoFireGuard aAutoFireGuard( *m_pUIRequestComposer );
1332 Any aData;
1333 m_xInteractiveHandler = handler->second;
1334 InteractiveSelectionResult eResult =
1335 handler->second->onInteractivePropertySelection( _rName, _bPrimary, aData,
1336 m_pUIRequestComposer->getUIForPropertyHandler( handler->second ) );
1338 switch ( eResult )
1340 case InteractiveSelectionResult_Cancelled:
1341 case InteractiveSelectionResult_Success:
1342 // okay, nothing to do
1343 break;
1344 case InteractiveSelectionResult_ObtainedValue:
1345 handler->second->setPropertyValue( _rName, aData );
1346 break;
1347 case InteractiveSelectionResult_Pending:
1348 // also okay, we expect that the handler has disabled the UI as necessary
1349 break;
1350 default:
1351 OSL_FAIL( "OPropertyBrowserController::Clicked: unknown result value!" );
1352 break;
1355 catch (const Exception&)
1357 DBG_UNHANDLED_EXCEPTION();
1359 m_xInteractiveHandler = NULL;
1362 //------------------------------------------------------------------------
1363 sal_Bool SAL_CALL OPropertyBrowserController::hasPropertyByName( const OUString& _rName ) throw (RuntimeException)
1365 for ( OrderedPropertyMap::const_iterator search = m_aProperties.begin();
1366 search != m_aProperties.end();
1367 ++search
1369 if ( search->second.Name == _rName )
1370 return true;
1371 return false;
1374 //------------------------------------------------------------------------
1375 void OPropertyBrowserController::Commit( const OUString& rName, const Any& _rValue )
1379 OUString sPlcHolder = String( PcrRes( RID_EMBED_IMAGE_PLACEHOLDER ) );
1380 bool bIsPlaceHolderValue = false;
1382 if ( rName.equals( PROPERTY_IMAGE_URL ) )
1384 // if the prop value is the PlaceHolder
1385 // can ignore it
1386 OUString sVal;
1387 _rValue >>= sVal;
1388 if ( sVal.equals( sPlcHolder ) )
1389 bIsPlaceHolderValue = true;
1391 m_sCommittingProperty = rName;
1393 bool bIsActuatingProperty = impl_isActuatingProperty_nothrow( rName );
1395 Any aOldValue;
1396 if ( bIsActuatingProperty )
1397 aOldValue = impl_getPropertyValue_throw( rName );
1399 // do we have a dedicated handler for this property, which we can delegate some tasks to?
1400 PropertyHandlerRef handler = impl_getHandlerForProperty_throw( rName );
1402 //////////////////////////////////////////////////////////////////////
1403 // set the value ( only if it's not a placeholder )
1404 if ( !bIsPlaceHolderValue )
1405 handler->setPropertyValue( rName, _rValue );
1407 //////////////////////////////////////////////////////////////////////
1408 // re-retrieve the value
1409 Any aNormalizedValue = handler->getPropertyValue( rName );
1411 // care for any inter-property dependencies
1412 if ( bIsActuatingProperty )
1413 impl_broadcastPropertyChange_nothrow( rName, aNormalizedValue, aOldValue, false );
1415 // and display it again. This ensures proper formatting
1416 getPropertyBox().SetPropertyValue( rName, aNormalizedValue, false );
1418 catch(const PropertyVetoException& eVetoException)
1420 InfoBox(m_pView, eVetoException.Message).Execute();
1421 PropertyHandlerRef handler = impl_getHandlerForProperty_throw( rName );
1422 Any aNormalizedValue = handler->getPropertyValue( rName );
1423 getPropertyBox().SetPropertyValue( rName, aNormalizedValue, false );
1425 catch(const Exception&)
1427 OSL_FAIL("OPropertyBrowserController::Commit : caught an exception !");
1430 m_sCommittingProperty = OUString();
1433 //--------------------------------------------------------------------
1434 namespace
1438 //--------------------------------------------------------------------
1439 void OPropertyBrowserController::focusGained( const Reference< XPropertyControl >& _Control )
1441 m_aControlObservers.notifyEach( &XPropertyControlObserver::focusGained, _Control );
1444 //--------------------------------------------------------------------
1445 void OPropertyBrowserController::valueChanged( const Reference< XPropertyControl >& _Control )
1447 m_aControlObservers.notifyEach( &XPropertyControlObserver::valueChanged, _Control );
1450 //------------------------------------------------------------------------
1451 namespace
1453 Reference< XPropertyHandler > lcl_createHandler( const ComponentContext& _rContext, const Any& _rFactoryDescriptor )
1455 Reference< XPropertyHandler > xHandler;
1457 OUString sServiceName;
1458 Reference< XSingleServiceFactory > xServiceFac;
1459 Reference< XSingleComponentFactory > xComponentFac;
1461 if ( _rFactoryDescriptor >>= sServiceName )
1462 _rContext.createComponent( sServiceName, xHandler );
1463 else if ( _rFactoryDescriptor >>= xServiceFac )
1464 xHandler = xHandler.query( xServiceFac->createInstance() );
1465 else if ( _rFactoryDescriptor >>= xComponentFac )
1466 xHandler = xHandler.query( xComponentFac->createInstanceWithContext( _rContext.getUNOContext() ) );
1467 OSL_ENSURE(xHandler.is(),"lcl_createHandler: Can not create handler");
1468 return xHandler;
1472 //------------------------------------------------------------------------
1473 void OPropertyBrowserController::getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers )
1475 _rHandlers.resize( 0 );
1476 if ( _rObjects.empty() )
1477 return;
1479 // create a component context for the handlers, containing some information about where
1480 // they live
1481 Reference< XComponentContext > xHandlerContext( m_aContext.getUNOContext() );
1483 // if our own creator did not pass a dialog parent window, use our own view for this
1484 Reference< XWindow > xParentWindow( m_aContext.getContextValueByAsciiName( "DialogParentWindow" ), UNO_QUERY );
1485 if ( !xParentWindow.is() )
1487 ::cppu::ContextEntry_Init aHandlerContextInfo[] =
1489 ::cppu::ContextEntry_Init( OUString( "DialogParentWindow" ), makeAny( VCLUnoHelper::GetInterface( m_pView ) ) )
1491 xHandlerContext = ::cppu::createComponentContext(
1492 aHandlerContextInfo, SAL_N_ELEMENTS( aHandlerContextInfo ),
1493 m_aContext.getUNOContext() );
1496 Sequence< Any > aHandlerFactories;
1497 if ( m_xModel.is() )
1498 aHandlerFactories = m_xModel->getHandlerFactories();
1500 const Any* pHandlerFactory = aHandlerFactories.getConstArray();
1501 const Any* pHandlerFactoryEnd = aHandlerFactories.getConstArray() + aHandlerFactories.getLength();
1503 while ( pHandlerFactory != pHandlerFactoryEnd )
1505 if ( _rObjects.size() == 1 )
1506 { // we're inspecting only one object -> one handler
1507 Reference< XPropertyHandler > xHandler( lcl_createHandler( m_aContext, *pHandlerFactory ) );
1508 if ( xHandler.is() )
1510 xHandler->inspect( _rObjects[0] );
1511 _rHandlers.push_back( xHandler );
1514 else
1516 // create a single handler for every single object
1517 ::std::vector< Reference< XPropertyHandler > > aSingleHandlers( _rObjects.size() );
1518 ::std::vector< Reference< XPropertyHandler > >::iterator pHandler = aSingleHandlers.begin();
1520 InterfaceArray::const_iterator pObject = _rObjects.begin();
1521 InterfaceArray::const_iterator pObjectEnd = _rObjects.end();
1523 for ( ; pObject != pObjectEnd; ++pObject )
1525 *pHandler = lcl_createHandler( m_aContext, *pHandlerFactory );
1526 if ( pHandler->is() )
1528 (*pHandler)->inspect( *pObject );
1529 ++pHandler;
1532 aSingleHandlers.resize( pHandler - aSingleHandlers.begin() );
1534 // then create a handler which composes information out of those single handlers
1535 if ( !aSingleHandlers.empty() )
1536 _rHandlers.push_back( new PropertyComposer( aSingleHandlers ) );
1539 ++pHandlerFactory;
1542 // note that the handlers will not be used by our caller, if they indicate that there are no
1543 // properties they feel responsible for
1546 //------------------------------------------------------------------------
1547 bool OPropertyBrowserController::impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty )
1549 OrderedPropertyMap::const_iterator search = m_aProperties.begin();
1550 for ( ; search != m_aProperties.end(); ++search )
1551 if ( search->second.Name == _rName )
1552 break;
1553 if ( _pProperty )
1554 *_pProperty = search;
1555 return ( search != m_aProperties.end() );
1558 //------------------------------------------------------------------------
1559 void OPropertyBrowserController::rebuildPropertyUI( const OUString& _rPropertyName ) throw (RuntimeException)
1561 ::osl::MutexGuard aGuard( m_aMutex );
1562 if ( !haveView() )
1563 throw RuntimeException();
1565 OrderedPropertyMap::const_iterator propertyPos;
1566 if ( !impl_findObjectProperty_nothrow( _rPropertyName, &propertyPos ) )
1567 return;
1569 OLineDescriptor aDescriptor;
1572 describePropertyLine( propertyPos->second, aDescriptor );
1574 catch( const Exception& )
1576 OSL_FAIL( "OPropertyBrowserController::rebuildPropertyUI: caught an exception!" );
1579 getPropertyBox().ChangeEntry( aDescriptor );
1582 //------------------------------------------------------------------------
1583 void OPropertyBrowserController::enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) throw (RuntimeException)
1585 ::osl::MutexGuard aGuard( m_aMutex );
1586 if ( !haveView() )
1587 throw RuntimeException();
1589 if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
1590 return;
1592 getPropertyBox().EnablePropertyLine( _rPropertyName, _bEnable );
1595 //------------------------------------------------------------------------
1596 void OPropertyBrowserController::enablePropertyUIElements( const OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable ) throw (RuntimeException)
1598 ::osl::MutexGuard aGuard( m_aMutex );
1599 if ( !haveView() )
1600 throw RuntimeException();
1602 if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
1603 return;
1605 getPropertyBox().EnablePropertyControls( _rPropertyName, _nElements, _bEnable );
1608 //------------------------------------------------------------------------
1609 void OPropertyBrowserController::showPropertyUI( const OUString& _rPropertyName ) throw (RuntimeException)
1611 ::osl::MutexGuard aGuard( m_aMutex );
1612 if ( !haveView() )
1613 throw RuntimeException();
1615 // look up the property in our object properties
1616 OrderedPropertyMap::const_iterator propertyPos;
1617 if ( !impl_findObjectProperty_nothrow( _rPropertyName, &propertyPos ) )
1618 return;
1620 if ( getPropertyBox().GetPropertyPos( _rPropertyName ) != LISTBOX_ENTRY_NOTFOUND )
1622 rebuildPropertyUI( _rPropertyName );
1623 return;
1626 OLineDescriptor aDescriptor;
1627 describePropertyLine( propertyPos->second, aDescriptor );
1629 // look for the position to insert the property
1631 // side note: The methods GetPropertyPos and InsertEntry of the OPropertyEditor work
1632 // only on the current page. This implies that it's impossible to use this method here
1633 // to show property lines which are *not* on the current page.
1634 // This is sufficient for now, but should be changed in the future.
1636 // by definition, the properties in m_aProperties are in the order in which they appear in the UI
1637 // So all we need is a predecessor of pProperty in m_aProperties
1638 sal_uInt16 nUIPos = LISTBOX_ENTRY_NOTFOUND;
1641 if ( propertyPos != m_aProperties.begin() )
1642 --propertyPos;
1643 nUIPos = getPropertyBox().GetPropertyPos( propertyPos->second.Name );
1645 while ( ( nUIPos == LISTBOX_ENTRY_NOTFOUND ) && ( propertyPos != m_aProperties.begin() ) );
1647 if ( nUIPos == LISTBOX_ENTRY_NOTFOUND )
1648 // insert at the very top
1649 nUIPos = 0;
1650 else
1651 // insert right after the predecessor we found
1652 ++nUIPos;
1654 getPropertyBox().InsertEntry(
1655 aDescriptor, impl_getPageIdForCategory_nothrow( aDescriptor.Category ), nUIPos );
1658 //------------------------------------------------------------------------
1659 void OPropertyBrowserController::hidePropertyUI( const OUString& _rPropertyName ) throw (RuntimeException)
1661 ::osl::MutexGuard aGuard( m_aMutex );
1662 if ( !haveView() )
1663 throw RuntimeException();
1665 if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
1666 return;
1668 getPropertyBox().RemoveEntry( _rPropertyName );
1671 //------------------------------------------------------------------------
1672 void OPropertyBrowserController::showCategory( const OUString& _rCategory, sal_Bool _bShow ) throw (RuntimeException)
1674 ::osl::MutexGuard aGuard( m_aMutex );
1675 if ( !haveView() )
1676 throw RuntimeException();
1678 sal_uInt16 nPageId = impl_getPageIdForCategory_nothrow( _rCategory );
1679 OSL_ENSURE( nPageId != (sal_uInt16)-1, "OPropertyBrowserController::showCategory: invalid category!" );
1681 getPropertyBox().ShowPropertyPage( nPageId, _bShow );
1684 //------------------------------------------------------------------------
1685 Reference< XPropertyControl > SAL_CALL OPropertyBrowserController::getPropertyControl( const OUString& _rPropertyName ) throw (RuntimeException)
1687 ::osl::MutexGuard aGuard( m_aMutex );
1688 if ( !haveView() )
1689 throw RuntimeException();
1691 Reference< XPropertyControl > xControl( getPropertyBox().GetPropertyControl( _rPropertyName ) );
1692 return xControl;
1695 //--------------------------------------------------------------------
1696 void SAL_CALL OPropertyBrowserController::registerControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException)
1698 m_aControlObservers.addInterface( _Observer );
1701 //--------------------------------------------------------------------
1702 void SAL_CALL OPropertyBrowserController::revokeControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException)
1704 m_aControlObservers.removeInterface( _Observer );
1707 //------------------------------------------------------------------------
1708 void SAL_CALL OPropertyBrowserController::setHelpSectionText( const OUString& _rHelpText ) throw (NoSupportException, RuntimeException)
1710 SolarMutexGuard aSolarGuard;
1711 ::osl::MutexGuard aGuard( m_aMutex );
1713 if ( !haveView() )
1714 throw DisposedException();
1716 if ( !getPropertyBox().HasHelpSection() )
1717 throw NoSupportException();
1719 getPropertyBox().SetHelpText( _rHelpText );
1722 //------------------------------------------------------------------------
1723 void OPropertyBrowserController::impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const Any& _rNewValue, const Any& _rOldValue, bool _bFirstTimeInit ) const
1725 // are there one or more handlers which are interested in the actuation?
1726 ::std::pair< PropertyHandlerMultiRepository::const_iterator, PropertyHandlerMultiRepository::const_iterator > aInterestedHandlers =
1727 m_aDependencyHandlers.equal_range( _rPropertyName );
1728 if ( aInterestedHandlers.first == aInterestedHandlers.second )
1729 // none of our handlers is interested in this
1730 return;
1732 ComposedUIAutoFireGuard aAutoFireGuard( *m_pUIRequestComposer );
1735 // collect the responses from all interested handlers
1736 PropertyHandlerMultiRepository::const_iterator handler = aInterestedHandlers.first;
1737 while ( handler != aInterestedHandlers.second )
1739 handler->second->actuatingPropertyChanged( _rPropertyName, _rNewValue, _rOldValue,
1740 m_pUIRequestComposer->getUIForPropertyHandler( handler->second ),
1741 _bFirstTimeInit );
1742 ++handler;
1745 catch( const Exception& )
1747 DBG_UNHANDLED_EXCEPTION();
1751 //............................................................................
1752 } // namespace pcr
1753 //............................................................................
1756 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */