GTK+

GTK+
Developer(s) GNOME Foundation
Stable release 3.2.2 / November 12, 2011; 3 months ago (2011-11-12)
Preview release 3.3.6 / December 19, 2011; 58 days ago (2011-12-19)
Development status Active
Written in C
Operating system Cross-platform
Platform Cross-platform
Size 18 MB
Available in Multilingual
Type Widget toolkit
License GNU LGPL version 2
Website www.gtk.org

GTK+ (GIMP Toolkit) is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.

The name GTK+ originates from GTK; the plus was added to distinguish an enhanced version.[1] It was originally created for the GNU Image Manipulation Program (GIMP), a free software raster graphics editor, in 1997 by Spencer Kimball and Peter Mattis, members of eXperimental Computing Facility (XCF) at the University of California, Berkeley. It is now maintained by members of the GNOME Foundation.

Contents

Design

GTK+ is an object-oriented widget toolkit written in the C programming language; object-orientation is achieved by using the GLib object system. On the X11 display server, GTK+ uses Xlib to draw widgets. Using Xlib provides flexibility and allows GTK+ to be used on platforms where the X Window System is unavailable. While GTK+ is primarily targeted at the X Window System, other platforms are supported, including Microsoft Windows (interfaced with the Windows API), and Mac OS X (interfaced with Quartz). HTML5 and Wayland backends are in development.

GTK+ can be configured to change the look of the widgets drawn; this is done using different display engines. Several display engines exist which try to emulate the look of the native widgets on the platform in use.

Programming language bindings

A library written in one programming language may be used in another programming language if bindings are written; GTK+ has bindings in many languages.[2]

See the table below:

Language Name Supported?
Ada GtkAda Partial support up to 2.18
C GTK+ Native (no binding necessary)
C++ gtkmm Yes
C# and other .NET languages Gtk# Partial support up to 2.20
D gtkD Partial support up to 2.22 (plus Cairo, Gda, Gl, GStreamer)
Erlang gtkNode Partial support up to 2.16
GOB languages written for the GObject system. Yes
Gambas gambas3-gb-gtk Yes
Genie languages written for the GObject system. Yes
Haskell gtk2hs Yes
Fortran gtk-fortran Partial support up to 2.24 & 3.0
FreeBASIC GladeToBac Supports all versions from 2.8 to 3.0
FreePascal (header) integrated into the core distribution GTK 2.16 with partial support of later versions
Java java-gnome Partial support up to 2.20 (not available on Windows)
JavaScript seed/GJS Yes
Lua lgob Supports all versions from 2.16
Lua LuaGtk Partial support up to 2.16
Ocaml LablGTK Partial support up to 2.16
Perl Gtk2-Perl Support up to GTK3
PHP PHP-GTK Partial support up to 2.20
Python PyGTK (native as of GTK3) Yes
R RGtk2 Partial support up to 2.12
Ruby ruby-gtk2 Yes
Smalltalk Smalltalk GTK GNU Smalltalk, Smalltalk YX, Squeak
Tcl Gnocl Yes
Vala languages written for the GObject system. Yes
Wrapl WraplGTK Almost full support up to 2.22

GUI designers

There were several attempts to create a GUI designer for GTK+. The following projects are active as of July 2011:

History

GTK+ was originally designed and used in the GNU Image Manipulation Program (GIMP) as a replacement of the Motif toolkit; at some point Peter Mattis became disenchanted with Motif and began to write his own GUI toolkit called the GIMP toolkit and had successfully replaced Motif by the 0.60 release of GIMP.[3] Finally GTK was re-written to be object oriented and was renamed GTK+. This was first used in the 0.99 release of GIMP.

The GTK+ 2.0.0 release series introduced new features which include improved text rendering using Pango, a new theme engine, improved accessibility using the Accessibility Toolkit, complete transition to Unicode using UTF-8 strings, and a more flexible API. Starting with version 2.8, GTK+ 2 depends on the Cairo graphics library for rendering vector graphics in GTK+ 2.

GTK+ version 3.0.0 included revised input device handling, support for themes written with CSS-like syntax, and the ability to receive information about other opened GTK+ applications.

