comparison audacious/playlist_list.c @ 0:cb178e5ad177 trunk

[svn] Import audacious source.
author nenolod
date Mon, 24 Oct 2005 03:06:47 -0700
parents
children 763afa52f416
comparison
equal deleted inserted replaced
-1:000000000000 0:cb178e5ad177
1 /* BMP - Cross-platform multimedia player
2 * Copyright (C) 2003-2004 BMP development team.
3 *
4 * Based on XMMS:
5 * Copyright (C) 1998-2003 XMMS development team.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 /*
23 * A note about Pango and some funky spacey fonts: Weirdly baselined
24 * fonts, or fonts with weird ascents or descents _will_ display a
25 * little bit weird in the playlist widget, but the display engine
26 * won't make it look too bad, just a little deranged. I honestly
27 * don't think it's worth fixing (around...), it doesn't have to be
28 * perfectly fitting, just the general look has to be ok, which it
29 * IMHO is.
30 *
31 * A second note: The numbers aren't perfectly aligned, but in the
32 * end it looks better when using a single Pango layout for each
33 * number.
34 */
35
36 #include "playlist_list.h"
37
38 #include <stdlib.h>
39 #include <string.h>
40
41 #include "main.h"
42 #include "input.h"
43 #include "playback.h"
44 #include "playlist.h"
45 #include "playlistwin.h"
46 #include "util.h"
47
48 #include "debug.h"
49
50 static PangoFontDescription *playlist_list_font = NULL;
51 static gint ascent, descent, width_delta_digit_one;
52 static gboolean has_slant;
53 static guint padding;
54
55 /* FIXME: the following globals should not be needed. */
56 static gint width_approx_letters;
57 static gint width_colon, width_colon_third;
58 static gint width_approx_digits, width_approx_digits_half;
59
60 static gboolean
61 playlist_list_auto_drag_down_func(gpointer data)
62 {
63 PlayList_List *pl = data;
64
65 if (pl->pl_auto_drag_down) {
66 playlist_list_move_down(pl);
67 pl->pl_first++;
68 playlistwin_update_list();
69 return TRUE;
70 }
71 return FALSE;
72 }
73
74 static gboolean
75 playlist_list_auto_drag_up_func(gpointer data)
76 {
77 PlayList_List *pl = data;
78
79 if (pl->pl_auto_drag_up) {
80 playlist_list_move_up(pl);
81 pl->pl_first--;
82 playlistwin_update_list();
83 return TRUE;
84
85 }
86 return FALSE;
87 }
88
89 void
90 playlist_list_move_up(PlayList_List * pl)
91 {
92 GList *list;
93
94 PLAYLIST_LOCK();
95 if ((list = playlist_get()) == NULL) {
96 PLAYLIST_UNLOCK();
97 return;
98 }
99 if (PLAYLIST_ENTRY(list->data)->selected) {
100 /* We are at the top */
101 PLAYLIST_UNLOCK();
102 return;
103 }
104 while (list) {
105 if (PLAYLIST_ENTRY(list->data)->selected)
106 glist_moveup(list);
107 list = g_list_next(list);
108 }
109 PLAYLIST_UNLOCK();
110 if (pl->pl_prev_selected != -1)
111 pl->pl_prev_selected--;
112 if (pl->pl_prev_min != -1)
113 pl->pl_prev_min--;
114 if (pl->pl_prev_max != -1)
115 pl->pl_prev_max--;
116 }
117
118 void
119 playlist_list_move_down(PlayList_List * pl)
120 {
121 GList *list;
122
123 PLAYLIST_LOCK();
124
125 if (!(list = g_list_last(playlist_get()))) {
126 PLAYLIST_UNLOCK();
127 return;
128 }
129
130 if (PLAYLIST_ENTRY(list->data)->selected) {
131 /* We are at the bottom */
132 PLAYLIST_UNLOCK();
133 return;
134 }
135
136 while (list) {
137 if (PLAYLIST_ENTRY(list->data)->selected)
138 glist_movedown(list);
139 list = g_list_previous(list);
140 }
141
142 PLAYLIST_UNLOCK();
143
144 if (pl->pl_prev_selected != -1)
145 pl->pl_prev_selected++;
146 if (pl->pl_prev_min != -1)
147 pl->pl_prev_min++;
148 if (pl->pl_prev_max != -1)
149 pl->pl_prev_max++;
150 }
151
152 static void
153 playlist_list_button_press_cb(GtkWidget * widget,
154 GdkEventButton * event,
155 PlayList_List * pl)
156 {
157 gint nr, y;
158
159 if (event->button == 1 && pl->pl_fheight &&
160 widget_contains(&pl->pl_widget, event->x, event->y)) {
161
162 y = event->y - pl->pl_widget.y;
163 nr = (y / pl->pl_fheight) + pl->pl_first;
164
165 if (nr >= playlist_get_length())
166 nr = playlist_get_length() - 1;
167
168 if (!(event->state & GDK_CONTROL_MASK))
169 playlist_select_all(FALSE);
170
171 if (event->state & GDK_SHIFT_MASK && pl->pl_prev_selected != -1) {
172 playlist_select_range(pl->pl_prev_selected, nr, TRUE);
173 pl->pl_prev_min = pl->pl_prev_selected;
174 pl->pl_prev_max = nr;
175 pl->pl_drag_pos = nr - pl->pl_first;
176 }
177 else {
178 if (playlist_select_invert(nr)) {
179 if (event->state & GDK_CONTROL_MASK) {
180 if (pl->pl_prev_min == -1) {
181 pl->pl_prev_min = pl->pl_prev_selected;
182 pl->pl_prev_max = pl->pl_prev_selected;
183 }
184 if (nr < pl->pl_prev_min)
185 pl->pl_prev_min = nr;
186 else if (nr > pl->pl_prev_max)
187 pl->pl_prev_max = nr;
188 }
189 else
190 pl->pl_prev_min = -1;
191 pl->pl_prev_selected = nr;
192 pl->pl_drag_pos = nr - pl->pl_first;
193 }
194 }
195 if (event->type == GDK_2BUTTON_PRESS) {
196 /*
197 * Ungrab the pointer to prevent us from
198 * hanging on to it during the sometimes slow
199 * bmp_playback_initiate().
200 */
201 gdk_pointer_ungrab(GDK_CURRENT_TIME);
202 gdk_flush();
203 playlist_set_position(nr);
204 if (!bmp_playback_get_playing())
205 bmp_playback_initiate();
206 }
207
208 pl->pl_dragging = TRUE;
209 playlistwin_update_list();
210 }
211 }
212
213 gint
214 playlist_list_get_playlist_position(PlayList_List * pl,
215 gint x,
216 gint y)
217 {
218 gint iy, length;
219
220 if (!widget_contains(WIDGET(pl), x, y) || !pl->pl_fheight)
221 return -1;
222
223 if ((length = playlist_get_length()) == 0)
224 return -1;
225 iy = y - pl->pl_widget.y;
226
227 return (MIN((iy / pl->pl_fheight) + pl->pl_first, length - 1));
228 }
229
230 static void
231 playlist_list_motion_cb(GtkWidget * widget,
232 GdkEventMotion * event,
233 PlayList_List * pl)
234 {
235 gint nr, y, off, i;
236
237 if (pl->pl_dragging) {
238 y = event->y - pl->pl_widget.y;
239 nr = (y / pl->pl_fheight);
240 if (nr < 0) {
241 nr = 0;
242 if (!pl->pl_auto_drag_up) {
243 pl->pl_auto_drag_up = TRUE;
244 pl->pl_auto_drag_up_tag =
245 gtk_timeout_add(100, playlist_list_auto_drag_up_func, pl);
246 }
247 }
248 else if (pl->pl_auto_drag_up)
249 pl->pl_auto_drag_up = FALSE;
250
251 if (nr >= pl->pl_num_visible) {
252 nr = pl->pl_num_visible - 1;
253 if (!pl->pl_auto_drag_down) {
254 pl->pl_auto_drag_down = TRUE;
255 pl->pl_auto_drag_down_tag =
256 gtk_timeout_add(100, playlist_list_auto_drag_down_func,
257 pl);
258 }
259 }
260 else if (pl->pl_auto_drag_down)
261 pl->pl_auto_drag_down = FALSE;
262
263 off = nr - pl->pl_drag_pos;
264 if (off) {
265 for (i = 0; i < abs(off); i++) {
266 if (off < 0)
267 playlist_list_move_up(pl);
268 else
269 playlist_list_move_down(pl);
270
271 }
272 playlistwin_update_list();
273 }
274 pl->pl_drag_pos = nr;
275 }
276 }
277
278 static void
279 playlist_list_button_release_cb(GtkWidget * widget,
280 GdkEventButton * event,
281 PlayList_List * pl)
282 {
283 pl->pl_dragging = FALSE;
284 pl->pl_auto_drag_down = FALSE;
285 pl->pl_auto_drag_up = FALSE;
286 }
287
288 static void
289 playlist_list_draw_string(PlayList_List * pl,
290 PangoFontDescription * font,
291 gint line,
292 gint width,
293 const gchar * text,
294 guint ppos)
295 {
296
297 gint len;
298 gint len_pixmap;
299 guint plist_length_int;
300 PangoLayout *layout;
301 gchar *text_clipped;
302
303 REQUIRE_STATIC_LOCK(playlist);
304
305 len = g_utf8_strlen(text, -1);
306 len_pixmap = (width_approx_letters * len);
307
308 while (len_pixmap > width && len > 4) {
309 len--;
310 len_pixmap -= width_approx_letters;
311 }
312
313 /* FIXME: Is it possible to overflow text_clipped when text is non
314 UTF-8? - descender */
315
316 text_clipped = g_new0(gchar, strlen(text)+1);
317 g_utf8_strncpy(text_clipped, text, len);
318
319 if (cfg.show_numbers_in_pl) {
320 gchar *pos_string = g_strdup_printf("%d", ppos);
321 plist_length_int =
322 gint_count_digits(playlist_get_length_nolock()) + 1;
323
324 padding = plist_length_int;
325 padding = ((padding + 1) * width_approx_digits);
326
327 layout = gtk_widget_create_pango_layout(playlistwin, pos_string);
328 pango_layout_set_font_description(layout, playlist_list_font);
329 pango_layout_set_width(layout, plist_length_int * 100);
330
331 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
332 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc,
333 pl->pl_widget.x +
334 (width_approx_digits *
335 (-1 + plist_length_int - strlen(pos_string))) +
336 (width_approx_digits / 4),
337 pl->pl_widget.y + (line - 1) * pl->pl_fheight +
338 ascent + abs(descent), layout);
339 g_free(pos_string);
340 g_object_unref(layout);
341 }
342 else {
343 padding = 3;
344 }
345
346 layout = gtk_widget_create_pango_layout(playlistwin, text_clipped);
347
348 pango_layout_set_font_description(layout, playlist_list_font);
349 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc,
350 pl->pl_widget.x + padding + (width_approx_letters / 4),
351 pl->pl_widget.y + (line - 1) * pl->pl_fheight +
352 ascent + abs(descent), layout);
353
354 g_object_unref(layout);
355 g_free(text_clipped);
356 }
357
358 void
359 playlist_list_draw(Widget * w)
360 {
361 PlayList_List *pl = PLAYLIST_LIST(w);
362 GList *list;
363 GdkGC *gc;
364 GdkPixmap *obj;
365 PangoLayout *layout;
366 gchar *title;
367 gint width, height;
368 gint i, max_first;
369 guint padding, padding_dwidth, padding_plength;
370 guint max_time_len = 0;
371 gint queue_tailpadding = 0;
372
373 gchar tail[100];
374 gchar queuepos[255]; /* FIXME CRITICAL: Allows for a limited number of queue positions only */
375 gchar length[40];
376
377 gchar **frags;
378 gchar *frag0;
379
380 gint plw_w, plw_h;
381
382 GdkRectangle *playlist_rect;
383
384 gc = pl->pl_widget.gc;
385
386 width = pl->pl_widget.width;
387 height = pl->pl_widget.height;
388
389 obj = pl->pl_widget.parent;
390
391 gtk_window_get_size(GTK_WINDOW(playlistwin), &plw_w, &plw_h);
392
393 playlist_rect = g_new0(GdkRectangle, 1);
394
395 playlist_rect->x = 0;
396 playlist_rect->y = 0;
397 playlist_rect->width = plw_w - 17;
398 playlist_rect->height = plw_h - 36;
399
400 gdk_gc_set_clip_origin(gc, 31, 58);
401 gdk_gc_set_clip_rectangle(gc, playlist_rect);
402 gdk_gc_set_foreground(gc,
403 skin_get_color(bmp_active_skin,
404 SKIN_PLEDIT_NORMALBG));
405 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, pl->pl_widget.y,
406 width, height);
407
408 if (!playlist_list_font) {
409 g_critical("Couldn't open playlist font");
410 return;
411 }
412
413 pl->pl_fheight = (ascent + abs(descent));
414 pl->pl_num_visible = height / pl->pl_fheight;
415
416 max_first = playlist_get_length() - pl->pl_num_visible;
417 max_first = MAX(max_first, 0);
418
419 pl->pl_first = CLAMP(pl->pl_first, 0, max_first);
420
421 PLAYLIST_LOCK();
422 list = playlist_get();
423
424 for (i = 0; i < pl->pl_first; i++)
425 list = g_list_next(list);
426
427 for (i = pl->pl_first;
428 list && i < pl->pl_first + pl->pl_num_visible;
429 list = g_list_next(list), i++) {
430 gint pos;
431 PlaylistEntry *entry = list->data;
432
433 if (entry->selected) {
434 gdk_gc_set_foreground(gc,
435 skin_get_color(bmp_active_skin,
436 SKIN_PLEDIT_SELECTEDBG));
437 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x,
438 pl->pl_widget.y +
439 ((i - pl->pl_first) * pl->pl_fheight),
440 width, pl->pl_fheight);
441 }
442 if (i == playlist_get_position_nolock())
443 gdk_gc_set_foreground(gc,
444 skin_get_color(bmp_active_skin,
445 SKIN_PLEDIT_CURRENT));
446 else
447 gdk_gc_set_foreground(gc,
448 skin_get_color(bmp_active_skin,
449 SKIN_PLEDIT_NORMAL));
450
451 /* FIXME: entry->title should NEVER be NULL, and there should
452 NEVER be a need to do a UTF-8 conversion. Playlist title
453 strings should be kept properly. */
454
455 if (!entry->title) {
456 gchar *basename = g_path_get_basename(entry->filename);
457 title = filename_to_utf8(basename);
458 g_free(basename);
459 }
460 else
461 title = str_to_utf8(entry->title);
462
463 pos = playlist_get_queue_position(entry);
464
465 tail[0] = 0;
466 queuepos[0] = 0;
467 length[0] = 0;
468
469 if (pos != -1)
470 g_snprintf(queuepos, sizeof(queuepos), "%d", pos + 1);
471
472 if (entry->length != -1)
473 g_snprintf(length, sizeof(length), "%d:%-2.2d",
474 entry->length / 60000, (entry->length / 1000) % 60);
475
476 if (pos != -1 || entry->length != -1) {
477 gint x, y;
478 guint tail_width;
479 guint tail_len;
480
481 strncat(tail, length, sizeof(tail));
482 tail_len = strlen(tail);
483
484 max_time_len = MAX(max_time_len, tail_len);
485
486 /* FIXME: This is just an approximate alignment, maybe
487 something still fast, but exact could be done */
488
489 tail_width = width - (tail_len * width_approx_digits) +
490 (width_approx_digits_half) - 3;
491
492 if (i == playlist_get_position_nolock())
493 gdk_gc_set_foreground(gc,
494 skin_get_color(bmp_active_skin,
495 SKIN_PLEDIT_CURRENT));
496 else
497 gdk_gc_set_foreground(gc,
498 skin_get_color(bmp_active_skin,
499 SKIN_PLEDIT_NORMAL));
500 playlist_list_draw_string(pl, playlist_list_font,
501 i - pl->pl_first, tail_width, title,
502 i + 1);
503
504 x = pl->pl_widget.x + width - width_approx_digits * 2;
505 y = pl->pl_widget.y + ((i - pl->pl_first) -
506 1) * pl->pl_fheight + ascent;
507
508 if (entry->selected) {
509 gdk_gc_set_foreground(gc,
510 skin_get_color(bmp_active_skin,
511 SKIN_PLEDIT_SELECTEDBG));
512 }
513 else {
514 gdk_gc_set_foreground(gc,
515 skin_get_color(bmp_active_skin,
516 SKIN_PLEDIT_NORMALBG));
517 }
518
519 /* This isn't very cool, but i don't see a way to
520 * calculate row widths with Pango fast enough here */
521
522 gdk_draw_rectangle(obj, gc, TRUE,
523 pl->pl_widget.x + pl->pl_widget.width -
524 (width_approx_digits * 6),
525 y + abs(descent),
526 (width_approx_digits * 6), pl->pl_fheight - 1);
527
528 if (i == playlist_get_position_nolock())
529 gdk_gc_set_foreground(gc,
530 skin_get_color(bmp_active_skin,
531 SKIN_PLEDIT_CURRENT));
532 else
533 gdk_gc_set_foreground(gc,
534 skin_get_color(bmp_active_skin,
535 SKIN_PLEDIT_NORMAL));
536
537 frags = NULL;
538 frag0 = NULL;
539
540 if ( (strlen(tail)>0) && (tail != NULL) ) {
541
542 frags = g_strsplit(tail, ":", 0);
543 frag0 = g_strconcat(frags[0], ":", NULL);
544
545 layout = gtk_widget_create_pango_layout(playlistwin, frags[1]);
546 pango_layout_set_font_description(layout, playlist_list_font);
547 pango_layout_set_width(layout, tail_len * 100);
548 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
549 gdk_draw_layout(obj, gc, x - (0.5 * width_approx_digits),
550 y + abs(descent), layout);
551 g_object_unref(layout);
552
553 layout = gtk_widget_create_pango_layout(playlistwin, frag0);
554 pango_layout_set_font_description(layout, playlist_list_font);
555 pango_layout_set_width(layout, tail_len * 100);
556 pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
557 gdk_draw_layout(obj, gc, x - (0.75 * width_approx_digits),
558 y + abs(descent), layout);
559 g_object_unref(layout);
560
561 g_free(frag0);
562 g_strfreev(frags);
563
564 }
565
566 if (pos != -1) {
567
568 if (i == playlist_get_position_nolock())
569 gdk_gc_set_foreground(gc,
570 skin_get_color(bmp_active_skin,
571 SKIN_PLEDIT_CURRENT));
572 else
573 gdk_gc_set_foreground(gc,
574 skin_get_color(bmp_active_skin,
575 SKIN_PLEDIT_NORMAL));
576
577 /* DON'T remove the commented code yet please -- Milosz */
578
579 queue_tailpadding = 5;
580
581 gdk_draw_rectangle(obj, gc, FALSE,
582 x -
583 (((queue_tailpadding +
584 strlen(queuepos)) *
585 width_approx_digits) +
586 (width_approx_digits / 4)),
587 y + abs(descent) + 1,
588 (strlen(queuepos)) *
589 width_approx_digits +
590 (width_approx_digits / 2),
591 pl->pl_fheight - 2);
592
593 layout =
594 gtk_widget_create_pango_layout(playlistwin, queuepos);
595 pango_layout_set_font_description(layout, playlist_list_font);
596 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
597
598 gdk_draw_layout(obj, gc,
599 x -
600 ((queue_tailpadding +
601 strlen(queuepos)) * width_approx_digits),
602 y + abs(descent), layout);
603 g_object_unref(layout);
604
605 }
606
607
608
609 }
610 else {
611 if (i == playlist_get_position_nolock())
612 gdk_gc_set_foreground(gc,
613 skin_get_color(bmp_active_skin,
614 SKIN_PLEDIT_CURRENT));
615 else
616 gdk_gc_set_foreground(gc,
617 skin_get_color(bmp_active_skin,
618 SKIN_PLEDIT_NORMAL));
619
620 playlist_list_draw_string(pl, playlist_list_font,
621 i - pl->pl_first, width, title, i + 1);
622 }
623
624 g_free(title);
625 }
626
627
628 /*
629 * Drop target hovering over the playlist, so draw some hint where the
630 * drop will occur.
631 *
632 * This is (currently? unfixably?) broken when dragging files from Qt/KDE apps,
633 * probably due to DnD signaling problems (actually i have no clue).
634 *
635 */
636
637 if (pl->pl_drag_motion) {
638 guint pos, x, y, plx, ply, plength, lpadding;
639
640 if (cfg.show_numbers_in_pl) {
641 lpadding = gint_count_digits(playlist_get_length_nolock()) + 1;
642 lpadding = ((lpadding + 1) * width_approx_digits);
643 }
644 else {
645 lpadding = 3;
646 };
647
648 /* We already hold the mutex and have the playlist locked, so call
649 the non-locking function. */
650 plength = playlist_get_length_nolock();
651
652 x = pl->drag_motion_x;
653 y = pl->drag_motion_y;
654
655 plx = pl->pl_widget.x;
656 ply = pl->pl_widget.y;
657
658 if ((x > pl->pl_widget.x) && !(x > pl->pl_widget.width)) {
659
660 if ((y > pl->pl_widget.y)
661 && !(y > (pl->pl_widget.height + ply))) {
662
663 pos = ((y - ((Widget *) pl)->y) / pl->pl_fheight) +
664 pl->pl_first;
665
666 if (pos > (plength)) {
667 pos = plength;
668 }
669
670 gdk_gc_set_foreground(gc,
671 skin_get_color(bmp_active_skin,
672 SKIN_PLEDIT_CURRENT));
673
674 gdk_draw_line(obj, gc, pl->pl_widget.x,
675 /* pl->pl_widget.x + lpadding + (width_approx_letters / 4),*/
676 pl->pl_widget.y +
677 ((pos - pl->pl_first) * pl->pl_fheight),
678 pl->pl_widget.width + pl->pl_widget.x - 1,
679 pl->pl_widget.y +
680 ((pos - pl->pl_first) * pl->pl_fheight));
681 }
682
683 }
684
685 /* When dropping on the borders of the playlist, outside the text area,
686 * files get appended at the end of the list. Show that too.
687 */
688
689 if ((y < ply) || (y > pl->pl_widget.height + ply)) {
690 if ((y >= 0) || (y <= (pl->pl_widget.height + ply))) {
691 pos = plength;
692 gdk_gc_set_foreground(gc,
693 skin_get_color(bmp_active_skin,
694 SKIN_PLEDIT_CURRENT));
695
696 gdk_draw_line(obj, gc, pl->pl_widget.x,
697 /* pl->pl_widget.x + lpadding + (width_approx_letters / 4), */
698 pl->pl_widget.y +
699 ((pos - pl->pl_first) * pl->pl_fheight),
700 pl->pl_widget.width + pl->pl_widget.x - 1,
701 pl->pl_widget.y +
702 ((pos - pl->pl_first) * pl->pl_fheight));
703
704 }
705 }
706
707
708 }
709
710 gdk_gc_set_foreground(gc,
711 skin_get_color(bmp_active_skin,
712 SKIN_PLEDIT_NORMAL));
713
714 if (cfg.show_numbers_in_pl) {
715
716 padding_plength = playlist_get_length_nolock();
717
718 if (padding_plength == 0) {
719 padding_dwidth = 0;
720 }
721 else {
722 padding_dwidth = gint_count_digits(playlist_get_length_nolock());
723 }
724
725 padding =
726 (padding_dwidth *
727 width_approx_digits) + width_approx_digits;
728
729
730 /* For italic or oblique fonts we add another half of the
731 * approximate width */
732 if (has_slant)
733 padding += width_approx_digits_half;
734
735 gdk_draw_line(obj, gc,
736 pl->pl_widget.x + padding,
737 pl->pl_widget.y,
738 pl->pl_widget.x + padding,
739 (pl->pl_widget.y + pl->pl_widget.height));
740 }
741
742 playlist_rect->x = 0;
743 playlist_rect->y = 0;
744 playlist_rect->width = plw_w;
745 playlist_rect->height = plw_h;
746
747 gdk_gc_set_clip_origin(gc, 0, 0);
748 gdk_gc_set_clip_rectangle(gc, NULL);
749
750 PLAYLIST_UNLOCK();
751 }
752
753
754 PlayList_List *
755 create_playlist_list(GList ** wlist,
756 GdkPixmap * parent,
757 GdkGC * gc,
758 gint x, gint y,
759 gint w, gint h)
760 {
761 PlayList_List *pl;
762
763 pl = g_new0(PlayList_List, 1);
764 widget_init(&pl->pl_widget, parent, gc, x, y, w, h, TRUE);
765
766 pl->pl_widget.button_press_cb =
767 (WidgetButtonPressFunc) playlist_list_button_press_cb;
768 pl->pl_widget.button_release_cb =
769 (WidgetButtonReleaseFunc) playlist_list_button_release_cb;
770 pl->pl_widget.motion_cb = (WidgetMotionFunc) playlist_list_motion_cb;
771 pl->pl_widget.draw = playlist_list_draw;
772
773 pl->pl_prev_selected = -1;
774 pl->pl_prev_min = -1;
775 pl->pl_prev_max = -1;
776
777 widget_list_add(wlist, WIDGET(pl));
778
779 return pl;
780 }
781
782 void
783 playlist_list_set_font(const gchar * font)
784 {
785
786 /* Welcome to bad hack central 2k3 */
787
788 gchar *font_lower;
789 gint width_temp;
790 gint width_temp_0;
791
792 playlist_list_font = pango_font_description_from_string(font);
793
794 text_get_extents(font,
795 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ",
796 &width_approx_letters, NULL, &ascent, &descent);
797
798 width_approx_letters = (width_approx_letters / 53);
799
800 /* Experimental: We don't weigh the 1 into total because it's width is almost always
801 * very different from the rest
802 */
803 text_get_extents(font, "023456789", &width_approx_digits, NULL, NULL,
804 NULL);
805 width_approx_digits = (width_approx_digits / 9);
806
807 /* Precache some often used calculations */
808 width_approx_digits_half = width_approx_digits / 2;
809
810 /* FIXME: We assume that any other number is broader than the "1" */
811 text_get_extents(font, "1", &width_temp, NULL, NULL, NULL);
812 text_get_extents(font, "2", &width_temp_0, NULL, NULL, NULL);
813
814 if (abs(width_temp_0 - width_temp) < 2) {
815 width_delta_digit_one = 0;
816 }
817 else {
818 width_delta_digit_one = ((width_temp_0 - width_temp) / 2) + 2;
819 }
820
821 text_get_extents(font, ":", &width_colon, NULL, NULL, NULL);
822 width_colon_third = width_colon / 4;
823
824 font_lower = g_utf8_strdown(font, strlen(font));
825 /* This doesn't take any i18n into account, but i think there is none with TTF fonts
826 * FIXME: This can probably be retrieved trough Pango too
827 */
828 has_slant = g_strstr_len(font_lower, strlen(font_lower), "oblique")
829 || g_strstr_len(font_lower, strlen(font_lower), "italic");
830
831 g_free(font_lower);
832 }