tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / inc / ChartController.hxx
blobc882c185b3f8cdb9b72e7dcd8a0fd91ea061f150
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
21 #include <LifeTime.hxx>
22 #include <ReferenceSizeProvider.hxx>
23 #include "CommandDispatchContainer.hxx"
24 #include "SelectionHelper.hxx"
26 #include <svx/svdtypes.hxx>
27 #include <vcl/timer.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <o3tl/sorted_vector.hxx>
31 #include <salhelper/simplereferenceobject.hxx>
33 #include <com/sun/star/frame/XDispatchProvider.hpp>
34 #include <com/sun/star/ui/XContextMenuInterception.hpp>
35 #include <com/sun/star/util/XModeChangeListener.hpp>
36 #include <com/sun/star/util/XCloseListener.hpp>
37 #include <com/sun/star/util/XModifyListener.hpp>
38 #include <com/sun/star/frame/XController2.hpp>
39 #include <com/sun/star/frame/XLayoutManagerListener.hpp>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <memory>
43 #include <string_view>
45 namespace com::sun::star::accessibility { class XAccessible; }
46 namespace com::sun::star::accessibility { class XAccessibleContext; }
47 namespace com::sun::star::awt { class XFocusListener; }
48 namespace com::sun::star::awt { class XKeyListener; }
49 namespace com::sun::star::awt { class XMouseListener; }
50 namespace com::sun::star::awt { class XMouseMotionListener; }
51 namespace com::sun::star::awt { class XPaintListener; }
52 namespace com::sun::star::awt { class XWindow; }
53 namespace com::sun::star::awt { class XWindowListener; }
54 namespace com::sun::star::awt { struct Point; }
55 namespace com::sun::star::document { class XUndoManager; }
56 namespace com::sun::star::frame { class XDispatch; }
57 namespace com::sun::star::frame { class XLayoutManagerEventBroadcaster; }
58 namespace com::sun::star::graphic { class XGraphic; }
59 namespace com::sun::star::lang { class XInitialization; }
60 namespace com::sun::star::uno { class XComponentContext; }
61 namespace com::sun::star::util { class XCloseable; }
62 namespace com::sun::star::view { class XSelectionSupplier; }
64 class SdrModel;
66 namespace svt
68 class AcceleratorExecute;
71 namespace svx::sidebar {
72 class SelectionChangeHandler;
75 namespace weld {
76 class Window;
79 class DropTargetHelper;
81 namespace chart
84 class UndoGuard;
85 class ChartView;
86 class ChartWindow;
87 class DrawModelWrapper;
88 class DrawViewWrapper;
89 class ViewElementListProvider;
90 class ViewElementListProvider;
91 class Diagram;
92 class AccessibleChartView;
93 class AccessibleTextHelper;
95 enum ChartDrawMode { CHARTDRAW_INSERT, CHARTDRAW_SELECT };
98 class ChartController final : public ::cppu::WeakImplHelper <
99 css::frame::XController2 //comprehends XComponent (css::frame::XController is required interface)
100 ,css::frame::XDispatchProvider //(required interface)
101 ,css::view::XSelectionSupplier //(optional interface)
102 ,css::ui::XContextMenuInterception //(optional interface)
103 ,css::util::XCloseListener //(needed for communication with XModel)
104 ,css::frame::XDispatch
105 ,css::awt::XWindow //this is the Window Controller part of this Controller, that will be given to a Frame via setComponent
106 ,css::util::XModifyListener
107 ,css::util::XModeChangeListener
108 ,css::frame::XLayoutManagerListener
111 public:
112 ChartController() = delete;
113 explicit ChartController(css::uno::Reference< css::uno::XComponentContext > xContext);
114 virtual ~ChartController() override;
116 OUString GetContextName();
118 // css::frame::XController (required interface)
119 virtual void SAL_CALL
120 attachFrame( const css::uno::Reference< css::frame::XFrame > & xFrame ) override;
122 virtual sal_Bool SAL_CALL
123 attachModel( const css::uno::Reference< css::frame::XModel > & xModel ) override;
125 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL
126 getFrame() override;
128 virtual css::uno::Reference< css::frame::XModel > SAL_CALL
129 getModel() override;
131 virtual css::uno::Any SAL_CALL
132 getViewData() override;
134 virtual void SAL_CALL
135 restoreViewData( const css::uno::Any& rValue ) override;
137 virtual sal_Bool SAL_CALL
138 suspend( sal_Bool bSuspend ) override;
140 // css::frame::XController2
141 virtual css::uno::Reference<css::awt::XWindow> SAL_CALL getComponentWindow() override;
142 virtual OUString SAL_CALL getViewControllerName() override;
143 virtual css::uno::Sequence<css::beans::PropertyValue> SAL_CALL getCreationArguments() override;
144 virtual css::uno::Reference<css::ui::XSidebarProvider> SAL_CALL getSidebar() override;
146 // css::lang::XComponent (base of XController)
147 virtual void SAL_CALL
148 dispose() override;
150 virtual void SAL_CALL
151 addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
153 virtual void SAL_CALL
154 removeEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
156 // css::frame::XDispatchProvider (required interface)
157 virtual css::uno::Reference< css::frame::XDispatch> SAL_CALL
158 queryDispatch( const css::util::URL& rURL
159 , const OUString& rTargetFrameName
160 , sal_Int32 nSearchFlags) override;
162 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL
163 queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor > & xDescripts) override;
165 // css::view::XSelectionSupplier (optional interface)
166 virtual sal_Bool SAL_CALL
167 select( const css::uno::Any& rSelection ) override;
169 virtual css::uno::Any SAL_CALL
170 getSelection() override;
172 virtual void SAL_CALL
173 addSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener > & xListener ) override;
175 virtual void SAL_CALL
176 removeSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener > & xListener ) override;
178 // css::ui::XContextMenuInterception (optional interface)
179 virtual void SAL_CALL
180 registerContextMenuInterceptor( const css::uno::Reference< css::ui::XContextMenuInterceptor > & xInterceptor) override;
182 virtual void SAL_CALL
183 releaseContextMenuInterceptor( const css::uno::Reference< css::ui::XContextMenuInterceptor > & xInterceptor) override;
185 //additional interfaces
187 // css::util::XCloseListener
188 virtual void SAL_CALL
189 queryClosing( const css::lang::EventObject& Source
190 , sal_Bool GetsOwnership ) override;
192 virtual void SAL_CALL
193 notifyClosing( const css::lang::EventObject& Source ) override;
195 // css::util::XEventListener (base of XCloseListener and XModifyListener)
196 virtual void SAL_CALL
197 disposing( const css::lang::EventObject& Source ) override;
199 // css::frame::XDispatch
201 virtual void SAL_CALL
202 dispatch( const css::util::URL& aURL
203 , const css::uno::Sequence< css::beans::PropertyValue >& aArgs ) override;
205 virtual void SAL_CALL
206 addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl
207 , const css::util::URL& aURL ) override;
209 virtual void SAL_CALL
210 removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl
211 , const css::util::URL& aURL ) override;
213 // css::awt::XWindow
214 virtual void SAL_CALL
215 setPosSize( sal_Int32 X, sal_Int32 Y
216 , sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) override;
218 virtual css::awt::Rectangle SAL_CALL
219 getPosSize() override;
221 virtual void SAL_CALL
222 setVisible( sal_Bool Visible ) override;
224 virtual void SAL_CALL
225 setEnable( sal_Bool Enable ) override;
227 virtual void SAL_CALL
228 setFocus() override;
230 virtual void SAL_CALL
231 addWindowListener( const css::uno::Reference< css::awt::XWindowListener >& xListener ) override;
233 virtual void SAL_CALL
234 removeWindowListener( const css::uno::Reference< css::awt::XWindowListener >& xListener ) override;
236 virtual void SAL_CALL
237 addFocusListener( const css::uno::Reference< css::awt::XFocusListener >& xListener ) override;
239 virtual void SAL_CALL
240 removeFocusListener( const css::uno::Reference< css::awt::XFocusListener >& xListener ) override;
242 virtual void SAL_CALL
243 addKeyListener( const css::uno::Reference< css::awt::XKeyListener >& xListener ) override;
245 virtual void SAL_CALL
246 removeKeyListener( const css::uno::Reference< css::awt::XKeyListener >& xListener ) override;
248 virtual void SAL_CALL
249 addMouseListener( const css::uno::Reference< css::awt::XMouseListener >& xListener ) override;
251 virtual void SAL_CALL
252 removeMouseListener( const css::uno::Reference< css::awt::XMouseListener >& xListener ) override;
254 virtual void SAL_CALL
255 addMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& xListener ) override;
257 virtual void SAL_CALL
258 removeMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& xListener ) override;
260 virtual void SAL_CALL
261 addPaintListener( const css::uno::Reference< css::awt::XPaintListener >& xListener ) override;
263 virtual void SAL_CALL
264 removePaintListener( const css::uno::Reference< css::awt::XPaintListener >& xListener ) override;
266 // css::util::XModifyListener
267 virtual void SAL_CALL modified(
268 const css::lang::EventObject& aEvent ) override;
270 // css::util::XModeChangeListener
271 virtual void SAL_CALL modeChanged(
272 const css::util::ModeChangeEvent& _rSource ) override;
274 // css::frame::XLayoutManagerListener
275 virtual void SAL_CALL layoutEvent(
276 const css::lang::EventObject& aSource,
277 ::sal_Int16 eLayoutEvent,
278 const css::uno::Any& aInfo ) override;
280 // WindowController stuff
281 void PrePaint();
282 void execute_Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
283 void execute_MouseButtonDown( const MouseEvent& rMEvt );
284 void execute_MouseMove( const MouseEvent& rMEvt );
285 void execute_MouseButtonUp( const MouseEvent& rMEvt );
286 void execute_Resize();
287 void execute_Command( const CommandEvent& rCEvt );
288 bool execute_KeyInput( const KeyEvent& rKEvt );
290 /** get help text to be shown in a quick help
292 @param aAtLogicPosition the position in logic coordinates (of the
293 window) of the mouse cursor to determine for
294 which object help is requested.
296 @param bIsBalloonHelp determines whether to return the long text version
297 (balloon help) or the shorter one (quick help).
299 @param rOutQuickHelpText is filled with the quick help text
301 @param rOutEqualRect is filled with a rectangle that denotes the region
302 in which the quick help does not change.
304 @return </sal_True>, if a quick help should be shown.
306 bool requestQuickHelp(
307 ::Point aAtLogicPosition, bool bIsBalloonHelp,
308 OUString & rOutQuickHelpText, css::awt::Rectangle & rOutEqualRect );
310 css::uno::Reference< css::accessibility::XAccessible > CreateAccessible();
312 /** Creates a helper accessibility class that must be initialized via initialize(). For
313 parameters see
315 The returned object should not be used directly. Instead a proxy object
316 should use this helper to retrieve its children and add them to its own
317 children.
319 rtl::Reference< ::chart::AccessibleTextHelper > createAccessibleTextContext();
321 static bool isObjectDeleteable( const css::uno::Any& rSelection );
323 void setDrawMode( ChartDrawMode eMode ) { m_eDrawMode = eMode; }
325 bool isShapeContext() const;
326 bool IsTextEdit() const;
328 ViewElementListProvider getViewElementListProvider();
329 DrawModelWrapper* GetDrawModelWrapper();
330 DrawViewWrapper* GetDrawViewWrapper();
331 ChartWindow* GetChartWindow() const;
332 weld::Window* GetChartFrame();
333 bool isAdditionalShapeSelected() const;
334 void SetAndApplySelection(const css::uno::Reference<css::drawing::XShape>& rxShape);
335 void StartTextEdit( const Point* pMousePixel = nullptr );
337 void NotifyUndoActionHdl( std::unique_ptr<SdrUndoAction> );
339 rtl::Reference<::chart::ChartView> const & getChartView() const { return m_xChartView; }
341 rtl::Reference<::chart::ChartModel> getChartModel();
342 rtl::Reference<::chart::Diagram> getFirstDiagram();
344 private:
345 class TheModel : public salhelper::SimpleReferenceObject
347 public:
348 explicit TheModel( rtl::Reference<::chart::ChartModel> xModel );
350 virtual ~TheModel() override;
352 void addListener( ChartController* pController );
353 void removeListener( ChartController* pController );
354 void tryTermination();
355 const rtl::Reference<::chart::ChartModel>&
356 getModel() const { return m_xModel;}
358 private:
359 rtl::Reference<::chart::ChartModel> m_xModel;
361 //the ownership between model and controller is not clear at first
362 //each controller might consider himself as owner of the model first
363 bool m_bOwnership;
365 class TheModelRef final
367 public:
368 TheModelRef( TheModel* pTheModel, ::osl::Mutex& rMutex );
369 TheModelRef( const TheModelRef& rTheModel, ::osl::Mutex& rMutex );
370 TheModelRef& operator=(ChartController::TheModel* pTheModel);
371 TheModelRef& operator=(const TheModelRef& rTheModel);
372 ~TheModelRef();
373 bool is() const;
374 TheModel* operator->() const { return m_xTheModel.get(); }
375 private:
376 rtl::Reference<TheModel> m_xTheModel;
377 ::osl::Mutex& m_rModelMutex;
380 mutable ::apphelper::LifeTimeManager m_aLifeTimeManager;
382 bool m_bSuspended;
384 css::uno::Reference< css::uno::XComponentContext> m_xCC;
386 //model
387 css::uno::Reference< css::frame::XFrame > m_xFrame;
388 mutable ::osl::Mutex m_aModelMutex;
389 TheModelRef m_aModel;
391 //view
392 css::uno::Reference<css::awt::XWindow> m_xViewWindow;
393 rtl::Reference<::chart::ChartView> m_xChartView;
394 std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper;
395 std::unique_ptr<DrawViewWrapper> m_pDrawViewWrapper;
397 Selection m_aSelection;
398 SdrDragMode m_eDragMode;
400 Timer m_aDoubleClickTimer;
401 bool m_bWaitingForDoubleClick;
402 bool m_bWaitingForMouseUp;
403 bool m_bFieldButtonDown;
405 bool m_bConnectingToView;
406 bool m_bDisposed;
408 css::uno::Reference< css::document::XUndoManager > m_xUndoManager;
409 std::unique_ptr< UndoGuard > m_pTextActionUndoGuard;
411 std::unique_ptr< ::svt::AcceleratorExecute > m_apAccelExecute;
413 CommandDispatchContainer m_aDispatchContainer;
415 std::unique_ptr< DropTargetHelper > m_apDropTargetHelper;
416 css::uno::Reference<
417 css::frame::XLayoutManagerEventBroadcaster > m_xLayoutManagerEventBroadcaster;
419 ChartDrawMode m_eDrawMode;
421 rtl::Reference<svx::sidebar::SelectionChangeHandler> mpSelectionChangeHandler;
423 bool impl_isDisposedOrSuspended() const;
424 ReferenceSizeProvider impl_createReferenceSizeProvider();
425 void impl_adaptDataSeriesAutoResize();
427 void impl_createDrawViewController();
428 void impl_deleteDrawViewController();
430 //executeDispatch methods
431 void executeDispatch_ObjectProperties();
432 void executeDispatch_FormatObject( std::u16string_view rDispatchCommand );
433 void executeDlg_ObjectProperties( const OUString& rObjectCID );
434 void executeDlg_ObjectProperties_withUndoGuard( std::shared_ptr<UndoGuard> aUndoGuard, const OUString& rObjectCID, bool bSuccessOnUnchanged );
436 void executeDispatch_ChartType();
438 void executeDispatch_InsertTitles();
439 void executeDispatch_InsertLegend();
440 void executeDispatch_DeleteLegend();
441 void executeDispatch_OpenLegendDialog();
442 void executeDispatch_InsertAxes();
443 void executeDispatch_InsertGrid();
445 void executeDispatch_InsertDataTable();
446 void executeDispatch_DeleteDataTable();
447 void executeDispatch_OpenInsertDataTableDialog();
449 void executeDispatch_InsertMenu_DataLabels();
450 void executeDispatch_InsertMenu_Trendlines();
451 void executeDispatch_InsertMenu_MeanValues();
453 void executeDispatch_InsertMeanValue();
454 void executeDispatch_InsertTrendline();
455 void executeDispatch_InsertTrendlineEquation( bool bInsertR2=false );
456 void executeDispatch_InsertErrorBars( bool bYError );
458 void executeDispatch_InsertR2Value();
459 void executeDispatch_DeleteR2Value();
461 void executeDispatch_DeleteMeanValue();
462 void executeDispatch_DeleteTrendline();
463 void executeDispatch_DeleteTrendlineEquation();
464 void executeDispatch_DeleteErrorBars( bool bYError );
466 void executeDispatch_InsertDataLabels();
467 void executeDispatch_InsertDataLabel();
468 void executeDispatch_DeleteDataLabels();
469 void executeDispatch_DeleteDataLabel();
471 void executeDispatch_ResetAllDataPoints();
472 void executeDispatch_ResetDataPoint();
474 void executeDispatch_InsertAxis();
475 void executeDispatch_InsertAxisTitle();
476 void executeDispatch_InsertMajorGrid();
477 void executeDispatch_InsertMinorGrid();
478 void executeDispatch_DeleteAxis();
479 void executeDispatch_DeleteMajorGrid();
480 void executeDispatch_DeleteMinorGrid();
482 void executeDispatch_InsertSpecialCharacter();
483 void executeDispatch_EditText( const Point* pMousePixel = nullptr );
484 void executeDispatch_SourceData();
485 void executeDispatch_MoveSeries( bool bForward );
487 bool EndTextEdit();
488 css::uno::Sequence< css::uno::Reference<css::chart2::XFormattedString >> GetFormattedTitle(
489 const EditTextObject& aEdit, const css::uno::Reference< css::drawing::XShape >& xShape );
491 void executeDispatch_View3D();
492 void executeDispatch_PositionAndSize( const ::css::uno::Sequence< ::css::beans::PropertyValue >* pArgs = nullptr );
494 void executeDispatch_EditData();
496 void executeDispatch_NewArrangement();
497 void executeDispatch_ScaleText();
499 void executeDispatch_Paste();
500 void executeDispatch_Copy();
501 void executeDispatch_Cut();
502 bool executeDispatch_Delete();
503 void executeDispatch_ToggleLegend();
504 void executeDispatch_ToggleGridHorizontal();
505 void executeDispatch_ToggleGridVertical();
507 void executeDispatch_LOKSetTextSelection(int nType, int nX, int nY);
508 void executeDispatch_LOKPieSegmentDragging(int nOffset);
509 void executeDispatch_FillColor(sal_uInt32 nColor);
510 void executeDispatch_FillGradient(std::u16string_view sJSONGradient);
511 void executeDispatch_LineColor(sal_uInt32 nColor);
512 void executeDispatch_LineWidth(sal_uInt32 nWidth);
514 void sendPopupRequest(std::u16string_view rCID, tools::Rectangle aRectangle);
516 void impl_ShapeControllerDispatch( const css::util::URL& rURL,
517 const css::uno::Sequence< css::beans::PropertyValue >& rArgs );
519 DECL_LINK( DoubleClickWaitingHdl, Timer*, void );
520 void execute_DoubleClick( const Point* pMousePixel, bool &bEditText );
521 void startDoubleClickWaiting();
522 void stopDoubleClickWaiting();
524 void impl_selectObjectAndNotiy();
525 void impl_notifySelectionChangeListeners();
526 void impl_invalidateAccessible();
527 void impl_initializeAccessible();
528 void impl_initializeAccessible( AccessibleChartView& xInit );
530 //sets the model member to null if it equals the parameter
531 //returns true if successful
532 bool impl_releaseThisModel( const css::uno::Reference< css::uno::XInterface > & xModel );
534 enum eMoveOrResizeType
536 MOVE_OBJECT,
537 CENTERED_RESIZE_OBJECT
539 /// @return </sal_True>, if resize/move was successful
540 bool impl_moveOrResizeObject(
541 const OUString & rCID, eMoveOrResizeType eType, double fAmountLogicX, double fAmountLogicY );
542 bool impl_DragDataPoint( std::u16string_view rCID, double fOffset );
544 static const o3tl::sorted_vector< std::u16string_view >& impl_getAvailableCommands();
546 void impl_PasteGraphic( css::uno::Reference< css::graphic::XGraphic > const & xGraphic,
547 const ::Point & aPosition );
548 void impl_PasteShapes( SdrModel* pModel );
549 void impl_PasteStringAsTextShape( const OUString& rString, const css::awt::Point& rPosition );
550 void impl_SetMousePointer( const MouseEvent & rEvent );
552 void impl_ClearSelection();
554 void impl_switchDiagramPositioningToExcludingPositioning();
557 } // namespace chart
559 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */