From 57f4ad12206f19d639260384220a5507e7b20086 Mon Sep 17 00:00:00 2001
From: TimePath <andrew.hardaker1995@gmail.com>
Date: Fri, 21 Jul 2017 23:34:47 +1000
Subject: [PATCH] Wrap gtkutil/button

---
 libs/gtkutil/button.cpp     | 30 +++++++-------
 libs/gtkutil/button.h       | 25 ++++++------
 libs/gtkutil/dialog.cpp     |  2 +-
 libs/gtkutil/dialog.h       |  2 +-
 libs/gtkutil/nonmodal.h     |  2 +-
 libs/gtkutil/toolbar.cpp    | 17 ++++----
 libs/gtkutil/toolbar.h      |  9 +++--
 libs/uilib/uilib.cpp        | 78 ++++++++++++++++++++++++++++++++++++-
 libs/uilib/uilib.h          | 28 ++++++++++++-
 radiant/dialog.cpp          |  4 +-
 radiant/entityinspector.cpp |  8 ++--
 radiant/patchdialog.cpp     |  8 ++--
 radiant/surfacedialog.cpp   |  4 +-
 13 files changed, 158 insertions(+), 59 deletions(-)

diff --git a/libs/gtkutil/button.cpp b/libs/gtkutil/button.cpp
index 08744ff4..778a74a8 100644
--- a/libs/gtkutil/button.cpp
+++ b/libs/gtkutil/button.cpp
@@ -30,11 +30,11 @@
 #include "image.h"
 #include "pointer.h"
 
