The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
message.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GUI_DIALOGS_MESSAGE_HPP_INCLUDED
16 #define GUI_DIALOGS_MESSAGE_HPP_INCLUDED
17 
18 #include "gui/dialogs/dialog.hpp"
19 #include "gui/widgets/control.hpp"
20 
21 namespace gui2
22 {
23 
24 class tbutton;
25 
26 /**
27  * Main class to show messages to the user.
28  *
29  * It can be used to show a message or ask a result from the user. For the
30  * most common usage cases there are helper functions defined.
31  */
32 class tmessage : public tdialog
33 {
34  friend struct tmessage_implementation;
35 
36 public:
37  tmessage(const std::string& title,
38  const std::string& message,
39  const bool auto_close,
40  const bool message_use_markup)
41  : title_(title)
42  , image_()
43  , message_(message)
44  , auto_close_(auto_close)
45  , message_use_markup_(message_use_markup)
46  , buttons_(count)
47  {
48  }
49 
50  enum tbutton_id {
51  left_1 = 0,
53  ok,
56  };
57 
58  /**
59  * Selects the style of the buttons to be shown.
60  *
61  * These values are not directly implemented in this class but are used
62  * by our helper functions.
63  */
65  auto_close /**< Enables auto close. */
66  ,
67  ok_button /**< Shows an ok button. */
68  ,
69  close_button /**< Shows a close button. */
70  ,
71  ok_cancel_buttons /**< Shows an ok and cancel button. */
72  ,
73  cancel_button /**< Shows a cancel button. */
74  ,
75  yes_no_buttons /**< Shows a yes and no button. */
76  };
77 
78  void set_button_caption(const tbutton_id button,
79  const std::string& caption);
80 
81  void set_button_visible(const tbutton_id button,
82  const twidget::tvisible::scoped_enum visible);
83 
84  void set_button_retval(const tbutton_id button, const int retval);
85 
86  /***** ***** ***** setters / getters for members ***** ****** *****/
87 
88  void set_title(const std::string& title)
89  {
90  title_ = title;
91  }
92 
94  {
95  image_ = image;
96  }
97 
99  {
100  message_ = message;
101  }
102 
103  void set_auto_close(const bool auto_close)
104  {
106  }
107 
108 protected:
109  /** Inherited from tdialog. */
110  void pre_show(twindow& window);
111 
112  /** Inherited from tdialog. */
113  void post_show(twindow& window);
114 
115 private:
116  /** The title for the dialog. */
118 
119  /**
120  * The image which is shown in the dialog.
121  *
122  * This image can be an icon or portrait or any other image.
123  */
125 
126  /** The message to show to the user. */
128 
129  /**
130  * Does the window need to use click_dismiss when the dialog doesn't need a
131  * scrollbar.
132  */
134 
135  /** Whether to enable formatting markup for the dialog message. */
137 
139  {
140  tbutton_status();
141 
145  int retval;
146  };
147 
148  /** Holds a pointer to the buttons. */
149  std::vector<tbutton_status> buttons_;
150 
151  /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
152  virtual const std::string& window_id() const;
153 };
154 
155 /**
156  * Shows a message to the user.
157  *
158  * Normally the dialog won't have a button only when the text doesn't fit in
159  * the dialog and a scrollbar is used the button will be shown.
160  *
161  * @param video The video which contains the surface to draw upon.
162  * @param title The title of the dialog.
163  * @param message The message to show in the dialog.
164  * @param button_caption The caption of the close button.
165  * @param auto_close When true the window will hide the ok button
166  * when the message doesn't need a scrollbar to
167  * show itself.
168  */
169 void show_message(CVideo& video,
170  const std::string& title,
171  const std::string& message,
172  const std::string& button_caption = "",
173  const bool auto_close = true,
174  const bool message_use_markup = false);
175 
176 /**
177  * Shows a message to the user.
178  *
179  * @note this function is rather untested, and the API might change in the
180  * near future.
181  *
182  * @param video The video which contains the surface to draw
183  * upon.
184  * @param title The title of the dialog.
185  * @param message The message to show in the dialog.
186  * @param button_style The style of the button(s) shown.
187  * @param message_use_markup Use markup for the message?
188  * @param title_use_markup Use markup for the title?
189  *
190  * @returns The retval of the dialog shown.
191  */
192 int show_message(CVideo& video,
193  const std::string& title,
194  const std::string& message,
195  const tmessage::tbutton_style button_style,
196  bool message_use_markup = false,
197  bool title_use_markup = false);
198 
199 /**
200  * Shows an error message to the user.
201  *
202  * @param video The video which contains the surface to draw
203  * upon.
204  * @param message The message to show in the dialog.
205  * @param message_use_markup Use markup for the message?
206  */
207 void show_error_message(CVideo& video,
208  const std::string& message,
209  bool message_use_markup = false);
210 
211 } // namespace gui2
212 
213 #endif
void set_title(const std::string &title)
Definition: message.hpp:88
void show_error_message(CVideo &video, const std::string &message, bool message_use_markup)
Shows an error message to the user.
Definition: message.cpp:198
void set_message(const std::string &message)
Definition: message.hpp:98
Definition: video.hpp:58
std::vector< tbutton_status > buttons_
Holds a pointer to the buttons.
Definition: message.hpp:149
Enables auto close.
Definition: message.hpp:65
Main class to show messages to the user.
Definition: message.hpp:32
std::string title_
The title for the dialog.
Definition: message.hpp:117
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:3783
twidget::tvisible::scoped_enum visible
Definition: message.hpp:144
Helper to implement private functions without modifying the header.
Definition: message.cpp:39
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Simple push button.
Definition: button.hpp:32
Shows a close button.
Definition: message.hpp:69
Abstract base class for all dialogs.
Definition: dialog.hpp:121
void set_button_retval(const tbutton_id button, const int retval)
Definition: message.cpp:127
void show_message(CVideo &video, const std::string &title, const std::string &message, const std::string &button_caption, const bool auto_close, const bool message_use_markup)
Shows a message to the user.
Definition: message.cpp:143
Shows an ok and cancel button.
Definition: message.hpp:71
tbutton_style
Selects the style of the buttons to be shown.
Definition: message.hpp:64
std::string message_
The message to show to the user.
Definition: message.hpp:127
bool message_use_markup_
Whether to enable formatting markup for the dialog message.
Definition: message.hpp:136
void set_auto_close(const bool auto_close)
Definition: message.hpp:103
GLuint GLuint GLsizei count
Definition: glew.h:1221
void set_image(const std::string &image)
Definition: message.hpp:93
Shows a cancel button.
Definition: message.hpp:73
virtual const std::string & window_id() const
Inherited from tdialog, implemented by REGISTER_DIALOG.
bool auto_close_
Does the window need to use click_dismiss when the dialog doesn't need a scrollbar.
Definition: message.hpp:133
void pre_show(twindow &window)
Inherited from tdialog.
Definition: message.cpp:65
std::string image_
The image which is shown in the dialog.
Definition: message.hpp:124
tmessage(const std::string &title, const std::string &message, const bool auto_close, const bool message_use_markup)
Definition: message.hpp:37
void post_show(twindow &window)
Inherited from tdialog.
Definition: message.cpp:101
void set_button_visible(const tbutton_id button, const twidget::tvisible::scoped_enum visible)
Definition: message.cpp:118
this module manages the cache of images.
Definition: image.cpp:75
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
Shows an ok button.
Definition: message.hpp:67
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Shows a yes and no button.
Definition: message.hpp:75
void set_button_caption(const tbutton_id button, const std::string &caption)
Definition: message.cpp:109