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 OUString
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();
193 if ( m_xBrowserController
.is() )
194 ImplDestroyController();
198 void PropBrw::ImplDestroyController()
200 implSetNewObject( Reference
< XPropertySet
>() );
202 if ( m_xMeAsFrame
.is() )
203 m_xMeAsFrame
->setComponent( NULL
, NULL
);
205 Reference
< XController
> xAsXController( m_xBrowserController
, UNO_QUERY
);
206 if ( xAsXController
.is() )
207 xAsXController
->attachFrame( NULL
);
211 ::comphelper::disposeComponent( m_xBrowserController
);
213 catch( const Exception
& )
215 DBG_UNHANDLED_EXCEPTION();
218 m_xBrowserController
.clear();
222 bool PropBrw::Close()
224 ImplDestroyController();
229 return DockingWindow::Close();
233 Sequence
< Reference
< XInterface
> >
234 PropBrw::CreateMultiSelectionSequence( const SdrMarkList
& _rMarkList
)
236 Sequence
< Reference
< XInterface
> > aSeq
;
237 InterfaceArray aInterfaces
;
239 sal_uInt32 nMarkCount
= _rMarkList
.GetMarkCount();
240 for( sal_uInt32 i
= 0 ; i
< nMarkCount
; i
++ )
242 SdrObject
* pCurrent
= _rMarkList
.GetMark(i
)->GetMarkedSdrObj();
244 boost::scoped_ptr
<SdrObjListIter
> pGroupIterator
;
245 if (pCurrent
->IsGroupObject())
247 pGroupIterator
.reset(new SdrObjListIter(*pCurrent
->GetSubList()));
248 pCurrent
= pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
253 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pCurrent
))
255 Reference
< XInterface
> xControlInterface(pDlgEdObj
->GetUnoControlModel(), UNO_QUERY
);
256 if (xControlInterface
.is())
257 aInterfaces
.push_back(xControlInterface
);
261 pCurrent
= pGroupIterator
&& pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
265 sal_Int32 nCount
= aInterfaces
.size();
266 aSeq
.realloc( nCount
);
267 Reference
< XInterface
>* pInterfaces
= aSeq
.getArray();
268 for( sal_Int32 i
= 0 ; i
< nCount
; i
++ )
269 pInterfaces
[i
] = aInterfaces
[i
];
275 void PropBrw::implSetNewObjectSequence
276 ( const Sequence
< Reference
< XInterface
> >& _rObjectSeq
)
278 Reference
< inspection::XObjectInspector
> xObjectInspector(m_xBrowserController
, UNO_QUERY
);
279 if ( xObjectInspector
.is() )
281 xObjectInspector
->inspect( _rObjectSeq
);
283 OUString aText
= IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES
);
284 aText
+= IDE_RESSTR(RID_STR_BRWTITLE_MULTISELECT
);
290 void PropBrw::implSetNewObject( const Reference
< XPropertySet
>& _rxObject
)
292 if ( m_xBrowserController
.is() )
294 m_xBrowserController
->setPropertyValue( "IntrospectedObject",
298 // set the new title according to the selected object
299 SetText( GetHeadlineName( _rxObject
) );
304 OUString
PropBrw::GetHeadlineName( const Reference
< XPropertySet
>& _rxObject
)
307 Reference
< lang::XServiceInfo
> xServiceInfo( _rxObject
, UNO_QUERY
);
309 if (xServiceInfo
.is()) // single selection
311 sal_uInt16 nResId
= 0;
312 aName
= IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES
);
314 if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
316 nResId
= RID_STR_CLASS_DIALOG
;
318 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
320 nResId
= RID_STR_CLASS_BUTTON
;
322 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
324 nResId
= RID_STR_CLASS_RADIOBUTTON
;
326 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
328 nResId
= RID_STR_CLASS_CHECKBOX
;
330 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
332 nResId
= RID_STR_CLASS_LISTBOX
;
334 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
336 nResId
= RID_STR_CLASS_COMBOBOX
;
338 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
340 nResId
= RID_STR_CLASS_GROUPBOX
;
342 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
344 nResId
= RID_STR_CLASS_EDIT
;
346 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
348 nResId
= RID_STR_CLASS_FIXEDTEXT
;
350 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
352 nResId
= RID_STR_CLASS_IMAGECONTROL
;
354 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
356 nResId
= RID_STR_CLASS_PROGRESSBAR
;
358 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
360 nResId
= RID_STR_CLASS_SCROLLBAR
;
362 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
364 nResId
= RID_STR_CLASS_FIXEDLINE
;
366 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
368 nResId
= RID_STR_CLASS_DATEFIELD
;
370 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
372 nResId
= RID_STR_CLASS_TIMEFIELD
;
374 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
376 nResId
= RID_STR_CLASS_NUMERICFIELD
;
378 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
380 nResId
= RID_STR_CLASS_CURRENCYFIELD
;
382 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
384 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
386 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
388 nResId
= RID_STR_CLASS_PATTERNFIELD
;
390 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
392 nResId
= RID_STR_CLASS_FILECONTROL
;
394 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
396 nResId
= RID_STR_CLASS_TREECONTROL
;
400 nResId
= RID_STR_CLASS_CONTROL
;
405 aName
+= IDE_RESSTR(nResId
);
408 else if (!_rxObject
.is()) // no properties
410 aName
= IDE_RESSTR(RID_STR_BRWTITLE_NO_PROPERTIES
);
417 void PropBrw::Resize()
419 DockingWindow::Resize();
422 Size aSize_
= GetOutputSizePixel();
423 Size
aPropWinSize( aSize_
);
424 aPropWinSize
.Width() -= (2*WIN_BORDER
);
425 aPropWinSize
.Height() -= (2*WIN_BORDER
);
427 if (m_xBrowserComponentWindow
.is())
429 m_xBrowserComponentWindow
->setPosSize(0, 0, aPropWinSize
.Width(), aPropWinSize
.Height(),
430 ::com::sun::star::awt::PosSize::WIDTH
| ::com::sun::star::awt::PosSize::HEIGHT
);
435 void PropBrw::ImplUpdate( const Reference
< XModel
>& _rxContextDocument
, SdrView
* pNewView
)
437 Reference
< XModel
> xContextDocument( _rxContextDocument
);
439 // if we should simply "empty" ourself, assume the context document didn't change
442 OSL_ENSURE( !_rxContextDocument
.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
443 xContextDocument
= m_xContextDocument
;
446 if ( xContextDocument
!= m_xContextDocument
)
448 m_xContextDocument
= xContextDocument
;
449 ImplReCreateController();
456 EndListening( *(pView
->GetModel()) );
465 // set focus on initialization
466 if ( m_bInitialStateChange
)
468 if ( m_xBrowserComponentWindow
.is() )
469 m_xBrowserComponentWindow
->setFocus();
470 m_bInitialStateChange
= false;
473 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
474 sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
476 if ( nMarkCount
== 0 )
478 EndListening( *(pView
->GetModel()) );
480 implSetNewObject( NULL
);
484 Reference
< XPropertySet
> xNewObject
;
485 Sequence
< Reference
< XInterface
> > aNewObjects
;
486 if ( nMarkCount
== 1 )
488 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(rMarkList
.GetMark(0)->GetMarkedSdrObj()))
490 if ( pDlgEdObj
->IsGroupObject() ) // group object
491 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
492 else // single selection
493 xNewObject
= xNewObject
.query( pDlgEdObj
->GetUnoControlModel() );
496 else if ( nMarkCount
> 1 ) // multiple selection
498 aNewObjects
= CreateMultiSelectionSequence( rMarkList
);
501 if ( aNewObjects
.getLength() )
502 implSetNewObjectSequence( aNewObjects
);
504 implSetNewObject( xNewObject
);
506 StartListening( *(pView
->GetModel()) );
508 catch ( const PropertyVetoException
& ) { /* silence */ }
509 catch ( const Exception
& )
511 DBG_UNHANDLED_EXCEPTION();
515 } // namespace basctl
517 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */