1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propbrw.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
35 #include "propbrw.hxx"
36 #include "dlgedobj.hxx"
38 #include "basidesh.hxx"
41 #ifndef _BASCTL_DLGRESID_HRC
42 #include <dlgresid.hrc>
44 #include <tools/debug.hxx>
45 #include <tools/diagnose_ex.h>
46 #include <sfx2/bindings.hxx>
47 #include <sfx2/childwin.hxx>
48 #include <sfx2/objitem.hxx>
50 #ifndef _SVX_SVXIDS_HRC
51 #include <svx/svxids.hrc>
53 #include <tools/shl.hxx>
54 #include <vcl/stdtext.hxx>
55 #include <svx/svdview.hxx>
56 #include <svx/svdogrp.hxx>
57 #include <svx/svdpage.hxx>
58 #include <svx/svditer.hxx>
59 #include <sfx2/viewsh.hxx>
61 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
62 #include <toolkit/unohlp.hxx>
64 #include <comphelper/property.hxx>
65 #include <comphelper/composedprops.hxx>
66 #include <comphelper/stl_types.hxx>
67 #include <comphelper/types.hxx>
68 #include <com/sun/star/beans/PropertyValue.hpp>
69 #include <com/sun/star/awt/PosSize.hpp>
70 #include <com/sun/star/lang/XServiceInfo.hpp>
71 #include <com/sun/star/inspection/XObjectInspector.hpp>
72 #include <comphelper/processfactory.hxx>
73 #include <cppuhelper/component_context.hxx>
75 #include <sfx2/dispatch.hxx>
76 #include <sfx2/viewfrm.hxx>
78 using namespace ::com::sun::star
;
79 using namespace ::com::sun::star::uno
;
80 using namespace ::com::sun::star::lang
;
81 using namespace ::com::sun::star::frame
;
82 using namespace ::com::sun::star::beans
;
83 using namespace ::com::sun::star::container
;
84 using namespace ::comphelper
;
86 //============================================================================
88 //============================================================================
90 SFX_IMPL_FLOATINGWINDOW(PropBrwMgr
, SID_SHOW_PROPERTYBROWSER
)
92 //----------------------------------------------------------------------------
94 PropBrwMgr::PropBrwMgr( Window
* _pParent
, sal_uInt16 nId
,
95 SfxBindings
*pBindings
, SfxChildWinInfo
* pInfo
)
96 :SfxChildWindow( _pParent
, nId
)
98 // set current selection
99 SfxViewShell
* pShell
= SfxViewShell::Current();
100 pWindow
= new PropBrw(
101 ::comphelper::getProcessServiceFactory(),
105 pShell
? pShell
->GetCurrentDocument() : Reference
< XModel
>()
108 eChildAlignment
= SFX_ALIGN_NOALIGNMENT
;
109 ((SfxFloatingWindow
*)pWindow
)->Initialize( pInfo
);
111 ((PropBrw
*)pWindow
)->Update( pShell
);
114 //----------------------------------------------------------------------------
115 void PropBrw::Update( const SfxViewShell
* _pShell
)
117 const BasicIDEShell
* pBasicIDEShell
= dynamic_cast< const BasicIDEShell
* >( _pShell
);
118 OSL_ENSURE( pBasicIDEShell
|| !_pShell
, "PropBrw::Update: invalid shell!" );
119 if ( pBasicIDEShell
)
121 ImplUpdate( pBasicIDEShell
->GetCurrentDocument(), pBasicIDEShell
->GetCurDlgView() );
125 ImplUpdate( NULL
, _pShell
->GetDrawView() );
129 ImplUpdate( NULL
, NULL
);
133 //----------------------------------------------------------------------------
135 const long STD_WIN_SIZE_X
= 300;
136 const long STD_WIN_SIZE_Y
= 350;
138 const long STD_MIN_SIZE_X
= 250;
139 const long STD_MIN_SIZE_Y
= 250;
141 const long STD_WIN_POS_X
= 50;
142 const long STD_WIN_POS_Y
= 50;
143 const long WIN_BORDER
= 2;
144 const long MIN_WIN_SIZE_X
= 50;
145 const long MIN_WIN_SIZE_Y
= 50;
147 //----------------------------------------------------------------------------
149 //============================================================================
151 //============================================================================
155 //----------------------------------------------------------------------------
157 PropBrw::PropBrw( const Reference
< XMultiServiceFactory
>& _xORB
, SfxBindings
* _pBindings
, PropBrwMgr
* _pMgr
, Window
* _pParent
,
158 const Reference
< XModel
>& _rxContextDocument
)
159 :SfxFloatingWindow( _pBindings
, _pMgr
, _pParent
, WinBits( WB_STDMODELESS
| WB_SIZEABLE
| WB_3DLOOK
| WB_ROLLABLE
) )
160 ,m_bInitialStateChange(sal_True
)
162 ,m_xContextDocument( _rxContextDocument
)
165 DBG_CTOR(PropBrw
,NULL
);
167 Size
aPropWinSize(STD_WIN_SIZE_X
,STD_WIN_SIZE_Y
);
168 SetMinOutputSizePixel(Size(STD_MIN_SIZE_X
,STD_MIN_SIZE_Y
));
169 SetOutputSizePixel(aPropWinSize
);
173 // create a frame wrapper for myself
174 m_xMeAsFrame
= Reference
< XFrame
>(m_xORB
->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Frame")), UNO_QUERY
);
175 if (m_xMeAsFrame
.is())
177 m_xMeAsFrame
->initialize( VCLUnoHelper::GetInterface ( this ) );
178 m_xMeAsFrame
->setName(::rtl::OUString::createFromAscii("form property browser")); // change name!
183 DBG_ERROR("PropBrw::PropBrw: could not create/initialize my frame!");
184 m_xMeAsFrame
.clear();
187 ImplReCreateController();
190 //----------------------------------------------------------------------------
192 void PropBrw::ImplReCreateController()
194 OSL_PRECOND( m_xMeAsFrame
.is(), "PropBrw::ImplCreateController: no frame for myself!" );
195 if ( !m_xMeAsFrame
.is() )
198 if ( m_xBrowserController
.is() )
199 ImplDestroyController();
203 Reference
< XPropertySet
> xFactoryProperties( m_xORB
, UNO_QUERY_THROW
);
204 Reference
< XComponentContext
> xOwnContext(
205 xFactoryProperties
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ),
208 // a ComponentContext for the
209 ::cppu::ContextEntry_Init aHandlerContextInfo
[] =
211 ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogParentWindow" ) ), makeAny( VCLUnoHelper::GetInterface ( this ) ) ),
212 ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContextDocument" ) ), makeAny( m_xContextDocument
) )
214 Reference
< XComponentContext
> xInspectorContext(
215 ::cppu::createComponentContext( aHandlerContextInfo
, sizeof( aHandlerContextInfo
) / sizeof( aHandlerContextInfo
[0] ),
218 // create a property browser controller
219 Reference
< XMultiComponentFactory
> xFactory( xInspectorContext
->getServiceManager(), UNO_QUERY_THROW
);
220 static const ::rtl::OUString s_sControllerServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.awt.PropertyBrowserController");
221 m_xBrowserController
= Reference
< XPropertySet
>(
222 xFactory
->createInstanceWithContext( s_sControllerServiceName
, xInspectorContext
), UNO_QUERY
224 if ( !m_xBrowserController
.is() )
226 ShowServiceNotAvailableError( GetParent(), s_sControllerServiceName
, sal_True
);
230 Reference
< XController
> xAsXController( m_xBrowserController
, UNO_QUERY
);
231 DBG_ASSERT(xAsXController
.is(), "PropBrw::PropBrw: invalid controller object!");
232 if (!xAsXController
.is())
234 ::comphelper::disposeComponent(m_xBrowserController
);
235 m_xBrowserController
.clear();
239 xAsXController
->attachFrame(m_xMeAsFrame
);
240 m_xBrowserComponentWindow
= m_xMeAsFrame
->getComponentWindow();
241 DBG_ASSERT(m_xBrowserComponentWindow
.is(), "PropBrw::PropBrw: attached the controller, but have no component window!");
245 Point aPropWinPos
= Point( WIN_BORDER
, WIN_BORDER
);
246 Size
aPropWinSize(STD_WIN_SIZE_X
,STD_WIN_SIZE_Y
);
247 aPropWinSize
.Width() -= (2*WIN_BORDER
);
248 aPropWinSize
.Height() -= (2*WIN_BORDER
);
250 if ( m_xBrowserComponentWindow
.is() )
252 m_xBrowserComponentWindow
->setPosSize(aPropWinPos
.X(), aPropWinPos
.Y(), aPropWinSize
.Width(), aPropWinSize
.Height(),
253 ::com::sun::star::awt::PosSize::WIDTH
| ::com::sun::star::awt::PosSize::HEIGHT
|
254 ::com::sun::star::awt::PosSize::X
| ::com::sun::star::awt::PosSize::Y
);
255 m_xBrowserComponentWindow
->setVisible(sal_True
);
260 DBG_ERROR("PropBrw::PropBrw: could not create/initialize the browser controller!");
263 ::comphelper::disposeComponent(m_xBrowserController
);
264 ::comphelper::disposeComponent(m_xBrowserComponentWindow
);
270 m_xBrowserController
.clear();
271 m_xBrowserComponentWindow
.clear();
277 //----------------------------------------------------------------------------
281 if ( m_xBrowserController
.is() )
282 ImplDestroyController();
284 DBG_DTOR(PropBrw
,NULL
);
287 //----------------------------------------------------------------------------
289 void PropBrw::ImplDestroyController()
291 implSetNewObject( Reference
< XPropertySet
>() );
293 if ( m_xMeAsFrame
.is() )
294 m_xMeAsFrame
->setComponent( NULL
, NULL
);
296 Reference
< XController
> xAsXController( m_xBrowserController
, UNO_QUERY
);
297 if ( xAsXController
.is() )
298 xAsXController
->attachFrame( NULL
);
302 ::comphelper::disposeComponent( m_xBrowserController
);
304 catch( const Exception
& )
306 DBG_UNHANDLED_EXCEPTION();
309 m_xBrowserController
.clear();
312 //----------------------------------------------------------------------------
314 sal_Bool
PropBrw::Close()
316 ImplDestroyController();
321 sal_Bool bClose
= SfxFloatingWindow::Close();
326 //----------------------------------------------------------------------------
327 Sequence
< Reference
< XInterface
> >
328 PropBrw::CreateMultiSelectionSequence( const SdrMarkList
& _rMarkList
)
330 Sequence
< Reference
< XInterface
> > aSeq
;
331 InterfaceArray aInterfaces
;
333 sal_uInt32 nMarkCount
= _rMarkList
.GetMarkCount();
334 for( sal_uInt32 i
= 0 ; i
< nMarkCount
; i
++ )
336 SdrObject
* pCurrent
= _rMarkList
.GetMark(i
)->GetMarkedSdrObj();
338 SdrObjListIter
* pGroupIterator
= NULL
;
339 if (pCurrent
->IsGroupObject())
341 pGroupIterator
= new SdrObjListIter(*pCurrent
->GetSubList());
342 pCurrent
= pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
347 DlgEdObj
* pDlgEdObj
= PTR_CAST(DlgEdObj
, pCurrent
);
350 Reference
< XInterface
> xControlInterface(pDlgEdObj
->GetUnoControlModel(), UNO_QUERY
);
351 if (xControlInterface
.is())
352 aInterfaces
.push_back(xControlInterface
);
356 pCurrent
= pGroupIterator
&& pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
359 delete pGroupIterator
;
362 sal_Int32 nCount
= aInterfaces
.size();
363 aSeq
.realloc( nCount
);
364 Reference
< XInterface
>* pInterfaces
= aSeq
.getArray();
365 for( sal_Int32 i
= 0 ; i
< nCount
; i
++ )
366 pInterfaces
[i
] = aInterfaces
[i
];
371 //----------------------------------------------------------------------------
372 void PropBrw::implSetNewObjectSequence
373 ( const Sequence
< Reference
< XInterface
> >& _rObjectSeq
)
375 Reference
< inspection::XObjectInspector
> xObjectInspector(m_xBrowserController
, UNO_QUERY
);
376 if ( xObjectInspector
.is() )
378 xObjectInspector
->inspect( _rObjectSeq
);
380 ::rtl::OUString aText
= ::rtl::OUString(String(IDEResId(RID_STR_BRWTITLE_PROPERTIES
)));
381 aText
+= ::rtl::OUString(String(IDEResId(RID_STR_BRWTITLE_MULTISELECT
)));
386 //----------------------------------------------------------------------------
388 void PropBrw::implSetNewObject( const Reference
< XPropertySet
>& _rxObject
)
390 if ( m_xBrowserController
.is() )
392 m_xBrowserController
->setPropertyValue(
393 ::rtl::OUString::createFromAscii( "IntrospectedObject" ),
397 // set the new title according to the selected object
398 SetText( GetHeadlineName( _rxObject
) );
402 //----------------------------------------------------------------------------
404 ::rtl::OUString
PropBrw::GetHeadlineName( const Reference
< XPropertySet
>& _rxObject
)
406 ::rtl::OUString aName
;
407 Reference
< lang::XServiceInfo
> xServiceInfo( _rxObject
, UNO_QUERY
);
409 if (xServiceInfo
.is()) // single selection
411 sal_uInt16 nResId
= 0;
412 aName
= ::rtl::OUString(String(IDEResId(RID_STR_BRWTITLE_PROPERTIES
)));
414 if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ) )
416 nResId
= RID_STR_CLASS_DIALOG
;
418 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ) )
420 nResId
= RID_STR_CLASS_BUTTON
;
422 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRadioButtonModel" ) ) ) )
424 nResId
= RID_STR_CLASS_RADIOBUTTON
;
426 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCheckBoxModel" ) ) ) )
428 nResId
= RID_STR_CLASS_CHECKBOX
;
430 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlListBoxModel" ) ) ) )
432 nResId
= RID_STR_CLASS_LISTBOX
;
434 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlComboBoxModel" ) ) ) )
436 nResId
= RID_STR_CLASS_COMBOBOX
;
438 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlGroupBoxModel" ) ) ) )
440 nResId
= RID_STR_CLASS_GROUPBOX
;
442 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlEditModel" ) ) ) )
444 nResId
= RID_STR_CLASS_EDIT
;
446 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedTextModel" ) ) ) )
448 nResId
= RID_STR_CLASS_FIXEDTEXT
;
450 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlImageControlModel" ) ) ) )
452 nResId
= RID_STR_CLASS_IMAGECONTROL
;
454 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlProgressBarModel" ) ) ) )
456 nResId
= RID_STR_CLASS_PROGRESSBAR
;
458 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlScrollBarModel" ) ) ) )
460 nResId
= RID_STR_CLASS_SCROLLBAR
;
462 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedLineModel" ) ) ) )
464 nResId
= RID_STR_CLASS_FIXEDLINE
;
466 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDateFieldModel" ) ) ) )
468 nResId
= RID_STR_CLASS_DATEFIELD
;
470 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlTimeFieldModel" ) ) ) )
472 nResId
= RID_STR_CLASS_TIMEFIELD
;
474 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlNumericFieldModel" ) ) ) )
476 nResId
= RID_STR_CLASS_NUMERICFIELD
;
478 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) ) ) )
480 nResId
= RID_STR_CLASS_CURRENCYFIELD
;
482 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFormattedFieldModel" ) ) ) )
484 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
486 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlPatternFieldModel" ) ) ) )
488 nResId
= RID_STR_CLASS_PATTERNFIELD
;
490 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFileControlModel" ) ) ) )
492 nResId
= RID_STR_CLASS_FILECONTROL
;
494 else if ( xServiceInfo
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.tree.TreeControlModel" ) ) ) )
496 nResId
= RID_STR_CLASS_TREECONTROL
;
500 nResId
= RID_STR_CLASS_CONTROL
;
505 aName
+= ::rtl::OUString( String(IDEResId(nResId
)) );
508 else if (!_rxObject
.is()) // no properties
510 aName
= ::rtl::OUString(String(IDEResId(RID_STR_BRWTITLE_NO_PROPERTIES
)));
512 // #i73075 Handled in implSetNewObjectSequence
513 //else // multiselection
515 // aName = ::rtl::OUString(String(IDEResId(RID_STR_BRWTITLE_PROPERTIES)));
516 // aName += ::rtl::OUString(String(IDEResId(RID_STR_BRWTITLE_MULTISELECT)));
522 //----------------------------------------------------------------------------
524 void PropBrw::FillInfo( SfxChildWinInfo
& rInfo
) const
526 rInfo
.bVisible
= sal_False
;
529 //----------------------------------------------------------------------------
531 void PropBrw::Resize()
533 SfxFloatingWindow::Resize();
536 Size aSize_
= GetOutputSizePixel();
537 Size
aPropWinSize( aSize_
);
538 aPropWinSize
.Width() -= (2*WIN_BORDER
);
539 aPropWinSize
.Height() -= (2*WIN_BORDER
);
541 if (m_xBrowserComponentWindow
.is())
543 m_xBrowserComponentWindow
->setPosSize(0, 0, aPropWinSize
.Width(), aPropWinSize
.Height(),
544 ::com::sun::star::awt::PosSize::WIDTH
| ::com::sun::star::awt::PosSize::HEIGHT
);
548 //----------------------------------------------------------------------------
550 void PropBrw::ImplUpdate( const Reference
< XModel
>& _rxContextDocument
, SdrView
* pNewView
)
552 Reference
< XModel
> xContextDocument( _rxContextDocument
);
554 // if we should simply "empty" ourself, assume the context document didn't change
557 OSL_ENSURE( !_rxContextDocument
.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
558 xContextDocument
= m_xContextDocument
;
561 if ( xContextDocument
!= m_xContextDocument
)
563 m_xContextDocument
= xContextDocument
;
564 ImplReCreateController();
571 EndListening( *(pView
->GetModel()) );
580 // set focus on initialization
581 if ( m_bInitialStateChange
)
583 if ( m_xBrowserComponentWindow
.is() )
584 m_xBrowserComponentWindow
->setFocus();
585 m_bInitialStateChange
= sal_False
;
588 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
589 sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
591 if ( nMarkCount
== 0 )
593 EndListening( *(pView
->GetModel()) );
595 implSetNewObject( NULL
);
599 Reference
< XPropertySet
> xNewObject
;
600 Sequence
< Reference
< XInterface
> > aNewObjects
;
601 if ( nMarkCount
== 1 )
603 DlgEdObj
* pDlgEdObj
= PTR_CAST( DlgEdObj
, rMarkList
.GetMark(0)->GetMarkedSdrObj() );
606 if ( pDlgEdObj
->IsGroupObject() ) // group object
607 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
608 else // single selection
609 xNewObject
= xNewObject
.query( pDlgEdObj
->GetUnoControlModel() );
612 else if ( nMarkCount
> 1 ) // multiple selection
614 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
617 if ( aNewObjects
.getLength() )
618 implSetNewObjectSequence( aNewObjects
);
620 implSetNewObject( xNewObject
);
622 StartListening( *(pView
->GetModel()) );
624 catch ( const PropertyVetoException
& ) { /* silence */ }
625 catch ( const Exception
& )
627 DBG_UNHANDLED_EXCEPTION();
631 //----------------------------------------------------------------------------