]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/dialog.h
cf2b2362d809ccd483abf66098e3b1864e41d1c5
[xonotic/netradiant.git] / radiant / dialog.h
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_DIALOG_H )
23 #define INCLUDED_DIALOG_H
24
25 #include <list>
26 #include <uilib/uilib.h>
27
28 #include "generic/callback.h"
29 #include "gtkutil/dialog.h"
30 #include "generic/callback.h"
31 #include "string/string.h"
32
33 template<class Self, class T = Self>
34 struct impexp {
35     static void Import(Self &self, T value) {
36         self = value;
37     }
38
39     static void Export(Self &self, const Callback<void(T)> &importCallback) {
40         importCallback(self);
41     }
42 };
43
44 template<class Self, class T = Self>
45 ImportExportCallback<T> mkImportExportCallback(Self &self) {
46     return {
47             ReferenceCaller<Self, void(T), impexp<Self, T>::Import>(self),
48             ReferenceCaller<Self, void(const Callback<void(T)> &), impexp<Self, T>::Export>(self)
49     };
50 }
51
52 #define BoolImport impexp<bool>::Import
53 #define BoolExport impexp<bool>::Export
54
55 typedef ReferenceCaller<bool, void(const Callback<void(bool)> &), BoolExport> BoolExportCaller;
56
57 #define IntImport impexp<int>::Import
58 #define IntExport impexp<int>::Export
59
60 typedef ReferenceCaller<int, void(const Callback<void(int)> &), IntExport> IntExportCaller;
61
62 #define SizeImport impexp<std::size_t>::Import
63 #define SizeExport impexp<std::size_t>::Export
64
65
66 #define FloatImport impexp<float>::Import
67 #define FloatExport impexp<float>::Export
68
69 typedef ReferenceCaller<float, void(const Callback<void(float)> &), FloatExport> FloatExportCaller;
70
71 #define StringImport impexp<CopiedString, const char *>::Import
72 #define StringExport impexp<CopiedString, const char *>::Export
73
74 template<>
75 struct impexp<CopiedString, const char *> {
76     static void Import(CopiedString &self, const char *value) {
77         self = value;
78     }
79
80     static void Export(CopiedString &self, const Callback<void(const char *)> &importCallback) {
81         importCallback(self.c_str());
82     }
83 };
84
85 typedef ReferenceCaller<CopiedString, void(const Callback<void(const char *)> &), StringExport> StringExportCaller;
86
87
88 struct DLG_DATA
89 {
90         virtual ~DLG_DATA() = default;
91         virtual void release() = 0;
92         virtual void importData() const = 0;
93         virtual void exportData() const = 0;
94 };
95
96
97 template<typename FirstArgument>
98 class CallbackDialogData;
99
100 typedef std::list<DLG_DATA*> DialogDataList;
101
102 class Dialog
103 {
104 ui::Window m_window;
105 DialogDataList m_data;
106 public:
107 ModalDialog m_modal;
108 ui::Window m_parent;
109
110 Dialog();
111 virtual ~Dialog();
112
113 /*!
114    start modal dialog box
115    you need to use AddModalButton to select eIDOK eIDCANCEL buttons
116  */
117 EMessageBoxReturn DoModal();
118 void EndModal( EMessageBoxReturn code );
119 virtual ui::Window BuildDialog() = 0;
120 virtual void exportData();
121 virtual void importData();
122 virtual void PreModal() { };
123 virtual void PostModal( EMessageBoxReturn code ) { };
124 virtual void ShowDlg();
125 virtual void HideDlg();
126 void Create();
127 void Destroy();
128 ui::Window GetWidget(){
129         return m_window;
130 }
131 const ui::Window GetWidget() const {
132         return m_window;
133 }
134
135     ui::CheckButton addCheckBox(ui::VBox vbox, const char *name, const char *flag, ImportExportCallback<bool> const &cb);
136 ui::CheckButton addCheckBox( ui::VBox vbox, const char* name, const char* flag, bool& data );
137
138     void addCombo(ui::VBox vbox, const char *name, StringArrayRange values, ImportExportCallback<int> const &cb);
139 void addCombo( ui::VBox vbox, const char* name, int& data, StringArrayRange values );
140 void addSlider( ui::VBox vbox, const char* name, int& data, gboolean draw_value, const char* low, const char* high, double value, double lower, double upper, double step_increment, double page_increment );
141
142     void addRadio(ui::VBox vbox, const char *name, StringArrayRange names, ImportExportCallback<int> const &cb);
143 void addRadio( ui::VBox vbox, const char* name, int& data, StringArrayRange names );
144
145     void addRadioIcons(ui::VBox vbox, const char *name, StringArrayRange icons, ImportExportCallback<int> const &cb);
146 void addRadioIcons( ui::VBox vbox, const char* name, int& data, StringArrayRange icons );
147
148     ui::Widget addIntEntry(ui::VBox vbox, const char *name, ImportExportCallback<int> const &cb);
149 ui::Widget addEntry( ui::VBox vbox, const char* name, int& data ){
150     return addIntEntry(vbox, name, mkImportExportCallback(data));
151 }
152
153     ui::Widget addSizeEntry(ui::VBox vbox, const char *name, ImportExportCallback<std::size_t> const &cb);
154 ui::Widget addEntry( ui::VBox vbox, const char* name, std::size_t& data ){
155     return addSizeEntry(vbox, name, mkImportExportCallback(data));
156 }
157
158     ui::Widget addFloatEntry(ui::VBox vbox, const char *name, ImportExportCallback<float> const &cb);
159 ui::Widget addEntry( ui::VBox vbox, const char* name, float& data ){
160     return addFloatEntry(vbox, name, mkImportExportCallback(data));
161 }
162
163     ui::Widget
164     addPathEntry(ui::VBox vbox, const char *name, bool browse_directory, ImportExportCallback<const char *> const &cb);
165 ui::Widget addPathEntry( ui::VBox vbox, const char* name, CopiedString& data, bool directory );
166 ui::SpinButton addSpinner( ui::VBox vbox, const char* name, int& data, double value, double lower, double upper );
167
168     ui::SpinButton
169     addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, ImportExportCallback<int> const &cb);
170
171     ui::SpinButton addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper,
172                               ImportExportCallback<float> const &cb);
173
174 protected:
175
176     void AddBoolToggleData(struct _GtkToggleButton &object, ImportExportCallback<bool> const &cb);
177
178     void AddIntRadioData(struct _GtkRadioButton &object, ImportExportCallback<int> const &cb);
179
180     void AddTextEntryData(struct _GtkEntry &object, ImportExportCallback<const char *> const &cb);
181
182     void AddIntEntryData(struct _GtkEntry &object, ImportExportCallback<int> const &cb);
183
184     void AddSizeEntryData(struct _GtkEntry &object, ImportExportCallback<std::size_t> const &cb);
185
186     void AddFloatEntryData(struct _GtkEntry &object, ImportExportCallback<float> const &cb);
187
188     void AddFloatSpinnerData(struct _GtkSpinButton &object, ImportExportCallback<float> const &cb);
189
190     void AddIntSpinnerData(struct _GtkSpinButton &object, ImportExportCallback<int> const &cb);
191
192     void AddIntAdjustmentData(struct _GtkAdjustment &object, ImportExportCallback<int> const &cb);
193
194     void AddIntComboData(struct _GtkComboBox &object, ImportExportCallback<int> const &cb);
195
196 void AddDialogData( struct _GtkToggleButton& object, bool& data );
197 void AddDialogData( struct _GtkRadioButton& object, int& data );
198 void AddDialogData( struct _GtkEntry& object, CopiedString& data );
199 void AddDialogData( struct _GtkEntry& object, int& data );
200 void AddDialogData( struct _GtkEntry& object, std::size_t& data );
201 void AddDialogData( struct _GtkEntry& object, float& data );
202 void AddDialogData( struct _GtkSpinButton& object, float& data );
203 void AddDialogData( struct _GtkSpinButton& object, int& data );
204 void AddDialogData( struct _GtkAdjustment& object, int& data );
205 void AddDialogData( struct _GtkComboBox& object, int& data );
206 };
207
208 #endif