annotate audacious/playlist_popup.c @ 254:5de006f3d342 trunk

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