gui/dialogs/message.hpp

Go to the documentation of this file.
00001 /* $Id: message.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef GUI_DIALOGS_MESSAGE_HPP_INCLUDED
00017 #define GUI_DIALOGS_MESSAGE_HPP_INCLUDED
00018 
00019 #include "gui/dialogs/dialog.hpp"
00020 #include "gui/widgets/control.hpp"
00021 
00022 namespace gui2 {
00023 
00024 class tbutton;
00025 
00026 /**
00027  * Main class to show messages to the user.
00028  *
00029  * It can be used to show a message or ask a result from the user. For the
00030  * most common usage cases there are helper functions defined.
00031  */
00032 class tmessage : public tdialog
00033 {
00034     friend struct tmessage_implementation;
00035 public:
00036     tmessage(const std::string& title, const std::string& message,
00037             const bool auto_close)
00038         : title_(title)
00039         , image_()
00040         , message_(message)
00041         , auto_close_(auto_close)
00042         , buttons_(count)
00043     {}
00044 
00045     enum tbutton_id {
00046           left_1 = 0
00047         , cancel
00048         , ok
00049         , right_1
00050         , count
00051     };
00052 
00053     /**
00054      * Selects the style of the buttons to be shown.
00055      *
00056      * These values are not directly implemented in this class but are used
00057      * by our helper functions.
00058      */
00059     enum tbutton_style
00060     {
00061           auto_close        /**< Enables auto close. */
00062         , ok_button         /**< Shows an ok button. */
00063         , close_button      /**< Shows a close button. */
00064         , ok_cancel_buttons /**< Shows an ok and cancel button. */
00065         , cancel_button     /**< Shows a cancel button. */
00066         , yes_no_buttons    /**< Shows a yes and no button. */
00067     };
00068 
00069     void set_button_caption(const tbutton_id button,
00070             const std::string& caption);
00071 
00072     void set_button_visible(const tbutton_id button,
00073             const twidget::tvisible visible);
00074 
00075     void set_button_retval(const tbutton_id button,
00076             const int retval);
00077 
00078     /***** ***** ***** setters / getters for members ***** ****** *****/
00079 
00080     void set_title(const std::string& title) {  title_ = title; }
00081 
00082     void set_image(const std::string& image) {  image_ = image; }
00083 
00084     void set_message(const std::string& message) {  message_ = message; }
00085 
00086     void set_auto_close(const bool auto_close) { auto_close_ = auto_close; }
00087 
00088 protected:
00089     /** Inherited from tdialog. */
00090     void pre_show(CVideo& video, twindow& window);
00091 
00092     /** Inherited from tdialog. */
00093     void post_show(twindow& window);
00094 
00095 private:
00096     /** The title for the dialog. */
00097     std::string title_;
00098 
00099     /**
00100      * The image which is shown in the dialog.
00101      *
00102      * This image can be an icon or portrait or any other image.
00103      */
00104     std::string image_;
00105 
00106     /** The message to show to the user. */
00107     std::string message_;
00108 
00109     /**
00110      * Does the window need to use click_dismiss when the dialog doesn't need a
00111      * scrollbar.
00112      */
00113     bool auto_close_;
00114 
00115     struct tbutton_status
00116     {
00117         tbutton_status();
00118 
00119         tbutton* button;
00120         std::string caption;
00121         twidget::tvisible visible;
00122         int retval;
00123     };
00124 
00125     /** Holds a pointer to the buttons. */
00126     std::vector<tbutton_status> buttons_;
00127 
00128     /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
00129     virtual const std::string& window_id() const;
00130 };
00131 
00132 /**
00133  * Shows a message to the user.
00134  *
00135  * Normally the dialog won't have a button only when the text doesn't fit in
00136  * the dialog and a scrollbar is used the button will be shown.
00137  *
00138  * @param video               The video which contains the surface to draw upon.
00139  * @param title               The title of the dialog.
00140  * @param message             The message to show in the dialog.
00141  * @param button_caption      The caption of the close button.
00142  * @param auto_close          When true the window will hide the ok button
00143  *                            when the message doesn't need a scrollbar to
00144  *                            show itself.
00145  */
00146 void show_message(CVideo& video, const std::string& title,
00147     const std::string& message, const std::string& button_caption = "",
00148     const bool auto_close = true);
00149 
00150 /**
00151  * Shows a message to the user.
00152  *
00153  * @note this function is rather untested, and the API might change in the
00154  * near future.
00155  *
00156  * @param video               The video which contains the surface to draw
00157  *                            upon.
00158  * @param title               The title of the dialog.
00159  * @param message             The message to show in the dialog.
00160  * @param button_style        The style of the button(s) shown.
00161  * @param message_use_markup  Use markup for the message?
00162  * @param title_use_markup    Use markup for the title?
00163  *
00164  * @returns                   The retval of the dialog shown.
00165  */
00166 int show_message(CVideo& video, const std::string& title,
00167     const std::string& message, const tmessage::tbutton_style button_style,
00168     bool message_use_markup = false,
00169     bool title_use_markup = false);
00170 
00171 /**
00172  * Shows an error message to the user.
00173  *
00174  * @param video               The video which contains the surface to draw
00175  *                            upon.
00176  * @param message             The message to show in the dialog.
00177  * @param message_use_markup  Use markup for the message?
00178  */
00179 void show_error_message(CVideo& video, const std::string& message,
00180     bool message_use_markup = false);
00181 
00182 } // namespace gui2
00183 
00184 #endif
00185 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:39 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs