GTK+ Architecture

GTK+ is written in C

It uses OO programming paradigm in C

GTK+ is built on top of GLIB,GObject and the GDK libraries.

GTK+

Gobject

GDK+

Glib

GTK+ layers

GTK+ http://www.gtk.org

-Muthiah A, Octave-Gtk+ team [gnumuthu@users.sf.net]

These slides are licensed under GNU FDL

GTK+ Type system
-Muthiah A, Octave-Gtk+ team

Glib & Gobject implement type system

Static & dynamic type registration

Classes & Objects can be created

Inheritance,polymorphism & encapsulation

GTK+ is GIMP Tool Kit, used in making GIMP.

G_TYPE_

FUNDAMENTAL

G_TYPE_OBJECT

GDK_TYPE_*

GTK_TYPE_*

GTK+ C OOP Vs C++
-Muthiah A, Octave-Gtk+ team

GTK+ C code, makes write easy wrappers. GTK+ bindings exist for more than 10 languages.

C++ code:

class usa: private hitler

{

dictator president;

timespan fouryears;

decmocracies UN[198];

vector<villains> terrorists;

america(string name);

private greencard(void);

void vote(citizen kane);

};

C code:

typedef struct _usa usa;

typedef struct _usaclass usaclass;

struct _usa

{

dictator president;

timespan fouryears;

democracies UN[198];

GSList terrorists;

}

GTK+ C OOP Vs C++
-Muthiah A, Octave-Gtk+ team

GTK+ C code has canonical code, for making standard

types and classes, which g++ makes for our C++ programs

C++ code:

class usa: private hitler

{

dictator president;

timespan fouryears;

decmocracies UN[198];

vector<villains> terrorists;

america(string name);

private greencard(void);

void vote(citizen kane);

};

C code: [contd]

struct _usaclass

{

GObject parent_class;

void (*greencard)(void);

}

usa_get_type(void);

usa_new(char *name);

usa_greencard(void);

usa_vote(citizen *kane);

Guts of GTK+ Type system
-Muthiah A, Octave-Gtk+ team

usa_get_type(void)

{

static int x=0;

if(!x)

{ static struct Gtype info

={

// base class init/clean

// our class init/clean

// other things Vtables

};

x=g_type_register_static()

}

return x;

}

usa_class_init(usaclass *klass)

{

hitler *class=(hitler *)klass;

class->vote=usa_vote;

klass->greencard=usa_greencard;

};

usa_init(usa *obj)

{

obj->president=”Abe Lincoln”;

obj->fouryears=4;

obj->terrorists=NULL;
}

GTK+ types are inited when we call gtk_init(), before creating any widgets.

GTK+ Inheritance
-Muthiah A, Octave-Gtk+ team

GTK+ is very fast because of the type system it implements, instead of depending on compilers.

On calling gtk_init() we setup the fundamental types

Other types are initialized when we first create them.

The gtk_window_new() class of functions register types.

Type system allows us to create user defined types.

New objects, inherited from Gobject, GTKObject or derived ones.

GTK classes are inited once.

gtk_windowclass_init registers the member functions and overrides the parent class types/member-functions.

Those function's of the parent we fail to override, will fall through to the parent. That is parents functions will be called if our handler [function pointer] is NULL.

So GTK+ is OOP get it!

GTK+ overview
-Muthiah A, Octave-Gtk+ team

GTK+ is glues well to scripting languages due to its

C code base; this makes GTK bindings popular

GTK system

GDK system

Drawing Functions

Xlib

Native Drawing

Signal & Event system

GObject system

Glib system

Threads & Main Loop

User Code

Enter main loop

Callbacks

GTK+ examples
-Muthiah A, Octave-Gtk+ team

GTK+ system is event driven!

We can extend GTK+ widgets to create our OWN. One such is the GTK dial widget.

GIMP main widget.

GTK+ examples
-Muthiah A, Octave-Gtk+ team

Access GTK+ demo programs by

[muthu@EarthSimulator]$ gtk-demo & #enjoy gtk

The GTK demo suite of programs

GTK+ examples
-Muthiah A, Octave-Gtk+ team

GTK+ system is event driven!

GTK Application program

GTK programs are interactive!

GTK+ Reference
-Muthiah A, Octave-Gtk+ team

Im writing a book on GTK+ along with Ishan Chattopadyay, who maintains GTK+ port for windows.

www.gtk.org , is the primary location for documents & source code.

www.gnome.org ,is the biggest project using GTK+

Gnome desktop is written fully on GTK+

Lots of mailing lists at http://mail.gnome.org

The gtk-app-devel@lists.gnome.org is a good place to start

Online Books by Havoc Pennington, GGAD ,free from http://developer.gnome.org , check it out

GTK+ Resources
-Muthiah A, Octave-Gtk+ team

Click on http://cybernetics.freewebspace.com/gtk

and get this whole presentation as a tarball.

Language Bindings for:

C API is automatically what the GTK+2.4 releases come with. Get it from www.gtk.org .

C++: gtkmm, a superb uptodate in touch with the latest GTK+2.4 sources http://gtkmm.sf.net

Python: http://www.pygtk.org ,is also hot on the trails of GTK+2.4

Perl : http://perl-gtk.sf.net is another uptodate binding.

Java: Java GNOME binding is also uptodate.

GTK#: The binding for C# is pushed by MONO project. See www.mono-project.com and http://gtksharp.sf.net .

Haskell, C# , Clisp , R and many more languages have GTK+ bindings.

2004-07-21T20:56:07