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.
button.h
Go to the documentation of this file.
1 #pragma once
5 #include <xtd/environment.h>
6 #include "button_base.h"
7 #include "dialog_result.h"
8 #include "ibutton_control.h"
9 #include "timer.h"
11 
13 namespace xtd {
15  namespace forms {
54  class forms_export_ button : public ibutton_control, public button_base {
55  public:
58  button() {
59  auto_repeat_timer_.tick += [&] {
60  auto_repeat_timer_.enabled(false);
61  if (enabled()) {
62  perform_click();
63  auto_repeat_timer_.interval_milliseconds(auto_repeat_interval_);
64  auto_repeat_timer_.enabled(auto_repeat_);
65  }
66  };
67  }
68 
71  virtual bool auto_repeat() const {return auto_repeat_;}
75  virtual button& auto_repeat(bool auto_repeat) {
76  if (auto_repeat_ != auto_repeat) {
77  auto_repeat_ = auto_repeat;
78  if (!auto_repeat_) auto_repeat_timer_.enabled(false);
79  }
80  return *this;
81  }
82 
85  virtual int32_t auto_repeat_delay() const {return auto_repeat_delay_;}
89  virtual button& auto_repeat_delay(int32_t auto_repeat_delay) {
90  if (auto_repeat_delay_ != auto_repeat_delay)
91  auto_repeat_delay_ = auto_repeat_delay;
92  return *this;
93  }
94 
97  virtual int32_t auto_repeat_interval() const {return auto_repeat_interval_;}
101  virtual button& auto_repeat_interval(int32_t auto_repeat_interval) {
102  if (auto_repeat_interval_ != auto_repeat_interval)
103  auto_repeat_interval_ = auto_repeat_interval;
104  return *this;
105  }
106 
109  virtual forms::auto_size_mode auto_size_mode() const {return auto_size_mode_;}
113 
114  forms::dialog_result dialog_result() const override {return dialog_result_;}
116 
117  void notify_default(bool value) override;
118 
119  void perform_click() override;
120 
121  protected:
122  forms::create_params create_params() const override;
123 
124  drawing::size measure_control() const override;
125 
126  void on_click(const event_args& e) override;
127 
128  void on_enabled_changed(const event_args& e) override {
131  }
132 
133  void on_handle_created(const event_args& e) override;
134 
135  void on_image_changed(const xtd::event_args& e) override;
136 
137  void on_mouse_down(const mouse_event_args& e) override {
138  auto_repeat_timer_.interval_milliseconds(auto_repeat_delay_);
139  auto_repeat_timer_.enabled(auto_repeat_);
142  }
143 
144  void on_mouse_enter(const event_args& e) override {
147  }
148 
149  void on_mouse_leave(const event_args& e) override {
152  }
153 
154  void on_mouse_up(const mouse_event_args& e) override {
155  auto_repeat_timer_.enabled(false);
158  }
159 
160  void on_paint(paint_event_args& e) override;
161 
165  //void wnd_proc(message& message) override;
166 
170 
173  xtd::forms::visual_styles::push_button_state state() const noexcept {return state_;}
174 
175  private:
176  //void wm_click(message& message);
177  //void wm_mouse_up(message& message);
178  bool auto_repeat_ = false;
179  timer auto_repeat_timer_;
180  int32_t auto_repeat_delay_ = 300;
181  int32_t auto_repeat_interval_ = 100;
182  bool default_button_ = false;
184  };
185  }
186 }
forms::dialog_result dialog_result() const override
Gets the value returned to the parent form when the button is clicked.
Definition: button.h:114
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition: button.h:154
virtual bool enabled() const
Gets a value indicating whether the control can respond to user interaction.
Definition: control.h:472
dialog_result
Specifies identifiers to indicate the return value of a dialog box.
Definition: dialog_result.h:39
Nothing is returned from the dialog box. This means that the modal dialog continues running...
Contains xtd::forms::button_base class.
void on_enabled_changed(const event_args &e) override
Raises the control::enabled_changed event.
Definition: button.h:128
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
virtual button & auto_repeat_delay(int32_t auto_repeat_delay)
Gets the auto repeat delay.
Definition: button.h:89
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
void on_mouse_leave(const event_args &e) override
Raises the control::mouse_leave event.
Definition: button.h:149
void on_mouse_down(const mouse_event_args &e) override
Raises the control::mouse_down event.
Definition: button.h:137
auto_size_mode
Specifies how a control will behave when its auto_size property is enabled.
Definition: auto_size_mode.h:18
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition: timer.h:29
Contains xtd::forms::timer component.
virtual forms::auto_size_mode auto_size_mode() const
Gets the mode by which the button automatically resizes itself.
Definition: button.h:109
Contains xtd::forms::visual_styles::push_button_state enum class.
The appearance of the control is determined by the user&#39;s operating system.
xtd::forms::visual_styles::push_button_state state() const noexcept
Processes Windows messages.
Definition: button.h:173
Provides data for the paint event.
Definition: paint_event_args.h:26
void on_enabled_changed(const event_args &e) override
Raises the control::enabled_changed event.
Definition: button_base.h:139
Contains xtd::forms::dialog_result enum class.
virtual bool auto_repeat() const
Gets if this button instance is auto repeat.
Definition: button.h:71
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
void on_mouse_enter(const event_args &e) override
Raises the control::mouse_enter event.
Definition: button.h:144
virtual int32_t auto_repeat_delay() const
Gets the auto repeat delay.
Definition: button.h:85
Contains xtd::environment class.
virtual int32_t auto_repeat_interval() const
Gets the auto repeat interval.
Definition: button.h:97
push_button_state
Specifies the visual state of a button that is drawn with visual styles.
Definition: push_button_state.h:20
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
Contains xtd::forms::ibutton_control interface.
The left mouse button was pressed.
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition: button_base.h:176
Represents a Windows button control.
Definition: button.h:54
Allows a control to act like a button on a form.
Definition: ibutton_control.h:22
button()
Initializes a new instance of the button class.
Definition: button.h:58
virtual button & auto_repeat(bool auto_repeat)
Sets if this button instance is auto repeat.
Definition: button.h:75
void on_mouse_leave(const event_args &e) override
Raises the control::mouse_leave event.
Definition: button_base.h:171
void on_mouse_down(const mouse_event_args &e) override
Raises the control::mouse_down event.
Definition: button_base.h:161
The button has the normal appearance.
virtual button & auto_repeat_interval(int32_t auto_repeat_interval)
Gets the auto repeat interval.
Definition: button.h:101