Release series Initial release date Major enhancements Latest minor version
1.0 14 April 1998 First stable version 1.0.6
1.2 27 February 1999 New widgets (GtkFontSelector, GtkPacker, GtkItemFactory, GtkCTree,
GtkInvisible, GtkCalendar, GtkLayout, GtkPlug, GtkSocket)
1.2.10
2.0 11 March 2002 GObject, Universal Unicode UTF-8 2.0.9
2.2 22 December 2002 Multihead support 2.2.4
2.4 16 March 2004 New widgets (GtkFileChooser, GtkComboBox, GtkComboBoxEntry,
GtkExpander, GtkFontButton, GtkColorButton)
2.4.14
2.6 16 December 2004 New widgets (GtkIconView, GtkAboutDialog, GtkCellView).
The last to support Windows 98/ME.
2.6.10
2.8 13 August 2005 Cairo integration 2.8.20
2.10 3 July 2006 New widgets (GtkStatusIcon, GtkAssistant, GtkLinkButton,
GtkRecentChooser) and print support (GtkPrintOperation)
2.10.14
2.12 14 September 2007 GtkBuilder 2.12.12
2.14 4 September 2008 Jpeg2000 load support 2.14.7
2.16 13 March 2009 New GtkOrientable, Caps Lock warning in password Entry.
Improvement on GtkScale, GtkStatusIcon, GtkFileChooser.
2.16.6
2.18 23 September 2009 New GtkInfoBar. Improvement on file chooser, printing.
GDK has been rewritten to use 'client-side windows'
2.18.9
2.20 23 March 2010 New GtkSpinner and GtkToolPalette, GtkOffscreenWindow. Improvement on file chooser,
keyboard handling, GDK.Introspection data is now included in GTK+
2.20.1
2.22 23 September 2010 gdk-pixbuf moved to separate module, most GDK drawing are based on Cairo,
many internal data are now private and can be sealed in preparation to GTK+3
2.22.1
2.24 30 January 2011 New simple combo box widget (GtkComboBoxText) added, the cups print backend can send print jobs as PDF,
GtkBuilder has gained support for text tags and menu toolbuttons and many introspection annotation fixes were added
2.24.8
3.0 10 February 2011 Cairo, more X11 agnostic, XInput2, CSS-based theme API 3.0.12
3.2 25 September 2011 New experimental Wayland and HTML5 backends, New Font Chooser dialog, New widgets: GtkLockButton and GtkOverlay 3.2.0

Future developments

Project Ridley is an attempt to consolidate several libraries that are currently external to GTK+, including libgnome, libgnomeui, libgnomeprint22, libgnomeprintui22, libglade, libgnomecanvas, libegg, libeel, gtkglext, and libsexy.[4]

Developers are also considering new directions for the library, including removing deprecated API components and adding an integrated scene graph system, similar to the Clutter graphics library, effectively integrating GTK+ with OpenGL.[5][6]

Development and design of the GTK+ 3 release of the toolkit started in February 2009 during the GTK+ Theming Hackfest held in Dublin.[7] A first draft of the development roadmap has been released on 9 April 2009.[8]

GTK+ hello world

The following code presents a graphical GTK+ hello-world program in the C programming language. This program has a window with the title "Hello, world!" and a label with similar text.

#include <gtk/gtk.h>
 
int main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *label;
 
    gtk_init(&argc, &argv);
 
    /* Create the main, top level window */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
    /* Give it the title */
    gtk_window_set_title(GTK_WINDOW(window), "Hello, world!");
 
    /*
    ** Map the destroy signal of the window to gtk_main_quit;
    ** When the window is about to be destroyed, we get a notification and
    ** stop the main GTK+ loop by returning 0
    */
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
 
    /*
    ** Assign the variable "label" to a new GTK label,
    ** with the text "Hello, world!"
    */
    label = gtk_label_new("Hello, world!");
 
    /* Plot the label onto the main window */
    gtk_container_add(GTK_CONTAINER(window), label);
 
    /* Make sure that everything, window and label, are visible */
    gtk_widget_show_all(window);
 
    /*
    ** Start the main loop, and do nothing (block) until
    ** the application is closed
    */
    gtk_main();
 
    return 0;
}

Using GCC and pkg-config in a Unix shell, this code can be compiled with the following command (assume above source has file name "helloworld.c"):

$ gcc -Wall helloworld.c -o helloworld `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`

GTK+ example using Vala instead of C

To create a "Hello World" program in Vala instead of C, do the following:

GeSHi Error: GeSHi could not find the language vala (using path /usr/share/php-geshi/geshi/) (code 2)

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, avisynth, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cfdg, cfm, cil, cmake, cobol, cpp, cpp-qt, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, gnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml, ocaml-brief, oobas, oracle11, oracle8, pascal, per, perl, php, php-brief, pic16, pixelbender, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80

Uses

Environments that use GTK+

GTK+ programs do not require a desktop environment made with GTK+. If the required libraries are installed, a GTK+ program can run on top of other X11-based desktop environments or window managers; this includes Mac OS X if X11.app is installed (which is the default since the Leopard release). GTK+ can also run under Microsoft Windows, where it is used by some popular cross-platform applications like Pidgin and GIMP. wxWidgets, a cross-platform GUI toolkit, uses GTK+ for Unix-like operating systems.[9] Other ports include DirectFB (used by the Debian installer, for example) and ncurses.[10]

Window managers

The following window managers use GTK+

Applications

Some notable applications that use GTK+ as a widget toolkit include:

See also

References

Bibliography

External links