http://zetcode.com/tutorials/gtktutorial/
gcc -o simple1 simple1.c `pkg-config --libs --cflags gtk+-2.0`


Diu l'autor del tutorial:
*http://www.gtkforums.com/about5729.html

I am the author of the GTK+ tutorial on the ZetCode website.

The API was broken in a newer version of the library. This is something, which programmers are not happy about. If you are a serious programmer, you will run into this sooner or later. This is called "being a programmer".

Just because there is a newer version of a library does not mean, you have to update the tutorial/your code right away. How many people use older versions of the library and how many people use newer versions, where the API was changed? I have worked on a large J2EE project, where we used Java 1.4. At that time, Sun has already released Java 1.6. So what? The customer had certain requirements and we had to fulfill them. No matter what the current Java language was.

On my Ubuntu 8.10, the example still compiles OK. The system uses GTK 2.14. The most current version is 2.20. Somewhere in between the API was broken. If you have a look at the Gnome site, you will see lots of libraries, that are going to be removed soon. bonobo, libart, libglade, orbit, libvfs etc. This was one of the major reasons, I have not expanded the tutorial. I have no intention to write tutorials about ephemeral things.
I will wait until things get more stable.

I like GTK+ and I will write additional tutorials about this library. And I will update the tutorial. One day, when the time comes.

PS: Charles Petzold has written a book on Winapi, Programming Windows, which is considered to be a bible on the topic. It is 12 years old. All the examples work on newer systems! Surely, newer APIs are not covered, but the foundations are there. This is simply because the backward compatibility was retained.
---
Hello.

I didn't want to sound cocky when I said that your tutorial is outdated and I'm sorry if it sounded like that. But there are couple of things that bothered me when I was reading your code, so I decided to update it.

Now, I know that APIs do change, but you're using some really old stuff in your code like GTK_CHECK_CAST macro, which has been deprecated since GLib and GTK+ 2.0 came out and type system has been moved to GLib (cca. 5 years ago). I'm coding for some time in GTK+ and I never used them, since they were already deprecated at the time I started.

But it's not just deprecated API that bothered me. You custom widget also doesn't follow established GObject coding practices that are followed by developers using GObject. A few deviations of your code that really do not belong into beginner-friendly tutorial:

    * Standard GObject macros are not defined: GTK_TYPE_CPU, GTK_IS_CPU_CLASS and GTK_CPU_GET_CLASS are missing
    * GObjects should have no public fields (exception being priv pointer for more efficient access to private data)
    * GObjects fileds should not be directly modified by application code. Accessors should be used instead.
    * Functionality of the object should be encapsulated in it (modifying a value should perform all updates automatically). Without encapsulation, there is no point in having custom widget, since you can manually paint GtkDrawingArea instead.

Hopefully you see now that your tutorial is not only slightly outdated and that API changes are really minor annoyance in this case.

Tadej
---
Tadej,

I agree with what you say. I think I am going to remove the GObject system from the example. As far as I know, it is good when you want to have your widget ported to other languages. And this is not mandatory.
Moreover, the GObject system is way too complicated for a beginner tutorial.

If I one day write something about the GObject system, I will get back to it.
