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