From: TimePath Date: Sat, 22 Jul 2017 05:53:10 +0000 (+1000) Subject: Remove from gtkutil/container.h X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6480b8b62d45f01df57f48892374a5059c295ac1;p=xonotic%2Fnetradiant.git Remove from gtkutil/container.h --- diff --git a/libs/gtkutil/container.h b/libs/gtkutil/container.h index 8e70e35a..12d0ca99 100644 --- a/libs/gtkutil/container.h +++ b/libs/gtkutil/container.h @@ -22,20 +22,11 @@ #if !defined( INCLUDED_GTKUTIL_CONTAINER_H ) #define INCLUDED_GTKUTIL_CONTAINER_H -#include - -inline ui::Widget container_add_widget( ui::Container container, ui::Widget widget ){ - container.add(widget); - return widget; -} - -inline void container_remove( ui::Widget item, gpointer data ){ - auto container = ui::Container(GTK_CONTAINER( data )); - container.add(item); -} - -inline void container_remove_all( ui::Container container ){ - gtk_container_foreach(container, (GtkCallback) container_remove, container ); +inline void container_remove_all(ui::Container container) +{ + container.foreach([=](ui::Widget it) mutable { + container.remove(it); + }); } #endif diff --git a/libs/gtkutil/menu.cpp b/libs/gtkutil/menu.cpp index 007d7a4e..51e156e9 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( menu, menu_item ); + menu.add(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( menu, menu_item ); + menu.add(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( parent, item ); + parent.add(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( menu, item ); + menu.add(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( menu, item ); + menu.add(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( menu, item ); + menu.add(item); return item; } diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index b064da65..69a46b6d 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -39,7 +39,7 @@ namespace ui { template _IMPL(T,); -#define this verify::test(*static_cast(this)) +#define this (verify::test(*static_cast(this))) IMPL(Editable, GTK_EDITABLE); @@ -97,6 +97,11 @@ namespace ui { gtk_container_add(this, widget); } + void IContainer::remove(Widget widget) + { + gtk_container_remove(this, widget); + } + IMPL(Bin, GTK_BIN); IMPL(Window, GTK_WINDOW); diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index 945f762e..6ebb6420 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -223,6 +223,11 @@ namespace ui { WRAP(Container, Widget, _GtkContainer, (), , void add(Widget widget); + + void remove(Widget widget); + + template + void foreach(Lambda &&lambda); ); WRAP(Bin, Container, _GtkBin, (), @@ -497,6 +502,30 @@ namespace ui { #undef WRAP + // callbacks + + namespace { + using GtkCallback = void (*)(_GtkWidget *, void *); + extern "C" { + void gtk_container_foreach(_GtkContainer *, GtkCallback, void *); + } + } + +#define this (*static_cast(this)) + + template + void IContainer::foreach(Lambda &&lambda) + { + GtkCallback cb = [](_GtkWidget *widget, void *data) -> void { + using Function = typename std::decay::type; + Function *f = static_cast(data); + (*f)(Widget(widget)); + }; + gtk_container_foreach(this, cb, &lambda); + } + +#undef this + } #endif diff --git a/radiant/console.cpp b/radiant/console.cpp index b6855523..f7bdc929 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 ); item.show(); - container_add_widget( menu, item ); + menu.add(item); } gboolean destroy_set_null( ui::Window widget, ui::Widget* p ){ diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 23910a34..ff198061 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( m_stack.back().first, item ); + m_stack.back().first.add(item); auto submenu = ui::Menu(); gtk_menu_item_set_submenu( item, GTK_WIDGET( submenu ) );