From 10840e969cedee4115afd4c782fe0cb5743ed9cf Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Wed, 6 Aug 2008 12:27:03 +0000 Subject: [PATCH] Move the return values from tbutton to twindow, where it belongs. --- src/addon_management.cpp | 4 ++-- src/game.cpp | 6 ++--- src/gui/dialogs/addon_connect.cpp | 3 +-- src/gui/dialogs/dialog.cpp | 3 +-- src/gui/dialogs/language_selection.cpp | 3 +-- src/gui/dialogs/mp_connect.cpp | 4 ++-- src/gui/dialogs/mp_create_game.cpp | 3 +-- src/gui/dialogs/mp_method_selection.cpp | 3 +-- src/gui/widgets/button.cpp | 22 ------------------- src/gui/widgets/button.hpp | 28 ------------------------ src/gui/widgets/window.cpp | 27 ++++++++++++++++++++--- src/gui/widgets/window.hpp | 29 +++++++++++++++++++++++++ src/gui/widgets/window_builder.cpp | 2 +- src/multiplayer.cpp | 4 ++-- 14 files changed, 68 insertions(+), 73 deletions(-) diff --git a/src/addon_management.cpp b/src/addon_management.cpp index 41d7b0bb6da..b399e6ef473 100644 --- a/src/addon_management.cpp +++ b/src/addon_management.cpp @@ -28,7 +28,7 @@ #include "gui/dialogs/addon_connect.hpp" #include "gui/dialogs/language_selection.hpp" #include "gui/dialogs/mp_method_selection.hpp" -#include "gui/widgets/button.hpp" +#include "gui/widgets/window.hpp" #include "log.hpp" #include "marked-up_text.hpp" #include "network.hpp" @@ -1096,7 +1096,7 @@ void manage_addons(game_display& disp) addon_dlg.show(disp.video()); res = addon_dlg.get_retval(); - if(res == gui2::tbutton::OK) { + if(res == gui2::twindow::OK) { res = 0; remote_host = addon_dlg.host_name(); } diff --git a/src/game.cpp b/src/game.cpp index e10eb9e8de1..e1bd04b7837 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -34,7 +34,7 @@ #include "gui/dialogs/addon_connect.hpp" #include "gui/dialogs/language_selection.hpp" #include "gui/dialogs/mp_method_selection.hpp" -#include "gui/widgets/button.hpp" +#include "gui/widgets/window.hpp" #include "help.hpp" #include "hotkeys.hpp" #include "intro.hpp" @@ -1198,7 +1198,7 @@ bool game_controller::play_multiplayer() dlg.show(disp().video()); - if(dlg.get_retval() == gui2::tbutton::OK) { + if(dlg.get_retval() == gui2::twindow::OK) { res = dlg.get_choice(); } else { return false; @@ -1359,7 +1359,7 @@ bool game_controller::change_language() dlg.show(disp().video()); - if(dlg.get_retval() == gui2::tbutton::OK) { + if(dlg.get_retval() == gui2::twindow::OK) { if(!no_gui_) { std::string wm_title_string = _("The Battle for Wesnoth"); wm_title_string += " - " + game_config::revision; diff --git a/src/gui/dialogs/addon_connect.cpp b/src/gui/dialogs/addon_connect.cpp index 5b128949258..77292712a36 100644 --- a/src/gui/dialogs/addon_connect.cpp +++ b/src/gui/dialogs/addon_connect.cpp @@ -14,7 +14,6 @@ #include "gui/dialogs/addon_connect.hpp" -#include "gui/widgets/button.hpp" #include "gui/widgets/widget.hpp" #include "gui/widgets/window.hpp" #include "gui/widgets/window_builder.hpp" @@ -62,7 +61,7 @@ void taddon_connect::pre_show(CVideo& /*video*/, twindow& window) void taddon_connect::post_show(twindow& window) { - if(get_retval() == tbutton::OK) { + if(get_retval() == twindow::OK) { ttext_box* host_widget = dynamic_cast(window.find_widget("host_name", false)); assert(host_widget); diff --git a/src/gui/dialogs/dialog.cpp b/src/gui/dialogs/dialog.cpp index c7f4a120fbd..7a7dea72d4d 100644 --- a/src/gui/dialogs/dialog.cpp +++ b/src/gui/dialogs/dialog.cpp @@ -16,7 +16,6 @@ #include "foreach.hpp" #include "gui/dialogs/field.hpp" -#include "gui/widgets/button.hpp" #include "gui/widgets/text.hpp" #include "gui/widgets/window.hpp" #include "log.hpp" @@ -48,7 +47,7 @@ void tdialog::show(CVideo& video) retval_ = window.show(true); - if(retval_ == tbutton::OK) { + if(retval_ == twindow::OK) { finalize_fields(window); } diff --git a/src/gui/dialogs/language_selection.cpp b/src/gui/dialogs/language_selection.cpp index 5eca45299bf..a1a563ce8d4 100644 --- a/src/gui/dialogs/language_selection.cpp +++ b/src/gui/dialogs/language_selection.cpp @@ -15,7 +15,6 @@ #include "gui/dialogs/language_selection.hpp" #include "foreach.hpp" -#include "gui/widgets/button.hpp" #include "gui/widgets/listbox.hpp" #include "gui/widgets/settings.hpp" #include "gui/widgets/window.hpp" @@ -76,7 +75,7 @@ void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window) void tlanguage_selection::post_show(twindow& window) { - if(get_retval() == tbutton::OK) { + if(get_retval() == twindow::OK) { tlistbox* list = dynamic_cast(window.find_widget("language_list", false)); assert(list); diff --git a/src/gui/dialogs/mp_connect.cpp b/src/gui/dialogs/mp_connect.cpp index 39f1b4a5483..7d1c7fc6c2a 100644 --- a/src/gui/dialogs/mp_connect.cpp +++ b/src/gui/dialogs/mp_connect.cpp @@ -106,7 +106,7 @@ void tmp_server_list::pre_show(CVideo& /*video*/, twindow& window) void tmp_server_list::post_show(twindow& window) { - if(get_retval() == tbutton::OK) { + if(get_retval() == twindow::OK) { const tlistbox* list = dynamic_cast(window.find_widget("server_list", false)); @@ -193,7 +193,7 @@ void tmp_connect::show_server_list(twindow& window) tmp_server_list dlg; dlg.show(*video_); - if(dlg.get_retval() == tbutton::OK) { + if(dlg.get_retval() == twindow::OK) { host_name_->set_value(window, dlg.host_name()); } } diff --git a/src/gui/dialogs/mp_create_game.cpp b/src/gui/dialogs/mp_create_game.cpp index c8ba7ee776a..6454df66efa 100644 --- a/src/gui/dialogs/mp_create_game.cpp +++ b/src/gui/dialogs/mp_create_game.cpp @@ -21,7 +21,6 @@ #include "gettext.hpp" #include "gui/dialogs/dialog.hpp" #include "gui/dialogs/field.hpp" -#include "gui/widgets/button.hpp" #include "gui/widgets/listbox.hpp" #include "gui/widgets/minimap.hpp" #include "gui/widgets/widget.hpp" @@ -148,7 +147,7 @@ void tmp_create_game::pre_show(CVideo& /*video*/, twindow& window) void tmp_create_game::post_show(twindow& window) { - if(get_retval() == tbutton::OK) { + if(get_retval() == twindow::OK) { tlistbox* list = dynamic_cast(window.find_widget("map_list", false)); assert(list); diff --git a/src/gui/dialogs/mp_method_selection.cpp b/src/gui/dialogs/mp_method_selection.cpp index 0531bf8764c..09b0304605a 100644 --- a/src/gui/dialogs/mp_method_selection.cpp +++ b/src/gui/dialogs/mp_method_selection.cpp @@ -15,7 +15,6 @@ #include "gui/dialogs/mp_method_selection.hpp" #include "game_preferences.hpp" -#include "gui/widgets/button.hpp" #include "gui/widgets/listbox.hpp" #include "gui/widgets/toggle_button.hpp" #include "gui/widgets/widget.hpp" @@ -73,7 +72,7 @@ void tmp_method_selection::pre_show(CVideo& /*video*/, twindow& window) void tmp_method_selection::post_show(twindow& window) { - if(get_retval() == tbutton::OK) { + if(get_retval() == twindow::OK) { ttext_box* user_widget = dynamic_cast(window.find_widget("user_name", false)); assert(user_widget); diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index f77b9e7d1f9..cb40378d77f 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -39,28 +39,6 @@ namespace gui2 { -tbutton::RETVAL tbutton::get_retval_by_id(const std::string& id) -{ -/*WIKI - * @page = GUIToolkitWML - * @order = 3_widget_button_2 - * - * List if the id's that have generate a return value: - * * ok confirms the dialog. - * * cancel cancels the dialog. - * - */ - // Note it might change to a map later depending on the number - // of items. - if(id == "ok") { - return OK; - } else if(id == "cancel") { - return CANCEL; - } else { - return NONE; - } -} - void tbutton::mouse_enter(tevent_handler&) { DBG_G_E << "Button: mouse enter.\n"; diff --git a/src/gui/widgets/button.hpp b/src/gui/widgets/button.hpp index 1c749ffa2de..aa54be60e24 100644 --- a/src/gui/widgets/button.hpp +++ b/src/gui/widgets/button.hpp @@ -33,34 +33,6 @@ public: { } - /***** ***** ***** ***** Return value handling ***** ***** ***** *****/ - - /** - * Default button values. - * - * These values are named return values and most are assigned to a widget - * automatically when using a certain id for that widget. - * - * Note this might be moved somewhere else since it will force people to - * include the button, while it should be and implementation detail for most - * callers. - */ - enum RETVAL { - NONE = 0, /**< - * Dialog is closed with no return - * value, should be rare but eg a - * message popup can do it. - */ - OK = -1, /**< Dialog is closed with ok button. */ - CANCEL = -2 /**< - * Dialog is closed with the cancel - * button. - */ - }; - - /** Gets the retval for the default buttons. */ - static RETVAL get_retval_by_id(const std::string& id); - void set_callback_mouse_left_click(void (*callback) (twidget*)) { callback_mouse_left_click_ = callback; } diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 4aa3dc7bb9b..e7e7e687b36 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -20,7 +20,6 @@ #include "config.hpp" #include "cursor.hpp" #include "font.hpp" -#include "gui/widgets/button.hpp" // due to the return values #include "log.hpp" #include "serialization/parser.hpp" #include "variable.hpp" @@ -83,6 +82,28 @@ twindow::twindow(CVideo& video, help_popup_.set_visible(false); } +twindow::RETVAL twindow::get_retval_by_id(const std::string& id) +{ +/*WIKI + * @page = GUIToolkitWML + * @order = 3_widget_window_2 + * + * List if the id's that have generate a return value: + * * ok confirms the dialog. + * * cancel cancels the dialog. + * + */ + // Note it might change to a map later depending on the number + // of items. + if(id == "ok") { + return OK; + } else if(id == "cancel") { + return CANCEL; + } else { + return NONE; + } +} + int twindow::show(const bool restore, void* /*flip_function*/) { log_scope2(gui_draw, "Window: show."); @@ -192,10 +213,10 @@ void twindow::key_press(tevent_handler& /*event_handler*/, bool& handled, SDLKey key, SDLMod /*modifier*/, Uint16 /*unicode*/) { if(key == SDLK_KP_ENTER || key == SDLK_RETURN) { - set_retval(tbutton::OK); + set_retval(OK); handled = true; } else if(key == SDLK_ESCAPE) { - set_retval(tbutton::CANCEL); + set_retval(CANCEL); handled = true; } } diff --git a/src/gui/widgets/window.hpp b/src/gui/widgets/window.hpp index 09420dbf9a6..77dd9c7f4c4 100644 --- a/src/gui/widgets/window.hpp +++ b/src/gui/widgets/window.hpp @@ -62,6 +62,35 @@ public: const unsigned vertical_placement, const std::string& definition); + /***** ***** ***** ***** Return value handling ***** ***** ***** *****/ + + /** + * Default return values. + * + * These values are named return values and most are assigned to a widget + * automatically when using a certain id for that widget. The automatic + * return values are always a negative number. + * + * Note this might be moved somewhere else since it will force people to + * include the button, while it should be and implementation detail for most + * callers. + */ + enum RETVAL { + NONE = 0, /**< + * Dialog is closed with no return + * value, should be rare but eg a + * message popup can do it. + */ + OK = -1, /**< Dialog is closed with ok button. */ + CANCEL = -2 /**< + * Dialog is closed with the cancel + * button. + */ + }; + + /** Gets the retval for the default buttons. */ + static RETVAL get_retval_by_id(const std::string& id); + // show the window // The flip function is the disp_.flip() if ommitted the video_flip() is used int show(const bool restore = true, void* flip_function = 0); diff --git a/src/gui/widgets/window_builder.cpp b/src/gui/widgets/window_builder.cpp index a04604e4624..f3b8a567521 100644 --- a/src/gui/widgets/window_builder.cpp +++ b/src/gui/widgets/window_builder.cpp @@ -535,7 +535,7 @@ twidget* tbuilder_button::build() const if(retval_) { button->set_retval(retval_); } else { - button->set_retval(tbutton::get_retval_by_id(id)); + button->set_retval(twindow::get_retval_by_id(id)); } DBG_G << "Window builder: placed button '" << id << "' with defintion '" diff --git a/src/multiplayer.cpp b/src/multiplayer.cpp index 7847447bb79..30aa2a59576 100644 --- a/src/multiplayer.cpp +++ b/src/multiplayer.cpp @@ -20,7 +20,7 @@ #include "gettext.hpp" #include "gui/dialogs/mp_connect.hpp" #include "gui/dialogs/mp_create_game.hpp" -#include "gui/widgets/button.hpp" +#include "gui/widgets/window.hpp" #include "log.hpp" #include "multiplayer.hpp" #include "multiplayer_ui.hpp" @@ -141,7 +141,7 @@ static server_type open_connection(game_display& disp, const std::string& origin gui2::tmp_connect dlg; dlg.show(disp.video()); - if(dlg.get_retval() == gui2::tbutton::OK) { + if(dlg.get_retval() == gui2::twindow::OK) { h = preferences::network_host(); } else { return ABORT_SERVER;