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