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 : #include "ChartController.hxx"
21 : #include "servicenames.hxx"
22 : #include "ResId.hxx"
23 : #include "dlg_DataSource.hxx"
24 : #include "ChartModelHelper.hxx"
25 : #include "ControllerCommandDispatch.hxx"
26 : #include "Strings.hrc"
27 : #include "chartview/ExplicitValueProvider.hxx"
28 : #include "ChartViewHelper.hxx"
29 :
30 : #include "ChartWindow.hxx"
31 : #include "chartview/DrawModelWrapper.hxx"
32 : #include "DrawViewWrapper.hxx"
33 : #include "ObjectIdentifier.hxx"
34 : #include "DiagramHelper.hxx"
35 : #include "ControllerLockGuard.hxx"
36 : #include "UndoGuard.hxx"
37 : #include "ChartDropTargetHelper.hxx"
38 :
39 : #include "macros.hxx"
40 : #include "dlg_CreationWizard.hxx"
41 : #include "dlg_ChartType.hxx"
42 : #include "AccessibleChartView.hxx"
43 : #include "DrawCommandDispatch.hxx"
44 : #include "ShapeController.hxx"
45 : #include "UndoActions.hxx"
46 :
47 : #include <comphelper/InlineContainer.hxx>
48 :
49 : #include <com/sun/star/awt/PosSize.hpp>
50 : #include <com/sun/star/chart2/XChartDocument.hpp>
51 : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
52 : #include <com/sun/star/frame/XLoadable.hpp>
53 : #include <com/sun/star/util/XCloneable.hpp>
54 : #include <com/sun/star/embed/XEmbeddedClient.hpp>
55 : #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
56 : #include <com/sun/star/util/XModifyBroadcaster.hpp>
57 : #include <com/sun/star/frame/LayoutManagerEvents.hpp>
58 : #include <com/sun/star/document/XUndoManagerSupplier.hpp>
59 : #include <com/sun/star/document/XUndoAction.hpp>
60 :
61 : //-------
62 : // header for define RET_OK
63 : #include <vcl/msgbox.hxx>
64 : //-------
65 :
66 : //-------
67 : #include <toolkit/awt/vclxwindow.hxx>
68 : #include <toolkit/helper/vclunohelper.hxx>
69 : #include <vcl/svapp.hxx>
70 : #include <osl/mutex.hxx>
71 : //-------
72 : #include <com/sun/star/frame/XLayoutManager.hpp>
73 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
74 :
75 : // this is needed to properly destroy the auto_ptr to the AcceleratorExecute
76 : // object in the DTOR
77 : #include <svtools/acceleratorexecute.hxx>
78 : #include <svx/ActionDescriptionProvider.hxx>
79 : #include <tools/diagnose_ex.h>
80 :
81 : // enable the following define to let the controller listen to model changes and
82 : // react on this by rebuilding the view
83 : #define TEST_ENABLE_MODIFY_LISTENER
84 :
85 : //.............................................................................
86 : namespace chart
87 : {
88 : //.............................................................................
89 :
90 : using namespace ::com::sun::star;
91 : using namespace ::com::sun::star::accessibility;
92 : using namespace ::com::sun::star::chart2;
93 : using ::com::sun::star::uno::Any;
94 : using ::com::sun::star::uno::Reference;
95 : using ::com::sun::star::uno::Sequence;
96 : DBG_NAME(ChartController)
97 : //-----------------------------------------------------------------
98 : // ChartController Constructor and Destructor
99 : //-----------------------------------------------------------------
100 :
101 0 : ChartController::ChartController(uno::Reference<uno::XComponentContext> const & xContext)
102 : : m_aLifeTimeManager( NULL )
103 : , m_bSuspended( sal_False )
104 : , m_bCanClose( sal_True )
105 : , m_xCC(xContext) //@todo is it allowed to hold this context??
106 : , m_xFrame( NULL )
107 : , m_aModelMutex()
108 : , m_aModel( NULL, m_aModelMutex )
109 : , m_pChartWindow( NULL )
110 : , m_xViewWindow()
111 : , m_xChartView()
112 : , m_pDrawModelWrapper()
113 : , m_pDrawViewWrapper(NULL)
114 : , m_eDragMode(SDRDRAG_MOVE)
115 : , m_bWaitingForDoubleClick(false)
116 : , m_bWaitingForMouseUp(false)
117 : , m_bConnectingToView(false)
118 : , m_xUndoManager( 0 )
119 : , m_aDispatchContainer( m_xCC, this )
120 0 : , m_eDrawMode( CHARTDRAW_SELECT )
121 : {
122 : DBG_CTOR(ChartController,NULL);
123 0 : m_aDoubleClickTimer.SetTimeoutHdl( LINK( this, ChartController, DoubleClickWaitingHdl ) );
124 0 : }
125 :
126 0 : ChartController::~ChartController()
127 : {
128 : DBG_DTOR(ChartController,NULL);
129 0 : stopDoubleClickWaiting();
130 0 : }
131 :
132 : //-----------------------------------------------------------------
133 :
134 0 : ChartController::RefCountable::RefCountable() : m_nRefCount(0)
135 : {
136 0 : }
137 :
138 0 : ChartController::RefCountable::~RefCountable()
139 : {
140 0 : }
141 0 : void ChartController::RefCountable::acquire()
142 : {
143 0 : m_nRefCount++;
144 0 : }
145 0 : void ChartController::RefCountable::release()
146 : {
147 0 : m_nRefCount--;
148 0 : if(!m_nRefCount)
149 0 : delete this;
150 0 : }
151 :
152 : //-----------------------------------------------------------------
153 :
154 0 : ChartController::TheModel::TheModel( const uno::Reference< frame::XModel > & xModel )
155 : : m_xModel( xModel )
156 : , m_xCloseable( NULL )
157 : , m_bOwnership( sal_True )
158 0 : , m_bOwnershipIsWellKnown( sal_False )
159 : {
160 : m_xCloseable =
161 0 : uno::Reference< util::XCloseable >( xModel, uno::UNO_QUERY );
162 0 : }
163 :
164 0 : ChartController::TheModel::~TheModel()
165 : {
166 0 : }
167 :
168 0 : void ChartController::TheModel::SetOwnerShip( sal_Bool bGetsOwnership )
169 : {
170 0 : m_bOwnership = bGetsOwnership;
171 0 : m_bOwnershipIsWellKnown = sal_True;
172 0 : }
173 :
174 0 : void ChartController::TheModel::addListener( ChartController* pController )
175 : {
176 0 : if(m_xCloseable.is())
177 : {
178 : //if you need to be able to veto against the destruction of the model
179 : // you must add as a close listener
180 :
181 : //otherwise you 'can' add as closelistener or 'must' add as dispose event listener
182 :
183 0 : m_xCloseable->addCloseListener(
184 0 : static_cast<util::XCloseListener*>(pController) );
185 : }
186 0 : else if( m_xModel.is() )
187 : {
188 : //we need to add as dispose event listener
189 0 : m_xModel->addEventListener(
190 0 : static_cast<util::XCloseListener*>(pController) );
191 : }
192 :
193 0 : }
194 :
195 0 : void ChartController::TheModel::removeListener( ChartController* pController )
196 : {
197 0 : if(m_xCloseable.is())
198 0 : m_xCloseable->removeCloseListener(
199 0 : static_cast<util::XCloseListener*>(pController) );
200 :
201 0 : else if( m_xModel.is() )
202 0 : m_xModel->removeEventListener(
203 0 : static_cast<util::XCloseListener*>(pController) );
204 0 : }
205 :
206 0 : void ChartController::TheModel::tryTermination()
207 : {
208 0 : if(!m_bOwnership)
209 0 : return;
210 :
211 : try
212 : {
213 0 : if(m_xCloseable.is())
214 : {
215 : try
216 : {
217 : //@todo ? are we allowed to use sal_True here if we have the explicit ownership?
218 : //I think yes, because there might be other closelistners later in the list which might be interested still
219 : //but make sure that we do not throw the CloseVetoException here ourselfs
220 : //so stop listening before trying to terminate or check the source of queryclosing event
221 0 : m_xCloseable->close(sal_True);
222 :
223 0 : m_bOwnership = false;
224 0 : m_bOwnershipIsWellKnown = sal_True;
225 : }
226 0 : catch( const util::CloseVetoException& )
227 : {
228 : //since we have indicated to give up the ownership with paramter true in close call
229 : //the one who has thrown the CloseVetoException is the new owner
230 :
231 : #if OSL_DEBUG_LEVEL > 1
232 : OSL_ENSURE( !m_bOwnership,
233 : "INFO: a well known owner has caught a CloseVetoException after calling close(true)" );
234 : #endif
235 :
236 0 : m_bOwnership = false;
237 0 : m_bOwnershipIsWellKnown = sal_True;
238 : return;
239 : }
240 :
241 : }
242 0 : else if( m_xModel.is() )
243 : {
244 : //@todo correct??
245 0 : m_xModel->dispose();
246 0 : return;
247 : }
248 : }
249 0 : catch(const uno::Exception& ex)
250 : {
251 : (void)(ex); // no warning in non-debug builds
252 : OSL_FAIL( OString( OString("Termination of model failed: ")
253 : + OUStringToOString( ex.Message, RTL_TEXTENCODING_ASCII_US ) ).getStr() );
254 : }
255 : }
256 :
257 : //-----------------------------------------------------------------
258 :
259 0 : ChartController::TheModelRef::TheModelRef( TheModel* pTheModel, ::osl::Mutex& rMutex )
260 0 : : m_pTheModel(pTheModel), m_rModelMutex(rMutex)
261 : {
262 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
263 0 : if(m_pTheModel)
264 0 : m_pTheModel->acquire();
265 0 : }
266 0 : ChartController::TheModelRef::TheModelRef( const TheModelRef& rTheModel, ::osl::Mutex& rMutex )
267 0 : : m_rModelMutex(rMutex)
268 : {
269 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
270 0 : m_pTheModel=rTheModel.operator->();
271 0 : if(m_pTheModel)
272 0 : m_pTheModel->acquire();
273 0 : }
274 0 : ChartController::TheModelRef& ChartController::TheModelRef::operator=(TheModel* pTheModel)
275 : {
276 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
277 0 : if(m_pTheModel==pTheModel)
278 0 : return *this;
279 0 : if(m_pTheModel)
280 0 : m_pTheModel->release();
281 0 : m_pTheModel=pTheModel;
282 0 : if(m_pTheModel)
283 0 : m_pTheModel->acquire();
284 0 : return *this;
285 : }
286 0 : ChartController::TheModelRef& ChartController::TheModelRef::operator=(const TheModelRef& rTheModel)
287 : {
288 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
289 0 : TheModel* pNew=rTheModel.operator->();
290 0 : if(m_pTheModel==pNew)
291 0 : return *this;
292 0 : if(m_pTheModel)
293 0 : m_pTheModel->release();
294 0 : m_pTheModel=pNew;
295 0 : if(m_pTheModel)
296 0 : m_pTheModel->acquire();
297 0 : return *this;
298 : }
299 0 : ChartController::TheModelRef::~TheModelRef()
300 : {
301 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
302 0 : if(m_pTheModel)
303 0 : m_pTheModel->release();
304 0 : }
305 0 : sal_Bool ChartController::TheModelRef::is() const
306 : {
307 0 : return (m_pTheModel != 0);
308 : }
309 :
310 :
311 : //-----------------------------------------------------------------
312 : // private methods
313 : //-----------------------------------------------------------------
314 :
315 0 : sal_Bool ChartController
316 : ::impl_isDisposedOrSuspended() const
317 : {
318 0 : if( m_aLifeTimeManager.impl_isDisposed() )
319 0 : return sal_True;
320 :
321 0 : if( m_bSuspended )
322 : {
323 : OSL_FAIL( "This Controller is suspended" );
324 0 : return sal_True;
325 : }
326 0 : return sal_False;
327 : }
328 :
329 : //-----------------------------------------------------------------
330 : // lang::XServiceInfo
331 : //-----------------------------------------------------------------
332 :
333 1 : APPHELPER_XSERVICEINFO_IMPL(ChartController,CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME)
334 :
335 0 : uno::Sequence< OUString > ChartController
336 : ::getSupportedServiceNames_Static()
337 : {
338 0 : uno::Sequence< OUString > aSNS( 2 );
339 0 : aSNS.getArray()[ 0 ] = CHART_CONTROLLER_SERVICE_NAME;
340 0 : aSNS.getArray()[ 1 ] = "com.sun.star.frame.Controller";
341 : //// @todo : add additional services if you support any further
342 0 : return aSNS;
343 : }
344 :
345 : //-----------------------------------------------------------------
346 : // XController
347 : //-----------------------------------------------------------------
348 :
349 0 : void SAL_CALL ChartController
350 : ::attachFrame( const uno::Reference<frame::XFrame>& xFrame )
351 : throw(uno::RuntimeException)
352 : {
353 0 : SolarMutexGuard aGuard;
354 :
355 0 : if( impl_isDisposedOrSuspended() ) //@todo? allow attaching the frame while suspended?
356 : return; //behave passive if already disposed or suspended
357 :
358 0 : if(m_xFrame.is()) //what happens, if we do have a Frame already??
359 : {
360 : //@todo? throw exception?
361 : OSL_FAIL( "there is already a frame attached to the controller" );
362 : return;
363 : }
364 :
365 : //--attach frame
366 0 : m_xFrame = xFrame; //the frameloader is responsible to call xFrame->setComponent
367 :
368 : //add as disposelistener to the frame (due to persistent reference) ??...:
369 :
370 : //the frame is considered to be owner of this controller and will live longer than we do
371 : //the frame or the disposer of the frame has the duty to call suspend and dispose on this object
372 : //so we do not need to add as lang::XEventListener for DisposingEvents right?
373 :
374 : //@todo nothing right???
375 :
376 :
377 :
378 : //--------------------------------------------------
379 : //create view @todo is this the correct place here??
380 :
381 0 : Window* pParent = NULL;
382 : //get the window parent from the frame to use as parent for our new window
383 0 : if(xFrame.is())
384 : {
385 0 : uno::Reference< awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
386 0 : VCLXWindow* pParentComponent = VCLXWindow::GetImplementation(xContainerWindow);
387 0 : pParentComponent->setVisible(sal_True);
388 :
389 0 : pParent = VCLUnoHelper::GetWindow( xContainerWindow );
390 : }
391 :
392 0 : if(m_pChartWindow)
393 : {
394 : //@todo delete ...
395 0 : m_pChartWindow->clear();
396 0 : m_apDropTargetHelper.reset();
397 : }
398 : {
399 : // calls to VCL
400 0 : SolarMutexGuard aSolarGuard;
401 0 : m_pChartWindow = new ChartWindow(this,pParent,pParent?pParent->GetStyle():0);
402 0 : m_pChartWindow->SetBackground();//no Background
403 0 : m_xViewWindow = uno::Reference< awt::XWindow >( m_pChartWindow->GetComponentInterface(), uno::UNO_QUERY );
404 0 : m_pChartWindow->Show();
405 : m_apDropTargetHelper.reset(
406 0 : new ChartDropTargetHelper( m_pChartWindow->GetDropTarget(),
407 0 : uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY )));
408 :
409 0 : impl_createDrawViewController();
410 : }
411 :
412 : //create the menu
413 : {
414 0 : uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
415 0 : if( xPropSet.is() )
416 : {
417 : try
418 : {
419 0 : uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
420 0 : xPropSet->getPropertyValue( "LayoutManager" ) >>= xLayoutManager;
421 0 : if ( xLayoutManager.is() )
422 : {
423 0 : xLayoutManager->lock();
424 0 : xLayoutManager->requestElement( "private:resource/menubar/menubar" );
425 : //@todo: createElement should become unnecessary, remove when #i79198# is fixed
426 0 : xLayoutManager->createElement( "private:resource/toolbar/standardbar" );
427 0 : xLayoutManager->requestElement( "private:resource/toolbar/standardbar" );
428 : //@todo: createElement should become unnecessary, remove when #i79198# is fixed
429 0 : xLayoutManager->createElement( "private:resource/toolbar/toolbar" );
430 0 : xLayoutManager->requestElement( "private:resource/toolbar/toolbar" );
431 :
432 : // #i12587# support for shapes in chart
433 0 : xLayoutManager->createElement( "private:resource/toolbar/drawbar" );
434 0 : xLayoutManager->requestElement( "private:resource/toolbar/drawbar" );
435 :
436 0 : xLayoutManager->requestElement( "private:resource/statusbar/statusbar" );
437 0 : xLayoutManager->unlock();
438 :
439 : // add as listener to get notified when
440 0 : m_xLayoutManagerEventBroadcaster.set( xLayoutManager, uno::UNO_QUERY );
441 0 : if( m_xLayoutManagerEventBroadcaster.is())
442 0 : m_xLayoutManagerEventBroadcaster->addLayoutManagerEventListener( this );
443 0 : }
444 : }
445 0 : catch( const uno::Exception & ex )
446 : {
447 : ASSERT_EXCEPTION( ex );
448 : }
449 0 : }
450 0 : }
451 : }
452 :
453 : //XModeChangeListener
454 0 : void SAL_CALL ChartController::modeChanged( const util::ModeChangeEvent& rEvent )
455 : throw ( uno::RuntimeException )
456 : {
457 : //adjust controller to view status changes
458 :
459 0 : if( rEvent.NewMode == "dirty" )
460 : {
461 : //the view has become dirty, we should repaint it if we have a window
462 0 : SolarMutexGuard aGuard;
463 0 : if( m_pChartWindow )
464 0 : m_pChartWindow->ForceInvalidate();
465 : }
466 0 : else if( rEvent.NewMode == "invalid" )
467 : {
468 : //the view is about to become invalid so end all actions on it
469 0 : impl_invalidateAccessible();
470 0 : SolarMutexGuard aGuard;
471 0 : if( m_pDrawViewWrapper && m_pDrawViewWrapper->IsTextEdit() )
472 0 : this->EndTextEdit();
473 0 : if( m_pDrawViewWrapper )
474 : {
475 0 : m_pDrawViewWrapper->UnmarkAll();
476 0 : m_pDrawViewWrapper->HideSdrPage();
477 0 : }
478 : }
479 : else
480 : {
481 : //the view was rebuild so we can start some actions on it again
482 0 : if( !m_bConnectingToView )
483 : {
484 0 : if(m_pChartWindow && m_aModel.is() )
485 : {
486 0 : m_bConnectingToView = true;
487 :
488 0 : GetDrawModelWrapper();
489 0 : if(m_pDrawModelWrapper)
490 : {
491 : {
492 0 : SolarMutexGuard aGuard;
493 0 : if( m_pDrawViewWrapper )
494 0 : m_pDrawViewWrapper->ReInit();
495 : }
496 :
497 : //reselect object
498 0 : if( m_aSelection.hasSelection() )
499 0 : this->impl_selectObjectAndNotiy();
500 : else
501 0 : ChartModelHelper::triggerRangeHighlighting( getModel() );
502 :
503 0 : impl_initializeAccessible();
504 :
505 : {
506 0 : SolarMutexGuard aGuard;
507 0 : if( m_pChartWindow )
508 0 : m_pChartWindow->Invalidate();
509 : }
510 : }
511 :
512 0 : m_bConnectingToView = false;
513 : }
514 : }
515 : }
516 0 : }
517 :
518 0 : sal_Bool SAL_CALL ChartController::attachModel( const uno::Reference< frame::XModel > & xModel )
519 : throw(uno::RuntimeException)
520 : {
521 0 : impl_invalidateAccessible();
522 :
523 : //is called to attach the controller to a new model.
524 : //return true if attach was successfully, false otherwise (e.g. if you do not work with a model)
525 :
526 0 : SolarMutexClearableGuard aClearableGuard;
527 0 : if( impl_isDisposedOrSuspended() ) //@todo? allow attaching a new model while suspended?
528 0 : return sal_False; //behave passive if already disposed or suspended
529 0 : aClearableGuard.clear();
530 :
531 0 : TheModelRef aNewModelRef( new TheModel( xModel), m_aModelMutex);
532 0 : TheModelRef aOldModelRef(m_aModel,m_aModelMutex);
533 0 : m_aModel = aNewModelRef;
534 :
535 : //--handle relations to the old model if any
536 0 : if( aOldModelRef.is() )
537 : {
538 0 : uno::Reference< util::XModeChangeBroadcaster > xViewBroadcaster( m_xChartView, uno::UNO_QUERY );
539 0 : if( xViewBroadcaster.is() )
540 0 : xViewBroadcaster->removeModeChangeListener(this);
541 0 : m_pDrawModelWrapper.reset();
542 :
543 0 : aOldModelRef->removeListener( this );
544 : #ifdef TEST_ENABLE_MODIFY_LISTENER
545 0 : uno::Reference< util::XModifyBroadcaster > xMBroadcaster( aOldModelRef->getModel(),uno::UNO_QUERY );
546 0 : if( xMBroadcaster.is())
547 0 : xMBroadcaster->removeModifyListener( this );
548 : #endif
549 : }
550 :
551 : //--handle relations to the new model
552 0 : aNewModelRef->addListener( this );
553 :
554 : // set new model at dispatchers
555 0 : m_aDispatchContainer.setModel( aNewModelRef->getModel());
556 0 : ControllerCommandDispatch * pDispatch = new ControllerCommandDispatch( m_xCC, this, &m_aDispatchContainer );
557 0 : pDispatch->initialize();
558 :
559 : // the dispatch container will return "this" for all commands returned by
560 : // impl_getAvailableCommands(). That means, for those commands dispatch()
561 : // is called here at the ChartController.
562 0 : m_aDispatchContainer.setChartDispatch( pDispatch, impl_getAvailableCommands() );
563 :
564 0 : DrawCommandDispatch* pDrawDispatch = new DrawCommandDispatch( m_xCC, this );
565 0 : if ( pDrawDispatch )
566 : {
567 0 : pDrawDispatch->initialize();
568 0 : m_aDispatchContainer.setDrawCommandDispatch( pDrawDispatch );
569 : }
570 :
571 0 : ShapeController* pShapeController = new ShapeController( m_xCC, this );
572 0 : if ( pShapeController )
573 : {
574 0 : pShapeController->initialize();
575 0 : m_aDispatchContainer.setShapeController( pShapeController );
576 : }
577 :
578 : #ifdef TEST_ENABLE_MODIFY_LISTENER
579 0 : uno::Reference< util::XModifyBroadcaster > xMBroadcaster( aNewModelRef->getModel(),uno::UNO_QUERY );
580 0 : if( xMBroadcaster.is())
581 0 : xMBroadcaster->addModifyListener( this );
582 : #endif
583 :
584 : //select chart area per default:
585 0 : select( uno::makeAny( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, OUString() ) ) );
586 :
587 0 : uno::Reference< lang::XMultiServiceFactory > xFact( getModel(), uno::UNO_QUERY );
588 0 : if( xFact.is())
589 : {
590 0 : m_xChartView = xFact->createInstance( CHART_VIEW_SERVICE_NAME );
591 0 : GetDrawModelWrapper();
592 0 : uno::Reference< util::XModeChangeBroadcaster > xViewBroadcaster( m_xChartView, uno::UNO_QUERY );
593 0 : if( xViewBroadcaster.is() )
594 0 : xViewBroadcaster->addModeChangeListener(this);
595 : }
596 :
597 : //the frameloader is responsible to call xModel->connectController
598 : {
599 0 : SolarMutexGuard aGuard;
600 0 : if( m_pChartWindow )
601 0 : m_pChartWindow->Invalidate();
602 : }
603 :
604 0 : uno::Reference< document::XUndoManagerSupplier > xSuppUndo( getModel(), uno::UNO_QUERY_THROW );
605 0 : m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
606 :
607 0 : return sal_True;
608 : }
609 :
610 0 : uno::Reference< frame::XFrame > SAL_CALL ChartController
611 : ::getFrame() throw(uno::RuntimeException)
612 : {
613 : //provides access to owner frame of this controller
614 : //return the frame containing this controller
615 :
616 0 : return m_xFrame;
617 : }
618 :
619 0 : uno::Reference< frame::XModel > SAL_CALL ChartController
620 : ::getModel() throw(uno::RuntimeException)
621 : {
622 : //provides access to currently attached model
623 : //returns the currently attached model
624 :
625 : //return nothing, if you do not have a model
626 0 : TheModelRef aModelRef( m_aModel, m_aModelMutex);
627 0 : if(aModelRef.is())
628 0 : return aModelRef->getModel();
629 :
630 0 : return uno::Reference< frame::XModel > ();
631 : }
632 :
633 0 : uno::Any SAL_CALL ChartController
634 : ::getViewData() throw(uno::RuntimeException)
635 : {
636 : //provides access to current view status
637 : //set of data that can be used to restore the current view status at later time
638 : // by using XController::restoreViewData()
639 :
640 0 : SolarMutexGuard aGuard;
641 0 : if( impl_isDisposedOrSuspended() )
642 0 : return uno::Any(); //behave passive if already disposed or suspended //@todo? or throw an exception??
643 :
644 : //-- collect current view state
645 0 : uno::Any aRet;
646 : //// @todo integrate specialized implementation
647 :
648 0 : return aRet;
649 : }
650 :
651 0 : void SAL_CALL ChartController
652 : ::restoreViewData( const uno::Any& /* Value */ )
653 : throw(uno::RuntimeException)
654 : {
655 : //restores the view status using the data gotten from a previous call to XController::getViewData()
656 :
657 0 : SolarMutexGuard aGuard;
658 0 : if( impl_isDisposedOrSuspended() )
659 0 : return; //behave passive if already disposed or suspended //@todo? or throw an exception??
660 :
661 : //// @todo integrate specialized implementation
662 : }
663 :
664 0 : sal_Bool SAL_CALL ChartController
665 : ::suspend( sal_Bool bSuspend )
666 : throw(uno::RuntimeException)
667 : {
668 : //is called to prepare the controller for closing the view
669 : //bSuspend==true: force the controller to suspend his work
670 : //bSuspend==false try to reactivate the controller
671 : //returns true if request was accepted and of course successfully finished, false otherwise
672 :
673 : //we may show dialogs here to ask the user for saving changes ... @todo?
674 :
675 0 : SolarMutexGuard aGuard;
676 0 : if( m_aLifeTimeManager.impl_isDisposed() )
677 0 : return sal_False; //behave passive if already disposed, return false because request was not accepted //@todo? correct
678 :
679 0 : if(bSuspend==m_bSuspended)
680 : {
681 : OSL_FAIL( "new suspend mode equals old suspend mode" );
682 0 : return sal_True;
683 : }
684 :
685 : //change suspend mode
686 0 : if(bSuspend)
687 : {
688 0 : m_bSuspended = bSuspend;
689 0 : return sal_True;
690 : }
691 : else
692 : {
693 0 : m_bSuspended = bSuspend;
694 : }
695 0 : return sal_True;
696 : }
697 :
698 :
699 0 : void ChartController::impl_createDrawViewController()
700 : {
701 0 : SolarMutexGuard aGuard;
702 0 : if(!m_pDrawViewWrapper)
703 : {
704 0 : if( m_pDrawModelWrapper )
705 : {
706 0 : m_pDrawViewWrapper = new DrawViewWrapper(&m_pDrawModelWrapper->getSdrModel(),m_pChartWindow,true);
707 0 : m_pDrawViewWrapper->attachParentReferenceDevice( getModel() );
708 : }
709 0 : }
710 0 : }
711 0 : void ChartController::impl_deleteDrawViewController()
712 : {
713 0 : if( m_pDrawViewWrapper )
714 : {
715 0 : SolarMutexGuard aGuard;
716 0 : if( m_pDrawViewWrapper->IsTextEdit() )
717 0 : this->EndTextEdit();
718 0 : DELETEZ( m_pDrawViewWrapper );
719 : }
720 0 : }
721 :
722 : //-----------------------------------------------------------------
723 : // XComponent (base of XController)
724 : //-----------------------------------------------------------------
725 :
726 0 : void SAL_CALL ChartController
727 : ::dispose() throw(uno::RuntimeException)
728 : {
729 : try
730 : {
731 : //This object should release all resources and references in the
732 : //easiest possible manner
733 : //This object must notify all registered listeners using the method
734 : //<member>XEventListener::disposing</member>
735 :
736 : //hold no mutex
737 0 : if( !m_aLifeTimeManager.dispose() )
738 0 : return;
739 :
740 : // OSL_ENSURE( m_bSuspended, "dispose was called but controller is not suspended" );
741 :
742 0 : this->stopDoubleClickWaiting();
743 :
744 : //end range highlighting
745 0 : if( m_aModel.is())
746 : {
747 0 : uno::Reference< view::XSelectionChangeListener > xSelectionChangeListener;
748 0 : uno::Reference< chart2::data::XDataReceiver > xDataReceiver( getModel(), uno::UNO_QUERY );
749 0 : if( xDataReceiver.is() )
750 0 : xSelectionChangeListener = uno::Reference< view::XSelectionChangeListener >( xDataReceiver->getRangeHighlighter(), uno::UNO_QUERY );
751 0 : if( xSelectionChangeListener.is() )
752 : {
753 0 : uno::Reference< frame::XController > xController( this );
754 0 : uno::Reference< lang::XComponent > xComp( xController, uno::UNO_QUERY );
755 0 : lang::EventObject aEvent( xComp );
756 0 : xSelectionChangeListener->disposing( aEvent );
757 0 : }
758 : }
759 :
760 : //--release all resources and references
761 : {
762 0 : uno::Reference< util::XModeChangeBroadcaster > xViewBroadcaster( m_xChartView, uno::UNO_QUERY );
763 0 : if( xViewBroadcaster.is() )
764 0 : xViewBroadcaster->removeModeChangeListener(this);
765 :
766 0 : impl_invalidateAccessible();
767 0 : SolarMutexGuard aSolarGuard;
768 0 : impl_deleteDrawViewController();
769 0 : m_pDrawModelWrapper.reset();
770 :
771 0 : m_apDropTargetHelper.reset();
772 :
773 : //the accessible view is disposed within window destructor of m_pChartWindow
774 0 : m_pChartWindow->clear();
775 0 : m_pChartWindow = NULL;//m_pChartWindow is deleted via UNO due to dispose of m_xViewWindow (trigerred by Framework (Controller pretends to be XWindow also))
776 0 : m_xViewWindow->dispose();
777 0 : m_xChartView.clear();
778 : }
779 :
780 : // remove as listener to layout manager events
781 0 : if( m_xLayoutManagerEventBroadcaster.is())
782 : {
783 0 : m_xLayoutManagerEventBroadcaster->removeLayoutManagerEventListener( this );
784 0 : m_xLayoutManagerEventBroadcaster.set( 0 );
785 : }
786 :
787 0 : m_xFrame.clear();
788 0 : m_xUndoManager.clear();
789 :
790 0 : TheModelRef aModelRef( m_aModel, m_aModelMutex);
791 0 : m_aModel = NULL;
792 :
793 0 : if( aModelRef.is())
794 : {
795 0 : uno::Reference< frame::XModel > xModel( aModelRef->getModel() );
796 0 : if(xModel.is())
797 0 : xModel->disconnectController( uno::Reference< frame::XController >( this ));
798 :
799 0 : aModelRef->removeListener( this );
800 : #ifdef TEST_ENABLE_MODIFY_LISTENER
801 : try
802 : {
803 0 : uno::Reference< util::XModifyBroadcaster > xMBroadcaster( aModelRef->getModel(),uno::UNO_QUERY );
804 0 : if( xMBroadcaster.is())
805 0 : xMBroadcaster->removeModifyListener( this );
806 : }
807 0 : catch( const uno::Exception & ex )
808 : {
809 : ASSERT_EXCEPTION( ex );
810 : }
811 : #endif
812 0 : aModelRef->tryTermination();
813 : }
814 :
815 : //// @todo integrate specialized implementation
816 : //e.g. release further resources and references
817 :
818 0 : m_aDispatchContainer.DisposeAndClear();
819 : }
820 0 : catch( const uno::Exception & ex )
821 : {
822 : ASSERT_EXCEPTION( ex );
823 : }
824 : }
825 :
826 0 : void SAL_CALL ChartController
827 : ::addEventListener( const uno::Reference<lang::XEventListener>& xListener )
828 : throw(uno::RuntimeException)
829 : {
830 0 : SolarMutexGuard aGuard;
831 0 : if( impl_isDisposedOrSuspended() )//@todo? allow adding of listeners in suspend mode?
832 0 : return; //behave passive if already disposed or suspended
833 :
834 : //--add listener
835 0 : m_aLifeTimeManager.m_aListenerContainer.addInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener );
836 : }
837 :
838 0 : void SAL_CALL ChartController
839 : ::removeEventListener( const uno::Reference<
840 : lang::XEventListener>& xListener )
841 : throw(uno::RuntimeException)
842 : {
843 0 : SolarMutexGuard aGuard;
844 0 : if( m_aLifeTimeManager.impl_isDisposed(false) )
845 0 : return; //behave passive if already disposed or suspended
846 :
847 : //--remove listener
848 0 : m_aLifeTimeManager.m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener );
849 : }
850 :
851 :
852 : //-----------------------------------------------------------------
853 : // util::XCloseListener
854 : //-----------------------------------------------------------------
855 0 : void SAL_CALL ChartController
856 : ::queryClosing( const lang::EventObject& rSource, sal_Bool bGetsOwnership )
857 : throw(util::CloseVetoException, uno::RuntimeException)
858 : {
859 : //do not use the m_aControllerMutex here because this call is not allowed to block
860 :
861 0 : TheModelRef aModelRef( m_aModel, m_aModelMutex);
862 :
863 0 : if( !aModelRef.is() )
864 : return;
865 :
866 0 : if( !(aModelRef->getModel() == rSource.Source) )
867 : {
868 : OSL_FAIL( "queryClosing was called on a controller from an unknown source" );
869 : return;
870 : }
871 :
872 0 : if( !m_bCanClose )//@todo tryaqcuire mutex
873 : {
874 0 : if( bGetsOwnership )
875 : {
876 0 : aModelRef->SetOwnerShip( bGetsOwnership );
877 : }
878 :
879 0 : throw util::CloseVetoException();
880 : }
881 : else
882 : {
883 : //@ todo prepare to to closing model -> don't start any further hindering actions
884 0 : }
885 : }
886 :
887 0 : void SAL_CALL ChartController
888 : ::notifyClosing( const lang::EventObject& rSource )
889 : throw(uno::RuntimeException)
890 : {
891 : //Listener should deregister himself and relaese all references to the closing object.
892 :
893 0 : TheModelRef aModelRef( m_aModel, m_aModelMutex);
894 0 : if( impl_releaseThisModel( rSource.Source ) )
895 : {
896 : //--stop listening to the closing model
897 0 : aModelRef->removeListener( this );
898 :
899 : // #i79087# If the model using this controller is closed, the frame is
900 : // expected to be closed as well
901 0 : Reference< util::XCloseable > xFrameCloseable( m_xFrame, uno::UNO_QUERY );
902 0 : if( xFrameCloseable.is())
903 : {
904 : try
905 : {
906 0 : xFrameCloseable->close( sal_False /* DeliverOwnership */ );
907 0 : m_xFrame.clear();
908 : }
909 0 : catch( const util::CloseVetoException & )
910 : {
911 : // closing was vetoed
912 : }
913 0 : }
914 0 : }
915 0 : }
916 :
917 0 : bool ChartController::impl_releaseThisModel( const uno::Reference< uno::XInterface > & xModel )
918 : {
919 0 : bool bReleaseModel = sal_False;
920 : {
921 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_aModelMutex );
922 0 : if( m_aModel.is() && m_aModel->getModel() == xModel )
923 : {
924 0 : m_aModel = NULL;
925 0 : m_xUndoManager.clear();
926 0 : bReleaseModel = true;
927 0 : }
928 : }
929 0 : if( bReleaseModel )
930 0 : m_aDispatchContainer.setModel( 0 );
931 0 : return bReleaseModel;
932 : }
933 :
934 : //-----------------------------------------------------------------
935 : // util::XEventListener (base of XCloseListener)
936 : //-----------------------------------------------------------------
937 0 : void SAL_CALL ChartController
938 : ::disposing( const lang::EventObject& rSource )
939 : throw(uno::RuntimeException)
940 : {
941 0 : if( !impl_releaseThisModel( rSource.Source ))
942 : {
943 0 : if( rSource.Source == m_xLayoutManagerEventBroadcaster )
944 0 : m_xLayoutManagerEventBroadcaster.set( 0 );
945 : }
946 0 : }
947 :
948 0 : void SAL_CALL ChartController::layoutEvent( const lang::EventObject& aSource, ::sal_Int16 eLayoutEvent, const uno::Any& /* aInfo */ )
949 : throw (uno::RuntimeException)
950 : {
951 0 : if( eLayoutEvent == frame::LayoutManagerEvents::MERGEDMENUBAR )
952 : {
953 0 : Reference< frame::XLayoutManager > xLM( aSource.Source, uno::UNO_QUERY );
954 0 : if( xLM.is())
955 : {
956 0 : xLM->createElement( "private:resource/statusbar/statusbar" );
957 0 : xLM->requestElement( "private:resource/statusbar/statusbar" );
958 0 : }
959 : }
960 0 : }
961 :
962 :
963 : //-----------------------------------------------------------------
964 : // XDispatchProvider (required interface)
965 : //-----------------------------------------------------------------
966 :
967 : namespace
968 : {
969 0 : bool lcl_isFormatObjectCommand( const OString& aCommand )
970 : {
971 0 : if( aCommand == "MainTitle"
972 0 : || aCommand == "SubTitle"
973 0 : || aCommand == "XTitle"
974 0 : || aCommand == "YTitle"
975 0 : || aCommand == "ZTitle"
976 0 : || aCommand == "SecondaryXTitle"
977 0 : || aCommand == "SecondaryYTitle"
978 0 : || aCommand == "AllTitles"
979 0 : || aCommand == "DiagramAxisX"
980 0 : || aCommand == "DiagramAxisY"
981 0 : || aCommand == "DiagramAxisZ"
982 0 : || aCommand == "DiagramAxisA"
983 0 : || aCommand == "DiagramAxisB"
984 0 : || aCommand == "DiagramAxisAll"
985 0 : || aCommand == "DiagramGridXMain"
986 0 : || aCommand == "DiagramGridYMain"
987 0 : || aCommand == "DiagramGridZMain"
988 0 : || aCommand == "DiagramGridXHelp"
989 0 : || aCommand == "DiagramGridYHelp"
990 0 : || aCommand == "DiagramGridZHelp"
991 0 : || aCommand == "DiagramGridAll"
992 :
993 0 : || aCommand == "DiagramWall"
994 0 : || aCommand == "DiagramFloor"
995 0 : || aCommand == "DiagramArea"
996 0 : || aCommand == "Legend"
997 :
998 0 : || aCommand == "FormatWall"
999 0 : || aCommand == "FormatFloor"
1000 0 : || aCommand == "FormatChartArea"
1001 0 : || aCommand == "FormatLegend"
1002 :
1003 0 : || aCommand == "FormatTitle"
1004 0 : || aCommand == "FormatAxis"
1005 0 : || aCommand == "FormatDataSeries"
1006 0 : || aCommand == "FormatDataPoint"
1007 0 : || aCommand == "FormatDataLabels"
1008 0 : || aCommand == "FormatDataLabel"
1009 0 : || aCommand == "FormatXErrorBars"
1010 0 : || aCommand == "FormatYErrorBars"
1011 0 : || aCommand == "FormatMeanValue"
1012 0 : || aCommand == "FormatTrendline"
1013 0 : || aCommand == "FormatTrendlineEquation"
1014 0 : || aCommand == "FormatStockLoss"
1015 0 : || aCommand == "FormatStockGain"
1016 0 : || aCommand == "FormatMajorGrid"
1017 0 : || aCommand == "FormatMinorGrid"
1018 : )
1019 0 : return true;
1020 :
1021 : // else
1022 0 : return false;
1023 : }
1024 : } // anonymous namespace
1025 :
1026 0 : uno::Reference<frame::XDispatch> SAL_CALL ChartController
1027 : ::queryDispatch( const util::URL& rURL
1028 : , const OUString& rTargetFrameName
1029 : , sal_Int32 /* nSearchFlags */)
1030 : throw(uno::RuntimeException)
1031 : {
1032 0 : if ( !m_aLifeTimeManager.impl_isDisposed() && getModel().is() )
1033 : {
1034 0 : if( !rTargetFrameName.isEmpty() && rTargetFrameName == "_self" )
1035 0 : return m_aDispatchContainer.getDispatchForURL( rURL );
1036 : }
1037 0 : return uno::Reference< frame::XDispatch > ();
1038 : }
1039 :
1040 0 : uno::Sequence<uno::Reference<frame::XDispatch > > ChartController
1041 : ::queryDispatches( const uno::Sequence<
1042 : frame::DispatchDescriptor>& xDescripts)
1043 : throw(uno::RuntimeException)
1044 : {
1045 0 : if ( !m_aLifeTimeManager.impl_isDisposed() )
1046 : {
1047 0 : return m_aDispatchContainer.getDispatchesForURLs( xDescripts );
1048 : }
1049 0 : return uno::Sequence<uno::Reference<frame::XDispatch > > ();
1050 : }
1051 :
1052 : //-----------------------------------------------------------------
1053 : // frame::XDispatch
1054 : //-----------------------------------------------------------------
1055 :
1056 0 : void SAL_CALL ChartController
1057 : ::dispatch( const util::URL& rURL
1058 : , const uno::Sequence< beans::PropertyValue >& rArgs )
1059 : throw (uno::RuntimeException)
1060 : {
1061 : //@todo avoid OString
1062 0 : OString aCommand( OUStringToOString( rURL.Path, RTL_TEXTENCODING_ASCII_US ) );
1063 :
1064 0 : if(aCommand == "Paste")
1065 0 : this->executeDispatch_Paste();
1066 0 : else if(aCommand == "Copy" )
1067 0 : this->executeDispatch_Copy();
1068 0 : else if(aCommand == "Cut" )
1069 0 : this->executeDispatch_Cut();
1070 0 : else if(aCommand == "DataRanges" )
1071 0 : this->executeDispatch_SourceData();
1072 : //----------------------------------
1073 0 : else if(aCommand == "Update" ) //Update Chart
1074 : {
1075 0 : ChartViewHelper::setViewToDirtyState( getModel() );
1076 0 : SolarMutexGuard aGuard;
1077 0 : if( m_pChartWindow )
1078 0 : m_pChartWindow->Invalidate();
1079 : }
1080 0 : else if(aCommand == "DiagramData" )
1081 0 : this->executeDispatch_EditData();
1082 : //insert objects
1083 0 : else if( aCommand == "InsertTitles"
1084 0 : || aCommand == "InsertMenuTitles")
1085 0 : this->executeDispatch_InsertTitles();
1086 0 : else if( aCommand == "InsertMenuLegend" )
1087 0 : this->executeDispatch_OpenLegendDialog();
1088 0 : else if( aCommand == "InsertLegend" )
1089 0 : this->executeDispatch_InsertLegend();
1090 0 : else if( aCommand == "DeleteLegend" )
1091 0 : this->executeDispatch_DeleteLegend();
1092 0 : else if( aCommand == "InsertMenuDataLabels" )
1093 0 : this->executeDispatch_InsertMenu_DataLabels();
1094 0 : else if( aCommand == "InsertMenuAxes"
1095 0 : || aCommand == "InsertRemoveAxes" )
1096 0 : this->executeDispatch_InsertAxes();
1097 0 : else if( aCommand == "InsertMenuGrids" )
1098 0 : this->executeDispatch_InsertGrid();
1099 0 : else if( aCommand == "InsertMenuTrendlines" )
1100 0 : this->executeDispatch_InsertMenu_Trendlines();
1101 0 : else if( aCommand == "InsertMenuMeanValues" )
1102 0 : this->executeDispatch_InsertMenu_MeanValues();
1103 0 : else if( aCommand == "InsertMenuXErrorBars" )
1104 0 : this->executeDispatch_InsertErrorBars(false);
1105 0 : else if( aCommand == "InsertMenuYErrorBars" )
1106 0 : this->executeDispatch_InsertErrorBars(true);
1107 0 : else if( aCommand == "InsertSymbol" )
1108 0 : this->executeDispatch_InsertSpecialCharacter();
1109 0 : else if( aCommand == "InsertTrendline" )
1110 0 : this->executeDispatch_InsertTrendline();
1111 0 : else if( aCommand == "DeleteTrendline" )
1112 0 : this->executeDispatch_DeleteTrendline();
1113 0 : else if( aCommand == "InsertMeanValue" )
1114 0 : this->executeDispatch_InsertMeanValue();
1115 0 : else if( aCommand == "DeleteMeanValue" )
1116 0 : this->executeDispatch_DeleteMeanValue();
1117 0 : else if( aCommand == "InsertXErrorBars" )
1118 0 : this->executeDispatch_InsertErrorBars(false);
1119 0 : else if( aCommand == "InsertYErrorBars" )
1120 0 : this->executeDispatch_InsertErrorBars(true);
1121 0 : else if( aCommand == "DeleteXErrorBars" )
1122 0 : this->executeDispatch_DeleteErrorBars(false);
1123 0 : else if( aCommand == "DeleteYErrorBars" )
1124 0 : this->executeDispatch_DeleteErrorBars(true);
1125 0 : else if( aCommand == "InsertTrendlineEquation" )
1126 0 : this->executeDispatch_InsertTrendlineEquation();
1127 0 : else if( aCommand == "DeleteTrendlineEquation" )
1128 0 : this->executeDispatch_DeleteTrendlineEquation();
1129 0 : else if( aCommand == "InsertTrendlineEquationAndR2" )
1130 0 : this->executeDispatch_InsertTrendlineEquation( true );
1131 0 : else if( aCommand == "InsertR2Value" )
1132 0 : this->executeDispatch_InsertR2Value();
1133 0 : else if( aCommand == "DeleteR2Value")
1134 0 : this->executeDispatch_DeleteR2Value();
1135 0 : else if( aCommand == "InsertDataLabels" )
1136 0 : this->executeDispatch_InsertDataLabels();
1137 0 : else if( aCommand == "InsertDataLabel" )
1138 0 : this->executeDispatch_InsertDataLabel();
1139 0 : else if( aCommand == "DeleteDataLabels")
1140 0 : this->executeDispatch_DeleteDataLabels();
1141 0 : else if( aCommand == "DeleteDataLabel" )
1142 0 : this->executeDispatch_DeleteDataLabel();
1143 0 : else if( aCommand == "ResetAllDataPoints" )
1144 0 : this->executeDispatch_ResetAllDataPoints();
1145 0 : else if( aCommand == "ResetDataPoint" )
1146 0 : this->executeDispatch_ResetDataPoint();
1147 0 : else if( aCommand == "InsertAxis" )
1148 0 : this->executeDispatch_InsertAxis();
1149 0 : else if( aCommand == "InsertMajorGrid" )
1150 0 : this->executeDispatch_InsertMajorGrid();
1151 0 : else if( aCommand == "InsertMinorGrid" )
1152 0 : this->executeDispatch_InsertMinorGrid();
1153 0 : else if( aCommand == "InsertAxisTitle" )
1154 0 : this->executeDispatch_InsertAxisTitle();
1155 0 : else if( aCommand == "DeleteAxis" )
1156 0 : this->executeDispatch_DeleteAxis();
1157 0 : else if( aCommand == "DeleteMajorGrid")
1158 0 : this->executeDispatch_DeleteMajorGrid();
1159 0 : else if( aCommand == "DeleteMinorGrid" )
1160 0 : this->executeDispatch_DeleteMinorGrid();
1161 : //format objects
1162 0 : else if( aCommand == "FormatSelection" )
1163 0 : this->executeDispatch_ObjectProperties();
1164 0 : else if( aCommand == "TransformDialog" )
1165 : {
1166 0 : if ( isShapeContext() )
1167 : {
1168 0 : this->impl_ShapeControllerDispatch( rURL, rArgs );
1169 : }
1170 : else
1171 : {
1172 0 : this->executeDispatch_PositionAndSize();
1173 : }
1174 : }
1175 0 : else if( lcl_isFormatObjectCommand(aCommand) )
1176 0 : this->executeDispatch_FormatObject(rURL.Path);
1177 : //more format
1178 0 : else if( aCommand == "DiagramType" )
1179 0 : this->executeDispatch_ChartType();
1180 0 : else if( aCommand == "View3D" )
1181 0 : this->executeDispatch_View3D();
1182 0 : else if ( aCommand == "Forward" )
1183 : {
1184 0 : if ( isShapeContext() )
1185 : {
1186 0 : this->impl_ShapeControllerDispatch( rURL, rArgs );
1187 : }
1188 : else
1189 : {
1190 0 : this->executeDispatch_MoveSeries( sal_True );
1191 : }
1192 : }
1193 0 : else if ( aCommand == "Backward" )
1194 : {
1195 0 : if ( isShapeContext() )
1196 : {
1197 0 : this->impl_ShapeControllerDispatch( rURL, rArgs );
1198 : }
1199 : else
1200 : {
1201 0 : this->executeDispatch_MoveSeries( sal_False );
1202 : }
1203 : }
1204 0 : else if( aCommand == "NewArrangement")
1205 0 : this->executeDispatch_NewArrangement();
1206 0 : else if( aCommand == "ToggleLegend" )
1207 0 : this->executeDispatch_ToggleLegend();
1208 0 : else if( aCommand == "ToggleGridHorizontal" )
1209 0 : this->executeDispatch_ToggleGridHorizontal();
1210 0 : else if( aCommand == "ScaleText" )
1211 0 : this->executeDispatch_ScaleText();
1212 0 : else if( aCommand == "StatusBarVisible" )
1213 : {
1214 : // workaround: this should not be necessary.
1215 0 : uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY );
1216 0 : if( xPropSet.is() )
1217 : {
1218 0 : uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
1219 0 : xPropSet->getPropertyValue( "LayoutManager" ) >>= xLayoutManager;
1220 0 : if ( xLayoutManager.is() )
1221 : {
1222 0 : bool bIsVisible( xLayoutManager->isElementVisible( "private:resource/statusbar/statusbar" ));
1223 0 : if( bIsVisible )
1224 : {
1225 0 : xLayoutManager->hideElement( "private:resource/statusbar/statusbar" );
1226 0 : xLayoutManager->destroyElement( "private:resource/statusbar/statusbar" );
1227 : }
1228 : else
1229 : {
1230 0 : xLayoutManager->createElement( "private:resource/statusbar/statusbar" );
1231 0 : xLayoutManager->showElement( "private:resource/statusbar/statusbar" );
1232 : }
1233 : // @todo: update menu state (checkmark next to "Statusbar").
1234 0 : }
1235 0 : }
1236 0 : }
1237 0 : }
1238 :
1239 0 : void SAL_CALL ChartController
1240 : ::addStatusListener( const uno::Reference<frame::XStatusListener >& /* xControl */
1241 : , const util::URL& /* aURL */ )
1242 : throw (uno::RuntimeException)
1243 : {
1244 : //@todo
1245 0 : }
1246 :
1247 0 : void SAL_CALL ChartController
1248 : ::removeStatusListener( const uno::Reference<frame::XStatusListener >& /* xControl */
1249 : , const util::URL& /* aURL */ )
1250 : throw (uno::RuntimeException)
1251 : {
1252 : //@todo
1253 0 : }
1254 :
1255 : //-----------------------------------------------------------------
1256 : // XContextMenuInterception (optional interface)
1257 : //-----------------------------------------------------------------
1258 0 : void SAL_CALL ChartController
1259 : ::registerContextMenuInterceptor( const uno::Reference<
1260 : ui::XContextMenuInterceptor > & /* xInterceptor */)
1261 : throw(uno::RuntimeException)
1262 : {
1263 : //@todo
1264 0 : }
1265 :
1266 0 : void SAL_CALL ChartController
1267 : ::releaseContextMenuInterceptor( const uno::Reference<
1268 : ui::XContextMenuInterceptor > & /* xInterceptor */)
1269 : throw(uno::RuntimeException)
1270 : {
1271 : //@todo
1272 0 : }
1273 :
1274 : // ____ XEmbeddedClient ____
1275 : // implementation see: ChartController_EditData.cxx
1276 :
1277 : //-----------------------------------------------------------------------------
1278 : //-----------------------------------------------------------------------------
1279 : //-----------------------------------------------------------------------------
1280 :
1281 0 : void SAL_CALL ChartController::executeDispatch_ChartType()
1282 : {
1283 : // using assignment for broken gcc 3.3
1284 : UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
1285 0 : String( SchResId( STR_ACTION_EDIT_CHARTTYPE )), m_xUndoManager );
1286 :
1287 0 : SolarMutexGuard aSolarGuard;
1288 : //prepare and open dialog
1289 0 : ChartTypeDialog aDlg( m_pChartWindow, getModel(), m_xCC );
1290 0 : if( aDlg.Execute() == RET_OK )
1291 : {
1292 0 : impl_adaptDataSeriesAutoResize();
1293 0 : aUndoGuard.commit();
1294 0 : }
1295 0 : }
1296 :
1297 0 : void SAL_CALL ChartController::executeDispatch_SourceData()
1298 : {
1299 : //-------------------------------------------------------------
1300 : //convert properties to ItemSet
1301 0 : uno::Reference< XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY );
1302 : OSL_ENSURE( xChartDoc.is(), "Invalid XChartDocument" );
1303 0 : if( !xChartDoc.is())
1304 0 : return;
1305 :
1306 : // using assignment for broken gcc 3.3
1307 : UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
1308 0 : String( SchResId( STR_ACTION_EDIT_DATA_RANGES )), m_xUndoManager );
1309 0 : if( xChartDoc.is())
1310 : {
1311 0 : SolarMutexGuard aSolarGuard;
1312 0 : ::chart::DataSourceDialog aDlg( m_pChartWindow, xChartDoc, m_xCC );
1313 0 : if( aDlg.Execute() == RET_OK )
1314 : {
1315 0 : impl_adaptDataSeriesAutoResize();
1316 0 : aUndoGuard.commit();
1317 0 : }
1318 0 : }
1319 : }
1320 :
1321 0 : void SAL_CALL ChartController::executeDispatch_MoveSeries( sal_Bool bForward )
1322 : {
1323 0 : ControllerLockGuard aCLGuard( getModel() );
1324 :
1325 : //get selected series
1326 0 : OUString aObjectCID(m_aSelection.getSelectedCID());
1327 : uno::Reference< XDataSeries > xGivenDataSeries( ObjectIdentifier::getDataSeriesForCID( //yyy todo also legendentries and labels?
1328 0 : aObjectCID, getModel() ) );
1329 :
1330 : UndoGuardWithSelection aUndoGuard(
1331 : ActionDescriptionProvider::createDescription(
1332 : (bForward ? ActionDescriptionProvider::MOVE_TOTOP : ActionDescriptionProvider::MOVE_TOBOTTOM),
1333 : String( SchResId( STR_OBJECT_DATASERIES ))),
1334 0 : m_xUndoManager );
1335 :
1336 0 : bool bChanged = DiagramHelper::moveSeries( ChartModelHelper::findDiagram( getModel() ), xGivenDataSeries, bForward );
1337 0 : if( bChanged )
1338 : {
1339 0 : m_aSelection.setSelection( ObjectIdentifier::getMovedSeriesCID( aObjectCID, bForward ) );
1340 0 : aUndoGuard.commit();
1341 0 : }
1342 0 : }
1343 :
1344 : // ____ XMultiServiceFactory ____
1345 : uno::Reference< uno::XInterface > SAL_CALL
1346 0 : ChartController::createInstance( const OUString& aServiceSpecifier )
1347 : throw (uno::Exception,
1348 : uno::RuntimeException)
1349 : {
1350 0 : uno::Reference< uno::XInterface > xResult;
1351 :
1352 0 : if( aServiceSpecifier == CHART_ACCESSIBLE_TEXT_SERVICE_NAME )
1353 0 : xResult.set( impl_createAccessibleTextContext());
1354 0 : return xResult;
1355 : }
1356 :
1357 : uno::Reference< uno::XInterface > SAL_CALL
1358 0 : ChartController::createInstanceWithArguments( const OUString& ServiceSpecifier,
1359 : const uno::Sequence< uno::Any >& /* Arguments */ )
1360 : throw (uno::Exception,
1361 : uno::RuntimeException)
1362 : {
1363 : // ignore Arguments
1364 0 : return createInstance( ServiceSpecifier );
1365 : }
1366 :
1367 : uno::Sequence< OUString > SAL_CALL
1368 0 : ChartController::getAvailableServiceNames()
1369 : throw (uno::RuntimeException)
1370 : {
1371 0 : uno::Sequence< OUString > aServiceNames(1);
1372 0 : aServiceNames[0] = CHART_ACCESSIBLE_TEXT_SERVICE_NAME;
1373 0 : return aServiceNames;
1374 : }
1375 :
1376 : // ____ XModifyListener ____
1377 0 : void SAL_CALL ChartController::modified( const lang::EventObject& /* aEvent */ )
1378 : throw (uno::RuntimeException)
1379 : {
1380 : // the source can also be a subobject of the ChartModel
1381 : // @todo: change the source in ChartModel to always be the model itself ?
1382 : //todo? update menu states ?
1383 0 : }
1384 :
1385 : //-----------------------------------------------------------------------------
1386 :
1387 0 : IMPL_LINK( ChartController, NotifyUndoActionHdl, SdrUndoAction*, pUndoAction )
1388 : {
1389 0 : ENSURE_OR_RETURN( pUndoAction, "invalid Undo action", 1L );
1390 :
1391 0 : OUString aObjectCID = m_aSelection.getSelectedCID();
1392 0 : if ( aObjectCID.isEmpty() )
1393 : {
1394 : try
1395 : {
1396 0 : const Reference< document::XUndoManagerSupplier > xSuppUndo( getModel(), uno::UNO_QUERY_THROW );
1397 0 : const Reference< document::XUndoManager > xUndoManager( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
1398 0 : const Reference< document::XUndoAction > xAction( new impl::ShapeUndoElement( *pUndoAction ) );
1399 0 : xUndoManager->addUndoAction( xAction );
1400 : }
1401 0 : catch( const uno::Exception& )
1402 : {
1403 : DBG_UNHANDLED_EXCEPTION();
1404 : }
1405 : }
1406 0 : return 0L;
1407 : }
1408 :
1409 0 : DrawModelWrapper* ChartController::GetDrawModelWrapper()
1410 : {
1411 0 : if( !m_pDrawModelWrapper.get() )
1412 : {
1413 0 : ExplicitValueProvider* pProvider = ExplicitValueProvider::getExplicitValueProvider( m_xChartView );
1414 0 : if( pProvider )
1415 0 : m_pDrawModelWrapper = pProvider->getDrawModelWrapper();
1416 0 : if ( m_pDrawModelWrapper.get() )
1417 : {
1418 0 : m_pDrawModelWrapper->getSdrModel().SetNotifyUndoActionHdl( LINK( this, ChartController, NotifyUndoActionHdl ) );
1419 : }
1420 : }
1421 0 : return m_pDrawModelWrapper.get();
1422 : }
1423 :
1424 0 : DrawViewWrapper* ChartController::GetDrawViewWrapper()
1425 : {
1426 0 : if ( !m_pDrawViewWrapper )
1427 : {
1428 0 : impl_createDrawViewController();
1429 : }
1430 0 : return m_pDrawViewWrapper;
1431 : }
1432 :
1433 0 : uno::Reference< XAccessible > ChartController::CreateAccessible()
1434 : {
1435 0 : uno::Reference< XAccessible > xResult = new AccessibleChartView( m_xCC, GetDrawViewWrapper() );
1436 0 : impl_initializeAccessible( uno::Reference< lang::XInitialization >( xResult, uno::UNO_QUERY ) );
1437 0 : return xResult;
1438 : }
1439 :
1440 0 : void ChartController::impl_invalidateAccessible()
1441 : {
1442 0 : SolarMutexGuard aGuard;
1443 0 : if( m_pChartWindow )
1444 : {
1445 0 : Reference< lang::XInitialization > xInit( m_pChartWindow->GetAccessible(false), uno::UNO_QUERY );
1446 0 : if(xInit.is())
1447 : {
1448 0 : uno::Sequence< uno::Any > aArguments(3);//empty arguments -> invalid accessible
1449 0 : xInit->initialize(aArguments);
1450 0 : }
1451 0 : }
1452 0 : }
1453 0 : void ChartController::impl_initializeAccessible()
1454 : {
1455 0 : SolarMutexGuard aGuard;
1456 0 : if( m_pChartWindow )
1457 0 : this->impl_initializeAccessible( Reference< lang::XInitialization >( m_pChartWindow->GetAccessible(false), uno::UNO_QUERY ) );
1458 0 : }
1459 0 : void ChartController::impl_initializeAccessible( const uno::Reference< lang::XInitialization >& xInit )
1460 : {
1461 0 : if(xInit.is())
1462 : {
1463 0 : uno::Sequence< uno::Any > aArguments(5);
1464 0 : uno::Reference<view::XSelectionSupplier> xSelectionSupplier(this);
1465 0 : aArguments[0]=uno::makeAny(xSelectionSupplier);
1466 0 : uno::Reference<frame::XModel> xModel(getModel());
1467 0 : aArguments[1]=uno::makeAny(xModel);
1468 0 : aArguments[2]=uno::makeAny(m_xChartView);
1469 0 : uno::Reference< XAccessible > xParent;
1470 : {
1471 0 : SolarMutexGuard aGuard;
1472 0 : if( m_pChartWindow )
1473 : {
1474 0 : Window* pParentWin( m_pChartWindow->GetAccessibleParentWindow());
1475 0 : if( pParentWin )
1476 0 : xParent.set( pParentWin->GetAccessible());
1477 0 : }
1478 : }
1479 0 : aArguments[3]=uno::makeAny(xParent);
1480 0 : aArguments[4]=uno::makeAny(m_xViewWindow);
1481 :
1482 0 : xInit->initialize(aArguments);
1483 : }
1484 0 : }
1485 :
1486 0 : ::std::set< OUString > ChartController::impl_getAvailableCommands()
1487 : {
1488 : return ::comphelper::MakeSet< OUString >
1489 : // commands for container forward
1490 0 : ( "AddDirect" ) ( "NewDoc" ) ( "Open" )
1491 0 : ( "Save" ) ( "SaveAs" ) ( "SendMail" )
1492 0 : ( "EditDoc" ) ( "ExportDirectToPDF" ) ( "PrintDefault" )
1493 :
1494 : // own commands
1495 0 : ( "Cut" ) ( "Copy" ) ( "Paste" )
1496 0 : ( "DataRanges" ) ( "DiagramData" )
1497 : // insert objects
1498 0 : ( "InsertMenuTitles" ) ( "InsertTitles" )
1499 0 : ( "InsertMenuLegend" ) ( "InsertLegend" ) ( "DeleteLegend" )
1500 0 : ( "InsertMenuDataLabels" )
1501 0 : ( "InsertMenuAxes" ) ( "InsertRemoveAxes" ) ( "InsertMenuGrids" )
1502 0 : ( "InsertSymbol" )
1503 0 : ( "InsertTrendlineEquation" ) ( "InsertTrendlineEquationAndR2" )
1504 0 : ( "InsertR2Value" ) ( "DeleteR2Value" )
1505 0 : ( "InsertMenuTrendlines" ) ( "InsertTrendline" )
1506 0 : ( "InsertMenuMeanValues" ) ( "InsertMeanValue" )
1507 0 : ( "InsertMenuXErrorBars" ) ( "InsertXErrorBars" )
1508 0 : ( "InsertMenuYErrorBars" ) ( "InsertYErrorBars" )
1509 0 : ( "InsertDataLabels" ) ( "InsertDataLabel" )
1510 0 : ( "DeleteTrendline" ) ( "DeleteMeanValue" ) ( "DeleteTrendlineEquation" )
1511 0 : ( "DeleteXErrorBars" ) ( "DeleteYErrorBars" )
1512 0 : ( "DeleteDataLabels" ) ( "DeleteDataLabel" )
1513 : //format objects
1514 0 : ( "FormatSelection" ) ( "TransformDialog" )
1515 0 : ( "DiagramType" ) ( "View3D" )
1516 0 : ( "Forward" ) ( "Backward" )
1517 0 : ( "MainTitle" ) ( "SubTitle" )
1518 0 : ( "XTitle" ) ( "YTitle" ) ( "ZTitle" )
1519 0 : ( "SecondaryXTitle" ) ( "SecondaryYTitle" )
1520 0 : ( "AllTitles" ) ( "Legend" )
1521 0 : ( "DiagramAxisX" ) ( "DiagramAxisY" ) ( "DiagramAxisZ" )
1522 0 : ( "DiagramAxisA" ) ( "DiagramAxisB" ) ( "DiagramAxisAll" )
1523 0 : ( "DiagramGridXMain" ) ( "DiagramGridYMain" ) ( "DiagramGridZMain" )
1524 0 : ( "DiagramGridXHelp" ) ( "DiagramGridYHelp" ) ( "DiagramGridZHelp" )
1525 0 : ( "DiagramGridAll" )
1526 0 : ( "DiagramWall" ) ( "DiagramFloor" ) ( "DiagramArea" )
1527 :
1528 : //context menu - format objects entries
1529 0 : ( "FormatWall" ) ( "FormatFloor" ) ( "FormatChartArea" )
1530 0 : ( "FormatLegend" )
1531 :
1532 0 : ( "FormatAxis" ) ( "FormatTitle" )
1533 0 : ( "FormatDataSeries" ) ( "FormatDataPoint" )
1534 0 : ( "ResetAllDataPoints" ) ( "ResetDataPoint" )
1535 0 : ( "FormatDataLabels" ) ( "FormatDataLabel" )
1536 0 : ( "FormatMeanValue" ) ( "FormatTrendline" ) ( "FormatTrendlineEquation" )
1537 0 : ( "FormatXErrorBars" ) ( "FormatYErrorBars" )
1538 0 : ( "FormatStockLoss" ) ( "FormatStockGain" )
1539 :
1540 0 : ( "FormatMajorGrid" ) ( "InsertMajorGrid" ) ( "DeleteMajorGrid" )
1541 0 : ( "FormatMinorGrid" ) ( "InsertMinorGrid" ) ( "DeleteMinorGrid" )
1542 0 : ( "InsertAxis" ) ( "DeleteAxis" ) ( "InsertAxisTitle" )
1543 :
1544 : // toolbar commands
1545 0 : ( "ToggleGridHorizontal" )( "ToggleLegend" ) ( "ScaleText" )
1546 0 : ( "NewArrangement" ) ( "Update" )
1547 0 : ( "DefaultColors" ) ( "BarWidth" ) ( "NumberOfLines" )
1548 0 : ( "ArrangeRow" )
1549 0 : ( "StatusBarVisible" )
1550 0 : ( "ChartElementSelector" )
1551 : ;
1552 : }
1553 :
1554 : //.............................................................................
1555 : } //namespace chart
1556 : //.............................................................................
1557 :
1558 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|