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 combo box.
158 void combobox(struct ctlpos
*cp
, char *text
, int staticid
, int listid
)
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
|
172 CBS_DROPDOWN
| CBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", listid
);
174 cp
->ypos
+= STATICHEIGHT
+ GAPWITHIN
+ COMBOHEIGHT
+ GAPBETWEEN
;
177 static void radioline_common(struct ctlpos
*cp
, int nacross
, va_list ap
)
186 btext
= va_arg(ap
, char *);
193 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
196 bid
= va_arg(ap
, int);
197 nextbtext
= va_arg(ap
, char *);
198 r
.left
= GAPBETWEEN
+ i
* (cp
->width
+ GAPBETWEEN
) / nacross
;
201 (i
+ 1) * (cp
->width
+ GAPBETWEEN
) / nacross
- r
.left
;
203 r
.right
= cp
->width
- r
.left
;
205 r
.bottom
= RADIOHEIGHT
;
206 doctl(cp
, r
, "BUTTON",
207 BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
208 group
, 0, btext
, bid
);
213 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
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
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
228 * (*) Button1 (*) Button2 (*) ButtonWithReallyLongTitle
230 void radioline(struct ctlpos
*cp
, char *text
, int id
, int nacross
, ...)
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
);
247 * A set of radio buttons on the same line, without a static above
248 * them. Otherwise just like radioline.
250 void bareradioline(struct ctlpos
*cp
, int nacross
, ...)
254 va_start(ap
, nacross
);
255 radioline_common(cp
, nacross
, ap
);
260 * A set of radio buttons on multiple lines, with a static above
263 void radiobig(struct ctlpos
*cp
, char *text
, int id
, ...)
272 r
.bottom
= STATICHEIGHT
;
273 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
274 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
280 btext
= va_arg(ap
, char *);
283 bid
= va_arg(ap
, int);
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
);
295 cp
->ypos
+= GAPBETWEEN
- GAPWITHIN
;
299 * A single standalone checkbox.
301 void checkbox(struct ctlpos
*cp
, char *text
, int id
)
308 r
.bottom
= CHECKBOXHEIGHT
;
309 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
310 doctl(cp
, r
, "BUTTON",
311 BS_AUTOCHECKBOX
| WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
, 0,
316 * A single standalone static text control.
318 void statictext(struct ctlpos
*cp
, char *text
, int lines
, int id
)
325 r
.bottom
= STATICHEIGHT
* lines
;
326 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
327 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, id
);
331 * A button on the right hand side, with a static to its left.
333 void staticbtn(struct ctlpos
*cp
, char *stext
, int sid
,
334 char *btext
, int bid
)
336 const int height
= (PUSHBTNHEIGHT
> STATICHEIGHT ?
337 PUSHBTNHEIGHT
: STATICHEIGHT
);
339 int lwid
, rwid
, rpos
;
341 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
342 lwid
= rpos
- 2 * GAPBETWEEN
;
343 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
346 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
348 r
.bottom
= STATICHEIGHT
;
349 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
352 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
354 r
.bottom
= PUSHBTNHEIGHT
;
355 doctl(cp
, r
, "BUTTON",
356 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
359 cp
->ypos
+= height
+ GAPBETWEEN
;
363 * Like staticbtn, but two buttons.
365 void static2btn(struct ctlpos
*cp
, char *stext
, int sid
,
366 char *btext1
, int bid1
, char *btext2
, int bid2
)
368 const int height
= (PUSHBTNHEIGHT
> STATICHEIGHT ?
369 PUSHBTNHEIGHT
: STATICHEIGHT
);
371 int lwid
, rwid1
, rwid2
, rpos1
, rpos2
;
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
;
380 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
382 r
.bottom
= STATICHEIGHT
;
383 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
386 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
388 r
.bottom
= PUSHBTNHEIGHT
;
389 doctl(cp
, r
, "BUTTON",
390 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
394 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
396 r
.bottom
= PUSHBTNHEIGHT
;
397 doctl(cp
, r
, "BUTTON",
398 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
401 cp
->ypos
+= height
+ GAPBETWEEN
;
405 * An edit control on the right hand side, with a static to its left.
407 static void staticedit_internal(struct ctlpos
*cp
, char *stext
,
408 int sid
, int eid
, int percentedit
,
411 const int height
= (EDITHEIGHT
> STATICHEIGHT ?
412 EDITHEIGHT
: STATICHEIGHT
);
414 int lwid
, rwid
, rpos
;
417 GAPBETWEEN
+ (100 - percentedit
) * (cp
->width
+ GAPBETWEEN
) / 100;
418 lwid
= rpos
- 2 * GAPBETWEEN
;
419 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
422 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
424 r
.bottom
= STATICHEIGHT
;
425 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
428 r
.top
= cp
->ypos
+ (height
- EDITHEIGHT
) / 2;
430 r
.bottom
= EDITHEIGHT
;
432 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
| style
,
433 WS_EX_CLIENTEDGE
, "", eid
);
435 cp
->ypos
+= height
+ GAPBETWEEN
;
438 void staticedit(struct ctlpos
*cp
, char *stext
,
439 int sid
, int eid
, int percentedit
)
441 staticedit_internal(cp
, stext
, sid
, eid
, percentedit
, 0);
444 void staticpassedit(struct ctlpos
*cp
, char *stext
,
445 int sid
, int eid
, int percentedit
)
447 staticedit_internal(cp
, stext
, sid
, eid
, percentedit
, ES_PASSWORD
);
451 * A drop-down list box on the right hand side, with a static to
454 void staticddl(struct ctlpos
*cp
, char *stext
,
455 int sid
, int lid
, int percentlist
)
457 const int height
= (COMBOHEIGHT
> STATICHEIGHT ?
458 COMBOHEIGHT
: STATICHEIGHT
);
460 int lwid
, rwid
, rpos
;
463 GAPBETWEEN
+ (100 - percentlist
) * (cp
->width
+ GAPBETWEEN
) / 100;
464 lwid
= rpos
- 2 * GAPBETWEEN
;
465 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
468 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
470 r
.bottom
= STATICHEIGHT
;
471 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
474 r
.top
= cp
->ypos
+ (height
- EDITHEIGHT
) / 2;
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
);
481 cp
->ypos
+= height
+ GAPBETWEEN
;
485 * A big multiline edit control with a static labelling it.
487 void bigeditctrl(struct ctlpos
*cp
, char *stext
,
488 int sid
, int eid
, int lines
)
495 r
.bottom
= STATICHEIGHT
;
496 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
497 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
502 r
.bottom
= EDITHEIGHT
+ (lines
- 1) * STATICHEIGHT
;
503 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
505 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| ES_MULTILINE
,
506 WS_EX_CLIENTEDGE
, "", eid
);
510 * A tab-control substitute when a real tab control is unavailable.
512 void ersatztab(struct ctlpos
*cp
, char *stext
, int sid
, int lid
, int s2id
)
514 const int height
= (COMBOHEIGHT
> STATICHEIGHT ?
515 COMBOHEIGHT
: STATICHEIGHT
);
517 int bigwid
, lwid
, rwid
, rpos
;
518 static const int BIGGAP
= 15;
519 static const int MEDGAP
= 3;
521 bigwid
= cp
->width
+ 2 * GAPBETWEEN
- 2 * BIGGAP
;
523 rpos
= BIGGAP
+ (bigwid
+ BIGGAP
) / 2;
524 lwid
= rpos
- 2 * BIGGAP
;
525 rwid
= bigwid
+ BIGGAP
- rpos
;
528 r
.top
= cp
->ypos
+ (height
- STATICHEIGHT
) / 2;
530 r
.bottom
= STATICHEIGHT
;
531 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
534 r
.top
= cp
->ypos
+ (height
- COMBOHEIGHT
) / 2;
536 r
.bottom
= COMBOHEIGHT
* 10;
537 doctl(cp
, r
, "COMBOBOX",
538 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
539 CBS_DROPDOWNLIST
| CBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", lid
);
541 cp
->ypos
+= height
+ MEDGAP
+ GAPBETWEEN
;
547 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_ETCHEDHORZ
,
552 * A static line, followed by an edit control on the left hand side
553 * and a button on the right.
555 void editbutton(struct ctlpos
*cp
, char *stext
, int sid
,
556 int eid
, char *btext
, int bid
)
558 const int height
= (EDITHEIGHT
> PUSHBTNHEIGHT ?
559 EDITHEIGHT
: PUSHBTNHEIGHT
);
561 int lwid
, rwid
, rpos
;
566 r
.bottom
= STATICHEIGHT
;
567 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
568 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
570 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
571 lwid
= rpos
- 2 * GAPBETWEEN
;
572 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
575 r
.top
= cp
->ypos
+ (height
- EDITHEIGHT
) / 2;
577 r
.bottom
= EDITHEIGHT
;
579 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
580 WS_EX_CLIENTEDGE
, "", eid
);
583 r
.top
= cp
->ypos
+ (height
- PUSHBTNHEIGHT
) / 2;
585 r
.bottom
= PUSHBTNHEIGHT
;
586 doctl(cp
, r
, "BUTTON",
587 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
590 cp
->ypos
+= height
+ GAPBETWEEN
;
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
599 void sesssaver(struct ctlpos
*cp
, char *text
,
600 int staticid
, int editid
, int listid
, ...)
604 int lwid
, rwid
, rpos
;
606 const int LISTDEFHEIGHT
= 66;
608 rpos
= GAPBETWEEN
+ 3 * (cp
->width
+ GAPBETWEEN
) / 4;
609 lwid
= rpos
- 2 * GAPBETWEEN
;
610 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
612 /* The static control. */
616 r
.bottom
= STATICHEIGHT
;
617 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
618 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, text
, staticid
);
620 /* The edit control. */
624 r
.bottom
= EDITHEIGHT
;
625 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
627 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
628 WS_EX_CLIENTEDGE
, "", editid
);
631 * The buttons (we should hold off on the list box until we
632 * know how big the buttons are).
634 va_start(ap
, listid
);
637 char *btext
= va_arg(ap
, char *);
641 bid
= va_arg(ap
, int);
645 r
.bottom
= PUSHBTNHEIGHT
;
646 y
+= r
.bottom
+ GAPWITHIN
;
647 doctl(cp
, r
, "BUTTON",
648 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
652 /* Compute list box height. LISTDEFHEIGHT, or height of buttons. */
655 if (y
< LISTDEFHEIGHT
)
661 cp
->ypos
+= y
+ GAPBETWEEN
;
662 doctl(cp
, r
, "LISTBOX",
663 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
|
664 LBS_NOTIFY
| LBS_HASSTRINGS
, WS_EX_CLIENTEDGE
, "", listid
);
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.
672 void envsetter(struct ctlpos
*cp
, char *stext
, int sid
,
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
)
678 const int height
= (STATICHEIGHT
> EDITHEIGHT
680 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
681 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
682 const static int percents
[] = { 20, 35, 10, 25 };
683 int i
, j
, xpos
, percent
;
684 const int LISTHEIGHT
= 42;
686 /* The static control. */
690 r
.bottom
= STATICHEIGHT
;
691 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
692 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
694 /* The statics+edits+buttons. */
695 for (j
= 0; j
< 2; j
++) {
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
;
704 r
.bottom
= (i
== 0 ? STATICHEIGHT
:
705 i
== 1 ? EDITHEIGHT
: PUSHBTNHEIGHT
);
706 r
.top
+= (height
- r
.bottom
) / 2;
708 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0,
709 j
== 0 ? e1stext
: e2stext
, j
== 0 ? e1sid
: e2sid
);
712 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
713 WS_EX_CLIENTEDGE
, "", j
== 0 ? e1id
: e2id
);
715 doctl(cp
, r
, "BUTTON",
716 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
717 0, j
== 0 ? b1text
: b2text
, j
== 0 ? b1id
: b2id
);
720 cp
->ypos
+= height
+ GAPWITHIN
;
727 r
.bottom
= LISTHEIGHT
;
728 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
729 doctl(cp
, r
, "LISTBOX",
730 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
731 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
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.
739 void charclass(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
740 char *btext
, int bid
, int eid
, char *s2text
, int s2id
)
743 const int height
= (STATICHEIGHT
> EDITHEIGHT
745 PUSHBTNHEIGHT ? STATICHEIGHT
: EDITHEIGHT
>
746 PUSHBTNHEIGHT ? EDITHEIGHT
: PUSHBTNHEIGHT
);
747 const static int percents
[] = { 30, 40, 30 };
748 int i
, xpos
, percent
;
749 const int LISTHEIGHT
= 52;
751 /* The static control. */
755 r
.bottom
= STATICHEIGHT
;
756 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
757 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
763 r
.bottom
= LISTHEIGHT
;
764 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
765 doctl(cp
, r
, "LISTBOX",
766 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
767 | LBS_USETABSTOPS
, WS_EX_CLIENTEDGE
, "", listid
);
769 /* The button+static+edit. */
771 for (i
= 0; i
< 3; i
++) {
772 r
.left
= xpos
+ GAPBETWEEN
;
773 percent
+= percents
[i
];
774 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
775 r
.right
= xpos
- r
.left
;
777 r
.bottom
= (i
== 0 ? PUSHBTNHEIGHT
:
778 i
== 1 ? STATICHEIGHT
: EDITHEIGHT
);
779 r
.top
+= (height
- r
.bottom
) / 2;
781 doctl(cp
, r
, "BUTTON",
782 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
785 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
| SS_CENTER
,
789 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| ES_AUTOHSCROLL
,
790 WS_EX_CLIENTEDGE
, "", eid
);
793 cp
->ypos
+= height
+ GAPBETWEEN
;
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.
801 void colouredit(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
802 char *btext
, int bid
, ...)
807 int lwid
, rwid
, rpos
;
808 const int LISTHEIGHT
= 66;
810 /* The static control. */
814 r
.bottom
= STATICHEIGHT
;
815 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
816 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
818 rpos
= GAPBETWEEN
+ 2 * (cp
->width
+ GAPBETWEEN
) / 3;
819 lwid
= rpos
- 2 * GAPBETWEEN
;
820 rwid
= cp
->width
+ GAPBETWEEN
- rpos
;
826 r
.bottom
= LISTHEIGHT
;
827 doctl(cp
, r
, "LISTBOX",
828 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_VSCROLL
| LBS_HASSTRINGS
829 | LBS_USETABSTOPS
| LBS_NOTIFY
, WS_EX_CLIENTEDGE
, "", listid
);
837 ltext
= va_arg(ap
, char *);
840 lid
= va_arg(ap
, int);
841 rid
= va_arg(ap
, int);
843 r
.bottom
= STATICHEIGHT
;
844 y
+= r
.bottom
+ GAPWITHIN
;
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, "",
856 r
.top
= y
+ 2 * GAPWITHIN
;
857 r
.bottom
= PUSHBTNHEIGHT
;
860 doctl(cp
, r
, "BUTTON",
861 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| BS_PUSHBUTTON
,
864 cp
->ypos
+= LISTHEIGHT
+ GAPBETWEEN
;
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.
872 void prefslist(struct prefslist
*hdl
, struct ctlpos
*cp
, char *stext
,
873 int sid
, int listid
, int upbid
, int dnbid
)
875 const static int percents
[] = { 5, 75, 20 };
877 int xpos
, percent
= 0, i
;
878 const int DEFLISTHEIGHT
= 52; /* XXX configurable? */
879 const int BTNSHEIGHT
= 2*PUSHBTNHEIGHT
+ GAPBETWEEN
;
882 /* Squirrel away IDs. */
883 hdl
->listid
= listid
;
887 /* The static label. */
891 r
.bottom
= STATICHEIGHT
;
892 cp
->ypos
+= r
.bottom
+ GAPWITHIN
;
893 doctl(cp
, r
, "STATIC", WS_CHILD
| WS_VISIBLE
, 0, stext
, sid
);
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
;
900 totalheight
= BTNSHEIGHT
;
903 for (i
=0; i
<3; i
++) {
905 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
906 left
= xpos
+ GAPBETWEEN
;
907 percent
+= percents
[i
];
908 xpos
= (cp
->width
+ GAPBETWEEN
) * percent
/ 100;
913 /* The drag list box. */
914 r
.left
= left
; r
.right
= wid
;
915 r
.top
= cp
->ypos
; r
.bottom
= totalheight
;
918 ctl
= doctl(cp
, r
, "LISTBOX",
919 WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
|
920 WS_VSCROLL
| LBS_HASSTRINGS
,
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
,
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
,
949 cp
->ypos
+= totalheight
+ GAPBETWEEN
;
954 * Helper function for prefslist: move item in list box.
956 static void pl_moveitem(HWND hwnd
, int listid
, int src
, int dst
)
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
,
972 SendDlgItemMessage (hwnd
, listid
, LB_SETITEMDATA
, dst
,
975 SendDlgItemMessage (hwnd
, listid
, LB_SETCURSEL
, dst
, 0);
979 int pl_itemfrompt(HWND hwnd
, POINT cursor
, BOOL scroll
)
982 POINT uppoint
, downpoint
;
983 int updist
, downdist
, upitem
, downitem
, i
;
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.
996 ret
= LBItemFromPt(hwnd
, cursor
, scroll
);
999 ret
= LBItemFromPt(hwnd
, cursor
, FALSE
);
1000 updist
= downdist
= 0;
1001 for (i
= 1; i
< 4096 && (!updist
|| !downdist
); i
++) {
1002 uppoint
= downpoint
= cursor
;
1005 upitem
= LBItemFromPt(hwnd
, uppoint
, FALSE
);
1006 downitem
= LBItemFromPt(hwnd
, downpoint
, FALSE
);
1007 if (!updist
&& upitem
!= ret
)
1009 if (!downdist
&& downitem
!= ret
)
1012 if (downdist
< updist
)
1018 * Handler for prefslist above.
1020 int handle_prefslist(struct prefslist
*hdl
,
1021 int *array
, int maxmemb
,
1022 int is_dlmsg
, HWND hwnd
,
1023 WPARAM wParam
, LPARAM lParam
)
1030 if ((int)wParam
== hdl
->listid
) {
1031 DRAGLISTINFO
*dlm
= (DRAGLISTINFO
*)lParam
;
1033 switch (dlm
->uNotification
) {
1036 SendDlgItemMessage(hwnd
, hdl
->listid
,
1037 LB_ADDSTRING
, 0, (LPARAM
) "");
1039 hdl
->srcitem
= LBItemFromPt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1041 /* XXX hack Q183115 */
1042 SetWindowLong(hwnd
, DWL_MSGRESULT
, TRUE
);
1045 DrawInsert(hwnd
, dlm
->hWnd
, -1); /* Clear arrow */
1046 SendDlgItemMessage(hwnd
, hdl
->listid
,
1047 LB_DELETESTRING
, hdl
->dummyitem
, 0);
1052 dest
= pl_itemfrompt(dlm
->hWnd
, dlm
->ptCursor
, TRUE
);
1053 if (dest
> hdl
->dummyitem
) dest
= hdl
->dummyitem
;
1054 DrawInsert (hwnd
, dlm
->hWnd
, dest
);
1056 SetWindowLong(hwnd
, DWL_MSGRESULT
, DL_MOVECURSOR
);
1058 SetWindowLong(hwnd
, DWL_MSGRESULT
, DL_STOPCURSOR
);
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);
1066 SendDlgItemMessage(hwnd
, hdl
->listid
,
1067 LB_DELETESTRING
, hdl
->dummyitem
, 0);
1068 if (hdl
->dragging
) {
1071 /* Correct for "missing" item. */
1072 if (dest
> hdl
->srcitem
) dest
--;
1073 pl_moveitem(hwnd
, hdl
->listid
, hdl
->srcitem
, dest
);
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
) {
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);
1107 /* Update array to match the list box. */
1108 for (i
=0; i
< maxmemb
; i
++)
1109 array
[i
] = SendDlgItemMessage (hwnd
, hdl
->listid
, LB_GETITEMDATA
,
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.
1121 void progressbar(struct ctlpos
*cp
, int id
)
1125 r
.left
= GAPBETWEEN
;
1127 r
.right
= cp
->width
;
1128 r
.bottom
= PROGBARHEIGHT
;
1129 cp
->ypos
+= r
.bottom
+ GAPBETWEEN
;
1131 doctl(cp
, r
, PROGRESS_CLASS
, WS_CHILD
| WS_VISIBLE
1135 , WS_EX_CLIENTEDGE
, "", id
);
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
1142 * button pair. Then we have a bareradioline, which is included in
1143 * this control group because it belongs before the `Add' button in
1146 void fwdsetter(struct ctlpos
*cp
, int listid
, char *stext
, int sid
,
1147 char *e1stext
, int e1sid
, int e1id
,
1148 char *e2stext
, int e2sid
, int e2id
,
1149 char *btext
, int bid
,
1150 char *r1text
, int r1id
, char *r2text
, int r2id
)
1153 const int height
= (STATICHEIGHT
> EDITHEIGHT
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;
1162 r
.left
= GAPBETWEEN
;
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
);
1171 /* The static control. */
1172 r
.left
= GAPBETWEEN
;
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
);
1179 /* The statics+edits+buttons. */
1180 for (j
= 0; j
< 2; j
++) {
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
;
1190 r
.bottom
= (i
== 0 ? STATICHEIGHT
:
1191 i
== 1 ? EDITHEIGHT
: PUSHBTNHEIGHT
);
1192 r
.top
+= (height
- r
.bottom
) / 2;
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) {
1202 * We postpone creation of the button until we've
1203 * done everything else, since it belongs last in
1206 button_r
= r
; /* structure copy */
1209 cp
->ypos
+= height
+ GAPWITHIN
;
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
,