Mercurial > audlegacy
annotate src/audacious/ui_skinned_playlist.c @ 4007:fc85f7ce6969
introduce WIDGET_SPIN_BTN
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Sun, 25 Nov 2007 15:32:00 +0100 |
parents | 351dc6ef07b9 |
children | 1112f53ecc18 |
rev | line source |
---|---|
3217 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3840 | 3 * Copyright (c) 2007 Tomasz Moń |
3217 | 4 * |
5 * Based on: | |
6 * BMP - Cross-platform multimedia player | |
7 * Copyright (C) 2003-2004 BMP development team. | |
8 * XMMS: | |
9 * Copyright (C) 1998-2003 XMMS development team. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; under version 3 of the License. | |
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, see <http://www.gnu.org/licenses>. | |
22 * | |
23 * The Audacious team does not consider modular code linking to | |
24 * Audacious or using our public API to be a derived work. | |
25 */ | |
26 | |
27 /* | |
28 * A note about Pango and some funky spacey fonts: Weirdly baselined | |
29 * fonts, or fonts with weird ascents or descents _will_ display a | |
30 * little bit weird in the playlist widget, but the display engine | |
31 * won't make it look too bad, just a little deranged. I honestly | |
32 * don't think it's worth fixing (around...), it doesn't have to be | |
33 * perfectly fitting, just the general look has to be ok, which it | |
34 * IMHO is. | |
35 * | |
36 * A second note: The numbers aren't perfectly aligned, but in the | |
37 * end it looks better when using a single Pango layout for each | |
38 * number. | |
39 */ | |
40 | |
41 | |
3251 | 42 #include "skin.h" |
3217 | 43 #include "ui_skinned_playlist.h" |
44 #include "main.h" | |
45 #include "util.h" | |
46 #include "ui_playlist.h" | |
47 | |
48 #include "input.h" | |
49 #include "strings.h" | |
50 #include "playback.h" | |
51 #include "playlist.h" | |
52 #include "ui_manager.h" | |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
53 #include "ui_fileinfopopup.h" |
3217 | 54 |
55 #include "debug.h" | |
56 static PangoFontDescription *playlist_list_font = NULL; | |
57 static gint ascent, descent, width_delta_digit_one; | |
58 static gboolean has_slant; | |
59 static guint padding; | |
60 | |
61 /* FIXME: the following globals should not be needed. */ | |
62 static gint width_approx_letters; | |
63 static gint width_colon, width_colon_third; | |
64 static gint width_approx_digits, width_approx_digits_half; | |
65 | |
66 #define UI_SKINNED_PLAYLIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_playlist_get_type(), UiSkinnedPlaylistPrivate)) | |
67 typedef struct _UiSkinnedPlaylistPrivate UiSkinnedPlaylistPrivate; | |
68 | |
69 enum { | |
70 REDRAW, | |
71 LAST_SIGNAL | |
72 }; | |
73 | |
74 struct _UiSkinnedPlaylistPrivate { | |
75 SkinPixmapId skin_index; | |
76 gint width, height; | |
77 gint resize_width, resize_height; | |
78 gint drag_pos; | |
79 gboolean dragging, auto_drag_down, auto_drag_up; | |
80 gint auto_drag_up_tag, auto_drag_down_tag; | |
81 }; | |
82 | |
83 static void ui_skinned_playlist_class_init (UiSkinnedPlaylistClass *klass); | |
84 static void ui_skinned_playlist_init (UiSkinnedPlaylist *playlist); | |
85 static void ui_skinned_playlist_destroy (GtkObject *object); | |
86 static void ui_skinned_playlist_realize (GtkWidget *widget); | |
87 static void ui_skinned_playlist_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
88 static void ui_skinned_playlist_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
89 static gboolean ui_skinned_playlist_expose (GtkWidget *widget, GdkEventExpose *event); | |
90 static gboolean ui_skinned_playlist_button_press (GtkWidget *widget, GdkEventButton *event); | |
91 static gboolean ui_skinned_playlist_button_release (GtkWidget *widget, GdkEventButton *event); | |
92 static gboolean ui_skinned_playlist_motion_notify (GtkWidget *widget, GdkEventMotion *event); | |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
93 static gboolean ui_skinned_playlist_leave_notify (GtkWidget *widget, GdkEventCrossing *event); |
3217 | 94 static void ui_skinned_playlist_redraw (UiSkinnedPlaylist *playlist); |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
95 static gboolean ui_skinned_playlist_popup_show (gpointer data); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
96 static void ui_skinned_playlist_popup_hide (GtkWidget *widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
97 static void ui_skinned_playlist_popup_timer_start (GtkWidget *widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
98 static void ui_skinned_playlist_popup_timer_stop (GtkWidget *widget); |
3217 | 99 |
100 static GtkWidgetClass *parent_class = NULL; | |
101 static guint playlist_signals[LAST_SIGNAL] = { 0 }; | |
102 | |
103 GType ui_skinned_playlist_get_type() { | |
104 static GType playlist_type = 0; | |
105 if (!playlist_type) { | |
106 static const GTypeInfo playlist_info = { | |
107 sizeof (UiSkinnedPlaylistClass), | |
108 NULL, | |
109 NULL, | |
110 (GClassInitFunc) ui_skinned_playlist_class_init, | |
111 NULL, | |
112 NULL, | |
113 sizeof (UiSkinnedPlaylist), | |
114 0, | |
115 (GInstanceInitFunc) ui_skinned_playlist_init, | |
116 }; | |
117 playlist_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedPlaylist", &playlist_info, 0); | |
118 } | |
119 | |
120 return playlist_type; | |
121 } | |
122 | |
123 static void ui_skinned_playlist_class_init(UiSkinnedPlaylistClass *klass) { | |
124 GObjectClass *gobject_class; | |
125 GtkObjectClass *object_class; | |
126 GtkWidgetClass *widget_class; | |
127 | |
128 gobject_class = G_OBJECT_CLASS(klass); | |
129 object_class = (GtkObjectClass*) klass; | |
130 widget_class = (GtkWidgetClass*) klass; | |
131 parent_class = gtk_type_class (gtk_widget_get_type ()); | |
132 | |
133 object_class->destroy = ui_skinned_playlist_destroy; | |
134 | |
135 widget_class->realize = ui_skinned_playlist_realize; | |
136 widget_class->expose_event = ui_skinned_playlist_expose; | |
137 widget_class->size_request = ui_skinned_playlist_size_request; | |
138 widget_class->size_allocate = ui_skinned_playlist_size_allocate; | |
139 widget_class->button_press_event = ui_skinned_playlist_button_press; | |
140 widget_class->button_release_event = ui_skinned_playlist_button_release; | |
141 widget_class->motion_notify_event = ui_skinned_playlist_motion_notify; | |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
142 widget_class->leave_notify_event = ui_skinned_playlist_leave_notify; |
3217 | 143 |
144 klass->redraw = ui_skinned_playlist_redraw; | |
145 | |
146 playlist_signals[REDRAW] = | |
147 g_signal_new ("redraw", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
148 G_STRUCT_OFFSET (UiSkinnedPlaylistClass, redraw), NULL, NULL, | |
149 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
150 | |
151 g_type_class_add_private (gobject_class, sizeof (UiSkinnedPlaylistPrivate)); | |
152 } | |
153 | |
154 static void ui_skinned_playlist_init(UiSkinnedPlaylist *playlist) { | |
155 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(playlist); | |
156 playlist->pressed = FALSE; | |
157 priv->resize_width = 0; | |
158 priv->resize_height = 0; | |
159 playlist->prev_selected = -1; | |
160 playlist->prev_min = -1; | |
161 playlist->prev_max = -1; | |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
162 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
163 g_object_set_data(G_OBJECT(playlist), "timer_id", GINT_TO_POINTER(0)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
164 g_object_set_data(G_OBJECT(playlist), "timer_active", GINT_TO_POINTER(0)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
165 |
3755
2ca446f02d97
export the fileinfopopup API.
William Pitcock <nenolod@atheme.org>
parents:
3514
diff
changeset
|
166 GtkWidget *popup = fileinfopopup_create(); |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
167 g_object_set_data(G_OBJECT(playlist), "popup", popup); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
168 g_object_set_data(G_OBJECT(playlist), "popup_active", GINT_TO_POINTER(0)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
169 g_object_set_data(G_OBJECT(playlist), "popup_position", GINT_TO_POINTER(-1)); |
3217 | 170 } |
171 | |
172 GtkWidget* ui_skinned_playlist_new(GtkWidget *fixed, gint x, gint y, gint w, gint h) { | |
173 | |
174 UiSkinnedPlaylist *hs = g_object_new (ui_skinned_playlist_get_type (), NULL); | |
175 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(hs); | |
176 | |
177 hs->x = x; | |
178 hs->y = y; | |
179 priv->width = w; | |
180 priv->height = h; | |
181 priv->skin_index = SKIN_PLEDIT; | |
182 | |
3939
d46d60247826
we don't need to store GtkFixed pointer, do we?
Tomasz Mon <desowin@gmail.com>
parents:
3840
diff
changeset
|
183 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(hs), hs->x, hs->y); |
3217 | 184 |
185 return GTK_WIDGET(hs); | |
186 } | |
187 | |
188 static void ui_skinned_playlist_destroy(GtkObject *object) { | |
189 UiSkinnedPlaylist *playlist; | |
190 | |
191 g_return_if_fail (object != NULL); | |
192 g_return_if_fail (UI_SKINNED_IS_PLAYLIST (object)); | |
193 | |
194 playlist = UI_SKINNED_PLAYLIST (object); | |
195 | |
196 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
197 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
198 } | |
199 | |
200 static void ui_skinned_playlist_realize(GtkWidget *widget) { | |
201 UiSkinnedPlaylist *playlist; | |
202 GdkWindowAttr attributes; | |
203 gint attributes_mask; | |
204 | |
205 g_return_if_fail (widget != NULL); | |
206 g_return_if_fail (UI_SKINNED_IS_PLAYLIST(widget)); | |
207 | |
208 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); | |
209 playlist = UI_SKINNED_PLAYLIST(widget); | |
210 | |
211 attributes.x = widget->allocation.x; | |
212 attributes.y = widget->allocation.y; | |
213 attributes.width = widget->allocation.width; | |
214 attributes.height = widget->allocation.height; | |
215 attributes.wclass = GDK_INPUT_OUTPUT; | |
216 attributes.window_type = GDK_WINDOW_CHILD; | |
217 attributes.event_mask = gtk_widget_get_events(widget); | |
218 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | | |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
219 GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; |
3217 | 220 attributes.visual = gtk_widget_get_visual(widget); |
221 attributes.colormap = gtk_widget_get_colormap(widget); | |
222 | |
223 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
224 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); | |
225 | |
226 widget->style = gtk_style_attach(widget->style, widget->window); | |
227 gdk_window_set_user_data(widget->window, widget); | |
228 } | |
229 | |
230 static void ui_skinned_playlist_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
231 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(widget); | |
232 | |
233 requisition->width = priv->width; | |
234 requisition->height = priv->height; | |
235 } | |
236 | |
237 static void ui_skinned_playlist_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
238 UiSkinnedPlaylist *playlist = UI_SKINNED_PLAYLIST (widget); | |
239 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(playlist); | |
240 | |
241 widget->allocation = *allocation; | |
242 if (GTK_WIDGET_REALIZED (widget)) | |
243 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); | |
244 | |
245 playlist->x = widget->allocation.x; | |
246 playlist->y = widget->allocation.y; | |
247 | |
248 if (priv->height != widget->allocation.height || priv->width != widget->allocation.width) { | |
249 priv->width = priv->width + priv->resize_width; | |
250 priv->height = priv->height + priv->resize_height; | |
251 priv->resize_width = 0; | |
252 priv->resize_height = 0; | |
253 gtk_widget_queue_draw(widget); | |
254 } | |
255 } | |
256 | |
257 static gboolean ui_skinned_playlist_auto_drag_down_func(gpointer data) { | |
258 UiSkinnedPlaylist *pl = UI_SKINNED_PLAYLIST(data); | |
259 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(data); | |
260 | |
261 if (priv->auto_drag_down) { | |
262 ui_skinned_playlist_move_down(pl); | |
263 pl->first++; | |
264 playlistwin_update_list(playlist_get_active()); | |
265 return TRUE; | |
266 } | |
267 return FALSE; | |
268 } | |
269 | |
270 static gboolean ui_skinned_playlist_auto_drag_up_func(gpointer data) { | |
271 UiSkinnedPlaylist *pl = UI_SKINNED_PLAYLIST(data); | |
272 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(data); | |
273 | |
274 if (priv->auto_drag_up) { | |
275 ui_skinned_playlist_move_up(pl); | |
276 pl->first--; | |
277 playlistwin_update_list(playlist_get_active()); | |
278 return TRUE; | |
279 | |
280 } | |
281 return FALSE; | |
282 } | |
283 | |
284 void ui_skinned_playlist_move_up(UiSkinnedPlaylist * pl) { | |
285 GList *list; | |
286 Playlist *playlist = playlist_get_active(); | |
287 | |
288 if (!playlist) | |
289 return; | |
290 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
291 PLAYLIST_LOCK(playlist); |
3217 | 292 if ((list = playlist->entries) == NULL) { |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
293 PLAYLIST_UNLOCK(playlist); |
3217 | 294 return; |
295 } | |
296 if (PLAYLIST_ENTRY(list->data)->selected) { | |
297 /* We are at the top */ | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
298 PLAYLIST_UNLOCK(playlist); |
3217 | 299 return; |
300 } | |
301 while (list) { | |
302 if (PLAYLIST_ENTRY(list->data)->selected) | |
303 glist_moveup(list); | |
304 list = g_list_next(list); | |
305 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
306 PLAYLIST_UNLOCK(playlist); |
3217 | 307 if (pl->prev_selected != -1) |
308 pl->prev_selected--; | |
309 if (pl->prev_min != -1) | |
310 pl->prev_min--; | |
311 if (pl->prev_max != -1) | |
312 pl->prev_max--; | |
313 } | |
314 | |
315 void ui_skinned_playlist_move_down(UiSkinnedPlaylist * pl) { | |
316 GList *list; | |
317 Playlist *playlist = playlist_get_active(); | |
318 | |
319 if (!playlist) | |
320 return; | |
321 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
322 PLAYLIST_LOCK(playlist); |
3217 | 323 |
324 if (!(list = g_list_last(playlist->entries))) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
325 PLAYLIST_UNLOCK(playlist); |
3217 | 326 return; |
327 } | |
328 | |
329 if (PLAYLIST_ENTRY(list->data)->selected) { | |
330 /* We are at the bottom */ | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
331 PLAYLIST_UNLOCK(playlist); |
3217 | 332 return; |
333 } | |
334 | |
335 while (list) { | |
336 if (PLAYLIST_ENTRY(list->data)->selected) | |
337 glist_movedown(list); | |
338 list = g_list_previous(list); | |
339 } | |
340 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
341 PLAYLIST_UNLOCK(playlist); |
3217 | 342 |
343 if (pl->prev_selected != -1) | |
344 pl->prev_selected++; | |
345 if (pl->prev_min != -1) | |
346 pl->prev_min++; | |
347 if (pl->prev_max != -1) | |
348 pl->prev_max++; | |
349 } | |
350 | |
351 static void | |
352 playlist_list_draw_string(GdkPixmap *obj, GdkGC *gc, UiSkinnedPlaylist *pl, | |
353 PangoFontDescription * font, | |
354 gint line, | |
355 gint width, | |
356 const gchar * text, | |
357 guint ppos) | |
358 { | |
359 guint plist_length_int; | |
360 Playlist *playlist = playlist_get_active(); | |
361 PangoLayout *layout; | |
362 | |
363 REQUIRE_LOCK(playlist->mutex); | |
364 | |
365 if (cfg.show_numbers_in_pl) { | |
366 gchar *pos_string = g_strdup_printf(cfg.show_separator_in_pl == TRUE ? "%d" : "%d.", ppos); | |
367 plist_length_int = | |
368 gint_count_digits(playlist_get_length(playlist)) + !cfg.show_separator_in_pl + 1; /* cf.show_separator_in_pl will be 0 if false */ | |
369 | |
370 padding = plist_length_int; | |
371 padding = ((padding + 1) * width_approx_digits); | |
372 | |
373 layout = gtk_widget_create_pango_layout(playlistwin, pos_string); | |
374 pango_layout_set_font_description(layout, playlist_list_font); | |
375 pango_layout_set_width(layout, plist_length_int * 100); | |
376 | |
377 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); | |
378 | |
379 | |
380 gdk_draw_layout(obj, gc, (width_approx_digits * | |
381 (-1 + plist_length_int - strlen(pos_string))) + | |
382 (width_approx_digits / 4), | |
383 (line - 1) * pl->fheight + | |
384 ascent + abs(descent), layout); | |
385 g_free(pos_string); | |
386 g_object_unref(layout); | |
387 | |
388 if (!cfg.show_separator_in_pl) | |
389 padding -= (width_approx_digits * 1.5); | |
390 } else { | |
391 padding = 3; | |
392 } | |
393 | |
394 width -= padding; | |
395 | |
396 layout = gtk_widget_create_pango_layout(playlistwin, text); | |
397 | |
398 pango_layout_set_font_description(layout, playlist_list_font); | |
399 pango_layout_set_width(layout, width * PANGO_SCALE); | |
400 pango_layout_set_single_paragraph_mode(layout, TRUE); | |
401 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); | |
402 gdk_draw_layout(obj, gc, | |
403 padding + (width_approx_letters / 4), | |
404 (line - 1) * pl->fheight + | |
405 ascent + abs(descent), layout); | |
406 | |
407 g_object_unref(layout); | |
408 } | |
409 | |
410 static gboolean ui_skinned_playlist_expose(GtkWidget *widget, GdkEventExpose *event) { | |
411 g_return_val_if_fail (widget != NULL, FALSE); | |
412 g_return_val_if_fail (UI_SKINNED_IS_PLAYLIST (widget), FALSE); | |
413 g_return_val_if_fail (event != NULL, FALSE); | |
414 | |
415 UiSkinnedPlaylist *pl = UI_SKINNED_PLAYLIST (widget); | |
416 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(pl); | |
417 | |
418 Playlist *playlist = playlist_get_active(); | |
419 GList *list; | |
420 PangoLayout *layout; | |
421 gchar *title; | |
422 gint width, height; | |
423 gint i, max_first; | |
424 guint padding, padding_dwidth, padding_plength; | |
425 guint max_time_len = 0; | |
426 gfloat queue_tailpadding = 0; | |
427 gint tpadding; | |
428 gsize tpadding_dwidth = 0; | |
429 gint x, y; | |
430 guint tail_width; | |
431 guint tail_len; | |
432 | |
433 gchar tail[100]; | |
434 gchar queuepos[255]; | |
435 gchar length[40]; | |
436 | |
437 gchar **frags; | |
438 gchar *frag0; | |
439 | |
440 gint plw_w, plw_h; | |
441 | |
442 GdkPixmap *obj = NULL; | |
443 GdkGC *gc; | |
444 | |
445 obj = gdk_pixmap_new(NULL, priv->width, priv->height, gdk_rgb_get_visual()->depth); | |
446 gc = gdk_gc_new(obj); | |
447 | |
448 GdkRectangle *playlist_rect; | |
449 | |
450 width = priv->width; | |
451 height = priv->height; | |
452 | |
453 plw_w = playlistwin_get_width(); | |
454 plw_h = playlistwin_get_height(); | |
455 | |
3514
331bfc72ef66
Convert some things to use GSlice.
William Pitcock <nenolod@atheme.org>
parents:
3511
diff
changeset
|
456 playlist_rect = g_slice_new0(GdkRectangle); |
3217 | 457 |
458 playlist_rect->x = 0; | |
459 playlist_rect->y = 0; | |
460 playlist_rect->width = plw_w - 17; | |
461 playlist_rect->height = plw_h - 36; | |
462 | |
463 gdk_gc_set_clip_origin(gc, 31, 58); | |
464 gdk_gc_set_clip_rectangle(gc, playlist_rect); | |
465 | |
466 gdk_gc_set_foreground(gc, | |
467 skin_get_color(bmp_active_skin, | |
468 SKIN_PLEDIT_NORMALBG)); | |
469 gdk_draw_rectangle(obj, gc, TRUE, 0, 0, | |
470 width, height); | |
471 | |
472 if (!playlist_list_font) { | |
473 g_critical("Couldn't open playlist font"); | |
474 return FALSE; | |
475 } | |
476 | |
477 pl->fheight = (ascent + abs(descent)); | |
478 pl->num_visible = height / pl->fheight; | |
479 | |
480 max_first = playlist_get_length(playlist) - pl->num_visible; | |
481 max_first = MAX(max_first, 0); | |
482 | |
483 pl->first = CLAMP(pl->first, 0, max_first); | |
484 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
485 PLAYLIST_LOCK(playlist); |
3217 | 486 list = playlist->entries; |
487 list = g_list_nth(list, pl->first); | |
488 | |
489 /* It sucks having to run the iteration twice but this is the only | |
490 way you can reliably get the maximum width so we can get our | |
491 playlist nice and aligned... -- plasmaroo */ | |
492 | |
493 for (i = pl->first; | |
494 list && i < pl->first + pl->num_visible; | |
495 list = g_list_next(list), i++) { | |
496 PlaylistEntry *entry = list->data; | |
497 | |
498 if (entry->length != -1) | |
499 { | |
500 g_snprintf(length, sizeof(length), "%d:%-2.2d", | |
501 entry->length / 60000, (entry->length / 1000) % 60); | |
502 tpadding_dwidth = MAX(tpadding_dwidth, strlen(length)); | |
503 } | |
504 } | |
505 | |
506 /* Reset */ | |
507 list = playlist->entries; | |
508 list = g_list_nth(list, pl->first); | |
509 | |
510 for (i = pl->first; | |
511 list && i < pl->first + pl->num_visible; | |
512 list = g_list_next(list), i++) { | |
513 gint pos; | |
514 PlaylistEntry *entry = list->data; | |
515 | |
516 if (entry->selected) { | |
517 gdk_gc_set_foreground(gc, | |
518 skin_get_color(bmp_active_skin, | |
519 SKIN_PLEDIT_SELECTEDBG)); | |
520 gdk_draw_rectangle(obj, gc, TRUE, 0, | |
521 ((i - pl->first) * pl->fheight), | |
522 width, pl->fheight); | |
523 } | |
524 | |
525 /* FIXME: entry->title should NEVER be NULL, and there should | |
526 NEVER be a need to do a UTF-8 conversion. Playlist title | |
527 strings should be kept properly. */ | |
528 | |
529 if (!entry->title) { | |
530 gchar *realfn = g_filename_from_uri(entry->filename, NULL, NULL); | |
531 gchar *basename = g_path_get_basename(realfn ? realfn : entry->filename); | |
532 title = filename_to_utf8(basename); | |
533 g_free(basename); g_free(realfn); | |
534 } | |
535 else | |
536 title = str_to_utf8(entry->title); | |
537 | |
538 title = convert_title_text(title); | |
539 | |
540 pos = playlist_get_queue_position(playlist, entry); | |
541 | |
542 tail[0] = 0; | |
543 queuepos[0] = 0; | |
544 length[0] = 0; | |
545 | |
546 if (pos != -1) | |
547 g_snprintf(queuepos, sizeof(queuepos), "%d", pos + 1); | |
548 | |
549 if (entry->length != -1) | |
550 { | |
551 g_snprintf(length, sizeof(length), "%d:%-2.2d", | |
552 entry->length / 60000, (entry->length / 1000) % 60); | |
553 } | |
554 | |
555 strncat(tail, length, sizeof(tail) - 1); | |
556 tail_len = strlen(tail); | |
557 | |
558 max_time_len = MAX(max_time_len, tail_len); | |
559 | |
560 if (pos != -1 && tpadding_dwidth <= 0) | |
561 tail_width = width - (width_approx_digits * (strlen(queuepos) + 2.25)); | |
562 else if (pos != -1) | |
563 tail_width = width - (width_approx_digits * (tpadding_dwidth + strlen(queuepos) + 4)); | |
564 else if (tpadding_dwidth > 0) | |
565 tail_width = width - (width_approx_digits * (tpadding_dwidth + 2.5)); | |
566 else | |
567 tail_width = width; | |
568 | |
569 if (i == playlist_get_position_nolock(playlist)) | |
570 gdk_gc_set_foreground(gc, | |
571 skin_get_color(bmp_active_skin, | |
572 SKIN_PLEDIT_CURRENT)); | |
573 else | |
574 gdk_gc_set_foreground(gc, | |
575 skin_get_color(bmp_active_skin, | |
576 SKIN_PLEDIT_NORMAL)); | |
577 playlist_list_draw_string(obj, gc, pl, playlist_list_font, | |
578 i - pl->first, tail_width, title, | |
579 i + 1); | |
580 | |
581 x = width - width_approx_digits * 2; | |
582 y = ((i - pl->first) - 1) * pl->fheight + ascent; | |
583 | |
584 frags = NULL; | |
585 frag0 = NULL; | |
586 | |
587 if ((strlen(tail) > 0) && (tail != NULL)) { | |
588 frags = g_strsplit(tail, ":", 0); | |
589 frag0 = g_strconcat(frags[0], ":", NULL); | |
590 | |
591 layout = gtk_widget_create_pango_layout(playlistwin, frags[1]); | |
592 pango_layout_set_font_description(layout, playlist_list_font); | |
593 pango_layout_set_width(layout, tail_len * 100); | |
594 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); | |
595 gdk_draw_layout(obj, gc, x - (0.5 * width_approx_digits), | |
596 y + abs(descent), layout); | |
597 g_object_unref(layout); | |
598 | |
599 layout = gtk_widget_create_pango_layout(playlistwin, frag0); | |
600 pango_layout_set_font_description(layout, playlist_list_font); | |
601 pango_layout_set_width(layout, tail_len * 100); | |
602 pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); | |
603 gdk_draw_layout(obj, gc, x - (0.75 * width_approx_digits), | |
604 y + abs(descent), layout); | |
605 g_object_unref(layout); | |
606 | |
607 g_free(frag0); | |
608 g_strfreev(frags); | |
609 } | |
610 | |
611 if (pos != -1) { | |
612 | |
613 /* DON'T remove the commented code yet please -- Milosz */ | |
614 | |
615 if (tpadding_dwidth > 0) | |
616 queue_tailpadding = tpadding_dwidth + 1; | |
617 else | |
618 queue_tailpadding = -0.75; | |
619 | |
620 gdk_draw_rectangle(obj, gc, FALSE, | |
621 x - | |
622 (((queue_tailpadding + | |
623 strlen(queuepos)) * | |
624 width_approx_digits) + | |
625 (width_approx_digits / 4)), | |
626 y + abs(descent), | |
627 (strlen(queuepos)) * | |
628 width_approx_digits + | |
629 (width_approx_digits / 2), | |
630 pl->fheight - 2); | |
631 | |
632 layout = | |
633 gtk_widget_create_pango_layout(playlistwin, queuepos); | |
634 pango_layout_set_font_description(layout, playlist_list_font); | |
635 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); | |
636 | |
637 gdk_draw_layout(obj, gc, | |
638 x - | |
639 ((queue_tailpadding + | |
640 strlen(queuepos)) * width_approx_digits) + | |
641 (width_approx_digits / 4), | |
642 y + abs(descent), layout); | |
643 g_object_unref(layout); | |
644 } | |
645 | |
646 g_free(title); | |
647 } | |
648 | |
649 | |
650 /* | |
651 * Drop target hovering over the playlist, so draw some hint where the | |
652 * drop will occur. | |
653 * | |
654 * This is (currently? unfixably?) broken when dragging files from Qt/KDE apps, | |
655 * probably due to DnD signaling problems (actually i have no clue). | |
656 * | |
657 */ | |
658 | |
659 if (pl->drag_motion) { | |
660 guint pos, plength, lpadding; | |
661 gint x, y, plx, ply; | |
662 | |
663 if (cfg.show_numbers_in_pl) { | |
664 lpadding = gint_count_digits(playlist_get_length(playlist)) + 1; | |
665 lpadding = ((lpadding + 1) * width_approx_digits); | |
666 } | |
667 else { | |
668 lpadding = 3; | |
669 }; | |
670 | |
671 /* We already hold the mutex and have the playlist locked, so call | |
672 the non-locking function. */ | |
673 plength = playlist_get_length(playlist); | |
674 | |
675 x = pl->drag_motion_x; | |
676 y = pl->drag_motion_y; | |
677 | |
678 plx = pl->x; | |
679 ply = pl->y; | |
680 | |
681 if ((x > pl->x) && !(x > priv->width)) { | |
682 | |
683 if ((y > pl->y) | |
684 && !(y > (priv->height + ply))) { | |
685 | |
3218
018b37cf0730
hasta la vista old widgetcore
Tomasz Mon <desowin@gmail.com>
parents:
3217
diff
changeset
|
686 pos = ((y - pl->y) / pl->fheight) + |
3217 | 687 pl->first; |
688 | |
689 if (pos > (plength)) { | |
690 pos = plength; | |
691 } | |
692 | |
693 gdk_gc_set_foreground(gc, | |
694 skin_get_color(bmp_active_skin, | |
695 SKIN_PLEDIT_CURRENT)); | |
696 | |
697 gdk_draw_line(obj, gc, 0, | |
698 ((pos - pl->first) * pl->fheight), | |
699 priv->width - 1, | |
700 ((pos - pl->first) * pl->fheight)); | |
701 } | |
702 | |
703 } | |
704 | |
705 /* When dropping on the borders of the playlist, outside the text area, | |
706 * files get appended at the end of the list. Show that too. | |
707 */ | |
708 | |
709 if ((y < ply) || (y > priv->height + ply)) { | |
710 if ((y >= 0) || (y <= (priv->height + ply))) { | |
711 pos = plength; | |
712 gdk_gc_set_foreground(gc, skin_get_color(bmp_active_skin, SKIN_PLEDIT_CURRENT)); | |
713 | |
714 gdk_draw_line(obj, gc, 0, ((pos - pl->first) * pl->fheight), | |
715 priv->width - 1, ((pos - pl->first) * pl->fheight)); | |
716 | |
717 } | |
718 } | |
719 } | |
720 | |
721 gdk_gc_set_foreground(gc, skin_get_color(bmp_active_skin, SKIN_PLEDIT_NORMAL)); | |
722 | |
723 if (cfg.show_numbers_in_pl) | |
724 { | |
725 padding_plength = playlist_get_length(playlist); | |
726 | |
727 if (padding_plength == 0) { | |
728 padding_dwidth = 0; | |
729 } | |
730 else { | |
731 padding_dwidth = gint_count_digits(playlist_get_length(playlist)); | |
732 } | |
733 | |
734 padding = | |
735 (padding_dwidth * | |
736 width_approx_digits) + width_approx_digits; | |
737 | |
738 | |
739 /* For italic or oblique fonts we add another half of the | |
740 * approximate width */ | |
741 if (has_slant) | |
742 padding += width_approx_digits_half; | |
743 | |
744 if (cfg.show_separator_in_pl) { | |
745 gdk_draw_line(obj, gc, padding, 0, padding, priv->height - 1); | |
746 } | |
747 } | |
748 | |
749 if (tpadding_dwidth != 0) | |
750 { | |
751 tpadding = (tpadding_dwidth * width_approx_digits) + (width_approx_digits * 1.5); | |
752 | |
753 if (has_slant) | |
754 tpadding += width_approx_digits_half; | |
755 | |
756 if (cfg.show_separator_in_pl) { | |
757 gdk_draw_line(obj, gc, priv->width - tpadding, 0, priv->width - tpadding, priv->height - 1); | |
758 } | |
759 } | |
760 | |
761 gdk_gc_set_clip_origin(gc, 0, 0); | |
762 gdk_gc_set_clip_rectangle(gc, NULL); | |
763 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
764 PLAYLIST_UNLOCK(playlist); |
3217 | 765 |
766 gdk_draw_drawable(widget->window, gc, obj, 0, 0, 0, 0, priv->width, priv->height); | |
767 | |
768 g_object_unref(obj); | |
769 g_object_unref(gc); | |
3514
331bfc72ef66
Convert some things to use GSlice.
William Pitcock <nenolod@atheme.org>
parents:
3511
diff
changeset
|
770 g_slice_free(GdkRectangle, playlist_rect); |
3217 | 771 |
772 return FALSE; | |
773 } | |
774 | |
775 gint ui_skinned_playlist_get_position(GtkWidget *widget, gint x, gint y) { | |
776 gint iy, length; | |
777 gint ret; | |
778 Playlist *playlist = playlist_get_active(); | |
779 UiSkinnedPlaylist *pl = UI_SKINNED_PLAYLIST (widget); | |
780 | |
781 if (!pl->fheight) | |
782 return -1; | |
783 | |
784 if ((length = playlist_get_length(playlist)) == 0) | |
785 return -1; | |
786 iy = y; | |
787 | |
788 ret = (iy / pl->fheight) + pl->first; | |
789 | |
790 if (ret > length - 1) | |
791 ret = -1; | |
792 | |
793 return ret; | |
794 } | |
795 | |
796 static gboolean ui_skinned_playlist_button_press(GtkWidget *widget, GdkEventButton *event) { | |
797 UiSkinnedPlaylist *pl = UI_SKINNED_PLAYLIST (widget); | |
798 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(widget); | |
799 | |
800 gint nr; | |
801 Playlist *playlist = playlist_get_active(); | |
802 | |
803 nr = ui_skinned_playlist_get_position(widget, event->x, event->y); | |
804 if (nr == -1) | |
805 return FALSE; | |
806 | |
807 if (event->button == 3) { | |
3370
dbca6c49bdff
fix playlist right click behaviour
Tomasz Mon <desowin@gmail.com>
parents:
3365
diff
changeset
|
808 ui_manager_popup_menu_show(GTK_MENU(playlistwin_popup_menu), |
dbca6c49bdff
fix playlist right click behaviour
Tomasz Mon <desowin@gmail.com>
parents:
3365
diff
changeset
|
809 event->x_root, event->y_root + 5, |
dbca6c49bdff
fix playlist right click behaviour
Tomasz Mon <desowin@gmail.com>
parents:
3365
diff
changeset
|
810 event->button, event->time); |
3217 | 811 GList* selection = playlist_get_selected(playlist); |
812 if (g_list_find(selection, GINT_TO_POINTER(nr)) == NULL) { | |
813 playlist_select_all(playlist, FALSE); | |
814 playlist_select_range(playlist, nr, nr, TRUE); | |
815 } | |
816 } else if (event->button == 1) { | |
817 if (!(event->state & GDK_CONTROL_MASK)) | |
818 playlist_select_all(playlist, FALSE); | |
819 | |
3365
b4ff4ef0211f
make queue on click on playlist with GDK_MOD1_MASK working again
Tomasz Mon <desowin@gmail.com>
parents:
3333
diff
changeset
|
820 if ((event->state & GDK_MOD1_MASK)) |
b4ff4ef0211f
make queue on click on playlist with GDK_MOD1_MASK working again
Tomasz Mon <desowin@gmail.com>
parents:
3333
diff
changeset
|
821 playlist_queue_position(playlist, nr); |
b4ff4ef0211f
make queue on click on playlist with GDK_MOD1_MASK working again
Tomasz Mon <desowin@gmail.com>
parents:
3333
diff
changeset
|
822 |
3217 | 823 if (event->state & GDK_SHIFT_MASK && pl->prev_selected != -1) { |
824 playlist_select_range(playlist, pl->prev_selected, nr, TRUE); | |
825 pl->prev_min = pl->prev_selected; | |
826 pl->prev_max = nr; | |
827 priv->drag_pos = nr - pl->first; | |
828 } | |
829 else { | |
830 if (playlist_select_invert(playlist, nr)) { | |
831 if (event->state & GDK_CONTROL_MASK) { | |
832 if (pl->prev_min == -1) { | |
833 pl->prev_min = pl->prev_selected; | |
834 pl->prev_max = pl->prev_selected; | |
835 } | |
836 if (nr < pl->prev_min) | |
837 pl->prev_min = nr; | |
838 else if (nr > pl->prev_max) | |
839 pl->prev_max = nr; | |
840 } | |
841 else | |
842 pl->prev_min = -1; | |
843 pl->prev_selected = nr; | |
844 priv->drag_pos = nr - pl->first; | |
845 } | |
846 } | |
847 if (event->type == GDK_2BUTTON_PRESS) { | |
848 /* | |
849 * Ungrab the pointer to prevent us from | |
850 * hanging on to it during the sometimes slow | |
851 * playback_initiate(). | |
852 */ | |
853 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
854 playlist_set_position(playlist, nr); | |
855 if (!playback_get_playing()) | |
856 playback_initiate(); | |
857 } | |
858 | |
859 priv->dragging = TRUE; | |
860 } | |
861 playlistwin_update_list(playlist); | |
3276 | 862 ui_skinned_playlist_popup_hide(widget); |
863 ui_skinned_playlist_popup_timer_stop(widget); | |
3217 | 864 |
865 return TRUE; | |
866 } | |
867 | |
868 static gboolean ui_skinned_playlist_button_release(GtkWidget *widget, GdkEventButton *event) { | |
869 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(widget); | |
870 | |
3998
351dc6ef07b9
I think it should work this way
Tomasz Mon <desowin@gmail.com>
parents:
3939
diff
changeset
|
871 priv->dragging = FALSE; |
351dc6ef07b9
I think it should work this way
Tomasz Mon <desowin@gmail.com>
parents:
3939
diff
changeset
|
872 priv->auto_drag_down = FALSE; |
351dc6ef07b9
I think it should work this way
Tomasz Mon <desowin@gmail.com>
parents:
3939
diff
changeset
|
873 priv->auto_drag_up = FALSE; |
351dc6ef07b9
I think it should work this way
Tomasz Mon <desowin@gmail.com>
parents:
3939
diff
changeset
|
874 gtk_widget_queue_draw(widget); |
3276 | 875 |
876 ui_skinned_playlist_popup_hide(widget); | |
877 ui_skinned_playlist_popup_timer_stop(widget); | |
3217 | 878 return TRUE; |
879 } | |
880 | |
881 static gboolean ui_skinned_playlist_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
882 UiSkinnedPlaylist *pl = UI_SKINNED_PLAYLIST(widget); | |
883 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(widget); | |
884 | |
885 gint nr, y, off, i; | |
886 if (priv->dragging) { | |
887 y = event->y; | |
888 nr = (y / pl->fheight); | |
889 if (nr < 0) { | |
890 nr = 0; | |
891 if (!priv->auto_drag_up) { | |
892 priv->auto_drag_up = TRUE; | |
893 priv->auto_drag_up_tag = | |
894 g_timeout_add(100, ui_skinned_playlist_auto_drag_up_func, pl); | |
895 } | |
896 } | |
897 else if (priv->auto_drag_up) | |
898 priv->auto_drag_up = FALSE; | |
899 | |
900 if (nr >= pl->num_visible) { | |
901 nr = pl->num_visible - 1; | |
902 if (!priv->auto_drag_down) { | |
903 priv->auto_drag_down = TRUE; | |
904 priv->auto_drag_down_tag = | |
905 g_timeout_add(100, ui_skinned_playlist_auto_drag_down_func, pl); | |
906 } | |
907 } | |
908 else if (priv->auto_drag_down) | |
909 priv->auto_drag_down = FALSE; | |
910 | |
911 off = nr - priv->drag_pos; | |
912 if (off) { | |
913 for (i = 0; i < abs(off); i++) { | |
914 if (off < 0) | |
915 ui_skinned_playlist_move_up(pl); | |
916 else | |
917 ui_skinned_playlist_move_down(pl); | |
918 | |
919 } | |
920 playlistwin_update_list(playlist_get_active()); | |
921 } | |
922 priv->drag_pos = nr; | |
3333
612007382f0c
show fileinfopopup only when cfg.show_filepopup_for_tuple is TRUE
Tomasz Mon <desowin@gmail.com>
parents:
3298
diff
changeset
|
923 } else if (cfg.show_filepopup_for_tuple) { |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
924 gint pos = ui_skinned_playlist_get_position(widget, event->x, event->y); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
925 gint cur_pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "popup_position")); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
926 if (pos != cur_pos) { |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
927 g_object_set_data(G_OBJECT(widget), "popup_position", GINT_TO_POINTER(pos)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
928 ui_skinned_playlist_popup_hide(widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
929 ui_skinned_playlist_popup_timer_stop(widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
930 if (pos != -1) |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
931 ui_skinned_playlist_popup_timer_start(widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
932 } |
3217 | 933 } |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
934 |
3217 | 935 return TRUE; |
936 } | |
937 | |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
938 static gboolean ui_skinned_playlist_leave_notify(GtkWidget *widget, GdkEventCrossing *event) { |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
939 ui_skinned_playlist_popup_hide(widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
940 ui_skinned_playlist_popup_timer_stop(widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
941 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
942 return FALSE; |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
943 } |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
944 |
3217 | 945 static void ui_skinned_playlist_redraw(UiSkinnedPlaylist *playlist) { |
946 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(playlist); | |
947 | |
948 if (priv->resize_height || priv->resize_width) | |
949 gtk_widget_set_size_request(GTK_WIDGET(playlist), priv->width+priv->resize_width, priv->height+priv->resize_height); | |
950 | |
951 gtk_widget_queue_draw(GTK_WIDGET(playlist)); | |
952 } | |
953 | |
954 void ui_skinned_playlist_set_font(const gchar * font) { | |
955 /* Welcome to bad hack central 2k3 */ | |
956 gchar *font_lower; | |
957 gint width_temp; | |
958 gint width_temp_0; | |
959 | |
960 playlist_list_font = pango_font_description_from_string(font); | |
961 | |
962 text_get_extents(font, | |
963 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ", | |
964 &width_approx_letters, NULL, &ascent, &descent); | |
965 | |
966 width_approx_letters = (width_approx_letters / 53); | |
967 | |
968 /* Experimental: We don't weigh the 1 into total because it's width is almost always | |
969 * very different from the rest | |
970 */ | |
971 text_get_extents(font, "023456789", &width_approx_digits, NULL, NULL, | |
972 NULL); | |
973 width_approx_digits = (width_approx_digits / 9); | |
974 | |
975 /* Precache some often used calculations */ | |
976 width_approx_digits_half = width_approx_digits / 2; | |
977 | |
978 /* FIXME: We assume that any other number is broader than the "1" */ | |
979 text_get_extents(font, "1", &width_temp, NULL, NULL, NULL); | |
980 text_get_extents(font, "2", &width_temp_0, NULL, NULL, NULL); | |
981 | |
982 if (abs(width_temp_0 - width_temp) < 2) { | |
983 width_delta_digit_one = 0; | |
984 } | |
985 else { | |
986 width_delta_digit_one = ((width_temp_0 - width_temp) / 2) + 2; | |
987 } | |
988 | |
989 text_get_extents(font, ":", &width_colon, NULL, NULL, NULL); | |
990 width_colon_third = width_colon / 4; | |
991 | |
992 font_lower = g_utf8_strdown(font, strlen(font)); | |
993 /* This doesn't take any i18n into account, but i think there is none with TTF fonts | |
994 * FIXME: This can probably be retrieved trough Pango too | |
995 */ | |
996 has_slant = g_strstr_len(font_lower, strlen(font_lower), "oblique") | |
997 || g_strstr_len(font_lower, strlen(font_lower), "italic"); | |
998 | |
999 g_free(font_lower); | |
1000 } | |
1001 | |
1002 void ui_skinned_playlist_resize_relative(GtkWidget *widget, gint w, gint h) { | |
1003 UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(widget); | |
1004 priv->resize_width += w; | |
1005 priv->resize_height += h; | |
1006 } | |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1007 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1008 static gboolean ui_skinned_playlist_popup_show(gpointer data) { |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1009 GtkWidget *widget = data; |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1010 gint pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "popup_position")); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1011 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1012 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "timer_active")) == 1 && pos != -1) { |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3276
diff
changeset
|
1013 Tuple *tuple; |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1014 Playlist *pl_active = playlist_get_active(); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1015 GtkWidget *popup = g_object_get_data(G_OBJECT(widget), "popup"); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1016 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1017 tuple = playlist_get_tuple(pl_active, pos); |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3370
diff
changeset
|
1018 if ((tuple == NULL) || (tuple_get_int(tuple, FIELD_LENGTH, NULL) < 1)) { |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1019 gchar *title = playlist_get_songtitle(pl_active, pos); |
3755
2ca446f02d97
export the fileinfopopup API.
William Pitcock <nenolod@atheme.org>
parents:
3514
diff
changeset
|
1020 fileinfopopup_show_from_title(popup, title); |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1021 g_free(title); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1022 } else { |
3755
2ca446f02d97
export the fileinfopopup API.
William Pitcock <nenolod@atheme.org>
parents:
3514
diff
changeset
|
1023 fileinfopopup_show_from_tuple(popup , tuple); |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1024 } |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1025 g_object_set_data(G_OBJECT(widget), "popup_active" , GINT_TO_POINTER(1)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1026 } |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1027 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1028 ui_skinned_playlist_popup_timer_stop(widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1029 return FALSE; |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1030 } |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1031 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1032 static void ui_skinned_playlist_popup_hide(GtkWidget *widget) { |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1033 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "popup_active")) == 1) { |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1034 GtkWidget *popup = g_object_get_data(G_OBJECT(widget), "popup"); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1035 g_object_set_data(G_OBJECT(widget), "popup_active", GINT_TO_POINTER(0)); |
3755
2ca446f02d97
export the fileinfopopup API.
William Pitcock <nenolod@atheme.org>
parents:
3514
diff
changeset
|
1036 fileinfopopup_hide(popup, NULL); |
3271
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1037 } |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1038 } |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1039 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1040 static void ui_skinned_playlist_popup_timer_start(GtkWidget *widget) { |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1041 gint timer_id = g_timeout_add(cfg.filepopup_delay*100, ui_skinned_playlist_popup_show, widget); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1042 g_object_set_data(G_OBJECT(widget), "timer_id", GINT_TO_POINTER(timer_id)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1043 g_object_set_data(G_OBJECT(widget), "timer_active", GINT_TO_POINTER(1)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1044 } |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1045 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1046 static void ui_skinned_playlist_popup_timer_stop(GtkWidget *widget) { |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1047 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "timer_active")) == 1) |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1048 g_source_remove(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "timer_id"))); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1049 |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1050 g_object_set_data(G_OBJECT(widget), "timer_id", GINT_TO_POINTER(0)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1051 g_object_set_data(G_OBJECT(widget), "timer_active", GINT_TO_POINTER(0)); |
5f40f7d2887f
better way to show fileinfopopup
Tomasz Mon <desowin@gmail.com>
parents:
3251
diff
changeset
|
1052 } |