1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#include <string.h>
#include <ncurses.h>
#include <dialog.h>
#include "editor.h"
int
disp_fields(WINDOW *window, struct field field[], int no_fields)
{
int i, j;
int len;
for (i=0; i < no_fields; i++) {
wmove(window, field[i].y, field[i].x);
switch (field[i].type) {
case F_TITLE:
case F_EDIT:
if (field[i].type == F_TITLE)
wattrset(window, title_attr);
else
wattrset(window, dialog_attr);
len=strlen(field[i].field);
for (j=0; j < field[i].width; j++)
if (j < len)
waddch(window, field[i].field[j]);
else
waddch(window, ' ');
break;
case F_BUTTON:
print_button(window, field[i].field,
field[i].y,
field[i].x,
FALSE);
break;
}
}
wrefresh(window);
return (0);
}
int
change_field(struct field field, int key)
{
int next;
switch(key) {
case KEY_UP:
next = field.up;
break;
case KEY_DOWN:
next = field.down;
break;
case '\t':
next = field.right;
break;
case KEY_BTAB:
next = field.left;
break;
case '\n':
case '\r':
next = field.right;
break;
default:
next = -1;
break;
}
return (next);
}
int
button_press(WINDOW *window, struct field field)
{
int key;
print_button(window, field.field,
field.y,
field.x,
TRUE);
key = wgetch(window);
switch (key) {
case '\n':
case '\r':
return (0);
case KEY_UP:
case KEY_DOWN:
case KEY_BTAB:
case '\t':
default:
return (key);
}
}
int
toggle_press(WINDOW *window, struct field field)
{
int key;
key = wgetch(window);
switch (key) {
case ' ':
field.spare++;
if (!field.misc[field.spare])
field.spare = 0;
sprintf(field.field, "%s", field.misc[field.spare]);
return (key);
break;
case '\n':
case '\r':
case KEY_UP:
case KEY_DOWN:
case KEY_BTAB:
case '\t':
default:
return (key);
}
}
|