xtd 0.2.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/forms/application>
#include <xtd/forms/application_context>
#include <xtd/forms/form>
using namespace xtd::forms;
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 += [&] {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 += [&] {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 += [&] {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);
}
Specifies the contextual information about an application thread.
Definition application_context.h:26
static void run()
Begins running a standard application message loop on the current thread, without a form.
static form create()
A factory to create an xtd::forms::form.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
Examples
application_context.cpp.

Protected Member Functions

virtual void exit_thread_core ()
 Terminates the message loop of the thread.
 
virtual void on_main_form_closed (object &sender, const event_args &e)
 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

std::optional< const_form_refmain_form () const noexcept
 Gets the form to use as context.
 
std::optional< form_refmain_form () noexcept
 Gets or sets the Form to use as context.
 
void main_form (const form &main_form)
 Sets the Form to use as context.
 
void main_form (std::nullptr_t)
 Resets the Form to use as context.
 
std::any tag () const noexcept
 Gets an object that contains data about the control.
 
void tag (std::any tag)
 Sets an object that contains data about the control.
 

Public Methods

void exit_thread ()
 Terminates the message loop of the thread.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const noexcept
 Returns a xtd::string that represents the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 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]

std::optional< const_form_ref > xtd::forms::application_context::main_form ( ) const
noexcept

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]

std::optional< form_ref > xtd::forms::application_context::main_form ( )
noexcept

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]

void xtd::forms::application_context::main_form ( const form main_form)

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]

void xtd::forms::application_context::main_form ( std::nullptr_t  )

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]

std::any xtd::forms::application_context::tag ( ) const
noexcept

Gets an object that contains data about the control.

Returns
A std::any 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]

void xtd::forms::application_context::tag ( std::any  tag)

Sets an object that contains data about the control.

Parameters
tagA std::any 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()

void xtd::forms::application_context::exit_thread ( )

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 void xtd::forms::application_context::exit_thread_core ( )
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 void xtd::forms::application_context::on_main_form_closed ( object sender,
const event_args e 
)
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: