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