xtd.forms - Reference Guide  0.1.0
Modern c++17 library containing classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows, Apple macOS and Linux like Ubuntu operating system.
xtd::forms::application_context Class Reference

Specifies the contextual information about an application thread. More...

#include <application_context.hpp>

Public Member Functions

 application_context ()=default
 Initializes a new instance of the application_context class with no context. More...
 
 application_context (const form &main_form)
 Initializes a new instance of the application_context class with the specified Form. More...
 
void exit_thread ()
 Terminates the message loop of the thread. More...
 
const formmain_form () const
 Gets the form to use as context. More...
 
formmain_form ()
 Gets or sets the Form to use as context. More...
 
void main_form (const form &main_form)
 Sets the Form to use as context. More...
 
std::any tag () const
 Gets an object that contains data about the control. More...
 
void tag (std::any tag)
 Sets an object that contains data about the control. More...
 

Public Attributes

event< application_context, event_handler< const application_context & > > thread_exit
 Occurs when the message loop of the thread should be terminated, by calling exit_thread(). More...
 

Protected Member Functions

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

Detailed Description

Specifies the contextual information about an application thread.

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.
Example
The following code example demonstrate the use of application and application_context classes.
#include <xtd/xtd.forms>
using namespace xtd::forms;
int main() {
form form1;
form1.click += [&] {
context.main_form(form1);
};
form1.text("Form 1 (Click the client area to set form as the main form)");
form1.show();
form form2;
form2.click += [&] {
context.main_form(form2);
};
form2.text("Form 2 (Click the client area to set form as the main form)");
form2.show();
form form3;
form3.click += [&] {
context.main_form(form3);
};
form3.text("Form 3 (Click the client area to set form as the main form)");
form3.show();
// if no client area form clicked, the application will not exit when you close the forms.
application::run(context);
}

Constructor & Destructor Documentation

§ application_context() [1/2]

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

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)
inlineexplicit

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

§ exit_thread()

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

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 ( )
inlineprotectedvirtual

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.

§ main_form() [1/3]

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

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/3]

form& xtd::forms::application_context::main_form ( )
inline

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/3]

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

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.

§ on_main_form_closed()

virtual void xtd::forms::application_context::on_main_form_closed ( const control sender,
const event_args e 
)
inlineprotectedvirtual

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.

§ tag() [1/2]

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

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)
inline

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.

Member Data Documentation

§ thread_exit

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

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


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