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