-void clicked_closure_callback( GtkWidget* widget, gpointer data ){
+void clicked_closure_callback( ui::Widget widget, gpointer data ){
 	( *reinterpret_cast<Callback*>( data ) )( );
 }
 
-void button_connect_callback( GtkButton* button, const Callback& callback ){
+void button_connect_callback( ui::Button button, const Callback& callback ){
 #if 1
 	g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
 #else
@@ -42,7 +42,7 @@ void button_connect_callback( GtkButton* button, const Callback& callback ){
 #endif
 }
 
-void button_connect_callback( GtkToolButton* button, const Callback& callback ){
+void button_connect_callback( ui::ToolButton button, const Callback& callback ){
 #if 1
 	g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
 #else
@@ -50,7 +50,7 @@ void button_connect_callback( GtkToolButton* button, const Callback& callback ){
 #endif
 }
 
-guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback ){
+guint toggle_button_connect_callback( ui::ToggleButton button, const Callback& callback ){
 #if 1
 	guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
 #else
@@ -60,7 +60,7 @@ guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& c
 	return handler;
 }
 
-guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callback& callback ){
+guint toggle_button_connect_callback( ui::ToggleToolButton button, const Callback& callback ){
 #if 1
 	guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
 #else
@@ -70,13 +70,13 @@ guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callbac
 	return handler;
 }
 
-void button_set_icon( GtkButton* button, const char* icon ){
-	GtkImage* image = new_local_image( icon );
-	gtk_widget_show( GTK_WIDGET( image ) );
+void button_set_icon( ui::Button button, const char* icon ){
+	ui::Image image = ui::Image(new_local_image( icon ));
+	image.show();
 	gtk_container_add( GTK_CONTAINER( button ), GTK_WIDGET( image ) );
 }
 
-void toggle_button_set_active_no_signal( GtkToggleButton* button, gboolean active ){
+void toggle_button_set_active_no_signal( ui::ToggleButton button, gboolean active ){
 	//globalOutputStream() << "set active: " << active << "\n";
 	guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( button ), "handler" ) );
 	//guint signal_id = g_signal_lookup("toggled", G_OBJECT_TYPE (button));
@@ -88,7 +88,7 @@ void toggle_button_set_active_no_signal( GtkToggleButton* button, gboolean activ
 	g_signal_handler_unblock( G_OBJECT( button ), handler_id );
 }
 
-void toggle_button_set_active_no_signal( GtkToggleToolButton* button, gboolean active ){
+void toggle_button_set_active_no_signal( ui::ToggleToolButton button, gboolean active ){
 	guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( button ), "handler" ) );
 	g_signal_handler_block( G_OBJECT( button ), handler_id );
 	gtk_toggle_tool_button_set_active( button, active );
@@ -96,7 +96,7 @@ void toggle_button_set_active_no_signal( GtkToggleToolButton* button, gboolean a
 }
 
 
-void radio_button_print_state( GtkRadioButton* button ){
+void radio_button_print_state( ui::RadioButton button ){
 	globalOutputStream() << "toggle button: ";
 	for ( GSList* radio = gtk_radio_button_get_group( button ); radio != 0; radio = g_slist_next( radio ) )
 	{
@@ -105,18 +105,18 @@ void radio_button_print_state( GtkRadioButton* button ){
 	globalOutputStream() << "\n";
 }
 
-GtkToggleButton* radio_button_get_nth( GtkRadioButton* radio, int index ){
+GtkToggleButton* radio_button_get_nth( ui::RadioButton radio, int index ){
 	GSList *group = gtk_radio_button_get_group( radio );
 	return GTK_TOGGLE_BUTTON( g_slist_nth_data( group, g_slist_length( group ) - index - 1 ) );
 }
 
-void radio_button_set_active( GtkRadioButton* radio, int index ){
+void radio_button_set_active( ui::RadioButton radio, int index ){
 	//radio_button_print_state(radio);
 	gtk_toggle_button_set_active( radio_button_get_nth( radio, index ), TRUE );
 	//radio_button_print_state(radio);
 }
 
-void radio_button_set_active_no_signal( GtkRadioButton* radio, int index ){
+void radio_button_set_active_no_signal( ui::RadioButton radio, int index ){
 	{
 		for ( GSList* l = gtk_radio_button_get_group( radio ); l != 0; l = g_slist_next( l ) )
 		{
@@ -132,7 +132,7 @@ void radio_button_set_active_no_signal( GtkRadioButton* radio, int index ){
 	}
 }
 
-int radio_button_get_active( GtkRadioButton* radio ){
+int radio_button_get_active( ui::RadioButton radio ){
 	//radio_button_print_state(radio);
 	GSList *group = gtk_radio_button_get_group( radio );
 	int index = g_slist_length( group ) - 1;
diff --git a/libs/gtkutil/button.h b/libs/gtkutil/button.h
index 1ffb025c..b7aa4127 100644
--- a/libs/gtkutil/button.h
+++ b/libs/gtkutil/button.h
@@ -22,27 +22,24 @@
 #if !defined( INCLUDED_GTKUTIL_BUTTON_H )
 #define INCLUDED_GTKUTIL_BUTTON_H
 
-#include <gtk/gtk.h>
+#include <uilib/uilib.h>
 #include "generic/callbackfwd.h"
 
-typedef struct _GtkButton GtkButton;
-typedef struct _GtkToggleButton GtkToggleButton;
-typedef struct _GtkRadioButton GtkRadioButton;
 typedef int gint;
 typedef gint gboolean;
 typedef unsigned int guint;
 
-void button_connect_callback( GtkButton* button, const Callback& callback );
-void button_connect_callback( GtkToolButton* button, const Callback& callback );
-guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback );
-guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callback& callback );
+void button_connect_callback( ui::Button button, const Callback& callback );
+void button_connect_callback( ui::ToolButton button, const Callback& callback );
+guint toggle_button_connect_callback( ui::ToggleButton button, const Callback& callback );
+guint toggle_button_connect_callback( ui::ToggleToolButton button, const Callback& callback );
 
-void button_set_icon( GtkButton* button, const char* icon );
-void toggle_button_set_active_no_signal( GtkToggleButton* item, gboolean active );
-void toggle_button_set_active_no_signal( GtkToggleToolButton* item, gboolean active );
+void button_set_icon( ui::Button button, const char* icon );
+void toggle_button_set_active_no_signal( ui::ToggleButton item, gboolean active );
+void toggle_button_set_active_no_signal( ui::ToggleToolButton item, gboolean active );
 
-void radio_button_set_active( GtkRadioButton* radio, int index );
-void radio_button_set_active_no_signal( GtkRadioButton* radio, int index );
-int radio_button_get_active( GtkRadioButton* radio );
+void radio_button_set_active( ui::RadioButton radio, int index );
+void radio_button_set_active_no_signal( ui::RadioButton radio, int index );
+int radio_button_get_active( ui::RadioButton radio );
 
 #endif
diff --git a/libs/gtkutil/dialog.cpp b/libs/gtkutil/dialog.cpp
index d22dc94c..dfeece8d 100644
--- a/libs/gtkutil/dialog.cpp
+++ b/libs/gtkutil/dialog.cpp
@@ -209,7 +209,7 @@ PathEntry PathEntry_new(){
 	gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
 
 	// browse button
-	GtkButton* button = ui::Button();
+	auto button = ui::Button();
 	button_set_icon( button, "ellipsis.bmp" );
 	gtk_widget_show( GTK_WIDGET( button ) );
 	gtk_box_pack_end( GTK_BOX( hbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
diff --git a/libs/gtkutil/dialog.h b/libs/gtkutil/dialog.h
index b5a43194..010432d6 100644
--- a/libs/gtkutil/dialog.h
+++ b/libs/gtkutil/dialog.h
@@ -94,7 +94,7 @@ class RadioHBox
 {
 public:
 GtkHBox* m_hbox;
-GtkRadioButton* m_radio;
+ui::RadioButton m_radio;
 RadioHBox( GtkHBox* hbox, GtkRadioButton* radio ) :
 	m_hbox( hbox ),
 	m_radio( radio ){
diff --git a/libs/gtkutil/nonmodal.h b/libs/gtkutil/nonmodal.h
index 4baf54b5..b8dc3f86 100644
--- a/libs/gtkutil/nonmodal.h
+++ b/libs/gtkutil/nonmodal.h
@@ -153,7 +153,7 @@ void connect( GtkRadioButton* radio ){
 	GSList* group = gtk_radio_button_get_group( radio );
 	for (; group != 0; group = g_slist_next( group ) )
 	{
-		toggle_button_connect_callback( GTK_TOGGLE_BUTTON( group->data ), m_changed );
+		toggle_button_connect_callback( ui::ToggleButton(GTK_TOGGLE_BUTTON( group->data )), m_changed );
 	}
 }
 };
diff --git a/libs/gtkutil/toolbar.cpp b/libs/gtkutil/toolbar.cpp
index c0659401..2f7cf5ff 100644
--- a/libs/gtkutil/toolbar.cpp
+++ b/libs/gtkutil/toolbar.cpp
@@ -36,15 +36,15 @@ void toolbar_append( GtkToolbar* toolbar, GtkToolItem* button, const char* descr
 	gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(button));
 }
 
-GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
-	auto button = GTK_TOOL_BUTTON(gtk_tool_button_new(GTK_WIDGET(new_local_image(icon)), nullptr));
+ui::ToolButton toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
+	auto button = ui::ToolButton(GTK_TOOL_BUTTON(gtk_tool_button_new(GTK_WIDGET(new_local_image(icon)), nullptr)));
 	button_connect_callback(button, callback);
 	toolbar_append(toolbar, GTK_TOOL_ITEM(button), description);
 	return button;
 }
 
-GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
-	auto button = GTK_TOGGLE_TOOL_BUTTON(gtk_toggle_tool_button_new());
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
+	auto button = ui::ToggleToolButton(GTK_TOGGLE_TOOL_BUTTON(gtk_toggle_tool_button_new()));
 	toggle_button_connect_callback(button, callback);
 	gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), GTK_WIDGET(new_local_image(icon)));
 	gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), description);
@@ -52,17 +52,18 @@ GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const ch
 	return button;
 }
 
-GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ){
+ui::ToolButton toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ){
 	return toolbar_append_button( toolbar, description, icon, command.m_callback );
 }
 
 void toggle_button_set_active_callback( GtkToggleToolButton& button, bool active ){
-	toggle_button_set_active_no_signal( &button, active );
+	toggle_button_set_active_no_signal( ui::ToggleToolButton(&button), active );
 }
 using ToggleButtonSetActiveCaller = ReferenceCaller1<GtkToggleToolButton, bool, toggle_button_set_active_callback>;
 
-GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){
 	auto button = toolbar_append_toggle_button( toolbar, description, icon, toggle.m_command.m_callback );
-	toggle.m_exportCallback( ToggleButtonSetActiveCaller( *button ) );
+	GtkToggleToolButton *button_ = button;
+	toggle.m_exportCallback( ToggleButtonSetActiveCaller( *button_ ) );
 	return button;
 }
diff --git a/libs/gtkutil/toolbar.h b/libs/gtkutil/toolbar.h
index 687fa0a3..421e20a5 100644
--- a/libs/gtkutil/toolbar.h
+++ b/libs/gtkutil/toolbar.h
@@ -23,6 +23,7 @@
 #define INCLUDED_GTKUTIL_TOOLBAR_H
 
 #include <gtk/gtk.h>
+#include <uilib/uilib.h>
 #include "generic/callbackfwd.h"
 
 typedef struct _GtkButton GtkButton;
@@ -31,9 +32,9 @@ typedef struct _GtkToolbar GtkToolbar;
 class Command;
 class Toggle;
 
-GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
-GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command );
-GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
-GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle );
+ui::ToolButton toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
+ui::ToolButton toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command );
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle );
 
 #endif
diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp
index dc0b93f2..1e37a1e0 100644
--- a/libs/uilib/uilib.cpp
+++ b/libs/uilib/uilib.cpp
@@ -24,13 +24,25 @@ namespace ui {
 
     Widget root{nullptr};
 
-#define this (*static_cast<self>(this))
+#define IMPL(T, F) template<> _IMPL(T, F)
+#define _IMPL(T, F) struct verify<T *> { using self = T; static self test(self it) { return self(F(it)); } }
+
+    template<class T>
+    struct verify;
+
+    template<class T> _IMPL(T,);
+
+#define this verify<self>::test(*static_cast<self>(this))
+
+    IMPL(Editable, GTK_EDITABLE);
 
     void IEditable::editable(bool value)
     {
         gtk_editable_set_editable(GTK_EDITABLE(this), value);
     }
 
+    IMPL(Widget, GTK_WIDGET);
+
     Widget::Widget() : Widget(nullptr)
     {}
 
@@ -66,6 +78,13 @@ namespace ui {
         return ::file_dialog(this, open, title, path, pattern, want_load, want_import, want_save);
     }
 
+    void IWidget::show()
+    {
+        gtk_widget_show(this);
+    }
+
+    IMPL(Window, GTK_WINDOW);
+
     Window::Window() : Window(nullptr)
     {}
 
@@ -113,27 +132,39 @@ namespace ui {
         gtk_window_add_accel_group(this, group);
     }
 
+    IMPL(Alignment, GTK_ALIGNMENT);
+
     Alignment::Alignment(float xalign, float yalign, float xscale, float yscale)
             : Alignment(GTK_ALIGNMENT(gtk_alignment_new(xalign, yalign, xscale, yscale)))
     {}
 
+    IMPL(Frame, GTK_FRAME);
+
     Frame::Frame(const char *label) : Frame(GTK_FRAME(gtk_frame_new(label)))
     {}
 
+    IMPL(Button, GTK_BUTTON);
+
     Button::Button() : Button(GTK_BUTTON(gtk_button_new()))
     {}
 
     Button::Button(const char *label) : Button(GTK_BUTTON(gtk_button_new_with_label(label)))
     {}
 
+    IMPL(ToggleButton, GTK_TOGGLE_BUTTON);
+
     bool IToggleButton::active()
     {
         return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this)) != 0;
     }
 
+    IMPL(CheckButton, GTK_CHECK_BUTTON);
+
     CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label)))
     {}
 
+    IMPL(MenuItem, GTK_MENU_ITEM);
+
     MenuItem::MenuItem() : MenuItem(GTK_MENU_ITEM(gtk_menu_item_new()))
     {}
 
@@ -141,35 +172,55 @@ namespace ui {
             GTK_MENU_ITEM((mnemonic ? gtk_menu_item_new_with_mnemonic : gtk_menu_item_new_with_label)(label)))
     {}
 
+    IMPL(TearoffMenuItem, GTK_TEAROFF_MENU_ITEM);
+
     TearoffMenuItem::TearoffMenuItem() : TearoffMenuItem(GTK_TEAROFF_MENU_ITEM(gtk_tearoff_menu_item_new()))
     {}
 
+    IMPL(ComboBoxText, GTK_COMBO_BOX_TEXT);
+
     ComboBoxText::ComboBoxText() : ComboBoxText(GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new()))
     {}
 
