2313
|
1 /* BMP - Cross-platform multimedia player
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
3 *
|
|
4 * Based on XMMS:
|
|
5 * Copyright (C) 1998-2003 XMMS development team.
|
|
6 *
|
|
7 * This program 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 * This program 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 this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
20 */
|
|
21
|
|
22 #include "widgetcore.h"
|
|
23
|
|
24 #include <glib.h>
|
|
25 #include <gdk/gdk.h>
|
|
26
|
|
27 #include "debug.h"
|
|
28
|
|
29
|
|
30 void
|
|
31 widget_init(Widget * widget, GdkPixmap * parent, GdkGC * gc,
|
|
32 gint x, gint y, gint width, gint height, gint visible)
|
|
33 {
|
|
34 widget->parent = parent;
|
|
35 widget->gc = gc;
|
|
36 widget_set_position(widget, x, y);
|
|
37 widget_set_size(widget, width, height);
|
|
38 widget->visible = visible;
|
|
39 widget->redraw = TRUE;
|
|
40 widget->mutex = g_mutex_new();
|
|
41 }
|
|
42
|
|
43 void
|
|
44 widget_set_position(Widget * widget, gint x, gint y)
|
|
45 {
|
|
46 widget->x = x;
|
|
47 widget->y = y;
|
|
48 widget_queue_redraw(widget);
|
|
49 }
|
|
50
|
|
51 void
|
|
52 widget_set_size(Widget * widget, gint width, gint height)
|
|
53 {
|
|
54 widget->width = width;
|
|
55 widget->height = height;
|
|
56 widget_queue_redraw(widget);
|
|
57 }
|
|
58
|
|
59 void
|
|
60 widget_queue_redraw(Widget * widget)
|
|
61 {
|
|
62 widget->redraw = TRUE;
|
|
63 }
|
|
64
|
|
65 gboolean
|
|
66 widget_contains(Widget * widget, gint x, gint y)
|
|
67 {
|
|
68 return (widget->visible &&
|
|
69 x >= widget->x &&
|
|
70 y >= widget->y &&
|
|
71 x < widget->x + widget->width &&
|
|
72 y < widget->y + widget->height);
|
|
73 }
|
|
74
|
|
75 void
|
|
76 widget_show(Widget * widget)
|
|
77 {
|
|
78 if (!widget)
|
|
79 return;
|
|
80
|
|
81 widget->visible = TRUE;
|
|
82 widget_draw(widget);
|
|
83 }
|
|
84
|
|
85 void
|
|
86 widget_hide(Widget * widget)
|
|
87 {
|
|
88 if (!widget)
|
|
89 return;
|
|
90
|
|
91 widget->visible = FALSE;
|
|
92 }
|
|
93
|
|
94 gboolean
|
|
95 widget_is_visible(Widget * widget)
|
|
96 {
|
|
97 if (!widget)
|
|
98 return FALSE;
|
|
99
|
|
100 return widget->visible;
|
|
101 }
|
|
102
|
|
103 void
|
|
104 widget_resize(Widget * widget, gint width, gint height)
|
|
105 {
|
|
106 widget_set_size(widget, width, height);
|
|
107 }
|
|
108
|
|
109 void
|
|
110 widget_move(Widget * widget, gint x, gint y)
|
|
111 {
|
|
112 widget_lock(widget);
|
|
113 widget_set_position(widget, x, y);
|
|
114 widget_unlock(widget);
|
|
115 }
|
|
116
|
|
117 void
|
|
118 widget_draw(Widget * widget)
|
|
119 {
|
|
120 if (widget->visible == FALSE)
|
|
121 return;
|
|
122
|
|
123 widget_lock(widget);
|
|
124 WIDGET(widget)->redraw = TRUE;
|
|
125 widget_unlock(widget);
|
|
126 }
|
|
127
|
|
128 void
|
|
129 widget_draw_quick(Widget * widget)
|
|
130 {
|
|
131 widget_lock(widget);
|
|
132 if (WIDGET(widget)->draw != NULL)
|
|
133 {
|
|
134 WIDGET(widget)->draw(widget);
|
|
135 gdk_flush();
|
|
136 }
|
|
137 widget_unlock(widget);
|
|
138 }
|
|
139
|
|
140 void
|
|
141 widget_list_add(GList ** list, Widget * widget)
|
|
142 {
|
|
143 (*list) = g_list_append(*list, widget);
|
|
144 }
|
|
145
|
|
146 void
|
|
147 handle_press_cb(GList * widget_list, GtkWidget * widget,
|
|
148 GdkEventButton * event)
|
|
149 {
|
|
150 GList *wl;
|
|
151
|
|
152 for (wl = widget_list; wl; wl = g_list_next(wl)) {
|
|
153 if (WIDGET(wl->data)->button_press_cb)
|
|
154 WIDGET(wl->data)->button_press_cb(widget, event, wl->data);
|
|
155 }
|
|
156 }
|
|
157
|
|
158 void
|
|
159 handle_release_cb(GList * widget_list, GtkWidget * widget,
|
|
160 GdkEventButton * event)
|
|
161 {
|
|
162 GList *wl;
|
|
163
|
|
164 for (wl = widget_list; wl; wl = g_list_next(wl)) {
|
|
165 if (WIDGET(wl->data)->button_release_cb)
|
|
166 WIDGET(wl->data)->button_release_cb(widget, event, wl->data);
|
|
167 }
|
|
168 }
|
|
169
|
|
170 void
|
|
171 handle_motion_cb(GList * widget_list, GtkWidget * widget,
|
|
172 GdkEventMotion * event)
|
|
173 {
|
|
174 GList *wl;
|
|
175
|
|
176 for (wl = widget_list; wl; wl = g_list_next(wl)) {
|
|
177 if (WIDGET(wl->data)->motion_cb)
|
|
178 WIDGET(wl->data)->motion_cb(widget, event, wl->data);
|
|
179 }
|
|
180 }
|
|
181
|
|
182 void
|
|
183 handle_scroll_cb(GList * wlist, GtkWidget * widget, GdkEventScroll * event)
|
|
184 {
|
|
185 GList *wl;
|
|
186
|
|
187 for (wl = wlist; wl; wl = g_list_next(wl)) {
|
|
188 if (WIDGET(wl->data)->mouse_scroll_cb)
|
|
189 WIDGET(wl->data)->mouse_scroll_cb(widget, event, wl->data);
|
|
190 }
|
|
191 }
|
|
192
|
|
193 void
|
|
194 widget_list_draw(GList * widget_list, gboolean * redraw, gboolean force)
|
|
195 {
|
|
196 GList *wl;
|
|
197 Widget *w;
|
|
198
|
|
199 *redraw = FALSE;
|
|
200 wl = widget_list;
|
|
201
|
|
202 for (wl = widget_list; wl; wl = g_list_next(wl)) {
|
|
203 w = WIDGET(wl->data);
|
|
204
|
|
205 REQUIRE_LOCK(w->mutex);
|
|
206
|
|
207 if (!w->draw)
|
|
208 continue;
|
|
209
|
|
210 if (!w->visible)
|
|
211 continue;
|
|
212
|
|
213 if (w->redraw || force) {
|
|
214 w->draw(w);
|
|
215 /* w->redraw = FALSE; */
|
|
216 *redraw = TRUE;
|
|
217 }
|
|
218 }
|
|
219 }
|
|
220
|
|
221 void
|
|
222 widget_list_change_pixmap(GList * widget_list, GdkPixmap * pixmap)
|
|
223 {
|
|
224 GList *wl;
|
|
225
|
|
226 for (wl = widget_list; wl; wl = g_list_next(wl)) {
|
|
227 Widget *widget = wl->data;
|
|
228 widget->parent = pixmap;
|
|
229 widget_queue_redraw(widget);
|
|
230 }
|
|
231 }
|
|
232
|
|
233 void
|
|
234 widget_list_clear_redraw(GList * widget_list)
|
|
235 {
|
|
236 GList *wl;
|
|
237
|
|
238 for (wl = widget_list; wl; wl = g_list_next(wl)) {
|
|
239 REQUIRE_LOCK(WIDGET(wl->data)->mutex);
|
|
240 WIDGET(wl->data)->redraw = FALSE;
|
|
241 }
|
|
242 }
|
|
243
|
|
244 void
|
|
245 widget_lock(Widget * widget)
|
|
246 {
|
|
247 g_mutex_lock(WIDGET(widget)->mutex);
|
|
248 }
|
|
249
|
|
250 void
|
|
251 widget_unlock(Widget * widget)
|
|
252 {
|
|
253 g_mutex_unlock(WIDGET(widget)->mutex);
|
|
254 }
|
|
255
|
|
256 void
|
|
257 widget_list_lock(GList * widget_list)
|
|
258 {
|
|
259 g_list_foreach(widget_list, (GFunc) widget_lock, NULL);
|
|
260 }
|
|
261
|
|
262 void
|
|
263 widget_list_unlock(GList * widget_list)
|
|
264 {
|
|
265 g_list_foreach(widget_list, (GFunc) widget_unlock, NULL);
|
|
266 }
|