xtd.forms - Reference Guide  0.1.0
Modern c++17 library containing classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows, Apple macOS and Linux like Ubuntu operating system.
button_base.h
1 #pragma once
2 #include <xtd/drawing/image.h>
3 #include "control.h"
4 #include "content_alignment.h"
5 #include "image_list.h"
6 #include "flat_style.h"
7 #include "text_format_flags.h"
8 
10 namespace xtd {
12  namespace forms {
17  class button_base : public control {
18  public:
22  bool auto_ellipsis() const {return this->auto_ellipsis_;}
23 
28  if (this->auto_ellipsis_ != auto_ellipsis)
29  this->auto_ellipsis_ = auto_ellipsis;
30  return *this;
31  }
32 
35  bool auto_size() const override {return this->control::auto_size();}
36 
39  control& auto_size(bool auto_size) override {
40  this->control::auto_size(auto_size);
41  if (this->get_state(state::auto_size))
42  this->auto_ellipsis_ = false;
43  return *this;
44  }
45 
46  virtual xtd::forms::flat_style flat_style() const {return flat_style_;}
48 
49  virtual const drawing::image& image() const {return image_;}
50  virtual button_base& image(const drawing::image& value);
51 
54  virtual content_alignment image_align() const {return image_align_;}
58 
59  virtual int32_t image_index() const {return image_index_;}
60  virtual button_base& image_index(int32_t value);
61 
62  virtual const forms::image_list& image_list() const {return image_list_;}
63  virtual button_base& image_list(const forms::image_list& value);
64 
67  virtual content_alignment text_align() const {return text_align_;}
71 
72  event<button_base, event_handler<control&>> image_changed;
73 
74  protected:
76  button_base();
77 
80  forms::create_params create_params() const override;
81 
84  drawing::size default_size() const override {return {75, 25};}
85 
89  drawing::size measure_control() const override;
90 
91  void on_back_color_changed(const event_args& e) override {
92  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
93  control::on_parent_back_color_changed(e);
94  }
95 
96  void on_enabled_changed(const event_args& e) override {
97  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
98  control::on_enabled_changed(e);
99  }
100 
101  void on_font_changed(const xtd::event_args& e) override {
102  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
103  control::on_font_changed(e);
104  }
105 
106  void on_fore_color_changed(const event_args& e) override {
107  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
108  control::on_fore_color_changed(e);
109  }
110 
111  virtual void on_image_changed(const xtd::event_args& e) {
112  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
113  if (can_raise_events()) image_changed(*this, e);
114  }
115 
116  void on_mouse_down(const mouse_event_args& e) override {
117  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
118  control::on_mouse_down(e);
119  }
120 
121  void on_mouse_enter(const event_args& e) override {
122  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
123  control::on_mouse_enter(e);
124  }
125 
126  void on_mouse_leave(const event_args& e) override {
127  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
128  control::on_mouse_leave(e);
129  }
130 
131  void on_mouse_up(const mouse_event_args& e) override {
132  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
133  control::on_mouse_up(e);
134  }
135 
136  void on_parent_back_color_changed(const event_args& e) override {
137  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
138  control::on_parent_back_color_changed(e);
139  }
140 
141  void on_parent_fore_color_changed(const event_args& e) override {
142  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
143  control::on_parent_fore_color_changed(e);
144  }
145 
146  void on_resize(const xtd::event_args& e) override {
147  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
148  control::on_resize(e);
149  }
150 
151  void on_text_changed(const xtd::event_args& e) override {
152  if (flat_style_ != xtd::forms::flat_style::system) invalidate();
153  control::on_text_changed(e);
154  }
155 
157  text_format_flags to_text_format_flags(content_alignment text_align);
158  xtd::drawing::rectangle compute_image_bounds() {return compute_image_bounds({0, 0, width(), height()});}
159  xtd::drawing::rectangle compute_image_bounds(const xtd::drawing::rectangle& rectangle);
160 
161  bool auto_ellipsis_ = false;
162  xtd::forms::flat_style flat_style_ = xtd::forms::flat_style::standard;
163  drawing::image image_ = drawing::image::empty;
164  forms::image_list image_list_;
165  int32_t image_index_ = -1;
169  };
170  }
171 }
Definition: image_list.h:11
drawing::size default_size() const override
Gets the default size of the control.
Definition: button_base.h:84
Implements the basic functionality common to button controls.
Definition: button_base.h:17
content_alignment
Specifies alignment of content on the drawing surface.
Definition: content_alignment.h:9
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
virtual bool auto_size() const
Gets a value that indicates whether the control resizes based on its contents.
Definition: control.h:211
bool can_raise_events() const override
Determines if events can be raised on the control.
Definition: control.h:274
virtual content_alignment image_align() const
Gets the alignment of the image on the button control.
Definition: button_base.h:54
drawing::size measure_control() const override
Measure this control.
control & auto_size(bool auto_size) override
Sets a value that indicates whether the control resizes based on its contents.
Definition: button_base.h:39
bool auto_ellipsis() const
Gets a value indicating whether the ellipsis character (...) appears at the right edge of the control...
Definition: button_base.h:22
button_base()
Initializes a new instance of the ButtonBase class.
The picture_box is sized equal to the size of the image that it contains.
virtual content_alignment text_align() const
Gets the alignment of the text on the button control.
Definition: button_base.h:67
flat_style
Specifies the appearance of a control.
Definition: flat_style.h:12
Defines the base class for controls, which are components with visual representation.
Definition: control.h:60
forms::create_params create_params() const override
Gets the required creation parameters when the control handle is created.
Definition: mouse_event_args.h:20
Content is vertically aligned at the middle, and horizontally aligned at the center.
bool auto_size() const override
Gets a value that indicates whether the control resizes based on its contents.
Definition: button_base.h:35
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:27