GTK objects are directed to the architecture

Source: Internet
Author: User
Tags gtk
GTK uses the C statement to create a scheme. Even though the C statement itself does not support object redirection, GTK uses some methods on the architecture, this allows GTK to support the concept of moving many objects.

In terms of the envelope feature of object direction, GTK models the differences in structure mode. In fact, GTK also directly blocks these structures as a type of difference, take the program example of creating the gtkwindow as an example:

Window = gtk_window_new (gtk_window_toplevel );


In the form of a function, all the functions related to the gtkwindow function start with the gtk_window name. The gtk_window_new () function is like the constructor used to explain the object to the program, if you want to set the relevance of the gtkwindow, such as the subject name:

Gtk_window_set_title (gtk_window (window), "haha! GTK +! ");


The first parameter Number of gtk_window_set_title () is subject to the gtkwindow indicator. This method is used to display the global function in the real world, it seems like the algorithm is used by gtkwindow, just like the public (public) method or the member function carried by the object ), in the private mode, GTK uses the static function, for example, in gtkwindow. in program C, you can see:

Static void gtk_window_dispose (gobject * object );
Static void gtk_window_destroy (gtkobject * object );
Static void gtk_window_finalize (gobject * object );
Static void gtk_window_show (gtkwidget * widget );
Static void gtk_window_hide (gtkwidget * widget );
Static void gtk_window_map (gtkwidget * widget );
Static void gtk_window_unmap (gtkwidget * widget );
Static void gtk_window_realize (gtkwidget * widget );
Static void gtk_window_unrealize (gtkwidget * widget );


These static functions cannot appear in the gtkwindow. h header file, which can be used in gtkwindow. C. In this case, they seem like the invalid functions of gtkwindow.

On the upload server, GTK uses the Link Method in the actual deployment. In the first GTK program, we have seen the following access protocols:
Gobject
+ -- Ginitiallyunowned
+ -- Gtkobject
+ -- Gtkwidget
+ -- Gtkcontainer
+ -- Gtkbin
+ -- Gtkwindow

For example, gtkcontainer has the following definitions in gtkcontainer. h:

Typedef struct _ gtkcontainer;
...

Struct _ gtkcontainer
{
Gtkwidget;

Gtkwidget * focus_child;

Guint border_width: 16;

/* <Private> */
Guint need_resize: 1;
Guint resize_mode: 2;
Guint reallocate_redraws: 1;
Guint has_focus_chain: 1;
};

There is a gtkwidget among the members of the gtkcontainer, And then you can see gtkwidget. h:

Typedef struct _ gtkwindow;
...
Struct _ gtkwidget
{
/* The object structure needs to be the first
* Element in the widget structure in order
* The object mechanic to work correctly. This
* Allows a gtkwidget pointer to be cast to
* Gtkobject pointer.
*/
Gtkobject object;
...
};

The gtkwidget contains a member gtkobject. The following example shows how to use the gtk_window_set_title () function to hold the member structure on the object with such a link:

Gtk_window_set_title (gtk_window (window), "haha! GTK +! ");


Gtk_window is a huge set. It is used to indicate a standard dynamic animation:

# Define gtk_window (OBJ)
(G_type_check_instance_cast (OBJ), gtk_type_window, gtkwindow ))


G_type_check_instance_cast is defined in gtype. H (/usr/include/glib-2.0/gobject/gtype. h) of glib:

# Define g_type_check_instance_cast (instance, g_type, c_type)
(_ G_type_cic (instance), (g_type), c_type ))


G_type_check_instance_cast will check whether the instance is g_type. If not, a warning message will be issued, if so, convert the standard type to the c_type sequence (the file on g_type_check_instance_cast sequence is explicitly described ).

Even if you are familiar with C ++, Java, and other support object providers, this architecture is incomplete in the concept of object direction, however, it is true that there are a lot of advantages in the ease-of-use and scalability.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.