update dev300-m58
[ooovba.git] / svx / source / form / fmPropBrw.cxx
blob57eebb7e6ba6304f10bf78e8b72fda84c73bc7b7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmPropBrw.cxx,v $
10 * $Revision: 1.33 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "fmhelp.hrc"
35 #include "fmprop.hrc"
36 #include "fmPropBrw.hxx"
37 #include "fmresids.hrc"
38 #include "fmservs.hxx"
39 #include "fmshimp.hxx"
40 #include "fmpgeimp.hxx"
42 #include "svx/dialmgr.hxx"
43 #include "svx/fmpage.hxx"
44 #include "svx/fmshell.hxx"
45 #include "svx/sdrpagewindow.hxx"
46 #include "svx/svdpagv.hxx"
47 #include "svx/svxids.hrc"
49 /** === begin UNO includes === **/
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include <com/sun/star/awt/PosSize.hpp>
52 #include <com/sun/star/form/XForm.hpp>
53 #include <com/sun/star/form/FormComponentType.hpp>
54 #include <com/sun/star/awt/XLayoutConstrains.hpp>
55 #include <com/sun/star/awt/XControlContainer.hpp>
56 #include <com/sun/star/container/XChild.hpp>
57 #include <com/sun/star/awt/PosSize.hpp>
58 #include <com/sun/star/inspection/ObjectInspector.hpp>
59 #include <com/sun/star/inspection/ObjectInspectorModel.hpp>
60 #include <com/sun/star/form/inspection/DefaultFormComponentInspectorModel.hpp>
61 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
62 #include <com/sun/star/inspection/DefaultHelpProvider.hpp>
63 /** === end UNO includes === **/
65 #include <comphelper/processfactory.hxx>
66 #include <comphelper/property.hxx>
67 #include <cppuhelper/component_context.hxx>
68 #include <sfx2/bindings.hxx>
69 #include <sfx2/childwin.hxx>
70 #include <sfx2/dispatch.hxx>
71 #include <sfx2/objitem.hxx>
72 #include <sfx2/objsh.hxx>
73 #include <sfx2/viewfrm.hxx>
74 #include <toolkit/unohlp.hxx>
75 #include <tools/debug.hxx>
76 #include <tools/diagnose_ex.h>
77 #include <tools/shl.hxx>
78 #include <unotools/confignode.hxx>
79 #include <vcl/stdtext.hxx>
81 #include <algorithm>
83 using namespace ::com::sun::star;
84 using namespace ::com::sun::star::uno;
85 using namespace ::com::sun::star::util;
86 using namespace ::com::sun::star::inspection;
87 using namespace ::com::sun::star::form::inspection;
88 using ::com::sun::star::awt::XWindow;
90 /*************************************************************************/
91 //========================================================================
92 //= FmPropBrwMgr
93 //========================================================================
94 //-----------------------------------------------------------------------
95 SFX_IMPL_FLOATINGWINDOW(FmPropBrwMgr, SID_FM_SHOW_PROPERTIES)
97 //-----------------------------------------------------------------------
98 FmPropBrwMgr::FmPropBrwMgr( Window* _pParent, sal_uInt16 _nId,
99 SfxBindings* _pBindings, SfxChildWinInfo* _pInfo)
100 :SfxChildWindow(_pParent, _nId)
102 pWindow = new FmPropBrw( ::comphelper::getProcessServiceFactory(), _pBindings, this, _pParent, _pInfo );
103 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
104 ((SfxFloatingWindow*)pWindow)->Initialize( _pInfo );
107 //========================================================================
108 //========================================================================
109 const long STD_WIN_SIZE_X = 300;
110 const long STD_WIN_SIZE_Y = 350;
112 const long STD_MIN_SIZE_X = 250;
113 const long STD_MIN_SIZE_Y = 250;
115 const long STD_WIN_POS_X = 50;
116 const long STD_WIN_POS_Y = 50;
117 const long WIN_BORDER = 2;
118 const long MIN_WIN_SIZE_X = 50;
119 const long MIN_WIN_SIZE_Y = 50;
121 using namespace ::com::sun::star::uno;
122 using namespace ::com::sun::star::lang;
123 using namespace ::com::sun::star::form;
124 using namespace ::com::sun::star::frame;
125 using namespace ::com::sun::star::beans;
126 using namespace ::com::sun::star::container;
127 using namespace ::svxform;
129 ::rtl::OUString GetUIHeadlineName(sal_Int16 nClassId, const Any& aUnoObj)
131 sal_uInt16 nClassNameResourceId = 0;
133 switch ( nClassId )
135 case FormComponentType::TEXTFIELD:
137 Reference< XInterface > xIFace;
138 aUnoObj >>= xIFace;
139 nClassNameResourceId = RID_STR_PROPTITLE_EDIT;
140 if (xIFace.is())
141 { // we have a chance to check if it's a formatted field model
142 Reference< XServiceInfo > xInfo(xIFace, UNO_QUERY);
143 if (xInfo.is() && (xInfo->supportsService(FM_SUN_COMPONENT_FORMATTEDFIELD)))
144 nClassNameResourceId = RID_STR_PROPTITLE_FORMATTED;
145 else if (!xInfo.is())
147 // couldn't distinguish between formatted and edit with the service name, so try with the properties
148 Reference< XPropertySet > xProps(xIFace, UNO_QUERY);
149 if (xProps.is())
151 Reference< XPropertySetInfo > xPropsInfo = xProps->getPropertySetInfo();
152 if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(FM_PROP_FORMATSSUPPLIER))
153 nClassNameResourceId = RID_STR_PROPTITLE_FORMATTED;
158 break;
160 case FormComponentType::COMMANDBUTTON:
161 nClassNameResourceId = RID_STR_PROPTITLE_PUSHBUTTON; break;
162 case FormComponentType::RADIOBUTTON:
163 nClassNameResourceId = RID_STR_PROPTITLE_RADIOBUTTON; break;
164 case FormComponentType::CHECKBOX:
165 nClassNameResourceId = RID_STR_PROPTITLE_CHECKBOX; break;
166 case FormComponentType::LISTBOX:
167 nClassNameResourceId = RID_STR_PROPTITLE_LISTBOX; break;
168 case FormComponentType::COMBOBOX:
169 nClassNameResourceId = RID_STR_PROPTITLE_COMBOBOX; break;
170 case FormComponentType::GROUPBOX:
171 nClassNameResourceId = RID_STR_PROPTITLE_GROUPBOX; break;
172 case FormComponentType::IMAGEBUTTON:
173 nClassNameResourceId = RID_STR_PROPTITLE_IMAGEBUTTON; break;
174 case FormComponentType::FIXEDTEXT:
175 nClassNameResourceId = RID_STR_PROPTITLE_FIXEDTEXT; break;
176 case FormComponentType::GRIDCONTROL:
177 nClassNameResourceId = RID_STR_PROPTITLE_DBGRID; break;
178 case FormComponentType::FILECONTROL:
179 nClassNameResourceId = RID_STR_PROPTITLE_FILECONTROL; break;
180 case FormComponentType::DATEFIELD:
181 nClassNameResourceId = RID_STR_PROPTITLE_DATEFIELD; break;
182 case FormComponentType::TIMEFIELD:
183 nClassNameResourceId = RID_STR_PROPTITLE_TIMEFIELD; break;
184 case FormComponentType::NUMERICFIELD:
185 nClassNameResourceId = RID_STR_PROPTITLE_NUMERICFIELD; break;
186 case FormComponentType::CURRENCYFIELD:
187 nClassNameResourceId = RID_STR_PROPTITLE_CURRENCYFIELD; break;
188 case FormComponentType::PATTERNFIELD:
189 nClassNameResourceId = RID_STR_PROPTITLE_PATTERNFIELD; break;
190 case FormComponentType::IMAGECONTROL:
191 nClassNameResourceId = RID_STR_PROPTITLE_IMAGECONTROL; break;
192 case FormComponentType::HIDDENCONTROL:
193 nClassNameResourceId = RID_STR_HIDDEN_CLASSNAME; break;
194 case FormComponentType::SCROLLBAR:
195 nClassNameResourceId = RID_STR_PROPTITLE_SCROLLBAR; break;
196 case FormComponentType::SPINBUTTON:
197 nClassNameResourceId = RID_STR_PROPTITLE_SPINBUTTON; break;
198 case FormComponentType::NAVIGATIONBAR:
199 nClassNameResourceId = RID_STR_PROPTITLE_NAVBAR; break;
200 case FormComponentType::CONTROL:
201 default:
202 nClassNameResourceId = RID_STR_CONTROL_CLASSNAME; break;
205 if ( !nClassNameResourceId )
206 return ::rtl::OUString();
208 return ::rtl::OUString( String( SVX_RES( nClassNameResourceId ) ) );
211 //========================================================================
212 // class FmPropBrw
213 //========================================================================
214 DBG_NAME(FmPropBrw);
215 //------------------------------------------------------------------------
216 FmPropBrw::FmPropBrw( const Reference< XMultiServiceFactory >& _xORB, SfxBindings* _pBindings,
217 SfxChildWindow* _pMgr, Window* _pParent, const SfxChildWinInfo* _pInfo )
218 :SfxFloatingWindow(_pBindings, _pMgr, _pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE|WB_3DLOOK|WB_ROLLABLE) )
219 ,SfxControllerItem(SID_FM_PROPERTY_CONTROL, *_pBindings)
220 ,m_bInitialStateChange(sal_True)
221 ,m_xORB(_xORB)
223 DBG_CTOR(FmPropBrw,NULL);
225 ::Size aPropWinSize(STD_WIN_SIZE_X,STD_WIN_SIZE_Y);
226 SetMinOutputSizePixel(::Size(STD_MIN_SIZE_X,STD_MIN_SIZE_Y));
227 SetOutputSizePixel(aPropWinSize);
228 SetUniqueId(UID_FORMPROPBROWSER_FRAME);
232 // create a frame wrapper for myself
233 m_xMeAsFrame = Reference< XFrame >(m_xORB->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Frame")), UNO_QUERY);
234 if (m_xMeAsFrame.is())
236 // create an intermediate window, which is to be the container window of the frame
237 // Do *not* use |this| as container window for the frame, this would result in undefined
238 // responsiblity for this window (as soon as we initialize a frame with a window, the frame
239 // is responsible for it's life time, but |this| is controlled by the belonging SfxChildWindow)
240 // #i34249# - 2004-09-27 - fs@openoffice.org
241 Window* pContainerWindow = new Window( this );
242 pContainerWindow->Show();
243 m_xFrameContainerWindow = VCLUnoHelper::GetInterface ( pContainerWindow );
245 m_xMeAsFrame->initialize( m_xFrameContainerWindow );
246 m_xMeAsFrame->setName(::rtl::OUString::createFromAscii("form property browser"));
247 if ( _pBindings->GetDispatcher() )
249 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFramesSupplier >
250 xSupp ( _pBindings->GetDispatcher()->GetFrame()->GetFrame()->GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
251 // if ( xSupp.is() )
252 // xSupp->getFrames()->append( m_xMeAsFrame );
253 // Don't append frame to frame hierachy to prevent UI_DEACTIVATE messages
254 // #i31834# - 2004-07-27 - cd@openoffice.org
258 catch (Exception&)
260 DBG_ERROR("FmPropBrw::FmPropBrw: could not create/initialize my frame!");
261 m_xMeAsFrame.clear();
264 if (m_xMeAsFrame.is())
265 _pMgr->SetFrame( m_xMeAsFrame );
268 if ( m_xBrowserComponentWindow.is() )
269 m_xBrowserComponentWindow->setVisible( sal_True );
271 if ( _pInfo )
272 m_sLastActivePage = _pInfo->aExtraString;
275 //------------------------------------------------------------------------
276 void FmPropBrw::Resize()
278 SfxFloatingWindow::Resize();
280 if ( m_xFrameContainerWindow.is() )
284 ::Size aOutputSize( GetOutputSizePixel() );
285 m_xFrameContainerWindow->setPosSize( 0, 0, aOutputSize.Width(), aOutputSize.Height(), awt::PosSize::POSSIZE );
287 catch( const Exception& )
289 OSL_ENSURE( sal_False, "FmPropBrw::Resize: caught an exception!" );
294 //------------------------------------------------------------------------
295 FmPropBrw::~FmPropBrw()
297 if (m_xBrowserController.is())
298 implDetachController();
301 // remove our own properties from the component context. We cannot ensure that the component context
302 // is freed (there might be refcount problems :-\), so at least ensure the context itself
303 // does hold the objects anymore
304 Reference<XNameContainer> xName(m_xInspectorContext,uno::UNO_QUERY);
305 if ( xName.is() )
307 const ::rtl::OUString pProps[] = { ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContextDocument" ) )
308 , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogParentWindow" ) )
309 , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlContext" ) )
310 , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlShapeAccess" ) ) };
311 for ( size_t i = 0; i < sizeof(pProps)/sizeof(pProps[0]); ++i )
312 xName->removeByName( pProps[i] );
315 catch (const Exception& )
317 DBG_UNHANDLED_EXCEPTION();
319 DBG_DTOR(FmPropBrw,NULL);
322 //-----------------------------------------------------------------------
323 ::rtl::OUString FmPropBrw::getCurrentPage() const
325 ::rtl::OUString sCurrentPage;
328 if ( m_xBrowserController.is() )
330 OSL_VERIFY( m_xBrowserController->getViewData() >>= sCurrentPage );
333 if ( !sCurrentPage.getLength() )
334 sCurrentPage = m_sLastActivePage;
336 catch( const Exception& )
338 OSL_ENSURE( sal_False, "FmPropBrw::getCurrentPage: caught an exception while retrieving the current page!" );
340 return sCurrentPage;
343 //-----------------------------------------------------------------------
344 void FmPropBrw::implDetachController()
346 m_sLastActivePage = getCurrentPage();
348 implSetNewSelection( InterfaceBag() );
350 if ( m_xMeAsFrame.is() )
354 m_xMeAsFrame->setComponent(NULL, NULL);
356 catch( const Exception& )
358 OSL_ENSURE( sal_False, "FmPropBrw::implDetachController: caught an exception while resetting the component!" );
362 // we attached a frame to the controller manually, so we need to manually tell it that it's detached, too
363 // 96068 - 09.01.2002 - fs@openoffice.org
364 if ( m_xBrowserController.is() )
365 m_xBrowserController->attachFrame( NULL );
367 m_xBrowserController.clear();
368 m_xInspectorModel.clear();
369 m_xMeAsFrame.clear();
372 //-----------------------------------------------------------------------
373 sal_Bool FmPropBrw::Close()
375 // suspend the controller (it is allowed to veto)
376 if ( m_xMeAsFrame.is() )
380 Reference< XController > xController( m_xMeAsFrame->getController() );
381 if ( xController.is() && !xController->suspend( sal_True ) )
382 return sal_False;
384 catch( const Exception& )
386 OSL_ENSURE( sal_False, "FmPropBrw::Close: caught an exception while asking the controller!" );
390 implDetachController();
392 if( IsRollUp() )
393 RollDown();
395 // remember our bindings: while we're closed, we're deleted, too, so accessing the bindings after this
396 // would be deadly
397 // 10/19/00 - 79321 - FS
398 SfxBindings& rBindings = SfxControllerItem::GetBindings();
400 sal_Bool bClose = SfxFloatingWindow::Close();
402 if (bClose)
404 rBindings.Invalidate(SID_FM_CTL_PROPERTIES);
405 rBindings.Invalidate(SID_FM_PROPERTIES);
408 return bClose;
411 //-----------------------------------------------------------------------
412 bool FmPropBrw::implIsReadOnlyModel() const
416 if ( m_xInspectorModel.is() )
417 return m_xInspectorModel->getIsReadOnly();
418 return false;
420 catch( const Exception& )
422 DBG_UNHANDLED_EXCEPTION();
424 return true;
427 //-----------------------------------------------------------------------
428 void FmPropBrw::implSetNewSelection( const InterfaceBag& _rSelection )
430 if ( m_xBrowserController.is() )
434 Reference< XObjectInspector > xInspector( m_xBrowserController, UNO_QUERY_THROW );
436 // tell it the objects to inspect
437 Sequence< Reference< XInterface > > aSelection( _rSelection.size() );
438 ::std::copy( _rSelection.begin(), _rSelection.end(), aSelection.getArray() );
440 xInspector->inspect( aSelection );
442 catch( const VetoException& )
444 return;
446 catch( const Exception& )
448 OSL_ENSURE( sal_False, "FmPropBrw::implSetNewSelection: caught an unexpected exception!" );
449 return;
452 // set the new title according to the selected object
453 String sTitle;
455 if ( _rSelection.empty() )
457 sTitle = String( SVX_RES( RID_STR_NO_PROPERTIES ) );
459 else if ( _rSelection.size() > 1 )
461 // no form component and (no form or no name) -> Multiselection
462 sTitle = String( SVX_RES( RID_STR_PROPERTIES_CONTROL ) );
463 sTitle += String( SVX_RES( RID_STR_PROPTITLE_MULTISELECT ) );
465 else
467 Reference< XPropertySet > xSingleSelection( *_rSelection.begin(), UNO_QUERY);
468 if ( ::comphelper::hasProperty( FM_PROP_CLASSID, xSingleSelection ) )
470 sal_Int16 nClassID = FormComponentType::CONTROL;
471 xSingleSelection->getPropertyValue( FM_PROP_CLASSID ) >>= nClassID;
473 sTitle = String( SVX_RES( RID_STR_PROPERTIES_CONTROL ) );
474 sTitle += String( GetUIHeadlineName( nClassID, makeAny( xSingleSelection ) ) );
476 else if ( Reference< XForm >( xSingleSelection, UNO_QUERY ).is() )
477 sTitle = String( SVX_RES( RID_STR_PROPERTIES_FORM ) );
480 if ( implIsReadOnlyModel() )
481 sTitle += String( SVX_RES( RID_STR_READONLY_VIEW ) );
483 SetText( sTitle );
485 // #95343# ---------------------------------
486 Reference< ::com::sun::star::awt::XLayoutConstrains > xLayoutConstrains( m_xBrowserController, UNO_QUERY );
487 if( xLayoutConstrains.is() )
489 ::Size aConstrainedSize;
490 ::com::sun::star::awt::Size aMinSize = xLayoutConstrains->getMinimumSize();
492 sal_Int32 nLeft(0), nTop(0), nRight(0), nBottom(0);
493 GetBorder( nLeft, nTop, nRight, nBottom );
494 aMinSize.Width += nLeft + nRight + 8;
495 aMinSize.Height += nTop + nBottom + 8;
497 aConstrainedSize.setHeight( aMinSize.Height );
498 aConstrainedSize.setWidth( aMinSize.Width );
499 SetMinOutputSizePixel( aConstrainedSize );
500 aConstrainedSize = GetOutputSizePixel();
501 sal_Bool bResize = sal_False;
502 if( aConstrainedSize.Width() < aMinSize.Width )
504 aConstrainedSize.setWidth( aMinSize.Width );
505 bResize = sal_True;
507 if( aConstrainedSize.Height() < aMinSize.Height )
509 aConstrainedSize.setHeight( aMinSize.Height );
510 bResize = sal_True;
512 if( bResize )
513 SetOutputSizePixel( aConstrainedSize );
518 //-----------------------------------------------------------------------
519 void FmPropBrw::FillInfo( SfxChildWinInfo& rInfo ) const
521 rInfo.bVisible = sal_False;
522 rInfo.aExtraString = getCurrentPage();
525 //-----------------------------------------------------------------------
526 IMPL_LINK( FmPropBrw, OnAsyncGetFocus, void*, /*NOTINTERESTEDIN*/ )
528 if (m_xBrowserComponentWindow.is())
529 m_xBrowserComponentWindow->setFocus();
530 return 0L;
533 //-----------------------------------------------------------------------
534 namespace
536 static bool lcl_shouldEnableHelpSection( const Reference< XMultiServiceFactory >& _rxFactory )
538 const ::rtl::OUString sConfigName( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Forms/PropertyBrowser/" ) );
539 const ::rtl::OUString sPropertyName( RTL_CONSTASCII_USTRINGPARAM( "DirectHelp" ) );
541 ::utl::OConfigurationTreeRoot aConfiguration(
542 ::utl::OConfigurationTreeRoot::createWithServiceFactory( _rxFactory, sConfigName ) );
544 bool bEnabled = false;
545 OSL_VERIFY( aConfiguration.getNodeValue( sPropertyName ) >>= bEnabled );
546 return bEnabled;
549 //-----------------------------------------------------------------------
550 void FmPropBrw::impl_createPropertyBrowser_throw( FmFormShell* _pFormShell )
552 // the document in which we live
553 Reference< XInterface > xDocument;
554 if ( _pFormShell && _pFormShell->GetObjectShell() )
555 xDocument = _pFormShell->GetObjectShell()->GetModel();
557 // the context of the controls in our document
558 Reference< awt::XControlContainer > xControlContext;
559 if ( _pFormShell && _pFormShell->GetFormView() )
561 SdrPageView* pPageView = _pFormShell->GetFormView()->GetSdrPageView();
563 if(pPageView)
565 SdrPageWindow* pPageWindow = pPageView->GetPageWindow(0L);
567 if(pPageWindow)
569 xControlContext = pPageWindow->GetControlContainer();
574 // the default parent window for message boxes
575 Reference< XWindow > xParentWindow( VCLUnoHelper::GetInterface ( this ) );
577 // the mapping from control models to control shapes
578 Reference< XMap > xControlMap;
579 FmFormPage* pFormPage = _pFormShell ? _pFormShell->GetCurPage() : NULL;
580 if ( pFormPage )
581 xControlMap = pFormPage->GetImpl().getControlToShapeMap();
583 // our own component context
584 Reference< XPropertySet > xFactoryProperties( m_xORB, UNO_QUERY_THROW );
585 Reference< XComponentContext > xOwnContext(
586 xFactoryProperties->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ),
587 UNO_QUERY_THROW );
589 // a ComponentContext for the
590 ::cppu::ContextEntry_Init aHandlerContextInfo[] =
592 ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContextDocument" ) ), makeAny( xDocument ) ),
593 ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogParentWindow" ) ), makeAny( xParentWindow ) ),
594 ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlContext" ) ), makeAny( xControlContext ) ),
595 ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ControlShapeAccess" ) ), makeAny( xControlMap ) )
597 m_xInspectorContext.set(
598 ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ),
599 xOwnContext ) );
601 bool bEnableHelpSection = lcl_shouldEnableHelpSection( m_xORB );
603 // an object inspector model
604 m_xInspectorModel =
605 bEnableHelpSection
606 ? DefaultFormComponentInspectorModel::createWithHelpSection( m_xInspectorContext, 3, 5 )
607 : DefaultFormComponentInspectorModel::createDefault( m_xInspectorContext );
609 // an object inspector
610 m_xBrowserController = m_xBrowserController.query(
611 ObjectInspector::createWithModel(
612 m_xInspectorContext, m_xInspectorModel
613 ) );
615 if ( !m_xBrowserController.is() )
617 ::rtl::OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.ObjectInspector" ) );
618 ShowServiceNotAvailableError( GetParent(), sServiceName, sal_True );
620 else
622 m_xBrowserController->attachFrame( m_xMeAsFrame );
623 m_xBrowserComponentWindow = m_xMeAsFrame->getComponentWindow();
624 DBG_ASSERT( m_xBrowserComponentWindow.is(), "FmPropBrw::impl_createPropertyBrowser_throw: attached the controller, but have no component window!" );
627 if ( bEnableHelpSection )
629 Reference< XObjectInspector > xInspector( m_xBrowserController, UNO_QUERY_THROW );
630 Reference< XObjectInspectorUI > xInspectorUI( xInspector->getInspectorUI() );
631 Reference< XInterface > xDefaultHelpProvider( DefaultHelpProvider::create( m_xInspectorContext, xInspectorUI ) );
635 //-----------------------------------------------------------------------
636 void FmPropBrw::impl_ensurePropertyBrowser_nothrow( FmFormShell* _pFormShell )
638 // the document in which we live
639 Reference< XInterface > xDocument;
640 SfxObjectShell* pObjectShell = _pFormShell ? _pFormShell->GetObjectShell() : NULL;
641 if ( pObjectShell )
642 xDocument = pObjectShell->GetModel();
643 if ( ( xDocument == m_xLastKnownDocument ) && m_xBrowserController.is() )
644 // nothing to do
645 return;
649 // clean up any previous instances of the object inspector
650 if ( m_xMeAsFrame.is() )
651 m_xMeAsFrame->setComponent( NULL, NULL );
652 else
653 ::comphelper::disposeComponent( m_xBrowserController );
654 m_xBrowserController.clear();
655 m_xInspectorModel.clear();
656 m_xBrowserComponentWindow.clear();
658 // and create a new one
659 impl_createPropertyBrowser_throw( _pFormShell );
661 catch( const Exception& )
663 DBG_UNHANDLED_EXCEPTION();
665 m_xLastKnownDocument = xDocument;
668 //-----------------------------------------------------------------------
669 void FmPropBrw::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
673 if (!pState || SID_FM_PROPERTY_CONTROL != nSID)
674 return;
676 if (eState >= SFX_ITEM_AVAILABLE)
678 FmFormShell* pShell = PTR_CAST(FmFormShell,((SfxObjectItem*)pState)->GetShell());
679 InterfaceBag aSelection;
680 if ( pShell )
681 pShell->GetImpl()->getCurrentSelection( aSelection );
683 impl_ensurePropertyBrowser_nothrow( pShell );
685 // set the new object to inspect
686 implSetNewSelection( aSelection );
688 // if this is the first time we're here, some additional things need to be done ...
689 if ( m_bInitialStateChange )
691 // if we're just newly created, we want to have the focus
692 PostUserEvent( LINK( this, FmPropBrw, OnAsyncGetFocus ) );
694 // and additionally, we want to show the page which was active during
695 // our previous incarnation
696 if ( m_sLastActivePage.getLength() )
700 if ( m_xBrowserController.is() )
701 m_xBrowserController->restoreViewData( makeAny( m_sLastActivePage ) );
703 catch( const Exception& )
705 OSL_ENSURE( sal_False, "FmPropBrw::StateChanged: caught an exception while setting the initial page!" );
709 m_bInitialStateChange = sal_False;
713 else
715 implSetNewSelection( InterfaceBag() );
718 catch (Exception&)
720 DBG_ERROR("FmPropBrw::StateChanged: Exception occured!");