LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - propcontroller.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 325 755 43.0 %
Date: 2014-11-03 Functions: 50 86 58.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #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"
      33             : 
      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 <osl/mutex.hxx>
      48             : #include <cppuhelper/component_context.hxx>
      49             : #include <cppuhelper/exc_hlp.hxx>
      50             : #include <cppuhelper/supportsservice.hxx>
      51             : 
      52             : #include <algorithm>
      53             : #include <functional>
      54             : #include <sal/macros.h>
      55             : 
      56             : 
      57             : // !!! outside the namespace !!!
      58           4 : extern "C" void SAL_CALL createRegistryInfo_OPropertyBrowserController()
      59             : {
      60           4 :     ::pcr::OAutoRegistration< ::pcr::OPropertyBrowserController > aAutoRegistration;
      61           4 : }
      62             : 
      63             : 
      64             : namespace pcr
      65             : {
      66             : 
      67             : 
      68             :     using namespace ::com::sun::star;
      69             :     using namespace ::com::sun::star::uno;
      70             :     using namespace ::com::sun::star::awt;
      71             :     using namespace ::com::sun::star::form;
      72             :     using namespace ::com::sun::star::beans;
      73             :     using namespace ::com::sun::star::script;
      74             :     using namespace ::com::sun::star::lang;
      75             :     using namespace ::com::sun::star::container;
      76             :     using namespace ::com::sun::star::frame;
      77             :     using namespace ::com::sun::star::util;
      78             :     using namespace ::com::sun::star::inspection;
      79             :     using namespace ::com::sun::star::ucb;
      80             :     using namespace ::comphelper;
      81             : 
      82             : 
      83             :     //= OPropertyBrowserController
      84             : 
      85             : 
      86           6 :     OPropertyBrowserController::OPropertyBrowserController( const Reference< XComponentContext >& _rxContext )
      87             :             :m_xContext(_rxContext)
      88             :             ,m_aDisposeListeners( m_aMutex )
      89             :             ,m_aControlObservers( m_aMutex )
      90             :             ,m_pView(NULL)
      91             :             ,m_bContainerFocusListening( false )
      92             :             ,m_bSuspendingPropertyHandlers( false )
      93             :             ,m_bConstructed( false )
      94           6 :             ,m_bBindingIntrospectee( false )
      95             :     {
      96           6 :     }
      97             : 
      98             : 
      99          18 :     OPropertyBrowserController::~OPropertyBrowserController()
     100             :     {
     101             :         // stop listening for property changes
     102           6 :         acquire();
     103           6 :         stopInspection( true );
     104          12 :     }
     105             : 
     106             : 
     107         694 :     IMPLEMENT_FORWARD_REFCOUNT( OPropertyBrowserController, OPropertyBrowserController_Base )
     108             : 
     109             : 
     110         108 :     Any SAL_CALL OPropertyBrowserController::queryInterface( const Type& _rType ) throw (RuntimeException, std::exception)
     111             :     {
     112         108 :         Any aReturn = OPropertyBrowserController_Base::queryInterface( _rType );
     113         108 :         if ( !aReturn.hasValue() )
     114          80 :             aReturn = ::cppu::queryInterface(
     115             :                 _rType,
     116             :                 static_cast< XObjectInspectorUI* >( this )
     117          40 :             );
     118         108 :         return aReturn;
     119             :     }
     120             : 
     121             : 
     122           4 :     void OPropertyBrowserController::startContainerWindowListening()
     123             :     {
     124           4 :         if (m_bContainerFocusListening)
     125           4 :             return;
     126             : 
     127           4 :         if (m_xFrame.is())
     128             :         {
     129           4 :             Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
     130           4 :             if (xContainerWindow.is())
     131             :             {
     132           4 :                 xContainerWindow->addFocusListener(this);
     133           4 :                 m_bContainerFocusListening = true;
     134           4 :             }
     135             :         }
     136             : 
     137             :         DBG_ASSERT(m_bContainerFocusListening, "OPropertyBrowserController::startContainerWindowListening: unable to start listening (inconsistence)!");
     138             :     }
     139             : 
     140             : 
     141           8 :     void OPropertyBrowserController::stopContainerWindowListening()
     142             :     {
     143           8 :         if (!m_bContainerFocusListening)
     144          12 :             return;
     145             : 
     146           4 :         if (m_xFrame.is())
     147             :         {
     148           4 :             Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
     149           4 :             if (xContainerWindow.is())
     150             :             {
     151           4 :                 xContainerWindow->removeFocusListener(this);
     152           4 :                 m_bContainerFocusListening = false;
     153           4 :             }
     154             :         }
     155             : 
     156             :         DBG_ASSERT(!m_bContainerFocusListening, "OPropertyBrowserController::stopContainerWindowListening: unable to stop listening (inconsistence)!");
     157             :     }
     158             : 
     159             : 
     160           8 :     Reference< XObjectInspectorModel > SAL_CALL OPropertyBrowserController::getInspectorModel() throw (RuntimeException, std::exception)
     161             :     {
     162           8 :         return m_xModel;
     163             :     }
     164             : 
     165             : 
     166           4 :     void OPropertyBrowserController::impl_initializeView_nothrow()
     167             :     {
     168             :         OSL_PRECOND( haveView(), "OPropertyBrowserController::impl_initializeView_nothrow: not to be called when we have no view!" );
     169           4 :         if ( !haveView() )
     170           0 :             return;
     171             : 
     172           4 :         if ( !m_xModel.is() )
     173             :             // allowed
     174           0 :             return;
     175             : 
     176             :         try
     177             :         {
     178           4 :             getPropertyBox().EnableHelpSection( m_xModel->getHasHelpSection() );
     179           4 :             getPropertyBox().SetHelpLineLimites( m_xModel->getMinHelpTextLines(), m_xModel->getMaxHelpTextLines() );
     180             :         }
     181           0 :         catch( const Exception& )
     182             :         {
     183             :             DBG_UNHANDLED_EXCEPTION();
     184             :         }
     185             :     }
     186             : 
     187             : 
     188           0 :     void OPropertyBrowserController::impl_updateReadOnlyView_nothrow()
     189             :     {
     190             :         // this is a huge cudgel, admitted.
     191             :         // The problem is that in case we were previously read-only, all our controls
     192             :         // were created read-only, too. We cannot simply switch them to not-read-only.
     193             :         // Even if they had an API for this, we do not know whether they were
     194             :         // originally created read-only, or if they are read-only just because
     195             :         // the model was.
     196           0 :         impl_rebindToInspectee_nothrow( m_aInspectedObjects );
     197           0 :     }
     198             : 
     199             : 
     200           0 :     bool OPropertyBrowserController::impl_isReadOnlyModel_throw() const
     201             :     {
     202           0 :         if ( !m_xModel.is() )
     203           0 :             return false;
     204             : 
     205           0 :         return m_xModel->getIsReadOnly();
     206             :     }
     207             : 
     208             : 
     209          44 :     void OPropertyBrowserController::impl_startOrStopModelListening_nothrow( bool _bDoListen ) const
     210             :     {
     211             :         try
     212             :         {
     213          44 :             Reference< XPropertySet > xModelProperties( m_xModel, UNO_QUERY );
     214          44 :             if ( !xModelProperties.is() )
     215             :                 // okay, so the model doesn't want to change its properties
     216             :                 // dynamically - fine with us
     217          64 :                 return;
     218             : 
     219             :             void (SAL_CALL XPropertySet::*pListenerOperation)( const OUString&, const Reference< XPropertyChangeListener >& )
     220          24 :                 = _bDoListen ? &XPropertySet::addPropertyChangeListener : &XPropertySet::removePropertyChangeListener;
     221             : 
     222          24 :             (xModelProperties.get()->*pListenerOperation)(
     223             :                 OUString(  "IsReadOnly"  ),
     224             :                 const_cast< OPropertyBrowserController* >( this )
     225          24 :             );
     226             :         }
     227           0 :         catch( const Exception& )
     228             :         {
     229             :             DBG_UNHANDLED_EXCEPTION();
     230             :         }
     231             :     }
     232             : 
     233             : 
     234          22 :     void OPropertyBrowserController::impl_bindToNewModel_nothrow( const Reference< XObjectInspectorModel >& _rxInspectorModel )
     235             :     {
     236          22 :         impl_startOrStopModelListening_nothrow( false );
     237          22 :         m_xModel = _rxInspectorModel;
     238          22 :         impl_startOrStopModelListening_nothrow( true );
     239             : 
     240             :         // initialize the view, if we already have one
     241          22 :         if ( haveView() )
     242           0 :             impl_initializeView_nothrow();
     243             : 
     244             :         // inspect again, if we already have inspectees
     245          22 :         if ( !m_aInspectedObjects.empty() )
     246           8 :             impl_rebindToInspectee_nothrow( m_aInspectedObjects );
     247          22 :     }
     248             : 
     249             : 
     250          12 :     void SAL_CALL OPropertyBrowserController::setInspectorModel( const Reference< XObjectInspectorModel >& _inspectorModel ) throw (RuntimeException, std::exception)
     251             :     {
     252          12 :         ::osl::MutexGuard aGuard( m_aMutex );
     253             : 
     254          12 :         if ( m_xModel == _inspectorModel )
     255          12 :             return;
     256             : 
     257          12 :         impl_bindToNewModel_nothrow( _inspectorModel );
     258             :     }
     259             : 
     260             : 
     261          16 :     Reference< XObjectInspectorUI > SAL_CALL OPropertyBrowserController::getInspectorUI() throw (RuntimeException, std::exception)
     262             :     {
     263             :         // we're derived from this interface, though we do not expose it in queryInterface and getTypes.
     264          16 :         return this;
     265             :     }
     266             : 
     267             : 
     268           4 :     void SAL_CALL OPropertyBrowserController::inspect( const Sequence< Reference< XInterface > >& _rObjects ) throw (com::sun::star::util::VetoException, RuntimeException, std::exception)
     269             :     {
     270           4 :         SolarMutexGuard aSolarGuard;
     271           8 :         ::osl::MutexGuard aGuard( m_aMutex );
     272             : 
     273           4 :         if ( m_bSuspendingPropertyHandlers || !suspendAll_nothrow() )
     274             :         {   // we already are trying to suspend the component (this is somewhere up the stack)
     275             :             // OR one of our property handlers raised a veto against closing. Well, we *need* to close
     276             :             // it in order to inspect another object.
     277           0 :             throw VetoException();
     278             :         }
     279           4 :         if ( m_bBindingIntrospectee )
     280           0 :             throw VetoException();
     281             : 
     282           4 :         m_bBindingIntrospectee = true;
     283           4 :         impl_rebindToInspectee_nothrow( InterfaceArray( _rObjects.getConstArray(), _rObjects.getConstArray() + _rObjects.getLength() ) );
     284           8 :         m_bBindingIntrospectee = false;
     285             : 
     286           4 :     }
     287             : 
     288             : 
     289           0 :     Reference< XDispatch > SAL_CALL OPropertyBrowserController::queryDispatch( const URL& /*URL*/, const OUString& /*TargetFrameName*/, ::sal_Int32 /*SearchFlags*/ ) throw (RuntimeException, std::exception)
     290             :     {
     291             :         // we don't have any dispatches at all, right now
     292           0 :         return Reference< XDispatch >();
     293             :     }
     294             : 
     295             : 
     296           0 :     Sequence< Reference< XDispatch > > SAL_CALL OPropertyBrowserController::queryDispatches( const Sequence< DispatchDescriptor >& Requests ) throw (RuntimeException, std::exception)
     297             :     {
     298           0 :         Sequence< Reference< XDispatch > > aReturn;
     299           0 :         sal_Int32 nLen = Requests.getLength();
     300           0 :         aReturn.realloc( nLen );
     301             : 
     302           0 :                 Reference< XDispatch >* pReturn     = aReturn.getArray();
     303           0 :         const   Reference< XDispatch >* pReturnEnd  = aReturn.getArray() + nLen;
     304           0 :         const   DispatchDescriptor*     pDescripts  = Requests.getConstArray();
     305             : 
     306           0 :         for ( ; pReturn != pReturnEnd; ++ pReturn, ++pDescripts )
     307           0 :             *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
     308             : 
     309           0 :         return aReturn;
     310             :     }
     311             : 
     312             : 
     313           2 :     void SAL_CALL OPropertyBrowserController::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException, std::exception)
     314             :     {
     315           2 :         if ( m_bConstructed )
     316           0 :             throw AlreadyInitializedException();
     317             : 
     318           2 :         StlSyntaxSequence< Any > arguments( _arguments );
     319           2 :         if ( arguments.empty() )
     320             :         {   // constructor: "createDefault()"
     321           2 :             createDefault();
     322           2 :             return;
     323             :         }
     324             : 
     325           0 :         Reference< XObjectInspectorModel > xModel;
     326           0 :         if ( arguments.size() == 1 )
     327             :         {   // constructor: "createWithModel( XObjectInspectorModel )"
     328           0 :             if ( !( arguments[0] >>= xModel ) )
     329           0 :                 throw IllegalArgumentException( OUString(), *this, 0 );
     330           0 :             createWithModel( xModel );
     331           0 :             return;
     332             :         }
     333             : 
     334           2 :         throw IllegalArgumentException( OUString(), *this, 0 );
     335             :     }
     336             : 
     337             : 
     338           2 :     void OPropertyBrowserController::createDefault()
     339             :     {
     340           2 :         m_bConstructed = true;
     341           2 :     }
     342             : 
     343             : 
     344           0 :     void OPropertyBrowserController::createWithModel( const Reference< XObjectInspectorModel >& _rxModel )
     345             :     {
     346           0 :         osl_atomic_increment( &m_refCount );
     347             :         {
     348           0 :             setInspectorModel( _rxModel );
     349             :         }
     350           0 :         osl_atomic_decrement( &m_refCount );
     351             : 
     352           0 :         m_bConstructed = true;
     353           0 :     }
     354             : 
     355             : 
     356           4 :     void SAL_CALL OPropertyBrowserController::attachFrame( const Reference< XFrame >& _rxFrame ) throw(RuntimeException, std::exception)
     357             :     {
     358           4 :         SolarMutexGuard aSolarGuard;
     359           8 :         ::osl::MutexGuard aGuard( m_aMutex );
     360             : 
     361           4 :         if (_rxFrame.is() && haveView())
     362           0 :             throw RuntimeException("Unable to attach to a second frame.",*this);
     363             : 
     364             :         // revoke as focus listener from the old container window
     365           4 :         stopContainerWindowListening();
     366             : 
     367           4 :         m_xFrame = _rxFrame;
     368           4 :         if (!m_xFrame.is())
     369           4 :             return;
     370             : 
     371             :         // TODO: this construction perhaps should be done outside. Don't know the exact meaning of attachFrame.
     372             :         // Maybe it is intended to only announce the frame to the controller, and the instance doing this
     373             :         // announcement is responsible for calling setComponent, too.
     374           8 :         Reference< XWindow > xContainerWindow = m_xFrame->getContainerWindow();
     375           4 :         VCLXWindow* pContainerWindow = VCLXWindow::GetImplementation(xContainerWindow);
     376           4 :         vcl::Window* pParentWin = pContainerWindow ? pContainerWindow->GetWindow() : NULL;
     377           4 :         if (!pParentWin)
     378           0 :             throw RuntimeException("The frame is invalid. Unable to extract the container window.",*this);
     379             : 
     380           4 :         if ( Construct( pParentWin ) )
     381             :         {
     382             :             try
     383             :             {
     384           4 :                 m_xFrame->setComponent( VCLUnoHelper::GetInterface( m_pView ), this );
     385             :             }
     386           0 :             catch( const Exception& )
     387             :             {
     388             :                 OSL_FAIL( "OPropertyBrowserController::attachFrame: caught an exception!" );
     389             :             }
     390             :         }
     391             : 
     392           4 :         startContainerWindowListening();
     393             : 
     394           8 :         UpdateUI();
     395             :     }
     396             : 
     397             : 
     398           8 :     sal_Bool SAL_CALL OPropertyBrowserController::attachModel( const Reference< XModel >& _rxModel ) throw(RuntimeException, std::exception)
     399             :     {
     400           8 :         Reference< XObjectInspectorModel > xModel( _rxModel, UNO_QUERY );
     401           8 :         if ( !xModel.is() )
     402           8 :             return false;
     403             : 
     404           0 :         setInspectorModel( xModel );
     405           0 :         return getInspectorModel() == _rxModel;
     406             :     }
     407             : 
     408             : 
     409           8 :     bool OPropertyBrowserController::suspendAll_nothrow()
     410             :     {
     411             :         // if there is a handle inside its "onInteractivePropertySelection" method,
     412             :         // then veto
     413             :         // Normally, we could expect every handler to do this itself, but being
     414             :         // realistic, it's safer to handle this here in general.
     415           8 :         if ( m_xInteractiveHandler.is() )
     416           0 :             return false;
     417             : 
     418           8 :         m_bSuspendingPropertyHandlers = true;
     419           8 :         bool bHandlerVeto = !suspendPropertyHandlers_nothrow( true );
     420           8 :         m_bSuspendingPropertyHandlers = false;
     421           8 :         if ( bHandlerVeto )
     422           0 :             return false;
     423             : 
     424           8 :         return true;
     425             :     }
     426             : 
     427             : 
     428           8 :     bool OPropertyBrowserController::suspendPropertyHandlers_nothrow( bool _bSuspend )
     429             :     {
     430           8 :         PropertyHandlerArray aAllHandlers;  // will contain every handler exactly once
     431          24 :         for (   PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.begin();
     432          16 :                 handler != m_aPropertyHandlers.end();
     433             :                 ++handler
     434             :             )
     435             :         {
     436           0 :             if ( ::std::find( aAllHandlers.begin(), aAllHandlers.end(), handler->second ) != aAllHandlers.end() )
     437             :                 // already visited this particular handler (m_aPropertyHandlers usually contains
     438             :                 // the same handler more than once)
     439           0 :                 continue;
     440           0 :             aAllHandlers.push_back( handler->second );
     441             :         }
     442             : 
     443          24 :         for ( PropertyHandlerArray::iterator loop = aAllHandlers.begin();
     444          16 :               loop != aAllHandlers.end();
     445             :               ++loop
     446             :             )
     447             :         {
     448             :             try
     449             :             {
     450           0 :                 if ( !(*loop)->suspend( _bSuspend ) )
     451           0 :                     if ( _bSuspend )
     452             :                         // if we're not suspending, but reactivating, ignore the error
     453           0 :                         return false;
     454             :             }
     455           0 :             catch( const Exception& )
     456             :             {
     457             :                 OSL_FAIL( "OPropertyBrowserController::suspendPropertyHandlers_nothrow: caught an exception!" );
     458             :             }
     459             :         }
     460           8 :         return true;
     461             :     }
     462             : 
     463             : 
     464           4 :     sal_Bool SAL_CALL OPropertyBrowserController::suspend( sal_Bool _bSuspend ) throw(RuntimeException, std::exception)
     465             :     {
     466           4 :         ::osl::MutexGuard aGuard( m_aMutex );
     467             :         OSL_ENSURE( haveView(), "OPropertyBrowserController::suspend: don't have a view anymore!" );
     468             : 
     469           4 :         if ( !_bSuspend )
     470             :         {   // this means a "suspend" is to be "revoked"
     471           0 :             suspendPropertyHandlers_nothrow( false );
     472             :             // we ourself cannot revoke our suspend
     473           0 :             return sal_False;
     474             :         }
     475             : 
     476           4 :         if ( !suspendAll_nothrow() )
     477           0 :             return sal_False;
     478             : 
     479             :         // commit the editor's content
     480           4 :         if ( haveView() )
     481           4 :             getPropertyBox().CommitModified();
     482             : 
     483             :         // stop listening
     484           4 :         stopContainerWindowListening();
     485             : 
     486             :         // outtahere
     487           4 :         return sal_True;
     488             :     }
     489             : 
     490             : 
     491           4 :     Any SAL_CALL OPropertyBrowserController::getViewData(  ) throw(RuntimeException, std::exception)
     492             :     {
     493           4 :         return makeAny( m_sPageSelection );
     494             :     }
     495             : 
     496             : 
     497           4 :     void SAL_CALL OPropertyBrowserController::restoreViewData( const Any& Data ) throw(RuntimeException, std::exception)
     498             :     {
     499           4 :         OUString sPageSelection;
     500           4 :         if ( ( Data >>= sPageSelection ) && !sPageSelection.isEmpty() )
     501             :         {
     502           0 :             m_sPageSelection = sPageSelection;
     503           0 :             selectPageFromViewData();
     504           4 :         }
     505           4 :     }
     506             : 
     507             : 
     508          40 :     Reference< XModel > SAL_CALL OPropertyBrowserController::getModel(  ) throw(RuntimeException, std::exception)
     509             :     {
     510             :         // have no model
     511          40 :         return Reference< XModel >();
     512             :     }
     513             : 
     514             : 
     515           4 :     Reference< XFrame > SAL_CALL OPropertyBrowserController::getFrame(  ) throw(RuntimeException, std::exception)
     516             :     {
     517           4 :         return m_xFrame;
     518             :     }
     519             : 
     520             : 
     521          10 :     void SAL_CALL OPropertyBrowserController::dispose(  ) throw(RuntimeException, std::exception)
     522             :     {
     523          10 :         SolarMutexGuard aSolarGuard;
     524             : 
     525             :         // stop inspecting the current object
     526          10 :         stopInspection( false );
     527             : 
     528             :         // say our dispose listeners goodbye
     529          20 :         ::com::sun::star::lang::EventObject aEvt;
     530          10 :         aEvt.Source = static_cast< ::cppu::OWeakObject* >(this);
     531          10 :         m_aDisposeListeners.disposeAndClear(aEvt);
     532          10 :         m_aControlObservers.disposeAndClear(aEvt);
     533             : 
     534             :         // don't delete explicitly (this is done by the frame we reside in)
     535          10 :         m_pView = NULL;
     536             : 
     537          20 :         Reference< XComponent > xViewAsComp( m_xView, UNO_QUERY );
     538          10 :         if ( xViewAsComp.is() )
     539           4 :             xViewAsComp->removeEventListener( static_cast< XPropertyChangeListener* >( this ) );
     540          10 :         m_xView.clear( );
     541             : 
     542          10 :         m_aInspectedObjects.clear();
     543          20 :         impl_bindToNewModel_nothrow( NULL );
     544          10 :     }
     545             : 
     546             : 
     547           8 :     void SAL_CALL OPropertyBrowserController::addEventListener( const Reference< XEventListener >& _rxListener ) throw(RuntimeException, std::exception)
     548             :     {
     549           8 :         m_aDisposeListeners.addInterface(_rxListener);
     550           8 :     }
     551             : 
     552             : 
     553           4 :     void SAL_CALL OPropertyBrowserController::removeEventListener( const Reference< XEventListener >& _rxListener ) throw(RuntimeException, std::exception)
     554             :     {
     555           4 :         m_aDisposeListeners.removeInterface(_rxListener);
     556           4 :     }
     557             : 
     558             : 
     559           4 :     OUString SAL_CALL OPropertyBrowserController::getImplementationName(  ) throw(RuntimeException, std::exception)
     560             :     {
     561           4 :         return getImplementationName_static();
     562             :     }
     563             : 
     564         440 :     sal_Bool SAL_CALL OPropertyBrowserController::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
     565             :     {
     566         440 :         return cppu::supportsService(this, ServiceName);
     567             :     }
     568             : 
     569             : 
     570         440 :     Sequence< OUString > SAL_CALL OPropertyBrowserController::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
     571             :     {
     572         440 :         return getSupportedServiceNames_static();
     573             :     }
     574             : 
     575             : 
     576           8 :     OUString OPropertyBrowserController::getImplementationName_static(  ) throw(RuntimeException)
     577             :     {
     578           8 :         return OUString("org.openoffice.comp.extensions.ObjectInspector");
     579             :     }
     580             : 
     581             : 
     582         444 :     Sequence< OUString > OPropertyBrowserController::getSupportedServiceNames_static(  ) throw(RuntimeException)
     583             :     {
     584         444 :         Sequence< OUString > aSupported(1);
     585         444 :         aSupported[0] = "com.sun.star.inspection.ObjectInspector";
     586         444 :         return aSupported;
     587             :     }
     588             : 
     589             : 
     590           6 :     Reference< XInterface > SAL_CALL OPropertyBrowserController::Create(const Reference< XComponentContext >& _rxContext)
     591             :     {
     592           6 :         return *(new OPropertyBrowserController( _rxContext ) );
     593             :     }
     594             : 
     595             : 
     596           0 :     void SAL_CALL OPropertyBrowserController::focusGained( const FocusEvent& _rSource ) throw (RuntimeException, std::exception)
     597             :     {
     598           0 :         Reference< XWindow > xSourceWindow(_rSource.Source, UNO_QUERY);
     599           0 :         Reference< XWindow > xContainerWindow;
     600           0 :         if (m_xFrame.is())
     601           0 :             xContainerWindow = m_xFrame->getContainerWindow();
     602             : 
     603           0 :         if ( xContainerWindow.get() == xSourceWindow.get() )
     604             :         {   // our container window got the focus
     605           0 :             if ( haveView() )
     606           0 :                 getPropertyBox().GrabFocus();
     607           0 :         }
     608           0 :     }
     609             : 
     610             : 
     611           0 :     void SAL_CALL OPropertyBrowserController::focusLost( const FocusEvent& /*_rSource*/ ) throw (RuntimeException, std::exception)
     612             :     {
     613             :         // not interested in
     614           0 :     }
     615             : 
     616             : 
     617           0 :     void SAL_CALL OPropertyBrowserController::disposing( const EventObject& _rSource ) throw(RuntimeException, std::exception)
     618             :     {
     619           0 :         if ( m_xView.is() && ( m_xView == _rSource.Source ) )
     620             :         {
     621           0 :             m_xView = NULL;
     622           0 :             m_pView = NULL;
     623             :         }
     624             : 
     625           0 :         for (   InterfaceArray::iterator loop = m_aInspectedObjects.begin();
     626           0 :                 loop != m_aInspectedObjects.end();
     627             :                 ++loop
     628             :             )
     629             :         {
     630           0 :             if ( *loop == _rSource.Source )
     631             :             {
     632           0 :                 m_aInspectedObjects.erase( loop );
     633           0 :                 break;
     634             :             }
     635             :         }
     636           0 :     }
     637             : 
     638             : 
     639           0 :     IMPL_LINK_NOARG(OPropertyBrowserController, OnPageActivation)
     640             :     {
     641           0 :         updateViewDataFromActivePage();
     642           0 :         return 0L;
     643             :     }
     644             : 
     645             : 
     646           4 :     void OPropertyBrowserController::updateViewDataFromActivePage()
     647             :     {
     648           4 :         if (!haveView())
     649           4 :             return;
     650             : 
     651           4 :         OUString sOldSelection = m_sPageSelection;
     652           4 :         m_sPageSelection = "";
     653             : 
     654           4 :         const sal_uInt16 nCurrentPage = m_pView->getActivaPage();
     655           4 :         if ( (sal_uInt16)-1 != nCurrentPage )
     656             :         {
     657          12 :             for (   HashString2Int16::const_iterator pageId = m_aPageIds.begin();
     658           8 :                     pageId != m_aPageIds.end();
     659             :                     ++pageId
     660             :                 )
     661             :             {
     662           0 :                 if ( nCurrentPage == pageId->second )
     663             :                 {
     664           0 :                     m_sPageSelection = pageId->first;
     665           0 :                     break;
     666             :                 }
     667             :             }
     668             :         }
     669             : 
     670           4 :         if ( !m_sPageSelection.isEmpty() )
     671           0 :             m_sLastValidPageSelection = m_sPageSelection;
     672           4 :         else if ( !sOldSelection.isEmpty() )
     673           0 :             m_sLastValidPageSelection = sOldSelection;
     674             :     }
     675             : 
     676             : 
     677           4 :     sal_uInt16 OPropertyBrowserController::impl_getPageIdForCategory_nothrow( const OUString& _rCategoryName ) const
     678             :     {
     679           4 :         sal_uInt16 nPageId = (sal_uInt16)-1;
     680           4 :         HashString2Int16::const_iterator pagePos = m_aPageIds.find( _rCategoryName );
     681           4 :         if ( pagePos != m_aPageIds.end() )
     682           0 :             nPageId = pagePos->second;
     683           4 :         return nPageId;
     684             :     }
     685             : 
     686             : 
     687           4 :     void OPropertyBrowserController::selectPageFromViewData()
     688             :     {
     689           4 :         sal_uInt16 nNewPage = impl_getPageIdForCategory_nothrow( m_sPageSelection );
     690             : 
     691           4 :         if ( haveView() && ( nNewPage != (sal_uInt16)-1 ) )
     692           0 :             m_pView->activatePage( nNewPage );
     693             : 
     694             :         // just in case ...
     695           4 :         updateViewDataFromActivePage();
     696           4 :     }
     697             : 
     698             : 
     699           4 :     bool OPropertyBrowserController::Construct(vcl::Window* _pParentWin)
     700             :     {
     701             :         DBG_ASSERT(!haveView(), "OPropertyBrowserController::Construct: already have a view!");
     702             :         DBG_ASSERT(_pParentWin, "OPropertyBrowserController::Construct: invalid parent window!");
     703             : 
     704           4 :         m_pView = new OPropertyBrowserView(_pParentWin);
     705           4 :         m_pView->setPageActivationHandler(LINK(this, OPropertyBrowserController, OnPageActivation));
     706             : 
     707             :         // add as dispose listener for our view. The view is disposed by the frame we're plugged into,
     708             :         // and this disposal _deletes_ the view, so it would be deadly if we use our m_pView member
     709             :         // after that
     710           4 :         m_xView = VCLUnoHelper::GetInterface(m_pView);
     711           4 :         Reference< XComponent > xViewAsComp(m_xView, UNO_QUERY);
     712           4 :         if (xViewAsComp.is())
     713           4 :             xViewAsComp->addEventListener( static_cast< XPropertyChangeListener* >( this ) );
     714             : 
     715           4 :         getPropertyBox().SetLineListener(this);
     716           4 :         getPropertyBox().SetControlObserver(this);
     717           4 :         impl_initializeView_nothrow();
     718             : 
     719           4 :         m_pView->Show();
     720             : 
     721           4 :         return true;
     722             :     }
     723             : 
     724             : 
     725           0 :     void SAL_CALL OPropertyBrowserController::propertyChange( const PropertyChangeEvent& _rEvent ) throw (RuntimeException, std::exception)
     726             :     {
     727           0 :         if ( _rEvent.Source == m_xModel )
     728             :         {
     729           0 :             if ( _rEvent.PropertyName == "IsReadOnly" )
     730           0 :                 impl_updateReadOnlyView_nothrow();
     731           0 :             return;
     732             :         }
     733             : 
     734           0 :         if ( m_sCommittingProperty == _rEvent.PropertyName )
     735           0 :             return;
     736             : 
     737           0 :         if ( !haveView() )
     738           0 :             return;
     739             : 
     740           0 :         Any aNewValue( _rEvent.NewValue );
     741           0 :         if ( impl_hasPropertyHandlerFor_nothrow( _rEvent.PropertyName ) )
     742             :         {
     743             :             // forward the new value to the property box, to reflect the change in the UI
     744           0 :             aNewValue = impl_getPropertyValue_throw( _rEvent.PropertyName );
     745             : 
     746             :             // check whether the state is ambiguous. This is interesting in case we display the properties
     747             :             // for multiple objects at once: In this case, we'll get a notification from one of the objects,
     748             :             // but need to care for the "composed" value, which can be "ambiguous".
     749           0 :             PropertyHandlerRef xHandler( impl_getHandlerForProperty_throw( _rEvent.PropertyName ), UNO_SET_THROW );
     750           0 :             PropertyState ePropertyState( xHandler->getPropertyState( _rEvent.PropertyName ) );
     751           0 :             bool bAmbiguousValue = ( PropertyState_AMBIGUOUS_VALUE == ePropertyState );
     752             : 
     753           0 :             getPropertyBox().SetPropertyValue( _rEvent.PropertyName, aNewValue, bAmbiguousValue );
     754             :         }
     755             : 
     756             :         // if it's a actuating property, then update the UI for any dependent
     757             :         // properties
     758           0 :         if ( impl_isActuatingProperty_nothrow( _rEvent.PropertyName ) )
     759           0 :             impl_broadcastPropertyChange_nothrow( _rEvent.PropertyName, aNewValue, _rEvent.OldValue, false );
     760             :     }
     761             : 
     762             : 
     763           0 :     Reference< XPropertyControl > SAL_CALL OPropertyBrowserController::createPropertyControl( ::sal_Int16 ControlType, sal_Bool _CreateReadOnly ) throw (IllegalArgumentException, RuntimeException, std::exception)
     764             :     {
     765           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     766             : 
     767           0 :         Reference< XPropertyControl > xControl;
     768             : 
     769             :         // default winbits: a border only
     770           0 :         WinBits nWinBits = WB_BORDER;
     771             : 
     772             :         // read-only-ness
     773           0 :         _CreateReadOnly |= impl_isReadOnlyModel_throw() ? 1 : 0;
     774           0 :         if ( _CreateReadOnly )
     775           0 :             nWinBits |= WB_READONLY;
     776             : 
     777           0 :         switch ( ControlType )
     778             :         {
     779             :             case PropertyControlType::StringListField:
     780           0 :                 xControl = new OMultilineEditControl( &getPropertyBox(), eStringList, nWinBits | WB_DROPDOWN | WB_TABSTOP );
     781           0 :                 break;
     782             : 
     783             :             case PropertyControlType::MultiLineTextField:
     784           0 :                 xControl = new OMultilineEditControl( &getPropertyBox(), eMultiLineText, nWinBits | WB_DROPDOWN | WB_TABSTOP );
     785           0 :                 break;
     786             : 
     787             :             case PropertyControlType::ListBox:
     788           0 :                 xControl = new OListboxControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN);
     789           0 :                 break;
     790             : 
     791             :             case PropertyControlType::ComboBox:
     792           0 :                 xControl = new OComboboxControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN);
     793           0 :                 break;
     794             : 
     795             :             case PropertyControlType::TextField:
     796           0 :                 xControl = new OEditControl( &getPropertyBox(), false, nWinBits | WB_TABSTOP );
     797           0 :                 break;
     798             : 
     799             :             case PropertyControlType::CharacterField:
     800           0 :                 xControl = new OEditControl( &getPropertyBox(), true, nWinBits | WB_TABSTOP );
     801           0 :                 break;
     802             : 
     803             :             case PropertyControlType::NumericField:
     804           0 :                 xControl = new ONumericControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
     805           0 :                 break;
     806             : 
     807             :             case PropertyControlType::DateTimeField:
     808           0 :                 xControl = new ODateTimeControl( &getPropertyBox(), nWinBits | WB_TABSTOP );
     809           0 :                 break;
     810             : 
     811             :             case PropertyControlType::DateField:
     812           0 :                 xControl = new ODateControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
     813           0 :                 break;
     814             : 
     815             :             case PropertyControlType::TimeField:
     816           0 :                 xControl = new OTimeControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_SPIN | WB_REPEAT );
     817           0 :                 break;
     818             : 
     819             :             case PropertyControlType::ColorListBox:
     820           0 :                 xControl = new OColorControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN );
     821           0 :                 break;
     822             : 
     823             :             case PropertyControlType::HyperlinkField:
     824           0 :                 xControl = new OHyperlinkControl( &getPropertyBox(), nWinBits | WB_TABSTOP | WB_DROPDOWN );
     825           0 :                 break;
     826             : 
     827             :             default:
     828           0 :                 throw IllegalArgumentException( OUString(), *this, 1 );
     829             :         }
     830             : 
     831           0 :         return xControl;
     832             :     }
     833             : 
     834             : 
     835          40 :     void OPropertyBrowserController::impl_toggleInspecteeListening_nothrow( bool _bOn )
     836             :     {
     837         192 :         for (   InterfaceArray::const_iterator loop = m_aInspectedObjects.begin();
     838         128 :                 loop != m_aInspectedObjects.end();
     839             :                 ++loop
     840             :             )
     841             :         {
     842             :             try
     843             :             {
     844          24 :                 Reference< XComponent > xComp( *loop, UNO_QUERY );
     845          24 :                 if ( xComp.is() )
     846             :                 {
     847          24 :                     if ( _bOn )
     848          12 :                         xComp->addEventListener( static_cast< XPropertyChangeListener* >( this ) );
     849             :                     else
     850          12 :                         xComp->removeEventListener( static_cast< XPropertyChangeListener* >( this ) );
     851          24 :                 }
     852             :             }
     853           0 :             catch( const Exception& )
     854             :             {
     855             :                 DBG_UNHANDLED_EXCEPTION();
     856             :             }
     857             :         }
     858          40 :     }
     859             : 
     860             : 
     861          28 :     void OPropertyBrowserController::stopInspection( bool _bCommitModified )
     862             :     {
     863          28 :         if ( haveView() )
     864             :         {
     865           4 :             if ( _bCommitModified )
     866             :                 // commit the editor's content
     867           0 :                 getPropertyBox().CommitModified();
     868             : 
     869             :             // hide the property box so that it does not flicker
     870           4 :             getPropertyBox().Hide();
     871             : 
     872             :             // clear the property box
     873           4 :             getPropertyBox().ClearAll();
     874             :         }
     875             : 
     876             :         // destroy the view first
     877          28 :         if ( haveView() )
     878             :         {
     879             :             // remove the pages
     880          12 :             for (   HashString2Int16::const_iterator erase = m_aPageIds.begin();
     881           8 :                     erase != m_aPageIds.end();
     882             :                     ++erase
     883             :                 )
     884           0 :                 getPropertyBox().RemovePage( erase->second );
     885           4 :             clearContainer( m_aPageIds );
     886             :         }
     887             : 
     888          28 :         clearContainer( m_aProperties );
     889             : 
     890             :         // de-register as dispose-listener from our inspected objects
     891          28 :         impl_toggleInspecteeListening_nothrow( false );
     892             : 
     893             :         // handlers are obsolete, so is our "composer" for their UI requests
     894          28 :         if ( m_pUIRequestComposer.get() )
     895          12 :             m_pUIRequestComposer->dispose();
     896          28 :         m_pUIRequestComposer.reset();
     897             : 
     898             :         // clean up the property handlers
     899          28 :         PropertyHandlerArray aAllHandlers;  // will contain every handler exactly once
     900          84 :         for ( PropertyHandlerRepository::const_iterator aHandler = m_aPropertyHandlers.begin();
     901          56 :               aHandler != m_aPropertyHandlers.end();
     902             :               ++aHandler
     903             :             )
     904           0 :             if ( ::std::find( aAllHandlers.begin(), aAllHandlers.end(), aHandler->second ) == aAllHandlers.end() )
     905           0 :                 aAllHandlers.push_back( aHandler->second );
     906             : 
     907          84 :         for ( PropertyHandlerArray::iterator loop = aAllHandlers.begin();
     908          56 :               loop != aAllHandlers.end();
     909             :               ++loop
     910             :             )
     911             :         {
     912             :             try
     913             :             {
     914           0 :                 (*loop)->removePropertyChangeListener( this );
     915           0 :                 (*loop)->dispose();
     916             :             }
     917           0 :             catch( const DisposedException& )
     918             :             {
     919             :             }
     920           0 :             catch( const Exception& )
     921             :             {
     922             :                 DBG_UNHANDLED_EXCEPTION();
     923             :             }
     924             :         }
     925             : 
     926          28 :         clearContainer( m_aPropertyHandlers );
     927          28 :         clearContainer( m_aDependencyHandlers );
     928          28 :     }
     929             : 
     930             : 
     931           0 :     bool OPropertyBrowserController::impl_hasPropertyHandlerFor_nothrow( const OUString& _rPropertyName ) const
     932             :     {
     933           0 :         PropertyHandlerRepository::const_iterator handlerPos = m_aPropertyHandlers.find( _rPropertyName );
     934           0 :         return ( handlerPos != m_aPropertyHandlers.end() );
     935             :     }
     936             : 
     937             : 
     938           0 :     OPropertyBrowserController::PropertyHandlerRef OPropertyBrowserController::impl_getHandlerForProperty_throw( const OUString& _rPropertyName ) const
     939             :     {
     940           0 :         PropertyHandlerRepository::const_iterator handlerPos = m_aPropertyHandlers.find( _rPropertyName );
     941           0 :         if ( handlerPos == m_aPropertyHandlers.end() )
     942           0 :             throw RuntimeException();
     943           0 :         return handlerPos->second;
     944             :     }
     945             : 
     946             : 
     947           0 :     Any OPropertyBrowserController::impl_getPropertyValue_throw( const OUString& _rPropertyName )
     948             :     {
     949           0 :         PropertyHandlerRef handler = impl_getHandlerForProperty_throw( _rPropertyName );
     950           0 :         return handler->getPropertyValue( _rPropertyName );
     951             :     }
     952             : 
     953             : 
     954          12 :     void OPropertyBrowserController::impl_rebindToInspectee_nothrow( const InterfaceArray& _rObjects )
     955             :     {
     956             :         try
     957             :         {
     958             :             // stop inspecting the old object(s)
     959          12 :             stopInspection( true );
     960             : 
     961             :             // inspect the new object(s)
     962          12 :             m_aInspectedObjects = _rObjects;
     963          12 :             doInspection();
     964             : 
     965             :             // update the user interface
     966          12 :             UpdateUI();
     967             :         }
     968             : 
     969           0 :         catch(const Exception&)
     970             :         {
     971             :             OSL_FAIL("OPropertyBrowserController::impl_rebindToInspectee_nothrow: caught an exception !");
     972             :         }
     973          12 :     }
     974             : 
     975             : 
     976          12 :     void OPropertyBrowserController::doInspection()
     977             :     {
     978             :         try
     979             :         {
     980             : 
     981             :             // obtain the properties of the object
     982          12 :             ::std::vector< Property > aProperties;
     983             : 
     984          24 :             PropertyHandlerArray aPropertyHandlers;
     985          12 :             getPropertyHandlers( m_aInspectedObjects, aPropertyHandlers );
     986             : 
     987          12 :             PropertyHandlerArray::iterator aHandler( aPropertyHandlers.begin() );
     988          32 :             while ( aHandler != aPropertyHandlers.end() )
     989             :             {
     990             :                 DBG_ASSERT( aHandler->get(), "OPropertyBrowserController::doInspection: invalid handler!" );
     991             : 
     992           8 :                 StlSyntaxSequence< Property > aThisHandlersProperties = (*aHandler)->getSupportedProperties();
     993             : 
     994           8 :                 if ( aThisHandlersProperties.empty() )
     995             :                 {
     996             :                     // this handler doesn't know anything about the current inspectee -> ignore it
     997           8 :                     (*aHandler)->dispose();
     998           8 :                     aHandler = aPropertyHandlers.erase( aHandler );
     999           8 :                     continue;
    1000             :                 }
    1001             : 
    1002             :                 // append these properties to our "all properties" array
    1003           0 :                 aProperties.reserve( aProperties.size() + aThisHandlersProperties.size() );
    1004           0 :                 for (   StlSyntaxSequence< Property >::const_iterator copyProperty = aThisHandlersProperties.begin();
    1005           0 :                         copyProperty != aThisHandlersProperties.end();
    1006             :                         ++copyProperty
    1007             :                     )
    1008             :                 {
    1009             :                     ::std::vector< Property >::const_iterator previous = ::std::find_if(
    1010             :                         aProperties.begin(),
    1011             :                         aProperties.end(),
    1012             :                         FindPropertyByName( copyProperty->Name )
    1013           0 :                     );
    1014           0 :                     if ( previous == aProperties.end() )
    1015             :                     {
    1016           0 :                         aProperties.push_back( *copyProperty );
    1017           0 :                         continue;
    1018             :                     }
    1019             : 
    1020             :                     // there already was another (previous) handler which supported this property.
    1021             :                     // Don't add it to aProperties, again.
    1022             : 
    1023             :                     // Also, ensure that handlers which previously expressed interest in *changes*
    1024             :                     // of this property are not notified.
    1025             :                     // This is 'cause we have a new handler which is responsible for this property,
    1026             :                     // which means it can give it a completely different meaning than the previous
    1027             :                     // handler for this property is prepared for.
    1028             :                     ::std::pair< PropertyHandlerMultiRepository::iterator, PropertyHandlerMultiRepository::iterator >
    1029           0 :                         aDepHandlers = m_aDependencyHandlers.equal_range( copyProperty->Name );
    1030           0 :                     m_aDependencyHandlers.erase( aDepHandlers.first, aDepHandlers.second );
    1031             :                 }
    1032             : 
    1033             :                 // determine the superseded properties
    1034           0 :                 StlSyntaxSequence< OUString > aSupersededByThisHandler = (*aHandler)->getSupersededProperties();
    1035           0 :                 for (   StlSyntaxSequence< OUString >::const_iterator superseded = aSupersededByThisHandler.begin();
    1036           0 :                         superseded != aSupersededByThisHandler.end();
    1037             :                         ++superseded
    1038             :                     )
    1039             :                 {
    1040             :                     ::std::vector< Property >::iterator existent = ::std::find_if(
    1041             :                         aProperties.begin(),
    1042             :                         aProperties.end(),
    1043             :                         FindPropertyByName( *superseded )
    1044           0 :                     );
    1045           0 :                     if ( existent != aProperties.end() )
    1046             :                         // one of the properties superseded by this handler was supported by a previous
    1047             :                         // one -> erase
    1048           0 :                         aProperties.erase( existent );
    1049             :                 }
    1050             : 
    1051             :                 // be notified of changes which this handler is responsible for
    1052           0 :                 (*aHandler)->addPropertyChangeListener( this );
    1053             : 
    1054             :                 // remember this handler for every of the properties which it is responsible
    1055             :                 // for
    1056           0 :                 for (   StlSyntaxSequence< Property >::const_iterator remember = aThisHandlersProperties.begin();
    1057           0 :                         remember != aThisHandlersProperties.end();
    1058             :                         ++remember
    1059             :                     )
    1060             :                 {
    1061           0 :                     m_aPropertyHandlers[ remember->Name ] = *aHandler;
    1062             :                     // note that this implies that if two handlers support the same property,
    1063             :                     // the latter wins
    1064             :                 }
    1065             : 
    1066             :                 // see if the handler expresses interest in any actuating properties
    1067           0 :                 StlSyntaxSequence< OUString > aInterestingActuations = (*aHandler)->getActuatingProperties();
    1068           0 :                 for (   StlSyntaxSequence< OUString >::const_iterator aLoop = aInterestingActuations.begin();
    1069           0 :                         aLoop != aInterestingActuations.end();
    1070             :                         ++aLoop
    1071             :                     )
    1072             :                 {
    1073             :                     m_aDependencyHandlers.insert( PropertyHandlerMultiRepository::value_type(
    1074           0 :                         *aLoop, *aHandler ) );
    1075             :                 }
    1076             : 
    1077           0 :                 ++aHandler;
    1078           0 :             }
    1079             : 
    1080             :             // create a new composer for UI requests coming from the handlers
    1081          12 :             m_pUIRequestComposer.reset( new ComposedPropertyUIUpdate( getInspectorUI(), this ) );
    1082             : 
    1083             :             // sort the properties by relative position, as indicated by the model
    1084          36 :             for (   ::std::vector< Property >::const_iterator sourceProps = aProperties.begin();
    1085          24 :                     sourceProps != aProperties.end();
    1086             :                     ++sourceProps
    1087             :                 )
    1088             :             {
    1089           0 :                 sal_Int32 nRelativePropertyOrder = sourceProps - aProperties.begin();
    1090           0 :                 if ( m_xModel.is() )
    1091           0 :                     nRelativePropertyOrder = m_xModel->getPropertyOrderIndex( sourceProps->Name );
    1092           0 :                 m_aProperties.insert(OrderedPropertyMap::value_type(nRelativePropertyOrder, *sourceProps));
    1093             :             }
    1094             : 
    1095             :             // be notified when one of our inspectees dies
    1096          24 :             impl_toggleInspecteeListening_nothrow( true );
    1097             :         }
    1098           0 :         catch(const Exception&)
    1099             :         {
    1100             :             OSL_FAIL("OPropertyBrowserController::doInspection : caught an exception !");
    1101             :         }
    1102          12 :     }
    1103             : 
    1104             : 
    1105           0 :     ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::getMinimumSize() throw (::com::sun::star::uno::RuntimeException, std::exception)
    1106             :     {
    1107           0 :         ::com::sun::star::awt::Size aSize;
    1108           0 :         if( m_pView )
    1109           0 :             return m_pView->getMinimumSize();
    1110             :         else
    1111           0 :             return aSize;
    1112             :     }
    1113             : 
    1114             : 
    1115           0 :     ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::getPreferredSize() throw (::com::sun::star::uno::RuntimeException, std::exception)
    1116             :     {
    1117           0 :         return getMinimumSize();
    1118             :     }
    1119             : 
    1120             : 
    1121           0 :     ::com::sun::star::awt::Size SAL_CALL OPropertyBrowserController::calcAdjustedSize( const ::com::sun::star::awt::Size& _rNewSize ) throw (::com::sun::star::uno::RuntimeException, std::exception)
    1122             :     {
    1123           0 :         awt::Size aMinSize = getMinimumSize( );
    1124           0 :         awt::Size aAdjustedSize( _rNewSize );
    1125           0 :         if ( aAdjustedSize.Width < aMinSize.Width )
    1126           0 :             aAdjustedSize.Width = aMinSize.Width;
    1127           0 :         if ( aAdjustedSize.Height < aMinSize.Height )
    1128           0 :             aAdjustedSize.Height = aMinSize.Height;
    1129           0 :         return aAdjustedSize;
    1130             :     }
    1131             : 
    1132             : 
    1133           0 :     void OPropertyBrowserController::describePropertyLine( const Property& _rProperty, OLineDescriptor& _rDescriptor )
    1134             :     {
    1135             :         try
    1136             :         {
    1137           0 :             PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.find( _rProperty.Name );
    1138           0 :             if ( handler == m_aPropertyHandlers.end() )
    1139           0 :                 throw RuntimeException();   // caught below
    1140             : 
    1141           0 :             _rDescriptor.assignFrom( handler->second->describePropertyLine( _rProperty.Name, this ) );
    1142             : 
    1143             : 
    1144             : 
    1145           0 :             _rDescriptor.xPropertyHandler = handler->second;
    1146           0 :             _rDescriptor.sName = _rProperty.Name;
    1147           0 :             _rDescriptor.aValue = _rDescriptor.xPropertyHandler->getPropertyValue( _rProperty.Name );
    1148             : 
    1149           0 :             if ( _rDescriptor.DisplayName.isEmpty() )
    1150             :             {
    1151             :             #ifdef DBG_UTIL
    1152             :                 OString sMessage( "OPropertyBrowserController::describePropertyLine: handler did not provide a display name for '" );
    1153             :                 sMessage += OString( _rProperty.Name.getStr(), _rProperty.Name.getLength(), RTL_TEXTENCODING_ASCII_US );
    1154             :                 sMessage += OString( "'!" );
    1155             :                 DBG_ASSERT( !_rDescriptor.DisplayName.isEmpty(), sMessage.getStr() );
    1156             :             #endif
    1157           0 :                 _rDescriptor.DisplayName = _rProperty.Name;
    1158             :             }
    1159             : 
    1160           0 :             PropertyState   ePropertyState( _rDescriptor.xPropertyHandler->getPropertyState( _rProperty.Name ) );
    1161           0 :             if ( PropertyState_AMBIGUOUS_VALUE == ePropertyState )
    1162             :             {
    1163           0 :                 _rDescriptor.bUnknownValue = true;
    1164           0 :                 _rDescriptor.aValue.clear();
    1165             :             }
    1166             : 
    1167           0 :             _rDescriptor.bReadOnly = impl_isReadOnlyModel_throw();
    1168             :         }
    1169           0 :         catch( const Exception& )
    1170             :         {
    1171             :             OSL_FAIL( "OPropertyBrowserController::describePropertyLine: caught an exception!" );
    1172             :         }
    1173           0 :     }
    1174             : 
    1175             : 
    1176           4 :     void OPropertyBrowserController::impl_buildCategories_throw()
    1177             :     {
    1178             :         OSL_PRECOND( m_aPageIds.empty(), "OPropertyBrowserController::impl_buildCategories_throw: duplicate call!" );
    1179             : 
    1180           4 :         StlSyntaxSequence< PropertyCategoryDescriptor > aCategories;
    1181           4 :         if ( m_xModel.is() )
    1182           4 :             aCategories = m_xModel->describeCategories();
    1183             : 
    1184           8 :         for (   StlSyntaxSequence< PropertyCategoryDescriptor >::const_iterator category = aCategories.begin();
    1185           4 :                 category != aCategories.end();
    1186             :                 ++category
    1187             :             )
    1188             :         {
    1189             :             OSL_ENSURE( m_aPageIds.find( category->ProgrammaticName ) == m_aPageIds.end(),
    1190             :                 "OPropertyBrowserController::impl_buildCategories_throw: duplicate programmatic name!" );
    1191             : 
    1192           0 :             m_aPageIds[ category->ProgrammaticName ] =
    1193           0 :                 getPropertyBox().AppendPage( category->UIName, HelpIdUrl::getHelpId( category->HelpURL ) );
    1194           4 :         }
    1195           4 :     }
    1196             : 
    1197             : 
    1198          16 :     void OPropertyBrowserController::UpdateUI()
    1199             :     {
    1200             :         try
    1201             :         {
    1202          16 :             if ( !haveView() )
    1203             :                 // too early, will return later
    1204          28 :                 return;
    1205             : 
    1206           4 :             getPropertyBox().DisableUpdate();
    1207             : 
    1208           4 :             bool bHaveFocus = getPropertyBox().HasChildPathFocus();
    1209             : 
    1210             :             // create our tab pages
    1211           4 :             impl_buildCategories_throw();
    1212             :             // (and allow for pages to be actually unused)
    1213           4 :             ::std::set< sal_uInt16 > aUsedPages;
    1214             : 
    1215             :             // when building the UI below, remember which properties are actuating,
    1216             :             // to allow for a initial actuatinPropertyChanged call
    1217           8 :             ::std::vector< OUString > aActuatingProperties;
    1218           8 :             ::std::vector< Any > aActuatingPropertyValues;
    1219             : 
    1220             :             // ask the handlers to describe the property UI, and insert the resulting
    1221             :             // entries into our list boxes
    1222           4 :             OrderedPropertyMap::const_iterator property( m_aProperties.begin() );
    1223           4 :             for ( ; property != m_aProperties.end(); ++property )
    1224             :             {
    1225           0 :                 OLineDescriptor aDescriptor;
    1226           0 :                 describePropertyLine( property->second, aDescriptor );
    1227             : 
    1228           0 :                 bool bIsActuatingProperty = impl_isActuatingProperty_nothrow( property->second.Name );
    1229             : 
    1230             :             #if OSL_DEBUG_LEVEL > 0
    1231             :                 if ( aDescriptor.Category.isEmpty() )
    1232             :                 {
    1233             :                     OString sMessage( "OPropertyBrowserController::UpdateUI: empty category provided for property '" );
    1234             :                     sMessage += OString( property->second.Name.getStr(), property->second.Name.getLength(), osl_getThreadTextEncoding() );
    1235             :                     sMessage += "'!";
    1236             :                     OSL_FAIL( sMessage.getStr() );
    1237             :                 }
    1238             :             #endif
    1239             :                 // finally insert this property control
    1240           0 :                 sal_uInt16 nTargetPageId = impl_getPageIdForCategory_nothrow( aDescriptor.Category );
    1241           0 :                 if ( nTargetPageId == (sal_uInt16)-1 )
    1242             :                 {
    1243             :                     // this category does not yet exist. This is allowed, as an inspector model might be lazy, and not provide
    1244             :                     // any category information of its own. In this case, we have a fallback ...
    1245           0 :                     m_aPageIds[ aDescriptor.Category ] =
    1246           0 :                         getPropertyBox().AppendPage( aDescriptor.Category, OString() );
    1247           0 :                     nTargetPageId = impl_getPageIdForCategory_nothrow( aDescriptor.Category );
    1248             :                 }
    1249             : 
    1250           0 :                 getPropertyBox().InsertEntry( aDescriptor, nTargetPageId );
    1251           0 :                 aUsedPages.insert( nTargetPageId );
    1252             : 
    1253             :                 // if it's an actuating property, remember it
    1254           0 :                 if ( bIsActuatingProperty )
    1255             :                 {
    1256           0 :                     aActuatingProperties.push_back( property->second.Name );
    1257           0 :                     aActuatingPropertyValues.push_back( impl_getPropertyValue_throw( property->second.Name ) );
    1258             :                 }
    1259           0 :             }
    1260             : 
    1261             :             // update any dependencies for the actuating properties which we encountered
    1262             :             {
    1263           4 :                 ::std::vector< OUString >::const_iterator aProperty = aActuatingProperties.begin();
    1264           4 :                 ::std::vector< Any >::const_iterator aPropertyValue = aActuatingPropertyValues.begin();
    1265           4 :                 for ( ; aProperty != aActuatingProperties.end(); ++aProperty, ++aPropertyValue )
    1266           0 :                     impl_broadcastPropertyChange_nothrow( *aProperty, *aPropertyValue, *aPropertyValue, true );
    1267             :             }
    1268             : 
    1269             :             // remove any unused pages (which we did not encounter properties for)
    1270           8 :             HashString2Int16 aSurvivingPageIds;
    1271          12 :             for (   HashString2Int16::iterator pageId = m_aPageIds.begin();
    1272           8 :                     pageId != m_aPageIds.end();
    1273             :                     ++pageId
    1274             :                 )
    1275             :             {
    1276           0 :                 if ( aUsedPages.find( pageId->second ) == aUsedPages.end() )
    1277           0 :                     getPropertyBox().RemovePage( pageId->second );
    1278             :                 else
    1279           0 :                     aSurvivingPageIds.insert( *pageId );
    1280             :             }
    1281           4 :             m_aPageIds.swap( aSurvivingPageIds );
    1282             : 
    1283             : 
    1284           4 :             getPropertyBox().Show();
    1285           4 :             getPropertyBox().EnableUpdate();
    1286           4 :             if ( bHaveFocus )
    1287           0 :                 getPropertyBox().GrabFocus();
    1288             : 
    1289             :             // activate the first page
    1290           4 :             if ( !m_aPageIds.empty() )
    1291             :             {
    1292           0 :                 Sequence< PropertyCategoryDescriptor > aCategories( m_xModel->describeCategories() );
    1293           0 :                 if ( aCategories.getLength() )
    1294           0 :                     m_pView->activatePage( m_aPageIds[ aCategories[0].ProgrammaticName ] );
    1295             :                 else
    1296             :                     // allowed: if we default-created the pages ...
    1297           0 :                     m_pView->activatePage( m_aPageIds.begin()->second );
    1298             :             }
    1299             : 
    1300             :             // activate the previously active page (if possible)
    1301           4 :             if ( !m_sLastValidPageSelection.isEmpty() )
    1302           0 :                 m_sPageSelection = m_sLastValidPageSelection;
    1303           8 :             selectPageFromViewData();
    1304             :         }
    1305           0 :         catch( const Exception& )
    1306             :         {
    1307             :             DBG_UNHANDLED_EXCEPTION();
    1308             :         }
    1309             :     }
    1310             : 
    1311             : 
    1312           0 :     void OPropertyBrowserController::Clicked( const OUString& _rName, bool _bPrimary )
    1313             :     {
    1314             :         try
    1315             :         {
    1316             :             // since the browse buttons do not get the focus when clicked with the mouse,
    1317             :             // we need to commit the changes in the current property field
    1318           0 :             getPropertyBox().CommitModified();
    1319             : 
    1320           0 :             PropertyHandlerRepository::const_iterator handler = m_aPropertyHandlers.find( _rName );
    1321             :             DBG_ASSERT( handler != m_aPropertyHandlers.end(), "OPropertyBrowserController::Clicked: a property without handler? This will crash!" );
    1322             : 
    1323           0 :             ComposedUIAutoFireGuard aAutoFireGuard( *m_pUIRequestComposer );
    1324             : 
    1325           0 :             Any aData;
    1326           0 :             m_xInteractiveHandler = handler->second;
    1327             :             InteractiveSelectionResult eResult =
    1328           0 :                 handler->second->onInteractivePropertySelection( _rName, _bPrimary, aData,
    1329           0 :                     m_pUIRequestComposer->getUIForPropertyHandler( handler->second ) );
    1330             : 
    1331           0 :             switch ( eResult )
    1332             :             {
    1333             :             case InteractiveSelectionResult_Cancelled:
    1334             :             case InteractiveSelectionResult_Success:
    1335             :                 // okay, nothing to do
    1336           0 :                 break;
    1337             :             case InteractiveSelectionResult_ObtainedValue:
    1338           0 :                 handler->second->setPropertyValue( _rName, aData );
    1339           0 :                 break;
    1340             :             case InteractiveSelectionResult_Pending:
    1341             :                 // also okay, we expect that the handler has disabled the UI as necessary
    1342           0 :                 break;
    1343             :             default:
    1344             :                 OSL_FAIL( "OPropertyBrowserController::Clicked: unknown result value!" );
    1345           0 :                 break;
    1346           0 :             }
    1347             :         }
    1348           0 :         catch (const Exception&)
    1349             :         {
    1350             :             DBG_UNHANDLED_EXCEPTION();
    1351             :         }
    1352           0 :         m_xInteractiveHandler = NULL;
    1353           0 :     }
    1354             : 
    1355             : 
    1356           0 :     bool SAL_CALL OPropertyBrowserController::hasPropertyByName( const OUString& _rName ) throw (RuntimeException)
    1357             :     {
    1358           0 :         for (   OrderedPropertyMap::const_iterator search = m_aProperties.begin();
    1359           0 :                 search != m_aProperties.end();
    1360             :                 ++search
    1361             :             )
    1362           0 :             if ( search->second.Name == _rName )
    1363           0 :                 return true;
    1364           0 :         return false;
    1365             :     }
    1366             : 
    1367             : 
    1368           0 :     void OPropertyBrowserController::Commit( const OUString& rName, const Any& _rValue )
    1369             :     {
    1370             :         try
    1371             :         {
    1372           0 :             OUString sPlcHolder = PcrRes(RID_EMBED_IMAGE_PLACEHOLDER).toString();
    1373           0 :             bool bIsPlaceHolderValue = false;
    1374             : 
    1375           0 :             if ( rName.equals( PROPERTY_IMAGE_URL ) )
    1376             :             {
    1377             :                 // if the prop value is the PlaceHolder
    1378             :                 // can ignore it
    1379           0 :                 OUString sVal;
    1380           0 :                 _rValue >>= sVal;
    1381           0 :                 if ( sVal.equals( sPlcHolder ) )
    1382           0 :                     bIsPlaceHolderValue = true;
    1383             :             }
    1384           0 :             m_sCommittingProperty = rName;
    1385             : 
    1386           0 :             bool bIsActuatingProperty = impl_isActuatingProperty_nothrow( rName );
    1387             : 
    1388           0 :             Any aOldValue;
    1389           0 :             if ( bIsActuatingProperty )
    1390           0 :                 aOldValue = impl_getPropertyValue_throw( rName );
    1391             : 
    1392             :             // do we have a dedicated handler for this property, which we can delegate some tasks to?
    1393           0 :             PropertyHandlerRef handler = impl_getHandlerForProperty_throw( rName );
    1394             : 
    1395             : 
    1396             :             // set the value ( only if it's not a placeholder )
    1397           0 :             if ( !bIsPlaceHolderValue )
    1398           0 :                 handler->setPropertyValue( rName, _rValue );
    1399             : 
    1400             : 
    1401             :             // re-retrieve the value
    1402           0 :             Any aNormalizedValue = handler->getPropertyValue( rName );
    1403             : 
    1404             :             // care for any inter-property dependencies
    1405           0 :             if ( bIsActuatingProperty )
    1406           0 :                 impl_broadcastPropertyChange_nothrow( rName, aNormalizedValue, aOldValue, false );
    1407             : 
    1408             :             // and display it again. This ensures proper formatting
    1409           0 :             getPropertyBox().SetPropertyValue( rName, aNormalizedValue, false );
    1410             :         }
    1411           0 :         catch(const PropertyVetoException& eVetoException)
    1412             :         {
    1413           0 :             InfoBox(m_pView, eVetoException.Message).Execute();
    1414           0 :             PropertyHandlerRef handler = impl_getHandlerForProperty_throw( rName );
    1415           0 :             Any aNormalizedValue = handler->getPropertyValue( rName );
    1416           0 :             getPropertyBox().SetPropertyValue( rName, aNormalizedValue, false );
    1417             :         }
    1418           0 :         catch(const Exception&)
    1419             :         {
    1420             :             OSL_FAIL("OPropertyBrowserController::Commit : caught an exception !");
    1421             :         }
    1422             : 
    1423           0 :         m_sCommittingProperty = "";
    1424           0 :     }
    1425             : 
    1426             : 
    1427             :     namespace
    1428             :     {
    1429             :     }
    1430             : 
    1431             : 
    1432           0 :     void OPropertyBrowserController::focusGained( const Reference< XPropertyControl >& _Control )
    1433             :     {
    1434           0 :         m_aControlObservers.notifyEach( &XPropertyControlObserver::focusGained, _Control );
    1435           0 :     }
    1436             : 
    1437             : 
    1438           0 :     void OPropertyBrowserController::valueChanged( const Reference< XPropertyControl >& _Control )
    1439             :     {
    1440           0 :         m_aControlObservers.notifyEach( &XPropertyControlObserver::valueChanged, _Control );
    1441           0 :     }
    1442             : 
    1443             : 
    1444             :     namespace
    1445             :     {
    1446           8 :         Reference< XPropertyHandler > lcl_createHandler( const Reference<XComponentContext>& _rContext, const Any& _rFactoryDescriptor )
    1447             :         {
    1448           8 :             Reference< XPropertyHandler > xHandler;
    1449             : 
    1450          16 :             OUString sServiceName;
    1451          16 :             Reference< XSingleServiceFactory > xServiceFac;
    1452          16 :             Reference< XSingleComponentFactory > xComponentFac;
    1453             : 
    1454           8 :             if ( _rFactoryDescriptor >>= sServiceName )
    1455           8 :                 xHandler.set( _rContext->getServiceManager()->createInstanceWithContext( sServiceName, _rContext ), UNO_QUERY );
    1456           0 :             else if ( _rFactoryDescriptor >>= xServiceFac )
    1457           0 :                 xHandler.set(xServiceFac->createInstance(), css::uno::UNO_QUERY);
    1458           0 :             else if ( _rFactoryDescriptor >>= xComponentFac )
    1459           0 :                 xHandler.set(xComponentFac->createInstanceWithContext( _rContext ), css::uno::UNO_QUERY);
    1460             :             OSL_ENSURE(xHandler.is(),"lcl_createHandler: Can not create handler");
    1461          16 :             return xHandler;
    1462             :         }
    1463             :     }
    1464             : 
    1465             : 
    1466          12 :     void OPropertyBrowserController::getPropertyHandlers( const InterfaceArray& _rObjects, PropertyHandlerArray& _rHandlers )
    1467             :     {
    1468          12 :         _rHandlers.resize( 0 );
    1469          12 :         if ( _rObjects.empty() )
    1470          12 :             return;
    1471             : 
    1472             :         // create a component context for the handlers, containing some information about where
    1473             :         // they live
    1474          12 :         Reference< XComponentContext > xHandlerContext( m_xContext );
    1475             : 
    1476             :         // if our own creator did not pass a dialog parent window, use our own view for this
    1477          24 :         Reference< XWindow > xParentWindow;
    1478          24 :         Any any = m_xContext->getValueByName( "DialogParentWindow" );
    1479          12 :         any >>= xParentWindow;
    1480          12 :         if ( !xParentWindow.is() )
    1481             :         {
    1482             :             ::cppu::ContextEntry_Init aHandlerContextInfo[] =
    1483             :             {
    1484             :                 ::cppu::ContextEntry_Init( OUString(  "DialogParentWindow"  ), makeAny( VCLUnoHelper::GetInterface( m_pView ) ) )
    1485          24 :             };
    1486          24 :             xHandlerContext = ::cppu::createComponentContext(
    1487             :                 aHandlerContextInfo, SAL_N_ELEMENTS( aHandlerContextInfo ),
    1488          36 :                 m_xContext );
    1489             :         }
    1490             : 
    1491          24 :         Sequence< Any > aHandlerFactories;
    1492          12 :         if ( m_xModel.is() )
    1493          12 :             aHandlerFactories = m_xModel->getHandlerFactories();
    1494             : 
    1495          12 :         const Any* pHandlerFactory = aHandlerFactories.getConstArray();
    1496          12 :         const Any* pHandlerFactoryEnd = aHandlerFactories.getConstArray() + aHandlerFactories.getLength();
    1497             : 
    1498          32 :         while ( pHandlerFactory != pHandlerFactoryEnd )
    1499             :         {
    1500           8 :             if ( _rObjects.size() == 1 )
    1501             :             {   // we're inspecting only one object -> one handler
    1502           8 :                 Reference< XPropertyHandler > xHandler( lcl_createHandler( m_xContext, *pHandlerFactory ) );
    1503           8 :                 if ( xHandler.is() )
    1504             :                 {
    1505           8 :                     xHandler->inspect( _rObjects[0] );
    1506           8 :                     _rHandlers.push_back( xHandler );
    1507           8 :                 }
    1508             :             }
    1509             :             else
    1510             :             {
    1511             :                 // create a single handler for every single object
    1512           0 :                 ::std::vector< Reference< XPropertyHandler > > aSingleHandlers( _rObjects.size() );
    1513           0 :                 ::std::vector< Reference< XPropertyHandler > >::iterator pHandler = aSingleHandlers.begin();
    1514             : 
    1515           0 :                 InterfaceArray::const_iterator pObject = _rObjects.begin();
    1516           0 :                 InterfaceArray::const_iterator pObjectEnd = _rObjects.end();
    1517             : 
    1518           0 :                 for ( ; pObject != pObjectEnd; ++pObject )
    1519             :                 {
    1520           0 :                     *pHandler = lcl_createHandler( m_xContext, *pHandlerFactory );
    1521           0 :                     if ( pHandler->is() )
    1522             :                     {
    1523           0 :                         (*pHandler)->inspect( *pObject );
    1524           0 :                         ++pHandler;
    1525             :                     }
    1526             :                 }
    1527           0 :                 aSingleHandlers.resize( pHandler - aSingleHandlers.begin() );
    1528             : 
    1529             :                 // then create a handler which composes information out of those single handlers
    1530           0 :                 if ( !aSingleHandlers.empty() )
    1531           0 :                     _rHandlers.push_back( new PropertyComposer( aSingleHandlers ) );
    1532             :             }
    1533             : 
    1534           8 :             ++pHandlerFactory;
    1535          12 :         }
    1536             : 
    1537             :         // note that the handlers will not be used by our caller, if they indicate that there are no
    1538             :         // properties they feel responsible for
    1539             :     }
    1540             : 
    1541             : 
    1542           0 :     bool OPropertyBrowserController::impl_findObjectProperty_nothrow( const OUString& _rName, OrderedPropertyMap::const_iterator* _pProperty )
    1543             :     {
    1544           0 :         OrderedPropertyMap::const_iterator search = m_aProperties.begin();
    1545           0 :         for ( ; search != m_aProperties.end(); ++search )
    1546           0 :             if ( search->second.Name == _rName )
    1547           0 :                 break;
    1548           0 :         if ( _pProperty )
    1549           0 :             *_pProperty = search;
    1550           0 :         return ( search != m_aProperties.end() );
    1551             :     }
    1552             : 
    1553             : 
    1554           0 :     void OPropertyBrowserController::rebuildPropertyUI( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
    1555             :     {
    1556           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1557           0 :         if ( !haveView() )
    1558           0 :             throw RuntimeException();
    1559             : 
    1560           0 :         OrderedPropertyMap::const_iterator propertyPos;
    1561           0 :         if ( !impl_findObjectProperty_nothrow( _rPropertyName, &propertyPos ) )
    1562           0 :             return;
    1563             : 
    1564           0 :         OLineDescriptor aDescriptor;
    1565             :         try
    1566             :         {
    1567           0 :             describePropertyLine( propertyPos->second, aDescriptor );
    1568             :         }
    1569           0 :         catch( const Exception& )
    1570             :         {
    1571             :             OSL_FAIL( "OPropertyBrowserController::rebuildPropertyUI: caught an exception!" );
    1572             :         }
    1573             : 
    1574           0 :         getPropertyBox().ChangeEntry( aDescriptor );
    1575             :    }
    1576             : 
    1577             : 
    1578           0 :     void OPropertyBrowserController::enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) throw (RuntimeException, std::exception)
    1579             :     {
    1580           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1581           0 :         if ( !haveView() )
    1582           0 :             throw RuntimeException();
    1583             : 
    1584           0 :         if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
    1585           0 :             return;
    1586             : 
    1587           0 :         getPropertyBox().EnablePropertyLine( _rPropertyName, _bEnable );
    1588             :     }
    1589             : 
    1590             : 
    1591           0 :     void OPropertyBrowserController::enablePropertyUIElements( const OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable ) throw (RuntimeException, std::exception)
    1592             :     {
    1593           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1594           0 :         if ( !haveView() )
    1595           0 :             throw RuntimeException();
    1596             : 
    1597           0 :         if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
    1598           0 :             return;
    1599             : 
    1600           0 :         getPropertyBox().EnablePropertyControls( _rPropertyName, _nElements, _bEnable );
    1601             :     }
    1602             : 
    1603             : 
    1604           0 :     void OPropertyBrowserController::showPropertyUI( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
    1605             :     {
    1606           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1607           0 :         if ( !haveView() )
    1608           0 :             throw RuntimeException();
    1609             : 
    1610             :         // look up the property in our object properties
    1611           0 :         OrderedPropertyMap::const_iterator propertyPos;
    1612           0 :         if ( !impl_findObjectProperty_nothrow( _rPropertyName, &propertyPos ) )
    1613           0 :             return;
    1614             : 
    1615           0 :         if ( getPropertyBox().GetPropertyPos( _rPropertyName ) != EDITOR_LIST_ENTRY_NOTFOUND )
    1616             :         {
    1617           0 :             rebuildPropertyUI( _rPropertyName );
    1618           0 :             return;
    1619             :         }
    1620             : 
    1621           0 :         OLineDescriptor aDescriptor;
    1622           0 :         describePropertyLine( propertyPos->second, aDescriptor );
    1623             : 
    1624             :         // look for the position to insert the property
    1625             : 
    1626             :         // side note: The methods GetPropertyPos and InsertEntry of the OPropertyEditor work
    1627             :         // only on the current page. This implies that it's impossible to use this method here
    1628             :         // to show property lines which are *not* on the current page.
    1629             :         // This is sufficient for now, but should be changed in the future.
    1630             : 
    1631             :         // by definition, the properties in m_aProperties are in the order in which they appear in the UI
    1632             :         // So all we need is a predecessor of pProperty in m_aProperties
    1633           0 :         sal_uInt16 nUIPos = EDITOR_LIST_ENTRY_NOTFOUND;
    1634           0 :         do
    1635             :         {
    1636           0 :             if ( propertyPos != m_aProperties.begin() )
    1637           0 :                 --propertyPos;
    1638           0 :             nUIPos = getPropertyBox().GetPropertyPos( propertyPos->second.Name );
    1639             :         }
    1640           0 :         while ( ( nUIPos == EDITOR_LIST_ENTRY_NOTFOUND ) && ( propertyPos != m_aProperties.begin() ) );
    1641             : 
    1642           0 :         if ( nUIPos == EDITOR_LIST_ENTRY_NOTFOUND )
    1643             :             // insert at the very top
    1644           0 :             nUIPos = 0;
    1645             :         else
    1646             :             // insert right after the predecessor we found
    1647           0 :             ++nUIPos;
    1648             : 
    1649           0 :         getPropertyBox().InsertEntry(
    1650           0 :             aDescriptor, impl_getPageIdForCategory_nothrow( aDescriptor.Category ), nUIPos );
    1651             :     }
    1652             : 
    1653             : 
    1654           0 :     void OPropertyBrowserController::hidePropertyUI( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
    1655             :     {
    1656           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1657           0 :         if ( !haveView() )
    1658           0 :             throw RuntimeException();
    1659             : 
    1660           0 :         if ( !impl_findObjectProperty_nothrow( _rPropertyName ) )
    1661           0 :             return;
    1662             : 
    1663           0 :         getPropertyBox().RemoveEntry( _rPropertyName );
    1664             :     }
    1665             : 
    1666             : 
    1667           0 :     void OPropertyBrowserController::showCategory( const OUString& _rCategory, sal_Bool _bShow ) throw (RuntimeException, std::exception)
    1668             :     {
    1669           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1670           0 :         if ( !haveView() )
    1671           0 :             throw RuntimeException();
    1672             : 
    1673           0 :         sal_uInt16 nPageId = impl_getPageIdForCategory_nothrow( _rCategory );
    1674             :         OSL_ENSURE( nPageId != (sal_uInt16)-1, "OPropertyBrowserController::showCategory: invalid category!" );
    1675             : 
    1676           0 :         getPropertyBox().ShowPropertyPage( nPageId, _bShow );
    1677           0 :     }
    1678             : 
    1679             : 
    1680           0 :     Reference< XPropertyControl > SAL_CALL OPropertyBrowserController::getPropertyControl( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
    1681             :     {
    1682           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1683           0 :         if ( !haveView() )
    1684           0 :             throw RuntimeException();
    1685             : 
    1686           0 :         Reference< XPropertyControl > xControl( getPropertyBox().GetPropertyControl( _rPropertyName ) );
    1687           0 :         return xControl;
    1688             :     }
    1689             : 
    1690             : 
    1691           0 :     void SAL_CALL OPropertyBrowserController::registerControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException, std::exception)
    1692             :     {
    1693           0 :         m_aControlObservers.addInterface( _Observer );
    1694           0 :     }
    1695             : 
    1696             : 
    1697           0 :     void SAL_CALL OPropertyBrowserController::revokeControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException, std::exception)
    1698             :     {
    1699           0 :         m_aControlObservers.removeInterface( _Observer );
    1700           0 :     }
    1701             : 
    1702             : 
    1703           0 :     void SAL_CALL OPropertyBrowserController::setHelpSectionText( const OUString& _rHelpText ) throw (NoSupportException, RuntimeException, std::exception)
    1704             :     {
    1705           0 :         SolarMutexGuard aSolarGuard;
    1706           0 :         ::osl::MutexGuard aGuard( m_aMutex );
    1707             : 
    1708           0 :         if ( !haveView() )
    1709           0 :             throw DisposedException();
    1710             : 
    1711           0 :         if ( !getPropertyBox().HasHelpSection() )
    1712           0 :             throw NoSupportException();
    1713             : 
    1714           0 :         getPropertyBox().SetHelpText( _rHelpText );
    1715           0 :     }
    1716             : 
    1717             : 
    1718           0 :     void OPropertyBrowserController::impl_broadcastPropertyChange_nothrow( const OUString& _rPropertyName, const Any& _rNewValue, const Any& _rOldValue, bool _bFirstTimeInit ) const
    1719             :     {
    1720             :         // are there one or more handlers which are interested in the actuation?
    1721             :         ::std::pair< PropertyHandlerMultiRepository::const_iterator, PropertyHandlerMultiRepository::const_iterator > aInterestedHandlers =
    1722           0 :             m_aDependencyHandlers.equal_range( _rPropertyName );
    1723           0 :         if ( aInterestedHandlers.first == aInterestedHandlers.second )
    1724             :             // none of our handlers is interested in this
    1725           0 :             return;
    1726             : 
    1727           0 :         ComposedUIAutoFireGuard aAutoFireGuard( *m_pUIRequestComposer );
    1728             :         try
    1729             :         {
    1730             :             // collect the responses from all interested handlers
    1731           0 :             PropertyHandlerMultiRepository::const_iterator handler = aInterestedHandlers.first;
    1732           0 :             while ( handler != aInterestedHandlers.second )
    1733             :             {
    1734           0 :                 handler->second->actuatingPropertyChanged( _rPropertyName, _rNewValue, _rOldValue,
    1735           0 :                     m_pUIRequestComposer->getUIForPropertyHandler( handler->second ),
    1736           0 :                     _bFirstTimeInit );
    1737           0 :                 ++handler;
    1738             :             }
    1739             :         }
    1740           0 :         catch( const Exception& )
    1741             :         {
    1742             :             DBG_UNHANDLED_EXCEPTION();
    1743           0 :         }
    1744             :     }
    1745             : 
    1746             : 
    1747          12 : } // namespace pcr
    1748             : 
    1749             : 
    1750             : 
    1751             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10