+    IMPL(ScrolledWindow, GTK_SCROLLED_WINDOW);
+
     ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr)))
     {}
 
+    IMPL(VBox, GTK_VBOX);
+
     VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing)))
     {}
 
+    IMPL(HBox, GTK_HBOX);
+
     HBox::HBox(bool homogenous, int spacing) : HBox(GTK_HBOX(gtk_hbox_new(homogenous, spacing)))
     {}
 
+    IMPL(HPaned, GTK_HPANED);
+
     HPaned::HPaned() : HPaned(GTK_HPANED(gtk_hpaned_new()))
     {}
 
+    IMPL(VPaned, GTK_VPANED);
+
     VPaned::VPaned() : VPaned(GTK_VPANED(gtk_vpaned_new()))
     {}
 
+    IMPL(Menu, GTK_MENU);
+
     Menu::Menu() : Menu(GTK_MENU(gtk_menu_new()))
     {}
 
+    IMPL(Table, GTK_TABLE);
+
     Table::Table(std::size_t rows, std::size_t columns, bool homogenous) : Table(
             GTK_TABLE(gtk_table_new(rows, columns, homogenous))
     )
     {}
 
+    IMPL(TextView, GTK_TEXT_VIEW);
+
     TextView::TextView() : TextView(GTK_TEXT_VIEW(gtk_text_view_new()))
     {}
 
