xtd 0.2.0
message_notifier.h
1 #pragma once
3 #include "component.h"
4 #include "iwin32_window.h"
5 #include "message_notifier_button.h"
6 #include "notifier_style.h"
7 #include <xtd/drawing/icon>
8 #include <xtd/chrono>
9 #include <xtd/delegate>
10 #include <xtd/ustring>
11 #include <xtd/event>
12 #include <xtd/event_args>
13 #include <xtd/not_implemented_exception>
14 #include <xtd/optional>
15 
17 namespace xtd {
19  namespace forms {
20  // TODO: IMPL + move to seperate file
22  public:
23  //...
24  explicit notifier_button_click_event_args(const message_notifier_button& button) : button_(button) {}
25 
26  xtd::forms::message_notifier_button button() const noexcept {
27  return button_;
28  }
29 
30  private:
32  //...
33  };
34 
35  using notifier_button_click_event_handler = delegate<void(object& sender, const notifier_button_click_event_args& e)>;
36 
37 
38  // TODO: IMPL + move to seperate file
40  public:
41  explicit notifier_closed_event_args(const std::optional<xtd::forms::message_notifier_button>& button) : button_(button) {}
42 
43  std::optional<xtd::forms::message_notifier_button> button() const noexcept {
44  return button_;
45  }
46 
47  bool close_on_timeout() const noexcept {
48  return close_on_timeout_;
49  }
50 
51  bool close_on_click_message() const noexcept {
52  return close_on_click_message_;
53  }
54 
55  private:
56  bool close_on_timeout_ = false;
57  bool close_on_click_message_ = false;
58  std::optional<xtd::forms::message_notifier_button> button_ = std::nullopt;
59  //...
60  };
61 
62  using notifier_closed_event_handler = delegate<void(object& sender, const notifier_closed_event_args& e)>;
63 
64 
65  class forms_export_ message_notifier final : public component {
66  public:
69 
70  message_notifier() = default;
71 
73 
74  const message_notifier_button_collection& buttons() const noexcept { return buttons_; }
75  message_notifier_button_collection& buttons() noexcept { return buttons_; }
76 
77  std::optional<xtd::forms::message_notifier_button> notifier_button_clicked() const noexcept { return notifier_button_clicked_; }
78 
79  xtd::ustring title() const noexcept { return title_; }
80  message_notifier& title(const xtd::ustring& title) noexcept { title_ = title; return *this; }
81 
82  xtd::ustring message() const noexcept { return message_; }
83  message_notifier& message(const xtd::ustring& message) noexcept { message_ = message; return *this; }
84 
85  const xtd::drawing::image& icon() const noexcept { return icon_; }
86  message_notifier& icon(const xtd::drawing::image& icon) noexcept { icon_ = icon; return *this; }
87  message_notifier& icon(const xtd::drawing::icon& icon) noexcept { icon_ = icon.to_bitmap(); return *this; }
88 
89  bool close_timeout_enabled() const noexcept { return close_timeout_enabled_; }
90  message_notifier& close_timeout_enabled(bool value) noexcept { close_timeout_enabled_ = value; return *this; }
91 
92  std::chrono::milliseconds close_timeout_interval() const noexcept { return close_timeout_interval_; }
93  message_notifier& close_timeout_interval(std::chrono::milliseconds value) noexcept { close_timeout_interval_ = value; return *this;}
94  message_notifier& close_timeout_interval_milliseconds(int32 value) noexcept { close_timeout_interval_ = std::chrono::milliseconds(value); return *this; }
95 
96  xtd::forms::notifier_style notifier_style() const noexcept {return notifier_style_; }
97  message_notifier& notifier_style(xtd::forms::notifier_style notifier_style) noexcept { notifier_style_ = notifier_style; return *this; }
98 
99  void reset();
100 
101  void show();
102  void show(const iwin32_window& owner);
103 
106 
107  protected:
108  virtual void on_notifier_closed(const xtd::forms::notifier_closed_event_args& e) {
109  notifier_closed(*this, e);
110  }
111  virtual void on_button_click(const xtd::forms::notifier_button_click_event_args& e) {
112  button_click(*this, e);
113  }
114 
115  private:
116  xtd::ustring title_;
117  xtd::ustring message_;
119  bool close_timeout_enabled_ = false;
120  std::chrono::milliseconds close_timeout_interval_ = std::chrono::milliseconds(10'000);
121  message_notifier_button_collection buttons_;
122  std::optional<xtd::forms::message_notifier_button> notifier_button_clicked_ = std::nullopt;
123  xtd::forms::notifier_style notifier_style_ = xtd::forms::notifier_style::standard;
124 
125  };
126  }
127 }
128 
Definition: message_notifier.h:65
Definition: message_notifier.h:39
xtd::drawing::bitmap to_bitmap() const
Converts this xtd::drawing::icon to a GDI+ xtd::drawing::bitmap.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Contains xtd::forms::layout::arranged_element_collection collection.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Definition: message_notifier.h:21
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Contains xtd::forms::iwin32_window interface.
Provides an interface to expose Win32 HWND handles.
Definition: iwin32_window.h:21
const message_notifier_button_collection & buttons() const noexcept
Properties.
Definition: message_notifier.h:74
Represents an event.
Definition: event.h:21
Provides a collection of button objects for use by a Windows Forms application.
Definition: buttons.h:23
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:48
Implements a Windows message.
Definition: message.h:26
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
Contains xtd::forms::component class.
Represents a Windows button control.
Definition: button.h:47
Definition: message_notifier_button.h:9
static image empty
Represent an empty xtd::drawing::image.
Definition: image.h:63
Represents a Windows icon, which is a small bitmap image that is used to represent an object...
Definition: icon.h:28
Provides the base implementation and enables object sharing between applications. ...
Definition: component.h:23