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 "propbrw.hxx"
22 : #include "basidesh.hxx"
23 : #include "dlgedobj.hxx"
24 : #include "iderid.hxx"
25 : #include "baside3.hxx"
26 :
27 : #include "dlgresid.hrc"
28 : #include <svx/svxids.hrc>
29 :
30 : #include <com/sun/star/awt/PosSize.hpp>
31 : #include <com/sun/star/inspection/XObjectInspector.hpp>
32 : #include <com/sun/star/lang/XServiceInfo.hpp>
33 : #include <comphelper/types.hxx>
34 : #include <cppuhelper/component_context.hxx>
35 : #include <svx/svditer.hxx>
36 : #include <svx/svdview.hxx>
37 : #include <toolkit/unohlp.hxx>
38 : #include <tools/diagnose_ex.h>
39 : #include <vcl/stdtext.hxx>
40 :
41 : #include <boost/scoped_ptr.hpp>
42 :
43 : namespace basctl
44 : {
45 :
46 : using namespace ::com::sun::star;
47 : using namespace ::com::sun::star::uno;
48 : using namespace ::com::sun::star::lang;
49 : using namespace ::com::sun::star::frame;
50 : using namespace ::com::sun::star::beans;
51 : using namespace ::com::sun::star::container;
52 : using namespace ::comphelper;
53 :
54 :
55 0 : void PropBrw::Update( const SfxViewShell* pShell )
56 : {
57 0 : Shell const* pIdeShell = dynamic_cast<Shell const*>(pShell);
58 : OSL_ENSURE( pIdeShell || !pShell, "PropBrw::Update: invalid shell!" );
59 0 : if (pIdeShell)
60 0 : ImplUpdate(pIdeShell->GetCurrentDocument(), pIdeShell->GetCurDlgView());
61 0 : else if (pShell)
62 0 : ImplUpdate(NULL, pShell->GetDrawView());
63 : else
64 0 : ImplUpdate(NULL, NULL);
65 0 : }
66 :
67 :
68 : namespace
69 : {
70 :
71 : const long STD_WIN_SIZE_X = 300;
72 : const long STD_WIN_SIZE_Y = 350;
73 :
74 : const long STD_MIN_SIZE_X = 250;
75 : const long STD_MIN_SIZE_Y = 250;
76 :
77 : const long WIN_BORDER = 2;
78 :
79 : } // namespace
80 :
81 :
82 : DBG_NAME(PropBrw)
83 :
84 :
85 0 : PropBrw::PropBrw (DialogWindowLayout& rLayout_):
86 : DockingWindow(&rLayout_),
87 : m_bInitialStateChange(true),
88 : m_xORB(comphelper::getProcessServiceFactory()),
89 0 : m_xContextDocument(SfxViewShell::Current() ? SfxViewShell::Current()->GetCurrentDocument() : Reference<XModel>()),
90 : rLayout(rLayout_),
91 0 : pView(0)
92 : {
93 : DBG_CTOR(PropBrw,NULL);
94 :
95 0 : Size aPropWinSize(STD_WIN_SIZE_X,STD_WIN_SIZE_Y);
96 0 : SetMinOutputSizePixel(Size(STD_MIN_SIZE_X,STD_MIN_SIZE_Y));
97 0 : SetOutputSizePixel(aPropWinSize);
98 :
99 : try
100 : {
101 : // create a frame wrapper for myself
102 0 : m_xMeAsFrame = Reference< XFrame >(m_xORB->createInstance( "com.sun.star.frame.Frame" ), UNO_QUERY);
103 0 : if (m_xMeAsFrame.is())
104 : {
105 0 : m_xMeAsFrame->initialize( VCLUnoHelper::GetInterface ( this ) );
106 0 : m_xMeAsFrame->setName( "form property browser" ); // change name!
107 : }
108 : }
109 0 : catch (const Exception&)
110 : {
111 : OSL_FAIL("PropBrw::PropBrw: could not create/initialize my frame!");
112 0 : m_xMeAsFrame.clear();
113 : }
114 :
115 0 : ImplReCreateController();
116 0 : }
117 :
118 :
119 0 : void PropBrw::ImplReCreateController()
120 : {
121 : OSL_PRECOND( m_xMeAsFrame.is(), "PropBrw::ImplCreateController: no frame for myself!" );
122 0 : if ( !m_xMeAsFrame.is() )
123 0 : return;
124 :
125 0 : if ( m_xBrowserController.is() )
126 0 : ImplDestroyController();
127 :
128 : try
129 : {
130 : Reference< XComponentContext > xOwnContext(
131 0 : comphelper::getComponentContext( m_xORB ) );
132 :
133 : // a ComponentContext for the
134 : ::cppu::ContextEntry_Init aHandlerContextInfo[] =
135 : {
136 : ::cppu::ContextEntry_Init( "DialogParentWindow", makeAny( VCLUnoHelper::GetInterface ( this ) ) ),
137 : ::cppu::ContextEntry_Init( "ContextDocument", makeAny( m_xContextDocument ) )
138 0 : };
139 : Reference< XComponentContext > xInspectorContext(
140 0 : ::cppu::createComponentContext( aHandlerContextInfo, SAL_N_ELEMENTS( aHandlerContextInfo ), xOwnContext ) );
141 :
142 : // create a property browser controller
143 0 : Reference< XMultiComponentFactory > xFactory( xInspectorContext->getServiceManager(), UNO_QUERY_THROW );
144 0 : static const OUString s_sControllerServiceName( "com.sun.star.awt.PropertyBrowserController" );
145 : m_xBrowserController = Reference< XPropertySet >(
146 0 : xFactory->createInstanceWithContext( s_sControllerServiceName, xInspectorContext ), UNO_QUERY
147 0 : );
148 0 : if ( !m_xBrowserController.is() )
149 : {
150 0 : ShowServiceNotAvailableError( GetParent(), s_sControllerServiceName, true );
151 : }
152 : else
153 : {
154 0 : Reference< XController > xAsXController( m_xBrowserController, UNO_QUERY );
155 : DBG_ASSERT(xAsXController.is(), "PropBrw::PropBrw: invalid controller object!");
156 0 : if (!xAsXController.is())
157 : {
158 0 : ::comphelper::disposeComponent(m_xBrowserController);
159 0 : m_xBrowserController.clear();
160 : }
161 : else
162 : {
163 0 : xAsXController->attachFrame(m_xMeAsFrame);
164 0 : m_xBrowserComponentWindow = m_xMeAsFrame->getComponentWindow();
165 : DBG_ASSERT(m_xBrowserComponentWindow.is(), "PropBrw::PropBrw: attached the controller, but have no component window!");
166 0 : }
167 : }
168 :
169 0 : Point aPropWinPos = Point( WIN_BORDER, WIN_BORDER );
170 0 : Size aPropWinSize(STD_WIN_SIZE_X,STD_WIN_SIZE_Y);
171 0 : aPropWinSize.Width() -= (2*WIN_BORDER);
172 0 : aPropWinSize.Height() -= (2*WIN_BORDER);
173 :
174 0 : if ( m_xBrowserComponentWindow.is() )
175 : {
176 0 : m_xBrowserComponentWindow->setPosSize(aPropWinPos.X(), aPropWinPos.Y(), aPropWinSize.Width(), aPropWinSize.Height(),
177 : ::com::sun::star::awt::PosSize::WIDTH | ::com::sun::star::awt::PosSize::HEIGHT |
178 0 : ::com::sun::star::awt::PosSize::X | ::com::sun::star::awt::PosSize::Y);
179 0 : m_xBrowserComponentWindow->setVisible(true);
180 0 : }
181 : }
182 0 : catch (const Exception&)
183 : {
184 : OSL_FAIL("PropBrw::PropBrw: could not create/initialize the browser controller!");
185 : try
186 : {
187 0 : ::comphelper::disposeComponent(m_xBrowserController);
188 0 : ::comphelper::disposeComponent(m_xBrowserComponentWindow);
189 : }
190 0 : catch(const Exception&)
191 : {
192 : }
193 :
194 0 : m_xBrowserController.clear();
195 0 : m_xBrowserComponentWindow.clear();
196 : }
197 :
198 0 : Resize();
199 : }
200 :
201 :
202 0 : PropBrw::~PropBrw()
203 : {
204 0 : if ( m_xBrowserController.is() )
205 0 : ImplDestroyController();
206 0 : rLayout.RemovePropertyBrowser();
207 :
208 : DBG_DTOR(PropBrw,NULL);
209 0 : }
210 :
211 :
212 0 : void PropBrw::ImplDestroyController()
213 : {
214 0 : implSetNewObject( Reference< XPropertySet >() );
215 :
216 0 : if ( m_xMeAsFrame.is() )
217 0 : m_xMeAsFrame->setComponent( NULL, NULL );
218 :
219 0 : Reference< XController > xAsXController( m_xBrowserController, UNO_QUERY );
220 0 : if ( xAsXController.is() )
221 0 : xAsXController->attachFrame( NULL );
222 :
223 : try
224 : {
225 0 : ::comphelper::disposeComponent( m_xBrowserController );
226 : }
227 0 : catch( const Exception& )
228 : {
229 : DBG_UNHANDLED_EXCEPTION();
230 : }
231 :
232 0 : m_xBrowserController.clear();
233 0 : }
234 :
235 :
236 0 : sal_Bool PropBrw::Close()
237 : {
238 0 : ImplDestroyController();
239 :
240 0 : if( IsRollUp() )
241 0 : RollDown();
242 :
243 0 : return DockingWindow::Close();
244 : }
245 :
246 :
247 : Sequence< Reference< XInterface > >
248 0 : PropBrw::CreateMultiSelectionSequence( const SdrMarkList& _rMarkList )
249 : {
250 0 : Sequence< Reference< XInterface > > aSeq;
251 0 : InterfaceArray aInterfaces;
252 :
253 0 : sal_uInt32 nMarkCount = _rMarkList.GetMarkCount();
254 0 : for( sal_uInt32 i = 0 ; i < nMarkCount ; i++ )
255 : {
256 0 : SdrObject* pCurrent = _rMarkList.GetMark(i)->GetMarkedSdrObj();
257 :
258 0 : boost::scoped_ptr<SdrObjListIter> pGroupIterator;
259 0 : if (pCurrent->IsGroupObject())
260 : {
261 0 : pGroupIterator.reset(new SdrObjListIter(*pCurrent->GetSubList()));
262 0 : pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
263 : }
264 :
265 0 : while (pCurrent)
266 : {
267 0 : if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pCurrent))
268 : {
269 0 : Reference< XInterface > xControlInterface(pDlgEdObj->GetUnoControlModel(), UNO_QUERY);
270 0 : if (xControlInterface.is())
271 0 : aInterfaces.push_back(xControlInterface);
272 : }
273 :
274 : // next element
275 0 : pCurrent = pGroupIterator && pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
276 : }
277 0 : }
278 :
279 0 : sal_Int32 nCount = aInterfaces.size();
280 0 : aSeq.realloc( nCount );
281 0 : Reference< XInterface >* pInterfaces = aSeq.getArray();
282 0 : for( sal_Int32 i = 0 ; i < nCount ; i++ )
283 0 : pInterfaces[i] = aInterfaces[i];
284 :
285 0 : return aSeq;
286 : }
287 :
288 :
289 0 : void PropBrw::implSetNewObjectSequence
290 : ( const Sequence< Reference< XInterface > >& _rObjectSeq )
291 : {
292 0 : Reference< inspection::XObjectInspector > xObjectInspector(m_xBrowserController, UNO_QUERY);
293 0 : if ( xObjectInspector.is() )
294 : {
295 0 : xObjectInspector->inspect( _rObjectSeq );
296 :
297 0 : OUString aText = IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES);
298 0 : aText += IDE_RESSTR(RID_STR_BRWTITLE_MULTISELECT);
299 0 : SetText( aText );
300 0 : }
301 0 : }
302 :
303 :
304 0 : void PropBrw::implSetNewObject( const Reference< XPropertySet >& _rxObject )
305 : {
306 0 : if ( m_xBrowserController.is() )
307 : {
308 0 : m_xBrowserController->setPropertyValue( "IntrospectedObject",
309 : makeAny( _rxObject )
310 0 : );
311 :
312 : // set the new title according to the selected object
313 0 : SetText( GetHeadlineName( _rxObject ) );
314 : }
315 0 : }
316 :
317 :
318 0 : OUString PropBrw::GetHeadlineName( const Reference< XPropertySet >& _rxObject )
319 : {
320 0 : OUString aName;
321 0 : Reference< lang::XServiceInfo > xServiceInfo( _rxObject, UNO_QUERY );
322 :
323 0 : if (xServiceInfo.is()) // single selection
324 : {
325 0 : sal_uInt16 nResId = 0;
326 0 : aName = IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES);
327 :
328 0 : if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
329 : {
330 0 : nResId = RID_STR_CLASS_DIALOG;
331 : }
332 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
333 : {
334 0 : nResId = RID_STR_CLASS_BUTTON;
335 : }
336 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
337 : {
338 0 : nResId = RID_STR_CLASS_RADIOBUTTON;
339 : }
340 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
341 : {
342 0 : nResId = RID_STR_CLASS_CHECKBOX;
343 : }
344 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
345 : {
346 0 : nResId = RID_STR_CLASS_LISTBOX;
347 : }
348 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
349 : {
350 0 : nResId = RID_STR_CLASS_COMBOBOX;
351 : }
352 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
353 : {
354 0 : nResId = RID_STR_CLASS_GROUPBOX;
355 : }
356 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
357 : {
358 0 : nResId = RID_STR_CLASS_EDIT;
359 : }
360 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
361 : {
362 0 : nResId = RID_STR_CLASS_FIXEDTEXT;
363 : }
364 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
365 : {
366 0 : nResId = RID_STR_CLASS_IMAGECONTROL;
367 : }
368 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
369 : {
370 0 : nResId = RID_STR_CLASS_PROGRESSBAR;
371 : }
372 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
373 : {
374 0 : nResId = RID_STR_CLASS_SCROLLBAR;
375 : }
376 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
377 : {
378 0 : nResId = RID_STR_CLASS_FIXEDLINE;
379 : }
380 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
381 : {
382 0 : nResId = RID_STR_CLASS_DATEFIELD;
383 : }
384 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
385 : {
386 0 : nResId = RID_STR_CLASS_TIMEFIELD;
387 : }
388 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
389 : {
390 0 : nResId = RID_STR_CLASS_NUMERICFIELD;
391 : }
392 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
393 : {
394 0 : nResId = RID_STR_CLASS_CURRENCYFIELD;
395 : }
396 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
397 : {
398 0 : nResId = RID_STR_CLASS_FORMATTEDFIELD;
399 : }
400 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
401 : {
402 0 : nResId = RID_STR_CLASS_PATTERNFIELD;
403 : }
404 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
405 : {
406 0 : nResId = RID_STR_CLASS_FILECONTROL;
407 : }
408 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
409 : {
410 0 : nResId = RID_STR_CLASS_TREECONTROL;
411 : }
412 : else
413 : {
414 0 : nResId = RID_STR_CLASS_CONTROL;
415 : }
416 :
417 0 : if (nResId)
418 : {
419 0 : aName += IDE_RESSTR(nResId);
420 : }
421 : }
422 0 : else if (!_rxObject.is()) // no properties
423 : {
424 0 : aName = IDE_RESSTR(RID_STR_BRWTITLE_NO_PROPERTIES);
425 : }
426 :
427 0 : return aName;
428 : }
429 :
430 :
431 0 : void PropBrw::Resize()
432 : {
433 0 : DockingWindow::Resize();
434 :
435 : // adjust size
436 0 : Size aSize_ = GetOutputSizePixel();
437 0 : Size aPropWinSize( aSize_ );
438 0 : aPropWinSize.Width() -= (2*WIN_BORDER);
439 0 : aPropWinSize.Height() -= (2*WIN_BORDER);
440 :
441 0 : if (m_xBrowserComponentWindow.is())
442 : {
443 0 : m_xBrowserComponentWindow->setPosSize(0, 0, aPropWinSize.Width(), aPropWinSize.Height(),
444 0 : ::com::sun::star::awt::PosSize::WIDTH | ::com::sun::star::awt::PosSize::HEIGHT);
445 : }
446 0 : }
447 :
448 :
449 0 : void PropBrw::ImplUpdate( const Reference< XModel >& _rxContextDocument, SdrView* pNewView )
450 : {
451 0 : Reference< XModel > xContextDocument( _rxContextDocument );
452 :
453 : // if we should simply "empty" ourself, assume the context document didn't change
454 0 : if ( !pNewView )
455 : {
456 : OSL_ENSURE( !_rxContextDocument.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
457 0 : xContextDocument = m_xContextDocument;
458 : }
459 :
460 0 : if ( xContextDocument != m_xContextDocument )
461 : {
462 0 : m_xContextDocument = xContextDocument;
463 0 : ImplReCreateController();
464 : }
465 :
466 : try
467 : {
468 0 : if ( pView )
469 : {
470 0 : EndListening( *(pView->GetModel()) );
471 0 : pView = NULL;
472 : }
473 :
474 0 : if ( !pNewView )
475 : return;
476 :
477 0 : pView = pNewView;
478 :
479 : // set focus on initialization
480 0 : if ( m_bInitialStateChange )
481 : {
482 0 : if ( m_xBrowserComponentWindow.is() )
483 0 : m_xBrowserComponentWindow->setFocus();
484 0 : m_bInitialStateChange = false;
485 : }
486 :
487 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
488 0 : sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
489 :
490 0 : if ( nMarkCount == 0 )
491 : {
492 0 : EndListening( *(pView->GetModel()) );
493 0 : pView = NULL;
494 0 : implSetNewObject( NULL );
495 : return;
496 : }
497 :
498 0 : Reference< XPropertySet > xNewObject;
499 0 : Sequence< Reference< XInterface > > aNewObjects;
500 0 : if ( nMarkCount == 1 )
501 : {
502 0 : if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(rMarkList.GetMark(0)->GetMarkedSdrObj()))
503 : {
504 0 : if ( pDlgEdObj->IsGroupObject() ) // group object
505 0 : aNewObjects = CreateMultiSelectionSequence( rMarkList );
506 : else // single selection
507 0 : xNewObject = xNewObject.query( pDlgEdObj->GetUnoControlModel() );
508 : }
509 : }
510 0 : else if ( nMarkCount > 1 ) // multiple selection
511 : {
512 0 : aNewObjects = CreateMultiSelectionSequence( rMarkList );
513 : }
514 :
515 0 : if ( aNewObjects.getLength() )
516 0 : implSetNewObjectSequence( aNewObjects );
517 : else
518 0 : implSetNewObject( xNewObject );
519 :
520 0 : StartListening( *(pView->GetModel()) );
521 : }
522 0 : catch ( const PropertyVetoException& ) { /* silence */ }
523 0 : catch ( const Exception& )
524 : {
525 : DBG_UNHANDLED_EXCEPTION();
526 0 : }
527 : }
528 :
529 : } // namespace basctl
530 :
531 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|