Re: How to put widget in CUSTOM GtkContainer
- Date: Tue, 29 Apr 2008 16:42:31 +0200
- From: Tomas Carnecky <tom@xxxxxxxxxxxxx>
- Subject: 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
> gtk-app-devel-list@xxxxxxxxx
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
--
So Long, and Thanks for All the Fish
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list