Debian Codegraph @

chart2/source/controller/main/ChartController.cxx

raw
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 <memory>
21 #include <sal/config.h>
22
23 #include <config_wasm_strip.h>
24 #include <ChartController.hxx>
25 #include <ChartView.hxx>
26 #include <ResId.hxx>
27 #include <dlg_DataSource.hxx>
28 #include <ChartModel.hxx>
29 #include <ChartType.hxx>
30 #include <ControllerCommandDispatch.hxx>
31 #include <DataSeries.hxx>
32 #include <Diagram.hxx>
33 #include <strings.hrc>
34 #include <ChartViewHelper.hxx>
35
36 #include <ChartWindow.hxx>
37 #include <chartview/DrawModelWrapper.hxx>
38 #include <DrawViewWrapper.hxx>
39 #include <ObjectIdentifier.hxx>
40 #include <ControllerLockGuard.hxx>
41 #include "UndoGuard.hxx"
42 #include "ChartDropTargetHelper.hxx"
43
44 #include <dlg_ChartType.hxx>
45 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
46 #include <AccessibleChartView.hxx>
47 #endif
48 #include "DrawCommandDispatch.hxx"
49 #include "ShapeController.hxx"
50 #include "UndoActions.hxx"
51 #include <ViewElementListProvider.hxx>
52
53 #include <BaseCoordinateSystem.hxx>
54
55 #include <com/sun/star/frame/XController2.hpp>
56 #include <com/sun/star/util/CloseVetoException.hpp>
57 #include <com/sun/star/frame/LayoutManagerEvents.hpp>
58 #include <com/sun/star/frame/XLayoutManagerEventBroadcaster.hpp>
59 #include <com/sun/star/ui/XSidebar.hpp>
60 #include <com/sun/star/chart2/XDataProviderAccess.hpp>
61 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
62
63 #include <sal/log.hxx>
64 #include <tools/debug.hxx>
65 #include <svx/sidebar/SelectionChangeHandler.hxx>
66 #include <toolkit/helper/vclunohelper.hxx>
67 #include <utility>
68 #include <vcl/dndlistenercontainer.hxx>
69 #include <vcl/svapp.hxx>
70 #include <vcl/weld.hxx>
71 #include <osl/mutex.hxx>
72 #include <comphelper/lok.hxx>
73
74 #include <sfx2/sidebar/SidebarController.hxx>
75 #include <com/sun/star/frame/XLayoutManager.hpp>
76
77 // this is needed to properly destroy the unique_ptr to the AcceleratorExecute
78 // object in the DTOR
79 #include <svtools/acceleratorexecute.hxx>
80 #include <svx/ActionDescriptionProvider.hxx>
81 #include <comphelper/diagnose_ex.hxx>
82
83 // enable the following define to let the controller listen to model changes and
84 // react on this by rebuilding the view
85 #define TEST_ENABLE_MODIFY_LISTENER
86
87 namespace chart
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::Reference;
94 using ::com::sun::star::uno::Sequence;
95
96 ChartController::ChartController(uno::Reference<uno::XComponentContext> xContext) :
97 m_aLifeTimeManager( nullptr ),
98 m_bSuspended( false ),
99 m_xCC(std::move(xContext)),
100 m_aModel( nullptr, m_aModelMutex ),
101 m_eDragMode(SdrDragMode::Move),
102 m_aDoubleClickTimer("chart2 ChartController m_aDoubleClickTimer"),
103 m_bWaitingForDoubleClick(false),
104 m_bWaitingForMouseUp(false),
105 m_bFieldButtonDown(false),
106 m_bConnectingToView(false),
107 m_bDisposed(false),
108 m_aDispatchContainer( m_xCC ),
109 m_eDrawMode( CHARTDRAW_SELECT ),
110 mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
111 [this]() { return this->GetContextName(); },
112 this, vcl::EnumContext::Context::Cell))
113 {
114 m_aDoubleClickTimer.SetInvokeHandler( LINK( this, ChartController, DoubleClickWaitingHdl ) );
115 }
116
117 ChartController::~ChartController()
118 {
119 stopDoubleClickWaiting();
120 }
121
122 ChartController::TheModel::TheModel( rtl::Reference<::chart::ChartModel> xModel ) :
123 m_xModel(std::move( xModel )),
124 m_bOwnership( true )
125 {
126 }
127
128 ChartController::TheModel::~TheModel()
129 {
130 }
131
132 void ChartController::TheModel::addListener( ChartController* pController )
133 {
134 if(m_xModel)
135 {
136 //if you need to be able to veto against the destruction of the model
137 // you must add as a close listener
138
139 //otherwise you 'can' add as closelistener or 'must' add as dispose event listener
140
141 m_xModel->addCloseListener(
142 static_cast<util::XCloseListener*>(pController) );
143 }
144 }
145
146 void ChartController::TheModel::removeListener( ChartController* pController )
147 {
148 if(m_xModel)
149 m_xModel->removeCloseListener(
150 static_cast<util::XCloseListener*>(pController) );
151 }
152
153 void ChartController::TheModel::tryTermination()
154 {
155 if(!m_bOwnership)
156 return;
157
158 try
159 {
160 if(m_xModel.is())
161 {
162 try
163 {
164 //@todo ? are we allowed to use sal_True here if we have the explicit ownership?
165 //I think yes, because there might be other CloseListeners later in the list which might be interested still
166 //but make sure that we do not throw the CloseVetoException here ourselves
167 //so stop listening before trying to terminate or check the source of queryclosing event
168 m_xModel->close(true);
169
170 m_bOwnership = false;
171 }
172 catch( const util::CloseVetoException& )
173 {
174 //since we have indicated to give up the ownership with parameter true in close call
175 //the one who has thrown the CloseVetoException is the new owner
176
177 SAL_WARN_IF( m_bOwnership, "chart2.main", "a well known owner has caught a CloseVetoException after calling close(true)");
178 m_bOwnership = false;
179 return;
180 }
181
182 }
183 }
184 catch(const uno::Exception&)
185 {
186 DBG_UNHANDLED_EXCEPTION( "chart2", "Termination of model failed" );
187 }
188 }
189
190 ChartController::TheModelRef::TheModelRef( TheModel* pTheModel, osl::Mutex& rMutex ) :
191 m_rModelMutex(rMutex)
192 {
193 osl::Guard< osl::Mutex > aGuard( m_rModelMutex );
194 m_xTheModel = pTheModel;
195 }
196 ChartController::TheModelRef::TheModelRef( const TheModelRef& rTheModel, ::osl::Mutex& rMutex ) :
197 m_rModelMutex(rMutex)
198 {
199 osl::Guard< osl::Mutex > aGuard( m_rModelMutex );
200 m_xTheModel = rTheModel.m_xTheModel;
201 }
202 ChartController::TheModelRef& ChartController::TheModelRef::operator=(TheModel* pTheModel)
203 {
204 osl::Guard< osl::Mutex > aGuard( m_rModelMutex );
205 m_xTheModel = pTheModel;
206 return *this;
207 }
208 ChartController::TheModelRef& ChartController::TheModelRef::operator=(const TheModelRef& rTheModel)
209 {
210 osl::Guard< osl::Mutex > aGuard( m_rModelMutex );
211 m_xTheModel = rTheModel.operator->();
212 return *this;
213 }
214 ChartController::TheModelRef::~TheModelRef()
215 {
216 osl::Guard< osl::Mutex > aGuard( m_rModelMutex );
217 m_xTheModel.clear();
218 }
219 bool ChartController::TheModelRef::is() const
220 {
221 return m_xTheModel.is();
222 }
223
224 namespace {
225
226 rtl::Reference<ChartType> getChartType(const rtl::Reference<ChartModel>& xChartDoc)
227 {
228 rtl::Reference<Diagram > xDiagram = xChartDoc->getFirstChartDiagram();
229 if (!xDiagram.is())
230 return nullptr;
231
232 const std::vector< rtl::Reference< BaseCoordinateSystem > > xCooSysSequence( xDiagram->getBaseCoordinateSystems());
233 if (xCooSysSequence.empty())
234 return nullptr;
235
236 return xCooSysSequence[0]->getChartTypes2()[0];
237 }
238
239 }
240
241 OUString ChartController::GetContextName()
242 {
243 if (m_bDisposed)
244 return OUString();
245
246 uno::Any aAny = getSelection();
247 if (!aAny.hasValue())
248 return u"Chart"_ustr;
249
250 OUString aCID;
251 aAny >>= aCID;
252
253 if (aCID.isEmpty())
254 return u"Chart"_ustr;
255
256 ObjectType eObjectID = ObjectIdentifier::getObjectType(aCID);
257 switch (eObjectID)
258 {
259 case OBJECTTYPE_DATA_SERIES:
260 return u"Series"_ustr;
261 case OBJECTTYPE_DATA_ERRORS_X:
262 case OBJECTTYPE_DATA_ERRORS_Y:
263 case OBJECTTYPE_DATA_ERRORS_Z:
264 return u"ErrorBar"_ustr;
265 case OBJECTTYPE_AXIS:
266 return u"Axis"_ustr;
267 case OBJECTTYPE_GRID:
268 return u"Grid"_ustr;
269 case OBJECTTYPE_DIAGRAM:
270 {
271 rtl::Reference<ChartType> xChartType = getChartType(getChartModel());
272 if (xChartType.is() && xChartType->getChartType() == "com.sun.star.chart2.PieChartType")
273 return u"ChartElements"_ustr;
274 break;
275 }
276 case OBJECTTYPE_DATA_CURVE:
277 case OBJECTTYPE_DATA_AVERAGE_LINE:
278 return u"Trendline"_ustr;
279 case OBJECTTYPE_TITLE:
280 return u"ChartTitle"_ustr;
281 case OBJECTTYPE_LEGEND:
282 return u"ChartLegend"_ustr;
283 case OBJECTTYPE_DATA_LABEL:
284 case OBJECTTYPE_DATA_LABELS:
285 return u"ChartLabel"_ustr;
286 default:
287 break;
288 }
289
290 return u"Chart"_ustr;
291 }
292
293 // private methods
294
295 bool ChartController::impl_isDisposedOrSuspended() const
296 {
297 if( m_aLifeTimeManager.impl_isDisposed() )
298 return true;
299
300 if( m_bSuspended )
301 {
302 OSL_FAIL( "This Controller is suspended" );
303 return true;
304 }
305 return false;
306 }
307
308 namespace {
309
310 uno::Reference<ui::XSidebar> getSidebarFromModel(const uno::Reference<frame::XModel>& xModel)
311 {
312 uno::Reference<container::XChild> xChild(xModel, uno::UNO_QUERY);
313 if (!xChild.is())
314 return nullptr;
315
316 uno::Reference<frame::XModel> xParent (xChild->getParent(), uno::UNO_QUERY);
317 if (!xParent.is())
318 return nullptr;
319
320 uno::Reference<frame::XController2> xController(xParent->getCurrentController(), uno::UNO_QUERY);
321 if (!xController.is())
322 return nullptr;
323
324 uno::Reference<ui::XSidebarProvider> xSidebarProvider = xController->getSidebar();
325 if (!xSidebarProvider.is())
326 return nullptr;
327
328 return xSidebarProvider->getSidebar();
329 }
330
331 }
332
333 // XController
334
335 void SAL_CALL ChartController::attachFrame(
336 const uno::Reference<frame::XFrame>& xFrame )
337 {
338 SolarMutexGuard aGuard;
339
340 if( impl_isDisposedOrSuspended() ) //@todo? allow attaching the frame while suspended?
341 return; //behave passive if already disposed or suspended
342
343 if(m_xFrame.is()) //what happens, if we do have a Frame already??
344 {
345 //@todo? throw exception?
346 OSL_FAIL( "there is already a frame attached to the controller" );
347 return;
348 }
349
350 //--attach frame
351 m_xFrame = xFrame; //the frameloader is responsible to call xFrame->setComponent
352
353 // Only notify after setting the frame, otherwise notification will fail
354 mpSelectionChangeHandler->Connect();
355
356 uno::Reference<ui::XSidebar> xSidebar = getSidebarFromModel(getChartModel());
357 if (xSidebar.is())
358 {
359 auto pSidebar = dynamic_cast<sfx2::sidebar::SidebarController*>(xSidebar.get());
360 assert(pSidebar);
361 pSidebar->registerSidebarForFrame(this);
362 pSidebar->updateModel(getChartModel());
363 css::lang::EventObject aEvent;
364 mpSelectionChangeHandler->selectionChanged(aEvent);
365 }
366
367 //add as disposelistener to the frame (due to persistent reference) ??...:
368
369 //the frame is considered to be owner of this controller and will live longer than we do
370 //the frame or the disposer of the frame has the duty to call suspend and dispose on this object
371 //so we do not need to add as lang::XEventListener for DisposingEvents right?
372
373 //@todo nothing right???
374
375 //create view @todo is this the correct place here??
376
377 vcl::Window* pParent = nullptr;
378 //get the window parent from the frame to use as parent for our new window
379 if(xFrame.is())
380 {
381 uno::Reference<awt::XWindow> xContainerWindow = xFrame->getContainerWindow();
382 if (xContainerWindow)
383 xContainerWindow->setVisible(true);
384 pParent = VCLUnoHelper::GetWindow( xContainerWindow );
385 }
386
387 {
388 // calls to VCL
389 SolarMutexGuard aSolarGuard;
390 auto pChartWindow = VclPtr<ChartWindow>::Create(this,pParent,pParent?pParent->GetStyle():0);
391 pChartWindow->SetBackground();//no Background
392 m_xViewWindow.set( pChartWindow->GetComponentInterface(), uno::UNO_QUERY );
393 pChartWindow->Show();
394 m_apDropTargetHelper.reset(
395 new ChartDropTargetHelper( pChartWindow->GetDropTarget(), getChartModel()));
396
397 impl_createDrawViewController();
398 }
399
400 //create the menu
401 {
402 uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
403 if( xPropSet.is() )
404 {
405 try
406 {
407 uno::Reference< css::frame::XLayoutManager > xLayoutManager;
408 xPropSet->getPropertyValue( u"LayoutManager"_ustr ) >>= xLayoutManager;
409 if ( xLayoutManager.is() )
410 {
411 xLayoutManager->lock();
412 xLayoutManager->requestElement( u"private:resource/menubar/menubar"_ustr );
413 //@todo: createElement should become unnecessary, remove when #i79198# is fixed
414 xLayoutManager->createElement( u"private:resource/toolbar/standardbar"_ustr );
415 xLayoutManager->requestElement( u"private:resource/toolbar/standardbar"_ustr );
416 //@todo: createElement should become unnecessary, remove when #i79198# is fixed
417 xLayoutManager->createElement( u"private:resource/toolbar/toolbar"_ustr );
418 xLayoutManager->requestElement( u"private:resource/toolbar/toolbar"_ustr );
419
420 // #i12587# support for shapes in chart
421 xLayoutManager->createElement( u"private:resource/toolbar/drawbar"_ustr );
422 xLayoutManager->requestElement( u"private:resource/toolbar/drawbar"_ustr );
423
424 xLayoutManager->requestElement( u"private:resource/statusbar/statusbar"_ustr );
425 xLayoutManager->unlock();
426
427 // add as listener to get notified when
428 m_xLayoutManagerEventBroadcaster.set( xLayoutManager, uno::UNO_QUERY );
429 if( m_xLayoutManagerEventBroadcaster.is())
430 m_xLayoutManagerEventBroadcaster->addLayoutManagerEventListener( this );
431 }
432 }
433 catch( const uno::Exception & )
434 {
435 DBG_UNHANDLED_EXCEPTION("chart2");
436 }
437 }
438 }
439 }
440
441 //XModeChangeListener
442 void SAL_CALL ChartController::modeChanged( const util::ModeChangeEvent& rEvent )
443 {
444 SolarMutexGuard aGuard;
445 auto pChartWindow(GetChartWindow());
446 //adjust controller to view status changes
447
448 if( rEvent.NewMode == "dirty" )
449 {
450 //the view has become dirty, we should repaint it if we have a window
451 if( pChartWindow )
452 pChartWindow->ForceInvalidate();
453 }
454 else if( rEvent.NewMode == "invalid" )
455 {
456 //the view is about to become invalid so end all actions on it
457 impl_invalidateAccessible();
458 if( m_pDrawViewWrapper && m_pDrawViewWrapper->IsTextEdit() )
459 this->EndTextEdit();
460 if( m_pDrawViewWrapper )
461 {
462 m_pDrawViewWrapper->UnmarkAll();
463 m_pDrawViewWrapper->HideSdrPage();
464 }
465 }
466 else
467 {
468 //the view was rebuild so we can start some actions on it again
469 if( !m_bConnectingToView )
470 {
471 if(pChartWindow && m_aModel.is() )
472 {
473 m_bConnectingToView = true;
474
475 GetDrawModelWrapper();
476 if(m_pDrawModelWrapper)
477 {
478 if( m_pDrawViewWrapper )
479 m_pDrawViewWrapper->ReInit();
480
481 //reselect object
482 if( m_aSelection.hasSelection() )
483 this->impl_selectObjectAndNotiy();
484 else
485 getChartModel()->triggerRangeHighlighting();
486
487 impl_initializeAccessible();
488
489 pChartWindow->Invalidate();
490 }
491
492 m_bConnectingToView = false;
493 }
494 }
495 }
496 }
497
498 sal_Bool SAL_CALL ChartController::attachModel( const uno::Reference< frame::XModel > & xModel )
499 {
500 impl_invalidateAccessible();
501
502 //is called to attach the controller to a new model.
503 //return true if attach was successfully, false otherwise (e.g. if you do not work with a model)
504
505 SolarMutexResettableGuard aGuard;
506 if( impl_isDisposedOrSuspended() ) //@todo? allow attaching a new model while suspended?
507 return false; //behave passive if already disposed or suspended
508 aGuard.clear();
509
510 ::chart::ChartModel* pChartModel = dynamic_cast<::chart::ChartModel*>(xModel.get());
511 assert(!xModel || pChartModel);
512
513 TheModelRef aNewModelRef( new TheModel(pChartModel), m_aModelMutex);
514 TheModelRef aOldModelRef(m_aModel,m_aModelMutex);
515 m_aModel = aNewModelRef;
516
517 //--handle relations to the old model if any
518 if( aOldModelRef.is() )
519 {
520 if( m_xChartView.is() )
521 m_xChartView->removeModeChangeListener(this);
522 m_pDrawModelWrapper.reset();
523
524 aOldModelRef->removeListener( this );
525 #ifdef TEST_ENABLE_MODIFY_LISTENER
526 if( aOldModelRef->getModel().is())
527 aOldModelRef->getModel()->removeModifyListener( this );
528 #endif
529 }
530
531 //--handle relations to the new model
532 aNewModelRef->addListener( this );
533
534 aGuard.reset(); // lock for m_aDispatchContainer access
535 // set new model at dispatchers
536 m_aDispatchContainer.setModel( aNewModelRef->getModel());
537 rtl::Reference<ControllerCommandDispatch> pDispatch = new ControllerCommandDispatch( m_xCC, this, &m_aDispatchContainer );
538 pDispatch->initialize();
539
540 // the dispatch container will return "this" for all commands returned by
541 // impl_getAvailableCommands(), and also for which ControllerCommandDispatch::commandHandled()
542 // gives true. That means, for those commands dispatch() is called here at the ChartController.
543 m_aDispatchContainer.setChartDispatch( pDispatch, impl_getAvailableCommands() );
544
545 rtl::Reference<DrawCommandDispatch> pDrawDispatch = new DrawCommandDispatch( m_xCC, this );
546 pDrawDispatch->initialize();
547 m_aDispatchContainer.setDrawCommandDispatch( pDrawDispatch.get() );
548
549 rtl::Reference<ShapeController> pShapeController = new ShapeController( m_xCC, this );
550 pShapeController->initialize();
551 m_aDispatchContainer.setShapeController( pShapeController.get() );
552 aGuard.clear();
553
554 #ifdef TEST_ENABLE_MODIFY_LISTENER
555 if( aNewModelRef->getModel().is())
556 aNewModelRef->getModel()->addModifyListener( this );
557 #endif
558
559 // #i119999# Do not do this per default to allow the user to deselect the chart OLE with a single press to ESC
560 // select chart area per default:
561 // select( uno::Any( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, OUString() ) ) );
562
563 rtl::Reference< ChartModel > xFact = getChartModel();
564 if( xFact.is())
565 {
566 m_xChartView = xFact->createChartView();
567 GetDrawModelWrapper();
568 m_xChartView->addModeChangeListener(this);
569 }
570
571 //the frameloader is responsible to call xModel->connectController
572 {
573 SolarMutexGuard aGuard2;
574 auto pChartWindow(GetChartWindow());
575 if( pChartWindow )
576 pChartWindow->Invalidate();
577 }
578
579 m_xUndoManager.set( getChartModel()->getUndoManager(), uno::UNO_SET_THROW );
580
581 return true;
582 }
583
584 uno::Reference< frame::XFrame > SAL_CALL ChartController::getFrame()
585 {
586 //provides access to owner frame of this controller
587 //return the frame containing this controller
588
589 return m_xFrame;
590 }
591
592 uno::Reference< frame::XModel > SAL_CALL ChartController::getModel()
593 {
594 return getChartModel();
595 }
596
597 rtl::Reference<::chart::ChartModel> ChartController::getChartModel()
598 {
599 //provides access to currently attached model
600 //returns the currently attached model
601
602 //return nothing, if you do not have a model
603 TheModelRef aModelRef( m_aModel, m_aModelMutex);
604 if(aModelRef.is())
605 return aModelRef->getModel();
606
607 return nullptr;
608 }
609
610 rtl::Reference<::chart::Diagram> ChartController::getFirstDiagram()
611 {
612 rtl::Reference<::chart::ChartModel> xModel = getChartModel();
613 if (!xModel)
614 return nullptr;
615 return xModel->getFirstChartDiagram();
616 }
617
618 uno::Any SAL_CALL ChartController::getViewData()
619 {
620 //provides access to current view status
621 //set of data that can be used to restore the current view status at later time
622 // by using XController::restoreViewData()
623
624 SolarMutexGuard aGuard;
625 if( impl_isDisposedOrSuspended() )
626 return uno::Any(); //behave passive if already disposed or suspended //@todo? or throw an exception??
627
628 //-- collect current view state
629 uno::Any aRet;
630 //// @todo integrate specialized implementation
631
632 return aRet;
633 }
634
635 void SAL_CALL ChartController::restoreViewData(
636 const uno::Any& /* Value */ )
637 {
638 //restores the view status using the data gotten from a previous call to XController::getViewData()
639
640 SolarMutexGuard aGuard;
641 if( impl_isDisposedOrSuspended() )
642 return; //behave passive if already disposed or suspended //@todo? or throw an exception??
643
644 //// @todo integrate specialized implementation
645 }
646
647 sal_Bool SAL_CALL ChartController::suspend( sal_Bool bSuspend )
648 {
649 //is called to prepare the controller for closing the view
650 //bSuspend==true: force the controller to suspend his work
651 //bSuspend==false try to reactivate the controller
652 //returns true if request was accepted and of course successfully finished, false otherwise
653
654 //we may show dialogs here to ask the user for saving changes ... @todo?
655
656 SolarMutexGuard aGuard;
657 if( m_aLifeTimeManager.impl_isDisposed() )
658 return false; //behave passive if already disposed, return false because request was not accepted //@todo? correct
659
660 if(bool(bSuspend) == m_bSuspended)
661 {
662 OSL_FAIL( "new suspend mode equals old suspend mode" );
663 return true;
664 }
665
666 //change suspend mode
667 m_bSuspended = bSuspend;
668 return true;
669 }
670
671 // css::frame::XController2
672
673 css::uno::Reference<css::awt::XWindow> SAL_CALL ChartController::getComponentWindow()
674 {
675 // it is a special characteristic of ChartController
676 // that it simultaneously provides the XWindow functionality
677 return this;
678 }
679
680 OUString SAL_CALL ChartController::getViewControllerName() { return {}; }
681
682 css::uno::Sequence<css::beans::PropertyValue> SAL_CALL ChartController::getCreationArguments()
683 {
684 return {};
685 }
686
687 css::uno::Reference<css::ui::XSidebarProvider> SAL_CALL ChartController::getSidebar() { return {}; }
688
689 void ChartController::impl_createDrawViewController()
690 {
691 SolarMutexGuard aGuard;
692 if(!m_pDrawViewWrapper)
693 {
694 if( m_pDrawModelWrapper )
695 {
696 bool bLokCalcGlobalRTL = false;
697 if(comphelper::LibreOfficeKit::isActive() && AllSettings::GetLayoutRTL())
698 {
699 rtl::Reference< ChartModel > xChartModel = getChartModel();
700 if (xChartModel.is())
701 {
702 uno::Reference<css::sheet::XSpreadsheetDocument> xSSDoc(xChartModel->getParent(), uno::UNO_QUERY);
703 if (xSSDoc.is())
704 bLokCalcGlobalRTL = true;
705 }
706 }
707
708 m_pDrawViewWrapper.reset( new DrawViewWrapper(m_pDrawModelWrapper->getSdrModel(),GetChartWindow()->GetOutDev()) );
709 m_pDrawViewWrapper->SetNegativeX(bLokCalcGlobalRTL);
710 m_pDrawViewWrapper->attachParentReferenceDevice( getChartModel() );
711 }
712 }
713 }
714
715 void ChartController::impl_deleteDrawViewController()
716 {
717 if( m_pDrawViewWrapper )
718 {
719 SolarMutexGuard aGuard;
720 if( m_pDrawViewWrapper->IsTextEdit() )
721 this->EndTextEdit();
722 m_pDrawViewWrapper.reset();
723 }
724 }
725
726 // XComponent (base of XController)
727
728 void SAL_CALL ChartController::dispose()
729 {
730 m_bDisposed = true;
731
732 mpSelectionChangeHandler->selectionChanged(css::lang::EventObject());
733 mpSelectionChangeHandler->Disconnect();
734
735 if (getModel().is())
736 {
737 uno::Reference<ui::XSidebar> xSidebar = getSidebarFromModel(getChartModel());
738 if (sfx2::sidebar::SidebarController* pSidebar = dynamic_cast<sfx2::sidebar::SidebarController*>(xSidebar.get()))
739 {
740 pSidebar->unregisterSidebarForFrame(this);
741 }
742 }
743
744 try
745 {
746 //This object should release all resources and references in the
747 //easiest possible manner
748 //This object must notify all registered listeners using the method
749 //<member>XEventListener::disposing</member>
750
751 //hold no mutex
752 if( !m_aLifeTimeManager.dispose() )
753 return;
754
755 // OSL_ENSURE( m_bSuspended, "dispose was called but controller is not suspended" );
756
757 this->stopDoubleClickWaiting();
758
759 //end range highlighting
760 if( m_aModel.is())
761 {
762 uno::Reference< view::XSelectionChangeListener > xSelectionChangeListener;
763 rtl::Reference< ChartModel > xDataReceiver = getChartModel();
764 if( xDataReceiver.is() )
765 xSelectionChangeListener.set( xDataReceiver->getRangeHighlighter(), uno::UNO_QUERY );
766 if( xSelectionChangeListener.is() )
767 {
768 uno::Reference< frame::XController > xController( this );
769 lang::EventObject aEvent( xController );
770 xSelectionChangeListener->disposing( aEvent );
771 }
772 }
773
774 //--release all resources and references
775 {
776 if( m_xChartView.is() )
777 m_xChartView->removeModeChangeListener(this);
778
779 impl_invalidateAccessible();
780 SolarMutexGuard aSolarGuard;
781 impl_deleteDrawViewController();
782 m_pDrawModelWrapper.reset();
783
784 m_apDropTargetHelper.reset();
785
786 //the accessible view is disposed within window destructor of m_pChartWindow
787 if(m_xViewWindow.is())
788 m_xViewWindow->dispose(); //ChartWindow is deleted via UNO due to dispose of m_xViewWindow (triggered by Framework (Controller pretends to be XWindow also))
789 m_xChartView.clear();
790 }
791
792 // remove as listener to layout manager events
793 if( m_xLayoutManagerEventBroadcaster.is())
794 {
795 m_xLayoutManagerEventBroadcaster->removeLayoutManagerEventListener( this );
796 m_xLayoutManagerEventBroadcaster.clear();
797 }
798
799 m_xFrame.clear();
800 m_xUndoManager.clear();
801
802 TheModelRef aModelRef( m_aModel, m_aModelMutex);
803 m_aModel = nullptr;
804
805 if( aModelRef.is())
806 {
807 rtl::Reference< ChartModel > xModel( aModelRef->getModel() );
808 if(xModel.is())
809 xModel->disconnectController( uno::Reference< frame::XController >( this ));
810
811 aModelRef->removeListener( this );
812 #ifdef TEST_ENABLE_MODIFY_LISTENER
813 try
814 {
815 if( aModelRef->getModel().is())
816 aModelRef->getModel()->removeModifyListener( this );
817 }
818 catch( const uno::Exception & )
819 {
820 DBG_UNHANDLED_EXCEPTION("chart2");
821 }
822 #endif
823 aModelRef->tryTermination();
824 }
825
826 //// @todo integrate specialized implementation
827 //e.g. release further resources and references
828
829 SolarMutexGuard g;
830 m_aDispatchContainer.DisposeAndClear();
831 }
832 catch( const uno::Exception & )
833 {
834 DBG_UNHANDLED_EXCEPTION("chart2");
835 assert(!m_xChartView.is());
836 }
837 }
838
839 void SAL_CALL ChartController::addEventListener(
840 const uno::Reference<lang::XEventListener>& xListener )
841 {
842 if( impl_isDisposedOrSuspended() )//@todo? allow adding of listeners in suspend mode?
843 return; //behave passive if already disposed or suspended
844
845 //--add listener
846 std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex);
847 m_aLifeTimeManager.m_aEventListeners.addInterface( aGuard2, xListener );
848 }
849
850 void SAL_CALL ChartController::removeEventListener(
851 const uno::Reference<lang::XEventListener>& xListener )
852 {
853 SolarMutexGuard aGuard;
854 if( m_aLifeTimeManager.impl_isDisposed(false) )
855 return; //behave passive if already disposed or suspended
856
857 //--remove listener
858 std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex);
859 m_aLifeTimeManager.m_aEventListeners.removeInterface( aGuard2, xListener );
860 }
861
862 // util::XCloseListener
863 void SAL_CALL ChartController::queryClosing(
864 const lang::EventObject& rSource,
865 sal_Bool /*bGetsOwnership*/ )
866 {
867 //do not use the m_aControllerMutex here because this call is not allowed to block
868
869 TheModelRef aModelRef( m_aModel, m_aModelMutex);
870
871 if( !aModelRef.is() )
872 return;
873
874 if( uno::Reference<XInterface>(static_cast<cppu::OWeakObject*>(aModelRef->getModel().get())) != rSource.Source )
875 {
876 OSL_FAIL( "queryClosing was called on a controller from an unknown source" );
877 return;
878 }
879
880 //@ todo prepare to closing model -> don't start any further hindering actions
881 }
882
883 void SAL_CALL ChartController::notifyClosing(
884 const lang::EventObject& rSource )
885 {
886 //Listener should deregister himself and release all references to the closing object.
887
888 TheModelRef aModelRef( m_aModel, m_aModelMutex);
889 if( !impl_releaseThisModel( rSource.Source ) )
890 return;
891
892 //--stop listening to the closing model
893 aModelRef->removeListener( this );
894
895 // #i79087# If the model using this controller is closed, the frame is
896 // expected to be closed as well
897 Reference< util::XCloseable > xFrameCloseable( m_xFrame, uno::UNO_QUERY );
898 if( xFrameCloseable.is())
899 {
900 try
901 {
902 xFrameCloseable->close( false /* DeliverOwnership */ );
903 m_xFrame.clear();
904 }
905 catch( const util::CloseVetoException & )
906 {
907 // closing was vetoed
908 }
909 }
910 }
911
912 bool ChartController::impl_releaseThisModel(
913 const uno::Reference< uno::XInterface > & xModel )
914 {
915 bool bReleaseModel = false;
916 {
917 ::osl::Guard< ::osl::Mutex > aGuard( m_aModelMutex );
918 if( m_aModel.is() && uno::Reference< uno::XInterface >(static_cast<cppu::OWeakObject*>(m_aModel->getModel().get())) == xModel )
919 {
920 m_aModel = nullptr;
921 m_xUndoManager.clear();
922 bReleaseModel = true;
923 }
924 }
925 if( bReleaseModel )
926 {
927 SolarMutexGuard g;
928 m_aDispatchContainer.setModel( nullptr );
929 }
930 return bReleaseModel;
931 }
932
933 // util::XEventListener (base of XCloseListener)
934 void SAL_CALL ChartController::disposing(
935 const lang::EventObject& rSource )
936 {
937 if( !impl_releaseThisModel( rSource.Source ))
938 {
939 if( rSource.Source == m_xLayoutManagerEventBroadcaster )
940 m_xLayoutManagerEventBroadcaster.clear();
941 }
942 }
943
944 void SAL_CALL ChartController::layoutEvent(
945 const lang::EventObject& aSource,
946 sal_Int16 eLayoutEvent,
947 const uno::Any& /* aInfo */ )
948 {
949 if( eLayoutEvent == frame::LayoutManagerEvents::MERGEDMENUBAR )
950 {
951 Reference< frame::XLayoutManager > xLM( aSource.Source, uno::UNO_QUERY );
952 if( xLM.is())
953 {
954 xLM->createElement( u"private:resource/statusbar/statusbar"_ustr );
955 xLM->requestElement( u"private:resource/statusbar/statusbar"_ustr );
956 }
957 }
958 }
959
960 // XDispatchProvider (required interface)
961
962 namespace
963 {
964
965 bool lcl_isFormatObjectCommand( std::u16string_view aCommand )
966 {
967 return aCommand == u"MainTitle"
968 || aCommand == u"SubTitle"
969 || aCommand == u"XTitle"
970 || aCommand == u"YTitle"
971 || aCommand == u"ZTitle"
972 || aCommand == u"SecondaryXTitle"
973 || aCommand == u"SecondaryYTitle"
974 || aCommand == u"AllTitles"
975 || aCommand == u"DiagramAxisX"
976 || aCommand == u"DiagramAxisY"
977 || aCommand == u"DiagramAxisZ"
978 || aCommand == u"DiagramAxisA"
979 || aCommand == u"DiagramAxisB"
980 || aCommand == u"DiagramAxisAll"
981 || aCommand == u"DiagramGridXMain"
982 || aCommand == u"DiagramGridYMain"
983 || aCommand == u"DiagramGridZMain"
984 || aCommand == u"DiagramGridXHelp"
985 || aCommand == u"DiagramGridYHelp"
986 || aCommand == u"DiagramGridZHelp"
987 || aCommand == u"DiagramGridAll"
988
989 || aCommand == u"DiagramWall"
990 || aCommand == u"DiagramFloor"
991 || aCommand == u"DiagramArea"
992 || aCommand == u"Legend"
993
994 || aCommand == u"FormatWall"
995 || aCommand == u"FormatFloor"
996 || aCommand == u"FormatChartArea"
997 || aCommand == u"FormatLegend"
998
999 || aCommand == u"FormatTitle"
1000 || aCommand == u"FormatAxis"
1001 || aCommand == u"FormatDataSeries"
1002 || aCommand == u"FormatDataPoint"
1003 || aCommand == u"FormatDataLabels"
1004 || aCommand == u"FormatDataLabel"
1005 || aCommand == u"FormatXErrorBars"
1006 || aCommand == u"FormatYErrorBars"
1007 || aCommand == u"FormatMeanValue"
1008 || aCommand == u"FormatTrendline"
1009 || aCommand == u"FormatTrendlineEquation"
1010 || aCommand == u"FormatStockLoss"
1011 || aCommand == u"FormatStockGain"
1012 || aCommand == u"FormatMajorGrid"
1013 || aCommand == u"FormatMinorGrid";
1014 }
1015
1016 } // anonymous namespace
1017
1018 uno::Reference<frame::XDispatch> SAL_CALL
1019 ChartController::queryDispatch(
1020 const util::URL& rURL,
1021 const OUString& rTargetFrameName,
1022 sal_Int32 /* nSearchFlags */)
1023 {
1024 SolarMutexGuard aGuard;
1025
1026 if ( !m_aLifeTimeManager.impl_isDisposed() && getModel().is() )
1027 {
1028 if (rTargetFrameName.isEmpty() || rTargetFrameName == "_self")
1029 return m_aDispatchContainer.getDispatchForURL( rURL );
1030 }
1031 return uno::Reference< frame::XDispatch > ();
1032 }
1033
1034 uno::Sequence<uno::Reference<frame::XDispatch > >
1035 ChartController::queryDispatches(
1036 const uno::Sequence<frame::DispatchDescriptor>& xDescripts )
1037 {
1038 SolarMutexGuard g;
1039
1040 if ( !m_aLifeTimeManager.impl_isDisposed() )
1041 {
1042 return m_aDispatchContainer.getDispatchesForURLs( xDescripts );
1043 }
1044 return uno::Sequence<uno::Reference<frame::XDispatch > > ();
1045 }
1046
1047 // frame::XDispatch
1048
1049 void SAL_CALL ChartController::dispatch(
1050 const util::URL& rURL,
1051 const uno::Sequence< beans::PropertyValue >& rArgs )
1052 {
1053 OUString aCommand = rURL.Path;
1054
1055 if(aCommand == "LOKSetTextSelection")
1056 {
1057 if (rArgs.getLength() == 3)
1058 {
1059 sal_Int32 nType = -1;
1060 rArgs[0].Value >>= nType;
1061 sal_Int32 nX = 0;
1062 rArgs[1].Value >>= nX;
1063 sal_Int32 nY = 0;
1064 rArgs[2].Value >>= nY;
1065 executeDispatch_LOKSetTextSelection(nType, nX, nY);
1066 }
1067 }
1068 else if (aCommand == "LOKTransform")
1069 {
1070 if (rArgs[0].Name == "Action")
1071 {
1072 OUString sAction;
1073 if ((rArgs[0].Value >>= sAction) && sAction == "PieSegmentDragging")
1074 {
1075 if (rArgs[1].Name == "Offset")
1076 {
1077 sal_Int32 nOffset;
1078 if (rArgs[1].Value >>= nOffset)
1079 {
1080 this->executeDispatch_LOKPieSegmentDragging(nOffset);
1081 }
1082 }
1083 }
1084 }
1085 else
1086 {
1087 this->executeDispatch_PositionAndSize(&rArgs);
1088 }
1089 }
1090 else if(aCommand == "FillColor")
1091 {
1092 if (rArgs.getLength() > 0)
1093 executeDispatch_FillColor(rArgs[0].Value);
1094 }
1095 else if(aCommand == "XLineColor")
1096 {
1097 if (rArgs.getLength() > 0)
1098 executeDispatch_LineColor(rArgs[0].Value);
1099 }
1100 else if(aCommand == "LineWidth")
1101 {
1102 if (rArgs.getLength() > 0)
1103 executeDispatch_LineWidth(rArgs[0].Value);
1104 }
1105 else if(aCommand.startsWith("FillGradient"))
1106 {
1107 this->executeDispatch_FillGradient(aCommand.subView(aCommand.indexOf('=') + 1));
1108 }
1109 else if(aCommand == "Paste")
1110 this->executeDispatch_Paste();
1111 else if(aCommand == "Copy" )
1112 this->executeDispatch_Copy();
1113 else if(aCommand == "Cut" )
1114 this->executeDispatch_Cut();
1115 else if(aCommand == "DataRanges" )
1116 this->executeDispatch_SourceData();
1117 else if(aCommand == "Update" ) //Update Chart
1118 {
1119 ChartViewHelper::setViewToDirtyState( getChartModel() );
1120 SolarMutexGuard aGuard;
1121 auto pChartWindow(GetChartWindow());
1122 if( pChartWindow )
1123 pChartWindow->Invalidate();
1124 }
1125 else if(aCommand == "DiagramData" )
1126 this->executeDispatch_EditData();
1127 //insert objects
1128 else if( aCommand == "InsertTitles"
1129 || aCommand == "InsertMenuTitles")
1130 this->executeDispatch_InsertTitles();
1131 else if( aCommand == "InsertMenuLegend" )
1132 this->executeDispatch_OpenLegendDialog();
1133 else if( aCommand == "InsertLegend" )
1134 this->executeDispatch_InsertLegend();
1135 else if( aCommand == "DeleteLegend" )
1136 this->executeDispatch_DeleteLegend();
1137 else if( aCommand == "InsertMenuDataLabels" )
1138 this->executeDispatch_InsertMenu_DataLabels();
1139 else if( aCommand == "InsertMenuAxes"
1140 || aCommand == "InsertRemoveAxes" )
1141 this->executeDispatch_InsertAxes();
1142 else if( aCommand == "InsertMenuGrids" )
1143 this->executeDispatch_InsertGrid();
1144 else if( aCommand == "InsertMenuTrendlines" )
1145 this->executeDispatch_InsertMenu_Trendlines();
1146 else if( aCommand == "InsertMenuMeanValues" )
1147 this->executeDispatch_InsertMenu_MeanValues();
1148 else if( aCommand == "InsertMenuXErrorBars" )
1149 this->executeDispatch_InsertErrorBars(false);
1150 else if( aCommand == "InsertMenuYErrorBars" )
1151 this->executeDispatch_InsertErrorBars(true);
1152 else if( aCommand == "InsertMenuDataTable" )
1153 this->executeDispatch_OpenInsertDataTableDialog();
1154 else if( aCommand == "InsertSymbol" )
1155 this->executeDispatch_InsertSpecialCharacter();
1156 else if( aCommand == "InsertTrendline" )
1157 this->executeDispatch_InsertTrendline();
1158 else if( aCommand == "DeleteTrendline" )
1159 this->executeDispatch_DeleteTrendline();
1160 else if( aCommand == "InsertMeanValue" )
1161 this->executeDispatch_InsertMeanValue();
1162 else if( aCommand == "DeleteMeanValue" )
1163 this->executeDispatch_DeleteMeanValue();
1164 else if( aCommand == "InsertXErrorBars" )
1165 this->executeDispatch_InsertErrorBars(false);
1166 else if( aCommand == "InsertYErrorBars" )
1167 this->executeDispatch_InsertErrorBars(true);
1168 else if( aCommand == "DeleteXErrorBars" )
1169 this->executeDispatch_DeleteErrorBars(false);
1170 else if( aCommand == "DeleteYErrorBars" )
1171 this->executeDispatch_DeleteErrorBars(true);
1172 else if( aCommand == "InsertTrendlineEquation" )
1173 this->executeDispatch_InsertTrendlineEquation();
1174 else if( aCommand == "DeleteTrendlineEquation" )
1175 this->executeDispatch_DeleteTrendlineEquation();
1176 else if( aCommand == "InsertTrendlineEquationAndR2" )
1177 this->executeDispatch_InsertTrendlineEquation( true );
1178 else if( aCommand == "InsertR2Value" )
1179 this->executeDispatch_InsertR2Value();
1180 else if( aCommand == "DeleteR2Value")
1181 this->executeDispatch_DeleteR2Value();
1182 else if( aCommand == "InsertDataLabels" )
1183 this->executeDispatch_InsertDataLabels();
1184 else if( aCommand == "InsertDataLabel" )
1185 this->executeDispatch_InsertDataLabel();
1186 else if( aCommand == "DeleteDataLabels")
1187 this->executeDispatch_DeleteDataLabels();
1188 else if( aCommand == "DeleteDataLabel" )
1189 this->executeDispatch_DeleteDataLabel();
1190 else if( aCommand == "ResetAllDataPoints" )
1191 this->executeDispatch_ResetAllDataPoints();
1192 else if( aCommand == "ResetDataPoint" )
1193 this->executeDispatch_ResetDataPoint();
1194 else if( aCommand == "InsertAxis" )
1195 this->executeDispatch_InsertAxis();
1196 else if( aCommand == "InsertMajorGrid" )
1197 this->executeDispatch_InsertMajorGrid();
1198 else if( aCommand == "InsertMinorGrid" )
1199 this->executeDispatch_InsertMinorGrid();
1200 else if( aCommand == "InsertAxisTitle" )
1201 this->executeDispatch_InsertAxisTitle();
1202 else if( aCommand == "DeleteAxis" )
1203 this->executeDispatch_DeleteAxis();
1204 else if( aCommand == "DeleteMajorGrid")
1205 this->executeDispatch_DeleteMajorGrid();
1206 else if( aCommand == "DeleteMinorGrid" )
1207 this->executeDispatch_DeleteMinorGrid();
1208 else if( aCommand == "InsertDataTable" )
1209 this->executeDispatch_InsertDataTable();
1210 else if( aCommand == "DeleteDataTable" )
1211 this->executeDispatch_DeleteDataTable();
1212 //format objects
1213 else if( aCommand == "FormatSelection" )
1214 this->executeDispatch_ObjectProperties();
1215 else if( aCommand == "TransformDialog" )
1216 {
1217 if ( isShapeContext() )
1218 {
1219 this->impl_ShapeControllerDispatch( rURL, rArgs );
1220 }
1221 else
1222 {
1223 this->executeDispatch_PositionAndSize();
1224 }
1225 }
1226 else if ( aCommand == "FontDialog" )
1227 this->impl_ShapeControllerDispatch(rURL, rArgs);
1228 else if (lcl_isFormatObjectCommand(aCommand))
1229 this->executeDispatch_FormatObject(rURL.Path);
1230 //more format
1231 else if( aCommand == "DiagramType" )
1232 this->executeDispatch_ChartType();
1233 else if( aCommand == "View3D" )
1234 this->executeDispatch_View3D();
1235 else if ( aCommand == "Forward" )
1236 {
1237 if ( isShapeContext() )
1238 {
1239 this->impl_ShapeControllerDispatch( rURL, rArgs );
1240 }
1241 else
1242 {
1243 this->executeDispatch_MoveSeries( true );
1244 }
1245 }
1246 else if ( aCommand == "Backward" )
1247 {
1248 if ( isShapeContext() )
1249 {
1250 this->impl_ShapeControllerDispatch( rURL, rArgs );
1251 }
1252 else
1253 {
1254 this->executeDispatch_MoveSeries( false );
1255 }
1256 }
1257 else if( aCommand == "NewArrangement")
1258 this->executeDispatch_NewArrangement();
1259 else if( aCommand == "ToggleLegend" )
1260 this->executeDispatch_ToggleLegend();
1261 else if( aCommand == "ToggleGridHorizontal" )
1262 this->executeDispatch_ToggleGridHorizontal();
1263 else if( aCommand == "ToggleGridVertical" )
1264 this->executeDispatch_ToggleGridVertical();
1265 else if( aCommand == "ScaleText" )
1266 this->executeDispatch_ScaleText();
1267 else if( aCommand == "Bold" || aCommand == "CharFontName" || aCommand == "FontHeight"
1268 || aCommand == "Italic" || aCommand == "Underline" || aCommand == "Strikeout"
1269 || aCommand == "Shadowed" || aCommand == "Color" || aCommand == "FontColor"
1270 || aCommand == "Grow" || aCommand == "Shrink" || aCommand == "ResetAttributes"
1271 || aCommand == "SuperScript" || aCommand == "SubScript"
1272 || aCommand == "Spacing"
1273 )
1274 {
1275 try
1276 {
1277 OUString aCID(m_aSelection.getSelectedCID());
1278 rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
1279 if (xChartModel.is())
1280 {
1281 // if the selected is title... we should get the text properties instead...
1282 // or the selected text properties
1283 std::vector<Reference<beans::XPropertySet>> xProperties;
1284 xProperties.emplace(xProperties.end(),
1285 ObjectIdentifier::getObjectPropertySet(aCID, xChartModel));
1286
1287 if (ObjectIdentifier::getObjectType(aCID) == OBJECTTYPE_TITLE)
1288 {
1289 Reference<chart2::XTitle> xTitle(xProperties[0], uno::UNO_QUERY);
1290 if (xTitle.is())
1291 {
1292 OutlinerView* pOutlinerView = nullptr;
1293 if (m_pDrawViewWrapper)
1294 {
1295 pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
1296 }
1297 // if the Title is not in edit mode
1298 if (!pOutlinerView)
1299 {
1300 const Sequence<Reference<chart2::XFormattedString>> aStrings(
1301 xTitle->getText());
1302 xProperties.pop_back();
1303 for (const auto& aString : aStrings)
1304 {
1305 Reference<beans::XPropertySet> xTitlePropSet(aString, uno::UNO_QUERY);
1306 xProperties.push_back(xTitlePropSet);
1307 }
1308 }
1309 // Todo: implement the edit mode case here.
1310 // the edited text attributes are a bit different from the properties
1311 // SfxItemSet aItemSet = pOutlinerView->GetAttribs();
1312 }
1313 }
1314 bool bAllPropertiesExist = (xProperties.size() > 0);
1315 for (const auto& xProperty : xProperties)
1316 {
1317 if (!xProperty.is())
1318 bAllPropertiesExist = false;
1319 }
1320 if (bAllPropertiesExist)
1321 {
1322 if (aCommand == "Bold")
1323 {
1324 executeDispatch_FontBold(xProperties);
1325 }
1326 else if (aCommand == "CharFontName")
1327 {
1328 executeDispatch_FontName(xProperties, rArgs);
1329 }
1330 else if (aCommand == "FontHeight")
1331 {
1332 executeDispatch_FontHeight(xProperties, rArgs);
1333 }
1334 else if (aCommand == "Italic")
1335 {
1336 executeDispatch_FontItalic(xProperties);
1337 }
1338 else if (aCommand == "Underline")
1339 {
1340 executeDispatch_FontUnderline(xProperties, rArgs);
1341 }
1342 else if (aCommand == "Strikeout")
1343 {
1344 executeDispatch_FontStrikeout(xProperties);
1345 }
1346 else if (aCommand == "Shadowed")
1347 {
1348 executeDispatch_FontShadowed(xProperties);
1349 }
1350 else if (aCommand == "Color" || aCommand == "FontColor")
1351 {
1352 executeDispatch_FontColor(xProperties, rArgs);
1353 }
1354 else if (aCommand == "Grow")
1355 {
1356 executeDispatch_FontGrow(xProperties);
1357 }
1358 else if (aCommand == "Shrink")
1359 {
1360 executeDispatch_FontShrink(xProperties);
1361 }
1362 else if (aCommand == "ResetAttributes")
1363 {
1364 executeDispatch_FontReset(xProperties);
1365 }
1366 else if (aCommand == "Spacing")
1367 {
1368 executeDispatch_FontSpacing(xProperties, rArgs);
1369 }
1370 else if (aCommand == "SuperScript")
1371 {
1372 executeDispatch_FontSuperScript(xProperties);
1373 }
1374 else if (aCommand == "SubScript")
1375 {
1376 executeDispatch_FontSubScript(xProperties);
1377 }
1378 }
1379 }
1380 }
1381 catch (const uno::Exception&)
1382 {
1383 DBG_UNHANDLED_EXCEPTION("chart2");
1384 }
1385
1386 }
1387 }
1388
1389 void SAL_CALL ChartController::addStatusListener(
1390 const uno::Reference<frame::XStatusListener >& /* xControl */,
1391 const util::URL& /* aURL */ )
1392 {
1393 //@todo
1394 }
1395
1396 void SAL_CALL ChartController::removeStatusListener(
1397 const uno::Reference<frame::XStatusListener >& /* xControl */,
1398 const util::URL& /* aURL */ )
1399 {
1400 //@todo
1401 }
1402
1403 // XContextMenuInterception (optional interface)
1404 void SAL_CALL ChartController::registerContextMenuInterceptor(
1405 const uno::Reference< ui::XContextMenuInterceptor >& /* xInterceptor */)
1406 {
1407 //@todo
1408 }
1409
1410 void SAL_CALL ChartController::releaseContextMenuInterceptor(
1411 const uno::Reference< ui::XContextMenuInterceptor > & /* xInterceptor */)
1412 {
1413 //@todo
1414 }
1415
1416 // ____ XEmbeddedClient ____
1417 // implementation see: ChartController_EditData.cxx
1418
1419 void ChartController::executeDispatch_ChartType()
1420 {
1421 auto xUndoGuard = std::make_shared<UndoLiveUpdateGuard>(SchResId(STR_ACTION_EDIT_CHARTTYPE),
1422 m_xUndoManager);
1423
1424 SolarMutexGuard aSolarGuard;
1425 //prepare and open dialog
1426 auto aDlg = std::make_shared<ChartTypeDialog>(GetChartFrame(), getChartModel());
1427 weld::DialogController::runAsync(aDlg, [this, xUndoGuard=std::move(xUndoGuard)](int nResult) {
1428 if (nResult == RET_OK)
1429 {
1430 impl_adaptDataSeriesAutoResize();
1431 xUndoGuard->commit();
1432 }
1433 });
1434 }
1435
1436 void ChartController::executeDispatch_SourceData()
1437 {
1438 //convert properties to ItemSet
1439 rtl::Reference< ::chart::ChartModel > xChartDoc = getChartModel();
1440 OSL_ENSURE( xChartDoc.is(), "Invalid XChartDocument" );
1441 if( !xChartDoc.is() )
1442 return;
1443
1444 // If there is a data table we should ask user if we really want to destroy it
1445 // and switch to data ranges.
1446 ChartModel& rModel = *xChartDoc;
1447 if ( rModel.hasInternalDataProvider() )
1448 {
1449 // Check if we will able to create data provider later
1450 css::uno::Reference< css::chart2::XDataProviderAccess > xCreatorDoc(
1451 rModel.getParent(), uno::UNO_QUERY);
1452 if (!xCreatorDoc.is())
1453 return;
1454
1455 SolarMutexGuard aSolarGuard;
1456
1457 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetChartFrame(),
1458 VclMessageType::Question, VclButtonsType::YesNo, SchResId(STR_DLG_REMOVE_DATA_TABLE)));
1459 // If "No" then just return
1460 if (xQueryBox->run() == RET_NO)
1461 return;
1462
1463 // Remove data table
1464 rModel.removeDataProviders();
1465
1466 // Ask parent document to create new data provider
1467
1468 uno::Reference< data::XDataProvider > xDataProvider = xCreatorDoc->createDataProvider();
1469 SAL_WARN_IF( !xDataProvider.is(), "chart2.main", "Data provider was not created" );
1470 if (xDataProvider.is())
1471 {
1472 rModel.attachDataProvider(xDataProvider);
1473 }
1474 }
1475 auto xUndoGuard = std::make_shared<UndoLiveUpdateGuard>(SchResId(STR_ACTION_EDIT_DATA_RANGES),
1476 m_xUndoManager);
1477 SolarMutexGuard aSolarGuard;
1478 auto aDlg = std::make_shared<DataSourceDialog>(GetChartFrame(), xChartDoc);
1479 weld::DialogController::runAsync(aDlg, [this, xUndoGuard=std::move(xUndoGuard)](int nResult) {
1480 if (nResult == RET_OK)
1481 {
1482 impl_adaptDataSeriesAutoResize();
1483 xUndoGuard->commit();
1484 }
1485 });
1486 }
1487
1488 void ChartController::executeDispatch_MoveSeries( bool bForward )
1489 {
1490 ControllerLockGuardUNO aCLGuard( getChartModel() );
1491
1492 //get selected series
1493 OUString aObjectCID(m_aSelection.getSelectedCID());
1494 rtl::Reference< DataSeries > xGivenDataSeries = ObjectIdentifier::getDataSeriesForCID( //yyy todo also legend entries and labels?
1495 aObjectCID, getChartModel() );
1496
1497 UndoGuardWithSelection aUndoGuard(
1498 ActionDescriptionProvider::createDescription(
1499 (bForward ? ActionDescriptionProvider::ActionType::MoveToTop : ActionDescriptionProvider::ActionType::MoveToBottom),
1500 SchResId(STR_OBJECT_DATASERIES)),
1501 m_xUndoManager );
1502
1503 bool bChanged = getFirstDiagram()->moveSeries( xGivenDataSeries, bForward );
1504 if( bChanged )
1505 {
1506 m_aSelection.setSelection( ObjectIdentifier::getMovedSeriesCID( aObjectCID, bForward ) );
1507 aUndoGuard.commit();
1508 }
1509 }
1510
1511 // ____ XModifyListener ____
1512 void SAL_CALL ChartController::modified(
1513 const lang::EventObject& /* aEvent */ )
1514 {
1515 // the source can also be a subobject of the ChartModel
1516 // @todo: change the source in ChartModel to always be the model itself ?
1517 //todo? update menu states ?
1518 }
1519
1520 void ChartController::NotifyUndoActionHdl( std::unique_ptr<SdrUndoAction> pUndoAction )
1521 {
1522 ENSURE_OR_RETURN_VOID( pUndoAction, "invalid Undo action" );
1523
1524 OUString aObjectCID = m_aSelection.getSelectedCID();
1525 if ( !aObjectCID.isEmpty() )
1526 return;
1527
1528 try
1529 {
1530 rtl::Reference< ChartModel > xSuppUndo = getChartModel();
1531 const Reference< document::XUndoManager > xUndoManager( xSuppUndo->getUndoManager(), uno::UNO_SET_THROW );
1532 const Reference< document::XUndoAction > xAction( new impl::ShapeUndoElement( std::move(pUndoAction) ) );
1533 xUndoManager->addUndoAction( xAction );
1534 }
1535 catch( const uno::Exception& )
1536 {
1537 DBG_UNHANDLED_EXCEPTION("chart2");
1538 }
1539 }
1540
1541 DrawModelWrapper* ChartController::GetDrawModelWrapper()
1542 {
1543 if( !m_pDrawModelWrapper )
1544 {
1545 if( m_xChartView )
1546 m_pDrawModelWrapper = m_xChartView->getDrawModelWrapper();
1547 if ( m_pDrawModelWrapper )
1548 {
1549 m_pDrawModelWrapper->getSdrModel().SetNotifyUndoActionHdl([this](std::unique_ptr<SdrUndoAction> pUndoAction){
1550 NotifyUndoActionHdl(std::move(pUndoAction));
1551 });
1552 }
1553 }
1554 return m_pDrawModelWrapper.get();
1555 }
1556
1557 DrawViewWrapper* ChartController::GetDrawViewWrapper()
1558 {
1559 if ( !m_pDrawViewWrapper )
1560 {
1561 impl_createDrawViewController();
1562 }
1563 return m_pDrawViewWrapper.get();
1564 }
1565
1566
1567 ChartWindow* ChartController::GetChartWindow() const
1568 {
1569 // clients getting the naked VCL Window from UNO should always have the
1570 // solar mutex (and keep it over the lifetime of this ptr), as VCL might
1571 // might deinit otherwise
1572 DBG_TESTSOLARMUTEX();
1573 if(!m_xViewWindow.is())
1574 return nullptr;
1575 return dynamic_cast<ChartWindow*>(VCLUnoHelper::GetWindow(m_xViewWindow));
1576 }
1577
1578 weld::Window* ChartController::GetChartFrame()
1579 {
1580 // clients getting the naked VCL Window from UNO should always have the
1581 // solar mutex (and keep it over the lifetime of this ptr), as VCL might
1582 // might deinit otherwise
1583 DBG_TESTSOLARMUTEX();
1584 return Application::GetFrameWeld(m_xViewWindow);
1585 }
1586
1587 bool ChartController::isAdditionalShapeSelected() const
1588 {
1589 return m_aSelection.isAdditionalShapeSelected();
1590 }
1591
1592 void ChartController::SetAndApplySelection(const Reference<drawing::XShape>& rxShape)
1593 {
1594 if(rxShape.is())
1595 {
1596 m_aSelection.setSelection(rxShape);
1597 m_aSelection.applySelection(GetDrawViewWrapper());
1598 }
1599 }
1600
1601 rtl::Reference<AccessibleChartView> ChartController::CreateAccessible()
1602 {
1603 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1604 rtl::Reference< AccessibleChartView > xResult = new AccessibleChartView( GetDrawViewWrapper() );
1605 impl_initializeAccessible( *xResult );
1606 return xResult;
1607 #else
1608 return {};
1609 #endif
1610 }
1611
1612 void ChartController::impl_invalidateAccessible()
1613 {
1614 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1615 SolarMutexGuard aGuard;
1616 auto pChartWindow(GetChartWindow());
1617 if( pChartWindow )
1618 {
1619 rtl::Reference<comphelper::OAccessible> pAccessible = pChartWindow->GetAccessible(false);
1620 if (pAccessible.is())
1621 {
1622 //empty arguments -> invalid accessible
1623 dynamic_cast<AccessibleChartView&>(*pAccessible).initialize();
1624 }
1625 }
1626 #endif
1627 }
1628 void ChartController::impl_initializeAccessible()
1629 {
1630 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1631 SolarMutexGuard aGuard;
1632 auto pChartWindow(GetChartWindow());
1633 if( !pChartWindow )
1634 return;
1635 rtl::Reference<comphelper::OAccessible> pInit = pChartWindow->GetAccessible(false);
1636 if (pInit.is())
1637 impl_initializeAccessible(dynamic_cast<AccessibleChartView&>(*pInit));
1638 #endif
1639 }
1640 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1641 void ChartController::impl_initializeAccessible( AccessibleChartView& rAccChartView )
1642 {
1643 SolarMutexGuard aGuard;
1644
1645 uno::Reference< XAccessible > xParent;
1646
1647 ChartWindow* pChartWindow = GetChartWindow();
1648 if( pChartWindow )
1649 xParent.set(pChartWindow->GetAccessibleParent());
1650
1651 rAccChartView.initialize(*this, getChartModel(), m_xChartView, xParent, pChartWindow);
1652 }
1653 #else
1654 void ChartController::impl_initializeAccessible( AccessibleChartView& /* rAccChartView */) {}
1655 #endif
1656
1657 const o3tl::sorted_vector< std::u16string_view >& ChartController::impl_getAvailableCommands()
1658 {
1659 static const o3tl::sorted_vector< std::u16string_view > s_AvailableCommands {
1660 // toolbar commands
1661 u"ChartElementSelector",
1662
1663 // LOK commands
1664 u"LOKSetTextSelection", u"LOKTransform",
1665 };
1666 return s_AvailableCommands;
1667 }
1668
1669 ViewElementListProvider ChartController::getViewElementListProvider()
1670 {
1671 return ViewElementListProvider(m_pDrawModelWrapper.get());
1672 }
1673
1674 } //namespace chart
1675
1676 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */