gobject inheritance for GtkWindow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux