gui/widgets/tree_view.hpp

Go to the documentation of this file.
00001 /* $Id: tree_view.hpp 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 #ifndef GUI_WIDGETS_TREE_VIEW_HPP_INCLUDED
00017 #define GUI_WIDGETS_TREE_VIEW_HPP_INCLUDED
00018 
00019 #include "gui/widgets/scrollbar_container.hpp"
00020 #include "gui/auxiliary/window_builder/tree_view.hpp"
00021 
00022 namespace gui2 {
00023 
00024 class ttree_view_node;
00025 
00026 class ttree_view
00027         : public tscrollbar_container
00028 {
00029     friend struct implementation::tbuilder_tree_view;
00030     friend class ttree_view_node;
00031 public:
00032 
00033     typedef implementation::tbuilder_tree_view::tnode tnode_definition;
00034 
00035     /**
00036      * Constructor.
00037      *
00038      * @param has_minimum         Does the listbox need to have one item
00039      *                            selected.
00040      * @param has_maximum         Can the listbox only have one item
00041      *                            selected.
00042      * @param placement           How are the items placed.
00043      * @param select              Select an item when selected, if false it
00044      *                            changes the visible state instead.
00045      */
00046     explicit ttree_view(const std::vector<tnode_definition>& node_definitions);
00047 
00048     using tscrollbar_container::finalize_setup;
00049 
00050     ttree_view_node& get_root_node() { return *root_node_; }
00051 
00052     ttree_view_node& add_node(const std::string& id
00053             , const std::map<std::string /* widget id */, string_map>& data);
00054 
00055     void remove_node(ttree_view_node* tree_view_node);
00056 
00057     /** Inherited from tscrollbar_container. */
00058     void child_populate_dirty_list(twindow& caller,
00059             const std::vector<twidget*>& call_stack);
00060 
00061     /** Inherited from tcontainer_. */
00062     void set_self_active(const bool /*active*/)  {}
00063 //      { state_ = active ? ENABLED : DISABLED; }
00064 
00065     bool empty() const;
00066 
00067     /** Inherited from tscrollbar_container. */
00068     void layout_children();
00069 
00070     /***** ***** ***** setters / getters for members ***** ****** *****/
00071 
00072     void set_indention_step_size(const unsigned indention_step_size)
00073     {
00074         indention_step_size_ = indention_step_size;
00075     }
00076 
00077     ttree_view_node* selected_item() { return selected_item_; }
00078 
00079     const ttree_view_node* selected_item() const { return selected_item_; }
00080 
00081     void set_selection_change_callback(boost::function<void()> callback)
00082     {
00083         selection_change_callback_ = callback;
00084     }
00085 
00086 protected:
00087 
00088     /***** ***** ***** ***** keyboard functions ***** ***** ***** *****/
00089 #if 0
00090     /** Inherited from tscrollbar_container. */
00091     void handle_key_up_arrow(SDLMod modifier, bool& handled);
00092 
00093     /** Inherited from tscrollbar_container. */
00094     void handle_key_down_arrow(SDLMod modifier, bool& handled);
00095 
00096     /** Inherited from tscrollbar_container. */
00097     void handle_key_left_arrow(SDLMod modifier, bool& handled);
00098 
00099     /** Inherited from tscrollbar_container. */
00100     void handle_key_right_arrow(SDLMod modifier, bool& handled);
00101 #endif
00102 private:
00103 
00104     /**
00105      * @todo evaluate which way the dependancy should go.
00106      *
00107      * We no depend on the implementation, maybe the implementation should
00108      * depend on us instead.
00109      */
00110     const std::vector<tnode_definition> node_definitions_;
00111 
00112     unsigned indention_step_size_;
00113 
00114     bool need_layout_;
00115 
00116     ttree_view_node* root_node_;
00117 
00118     ttree_view_node* selected_item_;
00119 
00120     boost::function<void ()> selection_change_callback_;
00121 
00122     /**
00123      * Resizes the content.
00124      *
00125      * The resize either happens due to resizing the content or invalidate the
00126      * layout of the window.
00127      *
00128      * @param width_modification  The wanted modification to the width:
00129      *                            * negative values reduce width.
00130      *                            * zero leave width as is.
00131      *                            * positive values increase width.
00132      * @param height_modification The wanted modification to the height:
00133      *                            * negative values reduce height.
00134      *                            * zero leave height as is.
00135      *                            * positive values increase height.
00136      */
00137     void resize_content(
00138               const int width_modification
00139             , const int height_modification);
00140 
00141     /** Layouts the children if needed. */
00142     void layout_children(const bool force);
00143 
00144     /** Inherited from tcontainer_. */
00145     virtual void finalize_setup();
00146 
00147     /** Inherited from tcontrol. */
00148     const std::string& get_control_type() const;
00149 
00150     /***** ***** ***** signal handlers ***** ****** *****/
00151 
00152     void signal_handler_left_button_down(const event::tevent event);
00153 };
00154 
00155 } // namespace gui2
00156 
00157 #endif
00158 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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