Suppressing Keyword Events

Sometimes it is neccesary to prevent that a keyword handler will be called as the result of a call to wkeyf. This can be the case when two keywords mutually influence each other, which could lead to an endless stream of events. There can also be other reasons to suppress the handling of an event.

In the following example there are two input elements: a text field into which a value can be typed and a gauge with a logarithmic representation of the value in the text field. If the user changes the text field, the gauge should be updated and if the gauge is manipulated, the text field must follow. In order to achieve this, the handlers of each of the keywords call wkeyf with an appropriate value for the other keyword. But it must be prevented that the handler for the other keyword will call wkeyf for the first keyword again, as this would lead to a continuous stream of unnecessary events. In a simple example like this, this could be done by maintaining a flag which would tell the handlers when it should not update the other element. But it is easier to call SuppressKeyevent(). Certainly when a program is more complicated, it would become quite cumbersome to administrate things.

Example program:

/* example6.c -XT */

#include "stddef.h"
#include "math.h"
#include "gipsyc.h"
#include "cmain.h"
#include "init.h"
#include "userfio.h"
#include "ggi.h"

static void logvalue(ident id, char *key, int code, void *arg);
static void realvalue(ident id, char *key, int code, void *arg);

 *    Keyword handler converting logarithmic to real value.
static void realvalue(ident id, char *key, int code, void *arg)
   float value;
   (void)userfreal(&value, 1, 2, key, " ");
   SuppressKeyevent(logvalue, (char*)arg);
   wkeyf("%s%.1f", (char*)arg, exp(value));

 *    Keyword handler converting real to logarithmic value.
static void logvalue(ident id, char *key, int code, void *arg)
   float value;
   (void)userfreal(&value, 1, 2, key, " ");
   if (value>0.0) {
      SuppressKeyevent(realvalue, (char*)arg);
      wkeyf("%s%.1f", (char*)arg, log(value));

 *   Main program
   ident text, gauge;


   text  = GgiSetLabel(GgiTextField("VALUE=", NULL, 4), "Value", 0);
   gauge = GgiGauge("LOGVAL=", NULL, 150, log(1.0), log(10.0));
   (void)GgiSetLabel(gauge, " ", 1);

   GgiSetPosition(text,  0, NULL, 0, NULL);
   GgiSetPosition(gauge, 0, text, 0, NULL);


   ScheduleKeyevent(logvalue,  "VALUE=",  KEYCHANGE, "LOGVAL=");
   ScheduleKeyevent(realvalue, "LOGVAL=", KEYCHANGE, "VALUE=");

Programming GIPSY Maintained by J. P. Terlouw