00001 /* $Id: language_selection.cpp 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 #define GETTEXT_DOMAIN "wesnoth-lib" 00017 00018 #include "gui/dialogs/language_selection.hpp" 00019 00020 #include "foreach.hpp" 00021 #ifdef GUI2_EXPERIMENTAL_LISTBOX 00022 #include "gui/widgets/list.hpp" 00023 #else 00024 #include "gui/widgets/listbox.hpp" 00025 #endif 00026 #include "gui/widgets/settings.hpp" 00027 #include "gui/widgets/window.hpp" 00028 #include "language.hpp" 00029 #include "preferences.hpp" 00030 00031 namespace gui2 { 00032 00033 /*WIKI 00034 * @page = GUIWindowDefinitionWML 00035 * @order = 2_language_selection 00036 * 00037 * == Language selection == 00038 * 00039 * This shows the dialog to select the language to use. When the dialog is 00040 * closed with the OK button it also updates the selected language in the 00041 * preferences. 00042 * 00043 * @begin{table}{dialog_widgets} 00044 * 00045 * language_list & & listbox & m & 00046 * This listbox contains the list with available languages. $ 00047 * 00048 * - & & control & o & 00049 * Show the name of the language in the current row. $ 00050 * 00051 * @end{table} 00052 */ 00053 00054 /** 00055 * @todo show we also reset the translations and is the tips of day call 00056 * really needed? 00057 */ 00058 00059 REGISTER_DIALOG(language_selection) 00060 00061 void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window) 00062 { 00063 tlistbox& list = find_widget<tlistbox>(&window, "language_list", false); 00064 window.keyboard_capture(&list); 00065 00066 const std::vector<language_def>& languages = get_languages(); 00067 const language_def& current_language = get_language(); 00068 foreach(const language_def& lang, languages) { 00069 string_map item; 00070 item.insert(std::make_pair("label", lang.language)); 00071 00072 list.add_row(item); 00073 if(lang == current_language) { 00074 list.select_row(list.get_item_count() - 1); 00075 } 00076 } 00077 } 00078 00079 void tlanguage_selection::post_show(twindow& window) 00080 { 00081 if(get_retval() == twindow::OK) { 00082 const int res = find_widget<tlistbox>(&window, "language_list", false) 00083 .get_selected_row(); 00084 00085 assert(res != -1); 00086 00087 const std::vector<language_def>& languages = get_languages(); 00088 ::set_language(languages[res]); 00089 preferences::set_language(languages[res].localename); 00090 } 00091 } 00092 00093 } // namespace gui2
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:58 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |