xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
button.h
Go to the documentation of this file.
1
4#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
13namespace xtd {
15 namespace forms {
55 public:
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
125
126 void on_click(const event_args& e) override;
127
128 void on_enabled_changed(const event_args& e) override {
130 button_base::on_enabled_changed(e);
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_);
141 button_base::on_mouse_down(e);
142 }
143
144 void on_mouse_enter(const event_args& e) override {
145 if (flat_style_ != xtd::forms::flat_style::system && enabled()) state_ = (mouse_buttons_ & mouse_buttons::left) == mouse_buttons::left ? xtd::forms::visual_styles::push_button_state::pressed : xtd::forms::visual_styles::push_button_state::hot;
146 button_base::on_mouse_enter(e);
147 }
148
149 void on_mouse_leave(const event_args& e) override {
151 button_base::on_mouse_leave(e);
152 }
153
154 void on_mouse_up(const mouse_event_args& e) override {
155 auto_repeat_timer_.enabled(false);
157 button_base::on_mouse_up(e);
158 }
159
160 void on_paint(paint_event_args& e) override;
161
165 //void wnd_proc(message& message) override;
166
168 forms::dialog_result dialog_result_ = forms::dialog_result::none;
170
171 private:
172 //void wm_click(message& message);
173 //void wm_mouse_up(message& message);
174 bool auto_repeat_ = false;
175 timer auto_repeat_timer_;
176 int32_t auto_repeat_delay_ = 300;
177 int32_t auto_repeat_interval_ = 100;
178 bool default_button_ = false;
180 };
181 }
182}
Contains xtd::forms::button_base class.
Stores an ordered pair of integers, which specify a height and width.
Definition size.h:25
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.h:18
Implements the basic functionality common to button controls.
Definition button_base.h:26
Represents a Windows button control.
Definition button.h:54
void perform_click() override
Generates a click event for the control.
virtual bool auto_repeat() const
Gets if this button instance is auto repeat.
Definition button.h:71
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_paint(paint_event_args &e) override
Raises the control::paint event.
void on_handle_created(const event_args &e) override
Raises the control::handle_created event.
void on_image_changed(const xtd::event_args &e) override
Raises the button_base::image_changed event.
void on_mouse_enter(const event_args &e) override
Raises the control::mouse_enter event.
Definition button.h:144
void on_click(const event_args &e) override
Raises the control::click event.
virtual int32_t auto_repeat_interval() const
Gets the auto repeat interval.
Definition button.h:97
forms::create_params create_params() const override
Gets the required creation parameters when the control handle is created.
virtual button & auto_repeat(bool auto_repeat)
Sets if this button instance is auto repeat.
Definition button.h:75
virtual button & auto_repeat_interval(int32_t auto_repeat_interval)
Gets the auto repeat interval.
Definition button.h:101
virtual button & auto_repeat_delay(int32_t auto_repeat_delay)
Gets the auto repeat delay.
Definition button.h:89
virtual forms::auto_size_mode auto_size_mode() const
Gets the mode by which the button automatically resizes itself.
Definition button.h:109
drawing::size measure_control() const override
Measure this control.
virtual int32_t auto_repeat_delay() const
Gets the auto repeat delay.
Definition button.h:85
virtual button & auto_size_mode(forms::auto_size_mode value)
Sets the mode by which the button automatically resizes itself.
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition button.h:154
void on_mouse_leave(const event_args &e) override
Raises the control::mouse_leave event.
Definition button.h:149
button()
Initializes a new instance of the button class.
Definition button.h:58
void on_mouse_down(const mouse_event_args &e) override
Raises the control::mouse_down event.
Definition button.h:137
void notify_default(bool value) override
Notifies a control that it is the default button so that its appearance and behavior is adjusted acco...
control & dialog_result(forms::dialog_result dialog_result) override
Sets the value returned to the parent form when the button is clicked.
void on_enabled_changed(const event_args &e) override
Raises the control::enabled_changed event.
Definition button.h:128
Defines the base class for controls, which are components with visual representation.
Definition control.h:67
virtual bool enabled() const
Gets a value indicating whether the control can respond to user interaction.
Definition control.h:448
Allows a control to act like a button on a form.
Definition ibutton_control.h:22
Provides data for the xtd::forms::control::mouse_up, xtd::forms::control::mouse_down,...
Definition mouse_event_args.h:29
Provides data for the paint event.
Definition paint_event_args.h:26
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::dialog_result enum class.
Contains xtd::environment class.
#define forms_export_
Define shared library export.
Definition forms_export.h:13
@ e
The E key.
push_button_state
Specifies the visual state of a button that is drawn with visual styles.
Definition push_button_state.h:20
dialog_result
Specifies identifiers to indicate the return value of a dialog box.
Definition dialog_result.h:39
auto_size_mode
Specifies how a control will behave when its auto_size property is enabled.
Definition auto_size_mode.h:18
@ default_state
The button has the default appearance.
@ normal
The button has the normal appearance.
@ system
The appearance of the control is determined by the user's operating system.
Contains xtd::forms::ibutton_control interface.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::forms::visual_styles::push_button_state enum class.
Contains xtd::forms::timer component.