2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afsconfig.h>
12 #include <afs/param.h>
18 #include <sys/types.h>
25 #include "gtxobjects.h"
26 #include "gtxwindows.h"
27 #include "gtxcurseswin.h"
29 #include "gtxkeymap.h"
32 extern char *gtx_CopyString();
33 static struct keymap_map *recursiveMap = 0;
34 static char menubuffer[1024]; /*Buffer for menu selections */
35 int gtxframe_exitValue = 0; /*Program exit value */
37 gtxframe_CtrlUCmd(awindow, arock)
41 struct gtx_frame *tframe;
43 tframe = awindow->w_frame;
44 if (!tframe->defaultLine)
46 *(tframe->defaultLine) = 0;
50 gtxframe_CtrlHCmd(awindow, arock)
54 register struct gtx_frame *tframe;
58 tframe = awindow->w_frame;
59 if (!(tp = tframe->defaultLine))
63 return 0; /* rubout at the end of the line */
68 gtxframe_RecursiveEndCmd(awindow, arock)
70 register struct gwin *awindow;
72 register struct gtx_frame *tframe;
74 tframe = awindow->w_frame;
75 tframe->flags |= GTXFRAME_RECURSIVEEND;
76 tframe->flags &= ~GTXFRAME_RECURSIVEERR;
80 gtxframe_RecursiveErrCmd(awindow, arock)
82 register struct gwin *awindow;
84 register struct gtx_frame *tframe;
86 tframe = awindow->w_frame;
87 tframe->flags |= GTXFRAME_RECURSIVEEND;
88 tframe->flags |= GTXFRAME_RECURSIVEERR;
92 gtxframe_SelfInsertCmd(awindow, arock)
96 register struct gtx_frame *tframe;
100 tframe = awindow->w_frame;
101 if (!(tp = tframe->defaultLine))
104 tp[pos] = arock; /* arock has char to insert */
105 tp[pos + 1] = 0; /* null-terminate it, too */
109 /* save map, setup recursive map and install it */
112 register struct gtx_frame *aframe;
118 /* setup recursive edit map if not previously done */
119 recursiveMap = keymap_Create();
120 keymap_BindToString(recursiveMap, "\010", gtxframe_CtrlHCmd, NULL,
122 keymap_BindToString(recursiveMap, "\177", gtxframe_CtrlHCmd, NULL,
124 keymap_BindToString(recursiveMap, "\025", gtxframe_CtrlUCmd, NULL,
126 keymap_BindToString(recursiveMap, "\033", gtxframe_RecursiveEndCmd,
128 keymap_BindToString(recursiveMap, "\015", gtxframe_RecursiveEndCmd,
130 keymap_BindToString(recursiveMap, "\012", gtxframe_RecursiveEndCmd,
132 keymap_BindToString(recursiveMap, "\003", gtxframe_RecursiveErrCmd,
134 keymap_BindToString(recursiveMap, "\007", gtxframe_RecursiveErrCmd,
137 for (i = 040; i < 0177; i++) {
140 keymap_BindToString(recursiveMap, tstring, gtxframe_SelfInsertCmd,
144 aframe->savemap = aframe->keymap;
145 aframe->keymap = recursiveMap;
146 keymap_InitState(aframe->keystate, aframe->keymap);
150 /* Restore map to previous value */
153 register struct gtx_frame *aframe;
155 aframe->keymap = aframe->savemap;
156 aframe->savemap = (struct keymap_map *)0;
157 keymap_InitState(aframe->keystate, aframe->keymap);
161 gtxframe_SetFrame(awin, aframe)
162 struct gtx_frame *aframe;
166 /* Unthread this frame */
167 awin->w_frame->window = NULL;
169 awin->w_frame = aframe;
170 aframe->window = awin; /* Set frame's window ptr */
175 gtxframe_GetFrame(awin)
178 return awin->w_frame;
181 /* Add a menu string to display list */
182 gtxframe_AddMenu(aframe, alabel, astring)
185 struct gtx_frame *aframe;
187 register struct gtxframe_menu *tmenu;
190 for (tmenu = aframe->menus; tmenu; tmenu = tmenu->next) {
191 if (strcmp(alabel, tmenu->name) == 0)
194 tmenu = (struct gtxframe_menu *)0;
196 /* Handle everything but the command string, which is handled by the
197 * common-case code below */
198 tmenu = (struct gtxframe_menu *)malloc(sizeof(*tmenu));
199 if (tmenu == (struct gtxframe_menu *)0)
201 memset(tmenu, 0, sizeof(*tmenu));
202 tmenu->next = aframe->menus;
203 aframe->menus = tmenu;
204 tmenu->name = gtx_CopyString(alabel);
208 * Common case: redo the string labels. Note: at this point, tmenu
209 * points to a valid menu.
211 if (tmenu->cmdString)
212 free(tmenu->cmdString);
213 tmenu->cmdString = gtx_CopyString(astring);
217 /* Delete a given menu from a frame*/
218 gtxframe_DeleteMenu(aframe, alabel)
219 struct gtx_frame *aframe;
222 register struct gtxframe_menu *tm, **lm;
224 for (lm = &aframe->menus, tm = *lm; tm; lm = &tm->next, tm = *lm) {
225 if (strcmp(alabel, tm->name) == 0) {
226 /* found it, remove and return success */
227 *lm = tm->next; /* unthread from list */
234 return (-1); /* failed to find entry to delete */
237 /* Function to remove all known menus */
238 gtxframe_ClearMenus(aframe)
239 struct gtx_frame *aframe;
242 register struct gtxframe_menu *tm, *nm;
244 if (aframe->menus != (struct gtxframe_menu *)0) {
245 for (tm = aframe->menus; tm; tm = nm) {
253 aframe->menus = (struct gtxframe_menu *)0;
257 gtxframe_AskForString(aframe, aprompt, adefault, aresult, aresultSize)
258 register struct gtx_frame *aframe;
267 /* Ensure recursive-edit map is initialized */
271 if (aframe->promptLine)
272 free(aframe->promptLine);
273 if (aframe->defaultLine)
274 free(aframe->defaultLine);
275 aframe->promptLine = gtx_CopyString(aprompt);
276 tp = aframe->defaultLine = (char *)malloc(1024);
280 strcpy(tp, adefault);
284 /* Do recursive edit */
285 gtx_InputServer(aframe->window);
286 tp = aframe->defaultLine; /* In case command reallocated it */
288 /* Back from recursive edit, check out what's happened */
289 if (aframe->flags & GTXFRAME_RECURSIVEERR) {
294 if (code + 1 > aresultSize) {
301 /* Fall through to cleanup and return code */
304 if (aframe->promptLine)
305 free(aframe->promptLine);
306 if (aframe->defaultLine)
307 free(aframe->defaultLine);
308 aframe->defaultLine = aframe->promptLine = NULL;
310 gtxframe_DisplayString(aframe, "[Aborted]");
314 gtxframe_DisplayString(aframe, amsgLine)
316 register struct gtx_frame *aframe;
318 if (aframe->messageLine)
319 free(aframe->messageLine);
320 aframe->messageLine = gtx_CopyString(amsgLine);
323 /* Called by input processor to try to clear the dude */
324 gtxframe_ClearMessageLine(aframe)
325 struct gtx_frame *aframe;
327 /* If we haven't shown message long enough yet, just return */
328 if (aframe->flags & GTXFRAME_NEWDISPLAY)
330 if (aframe->messageLine)
331 free(aframe->messageLine);
332 aframe->messageLine = NULL;
337 ShowMessageLine(aframe)
338 struct gtx_frame *aframe;
340 struct gwin_strparams strparms;
341 struct gwin_sizeparams sizeparms;
347 /* First, find window size */
348 WOP_GETDIMENSIONS(aframe->window, &sizeparms);
350 if (aframe->promptLine) {
351 memset(&strparms, 0, sizeof(strparms));
353 strparms.y = sizeparms.maxy - 1;
354 strparms.highlight = 1;
355 tp = strparms.s = (char *)malloc(1024);
356 strcpy(tp, aframe->promptLine);
357 strcat(tp, aframe->defaultLine);
358 WOP_DRAWSTRING(aframe->window, &strparms);
359 aframe->flags |= GTXFRAME_NEWDISPLAY;
360 } else if (aframe->messageLine) {
361 /* Otherwise we're visible, print the message at the bottom */
362 memset(&strparms, 0, sizeof(strparms));
363 strparms.highlight = 1;
365 strparms.y = sizeparms.maxy - 1;
366 strparms.s = aframe->messageLine;
367 WOP_DRAWSTRING(aframe->window, &strparms);
368 aframe->flags |= GTXFRAME_NEWDISPLAY;
373 /* Exit function, returning whatever has been put in its argument */
375 gtxframe_ExitCmd(a_exitValuep)
378 { /*gtxframe_ExitCmd */
380 int exitval; /*Value we've been asked to exit with */
382 /* This next call should be type independent! */
383 gator_cursesgwin_cleanup(&gator_basegwin);
385 exitval = *((int *)(a_exitValuep));
388 } /*gtxframe_ExitCmd */
393 struct gtx_frame *tframe;
394 struct keymap_map *newkeymap;
395 struct keymap_state *newkeystate;
398 * Allocate all the pieces first: frame, keymap, and key state.
400 tframe = (struct gtx_frame *)malloc(sizeof(struct gtx_frame));
401 if (tframe == (struct gtx_frame *)0) {
402 return ((struct gtx_frame *)0);
405 newkeymap = keymap_Create();
406 if (newkeymap == (struct keymap_map *)0) {
408 * Get rid of the frame before exiting.
411 return ((struct gtx_frame *)0);
414 newkeystate = (struct keymap_state *)
415 malloc(sizeof(struct keymap_state));
416 if (newkeystate == (struct keymap_state *)0) {
418 * Get rid of the frame AND the keymap before exiting.
422 return ((struct gtx_frame *)0);
426 * Now that all the pieces exist, fill them in and stick them in
429 memset(tframe, 0, sizeof(struct gtx_frame));
430 tframe->keymap = newkeymap;
431 tframe->keystate = newkeystate;
432 keymap_InitState(tframe->keystate, tframe->keymap);
433 keymap_BindToString(tframe->keymap, "\003", gtxframe_ExitCmd, "ExitCmd",
434 (char *)(>xframe_exitValue));
437 * At this point, we return successfully.
442 gtxframe_Delete(aframe)
443 register struct gtx_frame *aframe;
445 keymap_Delete(aframe->keymap);
446 free(aframe->keystate);
447 if (aframe->messageLine)
448 free(aframe->messageLine);
453 gtxframe_Display(aframe, awm)
455 register struct gtx_frame *aframe;
457 register struct gtxframe_dlist *tlist;
458 register struct gtxframe_menu *tm;
459 struct gwin_strparams strparms;
461 /* Run through the menus, displaying them on the top line */
463 for (tm = aframe->menus; tm; tm = tm->next) {
464 strcat(menubuffer, tm->name);
465 strcat(menubuffer, ":");
466 strcat(menubuffer, tm->cmdString);
467 strcat(menubuffer, " ");
469 if (menubuffer[0] != 0) {
470 memset(&strparms, 0, sizeof(strparms));
473 strparms.s = menubuffer;
474 strparms.highlight = 1;
475 WOP_DRAWSTRING(awm, &strparms);
478 /* Run through the display list, displaying all objects */
479 for (tlist = aframe->display; tlist; tlist = tlist->next) {
480 OOP_DISPLAY(((struct onode *)(tlist->data)));
483 /* Finally, show the message line */
484 ShowMessageLine(awm->w_frame);
488 /* Add an object to a window's display list */
489 gtxframe_AddToList(aframe, aobj)
491 register struct gtx_frame *aframe;
493 register struct gtxframe_dlist *tlist;
495 for (tlist = aframe->display; tlist; tlist = tlist->next) {
496 if (tlist->data == (char *)aobj) {
498 * Don't add the same thing twice.
505 * OK, it's not alreadyt there. Create a new list object, fill it
506 * in, and splice it on.
508 tlist = (struct gtxframe_dlist *)malloc(sizeof(struct gtxframe_dlist));
509 if (tlist == (struct gtxframe_dlist *)0)
511 tlist->data = (char *)aobj;
512 tlist->next = aframe->display;
513 aframe->display = tlist;
517 /* Remove an object from a display list, if it is already there */
518 gtxframe_RemoveFromList(aframe, aobj)
520 register struct gtx_frame *aframe;
522 register struct gtxframe_dlist *tlist, **plist;
524 plist = &aframe->display;
525 for (tlist = *plist; tlist; plist = &tlist->next, tlist = *plist) {
526 if (tlist->data == (char *)aobj) {
527 *plist = tlist->next;
532 return (-1); /* Item not found */
535 /* Clear out everything on the display list for the given frame*/
536 gtxframe_ClearList(aframe)
537 register struct gtx_frame *aframe;
539 register struct gtxframe_dlist *tlist, *nlist;
541 if (aframe->display != (struct gtxframe_dlist *)0) {
543 * Throw away each display list structure (we have at least
546 for (tlist = aframe->display; tlist; tlist = nlist) {
552 aframe->display = (struct gtxframe_dlist *)0;