1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
diff -Naur e-uae-0.8.28.orig/src/gui-gtk/led.c e-uae-0.8.28/src/gui-gtk/led.c
--- e-uae-0.8.28.orig/src/gui-gtk/led.c 2004-06-15 01:14:49.000000000 +0400
+++ e-uae-0.8.28/src/gui-gtk/led.c 2006-07-18 17:01:48.000000000 +0400
@@ -1,15 +1,17 @@
-/*
- * led.c
- *
- * Copyright 2004 Martin Garton
- */
+ /*
+ * E-UAE - The portable Amiga Emulator
+ *
+ * Custom Gtk+ LED widget
+ *
+ * Copyright 2004 Martin Garton
+ * Copyright 2006 Richard Drummond
+ */
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
-#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "led.h"
@@ -21,14 +23,19 @@
static void led_class_init (LedClass *class);
static gint led_expose (GtkWidget *w, GdkEventExpose *event);
static void led_destroy (GtkObject *object);
+static void led_realize (GtkWidget *widget);
+static void led_unrealize (GtkWidget *widget);
+static void led_size_request (GtkWidget *widget, GtkRequisition *requisition);
+static void led_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
+
guint led_get_type ()
{
static guint led_type = 0;
if (!led_type) {
- GtkTypeInfo led_info = {
- "Led",
+ static const GtkTypeInfo led_info = {
+ (char *) "Led",
sizeof (Led),
sizeof (LedClass),
(GtkClassInitFunc) led_class_init,
@@ -48,39 +55,102 @@
{
GtkObjectClass *object_class = (GtkObjectClass *) class;
GtkWidgetClass *widget_class = (GtkWidgetClass *) class;
- parent_class = gtk_type_class (gtk_object_get_type ());
+ parent_class = gtk_type_class (gtk_widget_get_type ());
object_class->destroy = led_destroy;
widget_class->expose_event = led_expose;
+ widget_class->realize = led_realize;
+ widget_class->unrealize = led_unrealize;
+ widget_class->size_request = led_size_request;
+ widget_class->size_allocate = led_size_allocate;
}
static void led_init (Led *theled)
{
theled->color = LED_OFF;
-
- GTK_WIDGET (theled)->requisition.width = LED_W + GTK_MISC (theled)->xpad * 2;
- GTK_WIDGET (theled)->requisition.height = LED_H + GTK_MISC (theled)->ypad * 2;
}
-
GtkWidget *led_new (void)
{
return gtk_type_new (led_get_type ());
}
-
static gint led_expose (GtkWidget *w, GdkEventExpose *event)
{
if (w && GTK_WIDGET_DRAWABLE (w)) {
- GtkStyle *style = gtk_style_copy (w->style);
- style->bg[GTK_STATE_NORMAL] = LED (w)->color;
- gtk_style_attach (style, w->window);
- gtk_draw_flat_box (style, w->window, GTK_STATE_NORMAL, GTK_SHADOW_NONE,
- 0, 0, LED_W, LED_H);
+ Led *theled = LED (w);
+ gdk_draw_rectangle (w->window, theled->gc, TRUE, 0, 0,
+ w->allocation.width, w->allocation.height);
}
return 0;
}
+static void led_realize (GtkWidget *widget)
+{
+ Led *theled;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (IS_LED (widget));
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ theled = LED (widget);
+
+ attributes.x = widget->allocation.x;
+ attributes.y = widget->allocation.y;
+ attributes.width = widget->allocation.width;
+ attributes.height = widget->allocation.height;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
+
+ gdk_window_set_user_data (widget->window, widget);
+
+ theled->gc = gdk_gc_new (widget->window);
+ gdk_gc_set_rgb_fg_color (theled->gc, &theled->color);
+
+ led_expose (widget, NULL);
+}
+
+static void led_unrealize (GtkWidget *widget)
+{
+ Led *theled = LED (widget);
+
+ g_object_unref (theled->gc);
+ theled->gc = NULL;
+
+ GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+}
+
+static void led_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+ requisition->width = LED_W;
+ requisition->height = LED_H;
+}
+
+static void led_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ Led *theled = LED (widget);
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (IS_LED (widget));
+ g_return_if_fail (allocation != NULL);
+
+ widget->allocation = *allocation;
+
+ if (GTK_WIDGET_REALIZED (widget)) {
+ gdk_window_move_resize (widget->window,
+ allocation->x, allocation->y,
+ allocation->width, allocation->height);
+ }
+}
+
static void led_destroy (GtkObject *o)
{
g_return_if_fail (o != NULL);
@@ -95,6 +165,8 @@
{
l->color = col;
- if (GTK_WIDGET_DRAWABLE (l))
+ if (GTK_WIDGET_REALIZED (l)) {
+ gdk_gc_set_rgb_fg_color (l->gc, &l->color);
led_expose (GTK_WIDGET (l), NULL);
+ }
}
diff -Naur e-uae-0.8.28.orig/src/gui-gtk/led.h e-uae-0.8.28/src/gui-gtk/led.h
--- e-uae-0.8.28.orig/src/gui-gtk/led.h 2004-05-20 00:56:23.000000000 +0400
+++ e-uae-0.8.28/src/gui-gtk/led.h 2006-07-18 17:01:42.000000000 +0400
@@ -1,10 +1,16 @@
-/* led.h */
+ /*
+ * E-UAE - The portable Amiga Emulator
+ *
+ * Custom Gtk+ LED widget
+ *
+ * Copyright 2004 Martin Garton
+ * Copyright 2006 Richard Drummond
+ */
#ifndef __LED_H__
#define __LED_H__
#include <gdk/gdk.h>
-#include <gtk/gtkmisc.h>
#ifdef __cplusplus
extern "C" {
@@ -21,15 +27,15 @@
struct _Led
{
- GtkMisc widget;
- GdkColor color;
+ GtkWidget widget;
+
+ GdkGC *gc;
+ GdkColor color;
};
struct _LedClass
{
GtkWidgetClass parent_class;
-
- //void (* led) (Led *led );
};
guint led_get_type (void);
|