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