bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / propctrlr / propcontroller.cxx
blob7236a9ba557fb7d9d9e1c46ea70f4a966cdd1ee4
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 "pcrservices.hxx"
21 #include "propcontroller.hxx"
22 #include "pcrstrings.hxx"
23 #include "standardcontrol.hxx"
24 #include "linedescriptor.hxx"
25 #include "propresid.hrc"
26 #include "formresid.hrc"
27 #include "propertyeditor.hxx"
28 #include "modulepcr.hxx"
29 #include "formstrings.hxx"
30 #include "formmetadata.hxx"
31 #include "formbrowsertools.hxx"
32 #include "propertycomposer.hxx"
34 #include <com/sun/star/awt/XWindow.hpp>
35 #include <com/sun/star/util/XCloseable.hpp>
36 #include <com/sun/star/inspection/PropertyControlType.hpp>
37 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
38 #include <tools/debug.hxx>
39 #include <tools/diagnose_ex.h>
40 #include <comphelper/types.hxx>
41 #include <comphelper/extract.hxx>
42 #include <toolkit/awt/vclxwindow.hxx>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <comphelper/property.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vcl/tabpage.hxx>
48 #include <osl/mutex.hxx>
49 #include <cppuhelper/queryinterface.hxx>
50 #include <cppuhelper/component_context.hxx>
51 #include <cppuhelper/exc_hlp.hxx>
52 #include <cppuhelper/supportsservice.hxx>
54 #include <algorithm>
55 #include <functional>
56 #include <sal/macros.h>
59 // !!! outside the namespace !!!
60 extern "C" void SAL_CALL createRegistryInfo_OPropertyBrowserController()
62 ::pcr::OAutoRegistration< ::pcr::OPropertyBrowserController > aAutoRegistration;
66 namespace pcr
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::awt;
73 using namespace ::com::sun::star::form;
74 using namespace ::com::sun::star::beans;
75 using namespace ::com::sun::star::script;
76 using namespace ::com::sun::star::lang;
77 using namespace ::com::sun::star::container;
78 using namespace ::com::sun::star::frame;
79 using namespace ::com::sun::star::util;
80 using namespace ::com::sun::star::inspection;
81 using namespace ::com::sun::star::ucb;
82 using namespace ::comphelper;
85 //= OPropertyBrowserController
88 OPropertyBrowserController::OPropertyBrowserController( const Reference< XComponentContext >& _rxContext )
89 :m_xContext(_rxContext)
90 ,m_aDisposeListeners( m_aMutex )
91 ,m_aControlObservers( m_aMutex )
92 ,m_pView(NULL)
93 ,m_bContainerFocusListening( false )
94 ,m_bSuspendingPropertyHandlers( false )
95 ,m_bConstructed( false )
96 ,m_bBindingIntrospectee( false )
101 OPropertyBrowserController::~OPropertyBrowserController()
103 // stop listening for property changes
104 acquire();
105 stopInspection( true );
109 IMPLEMENT_FORWARD_REFCOUNT( OPropertyBrowserController, OPropertyBrowserController_Base )
112 Any SAL_CALL OPropertyBrowserController::queryInterface( const Type& _rType ) throw (RuntimeException, std::exception)
114 Any aReturn = OPropertyBrowserController_Base::queryInterface( _rType );
115 if ( !aReturn.hasValue() )
116 aReturn = ::cppu::queryInterface(
117 _rType,
118 static_cast< XObjectInspectorUI* >( this )
120 return aReturn;
124 void OPropertyBrowserController::startContainerWindowListening()
126 if (m_bContainerFocusListening)
127 return;
129 if (m_xFrame.is())
131 Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
132 if (xContainerWindow.is())
134 xContainerWindow->addFocusListener(this);
135 m_bContainerFocusListening = true;
139 DBG_ASSERT(m_bContainerFocusListening, "OPropertyBrowserController::startContainerWindowListening: unable to start listening (inconsistence)!");
143 void OPropertyBrowserController::stopContainerWindowListening()
145 if (!m_bContainerFocusListening)
146 return;
148 if (m_xFrame.is())
150 Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
151 if (xContainerWindow.is())
153 xContainerWindow->removeFocusListener(this);
154 m_bContainerFocusListening = false;
158 DBG_ASSERT(!m_bContainerFocusListening, "OPropertyBrowserController::stopContainerWindowListening: unable to stop listening (inconsistence)!");
162 Reference< XObjectInspectorModel > SAL_CALL OPropertyBrowserController::getInspectorModel() throw (RuntimeException, std::exception)
164 return m_xModel;
168 void OPropertyBrowserController::impl_initializeView_nothrow()
170 OSL_PRECOND( haveView(), "OPropertyBrowserController::impl_initializeView_nothrow: not to be called when we have no view!" );
171 if ( !haveView() )
172 return;
174 if ( !m_xModel.is() )
175 // allowed
176 return;
180 getPropertyBox().EnableHelpSection( m_xModel->getHasHelpSection() );
181 getPropertyBox().SetHelpLineLimites( m_xModel->getMinHelpTextLines(), m_xModel->getMaxHelpTextLines() );
183 catch( const Exception& )
185 DBG_UNHANDLED_EXCEPTION();
190 void OPropertyBrowserController::impl_updateReadOnlyView_nothrow()
192 // this is a huge cudgel, admitted.
193 // The problem is that in case we were previously read-only, all our controls
194 // were created read-only, too. We cannot simply switch them to not-read-only.
195 // Even if they had an API for this, we do not know whether they were
196 // originally created read-only, or if they are read-only just because
197 // the model was.
198 impl_rebindToInspectee_nothrow( m_aInspectedObjects );
202 bool OPropertyBrowserController::impl_isReadOnlyModel_throw() const
204 if ( !m_xModel.is() )
205 return false;
207 return m_xModel->getIsReadOnly();
211 void OPropertyBrowserController::impl_startOrStopModelListening_nothrow( bool _bDoListen ) const
215 Reference< XPropertySet > xModelProperties( m_xModel, UNO_QUERY );
216 if ( !xModelProperties.is() )
217 // okay, so the model doesn't want to change its properties
218 // dynamically - fine with us
219 return;
221 void (SAL_CALL XPropertySet::*pListenerOperation)( const OUString&, const Reference< XPropertyChangeListener >& )
222 = _bDoListen ? &XPropertySet::addPropertyChangeListener : &XPropertySet::removePropertyChangeListener;
224 (xModelProperties.get()->*pListenerOperation)(
225 OUString( "IsReadOnly" ),
226 const_cast< OPropertyBrowserController* >( this )
229 catch( const Exception& )
231 DBG_UNHANDLED_EXCEPTION();
236 void OPropertyBrowserController::impl_bindToNewModel_nothrow( const Reference< XObjectInspectorModel >& _rxInspectorModel )
238 impl_startOrStopModelListening_nothrow( false );
239 m_xModel = _rxInspectorModel;
240 impl_startOrStopModelListening_nothrow( true );
242 // initialize the view, if we already have one
243 if ( haveView() )
244 impl_initializeView_nothrow();
246 // inspect again, if we already have inspectees
247 if ( !m_aInspectedObjects.empty() )
248 impl_rebindToInspectee_nothrow( m_aInspectedObjects );
252 void SAL_CALL OPropertyBrowserController::setInspectorModel( const Reference< XObjectInspectorModel >& _inspectorModel ) throw (RuntimeException, std::exception)
254 ::osl::MutexGuard aGuard( m_aMutex );
256 if ( m_xModel == _inspectorModel )
257 return;
259 impl_bindToNewModel_nothrow( _inspectorModel );
263 Reference< XObjectInspectorUI > SAL_CALL OPropertyBrowserController::getInspectorUI() throw (RuntimeException, std::exception)
265 // we're derived from this interface, though we do not expose it in queryInterface and getTypes.
266 return this;
270 void SAL_CALL OPropertyBrowserController::inspect( const Sequence< Reference< XInterface > >& _rObjects ) throw (com::sun::star::util::VetoException, RuntimeException, std::exception)
272 SolarMutexGuard aSolarGuard;
273 ::osl::MutexGuard aGuard( m_aMutex );
275 if ( m_bSuspendingPropertyHandlers || !suspendAll_nothrow() )
276 { // we already are trying to suspend the component (this is somewhere up the stack)
277 // OR one of our property handlers raised a veto against closing. Well, we *need* to close
278 // it in order to inspect another object.
279 throw VetoException();
281 if ( m_bBindingIntrospectee )
282 throw VetoException();
284 m_bBindingIntrospectee = true;
285 impl_rebindToInspectee_nothrow( InterfaceArray( _rObjects.getConstArray(), _rObjects.getConstArray() + _rObjects.getLength() ) );
286 m_bBindingIntrospectee = false;
291 Reference< XDispatch > SAL_CALL OPropertyBrowserController::queryDispatch( const URL& /*URL*/, const OUString& /*TargetFrameName*/, ::sal_Int32 /*SearchFlags*/ ) throw (RuntimeException, std::exception)
293 // we don't have any dispatches at all, right now
294 return Reference< XDispatch >();
298 Sequence< Reference< XDispatch > > SAL_CALL OPropertyBrowserController::queryDispatches( const Sequence< DispatchDescriptor >& Requests ) throw (RuntimeException, std::exception)
300 Sequence< Reference< XDispatch > > aReturn;
301 sal_Int32 nLen = Requests.getLength();
302 aReturn.realloc( nLen );
304 Reference< XDispatch >* pReturn = aReturn.getArray();
305 const Reference< XDispatch >* pReturnEnd = aReturn.getArray() + nLen;
306 const DispatchDescriptor* pDescripts = Requests.getConstArray();
308 for ( ; pReturn != pReturnEnd; ++ pReturn, ++pDescripts )
309 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
311 return aReturn;
315 void SAL_CALL OPropertyBrowserController::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException, std::exception)
317 if ( m_bConstructed )
318 throw AlreadyInitializedException();
320 StlSyntaxSequence< Any > arguments( _arguments );
321 if ( arguments.empty() )
322 { // constructor: "createDefault()"
323 createDefault();
324 return;
327 Reference< XObjectInspectorModel > xModel;
328 if ( arguments.size() == 1 )
329 { // constructor: "createWithModel( XObjectInspectorModel )"
330 if ( !( arguments[0] >>= xModel ) )
331 throw IllegalArgumentException( OUString(), *this, 0 );
332 createWithModel( xModel );
333 return;
336 throw IllegalArgumentException( OUString(), *this, 0 );
340 void OPropertyBrowserController::createDefault()
342 m_bConstructed = true;
346 void OPropertyBrowserController::createWithModel( const Reference< XObjectInspectorModel >& _rxModel )
348 osl_atomic_increment( &m_refCount );
350 setInspectorModel( _rxModel );
352 osl_atomic_decrement( &m_refCount );
354 m_bConstructed = true;
358 void SAL_CALL OPropertyBrowserController::attachFrame( const Reference< XFrame >& _rxFrame ) throw(RuntimeException, std::exception)
360 SolarMutexGuard aSolarGuard;
361 ::osl::MutexGuard aGuard( m_aMutex );
363 if (_rxFrame.is() && haveView())
364 throw RuntimeException("Unable to attach to a second frame.",*this);
366 // revoke as focus listener from the old container window
367 stopContainerWindowListening();
369 m_xFrame = _rxFrame;
370 if (!m_xFrame.is())
371 return;
373 // TODO: this construction perhaps should be done outside. Don't know the exact meaning of attachFrame.
374 // Maybe it is intended to only announce the frame to the controller, and the instance doing this
375 // announcement is responsible for calling setComponent, too.
376 Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
377 VCLXWindow* pContainerWindow = VCLXWindow::GetImplementation(xContainerWindow);
378 VclPtr<vcl::Window> pParentWin = pContainerWindow ? pContainerWindow->GetWindow() : VclPtr<vcl::Window>();
379 if (!pParentWin)
380 throw RuntimeException("The frame is invalid. Unable to extract the container window.",*this);
382 if ( Construct( pParentWin ) )
386 m_xFrame->setComponent( VCLUnoHelper::GetInterface( m_pView ), this );
388 catch( const Exception& )
390 OSL_FAIL( "OPropertyBrowserController::attachFrame: caught an exception!" );
394 startContainerWindowListening();
396 UpdateUI();
400 sal_Bool SAL_CALL OPropertyBrowserController::attachModel( const Reference< XModel >& _rxModel ) throw(RuntimeException, std::exception)
402 Reference< XObjectInspectorModel > xModel( _rxModel, UNO_QUERY );
403 if ( !xModel.is() )
404 return false;
406 setInspectorModel( xModel );
407 return getInspectorModel() == _rxModel;
411 bool OPropertyBrowserController::suspendAll_nothrow()
413 // if there is a handle inside its "onInteractivePropertySelection" method,
414 // then veto
415 // Normally, we could expect every handler to do this itself, but being
416 // realistic, it's safer to handle this here in general.
417 if ( m_xInteractiveHandler.is() )
418 return false;
420 m_bSuspendingPropertyHandlers = true;
421 bool bHandlerVeto = !suspendPropertyHandlers_nothrow( true );
422 m_bSuspendingPropertyHandlers = false;
423 if ( bHandlerVeto )
424 return false;
426 return true;
430 bool OPropertyBrowserController::suspendPropertyHandlers_nothrow( bool _bSuspend )
432 PropertyHandlerArray aAllHandlers; // will contain every handler exactly once
433 for ( PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.begin();
434 handler != m_aPropertyHandlers.end();
435 ++handler
438 if ( ::std::find( aAllHandlers.begin(), aAllHandlers.end(), handler->second ) != aAllHandlers.end() )
439 // already visited this particular handler (m_aPropertyHandlers usually contains
440 // the same handler more than once)
441 continue;
442 aAllHandlers.push_back( handler->second );
445 for ( PropertyHandlerArray::iterator loop = aAllHandlers.begin();
446 loop != aAllHandlers.end();
447 ++loop
452 if ( !(*loop)->suspend( _bSuspend ) )
453 if ( _bSuspend )
454 // if we're not suspending, but reactivating, ignore the error
455 return false;
457 catch( const Exception& )
459 OSL_FAIL( "OPropertyBrowserController::suspendPropertyHandlers_nothrow: caught an exception!" );
462 return true;
466 sal_Bool SAL_CALL OPropertyBrowserController::suspend( sal_Bool _bSuspend ) throw(RuntimeException, std::exception)
468 ::osl::MutexGuard aGuard( m_aMutex );
469 OSL_ENSURE( haveView(), "OPropertyBrowserController::suspend: don't have a view anymore!" );
471 if ( !_bSuspend )
472 { // this means a "suspend" is to be "revoked"
473 suspendPropertyHandlers_nothrow( false );
474 // we ourself cannot revoke our suspend
475 return sal_False;
478 if ( !suspendAll_nothrow() )
479 return sal_False;
481 // commit the editor's content
482 if ( haveView() )
483 getPropertyBox().CommitModified();
485 // stop listening
486 stopContainerWindowListening();
488 // outtahere
489 return sal_True;
493 Any SAL_CALL OPropertyBrowserController::getViewData( ) throw(RuntimeException, std::exception)
495 return makeAny( m_sPageSelection );
499 void SAL_CALL OPropertyBrowserController::restoreViewData( const Any& Data ) throw(RuntimeException, std::exception)
501 OUString sPageSelection;
502 if ( ( Data >>= sPageSelection ) && !sPageSelection.isEmpty() )
504 m_sPageSelection = sPageSelection;
505 selectPageFromViewData();
510 Reference< XModel > SAL_CALL OPropertyBrowserController::getModel( ) throw(RuntimeException, std::exception)
512 // have no model
513 return Reference< XModel >();
517 Reference< XFrame > SAL_CALL OPropertyBrowserController::getFrame( ) throw(RuntimeException, std::exception)
519 return m_xFrame;
523 void SAL_CALL OPropertyBrowserController::dispose( ) throw(RuntimeException, std::exception)
525 SolarMutexGuard aSolarGuard;
527 // stop inspecting the current object
528 stopInspection( false );
530 // say our dispose listeners goodbye
531 ::com::sun::star::lang::EventObject aEvt;
532 aEvt.Source = static_cast< ::cppu::OWeakObject* >(this);
533 m_aDisposeListeners.disposeAndClear(aEvt);
534 m_aControlObservers.disposeAndClear(aEvt);
536 // don't delete explicitly (this is done by the frame we reside in)
537 m_pView = NULL;
539 Reference< XComponent > xViewAsComp( m_xView, UNO_QUERY );
540 if ( xViewAsComp.is() )
541 xViewAsComp->removeEventListener( static_cast< XPropertyChangeListener* >( this ) );
542 m_xView.clear( );
544 m_aInspectedObjects.clear();
545 impl_bindToNewModel_nothrow( NULL );
549 void SAL_CALL OPropertyBrowserController::addEventListener( const Reference< XEventListener >& _rxListener ) throw(RuntimeException, std::exception)
551 m_aDisposeListeners.addInterface(_rxListener);
555 void SAL_CALL OPropertyBrowserController::removeEventListener( const Reference< XEventListener >& _rxListener ) throw(RuntimeException, std::exception)
557 m_aDisposeListeners.removeInterface(_rxListener);
561 OUString SAL_CALL OPropertyBrowserController::getImplementationName( ) throw(RuntimeException, std::exception)
563 return getImplementationName_static();
566 sal_Bool SAL_CALL OPropertyBrowserController::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
568 return cppu::supportsService(this, ServiceName);
572 Sequence< OUString > SAL_CALL OPropertyBrowserController::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
574 return getSupportedServiceNames_static();
578 OUString OPropertyBrowserController::getImplementationName_static( ) throw(RuntimeException)
580 return OUString("org.openoffice.comp.extensions.ObjectInspector");
584 Sequence< OUString > OPropertyBrowserController::getSupportedServiceNames_static( ) throw(RuntimeException)
586 Sequence< OUString > aSupported(1);
587 aSupported[0] = "com.sun.star.inspection.ObjectInspector";
588 return aSupported;
592 Reference< XInterface > SAL_CALL OPropertyBrowserController::Create(const Reference< XComponentContext >& _rxContext)
594 return *(new OPropertyBrowserController( _rxContext ) );
598 void SAL_CALL OPropertyBrowserController::focusGained( const FocusEvent& _rSource ) throw (RuntimeException, std::exception)
600 Reference< XWindow > xSourceWindow(_rSource.Source, UNO_QUERY);
601 Reference< XWindow > xContainerWindow;
602 if (m_xFrame.is())
603 xContainerWindow = m_xFrame->getContainerWindow();
605 if ( xContainerWindow.get() == xSourceWindow.get() )
606 { // our container window got the focus
607 if ( haveView() )
608 getPropertyBox().GrabFocus();
613 void SAL_CALL OPropertyBrowserController::focusLost( const FocusEvent& /*_rSource*/ ) throw (RuntimeException, std::exception)
615 // not interested in
619 void SAL_CALL OPropertyBrowserController::disposing( const EventObject& _rSource ) throw(RuntimeException, std::exception)
621 if ( m_xView.is() && ( m_xView == _rSource.Source ) )
623 m_xView = NULL;
624 m_pView = NULL;
627 for ( InterfaceArray::iterator loop = m_aInspectedObjects.begin();
628 loop != m_aInspectedObjects.end();
629 ++loop
632 if ( *loop == _rSource.Source )
634 m_aInspectedObjects.erase( loop );
635 break;
641 IMPL_LINK_NOARG(OPropertyBrowserController, OnPageActivation)
643 updateViewDataFromActivePage();
644 return 0L;
648 void OPropertyBrowserController::updateViewDataFromActivePage()
650 if (!haveView())
651 return;
653 OUString sOldSelection = m_sPageSelection;
654 m_sPageSelection.clear();
656 const sal_uInt16 nCurrentPage = m_pView->getActivaPage();
657 if ( (sal_uInt16)-1 != nCurrentPage )
659 for ( HashString2Int16::const_iterator pageId = m_aPageIds.begin();
660 pageId != m_aPageIds.end();
661 ++pageId
664 if ( nCurrentPage == pageId->second )
666 m_sPageSelection = pageId->first;
667 break;
672 if ( !m_sPageSelection.isEmpty() )
673 m_sLastValidPageSelection = m_sPageSelection;
674 else if ( !sOldSelection.isEmpty() )
675 m_sLastValidPageSelection = sOldSelection;
679 sal_uInt16 OPropertyBrowserController::impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const
681 sal_uInt16 nPageId = (sal_uInt16)-1;
682 HashString2Int16::const_iterator pagePos = m_aPageIds.find( _rCategoryName );
683 if ( pagePos != m_aPageIds.end() )
684 nPageId = pagePos->second;
685 return nPageId;
689 void OPropertyBrowserController::selectPageFromViewData()
691 sal_uInt16 nNewPage = impl_getPageIdForCategory_nothrow( m_sPageSelection );
693 if ( haveView() && ( nNewPage != (sal_uInt16)-1 ) )
694 m_pView->activatePage( nNewPage );
696 // just in case ...
697 updateViewDataFromActivePage();
701 bool OPropertyBrowserController::Construct(vcl::Window* _pParentWin)
703 DBG_ASSERT(!haveView(), "OPropertyBrowserController::Construct: already have a view!");
704 DBG_ASSERT(_pParentWin, "OPropertyBrowserController::Construct: invalid parent window!");
706 m_pView = VclPtr<OPropertyBrowserView>::Create(_pParentWin);
707 m_pView->setPageActivationHandler(LINK(this, OPropertyBrowserController, OnPageActivation));
709 // add as dispose listener for our view. The view is disposed by the frame we're plugged into,
710 // and this disposal _deletes_ the view, so it would be deadly if we use our m_pView member
711 // after that
712 m_xView = VCLUnoHelper::GetInterface(m_pView);
713 Reference< XComponent > xViewAsComp(m_xView, UNO_QUERY);
714 if (xViewAsComp.is())
715 xViewAsComp->addEventListener( static_cast< XPropertyChangeListener* >( this ) );
717 getPropertyBox().SetLineListener(this);
718 getPropertyBox().SetControlObserver(this);
719 impl_initializeView_nothrow();
721 m_pView->Show();
723 return true;
727 void SAL_CALL OPropertyBrowserController::propertyChange( const PropertyChangeEvent& _rEvent ) throw (RuntimeException, std::exception)
729 if ( _rEvent.Source == m_xModel )
731 if ( _rEvent.PropertyName == "IsReadOnly" )
732 impl_updateReadOnlyView_nothrow();
733 return;
736 if ( m_sCommittingProperty == _rEvent.PropertyName )
737 return;
739 if ( !haveView() )
740 return;
742 Any aNewValue( _rEvent.NewValue );
743 if ( impl_hasPropertyHandlerFor_nothrow( _rEvent.PropertyName ) )
745 // forward the new value to the property box, to reflect the change in the UI
746 aNewValue = impl_getPropertyValue_throw( _rEvent.PropertyName );
748 // check whether the state is ambiguous. This is interesting in case we display the properties
749 // for multiple objects at once: In this case, we'll get a notification from one of the objects,
750 // but need to care for the "composed" value, which can be "ambiguous".
751 PropertyHandlerRef xHandler( impl_getHandlerForProperty_throw( _rEvent.PropertyName ), UNO_SET_THROW );
752 PropertyState ePropertyState( xHandler->getPropertyState( _rEvent.PropertyName ) );
753 bool bAmbiguousValue = ( PropertyState_AMBIGUOUS_VALUE == ePropertyState );
755 getPropertyBox().SetPropertyValue( _rEvent.PropertyName, aNewValue, bAmbiguousValue );
758 // if it's a actuating property, then update the UI for any dependent
759 // properties
760 if ( impl_isActuatingProperty_nothrow( _rEvent.PropertyName ) )
761 impl_broadcastPropertyChange_nothrow( _rEvent.PropertyName, aNewValue, _rEvent.OldValue, false );
765 Reference< XPropertyControl > SAL_CALL OPropertyBrowserController::createPropertyControl( ::sal_Int16 ControlType, sal_Bool _CreateReadOnly ) throw (IllegalArgumentException, RuntimeException, std::exception)
767 ::osl::MutexGuard aGuard( m_aMutex );
769 Reference< XPropertyControl > xControl;
771 // default winbits: a border only
772 WinBits nWinBits = WB_BORDER;
774 // read-only-ness
775 _CreateReadOnly |= impl_isReadOnlyModel_throw() ? 1 : 0;
776 if ( _CreateReadOnly )
777 nWinBits |= WB_READONLY;
779 switch ( ControlType )
781 case PropertyControlType::StringListField:
782 xControl = new OMultilineEditControl( &getPropertyBox(), eStringList, nWinBits | WB_DROPDOWN | WB_TABSTOP );
783 break;
785 case PropertyControlType::MultiLineTextField:
786 xControl = new OMultilineEditControl( &getPropertyBox(), eMultiLineText, nWinBits | WB_DROPDOWN | WB_TABSTOP );
787 break;
789 case PropertyControlType::ListBox:
790 xControl = new OListboxControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN);
791 break;
793 case PropertyControlType::ComboBox:
794 xControl = new OComboboxControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN);
795 break;
797 case PropertyControlType::TextField:
798 xControl = new OEditControl( &getPropertyBox(), false, nWinBits | WB_TABSTOP );
799 break;
801 case PropertyControlType::CharacterField:
802 xControl = new OEditControl( &getPropertyBox(), true, nWinBits | WB_TABSTOP );
803 break;
805 case PropertyControlType::NumericField:
806 xControl = new ONumericControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
807 break;
809 case PropertyControlType::DateTimeField:
810 xControl = new ODateTimeControl( &getPropertyBox(), nWinBits | WB_TABSTOP );
811 break;
813 case PropertyControlType::DateField:
814 xControl = new ODateControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
815 break;
817 case PropertyControlType::TimeField:
818 xControl = new OTimeControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
819 break;
821 case PropertyControlType::ColorListBox:
822 xControl = new OColorControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN );
823 break;
825 case PropertyControlType::HyperlinkField:
826 xControl = new OHyperlinkControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN );
827 break;
829 default:
830 throw IllegalArgumentException( OUString(), *this, 1 );
833 return xControl;
837 void OPropertyBrowserController::impl_toggleInspecteeListening_nothrow( bool _bOn )
839 for ( InterfaceArray::const_iterator loop = m_aInspectedObjects.begin();
840 loop != m_aInspectedObjects.end();
841 ++loop
846 Reference< XComponent > xComp( *loop, UNO_QUERY );
847 if ( xComp.is() )
849 if ( _bOn )
850 xComp->addEventListener( static_cast< XPropertyChangeListener* >( this ) );
851 else
852 xComp->removeEventListener( static_cast< XPropertyChangeListener* >( this ) );
855 catch( const Exception& )
857 DBG_UNHANDLED_EXCEPTION();
863 void OPropertyBrowserController::stopInspection( bool _bCommitModified )
865 if ( haveView() )
867 if ( _bCommitModified )
868 // commit the editor's content
869 getPropertyBox().CommitModified();
871 // hide the property box so that it does not flicker
872 getPropertyBox().Hide();
874 // clear the property box
875 getPropertyBox().ClearAll();
878 // destroy the view first
879 if ( haveView() )
881 // remove the pages
882 for ( HashString2Int16::const_iterator erase = m_aPageIds.begin();
883 erase != m_aPageIds.end();
884 ++erase
886 getPropertyBox().RemovePage( erase->second );
887 clearContainer( m_aPageIds );
890 clearContainer( m_aProperties );
892 // de-register as dispose-listener from our inspected objects
893 impl_toggleInspecteeListening_nothrow( false );
895 // handlers are obsolete, so is our "composer" for their UI requests
896 if ( m_pUIRequestComposer.get() )
897 m_pUIRequestComposer->dispose();
898 m_pUIRequestComposer.reset();
900 // clean up the property handlers
901 PropertyHandlerArray aAllHandlers; // will contain every handler exactly once
902 for ( PropertyHandlerRepository::const_iterator aHandler = m_aPropertyHandlers.begin();
903 aHandler != m_aPropertyHandlers.end();
904 ++aHandler
906 if ( ::std::find( aAllHandlers.begin(), aAllHandlers.end(), aHandler->second ) == aAllHandlers.end() )
907 aAllHandlers.push_back( aHandler->second );
909 for ( PropertyHandlerArray::iterator loop = aAllHandlers.begin();
910 loop != aAllHandlers.end();
911 ++loop
916 (*loop)->removePropertyChangeListener( this );
917 (*loop)->dispose();
919 catch( const DisposedException& )
922 catch( const Exception& )
924 DBG_UNHANDLED_EXCEPTION();
928 clearContainer( m_aPropertyHandlers );
929 clearContainer( m_aDependencyHandlers );
933 bool OPropertyBrowserController::impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const
935 PropertyHandlerRepository::const_iterator handlerPos = m_aPropertyHandlers.find( _rPropertyName );
936 return ( handlerPos != m_aPropertyHandlers.end() );
940 OPropertyBrowserController::PropertyHandlerRef OPropertyBrowserController::impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const
942 PropertyHandlerRepository::const_iterator handlerPos = m_aPropertyHandlers.find( _rPropertyName );
943 if ( handlerPos == m_aPropertyHandlers.end() )
944 throw RuntimeException();
945 return handlerPos->second;
949 Any OPropertyBrowserController::impl_getPropertyValue_throw( const OUString& _rPropertyName )
951 PropertyHandlerRef handler = impl_getHandlerForProperty_throw( _rPropertyName );
952 return handler->getPropertyValue( _rPropertyName );
956 void OPropertyBrowserController::impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects )
960 // stop inspecting the old object(s)
961 stopInspection( true );
963 // inspect the new object(s)
964 m_aInspectedObjects = _rObjects;
965 doInspection();
967 // update the user interface
968 UpdateUI();
971 catch(const Exception&)
973 OSL_FAIL("OPropertyBrowserController::impl_rebindToInspectee_nothrow: caught an exception !");
978 void OPropertyBrowserController::doInspection()
983 // obtain the properties of the object
984 ::std::vector< Property > aProperties;
986 PropertyHandlerArray aPropertyHandlers;
987 getPropertyHandlers( m_aInspectedObjects, aPropertyHandlers );
989 PropertyHandlerArray::iterator aHandler( aPropertyHandlers.begin() );
990 while ( aHandler != aPropertyHandlers.end() )
992 DBG_ASSERT( aHandler->get(), "OPropertyBrowserController::doInspection: invalid handler!" );
994 StlSyntaxSequence< Property > aThisHandlersProperties = (*aHandler)->getSupportedProperties();
996 if ( aThisHandlersProperties.empty() )
998 // this handler doesn't know anything about the current inspectee -> ignore it
999 (*aHandler)->dispose();
1000 aHandler = aPropertyHandlers.erase( aHandler );
1001 continue;
1004 // append these properties to our "all properties" array
1005 aProperties.reserve( aProperties.size() + aThisHandlersProperties.size() );
1006 for ( StlSyntaxSequence< Property >::const_iterator copyProperty = aThisHandlersProperties.begin();
1007 copyProperty != aThisHandlersProperties.end();
1008 ++copyProperty
1011 ::std::vector< Property >::const_iterator previous = ::std::find_if(
1012 aProperties.begin(),
1013 aProperties.end(),
1014 FindPropertyByName( copyProperty->Name )
1016 if ( previous == aProperties.end() )
1018 aProperties.push_back( *copyProperty );
1019 continue;
1022 // there already was another (previous) handler which supported this property.
1023 // Don't add it to aProperties, again.
1025 // Also, ensure that handlers which previously expressed interest in *changes*
1026 // of this property are not notified.
1027 // This is 'cause we have a new handler which is responsible for this property,
1028 // which means it can give it a completely different meaning than the previous
1029 // handler for this property is prepared for.
1030 ::std::pair< PropertyHandlerMultiRepository::iterator, PropertyHandlerMultiRepository::iterator >
1031 aDepHandlers = m_aDependencyHandlers.equal_range( copyProperty->Name );
1032 m_aDependencyHandlers.erase( aDepHandlers.first, aDepHandlers.second );
1035 // determine the superseded properties
1036 StlSyntaxSequence< OUString > aSupersededByThisHandler = (*aHandler)->getSupersededProperties();
1037 for ( StlSyntaxSequence< OUString >::const_iterator superseded = aSupersededByThisHandler.begin();
1038 superseded != aSupersededByThisHandler.end();
1039 ++superseded
1042 ::std::vector< Property >::iterator existent = ::std::find_if(
1043 aProperties.begin(),
1044 aProperties.end(),
1045 FindPropertyByName( *superseded )
1047 if ( existent != aProperties.end() )
1048 // one of the properties superseded by this handler was supported by a previous
1049 // one -> erase
1050 aProperties.erase( existent );
1053 // be notified of changes which this handler is responsible for
1054 (*aHandler)->addPropertyChangeListener( this );
1056 // remember this handler for every of the properties which it is responsible
1057 // for
1058 for ( StlSyntaxSequence< Property >::const_iterator remember = aThisHandlersProperties.begin();
1059 remember != aThisHandlersProperties.end();
1060 ++remember
1063 m_aPropertyHandlers[ remember->Name ] = *aHandler;
1064 // note that this implies that if two handlers support the same property,
1065 // the latter wins
1068 // see if the handler expresses interest in any actuating properties
1069 StlSyntaxSequence< OUString > aInterestingActuations = (*aHandler)->getActuatingProperties();
1070 for ( StlSyntaxSequence< OUString >::const_iterator aLoop = aInterestingActuations.begin();
1071 aLoop != aInterestingActuations.end();
1072 ++aLoop
1075 m_aDependencyHandlers.insert( PropertyHandlerMultiRepository::value_type(
1076 *aLoop, *aHandler ) );
1079 ++aHandler;
1082 // create a new composer for UI requests coming from the handlers
1083 m_pUIRequestComposer.reset( new ComposedPropertyUIUpdate( getInspectorUI(), this ) );
1085 // sort the properties by relative position, as indicated by the model
1086 for ( ::std::vector< Property >::const_iterator sourceProps = aProperties.begin();
1087 sourceProps != aProperties.end();
1088 ++sourceProps
1091 sal_Int32 nRelativePropertyOrder = sourceProps - aProperties.begin();
1092 if ( m_xModel.is() )
1093 nRelativePropertyOrder = m_xModel->getPropertyOrderIndex( sourceProps->Name );
1094 m_aProperties.insert(OrderedPropertyMap::value_type(nRelativePropertyOrder, *sourceProps));
1097 // be notified when one of our inspectees dies
1098 impl_toggleInspecteeListening_nothrow( true );
1100 catch(const Exception&)
1102 OSL_FAIL("OPropertyBrowserController::doInspection : caught an exception !");
1107 ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::getMinimumSize() throw (::com::sun::star::uno::RuntimeException, std::exception)
1109 ::com::sun::star::awt::Size aSize;
1110 if( m_pView )
1111 return m_pView->getMinimumSize();
1112 else
1113 return aSize;
1117 ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::getPreferredSize() throw (::com::sun::star::uno::RuntimeException, std::exception)
1119 return getMinimumSize();
1123 ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::calcAdjustedSize( const ::com::sun::star::awt::Size& _rNewSize ) throw (::com::sun::star::uno::RuntimeException, std::exception)
1125 awt::Size aMinSize = getMinimumSize( );
1126 awt::Size aAdjustedSize( _rNewSize );
1127 if ( aAdjustedSize.Width < aMinSize.Width )
1128 aAdjustedSize.Width = aMinSize.Width;
1129 if ( aAdjustedSize.Height < aMinSize.Height )
1130 aAdjustedSize.Height = aMinSize.Height;
1131 return aAdjustedSize;
1135 void OPropertyBrowserController::describePropertyLine( const Property& _rProperty, OLineDescriptor& _rDescriptor )
1139 PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.find( _rProperty.Name );
1140 if ( handler == m_aPropertyHandlers.end() )
1141 throw RuntimeException(); // caught below
1143 _rDescriptor.assignFrom( handler->second->describePropertyLine( _rProperty.Name, this ) );
1147 _rDescriptor.xPropertyHandler = handler->second;
1148 _rDescriptor.sName = _rProperty.Name;
1149 _rDescriptor.aValue = _rDescriptor.xPropertyHandler->getPropertyValue( _rProperty.Name );
1151 if ( _rDescriptor.DisplayName.isEmpty() )
1153 #ifdef DBG_UTIL
1154 OString sMessage( "OPropertyBrowserController::describePropertyLine: handler did not provide a display name for '" );
1155 sMessage += OString( _rProperty.Name.getStr(), _rProperty.Name.getLength(), RTL_TEXTENCODING_ASCII_US );
1156 sMessage += OString( "'!" );
1157 DBG_ASSERT( !_rDescriptor.DisplayName.isEmpty(), sMessage.getStr() );
1158 #endif
1159 _rDescriptor.DisplayName = _rProperty.Name;
1162 PropertyState ePropertyState( _rDescriptor.xPropertyHandler->getPropertyState( _rProperty.Name ) );
1163 if ( PropertyState_AMBIGUOUS_VALUE == ePropertyState )
1165 _rDescriptor.bUnknownValue = true;
1166 _rDescriptor.aValue.clear();
1169 _rDescriptor.bReadOnly = impl_isReadOnlyModel_throw();
1171 catch( const Exception& )
1173 OSL_FAIL( "OPropertyBrowserController::describePropertyLine: caught an exception!" );
1178 void OPropertyBrowserController::impl_buildCategories_throw()
1180 OSL_PRECOND( m_aPageIds.empty(), "OPropertyBrowserController::impl_buildCategories_throw: duplicate call!" );
1182 StlSyntaxSequence< PropertyCategoryDescriptor > aCategories;
1183 if ( m_xModel.is() )
1184 aCategories = m_xModel->describeCategories();
1186 for ( StlSyntaxSequence< PropertyCategoryDescriptor >::const_iterator category = aCategories.begin();
1187 category != aCategories.end();
1188 ++category
1191 OSL_ENSURE( m_aPageIds.find( category->ProgrammaticName ) == m_aPageIds.end(),
1192 "OPropertyBrowserController::impl_buildCategories_throw: duplicate programmatic name!" );
1194 m_aPageIds[ category->ProgrammaticName ] =
1195 getPropertyBox().AppendPage( category->UIName, HelpIdUrl::getHelpId( category->HelpURL ) );
1200 void OPropertyBrowserController::UpdateUI()
1204 if ( !haveView() )
1205 // too early, will return later
1206 return;
1208 getPropertyBox().DisableUpdate();
1210 bool bHaveFocus = getPropertyBox().HasChildPathFocus();
1212 // create our tab pages
1213 impl_buildCategories_throw();
1214 // (and allow for pages to be actually unused)
1215 ::std::set< sal_uInt16 > aUsedPages;
1217 // when building the UI below, remember which properties are actuating,
1218 // to allow for a initial actuatinPropertyChanged call
1219 ::std::vector< OUString > aActuatingProperties;
1220 ::std::vector< Any > aActuatingPropertyValues;
1222 // ask the handlers to describe the property UI, and insert the resulting
1223 // entries into our list boxes
1224 OrderedPropertyMap::const_iterator property( m_aProperties.begin() );
1225 for ( ; property != m_aProperties.end(); ++property )
1227 OLineDescriptor aDescriptor;
1228 describePropertyLine( property->second, aDescriptor );
1230 bool bIsActuatingProperty = impl_isActuatingProperty_nothrow( property->second.Name );
1232 #if OSL_DEBUG_LEVEL > 0
1233 if ( aDescriptor.Category.isEmpty() )
1235 OString sMessage( "OPropertyBrowserController::UpdateUI: empty category provided for property '" );
1236 sMessage += OString( property->second.Name.getStr(), property->second.Name.getLength(), osl_getThreadTextEncoding() );
1237 sMessage += "'!";
1238 OSL_FAIL( sMessage.getStr() );
1240 #endif
1241 // finally insert this property control
1242 sal_uInt16 nTargetPageId = impl_getPageIdForCategory_nothrow( aDescriptor.Category );
1243 if ( nTargetPageId == (sal_uInt16)-1 )
1245 // this category does not yet exist. This is allowed, as an inspector model might be lazy, and not provide
1246 // any category information of its own. In this case, we have a fallback ...
1247 m_aPageIds[ aDescriptor.Category ] =
1248 getPropertyBox().AppendPage( aDescriptor.Category, OString() );
1249 nTargetPageId = impl_getPageIdForCategory_nothrow( aDescriptor.Category );
1252 getPropertyBox().InsertEntry( aDescriptor, nTargetPageId );
1253 aUsedPages.insert( nTargetPageId );
1255 // if it's an actuating property, remember it
1256 if ( bIsActuatingProperty )
1258 aActuatingProperties.push_back( property->second.Name );
1259 aActuatingPropertyValues.push_back( impl_getPropertyValue_throw( property->second.Name ) );
1263 // update any dependencies for the actuating properties which we encountered
1265 ::std::vector< OUString >::const_iterator aProperty = aActuatingProperties.begin();
1266 ::std::vector< Any >::const_iterator aPropertyValue = aActuatingPropertyValues.begin();
1267 for ( ; aProperty != aActuatingProperties.end(); ++aProperty, ++aPropertyValue )
1268 impl_broadcastPropertyChange_nothrow( *aProperty, *aPropertyValue, *aPropertyValue, true );
1271 // remove any unused pages (which we did not encounter properties for)
1272 HashString2Int16 aSurvivingPageIds;
1273 for ( HashString2Int16::iterator pageId = m_aPageIds.begin();
1274 pageId != m_aPageIds.end();
1275 ++pageId
1278 if ( aUsedPages.find( pageId->second ) == aUsedPages.end() )
1279 getPropertyBox().RemovePage( pageId->second );
1280 else
1281 aSurvivingPageIds.insert( *pageId );
1283 m_aPageIds.swap( aSurvivingPageIds );
1286 getPropertyBox().Show();
1287 getPropertyBox().EnableUpdate();
1288 if ( bHaveFocus )
1289 getPropertyBox().GrabFocus();
1291 // activate the first page
1292 if ( !m_aPageIds.empty() )
1294 Sequence< PropertyCategoryDescriptor > aCategories( m_xModel->describeCategories() );
1295 if ( aCategories.getLength() )
1296 m_pView->activatePage( m_aPageIds[ aCategories[0].ProgrammaticName ] );
1297 else
1298 // allowed: if we default-created the pages ...
1299 m_pView->activatePage( m_aPageIds.begin()->second );
1302 // activate the previously active page (if possible)
1303 if ( !m_sLastValidPageSelection.isEmpty() )
1304 m_sPageSelection = m_sLastValidPageSelection;
1305 selectPageFromViewData();
1307 catch( const Exception& )
1309 DBG_UNHANDLED_EXCEPTION();
1314 void OPropertyBrowserController::Clicked( const OUString& _rName, bool _bPrimary )
1318 // since the browse buttons do not get the focus when clicked with the mouse,
1319 // we need to commit the changes in the current property field
1320 getPropertyBox().CommitModified();
1322 PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.find( _rName );
1323 DBG_ASSERT( handler != m_aPropertyHandlers.end(), "OPropertyBrowserController::Clicked: a property without handler? This will crash!" );
1325 ComposedUIAutoFireGuard aAutoFireGuard( *m_pUIRequestComposer );
1327 Any aData;
1328 m_xInteractiveHandler = handler->second;
1329 InteractiveSelectionResult eResult =
1330 handler->second->onInteractivePropertySelection( _rName, _bPrimary, aData,
1331 m_pUIRequestComposer->getUIForPropertyHandler( handler->second ) );
1333 switch ( eResult )
1335 case InteractiveSelectionResult_Cancelled:
1336 case InteractiveSelectionResult_Success:
1337 // okay, nothing to do
1338 break;
1339 case InteractiveSelectionResult_ObtainedValue:
1340 handler->second->setPropertyValue( _rName, aData );
1341 break;
1342 case InteractiveSelectionResult_Pending:
1343 // also okay, we expect that the handler has disabled the UI as necessary
1344 break;
1345 default:
1346 OSL_FAIL( "OPropertyBrowserController::Clicked: unknown result value!" );
1347 break;
1350 catch (const Exception&)
1352 DBG_UNHANDLED_EXCEPTION();
1354 m_xInteractiveHandler = NULL;
1358 bool SAL_CALL OPropertyBrowserController::hasPropertyByName( const OUString& _rName ) throw (RuntimeException)
1360 for ( OrderedPropertyMap::const_iterator search = m_aProperties.begin();
1361 search != m_aProperties.end();
1362 ++search
1364 if ( search->second.Name == _rName )
1365 return true;
1366 return false;
1370 void OPropertyBrowserController::Commit( const OUString& rName, const Any& _rValue )
1374 OUString sPlcHolder = PcrRes(RID_EMBED_IMAGE_PLACEHOLDER).toString();
1375 bool bIsPlaceHolderValue = false;
1377 if ( rName == PROPERTY_IMAGE_URL )
1379 // if the prop value is the PlaceHolder
1380 // can ignore it
1381 OUString sVal;
1382 _rValue >>= sVal;
1383 if ( sVal.equals( sPlcHolder ) )
1384 bIsPlaceHolderValue = true;
1386 m_sCommittingProperty = rName;
1388 bool bIsActuatingProperty = impl_isActuatingProperty_nothrow( rName );
1390 Any aOldValue;
1391 if ( bIsActuatingProperty )
1392 aOldValue = impl_getPropertyValue_throw( rName );
1394 // do we have a dedicated handler for this property, which we can delegate some tasks to?
1395 PropertyHandlerRef handler = impl_getHandlerForProperty_throw( rName );
1398 // set the value ( only if it's not a placeholder )
1399 if ( !bIsPlaceHolderValue )
1400 handler->setPropertyValue( rName, _rValue );
1403 // re-retrieve the value
1404 Any aNormalizedValue = handler->getPropertyValue( rName );
1406 // care for any inter-property dependencies
1407 if ( bIsActuatingProperty )
1408 impl_broadcastPropertyChange_nothrow( rName, aNormalizedValue, aOldValue, false );
1410 // and display it again. This ensures proper formatting
1411 getPropertyBox().SetPropertyValue( rName, aNormalizedValue, false );
1413 catch(const PropertyVetoException& eVetoException)
1415 ScopedVclPtr<InfoBox>::Create(m_pView, eVetoException.Message)->Execute();
1416 PropertyHandlerRef handler = impl_getHandlerForProperty_throw( rName );
1417 Any aNormalizedValue = handler->getPropertyValue( rName );
1418 getPropertyBox().SetPropertyValue( rName, aNormalizedValue, false );
1420 catch(const Exception&)
1422 OSL_FAIL("OPropertyBrowserController::Commit : caught an exception !");
1425 m_sCommittingProperty.clear();
1429 namespace
1434 void OPropertyBrowserController::focusGained( const Reference< XPropertyControl >& _Control )
1436 m_aControlObservers.notifyEach( &XPropertyControlObserver::focusGained, _Control );
1440 void OPropertyBrowserController::valueChanged( const Reference< XPropertyControl >& _Control )
1442 m_aControlObservers.notifyEach( &XPropertyControlObserver::valueChanged, _Control );
1446 namespace
1448 Reference< XPropertyHandler > lcl_createHandler( const Reference<XComponentContext>& _rContext, const Any& _rFactoryDescriptor )
1450 Reference< XPropertyHandler > xHandler;
1452 OUString sServiceName;
1453 Reference< XSingleServiceFactory > xServiceFac;
1454 Reference< XSingleComponentFactory > xComponentFac;
1456 if ( _rFactoryDescriptor >>= sServiceName )
1457 xHandler.set( _rContext->getServiceManager()->createInstanceWithContext( sServiceName, _rContext ), UNO_QUERY );
1458 else if ( _rFactoryDescriptor >>= xServiceFac )
1459 xHandler.set(xServiceFac->createInstance(), css::uno::UNO_QUERY);
1460 else if ( _rFactoryDescriptor >>= xComponentFac )
1461 xHandler.set(xComponentFac->createInstanceWithContext( _rContext ), css::uno::UNO_QUERY);
1462 OSL_ENSURE(xHandler.is(),"lcl_createHandler: Can not create handler");
1463 return xHandler;
1468 void OPropertyBrowserController::getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers )
1470 _rHandlers.resize( 0 );
1471 if ( _rObjects.empty() )
1472 return;
1474 // create a component context for the handlers, containing some information about where
1475 // they live
1476 Reference< XComponentContext > xHandlerContext( m_xContext );
1478 // if our own creator did not pass a dialog parent window, use our own view for this
1479 Reference< XWindow > xParentWindow;
1480 Any any = m_xContext->getValueByName( "DialogParentWindow" );
1481 any >>= xParentWindow;
1482 if ( !xParentWindow.is() )
1484 ::cppu::ContextEntry_Init aHandlerContextInfo[] =
1486 ::cppu::ContextEntry_Init( OUString( "DialogParentWindow" ), makeAny( VCLUnoHelper::GetInterface( m_pView ) ) )
1488 xHandlerContext = ::cppu::createComponentContext(
1489 aHandlerContextInfo, SAL_N_ELEMENTS( aHandlerContextInfo ),
1490 m_xContext );
1493 Sequence< Any > aHandlerFactories;
1494 if ( m_xModel.is() )
1495 aHandlerFactories = m_xModel->getHandlerFactories();
1497 const Any* pHandlerFactory = aHandlerFactories.getConstArray();
1498 const Any* pHandlerFactoryEnd = aHandlerFactories.getConstArray() + aHandlerFactories.getLength();
1500 while ( pHandlerFactory != pHandlerFactoryEnd )
1502 if ( _rObjects.size() == 1 )
1503 { // we're inspecting only one object -> one handler
1504 Reference< XPropertyHandler > xHandler( lcl_createHandler( m_xContext, *pHandlerFactory ) );
1505 if ( xHandler.is() )
1507 xHandler->inspect( _rObjects[0] );
1508 _rHandlers.push_back( xHandler );
1511 else
1513 // create a single handler for every single object
1514 ::std::vector< Reference< XPropertyHandler > > aSingleHandlers( _rObjects.size() );
1515 ::std::vector< Reference< XPropertyHandler > >::iterator pHandler = aSingleHandlers.begin();
1517 InterfaceArray::const_iterator pObject = _rObjects.begin();
1518 InterfaceArray::const_iterator pObjectEnd = _rObjects.end();
1520 for ( ; pObject != pObjectEnd; ++pObject )
1522 *pHandler = lcl_createHandler( m_xContext, *pHandlerFactory );
1523 if ( pHandler->is() )
1525 (*pHandler)->inspect( *pObject );
1526 ++pHandler;
1529 aSingleHandlers.resize( pHandler - aSingleHandlers.begin() );
1531 // then create a handler which composes information out of those single handlers
1532 if ( !aSingleHandlers.empty() )
1533 _rHandlers.push_back( new PropertyComposer( aSingleHandlers ) );
1536 ++pHandlerFactory;
1539 // note that the handlers will not be used by our caller, if they indicate that there are no
1540 // properties they feel responsible for
1544 bool OPropertyBrowserController::impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty )
1546 OrderedPropertyMap::const_iterator search = m_aProperties.begin();
1547 for ( ; search != m_aProperties.end(); ++search )
1548 if ( search->second.Name == _rName )
1549 break;
1550 if ( _pProperty )
1551 *_pProperty = search;
1552 return ( search != m_aProperties.end() );
1556 void OPropertyBrowserController::rebuildPropertyUI( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
1558 ::osl::MutexGuard aGuard( m_aMutex );
1559 if ( !haveView() )
1560 throw RuntimeException();
1562 OrderedPropertyMap::const_iterator propertyPos;
1563 if ( !impl_findObjectProperty_nothrow( _rPropertyName, &propertyPos ) )
1564 return;
1566 OLineDescriptor aDescriptor;
1569 describePropertyLine( propertyPos->second, aDescriptor );
1571 catch( const Exception& )
1573 OSL_FAIL( "OPropertyBrowserController::rebuildPropertyUI: caught an exception!" );
1576 getPropertyBox().ChangeEntry( aDescriptor );
1580 void OPropertyBrowserController::enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) throw (RuntimeException, std::exception)
1582 ::osl::MutexGuard aGuard( m_aMutex );
1583 if ( !haveView() )
1584 throw RuntimeException();
1586 if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
1587 return;
1589 getPropertyBox().EnablePropertyLine( _rPropertyName, _bEnable );
1593 void OPropertyBrowserController::enablePropertyUIElements( const OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable ) throw (RuntimeException, std::exception)
1595 ::osl::MutexGuard aGuard( m_aMutex );
1596 if ( !haveView() )
1597 throw RuntimeException();
1599 if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
1600 return;
1602 getPropertyBox().EnablePropertyControls( _rPropertyName, _nElements, _bEnable );
1606 void OPropertyBrowserController::showPropertyUI( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
1608 ::osl::MutexGuard aGuard( m_aMutex );
1609 if ( !haveView() )
1610 throw RuntimeException();
1612 // look up the property in our object properties
1613 OrderedPropertyMap::const_iterator propertyPos;
1614 if ( !impl_findObjectProperty_nothrow( _rPropertyName, &propertyPos ) )
1615 return;
1617 if ( getPropertyBox().GetPropertyPos( _rPropertyName ) != EDITOR_LIST_ENTRY_NOTFOUND )
1619 rebuildPropertyUI( _rPropertyName );
1620 return;
1623 OLineDescriptor aDescriptor;
1624 describePropertyLine( propertyPos->second, aDescriptor );
1626 // look for the position to insert the property
1628 // side note: The methods GetPropertyPos and InsertEntry of the OPropertyEditor work
1629 // only on the current page. This implies that it's impossible to use this method here
1630 // to show property lines which are *not* on the current page.
1631 // This is sufficient for now, but should be changed in the future.
1633 // by definition, the properties in m_aProperties are in the order in which they appear in the UI
1634 // So all we need is a predecessor of pProperty in m_aProperties
1635 sal_uInt16 nUIPos = EDITOR_LIST_ENTRY_NOTFOUND;
1638 if ( propertyPos != m_aProperties.begin() )
1639 --propertyPos;
1640 nUIPos = getPropertyBox().GetPropertyPos( propertyPos->second.Name );
1642 while ( ( nUIPos == EDITOR_LIST_ENTRY_NOTFOUND ) && ( propertyPos != m_aProperties.begin() ) );
1644 if ( nUIPos == EDITOR_LIST_ENTRY_NOTFOUND )
1645 // insert at the very top
1646 nUIPos = 0;
1647 else
1648 // insert right after the predecessor we found
1649 ++nUIPos;
1651 getPropertyBox().InsertEntry(
1652 aDescriptor, impl_getPageIdForCategory_nothrow( aDescriptor.Category ), nUIPos );
1656 void OPropertyBrowserController::hidePropertyUI( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
1658 ::osl::MutexGuard aGuard( m_aMutex );
1659 if ( !haveView() )
1660 throw RuntimeException();
1662 if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
1663 return;
1665 getPropertyBox().RemoveEntry( _rPropertyName );
1669 void OPropertyBrowserController::showCategory( const OUString& _rCategory, sal_Bool _bShow ) throw (RuntimeException, std::exception)
1671 ::osl::MutexGuard aGuard( m_aMutex );
1672 if ( !haveView() )
1673 throw RuntimeException();
1675 sal_uInt16 nPageId = impl_getPageIdForCategory_nothrow( _rCategory );
1676 OSL_ENSURE( nPageId != (sal_uInt16)-1, "OPropertyBrowserController::showCategory: invalid category!" );
1678 getPropertyBox().ShowPropertyPage( nPageId, _bShow );
1682 Reference< XPropertyControl > SAL_CALL OPropertyBrowserController::getPropertyControl( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
1684 ::osl::MutexGuard aGuard( m_aMutex );
1685 if ( !haveView() )
1686 throw RuntimeException();
1688 Reference< XPropertyControl > xControl( getPropertyBox().GetPropertyControl( _rPropertyName ) );
1689 return xControl;
1693 void SAL_CALL OPropertyBrowserController::registerControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException, std::exception)
1695 m_aControlObservers.addInterface( _Observer );
1699 void SAL_CALL OPropertyBrowserController::revokeControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException, std::exception)
1701 m_aControlObservers.removeInterface( _Observer );
1705 void SAL_CALL OPropertyBrowserController::setHelpSectionText( const OUString& _rHelpText ) throw (NoSupportException, RuntimeException, std::exception)
1707 SolarMutexGuard aSolarGuard;
1708 ::osl::MutexGuard aGuard( m_aMutex );
1710 if ( !haveView() )
1711 throw DisposedException();
1713 if ( !getPropertyBox().HasHelpSection() )
1714 throw NoSupportException();
1716 getPropertyBox().SetHelpText( _rHelpText );
1720 void OPropertyBrowserController::impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const Any& _rNewValue, const Any& _rOldValue, bool _bFirstTimeInit ) const
1722 // are there one or more handlers which are interested in the actuation?
1723 ::std::pair< PropertyHandlerMultiRepository::const_iterator, PropertyHandlerMultiRepository::const_iterator > aInterestedHandlers =
1724 m_aDependencyHandlers.equal_range( _rPropertyName );
1725 if ( aInterestedHandlers.first == aInterestedHandlers.second )
1726 // none of our handlers is interested in this
1727 return;
1729 ComposedUIAutoFireGuard aAutoFireGuard( *m_pUIRequestComposer );
1732 // collect the responses from all interested handlers
1733 PropertyHandlerMultiRepository::const_iterator handler = aInterestedHandlers.first;
1734 while ( handler != aInterestedHandlers.second )
1736 handler->second->actuatingPropertyChanged( _rPropertyName, _rNewValue, _rOldValue,
1737 m_pUIRequestComposer->getUIForPropertyHandler( handler->second ),
1738 _bFirstTimeInit );
1739 ++handler;
1742 catch( const Exception& )
1744 DBG_UNHANDLED_EXCEPTION();
1749 } // namespace pcr
1753 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */