]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/dialog.cpp
GTK: wrap GTK_WIDGET
[xonotic/netradiant.git] / radiant / dialog.cpp
index fc35fd76015978035c063a4cb515de59a4217ac6..e588f93ff8599d2e0e0552aa77793af936f8afe5 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "dialog.h"
 
+#include <gtk/gtk.h>
+
 #include "debugging/debugging.h"
 
 
 #include "gtkmisc.h"
 
 
-GtkEntry* DialogEntry_new(){
-       auto entry = ui::Entry();
-       gtk_widget_show( GTK_WIDGET( entry ) );
-       gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 );
+ui::Entry DialogEntry_new(){
+       auto entry = ui::Entry(ui::New);
+       entry.show();
+       gtk_widget_set_size_request( entry , 64, -1 );
        return entry;
 }
 
 class DialogEntryRow
 {
 public:
-DialogEntryRow( ui::Widget row, GtkEntry* entry ) : m_row( row ), m_entry( entry ){
+DialogEntryRow( ui::Widget row, ui::Entry entry ) : m_row( row ), m_entry( entry ){
 }
 ui::Widget m_row;
-GtkEntry* m_entry;
+ui::Entry m_entry;
 };
 
 DialogEntryRow DialogEntryRow_new( const char* name ){
-       ui::Widget alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
-       gtk_widget_show( alignment );
+       auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
+       alignment.show();
 
-       GtkEntry* entry = DialogEntry_new();
-       gtk_container_add( GTK_CONTAINER( alignment ), GTK_WIDGET( entry ) );
+       auto entry = DialogEntry_new();
+       alignment.add(entry);
 
-       return DialogEntryRow( ui::Widget(GTK_WIDGET( DialogRow_new( name, alignment ) )), entry );
+       return DialogEntryRow( ui::Widget(DialogRow_new( name, alignment  )), entry );
 }
 
 
-GtkSpinButton* DialogSpinner_new( double value, double lower, double upper, int fraction ){
+ui::SpinButton DialogSpinner_new( double value, double lower, double upper, int fraction ){
        double step = 1.0 / double(fraction);
        unsigned int digits = 0;
        for (; fraction > 1; fraction /= 10 )
        {
                ++digits;
        }
-       GtkSpinButton* spin = ui::SpinButton( ui::Adjustment( value, lower, upper, step, 10, 0 ), step, digits );
-       gtk_widget_show( GTK_WIDGET( spin ) );
-       gtk_widget_set_size_request( GTK_WIDGET( spin ), 64, -1 );
+       auto spin = ui::SpinButton( ui::Adjustment( value, lower, upper, step, 10, 0 ), step, digits );
+       spin.show();
+       gtk_widget_set_size_request( spin , 64, -1 );
        return spin;
 }
 
@@ -91,17 +93,17 @@ public:
 DialogSpinnerRow( ui::Widget row, GtkSpinButton* spin ) : m_row( row ), m_spin( spin ){
 }
 ui::Widget m_row;
-GtkSpinButton* m_spin;
+ui::SpinButton m_spin;
 };
 
 DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lower, double upper, int fraction ){
-       ui::Widget alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
-       gtk_widget_show( alignment );
+       auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
+       alignment.show();
 
-       GtkSpinButton* spin = DialogSpinner_new( value, lower, upper, fraction );
-       gtk_container_add( GTK_CONTAINER( alignment ), GTK_WIDGET( spin ) );
+       auto spin = DialogSpinner_new( value, lower, upper, fraction );
+       alignment.add(spin);
 
-       return DialogSpinnerRow( ui::Widget(GTK_WIDGET( DialogRow_new( name, alignment ) )), spin );
+       return DialogSpinnerRow( ui::Widget(DialogRow_new( name, alignment  )), spin );
 }
 
 
