The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
scrollbar_container_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_SCROLLBAR_CONTAINER_PRIVATE_HPP_INCLUDED
16 #define GUI_WIDGETS_SCROLLBAR_CONTAINER_PRIVATE_HPP_INCLUDED
17 
19 
20 #include "utils/const_clone.hpp"
21 
22 /**
23  * @file
24  * Helper for header for the scrollbar_container.
25  *
26  * @note This file should only be included by scrollbar_container.cpp.
27  *
28  * This file is being used for a small experiment in which some private
29  * functions of tscrollbar_container are no longer in tscrollbar_container
30  * but moved in a friend class with static functions. The goal is to have
31  * less header recompilations, when there's a need to add or remove a private
32  * function. Also non-trivial functions like 'const foo& bar() const' and
33  * 'foo& bar()' are wrapped in a template to avoid code duplication (for
34  * typing not for the binary) to make maintenance easier.
35  */
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* tscrollbar_container::find_at(
51  * const tpoint&, const bool) [const].
52  *
53  * @tparam W twidget or const twidget.
54  */
55  template <class W>
56  static W*
58  scrollbar_container,
59  const tpoint& coordinate,
60  const bool must_be_active)
61  {
62 
63  assert(scrollbar_container.content_
64  && scrollbar_container.content_grid_);
65 
66  W* result = scrollbar_container.tcontainer_::find_at(coordinate,
67  must_be_active);
68 
69  if(result == scrollbar_container.content_) {
70  return scrollbar_container.content_grid_->find_at(coordinate,
71  must_be_active);
72  }
73 
74  return result;
75  }
76 
77  /**
78  * Implementation for the wrappers for
79  * [const] twidget* tscrollbar_container::find(
80  * const std::string&, const bool) [const].
81  *
82  * @tparam W twidget or const twidget.
83  */
84  template <class W>
85  static W*
87  scrollbar_container,
88  const std::string& id,
89  const bool must_be_active)
90  {
91  // Inherited.
92  W* result = scrollbar_container.tcontainer_::find(id, must_be_active);
93 
94  // Can be called before finalize so test instead of assert for the grid.
95  if(!result && scrollbar_container.content_grid_) {
96  result = scrollbar_container.content_grid_->find(id,
97  must_be_active);
98  }
99 
100  return result;
101  }
102 };
103 
104 } // namespace gui2
105 
106 #endif
static W * find_at(typename utils::tconst_clone< tscrollbar_container, W >::reference scrollbar_container, const tpoint &coordinate, const bool must_be_active)
Implementation for the wrappers for [const] twidget* tscrollbar_container::find_at( const tpoint&...
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
GLuint64EXT * result
Definition: glew.h:10727
Holds a 2D point.
Definition: point.hpp:24
static W * find(typename utils::tconst_clone< tscrollbar_container, W >::reference scrollbar_container, const std::string &id, const bool must_be_active)
Implementation for the wrappers for [const] twidget* tscrollbar_container::find( const std::string&...
Helper to implement private functions without modifying the header.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503