[This article is translated to the Serbo-Croatian language by Jovana Milutinovich from Webhostinggeeks.com

Free Pascal interface to GDK/GTK


Introduction

The GTK toolkit and its companion GDK are quickly becoming (next to the Qt toolkit) a very popular X-windows programming toolkit. This makes it suitable as a base for the Free Component Library (FCL, the Free Pascal equivalent of the Delphi VCL). As a first step in the development of FCL, the gtk and gdk header files have been translated to Pascal. All header files have been translated, and are compilable. only a few testprograms are available (volunteers to make some are welcome to contact me), but success reports indicate that the units are translated correctly, and programs can be made. It even works on Win32. For this reason, both the Lazarus and KCL projects use GTK as a GUI toolkit.

Downloading

The gtk units are part of the Free Pascal packages, and are shipped with the official distrubution.

The GTK libraries must be downloaded from the original GTK site.

Using the units:

There is an article on programming GTK by Florian Klaempfl and Michael Van Canneyt, written for the German Toolbox magazine. The original English version (in PDF format) can be viewed here. The example programs source code can also be downloaded.

The following is a (very) short explanation of how to use the GTK units. Most of what can be found here is already described in the articles on GTK.

  1. In C, you only need to input gtk.h. Here you need to put gtk, and separately glib or gdk if you need them, in your uses clause.
  2. Names :
    • Pascal reserved words in types, record element names etc. have been prepended with the word 'the'. so 'label' has become 'thelabel'
    • functions have been kept with the same names.
    • for types : gdk names have been kept. Pointers to a type are defined as the type name, prepended with P. So 'GtkWidget *' becomes 'PGtkWidget'. In gtkobject, names also have been kept. In all other files, types have been prepended with T, that is, the C type 'GtkWidget' has become 'TGtkWidget'

      This is annoying, but C is case sensitive, and Pascal is not, so there you have it...

      When translating, I've tried to stick to this scheme as closely as I could. One day, however, all will be done in a uniform manner...

  3. Macros. Many C macros have not been translated. The typecasting macros have been dropped, since they're useless under pascal. Macros to access record members have been translated, BUT they are to be considered as READ-ONLY. So they can be used to retrieve a value, but not to store one. e.g.
    function GTK WIDGET FLAGS(wid : pgtkwidget) : longint;
    
    can be used to retrieve the widget flags, but not to set them. so things like
    GTK WIDGET FLAGS(wid):=GTK WIDGET FLAGS(wid) and someflag;
    
    will not work, since this is a function, and NOT a macro as in C.
  4. Packed records. GCC allows you to specify members of a record in bit format. Since this is impossible in pascal, functions and procedures to get/set these elements have been made. e.g.
    function width set(var a : TGtkCListColumn) : gint;
    procedure set width set(var a : TGtkCListColumn;   width set : gint);
    
    can be used to get or set the width in a TGtkCListColumn... in general, it's the name with ' set' appended for getting a value (set from 'a set') , and 'set ' prepended (from 'to set') and again ' set' appended.

There is also an article on programming GTK by Florian Klaempfl and Michael Van Canneyt, written for the German Toolbox magazine. The original English version (in PDF format) can be viewed here. The example programs source code can also be downloaded.

More information about programming GTK is available in the following documents:


Back to packages page.