@@ -148,7 +150,7 @@ void IntRadioExport( GtkRadioButton& widget, const IntImportCallback& importCall
 typedef ImportExport<GtkRadioButton, int, IntRadioImport, IntRadioExport> IntRadioImportExport;
 
 void TextEntryImport( GtkEntry& widget, const char* text ){
-       gtk_entry_set_text( &widget, text );
+       ui::Entry(&widget).text(text);
 }
 void TextEntryExport( GtkEntry& widget, const StringImportCallback& importCallback ){
        importCallback( gtk_entry_get_text( &widget ) );
@@ -311,13 +313,13 @@ Dialog::~Dialog(){
 void Dialog::ShowDlg(){
        ASSERT_MESSAGE( m_window, "dialog was not constructed" );
        importData();
-       gtk_widget_show( GTK_WIDGET( m_window ) );
+       m_window.show();
 }
 
 void Dialog::HideDlg(){
        ASSERT_MESSAGE( m_window, "dialog was not constructed" );
        exportData();
-       gtk_widget_hide( GTK_WIDGET( m_window ) );
+       m_window.hide();
 }
 
 static gint delete_event_callback( ui::Widget widget, GdkEvent* event, gpointer data ){
@@ -330,14 +332,14 @@ void Dialog::Create(){
        ASSERT_MESSAGE( !m_window, "dialog cannot be constructed" );
 
        m_window = BuildDialog();
-       g_signal_connect( G_OBJECT( m_window ), "delete_event", G_CALLBACK( delete_event_callback ), this );
+       m_window.connect( "delete_event", G_CALLBACK( delete_event_callback ), this );
 }
 
 void Dialog::Destroy(){
        ASSERT_MESSAGE( m_window, "dialog cannot be destroyed" );
 
-       gtk_widget_destroy( GTK_WIDGET( m_window ) );
-       m_window = ui::Window();
+       m_window.destroy();
+       m_window = ui::Window{ui::null};
 }
 
 
@@ -443,7 +445,7 @@ EMessageBoxReturn Dialog::DoModal(){
                exportData();
        }
 
-       gtk_widget_hide( GTK_WIDGET( m_window ) );
+       m_window.hide();
 
        PostModal( m_modal.ret );
 
@@ -453,10 +455,10 @@ EMessageBoxReturn Dialog::DoModal(){
 
 ui::CheckButton Dialog::addCheckBox( ui::Widget vbox, const char* name, const char* flag, const BoolImportCallback& importViewer, const BoolExportCallback& exportViewer ){
        auto check = ui::CheckButton( flag );
-       gtk_widget_show( check );
+       check.show();
        AddBoolToggleData( *GTK_TOGGLE_BUTTON( check ), importViewer, exportViewer );
 
-       DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), ui::Widget(GTK_WIDGET( DialogRow_new( name, check ) ) ));
+       DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), ui::Widget(DialogRow_new( name, check  ) ));
        return check;
 }
 
@@ -465,10 +467,10 @@ ui::CheckButton Dialog::addCheckBox( ui::Widget vbox, const char* name, const ch
 }
 
 void Dialog::addCombo( ui::Widget vbox, const char* name, StringArrayRange values, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
-       ui::Widget alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
-       gtk_widget_show( alignment );
+       auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
+       alignment.show();
        {
-               ui::Widget combo = ui::ComboBoxText();
+               auto combo = ui::ComboBoxText(ui::New);
 
                for ( StringArrayRange::Iterator i = values.first; i != values.last; ++i )
                {
@@ -477,8 +479,8 @@ void Dialog::addCombo( ui::Widget vbox, const char* name, StringArrayRange value
 
                AddIntComboData( *GTK_COMBO_BOX( combo ), importViewer, exportViewer );
 
-               gtk_widget_show( combo );
-               gtk_container_add( GTK_CONTAINER( alignment ), combo );
+               combo.show();
+               alignment.add(combo);
        }
 
        auto row = DialogRow_new( name, alignment );
@@ -492,18 +494,18 @@ void Dialog::addCombo( ui::Widget vbox, const char* name, int& data, StringArray
 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 ){
 #if 0
        if ( draw_value == FALSE ) {
-               ui::Widget hbox2 = ui::HBox( FALSE, 0 );
-               gtk_widget_show( hbox2 );
-               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox2 ), FALSE, FALSE, 0 );
+               auto hbox2 = ui::HBox( FALSE, 0 );
+               hbox2.show();
+               vbox.pack_start( hbox2 , FALSE, FALSE, 0 );
                {
                        ui::Widget label = ui::Label( low );
-                       gtk_widget_show( label );
-                       gtk_box_pack_start( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 );
+                       label.show();
+                       hbox2.pack_start( label, FALSE, FALSE, 0 );
                }
                {
                        ui::Widget label = ui::Label( high );
-                       gtk_widget_show( label );
-                       gtk_box_pack_end( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 );
+                       label.show();
+                       hbox2.pack_end(label, FALSE, FALSE, 0);
                }
        }
 #endif
@@ -513,13 +515,13 @@ void Dialog::addSlider( ui::Widget vbox, const char* name, int& data, gboolean d
        AddIntAdjustmentData( *GTK_ADJUSTMENT(adj), IntImportCaller( data ), IntExportCaller( data ) );
 
        // scale
-       ui::Widget alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 );
-       gtk_widget_show( alignment );
+       auto alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 );
+       alignment.show();
 
        ui::Widget scale = ui::HScale( adj );
        gtk_scale_set_value_pos( GTK_SCALE( scale ), GTK_POS_LEFT );
-       gtk_widget_show( scale );
-       gtk_container_add( GTK_CONTAINER( alignment ), scale );
+       scale.show();
+       alignment.add(scale);
 
        gtk_scale_set_draw_value( GTK_SCALE( scale ), draw_value );
        gtk_scale_set_digits( GTK_SCALE( scale ), 0 );
@@ -529,11 +531,11 @@ void Dialog::addSlider( ui::Widget vbox, const char* name, int& data, gboolean d
 }
 
 void Dialog::addRadio( ui::Widget vbox, const char* name, StringArrayRange names, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
-       ui::Widget alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
-       gtk_widget_show( alignment );
+       auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 );
+       alignment.show();;
        {
                RadioHBox radioBox = RadioHBox_new( names );
-               gtk_container_add( GTK_CONTAINER( alignment ), GTK_WIDGET( radioBox.m_hbox ) );
+               alignment.add(radioBox.m_hbox);
                AddIntRadioData( *GTK_RADIO_BUTTON( radioBox.m_radio ), importViewer, exportViewer );
        }
 
@@ -547,24 +549,24 @@ void Dialog::addRadio( ui::Widget vbox, const char* name, int& data, StringArray
 
 void Dialog::addRadioIcons( ui::Widget vbox, const char* name, StringArrayRange icons, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
        ui::Widget table = ui::Table( 2, icons.last - icons.first, FALSE );
-       gtk_widget_show( table );
+       table.show();;
 
        gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
        gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
 
        GSList* group = 0;
-       ui::Widget radio;
+       ui::RadioButton radio{ui::null};
        for ( StringArrayRange::Iterator icon = icons.first; icon != icons.last; ++icon )
        {
                guint pos = static_cast<guint>( icon - icons.first );
-               GtkImage* image = new_local_image( *icon );
-               gtk_widget_show( GTK_WIDGET( image ) );
-               gtk_table_attach( GTK_TABLE( table ), GTK_WIDGET( image ), pos, pos + 1, 0, 1,
+               auto image = new_local_image( *icon );
+               image.show();
+               gtk_table_attach( GTK_TABLE( table ), image , pos, pos + 1, 0, 1,
                                                  (GtkAttachOptions) ( 0 ),
                                                  (GtkAttachOptions) ( 0 ), 0, 0 );
 
-               radio = ui::Widget(gtk_radio_button_new( group ));
-               gtk_widget_show( radio );
+               radio = ui::RadioButton(GTK_RADIO_BUTTON(gtk_radio_button_new( group )));
+               radio.show();
                gtk_table_attach( GTK_TABLE( table ), radio, pos, pos + 1, 1, 2,
                                                  (GtkAttachOptions) ( 0 ),
                                                  (GtkAttachOptions) ( 0 ), 0, 0 );
@@ -583,35 +585,35 @@ void Dialog::addRadioIcons( ui::Widget vbox, const char* name, int& data, String
 
 ui::Widget Dialog::addIntEntry( ui::Widget vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
        DialogEntryRow row( DialogEntryRow_new( name ) );
-       AddIntEntryData( *row.m_entry, importViewer, exportViewer );
+       AddIntEntryData( *GTK_ENTRY(row.m_entry), importViewer, exportViewer );
        DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
        return row.m_row;
 }
 
 ui::Widget Dialog::addSizeEntry( ui::Widget vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer ){
        DialogEntryRow row( DialogEntryRow_new( name ) );
-       AddSizeEntryData( *row.m_entry, importViewer, exportViewer );
+       AddSizeEntryData( *GTK_ENTRY(row.m_entry), importViewer, exportViewer );
        DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
        return row.m_row;
 }
 
 ui::Widget Dialog::addFloatEntry( ui::Widget vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){
        DialogEntryRow row( DialogEntryRow_new( name ) );
-       AddFloatEntryData( *row.m_entry, importViewer, exportViewer );
+       AddFloatEntryData( *GTK_ENTRY(row.m_entry), importViewer, exportViewer );
        DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
        return row.m_row;
 }
 
 ui::Widget Dialog::addPathEntry( ui::Widget vbox, const char* name, bool browse_directory, const StringImportCallback& importViewer, const StringExportCallback& exportViewer ){
        PathEntry pathEntry = PathEntry_new();
-       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 );
+       pathEntry.m_button.connect( "clicked", G_CALLBACK( browse_directory ? button_clicked_entry_browse_directory : button_clicked_entry_browse_file ), pathEntry.m_entry );
 
-       AddTextEntryData( *GTK_ENTRY( pathEntry.m_entry ), importViewer, exportViewer );
+       AddTextEntryData( *GTK_ENTRY(pathEntry.m_entry), importViewer, exportViewer );
 
-       auto row = DialogRow_new( name, ui::Widget(GTK_WIDGET( pathEntry.m_frame )) );
+       auto row = DialogRow_new( name, ui::Widget(pathEntry.m_frame ) );
        DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row );
 
-       return ui::Widget(GTK_WIDGET( row ));
+       return ui::Widget(row );
 }
 
 ui::Widget Dialog::addPathEntry( ui::Widget vbox, const char* name, CopiedString& data, bool browse_directory ){
@@ -620,7 +622,7 @@ ui::Widget Dialog::addPathEntry( ui::Widget vbox, const char* name, CopiedString
 
 ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, double value, double lower, double upper, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){
        DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 1 ) );
-       AddIntSpinnerData( *row.m_spin, importViewer, exportViewer );
+       AddIntSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), importViewer, exportViewer );
        DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
        return ui::SpinButton(row.m_spin);
 }
@@ -631,7 +633,7 @@ ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, int& data,
 
 ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, double value, double lower, double upper, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){
        DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 10 ) );
-       AddFloatSpinnerData( *row.m_spin, importViewer, exportViewer );
+       AddFloatSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), importViewer, exportViewer );
        DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row );
        return ui::SpinButton(row.m_spin);
 }