Sheet Signals

The interaction between user and sheet is done(as in all Gtk programs) through signals. In GtkSheet the next signals are implemented :

If you want to catch these signals , you must connect them to a callback(function that treats the signal/event).

The most used signals are : ACTIVATE,DEACTIVATE,TRAVERSE .

Callback functions for different signals have different parameters. For a correct use you should check out the Gtk-Extra Reference Manual , the examples or GtkSheet source code. Incorrect use of the callback function parameters will have an undefined result(in the worst case).

The ACTIVATE signal should be connected if you want to do something when a cell is clicked:

g_signal_connect(G_OBJECT(sheet),
                   "activate",
                   alarm_activate,
                    NULL);

//The callback function should have these parameters:

gint alarm_activate(GtkWidget *sheet, 
                    gint row, gint col, gpointer data)
{
................
}

If you have different functions that require the same cell to behave in a different way , I suggest that instead of writing "n" alarm_activate() callbacks , write just one callback function that looks like this:

g_signal_connect(G_OBJECT(sheet),
                   "activate",
                   alarm_activate,
                   (gpointer)function_name);

When the signal is connected , pass the function name (for example) as the last parameter.


gint alarm_activate(GtkWidget *sheet, 
                    gint row, gint col, gpointer function_name)
{
     if(strcmp(function_name,"table_new")==0){
               .....do_some_stuf()
     }
     else if(strcmp(function_name,"table_edit")==0){
               .....do_other_stuf()
     }
}

In this way , you will have a much cleaner code with fewer functions as possible. It is better to have a single callback function that treats all posible behaviour cases , instead of many functions which make the code harder to read.

A very important signal is TRAVERSE.

gtk_signal_connect(G_OBJECT(sheet),
                   "traverse",
                   alarm_traverse,
                    NULL);

//The callback function should have these parameters:


gint alarm_traverse(GtkWidget *widget,
                    gint row, gint col, gint *new_row, gint *new_col,
                    gpointer data)

{
...........
}

The "traverse" signal is emited before "deactivate_cell" and allows to veto the movement. In such case, the entry will remain in the site, and the other signals will not be emited.

The traverse signal is useful when you need to know what cell have you previously clicked or what was selected.

The explanation for the the other signals is quite straightforward so if you want more details you should check GtkSheet Reference Manual or the GtkSheet source code.