|
|
1.1 root 1: /*
2: * Create a dialog box and edit the fields
3: *
4: * Copyright (c) 1991-93 Udo Munk
5: */
6:
7: #ifdef AIX
8: #define NLS
9: #endif
10:
11: #include <curses.h>
12: #include <string.h>
13: #include "winfun.h"
14:
15: extern WINDOW *open_window();
16: extern int close_window();
17: extern int tab_active;
18:
19: dialog_box(bp)
20: struct dial *bp;
21: {
22: register WINDOW *w;
23: register int i, j;
24: int bw, bh, ret;
25: int active = 0;
26: int eoj = 1;
27:
28: bh = bp->d_anz * 2 + 3; /* compute high of box */
29: bw = strlen(bp->d_text) + 2; /* compute width of box */
30: for (i = 0; i < bp->d_anz; i++) {
31: j = bp->d_ptr[i]->e_len + strlen(bp->d_ptr[i]->e_text) + 3;
32: if (j > bw)
33: bw = j;
34: }
35:
36: if ((w = open_window(bh, bw, (LINES-bh)/2, (COLS-bw)/2)) == (WINDOW *) 0)
37: nomem();
38:
39: wattron(w, A_REVERSE); /* output inverted box */
40: for (i = 0; i < bh; i++)
41: for (j = 0; j < bw; j++)
42: mvwaddch(w, i, j, ' ');
43: mvwaddstr(w, 1, 1, bp->d_text); /* output title */
44: for (i = 0; i < bp->d_anz; i++) { /* output label and field of element */
45: mvwaddstr(w, i*2+3, 1, bp->d_ptr[i]->e_text);
46: waddch(w, ' ');
47: wattroff(w, A_REVERSE);
48: for (j = 0; j < bp->d_ptr[i]->e_len; j++)
49: waddch(w, ' ');
50: mvwaddstr(w, i*2+3, strlen(bp->d_ptr[i]->e_text)+2, bp->d_ptr[i]->e_data);
51: wattron(w, A_REVERSE);
52: }
53: wattroff(w, A_REVERSE);
54: wrefresh(w);
55:
56: tab_active = 1; /* activate TAB key to switch between elements */
57: while (eoj) { /* edit the elements */
58: ret = edit_field(w, active*2+3, strlen(bp->d_ptr[active]->e_text)+2, bp->d_ptr[active]->e_data, bp->d_ptr[active]->e_len, 1, NULL);
59: switch (ret) {
60: case WIN_OK:
61: case WIN_ABORT:
62: eoj = 0;
63: break;
64: case WIN_PREVFIE:
65: if (--active < 0)
66: active = bp->d_anz - 1;
67: break;
68: case WIN_NEXTFIE:
69: if (++active > (bp->d_anz - 1))
70: active = 0;
71: break;
72: }
73: }
74: close_window(w);
75: tab_active = 0;
76: return(ret);
77: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.