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