Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/gipsy/pguide/gui-example9.html
Дата изменения: Unknown Дата индексирования: Sat Jan 17 05:27:23 2009 Кодировка: Поисковые слова: mercury program |
In a complex GUI there are also often elements which are used infrequently
or only during specific phases of the use of the program. When these elements
are put in the `main' GUI, they use up valuable screen space in an inefficient
manner. In such a case it is better to open a separate window containing
these elements whenever they are needed and close this window afterwards.
This can be accomplished with the special container element
created by
GgiShell(). Other elements can be
put into it in exactly the same way as decribed above using
GgiUseShell().
After such a shell container has been created, it
is not visible yet. It can be put on the screen, `popped up', by calling
GgiShowShell().
Removing it, `popping down', is also done with this routine.
A special kind of shell element can be created with
GgiDialog().
This element behaves exactly as a normal shell element,
except that user interaction is limited to this element.
A number of general purpose pop-up elements have been inplemented. E.g., GgiPrompter, which allows the controlled input of a text string, such as a file name, GgiPlotPrompter, for entering plot file names and devices, and GgiVerify, for simple yes/no questions. The next page will show examples of the use of these elements.
Main program:
/* example9.c -XT */ #include "stddef.h" #include "gipsyc.h" #include "cmain.h" #include "init.h" #include "finis.h" #include "userfio.h" #include "ggi.h" /* * Button keyword handler for quitting. */ static void quit(ident id, char *key, int code, void *arg) { bool button=toflog(FALSE); (void)userflog(&button, 1, 2, key, " "); if (tobool(button)) { wkeyf(key); /* reset button */ finis_c(); /* exit */ } } MAIN_PROGRAM_ENTRY { void MyShell(char *key); ident button, quitbtn; init_c(); GgiAutoLayout(FALSE); GgiPostponeRealize(TRUE); button = GgiButton("FILE=", "File name entry"); /* pop shell up/down */ quitbtn = GgiButton("QUIT=", "Terminate program"); /* quit button */ GgiSetPosition(button, 0, NULL, 0, NULL); GgiSetPosition(quitbtn, 0, button, 0, NULL); MyShell("FILE="); /* create pop-up shell */ GgiRealize(); /* show what we'e made */ (void)ScheduleKeyevent(quit, "QUIT=", KEYCHANGE, NULL); MainLoop(); }
Pop-up shell:
/* example9_s.c */ #include "stddef.h" #include "gipsyc.h" #include "ggi.h" /* * Keyword handler for popping shell up or down. */ static void popshell(ident id, char *key, int code, void *arg) { static bool state=FALSE; bool button=toflog(FALSE); (void)userflog(&button, 1, 2, key, " "); if (tobool(button)) { wkeyf(key); /* reset button */ GgiShowShell((ident)arg, !state); /* pop up/down */ state = !state; /* update state */ } } /* * Create pop-up shell with contents. */ void MyShell(char *key) { static ident shell; ident prev, frame, input, close; shell = GgiShell("Filename"); /* shell container */ prev = GgiUseShell(shell); /* save current, use shell */ frame = GgiForm("Filename", 2); /* frame, thickness 2 pixels */ close = GgiSetLabel(GgiButton(key, "Close window"), "CLOSE", 0); GgiSetPosition(frame, 0, NULL, 0, NULL); GgiSetPosition(close, 0, NULL, 0, frame); GgiUseShell(frame); /* use frame */ input = GgiTextField("FILENAME=", "File name", 10); GgiSetLabel(input, "File", 0); GgiSetPosition(input, 0, NULL, 0, NULL); (void)GgiShell(prev); /* return to saved container */ ScheduleKeyevent(popshell, key, KEYCHANGE, shell); /* schedule open/close */ }
Maintained by J. P. Terlouw |