xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
toggle_button.h
Go to the documentation of this file.
1 #pragma once
5 #include "button_base.h"
6 #include "check_state.h"
8 
10 namespace xtd {
12  namespace forms {
30  class forms_export_ toggle_button : public button_base {
31  public:
34  toggle_button();
35 
39  virtual bool auto_check() const {return auto_check_;}
43  virtual toggle_button& auto_check(bool auto_check);
44 
47  virtual content_alignment check_align() const {return check_align_;}
50  virtual toggle_button& check_align(content_alignment check_align);
51 
55  virtual bool checked() const {return checked_;}
59  virtual toggle_button& checked(bool checked);
60 
70  virtual forms::check_state check_state() const {return check_state_;}
80 
83  drawing::size default_size() const override {return {104, 25};}
84 
88  virtual bool three_state() const {return three_state_;}
92  virtual toggle_button& three_state(bool three_state);
93 
97 
101 
102  protected:
105  forms::create_params create_params() const override;
106 
110  drawing::size measure_control() const override;
111 
116  virtual void on_checked_changed(const event_args& e) {
117  if (flat_style() != xtd::forms::flat_style::system && enabled()) {
121  }
122  checked_changed(*this, e);
123  if (flat_style() != xtd::forms::flat_style::system) invalidate();
124  }
125 
130  virtual void on_check_state_changed(const event_args& e) {
131  if (flat_style() != xtd::forms::flat_style::system && enabled()) {
135  }
136  check_state_changed(*this, e);
137  if (flat_style() != xtd::forms::flat_style::system) invalidate();
138  }
139 
140  void on_enabled_changed(const event_args& e) override {
145  }
147  }
148 
151  void on_handle_created(const event_args& e) override;
152 
153  void on_mouse_down(const mouse_event_args& e) override {
154  if (flat_style() != xtd::forms::flat_style::system && enabled()) {
158  }
160  }
161 
162  void on_mouse_enter(const event_args& e) override {
163  if (flat_style() != xtd::forms::flat_style::system && enabled()) {
167  }
169  }
170 
171  void on_mouse_leave(const event_args& e) override {
172  if (flat_style() != xtd::forms::flat_style::system && enabled()) {
176  }
178  }
179 
180  void on_mouse_up(const mouse_event_args& e) override {
185  }
187  }
188 
189  void on_paint(paint_event_args& e) override;
190 
193  xtd::forms::visual_styles::toggle_button_state state() const noexcept {return state_;}
194 
196  void wnd_proc(message& message) override;
197  virtual void wm_mouse_double_click(message& message);
198  virtual void wm_mouse_down(message& message);
199  virtual void wm_mouse_up(message& message);
200 
201  bool auto_check_ = true;
202  bool three_state_ = 0;
203  bool checked_ = false;
208  };
209  }
210 }
check_state
Specifies the state of a control, such as a check box, that can be checked, unchecked, or set to an indeterminate state.
Definition: check_state.h:19
The control is unchecked.
flat_style
Specifies the appearance of a control.
Definition: flat_style.h:20
Contains xtd::forms::button_base class.
mouse_buttons
Specifies constants that define which mouse button was pressed. This enumeration has a flag attribute...
Definition: mouse_buttons.h:18
xtd::forms::visual_styles::toggle_button_state state() const noexcept
Get state.
Definition: toggle_button.h:193
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
void on_mouse_enter(const event_args &e) override
Raises the control::mouse_enter event.
Definition: button_base.h:166
The button has a checked or latched appearance. Use this appearance to show that a toggle button has ...
virtual void on_check_state_changed(const event_args &e)
Raises the toggle_button::check_state_changed event.
Definition: toggle_button.h:130
Contains xtd::forms::check_state enum class.
toggle_button_state
Specifies the visual state of a check box that is drawn with visual styles.
Definition: toggle_button_state.h:20
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
Implements the basic functionality common to button controls.
Definition: button_base.h:26
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
The control is checked.
event< toggle_button, event_handler > checked_changed
Occurs when the value of the checked property changes.
Definition: toggle_button.h:96
virtual void on_checked_changed(const event_args &e)
Raises the toggle_button::checked_changed event.
Definition: toggle_button.h:116
Contains xtd::forms::visual_styles::toggle_button_state enum class.
The check box is three-state and disabled.
void on_mouse_enter(const event_args &e) override
Raises the control::mouse_enter event.
Definition: toggle_button.h:162
The appearance of the control is determined by the user&#39;s operating system.
event< toggle_button, event_handler > check_state_changed
Occurs when the value of the check_state property changes.
Definition: toggle_button.h:100
Represents an event.
Definition: event.h:21
Provides data for the paint event.
Definition: paint_event_args.h:27
content_alignment
Specifies alignment of content on the drawing surface.
Definition: content_alignment.h:17
void on_enabled_changed(const event_args &e) override
Raises the control::enabled_changed event.
Definition: button_base.h:139
void on_mouse_down(const mouse_event_args &e) override
Raises the control::mouse_down event.
Definition: toggle_button.h:153
void on_enabled_changed(const event_args &e) override
Raises the control::enabled_changed event.
Definition: toggle_button.h:140
The control is indeterminate. An indeterminate control generally has a shaded appearance.
The check box is three-state and pressed.
virtual content_alignment check_align() const
Gets the horizontal and vertical alignment of the check mark on a toggle_button control.
Definition: toggle_button.h:47
Implements a Windows message.
Definition: message.h:25
void on_mouse_leave(const event_args &e) override
Raises the control::mouse_leave event.
Definition: toggle_button.h:171
Content is vertically aligned in the middle, and horizontally aligned on the left.
virtual forms::check_state check_state() const
Gets the state of the toggle_button.
Definition: toggle_button.h:70
Provides data for the xtd::forms::control::mouse_up, xtd::forms::control::mouse_down, and xtd::forms::control::mouse_move events.
Definition: mouse_event_args.h:29
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition: toggle_button.h:180
virtual bool auto_check() const
Gets a value indicating whether the checked or check_state values and the toggle_button&#39;s appearance ...
Definition: toggle_button.h:39
virtual bool three_state() const
Gets a value indicating whether the toggle_button will allow three check states rather than two...
Definition: toggle_button.h:88
The left mouse button was pressed.
drawing::size default_size() const override
Gets the default size of the control.
Definition: toggle_button.h:83
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition: button_base.h:176
void on_mouse_leave(const event_args &e) override
Raises the control::mouse_leave event.
Definition: button_base.h:171
virtual bool checked() const
Gets a value indicating whether the toggle_button is in the checked state.
Definition: toggle_button.h:55
Represents a Windows toggle_button.
Definition: toggle_button.h:30
The check box is three-state and hot.
void on_mouse_down(const mouse_event_args &e) override
Raises the control::mouse_down event.
Definition: button_base.h:161