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