xtd - Reference Guide  0.1.0
Modern c++17 framework to create console, gui and unit test applications on Windows, macOS and Linux.
form.h
1 #pragma once
2 #include <cstddef>
3 #include <xtd/drawing/icon.h>
4 #include <xtd/io/path.h>
5 #include "form_border_style.h"
6 #include "form_closed_event_handler.h"
7 #include "form_closing_event_handler.h"
8 #include "form_start_position.h"
9 #include "form_window_state.h"
10 #include "container_control.h"
11 #include "dialog_result.h"
12 #include "ibutton_control.h"
13 #include "main_menu.h"
14 #include "screen.h"
15 
17 namespace xtd {
19  namespace forms {
21  class application;
22  class application_context;
24 
32  class form : public container_control {
33  public:
36  form();
37 
38  std::optional<std::reference_wrapper<ibutton_control>> accept_button() const {return accept_button_;}
39  form& accept_button(const ibutton_control& value);
40  form& accept_button(nullptr_t);
41 
42  std::optional<std::reference_wrapper<ibutton_control>> cancel_button() const {return cancel_button_;}
43  form& cancel_button(const ibutton_control& value);
44  form& cancel_button(nullptr_t);
45 
46  static std::optional<std::reference_wrapper<form>> active_form() {return active_form_;}
47 
48  virtual forms::auto_size_mode auto_size_mode() const {return auto_size_mode_;}
50 
51  virtual bool close_box() const {return close_box_;}
52  virtual form& close_box(bool value);
53 
54  virtual bool control_box() const {return control_box_;}
55  virtual form& control_box(bool value);
56 
57  drawing::size default_size() const override {return {300, 300};}
58 
59  virtual forms::dialog_result dialog_result() const {return dialog_result_;}
60  virtual form& dialog_result(forms::dialog_result value);
61 
62  virtual const xtd::drawing::icon& icon() const {return icon_;}
63  virtual form& icon(const xtd::drawing::icon& value);
64 
65  virtual forms::form_border_style form_border_style() const {return form_border_style_;}
67 
68  virtual bool help_button() const {return help_button_;}
69  virtual form& help_button(bool value);
70 
71  virtual bool maximize_box() const {return maximize_box_;}
72  virtual form& maximize_box(bool value);
73 
74  virtual std::optional<forms::main_menu> menu() const {return menu_;}
75  virtual form& menu(const forms::main_menu& value);
76  virtual form& menu(nullptr_t);
77 
78  virtual bool minimize_box() const {return minimize_box_;}
79  virtual form& minimize_box(bool value);
80 
81  bool modal() const {return get_state(state::modal);}
82 
83  virtual std::optional<control_ref> owner() const {return from_handle(owner_);}
84  virtual form& owner(const control& value);
85 
86  using container_control::parent;
87  control& parent(const control& value) override;
88 
89  virtual bool show_icon() const {return show_icon_;}
90  virtual form& show_icon(bool value);
91 
92  virtual form_start_position start_position() const {return start_position_;}
93  virtual form& start_position(form_start_position value);
94 
99  virtual bool top_level() const {return get_state(state::top_level);}
104  virtual form& top_level(bool top_level);
105 
106  virtual bool top_most() const {return top_most_;}
107  virtual form& top_most(bool value);
108 
109  void bring_to_front() override;
110 
111  using container_control::visible;
112  control& visible(bool visible) override;
113 
114  virtual form_window_state window_state() const {return window_state_;}
115  virtual form& window_state(form_window_state value);
116 
117  void activate();
118 
119  void center_to_screen();
120 
121  void close();
122 
123  bool pre_process_message(xtd::forms::message& message) override;
124 
125  virtual forms::dialog_result show_dialog();
126 
127  virtual forms::dialog_result show_dialog(const iwin32_window& owner);
128 
129  virtual void show_sheet(const iwin32_window& owner);
130 
131  virtual forms::dialog_result show_sheet_dialog(const iwin32_window& owner);
132 
135 
137 
139 
140  protected:
141  friend class application;
142  forms::create_params create_params() const override;
143 
144  virtual void on_activated(const event_args& e) {activated(*this, e);}
145 
146  virtual void on_deactivate(const event_args& e) {deactivate(*this, e);}
147 
148  void on_handle_created(const event_args &e) override;
149 
150  void on_handle_destroyed(const event_args &e) override;
151 
152  virtual void on_form_closed(const form_closed_event_args& e) {form_closed(*this, e);}
153 
154  virtual void on_form_closing(form_closing_event_args& e) {form_closing(*this, e);}
155 
156  void on_layout(const event_args& e) override;
157 
158  void on_resize(const event_args& e) override;
159 
160  void wnd_proc(message& message) override;
161 
162  virtual void wm_activate(message& message);
163 
164  virtual void wm_close(message& message);
165 
166  std::optional<std::reference_wrapper<ibutton_control>> accept_button_;
167  std::optional<std::reference_wrapper<ibutton_control>> cancel_button_;
168  static std::optional<std::reference_wrapper<form>> active_form_;
169  bool close_box_ = true;
170  bool control_box_ = true;
173  bool help_button_ = true;
174  xtd::drawing::icon icon_ = xtd::drawing::icon::empty;
175  bool maximize_box_ = true;
176  std::optional<forms::main_menu> menu_;
177  bool minimize_box_ = true;
178  std::shared_ptr<screen> previous_screeen_;
179  bool show_icon_ = true;
180  bool show_in_taskbar_ = true;
183 
184  private:
185  friend class application_context;
186  bool can_close_ = false;
187  bool top_most_ = false;
188  intptr_t owner_ = 0;
189  void internal_set_window_state();
190  intptr_t parent_before_show_dialog_ = 0;
191  };
192  }
193 }
Specifies the contextual information about an application thread.
Definition: application_context.h:17
form_window_state
Specifies how a form window is displayed.
Definition: form_window_state.h:10
forms::create_params create_params() const override
Gets the required creation parameters when the control handle is created.
Definition: form_closing_event_args.h:10
Provides focus-management functionality for controls that can function as a container for other contr...
Definition: container_control.h:13
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:8
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:15
Nothing is returned from the dialog box. This means that the modal dialog continues running...
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: action.h:6
form_border_style
Specifies the border styles for a form.
Definition: form_border_style.h:10
Provides an interface to expose Win32 HWND handles.
Definition: iwin32_window.h:10
The default appearance defined by the control class.
Represents a window or dialog box that makes up an application&#39;s user interface.
Definition: form.h:32
Definition: event.h:6
Provides static methods and properties to manage an application, such as methods to start and stop an...
Definition: application.h:37
dialog_result
Specifies identifiers to indicate the return value of a dialog box.
Definition: dialog_result.h:31
form()
Initializes a new instance of the Form class.
Contains xtd::tunit::unit_test class.
Definition: message.h:10
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition: menu.h:25
Defines the base class for controls, which are components with visual representation.
Definition: control.h:60
auto_size_mode
Specifies how a control will behave when its auto_size property is enabled.
Definition: auto_size_mode.h:10
The form is positioned at the Windows default location and has the dimensions specified in the form&#39;s...
virtual bool top_level() const
Gets a value indicating whether to display the form as a top-level window.
Definition: form.h:99
Definition: main_menu.h:15
Allows a control to act like a button on a form.
Definition: ibutton_control.h:14
form_start_position
Specifies the initial position of a form.
Definition: form_start_position.h:10
void wnd_proc(message &message) override
Processes Windows messages.
Definition: icon.h:11
Definition: form_closed_event_args.h:10