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/auxiliary/window_builder/horizontal_listbox.hpp"
00019
00020 #include "foreach.hpp"
00021 #include "gettext.hpp"
00022 #include "gui/auxiliary/log.hpp"
00023 #include "gui/auxiliary/widget_definition/listbox.hpp"
00024 #include "gui/auxiliary/window_builder/helper.hpp"
00025 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00026 #include "gui/widgets/list.hpp"
00027 #else
00028 #include "gui/widgets/listbox.hpp"
00029 #endif
00030 #include "wml_exception.hpp"
00031
00032 namespace gui2 {
00033
00034 namespace implementation {
00035
00036 tbuilder_horizontal_listbox::tbuilder_horizontal_listbox(const config& cfg)
00037 : tbuilder_control(cfg)
00038 , vertical_scrollbar_mode(
00039 get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
00040 , horizontal_scrollbar_mode(
00041 get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
00042 , list_builder(NULL)
00043 , list_data()
00044 {
00045 const config &l = cfg.child("list_definition");
00046
00047 VALIDATE(l, _("No list defined."));
00048 list_builder = new tbuilder_grid(l);
00049 assert(list_builder);
00050 VALIDATE(list_builder->rows == 1
00051 , _("A 'list_definition' should contain one row."));
00052
00053 const config &data = cfg.child("list_data");
00054 if (!data) return;
00055
00056 foreach(const config &row, data.child_range("row")) {
00057 unsigned col = 0;
00058
00059 foreach(const config &c, row.child_range("column")) {
00060 list_data.push_back(string_map());
00061 foreach (const config::attribute &i, c.attribute_range()) {
00062 list_data.back()[i.first] = i.second;
00063 }
00064 ++col;
00065 }
00066
00067 VALIDATE(col == list_builder->cols, _("'list_data' must have "
00068 "the same number of columns as the 'list_definition'."));
00069 }
00070 }
00071
00072 twidget* tbuilder_horizontal_listbox::build() const
00073 {
00074 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00075 tlist *widget = new tlist(true
00076 , true
00077 , tgenerator_::horizontal_list
00078 , true
00079 , list_builder);
00080
00081 init_control(widget);
00082 if(!list_data.empty()) {
00083 widget->append_rows(list_data);
00084 }
00085 return widget;
00086 #else
00087 tlistbox *widget = new tlistbox(
00088 true, true, tgenerator_::horizontal_list, true);
00089
00090 init_control(widget);
00091
00092 widget->set_list_builder(list_builder);
00093
00094 widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
00095 widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
00096
00097 DBG_GUI_G << "Window builder: placed listbox '"
00098 << id << "' with definition '"
00099 << definition << "'.\n";
00100
00101 boost::intrusive_ptr<const tlistbox_definition::tresolution> conf =
00102 boost::dynamic_pointer_cast
00103 <const tlistbox_definition::tresolution>(widget->config());
00104 assert(conf);
00105
00106 widget->init_grid(conf->grid);
00107
00108 widget->finalize(NULL, NULL, list_data);
00109
00110 return widget;
00111 #endif
00112 }
00113
00114 }
00115
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176