]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/widget.h
[q3map2] Unwind script stack in case of script loading error.
[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 #include "property.h"
32
33 class ToggleItem {
34     Callback<void(const Callback<void(bool)> &)> m_exportCallback;
35     typedef std::list<Callback<void(bool)>> ImportCallbacks;
36     ImportCallbacks m_importCallbacks;
37 public:
38     ToggleItem(const Callback<void(const Callback<void(bool)> &)> &exportCallback) : m_exportCallback(exportCallback)
39     {
40     }
41
42     void update()
43     {
44         for (ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i) {
45             m_exportCallback(*i);
46         }
47     }
48
49     void addCallback(const Callback<void(bool)> &callback)
50     {
51         m_importCallbacks.push_back(callback);
52         m_exportCallback(callback);
53     }
54
55     typedef MemberCaller<ToggleItem, void(const Callback<void(bool)> &), &ToggleItem::addCallback> AddCallbackCaller;
56 };
57
58 class ToggleShown {
59     bool m_shownDeferred;
60
61     ToggleShown(const ToggleShown &other); // NOT COPYABLE
62     ToggleShown &operator=(const ToggleShown &other); // NOT ASSIGNABLE
63
64     static gboolean notify_visible(ui::Widget widget, gpointer dummy, ToggleShown *self);
65
66     static gboolean destroy(ui::Widget widget, ToggleShown *self);
67
68 public:
69     ui::Widget m_widget;
70     ToggleItem m_item;
71
72     ToggleShown(bool shown)
73             : m_shownDeferred(shown), m_widget(ui::null), m_item(ActiveCaller(*this))
74     {
75     }
76
77     void update();
78
79     bool active() const;
80
81     void exportActive(const Callback<void(bool)> &importCallback);
82
83     typedef MemberCaller<ToggleShown, void(const Callback<void(bool)> &), &ToggleShown::exportActive> ActiveCaller;
84
85     void set(bool shown);
86
87     void toggle();
88
89     typedef MemberCaller<ToggleShown, void(), &ToggleShown::toggle> ToggleCaller;
90
91     void connect(ui::Widget widget);
92 };
93
94
95 void widget_queue_draw(ui::Widget &widget);
96
97 typedef ReferenceCaller<ui::Widget, void(), widget_queue_draw> WidgetQueueDrawCaller;
98
99
100 void widget_make_default(ui::Widget widget);
101
102 class WidgetFocusPrinter {
103     const char *m_name;
104
105     static gboolean focus_in(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self);
106
107     static gboolean focus_out(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self);
108
109 public:
110     WidgetFocusPrinter(const char *name) : m_name(name)
111     {
112     }
113
114     void connect(ui::Widget widget);
115 };
116
117 #endif