@@ -179,12 +230,18 @@ namespace ui {
     TreeView::TreeView(TreeModel model) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new_with_model(model)))
     {}
 
+    IMPL(Label, GTK_LABEL);
+
     Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label)))
     {}
 
+    IMPL(Image, GTK_IMAGE);
+
     Image::Image() : Image(GTK_IMAGE(gtk_image_new()))
     {}
 
+    IMPL(Entry, GTK_ENTRY);
+
     Entry::Entry() : Entry(GTK_ENTRY(gtk_entry_new()))
     {}
 
@@ -193,16 +250,22 @@ namespace ui {
         gtk_entry_set_max_length(this, static_cast<gint>(max_length));
     }
 
+    IMPL(SpinButton, GTK_SPIN_BUTTON);
+
     SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton(
             GTK_SPIN_BUTTON(gtk_spin_button_new(adjustment, climb_rate, digits)))
     {}
 
+    IMPL(HScale, GTK_HSCALE);
+
     HScale::HScale(Adjustment adjustment) : HScale(GTK_HSCALE(gtk_hscale_new(adjustment)))
     {}
 
     HScale::HScale(double min, double max, double step) : HScale(GTK_HSCALE(gtk_hscale_new_with_range(min, max, step)))
     {}
 
+    IMPL(Adjustment, GTK_ADJUSTMENT);
+
     Adjustment::Adjustment(double value,
                            double lower, double upper,
                            double step_increment, double page_increment,
@@ -211,9 +274,13 @@ namespace ui {
             GTK_ADJUSTMENT(gtk_adjustment_new(value, lower, upper, step_increment, page_increment, page_size)))
     {}
 
+    IMPL(CellRendererText, GTK_CELL_RENDERER_TEXT);
+
     CellRendererText::CellRendererText() : CellRendererText(GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()))
     {}
 
