4 #ifndef [PREF]_CTL_[TYPE]_H
5 #define [PREF]_CTL_[TYPE]_H
11 #define [PREF]_TYPE_[TYPE] ([pref]_[type]_get_type())
12 #define [PREF]_[TYPE](obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), [PREF]_TYPE_[TYPE], [Pref][Type]))
13 #define [PREF]_IS_[TYPE](obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), [PREF]_TYPE_[TYPE]))
14 #define [PREF]_[TYPE]_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), [PREF]_TYPE_[TYPE], [Pref][Type]Class))
15 #define [PREF]_IS_[TYPE]_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), [PREF]_TYPE_[TYPE]))
17 /// Instance object for [Pref][Type]
23 /// Class object for [Pref][Type]
24 struct [Pref][Type]Class
26 GtkWidgetClass parent_class;
29 /// Create new [Pref][Type]
30 extern GtkWidget *[pref]_[type]_new();
33 extern GType [pref]_[type]_get_type();
40 templ_cpp
= """// Source
45 GtkWidget *widget = GTK_WIDGET( g_object_new ([PREF]_TYPE_[TYPE], NULL ));
50 [preftype]_expose (GtkWidget *widget, GdkEventExpose *event)
52 g_assert([PREF]_IS_[TYPE](widget));
54 [PrefType] *self = [PREFTYPE](widget);
55 GdkWindow *window = widget->window;
56 cairo_t *c = gdk_cairo_create(GDK_DRAWABLE(window));
63 [preftype]_realize(GtkWidget *widget)
65 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
67 GdkWindowAttr attributes;
68 attributes.event_mask = GDK_EXPOSURE_MASK | GDK_BUTTON1_MOTION_MASK |
69 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
70 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
71 attributes.x = widget->allocation.x;
72 attributes.y = widget->allocation.y;
73 attributes.width = widget->allocation.width;
74 attributes.height = widget->allocation.height;
75 attributes.wclass = GDK_INPUT_OUTPUT;
76 attributes.window_type = GDK_WINDOW_CHILD;
78 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), &attributes, GDK_WA_X | GDK_WA_Y);
80 gdk_window_set_user_data(widget->window, widget);
81 widget->style = gtk_style_attach(widget->style, widget->window);
85 [preftype]_size_request (GtkWidget *widget,
86 GtkRequisition *requisition)
88 g_assert([PREF]_IS_[TYPE](widget));
90 // width/height is hardwired at 40px now
91 requisition->width = ...;
92 requisition->height = ...;
96 [preftype]_size_allocate (GtkWidget *widget,
97 GtkAllocation *allocation)
99 g_assert([PREF]_IS_[TYPE](widget));
101 widget->allocation = *allocation;
103 if (GTK_WIDGET_REALIZED(widget))
104 gdk_window_move_resize(widget->window, allocation->x, allocation->y, allocation->width, allocation->height );
108 [preftype]_class_init ([PrefType]Class *klass)
110 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
111 widget_class->realize = [preftype]_realize;
112 widget_class->expose_event = [preftype]_expose;
113 widget_class->size_request = [preftype]_size_request;
114 widget_class->size_allocate = [preftype]_size_allocate;
115 // widget_class->button_press_event = [preftype]_button_press;
116 // widget_class->button_release_event = [preftype]_button_release;
117 // widget_class->motion_notify_event = [preftype]_pointer_motion;
118 // widget_class->key_press_event = [preftype]_key_press;
119 // widget_class->scroll_event = [preftype]_scroll;
123 [preftype]_init ([PrefType] *self)
125 GtkWidget *widget = GTK_WIDGET(self);
126 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(self), GTK_CAN_FOCUS);
130 [preftype]_get_type (void)
132 static GType type = 0;
135 static const GTypeInfo type_info = {
136 sizeof([PrefType]Class),
137 NULL, /* base_init */
138 NULL, /* base_finalize */
139 (GClassInitFunc)[preftype]_class_init,
140 NULL, /* class_finalize */
141 NULL, /* class_data */
144 (GInstanceInitFunc)[preftype]_init
147 for (int i = 0; ; i++) {
148 char *name = g_strdup_printf("[PrefType]%u%d",
149 ((unsigned int)(intptr_t)[preftype]_class_init) >> 16, i);
150 if (g_type_from_name(name)) {
154 type = g_type_register_static(GTK_TYPE_WIDGET,
166 def subst(text
, pref
, type):
167 text
= text
.replace("[pref]", pref
.lower()).replace("[PREF]", pref
.upper()).replace("[Pref]", pref
)
168 text
= text
.replace("[type]", type.lower()).replace("[TYPE]", type.upper()).replace("[Type]", type)
169 text
= text
.replace("[preftype]", pref
.lower()+"_"+type.lower()).replace("[PrefType]", pref
+type)
170 text
= text
.replace("[PREFTYPE]", pref
.upper()+"_"+type.upper())
173 print subst(templ_h
, "Calf", "Led")
174 print subst(templ_cpp
, "Calf", "Led")