Sunday, July 03, 2011

cget -data

One of the great features of Tk/Gnocl widgets is data association. For some time now its been possible to set the -data options but not to extract it. The reason for this is that such associations are not gtk widget properties although support for the feature is via the Gdk libraries. I'm currently working on a Gnocl scripted megawidget which needs extra items of data passes to its events handlers, the -data option is ideal for this. Implementing the feature is a simple process, as the following code extract from the entry.c module cget function shows.

static const int variableIdx = 0;
static const int onChangedIdx = 1;
static const int valueIdx = 2;
static const int cursorIdx = 3;
static const int primaryIconIdx = 4;
static const int secondaryIconIdx = 5;
static const int dataIdx = 6;

static GnoclOption entryOptions[] =
{
    /* gnocl unique and complex options handled through configure */
    { "-variable", GNOCL_STRING, NULL },        /* 0 */
    { "-onChanged", GNOCL_STRING, NULL },   /* 1 */
    { "-value", GNOCL_STRING, NULL },            /* 2 */
    { "-showCursor", GNOCL_BOOL, NULL},      /* 3 */
    { "-primaryIcon", GNOCL_OBJ, NULL },        /* 4 */
    { "-secondaryIcon", GNOCL_OBJ, NULL },    /* 5 */
    { "-data", GNOCL_OBJ, "", gnoclOptData },  /* 6 */
...

static int cget ( Tcl_Interp *interp, EntryParams *para, GnoclOption options[], int idx )
{
    if ( idx == dataIdx )
    {
        obj = Tcl_NewStringObj ( g_object_get_data ( para->entry, "gnocl::data" ), -1 );
    }
...


The next step is ensuring that the functionality works for all widgets.

No comments: