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.
form.h
Go to the documentation of this file.
1 #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 
20 namespace xtd {
22  namespace forms {
24  class application;
25  class application_context;
27 
40  class forms_export_ form : public container_control {
41  public:
44  form();
45 
48  std::optional<std::reference_wrapper<ibutton_control>> accept_button() const {return accept_button_;}
52  form& accept_button(const ibutton_control& value);
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_;}
76  form& cancel_button(const ibutton_control& value);
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_;}
106  virtual form& dialog_result(forms::dialog_result value);
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<std::reference_wrapper<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 
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_;}
191  virtual form& start_position(form_start_position value);
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 
223  control& visible(bool visible) override;
224 
227  virtual form_window_state window_state() const {return window_state_;}
231  virtual form& window_state(form_window_state value);
232 
235  void activate();
236 
237  void bring_to_front() override;
238 
242  void center_to_screen();
243 
246  void close();
247 
248  bool pre_process_message(xtd::forms::message& message) override;
249 
252  virtual forms::dialog_result show_dialog();
256  virtual forms::dialog_result show_dialog(const iwin32_window& owner);
257 
261  virtual void show_sheet(const iwin32_window& owner);
262 
266  virtual forms::dialog_result show_sheet_dialog(const iwin32_window& owner);
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 
315  virtual void wm_activate(message& message);
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;
329  bool help_button_ = true;
330  xtd::drawing::icon icon_ = xtd::drawing::icon::empty;
331  bool maximize_box_ = true;
332  std::optional<std::reference_wrapper<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;
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 }
event< form, form_closing_event_handler > form_closing
Occurs before the form is closed.
Definition: form.h:282
Specifies the contextual information about an application thread.
Definition: application_context.h:26
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
virtual std::optional< std::reference_wrapper< forms::main_menu > > menu() const
Gets the main_menu that is displayed in the form.
Definition: form.h:142
Contains xtd::drawing::icon class.
Provides data for the form_closing event.
Definition: form_closing_event_args.h:19
dialog_result
Specifies identifiers to indicate the return value of a dialog box.
Definition: dialog_result.h:39
Provides focus-management functionality for controls that can function as a container for other contr...
Definition: container_control.h:21
The default appearance defined by the control class.
Nothing is returned from the dialog box. This means that the modal dialog continues running...
form_border_style
Specifies the border styles for a form.
Definition: form_border_style.h:18
event< form, form_closed_event_handler > form_closed
Occurs after the form is closed.
Definition: form.h:278
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
form_start_position
Specifies the initial position of a form.
Definition: form_start_position.h:18
virtual bool top_most() const
Gets a value indicating whether the form should be displayed as a topmost form.
Definition: form.h:206
form_window_state
Specifies how a form window is displayed.
Definition: form_window_state.h:18
virtual form_start_position start_position() const
Gets the starting position of the form at run time.
Definition: form.h:187
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
Contains xtd::forms::screen component.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
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
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
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
virtual forms::auto_size_mode auto_size_mode() const
Gets the mode by which the form automatically resizes itself.
Definition: form.h:64
auto_size_mode
Specifies how a control will behave when its auto_size property is enabled.
Definition: auto_size_mode.h:18
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
bool modal() const
Gets a value indicating whether this form is displayed modally.
Definition: form.h:162
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 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
drawing::size default_size() const override
Gets the default size of the control.
Definition: form.h:98
Provides an interface to expose Win32 HWND handles.
Definition: iwin32_window.h:19
virtual bool top_level() const
Gets a value indicating whether to display the form as a top-level window.
Definition: form.h:197
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
Represents a window or dialog box that makes up an application&#39;s user interface.
Definition: form.h:40
Represents an event.
Definition: event.h:21
The form is positioned at the Windows default location and has the dimensions specified in the form&#39;s...
Provides static methods and properties to manage an application, such as methods to start and stop an...
Definition: application.h:54
virtual form_window_state window_state() const
Gets a value that indicates whether form is minimized, maximized, or normal.
Definition: form.h:227
Contains xtd::forms::container_control class.
virtual bool visible() const
Gets a value indicating whether the control and all its child controls are displayed.
Definition: control.h:702
Contains xtd::forms::dialog_result enum class.
Contains xtd::io::path class.
virtual void on_activated(const event_args &e)
Raises the form::activated event.
Definition: form.h:291
event< form, event_handler > deactivate
Occurs when the form loses focus and is no longer the active form.
Definition: form.h:274
Implements a Windows message.
Definition: message.h:25
Contains xtd::forms::form_border_style enum class.
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
Contains xtd::forms::form_window_state enum class.
virtual void on_deactivate(const event_args &e)
Raises the form::deactivate event.
Definition: form.h:295
virtual std::optional< control_ref > parent() const
Gets the parent container of the control.
Definition: control.h:624
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual forms::dialog_result dialog_result() const
Gets the dialog result for the form.
Definition: form.h:102
virtual const xtd::drawing::icon & icon() const
Gets the icon for the form.
Definition: form.h:118
Contains xtd::forms::ibutton_control interface.
Contains xtd::forms::form_closed_event_args event handler.
Represents the menu structure of a form.
Definition: main_menu.h:32
event< form, event_handler > activated
Occurs when the form is activated in code or by the user.
Definition: form.h:270
virtual void on_form_closed(const form_closed_event_args &e)
Raises the form::form_closed event.
Definition: form.h:302
Allows a control to act like a button on a form.
Definition: ibutton_control.h:22
Contains xtd::forms::form_start_position enum class.
static std::optional< std::reference_wrapper< form > > active_form()
Gets the currently active form for this application.
Definition: form.h:60
Contains xtd::forms::form_closing_event_handler event handler.
Represents a Windows icon, which is a small bitmap image that is used to represent an object...
Definition: icon.h:22
virtual std::optional< control_ref > owner() const
Gets the form that owns this form.
Definition: form.h:166
virtual void on_form_closing(form_closing_event_args &e)
Raises the form::form_closing event.
Definition: form.h:306
Provides data for the form_closed event.
Definition: form_closed_event_args.h:19
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