Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_menurow.c @ 2765:ffb79e3d133a
fix segfault when starting with shaded windows
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Thu, 03 Jul 2008 15:52:56 +0200 |
parents | 5ae914e1b78c |
children | 7c7471554d88 |
rev | line source |
---|---|
2581 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Tomasz Moń | |
4 * | |
5 * Based on: | |
6 * BMP - Cross-platform multimedia player | |
7 * Copyright (C) 2003-2004 BMP development team. | |
8 * XMMS: | |
9 * Copyright (C) 1998-2003 XMMS development team. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; under version 3 of the License. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
22 * | |
23 * The Audacious team does not consider modular code linking to | |
24 * Audacious or using our public API to be a derived work. | |
25 */ | |
26 | |
27 #include <audacious/plugin.h> | |
28 #include "plugin.h" | |
29 #include "ui_skinned_menurow.h" | |
30 | |
31 enum { | |
32 DOUBLED, | |
33 CHANGE, | |
34 RELEASE, | |
35 LAST_SIGNAL | |
36 }; | |
37 | |
38 static void ui_skinned_menurow_class_init (UiSkinnedMenurowClass *klass); | |
39 static void ui_skinned_menurow_init (UiSkinnedMenurow *menurow); | |
40 static void ui_skinned_menurow_destroy (GtkObject *object); | |
41 static void ui_skinned_menurow_realize (GtkWidget *widget); | |
42 static void ui_skinned_menurow_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
43 static void ui_skinned_menurow_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
44 static gboolean ui_skinned_menurow_expose (GtkWidget *widget, GdkEventExpose *event); | |
45 static MenuRowItem menurow_find_selected (UiSkinnedMenurow * mr, gint x, gint y); | |
46 static gboolean ui_skinned_menurow_button_press (GtkWidget *widget, GdkEventButton *event); | |
47 static gboolean ui_skinned_menurow_button_release (GtkWidget *widget, GdkEventButton *event); | |
48 static gboolean ui_skinned_menurow_motion_notify (GtkWidget *widget, GdkEventMotion *event); | |
49 static void ui_skinned_menurow_toggle_scaled (UiSkinnedMenurow *menurow); | |
50 | |
51 static GtkWidgetClass *parent_class = NULL; | |
52 static guint menurow_signals[LAST_SIGNAL] = { 0 }; | |
53 | |
54 GType ui_skinned_menurow_get_type() { | |
55 static GType menurow_type = 0; | |
56 if (!menurow_type) { | |
57 static const GTypeInfo menurow_info = { | |
58 sizeof (UiSkinnedMenurowClass), | |
59 NULL, | |
60 NULL, | |
61 (GClassInitFunc) ui_skinned_menurow_class_init, | |
62 NULL, | |
63 NULL, | |
64 sizeof (UiSkinnedMenurow), | |
65 0, | |
66 (GInstanceInitFunc) ui_skinned_menurow_init, | |
67 }; | |
2590 | 68 menurow_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedMenurow", &menurow_info, 0); |
2581 | 69 } |
70 | |
71 return menurow_type; | |
72 } | |
73 | |
74 static void ui_skinned_menurow_class_init(UiSkinnedMenurowClass *klass) { | |
75 GObjectClass *gobject_class; | |
76 GtkObjectClass *object_class; | |
77 GtkWidgetClass *widget_class; | |
78 | |
79 gobject_class = G_OBJECT_CLASS(klass); | |
80 object_class = (GtkObjectClass*) klass; | |
81 widget_class = (GtkWidgetClass*) klass; | |
82 parent_class = gtk_type_class (gtk_widget_get_type ()); | |
83 | |
84 object_class->destroy = ui_skinned_menurow_destroy; | |
85 | |
86 widget_class->realize = ui_skinned_menurow_realize; | |
87 widget_class->expose_event = ui_skinned_menurow_expose; | |
88 widget_class->size_request = ui_skinned_menurow_size_request; | |
89 widget_class->size_allocate = ui_skinned_menurow_size_allocate; | |
90 widget_class->button_press_event = ui_skinned_menurow_button_press; | |
91 widget_class->button_release_event = ui_skinned_menurow_button_release; | |
92 widget_class->motion_notify_event = ui_skinned_menurow_motion_notify; | |
93 | |
94 klass->scaled = ui_skinned_menurow_toggle_scaled; | |
95 klass->change = NULL; | |
96 klass->release = NULL; | |
97 | |
98 menurow_signals[DOUBLED] = | |
99 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
100 G_STRUCT_OFFSET (UiSkinnedMenurowClass, scaled), NULL, NULL, | |
101 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
102 | |
103 | |
104 menurow_signals[CHANGE] = | |
105 g_signal_new ("change", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
106 G_STRUCT_OFFSET (UiSkinnedMenurowClass, change), NULL, NULL, | |
107 gtk_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); | |
108 | |
109 menurow_signals[RELEASE] = | |
110 g_signal_new ("release", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
111 G_STRUCT_OFFSET (UiSkinnedMenurowClass, release), NULL, NULL, | |
112 g_cclosure_marshal_VOID__UINT_POINTER, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_POINTER); | |
113 | |
114 } | |
115 | |
116 static void ui_skinned_menurow_init(UiSkinnedMenurow *menurow) { | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
117 menurow->scale_selected = config.scaled; |
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
118 menurow->always_selected = config.always_on_top; |
2581 | 119 } |
120 | |
121 GtkWidget* ui_skinned_menurow_new(GtkWidget *fixed, gint x, gint y, gint nx, gint ny, gint sx, gint sy, SkinPixmapId si) { | |
122 UiSkinnedMenurow *menurow = g_object_new (ui_skinned_menurow_get_type (), NULL); | |
123 | |
124 menurow->x = x; | |
125 menurow->y = y; | |
126 menurow->width = 8; | |
127 menurow->height = 43; | |
128 menurow->nx = nx; | |
129 menurow->ny = ny; | |
130 menurow->sx = sx; | |
131 menurow->sy = sy; | |
132 menurow->selected = MENUROW_NONE; | |
133 | |
134 menurow->skin_index = si; | |
135 | |
136 menurow->scaled = FALSE; | |
137 | |
138 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(menurow), menurow->x, menurow->y); | |
139 | |
140 return GTK_WIDGET(menurow); | |
141 } | |
142 | |
143 static void ui_skinned_menurow_destroy(GtkObject *object) { | |
144 UiSkinnedMenurow *menurow; | |
145 | |
146 g_return_if_fail (object != NULL); | |
147 g_return_if_fail (UI_SKINNED_IS_MENUROW (object)); | |
148 | |
149 menurow = UI_SKINNED_MENUROW (object); | |
150 | |
151 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
152 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
153 } | |
154 | |
155 static void ui_skinned_menurow_realize(GtkWidget *widget) { | |
156 UiSkinnedMenurow *menurow; | |
157 GdkWindowAttr attributes; | |
158 gint attributes_mask; | |
159 | |
160 g_return_if_fail (widget != NULL); | |
161 g_return_if_fail (UI_SKINNED_IS_MENUROW(widget)); | |
162 | |
163 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); | |
164 menurow = UI_SKINNED_MENUROW(widget); | |
165 | |
166 attributes.x = widget->allocation.x; | |
167 attributes.y = widget->allocation.y; | |
168 attributes.width = widget->allocation.width; | |
169 attributes.height = widget->allocation.height; | |
170 attributes.wclass = GDK_INPUT_OUTPUT; | |
171 attributes.window_type = GDK_WINDOW_CHILD; | |
172 attributes.event_mask = gtk_widget_get_events(widget); | |
173 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | | |
174 GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; | |
175 attributes.visual = gtk_widget_get_visual(widget); | |
176 attributes.colormap = gtk_widget_get_colormap(widget); | |
177 | |
178 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
179 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); | |
180 | |
181 widget->style = gtk_style_attach(widget->style, widget->window); | |
182 | |
183 gdk_window_set_user_data(widget->window, widget); | |
184 } | |
185 | |
186 static void ui_skinned_menurow_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
187 UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW(widget); | |
188 | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
189 requisition->width = menurow->width*(menurow->scaled ? config.scale_factor : 1); |
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
190 requisition->height = menurow->height*(menurow->scaled ? config.scale_factor : 1); |
2581 | 191 } |
192 | |
193 static void ui_skinned_menurow_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
194 UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW (widget); | |
195 | |
196 widget->allocation = *allocation; | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
197 widget->allocation.x *= (menurow->scaled ? config.scale_factor : 1); |
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
198 widget->allocation.y *= (menurow->scaled ? config.scale_factor : 1); |
2581 | 199 if (GTK_WIDGET_REALIZED (widget)) |
200 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); | |
201 | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
202 menurow->x = widget->allocation.x/(menurow->scaled ? config.scale_factor : 1); |
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
203 menurow->y = widget->allocation.y/(menurow->scaled ? config.scale_factor : 1); |
2581 | 204 } |
205 | |
206 static gboolean ui_skinned_menurow_expose(GtkWidget *widget, GdkEventExpose *event) { | |
207 g_return_val_if_fail (widget != NULL, FALSE); | |
208 g_return_val_if_fail (UI_SKINNED_IS_MENUROW (widget), FALSE); | |
209 g_return_val_if_fail (event != NULL, FALSE); | |
210 | |
211 UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW (widget); | |
212 g_return_val_if_fail (menurow->width > 0 && menurow->height > 0, FALSE); | |
213 | |
214 GdkPixbuf *obj = NULL; | |
215 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, menurow->width, menurow->height); | |
216 | |
217 if (menurow->selected == MENUROW_NONE) { | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
218 if (config.always_show_cb || menurow->pushed) |
2581 | 219 skin_draw_pixbuf(widget, aud_active_skin, obj, menurow->skin_index, |
220 menurow->nx, menurow->ny, 0, 0, 8, 43); | |
221 else | |
222 skin_draw_pixbuf(widget, aud_active_skin, obj, menurow->skin_index, | |
223 menurow->nx + 8, menurow->ny, 0, 0, 8, 43); | |
224 } | |
225 else { | |
226 skin_draw_pixbuf(widget, aud_active_skin, obj, menurow->skin_index, | |
227 menurow->sx + ((menurow->selected - 1) * 8), | |
228 menurow->sy, 0, 0, 8, 43); | |
229 } | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
230 if (config.always_show_cb || menurow->pushed) { |
2581 | 231 if (menurow->always_selected) |
232 skin_draw_pixbuf(widget, aud_active_skin, obj, menurow->skin_index, | |
233 menurow->sx + 8, menurow->sy + 10, 0, 10, 8, 8); | |
234 if (menurow->scale_selected) | |
235 skin_draw_pixbuf(widget, aud_active_skin, obj, menurow->skin_index, | |
236 menurow->sx + 24, menurow->sy + 26, 0, 26, 8, 8); | |
237 } | |
238 | |
239 ui_skinned_widget_draw(widget, obj, menurow->width, menurow->height, menurow->scaled); | |
240 | |
241 g_object_unref(obj); | |
242 | |
243 return FALSE; | |
244 } | |
245 | |
246 static MenuRowItem menurow_find_selected(UiSkinnedMenurow * mr, gint x, gint y) { | |
247 MenuRowItem ret = MENUROW_NONE; | |
248 | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
249 x = x/(mr->scaled ? config.scale_factor : 1); |
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
250 y = y/(mr->scaled ? config.scale_factor : 1); |
2581 | 251 if (x > 0 && x < 8) { |
252 if (y >= 0 && y <= 10) | |
253 ret = MENUROW_OPTIONS; | |
254 if (y >= 10 && y <= 17) | |
255 ret = MENUROW_ALWAYS; | |
256 if (y >= 18 && y <= 25) | |
257 ret = MENUROW_FILEINFOBOX; | |
258 if (y >= 26 && y <= 33) | |
259 ret = MENUROW_SCALE; | |
260 if (y >= 34 && y <= 42) | |
261 ret = MENUROW_VISUALIZATION; | |
262 } | |
263 return ret; | |
264 } | |
265 | |
266 static gboolean ui_skinned_menurow_button_press(GtkWidget *widget, GdkEventButton *event) { | |
267 g_return_val_if_fail (widget != NULL, FALSE); | |
268 g_return_val_if_fail (UI_SKINNED_IS_MENUROW (widget), FALSE); | |
269 g_return_val_if_fail (event != NULL, FALSE); | |
270 | |
271 UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW (widget); | |
272 | |
273 if (event->type == GDK_BUTTON_PRESS) { | |
274 if (event->button == 1) { | |
275 | |
276 menurow->pushed = TRUE; | |
277 menurow->selected = menurow_find_selected(menurow, event->x, event->y); | |
278 | |
279 gtk_widget_queue_draw(widget); | |
280 g_signal_emit_by_name(widget, "change", menurow->selected); | |
281 } | |
282 } | |
283 | |
284 return TRUE; | |
285 } | |
286 | |
287 static gboolean ui_skinned_menurow_button_release(GtkWidget *widget, GdkEventButton *event) { | |
288 UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW(widget); | |
289 if (menurow->pushed) { | |
290 menurow->pushed = FALSE; | |
291 | |
292 if (menurow->selected == MENUROW_ALWAYS) | |
293 menurow->always_selected = !menurow->always_selected; | |
294 | |
295 if (menurow->selected == MENUROW_SCALE) | |
296 menurow->scale_selected = !menurow->scale_selected; | |
297 | |
298 if ((int)(menurow->selected) != -1) | |
299 g_signal_emit_by_name(widget, "release", menurow->selected, event); | |
300 | |
301 menurow->selected = MENUROW_NONE; | |
302 gtk_widget_queue_draw(widget); | |
303 } | |
304 | |
305 return TRUE; | |
306 } | |
307 | |
308 static gboolean ui_skinned_menurow_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
309 g_return_val_if_fail (widget != NULL, FALSE); | |
310 g_return_val_if_fail (UI_SKINNED_IS_MENUROW (widget), FALSE); | |
311 g_return_val_if_fail (event != NULL, FALSE); | |
312 UiSkinnedMenurow *menurow = UI_SKINNED_MENUROW(widget); | |
313 | |
314 if (menurow->pushed) { | |
315 menurow->selected = menurow_find_selected(menurow, event->x, event->y); | |
316 | |
317 gtk_widget_queue_draw(widget); | |
318 g_signal_emit_by_name(widget, "change", menurow->selected); | |
319 } | |
320 | |
321 return TRUE; | |
322 } | |
323 | |
324 static void ui_skinned_menurow_toggle_scaled(UiSkinnedMenurow *menurow) { | |
325 GtkWidget *widget = GTK_WIDGET (menurow); | |
326 | |
327 menurow->scaled = !menurow->scaled; | |
2582
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
328 gtk_widget_set_size_request(widget, menurow->width* (menurow->scaled ? config.scale_factor : 1), |
9b4dfc007b87
use more local configuration options
Tomasz Mon <desowin@gmail.com>
parents:
2581
diff
changeset
|
329 menurow->height * (menurow->scaled ? config.scale_factor : 1)); |
2581 | 330 |
331 gtk_widget_queue_draw(GTK_WIDGET(menurow)); | |
332 } |