The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
register_widget.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 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_DETAIL_REGISTER_TPP_INCLUDED
16 #define GUI_WIDGETS_DETAIL_REGISTER_TPP_INCLUDED
17 
18 /**
19  * Registers a widget.
20  *
21  * Call this function to register a widget. Use this macro in the
22  * implementation, inside the gui2 namespace.
23  *
24  * See @ref gui2::load_widget_definitions for more information.
25  *
26  * @note When the type is tfoo_definition, the id "foo" and no special key best
27  * use RESISTER_WIDGET(foo) instead.
28  *
29  * @param type Class type of the window to register.
30  * @param id Id of the widget
31  * @param key The id to load if differs from id.
32  */
33 #define REGISTER_WIDGET3(type, id, key) \
34  namespace \
35  { \
36  \
37  namespace ns_##type \
38  { \
39  \
40  struct tregister_helper \
41  { \
42  tregister_helper() \
43  { \
44  register_widget(#id, \
45  std::bind(load_widget_definitions<type>, \
46  _1, \
47  _2, \
48  _3, \
49  key)); \
50  \
51  register_builder_widget( \
52  #id, \
53  std::bind( \
54  build_widget<implementation::tbuilder_##id>, \
55  _1)); \
56  } \
57  }; \
58  \
59  static tregister_helper register_helper; \
60  } \
61  }
62 
63 /**
64  * Wrapper for REGISTER_WIDGET3.
65  *
66  * "Calls" REGISTER_WIDGET3(tid_definition, id, _4)
67  */
68 #define REGISTER_WIDGET(id) REGISTER_WIDGET3(t##id##_definition, id, _4)
69 
70 #endif