2 * winctrls.c: routines to self-manage the controls in a dialog
19 #define STATICHEIGHT 8
20 #define CHECKBOXHEIGHT 8
23 #define COMBOHEIGHT 12
24 #define PUSHBTNHEIGHT 14
25 #define PROGBARHEIGHT 14
27 void ctlposinit(struct ctlpos
*cp
, HWND hwnd
,
28 int leftborder
, int rightborder
, int topborder
)
32 cp
->font
= SendMessage(hwnd
, WM_GETFONT
, 0, 0);
34 GetClientRect(hwnd
, &r
);
38 MapDialogRect(hwnd
, &r2
);
39 cp
->dlu4inpix
= r2
.right
;
40 cp
->width
= (r
.right
* 4) / (r2
.right
) - 2 * GAPBETWEEN
;
41 cp
->xoff
= leftborder
;
42 cp
->width
-= leftborder
+ rightborder
;
45 HWND
doctl(struct ctlpos
*cp
, RECT r
,
46 char *wclass
, int wstyle
, int exstyle
, char *wtext
, int wid
)
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.
56 MapDialogRect(cp
->hwnd
, &r
);
58 ctl
= CreateWindowEx(exstyle
, wclass
, wtext
, wstyle
,
59 r
.left
, r
.top
, r
.right
, r
.bottom
,
60 cp
->hwnd
, (HMENU
) wid
, hinst
, NULL
);
61 SendMessage(ctl
, WM_SETFONT
, cp
->font
, MAKELPARAM(TRUE
, 0));
66 * A title bar across the top of a sub-dialog.
68 void bartitle(struct ctlpos
*cp
, char *name
, int id
)
75 r
.bottom
= STATICHEIGHT
;
76 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
77 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, name
, id
);
81 * Begin a grouping box, with or without a group title.
83 void beginbox(struct ctlpos
*cp
, char *name
, int idbox
)
85 cp
->boxystart
= cp
->ypos
;
87 cp
->boxystart
-= STATICHEIGHT
/ 2;
89 cp
->ypos
+= STATICHEIGHT
;
91 cp
->width
-= 2 * GAPXBOX
;
100 void endbox(struct ctlpos
*cp
)
104 cp
->width
+= 2 * GAPXBOX
;
105 cp
->ypos
+= GAPYBOX
- GAPBETWEEN
;
108 r
.top
= cp
->boxystart
;
109 r
.bottom
= cp
->ypos
- cp
->boxystart
;
110 doctl(cp
, r
, "BUTTON", BS_GROUPBOX
| WS_CHILD
| WS_VISIBLE
, 0,
111 cp
->boxtext ? cp
->boxtext
: "", cp
->boxid
);
116 * Some edit boxes. Each one has a static above it. The percentages
117 * of the horizontal space are provided.
119 void multiedit(struct ctlpos
*cp
, ...)
129 int staticid
, editid
, pcwidth
;
130 text
= va_arg(ap
, char *);
133 staticid
= va_arg(ap
, int);
134 editid
= va_arg(ap
, int);
135 pcwidth
= va_arg(ap
, int);
137 r
.left
= xpos
+ GAPBETWEEN
;
139 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
140 r
.right
= xpos
- r
.left
;
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
;
148 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
149 WS_EX_CLIENTEDGE
, "", editid
);
152 cp
->ypos
+= STATICHEIGHT
+ GAPWITHIN
+ EDITHEIGHT
+ GAPBETWEEN
;
156 * A static line, followed by a full-width drop-down list (ie a
157 * non-editing combo box).
159 void dropdownlist(struct ctlpos
*cp
, char *text
, int staticid
, int listid
)
168 r
.bottom
= STATICHEIGHT
;
169 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, staticid
);
170 r
.top
= cp
->ypos
+ 8 + GAPWITHIN
;
171 r
.bottom
= COMBOHEIGHT
* 10;
172 doctl(cp
, r
, "COMBOBOX",
173 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
|
174 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", listid
);
176 cp
->ypos
+= STATICHEIGHT
+ GAPWITHIN
+ COMBOHEIGHT
+ GAPBETWEEN
;
179 static void radioline_common(struct ctlpos
*cp
, int nacross
, va_list ap
)
188 btext
= va_arg(ap
, char *);
195 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
198 bid
= va_arg(ap
, int);
199 nextbtext
= va_arg(ap
, char *);
200 r
.left
= GAPBETWEEN
+ i
* (cp
->width
+ GAPBETWEEN
) / nacross
;
203 (i
+ 1) * (cp
->width
+ GAPBETWEEN
) / nacross
- r
.left
;
205 r
.right
= cp
->width
- r
.left
;
207 r
.bottom
= RADIOHEIGHT
;
208 doctl(cp
, r
, "BUTTON",
209 BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
210 group
, 0, btext
, bid
);
215 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
219 * A set of radio buttons on the same line, with a static above
220 * them. `nacross' dictates how many parts the line is divided into
221 * (you might want this not to equal the number of buttons if you
222 * needed to line up some 2s and some 3s to look good in the same
225 * There's a bit of a hack in here to ensure that if nacross
226 * exceeds the actual number of buttons, the rightmost button
227 * really does get all the space right to the edge of the line, so
228 * you can do things like
230 * (*) Button1 (*) Button2 (*) ButtonWithReallyLongTitle
232 void radioline(struct ctlpos
*cp
, char *text
, int id
, int nacross
, ...)
240 r
.bottom
= STATICHEIGHT
;
241 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
242 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
243 va_start(ap
, nacross
);
244 radioline_common(cp
, nacross
, ap
);
249 * A set of radio buttons on the same line, without a static above
250 * them. Otherwise just like radioline.
252 void bareradioline(struct ctlpos
*cp
, int nacross
, ...)
256 va_start(ap
, nacross
);
257 radioline_common(cp
, nacross
, ap
);
262 * A set of radio buttons on multiple lines, with a static above
265 void radiobig(struct ctlpos
*cp
, char *text
, int id
, ...)
274 r
.bottom
= STATICHEIGHT
;
275 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
276 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
282 btext
= va_arg(ap
, char *);
285 bid
= va_arg(ap
, int);
289 r
.bottom
= STATICHEIGHT
;
290 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
291 doctl(cp
, r
, "BUTTON",
292 BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
293 group
, 0, btext
, bid
);
297 cp
->ypos
+= GAPBETWEEN
- GAPWITHIN
;
301 * A single standalone checkbox.
303 void checkbox(struct ctlpos
*cp
, char *text
, int id
)
310 r
.bottom
= CHECKBOXHEIGHT
;
311 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
312 doctl(cp
, r
, "BUTTON",
313 BS_AUTOCHECKBOX
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0,
318 * A single standalone static text control.
320 void statictext(struct ctlpos
*cp
, char *text
, int id
)
327 r
.bottom
= STATICHEIGHT
;
328 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
329 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
333 * A button on the right hand side, with a static to its left.
335 void staticbtn(struct ctlpos
*cp
, char *stext
, int sid
,
336 char *btext
, int bid
)
338 const int height
= (PUSHBTNHEIGHT
> STATICHEIGHT ?
339 PUSHBTNHEIGHT
: STATICHEIGHT
);
341 int lwid
, rwid
, rpos
;
343 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
344 lwid
= rpos
- 2 * GAPBETWEEN
;
345 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
348 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
350 r
.bottom
= STATICHEIGHT
;
351 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
354 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
356 r
.bottom
= PUSHBTNHEIGHT
;
357 doctl(cp
, r
, "BUTTON",
358 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
361 cp
->ypos
+= height
+ GAPBETWEEN
;
365 * Like staticbtn, but two buttons.
367 void static2btn(struct ctlpos
*cp
, char *stext
, int sid
,
368 char *btext1
, int bid1
, char *btext2
, int bid2
)
370 const int height
= (PUSHBTNHEIGHT
> STATICHEIGHT ?
371 PUSHBTNHEIGHT
: STATICHEIGHT
);
373 int lwid
, rwid1
, rwid2
, rpos1
, rpos2
;
375 rpos1
= GAPBETWEEN
+ (cp
->width
+ GAPBETWEEN
) / 2;
376 rpos2
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
377 lwid
= rpos1
- 2 * GAPBETWEEN
;
378 rwid1
= rpos2
- rpos1
- GAPBETWEEN
;
379 rwid2
= cp
->width
+ GAPBETWEEN
- rpos2
;
382 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
384 r
.bottom
= STATICHEIGHT
;
385 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
388 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
390 r
.bottom
= PUSHBTNHEIGHT
;
391 doctl(cp
, r
, "BUTTON",
392 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
396 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
398 r
.bottom
= PUSHBTNHEIGHT
;
399 doctl(cp
, r
, "BUTTON",
400 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
403 cp
->ypos
+= height
+ GAPBETWEEN
;
407 * An edit control on the right hand side, with a static to its left.
409 static void staticedit_internal(struct ctlpos
*cp
, char *stext
,
410 int sid
, int eid
, int percentedit
,
413 const int height
= (EDITHEIGHT
> STATICHEIGHT ?
414 EDITHEIGHT
: STATICHEIGHT
);
416 int lwid
, rwid
, rpos
;
419 GAPBETWEEN
+ (100 - percentedit
) * (cp
->width
+ GAPBETWEEN
) / 100;
420 lwid
= rpos
- 2 * GAPBETWEEN
;
421 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
424 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
426 r
.bottom
= STATICHEIGHT
;
427 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
430 r
.top
= cp
->ypos
+ (height
- EDITHEIGHT
) / 2;
432 r
.bottom
= EDITHEIGHT
;
434 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
| style
,
435 WS_EX_CLIENTEDGE
, "", eid
);
437 cp
->ypos
+= height
+ GAPBETWEEN
;
440 void staticedit(struct ctlpos
*cp
, char *stext
,
441 int sid
, int eid
, int percentedit
)
443 staticedit_internal(cp
, stext
, sid
, eid
, percentedit
, 0);
446 void staticpassedit(struct ctlpos
*cp
, char *stext
,
447 int sid
, int eid
, int percentedit
)
449 staticedit_internal(cp
, stext
, sid
, eid
, percentedit
, ES_PASSWORD
);
453 * A big multiline edit control with a static labelling it.
455 void bigeditctrl(struct ctlpos
*cp
, char *stext
,
456 int sid
, int eid
, int lines
)
463 r
.bottom
= STATICHEIGHT
;
464 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
465 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
470 r
.bottom
= EDITHEIGHT
+ (lines
- 1) * STATICHEIGHT
;
471 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
473 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| ES_MULTILINE
,
474 WS_EX_CLIENTEDGE
, "", eid
);
478 * A tab-control substitute when a real tab control is unavailable.
480 void ersatztab(struct ctlpos
*cp
, char *stext
, int sid
, int lid
, int s2id
)
482 const int height
= (COMBOHEIGHT
> STATICHEIGHT ?
483 COMBOHEIGHT
: STATICHEIGHT
);
485 int bigwid
, lwid
, rwid
, rpos
;
486 static const int BIGGAP
= 15;
487 static const int MEDGAP
= 3;
489 bigwid
= cp
->width
+ 2 * GAPBETWEEN
- 2 * BIGGAP
;
491 rpos
= BIGGAP
+ (bigwid
+ BIGGAP
) / 2;
492 lwid
= rpos
- 2 * BIGGAP
;
493 rwid
= bigwid
+ BIGGAP
- rpos
;
496 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
498 r
.bottom
= STATICHEIGHT
;
499 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
502 r
.top
= cp
->ypos
+ (height
- COMBOHEIGHT
) / 2;
504 r
.bottom
= COMBOHEIGHT
* 10;
505 doctl(cp
, r
, "COMBOBOX",
506 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
507 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", lid
);
509 cp
->ypos
+= height
+ MEDGAP
+ GAPBETWEEN
;
515 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
,
520 * A static line, followed by an edit control on the left hand side
521 * and a button on the right.
523 void editbutton(struct ctlpos
*cp
, char *stext
, int sid
,
524 int eid
, char *btext
, int bid
)
526 const int height
= (EDITHEIGHT
> PUSHBTNHEIGHT ?
527 EDITHEIGHT
: PUSHBTNHEIGHT
);
529 int lwid
, rwid
, rpos
;
534 r
.bottom
= STATICHEIGHT
;
535 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
536 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
538 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
539 lwid
= rpos
- 2 * GAPBETWEEN
;
540 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
543 r
.top
= cp
->ypos
+ (height
- EDITHEIGHT
) / 2;
545 r
.bottom
= EDITHEIGHT
;
547 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
548 WS_EX_CLIENTEDGE
, "", eid
);
551 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
553 r
.bottom
= PUSHBTNHEIGHT
;
554 doctl(cp
, r
, "BUTTON",
555 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
558 cp
->ypos
+= height
+ GAPBETWEEN
;
562 * Special control which was hard to describe generically: the
563 * session-saver assembly. A static; below that an edit box; below
564 * that a list box. To the right of the list box, a column of
567 void sesssaver(struct ctlpos
*cp
, char *text
,
568 int staticid
, int editid
, int listid
, ...)
572 int lwid
, rwid
, rpos
;
574 const int LISTDEFHEIGHT
= 66;
576 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
577 lwid
= rpos
- 2 * GAPBETWEEN
;
578 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
580 /* The static control. */
584 r
.bottom
= STATICHEIGHT
;
585 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
586 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, staticid
);
588 /* The edit control. */
592 r
.bottom
= EDITHEIGHT
;
593 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
595 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
596 WS_EX_CLIENTEDGE
, "", editid
);
599 * The buttons (we should hold off on the list box until we
600 * know how big the buttons are).
602 va_start(ap
, listid
);
605 char *btext
= va_arg(ap
, char *);
609 bid
= va_arg(ap
, int);
613 r
.bottom
= PUSHBTNHEIGHT
;
614 y
+= r
.bottom
+ GAPWITHIN
;
615 doctl(cp
, r
, "BUTTON",
616 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
620 /* Compute list box height. LISTDEFHEIGHT, or height of buttons. */
623 if (y
< LISTDEFHEIGHT
)
629 cp
->ypos
+= y
+ GAPBETWEEN
;
630 doctl(cp
, r
, "LISTBOX",
631 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
|
632 LBS_NOTIFY
| LBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", listid
);
636 * Another special control: the environment-variable setter. A
637 * static line first; then a pair of edit boxes with associated
638 * statics, and two buttons; then a list box.
640 void envsetter(struct ctlpos
*cp
, char *stext
, int sid
,
641 char *e1stext
, int e1sid
, int e1id
,
642 char *e2stext
, int e2sid
, int e2id
,
643 int listid
, char *b1text
, int b1id
, char *b2text
, int b2id
)
646 const int height
= (STATICHEIGHT
> EDITHEIGHT
648 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
649 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
650 const static int percents
[] = { 20, 35, 10, 25 };
651 int i
, j
, xpos
, percent
;
652 const int LISTHEIGHT
= 42;
654 /* The static control. */
658 r
.bottom
= STATICHEIGHT
;
659 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
660 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
662 /* The statics+edits+buttons. */
663 for (j
= 0; j
< 2; j
++) {
665 for (i
= 0; i
< 4; i
++) {
666 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
667 r
.left
= xpos
+ GAPBETWEEN
;
668 percent
+= percents
[i
];
669 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
670 r
.right
= xpos
- r
.left
;
672 r
.bottom
= (i
== 0 ? STATICHEIGHT
:
673 i
== 1 ? EDITHEIGHT
: PUSHBTNHEIGHT
);
674 r
.top
+= (height
- r
.bottom
) / 2;
676 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0,
677 j
== 0 ? e1stext
: e2stext
, j
== 0 ? e1sid
: e2sid
);
680 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
681 WS_EX_CLIENTEDGE
, "", j
== 0 ? e1id
: e2id
);
683 doctl(cp
, r
, "BUTTON",
684 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
685 0, j
== 0 ? b1text
: b2text
, j
== 0 ? b1id
: b2id
);
688 cp
->ypos
+= height
+ GAPWITHIN
;
695 r
.bottom
= LISTHEIGHT
;
696 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
697 doctl(cp
, r
, "LISTBOX",
698 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
699 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
703 * Yet another special control: the character-class setter. A
704 * static, then a list, then a line containing a
705 * button-and-static-and-edit.
707 void charclass(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
708 char *btext
, int bid
, int eid
, char *s2text
, int s2id
)
711 const int height
= (STATICHEIGHT
> EDITHEIGHT
713 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
714 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
715 const static int percents
[] = { 30, 40, 30 };
716 int i
, xpos
, percent
;
717 const int LISTHEIGHT
= 66;
719 /* The static control. */
723 r
.bottom
= STATICHEIGHT
;
724 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
725 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
731 r
.bottom
= LISTHEIGHT
;
732 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
733 doctl(cp
, r
, "LISTBOX",
734 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
735 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
737 /* The button+static+edit. */
739 for (i
= 0; i
< 3; i
++) {
740 r
.left
= xpos
+ GAPBETWEEN
;
741 percent
+= percents
[i
];
742 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
743 r
.right
= xpos
- r
.left
;
745 r
.bottom
= (i
== 0 ? PUSHBTNHEIGHT
:
746 i
== 1 ? STATICHEIGHT
: EDITHEIGHT
);
747 r
.top
+= (height
- r
.bottom
) / 2;
749 doctl(cp
, r
, "BUTTON",
750 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
753 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_CENTER
,
757 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
758 WS_EX_CLIENTEDGE
, "", eid
);
761 cp
->ypos
+= height
+ GAPBETWEEN
;
765 * A special control (horrors!). The colour editor. A static line;
766 * then on the left, a list box, and on the right, a sequence of
767 * two-part statics followed by a button.
769 void colouredit(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
770 char *btext
, int bid
, ...)
775 int lwid
, rwid
, rpos
;
776 const int LISTHEIGHT
= 66;
778 /* The static control. */
782 r
.bottom
= STATICHEIGHT
;
783 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
784 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
786 rpos
= GAPBETWEEN
+ 2 * (cp
->width
+ GAPBETWEEN
) / 3;
787 lwid
= rpos
- 2 * GAPBETWEEN
;
788 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
794 r
.bottom
= LISTHEIGHT
;
795 doctl(cp
, r
, "LISTBOX",
796 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
797 | LBS_USETABSTOPS
| LBS_NOTIFY
, WS_EX_CLIENTEDGE
, "", listid
);
805 ltext
= va_arg(ap
, char *);
808 lid
= va_arg(ap
, int);
809 rid
= va_arg(ap
, int);
811 r
.bottom
= STATICHEIGHT
;
812 y
+= r
.bottom
+ GAPWITHIN
;
815 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, ltext
, lid
);
816 r
.left
= rpos
+ r
.right
;
817 r
.right
= rwid
- r
.right
;
818 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_RIGHT
, 0, "",
824 r
.top
= y
+ 2 * GAPWITHIN
;
825 r
.bottom
= PUSHBTNHEIGHT
;
828 doctl(cp
, r
, "BUTTON",
829 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
832 cp
->ypos
+= LISTHEIGHT
+ GAPBETWEEN
;
836 * A special control for manipulating an ordered preference list
837 * (eg. for cipher selection).
838 * XXX: this is a rough hack and could be improved.
840 void prefslist(struct prefslist
*hdl
, struct ctlpos
*cp
, char *stext
,
841 int sid
, int listid
, int upbid
, int dnbid
)
843 const static int percents
[] = { 5, 75, 20 };
845 int xpos
, percent
= 0, i
;
846 const int DEFLISTHEIGHT
= 52; /* XXX configurable? */
847 const int BTNSHEIGHT
= 2*PUSHBTNHEIGHT
+ GAPBETWEEN
;
850 /* Squirrel away IDs. */
851 hdl
->listid
= listid
;
855 /* The static label. */
859 r
.bottom
= STATICHEIGHT
;
860 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
861 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
863 /* XXX it'd be nice to centre the buttons wrt the listbox
864 * but we'd have to find out how high the latter actually is. */
865 if (DEFLISTHEIGHT
> BTNSHEIGHT
) {
866 totalheight
= DEFLISTHEIGHT
;
868 totalheight
= BTNSHEIGHT
;
871 for (i
=0; i
<3; i
++) {
873 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
874 left
= xpos
+ GAPBETWEEN
;
875 percent
+= percents
[i
];
876 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
881 /* The drag list box. */
882 r
.left
= left
; r
.right
= wid
;
883 r
.top
= cp
->ypos
; r
.bottom
= totalheight
;
886 ctl
= doctl(cp
, r
, "LISTBOX",
887 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
888 WS_VSCROLL
| LBS_HASSTRINGS
,
896 /* The "Up" and "Down" buttons. */
897 /* XXX worry about accelerators if we have more than one
898 * prefslist on a panel */
899 r
.left
= left
; r
.right
= wid
;
900 r
.top
= cp
->ypos
; r
.bottom
= PUSHBTNHEIGHT
;
901 doctl(cp
, r
, "BUTTON",
902 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
905 r
.left
= left
; r
.right
= wid
;
906 r
.top
= cp
->ypos
+ PUSHBTNHEIGHT
+ GAPBETWEEN
;
907 r
.bottom
= PUSHBTNHEIGHT
;
908 doctl(cp
, r
, "BUTTON",
909 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
917 cp
->ypos
+= totalheight
+ GAPBETWEEN
;
922 * Helper function for prefslist: move item in list box.
924 static void pl_moveitem(HWND hwnd
, int listid
, int src
, int dst
)
928 /* Get the item's data. */
929 tlen
= SendDlgItemMessage (hwnd
, listid
, LB_GETTEXTLEN
, src
, 0);
930 txt
= smalloc(tlen
+1);
931 SendDlgItemMessage (hwnd
, listid
, LB_GETTEXT
, src
, (LPARAM
) txt
);
932 val
= SendDlgItemMessage (hwnd
, listid
, LB_GETITEMDATA
, src
, 0);
933 /* Deselect old location. */
934 SendDlgItemMessage (hwnd
, listid
, LB_SETSEL
, FALSE
, src
);
935 /* Delete it at the old location. */
936 SendDlgItemMessage (hwnd
, listid
, LB_DELETESTRING
, src
, 0);
937 /* Insert it at new location. */
938 SendDlgItemMessage (hwnd
, listid
, LB_INSERTSTRING
, dst
,
940 SendDlgItemMessage (hwnd
, listid
, LB_SETITEMDATA
, dst
,
943 SendDlgItemMessage (hwnd
, listid
, LB_SETCURSEL
, dst
, 0);
947 int pl_itemfrompt(HWND hwnd
, POINT cursor
, BOOL scroll
)
950 POINT uppoint
, downpoint
;
951 int updist
, downdist
, upitem
, downitem
, i
;
954 * Ghastly hackery to try to figure out not which
955 * _item_, but which _gap between items_, the user
956 * is pointing at. We do this by first working out
957 * which list item is under the cursor, and then
958 * working out how far the cursor would have to
959 * move up or down before the answer was different.
960 * Then we put the insertion point _above_ the
961 * current item if the upper edge is closer than
962 * the lower edge, or _below_ it if vice versa.
964 ret
= LBItemFromPt(hwnd
, cursor
, scroll
);
967 ret
= LBItemFromPt(hwnd
, cursor
, FALSE
);
968 updist
= downdist
= 0;
969 for (i
= 1; i
< 4096 && (!updist
|| !downdist
); i
++) {
970 uppoint
= downpoint
= cursor
;
973 upitem
= LBItemFromPt(hwnd
, uppoint
, FALSE
);
974 downitem
= LBItemFromPt(hwnd
, downpoint
, FALSE
);
975 if (!updist
&& upitem
!= ret
)
977 if (!downdist
&& downitem
!= ret
)
980 if (downdist
< updist
)
986 * Handler for prefslist above.
988 int handle_prefslist(struct prefslist
*hdl
,
989 int *array
, int maxmemb
,
990 int is_dlmsg
, HWND hwnd
,
991 WPARAM wParam
, LPARAM lParam
)
998 if (wParam
== hdl
->listid
) {
999 DRAGLISTINFO
*dlm
= (DRAGLISTINFO
*)lParam
;
1001 switch (dlm
->uNotification
) {
1004 SendDlgItemMessage(hwnd
, hdl
->listid
,
1005 LB_ADDSTRING
, 0, (LPARAM
) "");
1007 hdl
->srcitem
= LBItemFromPt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1009 /* XXX hack Q183115 */
1010 SetWindowLong(hwnd
, DWL_MSGRESULT
, TRUE
);
1013 DrawInsert(hwnd
, dlm
->hWnd
, -1); /* Clear arrow */
1014 SendDlgItemMessage(hwnd
, hdl
->listid
,
1015 LB_DELETESTRING
, hdl
->dummyitem
, 0);
1020 dest
= pl_itemfrompt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1021 if (dest
> hdl
->dummyitem
) dest
= hdl
->dummyitem
;
1022 DrawInsert (hwnd
, dlm
->hWnd
, dest
);
1024 SetWindowLong(hwnd
, DWL_MSGRESULT
, DL_MOVECURSOR
);
1026 SetWindowLong(hwnd
, DWL_MSGRESULT
, DL_STOPCURSOR
);
1030 if (!hdl
->dragging
) break;
1031 dest
= pl_itemfrompt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1032 if (dest
> hdl
->dummyitem
) dest
= hdl
->dummyitem
;
1033 DrawInsert (hwnd
, dlm
->hWnd
, -1);
1034 SendDlgItemMessage(hwnd
, hdl
->listid
,
1035 LB_DELETESTRING
, hdl
->dummyitem
, 0);
1038 /* Correct for "missing" item. This means you can't drag
1039 * an item to the end, but that seems to be the way this
1040 * control is used. */
1041 if (dest
> hdl
->srcitem
) dest
--;
1042 pl_moveitem(hwnd
, hdl
->listid
, hdl
->srcitem
, dest
);
1051 if (((LOWORD(wParam
) == hdl
->upbid
) ||
1052 (LOWORD(wParam
) == hdl
->dnbid
)) &&
1053 ((HIWORD(wParam
) == BN_CLICKED
) ||
1054 (HIWORD(wParam
) == BN_DOUBLECLICKED
))) {
1055 /* Move an item up or down the list. */
1056 /* Get the current selection, if any. */
1057 int selection
= SendDlgItemMessage (hwnd
, hdl
->listid
, LB_GETCURSEL
, 0, 0);
1058 if (selection
== LB_ERR
) {
1062 /* Get the total number of items. */
1063 nitems
= SendDlgItemMessage (hwnd
, hdl
->listid
, LB_GETCOUNT
, 0, 0);
1064 /* Should we do anything? */
1065 if (LOWORD(wParam
) == hdl
->upbid
&& (selection
> 0))
1066 pl_moveitem(hwnd
, hdl
->listid
, selection
, selection
- 1);
1067 else if (LOWORD(wParam
) == hdl
->dnbid
&& (selection
< nitems
- 1))
1068 pl_moveitem(hwnd
, hdl
->listid
, selection
, selection
+ 1);
1075 /* Update array to match the list box. */
1076 for (i
=0; i
< maxmemb
; i
++)
1077 array
[i
] = SendDlgItemMessage (hwnd
, hdl
->listid
, LB_GETITEMDATA
,
1085 * A progress bar (from Common Controls). We like our progress bars
1086 * to be smooth and unbroken, without those ugly divisions; some
1087 * older compilers may not support that, but that's life.
1089 void progressbar(struct ctlpos
*cp
, int id
)
1093 r
.left
= GAPBETWEEN
;
1095 r
.right
= cp
->width
;
1096 r
.bottom
= PROGBARHEIGHT
;
1097 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
1099 doctl(cp
, r
, PROGRESS_CLASS
, WS_CHILD
| WS_VISIBLE
1103 , WS_EX_CLIENTEDGE
, "", id
);
1107 * Another special control: the forwarding options setter. First a
1108 * list box; next a static header line, introducing a pair of edit
1109 * boxes with associated statics, another button, and a radio
1112 void fwdsetter(struct ctlpos
*cp
, int listid
, char *stext
, int sid
,
1113 char *e1stext
, int e1sid
, int e1id
,
1114 char *e2stext
, int e2sid
, int e2id
,
1115 char *btext
, int bid
)
1118 const int height
= (STATICHEIGHT
> EDITHEIGHT
1120 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
1121 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
1122 const static int percents
[] = { 25, 35, 15, 25 };
1123 int i
, j
, xpos
, percent
;
1124 const int LISTHEIGHT
= 42;
1127 r
.left
= GAPBETWEEN
;
1129 r
.right
= cp
->width
;
1130 r
.bottom
= LISTHEIGHT
;
1131 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
1132 doctl(cp
, r
, "LISTBOX",
1133 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
1134 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
1136 /* The static control. */
1137 r
.left
= GAPBETWEEN
;
1139 r
.right
= cp
->width
;
1140 r
.bottom
= STATICHEIGHT
;
1141 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
1142 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
1144 /* The statics+edits+buttons. */
1145 for (j
= 0; j
< 2; j
++) {
1147 for (i
= 0; i
< (j ?
2 : 4); i
++) {
1148 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
1149 r
.left
= xpos
+ GAPBETWEEN
;
1150 percent
+= percents
[i
];
1151 if (j
==1 && i
==1) percent
= 100;
1152 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
1153 r
.right
= xpos
- r
.left
;
1155 r
.bottom
= (i
== 0 ? STATICHEIGHT
:
1156 i
== 1 ? EDITHEIGHT
: PUSHBTNHEIGHT
);
1157 r
.top
+= (height
- r
.bottom
) / 2;
1159 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0,
1160 j
== 0 ? e1stext
: e2stext
, j
== 0 ? e1sid
: e2sid
);
1161 } else if (i
== 1) {
1162 doctl(cp
, r
, "EDIT",
1163 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
1164 WS_EX_CLIENTEDGE
, "", j
== 0 ? e1id
: e2id
);
1165 } else if (i
== 3) {
1166 doctl(cp
, r
, "BUTTON",
1167 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
1171 cp
->ypos
+= height
+ GAPWITHIN
;