The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
walker_widget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "asserts.hpp"
20 #include "gui/widgets/widget.hpp"
21 
22 namespace gui2
23 {
24 
25 namespace iterator
26 {
27 
28 namespace walker
29 {
30 
31 twidget::twidget(gui2::twidget& widget) : widget_(&widget)
32 {
33 }
34 
36 {
37  if(at_end(level)) {
38  return fail;
39  }
40 
41  switch(level) {
42  case widget:
43  if(widget_) {
44  widget_ = nullptr;
45  return invalid;
46  } else {
47  /* FALL DOWN */
48  }
49  case grid: /* FALL DOWN */
50  case child: /* FALL DOWN */
51  ;
52  }
53 
54  assert(false);
55  return fail;
56 }
57 
58 bool twidget::at_end(const tlevel level) const
59 {
60  switch(level) {
61  case widget:
62  return widget_ == nullptr;
63  case grid: /* FALL DOWN */
64  case child:
65  return true;
66  }
67 
68  assert(false);
69  return true;
70 }
71 
73 {
74  switch(level) {
75  case widget:
76  return widget_;
77  case grid: /* FALL DOWN */
78  case child:
79  return nullptr;
80  }
81 
82  assert(false);
83  return nullptr;
84 }
85 
86 } // namespace walker
87 
88 } // namespace iterator
89 
90 } // namespace gui2
Visit the widget itself.
Definition: walker.hpp:37
GLint level
Definition: glew.h:1220
tstate
The state of the walker.
Definition: walker.hpp:51
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
virtual tstate next(const tlevel level)
Inherited from gui2::iterator::twalker_.
virtual gui2::twidget * get(const tlevel level)
Inherited from gui2::iterator::twalker_.
When calling next the following it has the following results.
Definition: walker.hpp:71
twidget(gui2::twidget &widget)
Constructor.
tlevel
The level to walk at.
Definition: walker.hpp:35
Base class for all widgets.
Definition: widget.hpp:49
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
gui2::twidget * widget_
The control which the walker is attached to.
virtual bool at_end(const tlevel level) const
Inherited from gui2::iterator::twalker_.
Visit the children of its nested grid.
Definition: walker.hpp:40