comparison audacious/sbutton.c @ 0:cb178e5ad177 trunk

[svn] Import audacious source.
author nenolod
date Mon, 24 Oct 2005 03:06:47 -0700
parents
children f12d7e208b43
comparison
equal deleted inserted replaced
-1:000000000000 0:cb178e5ad177
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 "sbutton.h"
23
24 #include <glib.h>
25 #include <gtk/gtk.h>
26 #include <gdk/gdk.h>
27
28 void
29 sbutton_button_press_cb(GtkWidget * widget,
30 GdkEventButton * event,
31 SButton * button)
32 {
33 if (event->button != 1)
34 return;
35
36 if (widget_contains(&button->sb_widget, event->x, event->y)) {
37 button->sb_pressed = 1;
38 button->sb_inside = 1;
39 }
40 }
41
42 void
43 sbutton_button_release_cb(GtkWidget * widget, GdkEventButton * event,
44 SButton * button)
45 {
46 if (event->button != 1)
47 return;
48 if (button->sb_inside && button->sb_pressed) {
49 button->sb_inside = 0;
50 if (button->sb_push_cb)
51 button->sb_push_cb();
52 }
53 if (button->sb_pressed)
54 button->sb_pressed = 0;
55 }
56
57 void
58 sbutton_motion_cb(GtkWidget * widget, GdkEventMotion * event,
59 SButton * button)
60 {
61 int inside;
62
63 if (!button->sb_pressed)
64 return;
65
66 inside = widget_contains(&button->sb_widget, event->x, event->y);
67
68 if (inside != button->sb_inside)
69 button->sb_inside = inside;
70 }
71
72 SButton *
73 create_sbutton(GList ** wlist, GdkPixmap * parent, GdkGC * gc,
74 gint x, gint y, gint w, gint h, void (*cb) (void))
75 {
76 SButton *b;
77
78 b = g_new0(SButton, 1);
79 widget_init(&b->sb_widget, parent, gc, x, y, w, h, 1);
80 b->sb_widget.button_press_cb =
81 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
82 sbutton_button_press_cb;
83 b->sb_widget.button_release_cb =
84 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
85 sbutton_button_release_cb;
86 b->sb_widget.motion_cb =
87 (void (*)(GtkWidget *, GdkEventMotion *, gpointer))
88 sbutton_motion_cb;
89 b->sb_push_cb = cb;
90
91 widget_list_add(wlist, WIDGET(b));
92 return b;
93 }
94
95 void
96 free_sbutton(SButton * b)
97 {
98 g_free(b);
99 }