+    IMPL(TreeViewColumn, GTK_TREE_VIEW_COLUMN);
+
     TreeViewColumn::TreeViewColumn(const char *title, CellRenderer renderer,
                                    std::initializer_list<TreeViewColumnAttribute> attributes)
             : TreeViewColumn(gtk_tree_view_column_new_with_attributes(title, renderer, nullptr))
@@ -223,13 +290,20 @@ namespace ui {
         }
     };
 
+    IMPL(AccelGroup, GTK_ACCEL_GROUP);
+
     AccelGroup::AccelGroup() : AccelGroup(GTK_ACCEL_GROUP(gtk_accel_group_new()))
     {}
 
-    void IListStore::clear() {
+    IMPL(ListStore, GTK_LIST_STORE);
+
+    void IListStore::clear()
+    {
         gtk_list_store_clear(this);
     }
 
+    // IMPL(TreePath, GTK_TREE_PATH);
+
     TreePath::TreePath() : TreePath(gtk_tree_path_new())
     {}
 
diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h
index 284609d6..72ec0ca4 100644
--- a/libs/uilib/uilib.h
+++ b/libs/uilib/uilib.h
@@ -29,11 +29,13 @@ struct _GtkItem;
 struct _GtkLabel;
 struct _GtkListStore;
 struct _GtkMenu;
-struct _GtkMenuShell;
 struct _GtkMenuItem;
+struct _GtkMenuShell;
 struct _GtkMisc;
 struct _GtkObject;
 struct _GtkPaned;
+struct _GtkRadioButton;
+struct _GtkRadioToolButton;
 struct _GtkRange;
 struct _GtkScale;
 struct _GtkScrolledWindow;
@@ -42,6 +44,9 @@ struct _GtkTable;
 struct _GtkTearoffMenuItem;
 struct _GtkTextView;
 struct _GtkToggleButton;
+struct _GtkToggleToolButton;
+struct _GtkToolButton;
+struct _GtkToolItem;
 struct _GtkTreeModel;
 struct _GtkTreePath;
 struct _GtkTreeView;
@@ -194,6 +199,7 @@ namespace ui {
                  bool want_import = false,
                  bool want_save = false
          );
+         void show();
     );
 
     WRAP(Container, Widget, _GtkContainer, (),
@@ -264,6 +270,10 @@ namespace ui {
     ,
     );
 
+    WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
+    ,
+    );
+
     WRAP(Item, Bin, _GtkItem, (),
     ,
     );
