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
)
167 r
.bottom
= STATICHEIGHT
;
168 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, staticid
);
169 r
.top
= cp
->ypos
+ 8 + GAPWITHIN
;
170 r
.bottom
= COMBOHEIGHT
* 10;
171 doctl(cp
, r
, "COMBOBOX",
172 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
|
173 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", listid
);
175 cp
->ypos
+= STATICHEIGHT
+ GAPWITHIN
+ COMBOHEIGHT
+ GAPBETWEEN
;
178 static void radioline_common(struct ctlpos
*cp
, int nacross
, va_list ap
)
187 btext
= va_arg(ap
, char *);
194 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
197 bid
= va_arg(ap
, int);
198 nextbtext
= va_arg(ap
, char *);
199 r
.left
= GAPBETWEEN
+ i
* (cp
->width
+ GAPBETWEEN
) / nacross
;
202 (i
+ 1) * (cp
->width
+ GAPBETWEEN
) / nacross
- r
.left
;
204 r
.right
= cp
->width
- r
.left
;
206 r
.bottom
= RADIOHEIGHT
;
207 doctl(cp
, r
, "BUTTON",
208 BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
209 group
, 0, btext
, bid
);
214 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
218 * A set of radio buttons on the same line, with a static above
219 * them. `nacross' dictates how many parts the line is divided into
220 * (you might want this not to equal the number of buttons if you
221 * needed to line up some 2s and some 3s to look good in the same
224 * There's a bit of a hack in here to ensure that if nacross
225 * exceeds the actual number of buttons, the rightmost button
226 * really does get all the space right to the edge of the line, so
227 * you can do things like
229 * (*) Button1 (*) Button2 (*) ButtonWithReallyLongTitle
231 void radioline(struct ctlpos
*cp
, char *text
, int id
, int nacross
, ...)
239 r
.bottom
= STATICHEIGHT
;
240 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
241 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
242 va_start(ap
, nacross
);
243 radioline_common(cp
, nacross
, ap
);
248 * A set of radio buttons on the same line, without a static above
249 * them. Otherwise just like radioline.
251 void bareradioline(struct ctlpos
*cp
, int nacross
, ...)
255 va_start(ap
, nacross
);
256 radioline_common(cp
, nacross
, ap
);
261 * A set of radio buttons on multiple lines, with a static above
264 void radiobig(struct ctlpos
*cp
, char *text
, int id
, ...)
273 r
.bottom
= STATICHEIGHT
;
274 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
275 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
281 btext
= va_arg(ap
, char *);
284 bid
= va_arg(ap
, int);
288 r
.bottom
= STATICHEIGHT
;
289 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
290 doctl(cp
, r
, "BUTTON",
291 BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
292 group
, 0, btext
, bid
);
296 cp
->ypos
+= GAPBETWEEN
- GAPWITHIN
;
300 * A single standalone checkbox.
302 void checkbox(struct ctlpos
*cp
, char *text
, int id
)
309 r
.bottom
= CHECKBOXHEIGHT
;
310 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
311 doctl(cp
, r
, "BUTTON",
312 BS_AUTOCHECKBOX
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0,
317 * A single standalone static text control.
319 void statictext(struct ctlpos
*cp
, char *text
, int id
)
326 r
.bottom
= STATICHEIGHT
;
327 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
328 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
332 * A button on the right hand side, with a static to its left.
334 void staticbtn(struct ctlpos
*cp
, char *stext
, int sid
,
335 char *btext
, int bid
)
337 const int height
= (PUSHBTNHEIGHT
> STATICHEIGHT ?
338 PUSHBTNHEIGHT
: STATICHEIGHT
);
340 int lwid
, rwid
, rpos
;
342 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
343 lwid
= rpos
- 2 * GAPBETWEEN
;
344 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
347 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
349 r
.bottom
= STATICHEIGHT
;
350 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
353 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
355 r
.bottom
= PUSHBTNHEIGHT
;
356 doctl(cp
, r
, "BUTTON",
357 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
360 cp
->ypos
+= height
+ GAPBETWEEN
;
364 * Like staticbtn, but two buttons.
366 void static2btn(struct ctlpos
*cp
, char *stext
, int sid
,
367 char *btext1
, int bid1
, char *btext2
, int bid2
)
369 const int height
= (PUSHBTNHEIGHT
> STATICHEIGHT ?
370 PUSHBTNHEIGHT
: STATICHEIGHT
);
372 int lwid
, rwid1
, rwid2
, rpos1
, rpos2
;
374 rpos1
= GAPBETWEEN
+ (cp
->width
+ GAPBETWEEN
) / 2;
375 rpos2
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
376 lwid
= rpos1
- 2 * GAPBETWEEN
;
377 rwid1
= rpos2
- rpos1
- GAPBETWEEN
;
378 rwid2
= cp
->width
+ GAPBETWEEN
- rpos2
;
381 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
383 r
.bottom
= STATICHEIGHT
;
384 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
387 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
389 r
.bottom
= PUSHBTNHEIGHT
;
390 doctl(cp
, r
, "BUTTON",
391 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
395 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
397 r
.bottom
= PUSHBTNHEIGHT
;
398 doctl(cp
, r
, "BUTTON",
399 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
402 cp
->ypos
+= height
+ GAPBETWEEN
;
406 * An edit control on the right hand side, with a static to its left.
408 static void staticedit_internal(struct ctlpos
*cp
, char *stext
,
409 int sid
, int eid
, int percentedit
,
412 const int height
= (EDITHEIGHT
> STATICHEIGHT ?
413 EDITHEIGHT
: STATICHEIGHT
);
415 int lwid
, rwid
, rpos
;
418 GAPBETWEEN
+ (100 - percentedit
) * (cp
->width
+ GAPBETWEEN
) / 100;
419 lwid
= rpos
- 2 * GAPBETWEEN
;
420 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
423 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
425 r
.bottom
= STATICHEIGHT
;
426 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
429 r
.top
= cp
->ypos
+ (height
- EDITHEIGHT
) / 2;
431 r
.bottom
= EDITHEIGHT
;
433 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
| style
,
434 WS_EX_CLIENTEDGE
, "", eid
);
436 cp
->ypos
+= height
+ GAPBETWEEN
;
439 void staticedit(struct ctlpos
*cp
, char *stext
,
440 int sid
, int eid
, int percentedit
)
442 staticedit_internal(cp
, stext
, sid
, eid
, percentedit
, 0);
445 void staticpassedit(struct ctlpos
*cp
, char *stext
,
446 int sid
, int eid
, int percentedit
)
448 staticedit_internal(cp
, stext
, sid
, eid
, percentedit
, ES_PASSWORD
);
452 * A big multiline edit control with a static labelling it.
454 void bigeditctrl(struct ctlpos
*cp
, char *stext
,
455 int sid
, int eid
, int lines
)
462 r
.bottom
= STATICHEIGHT
;
463 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
464 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
469 r
.bottom
= EDITHEIGHT
+ (lines
- 1) * STATICHEIGHT
;
470 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
472 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| ES_MULTILINE
,
473 WS_EX_CLIENTEDGE
, "", eid
);
477 * A tab-control substitute when a real tab control is unavailable.
479 void ersatztab(struct ctlpos
*cp
, char *stext
, int sid
, int lid
, int s2id
)
481 const int height
= (COMBOHEIGHT
> STATICHEIGHT ?
482 COMBOHEIGHT
: STATICHEIGHT
);
484 int bigwid
, lwid
, rwid
, rpos
;
485 static const int BIGGAP
= 15;
486 static const int MEDGAP
= 3;
488 bigwid
= cp
->width
+ 2 * GAPBETWEEN
- 2 * BIGGAP
;
490 rpos
= BIGGAP
+ (bigwid
+ BIGGAP
) / 2;
491 lwid
= rpos
- 2 * BIGGAP
;
492 rwid
= bigwid
+ BIGGAP
- rpos
;
495 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
497 r
.bottom
= STATICHEIGHT
;
498 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
501 r
.top
= cp
->ypos
+ (height
- COMBOHEIGHT
) / 2;
503 r
.bottom
= COMBOHEIGHT
* 10;
504 doctl(cp
, r
, "COMBOBOX",
505 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
506 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", lid
);
508 cp
->ypos
+= height
+ MEDGAP
+ GAPBETWEEN
;
514 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
,
519 * A static line, followed by an edit control on the left hand side
520 * and a button on the right.
522 void editbutton(struct ctlpos
*cp
, char *stext
, int sid
,
523 int eid
, char *btext
, int bid
)
525 const int height
= (EDITHEIGHT
> PUSHBTNHEIGHT ?
526 EDITHEIGHT
: PUSHBTNHEIGHT
);
528 int lwid
, rwid
, rpos
;
533 r
.bottom
= STATICHEIGHT
;
534 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
535 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
537 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
538 lwid
= rpos
- 2 * GAPBETWEEN
;
539 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
542 r
.top
= cp
->ypos
+ (height
- EDITHEIGHT
) / 2;
544 r
.bottom
= EDITHEIGHT
;
546 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
547 WS_EX_CLIENTEDGE
, "", eid
);
550 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
552 r
.bottom
= PUSHBTNHEIGHT
;
553 doctl(cp
, r
, "BUTTON",
554 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
557 cp
->ypos
+= height
+ GAPBETWEEN
;
561 * Special control which was hard to describe generically: the
562 * session-saver assembly. A static; below that an edit box; below
563 * that a list box. To the right of the list box, a column of
566 void sesssaver(struct ctlpos
*cp
, char *text
,
567 int staticid
, int editid
, int listid
, ...)
571 int lwid
, rwid
, rpos
;
573 const int LISTDEFHEIGHT
= 66;
575 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
576 lwid
= rpos
- 2 * GAPBETWEEN
;
577 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
579 /* The static control. */
583 r
.bottom
= STATICHEIGHT
;
584 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
585 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, staticid
);
587 /* The edit control. */
591 r
.bottom
= EDITHEIGHT
;
592 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
594 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
595 WS_EX_CLIENTEDGE
, "", editid
);
598 * The buttons (we should hold off on the list box until we
599 * know how big the buttons are).
601 va_start(ap
, listid
);
604 char *btext
= va_arg(ap
, char *);
608 bid
= va_arg(ap
, int);
612 r
.bottom
= PUSHBTNHEIGHT
;
613 y
+= r
.bottom
+ GAPWITHIN
;
614 doctl(cp
, r
, "BUTTON",
615 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
619 /* Compute list box height. LISTDEFHEIGHT, or height of buttons. */
622 if (y
< LISTDEFHEIGHT
)
628 cp
->ypos
+= y
+ GAPBETWEEN
;
629 doctl(cp
, r
, "LISTBOX",
630 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
|
631 LBS_NOTIFY
| LBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", listid
);
635 * Another special control: the environment-variable setter. A
636 * static line first; then a pair of edit boxes with associated
637 * statics, and two buttons; then a list box.
639 void envsetter(struct ctlpos
*cp
, char *stext
, int sid
,
640 char *e1stext
, int e1sid
, int e1id
,
641 char *e2stext
, int e2sid
, int e2id
,
642 int listid
, char *b1text
, int b1id
, char *b2text
, int b2id
)
645 const int height
= (STATICHEIGHT
> EDITHEIGHT
647 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
648 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
649 const static int percents
[] = { 20, 35, 10, 25 };
650 int i
, j
, xpos
, percent
;
651 const int LISTHEIGHT
= 42;
653 /* The static control. */
657 r
.bottom
= STATICHEIGHT
;
658 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
659 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
661 /* The statics+edits+buttons. */
662 for (j
= 0; j
< 2; j
++) {
664 for (i
= 0; i
< 4; i
++) {
665 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
666 r
.left
= xpos
+ GAPBETWEEN
;
667 percent
+= percents
[i
];
668 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
669 r
.right
= xpos
- r
.left
;
671 r
.bottom
= (i
== 0 ? STATICHEIGHT
:
672 i
== 1 ? EDITHEIGHT
: PUSHBTNHEIGHT
);
673 r
.top
+= (height
- r
.bottom
) / 2;
675 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0,
676 j
== 0 ? e1stext
: e2stext
, j
== 0 ? e1sid
: e2sid
);
679 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
680 WS_EX_CLIENTEDGE
, "", j
== 0 ? e1id
: e2id
);
682 doctl(cp
, r
, "BUTTON",
683 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
684 0, j
== 0 ? b1text
: b2text
, j
== 0 ? b1id
: b2id
);
687 cp
->ypos
+= height
+ GAPWITHIN
;
694 r
.bottom
= LISTHEIGHT
;
695 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
696 doctl(cp
, r
, "LISTBOX",
697 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
698 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
702 * Yet another special control: the character-class setter. A
703 * static, then a list, then a line containing a
704 * button-and-static-and-edit.
706 void charclass(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
707 char *btext
, int bid
, int eid
, char *s2text
, int s2id
)
710 const int height
= (STATICHEIGHT
> EDITHEIGHT
712 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
713 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
714 const static int percents
[] = { 30, 40, 30 };
715 int i
, xpos
, percent
;
716 const int LISTHEIGHT
= 66;
718 /* The static control. */
722 r
.bottom
= STATICHEIGHT
;
723 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
724 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
730 r
.bottom
= LISTHEIGHT
;
731 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
732 doctl(cp
, r
, "LISTBOX",
733 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
734 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
736 /* The button+static+edit. */
738 for (i
= 0; i
< 3; i
++) {
739 r
.left
= xpos
+ GAPBETWEEN
;
740 percent
+= percents
[i
];
741 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
742 r
.right
= xpos
- r
.left
;
744 r
.bottom
= (i
== 0 ? PUSHBTNHEIGHT
:
745 i
== 1 ? STATICHEIGHT
: EDITHEIGHT
);
746 r
.top
+= (height
- r
.bottom
) / 2;
748 doctl(cp
, r
, "BUTTON",
749 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
752 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_CENTER
,
756 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
757 WS_EX_CLIENTEDGE
, "", eid
);
760 cp
->ypos
+= height
+ GAPBETWEEN
;
764 * A special control (horrors!). The colour editor. A static line;
765 * then on the left, a list box, and on the right, a sequence of
766 * two-part statics followed by a button.
768 void colouredit(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
769 char *btext
, int bid
, ...)
774 int lwid
, rwid
, rpos
;
775 const int LISTHEIGHT
= 66;
777 /* The static control. */
781 r
.bottom
= STATICHEIGHT
;
782 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
783 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
785 rpos
= GAPBETWEEN
+ 2 * (cp
->width
+ GAPBETWEEN
) / 3;
786 lwid
= rpos
- 2 * GAPBETWEEN
;
787 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
793 r
.bottom
= LISTHEIGHT
;
794 doctl(cp
, r
, "LISTBOX",
795 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
796 | LBS_USETABSTOPS
| LBS_NOTIFY
, WS_EX_CLIENTEDGE
, "", listid
);
804 ltext
= va_arg(ap
, char *);
807 lid
= va_arg(ap
, int);
808 rid
= va_arg(ap
, int);
810 r
.bottom
= STATICHEIGHT
;
811 y
+= r
.bottom
+ GAPWITHIN
;
814 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, ltext
, lid
);
815 r
.left
= rpos
+ r
.right
;
816 r
.right
= rwid
- r
.right
;
817 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_RIGHT
, 0, "",
823 r
.top
= y
+ 2 * GAPWITHIN
;
824 r
.bottom
= PUSHBTNHEIGHT
;
827 doctl(cp
, r
, "BUTTON",
828 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
831 cp
->ypos
+= LISTHEIGHT
+ GAPBETWEEN
;
835 * A special control for manipulating an ordered preference list
836 * (eg. for cipher selection).
837 * XXX: this is a rough hack and could be improved.
839 void prefslist(struct prefslist
*hdl
, struct ctlpos
*cp
, char *stext
,
840 int sid
, int listid
, int upbid
, int dnbid
)
842 const static int percents
[] = { 5, 75, 20 };
844 int xpos
, percent
= 0, i
;
845 const int DEFLISTHEIGHT
= 52; /* XXX configurable? */
846 const int BTNSHEIGHT
= 2*PUSHBTNHEIGHT
+ GAPBETWEEN
;
849 /* Squirrel away IDs. */
850 hdl
->listid
= listid
;
854 /* The static label. */
858 r
.bottom
= STATICHEIGHT
;
859 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
860 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
862 /* XXX it'd be nice to centre the buttons wrt the listbox
863 * but we'd have to find out how high the latter actually is. */
864 if (DEFLISTHEIGHT
> BTNSHEIGHT
) {
865 totalheight
= DEFLISTHEIGHT
;
867 totalheight
= BTNSHEIGHT
;
870 for (i
=0; i
<3; i
++) {
872 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
873 left
= xpos
+ GAPBETWEEN
;
874 percent
+= percents
[i
];
875 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
880 /* The drag list box. */
881 r
.left
= left
; r
.right
= wid
;
882 r
.top
= cp
->ypos
; r
.bottom
= totalheight
;
885 ctl
= doctl(cp
, r
, "LISTBOX",
886 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
887 WS_VSCROLL
| LBS_HASSTRINGS
,
895 /* The "Up" and "Down" buttons. */
896 /* XXX worry about accelerators if we have more than one
897 * prefslist on a panel */
898 r
.left
= left
; r
.right
= wid
;
899 r
.top
= cp
->ypos
; r
.bottom
= PUSHBTNHEIGHT
;
900 doctl(cp
, r
, "BUTTON",
901 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
904 r
.left
= left
; r
.right
= wid
;
905 r
.top
= cp
->ypos
+ PUSHBTNHEIGHT
+ GAPBETWEEN
;
906 r
.bottom
= PUSHBTNHEIGHT
;
907 doctl(cp
, r
, "BUTTON",
908 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
916 cp
->ypos
+= totalheight
+ GAPBETWEEN
;
921 * Helper function for prefslist: move item in list box.
923 static void pl_moveitem(HWND hwnd
, int listid
, int src
, int dst
)
927 /* Get the item's data. */
928 tlen
= SendDlgItemMessage (hwnd
, listid
, LB_GETTEXTLEN
, src
, 0);
929 txt
= smalloc(tlen
+1);
930 SendDlgItemMessage (hwnd
, listid
, LB_GETTEXT
, src
, (LPARAM
) txt
);
931 val
= SendDlgItemMessage (hwnd
, listid
, LB_GETITEMDATA
, src
, 0);
932 /* Deselect old location. */
933 SendDlgItemMessage (hwnd
, listid
, LB_SETSEL
, FALSE
, src
);
934 /* Delete it at the old location. */
935 SendDlgItemMessage (hwnd
, listid
, LB_DELETESTRING
, src
, 0);
936 /* Insert it at new location. */
937 SendDlgItemMessage (hwnd
, listid
, LB_INSERTSTRING
, dst
,
939 SendDlgItemMessage (hwnd
, listid
, LB_SETITEMDATA
, dst
,
942 SendDlgItemMessage (hwnd
, listid
, LB_SETCURSEL
, dst
, 0);
946 int pl_itemfrompt(HWND hwnd
, POINT cursor
, BOOL scroll
)
949 POINT uppoint
, downpoint
;
950 int updist
, downdist
, upitem
, downitem
, i
;
953 * Ghastly hackery to try to figure out not which
954 * _item_, but which _gap between items_, the user
955 * is pointing at. We do this by first working out
956 * which list item is under the cursor, and then
957 * working out how far the cursor would have to
958 * move up or down before the answer was different.
959 * Then we put the insertion point _above_ the
960 * current item if the upper edge is closer than
961 * the lower edge, or _below_ it if vice versa.
963 ret
= LBItemFromPt(hwnd
, cursor
, scroll
);
966 ret
= LBItemFromPt(hwnd
, cursor
, FALSE
);
967 updist
= downdist
= 0;
968 for (i
= 1; i
< 4096 && (!updist
|| !downdist
); i
++) {
969 uppoint
= downpoint
= cursor
;
972 upitem
= LBItemFromPt(hwnd
, uppoint
, FALSE
);
973 downitem
= LBItemFromPt(hwnd
, downpoint
, FALSE
);
974 if (!updist
&& upitem
!= ret
)
976 if (!downdist
&& downitem
!= ret
)
979 if (downdist
< updist
)
985 * Handler for prefslist above.
987 int handle_prefslist(struct prefslist
*hdl
,
988 int *array
, int maxmemb
,
989 int is_dlmsg
, HWND hwnd
,
990 WPARAM wParam
, LPARAM lParam
)
997 if ((int)wParam
== hdl
->listid
) {
998 DRAGLISTINFO
*dlm
= (DRAGLISTINFO
*)lParam
;
1000 switch (dlm
->uNotification
) {
1003 SendDlgItemMessage(hwnd
, hdl
->listid
,
1004 LB_ADDSTRING
, 0, (LPARAM
) "");
1006 hdl
->srcitem
= LBItemFromPt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1008 /* XXX hack Q183115 */
1009 SetWindowLong(hwnd
, DWL_MSGRESULT
, TRUE
);
1012 DrawInsert(hwnd
, dlm
->hWnd
, -1); /* Clear arrow */
1013 SendDlgItemMessage(hwnd
, hdl
->listid
,
1014 LB_DELETESTRING
, hdl
->dummyitem
, 0);
1019 dest
= pl_itemfrompt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1020 if (dest
> hdl
->dummyitem
) dest
= hdl
->dummyitem
;
1021 DrawInsert (hwnd
, dlm
->hWnd
, dest
);
1023 SetWindowLong(hwnd
, DWL_MSGRESULT
, DL_MOVECURSOR
);
1025 SetWindowLong(hwnd
, DWL_MSGRESULT
, DL_STOPCURSOR
);
1029 if (!hdl
->dragging
) break;
1030 dest
= pl_itemfrompt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1031 if (dest
> hdl
->dummyitem
) dest
= hdl
->dummyitem
;
1032 DrawInsert (hwnd
, dlm
->hWnd
, -1);
1033 SendDlgItemMessage(hwnd
, hdl
->listid
,
1034 LB_DELETESTRING
, hdl
->dummyitem
, 0);
1037 /* Correct for "missing" item. This means you can't drag
1038 * an item to the end, but that seems to be the way this
1039 * control is used. */
1040 if (dest
> hdl
->srcitem
) dest
--;
1041 pl_moveitem(hwnd
, hdl
->listid
, hdl
->srcitem
, dest
);
1050 if (((LOWORD(wParam
) == hdl
->upbid
) ||
1051 (LOWORD(wParam
) == hdl
->dnbid
)) &&
1052 ((HIWORD(wParam
) == BN_CLICKED
) ||
1053 (HIWORD(wParam
) == BN_DOUBLECLICKED
))) {
1054 /* Move an item up or down the list. */
1055 /* Get the current selection, if any. */
1056 int selection
= SendDlgItemMessage (hwnd
, hdl
->listid
, LB_GETCURSEL
, 0, 0);
1057 if (selection
== LB_ERR
) {
1061 /* Get the total number of items. */
1062 nitems
= SendDlgItemMessage (hwnd
, hdl
->listid
, LB_GETCOUNT
, 0, 0);
1063 /* Should we do anything? */
1064 if (LOWORD(wParam
) == hdl
->upbid
&& (selection
> 0))
1065 pl_moveitem(hwnd
, hdl
->listid
, selection
, selection
- 1);
1066 else if (LOWORD(wParam
) == hdl
->dnbid
&& (selection
< nitems
- 1))
1067 pl_moveitem(hwnd
, hdl
->listid
, selection
, selection
+ 1);
1074 /* Update array to match the list box. */
1075 for (i
=0; i
< maxmemb
; i
++)
1076 array
[i
] = SendDlgItemMessage (hwnd
, hdl
->listid
, LB_GETITEMDATA
,
1084 * A progress bar (from Common Controls). We like our progress bars
1085 * to be smooth and unbroken, without those ugly divisions; some
1086 * older compilers may not support that, but that's life.
1088 void progressbar(struct ctlpos
*cp
, int id
)
1092 r
.left
= GAPBETWEEN
;
1094 r
.right
= cp
->width
;
1095 r
.bottom
= PROGBARHEIGHT
;
1096 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
1098 doctl(cp
, r
, PROGRESS_CLASS
, WS_CHILD
| WS_VISIBLE
1102 , WS_EX_CLIENTEDGE
, "", id
);
1106 * Another special control: the forwarding options setter. First a
1107 * list box; next a static header line, introducing a pair of edit
1108 * boxes with associated statics, another button, and a radio
1111 void fwdsetter(struct ctlpos
*cp
, int listid
, char *stext
, int sid
,
1112 char *e1stext
, int e1sid
, int e1id
,
1113 char *e2stext
, int e2sid
, int e2id
,
1114 char *btext
, int bid
)
1117 const int height
= (STATICHEIGHT
> EDITHEIGHT
1119 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
1120 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
1121 const static int percents
[] = { 25, 35, 15, 25 };
1122 int i
, j
, xpos
, percent
;
1123 const int LISTHEIGHT
= 42;
1126 r
.left
= GAPBETWEEN
;
1128 r
.right
= cp
->width
;
1129 r
.bottom
= LISTHEIGHT
;
1130 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
1131 doctl(cp
, r
, "LISTBOX",
1132 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
1133 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
1135 /* The static control. */
1136 r
.left
= GAPBETWEEN
;
1138 r
.right
= cp
->width
;
1139 r
.bottom
= STATICHEIGHT
;
1140 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
1141 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
1143 /* The statics+edits+buttons. */
1144 for (j
= 0; j
< 2; j
++) {
1146 for (i
= 0; i
< (j ?
2 : 4); i
++) {
1147 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
1148 r
.left
= xpos
+ GAPBETWEEN
;
1149 percent
+= percents
[i
];
1150 if (j
==1 && i
==1) percent
= 100;
1151 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
1152 r
.right
= xpos
- r
.left
;
1154 r
.bottom
= (i
== 0 ? STATICHEIGHT
:
1155 i
== 1 ? EDITHEIGHT
: PUSHBTNHEIGHT
);
1156 r
.top
+= (height
- r
.bottom
) / 2;
1158 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0,
1159 j
== 0 ? e1stext
: e2stext
, j
== 0 ? e1sid
: e2sid
);
1160 } else if (i
== 1) {
1161 doctl(cp
, r
, "EDIT",
1162 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
1163 WS_EX_CLIENTEDGE
, "", j
== 0 ? e1id
: e2id
);
1164 } else if (i
== 3) {
1165 doctl(cp
, r
, "BUTTON",
1166 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
1170 cp
->ypos
+= height
+ GAPWITHIN
;