View creation

It is the vpd->view_create = hello_create; with hello_create being a function defined like this :

mstatic void* hello_create(gabywindow* window, gboolean first);

Important: hello_create is defined as a "mstatic" function, this means that it will be static excepted when compiled with Miguel wishes.

Its purpose is to create a widget which will then be put either in the main window of Gaby either in a separate window. This widget will then be recorded at window->widget. This means that the widget has not to be a window with title bar and the like. It will commonly be a Gtk[V,H]Box but any GTK container will work.

Let's have an example :

Example 12-2. Creating a view

mstatic void hello_create ( gabywindow *window, gboolean first )
{
        GtkWidget *vbox;
        GtkWidget *label;
        GtkWidget *hbb;
        GtkWidget *button;
        int *id = &(window->id);
        record *r;

        r = table_first(v->subtable->table, -1);
        *id = ( r == NULL ? 0 : r->id );

        r = table_first(window->view->subtable->table, -1);
        *id = ( r == NULL ? 0 : r->id );

        vbox = gtk_vbox_new(FALSE,0);
        window->widget = vbox;

        label = gtk_label_new("");
        gtk_widget_show(label);
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);

        hbb = gtk_hbutton_box_new();
        gtk_widget_show(hbb);
        gtk_box_pack_start(GTK_BOX(vbox), hbb, FALSE, TRUE, 0);

        button = gtk_button_new_with_label(_("Previous"));
        gtk_widget_show(button);
        gtk_signal_connect(GTK_OBJECT(button), "clicked", \
                                GTK_SIGNAL_FUNC(previous_clicked), window);
        gtk_container_add(GTK_CONTAINER(hbb), button);

        button = gtk_button_new_with_label(_("Next"));
        gtk_widget_show(button);
        gtk_signal_connect(GTK_OBJECT(button), "clicked", \
                                GTK_SIGNAL_FUNC(next_clicked), window);
        gtk_container_add(GTK_CONTAINER(hbb), button);

        gtk_widget_show(vbox);

        return;
}
Most lines are typical GTK as described in GTK documentation. The interesting lines are :
        int *id = &(window->id);
        record *r;
        r = table_first(v->subtable->table, -1);
        *id = ( r == NULL ? 0 : r->id );
This sets the record you're currently on to the first record of the table; or to 0 if the table is empty.

Note that unlike the previous version of the API you don't have to play with lots of gtk_object_get_data in your plug-ins, making them cleaner.