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