LCOV - code coverage report
Current view: top level - libreoffice/svx/source/form - fmPropBrw.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 267 0.4 %
Date: 2012-12-27 Functions: 1 21 4.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             : 
      21             : #include <sal/macros.h>
      22             : 
      23             : #include "fmhelp.hrc"
      24             : #include "fmprop.hrc"
      25             : #include "fmPropBrw.hxx"
      26             : #include "svx/fmresids.hrc"
      27             : #include "fmservs.hxx"
      28             : #include "fmshimp.hxx"
      29             : #include "fmpgeimp.hxx"
      30             : 
      31             : #include "svx/dialmgr.hxx"
      32             : #include "svx/fmpage.hxx"
      33             : #include "svx/fmshell.hxx"
      34             : #include "svx/sdrpagewindow.hxx"
      35             : #include "svx/svdpagv.hxx"
      36             : #include "svx/svxids.hrc"
      37             : 
      38             : #include <com/sun/star/beans/PropertyValue.hpp>
      39             : #include <com/sun/star/awt/PosSize.hpp>
      40             : #include <com/sun/star/form/XForm.hpp>
      41             : #include <com/sun/star/form/FormComponentType.hpp>
      42             : #include <com/sun/star/awt/XLayoutConstrains.hpp>
      43             : #include <com/sun/star/awt/XControlContainer.hpp>
      44             : #include <com/sun/star/container/XChild.hpp>
      45             : #include <com/sun/star/inspection/ObjectInspector.hpp>
      46             : #include <com/sun/star/inspection/ObjectInspectorModel.hpp>
      47             : #include <com/sun/star/form/inspection/DefaultFormComponentInspectorModel.hpp>
      48             : #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
      49             : #include <com/sun/star/inspection/DefaultHelpProvider.hpp>
      50             : 
      51             : #include <comphelper/processfactory.hxx>
      52             : #include <comphelper/property.hxx>
      53             : #include <cppuhelper/component_context.hxx>
      54             : #include <sfx2/bindings.hxx>
      55             : #include <sfx2/childwin.hxx>
      56             : #include <sfx2/dispatch.hxx>
      57             : #include <sfx2/objitem.hxx>
      58             : #include <sfx2/objsh.hxx>
      59             : #include <sfx2/viewfrm.hxx>
      60             : #include <toolkit/unohlp.hxx>
      61             : #include <tools/debug.hxx>
      62             : #include <tools/diagnose_ex.h>
      63             : #include <tools/shl.hxx>
      64             : #include <unotools/confignode.hxx>
      65             : #include <vcl/stdtext.hxx>
      66             : 
      67             : #include <algorithm>
      68             : 
      69             : using namespace ::com::sun::star;
      70             : using namespace ::com::sun::star::uno;
      71             : using namespace ::com::sun::star::util;
      72             : using namespace ::com::sun::star::inspection;
      73             : using namespace ::com::sun::star::form::inspection;
      74             : using ::com::sun::star::awt::XWindow;
      75             : 
      76             : /*************************************************************************/
      77             : //========================================================================
      78             : //= FmPropBrwMgr
      79             : //========================================================================
      80             : //-----------------------------------------------------------------------
      81          18 : SFX_IMPL_FLOATINGWINDOW(FmPropBrwMgr, SID_FM_SHOW_PROPERTIES)
      82             : 
      83             : //-----------------------------------------------------------------------
      84           0 : FmPropBrwMgr::FmPropBrwMgr( Window* _pParent, sal_uInt16 _nId,
      85             :                             SfxBindings* _pBindings, SfxChildWinInfo* _pInfo)
      86           0 :               :SfxChildWindow(_pParent, _nId)
      87             : {
      88           0 :     pWindow = new FmPropBrw( ::comphelper::getProcessServiceFactory(), _pBindings, this, _pParent, _pInfo );
      89           0 :     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
      90           0 :     ((SfxFloatingWindow*)pWindow)->Initialize( _pInfo );
      91           0 : }
      92             : 
      93             : //========================================================================
      94             : //========================================================================
      95             : const long STD_WIN_SIZE_X = 300;
      96             : const long STD_WIN_SIZE_Y = 350;
      97             : 
      98             : const long STD_MIN_SIZE_X = 250;
      99             : const long STD_MIN_SIZE_Y = 250;
     100             : 
     101             : using namespace ::com::sun::star::uno;
     102             : using namespace ::com::sun::star::lang;
     103             : using namespace ::com::sun::star::form;
     104             : using namespace ::com::sun::star::frame;
     105             : using namespace ::com::sun::star::beans;
     106             : using namespace ::com::sun::star::container;
     107             : using namespace ::svxform;
     108             : 
     109           0 : ::rtl::OUString GetUIHeadlineName(sal_Int16 nClassId, const Any& aUnoObj)
     110             : {
     111           0 :     sal_uInt16 nClassNameResourceId = 0;
     112             : 
     113           0 :     switch ( nClassId )
     114             :     {
     115             :         case FormComponentType::TEXTFIELD:
     116             :         {
     117           0 :             Reference< XInterface >  xIFace;
     118           0 :             aUnoObj >>= xIFace;
     119           0 :             nClassNameResourceId = RID_STR_PROPTITLE_EDIT;
     120           0 :             if (xIFace.is())
     121             :             {   // we have a chance to check if it's a formatted field model
     122           0 :                 Reference< XServiceInfo >  xInfo(xIFace, UNO_QUERY);
     123           0 :                 if (xInfo.is() && (xInfo->supportsService(FM_SUN_COMPONENT_FORMATTEDFIELD)))
     124           0 :                     nClassNameResourceId = RID_STR_PROPTITLE_FORMATTED;
     125           0 :                 else if (!xInfo.is())
     126             :                 {
     127             :                     // couldn't distinguish between formatted and edit with the service name, so try with the properties
     128           0 :                     Reference< XPropertySet >  xProps(xIFace, UNO_QUERY);
     129           0 :                     if (xProps.is())
     130             :                     {
     131           0 :                         Reference< XPropertySetInfo >  xPropsInfo = xProps->getPropertySetInfo();
     132           0 :                         if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(FM_PROP_FORMATSSUPPLIER))
     133           0 :                             nClassNameResourceId = RID_STR_PROPTITLE_FORMATTED;
     134           0 :                     }
     135           0 :                 }
     136           0 :             }
     137             :         }
     138           0 :         break;
     139             : 
     140             :         case FormComponentType::COMMANDBUTTON:
     141           0 :             nClassNameResourceId = RID_STR_PROPTITLE_PUSHBUTTON; break;
     142             :         case FormComponentType::RADIOBUTTON:
     143           0 :             nClassNameResourceId = RID_STR_PROPTITLE_RADIOBUTTON; break;
     144             :         case FormComponentType::CHECKBOX:
     145           0 :             nClassNameResourceId = RID_STR_PROPTITLE_CHECKBOX; break;
     146             :         case FormComponentType::LISTBOX:
     147           0 :             nClassNameResourceId = RID_STR_PROPTITLE_LISTBOX; break;
     148             :         case FormComponentType::COMBOBOX:
     149           0 :             nClassNameResourceId = RID_STR_PROPTITLE_COMBOBOX; break;
     150             :         case FormComponentType::GROUPBOX:
     151           0 :             nClassNameResourceId = RID_STR_PROPTITLE_GROUPBOX; break;
     152             :         case FormComponentType::IMAGEBUTTON:
     153           0 :             nClassNameResourceId = RID_STR_PROPTITLE_IMAGEBUTTON; break;
     154             :         case FormComponentType::FIXEDTEXT:
     155           0 :             nClassNameResourceId = RID_STR_PROPTITLE_FIXEDTEXT; break;
     156             :         case FormComponentType::GRIDCONTROL:
     157           0 :             nClassNameResourceId = RID_STR_PROPTITLE_DBGRID; break;
     158             :         case FormComponentType::FILECONTROL:
     159           0 :             nClassNameResourceId = RID_STR_PROPTITLE_FILECONTROL; break;
     160             :         case FormComponentType::DATEFIELD:
     161           0 :             nClassNameResourceId = RID_STR_PROPTITLE_DATEFIELD; break;
     162             :         case FormComponentType::TIMEFIELD:
     163           0 :             nClassNameResourceId = RID_STR_PROPTITLE_TIMEFIELD; break;
     164             :         case FormComponentType::NUMERICFIELD:
     165           0 :             nClassNameResourceId = RID_STR_PROPTITLE_NUMERICFIELD; break;
     166             :         case FormComponentType::CURRENCYFIELD:
     167           0 :             nClassNameResourceId = RID_STR_PROPTITLE_CURRENCYFIELD; break;
     168             :         case FormComponentType::PATTERNFIELD:
     169           0 :             nClassNameResourceId = RID_STR_PROPTITLE_PATTERNFIELD; break;
     170             :         case FormComponentType::IMAGECONTROL:
     171           0 :             nClassNameResourceId = RID_STR_PROPTITLE_IMAGECONTROL; break;
     172             :         case FormComponentType::HIDDENCONTROL:
     173           0 :             nClassNameResourceId = RID_STR_PROPTITLE_HIDDEN; break;
     174             :         case FormComponentType::SCROLLBAR:
     175           0 :             nClassNameResourceId = RID_STR_PROPTITLE_SCROLLBAR; break;
     176             :         case FormComponentType::SPINBUTTON:
     177           0 :             nClassNameResourceId = RID_STR_PROPTITLE_SPINBUTTON; break;
     178             :         case FormComponentType::NAVIGATIONBAR:
     179           0 :             nClassNameResourceId = RID_STR_PROPTITLE_NAVBAR; break;
     180             :         case FormComponentType::CONTROL:
     181             :         default:
     182           0 :             nClassNameResourceId = RID_STR_CONTROL; break;
     183             :     }
     184             : 
     185           0 :     if ( !nClassNameResourceId )
     186           0 :         return ::rtl::OUString();
     187             : 
     188           0 :     return ::rtl::OUString( String( SVX_RES( nClassNameResourceId ) ) );
     189             : }
     190             : 
     191             : //========================================================================
     192             : // class FmPropBrw
     193             : //========================================================================
     194             : DBG_NAME(FmPropBrw);
     195             : //------------------------------------------------------------------------
     196           0 : FmPropBrw::FmPropBrw( const Reference< XMultiServiceFactory >& _xORB, SfxBindings* _pBindings,
     197             :             SfxChildWindow* _pMgr, Window* _pParent, const SfxChildWinInfo* _pInfo )
     198             :     :SfxFloatingWindow(_pBindings, _pMgr, _pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE|WB_3DLOOK|WB_ROLLABLE) )
     199             :     ,SfxControllerItem(SID_FM_PROPERTY_CONTROL, *_pBindings)
     200             :     ,m_bInitialStateChange(sal_True)
     201             :     ,m_bInStateChange( false )
     202           0 :     ,m_xORB(_xORB)
     203             : {
     204             :     DBG_CTOR(FmPropBrw,NULL);
     205             : 
     206           0 :     ::Size aPropWinSize(STD_WIN_SIZE_X,STD_WIN_SIZE_Y);
     207           0 :     SetMinOutputSizePixel(::Size(STD_MIN_SIZE_X,STD_MIN_SIZE_Y));
     208           0 :     SetOutputSizePixel(aPropWinSize);
     209           0 :     SetUniqueId(UID_FORMPROPBROWSER_FRAME);
     210             : 
     211             :     try
     212             :     {
     213             :         // create a frame wrapper for myself
     214           0 :         m_xMeAsFrame = Reference< XFrame >(m_xORB->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Frame")) ), UNO_QUERY);
     215           0 :         if (m_xMeAsFrame.is())
     216             :         {
     217             :             // create an intermediate window, which is to be the container window of the frame
     218             :             // Do *not* use |this| as container window for the frame, this would result in undefined
     219             :             // responsiblity for this window (as soon as we initialize a frame with a window, the frame
     220             :             // is responsible for it's life time, but |this| is controlled by the belonging SfxChildWindow)
     221             :             // #i34249#
     222           0 :             Window* pContainerWindow = new Window( this );
     223           0 :             pContainerWindow->Show();
     224           0 :             m_xFrameContainerWindow = VCLUnoHelper::GetInterface ( pContainerWindow );
     225             : 
     226           0 :             m_xMeAsFrame->initialize( m_xFrameContainerWindow );
     227           0 :             m_xMeAsFrame->setName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("form property browser")) );
     228           0 :             if ( _pBindings->GetDispatcher() )
     229             :             {
     230             :                 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFramesSupplier >
     231           0 :                         xSupp ( _pBindings->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
     232             : //                if ( xSupp.is() )
     233             : //                    xSupp->getFrames()->append( m_xMeAsFrame );
     234             :                 // Don't append frame to frame hierachy to prevent UI_DEACTIVATE messages
     235             :                 // #i31834#
     236             :             }
     237             :         }
     238             :     }
     239           0 :     catch (Exception&)
     240             :     {
     241             :         OSL_FAIL("FmPropBrw::FmPropBrw: could not create/initialize my frame!");
     242           0 :         m_xMeAsFrame.clear();
     243             :     }
     244             : 
     245           0 :     if (m_xMeAsFrame.is())
     246           0 :         _pMgr->SetFrame( m_xMeAsFrame );
     247             : 
     248             : 
     249           0 :     if ( m_xBrowserComponentWindow.is() )
     250           0 :         m_xBrowserComponentWindow->setVisible( sal_True );
     251             : 
     252           0 :     if ( _pInfo )
     253           0 :         m_sLastActivePage = _pInfo->aExtraString;
     254           0 : }
     255             : 
     256             : //------------------------------------------------------------------------
     257           0 : void FmPropBrw::Resize()
     258             : {
     259           0 :     SfxFloatingWindow::Resize();
     260             : 
     261           0 :     if ( m_xFrameContainerWindow.is() )
     262             :     {
     263             :         try
     264             :         {
     265           0 :             ::Size aOutputSize( GetOutputSizePixel() );
     266           0 :             m_xFrameContainerWindow->setPosSize( 0, 0, aOutputSize.Width(), aOutputSize.Height(), awt::PosSize::POSSIZE );
     267             :         }
     268           0 :         catch( const Exception& )
     269             :         {
     270             :             OSL_FAIL( "FmPropBrw::Resize: caught an exception!" );
     271             :         }
     272             :     }
     273           0 : }
     274             : 
     275             : //------------------------------------------------------------------------
     276           0 : FmPropBrw::~FmPropBrw()
     277             : {
     278           0 :     if (m_xBrowserController.is())
     279           0 :         implDetachController();
     280             :     try
     281             :     {
     282             :         // remove our own properties from the component context. We cannot ensure that the component context
     283             :         // is freed (there might be refcount problems :-\), so at least ensure the context itself
     284             :         // does hold the objects anymore
     285           0 :         Reference<XNameContainer> xName(m_xInspectorContext,uno::UNO_QUERY);
     286           0 :         if ( xName.is() )
     287             :         {
     288             :             const ::rtl::OUString pProps[] = { ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContextDocument" ) )
     289             :                                              , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogParentWindow" ) )
     290             :                                              , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlContext" ) )
     291           0 :                                              , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlShapeAccess" ) ) };
     292           0 :             for ( size_t i = 0; i < sizeof(pProps)/sizeof(pProps[0]); ++i )
     293           0 :                 xName->removeByName( pProps[i] );
     294           0 :         }
     295             :     }
     296           0 :     catch (const Exception& )
     297             :     {
     298             :         DBG_UNHANDLED_EXCEPTION();
     299             :     }
     300             :     DBG_DTOR(FmPropBrw,NULL);
     301           0 : }
     302             : 
     303             : //-----------------------------------------------------------------------
     304           0 : ::rtl::OUString FmPropBrw::getCurrentPage() const
     305             : {
     306           0 :     ::rtl::OUString sCurrentPage;
     307             :     try
     308             :     {
     309           0 :         if ( m_xBrowserController.is() )
     310             :         {
     311           0 :             OSL_VERIFY( m_xBrowserController->getViewData() >>= sCurrentPage );
     312             :         }
     313             : 
     314           0 :         if ( sCurrentPage.isEmpty() )
     315           0 :             sCurrentPage = m_sLastActivePage;
     316             :     }
     317           0 :     catch( const Exception& )
     318             :     {
     319             :         OSL_FAIL( "FmPropBrw::getCurrentPage: caught an exception while retrieving the current page!" );
     320             :     }
     321           0 :     return sCurrentPage;
     322             : }
     323             : 
     324             : //-----------------------------------------------------------------------
     325           0 : void FmPropBrw::implDetachController()
     326             : {
     327           0 :     m_sLastActivePage = getCurrentPage();
     328             : 
     329           0 :     implSetNewSelection( InterfaceBag() );
     330             : 
     331           0 :     if ( m_xMeAsFrame.is() )
     332             :     {
     333             :         try
     334             :         {
     335           0 :             m_xMeAsFrame->setComponent(NULL, NULL);
     336             :         }
     337           0 :         catch( const Exception& )
     338             :         {
     339             :             OSL_FAIL( "FmPropBrw::implDetachController: caught an exception while resetting the component!" );
     340             :         }
     341             :     }
     342             : 
     343             :     // we attached a frame to the controller manually, so we need to manually tell it that it's detached, too
     344           0 :     if ( m_xBrowserController.is() )
     345           0 :         m_xBrowserController->attachFrame( NULL );
     346             : 
     347           0 :     m_xBrowserController.clear();
     348           0 :     m_xInspectorModel.clear();
     349           0 :     m_xMeAsFrame.clear();
     350           0 : }
     351             : 
     352             : //-----------------------------------------------------------------------
     353           0 : sal_Bool FmPropBrw::Close()
     354             : {
     355             :     // suspend the controller (it is allowed to veto)
     356           0 :     if ( m_xMeAsFrame.is() )
     357             :     {
     358             :         try
     359             :         {
     360           0 :             Reference< XController > xController( m_xMeAsFrame->getController() );
     361           0 :             if ( xController.is() && !xController->suspend( sal_True ) )
     362           0 :                 return sal_False;
     363             :         }
     364           0 :         catch( const Exception& )
     365             :         {
     366             :             OSL_FAIL( "FmPropBrw::Close: caught an exception while asking the controller!" );
     367             :         }
     368             :     }
     369             : 
     370           0 :     implDetachController();
     371             : 
     372           0 :     if( IsRollUp() )
     373           0 :         RollDown();
     374             : 
     375             :     // remember our bindings: while we're closed, we're deleted, too, so accessing the bindings after this
     376             :     // would be deadly
     377             :     // 10/19/00 - 79321 - FS
     378           0 :     SfxBindings& rBindings = SfxControllerItem::GetBindings();
     379             : 
     380           0 :     sal_Bool bClose = SfxFloatingWindow::Close();
     381             : 
     382           0 :     if (bClose)
     383             :     {
     384           0 :         rBindings.Invalidate(SID_FM_CTL_PROPERTIES);
     385           0 :         rBindings.Invalidate(SID_FM_PROPERTIES);
     386             :     }
     387             : 
     388           0 :     return bClose;
     389             : }
     390             : 
     391             : //-----------------------------------------------------------------------
     392           0 : bool FmPropBrw::implIsReadOnlyModel() const
     393             : {
     394             :     try
     395             :     {
     396           0 :         if ( m_xInspectorModel.is() )
     397           0 :             return m_xInspectorModel->getIsReadOnly();
     398           0 :         return false;
     399             :     }
     400           0 :     catch( const Exception& )
     401             :     {
     402             :         DBG_UNHANDLED_EXCEPTION();
     403             :     }
     404           0 :     return true;
     405             : }
     406             : 
     407             : //-----------------------------------------------------------------------
     408           0 : void FmPropBrw::implSetNewSelection( const InterfaceBag& _rSelection )
     409             : {
     410           0 :     if ( m_xBrowserController.is() )
     411             :     {
     412             :         try
     413             :         {
     414           0 :             Reference< XObjectInspector > xInspector( m_xBrowserController, UNO_QUERY_THROW );
     415             : 
     416             :             // tell it the objects to inspect
     417           0 :             Sequence< Reference< XInterface > > aSelection( _rSelection.size() );
     418           0 :             ::std::copy( _rSelection.begin(), _rSelection.end(), aSelection.getArray() );
     419             : 
     420           0 :             xInspector->inspect( aSelection );
     421             :         }
     422           0 :         catch( const VetoException& )
     423             :         {
     424             :             return;
     425             :         }
     426           0 :         catch( const Exception& )
     427             :         {
     428             :             OSL_FAIL( "FmPropBrw::implSetNewSelection: caught an unexpected exception!" );
     429             :             return;
     430             :         }
     431             : 
     432             :         // set the new title according to the selected object
     433           0 :         String sTitle;
     434             : 
     435           0 :         if ( _rSelection.empty() )
     436             :         {
     437           0 :             sTitle = String( SVX_RES( RID_STR_NO_PROPERTIES ) );
     438             :         }
     439           0 :         else if ( _rSelection.size() > 1 )
     440             :         {
     441             :             // no form component and (no form or no name) -> Multiselection
     442           0 :             sTitle = String( SVX_RES( RID_STR_PROPERTIES_CONTROL ) );
     443           0 :             sTitle += String( SVX_RES( RID_STR_PROPTITLE_MULTISELECT ) );
     444             :         }
     445             :         else
     446             :         {
     447           0 :             Reference< XPropertySet > xSingleSelection( *_rSelection.begin(), UNO_QUERY);
     448           0 :             if  ( ::comphelper::hasProperty( FM_PROP_CLASSID, xSingleSelection ) )
     449             :             {
     450           0 :                 sal_Int16 nClassID = FormComponentType::CONTROL;
     451           0 :                 xSingleSelection->getPropertyValue( FM_PROP_CLASSID ) >>= nClassID;
     452             : 
     453           0 :                 sTitle = String( SVX_RES( RID_STR_PROPERTIES_CONTROL ) );
     454           0 :                 sTitle += String( GetUIHeadlineName( nClassID, makeAny( xSingleSelection ) ) );
     455             :             }
     456           0 :             else if ( Reference< XForm >( xSingleSelection, UNO_QUERY ).is() )
     457           0 :                 sTitle = String( SVX_RES( RID_STR_PROPERTIES_FORM ) );
     458             :         }
     459             : 
     460           0 :         if ( implIsReadOnlyModel() )
     461           0 :             sTitle += String( SVX_RES( RID_STR_READONLY_VIEW ) );
     462             : 
     463           0 :         SetText( sTitle );
     464             : 
     465             :         // #95343# ---------------------------------
     466           0 :         Reference< ::com::sun::star::awt::XLayoutConstrains > xLayoutConstrains( m_xBrowserController, UNO_QUERY );
     467           0 :         if( xLayoutConstrains.is() )
     468             :         {
     469           0 :             ::Size aConstrainedSize;
     470           0 :             ::com::sun::star::awt::Size aMinSize = xLayoutConstrains->getMinimumSize();
     471             : 
     472           0 :             sal_Int32 nLeft(0), nTop(0), nRight(0), nBottom(0);
     473           0 :             GetBorder( nLeft, nTop, nRight, nBottom );
     474           0 :             aMinSize.Width += nLeft + nRight + 8;
     475           0 :             aMinSize.Height += nTop + nBottom + 8;
     476             : 
     477           0 :             aConstrainedSize.setHeight( aMinSize.Height );
     478           0 :             aConstrainedSize.setWidth( aMinSize.Width );
     479           0 :             SetMinOutputSizePixel( aConstrainedSize );
     480           0 :             aConstrainedSize = GetOutputSizePixel();
     481           0 :             sal_Bool bResize = sal_False;
     482           0 :             if( aConstrainedSize.Width() < aMinSize.Width )
     483             :             {
     484           0 :                 aConstrainedSize.setWidth( aMinSize.Width );
     485           0 :                 bResize = sal_True;
     486             :             }
     487           0 :             if( aConstrainedSize.Height() < aMinSize.Height )
     488             :             {
     489           0 :                 aConstrainedSize.setHeight( aMinSize.Height );
     490           0 :                 bResize = sal_True;
     491             :             }
     492           0 :             if( bResize )
     493           0 :                 SetOutputSizePixel( aConstrainedSize );
     494           0 :         }
     495             :     }
     496             : }
     497             : 
     498             : //-----------------------------------------------------------------------
     499           0 : void FmPropBrw::FillInfo( SfxChildWinInfo& rInfo ) const
     500             : {
     501           0 :     rInfo.bVisible = sal_False;
     502           0 :     rInfo.aExtraString = getCurrentPage();
     503           0 : }
     504             : 
     505             : //-----------------------------------------------------------------------
     506           0 : IMPL_LINK( FmPropBrw, OnAsyncGetFocus, void*, /*NOTINTERESTEDIN*/ )
     507             : {
     508           0 :     if (m_xBrowserComponentWindow.is())
     509           0 :         m_xBrowserComponentWindow->setFocus();
     510           0 :     return 0L;
     511             : }
     512             : 
     513             : //-----------------------------------------------------------------------
     514             : namespace
     515             : {
     516           0 :     static bool lcl_shouldEnableHelpSection( const Reference< XMultiServiceFactory >& _rxFactory )
     517             :     {
     518           0 :         const ::rtl::OUString sConfigName( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Forms/PropertyBrowser/" ) );
     519           0 :         const ::rtl::OUString sPropertyName( RTL_CONSTASCII_USTRINGPARAM( "DirectHelp" ) );
     520             : 
     521             :         ::utl::OConfigurationTreeRoot aConfiguration(
     522           0 :             ::utl::OConfigurationTreeRoot::createWithServiceFactory( _rxFactory, sConfigName ) );
     523             : 
     524           0 :         bool bEnabled = false;
     525           0 :         OSL_VERIFY( aConfiguration.getNodeValue( sPropertyName ) >>= bEnabled );
     526           0 :         return bEnabled;
     527             :     }
     528             : }
     529             : //-----------------------------------------------------------------------
     530           0 : void FmPropBrw::impl_createPropertyBrowser_throw( FmFormShell* _pFormShell )
     531             : {
     532             :     // the document in which we live
     533           0 :     Reference< XInterface > xDocument;
     534           0 :     if ( _pFormShell && _pFormShell->GetObjectShell() )
     535           0 :         xDocument = _pFormShell->GetObjectShell()->GetModel();
     536             : 
     537             :     // the context of the controls in our document
     538           0 :     Reference< awt::XControlContainer > xControlContext;
     539           0 :     if ( _pFormShell && _pFormShell->GetFormView() )
     540             :     {
     541           0 :         SdrPageView* pPageView = _pFormShell->GetFormView()->GetSdrPageView();
     542             : 
     543           0 :         if(pPageView)
     544             :         {
     545           0 :             SdrPageWindow* pPageWindow = pPageView->GetPageWindow(0L);
     546             : 
     547           0 :             if(pPageWindow)
     548             :             {
     549           0 :                 xControlContext = pPageWindow->GetControlContainer();
     550             :             }
     551             :         }
     552             :     }
     553             : 
     554             :     // the default parent window for message boxes
     555           0 :     Reference< XWindow > xParentWindow( VCLUnoHelper::GetInterface ( this ) );
     556             : 
     557             :     // the mapping from control models to control shapes
     558           0 :     Reference< XMap > xControlMap;
     559           0 :     FmFormPage* pFormPage = _pFormShell ? _pFormShell->GetCurPage() : NULL;
     560           0 :     if ( pFormPage )
     561           0 :         xControlMap = pFormPage->GetImpl().getControlToShapeMap();
     562             : 
     563             :     // our own component context
     564             :     Reference< XComponentContext > xOwnContext(
     565           0 :         comphelper::getComponentContext( m_xORB ) );
     566             : 
     567             :     // a ComponentContext for the
     568             :     ::cppu::ContextEntry_Init aHandlerContextInfo[] =
     569             :     {
     570             :         ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContextDocument" ) ), makeAny( xDocument ) ),
     571             :         ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogParentWindow" ) ), makeAny( xParentWindow ) ),
     572             :         ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlContext" ) ), makeAny( xControlContext ) ),
     573             :         ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlShapeAccess" ) ), makeAny( xControlMap ) )
     574           0 :     };
     575             :     m_xInspectorContext.set(
     576             :         ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ),
     577           0 :         xOwnContext ) );
     578             : 
     579           0 :     bool bEnableHelpSection = lcl_shouldEnableHelpSection( m_xORB );
     580             : 
     581             :     // an object inspector model
     582             :     m_xInspectorModel =
     583             :             bEnableHelpSection
     584             :         ?   DefaultFormComponentInspectorModel::createWithHelpSection( m_xInspectorContext, 3, 5 )
     585           0 :         :   DefaultFormComponentInspectorModel::createDefault( m_xInspectorContext );
     586             : 
     587             :     // an object inspector
     588             :     m_xBrowserController = m_xBrowserController.query(
     589             :         ObjectInspector::createWithModel(
     590             :             m_xInspectorContext, m_xInspectorModel
     591           0 :         ) );
     592             : 
     593           0 :     if ( !m_xBrowserController.is() )
     594             :     {
     595           0 :         ::rtl::OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.ObjectInspector" ) );
     596           0 :         ShowServiceNotAvailableError( GetParent(), sServiceName, sal_True );
     597             :     }
     598             :     else
     599             :     {
     600           0 :         m_xBrowserController->attachFrame( m_xMeAsFrame );
     601           0 :         m_xBrowserComponentWindow = m_xMeAsFrame->getComponentWindow();
     602             :         DBG_ASSERT( m_xBrowserComponentWindow.is(), "FmPropBrw::impl_createPropertyBrowser_throw: attached the controller, but have no component window!" );
     603             :     }
     604             : 
     605           0 :     if ( bEnableHelpSection )
     606             :     {
     607           0 :         Reference< XObjectInspector > xInspector( m_xBrowserController, UNO_QUERY_THROW );
     608           0 :         Reference< XObjectInspectorUI > xInspectorUI( xInspector->getInspectorUI() );
     609           0 :         Reference< XInterface > xDefaultHelpProvider( DefaultHelpProvider::create( m_xInspectorContext, xInspectorUI ) );
     610           0 :     }
     611           0 : }
     612             : 
     613             : //-----------------------------------------------------------------------
     614           0 : void FmPropBrw::impl_ensurePropertyBrowser_nothrow( FmFormShell* _pFormShell )
     615             : {
     616             :     // the document in which we live
     617           0 :     Reference< XInterface > xDocument;
     618           0 :     SfxObjectShell* pObjectShell = _pFormShell ? _pFormShell->GetObjectShell() : NULL;
     619           0 :     if ( pObjectShell )
     620           0 :         xDocument = pObjectShell->GetModel();
     621           0 :     if ( ( xDocument == m_xLastKnownDocument ) && m_xBrowserController.is() )
     622             :         // nothing to do
     623           0 :         return;
     624             : 
     625             :     try
     626             :     {
     627             :         // clean up any previous instances of the object inspector
     628           0 :         if ( m_xMeAsFrame.is() )
     629           0 :             m_xMeAsFrame->setComponent( NULL, NULL );
     630             :         else
     631           0 :             ::comphelper::disposeComponent( m_xBrowserController );
     632           0 :         m_xBrowserController.clear();
     633           0 :         m_xInspectorModel.clear();
     634           0 :         m_xBrowserComponentWindow.clear();
     635             : 
     636             :         // and create a new one
     637           0 :         impl_createPropertyBrowser_throw( _pFormShell );
     638             :     }
     639           0 :     catch( const Exception& )
     640             :     {
     641             :         DBG_UNHANDLED_EXCEPTION();
     642             :     }
     643           0 :     m_xLastKnownDocument = xDocument;
     644             : }
     645             : 
     646             : //-----------------------------------------------------------------------
     647           0 : void FmPropBrw::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
     648             : {
     649           0 :     if (!pState  || SID_FM_PROPERTY_CONTROL != nSID)
     650           0 :         return;
     651             : 
     652           0 :     m_bInStateChange = true;
     653             :     try
     654             :     {
     655           0 :         if (eState >= SFX_ITEM_AVAILABLE)
     656             :         {
     657           0 :             FmFormShell* pShell = PTR_CAST(FmFormShell,((SfxObjectItem*)pState)->GetShell());
     658           0 :             InterfaceBag aSelection;
     659           0 :             if ( pShell )
     660           0 :                 pShell->GetImpl()->getCurrentSelection( aSelection );
     661             : 
     662           0 :             impl_ensurePropertyBrowser_nothrow( pShell );
     663             : 
     664             :             // set the new object to inspect
     665           0 :             implSetNewSelection( aSelection );
     666             : 
     667             :             // if this is the first time we're here, some additional things need to be done ...
     668           0 :             if ( m_bInitialStateChange )
     669             :             {
     670             :                 // if we're just newly created, we want to have the focus
     671           0 :                 PostUserEvent( LINK( this, FmPropBrw, OnAsyncGetFocus ) );
     672             : 
     673             :                 // and additionally, we want to show the page which was active during
     674             :                 // our previous incarnation
     675           0 :                 if ( !m_sLastActivePage.isEmpty() )
     676             :                 {
     677             :                     try
     678             :                     {
     679           0 :                         if ( m_xBrowserController.is() )
     680           0 :                             m_xBrowserController->restoreViewData( makeAny( m_sLastActivePage ) );
     681             :                     }
     682           0 :                     catch( const Exception& )
     683             :                     {
     684             :                         OSL_FAIL( "FmPropBrw::StateChanged: caught an exception while setting the initial page!" );
     685             :                     }
     686             :                 }
     687             : 
     688           0 :                 m_bInitialStateChange = sal_False;
     689           0 :             }
     690             : 
     691             :         }
     692             :         else
     693             :         {
     694           0 :             implSetNewSelection( InterfaceBag() );
     695             :         }
     696             :     }
     697           0 :     catch (Exception&)
     698             :     {
     699             :         OSL_FAIL("FmPropBrw::StateChanged: Exception occurred!");
     700             :     }
     701           0 :     m_bInStateChange = false;
     702             : }
     703             : 
     704             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10