2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined(INCLUDED_GTKUTIL_WIDGET_H)
23 #define INCLUDED_GTKUTIL_WIDGET_H
26 #include <gtk/gtkwidget.h>
27 #include "generic/callback.h"
30 inline void widget_set_visible(GtkWidget* widget, bool shown)
34 gtk_widget_show(widget);
38 gtk_widget_hide(widget);
42 inline bool widget_is_visible(GtkWidget* widget)
44 return GTK_WIDGET_VISIBLE(widget) != FALSE;
47 inline void widget_toggle_visible(GtkWidget* widget)
49 widget_set_visible(widget, !widget_is_visible(widget));
54 BoolExportCallback m_exportCallback;
55 typedef std::list<BoolImportCallback> ImportCallbacks;
56 ImportCallbacks m_importCallbacks;
58 ToggleItem(const BoolExportCallback& exportCallback) : m_exportCallback(exportCallback)
64 for(ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i)
70 void addCallback(const BoolImportCallback& callback)
72 m_importCallbacks.push_back(callback);
73 m_exportCallback(callback);
75 typedef MemberCaller1<ToggleItem, const BoolImportCallback&, &ToggleItem::addCallback> AddCallbackCaller;
82 ToggleShown(const ToggleShown& other); // NOT COPYABLE
83 ToggleShown& operator=(const ToggleShown& other); // NOT ASSIGNABLE
85 static gboolean notify_visible(GtkWidget* widget, gpointer dummy, ToggleShown* self)
90 static gboolean destroy(GtkWidget* widget, ToggleShown* self)
92 self->m_shownDeferred = GTK_WIDGET_VISIBLE(self->m_widget) != FALSE;
100 ToggleShown(bool shown)
101 : m_shownDeferred(shown), m_widget(0), m_item(ActiveCaller(*this))
112 return m_shownDeferred;
116 return GTK_WIDGET_VISIBLE(m_widget) != FALSE;
119 void exportActive(const BoolImportCallback& importCallback)
121 importCallback(active());
123 typedef MemberCaller1<ToggleShown, const BoolImportCallback&, &ToggleShown::exportActive> ActiveCaller;
128 m_shownDeferred = shown;
132 widget_set_visible(m_widget, shown);
137 widget_toggle_visible(m_widget);
139 typedef MemberCaller<ToggleShown, &ToggleShown::toggle> ToggleCaller;
140 void connect(GtkWidget* widget)
143 widget_set_visible(m_widget, m_shownDeferred);
144 g_signal_connect(G_OBJECT(m_widget), "notify::visible", G_CALLBACK(notify_visible), this);
145 g_signal_connect(G_OBJECT(m_widget), "destroy", G_CALLBACK(destroy), this);
151 inline void widget_queue_draw(GtkWidget& widget)
153 gtk_widget_queue_draw(&widget);
155 typedef ReferenceCaller<GtkWidget, widget_queue_draw> WidgetQueueDrawCaller;
158 inline void widget_make_default(GtkWidget* widget)
160 GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_DEFAULT);
161 gtk_widget_grab_default(widget);