neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
dialog_button_box.hpp
Go to the documentation of this file.
1// dialog_button_box.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
27
28namespace neogfx
29{
30 enum class standard_button : uint32_t
31 {
32 Ok = 0x00000001,
33 Cancel = 0x00000002,
34 Close = 0x00000004,
35 Discard = 0x00000008,
36 Apply = 0x00000010,
37 Reset = 0x00000020,
38 RestoreDefaults = 0x00000040,
39 Yes = 0x00000080,
40 No = 0x00000100,
41 YesToAll = 0x00000200,
42 NoToAll = 0x00000400,
43 Abort = 0x00000800,
44 Retry = 0x00001000,
45 Ignore = 0x00002000,
46 Open = 0x00004000,
47 Save = 0x00008000,
48 SaveAll = 0x00010000,
49 Help = 0x00020000,
50 Custom1 = 0x01000000,
51 Custom2 = 0x02000000,
52 Custom3 = 0x04000000,
53 Custom4 = 0x08000000,
54 Custom5 = 0x10000000,
55 Custom6 = 0x20000000,
56 Custom7 = 0x40000000,
57 Custom8 = 0x80000000
58 };
59
61 {
62 return static_cast<standard_button>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
63 }
64
66 {
67 return static_cast<standard_button>(static_cast<uint32_t>(aLhs) & static_cast<uint32_t>(aRhs));
68 }
69
70 enum class button_role
71 {
72 Invalid,
73 Accept,
74 Reject,
76 Action,
77 Apply,
78 Reset,
79 Yes,
80 No,
81 Help
82 };
83}
84
113
126
127namespace neogfx
128{
129 class dialog_button_box : public widget<>
130 {
131 meta_object(widget<>)
132 public:
133 define_event(Accepted, accepted)
134 define_event(Rejected, rejected)
135 public:
136 define_event(Clicked, clicked, standard_button)
137 public:
138 typedef std::pair<button_role, std::string> button_details;
139 private:
140 typedef std::pair<standard_button, button_role> button_key;
141 struct button_sorter
142 {
143 bool operator()(const button_key& aLhs, const button_key& aRhs) const;
144 };
145 typedef std::multimap<button_key, std::unique_ptr<push_button>, button_sorter> button_list;
146 public:
147 struct button_not_found : std::logic_error { button_not_found() : std::logic_error("neogfx::dialog_button_box::button_not_found") {} };
148 public:
149 dialog_button_box(i_widget& aParent);
150 dialog_button_box(i_layout& aLayout);
151 ~dialog_button_box();
152 public:
153 standard_button button_with_role(button_role aButtonRole) const;
154 button_role role_of_button(standard_button aStandardButton);
155 void enable_role(button_role aButtonRole);
156 void disable_role(button_role aButtonRole);
157 push_button& button(standard_button aStandardButton) const;
158 void add_button(standard_button aStandardButton);
159 void add_button(standard_button aStandardButton, button_role aButtonRole, std::string const& aButtonText);
160 void add_buttons(standard_button aStandardButtons);
161 void set_default_button(standard_button aButton);
162 void clear();
163 i_layout& option_layout();
164 public:
165 static bool has_reject_role(standard_button aStandardButtons);
166 static button_details standard_button_details(standard_button aStandardButton);
167 private:
168 void init();
169 bool can_reject() const;
170 private:
171 static bool similar_role(button_role aButtonRole1, button_role aButtonRole2);
172 private:
173 sink iSink;
174 horizontal_layout iLayout;
175 horizontal_layout iOptionLayout;
176 horizontal_spacer iSpacer;
177 horizontal_layout iStandardButtonLayout;
178 button_list iButtons;
179 std::optional<standard_button> iDefaultButton;
180 };
181}
#define end_declare_enum(enumName)
Definition i_enum.hpp:62
#define declare_enum_string(enumName, enumEnumerator)
Definition i_enum.hpp:59
#define begin_declare_enum(enumName)
Definition i_enum.hpp:52
constexpr style_aspect operator&(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:60
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:55
Definition plf_hive.h:79
#define meta_object(...)
Definition i_object.hpp:28
#define define_event(name, declName,...)
Definition event.hpp:200