The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
grid_private.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 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_GRID_PRIVATE_HPP_INCLUDED
16 #define GUI_WIDGETS_GRID_PRIVATE_HPP_INCLUDED
17 
18 /**
19  * @file
20  * Helper for header for the grid.
21  *
22  * @note This file should only be included by grid.cpp.
23  *
24  * This file is being used for a small experiment in which some private
25  * functions of tgrid are no longer in tgrid but moved in a friend class with
26  * static functions. The goal is to have less header recompilations, when
27  * there's a need to add or remove a private function.
28  * Also non-trivial functions like 'const foo& bar() const' and 'foo& bar()'
29  * are wrapped in a template to avoid code duplication (for typing not for the
30  * binary) to make maintenance easier.
31  */
32 
33 #include "gui/widgets/grid.hpp"
34 
35 #include "utils/const_clone.hpp"
36 
37 namespace gui2
38 {
39 
40 /**
41  * Helper to implement private functions without modifying the header.
42  *
43  * The class is a helper to avoid recompilation and only has static
44  * functions.
45  */
47 {
48  /**
49  * Implementation for the wrappers for
50  * [const] twidget* tgrid::find_at(const tpoint&, const bool) [const].
51  *
52  * @tparam W twidget or const twidget.
53  */
54  template <class W>
56  const tpoint& coordinate,
57  const bool must_be_active)
58  {
59  typedef typename utils::tconst_clone<tgrid::tchild, W>::type hack;
60  for(hack & child : grid.children_)
61  {
62 
63  W* widget = child.widget();
64  if(!widget) {
65  continue;
66  }
67 
68  widget = widget->find_at(coordinate, must_be_active);
69  if(widget) {
70  return widget;
71  }
72  }
73 
74  return 0;
75  }
76 
77  /**
78  * Implementation for the wrappers for
79  * [const] twidget* tgrid::find(const std::string&,
80  * const bool) [const].
81  *
82  * @tparam W twidget or const twidget.
83  */
84  template <class W>
86  const std::string& id,
87  const bool must_be_active)
88  {
89  // Inherited.
90  W* widget = grid.twidget::find(id, must_be_active);
91  if(widget) {
92  return widget;
93  }
94 
95  typedef typename utils::tconst_clone<tgrid::tchild, W>::type hack;
96  for(hack & child : grid.children_)
97  {
98 
99  widget = child.widget();
100  if(!widget) {
101  continue;
102  }
103 
104  widget = widget->find(id, must_be_active);
105  if(widget) {
106  return widget;
107  }
108  }
109 
110  return 0;
111  }
112 
113  /**
114  * Helper function to do the resizing of a row.
115  *
116  * @param grid The grid to operate upon.
117  * @param row The row to resize.
118  * @param maximum_height The wanted maximum height.
119  *
120  * @returns The required row height after resizing.
121  */
122  static unsigned row_request_reduce_height(tgrid& grid,
123  const unsigned row,
124  const unsigned maximum_height);
125 
126  /**
127  * Helper function to do the resizing of a column.
128  *
129  * @param grid The grid to operate upon.
130  * @param column The column to resize.
131  * @param maximum_width The wanted maximum width.
132  *
133  * @returns The required column width after resizing.
134  */
135  static unsigned column_request_reduce_width(tgrid& grid,
136  const unsigned column,
137  const unsigned maximum_width);
138 
139 private:
140  /**
141  * Helper function to do the resizing of a widget.
142  *
143  * @param child The cell whose widget needs to be resized.
144  * @param maximum_height The wanted maximum height.
145  */
146  static void cell_request_reduce_height(tgrid::tchild& child,
147  const unsigned maximum_height);
148 
149  /**
150  * Helper function to do the resizing of a widget.
151  *
152  * @param child The cell whose widget needs to be resized.
153  * @param maximum_width The wanted maximum width.
154  */
155  static void cell_request_reduce_width(tgrid::tchild& child,
156  const unsigned maximum_width);
157 };
158 
159 } // namespace gui2
160 
161 #endif
Base container class.
Definition: grid.hpp:29
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
static W * find_at(typename utils::tconst_clone< tgrid, W >::reference grid, const tpoint &coordinate, const bool must_be_active)
Implementation for the wrappers for [const] twidget* tgrid::find_at(const tpoint&, const bool) [const].
static unsigned row_request_reduce_height(tgrid &grid, const unsigned row, const unsigned maximum_height)
Helper function to do the resizing of a row.
Definition: grid.cpp:944
GLenum GLenum GLvoid GLvoid * column
Definition: glew.h:3805
static void cell_request_reduce_width(tgrid::tchild &child, const unsigned maximum_width)
Helper function to do the resizing of a widget.
Definition: grid.cpp:1009
Holds a 2D point.
Definition: point.hpp:24
Child item of the grid.
Definition: grid.hpp:309
D type
The destination type, possibly const qualified.
Definition: const_clone.hpp:50
GLenum GLenum GLvoid * row
Definition: glew.h:3805
static unsigned column_request_reduce_width(tgrid &grid, const unsigned column, const unsigned maximum_width)
Helper function to do the resizing of a column.
Definition: grid.cpp:969
Helper to implement private functions without modifying the header.
static W * find(typename utils::tconst_clone< tgrid, W >::reference grid, const std::string &id, const bool must_be_active)
Implementation for the wrappers for [const] twidget* tgrid::find(const std::string&, const bool) [const].
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
static void cell_request_reduce_height(tgrid::tchild &child, const unsigned maximum_height)
Helper function to do the resizing of a widget.
Definition: grid.cpp:995
GLsizei const GLcharARB ** string
Definition: glew.h:4503