tdf#149529 crash on deref deleted ScDocument*
[LibreOffice.git] / include / svx / dialcontrol.hxx
blob8fafb3fc03aaef0b2669466ee50363f41147bbf7
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 .
20 #ifndef INCLUDED_SVX_DIALCONTROL_HXX
21 #define INCLUDED_SVX_DIALCONTROL_HXX
23 #include <memory>
24 #include <vcl/customweld.hxx>
25 #include <vcl/virdev.hxx>
26 #include <svx/svxdllapi.h>
28 class Edit;
30 namespace svx {
33 class SAL_WARN_UNUSED DialControlBmp final : public VirtualDevice
35 public:
36 explicit DialControlBmp(OutputDevice& rReference);
38 void InitBitmap(const vcl::Font& rFont);
39 void SetSize(const Size& rSize);
40 void CopyBackground( const DialControlBmp& rSrc );
41 void DrawBackground( const Size& rSize, bool bEnabled );
42 void DrawBackground();
43 void DrawElements( const OUString& rText, Degree100 nAngle );
44 Color GetBackgroundColor() const override;
46 private:
47 const Color& GetTextColor() const;
48 const Color& GetScaleLineColor() const;
49 const Color& GetButtonLineColor() const;
50 const Color& GetButtonFillColor( bool bMain ) const;
52 void Init();
54 tools::Rectangle maRect;
55 bool mbEnabled;
56 OutputDevice& mrParent;
57 tools::Long mnCenterX;
58 tools::Long mnCenterY;
61 /** This control allows to input a rotation angle, visualized by a dial.
63 Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
64 Dragging with the left mouse button sets an exact rotation angle. Pressing
65 the ESCAPE key during mouse drag cancels the operation and restores the old
66 state of the control.
68 It is possible to link a numeric field to this control using the function
69 SetLinkedField(). The DialControl will take full control of this numeric
70 field:
71 - Sets the rotation angle to the numeric field in mouse operations.
72 - Shows the value entered/modified in the numeric field.
73 - Enables/disables/shows/hides the field according to own state changes.
75 class SAL_WARN_UNUSED SVX_DLLPUBLIC DialControl final : public weld::CustomWidgetController
77 public:
78 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
80 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
82 virtual void StyleUpdated() override;
84 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
85 virtual bool MouseMove( const MouseEvent& rMEvt ) override;
86 virtual bool MouseButtonUp( const MouseEvent& rMEvt ) override;
87 virtual bool KeyInput(const KeyEvent& rKEvt) override;
88 virtual void LoseFocus() override;
90 virtual void Resize() override;
92 /** Returns the current rotation angle in 1/100 degrees. */
93 Degree100 GetRotation() const;
94 /** Sets the rotation to the passed value (in 1/100 degrees). */
95 void SetRotation( Degree100 nAngle );
96 /** Returns true, if the control is not in "don't care" state. */
97 bool HasRotation() const;
98 /** Sets the control to "don't care" state. */
99 void SetNoRotation();
101 /** Links the passed numeric edit field to the control (bi-directional).
102 * nDecimalPlaces:
103 * field value is unsign given decimal places
104 * default is 0 which means field values are in degrees,
105 * 2 means 100th of degree
107 void SetLinkedField(weld::MetricSpinButton* pField, sal_Int32 nDecimalPlaces = 0);
109 /** Save value for later comparison */
110 void SaveValue();
112 /** Compare value with the saved value */
113 bool IsValueModified() const;
115 const OUString& GetText() const { return mpImpl->maText; }
116 void SetText(const OUString& rText) { mpImpl->maText = rText; }
118 void SetModifyHdl( const Link<DialControl&,void>& rLink );
120 void Init( const Size& rWinSize );
122 void set_visible(bool bVisible)
124 if (bVisible)
125 Show();
126 else
127 Hide();
129 private:
130 struct SAL_DLLPRIVATE DialControl_Impl
132 ScopedVclPtr<DialControlBmp> mxBmpEnabled;
133 ScopedVclPtr<DialControlBmp> mxBmpDisabled;
134 ScopedVclPtr<DialControlBmp> mxBmpBuffered;
135 Link<DialControl&,void> maModifyHdl;
136 OUString maText;
137 weld::MetricSpinButton* mpLinkField;
138 sal_Int32 mnLinkedFieldValueMultiplyer;
139 Size maWinSize;
140 vcl::Font maWinFont;
141 Degree100 mnAngle;
142 Degree100 mnInitialAngle;
143 Degree100 mnOldAngle;
144 tools::Long mnCenterX;
145 tools::Long mnCenterY;
146 bool mbNoRot;
148 explicit DialControl_Impl(OutputDevice& rReference);
149 void Init( const Size& rWinSize, const vcl::Font& rWinFont );
150 void SetSize( const Size& rWinSize );
152 std::unique_ptr< DialControl_Impl > mpImpl;
154 void HandleMouseEvent( const Point& rPos, bool bInitial );
155 void HandleEscapeEvent();
157 void SetRotation( Degree100 nAngle, bool bBroadcast );
159 void Init( const Size& rWinSize, const vcl::Font& rWinFont );
161 void InvalidateControl();
163 DECL_DLLPRIVATE_LINK(LinkedFieldModifyHdl, weld::MetricSpinButton&, void);
168 #endif
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */