X Window Programming/GTK+

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Introduction[edit | edit source]

The GIMP Toolkit (abbreviated as GTK+) is a free and open source widget toolkit for creating graphical user interfaces that was initially created in 1998 for the GIMP, a raster graphics editor, by Spencer Kimball, Peter Mattis, and Josh MacDonald — all of whom were members of eXperimental Computing Facility (XCF) at Berkeley University. GTK+ is licensed under the LGPL.

Unlike many other widget toolkits, GTK+ isn't based on Xt. The advantage of this is that it allows GTK+ to be available on other systems and to be much more flexible. GTK+ allows the end-user to configure the look of the toolkit, down to offering a number of different display engines. Engines exist which emulate the look of other popular toolkits or platforms, like Windows 95, Motif, Qt or NextStep. The disadvantage is that it doesn't have access to the X resource database, which is the traditional way for customizing X11 applications.

GTK+ 2 includes improved text rendering using Pango, a new theme engine, improved accessibility using Accessibility Toolkit, complete transition to Unicode using UTF-8 strings and a more flexible API. However, GTK+ 2 lacks compatibility with GTK+ 1, and programmers must port applications to it. Starting with version 2.8 GTK+ relies on the Cairo library for rendering of vector graphics.

Programming languages[edit | edit source]

GTK+ uses the C programming language, although its designers use an object-oriented paradigm. The GNOME platform bindings provide for C++ (gtkmm), Perl, Ruby, Java and Python (PyGTK) bindings; others have written bindings for many other programming languages (including Ada, D, Haskell, Lua, Pascal, PHP, Pike and all .NET programming languages).

Environments that use GTK+[edit | edit source]

Screenshot of the GIMP 2.2 on a typical system
  • The GNOME environment uses GTK+ as a base, which means that programs written for GNOME use GTK+ as their toolkit.
  • Xfce also uses it as its base, though its apps typically do not depend on as many programs. (This is the difference between something being branded as a "GNOME program" and as a "GTK+ program".)
  • The GPE Palmtop Environment, Maemo (Nokia's Internet-tablet framework), and Access Linux Platform (a new Palm OS-compatible Personal digital PDA platform) also use GTK+ as a base.

Those desktop environments are not required to run GTK+ programs, though. If the libraries the program requires are installed, a GTK+ program can run on top of other X11-based environments such as KDE or an X11-plus-window manager environment; this includes MacOS X if X11.app is installed. GTK+ can also run under Microsoft Windows. Some of the more unusual ports include DirectFB and ncurses.