xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
common_dialog.h
Go to the documentation of this file.
1 #pragma once
5 #include <any>
6 #include <chrono>
7 #include <thread>
8 #include "application.h"
9 #include "form.h"
10 #include "component.h"
12 #include "dialog_result.h"
13 #include "help_event_handler.h"
14 #include "iwin32_window.h"
15 
17 struct __xtd_forms_common_dialog_closed_caller__;
19 
21 namespace xtd {
23  namespace forms {
31  class common_dialog : public component {
32  public:
34  common_dialog() = default;
35 
38  xtd::forms::dialog_result dialog_result() const {return dialog_result_;}
39 
43  std::any tag() const {return tag_;}
47  common_dialog& tag(const std::any& tag) {
48  tag_ = tag;
49  return*this;
50  }
51 
55  virtual void reset() = 0;
56 
61  auto form = form::active_form();
62  dialog_result_ = run_dialog(0) ? dialog_result::ok : dialog_result::cancel;
64  if (form.has_value()) form.value().get().activate();
65  return dialog_result_;
66  }
67 
73  auto form = form::active_form();
74  dialog_result_ = run_dialog(owner.handle()) ? dialog_result::ok : dialog_result::cancel;
76  if (form.has_value()) form.value().get().activate();
77  return dialog_result_;
78  }
79 
83  void show_sheet(const iwin32_window& owner) {
84  dialog_result_ = xtd::forms::dialog_result::none;
85  run_sheet(owner.handle());
86  }
87 
92  show_sheet(owner);
93  while (dialog_result_ == xtd::forms::dialog_result::none) {
95  std::this_thread::sleep_for(std::chrono::milliseconds(100));
96  }
97  return dialog_result_;
98  }
99 
103 
107 
108  protected:
110  friend struct ::__xtd_forms_common_dialog_closed_caller__;
112 
117  dialog_result_ = e.dialog_result();
118  dialog_closed(*this, e);
119  }
120 
124  virtual void on_help_request(help_event_args& e) {help_request(*this, e);}
125 
129  virtual bool run_dialog(intptr_t hwnd_owner) = 0;
130 
135  virtual void run_sheet(intptr_t hwnd_owner) = 0;
136 
138  std::any tag_;
141  };
142  }
143 }
Contains xtd::forms::application class.
Represents an event.
Definition: event.h:21
static void do_events()
Processes all Windows messages currently in the message queue.
Specifies the base class used for displaying dialog boxes on the screen.
Definition: common_dialog.h:31
virtual void on_help_request(help_event_args &e)
Raises the common_dialog::help_request event.
Definition: common_dialog.h:124
xtd::forms::dialog_result show_dialog(const iwin32_window &owner)
Runs a common dialog box with the specified owner.
Definition: common_dialog.h:72
std::any tag() const
Gets an object that contains data about the control.
Definition: common_dialog.h:43
virtual void run_sheet(intptr_t hwnd_owner)=0
When overridden in a derived class, specifies a common dialog box.
xtd::forms::dialog_result show_dialog()
Runs a common dialog box with a default owner.
Definition: common_dialog.h:60
xtd::forms::dialog_result dialog_result() const
Get async dialog_result result after dialog box is closing.
Definition: common_dialog.h:38
virtual void reset()=0
When overridden in a derived class, resets the properties of a common dialog box to their default val...
common_dialog()=default
Initializes a new instance of the common_dialog class.
common_dialog & tag(const std::any &tag)
Sets an object that contains data about the control.
Definition: common_dialog.h:47
xtd::forms::dialog_result show_sheet_dialog(const iwin32_window &owner)
Runs a common dialog box with the specified owner.
Definition: common_dialog.h:91
void show_sheet(const iwin32_window &owner)
Runs a common dialog box with the specified owner.
Definition: common_dialog.h:83
virtual bool run_dialog(intptr_t hwnd_owner)=0
When overridden in a derived class, specifies a common dialog box.
virtual void on_dialog_closed(const dialog_closed_event_args &e)
Raises the common_dialog::dialog_close event.
Definition: common_dialog.h:116
Provides the base implementation and enables object sharing between applications.
Definition: component.h:21
Provides data for a dialog closed event.
Definition: dialog_closed_event_args.h:17
Represents a window or dialog box that makes up an application's user interface.
Definition: form.h:40
void activate()
Activates the form and gives it focus.
static std::optional< std::reference_wrapper< form > > active_form()
Gets the currently active form for this application.
Definition: form.h:60
Provides data for the control_added and control_removed events.
Definition: help_event_args.h:22
Provides an interface to expose Win32 HWND handles.
Definition: iwin32_window.h:19
virtual intptr_t handle() const =0
Gets the handle to the window represented by the implementer.
Contains xtd::forms::component class.
Contains xtd::forms::dialog_closed_event_handler dialog.
Contains xtd::forms::dialog_result enum class.
Contains xtd::forms::form container.
event< common_dialog, dialog_closed_event_handler > dialog_closed
Occurs when the user close a common dialog box with dialog close button or other dialog buttons.
Definition: common_dialog.h:106
event< common_dialog, help_event_handler > help_request
Occurs when the user clicks the Help button on a common dialog box.
Definition: common_dialog.h:102
@ e
The E key.
dialog_result
Specifies identifiers to indicate the return value of a dialog box.
Definition: dialog_result.h:39
@ cancel
The dialog box return value is Cancel (usually sent from a button labeled Cancel).
@ none
Nothing is returned from the dialog box. This means that the modal dialog continues running.
@ ok
The dialog box return value is OK (usually sent from a button labeled OK).
Contains xtd::forms::help_event_handler event handler.
Contains xtd::forms::iwin32_window interface.
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