1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_CHARTCONTROLLER_HXX
20 #define INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_CHARTCONTROLLER_HXX
22 #include <LifeTime.hxx>
23 #include "CommandDispatchContainer.hxx"
24 #include "SelectionHelper.hxx"
26 #include <svx/svdtypes.hxx>
27 #include <vcl/timer.hxx>
28 #include <vcl/event.hxx>
30 #include <cppuhelper/implbase.hxx>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 #include <com/sun/star/document/XUndoManager.hpp>
34 #include <com/sun/star/frame/XController.hpp>
35 #include <com/sun/star/frame/XDispatchProvider.hpp>
36 #include <com/sun/star/frame/XDispatch.hpp>
37 #include <com/sun/star/view/XSelectionSupplier.hpp>
38 #include <com/sun/star/ui/XContextMenuInterception.hpp>
39 #include <com/sun/star/uno/XWeak.hpp>
40 #include <com/sun/star/util/XCloseListener.hpp>
41 #include <com/sun/star/util/XCloseable.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/uno/XComponentContext.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/util/XModifyListener.hpp>
47 #include <com/sun/star/util/XModeChangeListener.hpp>
48 #include <com/sun/star/awt/Point.hpp>
49 #include <com/sun/star/awt/Size.hpp>
50 #include <com/sun/star/util/XURLTransformer.hpp>
51 #include <com/sun/star/frame/XLayoutManagerListener.hpp>
52 #include <com/sun/star/frame/XLayoutManagerEventBroadcaster.hpp>
61 class AcceleratorExecute
;
64 namespace svx
{ namespace sidebar
{
65 class SelectionChangeHandler
;
68 class DropTargetHelper
;
70 namespace com
{ namespace sun
{ namespace star
{
81 class DrawModelWrapper
;
82 class DrawViewWrapper
;
83 class ReferenceSizeProvider
;
84 class ViewElementListProvider
;
86 enum ChartDrawMode
{ CHARTDRAW_INSERT
, CHARTDRAW_SELECT
};
89 class ChartController
: public ::cppu::WeakImplHelper
<
90 css::frame::XController
//comprehends XComponent (required interface)
91 ,css::frame::XDispatchProvider
//(required interface)
92 ,css::view::XSelectionSupplier
//(optional interface)
93 ,css::ui::XContextMenuInterception
//(optional interface)
94 ,css::util::XCloseListener
//(needed for communication with XModel)
95 ,css::lang::XServiceInfo
96 ,css::frame::XDispatch
97 ,css::awt::XWindow
//this is the Window Controller part of this Controller, that will be given to a Frame via setComponent
98 ,css::lang::XMultiServiceFactory
99 ,css::util::XModifyListener
100 ,css::util::XModeChangeListener
101 ,css::frame::XLayoutManagerListener
105 ChartController() = delete;
106 explicit ChartController(css::uno::Reference
< css::uno::XComponentContext
> const & xContext
);
107 virtual ~ChartController() override
;
109 OUString
GetContextName();
111 // css::lang::XServiceInfo
112 virtual OUString SAL_CALL
getImplementationName() override
;
113 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
114 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
116 // css::frame::XController (required interface)
117 virtual void SAL_CALL
118 attachFrame( const css::uno::Reference
< css::frame::XFrame
> & xFrame
) override
;
120 virtual sal_Bool SAL_CALL
121 attachModel( const css::uno::Reference
< css::frame::XModel
> & xModel
) override
;
123 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
126 virtual css::uno::Reference
< css::frame::XModel
> SAL_CALL
129 virtual css::uno::Any SAL_CALL
130 getViewData() override
;
132 virtual void SAL_CALL
133 restoreViewData( const css::uno::Any
& rValue
) override
;
135 virtual sal_Bool SAL_CALL
136 suspend( sal_Bool bSuspend
) override
;
138 // css::lang::XComponent (base of XController)
139 virtual void SAL_CALL
142 virtual void SAL_CALL
143 addEventListener( const css::uno::Reference
< css::lang::XEventListener
> & xListener
) override
;
145 virtual void SAL_CALL
146 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
> & xListener
) override
;
148 // css::frame::XDispatchProvider (required interface)
149 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
150 queryDispatch( const css::util::URL
& rURL
151 , const OUString
& rTargetFrameName
152 , sal_Int32 nSearchFlags
) override
;
154 virtual css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
155 queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
> & xDescripts
) override
;
157 // css::view::XSelectionSupplier (optional interface)
158 virtual sal_Bool SAL_CALL
159 select( const css::uno::Any
& rSelection
) override
;
161 virtual css::uno::Any SAL_CALL
162 getSelection() override
;
164 virtual void SAL_CALL
165 addSelectionChangeListener( const css::uno::Reference
< css::view::XSelectionChangeListener
> & xListener
) override
;
167 virtual void SAL_CALL
168 removeSelectionChangeListener( const css::uno::Reference
< css::view::XSelectionChangeListener
> & xListener
) override
;
170 // css::ui::XContextMenuInterception (optional interface)
171 virtual void SAL_CALL
172 registerContextMenuInterceptor( const css::uno::Reference
< css::ui::XContextMenuInterceptor
> & xInterceptor
) override
;
174 virtual void SAL_CALL
175 releaseContextMenuInterceptor( const css::uno::Reference
< css::ui::XContextMenuInterceptor
> & xInterceptor
) override
;
177 //additional interfaces
179 // css::util::XCloseListener
180 virtual void SAL_CALL
181 queryClosing( const css::lang::EventObject
& Source
182 , sal_Bool GetsOwnership
) override
;
184 virtual void SAL_CALL
185 notifyClosing( const css::lang::EventObject
& Source
) override
;
187 // css::util::XEventListener (base of XCloseListener and XModifyListener)
188 virtual void SAL_CALL
189 disposing( const css::lang::EventObject
& Source
) override
;
191 // css::frame::XDispatch
193 virtual void SAL_CALL
194 dispatch( const css::util::URL
& aURL
195 , const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
197 virtual void SAL_CALL
198 addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xControl
199 , const css::util::URL
& aURL
) override
;
201 virtual void SAL_CALL
202 removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xControl
203 , const css::util::URL
& aURL
) override
;
206 virtual void SAL_CALL
207 setPosSize( sal_Int32 X
, sal_Int32 Y
208 , sal_Int32 Width
, sal_Int32 Height
, sal_Int16 Flags
) override
;
210 virtual css::awt::Rectangle SAL_CALL
211 getPosSize() override
;
213 virtual void SAL_CALL
214 setVisible( sal_Bool Visible
) override
;
216 virtual void SAL_CALL
217 setEnable( sal_Bool Enable
) override
;
219 virtual void SAL_CALL
222 virtual void SAL_CALL
223 addWindowListener( const css::uno::Reference
< css::awt::XWindowListener
>& xListener
) override
;
225 virtual void SAL_CALL
226 removeWindowListener( const css::uno::Reference
< css::awt::XWindowListener
>& xListener
) override
;
228 virtual void SAL_CALL
229 addFocusListener( const css::uno::Reference
< css::awt::XFocusListener
>& xListener
) override
;
231 virtual void SAL_CALL
232 removeFocusListener( const css::uno::Reference
< css::awt::XFocusListener
>& xListener
) override
;
234 virtual void SAL_CALL
235 addKeyListener( const css::uno::Reference
< css::awt::XKeyListener
>& xListener
) override
;
237 virtual void SAL_CALL
238 removeKeyListener( const css::uno::Reference
< css::awt::XKeyListener
>& xListener
) override
;
240 virtual void SAL_CALL
241 addMouseListener( const css::uno::Reference
< css::awt::XMouseListener
>& xListener
) override
;
243 virtual void SAL_CALL
244 removeMouseListener( const css::uno::Reference
< css::awt::XMouseListener
>& xListener
) override
;
246 virtual void SAL_CALL
247 addMouseMotionListener( const css::uno::Reference
< css::awt::XMouseMotionListener
>& xListener
) override
;
249 virtual void SAL_CALL
250 removeMouseMotionListener( const css::uno::Reference
< css::awt::XMouseMotionListener
>& xListener
) override
;
252 virtual void SAL_CALL
253 addPaintListener( const css::uno::Reference
< css::awt::XPaintListener
>& xListener
) override
;
255 virtual void SAL_CALL
256 removePaintListener( const css::uno::Reference
< css::awt::XPaintListener
>& xListener
) override
;
258 // css::lang XMultiServiceFactory
259 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
260 createInstance( const OUString
& aServiceSpecifier
) override
;
261 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
262 createInstanceWithArguments( const OUString
& ServiceSpecifier
,
263 const css::uno::Sequence
<
264 css::uno::Any
>& Arguments
) override
;
265 virtual css::uno::Sequence
< OUString
> SAL_CALL
266 getAvailableServiceNames() override
;
268 // css::util::XModifyListener
269 virtual void SAL_CALL
modified(
270 const css::lang::EventObject
& aEvent
) override
;
272 // css::util::XModeChangeListener
273 virtual void SAL_CALL
modeChanged(
274 const css::util::ModeChangeEvent
& _rSource
) override
;
276 // css::frame::XLayoutManagerListener
277 virtual void SAL_CALL
layoutEvent(
278 const css::lang::EventObject
& aSource
,
279 ::sal_Int16 eLayoutEvent
,
280 const css::uno::Any
& aInfo
) override
;
282 // WindowController stuff
284 void execute_Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
285 void execute_MouseButtonDown( const MouseEvent
& rMEvt
);
286 void execute_MouseMove( const MouseEvent
& rMEvt
);
287 void execute_MouseButtonUp( const MouseEvent
& rMEvt
);
288 void execute_Resize();
289 void execute_Command( const CommandEvent
& rCEvt
);
290 bool execute_KeyInput( const KeyEvent
& rKEvt
);
292 /** get help text to be shown in a quick help
294 @param aAtLogicPosition the position in logic coordinates (of the
295 window) of the mouse cursor to determine for
296 which object help is requested.
298 @param bIsBalloonHelp determines whether to return the long text version
299 (balloon help) or the shorter one (quick help).
301 @param rOutQuickHelpText is filled with the quick help text
303 @param rOutEqualRect is filled with a rectangle that denotes the region
304 in which the quick help does not change.
306 @return </sal_True>, if a quick help should be shown.
308 bool requestQuickHelp(
309 ::Point aAtLogicPosition
, bool bIsBalloonHelp
,
310 OUString
& rOutQuickHelpText
, css::awt::Rectangle
& rOutEqualRect
);
312 css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessible();
314 static bool isObjectDeleteable( const css::uno::Any
& rSelection
);
316 void setDrawMode( ChartDrawMode eMode
) { m_eDrawMode
= eMode
; }
318 bool isShapeContext() const;
320 ViewElementListProvider
getViewElementListProvider();
321 DrawModelWrapper
* GetDrawModelWrapper();
322 DrawViewWrapper
* GetDrawViewWrapper();
323 VclPtr
<ChartWindow
> GetChartWindow();
324 weld::Window
* GetChartFrame();
325 bool isAdditionalShapeSelected();
326 void SetAndApplySelection(const css::uno::Reference
<css::drawing::XShape
>& rxShape
);
327 void StartTextEdit( const Point
* pMousePixel
= nullptr );
329 DECL_LINK( NotifyUndoActionHdl
, SdrUndoAction
*, void );
331 css::uno::Reference
<css::uno::XInterface
> const & getChartView();
334 class TheModel
: public salhelper::SimpleReferenceObject
337 explicit TheModel( const css::uno::Reference
<
338 css::frame::XModel
> & xModel
);
340 virtual ~TheModel() override
;
342 void addListener( ChartController
* pController
);
343 void removeListener( ChartController
* pController
);
344 void tryTermination();
345 const css::uno::Reference
< css::frame::XModel
>&
346 getModel() const { return m_xModel
;}
349 css::uno::Reference
< css::frame::XModel
> m_xModel
;
350 css::uno::Reference
< css::util::XCloseable
> m_xCloseable
;
352 //the ownership between model and controller is not clear at first
353 //each controller might consider himself as owner of the model first
356 class TheModelRef final
359 TheModelRef( TheModel
* pTheModel
, ::osl::Mutex
& rMutex
);
360 TheModelRef( const TheModelRef
& rTheModel
, ::osl::Mutex
& rMutex
);
361 TheModelRef
& operator=(ChartController::TheModel
* pTheModel
);
362 TheModelRef
& operator=(const TheModelRef
& rTheModel
);
365 TheModel
* operator->() const { return m_xTheModel
.get(); }
367 rtl::Reference
<TheModel
> m_xTheModel
;
368 ::osl::Mutex
& m_rModelMutex
;
371 mutable ::apphelper::LifeTimeManager m_aLifeTimeManager
;
375 css::uno::Reference
< css::uno::XComponentContext
> m_xCC
;
378 css::uno::Reference
< css::frame::XFrame
> m_xFrame
;
379 mutable ::osl::Mutex m_aModelMutex
;
380 TheModelRef m_aModel
;
383 css::uno::Reference
<css::awt::XWindow
> m_xViewWindow
;
384 css::uno::Reference
<css::uno::XInterface
> m_xChartView
;
385 std::shared_ptr
< DrawModelWrapper
> m_pDrawModelWrapper
;
386 DrawViewWrapper
* m_pDrawViewWrapper
;
388 Selection m_aSelection
;
389 SdrDragMode m_eDragMode
;
391 Timer m_aDoubleClickTimer
;
392 bool m_bWaitingForDoubleClick
;
393 bool m_bWaitingForMouseUp
;
394 bool m_bFieldButtonDown
;
396 bool m_bConnectingToView
;
399 css::uno::Reference
< css::document::XUndoManager
> m_xUndoManager
;
400 std::unique_ptr
< UndoGuard
> m_pTextActionUndoGuard
;
402 std::unique_ptr
< ::svt::AcceleratorExecute
> m_apAccelExecute
;
404 CommandDispatchContainer m_aDispatchContainer
;
406 std::unique_ptr
< DropTargetHelper
> m_apDropTargetHelper
;
408 css::frame::XLayoutManagerEventBroadcaster
> m_xLayoutManagerEventBroadcaster
;
410 ChartDrawMode m_eDrawMode
;
412 rtl::Reference
<svx::sidebar::SelectionChangeHandler
> mpSelectionChangeHandler
;
414 bool impl_isDisposedOrSuspended() const;
415 ReferenceSizeProvider
* impl_createReferenceSizeProvider();
416 void impl_adaptDataSeriesAutoResize();
418 void impl_createDrawViewController();
419 void impl_deleteDrawViewController();
421 //executeDispatch methods
422 void executeDispatch_ObjectProperties();
423 void executeDispatch_FormatObject( const OUString
& rDispatchCommand
);
424 void executeDlg_ObjectProperties( const OUString
& rObjectCID
);
425 bool executeDlg_ObjectProperties_withoutUndoGuard( const OUString
& rObjectCID
, bool bSuccessOnUnchanged
);
427 void executeDispatch_ChartType();
429 void executeDispatch_InsertTitles();
430 void executeDispatch_InsertLegend();
431 void executeDispatch_DeleteLegend();
432 void executeDispatch_OpenLegendDialog();
433 void executeDispatch_InsertAxes();
434 void executeDispatch_InsertGrid();
436 void executeDispatch_InsertMenu_DataLabels();
437 void executeDispatch_InsertMenu_Trendlines();
438 void executeDispatch_InsertMenu_MeanValues();
440 void executeDispatch_InsertMeanValue();
441 void executeDispatch_InsertTrendline();
442 void executeDispatch_InsertTrendlineEquation( bool bInsertR2
=false );
443 void executeDispatch_InsertErrorBars( bool bYError
);
445 void executeDispatch_InsertR2Value();
446 void executeDispatch_DeleteR2Value();
448 void executeDispatch_DeleteMeanValue();
449 void executeDispatch_DeleteTrendline();
450 void executeDispatch_DeleteTrendlineEquation();
451 void executeDispatch_DeleteErrorBars( bool bYError
);
453 void executeDispatch_InsertDataLabels();
454 void executeDispatch_InsertDataLabel();
455 void executeDispatch_DeleteDataLabels();
456 void executeDispatch_DeleteDataLabel();
458 void executeDispatch_ResetAllDataPoints();
459 void executeDispatch_ResetDataPoint();
461 void executeDispatch_InsertAxis();
462 void executeDispatch_InsertAxisTitle();
463 void executeDispatch_InsertMajorGrid();
464 void executeDispatch_InsertMinorGrid();
465 void executeDispatch_DeleteAxis();
466 void executeDispatch_DeleteMajorGrid();
467 void executeDispatch_DeleteMinorGrid();
469 void executeDispatch_InsertSpecialCharacter();
470 void executeDispatch_EditText( const Point
* pMousePixel
= nullptr );
471 void executeDispatch_SourceData();
472 void executeDispatch_MoveSeries( bool bForward
);
476 void executeDispatch_View3D();
477 void executeDispatch_PositionAndSize();
479 void executeDispatch_EditData();
481 void executeDispatch_NewArrangement();
482 void executeDispatch_ScaleText();
484 void executeDispatch_Paste();
485 void executeDispatch_Copy();
486 void executeDispatch_Cut();
487 bool executeDispatch_Delete();
488 void executeDispatch_ToggleLegend();
489 void executeDispatch_ToggleGridHorizontal();
490 void executeDispatch_ToggleGridVertical();
492 void executeDispatch_LOKSetTextSelection(int nType
, int nX
, int nY
);
494 void sendPopupRequest(OUString
const & rCID
, tools::Rectangle aRectangle
);
496 void impl_ShapeControllerDispatch( const css::util::URL
& rURL
,
497 const css::uno::Sequence
< css::beans::PropertyValue
>& rArgs
);
499 DECL_LINK( DoubleClickWaitingHdl
, Timer
*, void );
500 void execute_DoubleClick( const Point
* pMousePixel
);
501 void startDoubleClickWaiting();
502 void stopDoubleClickWaiting();
504 void impl_selectObjectAndNotiy();
505 void impl_notifySelectionChangeListeners();
506 void impl_invalidateAccessible();
507 void impl_initializeAccessible();
508 void impl_initializeAccessible( const css::uno::Reference
< css::lang::XInitialization
>& xInit
);
510 //sets the model member to null if it equals the parameter
511 //returns true if successful
512 bool impl_releaseThisModel( const css::uno::Reference
< css::uno::XInterface
> & xModel
);
514 enum eMoveOrResizeType
517 CENTERED_RESIZE_OBJECT
519 /// @return </sal_True>, if resize/move was successful
520 bool impl_moveOrResizeObject(
521 const OUString
& rCID
, eMoveOrResizeType eType
, double fAmountLogicX
, double fAmountLogicY
);
522 bool impl_DragDataPoint( const OUString
& rCID
, double fOffset
);
524 static const std::set
< OUString
>& impl_getAvailableCommands();
526 /** Creates a helper accessibility class that must be initialized via XInitialization. For
529 The returned object should not be used directly. Instead a proxy object
530 should use this helper to retrieve its children and add them to its own
533 css::uno::Reference
< css::accessibility::XAccessibleContext
>
534 impl_createAccessibleTextContext();
536 void impl_PasteGraphic( css::uno::Reference
< css::graphic::XGraphic
> const & xGraphic
,
537 const ::Point
& aPosition
);
538 void impl_PasteShapes( SdrModel
* pModel
);
539 void impl_PasteStringAsTextShape( const OUString
& rString
, const css::awt::Point
& rPosition
);
540 void impl_SetMousePointer( const MouseEvent
& rEvent
);
542 void impl_ClearSelection();
544 void impl_switchDiagramPositioningToExcludingPositioning();
551 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */