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