xtd - Reference Guide  0.1.0
Modern c++17 framework to create console, gui and unit test applications on Windows, macOS and Linux.
button.h
1 #pragma once
2 #include <xtd/environment.h>
3 #include "button_base.h"
4 #include "dialog_result.h"
5 #include "ibutton_control.h"
6 #include "timer.h"
7 #include "visual_styles/push_button_state.h"
8 
10 namespace xtd {
12  namespace forms {
22  class button : public ibutton_control, public button_base {
23  public:
26  button() {
27  auto_repeat_timer_.tick += [&] {
28  auto_repeat_timer_.enabled(false);
29  if (enabled()) {
30  perform_click();
31  auto_repeat_timer_.interval(auto_repeat_interval_);
32  auto_repeat_timer_.enabled(auto_repeat_);
33  }
34  };
35  }
36 
37  virtual bool auto_repeat() const {return auto_repeat_;}
38  virtual button& auto_repeat(bool auto_repeat) {
39  if (auto_repeat_ != auto_repeat) {
40  auto_repeat_ = auto_repeat;
41  if (!auto_repeat_) auto_repeat_timer_.enabled(false);
42  }
43  return *this;
44  }
45 
46  virtual int32_t auto_repeat_delay() const {return auto_repeat_delay_;}
47  virtual button& auto_repeat_delay(int32_t auto_repeat_delay) {
48  if (auto_repeat_delay_ != auto_repeat_delay)
49  auto_repeat_delay_ = auto_repeat_delay;
50  return *this;
51  }
52 
53  virtual int32_t auto_repeat_interval() const {return auto_repeat_interval_;}
54  virtual button& auto_repeat_interval(int32_t auto_repeat_interval) {
55  if (auto_repeat_interval_ != auto_repeat_interval)
56  auto_repeat_interval_ = auto_repeat_interval;
57  return *this;
58  }
59 
62  virtual forms::auto_size_mode auto_size_mode() const {return auto_size_mode_;}
66 
70  forms::dialog_result dialog_result() const override {return dialog_result_;}
75 
79  void notify_default(bool value) override;
80 
83  void perform_click() override;
84 
88  drawing::size measure_control() const override;
89 
90  protected:
94  forms::create_params create_params() const override;
95 
98  void on_click(const event_args& e) override;
99 
100  void on_enabled_changed(const event_args& e) override {
102  button_base::on_enabled_changed(e);
103  }
104 
105  void on_handle_created(const event_args& e) override;
106 
107  void on_image_changed(const xtd::event_args& e) override;
108 
109  void on_mouse_down(const mouse_event_args& e) override {
110  auto_repeat_timer_.interval(auto_repeat_delay_);
111  auto_repeat_timer_.enabled(auto_repeat_);
113  button_base::on_mouse_down(e);
114  }
115 
116  void on_mouse_enter(const event_args& e) override {
118  button_base::on_mouse_enter(e);
119  }
120 
121  void on_mouse_leave(const event_args& e) override {
123  button_base::on_mouse_leave(e);
124  }
125 
126  void on_mouse_up(const mouse_event_args& e) override {
127  auto_repeat_timer_.enabled(false);
129  button_base::on_mouse_up(e);
130  }
131 
132  void on_paint(paint_event_args& e) override;
133 
137  //void wnd_proc(message& message) override;
138 
142 
143  private:
144  //void wm_click(message& message);
145  //void wm_mouse_up(message& message);
146  bool auto_repeat_ = false;
147  timer auto_repeat_timer_;
148  int32_t auto_repeat_delay_ = 300;
149  int32_t auto_repeat_interval_ = 100;
150  bool default_button_ = false;
152  };
153  }
154 }
The button has the normal appearance.
void perform_click() override
Generates a click event for the control.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:8
forms::dialog_result dialog_result() const override
Gets the value returned to the parent form when the button is clicked.
Definition: button.h:70
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:15
Implements the basic functionality common to button controls.
Definition: button_base.h:17
Nothing is returned from the dialog box. This means that the modal dialog continues running...
forms::create_params create_params() const override
Gets a create_params on the base class when creating a window.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: action.h:6
Definition: timer.h:12
The appearance of the control is determined by the user&#39;s operating system.
virtual forms::auto_size_mode auto_size_mode() const
Gets the mode by which the button automatically resizes itself.
Definition: button.h:62
Definition: paint_event_args.h:15
dialog_result
Specifies identifiers to indicate the return value of a dialog box.
Definition: dialog_result.h:31
push_button_state
Specifies the visual state of a button that is drawn with visual styles.
Definition: push_button_state.h:12
void on_click(const event_args &e) override
Raises the Click event.
void notify_default(bool value) override
Notifies a control that it is the default button so that its appearance and behavior is adjusted acco...
Defines the base class for controls, which are components with visual representation.
Definition: control.h:60
auto_size_mode
Specifies how a control will behave when its auto_size property is enabled.
Definition: auto_size_mode.h:10
Contains xtd::environment class.
Definition: mouse_event_args.h:20
drawing::size measure_control() const override
Measure this control.
Represents a Windows button control.
Definition: button.h:22
The left mouse button was pressed.
Allows a control to act like a button on a form.
Definition: ibutton_control.h:14
button()
Initializes a new instance of the button class.
Definition: button.h:26