]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/widget.h
Merge branch 'TimePath/gtk++' into 'master'
[xonotic/netradiant.git] / libs / gtkutil / widget.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
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.
11
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.
16
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
20  */
21
22 #if !defined( INCLUDED_GTKUTIL_WIDGET_H )
23 #define INCLUDED_GTKUTIL_WIDGET_H
24
25 #include <list>
26 #include <uilib/uilib.h>
27 #include <gdk/gdk.h>
28 #include "generic/callback.h"
29 #include "warnings.h"
30 #include "debugging/debugging.h"
31
32 void widget_set_visible(ui::Widget widget, bool shown);
33
34 bool widget_is_visible(ui::Widget widget);
35
36 inline void widget_toggle_visible(ui::Widget widget)
37 {
38     widget_set_visible(widget, !widget_is_visible(widget));
39 }
40
41 class ToggleItem {
42     BoolExportCallback m_exportCallback;
43     typedef std::list<BoolImportCallback> ImportCallbacks;
44     ImportCallbacks m_importCallbacks;
45 public:
46     ToggleItem(const BoolExportCallback &exportCallback) : m_exportCallback(exportCallback)
47     {
48     }
49
50     void update()
51     {
52         for (ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i) {
53             m_exportCallback(*i);
54         }
55     }
56
57     void addCallback(const BoolImportCallback &callback)
58     {
59         m_importCallbacks.push_back(callback);
60         m_exportCallback(callback);
61     }
62
63     typedef MemberCaller1<ToggleItem, const BoolImportCallback &, &ToggleItem::addCallback> AddCallbackCaller;
64 };
65
66 class ToggleShown {
67     bool m_shownDeferred;
68
69     ToggleShown(const ToggleShown &other); // NOT COPYABLE
70     ToggleShown &operator=(const ToggleShown &other); // NOT ASSIGNABLE
71
72     static gboolean notify_visible(ui::Widget widget, gpointer dummy, ToggleShown *self);
73
74     static gboolean destroy(ui::Widget widget, ToggleShown *self);
75
76 public:
77     ui::Widget m_widget;
78     ToggleItem m_item;
79
80     ToggleShown(bool shown)
81             : m_shownDeferred(shown), m_widget(0), m_item(ActiveCaller(*this))
82     {
83     }
84
85     void update();
86
87     bool active() const;
88
89     void exportActive(const BoolImportCallback &importCallback);
90
91     typedef MemberCaller1<ToggleShown, const BoolImportCallback &, &ToggleShown::exportActive> ActiveCaller;
92
93     void set(bool shown);
94
95     void toggle();
96
97     typedef MemberCaller<ToggleShown, &ToggleShown::toggle> ToggleCaller;
98
99     void connect(ui::Widget widget);
100 };
101
102
103 void widget_queue_draw(ui::Widget &widget);
104
105 typedef ReferenceCaller<ui::Widget, widget_queue_draw> WidgetQueueDrawCaller;
106
107
108 void widget_make_default(ui::Widget widget);
109
110 class WidgetFocusPrinter {
111     const char *m_name;
112
113     static gboolean focus_in(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self);
114
115     static gboolean focus_out(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self);
116
117 public:
118     WidgetFocusPrinter(const char *name) : m_name(name)
119     {
120     }
121
122     void connect(ui::Widget widget);
123 };
124
125 #endif