From 1227d1b7ffbce0b50bf2efbfcb2dedd5a60a5761 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 22 Jul 2017 21:36:30 +1000 Subject: [PATCH] Wrap g_object_unref --- contrib/brushexport/interface.cpp | 6 +++--- contrib/sunplug/sunplug.cpp | 2 +- libs/gtkutil/glwidget.cpp | 2 +- libs/uilib/uilib.h | 12 ++++++++++++ radiant/build.cpp | 4 ++-- radiant/camwindow.cpp | 2 +- radiant/commands.cpp | 2 +- radiant/entityinspector.cpp | 6 +++--- radiant/feedback.cpp | 2 +- radiant/map.cpp | 2 +- radiant/patchdialog.cpp | 2 +- radiant/preferences.cpp | 2 +- radiant/textureentry.cpp | 12 ++++++------ radiant/textureentry.h | 4 ++-- radiant/texwindow.cpp | 6 +++--- radiant/xywindow.cpp | 2 +- 16 files changed, 40 insertions(+), 28 deletions(-) diff --git a/contrib/brushexport/interface.cpp b/contrib/brushexport/interface.cpp index 83bc5be3..c08ce71a 100644 --- a/contrib/brushexport/interface.cpp +++ b/contrib/brushexport/interface.cpp @@ -7,10 +7,10 @@ #define GLADE_HOOKUP_OBJECT( component,widget,name ) \ g_object_set_data_full( G_OBJECT( component ), name, \ - g_object_ref( widget ), (GDestroyNotify) g_object_unref ) + g_object_ref( (void *) widget ), (GDestroyNotify) g_object_unref ) #define GLADE_HOOKUP_OBJECT_NO_REF( component,widget,name ) \ - g_object_set_data( G_OBJECT( component ), name, widget ) + g_object_set_data( G_OBJECT( component ), name, (void *) widget ) // created by glade GtkWidget* @@ -208,7 +208,7 @@ void CreateWindow( void ){ // list store ui::ListStore ignorelist = ui::ListStore(gtk_list_store_new( 1, G_TYPE_STRING )); gtk_tree_view_set_model( GTK_TREE_VIEW( lookup_widget( wnd, "t_materialist" ) ), GTK_TREE_MODEL( ignorelist ) ); - g_object_unref( ignorelist ); + ignorelist.unref(); gtk_widget_show_all( wnd ); g_brushexp_window = wnd; diff --git a/contrib/sunplug/sunplug.cpp b/contrib/sunplug/sunplug.cpp index 6895bf22..a6928537 100644 --- a/contrib/sunplug/sunplug.cpp +++ b/contrib/sunplug/sunplug.cpp @@ -272,7 +272,7 @@ void about_plugin_window(){ gtk_box_pack_start( GTK_BOX( vbox ), label, FALSE, FALSE, 2 ); // insert the label in the box button = ui::Button( "OK" ); // create a button with text - g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( gtk_widget_destroy ), window ); // connect the click event to close the window + g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( gtk_widget_destroy ), (void *) window ); // connect the click event to close the window gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 2 ); // insert the button in the box gtk_window_set_position( GTK_WINDOW( window ), GTK_WIN_POS_CENTER ); // center the window on screen diff --git a/libs/gtkutil/glwidget.cpp b/libs/gtkutil/glwidget.cpp index 8a7a7339..0e4d75bf 100644 --- a/libs/gtkutil/glwidget.cpp +++ b/libs/gtkutil/glwidget.cpp @@ -203,7 +203,7 @@ gint glwidget_context_destroyed( ui::Widget widget, gpointer data ){ GLWidget_sharedContextDestroyed(); - g_object_unref( g_shared ); + g_shared.unref(); g_shared = ui::Widget(nullptr); } return FALSE; diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index 6a35f461..925384ee 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -176,8 +176,14 @@ namespace ui { explicit operator void *() const { return _handle; } + void unref() + { g_object_unref(_handle); } + template gulong connect(char const *detailed_signal, Lambda &&c_handler, void *data); + + template + gulong connect(char const *detailed_signal, Lambda &&c_handler, Object data); }; static_assert(sizeof(Object) == sizeof(Object::native), "object slicing"); @@ -543,6 +549,12 @@ namespace ui { return g_signal_connect(G_OBJECT(this), detailed_signal, c_handler, data); } + template + gulong Object::connect(char const *detailed_signal, Lambda &&c_handler, Object data) + { + return g_signal_connect(G_OBJECT(this), detailed_signal, c_handler, (_GtkObject *) data); + } + template void IContainer::foreach(Lambda &&lambda) { diff --git a/radiant/build.cpp b/radiant/build.cpp index a2b80dec..9b24958b 100644 --- a/radiant/build.cpp +++ b/radiant/build.cpp @@ -892,7 +892,7 @@ ui::Window BuildMenuDialog_construct( ModalDialog& modal, ProjectList& projectLi view.connect( "key_press_event", G_CALLBACK( project_key_press ), &projectList ); - g_object_unref( G_OBJECT( store ) ); + store.unref(); } } } @@ -925,7 +925,7 @@ ui::Window BuildMenuDialog_construct( ModalDialog& modal, ProjectList& projectLi scr.add(view); - g_object_unref( G_OBJECT( store ) ); + store.unref(); view.connect( "key_press_event", G_CALLBACK( commands_key_press ), store ); diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index f64691a2..df3bf3c8 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -1196,7 +1196,7 @@ CamWnd::~CamWnd(){ g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler ); g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler ); - g_object_unref( m_gl_widget ); + m_gl_widget.unref(); m_window_observer->release(); } diff --git a/radiant/commands.cpp b/radiant/commands.cpp index b3def079..6b2fe8ee 100644 --- a/radiant/commands.cpp +++ b/radiant/commands.cpp @@ -460,7 +460,7 @@ public: GlobalShortcuts_foreach( visitor ); } - g_object_unref( G_OBJECT( store ) ); + store.unref(); } } diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index 800ee919..1e8aaa7e 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -882,7 +882,7 @@ void SurfaceFlags_setEntityClass( EntityClass* eclass ){ gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1, (GtkAttachOptions)( GTK_FILL ), (GtkAttachOptions)( GTK_FILL ), 0, 0 ); - g_object_unref( widget ); + widget.unref(); gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN(widget)) ), str.c_str() ); } @@ -1341,7 +1341,7 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){ scr.add(view); - g_object_unref( G_OBJECT( store ) ); + store.unref(); g_entityClassList = view; g_entlist_store = store; } @@ -1429,7 +1429,7 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){ scr.add(view); - g_object_unref( G_OBJECT( store ) ); + store.unref(); g_entprops_store = store; } diff --git a/radiant/feedback.cpp b/radiant/feedback.cpp index 5a106879..e1c3c48c 100644 --- a/radiant/feedback.cpp +++ b/radiant/feedback.cpp @@ -321,7 +321,7 @@ ui::Window CDbgDlg::BuildDialog(){ scr.add(view); - g_object_unref( G_OBJECT( store ) ); + store.unref(); m_clist = store; } diff --git a/radiant/map.cpp b/radiant/map.cpp index 7b362552..c767cc2e 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -885,7 +885,7 @@ void DoMapInfo(){ } } - g_object_unref( G_OBJECT( EntityBreakdownWalker ) ); + EntityBreakdownWalker.unref(); char tmp[16]; sprintf( tmp, "%u", Unsigned( g_brushCount.get() ) ); diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp index a44fc103..9432187c 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -888,7 +888,7 @@ ui::Window PatchInspector::BuildDialog(){ (GtkAttachOptions)( GTK_FILL ), (GtkAttachOptions)( 0 ), 0, 0 ); gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 ); - g_object_set_data( G_OBJECT( window ), "hshift_entry", entry ); + g_object_set_data( G_OBJECT( window ), "hshift_entry", (void *) entry ); // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised // so we need to have at least one initialisation somewhere entry_set_float( entry, g_pi_globals.shift[0] ); diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 6af5d58e..ba5e75cb 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -730,7 +730,7 @@ ui::Window PrefsDlg::BuildDialog(){ { - GtkTreeStore* store = gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ); + auto store = gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ); ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) )); gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE ); diff --git a/radiant/textureentry.cpp b/radiant/textureentry.cpp index f692717e..96a46dcd 100644 --- a/radiant/textureentry.cpp +++ b/radiant/textureentry.cpp @@ -23,12 +23,6 @@ #include -template -class EntryCompletion; - -template -class EntryCompletion; - template void EntryCompletion::connect(ui::Entry entry) { @@ -72,3 +66,9 @@ void EntryCompletion::update() clear(); fill(); } + +template +class EntryCompletion; + +template +class EntryCompletion; diff --git a/radiant/textureentry.h b/radiant/textureentry.h index 7045b29a..d36aff6b 100644 --- a/radiant/textureentry.h +++ b/radiant/textureentry.h @@ -43,7 +43,7 @@ public: void append(const char *string); - typedef MemberCaller1 AppendCaller; + using AppendCaller = MemberCaller1; void fill(); @@ -51,7 +51,7 @@ public: void update(); - typedef MemberCaller UpdateCaller; + using UpdateCaller = MemberCaller; }; class TextureNameList { diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 880347f5..6081d14f 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -2139,7 +2139,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){ auto renderer = ui::CellRendererText(); g_TextureBrowser.m_assigned_tree = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( g_TextureBrowser.m_assigned_store ) )); - g_object_unref( G_OBJECT( g_TextureBrowser.m_assigned_store ) ); + g_TextureBrowser.m_assigned_store.unref(); g_TextureBrowser.m_assigned_tree.connect( "row-activated", (GCallback) TextureBrowser_removeTags, NULL ); gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_assigned_tree ), FALSE ); @@ -2167,7 +2167,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){ auto renderer = ui::CellRendererText(); g_TextureBrowser.m_available_tree = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( g_TextureBrowser.m_available_store ) )); - g_object_unref( G_OBJECT( g_TextureBrowser.m_available_store ) ); + g_TextureBrowser.m_available_store.unref(); g_TextureBrowser.m_available_tree.connect( "row-activated", (GCallback) TextureBrowser_assignTags, NULL ); gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ), FALSE ); @@ -2233,7 +2233,7 @@ void TextureBrowser_destroyWindow(){ g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_sizeHandler ); g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_exposeHandler ); - g_object_unref( g_TextureBrowser.m_gl_widget ); + g_TextureBrowser.m_gl_widget.unref(); } const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ){ diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 81b6d3d0..82501150 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -867,7 +867,7 @@ XYWnd::~XYWnd(){ g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler ); g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler ); - g_object_unref( m_gl_widget ); + m_gl_widget.unref(); m_window_observer->release(); } -- 2.39.2