Mercurial > audlegacy
annotate audacious/playlist_list.c @ 881:dd6fdc1ac5cc trunk
[svn] - Update NEWS
author | nenolod |
---|---|
date | Sat, 25 Mar 2006 17:07:37 -0800 |
parents | 45ec63505a4e |
children | 5e30566ad776 |
rev | line source |
---|---|
0 | 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" | |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
512
diff
changeset
|
43 #include "playback.h" |
0 | 44 #include "playlist.h" |
383 | 45 #include "ui_playlist.h" |
0 | 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 { | |
324
fbafca56b6a8
[svn] playlist window truncation fixes provided by external contributor: Tim Yamin <plasmaroo -at- gentoo.org>.
nenolod
parents:
284
diff
changeset
|
296 guint plist_length_int; |
0 | 297 |
298 PangoLayout *layout; | |
299 | |
300 REQUIRE_STATIC_LOCK(playlist); | |
301 | |
302 if (cfg.show_numbers_in_pl) { | |
303 gchar *pos_string = g_strdup_printf("%d", ppos); | |
304 plist_length_int = | |
305 gint_count_digits(playlist_get_length_nolock()) + 1; | |
306 | |
307 padding = plist_length_int; | |
308 padding = ((padding + 1) * width_approx_digits); | |
309 | |
310 layout = gtk_widget_create_pango_layout(playlistwin, pos_string); | |
311 pango_layout_set_font_description(layout, playlist_list_font); | |
312 pango_layout_set_width(layout, plist_length_int * 100); | |
313 | |
314 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); | |
315 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, | |
316 pl->pl_widget.x + | |
317 (width_approx_digits * | |
318 (-1 + plist_length_int - strlen(pos_string))) + | |
319 (width_approx_digits / 4), | |
320 pl->pl_widget.y + (line - 1) * pl->pl_fheight + | |
321 ascent + abs(descent), layout); | |
322 g_free(pos_string); | |
323 g_object_unref(layout); | |
324 } | |
325 else { | |
326 padding = 3; | |
327 } | |
328 | |
324
fbafca56b6a8
[svn] playlist window truncation fixes provided by external contributor: Tim Yamin <plasmaroo -at- gentoo.org>.
nenolod
parents:
284
diff
changeset
|
329 width -= padding; |
fbafca56b6a8
[svn] playlist window truncation fixes provided by external contributor: Tim Yamin <plasmaroo -at- gentoo.org>.
nenolod
parents:
284
diff
changeset
|
330 |
326 | 331 layout = gtk_widget_create_pango_layout(playlistwin, text); |
0 | 332 |
333 pango_layout_set_font_description(layout, playlist_list_font); | |
326 | 334 pango_layout_set_width(layout, width * PANGO_SCALE); |
335 pango_layout_set_single_paragraph_mode(layout, TRUE); | |
336 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); | |
0 | 337 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, |
338 pl->pl_widget.x + padding + (width_approx_letters / 4), | |
339 pl->pl_widget.y + (line - 1) * pl->pl_fheight + | |
340 ascent + abs(descent), layout); | |
341 | |
342 g_object_unref(layout); | |
343 } | |
344 | |
345 void | |
346 playlist_list_draw(Widget * w) | |
347 { | |
348 PlayList_List *pl = PLAYLIST_LIST(w); | |
349 GList *list; | |
350 GdkGC *gc; | |
351 GdkPixmap *obj; | |
352 PangoLayout *layout; | |
353 gchar *title; | |
354 gint width, height; | |
355 gint i, max_first; | |
356 guint padding, padding_dwidth, padding_plength; | |
357 guint max_time_len = 0; | |
358 gint queue_tailpadding = 0; | |
701
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
625
diff
changeset
|
359 gint tpadding; |
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
625
diff
changeset
|
360 gsize tpadding_dwidth = 0; |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
361 gint x, y; |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
362 guint tail_width; |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
363 guint tail_len; |
0 | 364 |
365 gchar tail[100]; | |
782
4c7ee8f64d9b
[svn] untag a critical fixme as it was actually deadchip smoking some craq
nenolod
parents:
736
diff
changeset
|
366 gchar queuepos[255]; |
0 | 367 gchar length[40]; |
368 | |
369 gchar **frags; | |
370 gchar *frag0; | |
371 | |
372 gint plw_w, plw_h; | |
373 | |
374 GdkRectangle *playlist_rect; | |
375 | |
376 gc = pl->pl_widget.gc; | |
377 | |
378 width = pl->pl_widget.width; | |
379 height = pl->pl_widget.height; | |
380 | |
381 obj = pl->pl_widget.parent; | |
382 | |
383 gtk_window_get_size(GTK_WINDOW(playlistwin), &plw_w, &plw_h); | |
384 | |
385 playlist_rect = g_new0(GdkRectangle, 1); | |
386 | |
387 playlist_rect->x = 0; | |
388 playlist_rect->y = 0; | |
389 playlist_rect->width = plw_w - 17; | |
390 playlist_rect->height = plw_h - 36; | |
391 | |
392 gdk_gc_set_clip_origin(gc, 31, 58); | |
393 gdk_gc_set_clip_rectangle(gc, playlist_rect); | |
394 gdk_gc_set_foreground(gc, | |
395 skin_get_color(bmp_active_skin, | |
396 SKIN_PLEDIT_NORMALBG)); | |
397 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, pl->pl_widget.y, | |
398 width, height); | |
399 | |
400 if (!playlist_list_font) { | |
401 g_critical("Couldn't open playlist font"); | |
402 return; | |
403 } | |
404 | |
405 pl->pl_fheight = (ascent + abs(descent)); | |
406 pl->pl_num_visible = height / pl->pl_fheight; | |
407 | |
408 max_first = playlist_get_length() - pl->pl_num_visible; | |
409 max_first = MAX(max_first, 0); | |
410 | |
411 pl->pl_first = CLAMP(pl->pl_first, 0, max_first); | |
412 | |
413 PLAYLIST_LOCK(); | |
414 list = playlist_get(); | |
610
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
415 list = g_list_nth(list, pl->pl_first); |
0 | 416 |
610
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
417 /* It sucks having to run the iteration twice but this is the only |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
418 way you can reliably get the maximum width so we can get our |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
419 playlist nice and aligned... -- plasmaroo */ |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
420 |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
421 for (i = pl->pl_first; |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
422 list && i < pl->pl_first + pl->pl_num_visible; |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
423 list = g_list_next(list), i++) { |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
424 PlaylistEntry *entry = list->data; |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
425 |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
426 if (entry->length != -1) |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
427 { |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
428 g_snprintf(length, sizeof(length), "%d:%-2.2d", |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
429 entry->length / 60000, (entry->length / 1000) % 60); |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
430 tpadding_dwidth = MAX(tpadding_dwidth, strlen(length)); |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
431 } |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
432 } |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
433 |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
434 /* Reset */ |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
435 list = playlist_get(); |
d056380ea0b3
[svn] playlist_list widget improvements via plasmaroo
nenolod
parents:
538
diff
changeset
|
436 list = g_list_nth(list, pl->pl_first); |
0 | 437 |
438 for (i = pl->pl_first; | |
439 list && i < pl->pl_first + pl->pl_num_visible; | |
440 list = g_list_next(list), i++) { | |
441 gint pos; | |
442 PlaylistEntry *entry = list->data; | |
443 | |
444 if (entry->selected) { | |
445 gdk_gc_set_foreground(gc, | |
446 skin_get_color(bmp_active_skin, | |
447 SKIN_PLEDIT_SELECTEDBG)); | |
448 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, | |
449 pl->pl_widget.y + | |
450 ((i - pl->pl_first) * pl->pl_fheight), | |
451 width, pl->pl_fheight); | |
452 } | |
453 if (i == playlist_get_position_nolock()) | |
454 gdk_gc_set_foreground(gc, | |
455 skin_get_color(bmp_active_skin, | |
456 SKIN_PLEDIT_CURRENT)); | |
457 else | |
458 gdk_gc_set_foreground(gc, | |
459 skin_get_color(bmp_active_skin, | |
460 SKIN_PLEDIT_NORMAL)); | |
461 | |
462 /* FIXME: entry->title should NEVER be NULL, and there should | |
463 NEVER be a need to do a UTF-8 conversion. Playlist title | |
464 strings should be kept properly. */ | |
465 | |
466 if (!entry->title) { | |
467 gchar *basename = g_path_get_basename(entry->filename); | |
468 title = filename_to_utf8(basename); | |
469 g_free(basename); | |
470 } | |
471 else | |
472 title = str_to_utf8(entry->title); | |
473 | |
474 pos = playlist_get_queue_position(entry); | |
475 | |
476 tail[0] = 0; | |
477 queuepos[0] = 0; | |
478 length[0] = 0; | |
479 | |
480 if (pos != -1) | |
481 g_snprintf(queuepos, sizeof(queuepos), "%d", pos + 1); | |
482 | |
483 if (entry->length != -1) | |
506
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
484 { |
0 | 485 g_snprintf(length, sizeof(length), "%d:%-2.2d", |
486 entry->length / 60000, (entry->length / 1000) % 60); | |
506
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
487 } |
0 | 488 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
489 strncat(tail, length, sizeof(tail)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
490 tail_len = strlen(tail); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
491 |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
492 max_time_len = MAX(max_time_len, tail_len); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
493 |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
494 if (pos != -1) |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
495 tail_width = width - (width_approx_digits * (tpadding_dwidth + strlen(queuepos) + 4)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
496 else |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
497 tail_width = width - (width_approx_digits * (tpadding_dwidth + 2.5)); |
0 | 498 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
499 if (i == playlist_get_position_nolock()) |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
500 gdk_gc_set_foreground(gc, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
501 skin_get_color(bmp_active_skin, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
502 SKIN_PLEDIT_CURRENT)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
503 else |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
504 gdk_gc_set_foreground(gc, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
505 skin_get_color(bmp_active_skin, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
506 SKIN_PLEDIT_NORMAL)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
507 playlist_list_draw_string(pl, playlist_list_font, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
508 i - pl->pl_first, tail_width, title, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
509 i + 1); |
0 | 510 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
511 x = pl->pl_widget.x + width - width_approx_digits * 2; |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
512 y = pl->pl_widget.y + ((i - pl->pl_first) - |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
513 1) * pl->pl_fheight + ascent; |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
514 |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
515 if (entry->selected) { |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
516 gdk_gc_set_foreground(gc, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
517 skin_get_color(bmp_active_skin, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
518 SKIN_PLEDIT_SELECTEDBG)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
519 } |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
520 else { |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
521 gdk_gc_set_foreground(gc, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
522 skin_get_color(bmp_active_skin, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
523 SKIN_PLEDIT_NORMALBG)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
524 } |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
525 |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
526 /* This isn't very cool, but i don't see a way to |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
527 * calculate row widths with Pango fast enough here */ |
0 | 528 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
529 gdk_draw_rectangle(obj, gc, TRUE, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
530 pl->pl_widget.x + pl->pl_widget.width - |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
531 (width_approx_digits * 6), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
532 y + abs(descent), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
533 (width_approx_digits * 6), pl->pl_fheight - 1); |
0 | 534 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
535 if (i == playlist_get_position_nolock()) |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
536 gdk_gc_set_foreground(gc, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
537 skin_get_color(bmp_active_skin, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
538 SKIN_PLEDIT_CURRENT)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
539 else |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
540 gdk_gc_set_foreground(gc, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
541 skin_get_color(bmp_active_skin, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
542 SKIN_PLEDIT_NORMAL)); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
543 |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
544 frags = NULL; |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
545 frag0 = NULL; |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
546 |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
547 if ((strlen(tail) > 0) && (tail != NULL)) { |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
548 frags = g_strsplit(tail, ":", 0); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
549 frag0 = g_strconcat(frags[0], ":", NULL); |
0 | 550 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
551 layout = gtk_widget_create_pango_layout(playlistwin, frags[1]); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
552 pango_layout_set_font_description(layout, playlist_list_font); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
553 pango_layout_set_width(layout, tail_len * 100); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
554 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
555 gdk_draw_layout(obj, gc, x - (0.5 * width_approx_digits), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
556 y + abs(descent), layout); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
557 g_object_unref(layout); |
0 | 558 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
559 layout = gtk_widget_create_pango_layout(playlistwin, frag0); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
560 pango_layout_set_font_description(layout, playlist_list_font); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
561 pango_layout_set_width(layout, tail_len * 100); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
562 pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
563 gdk_draw_layout(obj, gc, x - (0.75 * width_approx_digits), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
564 y + abs(descent), layout); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
565 g_object_unref(layout); |
0 | 566 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
567 g_free(frag0); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
568 g_strfreev(frags); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
569 } |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
570 |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
571 if (pos != -1) { |
0 | 572 |
573 if (i == playlist_get_position_nolock()) | |
574 gdk_gc_set_foreground(gc, | |
575 skin_get_color(bmp_active_skin, | |
576 SKIN_PLEDIT_CURRENT)); | |
577 else | |
578 gdk_gc_set_foreground(gc, | |
579 skin_get_color(bmp_active_skin, | |
580 SKIN_PLEDIT_NORMAL)); | |
581 | |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
582 /* DON'T remove the commented code yet please -- Milosz */ |
0 | 583 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
584 queue_tailpadding = 5; |
0 | 585 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
586 gdk_draw_rectangle(obj, gc, FALSE, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
587 x - |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
588 (((queue_tailpadding + |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
589 strlen(queuepos)) * |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
590 width_approx_digits) + |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
591 (width_approx_digits / 4)), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
592 y + abs(descent), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
593 (strlen(queuepos)) * |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
594 width_approx_digits + |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
595 (width_approx_digits / 2), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
596 pl->pl_fheight - 2); |
0 | 597 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
598 layout = |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
599 gtk_widget_create_pango_layout(playlistwin, queuepos); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
600 pango_layout_set_font_description(layout, playlist_list_font); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
601 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); |
0 | 602 |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
603 gdk_draw_layout(obj, gc, |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
604 x - |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
605 ((queue_tailpadding + |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
606 strlen(queuepos)) * width_approx_digits) + |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
607 (width_approx_digits / 4), |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
608 y + abs(descent), layout); |
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
609 g_object_unref(layout); |
0 | 610 } |
611 | |
612 g_free(title); | |
613 } | |
614 | |
615 | |
616 /* | |
617 * Drop target hovering over the playlist, so draw some hint where the | |
618 * drop will occur. | |
619 * | |
620 * This is (currently? unfixably?) broken when dragging files from Qt/KDE apps, | |
621 * probably due to DnD signaling problems (actually i have no clue). | |
622 * | |
623 */ | |
624 | |
625 if (pl->pl_drag_motion) { | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
610
diff
changeset
|
626 guint pos, plength, lpadding; |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
610
diff
changeset
|
627 gint x, y, plx, ply; |
0 | 628 |
629 if (cfg.show_numbers_in_pl) { | |
630 lpadding = gint_count_digits(playlist_get_length_nolock()) + 1; | |
631 lpadding = ((lpadding + 1) * width_approx_digits); | |
632 } | |
633 else { | |
634 lpadding = 3; | |
635 }; | |
636 | |
637 /* We already hold the mutex and have the playlist locked, so call | |
638 the non-locking function. */ | |
639 plength = playlist_get_length_nolock(); | |
640 | |
641 x = pl->drag_motion_x; | |
642 y = pl->drag_motion_y; | |
643 | |
644 plx = pl->pl_widget.x; | |
645 ply = pl->pl_widget.y; | |
646 | |
647 if ((x > pl->pl_widget.x) && !(x > pl->pl_widget.width)) { | |
648 | |
649 if ((y > pl->pl_widget.y) | |
650 && !(y > (pl->pl_widget.height + ply))) { | |
651 | |
652 pos = ((y - ((Widget *) pl)->y) / pl->pl_fheight) + | |
653 pl->pl_first; | |
654 | |
655 if (pos > (plength)) { | |
656 pos = plength; | |
657 } | |
658 | |
659 gdk_gc_set_foreground(gc, | |
660 skin_get_color(bmp_active_skin, | |
661 SKIN_PLEDIT_CURRENT)); | |
662 | |
663 gdk_draw_line(obj, gc, pl->pl_widget.x, | |
735 | 664 pl->pl_widget.y + ((pos - pl->pl_first) * pl->pl_fheight), |
0 | 665 pl->pl_widget.width + pl->pl_widget.x - 1, |
666 pl->pl_widget.y + | |
667 ((pos - pl->pl_first) * pl->pl_fheight)); | |
668 } | |
669 | |
670 } | |
671 | |
672 /* When dropping on the borders of the playlist, outside the text area, | |
673 * files get appended at the end of the list. Show that too. | |
674 */ | |
675 | |
676 if ((y < ply) || (y > pl->pl_widget.height + ply)) { | |
677 if ((y >= 0) || (y <= (pl->pl_widget.height + ply))) { | |
678 pos = plength; | |
679 gdk_gc_set_foreground(gc, | |
680 skin_get_color(bmp_active_skin, | |
681 SKIN_PLEDIT_CURRENT)); | |
682 | |
683 gdk_draw_line(obj, gc, pl->pl_widget.x, | |
736 | 684 pl->pl_widget.y + |
685 ((pos - pl->pl_first) * pl->pl_fheight), | |
0 | 686 pl->pl_widget.width + pl->pl_widget.x - 1, |
687 pl->pl_widget.y + | |
688 ((pos - pl->pl_first) * pl->pl_fheight)); | |
689 | |
690 } | |
691 } | |
692 } | |
693 | |
694 gdk_gc_set_foreground(gc, | |
695 skin_get_color(bmp_active_skin, | |
696 SKIN_PLEDIT_NORMAL)); | |
697 | |
698 if (cfg.show_numbers_in_pl) { | |
699 | |
700 padding_plength = playlist_get_length_nolock(); | |
701 | |
702 if (padding_plength == 0) { | |
703 padding_dwidth = 0; | |
704 } | |
705 else { | |
706 padding_dwidth = gint_count_digits(playlist_get_length_nolock()); | |
707 } | |
708 | |
709 padding = | |
710 (padding_dwidth * | |
711 width_approx_digits) + width_approx_digits; | |
712 | |
713 | |
714 /* For italic or oblique fonts we add another half of the | |
715 * approximate width */ | |
716 if (has_slant) | |
717 padding += width_approx_digits_half; | |
718 | |
719 gdk_draw_line(obj, gc, | |
720 pl->pl_widget.x + padding, | |
721 pl->pl_widget.y, | |
722 pl->pl_widget.x + padding, | |
723 (pl->pl_widget.y + pl->pl_widget.height)); | |
724 } | |
725 | |
506
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
726 if (tpadding_dwidth != 0) |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
727 { |
828
45ec63505a4e
[svn] - improvements to the playlist list control, via nhjm
nenolod
parents:
813
diff
changeset
|
728 tpadding = (tpadding_dwidth * width_approx_digits) + (width_approx_digits * 1.5); |
506
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
729 |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
730 if (has_slant) |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
731 tpadding += width_approx_digits_half; |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
732 |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
733 gdk_draw_line(obj, gc, |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
734 pl->pl_widget.x + pl->pl_widget.width - tpadding, |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
735 pl->pl_widget.y, |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
736 pl->pl_widget.x + pl->pl_widget.width - tpadding, |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
737 (pl->pl_widget.y + pl->pl_widget.height)); |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
738 |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
739 } |
4d3b74821345
[svn] Add a line between the time and the track name.
nenolod
parents:
460
diff
changeset
|
740 |
0 | 741 gdk_gc_set_clip_origin(gc, 0, 0); |
742 gdk_gc_set_clip_rectangle(gc, NULL); | |
743 | |
744 PLAYLIST_UNLOCK(); | |
813
c8cf439179b8
[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents:
797
diff
changeset
|
745 |
c8cf439179b8
[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents:
797
diff
changeset
|
746 g_free(playlist_rect); |
0 | 747 } |
748 | |
749 | |
750 PlayList_List * | |
751 create_playlist_list(GList ** wlist, | |
752 GdkPixmap * parent, | |
753 GdkGC * gc, | |
754 gint x, gint y, | |
755 gint w, gint h) | |
756 { | |
757 PlayList_List *pl; | |
758 | |
759 pl = g_new0(PlayList_List, 1); | |
760 widget_init(&pl->pl_widget, parent, gc, x, y, w, h, TRUE); | |
761 | |
762 pl->pl_widget.button_press_cb = | |
763 (WidgetButtonPressFunc) playlist_list_button_press_cb; | |
764 pl->pl_widget.button_release_cb = | |
765 (WidgetButtonReleaseFunc) playlist_list_button_release_cb; | |
766 pl->pl_widget.motion_cb = (WidgetMotionFunc) playlist_list_motion_cb; | |
767 pl->pl_widget.draw = playlist_list_draw; | |
768 | |
769 pl->pl_prev_selected = -1; | |
770 pl->pl_prev_min = -1; | |
771 pl->pl_prev_max = -1; | |
772 | |
773 widget_list_add(wlist, WIDGET(pl)); | |
774 | |
775 return pl; | |
776 } | |
777 | |
778 void | |
779 playlist_list_set_font(const gchar * font) | |
780 { | |
781 | |
782 /* Welcome to bad hack central 2k3 */ | |
783 | |
784 gchar *font_lower; | |
785 gint width_temp; | |
786 gint width_temp_0; | |
787 | |
788 playlist_list_font = pango_font_description_from_string(font); | |
789 | |
790 text_get_extents(font, | |
791 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ", | |
792 &width_approx_letters, NULL, &ascent, &descent); | |
793 | |
794 width_approx_letters = (width_approx_letters / 53); | |
795 | |
796 /* Experimental: We don't weigh the 1 into total because it's width is almost always | |
797 * very different from the rest | |
798 */ | |
799 text_get_extents(font, "023456789", &width_approx_digits, NULL, NULL, | |
800 NULL); | |
801 width_approx_digits = (width_approx_digits / 9); | |
802 | |
803 /* Precache some often used calculations */ | |
804 width_approx_digits_half = width_approx_digits / 2; | |
805 | |
806 /* FIXME: We assume that any other number is broader than the "1" */ | |
807 text_get_extents(font, "1", &width_temp, NULL, NULL, NULL); | |
808 text_get_extents(font, "2", &width_temp_0, NULL, NULL, NULL); | |
809 | |
810 if (abs(width_temp_0 - width_temp) < 2) { | |
811 width_delta_digit_one = 0; | |
812 } | |
813 else { | |
814 width_delta_digit_one = ((width_temp_0 - width_temp) / 2) + 2; | |
815 } | |
816 | |
817 text_get_extents(font, ":", &width_colon, NULL, NULL, NULL); | |
818 width_colon_third = width_colon / 4; | |
819 | |
820 font_lower = g_utf8_strdown(font, strlen(font)); | |
821 /* This doesn't take any i18n into account, but i think there is none with TTF fonts | |
822 * FIXME: This can probably be retrieved trough Pango too | |
823 */ | |
824 has_slant = g_strstr_len(font_lower, strlen(font_lower), "oblique") | |
825 || g_strstr_len(font_lower, strlen(font_lower), "italic"); | |
826 | |
827 g_free(font_lower); | |
828 } |