View filling

As I just said (and as the title says) this is the function which will take datas from a table to show them in the beautiful widgets you just created.

Here is the code :

Example 12-3. Filling a view

mstatic void hello_fill ( gabywindow *window )
{
        view *v = window->view;
        int *id = &(window->id);
        GtkWidget *label = gtk_object_get_data(GTK_OBJECT(win), "label");
        GString *str;
	
        if ( *id == 0 ) {
                gtk_label_set_text(GTK_LABEL(label), _("Hello, world !"));
                return;
        }

        str = get_subtable_stringed_field_id(v->subtable, *id, 0 );

        str = g_string_prepend(str, _("Hello, "));
        gtk_label_set_text(GTK_LABEL(label), str->str);
        g_string_free(str, 1);
}

The first thing is to retrieve the label widget we'll use to show the information :
        GtkWidget *label = gtk_object_get_data(GTK_OBJECT(win), "label");

Then we check if we have a record to show, since record ids start at 1, 0 means no record to show :
        if ( *id == 0 ) {
                gtk_label_set_text(GTK_LABEL(label), _("Hello, world !"));
                return;
        }

The easy case is done. Now we know that we have a real record to show. Since this is just an example, we'll just show one field and to be sure it will work with any tables we'll show the first one.
        str = get_subtable_stringed_field_id(v->subtable, *id, 0 );
It is now easy as adding "Hello" before the string we got and showing it in a widget :
        str = g_string_prepend(str, _("Hello, "));
        gtk_label_set_text(GTK_LABEL(label), str->str);
It is now finished, we free the string and leave.