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