The Battle for Wesnoth  1.19.7+dev
modeless_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2024
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 "gui/widgets/window.hpp"
19 
20 #include <string>
21 
22 namespace gui2::dialogs
23 {
24 /**
25  * The popup class shows windows that are shown non-modal.
26  *
27  * At the moment these windows also don't capture the mouse and keyboard so can
28  * only be used for things like tooltips. This behavior might change later.
29  */
30 class modeless_dialog : public window
31 {
32  /**
33  * Special helper function to get the id of the window.
34  *
35  * This is used in the unit tests, but these implementation details
36  * shouldn't be used in the normal code.
37  */
38  friend std::string get_modeless_dialog_id(const modeless_dialog& dialog);
39 
40 public:
41  explicit modeless_dialog(const std::string& window_id);
42 
43  virtual ~modeless_dialog();
44 
45  /**
46  * Shows the window.
47  *
48  * @param allow_interaction Does the dialog allow interaction?
49  * * true a non modal window is shown
50  * * false a tooltip window is shown
51  * @param auto_close_time The time in ms after which the dialog will
52  * automatically close, if 0 it doesn't close.
53  * @note the timeout is a minimum time and
54  * there's no guarantee about how fast it closes
55  * after the minimum.
56  */
57  void show(const bool allow_interaction = false,
58  const unsigned auto_close_time = 0);
59 
60 private:
61  /**
62  * The ID of the window to build. Usually defined by REGISTER_DIALOG.
63  *
64  * Falls back to widget::id(), which is set during construction.
65  */
66  virtual const std::string& window_id() const { return widget::id(); }
67 };
68 
69 } // namespace gui2::dialogs
The popup class shows windows that are shown non-modal.
modeless_dialog(const std::string &window_id)
friend std::string get_modeless_dialog_id(const modeless_dialog &dialog)
Special helper function to get the id of the window.
Definition: test_gui2.cpp:184
void show(const bool allow_interaction=false, const unsigned auto_close_time=0)
Shows the window.
virtual const std::string & window_id() const
The ID of the window to build.
const std::string & id() const
Definition: widget.cpp:110
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
dialogs::modal_dialog * dialog()
Inherited from widget.
Definition: window.hpp:268
This file contains the window object, this object is a top level container which has the event manage...