Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "gui/dialogs/simple_item_selector.hpp"
00019
00020 #include "foreach.hpp"
00021 #include "gui/widgets/button.hpp"
00022 #include "gui/widgets/label.hpp"
00023 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00024 #include "gui/widgets/list.hpp"
00025 #else
00026 #include "gui/widgets/listbox.hpp"
00027 #endif
00028 #include "gui/widgets/settings.hpp"
00029 #include "gui/widgets/window.hpp"
00030
00031 namespace gui2 {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 REGISTER_DIALOG(simple_item_selector)
00065
00066 tsimple_item_selector::tsimple_item_selector(const std::string& title, const std::string& message, list_type const& items, bool title_uses_markup, bool message_uses_markup)
00067 : index_(-1)
00068 , single_button_(false)
00069 , items_(items)
00070 , ok_label_()
00071 , cancel_label_()
00072 {
00073 register_label("title", true, title, title_uses_markup);
00074 register_label("message", true, message, message_uses_markup);
00075 }
00076
00077 void tsimple_item_selector::pre_show(CVideo& , twindow& window)
00078 {
00079 tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
00080 window.keyboard_capture(&list);
00081
00082 foreach(const tsimple_item_selector::item_type& it, items_) {
00083 std::map<std::string, string_map> data;
00084 string_map column;
00085
00086 column["label"] = it;
00087 data.insert(std::make_pair("item", column));
00088
00089 list.add_row(data);
00090 }
00091
00092 if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
00093 list.select_row(index_);
00094 }
00095
00096 index_ = -1;
00097
00098 tbutton& button_ok = find_widget<tbutton>(&window, "ok", false);
00099 tbutton& button_cancel = find_widget<tbutton>(&window, "cancel", false);
00100
00101 if(!ok_label_.empty()) {
00102 button_ok.set_label(ok_label_);
00103 }
00104
00105 if(!cancel_label_.empty()) {
00106 button_cancel.set_label(cancel_label_);
00107 }
00108
00109 if(single_button_) {
00110 button_cancel.set_visible(gui2::twidget::INVISIBLE);
00111 }
00112 }
00113
00114 void tsimple_item_selector::post_show(twindow& window)
00115 {
00116 if(get_retval() != twindow::OK) {
00117 return;
00118 }
00119
00120 tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
00121 index_ = list.get_selected_row();
00122 }
00123
00124 }