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.
application_context.h
Go to the documentation of this file.
1 #pragma once
5 #include <xtd/object.h>
6 #include "form.h"
7 
9 namespace xtd {
11  namespace forms {
13  class application;
15 
26  class application_context : public object {
27  public:
29 
32  application_context() = default;
36  explicit application_context(const form& main_form) {this->main_form(main_form);}
38 
41  if (main_form_ != nullptr) main_form_->handle_destroyed -= {*this, &application_context::on_main_form_closed};
42  }
44 
46 
51  const form& main_form() const {return *main_form_;}
55  form& main_form() {return *main_form_;}
59  void main_form(const form& main_form) {
60  if (main_form_ != nullptr) main_form_->handle_destroyed -= {*this, &application_context::on_main_form_closed};
61  main_form_ = const_cast<form*>(&main_form);
63  }
64 
69  std::any tag() const {return tag_;}
74  void tag(std::any tag) {tag_ = tag;}
76 
78 
85 
87 
94 
95  protected:
100 
105  virtual void on_main_form_closed(object& sender, const event_args& e) {
106  if (!main_form_->visible()) {
107  if (!main_form_->can_close_) main_form_->close();
108  if (main_form_->can_close_) {
111  }
112  }
113  }
114 
115  private:
116  friend class application;
117 
118  form* main_form_ = nullptr;
119  std::any tag_;
120  };
121  }
122 }
Specifies the contextual information about an application thread.
Definition: application_context.h:26
void main_form(const form &main_form)
Sets the Form to use as context.
Definition: application_context.h:59
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
static const event_args empty
Provides a value to use with events that do not have event data.
Definition: event_args.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
event< control, event_handler > visible_changed
Occurs when the value of the visible property changes.
Definition: control.h:1479
void tag(std::any tag)
Sets an object that contains data about the control.
Definition: application_context.h:74
std::any tag() const
Gets an object that contains data about the control.
Definition: application_context.h:69
const form & main_form() const
Gets the form to use as context.
Definition: application_context.h:51
Represents a window or dialog box that makes up an application&#39;s user interface.
Definition: form.h:40
event< control, event_handler > handle_destroyed
Occurs when the control&#39;s handle is in the process of being destroyed.
Definition: control.h:1196
Represents an event.
Definition: event.h:21
application_context()=default
Initializes a new instance of the application_context class with no context.
Contains xtd::forms::form container.
Provides static methods and properties to manage an application, such as methods to start and stop an...
Definition: application.h:54
virtual void on_main_form_closed(object &sender, const event_args &e)
Calls ExitThreadCore(), which raises the ThreadExit event.
Definition: application_context.h:105
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
void exit_thread()
Terminates the message loop of the thread.
Definition: application_context.h:83
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:27
application_context(const form &main_form)
Initializes a new instance of the application_context class with the specified Form.
Definition: application_context.h:36
control & visible(bool visible) override
Sets a value indicating whether the control and all its child controls are displayed.
virtual void exit_thread_core()
Terminates the message loop of the thread.
Definition: application_context.h:99
form & main_form()
Gets or sets the Form to use as context.
Definition: application_context.h:55
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
void close()
Closes the form.
event< application_context, event_handler > thread_exit
Occurs when the message loop of the thread should be terminated, by calling exit_thread().
Definition: application_context.h:92