1 #include "tilda-window.h"
4 tilda_window_add_term (TildaWindow *tw)
6 // FIXME: this is totally bad, but it's a good hack for feasability
7 static gint mynumber = 0;
8 TildaTerminal *tt = g_object_new (TILDA_TYPE_TERMINAL, "number", mynumber++, NULL);
9 g_ptr_array_add (tw->terms, tt);
11 GtkWidget *label = gtk_label_new ("Tilda");
12 gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label);
13 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
14 //gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
16 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1)
17 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE);
23 tilda_window_remove_term (TildaWindow *tw, int number)
27 for (i=0; i<tw->terms->len; ++i)
29 TildaTerminal *tt = g_ptr_array_index (tw->terms, i);
31 if (tt->number == number)
32 g_print ("Need to remove window %d terminal %d\n", tw->number, tt->number);
38 /*******************************************************************************
39 * ALL GOBJECT STUFF BELOW PLEASE
40 ******************************************************************************/
42 static GObjectClass *parent_class = NULL;
44 enum tilda_window_properties {
45 TILDA_WINDOW_NUMBER = 1,
49 tilda_window_instance_init (GTypeInstance *instance,
52 TildaWindow *self = (TildaWindow *) instance;
53 self->dispose_has_run = FALSE;
55 /* Initialize all properties */
56 self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
57 self->notebook = gtk_notebook_new ();
58 self->terms = g_ptr_array_new ();
60 /* Somewhat of a "poison" value, incase we don't set this */
61 self->number = 0xdeadbeef;
65 tilda_window_set_property (GObject *object,
70 TildaWindow *self = (TildaWindow *) object;
72 switch (property_id) {
74 case TILDA_WINDOW_NUMBER:
75 self->number = g_value_get_int (value);
76 g_print ("window number: %d\n", self->number);
80 /* We don't have this property */
81 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
87 tilda_window_get_property (GObject *object,
92 TildaWindow *self = (TildaWindow *) object;
94 switch (property_id) {
96 case TILDA_WINDOW_NUMBER:
97 g_value_set_int (value, self->number);
101 /* We don't have this property */
102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108 tilda_window_constructor (GType type,
109 guint n_construct_properties,
110 GObjectConstructParam *construct_properties)
115 /* Invoke parent constructor */
116 TildaWindowClass *klass;
117 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
118 obj = parent_class->constructor (type,
119 n_construct_properties,
120 construct_properties);
122 /* Do other stuff here. The object is ready to go now, and all
123 * ctor properties have been set.
125 * TODO: This is the place to do DBus-init */
126 self = TILDA_WINDOW(obj);
128 gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
129 gtk_widget_show (self->notebook);
131 tilda_window_add_term (self);
132 gtk_widget_show_all (self->window);
138 my_unref (gpointer data, gpointer user_data)
140 g_object_unref (G_OBJECT(data));
144 tilda_window_dispose (GObject *obj)
146 TildaWindow *self = (TildaWindow *) obj;
148 /* We don't want to run dispose twice, so just return immediately */
149 if (self->dispose_has_run)
153 * In dispose, you are supposed to free all types referenced from this
154 * object which might themselves hold a reference to self. Generally,
155 * the most simple solution is to unref all members on which you own a
158 * NOTE: See the following for how to deal with GtkObject-derived things:
159 * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
161 g_ptr_array_foreach (self->terms, my_unref, NULL);
162 gtk_widget_destroy (self->window);
164 /* Chain up to the parent class */
165 G_OBJECT_CLASS (parent_class)->dispose (obj);
169 tilda_window_finalize (GObject *obj)
171 TildaWindow *self = (TildaWindow *) obj;
174 * Here, complete the object's destruction.
175 * You might not need to do much...
177 // TODO: g_free() any primitives here
178 g_ptr_array_free (self->terms, TRUE);
181 /* Chain up to the parent class */
182 G_OBJECT_CLASS (parent_class)->finalize (obj);
186 tilda_window_class_init (gpointer g_class,
187 gpointer g_class_data)
189 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
190 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
193 /* Hook our functions to this type */
194 gobject_class->set_property = tilda_window_set_property;
195 gobject_class->get_property = tilda_window_get_property;
196 gobject_class->dispose = tilda_window_dispose;
197 gobject_class->finalize = tilda_window_finalize;
198 gobject_class->constructor = tilda_window_constructor;
200 parent_class = g_type_class_peek_parent (klass);
202 /* Install all of the properties */
203 pspec = g_param_spec_int ("number",
205 "Set window's number",
207 INT_MAX, // max value
209 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
211 g_object_class_install_property (gobject_class,
215 /* TODO: more properties */
219 tilda_window_get_type (void)
221 static GType type = 0;
225 static const GTypeInfo info = {
226 sizeof (TildaWindowClass),
227 NULL, /* base_init */
228 NULL, /* base_finalize */
229 tilda_window_class_init, /* class_init */
230 NULL, /* class_finalize */
231 NULL, /* class_data */
232 sizeof (TildaWindow),
234 tilda_window_instance_init, /* instance_init */
237 type = g_type_register_static (G_TYPE_OBJECT,
248 int main (int argc, char *argv[])
251 gint test_number = INT_MIN;
253 /* Initialize the GObject type system */
255 gtk_init (&argc, &argv);
257 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
258 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
259 g_assert (test_number == 10);
261 g_object_unref (G_OBJECT (tw));
263 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
264 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
265 g_assert (test_number == 22);
269 g_object_unref (G_OBJECT (tw));
276 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */