gui/auxiliary/window_builder/tree_view.cpp

Go to the documentation of this file.
00001 /* $Id: tree_view.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2010 - 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/tree_view.hpp"
00019 
00020 #include "foreach.hpp"
00021 #include "gettext.hpp"
00022 #include "gui/auxiliary/log.hpp"
00023 #include "gui/auxiliary/widget_definition/tree_view.hpp"
00024 #include "gui/auxiliary/window_builder/helper.hpp"
00025 #include "gui/widgets/tree_view.hpp"
00026 #include "wml_exception.hpp"
00027 
00028 namespace gui2 {
00029 
00030 namespace implementation {
00031 
00032 tbuilder_tree_view::tbuilder_tree_view(const config& cfg)
00033     : tbuilder_control(cfg)
00034     , vertical_scrollbar_mode(
00035             get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
00036     , horizontal_scrollbar_mode(
00037             get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
00038     , indention_step_size(cfg["indention_step_size"])
00039     , nodes()
00040 {
00041 
00042     foreach(const config &node, cfg.child_range("node")) {
00043         nodes.push_back(tnode(node));
00044     }
00045 
00046     VALIDATE(!nodes.empty(), _("No nodes defined for a tree view."));
00047 }
00048 
00049 twidget* tbuilder_tree_view::build() const
00050 {
00051     /*
00052      *  TODO see how much we can move in the constructor instead of
00053      *  builing in several steps.
00054      */
00055     ttree_view *widget = new ttree_view(nodes);
00056 
00057     init_control(widget);
00058 
00059     widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
00060     widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
00061 
00062     widget->set_indention_step_size(indention_step_size);
00063 
00064     DBG_GUI_G << "Window builder: placed tree_view '"
00065             << id << "' with definition '"
00066             << definition << "'.\n";
00067 
00068     boost::intrusive_ptr<const ttree_view_definition::tresolution> conf =
00069             boost::dynamic_pointer_cast
00070                 <const ttree_view_definition::tresolution>(widget->config());
00071     assert(conf);
00072 
00073     widget->init_grid(conf->grid);
00074     widget->finalize_setup();
00075 
00076     return widget;
00077 }
00078 
00079 tbuilder_tree_view::tnode::tnode(const config& cfg)
00080     : id(cfg["id"])
00081     , builder(NULL)
00082 {
00083     VALIDATE(!id.empty(), missing_mandatory_wml_key("node", "id"));
00084 
00085     VALIDATE(id != "root"
00086             , _("[node]id 'root' is reserved for the implementation."));
00087 
00088     const config& node_definition = cfg.child("node_definition");
00089 
00090     VALIDATE(node_definition, _("No node defined."));
00091 
00092     builder = new tbuilder_grid(node_definition);
00093 }
00094 
00095 } // namespace implementation
00096 
00097 } // namespace gui2
00098 
00099 /*WIKI_MACRO
00100  * @begin{macro}{tree_view_description}
00101  *
00102  *        A tree view is a control that holds several items of the same or
00103  *        different types. The items shown are called tree view nodes and when
00104  *        a node has children, these can be shown or hidden. Nodes that contain
00105  *        children need to provide a clickable button in order to fold or
00106  *        unfold the children.
00107  * @end{macro}
00108  */
00109 
00110 /*WIKI
00111  * @page = GUIWidgetInstanceWML
00112  * @order = 2_tree_view
00113  *
00114  * == Tree view ==
00115  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
00116  * @begin{tag}{name="tree_view"}{min=0}{max=-1}{super="generic/widget_instance"}
00117  * @macro = tree_view_description
00118  *
00119  * List with the tree view specific variables:
00120  * @begin{table}{config}
00121  *     vertical_scrollbar_mode & scrollbar_mode & initial_auto &
00122  *                                     Determines whether or not to show the
00123  *                                     scrollbar. $
00124  *     horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
00125  *                                     Determines whether or not to show the
00126  *                                     scrollbar. $
00127  *
00128  *     indention_step_size & unsigned & 0 &
00129  *                                     The number of pixels every level of
00130  *                                     nodes is indented from the previous
00131  *                                     level. $
00132  *
00133  *     node & section &  &             The tree view can contain multiple node
00134  *                                     sections. This part needs more
00135  *                                     documentation. $
00136  * @end{table}
00137  * @begin{tag}{name="node"}{min=0}{max=-1}
00138  * @begin{table}{config}
00139  *     id & string & "" &  $
00140  * @end{table}
00141  * @begin{tag}{name="node_definition"}{min=0}{max=-1}{super="gui/window/resolution/grid"}
00142  * @begin{table}{config}
00143  *     return_value_id & string & "" &  $
00144  * @end{table}
00145  * @end{tag}{name="node_definition"}
00146  * @end{tag}{name="node"}
00147  * @end{tag}{name="tree_view"}
00148  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
00149  * NOTE more documentation and examples are needed.
00150  */ // TODO annotate node
00151 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:42 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs