gobject inheritance for GtkWindow
- From: Sergio Perticone <g4ll0ws gmail com>
- To: gtk-list gnome org
- Subject: gobject inheritance for GtkWindow
- Date: Thu, 11 Oct 2007 15:05:38 +0200
Hi,
I'm learning GTK+ C API and I would want use _my own_ widget for default
window, created by inheritance from GtkWindow (like I do usually with
gtkmm). But it does not work.
My code is:
/**** window.h ****/
/* ..macro and includes as specified in gobject reference manual.. */
typedef struct _MyWindow MyWindow;
typedef struct _MyWindowClass MyWindowClass;
struct _MyWindow {
GtkWidget* window;
GtkWidget* button;
};
struct _MyWindowClass {
GtkWindowClass parent_class;
};
/* ... */
/**** window.c ****/
#include "window.h"
#include <gtk/gtkbutton.h>
#include <gtk/gtkmain.h>
/* ..prototypes.. */
GType mywindow_get_type(void)
{
static GType type = 0;
if(!type) {
static const GTypeInfo info = {
sizeof(MyWindowClass),
NULL, NULL,
(GClassInitFunc) mywindow_class_init,
NULL, NULL,
sizeof(MyWindow), 0,
(GInstanceInitFunc) mywindow_init
};
type = g_type_register_static(GTK_TYPE_WINDOW,
"MyWindow",
&info, 0);
}
return type;
}
static void mywindow_class_init(MyWindowClass* klass)
{
GtkObjectClass* object_class;
GtkWidgetClass* widget_class;
object_class = (GtkObjectClass*) klass;
widget_class = (GtkWidgetClass*) klass;
/* well, actually I do not understand this step */
}
static void mywindow_init(MyWindow* self)
{
g_signal_connect(G_OBJECT(self), "delete-event",
G_CALLBACK(destroy), NULL);
self->button = gtk_button_new_with_label("close");
g_signal_connect(G_OBJECT(self->button), "clicked",
G_CALLBACK(destroy), NULL);
gtk_container_add(GTK_CONTAINER(self), self->button);
gtk_widget_show(self->button);
}
GtkWidget* mywindow_new(void)
{
return GTK_WIDGET( g_object_new(MYWINDOW_TYPE, NULL) );
}
/* ..other stuff.. */
It compiles without error nor warning, but at run-time I get:
(foo:18259): GLib-GObject-WARNING **: specified instance size for type
`MyWindow' is smaller than the parent type's `GtkWindow' instance size
(foo:18259): GLib-GObject-CRITICAL **: g_object_new: assertion
`G_TYPE_IS_OBJECT (object_type)' failed
(foo:18259): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET
(widget)' failed
How it should be done?
Any little tip or even suggested docs/code to read is appreciated.
Thanks in advance,
s.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]