The Battle for Wesnoth  1.15.2+dev
scrollbar_container_private.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
18 
19 #include "utils/const_clone.hpp"
20 
21 /**
22  * @file
23  * Helper for header for the scrollbar_container.
24  *
25  * @note This file should only be included by scrollbar_container.cpp.
26  *
27  * This file is being used for a small experiment in which some private
28  * functions of scrollbar_container are no longer in scrollbar_container
29  * but moved in a friend class with static functions. The goal is to have
30  * less header recompilations, when there's a need to add or remove a private
31  * function. Also non-trivial functions like 'const foo& bar() const' and
32  * 'foo& bar()' are wrapped in a template to avoid code duplication (for
33  * typing not for the binary) to make maintenance easier.
34  */
35 
36 namespace gui2
37 {
38 
39 /**
40  * Helper to implement private functions without modifying the header.
41  *
42  * The class is a helper to avoid recompilation and only has static
43  * functions.
44  */
46 {
47  /**
48  * Implementation for the wrappers for
49  * [const] widget* scrollbar_container::find_at(
50  * const point&, const bool) [const].
51  *
52  * @tparam W widget or const widget.
53  */
54  template <class W>
55  static W*
58  const point& coordinate,
59  const bool must_be_active)
60  {
61 
62  assert(scrollbar_container.content_
63  && scrollbar_container.content_grid_);
64 
65  W* result = scrollbar_container.container_base::find_at(coordinate,
66  must_be_active);
67 
68  if(result == scrollbar_container.content_) {
69  return scrollbar_container.content_grid_->find_at(coordinate,
70  must_be_active);
71  }
72 
73  return result;
74  }
75 
76  /**
77  * Implementation for the wrappers for
78  * [const] widget* scrollbar_container::find(
79  * const std::string&, const bool) [const].
80  *
81  * @tparam W widget or const widget.
82  */
83  template <class W>
84  static W*
87  const std::string& id,
88  const bool must_be_active)
89  {
90  // Inherited.
91  W* result = scrollbar_container.container_base::find(id, must_be_active);
92 
93  // Can be called before finalize so test instead of assert for the grid.
94  if(!result && scrollbar_container.content_grid_) {
95  result = scrollbar_container.content_grid_->find(id,
96  must_be_active);
97  }
98 
99  return result;
100  }
101 };
102 
103 } // namespace gui2
typename const_clone< D, S >::reference const_clone_ref
Definition: const_clone.hpp:62
Generic file dialog.
Definition: field-fwd.hpp:22
static W * find(utils::const_clone_ref< scrollbar_container, W > scrollbar_container, const std::string &id, const bool must_be_active)
Implementation for the wrappers for [const] widget* scrollbar_container::find( const std::string&...
static W * find_at(utils::const_clone_ref< scrollbar_container, W > scrollbar_container, const point &coordinate, const bool must_be_active)
Implementation for the wrappers for [const] widget* scrollbar_container::find_at( const point&...
Base class for creating containers with one or two scrollbar(s).
Holds a 2D point.
Definition: point.hpp:23
Helper to implement private functions without modifying the header.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.