@@ -287,6 +297,22 @@ namespace ui {
     ,
     );
 
+    WRAP(ToolItem, Bin, _GtkToolItem, (),
+    ,
+    );
+
+    WRAP(ToolButton, ToolItem, _GtkToolButton, (),
+    ,
+    );
+
+    WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
+    ,
+    );
+
+    WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
+    ,
+    );
+
     WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
          ScrolledWindow();
     ,
diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp
index 51c2b107..b93bf00b 100644
--- a/radiant/dialog.cpp
+++ b/radiant/dialog.cpp
@@ -142,10 +142,10 @@ typedef ImportExport<GtkToggleButton, bool, BoolToggleImport, BoolToggleExport>
 
 
 void IntRadioImport( GtkRadioButton& widget, int index ){
-	radio_button_set_active( &widget, index );
+	radio_button_set_active( ui::RadioButton(&widget), index );
 }
 void IntRadioExport( GtkRadioButton& widget, const IntImportCallback& importCallback ){
-	importCallback( radio_button_get_active( &widget ) );
+	importCallback( radio_button_get_active( ui::RadioButton(&widget) ) );
 }
 typedef ImportExport<GtkRadioButton, int, IntRadioImport, IntRadioExport> IntRadioImportExport;
 
diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp
index 527e0239..912cd745 100644
--- a/radiant/entityinspector.cpp
+++ b/radiant/entityinspector.cpp
@@ -146,11 +146,11 @@ typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
 void update(){
 	const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
 	if ( !string_empty( value ) ) {
-		toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), atoi( value ) != 0 );
+		toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), atoi( value ) != 0 );
 	}
 	else
 	{
-		toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), false );
+		toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), false );
 	}
 }
 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
