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_base.h
Go to the documentation of this file.
1 #pragma once
5 #include <xtd/drawing/image.h>
6 #include "control.h"
7 #include "content_alignment.h"
8 #include "image_list.h"
10 #include "flat_style.h"
11 #include "text_format_flags.h"
12 
14 namespace xtd {
16  namespace forms {
26  class forms_export_ button_base : public control {
27  public:
31  bool auto_ellipsis() const {return data_->auto_ellipsis;}
32 
36  virtual button_base& auto_ellipsis(bool auto_ellipsis) {
37  if (data_->auto_ellipsis != auto_ellipsis)
38  data_->auto_ellipsis = auto_ellipsis;
39  return *this;
40  }
41 
42  bool auto_size() const override {return control::auto_size();}
43  control& auto_size(bool auto_size) override {
44  control::auto_size(auto_size);
45  if (get_state(state::auto_size))
46  data_->auto_ellipsis = false;
47  return *this;
48  }
49 
52  const xtd::forms::flat_button_appearance& flat_appearance() const {return data_->flat_appearance;}
55  xtd::forms::flat_button_appearance& flat_appearance() {return data_->flat_appearance;}
56 
59  virtual xtd::forms::flat_style flat_style() const {return data_->flat_style;}
63 
68  virtual const drawing::image& image() const {return data_->image;}
73  virtual button_base& image(const drawing::image& value);
74 
77  virtual content_alignment image_align() const {return data_->image_align;}
80  virtual button_base& image_align(content_alignment value);
81 
87  virtual int32_t image_index() const {return data_->image_index;}
93  virtual button_base& image_index(int32_t value);
94 
97  virtual const forms::image_list& image_list() const {return data_->image_list;}
100  virtual forms::image_list& image_list() {return data_->image_list;}
103  virtual button_base& image_list(const forms::image_list& value);
104 
107  virtual content_alignment text_align() const {return data_->text_align;}
110  virtual button_base& text_align(content_alignment value);
111 
116 
117  protected:
119  button_base();
120 
123  forms::create_params create_params() const override;
124 
127  drawing::size default_size() const override {return {75, 25};}
128 
132  drawing::size measure_control() const override;
133 
134  void on_back_color_changed(const event_args& e) override {
135  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
137  }
138 
139  void on_enabled_changed(const event_args& e) override {
140  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
142  }
143 
144  void on_font_changed(const xtd::event_args& e) override {
145  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
147  }
148 
149  void on_fore_color_changed(const event_args& e) override {
150  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
152  }
153 
156  virtual void on_image_changed(const xtd::event_args& e) {
157  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
158  if (can_raise_events()) image_changed(*this, e);
159  }
160 
161  void on_mouse_down(const mouse_event_args& e) override {
162  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
164  }
165 
166  void on_mouse_enter(const event_args& e) override {
167  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
169  }
170 
171  void on_mouse_leave(const event_args& e) override {
172  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
174  }
175 
176  void on_mouse_up(const mouse_event_args& e) override {
177  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
179  }
180 
181  void on_parent_back_color_changed(const event_args& e) override {
182  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
184  }
185 
186  void on_parent_fore_color_changed(const event_args& e) override {
187  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
189  }
190 
191  void on_resize(const xtd::event_args& e) override {
192  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
194  }
195 
196  void on_text_changed(const xtd::event_args& e) override {
197  if (data_->flat_style != xtd::forms::flat_style::system) invalidate();
199  }
200 
202  text_format_flags to_text_format_flags(content_alignment text_align);
203  xtd::drawing::rectangle compute_image_bounds() {return compute_image_bounds({0, 0, width(), height()});}
204  xtd::drawing::rectangle compute_image_bounds(const xtd::drawing::rectangle& rectangle);
206 
207  private:
208  struct data {
209  bool auto_ellipsis = false;
210  xtd::forms::flat_button_appearance flat_appearance;
212  xtd::drawing::image image = xtd::drawing::image::empty;
214  int32_t image_index = -1;
217  };
218  std::shared_ptr<data> data_ = std::make_shared<data>();
219  };
220  }
221 }
void on_parent_back_color_changed(const event_args &e) override
Raises the control::parent_back_color_changed event.
Definition: button_base.h:181
virtual void on_image_changed(const xtd::event_args &e)
Raises the button_base::image_changed event.
Definition: button_base.h:156
flat_style
Specifies the appearance of a control.
Definition: flat_style.h:20
Provides methods to manage a collection of xtd::drawing::image objects. This class cannot be inherite...
Definition: image_list.h:25
virtual void on_text_changed(const event_args &e)
Raises the control::text_changed event.
virtual void on_mouse_down(const mouse_event_args &e)
Raises the control::mouse_down event.
void on_resize(const xtd::event_args &e) override
Raises the control::resize event.
Definition: button_base.h:191
drawing::size default_size() const override
Gets the default size of the control.
Definition: button_base.h:127
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
const xtd::forms::flat_button_appearance & flat_appearance() const
Gets the appearance of the border and the colors used to indicate check state and mouse state...
Definition: button_base.h:52
void on_mouse_enter(const event_args &e) override
Raises the control::mouse_enter event.
Definition: button_base.h:166
The picture_box is sized equal to the size of the image that it contains.
virtual int32_t image_index() const
Gets the image list index value of the image displayed on the button control.
Definition: button_base.h:87
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_back_color_changed(const event_args &e) override
Raises the control::back_color_changed event.
Definition: button_base.h:134
Contains xtd::forms::text_format_flags enum class.
virtual const forms::image_list & image_list() const
Gets the image_list that contains the image displayed on a button control.
Definition: button_base.h:97
virtual const drawing::image & image() const
Gets the image that is displayed on a button control.
Definition: button_base.h:68
virtual void on_font_changed(const event_args &e)
Raises the control::font_changed event.
The appearance of the control is determined by the user&#39;s operating system.
virtual bool auto_size() const
Gets a value that indicates whether the control resizes based on its contents.
Contains xtd::drawing::image class.
void on_parent_fore_color_changed(const event_args &e) override
Raises the control::parent_fore_color_changed event.
Definition: button_base.h:186
virtual void on_fore_color_changed(const event_args &e)
Raises the control::fore_color_changed event.
virtual xtd::forms::flat_style flat_style() const
Gets the flat style appearance of the button control.
Definition: button_base.h:59
Specifies that the height of the control is defined.
Contains xtd::forms::flat_button_appearance class.
virtual void on_mouse_up(const mouse_event_args &e)
Raises the control::mouse_up event.
virtual content_alignment image_align() const
Gets the alignment of the image on the button control.
Definition: button_base.h:77
control & auto_size(bool auto_size) override
Sets a value that indicates whether the control resizes based on its contents.
Definition: button_base.h:43
Represents an event.
Definition: event.h:21
virtual void on_mouse_leave(const event_args &e)
Raises the control::mouse_leave event.
bool auto_ellipsis() const
Gets a value indicating whether the ellipsis character (...) appears at the right edge of the control...
Definition: button_base.h:31
virtual void on_parent_back_color_changed(const event_args &e)
Raises the control::parent_back_color_changed event.
virtual forms::image_list & image_list()
Gets the image_list that contains the image displayed on a button control.
Definition: button_base.h:100
virtual void on_parent_fore_color_changed(const event_args &e)
Raises the control::parent_fore_color_changed event.
Contains xtd::forms::image_list component.
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_font_changed(const xtd::event_args &e) override
Raises the control::font_changed event.
Definition: button_base.h:144
Specifies that the width of the control is defined.
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
Standard style dialog.
virtual content_alignment text_align() const
Gets the alignment of the text on the button control.
Definition: button_base.h:107
static image_list empty
Represents an image_list empty.
Definition: image_list.h:78
virtual void on_enabled_changed(const event_args &e)
Raises the control::enabled_changed event.
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:34
Contains xtd::forms::content_alignment enum class.
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
Contains xtd::forms::flat_style enum class.
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
Contains xtd::forms::control control.
virtual void on_mouse_enter(const event_args &e)
Raises the control::mouse_enter event.
void on_fore_color_changed(const event_args &e) override
Raises the control::fore_color_changed event.
Definition: button_base.h:149
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
xtd::forms::flat_button_appearance & flat_appearance()
Gets the appearance of the border and the colors used to indicate check state and mouse state...
Definition: button_base.h:55
Provides properties that specify the appearance of xtd::forms::button controls whose xtd::forms::flat...
Definition: flat_button_appearance.h:20
virtual void on_resize(const event_args &e)
Raises the control::resize event.
Content is vertically aligned at the middle, and horizontally aligned at the center.
text_format_flags
Specifies the display and layout information for text strings.
Definition: text_format_flags.h:18
image_list()
Initialize a new instance ao image_list class.
bool auto_size() const override
Gets a value that indicates whether the control resizes based on its contents.
Definition: button_base.h:42
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition: button_base.h:176
virtual button_base & auto_ellipsis(bool auto_ellipsis)
Sets a value indicating whether the ellipsis character (...) appears at the right edge of the control...
Definition: button_base.h:36
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
void on_text_changed(const xtd::event_args &e) override
Raises the control::text_changed event.
Definition: button_base.h:196
event< button_base, event_handler > image_changed
Occurs when the value of the image property changes.
Definition: button_base.h:115