X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fgtkutil%2Fwidget.h;h=28395b3516da90470c318b408d330fb85e498810;hb=HEAD;hp=225fccf4f595e2ea3e3eee7e331693ab88540322;hpb=231225d6f97d0b926b2e896e5783cccfbc7c5619;p=xonotic%2Fnetradiant.git diff --git a/libs/gtkutil/widget.h b/libs/gtkutil/widget.h index 225fccf4..ff93211d 100644 --- a/libs/gtkutil/widget.h +++ b/libs/gtkutil/widget.h @@ -1,190 +1,142 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ -#if !defined(INCLUDED_GTKUTIL_WIDGET_H) +#if !defined( INCLUDED_GTKUTIL_WIDGET_H ) #define INCLUDED_GTKUTIL_WIDGET_H #include -#include +#include +#include #include "generic/callback.h" #include "warnings.h" #include "debugging/debugging.h" +#include "property.h" -inline void widget_set_visible(GtkWidget* widget, bool shown) -{ - if(shown) - { - gtk_widget_show(widget); - } - else - { - gtk_widget_hide(widget); - } +#define GARUX_GTK_WORKAROUND +#ifndef GARUX_GTK_WORKAROUND +inline bool widget_is_visible( GtkWidget* widget ){ + return GTK_WIDGET_VISIBLE( widget ) != FALSE; } -inline bool widget_is_visible(GtkWidget* widget) -{ - return GTK_WIDGET_VISIBLE(widget) != FALSE; -} - -inline void widget_toggle_visible(GtkWidget* widget) -{ - widget_set_visible(widget, !widget_is_visible(widget)); +inline void widget_set_visible( GtkWidget* widget, bool show ){ + if ( show ) { + /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */ + GtkWidget* glwidget = GTK_WIDGET( g_object_get_data( G_OBJECT( widget ), "glwidget" ) ); + if ( glwidget ){ + //if ( widget_is_visible( glwidget ) ) + //globalOutputStream() << "glwidget have been already visible :0\n"; /* is not hidden aswell, according to this */ + gtk_widget_hide( glwidget ); + gtk_widget_show( glwidget ); + } + gtk_widget_show( widget ); + } + else + { + gtk_widget_hide( widget ); + } } +#endif -class ToggleItem -{ - BoolExportCallback m_exportCallback; - typedef std::list ImportCallbacks; - ImportCallbacks m_importCallbacks; +class ToggleItem { + Callback &)> m_exportCallback; + typedef std::list> ImportCallbacks; + ImportCallbacks m_importCallbacks; public: - ToggleItem(const BoolExportCallback& exportCallback) : m_exportCallback(exportCallback) - { - } - - void update() - { - for(ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i) + ToggleItem(const Callback &)> &exportCallback) : m_exportCallback(exportCallback) { - m_exportCallback(*i); } - } - - void addCallback(const BoolImportCallback& callback) - { - m_importCallbacks.push_back(callback); - m_exportCallback(callback); - } - typedef MemberCaller1 AddCallbackCaller; -}; -class ToggleShown -{ - bool m_shownDeferred; - - ToggleShown(const ToggleShown& other); // NOT COPYABLE - ToggleShown& operator=(const ToggleShown& other); // NOT ASSIGNABLE - - static gboolean notify_visible(GtkWidget* widget, gpointer dummy, ToggleShown* self) - { - self->update(); - return FALSE; - } - static gboolean destroy(GtkWidget* widget, ToggleShown* self) - { - self->m_shownDeferred = GTK_WIDGET_VISIBLE(self->m_widget) != FALSE; - self->m_widget = 0; - return FALSE; - } -public: - GtkWidget* 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 == 0) - { - return m_shownDeferred; - } - else + void update() { - return GTK_WIDGET_VISIBLE(m_widget) != FALSE; + for (ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i) { + m_exportCallback(*i); + } } - } - void exportActive(const BoolImportCallback& importCallback) - { - importCallback(active()); - } - typedef MemberCaller1 ActiveCaller; - void set(bool shown) - { - if(m_widget == 0) + + void addCallback(const Callback &callback) { - m_shownDeferred = shown; + m_importCallbacks.push_back(callback); + m_exportCallback(callback); } - else + + typedef MemberCaller &), &ToggleItem::addCallback> AddCallbackCaller; +}; + +class ToggleShown { + bool m_shownDeferred; + + ToggleShown(const ToggleShown &other); // NOT COPYABLE + ToggleShown &operator=(const ToggleShown &other); // NOT ASSIGNABLE + + static gboolean notify_visible(ui::Widget widget, gpointer dummy, ToggleShown *self); + + static gboolean destroy(ui::Widget widget, ToggleShown *self); + +public: + ui::Widget m_widget; + ToggleItem m_item; + + ToggleShown(bool shown) + : m_shownDeferred(shown), m_widget(ui::null), m_item(ActiveCaller(*this)) { - widget_set_visible(m_widget, shown); } - } - void toggle() - { - widget_toggle_visible(m_widget); - } - typedef MemberCaller ToggleCaller; - void connect(GtkWidget* 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(); - } + + void update(); + + bool active() const; + + void exportActive(const Callback &importCallback); + + typedef MemberCaller &), &ToggleShown::exportActive> 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(GtkWidget* widget) -{ - GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_DEFAULT); - gtk_widget_grab_default(widget); -} -class WidgetFocusPrinter -{ - const char* m_name; - - static gboolean focus_in(GtkWidget *widget, GdkEventFocus *event, WidgetFocusPrinter* self) - { - globalOutputStream() << self->m_name << " takes focus\n"; - return FALSE; - } - static gboolean focus_out(GtkWidget *widget, GdkEventFocus *event, WidgetFocusPrinter* self) - { - globalOutputStream() << self->m_name << " loses focus\n"; - return FALSE; - } +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); + public: - WidgetFocusPrinter(const char* name) : m_name(name) - { - } - void connect(GtkWidget* 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