1 #include "tilda-window.h"
3 static GObjectClass *parent_class = NULL;
5 enum tilda_window_properties {
6 TILDA_WINDOW_NUMBER = 1,
10 tilda_window_instance_init (GTypeInstance *instance,
13 TildaWindow *self = (TildaWindow *) instance;
14 self->dispose_has_run = FALSE;
16 /* Initialize all properties */
17 self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
18 self->terms = g_ptr_array_new ();
20 self->number = 0xdeadbeef;
24 tilda_window_set_property (GObject *object,
29 TildaWindow *self = (TildaWindow *) object;
31 switch (property_id) {
33 case TILDA_WINDOW_NUMBER:
34 self->number = g_value_get_int (value);
35 g_print ("window number: %d\n", self->number);
39 /* We don't have this property */
40 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
46 tilda_window_get_property (GObject *object,
51 TildaWindow *self = (TildaWindow *) object;
53 switch (property_id) {
55 case TILDA_WINDOW_NUMBER:
56 g_value_set_int (value, self->number);
60 /* We don't have this property */
61 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
67 tilda_window_constructor (GType type,
68 guint n_construct_properties,
69 GObjectConstructParam *construct_properties)
73 /* Invoke parent constructor */
74 TildaWindowClass *klass;
75 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
76 obj = parent_class->constructor (type,
77 n_construct_properties,
78 construct_properties);
80 /* Do other stuff here. The object is ready to go now, and all
81 * ctor properties have been set.
83 * TODO: This is the place to do DBus-init */
89 tilda_window_dispose (GObject *obj)
91 TildaWindow *self = (TildaWindow *) obj;
93 /* We don't want to run dispose twice, so just return immediately */
94 if (self->dispose_has_run)
98 * In dispose, you are supposed to free all types referenced from this
99 * object which might themselves hold a reference to self. Generally,
100 * the most simple solution is to unref all members on which you own a
104 /* Chain up to the parent class */
105 G_OBJECT_CLASS (parent_class)->dispose (obj);
109 tilda_window_finalize (GObject *obj)
111 TildaWindow *self = (TildaWindow *) obj;
114 * Here, complete the object's destruction.
115 * You might not need to do much...
117 // TODO: g_free() any primitives here
120 /* Chain up to the parent class */
121 G_OBJECT_CLASS (parent_class)->finalize (obj);
125 tilda_window_class_init (gpointer g_class,
126 gpointer g_class_data)
128 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
129 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
132 /* Hook our functions to this type */
133 gobject_class->set_property = tilda_window_set_property;
134 gobject_class->get_property = tilda_window_get_property;
135 gobject_class->dispose = tilda_window_dispose;
136 gobject_class->finalize = tilda_window_finalize;
137 gobject_class->constructor = tilda_window_constructor;
139 parent_class = g_type_class_peek_parent (klass);
141 /* Install all of the properties */
142 pspec = g_param_spec_int ("number",
144 "Set window's number",
146 INT_MAX, // max value
148 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
150 g_object_class_install_property (gobject_class,
154 /* TODO: more properties */
158 tilda_window_get_type (void)
160 static GType type = 0;
164 static const GTypeInfo info = {
165 sizeof (TildaWindowClass),
166 NULL, /* base_init */
167 NULL, /* base_finalize */
168 tilda_window_class_init, /* class_init */
169 NULL, /* class_finalize */
170 NULL, /* class_data */
171 sizeof (TildaWindow),
173 tilda_window_instance_init, /* instance_init */
176 type = g_type_register_static (G_TYPE_OBJECT,
186 int main (int argc, char *argv[])
189 gint test_number = INT_MIN;
191 /* Initialize the GObject type system */
193 gtk_init (&argc, &argv);
195 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
196 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
197 g_assert (test_number == 10);
199 g_object_unref (G_OBJECT (tw));
201 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
202 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
203 g_assert (test_number == 22);
205 g_object_unref (G_OBJECT (tw));
210 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */