Analysis of a component
To create a new component, you must first understand the working principle of the GTK object. This section is just a brief description. For more information, see the reference manual.
The GTK component has the object-oriented feature. However, it is implemented using standard C. This greatly improves the portability and Stability of the current C ++ compiler. However, this also means that the write component must pay attention to some implementation details. The common information of all instances of a component class (such as all button components) is stored inClass Structure
Class signal information is only stored in this structure (as a virtual function in C ). To support inheritance, the first domain of the class structure must be a copy of its parent class structure. The class structure declaration of the gtkbutton is as follows:
struct _GtkButtonClass { GtkContainerClass parent_class;
void (* pressed) (GtkButton *button); void (* released) (GtkButton *button); void (* clicked) (GtkButton *button); void (* enter) (GtkButton *button); void (* leave) (GtkButton *button); }; |
When a button is treated as a container (for example, when it is adjusted to an hour), its class structure is converted to gtkcontainerclass, and the corresponding fields are used to process signals.
Each component also has a structure, which is the basis for creating each instance. This structure stores different information domains for instances of each component. We call this structureObject Structure
. The following is a button class:
struct _GtkButton { GtkContainer container;
GtkWidget *child;
guint in_button : 1; guint button_down : 1; }; |
Note that it has similar structures. The first field is the object structure of the parent class. Therefore, this structure can be converted to the object structure of the parent class as needed.
<Previous |
Home |
Next >>> |
Compile Your Own Components |
Up |
Create a composite component |