Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

GtkVBox: A Windowless Container

This section describes some aspects of the GtkVBox widget, which differs substantially from the GtkEv widget presented earlier in the chapter. To understand this section you must first understand how GtkBox works from a user's point of view; see the section called GtkBox in the chapter called GTK+ Basics. You might want to look through the files gtkvbox.h and gtkvbox.c from your GTK+ distribution as you read.

Most of GtkVBox is implemented in the GtkBox base class; GtkVBox itself implements only size request and allocation. The GtkBox instance struct looks like this:


typedef struct _GtkBox        GtkBox;

struct _GtkBox
{
  GtkContainer container;
  
  GList *children;
  gint16 spacing;
  guint homogeneous : 1;
};
    

GtkBoxClass adds nothing to GtkContainerClass, and GtkVBox adds nothing to GtkBox.

Coding a GTK_NO_WINDOW Widget

The implementation of windowless widgets is slightly different from the implementation of "normal" widgets.

Windowless widgets must set the GTK_NO_WINDOW flag, so GTK+ can treat them appropriately. This should be done in the init function:


static void
gtk_box_init (GtkBox *box)
{
  GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW);

  box->children = NULL;
  box->spacing = 0;
  box->homogeneous = FALSE;
}
      

GtkBox uses the default realize method described in the section called Realization; because no GdkWindow needs to be created, a GTK_NO_WINDOW widget rarely needs a realize method. Recall that the default realize implementation sets the windowless widget's window field to the parent widget's window field.

Because boxes are invisible layout containers, the GtkBox draw and expose implementations simply pass the draw or expose request on to the box's children. This is identical to GtkBin's draw and expose implementations, except that there's a list of children to iterate over.

A GTK_NO_WINDOW widget that isn't invisible, such as GtkLabel, should be careful not to draw a background; the parent widget's background is used.

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire