Mercurial > audlegacy
annotate src/audacious/widgets/playlist_list.c @ 2441:af8b86badfdb trunk
[svn] - Cleaned up a bit
author | mf0102 |
---|---|
date | Mon, 29 Jan 2007 09:55:26 -0800 |
parents | 1b109bc34ede |
children | d6315e592e40 |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2006 Audacious development team. | |
3 * | |
4 * BMP - Cross-platform multimedia player | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
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, write to the Free Software | |
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
23 */ | |
24 | |
25 /* | |
26 * A note about Pango and some funky spacey fonts: Weirdly baselined | |
27 * fonts, or fonts with weird ascents or descents _will_ display a | |
28 * little bit weird in the playlist widget, but the display engine | |
29 * won't make it look too bad, just a little deranged. I honestly | |
30 * don't think it's worth fixing (around...), it doesn't have to be | |
31 * perfectly fitting, just the general look has to be ok, which it | |
32 * IMHO is. | |
33 * | |
34 * A second note: The numbers aren't perfectly aligned, but in the | |
35 * end it looks better when using a single Pango layout for each | |
36 * number. | |
37 */ | |
38 | |
39 #include "widgetcore.h" | |
40 | |
41 #include <stdlib.h> | |
42 #include <string.h> | |
43 | |
44 #include "main.h" | |
45 #include "input.h" | |
2385
ab2b1b6f6179
[svn] - add missing inclusion of strings.h where necessary, do not export main.h and export strings.h
giacomo
parents:
2361
diff
changeset
|
46 #include "strings.h" |
2313 | 47 #include "playback.h" |
48 #include "playlist.h" | |
49 #include "ui_playlist.h" | |
50 #include "util.h" | |
51 | |
52 #include "debug.h" | |
53 | |
54 static PangoFontDescription *playlist_list_font = NULL; | |
55 static gint ascent, descent, width_delta_digit_one; | |
56 static gboolean has_slant; | |
57 static guint padding; | |
58 | |
59 /* FIXME: the following globals should not be needed. */ | |
60 static gint width_approx_letters; | |
61 static gint width_colon, width_colon_third; | |
62 static gint width_approx_digits, width_approx_digits_half; | |
63 | |
64 GdkPixmap *rootpix; | |
65 | |
66 void playlist_list_draw(Widget * w); | |
67 | |
68 /* Sort of stolen from XChat, but not really, as theres uses Xlib */ | |
69 static void | |
70 shade_gdkimage_generic (GdkVisual *visual, GdkImage *ximg, int bpl, int w, int h, int rm, int gm, int bm, int bg) | |
71 { | |
72 int x, y; | |
73 int bgr = (256 - rm) * (bg & visual->red_mask); | |
74 int bgg = (256 - gm) * (bg & visual->green_mask); | |
75 int bgb = (256 - bm) * (bg & visual->blue_mask); | |
76 | |
77 for (x = 0; x < w; x++) | |
78 { | |
79 for (y = 0; y < h; y++) | |
80 { | |
81 unsigned long pixel = gdk_image_get_pixel (ximg, x, y); | |
82 int r, g, b; | |
83 | |
84 r = rm * (pixel & visual->red_mask) + bgr; | |
85 g = gm * (pixel & visual->green_mask) + bgg; | |
86 b = bm * (pixel & visual->blue_mask) + bgb; | |
87 | |
88 gdk_image_put_pixel (ximg, x, y, | |
89 ((r >> 8) & visual->red_mask) | | |
90 ((g >> 8) & visual->green_mask) | | |
91 ((b >> 8) & visual->blue_mask)); | |
92 } | |
93 } | |
94 } | |
95 | |
96 /* and this is definately mine... -nenolod */ | |
97 GdkPixmap * | |
98 shade_pixmap(GdkPixmap *in, gint x, gint y, gint x_offset, gint y_offset, gint w, gint h, GdkColor *shade_color) | |
99 { | |
100 GdkImage *ximg; | |
101 GdkPixmap *p; | |
102 GdkGC *gc; | |
103 | |
104 g_return_val_if_fail(in != NULL, NULL); | |
105 | |
106 p = gdk_pixmap_new(in, w, h, -1); | |
107 gc = gdk_gc_new(p); | |
108 | |
109 gdk_draw_drawable(p, gc, in, x, y, 0, 0, w, h); | |
110 | |
111 gdk_error_trap_push(); | |
112 | |
113 ximg = gdk_drawable_copy_to_image(in, NULL, x, y, 0, 0, w, h); /* copy */ | |
114 | |
115 gdk_error_trap_pop(); | |
116 | |
117 if (GDK_IS_IMAGE(ximg)) | |
118 { | |
119 shade_gdkimage_generic(gdk_drawable_get_visual(GDK_WINDOW(playlistwin->window)), | |
120 ximg, ximg->bpl, w, h, 60, 60, 60, shade_color->pixel); | |
121 | |
122 gdk_draw_image(p, gc, ximg, 0, 0, x, y, w, h); | |
123 | |
124 g_object_unref(ximg); | |
125 } | |
126 else { | |
127 cfg.playlist_transparent = FALSE; | |
128 } | |
129 | |
130 g_object_unref(in); | |
131 g_object_unref(gc); | |
132 | |
133 return p; | |
134 } | |
135 | |
136 #ifdef GDK_WINDOWING_X11 | |
137 | |
138 #include <gdk/gdkx.h> | |
139 | |
140 GdkDrawable *get_transparency_pixmap(void) | |
141 { | |
142 GdkDrawable *root; | |
2418
1b109bc34ede
[svn] - fix: W:playlist_list.c(162) [get_transparency_pixmap]: possible type-punned pointer dereference
nenolod
parents:
2385
diff
changeset
|
143 guchar *pm = NULL; |
2313 | 144 GdkAtom prop_type; |
145 gint prop_size; | |
146 GdkPixmap *pixmap; | |
147 gboolean ret; | |
2418
1b109bc34ede
[svn] - fix: W:playlist_list.c(162) [get_transparency_pixmap]: possible type-punned pointer dereference
nenolod
parents:
2385
diff
changeset
|
148 XID *pixmaps; |
2313 | 149 |
150 root = gdk_get_default_root_window(); | |
151 | |
152 pixmap = NULL; | |
153 pixmaps = NULL; | |
154 | |
155 gdk_error_trap_push(); | |
156 | |
157 ret = gdk_property_get(root, gdk_atom_intern("_XROOTPMAP_ID", TRUE), | |
158 0, 0, INT_MAX - 3, | |
159 FALSE, | |
160 &prop_type, NULL, &prop_size, | |
2418
1b109bc34ede
[svn] - fix: W:playlist_list.c(162) [get_transparency_pixmap]: possible type-punned pointer dereference
nenolod
parents:
2385
diff
changeset
|
161 &pm); |
2313 | 162 |
163 gdk_error_trap_pop(); | |
164 | |
2418
1b109bc34ede
[svn] - fix: W:playlist_list.c(162) [get_transparency_pixmap]: possible type-punned pointer dereference
nenolod
parents:
2385
diff
changeset
|
165 if (pm != NULL) |
1b109bc34ede
[svn] - fix: W:playlist_list.c(162) [get_transparency_pixmap]: possible type-punned pointer dereference
nenolod
parents:
2385
diff
changeset
|
166 pixmaps = (XID *) pm; |
1b109bc34ede
[svn] - fix: W:playlist_list.c(162) [get_transparency_pixmap]: possible type-punned pointer dereference
nenolod
parents:
2385
diff
changeset
|
167 |
2313 | 168 if ((ret == TRUE) && (prop_type == GDK_TARGET_PIXMAP) && (prop_size >= sizeof(XID)) && (pixmaps != NULL)) |
169 { | |
170 pixmap = gdk_pixmap_foreign_new_for_display(gdk_drawable_get_display(root), | |
171 pixmaps[0]); | |
172 | |
173 if (pixmaps != NULL) | |
174 g_free(pixmaps); | |
175 } | |
176 | |
177 return GDK_DRAWABLE(pixmap); | |
178 } | |
179 | |
180 static GdkFilterReturn | |
181 root_event_cb (GdkXEvent *xev, GdkEventProperty *event, gpointer data) | |
182 { | |
183 XEvent *xevent = (XEvent *)xev; | |
184 | |
185 if (xevent->type == PropertyNotify) | |
186 { | |
187 Atom at = XInternAtom (xevent->xproperty.display, "_XROOTPMAP_ID", True); | |
188 | |
189 if (at == xevent->xproperty.atom) | |
190 { | |
191 if (rootpix != NULL) | |
192 g_object_unref(rootpix); | |
193 | |
194 rootpix = shade_pixmap(get_transparency_pixmap(), 0, 0, 0, 0, gdk_screen_width(), gdk_screen_height(), | |
195 skin_get_color(bmp_active_skin, SKIN_PLEDIT_NORMALBG)); | |
196 | |
197 if (cfg.playlist_transparent) | |
198 { | |
199 playlistwin_update_list(playlist_get_active()); | |
200 draw_playlist_window(TRUE); | |
201 } | |
202 } | |
203 } | |
204 | |
205 return GDK_FILTER_CONTINUE; | |
206 } | |
207 | |
208 #else | |
209 | |
210 GdkPixmap *get_transparency_pixmap(void) | |
211 { | |
212 return NULL; | |
213 } | |
214 | |
215 #endif | |
216 | |
217 static gboolean | |
218 playlist_list_auto_drag_down_func(gpointer data) | |
219 { | |
220 PlayList_List *pl = data; | |
221 | |
222 if (pl->pl_auto_drag_down) { | |
223 playlist_list_move_down(pl); | |
224 pl->pl_first++; | |
225 playlistwin_update_list(playlist_get_active()); | |
226 return TRUE; | |
227 } | |
228 return FALSE; | |
229 } | |
230 | |
231 static gboolean | |
232 playlist_list_auto_drag_up_func(gpointer data) | |
233 { | |
234 PlayList_List *pl = data; | |
235 | |
236 if (pl->pl_auto_drag_up) { | |
237 playlist_list_move_up(pl); | |
238 pl->pl_first--; | |
239 playlistwin_update_list(playlist_get_active()); | |
240 return TRUE; | |
241 | |
242 } | |
243 return FALSE; | |
244 } | |
245 | |
246 void | |
247 playlist_list_move_up(PlayList_List * pl) | |
248 { | |
249 GList *list; | |
250 Playlist *playlist = playlist_get_active(); | |
251 | |
252 if (!playlist) | |
253 return; | |
254 | |
255 PLAYLIST_LOCK(playlist->mutex); | |
256 if ((list = playlist->entries) == NULL) { | |
257 PLAYLIST_UNLOCK(playlist->mutex); | |
258 return; | |
259 } | |
260 if (PLAYLIST_ENTRY(list->data)->selected) { | |
261 /* We are at the top */ | |
262 PLAYLIST_UNLOCK(playlist->mutex); | |
263 return; | |
264 } | |
265 while (list) { | |
266 if (PLAYLIST_ENTRY(list->data)->selected) | |
267 glist_moveup(list); | |
268 list = g_list_next(list); | |
269 } | |
270 PLAYLIST_UNLOCK(playlist->mutex); | |
271 if (pl->pl_prev_selected != -1) | |
272 pl->pl_prev_selected--; | |
273 if (pl->pl_prev_min != -1) | |
274 pl->pl_prev_min--; | |
275 if (pl->pl_prev_max != -1) | |
276 pl->pl_prev_max--; | |
277 } | |
278 | |
279 void | |
280 playlist_list_move_down(PlayList_List * pl) | |
281 { | |
282 GList *list; | |
283 Playlist *playlist = playlist_get_active(); | |
284 | |
285 if (!playlist) | |
286 return; | |
287 | |
288 PLAYLIST_LOCK(playlist->mutex); | |
289 | |
290 if (!(list = g_list_last(playlist->entries))) { | |
291 PLAYLIST_UNLOCK(playlist->mutex); | |
292 return; | |
293 } | |
294 | |
295 if (PLAYLIST_ENTRY(list->data)->selected) { | |
296 /* We are at the bottom */ | |
297 PLAYLIST_UNLOCK(playlist->mutex); | |
298 return; | |
299 } | |
300 | |
301 while (list) { | |
302 if (PLAYLIST_ENTRY(list->data)->selected) | |
303 glist_movedown(list); | |
304 list = g_list_previous(list); | |
305 } | |
306 | |
307 PLAYLIST_UNLOCK(playlist->mutex); | |
308 | |
309 if (pl->pl_prev_selected != -1) | |
310 pl->pl_prev_selected++; | |
311 if (pl->pl_prev_min != -1) | |
312 pl->pl_prev_min++; | |
313 if (pl->pl_prev_max != -1) | |
314 pl->pl_prev_max++; | |
315 } | |
316 | |
317 static void | |
318 playlist_list_button_press_cb(GtkWidget * widget, | |
319 GdkEventButton * event, | |
320 PlayList_List * pl) | |
321 { | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
322 gint nr; |
2313 | 323 Playlist *playlist = playlist_get_active(); |
324 | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
325 nr = playlist_list_get_playlist_position(pl, event->x, event->y); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
326 if (nr == -1) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
327 return; |
2313 | 328 |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
329 if (event->button == 3) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
330 { |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
331 GList* selection = playlist_get_selected(playlist); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
332 if (g_list_find(selection, GINT_TO_POINTER(nr)) == NULL) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
333 { |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
334 playlist_select_all(playlist, FALSE); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
335 playlist_select_range(playlist, nr, nr, TRUE); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
336 } |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
337 } |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
338 else if (event->button == 1) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
339 { |
2313 | 340 if (!(event->state & GDK_CONTROL_MASK)) |
341 playlist_select_all(playlist, FALSE); | |
342 | |
343 if (event->state & GDK_SHIFT_MASK && pl->pl_prev_selected != -1) { | |
344 playlist_select_range(playlist, pl->pl_prev_selected, nr, TRUE); | |
345 pl->pl_prev_min = pl->pl_prev_selected; | |
346 pl->pl_prev_max = nr; | |
347 pl->pl_drag_pos = nr - pl->pl_first; | |
348 } | |
349 else { | |
350 if (playlist_select_invert(playlist, nr)) { | |
351 if (event->state & GDK_CONTROL_MASK) { | |
352 if (pl->pl_prev_min == -1) { | |
353 pl->pl_prev_min = pl->pl_prev_selected; | |
354 pl->pl_prev_max = pl->pl_prev_selected; | |
355 } | |
356 if (nr < pl->pl_prev_min) | |
357 pl->pl_prev_min = nr; | |
358 else if (nr > pl->pl_prev_max) | |
359 pl->pl_prev_max = nr; | |
360 } | |
361 else | |
362 pl->pl_prev_min = -1; | |
363 pl->pl_prev_selected = nr; | |
364 pl->pl_drag_pos = nr - pl->pl_first; | |
365 } | |
366 } | |
367 if (event->type == GDK_2BUTTON_PRESS) { | |
368 /* | |
369 * Ungrab the pointer to prevent us from | |
370 * hanging on to it during the sometimes slow | |
371 * playback_initiate(). | |
372 */ | |
373 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
374 gdk_flush(); | |
375 playlist_set_position(playlist, nr); | |
376 if (!playback_get_playing()) | |
377 playback_initiate(); | |
378 } | |
379 | |
380 pl->pl_dragging = TRUE; | |
381 } | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
382 |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
383 playlistwin_update_list(playlist); |
2313 | 384 } |
385 | |
386 gint | |
387 playlist_list_get_playlist_position(PlayList_List * pl, | |
388 gint x, | |
389 gint y) | |
390 { | |
391 gint iy, length; | |
392 gint ret; | |
393 Playlist *playlist = playlist_get_active(); | |
394 | |
395 if (!widget_contains(WIDGET(pl), x, y) || !pl->pl_fheight) | |
396 return -1; | |
397 | |
398 if ((length = playlist_get_length(playlist)) == 0) | |
399 return -1; | |
400 iy = y - pl->pl_widget.y; | |
401 | |
402 ret = (iy / pl->pl_fheight) + pl->pl_first; | |
403 | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
404 if (ret > length - 1) |
2313 | 405 ret = -1; |
406 | |
407 return ret; | |
408 } | |
409 | |
410 static void | |
411 playlist_list_motion_cb(GtkWidget * widget, | |
412 GdkEventMotion * event, | |
413 PlayList_List * pl) | |
414 { | |
415 gint nr, y, off, i; | |
416 | |
417 if (pl->pl_dragging) { | |
418 y = event->y - pl->pl_widget.y; | |
419 nr = (y / pl->pl_fheight); | |
420 if (nr < 0) { | |
421 nr = 0; | |
422 if (!pl->pl_auto_drag_up) { | |
423 pl->pl_auto_drag_up = TRUE; | |
424 pl->pl_auto_drag_up_tag = | |
425 g_timeout_add(100, playlist_list_auto_drag_up_func, pl); | |
426 } | |
427 } | |
428 else if (pl->pl_auto_drag_up) | |
429 pl->pl_auto_drag_up = FALSE; | |
430 | |
431 if (nr >= pl->pl_num_visible) { | |
432 nr = pl->pl_num_visible - 1; | |
433 if (!pl->pl_auto_drag_down) { | |
434 pl->pl_auto_drag_down = TRUE; | |
435 pl->pl_auto_drag_down_tag = | |
436 g_timeout_add(100, playlist_list_auto_drag_down_func, | |
437 pl); | |
438 } | |
439 } | |
440 else if (pl->pl_auto_drag_down) | |
441 pl->pl_auto_drag_down = FALSE; | |
442 | |
443 off = nr - pl->pl_drag_pos; | |
444 if (off) { | |
445 for (i = 0; i < abs(off); i++) { | |
446 if (off < 0) | |
447 playlist_list_move_up(pl); | |
448 else | |
449 playlist_list_move_down(pl); | |
450 | |
451 } | |
452 playlistwin_update_list(playlist_get_active()); | |
453 } | |
454 pl->pl_drag_pos = nr; | |
455 } | |
456 } | |
457 | |
458 static void | |
459 playlist_list_button_release_cb(GtkWidget * widget, | |
460 GdkEventButton * event, | |
461 PlayList_List * pl) | |
462 { | |
463 pl->pl_dragging = FALSE; | |
464 pl->pl_auto_drag_down = FALSE; | |
465 pl->pl_auto_drag_up = FALSE; | |
466 } | |
467 | |
468 static void | |
469 playlist_list_draw_string(PlayList_List * pl, | |
470 PangoFontDescription * font, | |
471 gint line, | |
472 gint width, | |
473 const gchar * text, | |
474 guint ppos) | |
475 { | |
476 guint plist_length_int; | |
477 Playlist *playlist = playlist_get_active(); | |
478 | |
479 PangoLayout *layout; | |
480 | |
481 REQUIRE_LOCK(playlist->mutex); | |
482 | |
483 if (cfg.show_numbers_in_pl) { | |
484 gchar *pos_string = g_strdup_printf(cfg.show_separator_in_pl == TRUE ? "%d" : "%d.", ppos); | |
485 plist_length_int = | |
486 gint_count_digits(playlist_get_length_nolock(playlist)) + !cfg.show_separator_in_pl + 1; /* cf.show_separator_in_pl will be 0 if false */ | |
487 | |
488 padding = plist_length_int; | |
489 padding = ((padding + 1) * width_approx_digits); | |
490 | |
491 layout = gtk_widget_create_pango_layout(playlistwin, pos_string); | |
492 pango_layout_set_font_description(layout, playlist_list_font); | |
493 pango_layout_set_width(layout, plist_length_int * 100); | |
494 | |
495 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); | |
496 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, | |
497 pl->pl_widget.x + | |
498 (width_approx_digits * | |
499 (-1 + plist_length_int - strlen(pos_string))) + | |
500 (width_approx_digits / 4), | |
501 pl->pl_widget.y + (line - 1) * pl->pl_fheight + | |
502 ascent + abs(descent), layout); | |
503 g_free(pos_string); | |
504 g_object_unref(layout); | |
505 | |
506 if (!cfg.show_separator_in_pl) | |
507 padding -= (width_approx_digits * 1.5); | |
508 } | |
509 else { | |
510 padding = 3; | |
511 } | |
512 | |
513 width -= padding; | |
514 | |
515 layout = gtk_widget_create_pango_layout(playlistwin, text); | |
516 | |
517 pango_layout_set_font_description(layout, playlist_list_font); | |
518 pango_layout_set_width(layout, width * PANGO_SCALE); | |
519 pango_layout_set_single_paragraph_mode(layout, TRUE); | |
520 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); | |
521 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, | |
522 pl->pl_widget.x + padding + (width_approx_letters / 4), | |
523 pl->pl_widget.y + (line - 1) * pl->pl_fheight + | |
524 ascent + abs(descent), layout); | |
525 | |
526 g_object_unref(layout); | |
527 } | |
528 | |
529 void | |
530 playlist_list_draw(Widget * w) | |
531 { | |
532 Playlist *playlist = playlist_get_active(); | |
533 PlayList_List *pl = PLAYLIST_LIST(w); | |
534 GList *list; | |
535 GdkGC *gc; | |
536 GdkPixmap *obj; | |
537 PangoLayout *layout; | |
538 gchar *title; | |
539 gint width, height; | |
540 gint i, max_first; | |
541 guint padding, padding_dwidth, padding_plength; | |
542 guint max_time_len = 0; | |
543 gfloat queue_tailpadding = 0; | |
544 gint tpadding; | |
545 gsize tpadding_dwidth = 0; | |
546 gint x, y; | |
547 guint tail_width; | |
548 guint tail_len; | |
549 | |
550 gchar tail[100]; | |
551 gchar queuepos[255]; | |
552 gchar length[40]; | |
553 | |
554 gchar **frags; | |
555 gchar *frag0; | |
556 | |
557 gint plw_w, plw_h; | |
558 | |
559 GdkRectangle *playlist_rect; | |
560 | |
561 gc = pl->pl_widget.gc; | |
562 | |
563 width = pl->pl_widget.width; | |
564 height = pl->pl_widget.height; | |
565 | |
566 obj = pl->pl_widget.parent; | |
567 | |
568 plw_w = playlistwin_get_width(); | |
569 plw_h = playlistwin_get_height(); | |
570 | |
571 playlist_rect = g_new0(GdkRectangle, 1); | |
572 | |
573 playlist_rect->x = 0; | |
574 playlist_rect->y = 0; | |
575 playlist_rect->width = plw_w - 17; | |
576 playlist_rect->height = plw_h - 36; | |
577 | |
578 gdk_gc_set_clip_origin(gc, 31, 58); | |
579 gdk_gc_set_clip_rectangle(gc, playlist_rect); | |
580 | |
581 if (cfg.playlist_transparent == FALSE) | |
582 { | |
583 gdk_gc_set_foreground(gc, | |
584 skin_get_color(bmp_active_skin, | |
585 SKIN_PLEDIT_NORMALBG)); | |
586 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, pl->pl_widget.y, | |
587 width, height); | |
588 } | |
589 else | |
590 { | |
591 if (!rootpix) | |
592 rootpix = shade_pixmap(get_transparency_pixmap(), 0, 0, 0, 0, gdk_screen_width(), gdk_screen_height(), | |
593 skin_get_color(bmp_active_skin, SKIN_PLEDIT_NORMALBG)); | |
594 gdk_draw_drawable(obj, gc, rootpix, cfg.playlist_x + pl->pl_widget.x, | |
595 cfg.playlist_y + pl->pl_widget.y, pl->pl_widget.x, pl->pl_widget.y, | |
596 width, height); | |
597 } | |
598 | |
599 if (!playlist_list_font) { | |
600 g_critical("Couldn't open playlist font"); | |
601 return; | |
602 } | |
603 | |
604 pl->pl_fheight = (ascent + abs(descent)); | |
605 pl->pl_num_visible = height / pl->pl_fheight; | |
606 | |
607 max_first = playlist_get_length(playlist) - pl->pl_num_visible; | |
608 max_first = MAX(max_first, 0); | |
609 | |
610 pl->pl_first = CLAMP(pl->pl_first, 0, max_first); | |
611 | |
612 PLAYLIST_LOCK(playlist->mutex); | |
613 list = playlist->entries; | |
614 list = g_list_nth(list, pl->pl_first); | |
615 | |
616 /* It sucks having to run the iteration twice but this is the only | |
617 way you can reliably get the maximum width so we can get our | |
618 playlist nice and aligned... -- plasmaroo */ | |
619 | |
620 for (i = pl->pl_first; | |
621 list && i < pl->pl_first + pl->pl_num_visible; | |
622 list = g_list_next(list), i++) { | |
623 PlaylistEntry *entry = list->data; | |
624 | |
625 if (entry->length != -1) | |
626 { | |
627 g_snprintf(length, sizeof(length), "%d:%-2.2d", | |
628 entry->length / 60000, (entry->length / 1000) % 60); | |
629 tpadding_dwidth = MAX(tpadding_dwidth, strlen(length)); | |
630 } | |
631 } | |
632 | |
633 /* Reset */ | |
634 list = playlist->entries; | |
635 list = g_list_nth(list, pl->pl_first); | |
636 | |
637 for (i = pl->pl_first; | |
638 list && i < pl->pl_first + pl->pl_num_visible; | |
639 list = g_list_next(list), i++) { | |
640 gint pos; | |
641 PlaylistEntry *entry = list->data; | |
642 | |
643 if (entry->selected) { | |
644 gdk_gc_set_foreground(gc, | |
645 skin_get_color(bmp_active_skin, | |
646 SKIN_PLEDIT_SELECTEDBG)); | |
647 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, | |
648 pl->pl_widget.y + | |
649 ((i - pl->pl_first) * pl->pl_fheight), | |
650 width, pl->pl_fheight); | |
651 } | |
652 | |
653 /* FIXME: entry->title should NEVER be NULL, and there should | |
654 NEVER be a need to do a UTF-8 conversion. Playlist title | |
655 strings should be kept properly. */ | |
656 | |
657 if (!entry->title) { | |
658 gchar *basename = g_path_get_basename(entry->filename); | |
659 title = filename_to_utf8(basename); | |
660 g_free(basename); | |
661 } | |
662 else | |
663 title = str_to_utf8(entry->title); | |
664 | |
665 title = convert_title_text(title); | |
666 | |
667 pos = playlist_get_queue_position(playlist, entry); | |
668 | |
669 tail[0] = 0; | |
670 queuepos[0] = 0; | |
671 length[0] = 0; | |
672 | |
673 if (pos != -1) | |
674 g_snprintf(queuepos, sizeof(queuepos), "%d", pos + 1); | |
675 | |
676 if (entry->length != -1) | |
677 { | |
678 g_snprintf(length, sizeof(length), "%d:%-2.2d", | |
679 entry->length / 60000, (entry->length / 1000) % 60); | |
680 } | |
681 | |
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2356
diff
changeset
|
682 strncat(tail, length, sizeof(tail) - 1); |
2313 | 683 tail_len = strlen(tail); |
684 | |
685 max_time_len = MAX(max_time_len, tail_len); | |
686 | |
687 if (pos != -1 && tpadding_dwidth <= 0) | |
688 tail_width = width - (width_approx_digits * (strlen(queuepos) + 2.25)); | |
689 else if (pos != -1) | |
690 tail_width = width - (width_approx_digits * (tpadding_dwidth + strlen(queuepos) + 4)); | |
691 else if (tpadding_dwidth > 0) | |
692 tail_width = width - (width_approx_digits * (tpadding_dwidth + 2.5)); | |
693 else | |
694 tail_width = width; | |
695 | |
696 if (i == playlist_get_position_nolock(playlist)) | |
697 gdk_gc_set_foreground(gc, | |
698 skin_get_color(bmp_active_skin, | |
699 SKIN_PLEDIT_CURRENT)); | |
700 else | |
701 gdk_gc_set_foreground(gc, | |
702 skin_get_color(bmp_active_skin, | |
703 SKIN_PLEDIT_NORMAL)); | |
704 playlist_list_draw_string(pl, playlist_list_font, | |
705 i - pl->pl_first, tail_width, title, | |
706 i + 1); | |
707 | |
708 x = pl->pl_widget.x + width - width_approx_digits * 2; | |
709 y = pl->pl_widget.y + ((i - pl->pl_first) - | |
710 1) * pl->pl_fheight + ascent; | |
711 | |
712 frags = NULL; | |
713 frag0 = NULL; | |
714 | |
715 if ((strlen(tail) > 0) && (tail != NULL)) { | |
716 frags = g_strsplit(tail, ":", 0); | |
717 frag0 = g_strconcat(frags[0], ":", NULL); | |
718 | |
719 layout = gtk_widget_create_pango_layout(playlistwin, frags[1]); | |
720 pango_layout_set_font_description(layout, playlist_list_font); | |
721 pango_layout_set_width(layout, tail_len * 100); | |
722 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); | |
723 gdk_draw_layout(obj, gc, x - (0.5 * width_approx_digits), | |
724 y + abs(descent), layout); | |
725 g_object_unref(layout); | |
726 | |
727 layout = gtk_widget_create_pango_layout(playlistwin, frag0); | |
728 pango_layout_set_font_description(layout, playlist_list_font); | |
729 pango_layout_set_width(layout, tail_len * 100); | |
730 pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); | |
731 gdk_draw_layout(obj, gc, x - (0.75 * width_approx_digits), | |
732 y + abs(descent), layout); | |
733 g_object_unref(layout); | |
734 | |
735 g_free(frag0); | |
736 g_strfreev(frags); | |
737 } | |
738 | |
739 if (pos != -1) { | |
740 | |
741 /* DON'T remove the commented code yet please -- Milosz */ | |
742 | |
743 if (tpadding_dwidth > 0) | |
744 queue_tailpadding = tpadding_dwidth + 1; | |
745 else | |
746 queue_tailpadding = -0.75; | |
747 | |
748 gdk_draw_rectangle(obj, gc, FALSE, | |
749 x - | |
750 (((queue_tailpadding + | |
751 strlen(queuepos)) * | |
752 width_approx_digits) + | |
753 (width_approx_digits / 4)), | |
754 y + abs(descent), | |
755 (strlen(queuepos)) * | |
756 width_approx_digits + | |
757 (width_approx_digits / 2), | |
758 pl->pl_fheight - 2); | |
759 | |
760 layout = | |
761 gtk_widget_create_pango_layout(playlistwin, queuepos); | |
762 pango_layout_set_font_description(layout, playlist_list_font); | |
763 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); | |
764 | |
765 gdk_draw_layout(obj, gc, | |
766 x - | |
767 ((queue_tailpadding + | |
768 strlen(queuepos)) * width_approx_digits) + | |
769 (width_approx_digits / 4), | |
770 y + abs(descent), layout); | |
771 g_object_unref(layout); | |
772 } | |
773 | |
774 g_free(title); | |
775 } | |
776 | |
777 | |
778 /* | |
779 * Drop target hovering over the playlist, so draw some hint where the | |
780 * drop will occur. | |
781 * | |
782 * This is (currently? unfixably?) broken when dragging files from Qt/KDE apps, | |
783 * probably due to DnD signaling problems (actually i have no clue). | |
784 * | |
785 */ | |
786 | |
787 if (pl->pl_drag_motion) { | |
788 guint pos, plength, lpadding; | |
789 gint x, y, plx, ply; | |
790 | |
791 if (cfg.show_numbers_in_pl) { | |
792 lpadding = gint_count_digits(playlist_get_length_nolock(playlist)) + 1; | |
793 lpadding = ((lpadding + 1) * width_approx_digits); | |
794 } | |
795 else { | |
796 lpadding = 3; | |
797 }; | |
798 | |
799 /* We already hold the mutex and have the playlist locked, so call | |
800 the non-locking function. */ | |
801 plength = playlist_get_length_nolock(playlist); | |
802 | |
803 x = pl->drag_motion_x; | |
804 y = pl->drag_motion_y; | |
805 | |
806 plx = pl->pl_widget.x; | |
807 ply = pl->pl_widget.y; | |
808 | |
809 if ((x > pl->pl_widget.x) && !(x > pl->pl_widget.width)) { | |
810 | |
811 if ((y > pl->pl_widget.y) | |
812 && !(y > (pl->pl_widget.height + ply))) { | |
813 | |
814 pos = ((y - ((Widget *) pl)->y) / pl->pl_fheight) + | |
815 pl->pl_first; | |
816 | |
817 if (pos > (plength)) { | |
818 pos = plength; | |
819 } | |
820 | |
821 gdk_gc_set_foreground(gc, | |
822 skin_get_color(bmp_active_skin, | |
823 SKIN_PLEDIT_CURRENT)); | |
824 | |
825 gdk_draw_line(obj, gc, pl->pl_widget.x, | |
826 pl->pl_widget.y + ((pos - pl->pl_first) * pl->pl_fheight), | |
827 pl->pl_widget.width + pl->pl_widget.x - 1, | |
828 pl->pl_widget.y + | |
829 ((pos - pl->pl_first) * pl->pl_fheight)); | |
830 } | |
831 | |
832 } | |
833 | |
834 /* When dropping on the borders of the playlist, outside the text area, | |
835 * files get appended at the end of the list. Show that too. | |
836 */ | |
837 | |
838 if ((y < ply) || (y > pl->pl_widget.height + ply)) { | |
839 if ((y >= 0) || (y <= (pl->pl_widget.height + ply))) { | |
840 pos = plength; | |
841 gdk_gc_set_foreground(gc, | |
842 skin_get_color(bmp_active_skin, | |
843 SKIN_PLEDIT_CURRENT)); | |
844 | |
845 gdk_draw_line(obj, gc, pl->pl_widget.x, | |
846 pl->pl_widget.y + | |
847 ((pos - pl->pl_first) * pl->pl_fheight), | |
848 pl->pl_widget.width + pl->pl_widget.x - 1, | |
849 pl->pl_widget.y + | |
850 ((pos - pl->pl_first) * pl->pl_fheight)); | |
851 | |
852 } | |
853 } | |
854 } | |
855 | |
856 gdk_gc_set_foreground(gc, | |
857 skin_get_color(bmp_active_skin, | |
858 SKIN_PLEDIT_NORMAL)); | |
859 | |
860 if (cfg.show_numbers_in_pl) | |
861 { | |
862 padding_plength = playlist_get_length_nolock(playlist); | |
863 | |
864 if (padding_plength == 0) { | |
865 padding_dwidth = 0; | |
866 } | |
867 else { | |
868 padding_dwidth = gint_count_digits(playlist_get_length_nolock(playlist)); | |
869 } | |
870 | |
871 padding = | |
872 (padding_dwidth * | |
873 width_approx_digits) + width_approx_digits; | |
874 | |
875 | |
876 /* For italic or oblique fonts we add another half of the | |
877 * approximate width */ | |
878 if (has_slant) | |
879 padding += width_approx_digits_half; | |
880 | |
881 if (cfg.show_separator_in_pl) { | |
882 gdk_draw_line(obj, gc, | |
883 pl->pl_widget.x + padding, | |
884 pl->pl_widget.y, | |
885 pl->pl_widget.x + padding, | |
886 pl->pl_widget.y + pl->pl_widget.height - 1); | |
887 } | |
888 } | |
889 | |
890 if (tpadding_dwidth != 0) | |
891 { | |
892 tpadding = (tpadding_dwidth * width_approx_digits) + (width_approx_digits * 1.5); | |
893 | |
894 if (has_slant) | |
895 tpadding += width_approx_digits_half; | |
896 | |
897 if (cfg.show_separator_in_pl) { | |
898 gdk_draw_line(obj, gc, | |
899 pl->pl_widget.x + pl->pl_widget.width - tpadding, | |
900 pl->pl_widget.y, | |
901 pl->pl_widget.x + pl->pl_widget.width - tpadding, | |
902 pl->pl_widget.y + pl->pl_widget.height - 1); | |
903 } | |
904 } | |
905 | |
906 gdk_gc_set_clip_origin(gc, 0, 0); | |
907 gdk_gc_set_clip_rectangle(gc, NULL); | |
908 | |
909 PLAYLIST_UNLOCK(playlist->mutex); | |
910 | |
911 gdk_flush(); | |
912 | |
913 g_free(playlist_rect); | |
914 } | |
915 | |
916 | |
917 PlayList_List * | |
918 create_playlist_list(GList ** wlist, | |
919 GdkPixmap * parent, | |
920 GdkGC * gc, | |
921 gint x, gint y, | |
922 gint w, gint h) | |
923 { | |
924 PlayList_List *pl; | |
925 | |
926 pl = g_new0(PlayList_List, 1); | |
927 widget_init(&pl->pl_widget, parent, gc, x, y, w, h, TRUE); | |
928 | |
929 pl->pl_widget.button_press_cb = | |
930 (WidgetButtonPressFunc) playlist_list_button_press_cb; | |
931 pl->pl_widget.button_release_cb = | |
932 (WidgetButtonReleaseFunc) playlist_list_button_release_cb; | |
933 pl->pl_widget.motion_cb = (WidgetMotionFunc) playlist_list_motion_cb; | |
934 pl->pl_widget.draw = playlist_list_draw; | |
935 | |
936 pl->pl_prev_selected = -1; | |
937 pl->pl_prev_min = -1; | |
938 pl->pl_prev_max = -1; | |
939 | |
940 widget_list_add(wlist, WIDGET(pl)); | |
941 | |
942 #ifdef GDK_WINDOWING_X11 | |
943 gdk_window_set_events (gdk_get_default_root_window(), GDK_PROPERTY_CHANGE_MASK); | |
944 gdk_window_add_filter (gdk_get_default_root_window(), (GdkFilterFunc)root_event_cb, pl); | |
945 #endif | |
946 | |
947 return pl; | |
948 } | |
949 | |
950 void | |
951 playlist_list_set_font(const gchar * font) | |
952 { | |
953 | |
954 /* Welcome to bad hack central 2k3 */ | |
955 | |
956 gchar *font_lower; | |
957 gint width_temp; | |
958 gint width_temp_0; | |
959 | |
960 playlist_list_font = pango_font_description_from_string(font); | |
961 | |
962 text_get_extents(font, | |
963 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ", | |
964 &width_approx_letters, NULL, &ascent, &descent); | |
965 | |
966 width_approx_letters = (width_approx_letters / 53); | |
967 | |
968 /* Experimental: We don't weigh the 1 into total because it's width is almost always | |
969 * very different from the rest | |
970 */ | |
971 text_get_extents(font, "023456789", &width_approx_digits, NULL, NULL, | |
972 NULL); | |
973 width_approx_digits = (width_approx_digits / 9); | |
974 | |
975 /* Precache some often used calculations */ | |
976 width_approx_digits_half = width_approx_digits / 2; | |
977 | |
978 /* FIXME: We assume that any other number is broader than the "1" */ | |
979 text_get_extents(font, "1", &width_temp, NULL, NULL, NULL); | |
980 text_get_extents(font, "2", &width_temp_0, NULL, NULL, NULL); | |
981 | |
982 if (abs(width_temp_0 - width_temp) < 2) { | |
983 width_delta_digit_one = 0; | |
984 } | |
985 else { | |
986 width_delta_digit_one = ((width_temp_0 - width_temp) / 2) + 2; | |
987 } | |
988 | |
989 text_get_extents(font, ":", &width_colon, NULL, NULL, NULL); | |
990 width_colon_third = width_colon / 4; | |
991 | |
992 font_lower = g_utf8_strdown(font, strlen(font)); | |
993 /* This doesn't take any i18n into account, but i think there is none with TTF fonts | |
994 * FIXME: This can probably be retrieved trough Pango too | |
995 */ | |
996 has_slant = g_strstr_len(font_lower, strlen(font_lower), "oblique") | |
997 || g_strstr_len(font_lower, strlen(font_lower), "italic"); | |
998 | |
999 g_free(font_lower); | |
1000 } |