]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/dialog.cpp
Remove implicit Window constructor
[xonotic/netradiant.git] / radiant / dialog.cpp
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 //
23 // Base dialog class, provides a way to run modal dialogs and
24 // set/get the widget values in member variables.
25 //
26 // Leonardo Zide (leo@lokigames.com)
27 //
28
29 #include "dialog.h"
30
31 #include "debugging/debugging.h"
32
33
34 #include "mainframe.h"
35
36 #include <stdlib.h>
37
38 #include "stream/stringstream.h"
39 #include "convert.h"
40 #include "gtkutil/dialog.h"
41 #include "gtkutil/button.h"
42 #include "gtkutil/entry.h"
43 #include "gtkutil/image.h"
44
45 #include "gtkmisc.h"
46
47
48 ui::Entry DialogEntry_new(){
49         auto entry = ui::Entry();
50         entry.show();
51         gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 );
52         return entry;
53 }
54
55 class DialogEntryRow
56 {
57 public:
58 DialogEntryRow( ui::Widget row, GtkEntry* entry ) : m_row( row ), m_entry( entry ){
59 }
60 ui::Widget m_row;
61 GtkEntry* m_entry;
62 };
63
64 DialogEntryRow DialogEntryRow_new( const char* name ){
65         auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
66         alignment.show();
67
68         auto entry = DialogEntry_new();
69         alignment.add(entry);
70
71         return DialogEntryRow( ui::Widget(GTK_WIDGET( DialogRow_new( name, alignment ) )), entry );
72 }
73
74
75 ui::SpinButton DialogSpinner_new( double value, double lower, double upper, int fraction ){
76         double step = 1.0 / double(fraction);
77         unsigned int digits = 0;
78         for (; fraction > 1; fraction /= 10 )
79         {
80                 ++digits;
81         }
82         auto spin = ui::SpinButton( ui::Adjustment( value, lower, upper, step, 10, 0 ), step, digits );
83         spin.show();
84         gtk_widget_set_size_request( GTK_WIDGET( spin ), 64, -1 );
85         return spin;
86 }
87
88 class DialogSpinnerRow
89 {
90 public:
91 DialogSpinnerRow( ui::Widget row, GtkSpinButton* spin ) : m_row( row ), m_spin( spin ){
92 }
93 ui::Widget m_row;
94 GtkSpinButton* m_spin;
95 };
96
97 DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lower, double upper, int fraction ){
98         auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
99         alignment.show();
100
101         auto spin = DialogSpinner_new( value, lower, upper, fraction );
102         alignment.add(spin);
103
104         return DialogSpinnerRow( ui::Widget(GTK_WIDGET( DialogRow_new( name, alignment ) )), spin );
105 }
106
107
108
109 template<
110         typename Type_,
111         typename Other_,
112         void( *Import ) ( Type_&, Other_ ),
113         void( *Export ) ( Type_&, const Callback1<Other_>& )
114         >
115 class ImportExport
116 {
117 public:
118 typedef Type_ Type;
119 typedef Other_ Other;
120
121 typedef ReferenceCaller1<Type, Other, Import> ImportCaller;
122 typedef ReferenceCaller1<Type, const Callback1<Other>&, Export> ExportCaller;
123 };
124
125 typedef ImportExport<bool, bool, BoolImport, BoolExport> BoolImportExport;
126 typedef ImportExport<int, int, IntImport, IntExport> IntImportExport;
127 typedef ImportExport<std::size_t, std::size_t, SizeImport, SizeExport> SizeImportExport;
128 typedef ImportExport<float, float, FloatImport, FloatExport> FloatImportExport;
129 typedef ImportExport<CopiedString, const char*, StringImport, StringExport> StringImportExport;
130
131
132
133 void BoolToggleImport( GtkToggleButton& widget, bool value ){
134         gtk_toggle_button_set_active( &widget, value );
135 }
136 void BoolToggleExport( GtkToggleButton& widget, const BoolImportCallback& importCallback ){
137         importCallback( gtk_toggle_button_get_active( &widget ) != FALSE );
138 }
139 typedef ImportExport<GtkToggleButton, bool, BoolToggleImport, BoolToggleExport> BoolToggleImportExport;
140
141
142 void IntRadioImport( GtkRadioButton& widget, int index ){
143         radio_button_set_active( ui::RadioButton(&widget), index );
144 }
145 void IntRadioExport( GtkRadioButton& widget, const IntImportCallback& importCallback ){
146         importCallback( radio_button_get_active( ui::RadioButton(&widget) ) );
147 }
148 typedef ImportExport<GtkRadioButton, int, IntRadioImport, IntRadioExport> IntRadioImportExport;
149
150 void TextEntryImport( GtkEntry& widget, const char* text ){
151         gtk_entry_set_text( &widget, text );
152 }
153 void TextEntryExport( GtkEntry& widget, const StringImportCallback& importCallback ){
154         importCallback( gtk_entry_get_text( &widget ) );
155 }
156 typedef ImportExport<GtkEntry, const char*, TextEntryImport, TextEntryExport> TextEntryImportExport;
157
158
159 void IntEntryImport( GtkEntry& widget, int value ){
160         entry_set_int( ui::Entry(&widget), value );
161 }
162 void IntEntryExport( GtkEntry& widget, const IntImportCallback& importCallback ){
163         importCallback( atoi( gtk_entry_get_text( &widget ) ) );
164 }
165 typedef ImportExport<GtkEntry, int, IntEntryImport, IntEntryExport> IntEntryImportExport;
166
167
168 void SizeEntryImport( GtkEntry& widget, std::size_t value ){
169         entry_set_int( ui::Entry(&widget), int(value) );
170 }
171 void SizeEntryExport( GtkEntry& widget, const SizeImportCallback& importCallback ){
172         int value = atoi( gtk_entry_get_text( &widget ) );
173         if ( value < 0 ) {
174                 value = 0;
175         }
176         importCallback( value );
177 }
178 typedef ImportExport<GtkEntry, std::size_t, SizeEntryImport, SizeEntryExport> SizeEntryImportExport;
179
180
181 void FloatEntryImport( GtkEntry& widget, float value ){
182         entry_set_float( ui::Entry(&widget), value );
183 }
184 void FloatEntryExport( GtkEntry& widget, const FloatImportCallback& importCallback ){
185         importCallback( (float)atof( gtk_entry_get_text( &widget ) ) );
186 }
187 typedef ImportExport<GtkEntry, float, FloatEntryImport, FloatEntryExport> FloatEntryImportExport;
188
189
190 void FloatSpinnerImport( GtkSpinButton& widget, float value ){
191         gtk_spin_button_set_value( &widget, value );
192 }
193 void FloatSpinnerExport( GtkSpinButton& widget, const FloatImportCallback& importCallback ){
194         importCallback( float(gtk_spin_button_get_value( &widget ) ) );
195 }
196 typedef ImportExport<GtkSpinButton, float, FloatSpinnerImport, FloatSpinnerExport> FloatSpinnerImportExport;
197
198
199 void IntSpinnerImport( GtkSpinButton& widget, int value ){
200         gtk_spin_button_set_value( &widget, value );
201 }
202 void IntSpinnerExport( GtkSpinButton& widget, const IntImportCallback& importCallback ){
203         importCallback( gtk_spin_button_get_value_as_int( &widget ) );
204 }
205 typedef ImportExport<GtkSpinButton, int, IntSpinnerImport, IntSpinnerExport> IntSpinnerImportExport;
206
207
208 void IntAdjustmentImport( GtkAdjustment& widget, int value ){
209         gtk_adjustment_set_value( &widget, value );
210 }
211 void IntAdjustmentExport( GtkAdjustment& widget, const IntImportCallback& importCallback ){
212         importCallback( (int)gtk_adjustment_get_value( &widget ) );
213 }
214 typedef ImportExport<GtkAdjustment, int, IntAdjustmentImport, IntAdjustmentExport> IntAdjustmentImportExport;
215
216
217 void IntComboImport( GtkComboBox& widget, int value ){
218         gtk_combo_box_set_active( &widget, value );
219 }
220 void IntComboExport( GtkComboBox& widget, const IntImportCallback& importCallback ){
221         importCallback( gtk_combo_box_get_active( &widget ) );
222 }
223 typedef ImportExport<GtkComboBox, int, IntComboImport, IntComboExport> IntComboImportExport;
224
225
226 template<typename FirstArgument>
227 class CallbackDialogData : public DLG_DATA
228 {
229 public:
230 typedef Callback1<FirstArgument> ImportCallback;
231 typedef Callback1<const ImportCallback&> ExportCallback;
232
233 private:
234 ImportCallback m_importWidget;
235 ExportCallback m_exportWidget;
236 ImportCallback m_importViewer;
237 ExportCallback m_exportViewer;
238
239 public:
240 CallbackDialogData( const ImportCallback& importWidget, const ExportCallback& exportWidget, const ImportCallback& importViewer, const ExportCallback& exportViewer )
241         : m_importWidget( importWidget ), m_exportWidget( exportWidget ), m_importViewer( importViewer ), m_exportViewer( exportViewer ){
242 }
243 void release(){
244         delete this;
245 }
246 void importData() const {
247         m_exportViewer( m_importWidget );
248 }
249 void exportData() const {
250         m_exportWidget( m_importViewer );
251 }
252 };
253
254 template<typename Widget, typename Viewer>
255 class AddData
256 {
257 DialogDataList& m_data;
258 public:
259 AddData( DialogDataList& data ) : m_data( data ){
260 }
261 void apply( typename Widget::Type& widget, typename Viewer::Type& viewer ) const {
262         m_data.push_back(
263                 new CallbackDialogData<typename Widget::Other>(
264                         typename Widget::ImportCaller( widget ),
265                         typename Widget::ExportCaller( widget ),
266                         typename Viewer::ImportCaller( viewer ),
267                         typename Viewer::ExportCaller( viewer )
268                         )
269                 );
270 }
271 };
272
273 template<typename Widget>
274 class AddCustomData
275 {
276 DialogDataList& m_data;
277 public:
278 AddCustomData( DialogDataList& data ) : m_data( data ){
279 }
280 void apply(
281         typename Widget::Type& widget,
282         const Callback1<typename Widget::Other>& importViewer,
283         const Callback1<const Callback1<typename Widget::Other>&>& exportViewer
284         ) const {
285         m_data.push_back(
286                 new CallbackDialogData<typename Widget::Other>(
287                         typename Widget::ImportCaller( widget ),
288                         typename Widget::ExportCaller( widget ),
289                         importViewer,
290                         exportViewer
291                         )
292                 );
293 }
294 };
295
296 // =============================================================================
297 // Dialog class
298
299 Dialog::Dialog() : m_window( 0 ), m_parent( 0 ){
300 }
301
302 Dialog::~Dialog(){
303         for ( DialogDataList::iterator i = m_data.begin(); i != m_data.end(); ++i )
304         {
305                 ( *i )->release();
306         }
307
308         ASSERT_MESSAGE( !m_window, "dialog window not destroyed" );
309 }
310
311 void Dialog::ShowDlg(){
312         ASSERT_MESSAGE( m_window, "dialog was not constructed" );
313         importData();
314         m_window.show();
315 }
316
317 void Dialog::HideDlg(){
318         ASSERT_MESSAGE( m_window, "dialog was not constructed" );
319         exportData();
320         gtk_widget_hide( GTK_WIDGET( m_window ) );
321 }
322
323 static gint delete_event_callback( ui::Widget widget, GdkEvent* event, gpointer data ){
324         reinterpret_cast<Dialog*>( data )->HideDlg();
325         reinterpret_cast<Dialog*>( data )->EndModal( eIDCANCEL );
326         return TRUE;
327 }
328
329 void Dialog::Create(){
330         ASSERT_MESSAGE( !m_window, "dialog cannot be constructed" );
331
332         m_window = BuildDialog();
333         g_signal_connect( G_OBJECT( m_window ), "delete_event", G_CALLBACK( delete_event_callback ), this );
334 }
335
336 void Dialog::Destroy(){
337         ASSERT_MESSAGE( m_window, "dialog cannot be destroyed" );
338
339         gtk_widget_destroy( GTK_WIDGET( m_window ) );
340         m_window = ui::Window{ui::null};
341 }
342
343
344 void Dialog::AddBoolToggleData( GtkToggleButton& widget, const BoolImportCallback& importViewer, const BoolExportCallback& exportViewer ){
345         AddCustomData<BoolToggleImportExport>( m_data ).apply( widget, importViewer, exportViewer );
346 }
347
348 void Dialog::AddIntRadioData( GtkRadioButton& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
349         AddCustomData<IntRadioImportExport>( m_data ).apply( widget, importViewer, exportViewer );
350 }
351
352 void Dialog::AddTextEntryData( GtkEntry& widget, const StringImportCallback& importViewer, const StringExportCallback& exportViewer ){
353         AddCustomData<TextEntryImportExport>( m_data ).apply( widget, importViewer, exportViewer );
354 }
355
356 void Dialog::AddIntEntryData( GtkEntry& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
357         AddCustomData<IntEntryImportExport>( m_data ).apply( widget, importViewer, exportViewer );
358 }
359
360 void Dialog::AddSizeEntryData( GtkEntry& widget, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer ){
361         AddCustomData<SizeEntryImportExport>( m_data ).apply( widget, importViewer, exportViewer );
362 }
363
364 void Dialog::AddFloatEntryData( GtkEntry& widget, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){
365         AddCustomData<FloatEntryImportExport>( m_data ).apply( widget, importViewer, exportViewer );
366 }
367
368 void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){
369         AddCustomData<FloatSpinnerImportExport>( m_data ).apply( widget, importViewer, exportViewer );
370 }
371
372 void Dialog::AddIntSpinnerData( GtkSpinButton& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
373         AddCustomData<IntSpinnerImportExport>( m_data ).apply( widget, importViewer, exportViewer );
374 }
375
376 void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
377         AddCustomData<IntAdjustmentImportExport>( m_data ).apply( widget, importViewer, exportViewer );
378 }
379
380 void Dialog::AddIntComboData( GtkComboBox& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
381         AddCustomData<IntComboImportExport>( m_data ).apply( widget, importViewer, exportViewer );
382 }
383
384
385 void Dialog::AddDialogData( GtkToggleButton& widget, bool& data ){
386         AddData<BoolToggleImportExport, BoolImportExport>( m_data ).apply( widget, data );
387 }
388 void Dialog::AddDialogData( GtkRadioButton& widget, int& data ){
389         AddData<IntRadioImportExport, IntImportExport>( m_data ).apply( widget, data );
390 }
391 void Dialog::AddDialogData( GtkEntry& widget, CopiedString& data ){
392         AddData<TextEntryImportExport, StringImportExport>( m_data ).apply( widget, data );
393 }
394 void Dialog::AddDialogData( GtkEntry& widget, int& data ){
395         AddData<IntEntryImportExport, IntImportExport>( m_data ).apply( widget, data );
396 }
397 void Dialog::AddDialogData( GtkEntry& widget, std::size_t& data ){
398         AddData<SizeEntryImportExport, SizeImportExport>( m_data ).apply( widget, data );
399 }
400 void Dialog::AddDialogData( GtkEntry& widget, float& data ){
401         AddData<FloatEntryImportExport, FloatImportExport>( m_data ).apply( widget, data );
402 }
403 void Dialog::AddDialogData( GtkSpinButton& widget, float& data ){
404         AddData<FloatSpinnerImportExport, FloatImportExport>( m_data ).apply( widget, data );
405 }
406 void Dialog::AddDialogData( GtkSpinButton& widget, int& data ){
407         AddData<IntSpinnerImportExport, IntImportExport>( m_data ).apply( widget, data );
408 }
409 void Dialog::AddDialogData( GtkAdjustment& widget, int& data ){
410         AddData<IntAdjustmentImportExport, IntImportExport>( m_data ).apply( widget, data );
411 }
412 void Dialog::AddDialogData( GtkComboBox& widget, int& data ){
413         AddData<IntComboImportExport, IntImportExport>( m_data ).apply( widget, data );
414 }
415
416 void Dialog::exportData(){
417         for ( DialogDataList::iterator i = m_data.begin(); i != m_data.end(); ++i )
418         {
419                 ( *i )->exportData();
420         }
421 }
422
423 void Dialog::importData(){
424         for ( DialogDataList::iterator i = m_data.begin(); i != m_data.end(); ++i )
425         {
426                 ( *i )->importData();
427         }
428 }
429
430 void Dialog::EndModal( EMessageBoxReturn code ){
431         m_modal.loop = 0;
432         m_modal.ret = code;
433 }
434
435 EMessageBoxReturn Dialog::DoModal(){
436         importData();
437
438         PreModal();
439
440         EMessageBoxReturn ret = modal_dialog_show( m_window, m_modal );
441         ASSERT_TRUE( (bool) m_window );
442         if ( ret == eIDOK ) {
443                 exportData();
444         }
445
446         gtk_widget_hide( GTK_WIDGET( m_window ) );
447
448         PostModal( m_modal.ret );
449
450         return m_modal.ret;
451 }
452
453
454 ui::CheckButton Dialog::addCheckBox( ui::Widget vbox, const char* name, const char* flag, const BoolImportCallback& importViewer, const BoolExportCallback& exportViewer ){
455         auto check = ui::CheckButton( flag );
456         check.show();
457         AddBoolToggleData( *GTK_TOGGLE_BUTTON( check ), importViewer, exportViewer );
458
459         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), ui::Widget(GTK_WIDGET( DialogRow_new( name, check ) ) ));
460         return check;
461 }
462
463 ui::CheckButton Dialog::addCheckBox( ui::Widget vbox, const char* name, const char* flag, bool& data ){
464         return addCheckBox( vbox, name, flag, BoolImportCaller( data ), BoolExportCaller( data ) );
465 }
466
467 void Dialog::addCombo( ui::Widget vbox, const char* name, StringArrayRange values, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
468         auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
469         alignment.show();
470         {
471                 ui::Widget combo = ui::ComboBoxText();
472
473                 for ( StringArrayRange::Iterator i = values.first; i != values.last; ++i )
474                 {
475                         gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), *i );
476                 }
477
478                 AddIntComboData( *GTK_COMBO_BOX( combo ), importViewer, exportViewer );
479
480                 combo.show();
481                 alignment.add(combo);
482         }
483
484         auto row = DialogRow_new( name, alignment );
485         DialogVBox_packRow( ui::VBox(GTK_VBOX(vbox)), row );
486 }
487
488 void Dialog::addCombo( ui::Widget vbox, const char* name, int& data, StringArrayRange values ){
489         addCombo( vbox, name, values, IntImportCaller( data ), IntExportCaller( data ) );
490 }
491
492 void Dialog::addSlider( ui::Widget 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 ){
493 #if 0
494         if ( draw_value == FALSE ) {
495                 ui::Widget hbox2 = ui::HBox( FALSE, 0 );
496                 hbox2.show();
497                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox2 ), FALSE, FALSE, 0 );
498                 {
499                         ui::Widget label = ui::Label( low );
500                         label.show();
501                         gtk_box_pack_start( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 );
502                 }
503                 {
504                         ui::Widget label = ui::Label( high );
505                         label.show();
506                         gtk_box_pack_end( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 );
507                 }
508         }
509 #endif
510
511         // adjustment
512         auto adj = ui::Adjustment( value, lower, upper, step_increment, page_increment, 0 );
513         AddIntAdjustmentData( *GTK_ADJUSTMENT(adj), IntImportCaller( data ), IntExportCaller( data ) );
514
515         // scale
516         auto alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 );
517         alignment.show();
518
519         ui::Widget scale = ui::HScale( adj );
520         gtk_scale_set_value_pos( GTK_SCALE( scale ), GTK_POS_LEFT );
521         scale.show();
522         alignment.add(scale);
523
524         gtk_scale_set_draw_value( GTK_SCALE( scale ), draw_value );
525         gtk_scale_set_digits( GTK_SCALE( scale ), 0 );
526
527         auto row = DialogRow_new( name, alignment );
528         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row );
529 }
530
531 void Dialog::addRadio( ui::Widget vbox, const char* name, StringArrayRange names, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
532         auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
533         alignment.show();;
534         {
535                 RadioHBox radioBox = RadioHBox_new( names );
536                 alignment.add(radioBox.m_hbox);
537                 AddIntRadioData( *GTK_RADIO_BUTTON( radioBox.m_radio ), importViewer, exportViewer );
538         }
539
540         auto row = DialogRow_new( name, alignment );
541         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row );
542 }
543
544 void Dialog::addRadio( ui::Widget vbox, const char* name, int& data, StringArrayRange names ){
545         addRadio( vbox, name, names, IntImportCaller( data ), IntExportCaller( data ) );
546 }
547
548 void Dialog::addRadioIcons( ui::Widget vbox, const char* name, StringArrayRange icons, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
549         ui::Widget table = ui::Table( 2, icons.last - icons.first, FALSE );
550         table.show();;
551
552         gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
553         gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
554
555         GSList* group = 0;
556         ui::Widget radio;
557         for ( StringArrayRange::Iterator icon = icons.first; icon != icons.last; ++icon )
558         {
559                 guint pos = static_cast<guint>( icon - icons.first );
560                 auto image = new_local_image( *icon );
561                 image.show();
562                 gtk_table_attach( GTK_TABLE( table ), GTK_WIDGET( image ), pos, pos + 1, 0, 1,
563                                                   (GtkAttachOptions) ( 0 ),
564                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
565
566                 radio = ui::Widget(gtk_radio_button_new( group ));
567                 radio.show();
568                 gtk_table_attach( GTK_TABLE( table ), radio, pos, pos + 1, 1, 2,
569                                                   (GtkAttachOptions) ( 0 ),
570                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
571
572                 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( radio ) );
573         }
574
575         AddIntRadioData( *GTK_RADIO_BUTTON( radio ), importViewer, exportViewer );
576
577         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), DialogRow_new( name, table ) );
578 }
579
580 void Dialog::addRadioIcons( ui::Widget vbox, const char* name, int& data, StringArrayRange icons ){
581         addRadioIcons( vbox, name, icons, IntImportCaller( data ), IntExportCaller( data ) );
582 }
583
584 ui::Widget Dialog::addIntEntry( ui::Widget vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
585         DialogEntryRow row( DialogEntryRow_new( name ) );
586         AddIntEntryData( *row.m_entry, importViewer, exportViewer );
587         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
588         return row.m_row;
589 }
590
591 ui::Widget Dialog::addSizeEntry( ui::Widget vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer ){
592         DialogEntryRow row( DialogEntryRow_new( name ) );
593         AddSizeEntryData( *row.m_entry, importViewer, exportViewer );
594         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
595         return row.m_row;
596 }
597
598 ui::Widget Dialog::addFloatEntry( ui::Widget vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){
599         DialogEntryRow row( DialogEntryRow_new( name ) );
600         AddFloatEntryData( *row.m_entry, importViewer, exportViewer );
601         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
602         return row.m_row;
603 }
604
605 ui::Widget Dialog::addPathEntry( ui::Widget vbox, const char* name, bool browse_directory, const StringImportCallback& importViewer, const StringExportCallback& exportViewer ){
606         PathEntry pathEntry = PathEntry_new();
607         g_signal_connect( G_OBJECT( pathEntry.m_button ), "clicked", G_CALLBACK( browse_directory ? button_clicked_entry_browse_directory : button_clicked_entry_browse_file ), pathEntry.m_entry );
608
609         AddTextEntryData( *GTK_ENTRY( pathEntry.m_entry ), importViewer, exportViewer );
610
611         auto row = DialogRow_new( name, ui::Widget(GTK_WIDGET( pathEntry.m_frame )) );
612         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row );
613
614         return ui::Widget(GTK_WIDGET( row ));
615 }
616
617 ui::Widget Dialog::addPathEntry( ui::Widget vbox, const char* name, CopiedString& data, bool browse_directory ){
618         return addPathEntry( vbox, name, browse_directory, StringImportCallback( StringImportCaller( data ) ), StringExportCallback( StringExportCaller( data ) ) );
619 }
620
621 ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, double value, double lower, double upper, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
622         DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 1 ) );
623         AddIntSpinnerData( *row.m_spin, importViewer, exportViewer );
624         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
625         return ui::SpinButton(row.m_spin);
626 }
627
628 ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, int& data, double value, double lower, double upper ){
629         return addSpinner( vbox, name, value, lower, upper, IntImportCallback( IntImportCaller( data ) ), IntExportCallback( IntExportCaller( data ) ) );
630 }
631
632 ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, double value, double lower, double upper, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){
633         DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 10 ) );
634         AddFloatSpinnerData( *row.m_spin, importViewer, exportViewer );
635         DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
636         return ui::SpinButton(row.m_spin);
637 }