From 70626e6ea48e0c0493e5b2d8a44d53774a97d9f8 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 17 Feb 2016 13:05:49 +1100 Subject: [PATCH] Wrap GtkButton --- contrib/bobtoolz/dialogs/dialogs-gtk.cpp | 16 ++++++++-------- libs/uilib/uilib.cpp | 3 +++ libs/uilib/uilib.h | 5 +++++ radiant/findtexturedialog.cpp | 4 ++-- radiant/gtkdlgs.cpp | 4 ++-- radiant/surfacedialog.cpp | 14 +++++++------- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp index 73c8e2fd..3cbc232b 100644 --- a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp +++ b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp @@ -243,7 +243,7 @@ EMessageBoxReturn DoMessageBox( const char* lpText, const char* lpCaption, EMess gtk_widget_show( hbox ); if ( type == eMB_OK ) { - w = ui::Widget(gtk_button_new_with_label( "Ok" )); + w = ui::Button( "Ok" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDOK ) ); @@ -253,7 +253,7 @@ EMessageBoxReturn DoMessageBox( const char* lpText, const char* lpCaption, EMess ret = eIDOK; } else if ( type == eMB_OKCANCEL ) { - w = ui::Widget(gtk_button_new_with_label( "Ok" )); + w = ui::Button( "Ok" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDOK ) ); @@ -261,7 +261,7 @@ EMessageBoxReturn DoMessageBox( const char* lpText, const char* lpCaption, EMess gtk_widget_grab_default( w ); gtk_widget_show( w ); - w = ui::Widget(gtk_button_new_with_label( "Cancel" )); + w = ui::Button( "Cancel" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDCANCEL ) ); @@ -269,7 +269,7 @@ EMessageBoxReturn DoMessageBox( const char* lpText, const char* lpCaption, EMess ret = eIDCANCEL; } else if ( type == eMB_YESNOCANCEL ) { - w = ui::Widget(gtk_button_new_with_label( "Yes" )); + w = ui::Button( "Yes" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDYES ) ); @@ -277,13 +277,13 @@ EMessageBoxReturn DoMessageBox( const char* lpText, const char* lpCaption, EMess gtk_widget_grab_default( w ); gtk_widget_show( w ); - w = ui::Widget(gtk_button_new_with_label( "No" )); + w = ui::Button( "No" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDNO ) ); gtk_widget_show( w ); - w = ui::Widget(gtk_button_new_with_label( "Cancel" )); + w = ui::Button( "Cancel" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDCANCEL ) ); @@ -292,7 +292,7 @@ EMessageBoxReturn DoMessageBox( const char* lpText, const char* lpCaption, EMess } else /* if (mode == MB_YESNO) */ { - w = ui::Widget(gtk_button_new_with_label( "Yes" )); + w = ui::Button( "Yes" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDYES ) ); @@ -300,7 +300,7 @@ EMessageBoxReturn DoMessageBox( const char* lpText, const char* lpCaption, EMess gtk_widget_grab_default( w ); gtk_widget_show( w ); - w = ui::Widget(gtk_button_new_with_label( "No" )); + w = ui::Button( "No" ); gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 ); gtk_signal_connect( GTK_OBJECT( w ), "clicked", GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( eIDNO ) ); diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index 5ce21dbb..16f90e65 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -84,6 +84,9 @@ namespace ui { return g_signal_connect(G_OBJECT(*this), "key-press-event", (GCallback) +func, &pass); } + Button::Button(const char *label) : Button(GTK_BUTTON(gtk_button_new_with_label(label))) + { } + Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label))) { } diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index 61386801..64a1c690 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -6,6 +6,7 @@ using ui_typeinst = struct _GTypeInstance; using ui_widget = struct _GtkWidget; using ui_window = struct _GtkWindow; +using ui_button = struct _GtkButton; using ui_menuitem = struct _GtkMenuItem; using ui_label = struct _GtkLabel; @@ -109,6 +110,10 @@ namespace ui { void *extra = nullptr); ); + WIDGET(Button, ui_button, + Button(const char *label); + ); + WIDGET(CheckButton, ui_widget,); WIDGET(SpinButton, ui_widget,); diff --git a/radiant/findtexturedialog.cpp b/radiant/findtexturedialog.cpp index 36ccafb1..36db069f 100644 --- a/radiant/findtexturedialog.cpp +++ b/radiant/findtexturedialog.cpp @@ -201,14 +201,14 @@ ui::Window FindTextureDialog::BuildDialog(){ gtk_widget_show( vbox ); gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 ); - button = ui::Widget(gtk_button_new_with_label( "Apply" )); + button = ui::Button( "Apply" ); gtk_widget_show( button ); gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 ); g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnApply ), 0 ); gtk_widget_set_usize( button, 60, -2 ); - button = ui::Widget(gtk_button_new_with_label( "Close" )); + button = ui::Button( "Close" ); gtk_widget_show( button ); gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 ); g_signal_connect( G_OBJECT( button ), "clicked", diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index c3aba62b..1536daf7 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -776,14 +776,14 @@ static void CreateGtkTextEditor(){ gtk_widget_show( hbox ); gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 ); - button = ui::Widget(gtk_button_new_with_label( "Close" )); + button = ui::Button( "Close" ); gtk_widget_show( button ); gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 ); g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( editor_close ), dlg ); gtk_widget_set_usize( button, 60, -2 ); - button = ui::Widget(gtk_button_new_with_label( "Save" )); + button = ui::Button( "Save" ); gtk_widget_show( button ); gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 ); g_signal_connect( G_OBJECT( button ), "clicked", diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index dbd07612..ebd828c4 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -814,7 +814,7 @@ ui::Window SurfaceInspector::BuildDialog(){ } { // match grid button - ui::Widget button = ui::Widget(gtk_button_new_with_label( "Match Grid" )); + ui::Widget button = ui::Button( "Match Grid" ); gtk_widget_show( button ); gtk_table_attach( GTK_TABLE( table ), button, 2, 4, 5, 6, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -863,7 +863,7 @@ ui::Window SurfaceInspector::BuildDialog(){ (GtkAttachOptions) ( 0 ), 0, 0 ); } { - ui::Widget button = ui::Widget(gtk_button_new_with_label( "Axial" )); + ui::Widget button = ui::Button( "Axial" ); gtk_widget_show( button ); gtk_table_attach( GTK_TABLE( table ), button, 0, 1, 1, 2, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -873,7 +873,7 @@ ui::Window SurfaceInspector::BuildDialog(){ gtk_widget_set_usize( button, 60, -2 ); } { - ui::Widget button = ui::Widget(gtk_button_new_with_label( "Fit" )); + ui::Widget button = ui::Button( "Fit" ); gtk_widget_show( button ); gtk_table_attach( GTK_TABLE( table ), button, 1, 2, 1, 2, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -883,7 +883,7 @@ ui::Window SurfaceInspector::BuildDialog(){ gtk_widget_set_usize( button, 60, -2 ); } { - ui::Widget button = ui::Widget(gtk_button_new_with_label( "CAP" )); + ui::Widget button = ui::Button( "CAP" ); gtk_widget_show( button ); gtk_table_attach( GTK_TABLE( table ), button, 0, 1, 3, 4, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -893,7 +893,7 @@ ui::Window SurfaceInspector::BuildDialog(){ gtk_widget_set_usize( button, 60, -2 ); } { - ui::Widget button = ui::Widget(gtk_button_new_with_label( "Set..." )); + ui::Widget button = ui::Button( "Set..." ); gtk_widget_show( button ); gtk_table_attach( GTK_TABLE( table ), button, 1, 2, 3, 4, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -903,7 +903,7 @@ ui::Window SurfaceInspector::BuildDialog(){ gtk_widget_set_usize( button, 60, -2 ); } { - ui::Widget button = ui::Widget(gtk_button_new_with_label( "Natural" )); + ui::Widget button = ui::Button( "Natural" ); gtk_widget_show( button ); gtk_table_attach( GTK_TABLE( table ), button, 2, 3, 3, 4, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -913,7 +913,7 @@ ui::Window SurfaceInspector::BuildDialog(){ gtk_widget_set_usize( button, 60, -2 ); } { - ui::Widget button = ui::Widget(gtk_button_new_with_label( "Fit" )); + ui::Widget button = ui::Button( "Fit" ); gtk_widget_show( button ); gtk_table_attach( GTK_TABLE( table ), button, 3, 4, 3, 4, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), -- 2.39.2