]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - winctrls.c
Pageant interface changes. You can now do `pageant -c command' to
[PuTTY.git] / winctrls.c
1 /*
2  * winctrls.c: routines to self-manage the controls in a dialog
3  * box.
4  */
5
6 #include <windows.h>
7 #include <commctrl.h>
8
9 #include "winstuff.h"
10
11 #define GAPBETWEEN 3
12 #define GAPWITHIN 1
13 #define GAPXBOX 7
14 #define GAPYBOX 4
15 #define DLGWIDTH 168
16 #define STATICHEIGHT 8
17 #define CHECKBOXHEIGHT 8
18 #define RADIOHEIGHT 8
19 #define EDITHEIGHT 12
20 #define COMBOHEIGHT 12
21 #define PUSHBTNHEIGHT 14
22 #define PROGBARHEIGHT 14
23
24 void ctlposinit(struct ctlpos *cp, HWND hwnd,
25                 int leftborder, int rightborder, int topborder) {
26     RECT r, r2;
27     cp->hwnd = hwnd;
28     cp->font = SendMessage(hwnd, WM_GETFONT, 0, 0);
29     cp->ypos = topborder;
30     GetClientRect(hwnd, &r);
31     r2.left = r2.top = 0;
32     r2.right = 4;
33     r2.bottom = 8;
34     MapDialogRect(hwnd, &r2);
35     cp->dlu4inpix = r2.right;
36     cp->width = (r.right * 4) / (r2.right) - 2*GAPBETWEEN;
37     cp->xoff = leftborder;
38     cp->width -= leftborder + rightborder;
39 }
40
41 void doctl(struct ctlpos *cp, RECT r,
42            char *wclass, int wstyle, int exstyle,
43            char *wtext, int wid) {
44     HWND ctl;
45     /*
46      * Note nonstandard use of RECT. This is deliberate: by
47      * transforming the width and height directly we arrange to
48      * have all supposedly same-sized controls really same-sized.
49      */
50
51     r.left += cp->xoff;
52     MapDialogRect(cp->hwnd, &r);
53
54     ctl = CreateWindowEx(exstyle, wclass, wtext, wstyle,
55                          r.left, r.top, r.right, r.bottom,
56                          cp->hwnd, (HMENU)wid, hinst, NULL);
57     SendMessage(ctl, WM_SETFONT, cp->font, MAKELPARAM(TRUE, 0));
58 }
59
60 /*
61  * A title bar across the top of a sub-dialog.
62  */
63 void bartitle(struct ctlpos *cp, char *name, int id) {
64     RECT r;
65
66     r.left = GAPBETWEEN; r.right = cp->width;
67     r.top = cp->ypos; r.bottom = STATICHEIGHT;
68     cp->ypos += r.bottom + GAPBETWEEN;
69     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, name, id);
70 }
71
72 /*
73  * Begin a grouping box, with or without a group title.
74  */
75 void beginbox(struct ctlpos *cp, char *name, int idbox) {
76     cp->boxystart = cp->ypos;
77     if (!name)
78         cp->boxystart -= STATICHEIGHT/2;
79     if (name)
80         cp->ypos += STATICHEIGHT;
81     cp->ypos += GAPYBOX;
82     cp->width -= 2*GAPXBOX;
83     cp->xoff += GAPXBOX;
84     cp->boxid = idbox;
85     cp->boxtext = name;
86 }
87
88 /*
89  * End a grouping box.
90  */
91 void endbox(struct ctlpos *cp) {
92     RECT r;
93     cp->xoff -= GAPXBOX;
94     cp->width += 2*GAPXBOX;
95     cp->ypos += GAPYBOX - GAPBETWEEN;
96     r.left = GAPBETWEEN; r.right = cp->width;
97     r.top = cp->boxystart; r.bottom = cp->ypos - cp->boxystart;
98     doctl(cp, r, "BUTTON", BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 0,
99           cp->boxtext ? cp->boxtext : "", cp->boxid);
100     cp->ypos += GAPYBOX;
101 }
102
103 /*
104  * Some edit boxes. Each one has a static above it. The percentages
105  * of the horizontal space are provided.
106  */
107 void multiedit(struct ctlpos *cp, ...) {
108     RECT r;
109     va_list ap;
110     int percent, xpos;
111
112     percent = xpos = 0;
113     va_start(ap, cp);
114     while (1) {
115         char *text;
116         int staticid, editid, pcwidth;
117         text = va_arg(ap, char *);
118         if (!text)
119             break;
120         staticid = va_arg(ap, int);
121         editid = va_arg(ap, int);
122         pcwidth = va_arg(ap, int);
123
124         r.left = xpos + GAPBETWEEN;
125         percent += pcwidth;
126         xpos = (cp->width + GAPBETWEEN) * percent / 100;
127         r.right = xpos - r.left;
128
129         r.top = cp->ypos; r.bottom = STATICHEIGHT;
130         doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0,
131               text, staticid);
132         r.top = cp->ypos + 8 + GAPWITHIN; r.bottom = EDITHEIGHT;
133         doctl(cp, r, "EDIT",
134               WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
135               WS_EX_CLIENTEDGE,
136               "", editid);
137     }
138     va_end(ap);
139     cp->ypos += 8+GAPWITHIN+12+GAPBETWEEN;
140 }
141
142 /*
143  * A set of radio buttons on the same line, with a static above
144  * them. `nacross' dictates how many parts the line is divided into
145  * (you might want this not to equal the number of buttons if you
146  * needed to line up some 2s and some 3s to look good in the same
147  * panel).
148  * 
149  * There's a bit of a hack in here to ensure that if nacross
150  * exceeds the actual number of buttons, the rightmost button
151  * really does get all the space right to the edge of the line, so
152  * you can do things like
153  * 
154  * (*) Button1  (*) Button2  (*) ButtonWithReallyLongTitle
155  */
156 void radioline(struct ctlpos *cp,
157                char *text, int id, int nacross, ...) {
158     RECT r;
159     va_list ap;
160     int group;
161     int i;
162     char *btext;
163
164     r.left = GAPBETWEEN; r.top = cp->ypos;
165     r.right = cp->width; r.bottom = STATICHEIGHT;
166     cp->ypos += r.bottom + GAPWITHIN;
167     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id);
168     va_start(ap, nacross);
169     group = WS_GROUP;
170     i = 0;
171     btext = va_arg(ap, char *);
172     while (1) {
173         char *nextbtext;
174         int bid;
175         if (!btext)
176             break;
177         bid = va_arg(ap, int);
178         nextbtext = va_arg(ap, char *);
179         r.left = GAPBETWEEN + i * (cp->width+GAPBETWEEN)/nacross;
180         if (nextbtext)
181             r.right = (i+1) * (cp->width+GAPBETWEEN)/nacross - r.left;
182         else
183             r.right = cp->width - r.left;
184         r.top = cp->ypos; r.bottom = RADIOHEIGHT;
185         doctl(cp, r, "BUTTON",
186               BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP | group,
187               0,
188               btext, bid);
189         group = 0;
190         i++;
191         btext = nextbtext;
192     }
193     va_end(ap);
194     cp->ypos += r.bottom + GAPBETWEEN;
195 }
196
197 /*
198  * A set of radio buttons on multiple lines, with a static above
199  * them.
200  */
201 void radiobig(struct ctlpos *cp, char *text, int id, ...) {
202     RECT r;
203     va_list ap;
204     int group;
205
206     r.left = GAPBETWEEN; r.top = cp->ypos;
207     r.right = cp->width; r.bottom = STATICHEIGHT;
208     cp->ypos += r.bottom + GAPWITHIN;
209     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id);
210     va_start(ap, id);
211     group = WS_GROUP;
212     while (1) {
213         char *btext;
214         int bid;
215         btext = va_arg(ap, char *);
216         if (!btext)
217             break;
218         bid = va_arg(ap, int);
219         r.left = GAPBETWEEN; r.top = cp->ypos;
220         r.right = cp->width; r.bottom = STATICHEIGHT;
221         cp->ypos += r.bottom + GAPWITHIN;
222         doctl(cp, r, "BUTTON",
223               BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP | group,
224               0,
225               btext, bid);
226         group = 0;
227     }
228     va_end(ap);
229     cp->ypos += GAPBETWEEN - GAPWITHIN;
230 }
231
232 /*
233  * A single standalone checkbox.
234  */
235 void checkbox(struct ctlpos *cp, char *text, int id) {
236     RECT r;
237
238     r.left = GAPBETWEEN; r.top = cp->ypos;
239     r.right = cp->width; r.bottom = CHECKBOXHEIGHT;
240     cp->ypos += r.bottom + GAPBETWEEN;
241     doctl(cp, r, "BUTTON",
242           BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0,
243           text, id);
244 }
245
246 /*
247  * A single standalone static text control.
248  */
249 void statictext(struct ctlpos *cp, char *text, int id) {
250     RECT r;
251
252     r.left = GAPBETWEEN; r.top = cp->ypos;
253     r.right = cp->width; r.bottom = STATICHEIGHT;
254     cp->ypos += r.bottom + GAPBETWEEN;
255     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id);
256 }
257
258 /*
259  * A button on the right hand side, with a static to its left.
260  */
261 void staticbtn(struct ctlpos *cp, char *stext, int sid,
262                char *btext, int bid) {
263     const int height = (PUSHBTNHEIGHT > STATICHEIGHT ?
264                         PUSHBTNHEIGHT : STATICHEIGHT);
265     RECT r;
266     int lwid, rwid, rpos;
267
268     rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
269     lwid = rpos - 2*GAPBETWEEN;
270     rwid = cp->width + GAPBETWEEN - rpos;
271
272     r.left = GAPBETWEEN; r.top = cp->ypos + (height-STATICHEIGHT)/2;
273     r.right = lwid; r.bottom = STATICHEIGHT;
274     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
275
276     r.left = rpos; r.top = cp->ypos + (height-PUSHBTNHEIGHT)/2;
277     r.right = rwid; r.bottom = PUSHBTNHEIGHT;
278     doctl(cp, r, "BUTTON",
279           WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
280           0,
281           btext, bid);
282
283     cp->ypos += height + GAPBETWEEN;
284 }
285
286 /*
287  * An edit control on the right hand side, with a static to its left.
288  */
289 static void staticedit_internal(struct ctlpos *cp, char *stext,
290                                 int sid, int eid, int percentedit,
291                                 int style) {
292     const int height = (EDITHEIGHT > STATICHEIGHT ?
293                         EDITHEIGHT : STATICHEIGHT);
294     RECT r;
295     int lwid, rwid, rpos;
296
297     rpos = GAPBETWEEN + (100-percentedit) * (cp->width + GAPBETWEEN) / 100;
298     lwid = rpos - 2*GAPBETWEEN;
299     rwid = cp->width + GAPBETWEEN - rpos;
300
301     r.left = GAPBETWEEN; r.top = cp->ypos + (height-STATICHEIGHT)/2;
302     r.right = lwid; r.bottom = STATICHEIGHT;
303     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
304
305     r.left = rpos; r.top = cp->ypos + (height-EDITHEIGHT)/2;
306     r.right = rwid; r.bottom = EDITHEIGHT;
307     doctl(cp, r, "EDIT",
308           WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL | style,
309           WS_EX_CLIENTEDGE,
310           "", eid);
311
312     cp->ypos += height + GAPBETWEEN;
313 }
314
315 void staticedit(struct ctlpos *cp, char *stext,
316                 int sid, int eid, int percentedit) {
317     staticedit_internal(cp, stext, sid, eid, percentedit, 0);
318 }
319
320 void staticpassedit(struct ctlpos *cp, char *stext,
321                     int sid, int eid, int percentedit) {
322     staticedit_internal(cp, stext, sid, eid, percentedit, ES_PASSWORD);
323 }
324
325 /*
326  * A big multiline edit control with a static labelling it.
327  */
328 void bigeditctrl(struct ctlpos *cp, char *stext,
329                  int sid, int eid, int lines) {
330     RECT r;
331
332     r.left = GAPBETWEEN; r.top = cp->ypos;
333     r.right = cp->width; r.bottom = STATICHEIGHT;
334     cp->ypos += r.bottom + GAPWITHIN;
335     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
336
337     r.left = GAPBETWEEN; r.top = cp->ypos;
338     r.right = cp->width; r.bottom = EDITHEIGHT + (lines-1) * STATICHEIGHT;
339     cp->ypos += r.bottom + GAPBETWEEN;
340     doctl(cp, r, "EDIT",
341           WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE,
342           WS_EX_CLIENTEDGE,
343           "", eid);
344 }
345
346 /*
347  * A tab-control substitute when a real tab control is unavailable.
348  */
349 void ersatztab(struct ctlpos *cp, char *stext, int sid,
350                int lid, int s2id) {
351     const int height = (COMBOHEIGHT > STATICHEIGHT ?
352                         COMBOHEIGHT : STATICHEIGHT);
353     RECT r;
354     int bigwid, lwid, rwid, rpos;
355     static const int BIGGAP = 15;
356     static const int MEDGAP = 3;
357
358     bigwid = cp->width + 2*GAPBETWEEN - 2*BIGGAP;
359     cp->ypos += MEDGAP;
360     rpos = BIGGAP + (bigwid + BIGGAP) / 2;
361     lwid = rpos - 2*BIGGAP;
362     rwid = bigwid + BIGGAP - rpos;
363
364     r.left = BIGGAP; r.top = cp->ypos + (height-STATICHEIGHT)/2;
365     r.right = lwid; r.bottom = STATICHEIGHT;
366     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
367
368     r.left = rpos; r.top = cp->ypos + (height-COMBOHEIGHT)/2;
369     r.right = rwid; r.bottom = COMBOHEIGHT*10;
370     doctl(cp, r, "COMBOBOX",
371           WS_CHILD | WS_VISIBLE | WS_TABSTOP |
372           CBS_DROPDOWNLIST | CBS_HASSTRINGS,
373           WS_EX_CLIENTEDGE,
374           "", lid);
375
376     cp->ypos += height + MEDGAP + GAPBETWEEN;
377
378     r.left = GAPBETWEEN; r.top = cp->ypos;
379     r.right = cp->width; r.bottom = 2;
380     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ,
381           0, "", s2id);
382 }
383
384 /*
385  * A static line, followed by an edit control on the left hand side
386  * and a button on the right.
387  */
388 void editbutton(struct ctlpos *cp, char *stext, int sid,
389                 int eid, char *btext, int bid) {
390     const int height = (EDITHEIGHT > PUSHBTNHEIGHT ?
391                         EDITHEIGHT : PUSHBTNHEIGHT);
392     RECT r;
393     int lwid, rwid, rpos;
394
395     r.left = GAPBETWEEN; r.top = cp->ypos;
396     r.right = cp->width; r.bottom = STATICHEIGHT;
397     cp->ypos += r.bottom + GAPWITHIN;
398     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
399
400     rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
401     lwid = rpos - 2*GAPBETWEEN;
402     rwid = cp->width + GAPBETWEEN - rpos;
403
404     r.left = GAPBETWEEN; r.top = cp->ypos + (height-EDITHEIGHT)/2;
405     r.right = lwid; r.bottom = EDITHEIGHT;
406     doctl(cp, r, "EDIT",
407           WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
408           WS_EX_CLIENTEDGE,
409           "", eid);
410
411     r.left = rpos; r.top = cp->ypos + (height-PUSHBTNHEIGHT)/2;
412     r.right = rwid; r.bottom = PUSHBTNHEIGHT;
413     doctl(cp, r, "BUTTON",
414           WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
415           0,
416           btext, bid);
417
418     cp->ypos += height + GAPBETWEEN;
419 }
420
421 /*
422  * Special control which was hard to describe generically: the
423  * session-saver assembly. A static; below that an edit box; below
424  * that a list box. To the right of the list box, a column of
425  * buttons.
426  */
427 void sesssaver(struct ctlpos *cp, char *text,
428                int staticid, int editid, int listid, ...) {
429     RECT r;
430     va_list ap;
431     int lwid, rwid, rpos;
432     int y;
433     const int LISTDEFHEIGHT = 66;
434
435     rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
436     lwid = rpos - 2*GAPBETWEEN;
437     rwid = cp->width + GAPBETWEEN - rpos;
438
439     /* The static control. */
440     r.left = GAPBETWEEN; r.top = cp->ypos;
441     r.right = lwid; r.bottom = STATICHEIGHT;
442     cp->ypos += r.bottom + GAPWITHIN;
443     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, staticid);
444
445     /* The edit control. */
446     r.left = GAPBETWEEN; r.top = cp->ypos;
447     r.right = lwid; r.bottom = EDITHEIGHT;
448     cp->ypos += r.bottom + GAPWITHIN;
449     doctl(cp, r, "EDIT",
450           WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
451           WS_EX_CLIENTEDGE,
452           "", editid);
453
454     /*
455      * The buttons (we should hold off on the list box until we
456      * know how big the buttons are).
457      */
458     va_start(ap, listid);
459     y = cp->ypos;
460     while (1) {
461         char *btext = va_arg(ap, char *);
462         int bid;
463         if (!btext) break;
464         bid = va_arg(ap, int);
465         r.left = rpos; r.top = y;
466         r.right = rwid; r.bottom = PUSHBTNHEIGHT;
467         y += r.bottom + GAPWITHIN;
468         doctl(cp, r, "BUTTON",
469               WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
470               0,
471               btext, bid);
472     }
473
474     /* Compute list box height. LISTDEFHEIGHT, or height of buttons. */
475     y -= cp->ypos;
476     y -= GAPWITHIN;
477     if (y < LISTDEFHEIGHT) y = LISTDEFHEIGHT;
478     r.left = GAPBETWEEN; r.top = cp->ypos;
479     r.right = lwid; r.bottom = y;
480     cp->ypos += y + GAPBETWEEN;
481     doctl(cp, r, "LISTBOX",
482           WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | 
483           LBS_NOTIFY | LBS_HASSTRINGS,
484           WS_EX_CLIENTEDGE,
485           "", listid);
486 }
487
488 /*
489  * Another special control: the environment-variable setter. A
490  * static line first; then a pair of edit boxes with associated
491  * statics, and two buttons; then a list box.
492  */
493 void envsetter(struct ctlpos *cp, char *stext, int sid,
494                char *e1stext, int e1sid, int e1id,
495                char *e2stext, int e2sid, int e2id,
496                int listid,
497                char *b1text, int b1id, char *b2text, int b2id) {
498     RECT r;
499     const int height = (STATICHEIGHT > EDITHEIGHT && STATICHEIGHT > PUSHBTNHEIGHT ?
500                         STATICHEIGHT :
501                         EDITHEIGHT > PUSHBTNHEIGHT ?
502                         EDITHEIGHT : PUSHBTNHEIGHT);
503     const static int percents[] = { 20, 35, 10, 25 };
504     int i, j, xpos, percent;
505     const int LISTHEIGHT = 42;
506
507     /* The static control. */
508     r.left = GAPBETWEEN; r.top = cp->ypos;
509     r.right = cp->width; r.bottom = STATICHEIGHT;
510     cp->ypos += r.bottom + GAPWITHIN;
511     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
512
513     /* The statics+edits+buttons. */
514     for (j = 0; j < 2; j++) {
515         percent = 10;
516         for (i = 0; i < 4; i++) {
517             xpos = (cp->width + GAPBETWEEN) * percent / 100;
518             r.left = xpos + GAPBETWEEN;
519             percent += percents[i];
520             xpos = (cp->width + GAPBETWEEN) * percent / 100;
521             r.right = xpos - r.left;
522             r.top = cp->ypos;
523             r.bottom = (i==0 ? STATICHEIGHT :
524                         i==1 ? EDITHEIGHT :
525                         PUSHBTNHEIGHT);
526             r.top += (height-r.bottom)/2;
527             if (i==0) {
528                 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0,
529                       j==0 ? e1stext : e2stext, j==0 ? e1sid : e2sid);
530             } else if (i==1) {
531                 doctl(cp, r, "EDIT",
532                       WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
533                       WS_EX_CLIENTEDGE,
534                       "", j==0 ? e1id : e2id);
535             } else if (i==3) {
536                 doctl(cp, r, "BUTTON",
537                       WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
538                       0,
539                       j==0 ? b1text : b2text, j==0 ? b1id : b2id);
540             }
541         }
542         cp->ypos += height + GAPWITHIN;
543     }
544
545     /* The list box. */
546     r.left = GAPBETWEEN; r.top = cp->ypos;
547     r.right = cp->width; r.bottom = LISTHEIGHT;
548     cp->ypos += r.bottom + GAPBETWEEN;
549     doctl(cp, r, "LISTBOX",
550           WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS |
551           LBS_USETABSTOPS,
552           WS_EX_CLIENTEDGE,
553           "", listid);
554 }
555
556 /*
557  * Yet another special control: the character-class setter. A
558  * static, then a list, then a line containing a
559  * button-and-static-and-edit. 
560  */
561 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
562                char *btext, int bid, int eid, char *s2text, int s2id) {
563     RECT r;
564     const int height = (STATICHEIGHT > EDITHEIGHT && STATICHEIGHT > PUSHBTNHEIGHT ?
565                         STATICHEIGHT :
566                         EDITHEIGHT > PUSHBTNHEIGHT ?
567                         EDITHEIGHT : PUSHBTNHEIGHT);
568     const static int percents[] = { 30, 40, 30 };
569     int i, xpos, percent;
570     const int LISTHEIGHT = 66;
571
572     /* The static control. */
573     r.left = GAPBETWEEN; r.top = cp->ypos;
574     r.right = cp->width; r.bottom = STATICHEIGHT;
575     cp->ypos += r.bottom + GAPWITHIN;
576     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
577
578     /* The list box. */
579     r.left = GAPBETWEEN; r.top = cp->ypos;
580     r.right = cp->width; r.bottom = LISTHEIGHT;
581     cp->ypos += r.bottom + GAPWITHIN;
582     doctl(cp, r, "LISTBOX",
583           WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS |
584           LBS_USETABSTOPS,
585           WS_EX_CLIENTEDGE,
586           "", listid);
587
588     /* The button+static+edit. */
589     percent = xpos = 0;
590     for (i = 0; i < 3; i++) {
591         r.left = xpos + GAPBETWEEN;
592         percent += percents[i];
593         xpos = (cp->width + GAPBETWEEN) * percent / 100;
594         r.right = xpos - r.left;
595         r.top = cp->ypos;
596         r.bottom = (i==0 ? PUSHBTNHEIGHT :
597                     i==1 ? STATICHEIGHT :
598                     EDITHEIGHT);
599         r.top += (height-r.bottom)/2;
600         if (i==0) {
601             doctl(cp, r, "BUTTON",
602                   WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
603                   0, btext, bid);
604         } else if (i==1) {
605             doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_CENTER,
606                   0, s2text, s2id);
607         } else if (i==2) {
608             doctl(cp, r, "EDIT",
609                   WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
610                   WS_EX_CLIENTEDGE, "", eid);
611         }
612     }
613     cp->ypos += height + GAPBETWEEN;
614 }
615
616 /*
617  * A special control (horrors!). The colour editor. A static line;
618  * then on the left, a list box, and on the right, a sequence of
619  * two-part statics followed by a button.
620  */
621 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
622                 char *btext, int bid, ...) {
623     RECT r;
624     int y;
625     va_list ap;
626     int lwid, rwid, rpos;
627     const int LISTHEIGHT = 66;
628
629     /* The static control. */
630     r.left = GAPBETWEEN; r.top = cp->ypos;
631     r.right = cp->width; r.bottom = STATICHEIGHT;
632     cp->ypos += r.bottom + GAPWITHIN;
633     doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
634     
635     rpos = GAPBETWEEN + 2 * (cp->width + GAPBETWEEN) / 3;
636     lwid = rpos - 2*GAPBETWEEN;
637     rwid = cp->width + GAPBETWEEN - rpos;
638
639     /* The list box. */
640     r.left = GAPBETWEEN; r.top = cp->ypos;
641     r.right = lwid; r.bottom = LISTHEIGHT;
642     doctl(cp, r, "LISTBOX",
643           WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS |
644           LBS_USETABSTOPS | LBS_NOTIFY,
645           WS_EX_CLIENTEDGE,
646           "", listid);
647
648     /* The statics. */
649     y = cp->ypos;
650     va_start(ap, bid);
651     while (1) {
652         char *ltext;
653         int lid, rid;
654         ltext = va_arg(ap, char *);
655         if (!ltext) break;
656         lid = va_arg(ap, int);
657         rid = va_arg(ap, int);
658         r.top = y; r.bottom = STATICHEIGHT;
659         y += r.bottom + GAPWITHIN;
660         r.left = rpos; r.right = rwid/2;
661         doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, ltext, lid);
662         r.left = rpos + r.right; r.right = rwid - r.right;
663         doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0, "", rid);
664     }
665     va_end(ap);
666
667     /* The button. */
668     r.top = y + 2*GAPWITHIN; r.bottom = PUSHBTNHEIGHT;
669     r.left = rpos; r.right = rwid;
670     doctl(cp, r, "BUTTON",
671           WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
672           0, btext, bid);
673
674     cp->ypos += LISTHEIGHT + GAPBETWEEN;
675 }
676
677 /*
678  * A progress bar (from Common Controls). We like our progress bars
679  * to be smooth and unbroken, without those ugly divisions; some
680  * older compilers may not support that, but that's life.
681  */
682 void progressbar(struct ctlpos *cp, int id) {
683     RECT r;
684
685     r.left = GAPBETWEEN; r.top = cp->ypos;
686     r.right = cp->width; r.bottom = PROGBARHEIGHT;
687     cp->ypos += r.bottom + GAPBETWEEN;
688
689     doctl(cp, r, PROGRESS_CLASS,
690           WS_CHILD | WS_VISIBLE
691 #ifdef PBS_SMOOTH
692           | PBS_SMOOTH
693 #endif
694           , WS_EX_CLIENTEDGE, "", id);
695 }