The Battle for Wesnoth  1.17.0-dev
modeless_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <memory>
19 #include <string>
20 
21 namespace gui2
22 {
23 
24 class window;
25 
26 namespace dialogs
27 {
28 
29 /**
30  * The popup class shows windows that are shown non-modal.
31  *
32  * At the moment these windows also don't capture the mouse and keyboard so can
33  * only be used for things like tooltips. This behavior might change later.
34  */
36 {
37  /**
38  * Special helper function to get the id of the window.
39  *
40  * This is used in the unit tests, but these implementation details
41  * shouldn't be used in the normal code.
42  */
43  friend std::string unit_test_mark_popup_as_tested(const modeless_dialog& dialog);
44 
45  /**
46  * Special helper function for the unit test to the the window.
47  *
48  * This is used in the unit tests, but these implementation details
49  * shouldn't be used in the normal code.
50  */
51  friend window* unit_test_window(const modeless_dialog& dialog);
52 
53 public:
55 
56  virtual ~modeless_dialog();
57 
58  /**
59  * Shows the window.
60  *
61  * @param allow_interaction Does the dialog allow interaction?
62  * * true a non modal window is shown
63  * * false a tooltip window is shown
64  * @param auto_close_time The time in ms after which the dialog will
65  * automatically close, if 0 it doesn't close.
66  * @note the timeout is a minimum time and
67  * there's no guarantee about how fast it closes
68  * after the minimum.
69  */
70  void show(const bool allow_interaction = false,
71  const unsigned auto_close_time = 0);
72 
73 
74  /**
75  * Hides the window.
76  *
77  * The hiding also destroys the window. It is save to call the function
78  * when the window is not shown.
79  */
80  void hide();
81 
82  /** Returns a pointer to the dialog's window. Will be null if it hasn't been built yet. */
83  window* get_window() const
84  {
85  return window_.get();
86  }
87 
88 protected:
89  /** The window, used in show. */
90  std::unique_ptr<window> window_;
91 
92 private:
93  /** The id of the window to build. */
94  virtual const std::string& window_id() const = 0;
95 
96  /**
97  * Builds the window.
98  *
99  * Every dialog shows it's own kind of window, this function should return
100  * the window to show.
101  *
102  * @returns The window to show.
103  */
104  std::unique_ptr<window> build_window() const;
105 
106  /**
107  * Actions to be taken directly after the window is build.
108  *
109  * @param window The window just created.
110  */
111  virtual void post_build(window& window);
112 
113  /**
114  * Actions to be taken before showing the window.
115  *
116  * @param window The window to be shown.
117  */
118  virtual void pre_show(window& window);
119 };
120 
121 } // namespace dialogs
122 } // 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:156
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:23
std::unique_ptr< window > build_window() const
Builds the window.
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:149
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:65