1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "propbrw.hxx"
22 #include "basidesh.hxx"
23 #include "dlgedobj.hxx"
25 #include "baside3.hxx"
27 #include "dlgresid.hrc"
28 #include <svx/svxids.hrc>
30 #include <com/sun/star/awt/PosSize.hpp>
31 #include <com/sun/star/frame/Frame.hpp>
32 #include <com/sun/star/inspection/XObjectInspector.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <comphelper/types.hxx>
35 #include <cppuhelper/component_context.hxx>
36 #include <svx/svditer.hxx>
37 #include <svx/svdview.hxx>
38 #include <toolkit/unohlp.hxx>
39 #include <tools/diagnose_ex.h>
40 #include <vcl/stdtext.hxx>
42 #include <boost/scoped_ptr.hpp>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::lang
;
50 using namespace ::com::sun::star::frame
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::container
;
53 using namespace ::comphelper
;
56 void PropBrw::Update( const SfxViewShell
* pShell
)
58 Shell
const* pIdeShell
= dynamic_cast<Shell
const*>(pShell
);
59 OSL_ENSURE( pIdeShell
|| !pShell
, "PropBrw::Update: invalid shell!" );
61 ImplUpdate(pIdeShell
->GetCurrentDocument(), pIdeShell
->GetCurDlgView());
63 ImplUpdate(NULL
, pShell
->GetDrawView());
65 ImplUpdate(NULL
, NULL
);
72 const long STD_WIN_SIZE_X
= 300;
73 const long STD_WIN_SIZE_Y
= 350;
75 const long STD_MIN_SIZE_X
= 250;
76 const long STD_MIN_SIZE_Y
= 250;
78 const long WIN_BORDER
= 2;
86 PropBrw::PropBrw (DialogWindowLayout
& rLayout_
):
87 DockingWindow(&rLayout_
),
88 m_bInitialStateChange(true),
89 m_xContextDocument(SfxViewShell::Current() ? SfxViewShell::Current()->GetCurrentDocument() : Reference
<XModel
>()),
93 DBG_CTOR(PropBrw
,NULL
);
95 Size
aPropWinSize(STD_WIN_SIZE_X
,STD_WIN_SIZE_Y
);
96 SetMinOutputSizePixel(Size(STD_MIN_SIZE_X
,STD_MIN_SIZE_Y
));
97 SetOutputSizePixel(aPropWinSize
);
101 // create a frame wrapper for myself
102 m_xMeAsFrame
= frame::Frame::create( comphelper::getProcessComponentContext() );
103 m_xMeAsFrame
->initialize( VCLUnoHelper::GetInterface ( this ) );
104 m_xMeAsFrame
->setName( "form property browser" ); // change name!
106 catch (const Exception
&)
108 OSL_FAIL("PropBrw::PropBrw: could not create/initialize my frame!");
109 m_xMeAsFrame
.clear();
112 ImplReCreateController();
116 void PropBrw::ImplReCreateController()
118 OSL_PRECOND( m_xMeAsFrame
.is(), "PropBrw::ImplCreateController: no frame for myself!" );
119 if ( !m_xMeAsFrame
.is() )
122 if ( m_xBrowserController
.is() )
123 ImplDestroyController();
127 Reference
< XComponentContext
> xOwnContext
= comphelper::getProcessComponentContext();
129 // a ComponentContext for the
130 ::cppu::ContextEntry_Init aHandlerContextInfo
[] =
132 ::cppu::ContextEntry_Init( "DialogParentWindow", makeAny( VCLUnoHelper::GetInterface ( this ) ) ),
133 ::cppu::ContextEntry_Init( "ContextDocument", makeAny( m_xContextDocument
) )
135 Reference
< XComponentContext
> xInspectorContext(
136 ::cppu::createComponentContext( aHandlerContextInfo
, SAL_N_ELEMENTS( aHandlerContextInfo
), xOwnContext
) );
138 // create a property browser controller
139 Reference
< XMultiComponentFactory
> xFactory( xInspectorContext
->getServiceManager(), UNO_QUERY_THROW
);
140 static const OUString
s_sControllerServiceName( "com.sun.star.awt.PropertyBrowserController" );
141 m_xBrowserController
= Reference
< XPropertySet
>(
142 xFactory
->createInstanceWithContext( s_sControllerServiceName
, xInspectorContext
), UNO_QUERY
144 if ( !m_xBrowserController
.is() )
146 ShowServiceNotAvailableError( GetParent(), s_sControllerServiceName
, true );
150 Reference
< XController
> xAsXController( m_xBrowserController
, UNO_QUERY
);
151 DBG_ASSERT(xAsXController
.is(), "PropBrw::PropBrw: invalid controller object!");
152 if (!xAsXController
.is())
154 ::comphelper::disposeComponent(m_xBrowserController
);
155 m_xBrowserController
.clear();
159 xAsXController
->attachFrame( Reference
<XFrame
>(m_xMeAsFrame
,UNO_QUERY_THROW
) );
160 m_xBrowserComponentWindow
= m_xMeAsFrame
->getComponentWindow();
161 DBG_ASSERT(m_xBrowserComponentWindow
.is(), "PropBrw::PropBrw: attached the controller, but have no component window!");
165 Point aPropWinPos
= Point( WIN_BORDER
, WIN_BORDER
);
166 Size
aPropWinSize(STD_WIN_SIZE_X
,STD_WIN_SIZE_Y
);
167 aPropWinSize
.Width() -= (2*WIN_BORDER
);
168 aPropWinSize
.Height() -= (2*WIN_BORDER
);
170 if ( m_xBrowserComponentWindow
.is() )
172 m_xBrowserComponentWindow
->setPosSize(aPropWinPos
.X(), aPropWinPos
.Y(), aPropWinSize
.Width(), aPropWinSize
.Height(),
173 ::com::sun::star::awt::PosSize::WIDTH
| ::com::sun::star::awt::PosSize::HEIGHT
|
174 ::com::sun::star::awt::PosSize::X
| ::com::sun::star::awt::PosSize::Y
);
175 m_xBrowserComponentWindow
->setVisible(true);
178 catch (const Exception
&)
180 OSL_FAIL("PropBrw::PropBrw: could not create/initialize the browser controller!");
183 ::comphelper::disposeComponent(m_xBrowserController
);
184 ::comphelper::disposeComponent(m_xBrowserComponentWindow
);
186 catch(const Exception
&)
190 m_xBrowserController
.clear();
191 m_xBrowserComponentWindow
.clear();
200 if ( m_xBrowserController
.is() )
201 ImplDestroyController();
203 DBG_DTOR(PropBrw
,NULL
);
207 void PropBrw::ImplDestroyController()
209 implSetNewObject( Reference
< XPropertySet
>() );
211 if ( m_xMeAsFrame
.is() )
212 m_xMeAsFrame
->setComponent( NULL
, NULL
);
214 Reference
< XController
> xAsXController( m_xBrowserController
, UNO_QUERY
);
215 if ( xAsXController
.is() )
216 xAsXController
->attachFrame( NULL
);
220 ::comphelper::disposeComponent( m_xBrowserController
);
222 catch( const Exception
& )
224 DBG_UNHANDLED_EXCEPTION();
227 m_xBrowserController
.clear();
231 sal_Bool
PropBrw::Close()
233 ImplDestroyController();
238 return DockingWindow::Close();
242 Sequence
< Reference
< XInterface
> >
243 PropBrw::CreateMultiSelectionSequence( const SdrMarkList
& _rMarkList
)
245 Sequence
< Reference
< XInterface
> > aSeq
;
246 InterfaceArray aInterfaces
;
248 sal_uInt32 nMarkCount
= _rMarkList
.GetMarkCount();
249 for( sal_uInt32 i
= 0 ; i
< nMarkCount
; i
++ )
251 SdrObject
* pCurrent
= _rMarkList
.GetMark(i
)->GetMarkedSdrObj();
253 boost::scoped_ptr
<SdrObjListIter
> pGroupIterator
;
254 if (pCurrent
->IsGroupObject())
256 pGroupIterator
.reset(new SdrObjListIter(*pCurrent
->GetSubList()));
257 pCurrent
= pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
262 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pCurrent
))
264 Reference
< XInterface
> xControlInterface(pDlgEdObj
->GetUnoControlModel(), UNO_QUERY
);
265 if (xControlInterface
.is())
266 aInterfaces
.push_back(xControlInterface
);
270 pCurrent
= pGroupIterator
&& pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
274 sal_Int32 nCount
= aInterfaces
.size();
275 aSeq
.realloc( nCount
);
276 Reference
< XInterface
>* pInterfaces
= aSeq
.getArray();
277 for( sal_Int32 i
= 0 ; i
< nCount
; i
++ )
278 pInterfaces
[i
] = aInterfaces
[i
];
284 void PropBrw::implSetNewObjectSequence
285 ( const Sequence
< Reference
< XInterface
> >& _rObjectSeq
)
287 Reference
< inspection::XObjectInspector
> xObjectInspector(m_xBrowserController
, UNO_QUERY
);
288 if ( xObjectInspector
.is() )
290 xObjectInspector
->inspect( _rObjectSeq
);
292 OUString aText
= IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES
);
293 aText
+= IDE_RESSTR(RID_STR_BRWTITLE_MULTISELECT
);
299 void PropBrw::implSetNewObject( const Reference
< XPropertySet
>& _rxObject
)
301 if ( m_xBrowserController
.is() )
303 m_xBrowserController
->setPropertyValue( "IntrospectedObject",
307 // set the new title according to the selected object
308 SetText( GetHeadlineName( _rxObject
) );
313 OUString
PropBrw::GetHeadlineName( const Reference
< XPropertySet
>& _rxObject
)
316 Reference
< lang::XServiceInfo
> xServiceInfo( _rxObject
, UNO_QUERY
);
318 if (xServiceInfo
.is()) // single selection
320 sal_uInt16 nResId
= 0;
321 aName
= IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES
);
323 if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
325 nResId
= RID_STR_CLASS_DIALOG
;
327 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
329 nResId
= RID_STR_CLASS_BUTTON
;
331 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
333 nResId
= RID_STR_CLASS_RADIOBUTTON
;
335 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
337 nResId
= RID_STR_CLASS_CHECKBOX
;
339 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
341 nResId
= RID_STR_CLASS_LISTBOX
;
343 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
345 nResId
= RID_STR_CLASS_COMBOBOX
;
347 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
349 nResId
= RID_STR_CLASS_GROUPBOX
;
351 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
353 nResId
= RID_STR_CLASS_EDIT
;
355 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
357 nResId
= RID_STR_CLASS_FIXEDTEXT
;
359 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
361 nResId
= RID_STR_CLASS_IMAGECONTROL
;
363 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
365 nResId
= RID_STR_CLASS_PROGRESSBAR
;
367 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
369 nResId
= RID_STR_CLASS_SCROLLBAR
;
371 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
373 nResId
= RID_STR_CLASS_FIXEDLINE
;
375 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
377 nResId
= RID_STR_CLASS_DATEFIELD
;
379 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
381 nResId
= RID_STR_CLASS_TIMEFIELD
;
383 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
385 nResId
= RID_STR_CLASS_NUMERICFIELD
;
387 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
389 nResId
= RID_STR_CLASS_CURRENCYFIELD
;
391 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
393 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
395 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
397 nResId
= RID_STR_CLASS_PATTERNFIELD
;
399 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
401 nResId
= RID_STR_CLASS_FILECONTROL
;
403 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
405 nResId
= RID_STR_CLASS_TREECONTROL
;
409 nResId
= RID_STR_CLASS_CONTROL
;
414 aName
+= IDE_RESSTR(nResId
);
417 else if (!_rxObject
.is()) // no properties
419 aName
= IDE_RESSTR(RID_STR_BRWTITLE_NO_PROPERTIES
);
426 void PropBrw::Resize()
428 DockingWindow::Resize();
431 Size aSize_
= GetOutputSizePixel();
432 Size
aPropWinSize( aSize_
);
433 aPropWinSize
.Width() -= (2*WIN_BORDER
);
434 aPropWinSize
.Height() -= (2*WIN_BORDER
);
436 if (m_xBrowserComponentWindow
.is())
438 m_xBrowserComponentWindow
->setPosSize(0, 0, aPropWinSize
.Width(), aPropWinSize
.Height(),
439 ::com::sun::star::awt::PosSize::WIDTH
| ::com::sun::star::awt::PosSize::HEIGHT
);
444 void PropBrw::ImplUpdate( const Reference
< XModel
>& _rxContextDocument
, SdrView
* pNewView
)
446 Reference
< XModel
> xContextDocument( _rxContextDocument
);
448 // if we should simply "empty" ourself, assume the context document didn't change
451 OSL_ENSURE( !_rxContextDocument
.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
452 xContextDocument
= m_xContextDocument
;
455 if ( xContextDocument
!= m_xContextDocument
)
457 m_xContextDocument
= xContextDocument
;
458 ImplReCreateController();
465 EndListening( *(pView
->GetModel()) );
474 // set focus on initialization
475 if ( m_bInitialStateChange
)
477 if ( m_xBrowserComponentWindow
.is() )
478 m_xBrowserComponentWindow
->setFocus();
479 m_bInitialStateChange
= false;
482 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
483 sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
485 if ( nMarkCount
== 0 )
487 EndListening( *(pView
->GetModel()) );
489 implSetNewObject( NULL
);
493 Reference
< XPropertySet
> xNewObject
;
494 Sequence
< Reference
< XInterface
> > aNewObjects
;
495 if ( nMarkCount
== 1 )
497 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(rMarkList
.GetMark(0)->GetMarkedSdrObj()))
499 if ( pDlgEdObj
->IsGroupObject() ) // group object
500 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
501 else // single selection
502 xNewObject
= xNewObject
.query( pDlgEdObj
->GetUnoControlModel() );
505 else if ( nMarkCount
> 1 ) // multiple selection
507 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
510 if ( aNewObjects
.getLength() )
511 implSetNewObjectSequence( aNewObjects
);
513 implSetNewObject( xNewObject
);
515 StartListening( *(pView
->GetModel()) );
517 catch ( const PropertyVetoException
& ) { /* silence */ }
518 catch ( const Exception
& )
520 DBG_UNHANDLED_EXCEPTION();
524 } // namespace basctl
526 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */