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 #ifndef INCLUDED_SVX_GRAPHCTL_HXX
20 #define INCLUDED_SVX_GRAPHCTL_HXX
21 
22 #include <vcl/graph.hxx>
23 #include <vcl/customweld.hxx>
24 #include <svx/svxdllapi.h>
25 
26 #include <svx/svdview.hxx>
27 #include <svx/svdobj.hxx>
28 
29 class GraphCtrl;
30 
31 class GraphCtrlUserCall final : public SdrObjUserCall
32 {
33     GraphCtrl& rWin;
34 
35 public:
36 
GraphCtrlUserCall(GraphCtrl & rGraphWin)37     GraphCtrlUserCall(GraphCtrl& rGraphWin)
38         : rWin(rGraphWin)
39     {}
40 
41     virtual void Changed(const SdrObject& rObj, SdrUserCallType eType, const tools::Rectangle& rOldBoundRect) override;
42 };
43 
44 class SvxGraphCtrlAccessibleContext;
45 
46 class SVX_DLLPUBLIC GraphCtrl : public weld::CustomWidgetController
47 {
48     friend class GraphCtrlView;
49     friend class GraphCtrlUserCall;
50 
51     Graphic             aGraphic;
52     ScopedVclPtrInstance<VirtualDevice> xVD;
53     Idle                aUpdateIdle;
54     Link<GraphCtrl*,void>  aMousePosLink;
55     Link<GraphCtrl*,void>  aGraphSizeLink;
56     Link<GraphCtrl*,void>  aUpdateLink;
57     MapMode const          aMap100;
58     Size                aGraphSize;
59     Point               aMousePos;
60     std::unique_ptr<GraphCtrlUserCall> pUserCall;
61     SdrObjKind          eObjKind;
62     sal_uInt16          nPolyEdit;
63     bool                bEditMode;
64     bool                mbSdrMode;
65     bool                mbInIdleUpdate;
66     weld::Dialog*       mpDialog;
67 
68                         DECL_LINK( UpdateHdl, Timer*, void );
69 
70     rtl::Reference<SvxGraphCtrlAccessibleContext> mpAccContext;
71 
72 protected:
73 
74     std::unique_ptr<SdrModel>  pModel;
75     std::unique_ptr<SdrView>   pView;
76 
77     virtual void        Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
78     virtual void        Resize() override;
79     virtual bool        KeyInput(const KeyEvent& rKEvt) override;
80     virtual bool        MouseButtonDown(const MouseEvent& rMEvt) override;
81     virtual bool        MouseButtonUp(const MouseEvent& rMEvt) override;
82     virtual bool        MouseMove(const MouseEvent& rMEvt) override;
83 
84     virtual void        InitSdrModel();
85 
86     virtual void        SdrObjCreated( const SdrObject& rObj );
87     virtual void        SdrObjChanged( const SdrObject& rObj );
88     virtual void        MarkListHasChanged();
89 
90     void GraphicToVD();
91 
GetSdrUserCall()92     SdrObjUserCall* GetSdrUserCall() { return pUserCall.get(); }
93 
94 public:
95 
96     GraphCtrl(weld::Dialog* pDialog);
97     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
98     virtual ~GraphCtrl() override;
99 
100     void                SetGraphic( const Graphic& rGraphic, bool bNewModel = true );
GetGraphic() const101     const Graphic&      GetGraphic() const { return aGraphic; }
GetGraphicSize() const102     const Size&         GetGraphicSize() const { return aGraphSize; }
103 
GetMousePos() const104     const Point&        GetMousePos() const { return aMousePos; }
105 
106     void                SetEditMode( const bool bEditMode );
107 
108     void                SetPolyEditMode( const sal_uInt16 nPolyEdit );
GetPolyEditMode() const109     sal_uInt16          GetPolyEditMode() const { return nPolyEdit; }
110 
111     void                SetObjKind( const SdrObjKind eObjKind );
112 
GetSdrModel() const113     SdrModel*           GetSdrModel() const { return pModel.get(); }
GetSdrView() const114     SdrView*            GetSdrView() const { return pView.get(); }
115     SdrObject*          GetSelectedSdrObject() const;
IsChanged() const116     bool                IsChanged() const { return mbSdrMode && pModel->IsChanged(); }
117 
SetMousePosLink(const Link<GraphCtrl *,void> & rLink)118     void                SetMousePosLink( const Link<GraphCtrl*,void>& rLink ) { aMousePosLink = rLink; }
119 
SetGraphSizeLink(const Link<GraphCtrl *,void> & rLink)120     void                SetGraphSizeLink( const Link<GraphCtrl*,void>& rLink ) { aGraphSizeLink = rLink; }
121 
SetUpdateLink(const Link<GraphCtrl *,void> & rLink)122     void                SetUpdateLink( const Link<GraphCtrl*,void>& rLink ) { aUpdateLink = rLink; }
123     void                QueueIdleUpdate();
124 
125     void                SetSdrMode(bool b);
126 
127     Point               GetPositionInDialog() const;
128     virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
129 };
130 
131 class GraphCtrlView : public SdrView
132 {
133     GraphCtrl& rGraphCtrl;
134 
135 protected:
136 
MarkListHasChanged()137     virtual void MarkListHasChanged() override
138     {
139         SdrView::MarkListHasChanged();
140         rGraphCtrl.MarkListHasChanged();
141     }
142 
143 public:
GraphCtrlView(SdrModel & rSdrModel,GraphCtrl * pWindow)144     GraphCtrlView(SdrModel& rSdrModel, GraphCtrl* pWindow)
145         : SdrView(rSdrModel, &pWindow->GetDrawingArea()->get_ref_device())
146         , rGraphCtrl(*pWindow)
147     {
148     }
149 
150     virtual ~GraphCtrlView() override;
151 
152     // override these so we can get the occasions SdrPaintView would call Window::Invalidate on its vcl::Window
153     // if it had one, and route to WidgetController::Invalidate instead
154     virtual rtl::Reference<sdr::overlay::OverlayManager> CreateOverlayManager(OutputDevice& rDevice) const override;
155     virtual void InvalidateOneWin(OutputDevice& rWin) override;
156     virtual void InvalidateOneWin(OutputDevice& rWin, const tools::Rectangle& rRect) override;
157 };
158 
159 #endif // INCLUDED_SVX_GRAPHCTL_HXX
160 
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
162