@@ -989,14 +989,14 @@ void EntityInspector_updateSpawnflags(){
 		{
 			int v = !!( f & ( 1 << spawn_table[i] ) );
 
-			toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), v );
+			toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), v );
 		}
 	}
 	{
 		// take care of the remaining ones
 		for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
 		{
-			toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), FALSE );
+			toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), FALSE );
 		}
 	}
 }
diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp
index 10d1806f..9068b752 100644
--- a/radiant/patchdialog.cpp
+++ b/radiant/patchdialog.cpp
@@ -158,16 +158,16 @@ typedef struct _GtkCheckButton GtkCheckButton;
 class Subdivisions
 {
 public:
-GtkCheckButton* m_enabled;
+ui::CheckButton m_enabled;
 GtkEntry* m_horizontal;
 GtkEntry* m_vertical;
-Subdivisions() : m_enabled( 0 ), m_horizontal( 0 ), m_vertical( 0 ){
+Subdivisions() : m_enabled( (GtkCheckButton *) 0 ), m_horizontal( 0 ), m_vertical( 0 ){
 }
 void update(){
 	PatchFixedSubdivisions subdivisions;
 	Scene_PatchGetFixedSubdivisions( subdivisions );
 
-	toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_enabled ), subdivisions.m_enabled );
+	toggle_button_set_active_no_signal( m_enabled, subdivisions.m_enabled );
 
 	if ( subdivisions.m_enabled ) {
 		entry_set_int( m_horizontal, static_cast<int>( subdivisions.m_x ) );
@@ -748,7 +748,7 @@ ui::Window PatchInspector::BuildDialog(){
 												  (GtkAttachOptions)( 0 ), 0, 0 );
 							}
 							{
-								GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
+								auto check = ui::CheckButton(GTK_CHECK_BUTTON( gtk_check_button_new() ));
 								gtk_widget_show( GTK_WIDGET( check ) );
 								gtk_table_attach( table, GTK_WIDGET( check ), 1, 2, 0, 1,
 												  (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp
index 438498e0..2a2d0982 100644
--- a/radiant/surfacedialog.cpp
+++ b/radiant/surfacedialog.cpp
@@ -1171,12 +1171,12 @@ void SurfaceInspector::Update(){
 
 		for ( GtkCheckButton** p = m_surfaceFlags; p != m_surfaceFlags + 32; ++p )
 		{
-			toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( *p ), flags.m_surfaceFlags & ( 1 << ( p - m_surfaceFlags ) ) );
+			toggle_button_set_active_no_signal( ui::CheckButton( *p ), flags.m_surfaceFlags & ( 1 << ( p - m_surfaceFlags ) ) );
 		}
 
 		for ( GtkCheckButton** p = m_contentFlags; p != m_contentFlags + 32; ++p )
 		{
-			toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( *p ), flags.m_contentFlags & ( 1 << ( p - m_contentFlags ) ) );
+			toggle_button_set_active_no_signal( ui::CheckButton( *p ), flags.m_contentFlags & ( 1 << ( p - m_contentFlags ) ) );
 		}
 	}
 }
-- 
2.39.5