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