MapItemListDialog: add airspace ack button (#2139)
[xcsoar.git] / src / Dialogs / WidgetDialog.hpp
blobc96ebc478f6dcce022b3597b6ca4df65b0a1449e
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_WIDGET_DIALOG_HPP
25 #define XCSOAR_WIDGET_DIALOG_HPP
27 #include "Screen/Point.hpp"
28 #include "Form/Form.hpp"
29 #include "Form/ButtonPanel.hpp"
30 #include "Widget/ManagedWidget.hpp"
32 #include <tchar.h>
34 class Widget;
36 class WidgetDialog : public WndForm {
37 ButtonPanel buttons;
39 ManagedWidget widget;
41 bool auto_size;
43 bool changed;
45 public:
46 WidgetDialog(const DialogLook &look);
48 void Create(SingleWindow &parent, const TCHAR *caption,
49 const PixelRect &rc, Widget *widget);
51 /**
52 * Create a full-screen dialog.
54 void CreateFull(SingleWindow &parent, const TCHAR *caption, Widget *widget);
56 /**
57 * Create a dialog with an automatic size (by
58 * Widget::GetMinimumSize() and Widget::GetMaximumSize()).
60 void CreateAuto(SingleWindow &parent, const TCHAR *caption, Widget *widget);
62 /**
63 * Create a dialog, but do not associate it with a #Widget yet.
64 * Call FinishPreliminary() to resume building the dialog.
66 void CreatePreliminary(SingleWindow &parent, const TCHAR *caption);
68 void FinishPreliminary(Widget *widget);
70 bool GetChanged() const {
71 return changed;
74 Widget &GetWidget() {
75 assert(widget.IsDefined());
76 return *widget.Get();
79 Widget *StealWidget() {
80 assert(widget.IsDefined());
81 widget.Unprepare();
82 return widget.Steal();
85 WndButton *AddButton(const TCHAR *caption,
86 ActionListener &listener, int id) {
87 return buttons.Add(caption, listener, id);
90 WndButton *AddButton(const TCHAR *caption, int modal_result) {
91 return AddButton(caption, *this, modal_result);
94 int ShowModal();
96 /* virtual methods from class ActionListener */
97 virtual void OnAction(int id) override;
99 private:
100 void AutoSize();
102 protected:
103 /* virtual methods from class Window */
104 virtual void OnDestroy() override;
105 virtual void OnResize(PixelSize new_size) override;
109 * Show a #Widget in a dialog, with OK and Cancel buttons.
111 * @param widget the #Widget to be displayed; it is not "prepared" and
112 * will be "unprepared" (but "initialised") before returning; the
113 * caller is responsible for destructing it
114 * @return true if changed data was saved
116 bool
117 DefaultWidgetDialog(SingleWindow &parent, const DialogLook &look,
118 const TCHAR *caption, const PixelRect &rc, Widget &widget);
120 bool
121 DefaultWidgetDialog(SingleWindow &parent, const DialogLook &look,
122 const TCHAR *caption, Widget &widget);
124 #endif