Article title: GNOMEnclature: Prepare for GNOME2 (1 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Introduction to GTK + 2 Before you study the next generation of GTK +, you may want to know when GNOME 2 can be used for the product. GNOME 2 is scheduled to be released in February 15, 2002. large applications such as Gnumeric and Evolution will be migrated to GNOME 2 later.
Okay. let's start exploring GTK +! Initially, GTK + was developed for use in Gimp (GTK indicates Gimp ToolKit ). GTK + is currently available on many platforms, including Linux and Windows. Many free software projects (including GNOME itself, Mozilla, Gimp, and many other projects) use it.
Like GTK + 1, GTK + 2 depends on GLib, which is a convenient library for C developers. GLib contains many features that make your programming easier, including object systems and data structures such as hash, list, and tree.
GTK + 2 also depends on ATK and Pango. ATK is an accessible Toolkit that enables people with disabilities to use GTK + applications. Pango is a framework for displaying international text. Later, this article will describe these two software packages.
Install GTK + 2 To make full use of this article, we recommend that you install GTK + 2 and run it. To install GTK + 2, make sure that pkg-config 0.8 or later is installed on your system. All major distributions should have a software package that provides pkg-config. Of course, GTK + 2 also depends on external libraries, such as glib, atk, and pango. You must install these libraries before compiling GTK + 2. Generally, the best way is to download the latest glib, atk, pango, and gtk + source code tar packages (see references later in this article ). You can see the latest "vx. y" directory, which is "v1.3" currently ".
You may be surprised: We spent all our time talking about GTK + 2, but we recommend that you install GTK + 1.3. This is because GTK + 1.3.11 is the latest available GTK + version when writing this article. Once GTK + is fully ready for use in the product, GTK + 2.0 will be released. Before that, it was okay to use GTK + 1.3 for testing because it included almost all new feature components that will appear in the official GTK + 2.0 release.
Now that we have explained it clearly, we should re-go to the topic of installing the new GTK +. Because GTK + 2 has several build-time dependencies, you should first install glib and then install atk, pango, and gtk +. this installation order is very important. Install each software package as follows:
Listing 1. install GTK + and support Library source code
Tar xzvf package-version.tar.gz
Cd package-version
./Configure
Make
Make install
Once all the software packages are installed, you should be able to start gtk-demo. this is a great small program that allows you to see that GTK + 2 is running.
What are the new features of GTK + 2? Many users have always demanded that GTK + be able to use anti-Sawtooth fonts. Now, this feature has been added to GTK + 2. The GTK + 2 font anti-Sawtooth processing is implemented by using the Xft library and XRender extension (which is part of XFree86 4 and later.
To enable the anti-Sawtooth font for the GTK + 2 application, set the environment variable GDK_USE_XFT = 1. All GTK + 2 applications started from shell with GDK_USE_XFT set to 1 should display the anti-Sawtooth font text. If you want to, enable the anti-Sawtooth text and run gtk-demo again.
Dialog box example
Double buffering and image processing The font anti-Sawtooth processing is not the only graphic improvement in GTK + 2; GTK + now uses double buffering to update the screen. Because there is no double buffer, GTK + 1 applications sometimes flash when you redraw or adjust the size of the hour. GTK + 2 does not have this problem, so the display of the new GTK + 2 application will be more stable.
GTK + 2 also provides many improvements based on developers' expectations. For example, GdkPixbuf (formerly a separate library) is now part of GTK +. GdkPixbuf processes and stores images in multiple formats (such as GIF, PNG, JPEG, BMP, and so on. Since GdkPixbuf is already part of GTK +, GTK + can also be used to draw the alpha blended icon of menus, toolbar, and buttons ).
Here is a sample GTK + 2 program for loading a small bitmap image called gnome.png:
In the sample program, we use the gtk_image_from_new_file () function to create a GtkImage object. The GtkImage object uses GdkPixbuf internally to automatically mount the image:
List 2. use the GtkImage object to display the image
# Include
Int
Main (int argc, char ** argv)
{
GtkWidget * window;
GtkWidget * image;
After compilation, execute./image-button. This is what you should see:
Pango Pango is a new full-featured framework for international text layout and display. Thanks to Pango, GTK + 2 is now more useful for users who do not live in the United States or Europe. Pango can process texts arranged from left to right, and easily manage complex languages. it can even process different forms of letters according to the use environment.
Pango supports bidirectional text, so you can combine left-to-right text with right-to-left text, and plug-ins used to determine the shape of complex texts (such as Arabic and Thai. Pango is not just International; Pango library handles the display of anti-Sawtooth font text with the help of Xft and XRender extensions. For more information, read two developerWorks articles on Pango (see references ).
Unicode and UTF-8 In GTK + 2, any string passed to the gtk _ * () function should be in Unicode UTF-8 encoding format. GTK + 2 completely eliminates internationalization issues in earlier versions of GTK + thanks to the internal use of UTF-8.
Because ASCII is a subset of the UTF-8, this change does not affect the existing GTK + code as you think. However, when ASCII is mapped directly to the UTF-8, it cannot be reversely mapped. Many non-English Character sets occupy multiple bytes for each character during UTF-8 encoding. To handle situations where character encoding is greater than normal, when a character in the form of a UTF-8 string needs to be iterated, a special function called g_utf8_next_char () should be used (in fact, it is a macro ). This macro will determine whether to use a small byte or a large byte "hop" as needed )". Here is a small example where we want to verify and iterate a UTF-8 string:
Listing 3. verify and iterate a UTF-8 string
Gchar * p;
G_return_if_fail (g_utf8_validate (str ));
P = str;
While (p ){
Gunichar c = g_utf8_get_char (p)
/* Do something with c .*/
P = g_utf8_next_char (p );
}
To convert a locally encoded string to a UTF-8, you can use:
Listing 4. converting a locally encoded string into a UTF-8
Gchar * g_locale_to_utf8 (const gchar * opsysstring,
Gssize length,
Gsize * bytes_read,
Gsize * bytes_written,
GError ** error );
If you do not want to know the number of bytes read/write, the last three parameters can be NULL. If a NULL-terminated string is being passed to this function, the length is set to-1. for example:
Atk, accessible toolbox Now GTK + 2 makes full use of ATK (accessible Toolkit )). ATK makes it possible for people with disabilities (such as poor eyesight or inaccessibility) to interact with GTK + 2 applications. In future articles, we will discuss ATK in more detail and show you how to enable people with disabilities to access your own applications. You can also access GNOME "accessible projects (Accessibility projects)" (see references ).
Fixed item (stock item) Both GNOME 1 and GNOME 2 support "fixed items", making it easy for developers to add generic menu items and buttons to their applications. Since fixed items are globally defined, rather than defined within the application, they can easily provide a uniform appearance for all GNOME applications.
Generally, a single fixed item consists of an icon, a text tag, and an optional shortcut key. In addition to giving the application a uniform appearance, the fixed items also provide great help for internationalization, because they only need to be converted once (in the GTK + library ), there is no application-specific data that needs to be converted by developers themselves. For the GNOME 2 platform, the fixed item support has been moved from gnome-lib to GTK +, making it possible for more applications to have a consistent appearance.
The sample code snippet is used to create a button with a floppy image and a "Save" tag:
Listing 5. create a button with a floppy image and a "Save" tag
GtkWidget * button;
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