How to put widget in CUSTOM GtkContainer
Hi there, my name is Alan and I have some troubles with GtkContainer. It's about 2 days, I already have spent trying to solve it, but I (i guess) can't. I'm writing a program, which looks like: +-+ | Main Window (GtkWindow) | | +-+ | | | My custom widget| | | | +-+ | | | | | GtkButton | | | | | +-+ | | | +-+ | +-+ I need some approach to place a GtkButton in my custom widget. I found (from GTK+ sources) that GtkTreeView, GtkNotebook (and others) inherits from GtkContainer . So, I decide to inherit my widget not from GtkWidget, but from GtkContainer. typedef struct _GridGrid; typedef struct _GridClass GridClass; struct _Grid { GtkContainer parent; }; struct _GridClass { GtkContainerClass parent_class; }; And my _get_type function looks like: GtkType grid_get_type () { static GtkType grid_type = 0; if (!grid_type) { const GTypeInfo object_info = { sizeof (GtkContainerClass), NULL, NULL, (GClassInitFunc) grid_class_init, NULL, NULL, sizeof (Grid), 0, (GInstanceInitFunc) grid_init, NULL, }; grid_type = g_type_register_static (GTK_TYPE_CONTAINER, g_intern_static_string ("Grid"), &object_info, 0); } return grid_type; } The main feature of this function is GTK_TYPE_CONTAINER ;-) You see ;-) Next in my program, I'm creating my widget (grid) with that: [...] grid = grid_new (); gtk_container_add (GTK_CONTAINER (window), grid); [...] So, my problem starts here: at _new() function. I want to create GtkButton and place it in my widget. GtkWidget* grid_new () { Grid *grid; grid = g_object_new (grid_get_type (), NULL); button = gtk_button_new_with_label ("Test"); gtk_widget_set_parent (button, GTK_WIDGET (grid)); gtk_widget_show (button); return GTK_WIDGET (grid); } Everything right and works without errors ;-) But nothing happens. I can't see a GtkButton ;-) How to solve it? I need some way for "draw" (expose) GtkButton in my custom widget ;-) How to do it? P.S. I extremely think, that I just forgot something. But there are no tutorials about it ;-) "Information vacuum", so I decide to ask in mailing-lists. P.P.S. Only information about custom widget creation is a GTK sources, but (even with it) I can't solve my problem. ;-) P.P.P.S. Also, I really want to understand how GtkBox works ;-) Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to put widget in CUSTOM GtkContainer
AlannY wrote: > Hi there, my name is Alan and I have some troubles with GtkContainer. > > It's about 2 days, I already have spent trying to solve it, but I (i > guess) can't. > > I'm writing a program, which looks like: > +-+ > | Main Window (GtkWindow) | > | +-+ | > | | My custom widget| | > | | +-+ | | > | | | GtkButton | | | > | | +-+ | | > | +-+ | > +-+ > > I need some approach to place a GtkButton in my custom widget. I found > (from GTK+ sources) that GtkTreeView, GtkNotebook (and others) inherits > from GtkContainer . So, I decide to inherit my widget not from > GtkWidget, but from GtkContainer. > > typedef struct _GridGrid; > typedef struct _GridClass GridClass; > > struct _Grid > { >GtkContainer parent; > }; > > struct _GridClass > { >GtkContainerClass parent_class; > }; > > And my _get_type function looks like: > > GtkType > grid_get_type () > { >static GtkType grid_type = 0; > >if (!grid_type) > { >const GTypeInfo object_info = >{ > sizeof (GtkContainerClass), > NULL, > NULL, > (GClassInitFunc) grid_class_init, That still isn't the whole code! What does grid_class_init() do? Attach both the whole grid header and source file to the email. > NULL, > NULL, > sizeof (Grid), > 0, > (GInstanceInitFunc) grid_init, > NULL, >}; > >grid_type = g_type_register_static (GTK_TYPE_CONTAINER, > g_intern_static_string ("Grid"), &object_info, 0); > } > >return grid_type; > } > > The main feature of this function is GTK_TYPE_CONTAINER ;-) You see ;-) > > Next in my program, I'm creating my widget (grid) with that: > > [...] > grid = grid_new (); > gtk_container_add (GTK_CONTAINER (window), grid); > [...] > > So, my problem starts here: at _new() function. I want to create > GtkButton and place it in my widget. > > GtkWidget* > grid_new () > { >Grid *grid; > >grid = g_object_new (grid_get_type (), NULL); > >button = gtk_button_new_with_label ("Test"); >gtk_widget_set_parent (button, GTK_WIDGET (grid)); >gtk_widget_show (button); > >return GTK_WIDGET (grid); > } > > Everything right and works without errors ;-) But nothing happens. I > can't see a GtkButton ;-) > > How to solve it? I need some way for "draw" (expose) GtkButton in my > custom widget ;-) How to do it? > > P.S. I extremely think, that I just forgot something. But there are no > tutorials about it ;-) "Information vacuum", so I decide to ask in > mailing-lists. > P.P.S. Only information about custom widget creation is a GTK sources, > but (even with it) I can't solve my problem. ;-) > P.P.P.S. Also, I really want to understand how GtkBox works ;-) And stop creating new threads... This is your third thread in gtk-app-devel where you ask the same question. tom ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to put widget in CUSTOM GtkContainer
I don't believe that using set_parent() will actually place the widget inside the container; try gtk_container_add(GTK_CONTAINER(grid), widget); instead 2008/4/29 Tomas Carnecky <[EMAIL PROTECTED]>: > AlannY wrote: > > Hi there, my name is Alan and I have some troubles with GtkContainer. > > > > It's about 2 days, I already have spent trying to solve it, but I (i > > guess) can't. > > > > I'm writing a program, which looks like: > > +-+ > > | Main Window (GtkWindow) | > > | +-+ | > > | | My custom widget| | > > | | +-+ | | > > | | | GtkButton | | | > > | | +-+ | | > > | +-+ | > > +-+ > > > > I need some approach to place a GtkButton in my custom widget. I found > > (from GTK+ sources) that GtkTreeView, GtkNotebook (and others) inherits > > from GtkContainer . So, I decide to inherit my widget not from > > GtkWidget, but from GtkContainer. > > > > typedef struct _GridGrid; > > typedef struct _GridClass GridClass; > > > > struct _Grid > > { > >GtkContainer parent; > > }; > > > > struct _GridClass > > { > >GtkContainerClass parent_class; > > }; > > > > And my _get_type function looks like: > > > > GtkType > > grid_get_type () > > { > >static GtkType grid_type = 0; > > > >if (!grid_type) > > { > >const GTypeInfo object_info = > >{ > > sizeof (GtkContainerClass), > > NULL, > > NULL, > > (GClassInitFunc) grid_class_init, > > That still isn't the whole code! What does grid_class_init() do? Attach > both the whole grid header and source file to the email. > > > NULL, > > NULL, > > sizeof (Grid), > > 0, > > (GInstanceInitFunc) grid_init, > > NULL, > >}; > > > >grid_type = g_type_register_static (GTK_TYPE_CONTAINER, > > g_intern_static_string ("Grid"), &object_info, 0); > > } > > > >return grid_type; > > } > > > > The main feature of this function is GTK_TYPE_CONTAINER ;-) You see ;-) > > > > Next in my program, I'm creating my widget (grid) with that: > > > > [...] > > grid = grid_new (); > > gtk_container_add (GTK_CONTAINER (window), grid); > > [...] > > > > So, my problem starts here: at _new() function. I want to create > > GtkButton and place it in my widget. > > > > GtkWidget* > > grid_new () > > { > >Grid *grid; > > > >grid = g_object_new (grid_get_type (), NULL); > > > >button = gtk_button_new_with_label ("Test"); > >gtk_widget_set_parent (button, GTK_WIDGET (grid)); > >gtk_widget_show (button); > > > >return GTK_WIDGET (grid); > > } > > > > Everything right and works without errors ;-) But nothing happens. I > > can't see a GtkButton ;-) > > > > How to solve it? I need some way for "draw" (expose) GtkButton in my > > custom widget ;-) How to do it? > > > > P.S. I extremely think, that I just forgot something. But there are no > > tutorials about it ;-) "Information vacuum", so I decide to ask in > > mailing-lists. > > P.P.S. Only information about custom widget creation is a GTK sources, > > but (even with it) I can't solve my problem. ;-) > > P.P.P.S. Also, I really want to understand how GtkBox works ;-) > > And stop creating new threads... This is your third thread in > gtk-app-devel where you ask the same question. > > tom > > ___ > gtk-list mailing list > gtk-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-list > ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to put widget in CUSTOM GtkContainer
Tomas Carnecky wrote: > AlannY wrote: > That still isn't the whole code! What does grid_class_init() do? Attach > both the whole grid header and source file to the email. /* ** */ static void grid_class_init (GridClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; parent_class = gtk_type_class (gtk_widget_get_type ()); object_class->destroy = grid_destroy; widget_class->realize = grid_realize; widget_class->expose_event = grid_expose; } /* ** */ static void grid_init (Grid *grid) { } /* ** */ static void grid_realize (GtkWidget *widget) { Grid *grid; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail (widget != NULL); g_return_if_fail (IS_GRID (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); grid = GRID (widget); attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); gdk_window_set_user_data (widget->window, widget); gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); } /* ** */ static gboolean grid_expose (GtkWidget *widget, GdkEventExpose *event) { g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (IS_GRID (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (event->count > 0) return FALSE; return FALSE; } /* ** */ static void grid_destroy (GtkObject *object) { g_return_if_fail (object != NULL); g_return_if_fail (IS_GRID (object)); if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } /* ** */ That's all I have ;-) ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to put widget in CUSTOM GtkContainer
Milosz Derezynski wrote: > I don't believe that using set_parent() will actually place the widget > inside the container; try gtk_container_add(GTK_CONTAINER(grid), > widget); instead I don't believe in it too ;-) So I decide to ask what to do ;-) gtk_container_add not works ;-) ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to put widget in CUSTOM GtkContainer
On Tue, 2008-04-29 at 18:03 +0400, AlannY wrote: > Milosz Derezynski wrote: > > I don't believe that using set_parent() will actually place the widget > > inside the container; try gtk_container_add(GTK_CONTAINER(grid), > > widget); instead > > I don't believe in it too ;-) So I decide to ask what to do ;-) > gtk_container_add not works ;-) could you please stop wincing? it's neither funny nor appropriate. you're not implementing the GtkContainer virtual functions. you're also adding a GdkWindow to a container widget - which is not recommended. you should read the tutorial on how to subclass a GObject first: http://library.gnome.org/devel/gobject/stable/howto-gobject.html and then read the documentation and implementations of GtkContainer, starting with something simple like GtkBin. you might also ponder on switching to another language altogether. ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to put widget in CUSTOM GtkContainer
AlannY wrote: > Tomas Carnecky wrote: >> AlannY wrote: >> That still isn't the whole code! What does grid_class_init() do? Attach >> both the whole grid header and source file to the email. > > /* ** */ > > static void > grid_class_init (GridClass *class) > { >GtkObjectClass *object_class; >GtkWidgetClass *widget_class; > >object_class = (GtkObjectClass*) class; >widget_class = (GtkWidgetClass*) class; > >parent_class = gtk_type_class (gtk_widget_get_type ()); > >object_class->destroy = grid_destroy; > >widget_class->realize = grid_realize; >widget_class->expose_event = grid_expose; here you have to set GtkContainerClass->add, remove, forall and child_type. See http://svn.gnome.org/viewvc/gtk%2B/trunk/gtk/gtkbin.c?revision=19491&view=markup as an example of a widget that derives from GtkContainer. > } > > /* ** */ > static void > grid_init (Grid *grid) > { > } > > /* ** */ > static void > grid_realize (GtkWidget *widget) > { >Grid *grid; >GdkWindowAttr attributes; >gint attributes_mask; > >g_return_if_fail (widget != NULL); >g_return_if_fail (IS_GRID (widget)); > >GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); >grid = GRID (widget); > >attributes.x = widget->allocation.x; >attributes.y = widget->allocation.y; >attributes.width = widget->allocation.width; >attributes.height = widget->allocation.height; >attributes.wclass = GDK_INPUT_OUTPUT; >attributes.window_type = GDK_WINDOW_CHILD; >attributes.event_mask = gtk_widget_get_events (widget) | > GDK_EXPOSURE_MASK; >attributes.visual = gtk_widget_get_visual (widget); >attributes.colormap = gtk_widget_get_colormap (widget); > >attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; >widget->window = gdk_window_new (widget->parent->window, &attributes, > attributes_mask); > >widget->style = gtk_style_attach (widget->style, widget->window); > >gdk_window_set_user_data (widget->window, widget); > >gtk_style_set_background (widget->style, widget->window, > GTK_STATE_ACTIVE); > } > > /* ** */ > static gboolean > grid_expose (GtkWidget *widget, > GdkEventExpose *event) > { >g_return_val_if_fail (widget != NULL, FALSE); >g_return_val_if_fail (IS_GRID (widget), FALSE); >g_return_val_if_fail (event != NULL, FALSE); > >if (event->count > 0) > return FALSE; > >return FALSE; > } > > /* ** */ > static void > grid_destroy (GtkObject *object) > { >g_return_if_fail (object != NULL); >g_return_if_fail (IS_GRID (object)); > >if (GTK_OBJECT_CLASS (parent_class)->destroy) > (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); > } > > /* ** */ > > That's all I have ;-) > ___ > gtk-app-devel-list mailing list > [EMAIL PROTECTED] > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > -- So Long, and Thanks for All the Fish ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list