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
Answertopia.com

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

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

The GtkWidget Base Class

Obviously, to subclass GtkWidget, you will have to be familiar with the base class. This section offers a brief tour of the GtkWidget class and instance structs, and some important GTK+ routines that aren't very common in everyday programming.

The GtkWidget Instance Struct

A GtkWidget instance looks like this:


typedef struct _GtkWidget GtkWidget;

struct _GtkWidget
{
  GtkObject object;

  guint16 private_flags;
  
  guint8 state;

  guint8 saved_state;
  
  gchar *name;

  GtkStyle *style;
  
  GtkRequisition requisition;

  GtkAllocation allocation;
  
  GdkWindow *window;

  GtkWidget *parent;
};
      

The private_flags, state, and saved_state fields should all be accessed with macros, if at all. Some of these macros will come up as we discuss widget implementations. The state field stores the widget's state as described in the section called Widget States in the chapter called GTK+ Basics. saved_state is used to save the widget's previous state when the current state is GTK_STATE_INSENSITIVE; when the widget is re-sensitized, its original state is restored. As the section called Widget States in the chapter called GTK+ Basics explains, the current state can be accessed with the GTK_WIDGET_STATE() macro.

The name of a widget is used in a gtkrc file to group widgets together for customization purposes. By default, the name of a widget is the type name registered with the object system (in GTK+, this type name is always the name of the instance struct, such as "GtkLabel"). Particular widgets can be given a different name with gtk_widget_set_name(); for example, if you want a particular label to appear in a different font, you can give it a name like "FunkyFontLabel" and then specify a different font for that name in a gtkrc shipped with your application.

The requisition and allocation fields store the last requested and allocated size of the widget, respectively. the section called Size Negotiation will have more to say about this.

The window field stores the widget's GdkWindow, or the widget's parent's GdkWindow if the widget has none. The parent field is a pointer to the widget's parent container; it will be NULL if the widget is not inside a container.

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire