gui/widgets/tree_view_node.hpp

Go to the documentation of this file.
00001 /* $Id: tree_view_node.hpp 54007 2012-04-28 19:16:10Z mordante $ */
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 #ifndef GUI_WIDGETS_TREE_VIEW_NODE_HPP_INCLUDED
00017 #define GUI_WIDGETS_TREE_VIEW_NODE_HPP_INCLUDED
00018 
00019 #include "gui/auxiliary/window_builder/tree_view.hpp"
00020 
00021 #include <boost/ptr_container/ptr_vector.hpp>
00022 
00023 namespace gui2 {
00024 
00025 class tselectable_;
00026 class ttoggle_button;
00027 class ttree_view;
00028 
00029 class ttree_view_node
00030     : public twidget
00031 {
00032     friend struct ttree_view_node_implementation;
00033     friend class ttree_view;
00034 
00035 public:
00036 
00037     typedef implementation::tbuilder_tree_view::tnode tnode_definition;
00038     ttree_view_node(const std::string& id
00039             , const std::vector<tnode_definition>& node_definitions
00040             , ttree_view_node* parent_node
00041             , ttree_view& parent_tree_view
00042             , const std::map<std::string /* widget id */, string_map>& data);
00043 
00044     ~ttree_view_node();
00045 
00046     /**
00047      * Adds a child item to the list of child nodes.
00048      *
00049      * @param id                  The id of the node definition to use for the
00050      *                            new node.
00051      * @param data                The data to send to the set_members of the
00052      *                            widgets. If the member id is not an empty
00053      *                            string it is only send to the widget that has
00054      *                            the wanted id (if any). If the member id is an
00055      *                            empty string, it is send to all members.
00056      *                            Having both empty and non-empty id's gives
00057      *                            undefined behaviour.
00058      * @param index               The item before which to add the new item,
00059      *                            0 == begin, -1 == end.
00060      */
00061     ttree_view_node& add_child(const std::string& id
00062             , const std::map<std::string /* widget id */, string_map>& data
00063             , const int index = -1);
00064 
00065     /**
00066      * Adds a sibbling for a node at the end of the list.
00067      *
00068      * @param id                  The id of the node definition to use for the
00069      *                            new node.
00070      * @param data                The data to send to the set_members of the
00071      *                            widgets. If the member id is not an empty
00072      *                            string it is only send to the widget that has
00073      *                            the wanted id (if any). If the member id is an
00074      *                            empty string, it is send to all members.
00075      *                            Having both empty and non-empty id's gives
00076      *                            undefined behaviour.
00077      */
00078     ttree_view_node& add_sibling(const std::string& id
00079             , const std::map<std::string /* widget id */, string_map>& data)
00080     {
00081         assert(!is_root_node());
00082         return parent_node().add_child(id, data);
00083     }
00084 
00085     /**
00086      * Is this node the root node?
00087      *
00088      * When the parent tree view is created it adds one special node, the root
00089      * node. This node has no parent node and some other special features so
00090      * several code paths need to check whether they are the parent node.
00091      */
00092     bool is_root_node() const { return parent_node_ == NULL; }
00093 
00094     /**
00095      * The indention level of the node.
00096      *
00097      * The root node starts at level 0.
00098      */
00099     unsigned get_indention_level() const;
00100 
00101     /** Does the node have children? */
00102     bool empty() const { return children_.empty(); }
00103 
00104     /** Is the node folded? */
00105     bool is_folded() const;
00106 
00107 #if 0
00108     enum texpand_mode
00109     {
00110           recursive_restore // recursively restores collapse mode
00111         , recursive_expand // recursively expands the children
00112         , not_recursive
00113     };
00114 
00115 
00116 
00117     // If recursive all children will be closed recursively causing
00118     // restore expaning not to expand anything
00119 //      void fold(const bool recursive); // FIXME implement
00120 
00121 //      void unfold(const texpand_mode mode); // FIXME implement
00122 #endif
00123 
00124     /**
00125      * Inherited from twidget.
00126      *
00127      * @todo Implement properly.
00128      */
00129     virtual iterator::twalker_* create_walker() { return NULL; }
00130 
00131     /** Inherited from twidget.*/
00132     twidget* find_at(const tpoint& coordinate, const bool must_be_active);
00133 
00134     /** Inherited from twidget.*/
00135     const twidget* find_at(
00136               const tpoint& coordinate
00137             , const bool must_be_active) const;
00138 
00139     /** Inherited from twidget.*/
00140     twidget* find(const std::string& id, const bool must_be_active)
00141     {
00142         twidget* result = twidget::find(id, must_be_active);
00143         return result ? result : grid_.find(id, must_be_active);
00144     }
00145 
00146     /** Inherited from twidget.*/
00147     const twidget* find(const std::string& id
00148             , const bool must_be_active) const
00149     {
00150         const twidget* result = twidget::find(id, must_be_active);
00151         return result ? result : grid_.find(id, must_be_active);
00152     }
00153 
00154     /**
00155      * The "size" of the widget.
00156      *
00157      * @todo Rename this function, names to close to the size of the widget.
00158      */
00159     size_t size() const { return children_.size(); }
00160 
00161     /**
00162      * Removes all child items from the widget.
00163      */
00164     void clear();
00165 
00166     /***** ***** ***** setters / getters for members ***** ****** *****/
00167 
00168     /**
00169      * Returns the parent node.
00170      *
00171      * @pre                       is_root_node() == false.
00172      */
00173     ttree_view_node& parent_node();
00174 
00175     /** The const version of @ref parent_node. */
00176     const ttree_view_node& parent_node() const;
00177 
00178     ttree_view& tree_view();
00179 
00180     const ttree_view& tree_view() const;
00181 
00182 private:
00183 
00184     /** Inherited from twidget. */
00185     void request_reduce_width(const unsigned /*maximum_width*/) {}
00186 
00187     /**
00188      * Our parent node.
00189      *
00190      * All nodes except the root node have a parent node.
00191      */
00192     ttree_view_node* parent_node_;
00193 
00194     /** The tree view that owns us. */
00195     ttree_view& tree_view_;
00196 
00197     /** Grid holding our contents. */
00198     tgrid grid_;
00199 
00200     /**
00201      * Our children.
00202      *
00203      * We want the returned child nodes to remain stable so store pointers.
00204      */
00205     boost::ptr_vector<ttree_view_node> children_;
00206 
00207     /**
00208      * The node definitions known to use.
00209      *
00210      * This list is needed to create new nodes.
00211      *
00212      * @todo Maybe store this list in the tree_view to avoid copying the
00213      * reference.
00214      */
00215     const std::vector<tnode_definition>& node_definitions_;
00216 
00217     /** The icon to show the folded state. */
00218     ttoggle_button* icon_;
00219 
00220     /** The label to show our selected state. */
00221     tselectable_* label_;
00222 
00223     /**
00224      * "Inherited" from twidget.
00225      *
00226      * This version needs to call its children, which are it's child nodes.
00227      */
00228     void impl_populate_dirty_list(twindow& caller,
00229             const std::vector<twidget*>& call_stack);
00230 
00231     tpoint calculate_best_size() const;
00232 
00233     bool disable_click_dismiss() const { return true; }
00234 
00235     tpoint calculate_best_size(const int indention_level
00236             , const unsigned indention_step_size) const;
00237 
00238     tpoint get_current_size() const;
00239     tpoint get_folded_size() const;
00240     tpoint get_unfolded_size() const;
00241 
00242     void set_origin(const tpoint& origin);
00243 
00244     void place(const tpoint& origin, const tpoint& size);
00245 
00246     unsigned place(
00247               const unsigned indention_step_size
00248             , tpoint origin
00249             , unsigned width);
00250 
00251     void set_visible_area(const SDL_Rect& area);
00252 
00253     void impl_draw_children(surface& frame_buffer);
00254     void impl_draw_children(surface& frame_buffer, int x_offset, int y_offset);
00255 
00256     // FIXME rename to icon
00257     void signal_handler_left_button_click(const event::tevent event);
00258 
00259     void signal_handler_label_left_button_click(
00260               const event::tevent event
00261             , bool& handled
00262             , bool& halt);
00263 
00264     void init_grid(tgrid* grid
00265             , const std::map<
00266                 std::string /* widget id */, string_map>& data);
00267 
00268     const std::string& get_control_type() const;
00269 };
00270 
00271 } // namespace gui2
00272 
00273 #endif
00274 
00275 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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