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.
control.h
Go to the documentation of this file.
1 #pragma once
5 #include <any>
6 #include <condition_variable>
7 #include <cstdint>
8 #include <functional>
9 #include <map>
10 #include <memory>
11 #include <optional>
12 #include <string>
13 #include <thread>
14 #include <vector>
15 #include <xtd/iasync_result.h>
16 #include <xtd/drawing/color.h>
17 #include <xtd/drawing/font.h>
18 #include <xtd/drawing/point.h>
19 #include <xtd/drawing/rectangle.h>
20 #include <xtd/drawing/size.h>
21 #include <xtd/forms/create_params.h>
22 
23 #include "../forms_export.h"
25 #include "anchor_styles.h"
26 #include "auto_size_mode.h"
27 #include "bounds_specified.h"
28 #include "component.h"
29 #include "control_event_handler.h"
30 #include "control_ref.h"
31 #include "control_styles.h"
32 #include "cursors.h"
33 #include "dock_style.h"
34 #include "image_layout.h"
35 #include "iwin32_window.h"
36 #include "key_event_handler.h"
38 #include "mouse_event_handler.h"
39 #include "padding.h"
40 #include "paint_event_handler.h"
41 #include "message.h"
42 #include "theme_colors.h"
43 #include "timer.h"
44 
46 namespace xtd {
48  namespace forms {
50  class application;
51  class screen;
53 
67  class forms_export_ control : public component, public iwin32_window {
68  protected:
70  enum class state {
71  empty = 0,
72  creating = 0b1,
73  created = 0b10,
74  destroying = 0b100,
75  destroyed = 0b1000,
76  creating_handle = 0b10000,
77  recreate = 0b100000,
78  parent_recreating = 0b1000000,
79 
80  client_size_setted = 0b10000000,
81  modal = 0b100000000,
82  top_level = 0b1000000000,
83  visible = 0b10000000000,
84  enabled = 0b100000000000,
85  auto_size = 0b1000000000000,
86  tab_stop = 0b10000000000000,
87  allow_drop = 0b100000000000000,
88  drop_target = 0b1000000000000000,
89 
90  layout_deferred = 0b10000000000000000,
91  docked = 0b100000000000000000,
92 
93  double_click_fired = 0b1000000000000000000,
94  double_buffered = 0b10000000000000000000,
95  /*
96  mouse_enter_pending = 0,
97  tracking_mouse_event = 0,
98  mouse_pressed = 0,
99  use_wait_cursor = 0,
100  */
101 
102  /*
103  is_accessible = 0,
104  no_zorder = 0,
105  size_locked_by_os = 0,
106  causes_validation = 0,
107  own_ctl_brush = 0,
108  exception_while_painting = 0,
109  layout_sis_dirty = 0,
110  checked_host = 0,
111  hosted_in_dialog = 0,
112  validation_cancelled = 0,
113  mirrored = 0,
114  */
115  };
117 
119  public:
120  async_result_invoke(std::any async_state) : async_state_(async_state) {}
121  std::any async_state() const noexcept override {return async_state_;}
122  std::shared_mutex& async_mutex() override {return *async_mutex_;}
123  bool completed_synchronously() const noexcept override {return false;}
124  bool is_completed() const noexcept override {return *is_completed_;};
125 
126  std::any async_state_;
127  std::shared_ptr<bool> is_completed_ = std::make_shared<bool>(false);
128  std::shared_ptr<std::shared_mutex> async_mutex_ = std::make_shared<std::shared_mutex>();
129  };
130 
131  public:
134  public:
137 
141  explicit control_collection(const allocator_type& allocator = allocator_type());
143  control_collection(const base& collection);
144  control_collection(const control_collection& collection);
145  control_collection& operator=(const control_collection& collection);
148 
149  using base::operator[];
154  std::optional<value_type> operator[](const xtd::ustring& name) const;
159  std::optional<value_type> operator[](const xtd::ustring& name);
160  };
161 
164  control();
169  explicit control(const xtd::ustring& text) : control() {
170  this->text(text);
171  }
177  explicit control(const control& parent, const xtd::ustring& text) : control() {
178  this->parent(parent);
179  this->text(text);
180  }
189  explicit control(const xtd::ustring& text, int32_t left, int32_t top, int32_t width, int32_t height) : control() {
190  this->text(text);
191  this->left(left);
192  this->top(top);
193  this->width(width);
194  this->height(height);
195  }
205  explicit control(const control& parent, const xtd::ustring& text, int32_t left, int32_t top, int32_t width, int32_t height) : control() {
206  this->parent(parent);
207  this->text(text);
208  this->left(left);
209  this->top(top);
210  this->width(width);
211  this->height(height);
212  }
213 
215  control(control&&) = delete;
216  control(const control&) = delete;
217  ~control();
219 
227  virtual anchor_styles anchor() const {return anchor_;}
236  virtual control& anchor(anchor_styles anchor);
237 
240  virtual drawing::point auto_scroll_point() const {return auto_scroll_point_;}
241 
245  virtual bool auto_size() const {return get_state(state::auto_size);}
250  virtual control& auto_size(bool auto_size);
251 
256  virtual drawing::color back_color() const;
264  virtual control& back_color(const drawing::color& color);
266  virtual control& back_color(nullptr_t);
268 
272  virtual const xtd::drawing::image& background_image() const {return background_image_;}
277  virtual control& background_image(const xtd::drawing::image& background_image);
278 
283  virtual xtd::forms::image_layout background_image_layout() const {return background_image_layout_;}
284 
290  virtual control& background_image_layout(xtd::forms::image_layout background_image_layout);
291 
296  virtual int32_t bottom() const {return top() + height();}
297 
301  virtual drawing::rectangle bounds() const {return {location_, size_};}
306  virtual control& bounds(const drawing::rectangle& bounds) {
307  set_bounds_core(bounds.x(), bounds.y(), bounds.width(), bounds.height(), bounds_specified::all);
308  return *this;
309  }
310 
314  virtual bool can_focus() const;
315 
327  virtual bool can_select() const {return enabled() && visible() && get_style(control_styles::selectable);}
328 
331  bool can_raise_events() const override {return can_raise_events_;}
332 
337  virtual const drawing::rectangle& client_rectangle() const {return client_rectangle_;}
338 
342  virtual const drawing::size& client_size() const {return client_size_;}
347  virtual control& client_size(const drawing::size& client_size) {
348  if (!get_state(state::client_size_setted) || client_size_ != client_size) {
349  set_state(state::client_size_setted, true);
350  set_client_size_core(client_size.width(), client_size.height());
351  }
352  return *this;
353  }
354 
357  virtual xtd::ustring company_name() const {return "Gammasoft";}
358 
365  virtual control_collection& controls() {return controls_;}
372  virtual const control_collection& controls() const {return controls_;}
373 
377  virtual bool created() {return get_state(state::created);}
378 
381  virtual forms::cursor cursor() const;
385  virtual control& cursor(const forms::cursor& cursor);
387  virtual control& cursor(nullptr_t);
389 
393  virtual drawing::color default_back_color() const {return xtd::forms::theme_colors::current_theme().control();}
394 
398 
401  virtual drawing::font default_font() const;
402 
405  virtual drawing::color default_fore_color() const {return xtd::forms::theme_colors::current_theme().control_text();}
406 
409  virtual drawing::size default_size() const {return {0, 0};}
410 
413  virtual drawing::rectangle display_rectangle() const {return client_rectangle_;}
414 
423  virtual dock_style dock() const {return dock_;}
433  virtual control& dock(dock_style dock);
434 
437  virtual bool double_buffered() const {return get_state(state::double_buffered);}
441  virtual control& double_buffered(bool double_buffered) {
442  set_state(state::double_buffered, double_buffered);
443  return *this;
444  }
445 
448  virtual bool enabled() const {return get_state(state::enabled);}
452  virtual control& enabled(bool enabled);
453 
456  virtual bool focused() const {return focused_;}
457 
460  virtual drawing::color fore_color() const;
464  virtual control& fore_color(const drawing::color& color);
466  virtual control& fore_color(nullptr_t);
468 
471  virtual drawing::font font() const;
475  virtual control& font(const drawing::font& font);
477  virtual control& font(nullptr_t);
479 
482  intptr_t handle() const override;
483 
486  virtual int32_t height() const {return size_.height();}
490  virtual control& height(int32_t height) {
491  if (size_.height() != height)
492  set_bounds_core(0, 0, 0, height, bounds_specified::height);
493  return *this;
494  }
495 
499  bool is_handle_created() const;
500 
503  virtual int32_t left() const {return location_.x();}
507  virtual control& left(int32_t left) {
508  if (location_.x() != left)
509  set_bounds_core(left, 0, 0, 0, bounds_specified::x);
510  return *this;
511  }
512 
515  virtual drawing::point location() const {return location_;}
520  if (location_ != location)
521  set_bounds_core(location.x(), location.y(), 0, 0, bounds_specified::location);
522  return *this;
523  }
524 
527  virtual forms::padding margin() const {return margin_;}
531  virtual control& margin(const forms::padding& margin) {
532  if (margin_ != margin)
533  margin_ = margin;
534  return *this;
535  }
536 
542  virtual const drawing::size& maximum_size() const;
548  virtual control& maximum_size(const drawing::size& size);
549 
555  virtual const drawing::size& minimum_size() const;
561  virtual control& minimum_size(const drawing::size& size);
562 
565  static forms::keys modifier_keys() {return modifier_keys_;}
566 
569  static forms::mouse_buttons mouse_buttons() {return mouse_buttons_;}
570 
573  virtual const xtd::ustring& name() const {return name_;}
577  virtual control& name(const xtd::ustring& name) {
578  name_ = name;
579  return*this;
580  }
581 
584  virtual forms::padding padding() const {return padding_;}
589  if (padding_ != padding)
590  padding_ = padding;
591  return *this;
592  }
593 
596  virtual std::optional<control_ref> parent() const {return from_handle(parent_);}
600  virtual control& parent(const control& parent);
604  virtual control& parent(std::nullptr_t);
605 
608  virtual xtd::ustring product_name() const {return "xtd";}
609 
612  bool recreating_handle() const {return get_state(state::recreate);}
613 
616  virtual int32_t right() const {return left() + width();}
617 
620  virtual const drawing::size& size() const {return size_;}
624  virtual control& size(const drawing::size& size) {
625  if (get_state(state::client_size_setted) || size_ != size) {
626  set_state(state::client_size_setted, false);
627  set_bounds_core(0, 0, size.width(), size.height(), bounds_specified::size);
628  }
629  return *this;
630  }
631 
636  virtual std::any tag() const {return tag_;}
637 
643  virtual control& tag(std::any tag) {
644  tag_ = tag;
645  return*this;
646  }
647 
650  virtual const xtd::ustring& text() const {return text_;}
654  virtual control& text(const xtd::ustring& text);
655 
658  virtual int32_t top() const {return location_.y();}
662  virtual control& top(int32_t top) {
663  if (location_.y() != top)
664  set_bounds_core(0, top, 0, 0, bounds_specified::y);
665  return *this;
666  }
667 
670  virtual std::optional<control_ref> top_level_control() const;
671 
674  virtual bool visible() const {return get_state(state::visible);}
678  virtual control& visible(bool visible);
679 
682  virtual int32_t width() const {return size_.width();}
686  virtual control& width(int32_t width) {
687  if (size_.width() != width)
688  set_bounds_core(0, 0, width, 0, bounds_specified::width);
689  return *this;
690  }
691 
696  friend control& operator<<(control& parent, control& child) {
697  child.parent(parent);
698  return parent;
699  }
700 
705  friend control& operator>>(control& parent, control& child) {
706  if (child.parent().has_value() && &child.parent().value().get() == &parent)
707  child.parent(nullptr);
708  return parent;
709  }
710 
714  std::shared_ptr<xtd::iasync_result> begin_invoke(delegate<void()> value) {return begin_invoke(delegate<void(std::vector<std::any>)>(value), {});}
715 
720  std::shared_ptr<xtd::iasync_result> begin_invoke(delegate<void(std::vector<std::any>)> value, const std::vector<std::any>& args);
721 
723  template<typename delegate_t>
724  std::shared_ptr<xtd::iasync_result> begin_invoke(delegate_t value, const std::vector<std::any>& args) {return begin_invoke(delegate<void(std::vector<std::any>)>(value), args);}
725 
726  template<typename delegate_t>
727  std::shared_ptr<xtd::iasync_result> begin_invoke(delegate_t value) {return begin_invoke(delegate<void(std::vector<std::any>)>(value), {});}
729 
732  virtual void bring_to_front();
733 
740  template<typename control_t>
741  static std::unique_ptr<control_t> create(const drawing::point& location = {-1, -1}, const drawing::size& size = {-1, -1}, const drawing::color& back_color = drawing::color::empty, const drawing::color& fore_color = drawing::color::empty) {
742  std::unique_ptr<control_t> item = std::make_unique<control_t>();
743  if (location != drawing::point {-1, -1}) item->location(location);
744  if (size != drawing::size {-1, -1}) item->size(size);
745  if (back_color != drawing::color::empty) item->back_color(back_color);
746  if (fore_color != drawing::color::empty) item->fore_color(fore_color);
747  return item;
748  }
749 
757  template<typename control_t>
758  static std::unique_ptr<control_t> create(const control& parent, const drawing::point& location = {-1, -1}, const drawing::size& size = {-1, -1}, const drawing::color& back_color = drawing::color::empty, const drawing::color& fore_color = drawing::color::empty) {
759  std::unique_ptr<control_t> item = std::make_unique<control_t>();
760  item->parent(parent);
761  if (location != drawing::point {-1, -1}) item->location(location);
762  if (size != drawing::size {-1, -1}) item->size(size);
763  if (back_color != drawing::color::empty) item->back_color(back_color);
764  if (fore_color != drawing::color::empty) item->fore_color(fore_color);
765  return item;
766  }
767 
775  template<typename control_t>
776  static std::unique_ptr<control_t> create(const xtd::ustring& text, const drawing::point& location = {-1, -1}, const drawing::size& size = {-1, -1}, const drawing::color& back_color = drawing::color::empty, const drawing::color& fore_color = drawing::color::empty) {
777  std::unique_ptr<control_t> item = std::make_unique<control_t>();
778  item->text(text);
779  if (location != drawing::point {-1, -1}) item->location(location);
780  if (size != drawing::size {-1, -1}) item->size(size);
781  if (back_color != drawing::color::empty) item->back_color(back_color);
782  if (fore_color != drawing::color::empty) item->fore_color(fore_color);
783  return item;
784  }
785 
794  template<typename control_t>
795  static std::unique_ptr<control_t> create(const control& parent, const xtd::ustring& text, const drawing::point& location = {-1, -1}, const drawing::size& size = {-1, -1}, const drawing::color& back_color = drawing::color::empty, const drawing::color& fore_color = drawing::color::empty) {
796  std::unique_ptr<control_t> item = std::make_unique<control_t>();
797  item->parent(parent);
798  item->text(text);
799  if (location != drawing::point {-1, -1}) item->location(location);
800  if (size != drawing::size {-1, -1}) item->size(size);
801  if (back_color != drawing::color::empty) item->back_color(back_color);
802  if (fore_color != drawing::color::empty) item->fore_color(fore_color);
803  return item;
804  }
805 
809  void create_control();
810 
815  drawing::graphics create_graphics() const;
816 
821  virtual void create_handle();
822 
827  virtual void destroy_control();
828 
832  virtual void destroy_handle();
833 
836  void end_invoke(std::shared_ptr<xtd::iasync_result> async);
837 
841  bool focus();
842 
847  static std::optional<control_ref> from_child_handle(intptr_t handle);
848 
852  static std::optional<control_ref> from_handle(intptr_t handle);
853 
858  size_t get_child_index(intptr_t child) const {
859  for (size_t index = 0;index < controls().size(); ++index)
860  if (controls()[index].get().handle() == child) return index;
862  }
863 
867  size_t get_child_index(intptr_t child, bool& throw_exception) const {
868  throw_exception = false;
869  try {
870  return get_child_index(child);
871  } catch(...) {
872  throw_exception = true;
873  return control_collection::npos;
874  }
875  }
876 
879  virtual void hide() {visible(false);}
880 
883  virtual void invalidate() const {invalidate({{0, 0}, client_size()}, false);}
884 
888  virtual void invalidate(bool invalidate_children) const {invalidate({{0, 0}, client_size()}, invalidate_children);}
889 
893  virtual void invalidate(const drawing::rectangle& rect) const {invalidate(rect, false);}
894 
899  virtual void invalidate(const drawing::rectangle& rect, bool invalidate_children) const;
900 
903  void invoke(delegate<void()> value) {invoke(delegate<void(std::vector<std::any>)>(value), {});}
904 
908  void invoke(delegate<void(std::vector<std::any>)> value, const std::vector<std::any>& args) {end_invoke(begin_invoke(value, args));}
909 
911  template<typename delegate_t>
912  void invoke(delegate_t value, const std::vector<std::any>& args) {invoke(delegate<void(std::vector<std::any>)>(value), args);}
913 
914  template<typename delegate_t>
915  void invoke(delegate_t value) {invoke(delegate<void(std::vector<std::any>)>(value), {});}
917 
920  void perform_layout();
921 
925  xtd::drawing::point point_to_client(const xtd::drawing::point& p);
926 
930  xtd::drawing::point point_to_screen(const xtd::drawing::point& p);
931 
936  virtual bool pre_process_message(xtd::forms::message& message);
937 
941  virtual void refresh() const;
942 
947  void resume_layout() {resume_layout(true);}
948 
955  void resume_layout(bool perform_layout) {
956  set_state(state::layout_deferred, false);
957  if (perform_layout) this->perform_layout();
958  }
959 
966  intptr_t send_message(intptr_t hwnd, int32_t msg, intptr_t wparam, intptr_t lparam) const;
967 
970  void set_auto_size_mode(auto_size_mode auto_size_mode);
971 
977  void set_bounds(int32_t x, int32_t y, int32_t width, int32_t height) {set_bounds(x, y, width, height, bounds_specified::all);}
978 
985  void set_bounds(int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified) {set_bounds_core(x, y, width, height, specified);}
986 
989  virtual void show() {visible(true);}
990 
996  void suspend_layout() {
997  set_state(state::layout_deferred, true);
998  }
999 
1002  xtd::ustring to_string() const noexcept override;
1003 
1010  virtual void update() const;
1011 
1013  friend std::ostream& operator<<(std::ostream& os, const xtd::forms::control& control) noexcept {
1014  return os << control.to_string();
1015  }
1016 
1017  bool operator==(const control& value) const {return this == &value;}
1018  bool operator!=(const control& value) const {return !operator==(value);}
1019  bool operator<(const control& value) const {return this < &value;}
1021 
1026 
1031 
1036 
1041 
1066 
1071 
1076 
1080 
1084 
1089 
1113 
1134 
1139 
1144 
1149 
1154 
1159 
1171 
1185 
1197 
1202 
1207 
1229 
1245 
1265 
1279 
1293 
1308 
1322 
1336 
1350 
1365 
1374 
1379 
1388 
1393 
1398 
1403 
1404  protected:
1405  friend class application;
1406  friend class paint_event_args;
1407  friend class screen;
1408 
1414  virtual forms::create_params create_params() const;
1415 
1418  virtual void def_wnd_proc(message& message);
1419 
1424  bool get_style(control_styles flag) const {return ((int32_t)style_ & (int32_t)flag) == (int32_t)flag;}
1425 
1428  virtual drawing::size measure_control() const;
1429 
1432  drawing::size measure_text() const;
1433 
1437  virtual void on_auto_size_changed(const event_args& e);
1438 
1442  virtual void on_back_color_changed(const event_args& e);
1443 
1447  virtual void on_background_image_changed(const event_args& e);
1448 
1452  virtual void on_background_image_layout_changed(const event_args& e);
1453 
1457  virtual void on_click(const event_args& e);
1458 
1462  virtual void on_client_size_changed(const event_args& e);
1463 
1467  virtual void on_control_added(const control_event_args& e);
1468 
1472  virtual void on_control_removed(const control_event_args& e);
1473 
1477  virtual void on_create_control();
1478 
1482  virtual void on_cursor_changed(const event_args& e);
1483 
1487  virtual void on_dock_changed(const event_args& e);
1488 
1492  virtual void on_double_click(const event_args& e);
1493 
1497  virtual void on_enabled_changed(const event_args& e);
1498 
1502  virtual void on_fore_color_changed(const event_args& e);
1503 
1507  virtual void on_font_changed(const event_args& e);
1508 
1512  virtual void on_got_focus(const event_args& e);
1513 
1517  virtual void on_handle_created(const event_args& e);
1518 
1522  virtual void on_handle_destroyed(const event_args& e);
1523 
1527  virtual void on_key_down(key_event_args& e);
1528 
1532  virtual void on_key_press(key_press_event_args& e);
1533 
1537  virtual void on_key_up(key_event_args& e);
1538 
1542  virtual void on_layout(const event_args& e);
1543 
1547  virtual void on_location_changed(const event_args& e);
1548 
1552  virtual void on_lost_focus(const event_args& e);
1553 
1557  virtual void on_mouse_click(const mouse_event_args& e);
1558 
1562  virtual void on_mouse_double_click(const mouse_event_args& e);
1563 
1567  virtual void on_mouse_down(const mouse_event_args& e);
1568 
1572  virtual void on_mouse_enter(const event_args& e);
1573 
1577  virtual void on_mouse_horizontal_wheel(const mouse_event_args& e);
1578 
1582  virtual void on_mouse_leave(const event_args& e);
1583 
1587  virtual void on_mouse_move(const mouse_event_args& e);
1588 
1592  virtual void on_mouse_up(const mouse_event_args& e);
1593 
1597  virtual void on_mouse_wheel(const mouse_event_args& e);
1598 
1602  virtual void on_paint(paint_event_args& e);
1603 
1607  virtual void on_parent_back_color_changed(const event_args& e);
1608 
1612  virtual void on_parent_cursor_changed(const event_args& e);
1613 
1617  virtual void on_parent_changed(const event_args& e);
1618 
1622  virtual void on_parent_enabled_changed(const event_args& e);
1623 
1627  virtual void on_parent_fore_color_changed(const event_args& e);
1628 
1632  virtual void on_parent_font_changed(const event_args& e);
1633 
1637  virtual void on_resize(const event_args& e);
1638 
1642  virtual void on_size_changed(const event_args& e);
1643 
1647  virtual void on_text_changed(const event_args& e);
1648 
1652  virtual void on_visible_changed(const event_args& e);
1653 
1656  virtual void recreate_handle();
1657 
1668  virtual void set_bounds_core(int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified);
1669 
1677  virtual void set_client_size_core(int32_t width, int32_t height);
1678 
1684  void set_style(control_styles flag, bool value) {style_ = value ? (control_styles)((int32_t)style_ | (int32_t)flag) : (control_styles)((int32_t)style_ & ~(int32_t)flag);}
1685 
1691  virtual void wnd_proc(message& m);
1692 
1694  bool get_state(control::state flag) const {return ((int32_t)state_ & (int32_t)flag) == (int32_t)flag;}
1695  void set_state(control::state flag, bool value) { state_ = value ? (control::state)((int32_t)state_ | (int32_t)flag) : (control::state)((int32_t)state_ & ~(int32_t)flag); }
1696 
1698  drawing::point auto_scroll_point_;
1699  auto_size_mode auto_size_mode_ = auto_size_mode::grow_and_shrink;
1700  std::optional<drawing::color> back_color_;
1701  xtd::drawing::image background_image_ = xtd::drawing::image::empty;
1702  xtd::forms::image_layout background_image_layout_ = xtd::forms::image_layout::tile;
1703  bool can_focus_ = true;
1704  bool can_raise_events_ = true;
1705  drawing::rectangle client_rectangle_;
1706  drawing::size client_size_;
1707  control_collection controls_;
1708  std::optional<forms::cursor> cursor_;
1709  dock_style dock_ = dock_style::none;
1710  bool focused_ = false;
1711  std::optional<drawing::color> fore_color_;
1712  std::optional<drawing::font> font_;
1713  intptr_t handle_ = 0;
1714  drawing::point location_;
1715  forms::padding margin_ {3};
1716  drawing::size maximum_size_;
1717  drawing::size minimum_size_;
1718  forms::padding padding_;
1719  static forms::keys modifier_keys_;
1720  static forms::mouse_buttons mouse_buttons_;
1721  bool mouse_in_ = false;
1722  xtd::ustring name_;
1723  intptr_t parent_ = 0;
1724  drawing::size parent_size_;
1725  drawing::size size_;
1726  control::state state_ = state::empty;
1728  std::any tag_;
1729  xtd::ustring text_;
1730  static std::map<intptr_t, control*> handles_;
1731  static control_collection top_level_controls_;
1733 
1734  private:
1735  void on_parent_size_changed(object& sender, const event_args& e);
1736  void do_layout_children_with_dock_style();
1737  void do_layout_with_auto_size_mode();
1738  void do_layout_with_anchor_styles();
1739  control(const xtd::ustring& name, bool) {name_ = name;}
1740  intptr_t wnd_proc_(intptr_t hwnd, int32_t msg, intptr_t wparam, intptr_t lparam, intptr_t handle);
1741  void wm_child_activate(message& message);
1742  void wm_create(message& message);
1743  void wm_command(message& message);
1744  void wm_key_char(message& message);
1745  void wm_kill_focus(message& message);
1746  void wm_mouse_down(message& message);
1747  void wm_mouse_double_click(message& message);
1748  void wm_mouse_enter(message& message);
1749  void wm_mouse_leave(message& message);
1750  void wm_mouse_up(message& message);
1751  void wm_mouse_move(message& message);
1752  void wm_move(message& message);
1753  void wm_mouse_wheel(message& message);
1754  void wm_paint(message& message);
1755  void wm_scroll(message& message);
1756  void wm_set_focus(message& message);
1757  void wm_set_text(message& message);
1758  void wm_size(message& message);
1759  };
1760  }
1761 }
event< control, control_event_handler > control_removed
Occurs when a new control is removed to the control::control_collection.
Definition: control.h:1083
virtual forms::cursor default_cursor() const
Gets the default cursor for the control.
Definition: control.h:397
event< control, event_handler > resize
Occurs when the control is resized.
Definition: control.h:1387
Represents a display device or multiple display devices on a single system.
Definition: screen.h:29
virtual control & width(int32_t width)
Sets the width of the control.
Definition: control.h:686
virtual void hide()
Conceals the control from the user.
Definition: control.h:879
Contains xtd::forms::cursors factory.
Represents a display device or multiple display devices on a single system.
Definition: padding.h:20
virtual void show()
Displays the control to the user.
Definition: control.h:989
Contains xtd::forms::theme_colors class.
virtual xtd::forms::image_layout background_image_layout() const
Gets the background image layout as defined in the xtd::forms::image_layout enumeration.
Definition: control.h:283
virtual forms::padding margin() const
Gets the space between controls.
Definition: control.h:527
Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.
Definition: font.h:39
virtual const drawing::size & size() const
Gets the height and width of the control.
Definition: control.h:620
event< control, event_handler > layout
Occurs when a control should reposition its child controls.
Definition: control.h:1201
virtual bool enabled() const
Gets a value indicating whether the control can respond to user interaction.
Definition: control.h:448
virtual drawing::point location() const
Gets the coordinates of the upper-left corner of the control relative to the upper-left corner of its...
Definition: control.h:515
The image is tiled across the control&#39;s client rectangle.
event< control, event_handler > enabled_changed
Occurs when the value of the enabled property changes.
Definition: control.h:1148
Bind control edges to the top of its container.
virtual void invalidate(const drawing::rectangle &rect) const
Invalidates the specified region of the control (adds it to the control&#39;s update region, which is the area that will be repainted at the next paint operation), and causes a paint message to be sent to the control.
Definition: control.h:893
virtual int32_t right() const
Gets the distance, in pixels, between the right edge of the control and the left edge of its containe...
Definition: control.h:616
event< control, event_handler > background_image_changed
Occurs when the value of the background_image property changes.
Definition: control.h:1035
virtual drawing::rectangle bounds() const
Gets the size and location of the control including its nonclient elements, in pixels, relative to the parent control.
Definition: control.h:301
Represents the status of an asynchronous operation.
Definition: iasync_result.h:21
event< control, mouse_event_handler > mouse_horizontal_wheel
Occurs when the mouse horizontal wheel moves while the control has focus.
Definition: control.h:1307
virtual const xtd::ustring & name() const
Gets the name of the control.
Definition: control.h:573
mouse_buttons
Specifies constants that define which mouse button was pressed. This enumeration has a flag attribute...
Definition: mouse_buttons.h:18
static forms::mouse_buttons mouse_buttons()
Gets a value indicating which of the mouse buttons is in a pressed state.
Definition: control.h:569
virtual control & name(const xtd::ustring &name)
Sets the name of the control.
Definition: control.h:577
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
event< control, event_handler > client_size_changed
Occurs when the value of the client_size property changes.
Definition: control.h:1070
Contains xtd::forms::key_event_handler event handler.
Contains xtd::forms::arranged_element_collection collection.
static std::unique_ptr< control_t > create(const control &parent, const xtd::ustring &text, const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
A factory to create a specified control with specified parent, text, location ,size back_color and fo...
Definition: control.h:795
void resume_layout(bool perform_layout)
Resumes usual layout logic, optionally forcing an immediate layout of pending layout requests...
Definition: control.h:955
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:159
The picture_box is sized equal to the size of the image that it contains.
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
Contains xtd::forms::paint_event_handler event handler.
virtual drawing::rectangle display_rectangle() const
Gets the rectangle that represents the display area of the control.
Definition: control.h:413
Represents a collection of controls.
Definition: control.h:133
Contains xtd::drawing::point class.
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
Specifies that the top edge of the control is defined.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static const xtd::drawing::color empty
Represents a color that is null.
Definition: color.h:42
virtual int32_t height() const
Gets the height of the control.
Definition: control.h:486
event< control, event_handler > mouse_enter
Occurs when the mouse pointer enters the control.
Definition: control.h:1292
virtual void invalidate(bool invalidate_children) const
Invalidates a specific region of the control and causes a paint message to be sent to the control...
Definition: control.h:888
static std::unique_ptr< control_t > create(const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
A factory to create a specified control with specified location ,size back_color and fore_color...
Definition: control.h:741
virtual bool can_select() const
Gets a value indicating whether the control can be selected.
Definition: control.h:327
int32_t width() const
Gets the horizontal component of this Size class.
Definition: size.h:67
event< control, key_event_handler > key_down
Occurs when a key is pressed while the control has focus.
Definition: control.h:1170
void invoke(delegate< void()> value)
Executes the specified delegate on the thread that owns the control&#39;s underlying window handle...
Definition: control.h:903
event< control, event_handler > visible_changed
Occurs when the value of the visible property changes.
Definition: control.h:1402
event< control, event_handler > lost_focus
Occurs when the control loses focus.
Definition: control.h:1228
Contains xtd::forms::anchor_styles enum class.
event< control, event_handler > auto_size_changed
Occurs when the value of the auto_size property changes.
Definition: control.h:1025
virtual control & client_size(const drawing::size &client_size)
Sets the height and width of the client area of the control.
Definition: control.h:347
auto_size_mode
Specifies how a control will behave when its auto_size property is enabled.
Definition: auto_size_mode.h:18
virtual dock_style dock() const
Gets or sets which control borders are docked to its parent control and determines how a control is r...
Definition: control.h:423
event< control, event_handler > fore_color_changed
Occurs when the value of the fore_color property changes.
Definition: control.h:1153
Contains xtd::forms::message class.
The control grows or shrinks to fit its contents. The control cannot be resized manually.
void invoke(delegate< void(std::vector< std::any >)> value, const std::vector< std::any > &args)
Executes the specified delegate, on the thread that owns the control&#39;s underlying window handle...
Definition: control.h:908
Contains xtd::iasync_result interface.
virtual control & left(int32_t left)
Sets the distance, in pixels, between the left edge of the control and the left edge of its container...
Definition: control.h:507
event< control, control_event_handler > control_added
Occurs when a new control is added to the control::control_collection.
Definition: control.h:1079
virtual const control_collection & controls() const
Gets the collection of controls contained within the control.
Definition: control.h:372
Contains xtd::forms::timer component.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
std::any async_state() const noexcept override
Gets a user-defined object that qualifies or contains information about an asynchronous operation...
Definition: control.h:121
Specifies that the left edge of the control is defined.
Represents the image used to paint the mouse pointer.
Definition: cursor.h:35
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
Represents a collection of objects.
Definition: arranged_element_collection.h:28
virtual const drawing::rectangle & client_rectangle() const
Gets the rectangle that represents the client area of the control.
Definition: control.h:337
void set_bounds(int32_t x, int32_t y, int32_t width, int32_t height)
Sets the bounds of the control to the specified location and size.
Definition: control.h:977
std::shared_mutex & async_mutex() override
Gets a std::mutex that is used to wait for an asynchronous operation to complete. ...
Definition: control.h:122
Contains xtd::forms::control_styles enum class.
virtual drawing::point auto_scroll_point() const
Gets where this control is scrolled to in scroll_control_into_view(control).
Definition: control.h:240
event< control, mouse_event_handler > mouse_click
Occurs when the control is clicked by the mouse.
Definition: control.h:1244
int32_t height() const
Gets he vertical component of this Size Class.
Definition: size.h:57
virtual const drawing::size & client_size() const
Gets the height and width of the client area of the control.
Definition: control.h:342
virtual control & padding(const forms::padding &padding)
Sets padding within the control.
Definition: control.h:588
Contains xtd::forms::iwin32_window interface.
Contains xtd::forms::control_ref typedef.
virtual bool auto_size() const
Gets a value that indicates whether the control resizes based on its contents.
Definition: control.h:245
Contains xtd::forms::padding class.
size_t get_child_index(intptr_t child) const
Retrieves the index of a control within the control collection.
Definition: control.h:858
xtd::ustring to_string() const noexcept override
Returns a string containing the name of the control, if any.
Provides an interface to expose Win32 HWND handles.
Definition: iwin32_window.h:19
Contains xtd::forms::key_press_event_handler event handler.
event< control, event_handler > double_click
Occurs when the control is double-clicked.
Definition: control.h:1112
static std::unique_ptr< control_t > create(const control &parent, const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
A factory to create a specified control with specified parent, location ,size back_color and fore_col...
Definition: control.h:758
bool can_raise_events() const override
Determines if events can be raised on the control.
Definition: control.h:331
static cursor default_cursor()
Gets the default cursor, which is usually an arrow cursor.
virtual control_collection & controls()
Gets the collection of controls contained within the control.
Definition: control.h:365
virtual drawing::color default_fore_color() const
Gets the default foreground color of the control.
Definition: control.h:405
virtual drawing::color default_back_color() const
Gets the default background color of the control.
Definition: control.h:393
virtual control & bounds(const drawing::rectangle &bounds)
Sets the size and location of the control including its nonclient elements, in pixels, relative to the parent control.
Definition: control.h:306
Contains xtd::forms::image_layout enum class.
event< control, paint_event_handler > paint
Occurs when the control is redrawn.
Definition: control.h:1373
event< control, mouse_event_handler > mouse_down
Occurs when the mouse pointer is over the control and a mouse button is pressed.
Definition: control.h:1278
Specifies that the height of the control is defined.
Contains xtd::drawing::rectangle class.
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
The CTRL modifier key.
event< control, event_handler > handle_destroyed
Occurs when the control&#39;s handle is in the process of being destroyed.
Definition: control.h:1143
Represents an event.
Definition: event.h:21
virtual control & margin(const forms::padding &margin)
Sets the space between controls.
Definition: control.h:531
bool recreating_handle() const
Gets a value indicating whether the control is currently re-creating its handle.
Definition: control.h:612
Provides data for the paint event.
Definition: paint_event_args.h:26
virtual void invalidate() const
Invalidates the entire surface of the control and causes the control to be redrawn.
Definition: control.h:883
Specifies that both the width and height property values of the control are defined.
control(const xtd::ustring &text, int32_t left, int32_t top, int32_t width, int32_t height)
Initializes a new instance of the control class with specific text, size, and location.
Definition: control.h:189
Provides static methods and properties to manage an application, such as methods to start and stop an...
Definition: application.h:54
event< control, mouse_event_handler > mouse_move
Occurs when the mouse pointer is moved over the control.
Definition: control.h:1335
Specifies that both the location and size property values are defined.
event< control, event_handler > font_changed
Occurs when the value of the font property changes.
Definition: control.h:1158
control_styles
Specifies the style and behavior of a control.
Definition: control_styles.h:29
virtual drawing::size default_size() const
Gets the default size of the control.
Definition: control.h:409
virtual control & height(int32_t height)
Sets the height of the control.
Definition: control.h:490
virtual int32_t width() const
Gets the width of the control.
Definition: control.h:682
The exception that is thrown when one of the arguments provided to a method is not valid...
Definition: argument_exception.h:19
event< control, event_handler > background_image_layout_changed
Occurs when the value of the background_image_layout property changes.
Definition: control.h:1040
bool completed_synchronously() const noexcept override
Gets a value that indicates whether the asynchronous operation completed synchronously.
Definition: control.h:123
virtual int32_t top() const
Gets the distance, in pixels, between the top edge of the control and the top edge of its container&#39;s...
Definition: control.h:658
Contains xtd::forms::control_event_handler event handler.
Contains xtd::drawing::size class.
event< control, event_handler > back_color_changed
Occurs when the value of the back_color property changes.
Definition: control.h:1030
event< control, event_handler > location_changed
Occurs when the value of the location property changes.
Definition: control.h:1206
virtual bool visible() const
Gets a value indicating whether the control and all its child controls are displayed.
Definition: control.h:674
Specifies that the width of the control is defined.
std::shared_ptr< xtd::iasync_result > begin_invoke(delegate< void()> value)
Executes the specified delegate asynchronously on the thread that the control&#39;s underlying handle was...
Definition: control.h:714
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
event< control, event_handler > size_changed
Occurs when the value of the size property changes.
Definition: control.h:1392
virtual control & location(const drawing::point &location)
Sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its...
Definition: control.h:519
virtual bool created()
Gets a value indicating whether the control has been created.
Definition: control.h:377
event< control, mouse_event_handler > mouse_double_click
Occurs when the control is double clicked by the mouse.
Definition: control.h:1264
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
Contains xtd::drawing::color class.
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:34
Implements a Windows message.
Definition: message.h:25
event< control, event_handler > dock_changed
Occurs when the value of the dock property changes.
Definition: control.h:1088
event< control, key_press_event_handler > key_press
Occurs when a character. space or backspace key is pressed while the control has focus.
Definition: control.h:1184
The control is not docked.
virtual int32_t left() const
Gets the distance, in pixels, between the left edge of the control and the left edge of its container...
Definition: control.h:503
bool is_completed() const noexcept override
Gets a value that indicates whether the asynchronous operation has completed.
Definition: control.h:124
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:205
Defines the base class for controls, which are components with visual representation.
Definition: control.h:67
event< control, event_handler > parent_changed
Occurs when the value of the parent property changes.
Definition: control.h:1378
virtual forms::padding padding() const
Gets padding within the control.
Definition: control.h:584
dock_style
Specifies the position and manner in which a control is docked.
Definition: dock_style.h:19
event< control, event_handler > mouse_leave
Occurs when the mouse pointer leaves the control.
Definition: control.h:1321
size_t get_child_index(intptr_t child, bool &throw_exception) const
Retrieves the index of the specified child control within the control collection, and optionally rais...
Definition: control.h:867
Contains xtd::forms::mouse_event_handler event handler.
keys
Specifies key codes and modifiers.
Definition: keys.h:73
control(const xtd::ustring &text)
Initializes a new instance of the control class with specific text.
Definition: control.h:169
virtual const xtd::drawing::image & background_image() const
Gets the background image displayed in the control.
Definition: control.h:272
virtual control & double_buffered(bool double_buffered)
Sets a value indicating whether this control should redraw its surface using a secondary buffer to re...
Definition: control.h:441
event< control, event_handler > cursor_changed
Occurs when the value of the cursor property changes.
Definition: control.h:1075
virtual int32_t bottom() const
Gets the distance, in pixels, between the bottom edge of the control and the top edge of its containe...
Definition: control.h:296
Provides data for the key_press event.
Definition: key_press_event_args.h:23
std::allocator< value_type > allocator_type
Represents the allocator type of the collection.
Definition: arranged_element_collection.h:62
virtual control & top(int32_t top)
Sets the distance, in pixels, between the top edge of the control and the top edge of its container&#39;s...
Definition: control.h:662
Contains xtd::forms::dock_style enum class.
virtual anchor_styles anchor() const
Gets the edges of the container to which a control is bound and determines how a control is resized w...
Definition: control.h:227
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
bool get_style(control_styles flag) const
Retrieves the value of the specified control style bit for the control.
Definition: control.h:1424
friend control & operator>>(control &parent, control &child)
Remove child control.
Definition: control.h:705
event< control, event_handler > text_changed
Occurs when the value of the text property changes.
Definition: control.h:1397
Contains xtd::forms::auto_size_mode enum class.
Provides data for the control_added and control_removed events.
Definition: control_event_args.h:23
virtual bool double_buffered() const
Gets a value indicating whether this control should redraw its surface using a secondary buffer to re...
Definition: control.h:437
virtual std::optional< control_ref > parent() const
Gets the parent container of the control.
Definition: control.h:596
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual bool focused() const
Gets a value indicating whether the control has input focus.
Definition: control.h:456
Contains xtd::forms::component class.
void resume_layout()
Resumes usual layout logic.
Definition: control.h:947
control(const control &parent, const xtd::ustring &text, int32_t left, int32_t top, int32_t width, int32_t height)
Initializes a new instance of the control class as a child control, with specific text...
Definition: control.h:205
virtual xtd::ustring product_name() const
Gets the product name of the assembly containing the control.
Definition: control.h:608
void suspend_layout()
Temporarily suspends the layout logic for the control.
Definition: control.h:996
virtual std::any tag() const
Gets the object that contains data about the control.
Definition: control.h:636
Specifies that both the x and y coordinates of the control are defined.
virtual xtd::ustring company_name() const
Gets the name of the company or creator of the application containing the control.
Definition: control.h:357
void set_bounds(int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified)
Sets the specified bounds of the control to the specified location and size.
Definition: control.h:985
static forms::keys modifier_keys()
Gets a value indicating which of the modifier keys (SHIFT, CTRL, and ALT) is in a pressed state...
Definition: control.h:565
bounds_specified
Specifies the bounds of the control to use when defining a control&#39;s size and position. This enumeration has a flags attribute that allows a bitwise combination of its member values.
Definition: bounds_specified.h:18
event< control, key_event_handler > key_up
Occurs when a key is released while the control has focus.
Definition: control.h:1196
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
event< control, mouse_event_handler > mouse_up
Occurs when the mouse pointer is over the control and a mouse button is released. ...
Definition: control.h:1349
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Definition: control.h:650
Contains xtd::forms::bounds_specified enum class.
Provides data for the key_down or key_up event.
Definition: key_event_args.h:22
image_layout
Specifies the position of the image on the control.
Definition: image_layout.h:17
Bind control edges to the left of its container.
event< control, mouse_event_handler > mouse_wheel
Occurs when the mouse wheel moves while the control has focus.
Definition: control.h:1364
anchor_styles
Specifies how a control anchors to the edges of its container.
Definition: anchor_styles.h:19
virtual control & tag(std::any tag)
Sets the object that contains data about the control.
Definition: control.h:643
event< control, event_handler > got_focus
Occurs when the control receives focus.
Definition: control.h:1133
Contains xtd::drawing::font class.
static std::unique_ptr< control_t > create(const xtd::ustring &text, const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
A factory to create a specified control with specified text, location ,size back_color and fore_color...
Definition: control.h:776
event< control, event_handler > handle_created
Occurs when a handle is created for the control.
Definition: control.h:1138
Provides the base implementation and enables object sharing between applications. ...
Definition: component.h:21
size_t size
Represents a size of any object in bytes.
Definition: types.h:171
If true, the control can receive focus.
event< control, event_handler > click
Occurs when the control is clicked.
Definition: control.h:1065
friend control & operator<<(control &parent, control &child)
Add child control.
Definition: control.h:696
void set_style(control_styles flag, bool value)
Sets a specified control_styles flag to either true or false.
Definition: control.h:1684
control(const control &parent, const xtd::ustring &text)
Initializes a new instance of the control class as a child control, with specific text...
Definition: control.h:177
virtual control & size(const drawing::size &size)
Sets the height and width of the control.
Definition: control.h:624
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37