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/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 #include "gui/widgets/grid.hpp"
00026 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00027 #include "gui/widgets/list.hpp"
00028 #else
00029 #include "gui/widgets/listbox.hpp"
00030 #endif
00031 #include "gui/widgets/pane.hpp"
00032 #include "gui/widgets/viewport.hpp"
00033 #include "gui/widgets/settings.hpp"
00034 #include "wml_exception.hpp"
00035
00036 namespace gui2 {
00037
00038 namespace implementation {
00039
00040 tbuilder_listbox::tbuilder_listbox(const config& cfg)
00041 : tbuilder_control(cfg)
00042 , vertical_scrollbar_mode(
00043 get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
00044 , horizontal_scrollbar_mode(
00045 get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
00046 , header(NULL)
00047 , footer(NULL)
00048 , list_builder(NULL)
00049 , list_data()
00050 {
00051 if(const config &h = cfg.child("header")) {
00052 header = new tbuilder_grid(h);
00053 }
00054
00055 if(const config &f = cfg.child("footer")) {
00056 footer = new tbuilder_grid(f);
00057 }
00058
00059 const config &l = cfg.child("list_definition");
00060
00061 VALIDATE(l, _("No list defined."));
00062 list_builder = new tbuilder_grid(l);
00063 assert(list_builder);
00064 VALIDATE(list_builder->rows == 1
00065 , _("A 'list_definition' should contain one row."));
00066
00067 const config &data = cfg.child("list_data");
00068 if(!data) {
00069 return;
00070 }
00071
00072 foreach(const config& row, data.child_range("row")) {
00073 unsigned col = 0;
00074
00075 foreach(const config& c, row.child_range("column")) {
00076 list_data.push_back(string_map());
00077 foreach(const config::attribute& i, c.attribute_range()) {
00078 list_data.back()[i.first] = i.second;
00079 }
00080 ++col;
00081 }
00082
00083 VALIDATE(col == list_builder->cols
00084 , _("'list_data' must have the same number of "
00085 "columns as the 'list_definition'."));
00086 }
00087 }
00088
00089 twidget* tbuilder_listbox::build() const
00090 {
00091 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00092 tlist *widget = new tlist(true
00093 , true
00094 , tgenerator_::vertical_list
00095 , true
00096 , list_builder);
00097
00098 init_control(widget);
00099 if(!list_data.empty()) {
00100 widget->append_rows(list_data);
00101 }
00102 return widget;
00103 #else
00104 if(new_widgets) {
00105
00106 tpane *pane = new tpane(list_builder);
00107 pane->set_id(id);
00108
00109
00110 tgrid* grid = new tgrid();
00111 grid->set_rows_cols(1, 1);
00112 #if 0
00113 grid->set_child(
00114 pane
00115 , 0
00116 , 0
00117 , tgrid::VERTICAL_GROW_SEND_TO_CLIENT
00118 | tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT
00119 , tgrid::BORDER_ALL);
00120 #else
00121 tviewport *viewport = new tviewport(*pane);
00122 grid->set_child(
00123 viewport
00124 , 0
00125 , 0
00126 , tgrid::VERTICAL_GROW_SEND_TO_CLIENT
00127 | tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT
00128 , tgrid::BORDER_ALL);
00129 #endif
00130 return grid;
00131 }
00132
00133 tlistbox *widget = new tlistbox(
00134 true, true, tgenerator_::vertical_list, true);
00135
00136 init_control(widget);
00137
00138 widget->set_list_builder(list_builder);
00139
00140 widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
00141 widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
00142
00143 DBG_GUI_G << "Window builder: placed listbox '"
00144 << id << "' with definition '"
00145 << definition << "'.\n";
00146
00147 boost::intrusive_ptr<const tlistbox_definition::tresolution> conf =
00148 boost::dynamic_pointer_cast
00149 <const tlistbox_definition::tresolution>(widget->config());
00150 assert(conf);
00151
00152 widget->init_grid(conf->grid);
00153
00154 widget->finalize(header, footer, list_data);
00155
00156 return widget;
00157 #endif
00158 }
00159
00160 }
00161
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252