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