6 #include <condition_variable>
21 #include <xtd/forms/create_params.h>
23 #include "../forms_export.h"
76 creating_handle = 0b10000,
78 parent_recreating = 0b1000000,
80 client_size_setted = 0b10000000,
82 top_level = 0b1000000000,
83 visible = 0b10000000000,
84 enabled = 0b100000000000,
86 tab_stop = 0b10000000000000,
87 allow_drop = 0b100000000000000,
88 drop_target = 0b1000000000000000,
90 layout_deferred = 0b10000000000000000,
91 docked = 0b100000000000000000,
93 double_click_fired = 0b1000000000000000000,
94 double_buffered = 0b10000000000000000000,
121 std::any
async_state() const noexcept
override {
return async_state_;}
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>();
149 using base::operator[];
178 this->parent(parent);
206 this->parent(parent);
245 virtual bool auto_size()
const {
return get_state(state::auto_size);}
266 virtual control& back_color(nullptr_t);
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());
377 virtual bool created() {
return get_state(state::created);}
442 set_state(state::double_buffered, double_buffered);
448 virtual bool enabled()
const {
return get_state(state::enabled);}
456 virtual bool focused()
const {
return focused_;}
466 virtual control& fore_color(nullptr_t);
477 virtual control& font(nullptr_t);
486 virtual int32_t
height()
const {
return size_.height();}
491 if (size_.height() !=
height)
503 virtual int32_t
left()
const {
return location_.x();}
508 if (location_.x() != left)
532 if (margin_ != margin)
596 virtual std::optional<control_ref>
parent()
const {
return from_handle(parent_);}
625 if (get_state(state::client_size_setted) || size_ !=
size) {
626 set_state(state::client_size_setted,
false);
636 virtual std::any
tag()
const {
return tag_;}
658 virtual int32_t
top()
const {
return location_.y();}
663 if (location_.y() !=
top)
674 virtual bool visible()
const {
return get_state(state::visible);}
682 virtual int32_t
width()
const {
return size_.width();}
687 if (size_.width() !=
width)
706 if (child.
parent().has_value() && &child.
parent().value().get() == &parent)
714 std::shared_ptr<xtd::iasync_result>
begin_invoke(delegate<
void()> value) {
return begin_invoke(delegate<
void(std::vector<std::any>)>(value), {});}
720 std::shared_ptr<xtd::iasync_result>
begin_invoke(delegate<
void(std::vector<std::any>)> value,
const std::vector<std::any>& args);
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);}
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), {});}
740 template<
typename control_t>
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);
757 template<
typename control_t>
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);
775 template<
typename control_t>
777 std::unique_ptr<control_t> item = std::make_unique<control_t>();
779 if (location !=
drawing::point {-1, -1}) item->location(location);
780 if (size != drawing::size {-1, -1}) item->size(size);
794 template<
typename control_t>
796 std::unique_ptr<control_t> item = std::make_unique<control_t>();
797 item->parent(parent);
799 if (location !=
drawing::point {-1, -1}) item->location(location);
800 if (size != drawing::size {-1, -1}) item->size(size);
859 for (
size_t index = 0;index < controls().size(); ++index)
860 if (controls()[index].get().handle() == child)
return index;
868 throw_exception =
false;
870 return get_child_index(child);
872 throw_exception =
true;
873 return control_collection::npos;
879 virtual void hide() {visible(
false);}
888 virtual void invalidate(
bool invalidate_children)
const {
invalidate({{0, 0}, client_size()}, invalidate_children);}
903 void invoke(delegate<
void()> value) {
invoke(delegate<
void(std::vector<std::any>)>(value), {});}
908 void invoke(delegate<
void(std::vector<std::any>)> value,
const std::vector<std::any>& args) {end_invoke(begin_invoke(value, args));}
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);}
914 template<
typename delegate_t>
915 void invoke(delegate_t value) {invoke(delegate<
void(std::vector<std::any>)>(value), {});}
956 set_state(state::layout_deferred,
false);
957 if (perform_layout) this->perform_layout();
966 intptr_t
send_message(intptr_t hwnd, int32_t msg, intptr_t wparam, intptr_t lparam)
const;
989 virtual void show() {visible(
true);}
997 set_state(state::layout_deferred,
true);
1010 virtual
void update() const;
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;}
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); }
1700 std::optional<drawing::color> back_color_;
1703 bool can_focus_ =
true;
1704 bool can_raise_events_ =
true;
1707 control_collection controls_;
1708 std::optional<forms::cursor> cursor_;
1710 bool focused_ =
false;
1711 std::optional<drawing::color> fore_color_;
1712 std::optional<drawing::font> font_;
1713 intptr_t handle_ = 0;
1721 bool mouse_in_ =
false;
1723 intptr_t parent_ = 0;
1726 control::state state_ = state::empty;
1730 static std::map<intptr_t, control*> handles_;
1731 static control_collection top_level_controls_;
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);
Contains xtd::forms::anchor_styles enum class.
Contains xtd::forms::arranged_element_collection collection.
Contains xtd::forms::auto_size_mode enum class.
Contains xtd::forms::bounds_specified enum class.
The exception that is thrown when one of the arguments provided to a method is not valid.
Definition: argument_exception.h:19
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
static const xtd::drawing::color empty
Represents a color that is null.
Definition: color.h:42
Defines a particular format for text, including font face, size, and style attributes....
Definition: font.h:39
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
An abstract base class that provides functionality for the bitmap and metafile descended classes.
Definition: image.h:34
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
int32_t width() const
Gets the horizontal component of this Size class.
Definition: size.h:67
int32_t height() const
Gets he vertical component of this Size Class.
Definition: size.h:57
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Represents an event.
Definition: event.h:21
Represents the status of an asynchronous operation.
Definition: iasync_result.h:21
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::drawing::color class.
Contains xtd::forms::component class.
Contains xtd::forms::control_event_handler event handler.
Contains xtd::forms::control_ref typedef.
Contains xtd::forms::control_styles enum class.
Contains xtd::forms::cursors factory.
Contains xtd::forms::dock_style enum class.
Contains xtd::drawing::font class.
drawing::graphics create_graphics() const
Creates the xtd::drawing::graphics for the control.
virtual void on_click(const event_args &e)
Raises the control::click event.
virtual void on_back_color_changed(const event_args &e)
Raises the control::back_color_changed event.
virtual void on_auto_size_changed(const event_args &e)
Raises the control::auto_size_changed event.
event< control, event_handler > parent_changed
Occurs when the value of the parent property changes.
Definition: control.h:1378
virtual void on_size_changed(const event_args &e)
Raises the control::size_changed event.
event< control, event_handler > dock_changed
Occurs when the value of the dock property changes.
Definition: control.h:1088
virtual void on_parent_back_color_changed(const event_args &e)
Raises the control::parent_back_color_changed event.
event< control, event_handler > background_image_changed
Occurs when the value of the background_image property changes.
Definition: control.h:1035
virtual void on_got_focus(const event_args &e)
Raises the control::got_focus event.
virtual void on_mouse_up(const mouse_event_args &e)
Raises the control::mouse_up event.
virtual void on_layout(const event_args &e)
Raises the control::layout event.
event< control, event_handler > client_size_changed
Occurs when the value of the client_size property changes.
Definition: control.h:1070
virtual void on_parent_fore_color_changed(const event_args &e)
Raises the control::parent_fore_color_changed event.
event< control, key_event_handler > key_up
Occurs when a key is released while the control has focus.
Definition: control.h:1196
virtual void on_key_up(key_event_args &e)
Raises the control::key_up event.
virtual void on_handle_created(const event_args &e)
Raises the control::handle_created event.
event< control, event_handler > enabled_changed
Occurs when the value of the enabled property changes.
Definition: control.h:1148
virtual void on_parent_changed(const event_args &e)
Raises the control::parent_changed event.
virtual void on_parent_cursor_changed(const event_args &e)
Raises the control::parent_cursor_changed event.
virtual void on_key_down(key_event_args &e)
Raises the control::key_down event.
event< control, event_handler > visible_changed
Occurs when the value of the visible property changes.
Definition: control.h:1402
virtual void on_background_image_changed(const event_args &e)
Raises the control::background_image_changed event.
virtual void on_handle_destroyed(const event_args &e)
Raises the control::handle_destroyed event.
virtual void on_cursor_changed(const event_args &e)
Raises the control::cursor_changed event.
event< control, event_handler > text_changed
Occurs when the value of the text property changes.
Definition: control.h:1397
virtual void on_dock_changed(const event_args &e)
Raises the control::dock_changed event.
event< control, event_handler > layout
Occurs when a control should reposition its child controls.
Definition: control.h:1201
event< control, event_handler > font_changed
Occurs when the value of the font property changes.
Definition: control.h:1158
virtual void on_font_changed(const event_args &e)
Raises the control::font_changed event.
virtual void on_lost_focus(const event_args &e)
Raises the control::lost_focus event.
event< control, event_handler > double_click
Occurs when the control is double-clicked.
Definition: control.h:1112
event< control, event_handler > click
Occurs when the control is clicked.
Definition: control.h:1065
virtual void on_mouse_double_click(const mouse_event_args &e)
Raises the control::mouse_double_click event.
virtual void on_background_image_layout_changed(const event_args &e)
Raises the control::background_image_layout_changed event.
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
virtual void on_paint(paint_event_args &e)
Raises the control::paint event.
event< control, event_handler > handle_created
Occurs when a handle is created for the control.
Definition: control.h:1138
event< control, event_handler > handle_destroyed
Occurs when the control's handle is in the process of being destroyed.
Definition: control.h:1143
virtual void on_create_control()
Raises the control::create_control event.
virtual void on_control_added(const control_event_args &e)
Raises the control::control_added event.
event< control, control_event_handler > control_removed
Occurs when a new control is removed to the control::control_collection.
Definition: control.h:1083
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
virtual void on_double_click(const event_args &e)
Raises the double_click event.
virtual void on_control_removed(const control_event_args &e)
Raises the control::control_removed event.
event< control, event_handler > mouse_enter
Occurs when the mouse pointer enters the control.
Definition: control.h:1292
event< control, event_handler > auto_size_changed
Occurs when the value of the auto_size property changes.
Definition: control.h:1025
event< control, mouse_event_handler > mouse_double_click
Occurs when the control is double clicked by the mouse.
Definition: control.h:1264
virtual void on_resize(const event_args &e)
Raises the control::resize event.
event< control, paint_event_handler > paint
Occurs when the control is redrawn.
Definition: control.h:1373
event< control, event_handler > lost_focus
Occurs when the control loses focus.
Definition: control.h:1228
event< control, event_handler > background_image_layout_changed
Occurs when the value of the background_image_layout property changes.
Definition: control.h:1040
virtual void on_enabled_changed(const event_args &e)
Raises the control::enabled_changed event.
virtual void on_fore_color_changed(const event_args &e)
Raises the control::fore_color_changed event.
virtual void on_location_changed(const event_args &e)
Raises the control::location_changed event.
event< control, event_handler > mouse_leave
Occurs when the mouse pointer leaves the control.
Definition: control.h:1321
event< control, mouse_event_handler > mouse_move
Occurs when the mouse pointer is moved over the control.
Definition: control.h:1335
virtual void on_visible_changed(const event_args &e)
Raises the control::visible_changed event.
virtual void on_mouse_down(const mouse_event_args &e)
Raises the control::mouse_down event.
virtual void on_client_size_changed(const event_args &e)
Raises the control::client_size_changed event.
virtual void on_parent_font_changed(const event_args &e)
Raises the control::parent_font_changed event.
virtual void on_key_press(key_press_event_args &e)
Raises the control::key_press event.
virtual void on_mouse_wheel(const mouse_event_args &e)
Raises the control::mouse_wheel event.
event< control, key_event_handler > key_down
Occurs when a key is pressed while the control has focus.
Definition: control.h:1170
event< control, event_handler > got_focus
Occurs when the control receives focus.
Definition: control.h:1133
event< control, event_handler > location_changed
Occurs when the value of the location property changes.
Definition: control.h:1206
virtual void on_text_changed(const event_args &e)
Raises the control::text_changed event.
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
event< control, mouse_event_handler > mouse_horizontal_wheel
Occurs when the mouse horizontal wheel moves while the control has focus.
Definition: control.h:1307
event< control, mouse_event_handler > mouse_wheel
Occurs when the mouse wheel moves while the control has focus.
Definition: control.h:1364
event< control, event_handler > back_color_changed
Occurs when the value of the back_color property changes.
Definition: control.h:1030
event< control, control_event_handler > control_added
Occurs when a new control is added to the control::control_collection.
Definition: control.h:1079
virtual void on_mouse_horizontal_wheel(const mouse_event_args &e)
Raises the control::mouse_horizontal_wheel event.
event< control, event_handler > fore_color_changed
Occurs when the value of the fore_color property changes.
Definition: control.h:1153
event< control, event_handler > resize
Occurs when the control is resized.
Definition: control.h:1387
virtual void on_mouse_enter(const event_args &e)
Raises the control::mouse_enter event.
event< control, event_handler > cursor_changed
Occurs when the value of the cursor property changes.
Definition: control.h:1075
virtual void on_mouse_leave(const event_args &e)
Raises the control::mouse_leave event.
virtual void on_parent_enabled_changed(const event_args &e)
Raises the xtd::control::enabled_changed event when the xtd::control::enabled property value of the c...
virtual void on_mouse_move(const mouse_event_args &e)
Raises the control::mouse_move event.
event< control, mouse_event_handler > mouse_click
Occurs when the control is clicked by the mouse.
Definition: control.h:1244
virtual void on_mouse_click(const mouse_event_args &e)
Raises the control::mouse_click event.
event< control, event_handler > size_changed
Occurs when the value of the size property changes.
Definition: control.h:1392
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
size_t size
Represents a size of any object in bytes.
Definition: types.h:171
Contains xtd::iasync_result interface.
Contains xtd::forms::image_layout enum class.
Contains xtd::forms::iwin32_window interface.
Contains xtd::forms::key_event_handler event handler.
Contains xtd::forms::key_press_event_handler event handler.
Contains xtd::forms::message class.
Contains xtd::forms::mouse_event_handler event handler.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::forms::padding class.
Contains xtd::forms::paint_event_handler event handler.
Contains xtd::drawing::point class.
Contains xtd::drawing::rectangle class.
Contains xtd::drawing::size class.
Contains xtd::forms::theme_colors class.
Contains xtd::forms::timer component.