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