Add 'what does "PuTTY" mean?', and add some IPA to the shortened pronunciation
[u/mdw/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>
6e522441 7#include <commctrl.h>
8c3cd914 8
9#include "winstuff.h"
ca20bfcf 10#include "puttymem.h"
11
12#include "putty.h"
8c3cd914 13
14#define GAPBETWEEN 3
15#define GAPWITHIN 1
16#define GAPXBOX 7
17#define GAPYBOX 4
18#define DLGWIDTH 168
19#define STATICHEIGHT 8
20#define CHECKBOXHEIGHT 8
21#define RADIOHEIGHT 8
22#define EDITHEIGHT 12
23#define COMBOHEIGHT 12
24#define PUSHBTNHEIGHT 14
6e522441 25#define PROGBARHEIGHT 14
8c3cd914 26
27void ctlposinit(struct ctlpos *cp, HWND hwnd,
32874aea 28 int leftborder, int rightborder, int topborder)
29{
8c3cd914 30 RECT r, r2;
31 cp->hwnd = hwnd;
32 cp->font = SendMessage(hwnd, WM_GETFONT, 0, 0);
33 cp->ypos = topborder;
34 GetClientRect(hwnd, &r);
35 r2.left = r2.top = 0;
36 r2.right = 4;
37 r2.bottom = 8;
38 MapDialogRect(hwnd, &r2);
39 cp->dlu4inpix = r2.right;
32874aea 40 cp->width = (r.right * 4) / (r2.right) - 2 * GAPBETWEEN;
8c3cd914 41 cp->xoff = leftborder;
42 cp->width -= leftborder + rightborder;
43}
44
ca20bfcf 45HWND doctl(struct ctlpos *cp, RECT r,
32874aea 46 char *wclass, int wstyle, int exstyle, char *wtext, int wid)
47{
8c3cd914 48 HWND ctl;
49 /*
50 * Note nonstandard use of RECT. This is deliberate: by
51 * transforming the width and height directly we arrange to
52 * have all supposedly same-sized controls really same-sized.
53 */
54
55 r.left += cp->xoff;
56 MapDialogRect(cp->hwnd, &r);
57
58 ctl = CreateWindowEx(exstyle, wclass, wtext, wstyle,
32874aea 59 r.left, r.top, r.right, r.bottom,
60 cp->hwnd, (HMENU) wid, hinst, NULL);
8c3cd914 61 SendMessage(ctl, WM_SETFONT, cp->font, MAKELPARAM(TRUE, 0));
ca20bfcf 62 return ctl;
8c3cd914 63}
64
65/*
66 * A title bar across the top of a sub-dialog.
67 */
32874aea 68void bartitle(struct ctlpos *cp, char *name, int id)
69{
8c3cd914 70 RECT r;
71
32874aea 72 r.left = GAPBETWEEN;
73 r.right = cp->width;
74 r.top = cp->ypos;
75 r.bottom = STATICHEIGHT;
8c3cd914 76 cp->ypos += r.bottom + GAPBETWEEN;
77 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, name, id);
78}
79
80/*
81 * Begin a grouping box, with or without a group title.
82 */
32874aea 83void beginbox(struct ctlpos *cp, char *name, int idbox)
84{
8c3cd914 85 cp->boxystart = cp->ypos;
3ac9cd9f 86 if (!name)
32874aea 87 cp->boxystart -= STATICHEIGHT / 2;
8c3cd914 88 if (name)
32874aea 89 cp->ypos += STATICHEIGHT;
8c3cd914 90 cp->ypos += GAPYBOX;
32874aea 91 cp->width -= 2 * GAPXBOX;
8c3cd914 92 cp->xoff += GAPXBOX;
93 cp->boxid = idbox;
8c3cd914 94 cp->boxtext = name;
95}
96
97/*
98 * End a grouping box.
99 */
32874aea 100void endbox(struct ctlpos *cp)
101{
8c3cd914 102 RECT r;
103 cp->xoff -= GAPXBOX;
32874aea 104 cp->width += 2 * GAPXBOX;
8c3cd914 105 cp->ypos += GAPYBOX - GAPBETWEEN;
32874aea 106 r.left = GAPBETWEEN;
107 r.right = cp->width;
108 r.top = cp->boxystart;
109 r.bottom = cp->ypos - cp->boxystart;
3ac9cd9f 110 doctl(cp, r, "BUTTON", BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 0,
32874aea 111 cp->boxtext ? cp->boxtext : "", cp->boxid);
8c3cd914 112 cp->ypos += GAPYBOX;
113}
114
115/*
116 * Some edit boxes. Each one has a static above it. The percentages
117 * of the horizontal space are provided.
118 */
32874aea 119void multiedit(struct ctlpos *cp, ...)
120{
8c3cd914 121 RECT r;
122 va_list ap;
123 int percent, xpos;
124
125 percent = xpos = 0;
126 va_start(ap, cp);
127 while (1) {
32874aea 128 char *text;
129 int staticid, editid, pcwidth;
130 text = va_arg(ap, char *);
131 if (!text)
132 break;
133 staticid = va_arg(ap, int);
134 editid = va_arg(ap, int);
135 pcwidth = va_arg(ap, int);
136
137 r.left = xpos + GAPBETWEEN;
138 percent += pcwidth;
139 xpos = (cp->width + GAPBETWEEN) * percent / 100;
140 r.right = xpos - r.left;
141
142 r.top = cp->ypos;
143 r.bottom = STATICHEIGHT;
144 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, staticid);
145 r.top = cp->ypos + 8 + GAPWITHIN;
146 r.bottom = EDITHEIGHT;
147 doctl(cp, r, "EDIT",
148 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
149 WS_EX_CLIENTEDGE, "", editid);
8c3cd914 150 }
151 va_end(ap);
875b193f 152 cp->ypos += STATICHEIGHT + GAPWITHIN + EDITHEIGHT + GAPBETWEEN;
153}
154
155/*
b8ae1f0f 156 * A static line, followed by a full-width combo box.
875b193f 157 */
b8ae1f0f 158void combobox(struct ctlpos *cp, char *text, int staticid, int listid)
875b193f 159{
160 RECT r;
875b193f 161
162 r.left = GAPBETWEEN;
163 r.right = cp->width;
164
165 r.top = cp->ypos;
166 r.bottom = STATICHEIGHT;
167 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, staticid);
168 r.top = cp->ypos + 8 + GAPWITHIN;
169 r.bottom = COMBOHEIGHT * 10;
170 doctl(cp, r, "COMBOBOX",
171 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL |
b8ae1f0f 172 CBS_DROPDOWN | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", listid);
875b193f 173
174 cp->ypos += STATICHEIGHT + GAPWITHIN + COMBOHEIGHT + GAPBETWEEN;
8c3cd914 175}
176
d74d141c 177static void radioline_common(struct ctlpos *cp, int nacross, va_list ap)
32874aea 178{
8c3cd914 179 RECT r;
8c3cd914 180 int group;
181 int i;
1cd48051 182 char *btext;
8c3cd914 183
8c3cd914 184 group = WS_GROUP;
185 i = 0;
1cd48051 186 btext = va_arg(ap, char *);
8c3cd914 187 while (1) {
32874aea 188 char *nextbtext;
189 int bid;
190 if (!btext)
191 break;
192 if (i == nacross) {
f37caa11 193 cp->ypos += r.bottom + GAPBETWEEN;
32874aea 194 i = 0;
f37caa11 195 }
32874aea 196 bid = va_arg(ap, int);
197 nextbtext = va_arg(ap, char *);
198 r.left = GAPBETWEEN + i * (cp->width + GAPBETWEEN) / nacross;
199 if (nextbtext)
200 r.right =
201 (i + 1) * (cp->width + GAPBETWEEN) / nacross - r.left;
202 else
203 r.right = cp->width - r.left;
204 r.top = cp->ypos;
205 r.bottom = RADIOHEIGHT;
206 doctl(cp, r, "BUTTON",
207 BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP |
208 group, 0, btext, bid);
209 group = 0;
210 i++;
211 btext = nextbtext;
8c3cd914 212 }
8c3cd914 213 cp->ypos += r.bottom + GAPBETWEEN;
214}
215
216/*
d74d141c 217 * A set of radio buttons on the same line, with a static above
218 * them. `nacross' dictates how many parts the line is divided into
219 * (you might want this not to equal the number of buttons if you
220 * needed to line up some 2s and some 3s to look good in the same
221 * panel).
222 *
223 * There's a bit of a hack in here to ensure that if nacross
224 * exceeds the actual number of buttons, the rightmost button
225 * really does get all the space right to the edge of the line, so
226 * you can do things like
227 *
228 * (*) Button1 (*) Button2 (*) ButtonWithReallyLongTitle
229 */
230void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...)
231{
232 RECT r;
233 va_list ap;
234
235 r.left = GAPBETWEEN;
236 r.top = cp->ypos;
237 r.right = cp->width;
238 r.bottom = STATICHEIGHT;
239 cp->ypos += r.bottom + GAPWITHIN;
240 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id);
241 va_start(ap, nacross);
242 radioline_common(cp, nacross, ap);
243 va_end(ap);
244}
245
246/*
247 * A set of radio buttons on the same line, without a static above
248 * them. Otherwise just like radioline.
249 */
250void bareradioline(struct ctlpos *cp, int nacross, ...)
251{
252 va_list ap;
253
254 va_start(ap, nacross);
255 radioline_common(cp, nacross, ap);
256 va_end(ap);
257}
258
259/*
8c3cd914 260 * A set of radio buttons on multiple lines, with a static above
261 * them.
262 */
32874aea 263void radiobig(struct ctlpos *cp, char *text, int id, ...)
264{
8c3cd914 265 RECT r;
266 va_list ap;
267 int group;
268
32874aea 269 r.left = GAPBETWEEN;
270 r.top = cp->ypos;
271 r.right = cp->width;
272 r.bottom = STATICHEIGHT;
8c3cd914 273 cp->ypos += r.bottom + GAPWITHIN;
274 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id);
275 va_start(ap, id);
276 group = WS_GROUP;
277 while (1) {
32874aea 278 char *btext;
279 int bid;
280 btext = va_arg(ap, char *);
281 if (!btext)
282 break;
283 bid = va_arg(ap, int);
284 r.left = GAPBETWEEN;
285 r.top = cp->ypos;
286 r.right = cp->width;
287 r.bottom = STATICHEIGHT;
288 cp->ypos += r.bottom + GAPWITHIN;
289 doctl(cp, r, "BUTTON",
290 BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP |
291 group, 0, btext, bid);
292 group = 0;
8c3cd914 293 }
294 va_end(ap);
295 cp->ypos += GAPBETWEEN - GAPWITHIN;
296}
297
298/*
299 * A single standalone checkbox.
300 */
32874aea 301void checkbox(struct ctlpos *cp, char *text, int id)
302{
8c3cd914 303 RECT r;
304
32874aea 305 r.left = GAPBETWEEN;
306 r.top = cp->ypos;
307 r.right = cp->width;
308 r.bottom = CHECKBOXHEIGHT;
8c3cd914 309 cp->ypos += r.bottom + GAPBETWEEN;
310 doctl(cp, r, "BUTTON",
32874aea 311 BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0,
312 text, id);
8c3cd914 313}
314
315/*
6e522441 316 * A single standalone static text control.
317 */
66ee282a 318void statictext(struct ctlpos *cp, char *text, int lines, int id)
32874aea 319{
6e522441 320 RECT r;
321
32874aea 322 r.left = GAPBETWEEN;
323 r.top = cp->ypos;
324 r.right = cp->width;
66ee282a 325 r.bottom = STATICHEIGHT * lines;
6e522441 326 cp->ypos += r.bottom + GAPBETWEEN;
327 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id);
328}
329
330/*
8c3cd914 331 * A button on the right hand side, with a static to its left.
332 */
333void staticbtn(struct ctlpos *cp, char *stext, int sid,
32874aea 334 char *btext, int bid)
335{
8c3cd914 336 const int height = (PUSHBTNHEIGHT > STATICHEIGHT ?
32874aea 337 PUSHBTNHEIGHT : STATICHEIGHT);
8c3cd914 338 RECT r;
339 int lwid, rwid, rpos;
340
341 rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
32874aea 342 lwid = rpos - 2 * GAPBETWEEN;
8c3cd914 343 rwid = cp->width + GAPBETWEEN - rpos;
344
32874aea 345 r.left = GAPBETWEEN;
346 r.top = cp->ypos + (height - STATICHEIGHT) / 2;
347 r.right = lwid;
348 r.bottom = STATICHEIGHT;
8c3cd914 349 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
350
32874aea 351 r.left = rpos;
352 r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2;
353 r.right = rwid;
354 r.bottom = PUSHBTNHEIGHT;
8c3cd914 355 doctl(cp, r, "BUTTON",
32874aea 356 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
357 0, btext, bid);
8c3cd914 358
359 cp->ypos += height + GAPBETWEEN;
360}
361
362/*
af282e3b 363 * Like staticbtn, but two buttons.
364 */
365void static2btn(struct ctlpos *cp, char *stext, int sid,
366 char *btext1, int bid1, char *btext2, int bid2)
367{
368 const int height = (PUSHBTNHEIGHT > STATICHEIGHT ?
369 PUSHBTNHEIGHT : STATICHEIGHT);
370 RECT r;
371 int lwid, rwid1, rwid2, rpos1, rpos2;
372
373 rpos1 = GAPBETWEEN + (cp->width + GAPBETWEEN) / 2;
374 rpos2 = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
375 lwid = rpos1 - 2 * GAPBETWEEN;
376 rwid1 = rpos2 - rpos1 - GAPBETWEEN;
377 rwid2 = cp->width + GAPBETWEEN - rpos2;
378
379 r.left = GAPBETWEEN;
380 r.top = cp->ypos + (height - STATICHEIGHT) / 2;
381 r.right = lwid;
382 r.bottom = STATICHEIGHT;
383 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
384
385 r.left = rpos1;
386 r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2;
387 r.right = rwid1;
388 r.bottom = PUSHBTNHEIGHT;
389 doctl(cp, r, "BUTTON",
390 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
391 0, btext1, bid1);
392
393 r.left = rpos2;
394 r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2;
395 r.right = rwid2;
396 r.bottom = PUSHBTNHEIGHT;
397 doctl(cp, r, "BUTTON",
398 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
399 0, btext2, bid2);
400
401 cp->ypos += height + GAPBETWEEN;
402}
403
404/*
8c3cd914 405 * An edit control on the right hand side, with a static to its left.
406 */
6e522441 407static void staticedit_internal(struct ctlpos *cp, char *stext,
32874aea 408 int sid, int eid, int percentedit,
409 int style)
410{
8c3cd914 411 const int height = (EDITHEIGHT > STATICHEIGHT ?
32874aea 412 EDITHEIGHT : STATICHEIGHT);
8c3cd914 413 RECT r;
414 int lwid, rwid, rpos;
415
32874aea 416 rpos =
417 GAPBETWEEN + (100 - percentedit) * (cp->width + GAPBETWEEN) / 100;
418 lwid = rpos - 2 * GAPBETWEEN;
8c3cd914 419 rwid = cp->width + GAPBETWEEN - rpos;
420
32874aea 421 r.left = GAPBETWEEN;
422 r.top = cp->ypos + (height - STATICHEIGHT) / 2;
423 r.right = lwid;
424 r.bottom = STATICHEIGHT;
8c3cd914 425 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
426
32874aea 427 r.left = rpos;
428 r.top = cp->ypos + (height - EDITHEIGHT) / 2;
429 r.right = rwid;
430 r.bottom = EDITHEIGHT;
8c3cd914 431 doctl(cp, r, "EDIT",
32874aea 432 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL | style,
433 WS_EX_CLIENTEDGE, "", eid);
8c3cd914 434
435 cp->ypos += height + GAPBETWEEN;
436}
437
6e522441 438void staticedit(struct ctlpos *cp, char *stext,
32874aea 439 int sid, int eid, int percentedit)
440{
6e522441 441 staticedit_internal(cp, stext, sid, eid, percentedit, 0);
442}
443
444void staticpassedit(struct ctlpos *cp, char *stext,
32874aea 445 int sid, int eid, int percentedit)
446{
6e522441 447 staticedit_internal(cp, stext, sid, eid, percentedit, ES_PASSWORD);
448}
449
450/*
2c9c6388 451 * A drop-down list box on the right hand side, with a static to
452 * its left.
453 */
454void staticddl(struct ctlpos *cp, char *stext,
455 int sid, int lid, int percentlist)
456{
457 const int height = (COMBOHEIGHT > STATICHEIGHT ?
458 COMBOHEIGHT : STATICHEIGHT);
459 RECT r;
460 int lwid, rwid, rpos;
461
462 rpos =
463 GAPBETWEEN + (100 - percentlist) * (cp->width + GAPBETWEEN) / 100;
464 lwid = rpos - 2 * GAPBETWEEN;
465 rwid = cp->width + GAPBETWEEN - rpos;
466
467 r.left = GAPBETWEEN;
468 r.top = cp->ypos + (height - STATICHEIGHT) / 2;
469 r.right = lwid;
470 r.bottom = STATICHEIGHT;
471 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
472
473 r.left = rpos;
474 r.top = cp->ypos + (height - EDITHEIGHT) / 2;
475 r.right = rwid;
476 r.bottom = COMBOHEIGHT*4;
477 doctl(cp, r, "COMBOBOX",
478 WS_CHILD | WS_VISIBLE | WS_TABSTOP |
479 CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", lid);
480
481 cp->ypos += height + GAPBETWEEN;
482}
483
484/*
6e522441 485 * A big multiline edit control with a static labelling it.
486 */
487void bigeditctrl(struct ctlpos *cp, char *stext,
32874aea 488 int sid, int eid, int lines)
489{
6e522441 490 RECT r;
491
32874aea 492 r.left = GAPBETWEEN;
493 r.top = cp->ypos;
494 r.right = cp->width;
495 r.bottom = STATICHEIGHT;
6e522441 496 cp->ypos += r.bottom + GAPWITHIN;
497 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
498
32874aea 499 r.left = GAPBETWEEN;
500 r.top = cp->ypos;
501 r.right = cp->width;
502 r.bottom = EDITHEIGHT + (lines - 1) * STATICHEIGHT;
6e522441 503 cp->ypos += r.bottom + GAPBETWEEN;
504 doctl(cp, r, "EDIT",
32874aea 505 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE,
506 WS_EX_CLIENTEDGE, "", eid);
6e522441 507}
508
8c3cd914 509/*
510 * A tab-control substitute when a real tab control is unavailable.
511 */
32874aea 512void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id)
513{
8c3cd914 514 const int height = (COMBOHEIGHT > STATICHEIGHT ?
32874aea 515 COMBOHEIGHT : STATICHEIGHT);
8c3cd914 516 RECT r;
517 int bigwid, lwid, rwid, rpos;
518 static const int BIGGAP = 15;
519 static const int MEDGAP = 3;
520
32874aea 521 bigwid = cp->width + 2 * GAPBETWEEN - 2 * BIGGAP;
8c3cd914 522 cp->ypos += MEDGAP;
523 rpos = BIGGAP + (bigwid + BIGGAP) / 2;
32874aea 524 lwid = rpos - 2 * BIGGAP;
8c3cd914 525 rwid = bigwid + BIGGAP - rpos;
526
32874aea 527 r.left = BIGGAP;
528 r.top = cp->ypos + (height - STATICHEIGHT) / 2;
529 r.right = lwid;
530 r.bottom = STATICHEIGHT;
8c3cd914 531 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
532
32874aea 533 r.left = rpos;
534 r.top = cp->ypos + (height - COMBOHEIGHT) / 2;
535 r.right = rwid;
536 r.bottom = COMBOHEIGHT * 10;
8c3cd914 537 doctl(cp, r, "COMBOBOX",
32874aea 538 WS_CHILD | WS_VISIBLE | WS_TABSTOP |
539 CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", lid);
8c3cd914 540
541 cp->ypos += height + MEDGAP + GAPBETWEEN;
542
32874aea 543 r.left = GAPBETWEEN;
544 r.top = cp->ypos;
545 r.right = cp->width;
546 r.bottom = 2;
8c3cd914 547 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ,
32874aea 548 0, "", s2id);
8c3cd914 549}
550
551/*
552 * A static line, followed by an edit control on the left hand side
553 * and a button on the right.
554 */
555void editbutton(struct ctlpos *cp, char *stext, int sid,
32874aea 556 int eid, char *btext, int bid)
557{
8c3cd914 558 const int height = (EDITHEIGHT > PUSHBTNHEIGHT ?
32874aea 559 EDITHEIGHT : PUSHBTNHEIGHT);
8c3cd914 560 RECT r;
561 int lwid, rwid, rpos;
562
32874aea 563 r.left = GAPBETWEEN;
564 r.top = cp->ypos;
565 r.right = cp->width;
566 r.bottom = STATICHEIGHT;
8c3cd914 567 cp->ypos += r.bottom + GAPWITHIN;
568 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
569
570 rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
32874aea 571 lwid = rpos - 2 * GAPBETWEEN;
8c3cd914 572 rwid = cp->width + GAPBETWEEN - rpos;
573
32874aea 574 r.left = GAPBETWEEN;
575 r.top = cp->ypos + (height - EDITHEIGHT) / 2;
576 r.right = lwid;
577 r.bottom = EDITHEIGHT;
8c3cd914 578 doctl(cp, r, "EDIT",
32874aea 579 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
580 WS_EX_CLIENTEDGE, "", eid);
8c3cd914 581
32874aea 582 r.left = rpos;
583 r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2;
584 r.right = rwid;
585 r.bottom = PUSHBTNHEIGHT;
8c3cd914 586 doctl(cp, r, "BUTTON",
32874aea 587 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
588 0, btext, bid);
8c3cd914 589
590 cp->ypos += height + GAPBETWEEN;
591}
592
593/*
594 * Special control which was hard to describe generically: the
595 * session-saver assembly. A static; below that an edit box; below
596 * that a list box. To the right of the list box, a column of
597 * buttons.
598 */
599void sesssaver(struct ctlpos *cp, char *text,
32874aea 600 int staticid, int editid, int listid, ...)
601{
8c3cd914 602 RECT r;
603 va_list ap;
604 int lwid, rwid, rpos;
605 int y;
606 const int LISTDEFHEIGHT = 66;
607
608 rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
32874aea 609 lwid = rpos - 2 * GAPBETWEEN;
8c3cd914 610 rwid = cp->width + GAPBETWEEN - rpos;
611
612 /* The static control. */
32874aea 613 r.left = GAPBETWEEN;
614 r.top = cp->ypos;
615 r.right = lwid;
616 r.bottom = STATICHEIGHT;
8c3cd914 617 cp->ypos += r.bottom + GAPWITHIN;
618 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, staticid);
619
620 /* The edit control. */
32874aea 621 r.left = GAPBETWEEN;
622 r.top = cp->ypos;
623 r.right = lwid;
624 r.bottom = EDITHEIGHT;
8c3cd914 625 cp->ypos += r.bottom + GAPWITHIN;
626 doctl(cp, r, "EDIT",
32874aea 627 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
628 WS_EX_CLIENTEDGE, "", editid);
8c3cd914 629
630 /*
631 * The buttons (we should hold off on the list box until we
632 * know how big the buttons are).
633 */
634 va_start(ap, listid);
635 y = cp->ypos;
636 while (1) {
32874aea 637 char *btext = va_arg(ap, char *);
638 int bid;
639 if (!btext)
640 break;
641 bid = va_arg(ap, int);
642 r.left = rpos;
643 r.top = y;
644 r.right = rwid;
645 r.bottom = PUSHBTNHEIGHT;
646 y += r.bottom + GAPWITHIN;
647 doctl(cp, r, "BUTTON",
648 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
649 0, btext, bid);
8c3cd914 650 }
651
652 /* Compute list box height. LISTDEFHEIGHT, or height of buttons. */
653 y -= cp->ypos;
654 y -= GAPWITHIN;
32874aea 655 if (y < LISTDEFHEIGHT)
656 y = LISTDEFHEIGHT;
657 r.left = GAPBETWEEN;
658 r.top = cp->ypos;
659 r.right = lwid;
660 r.bottom = y;
8c3cd914 661 cp->ypos += y + GAPBETWEEN;
662 doctl(cp, r, "LISTBOX",
32874aea 663 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL |
664 LBS_NOTIFY | LBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", listid);
8c3cd914 665}
666
667/*
668 * Another special control: the environment-variable setter. A
669 * static line first; then a pair of edit boxes with associated
670 * statics, and two buttons; then a list box.
671 */
672void envsetter(struct ctlpos *cp, char *stext, int sid,
32874aea 673 char *e1stext, int e1sid, int e1id,
674 char *e2stext, int e2sid, int e2id,
675 int listid, char *b1text, int b1id, char *b2text, int b2id)
676{
8c3cd914 677 RECT r;
32874aea 678 const int height = (STATICHEIGHT > EDITHEIGHT
679 && STATICHEIGHT >
680 PUSHBTNHEIGHT ? STATICHEIGHT : EDITHEIGHT >
681 PUSHBTNHEIGHT ? EDITHEIGHT : PUSHBTNHEIGHT);
8c3cd914 682 const static int percents[] = { 20, 35, 10, 25 };
683 int i, j, xpos, percent;
684 const int LISTHEIGHT = 42;
685
686 /* The static control. */
32874aea 687 r.left = GAPBETWEEN;
688 r.top = cp->ypos;
689 r.right = cp->width;
690 r.bottom = STATICHEIGHT;
8c3cd914 691 cp->ypos += r.bottom + GAPWITHIN;
692 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
693
694 /* The statics+edits+buttons. */
695 for (j = 0; j < 2; j++) {
32874aea 696 percent = 10;
697 for (i = 0; i < 4; i++) {
698 xpos = (cp->width + GAPBETWEEN) * percent / 100;
699 r.left = xpos + GAPBETWEEN;
700 percent += percents[i];
701 xpos = (cp->width + GAPBETWEEN) * percent / 100;
702 r.right = xpos - r.left;
703 r.top = cp->ypos;
704 r.bottom = (i == 0 ? STATICHEIGHT :
705 i == 1 ? EDITHEIGHT : PUSHBTNHEIGHT);
706 r.top += (height - r.bottom) / 2;
707 if (i == 0) {
708 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0,
709 j == 0 ? e1stext : e2stext, j == 0 ? e1sid : e2sid);
710 } else if (i == 1) {
711 doctl(cp, r, "EDIT",
712 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
713 WS_EX_CLIENTEDGE, "", j == 0 ? e1id : e2id);
714 } else if (i == 3) {
715 doctl(cp, r, "BUTTON",
716 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
717 0, j == 0 ? b1text : b2text, j == 0 ? b1id : b2id);
718 }
719 }
720 cp->ypos += height + GAPWITHIN;
8c3cd914 721 }
722
723 /* The list box. */
32874aea 724 r.left = GAPBETWEEN;
725 r.top = cp->ypos;
726 r.right = cp->width;
727 r.bottom = LISTHEIGHT;
8c3cd914 728 cp->ypos += r.bottom + GAPBETWEEN;
729 doctl(cp, r, "LISTBOX",
32874aea 730 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
731 | LBS_USETABSTOPS, WS_EX_CLIENTEDGE, "", listid);
8c3cd914 732}
733
734/*
735 * Yet another special control: the character-class setter. A
736 * static, then a list, then a line containing a
737 * button-and-static-and-edit.
738 */
739void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
32874aea 740 char *btext, int bid, int eid, char *s2text, int s2id)
741{
8c3cd914 742 RECT r;
32874aea 743 const int height = (STATICHEIGHT > EDITHEIGHT
744 && STATICHEIGHT >
745 PUSHBTNHEIGHT ? STATICHEIGHT : EDITHEIGHT >
746 PUSHBTNHEIGHT ? EDITHEIGHT : PUSHBTNHEIGHT);
8c3cd914 747 const static int percents[] = { 30, 40, 30 };
748 int i, xpos, percent;
6908fed7 749 const int LISTHEIGHT = 52;
8c3cd914 750
751 /* The static control. */
32874aea 752 r.left = GAPBETWEEN;
753 r.top = cp->ypos;
754 r.right = cp->width;
755 r.bottom = STATICHEIGHT;
8c3cd914 756 cp->ypos += r.bottom + GAPWITHIN;
757 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
758
759 /* The list box. */
32874aea 760 r.left = GAPBETWEEN;
761 r.top = cp->ypos;
762 r.right = cp->width;
763 r.bottom = LISTHEIGHT;
8c3cd914 764 cp->ypos += r.bottom + GAPWITHIN;
765 doctl(cp, r, "LISTBOX",
32874aea 766 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
767 | LBS_USETABSTOPS, WS_EX_CLIENTEDGE, "", listid);
8c3cd914 768
769 /* The button+static+edit. */
770 percent = xpos = 0;
771 for (i = 0; i < 3; i++) {
32874aea 772 r.left = xpos + GAPBETWEEN;
773 percent += percents[i];
774 xpos = (cp->width + GAPBETWEEN) * percent / 100;
775 r.right = xpos - r.left;
776 r.top = cp->ypos;
777 r.bottom = (i == 0 ? PUSHBTNHEIGHT :
778 i == 1 ? STATICHEIGHT : EDITHEIGHT);
779 r.top += (height - r.bottom) / 2;
780 if (i == 0) {
781 doctl(cp, r, "BUTTON",
782 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
783 0, btext, bid);
784 } else if (i == 1) {
785 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_CENTER,
786 0, s2text, s2id);
787 } else if (i == 2) {
788 doctl(cp, r, "EDIT",
789 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
790 WS_EX_CLIENTEDGE, "", eid);
791 }
8c3cd914 792 }
793 cp->ypos += height + GAPBETWEEN;
794}
795
796/*
797 * A special control (horrors!). The colour editor. A static line;
798 * then on the left, a list box, and on the right, a sequence of
799 * two-part statics followed by a button.
800 */
801void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
32874aea 802 char *btext, int bid, ...)
803{
8c3cd914 804 RECT r;
805 int y;
806 va_list ap;
807 int lwid, rwid, rpos;
808 const int LISTHEIGHT = 66;
809
810 /* The static control. */
32874aea 811 r.left = GAPBETWEEN;
812 r.top = cp->ypos;
813 r.right = cp->width;
814 r.bottom = STATICHEIGHT;
8c3cd914 815 cp->ypos += r.bottom + GAPWITHIN;
816 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
32874aea 817
8c3cd914 818 rpos = GAPBETWEEN + 2 * (cp->width + GAPBETWEEN) / 3;
32874aea 819 lwid = rpos - 2 * GAPBETWEEN;
8c3cd914 820 rwid = cp->width + GAPBETWEEN - rpos;
821
822 /* The list box. */
32874aea 823 r.left = GAPBETWEEN;
824 r.top = cp->ypos;
825 r.right = lwid;
826 r.bottom = LISTHEIGHT;
8c3cd914 827 doctl(cp, r, "LISTBOX",
32874aea 828 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
829 | LBS_USETABSTOPS | LBS_NOTIFY, WS_EX_CLIENTEDGE, "", listid);
8c3cd914 830
831 /* The statics. */
832 y = cp->ypos;
833 va_start(ap, bid);
834 while (1) {
32874aea 835 char *ltext;
836 int lid, rid;
837 ltext = va_arg(ap, char *);
838 if (!ltext)
839 break;
840 lid = va_arg(ap, int);
841 rid = va_arg(ap, int);
842 r.top = y;
843 r.bottom = STATICHEIGHT;
844 y += r.bottom + GAPWITHIN;
845 r.left = rpos;
846 r.right = rwid / 2;
847 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, ltext, lid);
848 r.left = rpos + r.right;
849 r.right = rwid - r.right;
850 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0, "",
851 rid);
8c3cd914 852 }
853 va_end(ap);
854
855 /* The button. */
32874aea 856 r.top = y + 2 * GAPWITHIN;
857 r.bottom = PUSHBTNHEIGHT;
858 r.left = rpos;
859 r.right = rwid;
8c3cd914 860 doctl(cp, r, "BUTTON",
32874aea 861 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
862 0, btext, bid);
8c3cd914 863
864 cp->ypos += LISTHEIGHT + GAPBETWEEN;
865}
866
6e522441 867/*
ca20bfcf 868 * A special control for manipulating an ordered preference list
869 * (eg. for cipher selection).
870 * XXX: this is a rough hack and could be improved.
871 */
872void prefslist(struct prefslist *hdl, struct ctlpos *cp, char *stext,
873 int sid, int listid, int upbid, int dnbid)
874{
875 const static int percents[] = { 5, 75, 20 };
876 RECT r;
877 int xpos, percent = 0, i;
878 const int DEFLISTHEIGHT = 52; /* XXX configurable? */
879 const int BTNSHEIGHT = 2*PUSHBTNHEIGHT + GAPBETWEEN;
880 int totalheight;
881
882 /* Squirrel away IDs. */
883 hdl->listid = listid;
884 hdl->upbid = upbid;
885 hdl->dnbid = dnbid;
886
887 /* The static label. */
888 r.left = GAPBETWEEN;
889 r.top = cp->ypos;
890 r.right = cp->width;
891 r.bottom = STATICHEIGHT;
892 cp->ypos += r.bottom + GAPWITHIN;
893 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
894
895 /* XXX it'd be nice to centre the buttons wrt the listbox
896 * but we'd have to find out how high the latter actually is. */
897 if (DEFLISTHEIGHT > BTNSHEIGHT) {
898 totalheight = DEFLISTHEIGHT;
899 } else {
900 totalheight = BTNSHEIGHT;
901 }
902
903 for (i=0; i<3; i++) {
904 int left, wid;
905 xpos = (cp->width + GAPBETWEEN) * percent / 100;
906 left = xpos + GAPBETWEEN;
907 percent += percents[i];
908 xpos = (cp->width + GAPBETWEEN) * percent / 100;
909 wid = xpos - left;
910
911 switch (i) {
912 case 1:
913 /* The drag list box. */
914 r.left = left; r.right = wid;
915 r.top = cp->ypos; r.bottom = totalheight;
916 {
917 HWND ctl;
918 ctl = doctl(cp, r, "LISTBOX",
919 WS_CHILD | WS_VISIBLE | WS_TABSTOP |
920 WS_VSCROLL | LBS_HASSTRINGS,
921 WS_EX_CLIENTEDGE,
922 "", listid);
923 MakeDragList(ctl);
924 }
925 break;
926
927 case 2:
928 /* The "Up" and "Down" buttons. */
929 /* XXX worry about accelerators if we have more than one
930 * prefslist on a panel */
931 r.left = left; r.right = wid;
932 r.top = cp->ypos; r.bottom = PUSHBTNHEIGHT;
933 doctl(cp, r, "BUTTON",
934 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
935 0, "&Up", upbid);
936
937 r.left = left; r.right = wid;
938 r.top = cp->ypos + PUSHBTNHEIGHT + GAPBETWEEN;
939 r.bottom = PUSHBTNHEIGHT;
940 doctl(cp, r, "BUTTON",
941 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
942 0, "&Down", dnbid);
943
944 break;
945
946 }
947 }
948
949 cp->ypos += totalheight + GAPBETWEEN;
950
951}
952
953/*
954 * Helper function for prefslist: move item in list box.
955 */
956static void pl_moveitem(HWND hwnd, int listid, int src, int dst)
957{
958 int tlen, val;
959 char *txt;
960 /* Get the item's data. */
961 tlen = SendDlgItemMessage (hwnd, listid, LB_GETTEXTLEN, src, 0);
962 txt = smalloc(tlen+1);
963 SendDlgItemMessage (hwnd, listid, LB_GETTEXT, src, (LPARAM) txt);
964 val = SendDlgItemMessage (hwnd, listid, LB_GETITEMDATA, src, 0);
965 /* Deselect old location. */
966 SendDlgItemMessage (hwnd, listid, LB_SETSEL, FALSE, src);
967 /* Delete it at the old location. */
968 SendDlgItemMessage (hwnd, listid, LB_DELETESTRING, src, 0);
969 /* Insert it at new location. */
970 SendDlgItemMessage (hwnd, listid, LB_INSERTSTRING, dst,
971 (LPARAM) txt);
972 SendDlgItemMessage (hwnd, listid, LB_SETITEMDATA, dst,
973 (LPARAM) val);
974 /* Set selection. */
975 SendDlgItemMessage (hwnd, listid, LB_SETCURSEL, dst, 0);
976 sfree (txt);
977}
978
979int pl_itemfrompt(HWND hwnd, POINT cursor, BOOL scroll)
980{
981 int ret;
982 POINT uppoint, downpoint;
983 int updist, downdist, upitem, downitem, i;
984
985 /*
986 * Ghastly hackery to try to figure out not which
987 * _item_, but which _gap between items_, the user
988 * is pointing at. We do this by first working out
989 * which list item is under the cursor, and then
990 * working out how far the cursor would have to
991 * move up or down before the answer was different.
992 * Then we put the insertion point _above_ the
993 * current item if the upper edge is closer than
994 * the lower edge, or _below_ it if vice versa.
995 */
996 ret = LBItemFromPt(hwnd, cursor, scroll);
ca20bfcf 997 if (ret == -1)
998 return ret;
999 ret = LBItemFromPt(hwnd, cursor, FALSE);
ca20bfcf 1000 updist = downdist = 0;
1001 for (i = 1; i < 4096 && (!updist || !downdist); i++) {
1002 uppoint = downpoint = cursor;
1003 uppoint.y -= i;
1004 downpoint.y += i;
1005 upitem = LBItemFromPt(hwnd, uppoint, FALSE);
1006 downitem = LBItemFromPt(hwnd, downpoint, FALSE);
1007 if (!updist && upitem != ret)
1008 updist = i;
1009 if (!downdist && downitem != ret)
1010 downdist = i;
1011 }
1012 if (downdist < updist)
1013 ret++;
1014 return ret;
1015}
1016
1017/*
1018 * Handler for prefslist above.
1019 */
1020int handle_prefslist(struct prefslist *hdl,
1021 int *array, int maxmemb,
1022 int is_dlmsg, HWND hwnd,
1023 WPARAM wParam, LPARAM lParam)
1024{
1025 int i;
1026 int ret;
1027
1028 if (is_dlmsg) {
1029
cdcbdf3b 1030 if ((int)wParam == hdl->listid) {
ca20bfcf 1031 DRAGLISTINFO *dlm = (DRAGLISTINFO *)lParam;
1032 int dest;
1033 switch (dlm->uNotification) {
1034 case DL_BEGINDRAG:
1035 hdl->dummyitem =
1036 SendDlgItemMessage(hwnd, hdl->listid,
1037 LB_ADDSTRING, 0, (LPARAM) "");
1038
1039 hdl->srcitem = LBItemFromPt(dlm->hWnd, dlm->ptCursor, TRUE);
1040 hdl->dragging = 0;
1041 /* XXX hack Q183115 */
1042 SetWindowLong(hwnd, DWL_MSGRESULT, TRUE);
1043 ret = 1; break;
1044 case DL_CANCELDRAG:
1045 DrawInsert(hwnd, dlm->hWnd, -1); /* Clear arrow */
1046 SendDlgItemMessage(hwnd, hdl->listid,
1047 LB_DELETESTRING, hdl->dummyitem, 0);
1048 hdl->dragging = 0;
1049 ret = 1; break;
1050 case DL_DRAGGING:
1051 hdl->dragging = 1;
1052 dest = pl_itemfrompt(dlm->hWnd, dlm->ptCursor, TRUE);
1053 if (dest > hdl->dummyitem) dest = hdl->dummyitem;
1054 DrawInsert (hwnd, dlm->hWnd, dest);
1055 if (dest >= 0)
1056 SetWindowLong(hwnd, DWL_MSGRESULT, DL_MOVECURSOR);
1057 else
1058 SetWindowLong(hwnd, DWL_MSGRESULT, DL_STOPCURSOR);
1059 ret = 1; break;
1060 case DL_DROPPED:
2b241edd 1061 if (hdl->dragging) {
1062 dest = pl_itemfrompt(dlm->hWnd, dlm->ptCursor, TRUE);
1063 if (dest > hdl->dummyitem) dest = hdl->dummyitem;
1064 DrawInsert (hwnd, dlm->hWnd, -1);
1065 }
ca20bfcf 1066 SendDlgItemMessage(hwnd, hdl->listid,
1067 LB_DELETESTRING, hdl->dummyitem, 0);
2b241edd 1068 if (hdl->dragging) {
1069 hdl->dragging = 0;
1070 if (dest >= 0) {
1071 /* Correct for "missing" item. */
1072 if (dest > hdl->srcitem) dest--;
1073 pl_moveitem(hwnd, hdl->listid, hdl->srcitem, dest);
1074 }
ca20bfcf 1075 }
1076 ret = 1; break;
1077 }
1078 }
1079
1080 } else {
1081
1082 ret = 0;
1083 if (((LOWORD(wParam) == hdl->upbid) ||
1084 (LOWORD(wParam) == hdl->dnbid)) &&
1085 ((HIWORD(wParam) == BN_CLICKED) ||
1086 (HIWORD(wParam) == BN_DOUBLECLICKED))) {
1087 /* Move an item up or down the list. */
1088 /* Get the current selection, if any. */
1089 int selection = SendDlgItemMessage (hwnd, hdl->listid, LB_GETCURSEL, 0, 0);
1090 if (selection == LB_ERR) {
1091 MessageBeep(0);
1092 } else {
1093 int nitems;
1094 /* Get the total number of items. */
1095 nitems = SendDlgItemMessage (hwnd, hdl->listid, LB_GETCOUNT, 0, 0);
1096 /* Should we do anything? */
1097 if (LOWORD(wParam) == hdl->upbid && (selection > 0))
1098 pl_moveitem(hwnd, hdl->listid, selection, selection - 1);
1099 else if (LOWORD(wParam) == hdl->dnbid && (selection < nitems - 1))
1100 pl_moveitem(hwnd, hdl->listid, selection, selection + 1);
1101 }
1102
1103 }
1104
1105 }
1106
1107 /* Update array to match the list box. */
1108 for (i=0; i < maxmemb; i++)
1109 array[i] = SendDlgItemMessage (hwnd, hdl->listid, LB_GETITEMDATA,
1110 i, 0);
1111
1112 return ret;
1113
1114}
1115
1116/*
6e522441 1117 * A progress bar (from Common Controls). We like our progress bars
1118 * to be smooth and unbroken, without those ugly divisions; some
1119 * older compilers may not support that, but that's life.
1120 */
32874aea 1121void progressbar(struct ctlpos *cp, int id)
1122{
6e522441 1123 RECT r;
1124
32874aea 1125 r.left = GAPBETWEEN;
1126 r.top = cp->ypos;
1127 r.right = cp->width;
1128 r.bottom = PROGBARHEIGHT;
6e522441 1129 cp->ypos += r.bottom + GAPBETWEEN;
1130
32874aea 1131 doctl(cp, r, PROGRESS_CLASS, WS_CHILD | WS_VISIBLE
6e522441 1132#ifdef PBS_SMOOTH
32874aea 1133 | PBS_SMOOTH
6e522441 1134#endif
32874aea 1135 , WS_EX_CLIENTEDGE, "", id);
6e522441 1136}
d74d141c 1137
1138/*
1139 * Another special control: the forwarding options setter. First a
1140 * list box; next a static header line, introducing a pair of edit
1141 * boxes with associated statics, another button, and a radio
a4b92c62 1142 * button pair. Then we have a bareradioline, which is included in
1143 * this control group because it belongs before the `Add' button in
1144 * the tab order.
d74d141c 1145 */
1146void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
1147 char *e1stext, int e1sid, int e1id,
1148 char *e2stext, int e2sid, int e2id,
a4b92c62 1149 char *btext, int bid,
1150 char *r1text, int r1id, char *r2text, int r2id)
d74d141c 1151{
a4b92c62 1152 RECT r, button_r;
d74d141c 1153 const int height = (STATICHEIGHT > EDITHEIGHT
1154 && STATICHEIGHT >
1155 PUSHBTNHEIGHT ? STATICHEIGHT : EDITHEIGHT >
1156 PUSHBTNHEIGHT ? EDITHEIGHT : PUSHBTNHEIGHT);
1157 const static int percents[] = { 25, 35, 15, 25 };
1158 int i, j, xpos, percent;
1159 const int LISTHEIGHT = 42;
1160
1161 /* The list box. */
1162 r.left = GAPBETWEEN;
1163 r.top = cp->ypos;
1164 r.right = cp->width;
1165 r.bottom = LISTHEIGHT;
1166 cp->ypos += r.bottom + GAPBETWEEN;
1167 doctl(cp, r, "LISTBOX",
1168 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
1169 | LBS_USETABSTOPS, WS_EX_CLIENTEDGE, "", listid);
1170
1171 /* The static control. */
1172 r.left = GAPBETWEEN;
1173 r.top = cp->ypos;
1174 r.right = cp->width;
1175 r.bottom = STATICHEIGHT;
1176 cp->ypos += r.bottom + GAPWITHIN;
1177 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
1178
1179 /* The statics+edits+buttons. */
1180 for (j = 0; j < 2; j++) {
1181 percent = 0;
1182 for (i = 0; i < (j ? 2 : 4); i++) {
1183 xpos = (cp->width + GAPBETWEEN) * percent / 100;
1184 r.left = xpos + GAPBETWEEN;
1185 percent += percents[i];
1186 if (j==1 && i==1) percent = 100;
1187 xpos = (cp->width + GAPBETWEEN) * percent / 100;
1188 r.right = xpos - r.left;
1189 r.top = cp->ypos;
1190 r.bottom = (i == 0 ? STATICHEIGHT :
1191 i == 1 ? EDITHEIGHT : PUSHBTNHEIGHT);
1192 r.top += (height - r.bottom) / 2;
1193 if (i == 0) {
1194 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0,
1195 j == 0 ? e1stext : e2stext, j == 0 ? e1sid : e2sid);
1196 } else if (i == 1) {
1197 doctl(cp, r, "EDIT",
1198 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
1199 WS_EX_CLIENTEDGE, "", j == 0 ? e1id : e2id);
1200 } else if (i == 3) {
a4b92c62 1201 /*
1202 * We postpone creation of the button until we've
1203 * done everything else, since it belongs last in
1204 * the tab order.
1205 */
1206 button_r = r; /* structure copy */
d74d141c 1207 }
1208 }
1209 cp->ypos += height + GAPWITHIN;
1210 }
a4b92c62 1211 bareradioline(cp, 2, r1text, r1id, r2text, r2id, NULL);
1212 /* Create the postponed button. */
1213 doctl(cp, button_r, "BUTTON",
1214 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
1215 0, btext, bid);
d74d141c 1216}