Mercurial > audlegacy
annotate src/audacious/widgets/playlist_list.c @ 2865:d226b83fa329 trunk
BSD relicensing (pass 6).
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sat, 23 Jun 2007 22:51:13 -0500 |
parents | d992765e15ee |
children | 41d3854f3625 |
rev | line source |
---|---|
2313 | 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" | |
2385
ab2b1b6f6179
[svn] - add missing inclusion of strings.h where necessary, do not export main.h and export strings.h
giacomo
parents:
2361
diff
changeset
|
46 #include "strings.h" |
2313 | 47 #include "playback.h" |
48 #include "playlist.h" | |
49 #include "ui_playlist.h" | |
50 #include "util.h" | |
51 | |
52 #include "debug.h" | |
53 | |
54 static PangoFontDescription *playlist_list_font = NULL; | |
55 static gint ascent, descent, width_delta_digit_one; | |
56 static gboolean has_slant; | |
57 static guint padding; | |
58 | |
59 /* FIXME: the following globals should not be needed. */ | |
60 static gint width_approx_letters; | |
61 static gint width_colon, width_colon_third; | |
62 static gint width_approx_digits, width_approx_digits_half; | |
63 | |
64 void playlist_list_draw(Widget * w); | |
65 | |
66 static gboolean | |
67 playlist_list_auto_drag_down_func(gpointer data) | |
68 { | |
69 PlayList_List *pl = data; | |
70 | |
71 if (pl->pl_auto_drag_down) { | |
72 playlist_list_move_down(pl); | |
73 pl->pl_first++; | |
74 playlistwin_update_list(playlist_get_active()); | |
75 return TRUE; | |
76 } | |
77 return FALSE; | |
78 } | |
79 | |
80 static gboolean | |
81 playlist_list_auto_drag_up_func(gpointer data) | |
82 { | |
83 PlayList_List *pl = data; | |
84 | |
85 if (pl->pl_auto_drag_up) { | |
86 playlist_list_move_up(pl); | |
87 pl->pl_first--; | |
88 playlistwin_update_list(playlist_get_active()); | |
89 return TRUE; | |
90 | |
91 } | |
92 return FALSE; | |
93 } | |
94 | |
95 void | |
96 playlist_list_move_up(PlayList_List * pl) | |
97 { | |
98 GList *list; | |
99 Playlist *playlist = playlist_get_active(); | |
100 | |
101 if (!playlist) | |
102 return; | |
103 | |
104 PLAYLIST_LOCK(playlist->mutex); | |
105 if ((list = playlist->entries) == NULL) { | |
106 PLAYLIST_UNLOCK(playlist->mutex); | |
107 return; | |
108 } | |
109 if (PLAYLIST_ENTRY(list->data)->selected) { | |
110 /* We are at the top */ | |
111 PLAYLIST_UNLOCK(playlist->mutex); | |
112 return; | |
113 } | |
114 while (list) { | |
115 if (PLAYLIST_ENTRY(list->data)->selected) | |
116 glist_moveup(list); | |
117 list = g_list_next(list); | |
118 } | |
119 PLAYLIST_UNLOCK(playlist->mutex); | |
120 if (pl->pl_prev_selected != -1) | |
121 pl->pl_prev_selected--; | |
122 if (pl->pl_prev_min != -1) | |
123 pl->pl_prev_min--; | |
124 if (pl->pl_prev_max != -1) | |
125 pl->pl_prev_max--; | |
126 } | |
127 | |
128 void | |
129 playlist_list_move_down(PlayList_List * pl) | |
130 { | |
131 GList *list; | |
132 Playlist *playlist = playlist_get_active(); | |
133 | |
134 if (!playlist) | |
135 return; | |
136 | |
137 PLAYLIST_LOCK(playlist->mutex); | |
138 | |
139 if (!(list = g_list_last(playlist->entries))) { | |
140 PLAYLIST_UNLOCK(playlist->mutex); | |
141 return; | |
142 } | |
143 | |
144 if (PLAYLIST_ENTRY(list->data)->selected) { | |
145 /* We are at the bottom */ | |
146 PLAYLIST_UNLOCK(playlist->mutex); | |
147 return; | |
148 } | |
149 | |
150 while (list) { | |
151 if (PLAYLIST_ENTRY(list->data)->selected) | |
152 glist_movedown(list); | |
153 list = g_list_previous(list); | |
154 } | |
155 | |
156 PLAYLIST_UNLOCK(playlist->mutex); | |
157 | |
158 if (pl->pl_prev_selected != -1) | |
159 pl->pl_prev_selected++; | |
160 if (pl->pl_prev_min != -1) | |
161 pl->pl_prev_min++; | |
162 if (pl->pl_prev_max != -1) | |
163 pl->pl_prev_max++; | |
164 } | |
165 | |
166 static void | |
167 playlist_list_button_press_cb(GtkWidget * widget, | |
168 GdkEventButton * event, | |
169 PlayList_List * pl) | |
170 { | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
171 gint nr; |
2313 | 172 Playlist *playlist = playlist_get_active(); |
173 | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
174 nr = playlist_list_get_playlist_position(pl, event->x, event->y); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
175 if (nr == -1) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
176 return; |
2313 | 177 |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
178 if (event->button == 3) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
179 { |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
180 GList* selection = playlist_get_selected(playlist); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
181 if (g_list_find(selection, GINT_TO_POINTER(nr)) == NULL) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
182 { |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
183 playlist_select_all(playlist, FALSE); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
184 playlist_select_range(playlist, nr, nr, TRUE); |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
185 } |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
186 } |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
187 else if (event->button == 1) |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
188 { |
2313 | 189 if (!(event->state & GDK_CONTROL_MASK)) |
190 playlist_select_all(playlist, FALSE); | |
191 | |
192 if (event->state & GDK_SHIFT_MASK && pl->pl_prev_selected != -1) { | |
193 playlist_select_range(playlist, pl->pl_prev_selected, nr, TRUE); | |
194 pl->pl_prev_min = pl->pl_prev_selected; | |
195 pl->pl_prev_max = nr; | |
196 pl->pl_drag_pos = nr - pl->pl_first; | |
197 } | |
198 else { | |
199 if (playlist_select_invert(playlist, nr)) { | |
200 if (event->state & GDK_CONTROL_MASK) { | |
201 if (pl->pl_prev_min == -1) { | |
202 pl->pl_prev_min = pl->pl_prev_selected; | |
203 pl->pl_prev_max = pl->pl_prev_selected; | |
204 } | |
205 if (nr < pl->pl_prev_min) | |
206 pl->pl_prev_min = nr; | |
207 else if (nr > pl->pl_prev_max) | |
208 pl->pl_prev_max = nr; | |
209 } | |
210 else | |
211 pl->pl_prev_min = -1; | |
212 pl->pl_prev_selected = nr; | |
213 pl->pl_drag_pos = nr - pl->pl_first; | |
214 } | |
215 } | |
216 if (event->type == GDK_2BUTTON_PRESS) { | |
217 /* | |
218 * Ungrab the pointer to prevent us from | |
219 * hanging on to it during the sometimes slow | |
220 * playback_initiate(). | |
221 */ | |
222 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
223 gdk_flush(); | |
224 playlist_set_position(playlist, nr); | |
225 if (!playback_get_playing()) | |
226 playback_initiate(); | |
227 } | |
228 | |
229 pl->pl_dragging = TRUE; | |
230 } | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
231 |
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
232 playlistwin_update_list(playlist); |
2313 | 233 } |
234 | |
235 gint | |
236 playlist_list_get_playlist_position(PlayList_List * pl, | |
237 gint x, | |
238 gint y) | |
239 { | |
240 gint iy, length; | |
241 gint ret; | |
242 Playlist *playlist = playlist_get_active(); | |
243 | |
244 if (!widget_contains(WIDGET(pl), x, y) || !pl->pl_fheight) | |
245 return -1; | |
246 | |
247 if ((length = playlist_get_length(playlist)) == 0) | |
248 return -1; | |
249 iy = y - pl->pl_widget.y; | |
250 | |
251 ret = (iy / pl->pl_fheight) + pl->pl_first; | |
252 | |
2356
4b2c7d9523e7
[svn] right-clicking on playlist entry automatically selects the entry if it was unselected before, closes #728
mf0102
parents:
2313
diff
changeset
|
253 if (ret > length - 1) |
2313 | 254 ret = -1; |
255 | |
256 return ret; | |
257 } | |
258 | |
259 static void | |
260 playlist_list_motion_cb(GtkWidget * widget, | |
261 GdkEventMotion * event, | |
262 PlayList_List * pl) | |
263 { | |
264 gint nr, y, off, i; | |
265 | |
266 if (pl->pl_dragging) { | |
267 y = event->y - pl->pl_widget.y; | |
268 nr = (y / pl->pl_fheight); | |
269 if (nr < 0) { | |
270 nr = 0; | |
271 if (!pl->pl_auto_drag_up) { | |
272 pl->pl_auto_drag_up = TRUE; | |
273 pl->pl_auto_drag_up_tag = | |
274 g_timeout_add(100, playlist_list_auto_drag_up_func, pl); | |
275 } | |
276 } | |
277 else if (pl->pl_auto_drag_up) | |
278 pl->pl_auto_drag_up = FALSE; | |
279 | |
280 if (nr >= pl->pl_num_visible) { | |
281 nr = pl->pl_num_visible - 1; | |
282 if (!pl->pl_auto_drag_down) { | |
283 pl->pl_auto_drag_down = TRUE; | |
284 pl->pl_auto_drag_down_tag = | |
285 g_timeout_add(100, playlist_list_auto_drag_down_func, | |
286 pl); | |
287 } | |
288 } | |
289 else if (pl->pl_auto_drag_down) | |
290 pl->pl_auto_drag_down = FALSE; | |
291 | |
292 off = nr - pl->pl_drag_pos; | |
293 if (off) { | |
294 for (i = 0; i < abs(off); i++) { | |
295 if (off < 0) | |
296 playlist_list_move_up(pl); | |
297 else | |
298 playlist_list_move_down(pl); | |
299 | |
300 } | |
301 playlistwin_update_list(playlist_get_active()); | |
302 } | |
303 pl->pl_drag_pos = nr; | |
304 } | |
305 } | |
306 | |
307 static void | |
308 playlist_list_button_release_cb(GtkWidget * widget, | |
309 GdkEventButton * event, | |
310 PlayList_List * pl) | |
311 { | |
312 pl->pl_dragging = FALSE; | |
313 pl->pl_auto_drag_down = FALSE; | |
314 pl->pl_auto_drag_up = FALSE; | |
315 } | |
316 | |
317 static void | |
318 playlist_list_draw_string(PlayList_List * pl, | |
319 PangoFontDescription * font, | |
320 gint line, | |
321 gint width, | |
322 const gchar * text, | |
323 guint ppos) | |
324 { | |
325 guint plist_length_int; | |
326 Playlist *playlist = playlist_get_active(); | |
327 | |
328 PangoLayout *layout; | |
329 | |
330 REQUIRE_LOCK(playlist->mutex); | |
331 | |
332 if (cfg.show_numbers_in_pl) { | |
333 gchar *pos_string = g_strdup_printf(cfg.show_separator_in_pl == TRUE ? "%d" : "%d.", ppos); | |
334 plist_length_int = | |
2672 | 335 gint_count_digits(playlist_get_length(playlist)) + !cfg.show_separator_in_pl + 1; /* cf.show_separator_in_pl will be 0 if false */ |
2313 | 336 |
337 padding = plist_length_int; | |
338 padding = ((padding + 1) * width_approx_digits); | |
339 | |
340 layout = gtk_widget_create_pango_layout(playlistwin, pos_string); | |
341 pango_layout_set_font_description(layout, playlist_list_font); | |
342 pango_layout_set_width(layout, plist_length_int * 100); | |
343 | |
344 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); | |
345 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, | |
346 pl->pl_widget.x + | |
347 (width_approx_digits * | |
348 (-1 + plist_length_int - strlen(pos_string))) + | |
349 (width_approx_digits / 4), | |
350 pl->pl_widget.y + (line - 1) * pl->pl_fheight + | |
351 ascent + abs(descent), layout); | |
352 g_free(pos_string); | |
353 g_object_unref(layout); | |
354 | |
355 if (!cfg.show_separator_in_pl) | |
356 padding -= (width_approx_digits * 1.5); | |
357 } | |
358 else { | |
359 padding = 3; | |
360 } | |
361 | |
362 width -= padding; | |
363 | |
364 layout = gtk_widget_create_pango_layout(playlistwin, text); | |
365 | |
366 pango_layout_set_font_description(layout, playlist_list_font); | |
367 pango_layout_set_width(layout, width * PANGO_SCALE); | |
368 pango_layout_set_single_paragraph_mode(layout, TRUE); | |
369 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); | |
370 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, | |
371 pl->pl_widget.x + padding + (width_approx_letters / 4), | |
372 pl->pl_widget.y + (line - 1) * pl->pl_fheight + | |
373 ascent + abs(descent), layout); | |
374 | |
375 g_object_unref(layout); | |
376 } | |
377 | |
378 void | |
379 playlist_list_draw(Widget * w) | |
380 { | |
381 Playlist *playlist = playlist_get_active(); | |
382 PlayList_List *pl = PLAYLIST_LIST(w); | |
383 GList *list; | |
384 GdkGC *gc; | |
385 GdkPixmap *obj; | |
386 PangoLayout *layout; | |
387 gchar *title; | |
388 gint width, height; | |
389 gint i, max_first; | |
390 guint padding, padding_dwidth, padding_plength; | |
391 guint max_time_len = 0; | |
392 gfloat queue_tailpadding = 0; | |
393 gint tpadding; | |
394 gsize tpadding_dwidth = 0; | |
395 gint x, y; | |
396 guint tail_width; | |
397 guint tail_len; | |
398 | |
399 gchar tail[100]; | |
400 gchar queuepos[255]; | |
401 gchar length[40]; | |
402 | |
403 gchar **frags; | |
404 gchar *frag0; | |
405 | |
406 gint plw_w, plw_h; | |
407 | |
408 GdkRectangle *playlist_rect; | |
409 | |
410 gc = pl->pl_widget.gc; | |
411 | |
412 width = pl->pl_widget.width; | |
413 height = pl->pl_widget.height; | |
414 | |
415 obj = pl->pl_widget.parent; | |
416 | |
417 plw_w = playlistwin_get_width(); | |
418 plw_h = playlistwin_get_height(); | |
419 | |
420 playlist_rect = g_new0(GdkRectangle, 1); | |
421 | |
422 playlist_rect->x = 0; | |
423 playlist_rect->y = 0; | |
424 playlist_rect->width = plw_w - 17; | |
425 playlist_rect->height = plw_h - 36; | |
426 | |
427 gdk_gc_set_clip_origin(gc, 31, 58); | |
428 gdk_gc_set_clip_rectangle(gc, playlist_rect); | |
429 | |
2461 | 430 gdk_gc_set_foreground(gc, |
431 skin_get_color(bmp_active_skin, | |
432 SKIN_PLEDIT_NORMALBG)); | |
433 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, pl->pl_widget.y, | |
434 width, height); | |
2313 | 435 |
436 if (!playlist_list_font) { | |
437 g_critical("Couldn't open playlist font"); | |
438 return; | |
439 } | |
440 | |
441 pl->pl_fheight = (ascent + abs(descent)); | |
442 pl->pl_num_visible = height / pl->pl_fheight; | |
443 | |
444 max_first = playlist_get_length(playlist) - pl->pl_num_visible; | |
445 max_first = MAX(max_first, 0); | |
446 | |
447 pl->pl_first = CLAMP(pl->pl_first, 0, max_first); | |
448 | |
449 PLAYLIST_LOCK(playlist->mutex); | |
450 list = playlist->entries; | |
451 list = g_list_nth(list, pl->pl_first); | |
452 | |
453 /* It sucks having to run the iteration twice but this is the only | |
454 way you can reliably get the maximum width so we can get our | |
455 playlist nice and aligned... -- plasmaroo */ | |
456 | |
457 for (i = pl->pl_first; | |
458 list && i < pl->pl_first + pl->pl_num_visible; | |
459 list = g_list_next(list), i++) { | |
460 PlaylistEntry *entry = list->data; | |
461 | |
462 if (entry->length != -1) | |
463 { | |
464 g_snprintf(length, sizeof(length), "%d:%-2.2d", | |
465 entry->length / 60000, (entry->length / 1000) % 60); | |
466 tpadding_dwidth = MAX(tpadding_dwidth, strlen(length)); | |
467 } | |
468 } | |
469 | |
470 /* Reset */ | |
471 list = playlist->entries; | |
472 list = g_list_nth(list, pl->pl_first); | |
473 | |
474 for (i = pl->pl_first; | |
475 list && i < pl->pl_first + pl->pl_num_visible; | |
476 list = g_list_next(list), i++) { | |
477 gint pos; | |
478 PlaylistEntry *entry = list->data; | |
479 | |
480 if (entry->selected) { | |
481 gdk_gc_set_foreground(gc, | |
482 skin_get_color(bmp_active_skin, | |
483 SKIN_PLEDIT_SELECTEDBG)); | |
484 gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, | |
485 pl->pl_widget.y + | |
486 ((i - pl->pl_first) * pl->pl_fheight), | |
487 width, pl->pl_fheight); | |
488 } | |
489 | |
490 /* FIXME: entry->title should NEVER be NULL, and there should | |
491 NEVER be a need to do a UTF-8 conversion. Playlist title | |
492 strings should be kept properly. */ | |
493 | |
494 if (!entry->title) { | |
495 gchar *basename = g_path_get_basename(entry->filename); | |
496 title = filename_to_utf8(basename); | |
497 g_free(basename); | |
498 } | |
499 else | |
500 title = str_to_utf8(entry->title); | |
501 | |
502 title = convert_title_text(title); | |
503 | |
504 pos = playlist_get_queue_position(playlist, entry); | |
505 | |
506 tail[0] = 0; | |
507 queuepos[0] = 0; | |
508 length[0] = 0; | |
509 | |
510 if (pos != -1) | |
511 g_snprintf(queuepos, sizeof(queuepos), "%d", pos + 1); | |
512 | |
513 if (entry->length != -1) | |
514 { | |
515 g_snprintf(length, sizeof(length), "%d:%-2.2d", | |
516 entry->length / 60000, (entry->length / 1000) % 60); | |
517 } | |
518 | |
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2356
diff
changeset
|
519 strncat(tail, length, sizeof(tail) - 1); |
2313 | 520 tail_len = strlen(tail); |
521 | |
522 max_time_len = MAX(max_time_len, tail_len); | |
523 | |
524 if (pos != -1 && tpadding_dwidth <= 0) | |
525 tail_width = width - (width_approx_digits * (strlen(queuepos) + 2.25)); | |
526 else if (pos != -1) | |
527 tail_width = width - (width_approx_digits * (tpadding_dwidth + strlen(queuepos) + 4)); | |
528 else if (tpadding_dwidth > 0) | |
529 tail_width = width - (width_approx_digits * (tpadding_dwidth + 2.5)); | |
530 else | |
531 tail_width = width; | |
532 | |
533 if (i == playlist_get_position_nolock(playlist)) | |
534 gdk_gc_set_foreground(gc, | |
535 skin_get_color(bmp_active_skin, | |
536 SKIN_PLEDIT_CURRENT)); | |
537 else | |
538 gdk_gc_set_foreground(gc, | |
539 skin_get_color(bmp_active_skin, | |
540 SKIN_PLEDIT_NORMAL)); | |
541 playlist_list_draw_string(pl, playlist_list_font, | |
542 i - pl->pl_first, tail_width, title, | |
543 i + 1); | |
544 | |
545 x = pl->pl_widget.x + width - width_approx_digits * 2; | |
546 y = pl->pl_widget.y + ((i - pl->pl_first) - | |
547 1) * pl->pl_fheight + ascent; | |
548 | |
549 frags = NULL; | |
550 frag0 = NULL; | |
551 | |
552 if ((strlen(tail) > 0) && (tail != NULL)) { | |
553 frags = g_strsplit(tail, ":", 0); | |
554 frag0 = g_strconcat(frags[0], ":", NULL); | |
555 | |
556 layout = gtk_widget_create_pango_layout(playlistwin, frags[1]); | |
557 pango_layout_set_font_description(layout, playlist_list_font); | |
558 pango_layout_set_width(layout, tail_len * 100); | |
559 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); | |
560 gdk_draw_layout(obj, gc, x - (0.5 * width_approx_digits), | |
561 y + abs(descent), layout); | |
562 g_object_unref(layout); | |
563 | |
564 layout = gtk_widget_create_pango_layout(playlistwin, frag0); | |
565 pango_layout_set_font_description(layout, playlist_list_font); | |
566 pango_layout_set_width(layout, tail_len * 100); | |
567 pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); | |
568 gdk_draw_layout(obj, gc, x - (0.75 * width_approx_digits), | |
569 y + abs(descent), layout); | |
570 g_object_unref(layout); | |
571 | |
572 g_free(frag0); | |
573 g_strfreev(frags); | |
574 } | |
575 | |
576 if (pos != -1) { | |
577 | |
578 /* DON'T remove the commented code yet please -- Milosz */ | |
579 | |
580 if (tpadding_dwidth > 0) | |
581 queue_tailpadding = tpadding_dwidth + 1; | |
582 else | |
583 queue_tailpadding = -0.75; | |
584 | |
585 gdk_draw_rectangle(obj, gc, FALSE, | |
586 x - | |
587 (((queue_tailpadding + | |
588 strlen(queuepos)) * | |
589 width_approx_digits) + | |
590 (width_approx_digits / 4)), | |
591 y + abs(descent), | |
592 (strlen(queuepos)) * | |
593 width_approx_digits + | |
594 (width_approx_digits / 2), | |
595 pl->pl_fheight - 2); | |
596 | |
597 layout = | |
598 gtk_widget_create_pango_layout(playlistwin, queuepos); | |
599 pango_layout_set_font_description(layout, playlist_list_font); | |
600 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); | |
601 | |
602 gdk_draw_layout(obj, gc, | |
603 x - | |
604 ((queue_tailpadding + | |
605 strlen(queuepos)) * width_approx_digits) + | |
606 (width_approx_digits / 4), | |
607 y + abs(descent), layout); | |
608 g_object_unref(layout); | |
609 } | |
610 | |
611 g_free(title); | |
612 } | |
613 | |
614 | |
615 /* | |
616 * Drop target hovering over the playlist, so draw some hint where the | |
617 * drop will occur. | |
618 * | |
619 * This is (currently? unfixably?) broken when dragging files from Qt/KDE apps, | |
620 * probably due to DnD signaling problems (actually i have no clue). | |
621 * | |
622 */ | |
623 | |
624 if (pl->pl_drag_motion) { | |
625 guint pos, plength, lpadding; | |
626 gint x, y, plx, ply; | |
627 | |
628 if (cfg.show_numbers_in_pl) { | |
2672 | 629 lpadding = gint_count_digits(playlist_get_length(playlist)) + 1; |
2313 | 630 lpadding = ((lpadding + 1) * width_approx_digits); |
631 } | |
632 else { | |
633 lpadding = 3; | |
634 }; | |
635 | |
636 /* We already hold the mutex and have the playlist locked, so call | |
637 the non-locking function. */ | |
2672 | 638 plength = playlist_get_length(playlist); |
2313 | 639 |
640 x = pl->drag_motion_x; | |
641 y = pl->drag_motion_y; | |
642 | |
643 plx = pl->pl_widget.x; | |
644 ply = pl->pl_widget.y; | |
645 | |
646 if ((x > pl->pl_widget.x) && !(x > pl->pl_widget.width)) { | |
647 | |
648 if ((y > pl->pl_widget.y) | |
649 && !(y > (pl->pl_widget.height + ply))) { | |
650 | |
651 pos = ((y - ((Widget *) pl)->y) / pl->pl_fheight) + | |
652 pl->pl_first; | |
653 | |
654 if (pos > (plength)) { | |
655 pos = plength; | |
656 } | |
657 | |
658 gdk_gc_set_foreground(gc, | |
659 skin_get_color(bmp_active_skin, | |
660 SKIN_PLEDIT_CURRENT)); | |
661 | |
662 gdk_draw_line(obj, gc, pl->pl_widget.x, | |
663 pl->pl_widget.y + ((pos - pl->pl_first) * pl->pl_fheight), | |
664 pl->pl_widget.width + pl->pl_widget.x - 1, | |
665 pl->pl_widget.y + | |
666 ((pos - pl->pl_first) * pl->pl_fheight)); | |
667 } | |
668 | |
669 } | |
670 | |
671 /* When dropping on the borders of the playlist, outside the text area, | |
672 * files get appended at the end of the list. Show that too. | |
673 */ | |
674 | |
675 if ((y < ply) || (y > pl->pl_widget.height + ply)) { | |
676 if ((y >= 0) || (y <= (pl->pl_widget.height + ply))) { | |
677 pos = plength; | |
678 gdk_gc_set_foreground(gc, | |
679 skin_get_color(bmp_active_skin, | |
680 SKIN_PLEDIT_CURRENT)); | |
681 | |
682 gdk_draw_line(obj, gc, pl->pl_widget.x, | |
683 pl->pl_widget.y + | |
684 ((pos - pl->pl_first) * pl->pl_fheight), | |
685 pl->pl_widget.width + pl->pl_widget.x - 1, | |
686 pl->pl_widget.y + | |
687 ((pos - pl->pl_first) * pl->pl_fheight)); | |
688 | |
689 } | |
690 } | |
691 } | |
692 | |
693 gdk_gc_set_foreground(gc, | |
694 skin_get_color(bmp_active_skin, | |
695 SKIN_PLEDIT_NORMAL)); | |
696 | |
697 if (cfg.show_numbers_in_pl) | |
698 { | |
2672 | 699 padding_plength = playlist_get_length(playlist); |
2313 | 700 |
701 if (padding_plength == 0) { | |
702 padding_dwidth = 0; | |
703 } | |
704 else { | |
2672 | 705 padding_dwidth = gint_count_digits(playlist_get_length(playlist)); |
2313 | 706 } |
707 | |
708 padding = | |
709 (padding_dwidth * | |
710 width_approx_digits) + width_approx_digits; | |
711 | |
712 | |
713 /* For italic or oblique fonts we add another half of the | |
714 * approximate width */ | |
715 if (has_slant) | |
716 padding += width_approx_digits_half; | |
717 | |
718 if (cfg.show_separator_in_pl) { | |
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 - 1); | |
724 } | |
725 } | |
726 | |
727 if (tpadding_dwidth != 0) | |
728 { | |
729 tpadding = (tpadding_dwidth * width_approx_digits) + (width_approx_digits * 1.5); | |
730 | |
731 if (has_slant) | |
732 tpadding += width_approx_digits_half; | |
733 | |
734 if (cfg.show_separator_in_pl) { | |
735 gdk_draw_line(obj, gc, | |
736 pl->pl_widget.x + pl->pl_widget.width - tpadding, | |
737 pl->pl_widget.y, | |
738 pl->pl_widget.x + pl->pl_widget.width - tpadding, | |
739 pl->pl_widget.y + pl->pl_widget.height - 1); | |
740 } | |
741 } | |
742 | |
743 gdk_gc_set_clip_origin(gc, 0, 0); | |
744 gdk_gc_set_clip_rectangle(gc, NULL); | |
745 | |
746 PLAYLIST_UNLOCK(playlist->mutex); | |
747 | |
748 gdk_flush(); | |
749 | |
750 g_free(playlist_rect); | |
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 } |