The Battle for Wesnoth  1.15.1+dev
modeless_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 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 
17 #include <memory>
18 #include <string>
19 
20 namespace gui2
21 {
22 
23 class window;
24 
25 namespace dialogs
26 {
27 
28 /**
29  * The popup class shows windows that are shown non-modal.
30  *
31  * At the moment these windows also don't capture the mouse and keyboard so can
32  * only be used for things like tooltips. This behavior might change later.
33  */
35 {
36  /**
37  * Special helper function to get the id of the window.
38  *
39  * This is used in the unit tests, but these implementation details
40  * shouldn't be used in the normal code.
41  */
42  friend std::string unit_test_mark_popup_as_tested(const modeless_dialog& dialog);
43 
44  /**
45  * Special helper function for the unit test to the the window.
46  *
47  * This is used in the unit tests, but these implementation details
48  * shouldn't be used in the normal code.
49  */
50  friend window* unit_test_window(const modeless_dialog& dialog);
51 
52 public:
54 
55  virtual ~modeless_dialog();
56 
57  /**
58  * Shows the window.
59  *
60  * @param allow_interaction Does the dialog allow interaction?
61  * * true a non modal window is shown
62  * * false a tooltip window is shown
63  * @param auto_close_time The time in ms after which the dialog will
64  * automatically close, if 0 it doesn't close.
65  * @note the timeout is a minimum time and
66  * there's no guarantee about how fast it closes
67  * after the minimum.
68  */
69  void show(const bool allow_interaction = false,
70  const unsigned auto_close_time = 0);
71 
72 
73  /**
74  * Hides the window.
75  *
76  * The hiding also destroys the window. It is save to call the function
77  * when the window is not shown.
78  */
79  void hide();
80 
81  /** Returns a pointer to the dialog's window. Will be null if it hasn't been built yet. */
82  window* get_window() const
83  {
84  return window_.get();
85  }
86 
87 protected:
88  /** The window, used in show. */
89  std::unique_ptr<window> window_;
90 
91 private:
92  /** The id of the window to build. */
93  virtual const std::string& window_id() const = 0;
94 
95  /**
96  * Builds the window.
97  *
98  * Every dialog shows it's own kind of window, this function should return
99  * the window to show.
100  *
101  * @returns The window to show.
102  */
103  window* build_window() const;
104 
105  /**
106  * Actions to be taken directly after the window is build.
107  *
108  * @param window The window just created.
109  */
110  virtual void post_build(window& window);
111 
112  /**
113  * Actions to be taken before showing the window.
114  *
115  * @param window The window to be shown.
116  */
117  virtual void pre_show(window& window);
118 };
119 
120 } // namespace dialogs
121 } // namespace gui2
friend window * unit_test_window(const modeless_dialog &dialog)
Special helper function for the unit test to the the window.
Definition: test_gui2.cpp:154
window * build_window() const
Builds the window.
virtual void post_build(window &window)
Actions to be taken directly after the window is build.
virtual const std::string & window_id() const =0
The id of the window to build.
Generic file dialog.
Definition: field-fwd.hpp:22
void hide()
Hides the window.
Various uncategorised dialogs.
window * get_window() const
Returns a pointer to the dialog&#39;s window.
virtual void pre_show(window &window)
Actions to be taken before showing the window.
std::unique_ptr< window > window_
The window, used in show.
void show(const bool allow_interaction=false, const unsigned auto_close_time=0)
Shows the window.
friend std::string unit_test_mark_popup_as_tested(const modeless_dialog &dialog)
Special helper function to get the id of the window.
Definition: test_gui2.cpp:147
The popup class shows windows that are shown non-modal.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63