From 234b657ba977434c3c0be08fb154eaac6c3ac798 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 22 Jul 2017 02:13:41 +1000 Subject: [PATCH] Wrap gtkutil/container --- include/qerplugin.h | 2 +- libs/gtkutil/container.h | 11 ++++++----- libs/gtkutil/menu.cpp | 12 ++++++------ libs/uilib/uilib.h | 6 +++--- radiant/console.cpp | 2 +- radiant/entityinspector.cpp | 4 ++-- radiant/plugintoolbar.cpp | 13 ++++++------- radiant/plugintoolbar.h | 8 ++++---- radiant/xywindow.cpp | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/qerplugin.h b/include/qerplugin.h index e97c0107..4adefa36 100644 --- a/include/qerplugin.h +++ b/include/qerplugin.h @@ -86,7 +86,7 @@ typedef bool ( *PFN_QERAPP_COLORDIALOG )( ui::Widget parent, Vector3& color, // load a .bmp file and create a GtkImage widget from it // NOTE: 'filename' is relative to /plugins/bitmaps/ typedef struct _GtkImage GtkImage; -typedef GtkImage* ( *PFN_QERAPP_NEWIMAGE )( const char* filename ); +typedef ui::Image ( *PFN_QERAPP_NEWIMAGE )( const char* filename ); // ======================================== diff --git a/libs/gtkutil/container.h b/libs/gtkutil/container.h index e633d81c..d931f0f0 100644 --- a/libs/gtkutil/container.h +++ b/libs/gtkutil/container.h @@ -24,17 +24,18 @@ #include -inline GtkWidget* container_add_widget( GtkContainer* container, GtkWidget* widget ){ +inline ui::Widget container_add_widget( ui::Container container, ui::Widget widget ){ gtk_container_add( container, widget ); return widget; } -inline void container_remove( GtkWidget* item, gpointer data ){ - gtk_container_remove( GTK_CONTAINER( data ), item ); +inline void container_remove( ui::Widget item, gpointer data ){ + auto container = ui::Container(GTK_CONTAINER( data )); + gtk_container_remove( container, item ); } -inline void container_remove_all( GtkContainer* container ){ - gtk_container_foreach( container, container_remove, container ); +inline void container_remove_all( ui::Container container ){ + gtk_container_foreach(container, (GtkCallback) container_remove, container ); } #endif diff --git a/libs/gtkutil/menu.cpp b/libs/gtkutil/menu.cpp index 9fafb175..3e227a2c 100644 --- a/libs/gtkutil/menu.cpp +++ b/libs/gtkutil/menu.cpp @@ -39,7 +39,7 @@ void menu_add_item( ui::Menu menu, ui::MenuItem item ){ ui::MenuItem menu_separator( ui::Menu menu ){ auto menu_item = ui::MenuItem(GTK_MENU_ITEM( gtk_menu_item_new() )); - container_add_widget( GTK_CONTAINER( menu ), GTK_WIDGET( menu_item ) ); + container_add_widget( menu, menu_item ); gtk_widget_set_sensitive( GTK_WIDGET( menu_item ), FALSE ); menu_item.show(); return menu_item; @@ -47,7 +47,7 @@ ui::MenuItem menu_separator( ui::Menu menu ){ ui::TearoffMenuItem menu_tearoff( ui::Menu menu ){ auto menu_item = ui::TearoffMenuItem(GTK_TEAROFF_MENU_ITEM( gtk_tearoff_menu_item_new() )); - container_add_widget( GTK_CONTAINER( menu ), GTK_WIDGET( menu_item ) ); + container_add_widget( menu, menu_item ); // gtk_widget_set_sensitive(GTK_WIDGET(menu_item), FALSE); -- controls whether menu is detachable menu_item.show(); return menu_item; @@ -65,7 +65,7 @@ ui::MenuItem new_sub_menu_item_with_mnemonic( const char* mnemonic ){ ui::Menu create_sub_menu_with_mnemonic( ui::MenuShell parent, const char* mnemonic ){ auto item = new_sub_menu_item_with_mnemonic( mnemonic ); - container_add_widget( GTK_CONTAINER( parent ), GTK_WIDGET( item ) ); + container_add_widget( parent, item ); return ui::Menu(GTK_MENU( gtk_menu_item_get_submenu( item ) )); } @@ -108,7 +108,7 @@ ui::MenuItem new_menu_item_with_mnemonic( const char *mnemonic, const Callback& ui::MenuItem create_menu_item_with_mnemonic( ui::Menu menu, const char *mnemonic, const Callback& callback ){ auto item = new_menu_item_with_mnemonic( mnemonic, callback ); - container_add_widget( GTK_CONTAINER( menu ), GTK_WIDGET( item ) ); + container_add_widget( menu, item ); return item; } @@ -121,7 +121,7 @@ ui::CheckMenuItem new_check_menu_item_with_mnemonic( const char* mnemonic, const ui::CheckMenuItem create_check_menu_item_with_mnemonic( ui::Menu menu, const char* mnemonic, const Callback& callback ){ auto item = new_check_menu_item_with_mnemonic( mnemonic, callback ); - container_add_widget( GTK_CONTAINER( menu ), GTK_WIDGET( item ) ); + container_add_widget( menu, item ); return item; } @@ -138,7 +138,7 @@ ui::RadioMenuItem new_radio_menu_item_with_mnemonic( GSList** group, const char* ui::RadioMenuItem create_radio_menu_item_with_mnemonic( ui::Menu menu, GSList** group, const char* mnemonic, const Callback& callback ){ auto item = new_radio_menu_item_with_mnemonic( group, mnemonic, callback ); - container_add_widget( GTK_CONTAINER( menu ), GTK_WIDGET( item ) ); + container_add_widget( menu, item ); return item; } diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index 70ae9a07..2b18ffb2 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -372,17 +372,17 @@ namespace ui { , ); - WRAP(Table, Widget, _GtkTable, (), + WRAP(Table, Container, _GtkTable, (), Table(std::size_t rows, std::size_t columns, bool homogenous); , ); - WRAP(TextView, Widget, _GtkTextView, (), + WRAP(TextView, Container, _GtkTextView, (), TextView(); , ); - WRAP(Toolbar, Widget, _GtkToolbar, (), + WRAP(Toolbar, Container, _GtkToolbar, (), , ); diff --git a/radiant/console.cpp b/radiant/console.cpp index 9d5f9924..53913149 100644 --- a/radiant/console.cpp +++ b/radiant/console.cpp @@ -93,7 +93,7 @@ void console_populate_popup( GtkTextView* textview, ui::Menu menu, gpointer user ui::Widget item(ui::MenuItem( "Clear" )); g_signal_connect( G_OBJECT( item ), "activate", G_CALLBACK( console_clear ), 0 ); gtk_widget_show( item ); - container_add_widget( GTK_CONTAINER( menu ), item ); + container_add_widget( menu, item ); } gboolean destroy_set_null( ui::Window widget, ui::Widget* p ){ diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index a0a3bdfa..616db701 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -730,7 +730,7 @@ int spawn_table[MAX_FLAGS]; // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags.. GtkTable* g_spawnflagsTable; -GtkVBox* g_attributeBox = 0; +ui::VBox g_attributeBox{nullptr}; typedef std::vector EntityAttributes; EntityAttributes g_entityAttributes; } @@ -967,7 +967,7 @@ void EntityInspector_setEntityClass( EntityClass *eclass ){ if ( eclass != g_current_attributes ) { g_current_attributes = eclass; - container_remove_all( GTK_CONTAINER( g_attributeBox ) ); + container_remove_all( g_attributeBox ); GlobalEntityAttributes_clear(); for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i ) diff --git a/radiant/plugintoolbar.cpp b/radiant/plugintoolbar.cpp index 77216664..3a79f3e1 100644 --- a/radiant/plugintoolbar.cpp +++ b/radiant/plugintoolbar.cpp @@ -32,7 +32,7 @@ #include "mainframe.h" #include "plugin.h" -GtkImage* new_plugin_image( const char* filename ){ +ui::Image new_plugin_image( const char* filename ){ { StringOutputStream fullpath( 256 ); fullpath << GameToolsPath_get() << g_pluginsDir << "bitmaps/" << filename; @@ -90,7 +90,7 @@ void PlugInToolbar_AddButton( GtkToolbar* toolbar, const IToolbarButton* button toolbar_insert( toolbar, button->getImage(), button->getText(), button->getTooltip(), button->getType(), G_CALLBACK( ActivateToolbarButton ), reinterpret_cast( const_cast( button ) ) ); } -GtkToolbar* g_plugin_toolbar = 0; +ui::Toolbar g_plugin_toolbar{nullptr}; void PluginToolbar_populate(){ class AddToolbarItemVisitor : public ToolbarModules::Visitor @@ -114,16 +114,15 @@ public: } void PluginToolbar_clear(){ - container_remove_all( GTK_CONTAINER( g_plugin_toolbar ) ); + container_remove_all( g_plugin_toolbar ); } -GtkToolbar* create_plugin_toolbar(){ - GtkToolbar *toolbar; +ui::Toolbar create_plugin_toolbar(){ - toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); + auto toolbar = ui::Toolbar(GTK_TOOLBAR( gtk_toolbar_new() )); gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL ); gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); - gtk_widget_show( GTK_WIDGET( toolbar ) ); + toolbar.show(); g_plugin_toolbar = toolbar; diff --git a/radiant/plugintoolbar.h b/radiant/plugintoolbar.h index 7621cfd2..ca35b1bc 100644 --- a/radiant/plugintoolbar.h +++ b/radiant/plugintoolbar.h @@ -19,15 +19,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #if !defined( INCLUDED_PLUGINTOOLBAR_H ) #define INCLUDED_PLUGINTOOLBAR_H -typedef struct _GtkToolbar GtkToolbar; -GtkToolbar* create_plugin_toolbar(); +ui::Toolbar create_plugin_toolbar(); void PluginToolbar_populate(); void PluginToolbar_clear(); -typedef struct _GtkImage GtkImage; -GtkImage* new_plugin_image( const char* filename ); // filename is relative to plugin bitmaps path +ui::Image new_plugin_image( const char* filename ); // filename is relative to plugin bitmaps path #endif diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 86b36572..23910a34 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -1107,7 +1107,7 @@ void visit( EntityClass* e ){ void pushMenu( const CopiedString& name ){ auto item = ui::MenuItem( name.c_str() ); item.show(); - container_add_widget( GTK_CONTAINER( m_stack.back().first ), GTK_WIDGET( item ) ); + container_add_widget( m_stack.back().first, item ); auto submenu = ui::Menu(); gtk_menu_item_set_submenu( item, GTK_WIDGET( submenu ) ); -- 2.39.2