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