User:Gnepets/chap1

In this chapter we will look at some very simple GTK+ examples. Theory will be at the bottom of this chapter, it should be much easier to digest once you have written some code.

An empty window
In this example we create a single window, set its title and size and connect an event that allows the application to close.

Congratulations, you have created your first GTK+ window. You may not completely understand the code you have written yet, thats allright eventually you will. GTK+ is object oriented, as C is not designed as an object oriented language you must explicitly upcast and downcast objects, this will occur most often with the paramater passed to a function. You first cast window from a GtkWidget to a GtkWindow when you wrote GTK_WINDOW (window).

This call initialise GTK+ and hands to it a list of command line arguments the program recieved when initialising.

This line creates a new GtkWindow down cast as a GtkWidget
 * GTK_WINDOW_TOPLEVEL A gtk window that registers itself to the window manager as a window.

this function sets the title of a GtkWindow.
 * GTK_WINDOW (window) the main window, cast from a GtkWidget to a GtkWindow
 * "Hello World" the new title of the window

we are setting the windows size request, as the name suggests a size request does not guarantee you will get a specific size, you will learn more about this later.
 * window a GtkWidget
 * 200 width
 * 200 height

we are connecting a callback (function) to be called when the "destroy" event is emitted from window.
 * G_OBJECT (window) window cast as a G_OBJECT
 * "destroy" the signal that is being connected to
 * G_CALLBACK (gtk_main_quit) the function that is called when the signal is sent
 * NULL an empty gpointer, for data that could be passed to the function

show the widget window, all widgets must be shown including all parent widgets.
 * window the widget that is being made visible

we rest in GTKs main loop until gtk_main_quit is called; we have connected gtk_main_quit  to the windows "destroy" event.

Window with a button
TODO

Theory
TODO