Move the return values from tbutton to twindow, where it belongs.

This commit is contained in:
Mark de Wever 2008-08-06 12:27:03 +00:00
parent dc88a59cc8
commit 10840e969c
14 changed files with 68 additions and 73 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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<ttext_box*>(window.find_widget("host_name", false));
assert(host_widget);

View File

@ -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);
}

View File

@ -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<tlistbox*>(window.find_widget("language_list", false));
assert(list);

View File

@ -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<tlistbox*>(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());
}
}

View File

@ -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<tlistbox*>(window.find_widget("map_list", false));
assert(list);

View File

@ -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<ttext_box*>(window.find_widget("user_name", false));
assert(user_widget);

View File

@ -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";

View File

@ -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; }

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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 '"

View File

@ -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;