Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/gipsy/pguide/gui-example6.html
Дата изменения: Unknown Дата индексирования: Sat Jan 17 05:27:16 2009 Кодировка: Поисковые слова: mars polar lander |
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 as 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.
/* 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 */ MAIN_PROGRAM_ENTRY { ident text, gauge; init_c(); GgiAutoLayout(FALSE); GgiPostponeRealize(TRUE); 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); GgiRealize(); ScheduleKeyevent(logvalue, "VALUE=", KEYCHANGE, "LOGVAL="); ScheduleKeyevent(realvalue, "LOGVAL=", KEYCHANGE, "VALUE="); wkeyf("VALUE=2.0"); MainLoop(); }
![]() ![]() |
Maintained by J. P. Terlouw |