0
|
1 /* BMP - Cross-platform multimedia player
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
3 *
|
|
4 * Based on XMMS:
|
|
5 * Copyright (C) 1998-2003 XMMS development team.
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
20 */
|
|
21
|
|
22 #include "playlist_popup.h"
|
|
23
|
|
24 #include <glib.h>
|
|
25 #include <gtk/gtk.h>
|
|
26 #include <gdk/gdk.h>
|
|
27 #include <string.h>
|
|
28
|
|
29 #include "skin.h"
|
|
30 #include "util.h"
|
|
31
|
|
32 typedef struct {
|
|
33 GtkWidget *window;
|
|
34 GdkGC *gc;
|
|
35 gint num_items;
|
|
36 gint *nx, *ny;
|
|
37 gint *sx, *sy;
|
|
38 gint barx, bary;
|
|
39 gint active, base;
|
|
40 void (*handler) (gint item);
|
|
41 } PlaylistPopup;
|
|
42
|
|
43 static PlaylistPopup *popup = NULL;
|
|
44
|
|
45 static void
|
|
46 playlist_popup_draw(PlaylistPopup * popup)
|
|
47 {
|
|
48 gint i;
|
|
49
|
|
50 skin_draw_pixmap(bmp_active_skin, popup->window->window, popup->gc,
|
|
51 SKIN_PLEDIT, popup->barx, popup->bary, 0, 0, 3,
|
|
52 popup->num_items * 18);
|
|
53 for (i = 0; i < popup->num_items; i++) {
|
|
54 if (i == popup->active)
|
|
55 skin_draw_pixmap(bmp_active_skin, popup->window->window,
|
|
56 popup->gc, SKIN_PLEDIT, popup->sx[i],
|
|
57 popup->sy[i], 3, i * 18, 22, 18);
|
|
58 else
|
|
59 skin_draw_pixmap(bmp_active_skin, popup->window->window,
|
|
60 popup->gc, SKIN_PLEDIT, popup->nx[i],
|
|
61 popup->ny[i], 3, i * 18, 22, 18);
|
|
62 }
|
|
63 /* FIXME: What is this flush doing here? */
|
|
64 gdk_flush();
|
|
65 }
|
|
66
|
|
67 void
|
|
68 playlist_popup_destroy(void)
|
|
69 {
|
|
70 if (popup) {
|
|
71 gdk_pointer_ungrab(GDK_CURRENT_TIME);
|
|
72 gdk_flush();
|
|
73 gtk_widget_destroy(popup->window);
|
|
74 g_object_unref(popup->gc);
|
|
75 g_free(popup->nx);
|
|
76 g_free(popup->ny);
|
|
77 g_free(popup->sx);
|
|
78 g_free(popup->sy);
|
|
79 if (popup->handler && popup->active != -1)
|
|
80 popup->handler(popup->active + popup->base);
|
|
81 g_free(popup);
|
|
82 popup = NULL;
|
|
83 }
|
|
84 }
|
|
85
|
|
86 static void
|
|
87 playlist_popup_expose(GtkWidget * widget, GdkEvent * event,
|
|
88 gpointer callback_data)
|
|
89 {
|
|
90 playlist_popup_draw(popup);
|
|
91 }
|
|
92
|
|
93 static void
|
|
94 playlist_popup_motion(GtkWidget * widget,
|
|
95 GdkEventMotion * event, gpointer callback_data)
|
|
96 {
|
|
97 gint active;
|
|
98
|
|
99 if (event->x >= 0 && event->x < 25 && event->y >= 0
|
|
100 && event->y < popup->num_items * 18) {
|
|
101 active = event->y / 18;
|
|
102 if (popup->active != active) {
|
|
103 popup->active = active;
|
|
104 playlist_popup_draw(popup);
|
|
105 }
|
|
106 }
|
|
107 else if (popup->active != -1) {
|
|
108 popup->active = -1;
|
|
109 playlist_popup_draw(popup);
|
|
110 }
|
|
111 }
|
|
112
|
|
113 static void
|
|
114 playlist_popup_release(GtkWidget * widget,
|
|
115 GdkEventButton * event, gpointer callback_data)
|
|
116 {
|
|
117 playlist_popup_destroy();
|
|
118 }
|
|
119
|
|
120 void
|
|
121 playlist_popup(gint x, gint y, gint num_items, gint * nx, gint * ny,
|
|
122 gint * sx, gint * sy, gint barx, gint bary, gint base,
|
|
123 void (*handler) (gint item))
|
|
124 {
|
|
125 if (popup)
|
|
126 playlist_popup_destroy();
|
|
127 popup = g_new0(PlaylistPopup, 1);
|
|
128 popup->num_items = num_items;
|
|
129 popup->nx = g_new0(gint, num_items);
|
|
130 memcpy(popup->nx, nx, sizeof(gint) * num_items);
|
|
131 popup->ny = g_new0(gint, num_items);
|
|
132 memcpy(popup->ny, ny, sizeof(gint) * num_items);
|
|
133 popup->sx = g_new0(gint, num_items);
|
|
134 memcpy(popup->sx, sx, sizeof(gint) * num_items);
|
|
135 popup->sy = g_new0(gint, num_items);
|
|
136 memcpy(popup->sy, sy, sizeof(gint) * num_items);
|
|
137 popup->barx = barx;
|
|
138 popup->bary = bary;
|
|
139 popup->handler = handler;
|
|
140 popup->active = num_items - 1;
|
|
141 popup->base = base;
|
|
142
|
|
143 popup->window = gtk_window_new(GTK_WINDOW_POPUP);
|
|
144 gtk_window_set_default_size(GTK_WINDOW(popup->window), 25,
|
|
145 num_items * 18);
|
|
146 gtk_widget_set_app_paintable(popup->window, TRUE);
|
|
147 gtk_widget_set_events(popup->window,
|
|
148 GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK
|
|
149 | GDK_EXPOSURE_MASK);
|
|
150 gtk_widget_realize(popup->window);
|
|
151
|
|
152 popup->gc = gdk_gc_new(popup->window->window);
|
|
153
|
|
154 g_signal_connect(popup->window, "expose_event",
|
|
155 G_CALLBACK(playlist_popup_expose), NULL);
|
|
156 g_signal_connect(popup->window, "motion_notify_event",
|
|
157 G_CALLBACK(playlist_popup_motion), NULL);
|
|
158 g_signal_connect(popup->window, "button_release_event",
|
|
159 G_CALLBACK(playlist_popup_release), NULL);
|
|
160
|
|
161 util_set_cursor(popup->window);
|
|
162
|
|
163 gtk_window_move(GTK_WINDOW(popup->window), x - 1, y - 1);
|
|
164 gtk_widget_show(popup->window);
|
|
165 gdk_window_raise(popup->window->window);
|
|
166 gdk_flush();
|
|
167
|
|
168 playlist_popup_draw(popup);
|
|
169
|
|
170 gdk_pointer_grab(popup->window->window, FALSE,
|
|
171 GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
|
|
172 NULL, NULL, GDK_CURRENT_TIME);
|
|
173 gdk_flush();
|
|
174 }
|