xtd 1.0.0
Loading...
Searching...
No Matches
xtd::forms::application_context Class Reference
Inheritance diagram for xtd::forms::application_context:
xtd::object

Definition

Specifies the contextual information about an application thread.

Header
#include <xtd/forms/application_context>
Namespace
xtd::forms
Library
xtd.forms
Remarks
You can use the application_context class to redefine the circumstances that cause a message loop to exit. By default, the application_context listens to the closed event on the application's main form, then exits the thread's message loop.
Examples
The following code example demonstrates the use of application and application_context classes.
#include <xtd/xtd>
auto main() -> int {
auto context = application_context {};
auto form1 = form::create("Form 1 (Click the client area to set form as the main form)");
form1.click += delegate_ {context.main_form(form1);};
form1.show();
auto form2 = form::create("Form 2 (Click the client area to set form as the main form)");
form2.click += delegate_ {context.main_form(form2);};
form2.show();
auto form3 = form::create("Form 3 (Click the client area to set form as the main form)");
form3.click += delegate_ {context.main_form(form3);};
form3.show();
// if no client area form clicked, the application will not exit when you close the forms.
application::run(context);
}
application_context()
Initializes a new instance of the application_context class with no context.
static auto create() -> form
A factory to create an xtd::forms::form.
#define delegate_
The declaration of a delegate type is similar to a method signature. It has a return value and any nu...
Definition delegate.hpp:1018

Protected Member Functions

virtual auto exit_thread_core () -> void
 Terminates the message loop of the thread.
virtual auto on_main_form_closed (object &sender, const event_args &e) -> void
 Calls ExitThreadCore(), which raises the ThreadExit event.

Public Events

event< application_context, event_handlerthread_exit
 Occurs when the message loop of the thread should be terminated, by calling exit_thread().

Public Constructors

 application_context ()
 Initializes a new instance of the application_context class with no context.
 application_context (const form &main_form) noexcept
 Initializes a new instance of the application_context class with the specified Form.

Public Properties

auto main_form () const noexcept -> std::optional< const_form_ref >
 Gets the form to use as context.
auto main_form () noexcept -> std::optional< form_ref >
 Gets or sets the Form to use as context.
auto main_form (const form &main_form) -> void
 Sets the Form to use as context.
auto main_form (std::nullptr_t) -> void
 Resets the Form to use as context.
auto tag () const noexcept -> xtd::any_object
 Gets an object that contains data about the control.
auto tag (const xtd::any_object &tag) -> void
 Sets an object that contains data about the control.

Public Methods

auto exit_thread () -> void
 Terminates the message loop of the thread.

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
virtual auto equals (const object &obj) const noexcept -> bool
 Determines whether the specified object is equal to the current object.
virtual auto get_hash_code () const noexcept -> xtd::usize
 Serves as a hash function for a particular type.
virtual auto get_type () const noexcept -> type_object
 Gets the type of the current instance.
template<typename object_t>
auto memberwise_clone () const -> xtd::unique_ptr_object< object_t >
 Creates a shallow copy of the current object.
virtual auto to_string () const -> xtd::string
 Returns a xtd::string that represents the current object.
template<typename object_a_t, typename object_b_t>
static auto equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static auto reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are the same instance.

Constructor & Destructor Documentation

◆ application_context() [1/2]

xtd::forms::application_context::application_context ( )

Initializes a new instance of the application_context class with no context.

◆ application_context() [2/2]

xtd::forms::application_context::application_context ( const form & main_form)
explicitnoexcept

Initializes a new instance of the application_context class with the specified Form.

Parameters
main_formThe main form of the application to use for context.
Remarks
If on_main_form_closed is not overridden, the message loop of the thread terminates when main_form is closed.

Member Function Documentation

◆ main_form() [1/4]

auto xtd::forms::application_context::main_form ( ) const -> std::optional< const_form_ref >
nodiscardnoexcept

Gets the form to use as context.

Returns
The form to use as context.
Remarks
This property determines the main form for this context. This property can change at any time. If on_main_form_closed is not overridden, the message loop of the thread terminates when the main_form parameter closes.

◆ main_form() [2/4]

auto xtd::forms::application_context::main_form ( ) -> std::optional< form_ref >
nodiscardnoexcept

Gets or sets the Form to use as context.

Returns
The form to use as context.
Remarks
This property determines the main form for this context. This property can change at any time. If on_main_form_closed is not overridden, the message loop of the thread terminates when the main_form parameter closes.

◆ main_form() [3/4]

auto xtd::forms::application_context::main_form ( const form & main_form) -> void

Sets the Form to use as context.

Parameters
main_formThe form to use as context.
Remarks
This property determines the main form for this context. This property can change at any time. If on_main_form_closed is not overridden, the message loop of the thread terminates when the main_form parameter closes.

◆ main_form() [4/4]

auto xtd::forms::application_context::main_form ( std::nullptr_t ) -> void

Resets the Form to use as context.

Parameters
nullptr
Remarks
This property determines the main form for this context. This property can change at any time. If on_main_form_closed is not overridden, the message loop of the thread terminates when the main_form parameter closes.

◆ tag() [1/2]

auto xtd::forms::application_context::tag ( ) const -> xtd::any_object
nodiscardnoexcept

Gets an object that contains data about the control.

Returns
A xtd::any_object that contains data about the control. The default is empty.
Remarks
Any type of class can be assigned to this property.
A common use for the tag property is to store data that is closely associated with the control. For example, if you have a control that displays information about a customer, you might store a data_set that contains the customer's order history in that control's tag property so the data can be accessed quickly.

◆ tag() [2/2]

auto xtd::forms::application_context::tag ( const xtd::any_object & tag) -> void

Sets an object that contains data about the control.

Parameters
tagA xtd::any_object that contains data about the control. The default is empty.
Remarks
Any type of class can be assigned to this property.
A common use for the tag property is to store data that is closely associated with the control. For example, if you have a control that displays information about a customer, you might store a data_set that contains the customer's order history in that control's tag property so the data can be accessed quickly.

◆ exit_thread()

auto xtd::forms::application_context::exit_thread ( ) -> void

Terminates the message loop of the thread.

Remarks
This method calls exit_thread_core.
Note
exit_thread and exit_thread_core do not actually cause the thread to terminate. These methods raise the thread_exit event to which the Application object listens. The Application object then terminates the thread.

◆ exit_thread_core()

virtual auto xtd::forms::application_context::exit_thread_core ( ) -> void
protectedvirtual

Terminates the message loop of the thread.

Remarks
This method is called from exit_thread.
Note
exit_thread and exit_thread_core do not actually cause the thread to terminate. These methods raise the thread_exit event to which the Application object listens. The Application object then terminates the thread.

◆ on_main_form_closed()

virtual auto xtd::forms::application_context::on_main_form_closed ( object & sender,
const event_args & e ) -> void
protectedvirtual

Calls ExitThreadCore(), which raises the ThreadExit event.

Parameters
senderThe object that raised the event.
eThe event_args that contains the event data.
Remarks
The default implementation of this method calls exit_thread_core.

Member Data Documentation

◆ thread_exit

event<application_context, event_handler> xtd::forms::application_context::thread_exit

Occurs when the message loop of the thread should be terminated, by calling exit_thread().

Remarks
For more information about handling events, see Handling and Raising Events.

The documentation for this class was generated from the following file: