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