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 : static const char 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 : disposeOnce();
194 0 : }
195 :
196 0 : void PropBrw::dispose()
197 : {
198 0 : if ( m_xBrowserController.is() )
199 0 : ImplDestroyController();
200 0 : DockingWindow::dispose();
201 0 : }
202 :
203 :
204 0 : void PropBrw::ImplDestroyController()
205 : {
206 0 : implSetNewObject( Reference< XPropertySet >() );
207 :
208 0 : if ( m_xMeAsFrame.is() )
209 0 : m_xMeAsFrame->setComponent( NULL, NULL );
210 :
211 0 : Reference< XController > xAsXController( m_xBrowserController, UNO_QUERY );
212 0 : if ( xAsXController.is() )
213 0 : xAsXController->attachFrame( NULL );
214 :
215 : try
216 : {
217 0 : ::comphelper::disposeComponent( m_xBrowserController );
218 : }
219 0 : catch( const Exception& )
220 : {
221 : DBG_UNHANDLED_EXCEPTION();
222 : }
223 :
224 0 : m_xBrowserController.clear();
225 0 : }
226 :
227 :
228 0 : bool PropBrw::Close()
229 : {
230 0 : ImplDestroyController();
231 :
232 0 : if( IsRollUp() )
233 0 : RollDown();
234 :
235 0 : return DockingWindow::Close();
236 : }
237 :
238 :
239 : Sequence< Reference< XInterface > >
240 0 : PropBrw::CreateMultiSelectionSequence( const SdrMarkList& _rMarkList )
241 : {
242 0 : Sequence< Reference< XInterface > > aSeq;
243 0 : InterfaceArray aInterfaces;
244 :
245 0 : const size_t nMarkCount = _rMarkList.GetMarkCount();
246 0 : for( size_t i = 0 ; i < nMarkCount ; ++i )
247 : {
248 0 : SdrObject* pCurrent = _rMarkList.GetMark(i)->GetMarkedSdrObj();
249 :
250 0 : boost::scoped_ptr<SdrObjListIter> pGroupIterator;
251 0 : if (pCurrent->IsGroupObject())
252 : {
253 0 : pGroupIterator.reset(new SdrObjListIter(*pCurrent->GetSubList()));
254 0 : pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
255 : }
256 :
257 0 : while (pCurrent)
258 : {
259 0 : if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pCurrent))
260 : {
261 0 : Reference< XInterface > xControlInterface(pDlgEdObj->GetUnoControlModel(), UNO_QUERY);
262 0 : if (xControlInterface.is())
263 0 : aInterfaces.push_back(xControlInterface);
264 : }
265 :
266 : // next element
267 0 : pCurrent = pGroupIterator && pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
268 : }
269 0 : }
270 :
271 0 : sal_Int32 nCount = aInterfaces.size();
272 0 : aSeq.realloc( nCount );
273 0 : Reference< XInterface >* pInterfaces = aSeq.getArray();
274 0 : for( sal_Int32 i = 0 ; i < nCount ; i++ )
275 0 : pInterfaces[i] = aInterfaces[i];
276 :
277 0 : return aSeq;
278 : }
279 :
280 :
281 0 : void PropBrw::implSetNewObjectSequence
282 : ( const Sequence< Reference< XInterface > >& _rObjectSeq )
283 : {
284 0 : Reference< inspection::XObjectInspector > xObjectInspector(m_xBrowserController, UNO_QUERY);
285 0 : if ( xObjectInspector.is() )
286 : {
287 0 : xObjectInspector->inspect( _rObjectSeq );
288 :
289 0 : OUString aText = IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES);
290 0 : aText += IDE_RESSTR(RID_STR_BRWTITLE_MULTISELECT);
291 0 : SetText( aText );
292 0 : }
293 0 : }
294 :
295 :
296 0 : void PropBrw::implSetNewObject( const Reference< XPropertySet >& _rxObject )
297 : {
298 0 : if ( m_xBrowserController.is() )
299 : {
300 0 : m_xBrowserController->setPropertyValue( "IntrospectedObject",
301 : makeAny( _rxObject )
302 0 : );
303 :
304 : // set the new title according to the selected object
305 0 : SetText( GetHeadlineName( _rxObject ) );
306 : }
307 0 : }
308 :
309 :
310 0 : OUString PropBrw::GetHeadlineName( const Reference< XPropertySet >& _rxObject )
311 : {
312 0 : OUString aName;
313 0 : Reference< lang::XServiceInfo > xServiceInfo( _rxObject, UNO_QUERY );
314 :
315 0 : if (xServiceInfo.is()) // single selection
316 : {
317 0 : sal_uInt16 nResId = 0;
318 0 : aName = IDE_RESSTR(RID_STR_BRWTITLE_PROPERTIES);
319 :
320 0 : if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
321 : {
322 0 : nResId = RID_STR_CLASS_DIALOG;
323 : }
324 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
325 : {
326 0 : nResId = RID_STR_CLASS_BUTTON;
327 : }
328 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
329 : {
330 0 : nResId = RID_STR_CLASS_RADIOBUTTON;
331 : }
332 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
333 : {
334 0 : nResId = RID_STR_CLASS_CHECKBOX;
335 : }
336 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
337 : {
338 0 : nResId = RID_STR_CLASS_LISTBOX;
339 : }
340 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
341 : {
342 0 : nResId = RID_STR_CLASS_COMBOBOX;
343 : }
344 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
345 : {
346 0 : nResId = RID_STR_CLASS_GROUPBOX;
347 : }
348 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
349 : {
350 0 : nResId = RID_STR_CLASS_EDIT;
351 : }
352 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
353 : {
354 0 : nResId = RID_STR_CLASS_FIXEDTEXT;
355 : }
356 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
357 : {
358 0 : nResId = RID_STR_CLASS_IMAGECONTROL;
359 : }
360 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
361 : {
362 0 : nResId = RID_STR_CLASS_PROGRESSBAR;
363 : }
364 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
365 : {
366 0 : nResId = RID_STR_CLASS_SCROLLBAR;
367 : }
368 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
369 : {
370 0 : nResId = RID_STR_CLASS_FIXEDLINE;
371 : }
372 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
373 : {
374 0 : nResId = RID_STR_CLASS_DATEFIELD;
375 : }
376 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
377 : {
378 0 : nResId = RID_STR_CLASS_TIMEFIELD;
379 : }
380 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
381 : {
382 0 : nResId = RID_STR_CLASS_NUMERICFIELD;
383 : }
384 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
385 : {
386 0 : nResId = RID_STR_CLASS_CURRENCYFIELD;
387 : }
388 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
389 : {
390 0 : nResId = RID_STR_CLASS_FORMATTEDFIELD;
391 : }
392 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
393 : {
394 0 : nResId = RID_STR_CLASS_PATTERNFIELD;
395 : }
396 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
397 : {
398 0 : nResId = RID_STR_CLASS_FILECONTROL;
399 : }
400 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
401 : {
402 0 : nResId = RID_STR_CLASS_TREECONTROL;
403 : }
404 : else
405 : {
406 0 : nResId = RID_STR_CLASS_CONTROL;
407 : }
408 :
409 0 : if (nResId)
410 : {
411 0 : aName += IDE_RESSTR(nResId);
412 : }
413 : }
414 0 : else if (!_rxObject.is()) // no properties
415 : {
416 0 : aName = IDE_RESSTR(RID_STR_BRWTITLE_NO_PROPERTIES);
417 : }
418 :
419 0 : return aName;
420 : }
421 :
422 :
423 0 : void PropBrw::Resize()
424 : {
425 0 : DockingWindow::Resize();
426 :
427 : // adjust size
428 0 : Size aSize_ = GetOutputSizePixel();
429 0 : Size aPropWinSize( aSize_ );
430 0 : aPropWinSize.Width() -= (2*WIN_BORDER);
431 0 : aPropWinSize.Height() -= (2*WIN_BORDER);
432 :
433 0 : if (m_xBrowserComponentWindow.is())
434 : {
435 0 : m_xBrowserComponentWindow->setPosSize(0, 0, aPropWinSize.Width(), aPropWinSize.Height(),
436 0 : ::com::sun::star::awt::PosSize::WIDTH | ::com::sun::star::awt::PosSize::HEIGHT);
437 : }
438 0 : }
439 :
440 :
441 0 : void PropBrw::ImplUpdate( const Reference< XModel >& _rxContextDocument, SdrView* pNewView )
442 : {
443 0 : Reference< XModel > xContextDocument( _rxContextDocument );
444 :
445 : // if we should simply "empty" ourself, assume the context document didn't change
446 0 : if ( !pNewView )
447 : {
448 : OSL_ENSURE( !_rxContextDocument.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
449 0 : xContextDocument = m_xContextDocument;
450 : }
451 :
452 0 : if ( xContextDocument != m_xContextDocument )
453 : {
454 0 : m_xContextDocument = xContextDocument;
455 0 : ImplReCreateController();
456 : }
457 :
458 : try
459 : {
460 0 : if ( pView )
461 : {
462 0 : EndListening( *(pView->GetModel()) );
463 0 : pView = NULL;
464 : }
465 :
466 0 : if ( !pNewView )
467 0 : return;
468 :
469 0 : pView = pNewView;
470 :
471 : // set focus on initialization
472 0 : if ( m_bInitialStateChange )
473 : {
474 0 : if ( m_xBrowserComponentWindow.is() )
475 0 : m_xBrowserComponentWindow->setFocus();
476 0 : m_bInitialStateChange = false;
477 : }
478 :
479 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
480 0 : const size_t nMarkCount = rMarkList.GetMarkCount();
481 :
482 0 : if ( nMarkCount == 0 )
483 : {
484 0 : EndListening( *(pView->GetModel()) );
485 0 : pView = NULL;
486 0 : implSetNewObject( NULL );
487 0 : return;
488 : }
489 :
490 0 : Reference< XPropertySet > xNewObject;
491 0 : Sequence< Reference< XInterface > > aNewObjects;
492 0 : if ( nMarkCount == 1 )
493 : {
494 0 : if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(rMarkList.GetMark(0)->GetMarkedSdrObj()))
495 : {
496 0 : if ( pDlgEdObj->IsGroupObject() ) // group object
497 0 : aNewObjects = CreateMultiSelectionSequence( rMarkList );
498 : else // single selection
499 0 : xNewObject.set(pDlgEdObj->GetUnoControlModel(), css::uno::UNO_QUERY);
500 : }
501 : }
502 0 : else if ( nMarkCount > 1 ) // multiple selection
503 : {
504 0 : aNewObjects = CreateMultiSelectionSequence( rMarkList );
505 : }
506 :
507 0 : if ( aNewObjects.getLength() )
508 0 : implSetNewObjectSequence( aNewObjects );
509 : else
510 0 : implSetNewObject( xNewObject );
511 :
512 0 : StartListening( *(pView->GetModel()) );
513 : }
514 0 : catch ( const PropertyVetoException& ) { /* silence */ }
515 0 : catch ( const Exception& )
516 : {
517 : DBG_UNHANDLED_EXCEPTION();
518 0 : }
519 : }
520 :
521 0 : } // namespace basctl
522 :
523 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|