LibreOffice Module vcl (master)  1
toolkit/button.hxx
Go to the documentation of this file.
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 #pragma once
20 
21 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
22 #error "don't use this in new code"
23 #endif
24 
25 #include <vcl/button.hxx>
26 
27 class VCL_DLLPUBLIC OKButton final : public PushButton
28 {
29 private:
31 
32  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
33 
34  OKButton (const OKButton &) = delete;
35  OKButton & operator= (const OKButton &) = delete;
36 
37 public:
38  explicit OKButton( vcl::Window* pParent, WinBits nStyle = WB_DEFBUTTON );
39 
40  virtual void Click() override;
41 };
42 
44 {
45 protected:
47 private:
48  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
49 
50  CancelButton (const CancelButton &) = delete;
51  CancelButton & operator= (const CancelButton &) = delete;
52 
53 public:
54  explicit CancelButton( vcl::Window* pParent, WinBits nStyle = 0 );
55 
56  virtual void Click() override;
57 };
58 
59 class CloseButton final : public CancelButton
60 {
61 public:
62  explicit CloseButton(vcl::Window* pParent, WinBits nStyle = 0);
63 };
64 
65 class VCL_DLLPUBLIC HelpButton final : public PushButton
66 {
67 private:
69  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
70 
71  HelpButton( const HelpButton & ) = delete;
72  HelpButton & operator= ( const HelpButton & ) = delete;
73 
74  virtual void StateChanged( StateChangedType nStateChange ) override;
75 
76 public:
77  explicit HelpButton( vcl::Window* pParent, WinBits nStyle = 0 );
78 
79  virtual void Click() override;
80 };
81 
83 {
84 private:
88  bool mbTriState;
90  SAL_DLLPRIVATE void ImplInitCheckBoxData();
91  SAL_DLLPRIVATE static WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle );
92  SAL_DLLPRIVATE void ImplInitSettings( bool bBackground );
93  SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags,
94  const Point& rPos, const Size& rSize,
95  const Size& rImageSize, tools::Rectangle& rStateRect,
96  tools::Rectangle& rMouseRect );
97  SAL_DLLPRIVATE void ImplDrawCheckBox(vcl::RenderContext& rRenderContext );
98  SAL_DLLPRIVATE tools::Long ImplGetImageToTextDistance() const;
99  SAL_DLLPRIVATE Size ImplGetCheckImageSize() const;
100 
101  CheckBox(const CheckBox &) = delete;
102  CheckBox& operator= (const CheckBox &) = delete;
103 
104 protected:
106  using Window::ImplInit;
107  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
108  virtual void FillLayoutData() const override;
109  virtual const vcl::Font& GetCanonicalFont( const StyleSettings& _rStyle ) const override;
110  virtual const Color& GetCanonicalTextColor( const StyleSettings& _rStyle ) const override;
111  void ImplAdjustNWFSizes() override;
112 
113  virtual void ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext);
114  SAL_DLLPRIVATE const tools::Rectangle& GetStateRect() const { return maStateRect; }
115  SAL_DLLPRIVATE const tools::Rectangle& GetMouseRect() const { return maMouseRect; }
116 
117 public:
118  SAL_DLLPRIVATE void ImplCheck();
119 public:
120  explicit CheckBox( vcl::Window* pParent, WinBits nStyle = 0 );
121 
122  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
123  virtual void Tracking( const TrackingEvent& rTEvt ) override;
124  virtual void KeyInput( const KeyEvent& rKEvt ) override;
125  virtual void KeyUp( const KeyEvent& rKEvt ) override;
126  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
127  virtual void Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags ) override;
128  virtual void Resize() override;
129  virtual void GetFocus() override;
130  virtual void LoseFocus() override;
131  virtual void StateChanged( StateChangedType nType ) override;
132  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
133  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
134 
135  void Toggle();
136 
137  void SetState( TriState eState );
138  TriState GetState() const { return meState; }
139 
140  void Check( bool bCheck = true )
141  {
142  SetState( bCheck ? TRISTATE_TRUE : TRISTATE_FALSE );
143  }
144 
145  bool IsChecked() const
146  {
147  return (GetState() == TRISTATE_TRUE);
148  }
149 
150  void EnableTriState( bool bTriState = true );
151  bool IsTriStateEnabled() const { return mbTriState; }
152 
153  static Image GetCheckImage( const AllSettings& rSettings, DrawButtonFlags nFlags );
154 
155  Size CalcMinimumSize( tools::Long nMaxWidth = 0 ) const;
156  virtual Size GetOptimalSize() const override;
157 
158  void SetToggleHdl( const Link<CheckBox&,void>& rLink ) { maToggleHdl = rLink; }
159 
160  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
161  virtual void ShowFocus(const tools::Rectangle& rRect) override;
162 
164  void DumpAsPropertyTree(tools::JsonWriter&) override;
165 
166  virtual FactoryFunction GetUITestFactory() const override;
167 };
168 
170 {
171 private:
172  friend class VclBuilder;
173 
174  std::shared_ptr< std::vector< VclPtr< RadioButton > > > m_xGroup;
178  bool mbChecked;
183  SAL_DLLPRIVATE void ImplInitRadioButtonData();
184  SAL_DLLPRIVATE WinBits ImplInitStyle( const vcl::Window* pPrevWindow, WinBits nStyle );
185  SAL_DLLPRIVATE void ImplInitSettings( bool bBackground );
186  SAL_DLLPRIVATE void ImplDrawRadioButtonState(vcl::RenderContext& rRenderContext);
187  SAL_DLLPRIVATE void ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags,
188  const Point& rPos, const Size& rSize,
189  const Size& rImageSize, tools::Rectangle& rStateRect,
190  tools::Rectangle& rMouseRect );
191  SAL_DLLPRIVATE void ImplDrawRadioButton(vcl::RenderContext& rRenderContext );
192  SAL_DLLPRIVATE void ImplUncheckAllOther();
193  SAL_DLLPRIVATE Size ImplGetRadioImageSize() const;
194  SAL_DLLPRIVATE tools::Long ImplGetImageToTextDistance() const;
195 
196  RadioButton(const RadioButton &) = delete;
197  RadioButton& operator= (const RadioButton &) = delete;
198 
199 protected:
201  using Window::ImplInit;
202  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
203 
204 public:
205  SAL_DLLPRIVATE void ImplCallClick( bool bGrabFocus = false, GetFocusFlags nFocusFlags = GetFocusFlags::NONE );
206 
207 protected:
208  virtual void FillLayoutData() const override;
209  virtual const vcl::Font&
210  GetCanonicalFont( const StyleSettings& _rStyle ) const override;
211  virtual const Color&
212  GetCanonicalTextColor( const StyleSettings& _rStyle ) const override;
213  void ImplAdjustNWFSizes() override;
214 
215 public:
216  /*
217  bUsesExplicitGroup of true means that group() is used to set what radiobuttons are part of a group
218  while false means that contiguous radiobuttons are considered part of a group where WB_GROUP designates
219  the start of the group and all contiguous radiobuttons without WB_GROUP set form the rest of the group.
220 
221  true is fairly straightforward, false leads to trick situations and is the legacy case
222  */
223  explicit RadioButton(vcl::Window* pParent, bool bUsesExplicitGroup = true, WinBits nWinStyle = 0);
224  virtual ~RadioButton() override;
225  virtual void dispose() override;
226 
227  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
228  virtual void Tracking( const TrackingEvent& rTEvt ) override;
229  virtual void KeyInput( const KeyEvent& rKEvt ) override;
230  virtual void KeyUp( const KeyEvent& rKEvt ) override;
231  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
232  virtual void Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags ) override;
233  virtual void Resize() override;
234  virtual void GetFocus() override;
235  virtual void LoseFocus() override;
236  virtual void StateChanged( StateChangedType nType ) override;
237  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
238  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
239 
240  void Toggle();
241 
242  bool IsStateChanged() const { return mbStateChanged; }
243 
244  void EnableRadioCheck( bool bRadioCheck ) { mbRadioCheck = bRadioCheck; }
245  bool IsRadioCheckEnabled() const { return mbRadioCheck; }
246 
247  void SetModeRadioImage( const Image& rImage );
248 
249  void SetState( bool bCheck );
250  void Check( bool bCheck = true );
251  bool IsChecked() const { return mbChecked; }
252 
253  static Image GetRadioImage( const AllSettings& rSettings, DrawButtonFlags nFlags );
254 
255  Size CalcMinimumSize( tools::Long nMaxWidth = 0 ) const;
256  virtual Size GetOptimalSize() const override;
257 
258  void SetToggleHdl( const Link<RadioButton&,void>& rLink ) { maToggleHdl = rLink; }
259 
273  std::vector<VclPtr<RadioButton> > GetRadioButtonGroup(bool bIncludeThis = true) const;
274 
275  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
276 
277  /*
278  * Group this RadioButton with another
279  */
280  void group(RadioButton &rOther);
281  virtual void ShowFocus(const tools::Rectangle& rRect) override;
282 
284  void DumpAsPropertyTree(tools::JsonWriter&) override;
285 
286  virtual FactoryFunction GetUITestFactory() const override;
287 };
288 
290 {
291 private:
293 
294  SAL_DLLPRIVATE void ImplInitStyle();
295 
296  ImageButton( const ImageButton & ) = delete;
297  ImageButton & operator= ( const ImageButton & ) = delete;
298 
299 public:
300  ImageButton( vcl::Window* pParent, WinBits nStyle = 0 );
301 };
302 
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< std::vector< VclPtr< RadioButton > > > m_xGroup
void EnableRadioCheck(bool bRadioCheck)
tools::Rectangle maStateRect
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:414
virtual void ImplAdjustNWFSizes()
Definition: window3.cxx:35
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
tools::Rectangle maStateRect
long Long
Link< CheckBox &, void > maToggleHdl
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
SAL_DLLPRIVATE const tools::Rectangle & GetStateRect() const
bool IsRadioCheckEnabled() const
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
tools::Rectangle maMouseRect
DrawButtonFlags
Definition: decoview.hxx:53
virtual bool set_property(const OString &rKey, const OUString &rValue) override
Definition: button.cxx:518
virtual const Color & GetCanonicalTextColor(const StyleSettings &_rStyle) const
Definition: ctrl.cxx:413
TRISTATE_TRUE
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: button.cxx:106
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: button.cxx:590
bool IsStateChanged() const
StateChangedType
Definition: window.hxx:317
sal_Int64 WinBits
WinBits const WB_DEFBUTTON
Link< RadioButton &, void > maToggleHdl
Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, sidebar, etc.
Definition: builder.hxx:65
virtual void Tracking(const TrackingEvent &rTEvt)
Definition: window.cxx:1931
bool IsChecked() const
virtual void Click()
Definition: button.cxx:122
TriState GetState() const
PushButton & operator=(const PushButton &)=delete
GetFocusFlags
Definition: window.hxx:339
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
DrawFlags
Definition: window.hxx:360
bool IsTriStateEnabled() const
virtual FactoryFunction GetUITestFactory() const override
Definition: button.cxx:551
TRISTATE_FALSE
CloseButton(vcl::Window *pParent, WinBits nStyle=0)
Definition: button.cxx:1728
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
bool IsChecked() const
virtual void Draw(::OutputDevice *pDev, const Point &rPos, DrawFlags nFlags)
Definition: window.cxx:1828
void SetToggleHdl(const Link< CheckBox &, void > &rLink)
Button & operator=(const Button &)=delete
TriState meState
static SAL_DLLPRIVATE WinBits ImplInitStyle(const vcl::Window *pPrevWindow, WinBits nStyle)
Definition: button.cxx:601
void Check(bool bCheck=true)
virtual void LoseFocus()
Definition: window.cxx:1854
bool mbUsesExplicitGroup
virtual void ShowFocus(const tools::Rectangle &rRect)
Definition: window2.cxx:49
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1804
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:937
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
virtual void StateChanged(StateChangedType nType) override
Definition: button.cxx:1363
virtual void Resize() override
Definition: ctrl.cxx:74
virtual void GetFocus()
Definition: window.cxx:1840
virtual const vcl::Font & GetCanonicalFont(const StyleSettings &_rStyle) const
Definition: ctrl.cxx:408
virtual void DumpAsPropertyTree(tools::JsonWriter &) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: button.cxx:556
Definition: image.hxx:39
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1021
virtual void KeyUp(const KeyEvent &rKEvt)
Definition: window.cxx:1821
SAL_DLLPRIVATE const tools::Rectangle & GetMouseRect() const
void ImplInitSettings()
Definition: ctrl.cxx:428
tools::Rectangle maMouseRect
TriState
void SetToggleHdl(const Link< RadioButton &, void > &rLink)
tuple group
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35