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/helper/vclunohelper.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;
82 PropBrw::PropBrw (DialogWindowLayout
& rLayout_
):
83 DockingWindow(&rLayout_
),
84 m_bInitialStateChange(true),
85 m_xContextDocument(SfxViewShell::Current() ? SfxViewShell::Current()->GetCurrentDocument() : Reference
<XModel
>()),
88 Size
aPropWinSize(STD_WIN_SIZE_X
,STD_WIN_SIZE_Y
);
89 SetMinOutputSizePixel(Size(STD_MIN_SIZE_X
,STD_MIN_SIZE_Y
));
90 SetOutputSizePixel(aPropWinSize
);
94 // create a frame wrapper for myself
95 m_xMeAsFrame
= frame::Frame::create( comphelper::getProcessComponentContext() );
96 m_xMeAsFrame
->initialize( VCLUnoHelper::GetInterface ( this ) );
97 m_xMeAsFrame
->setName( "form property browser" ); // change name!
99 catch (const Exception
&)
101 OSL_FAIL("PropBrw::PropBrw: could not create/initialize my frame!");
102 m_xMeAsFrame
.clear();
105 ImplReCreateController();
109 void PropBrw::ImplReCreateController()
111 OSL_PRECOND( m_xMeAsFrame
.is(), "PropBrw::ImplCreateController: no frame for myself!" );
112 if ( !m_xMeAsFrame
.is() )
115 if ( m_xBrowserController
.is() )
116 ImplDestroyController();
120 Reference
< XComponentContext
> xOwnContext
= comphelper::getProcessComponentContext();
122 // a ComponentContext for the
123 ::cppu::ContextEntry_Init aHandlerContextInfo
[] =
125 ::cppu::ContextEntry_Init( "DialogParentWindow", makeAny( VCLUnoHelper::GetInterface ( this ) ) ),
126 ::cppu::ContextEntry_Init( "ContextDocument", makeAny( m_xContextDocument
) )
128 Reference
< XComponentContext
> xInspectorContext(
129 ::cppu::createComponentContext( aHandlerContextInfo
, SAL_N_ELEMENTS( aHandlerContextInfo
), xOwnContext
) );
131 // create a property browser controller
132 Reference
< XMultiComponentFactory
> xFactory( xInspectorContext
->getServiceManager(), UNO_QUERY_THROW
);
133 static const char s_sControllerServiceName
[] = "com.sun.star.awt.PropertyBrowserController";
134 m_xBrowserController
= Reference
< XPropertySet
>(
135 xFactory
->createInstanceWithContext( s_sControllerServiceName
, xInspectorContext
), UNO_QUERY
137 if ( !m_xBrowserController
.is() )
139 ShowServiceNotAvailableError( GetParent(), s_sControllerServiceName
, true );
143 Reference
< XController
> xAsXController( m_xBrowserController
, UNO_QUERY
);
144 DBG_ASSERT(xAsXController
.is(), "PropBrw::PropBrw: invalid controller object!");
145 if (!xAsXController
.is())
147 ::comphelper::disposeComponent(m_xBrowserController
);
148 m_xBrowserController
.clear();
152 xAsXController
->attachFrame( Reference
<XFrame
>(m_xMeAsFrame
,UNO_QUERY_THROW
) );
153 m_xBrowserComponentWindow
= m_xMeAsFrame
->getComponentWindow();
154 DBG_ASSERT(m_xBrowserComponentWindow
.is(), "PropBrw::PropBrw: attached the controller, but have no component window!");
158 Point aPropWinPos
= Point( WIN_BORDER
, WIN_BORDER
);
159 Size
aPropWinSize(STD_WIN_SIZE_X
,STD_WIN_SIZE_Y
);
160 aPropWinSize
.Width() -= (2*WIN_BORDER
);
161 aPropWinSize
.Height() -= (2*WIN_BORDER
);
163 if ( m_xBrowserComponentWindow
.is() )
165 m_xBrowserComponentWindow
->setPosSize(aPropWinPos
.X(), aPropWinPos
.Y(), aPropWinSize
.Width(), aPropWinSize
.Height(),
166 ::com::sun::star::awt::PosSize::WIDTH
| ::com::sun::star::awt::PosSize::HEIGHT
|
167 ::com::sun::star::awt::PosSize::X
| ::com::sun::star::awt::PosSize::Y
);
168 m_xBrowserComponentWindow
->setVisible(true);
171 catch (const Exception
&)
173 OSL_FAIL("PropBrw::PropBrw: could not create/initialize the browser controller!");
176 ::comphelper::disposeComponent(m_xBrowserController
);
177 ::comphelper::disposeComponent(m_xBrowserComponentWindow
);
179 catch(const Exception
&)
183 m_xBrowserController
.clear();
184 m_xBrowserComponentWindow
.clear();
196 void PropBrw::dispose()
198 if ( m_xBrowserController
.is() )
199 ImplDestroyController();
200 DockingWindow::dispose();
204 void PropBrw::ImplDestroyController()
206 implSetNewObject( Reference
< XPropertySet
>() );
208 if ( m_xMeAsFrame
.is() )
209 m_xMeAsFrame
->setComponent( NULL
, NULL
);
211 Reference
< XController
> xAsXController( m_xBrowserController
, UNO_QUERY
);
212 if ( xAsXController
.is() )
213 xAsXController
->attachFrame( NULL
);
217 ::comphelper::disposeComponent( m_xBrowserController
);
219 catch( const Exception
& )
221 DBG_UNHANDLED_EXCEPTION();
224 m_xBrowserController
.clear();
228 bool PropBrw::Close()
230 ImplDestroyController();
235 return DockingWindow::Close();
239 Sequence
< Reference
< XInterface
> >
240 PropBrw::CreateMultiSelectionSequence( const SdrMarkList
& _rMarkList
)
242 Sequence
< Reference
< XInterface
> > aSeq
;
243 InterfaceArray aInterfaces
;
245 const size_t nMarkCount
= _rMarkList
.GetMarkCount();
246 for( size_t i
= 0 ; i
< nMarkCount
; ++i
)
248 SdrObject
* pCurrent
= _rMarkList
.GetMark(i
)->GetMarkedSdrObj();
250 boost::scoped_ptr
<SdrObjListIter
> pGroupIterator
;
251 if (pCurrent
->IsGroupObject())
253 pGroupIterator
.reset(new SdrObjListIter(*pCurrent
->GetSubList()));
254 pCurrent
= pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
259 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pCurrent
))
261 Reference
< XInterface
> xControlInterface(pDlgEdObj
->GetUnoControlModel(), UNO_QUERY
);
262 if (xControlInterface
.is())
263 aInterfaces
.push_back(xControlInterface
);
267 pCurrent
= pGroupIterator
&& pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
271 sal_Int32 nCount
= aInterfaces
.size();
272 aSeq
.realloc( nCount
);
273 Reference
< XInterface
>* pInterfaces
= aSeq
.getArray();
274 for( sal_Int32 i
= 0 ; i
< nCount
; i
++ )
275 pInterfaces
[i
] = aInterfaces
[i
];
281 void PropBrw::implSetNewObjectSequence
282 ( const Sequence
< Reference
< XInterface
> >& _rObjectSeq
)
284 Reference
< inspection::XObjectInspector
> xObjectInspector(m_xBrowserController
, UNO_QUERY
);
285 if ( xObjectInspector
.is() )
287 xObjectInspector
->inspect( _rObjectSeq
);
289 OUString aText
= IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES
);
290 aText
+= IDE_RESSTR(RID_STR_BRWTITLE_MULTISELECT
);
296 void PropBrw::implSetNewObject( const Reference
< XPropertySet
>& _rxObject
)
298 if ( m_xBrowserController
.is() )
300 m_xBrowserController
->setPropertyValue( "IntrospectedObject",
304 // set the new title according to the selected object
305 SetText( GetHeadlineName( _rxObject
) );
310 OUString
PropBrw::GetHeadlineName( const Reference
< XPropertySet
>& _rxObject
)
313 Reference
< lang::XServiceInfo
> xServiceInfo( _rxObject
, UNO_QUERY
);
315 if (xServiceInfo
.is()) // single selection
317 sal_uInt16 nResId
= 0;
318 aName
= IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES
);
320 if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
322 nResId
= RID_STR_CLASS_DIALOG
;
324 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
326 nResId
= RID_STR_CLASS_BUTTON
;
328 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
330 nResId
= RID_STR_CLASS_RADIOBUTTON
;
332 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
334 nResId
= RID_STR_CLASS_CHECKBOX
;
336 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
338 nResId
= RID_STR_CLASS_LISTBOX
;
340 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
342 nResId
= RID_STR_CLASS_COMBOBOX
;
344 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
346 nResId
= RID_STR_CLASS_GROUPBOX
;
348 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
350 nResId
= RID_STR_CLASS_EDIT
;
352 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
354 nResId
= RID_STR_CLASS_FIXEDTEXT
;
356 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
358 nResId
= RID_STR_CLASS_IMAGECONTROL
;
360 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
362 nResId
= RID_STR_CLASS_PROGRESSBAR
;
364 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
366 nResId
= RID_STR_CLASS_SCROLLBAR
;
368 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
370 nResId
= RID_STR_CLASS_FIXEDLINE
;
372 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
374 nResId
= RID_STR_CLASS_DATEFIELD
;
376 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
378 nResId
= RID_STR_CLASS_TIMEFIELD
;
380 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
382 nResId
= RID_STR_CLASS_NUMERICFIELD
;
384 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
386 nResId
= RID_STR_CLASS_CURRENCYFIELD
;
388 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
390 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
392 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
394 nResId
= RID_STR_CLASS_PATTERNFIELD
;
396 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
398 nResId
= RID_STR_CLASS_FILECONTROL
;
400 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
402 nResId
= RID_STR_CLASS_TREECONTROL
;
406 nResId
= RID_STR_CLASS_CONTROL
;
411 aName
+= IDE_RESSTR(nResId
);
414 else if (!_rxObject
.is()) // no properties
416 aName
= IDE_RESSTR(RID_STR_BRWTITLE_NO_PROPERTIES
);
423 void PropBrw::Resize()
425 DockingWindow::Resize();
428 Size aSize_
= GetOutputSizePixel();
429 Size
aPropWinSize( aSize_
);
430 aPropWinSize
.Width() -= (2*WIN_BORDER
);
431 aPropWinSize
.Height() -= (2*WIN_BORDER
);
433 if (m_xBrowserComponentWindow
.is())
435 m_xBrowserComponentWindow
->setPosSize(0, 0, aPropWinSize
.Width(), aPropWinSize
.Height(),
436 ::com::sun::star::awt::PosSize::WIDTH
| ::com::sun::star::awt::PosSize::HEIGHT
);
441 void PropBrw::ImplUpdate( const Reference
< XModel
>& _rxContextDocument
, SdrView
* pNewView
)
443 Reference
< XModel
> xContextDocument( _rxContextDocument
);
445 // if we should simply "empty" ourself, assume the context document didn't change
448 OSL_ENSURE( !_rxContextDocument
.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
449 xContextDocument
= m_xContextDocument
;
452 if ( xContextDocument
!= m_xContextDocument
)
454 m_xContextDocument
= xContextDocument
;
455 ImplReCreateController();
462 EndListening( *(pView
->GetModel()) );
471 // set focus on initialization
472 if ( m_bInitialStateChange
)
474 if ( m_xBrowserComponentWindow
.is() )
475 m_xBrowserComponentWindow
->setFocus();
476 m_bInitialStateChange
= false;
479 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
480 const size_t nMarkCount
= rMarkList
.GetMarkCount();
482 if ( nMarkCount
== 0 )
484 EndListening( *(pView
->GetModel()) );
486 implSetNewObject( NULL
);
490 Reference
< XPropertySet
> xNewObject
;
491 Sequence
< Reference
< XInterface
> > aNewObjects
;
492 if ( nMarkCount
== 1 )
494 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(rMarkList
.GetMark(0)->GetMarkedSdrObj()))
496 if ( pDlgEdObj
->IsGroupObject() ) // group object
497 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
498 else // single selection
499 xNewObject
.set(pDlgEdObj
->GetUnoControlModel(), css::uno::UNO_QUERY
);
502 else if ( nMarkCount
> 1 ) // multiple selection
504 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
507 if ( aNewObjects
.getLength() )
508 implSetNewObjectSequence( aNewObjects
);
510 implSetNewObject( xNewObject
);
512 StartListening( *(pView
->GetModel()) );
514 catch ( const PropertyVetoException
& ) { /* silence */ }
515 catch ( const Exception
& )
517 DBG_UNHANDLED_EXCEPTION();
521 } // namespace basctl
523 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */