xtd - Reference Guide  0.1.0
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
form.h
Go to the documentation of this file.
1
4#pragma once
5#include <cstddef>
6#include <xtd/drawing/icon.h>
7#include <xtd/io/path.h>
8#include "form_border_style.h"
11#include "form_start_position.h"
12#include "form_window_state.h"
13#include "container_control.h"
14#include "dialog_result.h"
15#include "ibutton_control.h"
16#include "main_menu.h"
17#include "screen.h"
18
20namespace xtd {
22 namespace forms {
24 class application;
25 class application_context;
27
41 public:
45
48 std::optional<std::reference_wrapper<ibutton_control>> accept_button() const {return accept_button_;}
56 form& accept_button(nullptr_t);
57
60 static std::optional<std::reference_wrapper<form>> active_form() {return active_form_;}
61
64 virtual forms::auto_size_mode auto_size_mode() const {return auto_size_mode_;}
69
72 std::optional<std::reference_wrapper<ibutton_control>> cancel_button() const {return cancel_button_;}
80 form& cancel_button(nullptr_t);
81
84 virtual bool close_box() const {return close_box_;}
88 virtual form& close_box(bool value);
89
92 virtual bool control_box() const {return control_box_;}
96 virtual form& control_box(bool value);
97
98 drawing::size default_size() const override {return {300, 300};}
99
102 virtual forms::dialog_result dialog_result() const {return dialog_result_;}
107
110 virtual forms::form_border_style form_border_style() const {return form_border_style_;}
115
118 virtual const xtd::drawing::icon& icon() const {return icon_;}
122 virtual form& icon(const xtd::drawing::icon& value);
123
126 virtual bool help_button() const {return help_button_;}
130 virtual form& help_button(bool value);
131
134 virtual bool maximize_box() const {return maximize_box_;}
138 virtual form& maximize_box(bool value);
139
142 virtual std::optional<forms::main_menu> menu() const {return menu_;}
146 virtual form& menu(const forms::main_menu& value);
150 virtual form& menu(nullptr_t);
151
154 virtual bool minimize_box() const {return minimize_box_;}
158 virtual form& minimize_box(bool value);
159
162 bool modal() const {return get_state(state::modal);}
163
166 virtual std::optional<control_ref> owner() const {return from_handle(owner_);}
170 virtual form& owner(const control& value);
171
172 using container_control::parent;
175 control& parent(const control& value) override;
176
179 virtual bool show_icon() const {return show_icon_;}
183 virtual form& show_icon(bool value);
184
187 virtual form_start_position start_position() const {return start_position_;}
192
197 virtual bool top_level() const {return get_state(state::top_level);}
202 virtual form& top_level(bool top_level);
203
206 virtual bool top_most() const {return top_most_;}
210 virtual form& top_most(bool value);
211
214 virtual double opacity() const {return opacity_;}
217 virtual form& opacity(double opacity);
218
219 using container_control::visible;
223 control& visible(bool visible) override;
224
227 virtual form_window_state window_state() const {return window_state_;}
232
235 void activate();
236
237 void bring_to_front() override;
238
243
246 void close();
247
249
257
261 virtual void show_sheet(const iwin32_window& owner);
262
267
271
275
279
283
284 protected:
285 friend class application;
286
287 forms::create_params create_params() const override;
288
291 virtual void on_activated(const event_args& e) {activated(*this, e);}
292
295 virtual void on_deactivate(const event_args& e) {deactivate(*this, e);}
296
297 void on_handle_created(const event_args &e) override;
298 void on_handle_destroyed(const event_args &e) override;
299
302 virtual void on_form_closed(const form_closed_event_args& e) {form_closed(*this, e);}
303
306 virtual void on_form_closing(form_closing_event_args& e) {form_closing(*this, e);}
307
308 void on_layout(const event_args& e) override;
309 void on_location_changed(const event_args& e) override;
310 void on_resize(const event_args& e) override;
311 void wnd_proc(message& message) override;
312
316
319 virtual void wm_close(message& message);
320
322 std::optional<std::reference_wrapper<ibutton_control>> accept_button_;
323 std::optional<std::reference_wrapper<ibutton_control>> cancel_button_;
324 static std::optional<std::reference_wrapper<form>> active_form_;
325 bool close_box_ = true;
326 bool control_box_ = true;
327 forms::dialog_result dialog_result_ = forms::dialog_result::none;
328 forms::form_border_style form_border_style_ = form_border_style::sizable;
329 bool help_button_ = true;
330 xtd::drawing::icon icon_ = xtd::drawing::icon::empty;
331 bool maximize_box_ = true;
332 std::optional<forms::main_menu> menu_;
333 bool minimize_box_ = true;
334 std::shared_ptr<screen> previous_screen_;
335 bool show_icon_ = true;
336 bool show_in_taskbar_ = true;
337 form_start_position start_position_ = form_start_position::windows_default_location;
338 form_window_state window_state_ = form_window_state::normal;
340
341 private:
342 friend class application_context;
343 bool can_close_ = false;
344 bool top_most_ = false;
345 intptr_t owner_ = 0;
346 void internal_set_window_state();
347 intptr_t parent_before_show_dialog_ = 0;
348 double opacity_ = 1.0;
349 };
350 }
351}
Represents a Windows icon, which is a small bitmap image that is used to represent an object....
Definition: icon.h:22
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
Represents an event.
Definition: event.h:21
Specifies the contextual information about an application thread.
Definition: application_context.h:26
Provides static methods and properties to manage an application, such as methods to start and stop an...
Definition: application.h:54
Provides focus-management functionality for controls that can function as a container for other contr...
Definition: container_control.h:21
Defines the base class for controls, which are components with visual representation.
Definition: control.h:67
Provides data for the form_closed event.
Definition: form_closed_event_args.h:19
Provides data for the form_closing event.
Definition: form_closing_event_args.h:19
Represents a window or dialog box that makes up an application's user interface.
Definition: form.h:40
void center_to_screen()
Centers the position of the form within the bounds of the parent form.
virtual bool control_box() const
Gets a value indicating whether a control box is displayed in the caption bar of the form.
Definition: form.h:92
virtual forms::dialog_result dialog_result() const
Gets the dialog result for the form.
Definition: form.h:102
virtual bool maximize_box() const
Gets a value indicating whether the Maximize button is displayed in the caption bar of the form.
Definition: form.h:134
void activate()
Activates the form and gives it focus.
virtual forms::dialog_result show_dialog()
Shows the form as a modal dialog box.
virtual void on_form_closing(form_closing_event_args &e)
Raises the form::form_closing event.
Definition: form.h:306
void on_handle_destroyed(const event_args &e) override
Raises the control::handle_destroyed event.
virtual form & top_level(bool top_level)
Sets a value indicating whether to display the form as a top-level window.
virtual form & window_state(form_window_state value)
Sets a value that indicates whether form is minimized, maximized, or normal.
control & visible(bool visible) override
Sets a value indicating whether the control and all its child controls are displayed.
virtual form & dialog_result(forms::dialog_result value)
Sets the dialog result for the form.
virtual form & auto_size_mode(forms::auto_size_mode value)
Sets the mode by which the form automatically resizes itself.
bool pre_process_message(xtd::forms::message &message) override
Preprocesses keyboard or input messages within the message loop before they are dispatched.
virtual form & close_box(bool value)
Sets a value indicating whether a close box is displayed in the caption bar of the form.
void bring_to_front() override
Brings the control to the front of the z-order.
virtual void on_activated(const event_args &e)
Raises the form::activated event.
Definition: form.h:291
virtual form & menu(nullptr_t)
Sets the main_menu that is displayed in the form.
forms::create_params create_params() const override
Gets the required creation parameters when the control handle is created.
form()
Initializes a new instance of the Form class.
virtual form_window_state window_state() const
Gets a value that indicates whether form is minimized, maximized, or normal.
Definition: form.h:227
virtual std::optional< forms::main_menu > menu() const
Gets the main_menu that is displayed in the form.
Definition: form.h:142
virtual form & maximize_box(bool value)
Sets a value indicating whether the Maximize button is displayed in the caption bar of the form.
virtual bool show_icon() const
Gets a value indicating whether an icon is displayed in the caption bar of the form.
Definition: form.h:179
virtual form & control_box(bool value)
Sets a value indicating whether a control box is displayed in the caption bar of the form.
virtual form & top_most(bool value)
Sets a value indicating whether the form should be displayed as a topmost form.
bool modal() const
Gets a value indicating whether this form is displayed modally.
Definition: form.h:162
virtual void on_deactivate(const event_args &e)
Raises the form::deactivate event.
Definition: form.h:295
virtual forms::auto_size_mode auto_size_mode() const
Gets the mode by which the form automatically resizes itself.
Definition: form.h:64
virtual form & owner(const control &value)
Sets the form that owns this form.
virtual form & icon(const xtd::drawing::icon &value)
Sets the icon for the form.
virtual void wm_activate(message &message)
Processes the active message the form control receives as the top-level window.
virtual form & minimize_box(bool value)
Sets a value indicating whether the Minimize button is displayed in the caption bar of the form.
virtual form & help_button(bool value)
Sets a value indicating whether a Help button should be displayed in the caption box of the form.
virtual void show_sheet(const iwin32_window &owner)
Shows the form as a sheet dialog box.
void on_handle_created(const event_args &e) override
Raises the control::handle_created event.
virtual form & show_icon(bool value)
Sets a value indicating whether an icon is displayed in the caption bar of the form.
form & cancel_button(nullptr_t)
Gets the button control that is clicked when the user presses the ESC key.
virtual void wm_close(message &message)
Processes the close message the form control receives as the top-level window.
virtual const xtd::drawing::icon & icon() const
Gets the icon for the form.
Definition: form.h:118
void on_layout(const event_args &e) override
Raises the control::layout event.
virtual void on_form_closed(const form_closed_event_args &e)
Raises the form::form_closed event.
Definition: form.h:302
drawing::size default_size() const override
Gets the default size of the control.
Definition: form.h:98
virtual form & opacity(double opacity)
Sets form opacity.
static std::optional< std::reference_wrapper< form > > active_form()
Gets the currently active form for this application.
Definition: form.h:60
virtual form & menu(const forms::main_menu &value)
Sets the main_menu that is displayed in the form.
std::optional< std::reference_wrapper< ibutton_control > > cancel_button() const
Gets the button control that is clicked when the user presses the ESC key.
Definition: form.h:72
void close()
Closes the form.
virtual bool top_level() const
Gets a value indicating whether to display the form as a top-level window.
Definition: form.h:197
form & accept_button(nullptr_t)
Sets the button on the form that is clicked when the user presses the ENTER key.
virtual std::optional< control_ref > owner() const
Gets the form that owns this form.
Definition: form.h:166
virtual double opacity() const
Gets form opacity.
Definition: form.h:214
virtual forms::form_border_style form_border_style() const
Gets the border style of the form.
Definition: form.h:110
virtual bool minimize_box() const
Gets a value indicating whether the Minimize button is displayed in the caption bar of the form.
Definition: form.h:154
void wnd_proc(message &message) override
Processes Windows messages.
virtual bool close_box() const
Gets a value indicating whether a close box is displayed in the caption bar of the form.
Definition: form.h:84
virtual bool help_button() const
Gets a value indicating whether a Help button should be displayed in the caption box of the form.
Definition: form.h:126
form & accept_button(const ibutton_control &value)
Sets the button on the form that is clicked when the user presses the ENTER key.
virtual forms::dialog_result show_sheet_dialog(const iwin32_window &owner)
Shows the form as a modal sheet dialog box.
virtual form_start_position start_position() const
Gets the starting position of the form at run time.
Definition: form.h:187
control & parent(const control &value) override
Sets the parent container of the control.
std::optional< std::reference_wrapper< ibutton_control > > accept_button() const
Gets the button on the form that is clicked when the user presses the ENTER key.
Definition: form.h:48
form & cancel_button(const ibutton_control &value)
Gets the button control that is clicked when the user presses the ESC key.
virtual form & start_position(form_start_position value)
Sets the starting position of the form at run time.
virtual forms::dialog_result show_dialog(const iwin32_window &owner)
Shows the form as a modal dialog box with the specified owner. @parm owner Any object that implements...
virtual bool top_most() const
Gets a value indicating whether the form should be displayed as a topmost form.
Definition: form.h:206
void on_location_changed(const event_args &e) override
Raises the control::location_changed event.
virtual form & form_border_style(forms::form_border_style value)
Gets the border style of the form.
void on_resize(const event_args &e) override
Raises the control::resize event.
Allows a control to act like a button on a form.
Definition: ibutton_control.h:22
Provides an interface to expose Win32 HWND handles.
Definition: iwin32_window.h:19
Represents the menu structure of a form.
Definition: main_menu.h:30
Implements a Windows message.
Definition: message.h:25
Contains xtd::forms::container_control class.
Contains xtd::forms::dialog_result enum class.
Contains xtd::forms::form_border_style enum class.
Contains xtd::forms::form_closed_event_args event handler.
Contains xtd::forms::form_closing_event_handler event handler.
Contains xtd::forms::form_start_position enum class.
Contains xtd::forms::form_window_state enum class.
event< form, form_closing_event_handler > form_closing
Occurs before the form is closed.
Definition: form.h:282
event< form, form_closed_event_handler > form_closed
Occurs after the form is closed.
Definition: form.h:278
event< form, event_handler > activated
Occurs when the form is activated in code or by the user.
Definition: form.h:270
event< form, event_handler > deactivate
Occurs when the form loses focus and is no longer the active form.
Definition: form.h:274
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
@ e
The E key.
dialog_result
Specifies identifiers to indicate the return value of a dialog box.
Definition: dialog_result.h:39
form_window_state
Specifies how a form window is displayed.
Definition: form_window_state.h:18
auto_size_mode
Specifies how a control will behave when its auto_size property is enabled.
Definition: auto_size_mode.h:18
form_start_position
Specifies the initial position of a form.
Definition: form_start_position.h:18
form_border_style
Specifies the border styles for a form.
Definition: form_border_style.h:18
Contains xtd::forms::ibutton_control interface.
Contains xtd::drawing::icon class.
Contains xtd::forms::main_menu menu.
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::io::path class.
Contains xtd::forms::screen component.