From: TimePath Date: Sat, 22 Jul 2017 07:00:15 +0000 (+1000) Subject: Remove from gtkutil/widget.h X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d7b2cf7cd88ca303ef95209ffdac6a97e22f30a8;p=xonotic%2Fnetradiant.git Remove from gtkutil/widget.h --- diff --git a/libs/gtkutil/CMakeLists.txt b/libs/gtkutil/CMakeLists.txt index 962b6aab..7781a1ef 100644 --- a/libs/gtkutil/CMakeLists.txt +++ b/libs/gtkutil/CMakeLists.txt @@ -19,7 +19,7 @@ add_library(gtkutil paned.cpp paned.h pointer.h toolbar.cpp toolbar.h - widget.h + widget.cpp widget.h window.cpp window.h xorrectangle.h ) diff --git a/libs/gtkutil/widget.cpp b/libs/gtkutil/widget.cpp new file mode 100644 index 00000000..83782920 --- /dev/null +++ b/libs/gtkutil/widget.cpp @@ -0,0 +1,100 @@ +#include "widget.h" +#include + +void widget_set_visible(ui::Widget widget, bool shown) +{ + if (shown) { + widget.show(); + } else { + gtk_widget_hide(widget); + } +} + +bool widget_is_visible(ui::Widget widget) +{ + return gtk_widget_get_visible(widget) != FALSE; +} + +void widget_queue_draw(ui::Widget &widget) +{ + gtk_widget_queue_draw(widget); +} + +void widget_make_default(ui::Widget widget) +{ + gtk_widget_set_can_default(widget, true); + gtk_widget_grab_default(widget); +} + +gboolean ToggleShown::notify_visible(ui::Widget widget, gpointer dummy, ToggleShown *self) +{ + self->update(); + return FALSE; +} + +gboolean ToggleShown::destroy(ui::Widget widget, ToggleShown *self) +{ + self->m_shownDeferred = gtk_widget_get_visible(self->m_widget) != FALSE; + self->m_widget = ui::Widget(nullptr); + return FALSE; +} + +void ToggleShown::update() +{ + m_item.update(); +} + +bool ToggleShown::active() const +{ + if (!m_widget) { + return m_shownDeferred; + } else { + return gtk_widget_get_visible(m_widget) != FALSE; + } +} + +void ToggleShown::exportActive(const BoolImportCallback &importCallback) +{ + importCallback(active()); +} + +void ToggleShown::set(bool shown) +{ + if (!m_widget) { + m_shownDeferred = shown; + } else { + widget_set_visible(m_widget, shown); + } +} + +void ToggleShown::toggle() +{ + widget_toggle_visible(m_widget); +} + +void ToggleShown::connect(ui::Widget widget) +{ + m_widget = widget; + widget_set_visible(m_widget, m_shownDeferred); + g_signal_connect(G_OBJECT(m_widget), "notify::visible", G_CALLBACK(notify_visible), this); + g_signal_connect(G_OBJECT(m_widget), "destroy", G_CALLBACK(destroy), this); + update(); +} + +gboolean WidgetFocusPrinter::focus_in(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self) +{ + globalOutputStream() << self->m_name << " takes focus\n"; + return FALSE; +} + +gboolean WidgetFocusPrinter::focus_out(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self) +{ + globalOutputStream() << self->m_name << " loses focus\n"; + return FALSE; +} + +void WidgetFocusPrinter::connect(ui::Widget widget) +{ + g_signal_connect(G_OBJECT(widget), "focus_in_event", G_CALLBACK(focus_in), this); + g_signal_connect(G_OBJECT(widget), "focus_out_event", G_CALLBACK(focus_out), this); +} diff --git a/libs/gtkutil/widget.h b/libs/gtkutil/widget.h index 77938c64..52a90ef5 100644 --- a/libs/gtkutil/widget.h +++ b/libs/gtkutil/widget.h @@ -23,144 +23,104 @@ #define INCLUDED_GTKUTIL_WIDGET_H #include -#include +#include +#include +#include #include "generic/callback.h" #include "warnings.h" #include "debugging/debugging.h" -inline void widget_set_visible( ui::Widget widget, bool shown ){ - if ( shown ) { - widget.show(); - } - else - { - gtk_widget_hide( widget ); - } -} +void widget_set_visible(ui::Widget widget, bool shown); -inline bool widget_is_visible( ui::Widget widget ){ - return gtk_widget_get_visible( widget ) != FALSE; -} +bool widget_is_visible(ui::Widget widget); -inline void widget_toggle_visible( ui::Widget widget ){ - widget_set_visible( widget, !widget_is_visible( widget ) ); +inline void widget_toggle_visible(ui::Widget widget) +{ + widget_set_visible(widget, !widget_is_visible(widget)); } -class ToggleItem -{ -BoolExportCallback m_exportCallback; -typedef std::list ImportCallbacks; -ImportCallbacks m_importCallbacks; +class ToggleItem { + BoolExportCallback m_exportCallback; + typedef std::list ImportCallbacks; + ImportCallbacks m_importCallbacks; public: -ToggleItem( const BoolExportCallback& exportCallback ) : m_exportCallback( exportCallback ){ -} + ToggleItem(const BoolExportCallback &exportCallback) : m_exportCallback(exportCallback) + { + } + + void update() + { + for (ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i) { + m_exportCallback(*i); + } + } + + void addCallback(const BoolImportCallback &callback) + { + m_importCallbacks.push_back(callback); + m_exportCallback(callback); + } + + typedef MemberCaller1 AddCallbackCaller; +}; -void update(){ - for ( ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i ) - { - m_exportCallback( *i ); - } -} +class ToggleShown { + bool m_shownDeferred; -void addCallback( const BoolImportCallback& callback ){ - m_importCallbacks.push_back( callback ); - m_exportCallback( callback ); -} -typedef MemberCaller1 AddCallbackCaller; -}; + ToggleShown(const ToggleShown &other); // NOT COPYABLE + ToggleShown &operator=(const ToggleShown &other); // NOT ASSIGNABLE -class ToggleShown -{ -bool m_shownDeferred; + static gboolean notify_visible(ui::Widget widget, gpointer dummy, ToggleShown *self); -ToggleShown( const ToggleShown& other ); // NOT COPYABLE -ToggleShown& operator=( const ToggleShown& other ); // NOT ASSIGNABLE + static gboolean destroy(ui::Widget widget, ToggleShown *self); -static gboolean notify_visible( ui::Widget widget, gpointer dummy, ToggleShown* self ){ - self->update(); - return FALSE; -} -static gboolean destroy( ui::Widget widget, ToggleShown* self ){ - self->m_shownDeferred = gtk_widget_get_visible( self->m_widget ) != FALSE; - self->m_widget = ui::Widget(nullptr); - return FALSE; -} public: -ui::Widget m_widget; -ToggleItem m_item; + ui::Widget m_widget; + ToggleItem m_item; -ToggleShown( bool shown ) - : m_shownDeferred( shown ), m_widget( 0 ), m_item( ActiveCaller( *this ) ){ -} -void update(){ - m_item.update(); -} -bool active() const { - if ( !m_widget ) { - return m_shownDeferred; - } - else - { - return gtk_widget_get_visible( m_widget ) != FALSE; - } -} -void exportActive( const BoolImportCallback& importCallback ){ - importCallback( active() ); -} -typedef MemberCaller1 ActiveCaller; -void set( bool shown ){ - if ( !m_widget ) { - m_shownDeferred = shown; - } - else - { - widget_set_visible( m_widget, shown ); - } -} -void toggle(){ - widget_toggle_visible( m_widget ); -} -typedef MemberCaller ToggleCaller; -void connect( ui::Widget widget ){ - m_widget = widget; - widget_set_visible( m_widget, m_shownDeferred ); - g_signal_connect( G_OBJECT( m_widget ), "notify::visible", G_CALLBACK( notify_visible ), this ); - g_signal_connect( G_OBJECT( m_widget ), "destroy", G_CALLBACK( destroy ), this ); - update(); -} + ToggleShown(bool shown) + : m_shownDeferred(shown), m_widget(0), m_item(ActiveCaller(*this)) + { + } + + void update(); + + bool active() const; + + void exportActive(const BoolImportCallback &importCallback); + + typedef MemberCaller1 ActiveCaller; + + void set(bool shown); + + void toggle(); + + typedef MemberCaller ToggleCaller; + + void connect(ui::Widget widget); }; -inline void widget_queue_draw( GtkWidget& widget ){ - gtk_widget_queue_draw( &widget ); -} -typedef ReferenceCaller WidgetQueueDrawCaller; +void widget_queue_draw(ui::Widget &widget); +typedef ReferenceCaller WidgetQueueDrawCaller; -inline void widget_make_default( ui::Widget widget ){ - gtk_widget_set_can_default( widget, true ); - gtk_widget_grab_default( widget ); -} -class WidgetFocusPrinter -{ -const char* m_name; +void widget_make_default(ui::Widget widget); + +class WidgetFocusPrinter { + const char *m_name; + + static gboolean focus_in(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self); + + static gboolean focus_out(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self); -static gboolean focus_in( ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter* self ){ - globalOutputStream() << self->m_name << " takes focus\n"; - return FALSE; -} -static gboolean focus_out( ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter* self ){ - globalOutputStream() << self->m_name << " loses focus\n"; - return FALSE; -} public: -WidgetFocusPrinter( const char* name ) : m_name( name ){ -} -void connect( ui::Widget widget ){ - g_signal_connect( G_OBJECT( widget ), "focus_in_event", G_CALLBACK( focus_in ), this ); - g_signal_connect( G_OBJECT( widget ), "focus_out_event", G_CALLBACK( focus_out ), this ); -} + WidgetFocusPrinter(const char *name) : m_name(name) + { + } + + void connect(ui::Widget widget); }; #endif diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index ae523fa1..d77b519b 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -1148,7 +1148,7 @@ CamWnd::CamWnd() : m_gl_widget( ui::Widget(glwidget_new( TRUE )) ), m_window_observer( NewWindowObserver() ), m_XORRectangle( m_gl_widget ), - m_deferredDraw( WidgetQueueDrawCaller( *m_gl_widget ) ), + m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ), m_deferred_motion( selection_motion, m_window_observer ), m_selection_button_press_handler( 0 ), m_selection_button_release_handler( 0 ), diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index ff198061..0d457d2c 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -787,7 +787,7 @@ void XYWnd_CameraMoved( XYWnd& xywnd ){ XYWnd::XYWnd() : m_gl_widget( glwidget_new( FALSE ) ), - m_deferredDraw( WidgetQueueDrawCaller( *m_gl_widget ) ), + m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ), m_deferred_motion( xywnd_motion, this ), m_parent( 0 ), m_window_observer( NewWindowObserver() ),