1 /*
2  *  CONTROL.C
3  *
4  *  Written on 10-Jul-94 by John Dennis and released to the public domain.
5  *
6  *  The display routines for controls of various different types.
7  */
8 
9 #include <stdio.h>
10 #include <string.h>
11 #include "winsys.h"
12 #include "menu.h"
13 #include "specch.h"
14 #include "memextra.h"
15 
16 static char *text = NULL;
17 
18 /*
19  *  Makes up a button.
20  */
21 
MakeButton(button * b,int sel)22 char *MakeButton(button * b, int sel)
23 {
24     if (text == NULL) text = xmalloc(255);
25 
26     if (sel)
27     {
28         sprintf(text, "%c %s %c", SC14, b->btext, SC15);
29     }
30     else
31     {
32         sprintf(text, "  %s  ", b->btext);
33     }
34     return text;
35 }
36 
37 /*
38  *  Puts a button onto the screen, handling all the states of the button.
39  */
40 
ShowButton(button * b)41 void ShowButton(button * b)
42 {
43     char *s;
44     static unsigned char ublock[2] = {'\0', '\0'};
45     int len;
46     unsigned char attr;
47 
48     if (text == NULL) text = xmalloc(255);
49 
50     s = MakeButton(b, b->select);
51     len = strlen(s);
52     if (b->select)
53     {
54         attr = (unsigned char)b->sattr;
55     }
56     else
57     {
58         attr = (unsigned char)b->fattr;
59     }
60 
61     if (!b->down)
62     {
63         WndPutsn(b->x, b->y, 1, attr | F_ALTERNATE, s);
64         WndPutsn(b->x + 1, b->y, len - 2, attr, s + 1);
65         WndPutsn(b->x + len - 1, b->y, 1, attr | F_ALTERNATE, s + len - 1);
66         ublock[0] = SC16;
67         WndWriteStr(b->x + len, b->y, b->battr | F_ALTERNATE, (char *)ublock);
68 
69         memset(text, SC17, 255);
70         *(text + len) = '\0';
71         WndPutsn(b->x + 1, b->y + 1, len, b->battr | F_ALTERNATE, text);
72 
73     }
74     else
75     {
76         WndPutsn(b->x, b->y, 1, attr | F_ALTERNATE, s);
77         WndPutsn(b->x + 1, b->y, len - 2, attr, s + 1);
78         WndPutsn(b->x + len - 1, b->y, 1, attr | F_ALTERNATE, s + len - 1);
79         WndWriteStr(b->x, b->y, b->battr, " ");
80 
81         memset(text, ' ', 255);
82         *(text + len) = '\0';
83 
84         WndPutsn(b->x + 1, b->y + 1, len, b->battr, text);
85     }
86     return;
87 }
88 
89 /*
90  *  Puts a checkbox button onto the screen, handling all the states of
91  *  the check box.
92  */
93 
ShowCkbutton(ckbutton * i)94 void ShowCkbutton(ckbutton * i)
95 {
96     int fa = (i->select) ? i->sattr : i->fattr;
97 
98     if (text == NULL) text = xmalloc(255);
99 
100     if (i->down)
101     {
102         strcpy(text, " [x] ");
103     }
104     else
105     {
106         strcpy(text, " [ ] ");
107     }
108     WndWriteStr(i->x, i->y, fa, text);
109     WndWriteStr(i->px, i->y, fa, i->prtext);
110 }
111 
112 /*
113  *  Displays an editf control.
114  */
115 
ShowEditField(editf * i)116 void ShowEditField(editf * i)
117 {
118     if (!i->select)
119     {
120         WndPutsn(i->x, i->y, i->len, i->fattr, i->buf);
121     }
122     else
123     {
124         WndPutsn(i->x, i->y, i->len, i->sattr, i->buf);
125     }
126 }
127 
D_ShowTxt(textl * i)128 void D_ShowTxt(textl * i)
129 {
130     if (i->text)
131     {
132         WndWriteStr(i->x, i->y, i->fattr, i->text);
133     }
134 }
135 
D_ShowWBox(wbox * i)136 void D_ShowWBox(wbox * i)
137 {
138     WndBox(i->x1, i->y1, i->x2, i->y2, i->fattr, i->type);
139     if (i->title)
140     {
141         int x;
142         x = ((i->x2 - i->x1) / 2) - (strlen(i->title) / 2) + i->x1;
143         WndWriteStr(x, i->y1, i->tattr, i->title);
144     }
145 }
146