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