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