The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
multi_page.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 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 
16 #ifndef GUI_WIDGETS_MULTI_PAGE_HPP_INCLUDED
17 #define GUI_WIDGETS_MULTI_PAGE_HPP_INCLUDED
18 
20 
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 namespace implementation
30 {
31 struct tbuilder_multi_page;
32 }
33 
34 class tgenerator_;
35 
36 /** The multi page class. */
37 class tmulti_page : public tcontainer_
38 {
40  friend class tdebug_layout_graph;
41 
42 public:
43  tmulti_page();
44 
45  /***** ***** ***** ***** Page handling. ***** ***** ****** *****/
46 
47  /**
48  * Adds single page to the grid.
49  *
50  * This function expect a page to one multiple widget.
51  *
52  * @param item The data to send to the set_members of the
53  * widget.
54  */
55  void add_page(const string_map& item);
56 
57  /**
58  * Adds single page to the grid.
59  *
60  * This function expect a page to have multiple widgets (either multiple
61  * columns or one column with multiple widgets).
62  *
63  *
64  * @param data The data to send to the set_members of the
65  * widgets. If the member id is not an empty
66  * string it is only send to the widget that
67  * has the wanted id (if any). If the member
68  * id is an empty string, it is send to all
69  * members. Having both empty and non-empty
70  * id's gives undefined behavior.
71  */
72  void
73  add_page(const std::map<std::string /* widget id */, string_map>& data);
74 
75  /**
76  * Removes a page in the multi page.
77  *
78  * @param page The page to remove, when not in
79  * range the function is ignored.
80  * @param count The number of pages to remove, 0 means all
81  * pages (starting from page).
82  */
83  void remove_page(const unsigned page, unsigned count = 1);
84 
85  /** Removes all pages in the multi page, clearing it. */
86  void clear();
87 
88  /** Returns the number of pages. */
89  unsigned get_page_count() const;
90 
91  /**
92  * Selectes a page.
93  *
94  * @param page The page to select.
95  * @param select Select or deselect the page.
96  */
97  void select_page(const unsigned page, const bool select = true);
98 
99  /**
100  * Returns the selected page.
101  *
102  * @returns The selected page.
103  * @retval -1 No page selected.
104  */
105  int get_selected_page() const;
106 
107  /**
108  * Returns the grid for the page.
109  *
110  * @param page The page to get the grid from, the caller
111  * has to make sure the page is a valid page.
112  *
113  * @returns The grid of the wanted page.
114  */
115  const tgrid& page_grid(const unsigned page) const;
116 
117  /**
118  * Returns the grid for the page.
119  *
120  * @param page The page to get the grid from, the caller
121  * has to make sure the page is a valid page.
122  *
123  * @returns The grid of the wanted page.
124  */
125  tgrid& page_grid(const unsigned page);
126 
127  /***** ***** ***** inherited ***** ****** *****/
128 
129  /** See @ref tcontrol::get_active. */
130  virtual bool get_active() const override;
131 
132  /** See @ref tcontrol::get_state. */
133  virtual unsigned get_state() const override;
134 
135  /***** ***** ***** setters / getters for members ***** ****** *****/
136 
138  {
139  page_builder_ = page_builder;
140  }
141 
142 private:
143  /**
144  * Finishes the building initialization of the widget.
145  *
146  * @param page_data The initial data to fill the widget with.
147  */
148  void finalize(const std::vector<string_map>& page_data);
149 
150  /**
151  * Contains a pointer to the generator.
152  *
153  * The pointer is not owned by this class, it's stored in the content_grid_
154  * of the tscrollbar_container super class and freed when it's grid is
155  * freed.
156  */
158 
159  /** Contains the builder for the new items. */
161 
162  /** See @ref twidget::impl_draw_background. */
163  virtual void impl_draw_background(surface& frame_buffer,
164  int x_offset,
165  int y_offset) override;
166 
167  /** See @ref tcontrol::get_control_type. */
168  virtual const std::string& get_control_type() const override;
169 
170  /** See @ref tcontainer_::set_self_active. */
171  virtual void set_self_active(const bool active) override;
172 };
173 
174 // }---------- DEFINITION ---------{
175 
177 {
178  explicit tmulti_page_definition(const config& cfg);
179 
181  {
182  explicit tresolution(const config& cfg);
183 
185  };
186 };
187 
188 // }---------- BUILDER -----------{
189 
190 namespace implementation
191 {
192 
194 {
195  explicit tbuilder_multi_page(const config& cfg);
196 
198 
199  twidget* build() const;
200 
202 
203  /**
204  * Multi page data.
205  *
206  * Contains a vector with the data to set in every cell, it's used to
207  * serialize the data in the config, so the config is no longer required.
208  */
209  std::vector<std::map<std::string, t_string> > data;
210 };
211 
212 } // namespace implementation
213 
214 // }------------ END --------------
215 
216 } // namespace gui2
217 
218 #endif
Abstract base class for the generator.
Definition: generator.hpp:41
void set_page_builder(tbuilder_grid_ptr page_builder)
Definition: multi_page.hpp:137
virtual unsigned get_state() const override
See tcontrol::get_state.
Definition: multi_page.cpp:113
Base container class.
Definition: grid.hpp:29
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
const tgrid & page_grid(const unsigned page) const
Returns the grid for the page.
Definition: multi_page.cpp:96
Base class of a resolution, contains the common keys for a resolution.
std::vector< std::map< std::string, t_string > > data
Multi page data.
Definition: multi_page.hpp:209
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
virtual twidget * build() const =0
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: multi_page.cpp:170
void finalize(const std::vector< string_map > &page_data)
Finishes the building initialization of the widget.
Definition: multi_page.cpp:154
int get_selected_page() const
Returns the selected page.
Definition: multi_page.cpp:90
void add_page(const string_map &item)
Adds single page to the grid.
Definition: multi_page.cpp:42
The multi page class.
Definition: multi_page.hpp:37
GLuint GLuint GLsizei count
Definition: glew.h:1221
tmulti_page_definition(const config &cfg)
Definition: multi_page.cpp:183
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
virtual void set_self_active(const bool active) override
See tcontainer_::set_self_active.
Definition: multi_page.cpp:176
unsigned get_page_count() const
Returns the number of pages.
Definition: multi_page.cpp:78
tgenerator_ * generator_
Contains a pointer to the generator.
Definition: multi_page.hpp:157
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
Definition: multi_page.cpp:55
virtual void impl_draw_background(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_background.
Definition: multi_page.cpp:161
void clear()
Removes all pages in the multi page, clearing it.
Definition: multi_page.cpp:72
void select_page(const unsigned page, const bool select=true)
Selectes a page.
Definition: multi_page.cpp:84
A generic container base class.
Definition: container.hpp:32
Base class for all widgets.
Definition: widget.hpp:49
virtual bool get_active() const override
See tcontrol::get_active.
Definition: multi_page.cpp:108
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
friend class tdebug_layout_graph
Definition: multi_page.hpp:40
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Contains the implementation details for lexical_cast and shouldn't be used directly.
tbuilder_grid_const_ptr page_builder_
Contains the builder for the new items.
Definition: multi_page.hpp:160