00001 /* $Id: multi_page.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/multi_page.hpp" 00019 00020 #include "config.hpp" 00021 #include "foreach.hpp" 00022 #include "gettext.hpp" 00023 #include "gui/auxiliary/log.hpp" 00024 #include "gui/auxiliary/widget_definition/multi_page.hpp" 00025 #include "gui/widgets/multi_page.hpp" 00026 #include "wml_exception.hpp" 00027 00028 namespace gui2 { 00029 00030 namespace implementation { 00031 00032 tbuilder_multi_page::tbuilder_multi_page(const config& cfg) 00033 : implementation::tbuilder_control(cfg) 00034 , builder(NULL) 00035 , data() 00036 { 00037 const config &page = cfg.child("page_definition"); 00038 00039 VALIDATE(page, _("No page defined.")); 00040 builder = new tbuilder_grid(page); 00041 assert(builder); 00042 00043 /** @todo This part is untested. */ 00044 const config &d = cfg.child("page_data"); 00045 if(!d){ 00046 return; 00047 } 00048 00049 foreach(const config &row, d.child_range("row")) { 00050 unsigned col = 0; 00051 00052 foreach(const config &column, row.child_range("column")) { 00053 data.push_back(string_map()); 00054 foreach(const config::attribute &i, column.attribute_range()) { 00055 data.back()[i.first] = i.second; 00056 } 00057 ++col; 00058 } 00059 00060 VALIDATE(col == builder->cols 00061 , _("'list_data' must have " 00062 "the same number of columns as the 'list_definition'.")); 00063 } 00064 } 00065 00066 twidget* tbuilder_multi_page::build() const 00067 { 00068 tmulti_page *widget = new tmulti_page(); 00069 00070 init_control(widget); 00071 00072 widget->set_page_builder(builder); 00073 00074 DBG_GUI_G << "Window builder: placed multi_page '" 00075 << id << "' with definition '" 00076 << definition << "'.\n"; 00077 00078 boost::intrusive_ptr<const tmulti_page_definition::tresolution> conf = 00079 boost::dynamic_pointer_cast 00080 <const tmulti_page_definition::tresolution>(widget->config()); 00081 assert(conf); 00082 00083 widget->init_grid(conf->grid); 00084 00085 widget->finalize(data); 00086 00087 return widget; 00088 } 00089 00090 } // namespace implementation 00091 00092 } // namespace gui2 00093 00094 /*WIKI_MACRO 00095 * @begin{macro}{multi_page_description} 00096 * 00097 * A multi page is a control that contains several 'pages' of which 00098 * only one is visible. The pages can contain the same widgets containing 00099 * the same 'kind' of data or look completely different. 00100 * @end{macro} 00101 */ 00102 00103 /*WIKI 00104 * @page = GUIWidgetInstanceWML 00105 * @order = 2_multi_page 00106 * @begin{parent}{name="gui/window/resolution/grid/row/column/"} 00107 * @begin{tag}{name="multi_page"}{min=0}{max=-1}{super="generic/widget_instance"} 00108 * == Multi page == 00109 * 00110 * @macro = multi_page_description 00111 * 00112 * List with the multi page specific variables: 00113 * @begin{table}{config} 00114 * page_definition & section & & This defines how a multi page item 00115 * looks. It must contain the grid 00116 * definition for at least one page. $ 00117 * 00118 * page_data & section & [] & A grid alike section which stores the 00119 * initial data for the multi page. Every 00120 * row must have the same number of columns 00121 * as the 'page_definition'. $ 00122 * horizontal_scrollbar_mode & scrollbar_mode & initial_auto & 00123 * Determines whether or not to show the 00124 * scrollbar. 00125 * vertical_scrollbar_mode & scrollbar_mode & initial_auto & 00126 * Determines whether or not to show the 00127 * scrollbar. 00128 * @end{table} 00129 * @begin{tag}{name="page_definition"}{min=0}{max=1}{super="gui/window/resolution/grid"} 00130 * @end{tag}{name="page_definition"} 00131 * @begin{tag}{name="page_data"}{min=0}{max=1}{super="gui/window/resolution/grid"} 00132 * @end{tag}{name="page_data"} 00133 * @end{tag}{name="multi_page"} 00134 * @end{parent}{name="gui/window/resolution/grid/row/column/"} 00135 */ 00136
| Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:41 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |