gui/auxiliary/window_builder/horizontal_listbox.cpp

Go to the documentation of this file.
00001 /* $Id: horizontal_listbox.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/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); // FIXME in finalize???
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 } // namespace implementation
00115 
00116 } // namespace gui2
00117 
00118 /*WIKI_MACRO
00119  * @begin{macro}{horizontal_listbox_description}
00120  *
00121  *        A horizontal listbox is a control that holds several items of the
00122  *        same type.  Normally the items in a listbox are ordered in rows,
00123  *        this version orders them in columns instead.
00124  * @end{macro}
00125  */
00126 
00127 /*WIKI
00128  * @page = GUIWidgetInstanceWML
00129  * @order = 2_horizontal_listbox
00130  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
00131  * @begin{tag}{name="horizontal_listbox"}{min="0"}{max="-1"}{super="generic/widget_instance"}
00132  * == Horizontal listbox ==
00133  *
00134  * @macro = horizontal_listbox_description
00135  *
00136  * List with the horizontal listbox specific variables:
00137  * @begin{table}{config}
00138  *     vertical_scrollbar_mode & scrollbar_mode & initial_auto &
00139  *                                     Determines whether or not to show the
00140  *                                     scrollbar. $
00141  *     horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
00142  *                                     Determines whether or not to show the
00143  *                                     scrollbar. $
00144  *
00145  *     list_definition & section & &   This defines how a listbox item
00146  *                                     looks. It must contain the grid
00147  *                                     definition for 1 column of the list. $
00148  *
00149  *     list_data & section & [] &      A grid alike section which stores the
00150  *                                     initial data for the listbox. Every row
00151  *                                     must have the same number of columns as
00152  *                                     the 'list_definition'. $
00153  *
00154  * @end{table}
00155  * @begin{tag}{name="header"}{min=0}{max=1}{super="gui/window/resolution/grid"}
00156  * @end{tag}{name="header"}
00157  * @begin{tag}{name="footer"}{min=0}{max=1}{super="gui/window/resolution/grid"}
00158  * @end{tag}{name="footer"}
00159  * @begin{tag}{name="list_definition"}{min=0}{max=1}
00160  * @begin{tag}{name="row"}{min=1}{max=1}{super="generic/listbox_grid/row"}
00161  * @end{tag}{name="row"}
00162  * @end{tag}{name="list_definition"}
00163  * @begin{tag}{name="list_data"}{min=0}{max=1}{super="generic/listbox_grid"}
00164  * @end{tag}{name="list_data"}
00165  * In order to force widgets to be the same size inside a horizontal listbox,
00166  * the widgets need to be inside a linked_group.
00167  *
00168  * Inside the list section there are only the following widgets allowed
00169  * * grid (to nest)
00170  * * selectable widgets which are
00171  * ** toggle_button
00172  * ** toggle_panel
00173  * @end{tag}{name="horizontal_listbox"}
00174  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
00175  */
00176 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:57 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs