The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tree_view.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GUI_WIDGETS_TREE_VIEW_HPP_INCLUDED
16 #define GUI_WIDGETS_TREE_VIEW_HPP_INCLUDED
17 
19 
20 namespace gui2
21 {
22 
23 namespace implementation {
24  struct tbuilder_tree_view;
25  struct ttree_node
26  {
27  explicit ttree_node(const config& cfg);
28 
30  bool unfolded;
32  };
33 }
34 
35 // ------------ WIDGET -----------{
36 
37 class ttree_view_node;
38 
40 {
42  friend class ttree_view_node;
43 
44 public:
46 
47  explicit ttree_view(const std::vector<tnode_definition>& node_definitions);
48 
50 
52  {
53  return *root_node_;
54  }
55 
57  add_node(const std::string& id,
58  const std::map<std::string /* widget id */, string_map>& data);
59 
60  void remove_node(ttree_view_node* tree_view_node);
61 
62  /** See @ref twidget::child_populate_dirty_list. */
63  virtual void
65  const std::vector<twidget*>& call_stack) override;
66 
67  /** See @ref tcontainer_::set_self_active. */
68  virtual void set_self_active(const bool active) override;
69 
70  bool empty() const;
71 
72  /** See @ref twidget::layout_children. */
73  virtual void layout_children() override;
74 
75  /***** ***** ***** setters / getters for members ***** ****** *****/
76 
77  void set_indention_step_size(const unsigned indention_step_size)
78  {
79  indention_step_size_ = indention_step_size;
80  }
81 
83  {
84  return selected_item_;
85  }
86 
88  {
89  return selected_item_;
90  }
91 
92  void set_selection_change_callback(std::function<void(twidget&)> callback)
93  {
94  selection_change_callback_ = callback;
95  }
96 
97 protected:
98 /***** ***** ***** ***** keyboard functions ***** ***** ***** *****/
99  /** Inherited from tscrollbar_container. */
100  void handle_key_up_arrow(SDLMod modifier, bool& handled);
101 
102  /** Inherited from tscrollbar_container. */
103  void handle_key_down_arrow(SDLMod modifier, bool& handled);
104 
105  /** Inherited from tscrollbar_container. */
106  void handle_key_left_arrow(SDLMod modifier, bool& handled);
107 
108  /** Inherited from tscrollbar_container. */
109  void handle_key_right_arrow(SDLMod modifier, bool& handled);
110 private:
111  /**
112  * @todo evaluate which way the dependancy should go.
113  *
114  * We no depend on the implementation, maybe the implementation should
115  * depend on us instead.
116  */
117  const std::vector<tnode_definition> node_definitions_;
118 
120 
122 
124 
126 
127  std::function<void(twidget&)> selection_change_callback_;
128 
129  /**
130  * Resizes the content.
131  *
132  * The resize either happens due to resizing the content or invalidate the
133  * layout of the window.
134  *
135  * @param width_modification The wanted modification to the width:
136  * * negative values reduce width.
137  * * zero leave width as is.
138  * * positive values increase width.
139  * @param height_modification The wanted modification to the height:
140  * * negative values reduce height.
141  * * zero leave height as is.
142  * * positive values increase height.
143  */
144  void resize_content(const int width_modification,
145  const int height_modification,
146  const int width__modification_pos = -1,
147  const int height_modification_pos = -1);
148 
149  /** Layouts the children if needed. */
150  void layout_children(const bool force);
151 
152  /** Inherited from tcontainer_. */
153  virtual void finalize_setup();
154 
155  /** See @ref tcontrol::get_control_type. */
156  virtual const std::string& get_control_type() const override;
157 
158  /***** ***** ***** signal handlers ***** ****** *****/
159 
161 
162  template<ttree_view_node* (ttree_view_node::*func) ()>
164 
165  template<ttree_view_node* (ttree_view_node::*func) ()>
166  bool handle_up_down_arrow();
167 };
168 
169 // }---------- DEFINITION ---------{
170 
172 {
173 
174  explicit ttree_view_definition(const config& cfg);
175 
177  {
178  explicit tresolution(const config& cfg);
179 
181  };
182 };
183 
184 // }---------- BUILDER -----------{
185 
186 namespace implementation
187 {
188 
190 {
191  explicit tbuilder_tree_view(const config& cfg);
192 
194 
195  twidget* build() const;
196 
199 
201 
202  /**
203  * The types of nodes in the tree view.
204  *
205  * Since we expect the amount of nodes to remain low it's stored in a
206  * vector and not in a map.
207  */
208  std::vector<ttree_node> nodes;
209 
210  /*
211  * NOTE this class doesn't have a data section, so it can only be filled
212  * with data by the engine. I think this poses no limit on the usage since
213  * I don't foresee that somebody wants to pre-fill a tree view. If the need
214  * arises the data part can be added.
215  */
216 };
217 
218 } // namespace implementation
219 
220 // }------------ END --------------
221 
222 } // namespace gui2
223 
224 #endif
tscrollbar_container::tscrollbar_mode horizontal_scrollbar_mode
Definition: tree_view.hpp:198
#define SDLMod
Definition: compat.hpp:30
unsigned indention_step_size_
Definition: tree_view.hpp:119
implementation::ttree_node tnode_definition
Definition: tree_view.hpp:45
bool handle_up_down_arrow()
Definition: tree_view.cpp:206
ttree_view_node * selected_item()
Definition: tree_view.hpp:82
tscrollbar_container::tscrollbar_mode vertical_scrollbar_mode
Definition: tree_view.hpp:197
const std::vector< tnode_definition > node_definitions_
Definition: tree_view.hpp:117
ttree_view_node * selected_item_
Definition: tree_view.hpp:125
void set_indention_step_size(const unsigned indention_step_size)
Definition: tree_view.hpp:77
virtual void finalize_setup()
Inherited from tcontainer_.
Definition: tree_view.cpp:164
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: tree_view.cpp:179
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
void handle_key_down_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
Definition: tree_view.cpp:231
Base class of a resolution, contains the common keys for a resolution.
ttree_view_node * root_node_
Definition: tree_view.hpp:123
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
ttree_view_node & add_node(const std::string &id, const std::map< std::string, string_map > &data)
Definition: tree_view.cpp:58
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
std::function< void(twidget &)> selection_change_callback_
Definition: tree_view.hpp:127
void set_selection_change_callback(std::function< void(twidget &)> callback)
Definition: tree_view.hpp:92
std::vector< ttree_node > nodes
The types of nodes in the tree view.
Definition: tree_view.hpp:208
virtual twidget * build() const =0
virtual void set_self_active(const bool active) override
See tcontainer_::set_self_active.
Definition: tree_view.cpp:102
void handle_key_left_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
Definition: tree_view.cpp:242
tscrollbar_mode
The way to handle the showing or hiding of the scrollbar.
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
void finalize_setup()
The builder needs to call us so we do our setup.
ttree_view_definition(const config &cfg)
Definition: tree_view.cpp:266
void signal_handler_left_button_down(const event::tevent event)
Definition: tree_view.cpp:185
void handle_key_up_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
Definition: tree_view.cpp:221
ttree_view_node & get_root_node()
Definition: tree_view.hpp:51
ttree_node(const config &cfg)
Definition: tree_view.cpp:418
void handle_key_right_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
Definition: tree_view.cpp:253
ttree_view(const std::vector< tnode_definition > &node_definitions)
Definition: tree_view.cpp:40
cl_event event
Definition: glew.h:3070
Base class for all widgets.
Definition: widget.hpp:49
ttree_view_node * get_next_node()
Definition: tree_view.cpp:192
const ttree_view_node * selected_item() const
Definition: tree_view.hpp:87
bool empty() const
Definition: tree_view.cpp:107
void remove_node(ttree_view_node *tree_view_node)
Definition: tree_view.cpp:65
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
virtual void layout_children() override
See twidget::layout_children.
Definition: tree_view.cpp:112
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Contains the implementation details for lexical_cast and shouldn't be used directly.
void resize_content(const int width_modification, const int height_modification, const int width__modification_pos=-1, const int height_modification_pos=-1)
Resizes the content.
Definition: tree_view.cpp:117
Base class for creating containers with one or two scrollbar(s).
virtual void child_populate_dirty_list(twindow &caller, const std::vector< twidget * > &call_stack) override
See twidget::child_populate_dirty_list.
Definition: tree_view.cpp:92