Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_number.c @ 3032:6baa6eaf8290
Don't use deprecated gtk_type_class()
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Fri, 10 Apr 2009 11:02:41 +0200 |
parents | 963796db51ea |
children | ab8771a5f654 |
rev | line source |
---|---|
2588 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Tomasz Moń | |
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 #include "ui_skinned_number.h" | |
28 #include "skins_cfg.h" | |
29 #include "strings.h" | |
30 #include <string.h> | |
31 #include <ctype.h> | |
32 #include <gtk/gtkmain.h> | |
33 #include <gtk/gtkmarshal.h> | |
34 | |
35 #define UI_TYPE_SKINNED_NUMBER (ui_skinned_number_get_type()) | |
36 | |
37 enum { | |
38 DOUBLED, | |
39 LAST_SIGNAL | |
40 }; | |
41 | |
42 static void ui_skinned_number_class_init (UiSkinnedNumberClass *klass); | |
43 static void ui_skinned_number_init (UiSkinnedNumber *number); | |
44 static void ui_skinned_number_destroy (GtkObject *object); | |
45 static void ui_skinned_number_realize (GtkWidget *widget); | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
46 static void ui_skinned_number_unrealize (GtkWidget *widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
47 static void ui_skinned_number_map (GtkWidget *widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
48 static void ui_skinned_number_unmap (GtkWidget *widget); |
2588 | 49 static void ui_skinned_number_size_request (GtkWidget *widget, GtkRequisition *requisition); |
50 static void ui_skinned_number_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
51 static gboolean ui_skinned_number_expose (GtkWidget *widget, GdkEventExpose *event); | |
52 static void ui_skinned_number_toggle_scaled (UiSkinnedNumber *number); | |
53 | |
54 static GtkWidgetClass *parent_class = NULL; | |
55 static guint number_signals[LAST_SIGNAL] = { 0 }; | |
56 | |
57 GType ui_skinned_number_get_type() { | |
58 static GType number_type = 0; | |
59 if (!number_type) { | |
60 static const GTypeInfo number_info = { | |
61 sizeof (UiSkinnedNumberClass), | |
62 NULL, | |
63 NULL, | |
64 (GClassInitFunc) ui_skinned_number_class_init, | |
65 NULL, | |
66 NULL, | |
67 sizeof (UiSkinnedNumber), | |
68 0, | |
69 (GInstanceInitFunc) ui_skinned_number_init, | |
70 }; | |
2590 | 71 number_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedNumber", &number_info, 0); |
2588 | 72 } |
73 | |
74 return number_type; | |
75 } | |
76 | |
77 static void ui_skinned_number_class_init(UiSkinnedNumberClass *klass) { | |
78 GtkObjectClass *object_class; | |
79 GtkWidgetClass *widget_class; | |
80 | |
81 object_class = (GtkObjectClass*) klass; | |
82 widget_class = (GtkWidgetClass*) klass; | |
3032
6baa6eaf8290
Don't use deprecated gtk_type_class()
Tomasz Mon <desowin@gmail.com>
parents:
3017
diff
changeset
|
83 parent_class = g_type_class_peek_parent(klass); |
2588 | 84 |
85 object_class->destroy = ui_skinned_number_destroy; | |
86 | |
87 widget_class->realize = ui_skinned_number_realize; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
88 widget_class->unrealize = ui_skinned_number_unrealize; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
89 widget_class->map = ui_skinned_number_map; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
90 widget_class->unmap = ui_skinned_number_unmap; |
2588 | 91 widget_class->expose_event = ui_skinned_number_expose; |
92 widget_class->size_request = ui_skinned_number_size_request; | |
93 widget_class->size_allocate = ui_skinned_number_size_allocate; | |
94 | |
95 klass->scaled = ui_skinned_number_toggle_scaled; | |
96 | |
97 number_signals[DOUBLED] = | |
98 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
99 G_STRUCT_OFFSET (UiSkinnedNumberClass, scaled), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2888
diff
changeset
|
100 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2588 | 101 } |
102 | |
103 static void ui_skinned_number_init(UiSkinnedNumber *number) { | |
104 number->width = 9; | |
105 number->height = 13; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
106 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
107 number->event_window = NULL; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
108 GTK_WIDGET_SET_FLAGS(number, GTK_NO_WINDOW); |
2588 | 109 } |
110 | |
111 GtkWidget* ui_skinned_number_new(GtkWidget *fixed, gint x, gint y, SkinPixmapId si) { | |
112 UiSkinnedNumber *number = g_object_new (ui_skinned_number_get_type (), NULL); | |
113 | |
114 number->x = x; | |
115 number->y = y; | |
116 number->num = 0; | |
117 number->skin_index = si; | |
118 | |
119 number->scaled = FALSE; | |
120 | |
121 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(number), number->x, number->y); | |
122 | |
123 return GTK_WIDGET(number); | |
124 } | |
125 | |
126 static void ui_skinned_number_destroy(GtkObject *object) { | |
127 UiSkinnedNumber *number; | |
128 | |
129 g_return_if_fail (object != NULL); | |
130 g_return_if_fail (UI_SKINNED_IS_NUMBER (object)); | |
131 | |
132 number = UI_SKINNED_NUMBER (object); | |
133 | |
134 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
135 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
136 } | |
137 | |
138 static void ui_skinned_number_realize(GtkWidget *widget) { | |
139 UiSkinnedNumber *number; | |
140 GdkWindowAttr attributes; | |
141 gint attributes_mask; | |
142 | |
143 g_return_if_fail (widget != NULL); | |
144 g_return_if_fail (UI_SKINNED_IS_NUMBER(widget)); | |
145 | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
146 if (GTK_WIDGET_CLASS (parent_class)->realize) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
147 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); |
2588 | 148 number = UI_SKINNED_NUMBER(widget); |
149 | |
150 attributes.x = widget->allocation.x; | |
151 attributes.y = widget->allocation.y; | |
152 attributes.width = widget->allocation.width; | |
153 attributes.height = widget->allocation.height; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
154 attributes.wclass = GDK_INPUT_ONLY; |
2588 | 155 attributes.window_type = GDK_WINDOW_CHILD; |
156 attributes.event_mask = gtk_widget_get_events(widget); | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
157 attributes.event_mask |= GDK_BUTTON_PRESS_MASK; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
158 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
159 attributes_mask = GDK_WA_X | GDK_WA_Y; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
160 number->event_window = gdk_window_new (widget->window, &attributes, attributes_mask); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
161 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
162 gdk_window_set_user_data(number->event_window, widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
163 } |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
164 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
165 static void ui_skinned_number_unrealize(GtkWidget *widget) { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
166 UiSkinnedNumber *number = UI_SKINNED_NUMBER(widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
167 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
168 if ( number->event_window != NULL ) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
169 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
170 gdk_window_set_user_data( number->event_window , NULL ); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
171 gdk_window_destroy( number->event_window ); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
172 number->event_window = NULL; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
173 } |
2588 | 174 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
175 if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
176 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
177 } |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
178 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
179 static void ui_skinned_number_map (GtkWidget *widget) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
180 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
181 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
182 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
183 if (number->event_window != NULL) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
184 gdk_window_show (number->event_window); |
2588 | 185 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
186 if (GTK_WIDGET_CLASS (parent_class)->map) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
187 (* GTK_WIDGET_CLASS (parent_class)->map) (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
188 } |
2588 | 189 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
190 static void ui_skinned_number_unmap (GtkWidget *widget) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
191 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
192 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
193 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
194 if (number->event_window != NULL) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
195 gdk_window_hide (number->event_window); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
196 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
197 if (GTK_WIDGET_CLASS (parent_class)->unmap) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
198 (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); |
2588 | 199 } |
200 | |
201 static void ui_skinned_number_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
202 UiSkinnedNumber *number = UI_SKINNED_NUMBER(widget); | |
203 | |
204 requisition->width = number->width * ( number->scaled ? config.scale_factor : 1 ); | |
205 requisition->height = number->height*( number->scaled ? config.scale_factor : 1); | |
206 } | |
207 | |
208 static void ui_skinned_number_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
209 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
210 | |
211 widget->allocation = *allocation; | |
212 widget->allocation.x *= (number->scaled ? config.scale_factor: 1 ); | |
213 widget->allocation.y *= (number->scaled ? config.scale_factor: 1 ); | |
214 if (GTK_WIDGET_REALIZED (widget)) | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
215 if (number->event_window) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
216 gdk_window_move_resize(number->event_window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); |
2588 | 217 |
218 number->x = widget->allocation.x/(number->scaled ? config.scale_factor : 1); | |
219 number->y = widget->allocation.y/(number->scaled ? config.scale_factor : 1); | |
220 } | |
221 | |
222 static gboolean ui_skinned_number_expose(GtkWidget *widget, GdkEventExpose *event) { | |
223 g_return_val_if_fail (widget != NULL, FALSE); | |
224 g_return_val_if_fail (UI_SKINNED_IS_NUMBER (widget), FALSE); | |
225 g_return_val_if_fail (event != NULL, FALSE); | |
226 | |
227 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
228 g_return_val_if_fail (number->width > 0 && number->height > 0, FALSE); | |
229 | |
230 GdkPixbuf *obj; | |
231 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, number->width, number->height); | |
232 | |
233 if (number->num > 11 || number->num < 0) | |
234 number->num = 10; | |
235 | |
236 skin_draw_pixbuf(widget, aud_active_skin, obj, | |
237 number->skin_index, number->num * 9, 0, | |
238 0, 0, number->width, number->height); | |
239 | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
240 ui_skinned_widget_draw_with_coordinates(widget, obj, number->width, number->height, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
241 widget->allocation.x, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
242 widget->allocation.y, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
243 number->scaled); |
2588 | 244 |
245 g_object_unref(obj); | |
246 | |
247 return FALSE; | |
248 } | |
249 | |
250 static void ui_skinned_number_toggle_scaled(UiSkinnedNumber *number) { | |
251 GtkWidget *widget = GTK_WIDGET (number); | |
252 number->scaled = !number->scaled; | |
253 | |
254 gtk_widget_set_size_request(widget, number->width * ( number->scaled ? config.scale_factor : 1), | |
255 number->height * ( number->scaled ? config.scale_factor : 1) ); | |
256 | |
257 gtk_widget_queue_draw(GTK_WIDGET(number)); | |
258 } | |
259 | |
260 void ui_skinned_number_set_number(GtkWidget *widget, gint num) { | |
261 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget)); | |
262 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
263 | |
264 if (number->num == num) | |
265 return; | |
266 | |
267 number->num = num; | |
268 gtk_widget_queue_draw(GTK_WIDGET(number)); | |
269 } | |
270 | |
271 void ui_skinned_number_set_size(GtkWidget *widget, gint width, gint height) { | |
272 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget)); | |
273 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
274 | |
275 number->width = width; | |
276 number->height = height; | |
277 | |
278 gtk_widget_set_size_request(widget, width*(number->scaled ? config.scale_factor : 1 ), | |
279 height*(number->scaled ? config.scale_factor : 1 )); | |
280 } |