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.
Loading...
Searching...
No Matches
application_context.h
Go to the documentation of this file.
1
4#pragma once
5#include <xtd/object.h>
6#include "form.h"
7
9namespace xtd {
11 namespace forms {
13 class application;
15
26 class application_context : public object {
27 public:
33 explicit application_context(const form& main_form) {this->main_form(main_form);}
34
37 if (main_form_ != nullptr) main_form_->handle_destroyed -= {*this, &application_context::on_main_form_closed};
38 }
40
44 const form& main_form() const {return *main_form_;}
48 form& main_form() {return *main_form_;}
52 void main_form(const form& main_form) {
53 if (main_form_ != nullptr) main_form_->handle_destroyed -= {*this, &application_context::on_main_form_closed};
54 main_form_ = const_cast<form*>(&main_form);
56 }
57
62 std::any tag() const {return tag_;}
67 void tag(std::any tag) {tag_ = tag;}
68
72
77
78 protected:
83
88 virtual void on_main_form_closed(object& sender, const event_args& e) {
89 if (!main_form_->visible()) {
90 if (!main_form_->can_close_) main_form_->close();
91 if (main_form_->can_close_) {
94 }
95 }
96 }
97
98 private:
99 friend class application;
100
101 form* main_form_ = nullptr;
102 std::any tag_;
103 };
104 }
105}
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:31
Represents an event.
Definition: event.h:21
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:52
application_context()=default
Initializes a new instance of the application_context class with no context.
void exit_thread()
Terminates the message loop of the thread.
Definition: application_context.h:76
virtual void exit_thread_core()
Terminates the message loop of the thread.
Definition: application_context.h:82
form & main_form()
Gets or sets the Form to use as context.
Definition: application_context.h:48
std::any tag() const
Gets an object that contains data about the control.
Definition: application_context.h:62
const form & main_form() const
Gets the form to use as context.
Definition: application_context.h:44
application_context(const form &main_form)
Initializes a new instance of the application_context class with the specified Form.
Definition: application_context.h:33
virtual void on_main_form_closed(object &sender, const event_args &e)
Calls ExitThreadCore(), which raises the ThreadExit event.
Definition: application_context.h:88
void tag(std::any tag)
Sets an object that contains data about the control.
Definition: application_context.h:67
Provides static methods and properties to manage an application, such as methods to start and stop an...
Definition: application.h:54
Represents a window or dialog box that makes up an application's user interface.
Definition: form.h:40
control & visible(bool visible) override
Sets a value indicating whether the control and all its child controls are displayed.
void close()
Closes the form.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Contains xtd::forms::form container.
event< control, event_handler > visible_changed
Occurs when the value of the visible property changes.
Definition: control.h:1402
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:71
event< control, event_handler > handle_destroyed
Occurs when the control's handle is in the process of being destroyed.
Definition: control.h:1143
@ e
The E key.
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::object class.