The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
simple_item_selector.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Ignacio Riquelme Morelle <[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_DIALOGS_SIMPLE_ITEM_SELECTOR_HPP_INCLUDED
16 #define GUI_DIALOGS_SIMPLE_ITEM_SELECTOR_HPP_INCLUDED
17 
18 #include "gui/dialogs/dialog.hpp"
19 
20 #include <vector>
21 
22 namespace gui2
23 {
24 
26 {
27 public:
28  typedef std::vector<std::string> list_type;
30 
32  const std::string& message,
33  list_type const& items,
34  bool title_uses_markup = false,
35  bool message_uses_markup = false);
36 
37  /**
38  * Returns the selected item index after displaying.
39  * @return -1 if the dialog was canceled.
40  */
41  int selected_index() const
42  {
43  return index_;
44  }
45 
46  /** Sets the initially selected item index (-1 by default). */
48  {
49  index_ = index;
50  }
51 
52  /** Sets the caption for the OK button. */
53  void set_ok_label(const std::string& s)
54  {
55  ok_label_ = s;
56  }
57  const std::string& ok_label() const
58  {
59  return ok_label_;
60  }
61 
62  /** Sets the caption for the Cancel button. */
64  {
65  cancel_label_ = s;
66  }
67  const std::string& cancel_label() const
68  {
69  return cancel_label_;
70  }
71 
72  /** Sets whether the Cancel button should be hidden or not. */
74  {
76  }
77  bool single_button() const
78  {
79  return single_button_;
80  }
81 
82 private:
83  int index_;
84 
86  list_type items_;
87 
89 
90  /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
91  virtual const std::string& window_id() const;
92 
93  /** Inherited from tdialog. */
94  void pre_show(twindow& window);
95 
96  /** Inherited from tdialog. */
97  void post_show(twindow& window);
98 };
99 }
100 
101 #endif /* ! GUI_DIALOGS_SIMPLE_ITEM_SELECTOR_HPP_INCLUDED */
const std::vector< std::string > items
void set_ok_label(const std::string &s)
Sets the caption for the OK button.
void set_single_button(bool value)
Sets whether the Cancel button should be hidden or not.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
tsimple_item_selector(const std::string &title, const std::string &message, list_type const &items, bool title_uses_markup=false, bool message_uses_markup=false)
Abstract base class for all dialogs.
Definition: dialog.hpp:121
const std::string & ok_label() const
GLsizei const GLfloat * value
Definition: glew.h:1817
int selected_index() const
Returns the selected item index after displaying.
const std::string & cancel_label() const
void set_cancel_label(const std::string &s)
Sets the caption for the Cancel button.
void post_show(twindow &window)
Inherited from tdialog.
virtual const std::string & window_id() const
Inherited from tdialog, implemented by REGISTER_DIALOG.
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
GLuint index
Definition: glew.h:1782
void pre_show(twindow &window)
Inherited from tdialog.
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
std::vector< std::string > list_type
GLdouble s
Definition: glew.h:1358
GLsizei const GLcharARB ** string
Definition: glew.h:4503