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

Generated by: LCOV version 1.10