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 * An edit control on the right hand side, with a static to its left.
367 static void staticedit_internal(struct ctlpos *cp, char *stext,
368 int sid, int eid, int percentedit,
371 const int height = (EDITHEIGHT > STATICHEIGHT ?
372 EDITHEIGHT : STATICHEIGHT);
374 int lwid, rwid, rpos;
377 GAPBETWEEN + (100 - percentedit) * (cp->width + GAPBETWEEN) / 100;
378 lwid = rpos - 2 * GAPBETWEEN;
379 rwid = cp->width + GAPBETWEEN - rpos;
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 - EDITHEIGHT) / 2;
390 r.bottom = EDITHEIGHT;
392 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL | style,
393 WS_EX_CLIENTEDGE, "", eid);
395 cp->ypos += height + GAPBETWEEN;
398 void staticedit(struct ctlpos *cp, char *stext,
399 int sid, int eid, int percentedit)
401 staticedit_internal(cp, stext, sid, eid, percentedit, 0);
404 void staticpassedit(struct ctlpos *cp, char *stext,
405 int sid, int eid, int percentedit)
407 staticedit_internal(cp, stext, sid, eid, percentedit, ES_PASSWORD);
411 * A big multiline edit control with a static labelling it.
413 void bigeditctrl(struct ctlpos *cp, char *stext,
414 int sid, int eid, int lines)
421 r.bottom = STATICHEIGHT;
422 cp->ypos += r.bottom + GAPWITHIN;
423 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
428 r.bottom = EDITHEIGHT + (lines - 1) * STATICHEIGHT;
429 cp->ypos += r.bottom + GAPBETWEEN;
431 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE,
432 WS_EX_CLIENTEDGE, "", eid);
436 * A tab-control substitute when a real tab control is unavailable.
438 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id)
440 const int height = (COMBOHEIGHT > STATICHEIGHT ?
441 COMBOHEIGHT : STATICHEIGHT);
443 int bigwid, lwid, rwid, rpos;
444 static const int BIGGAP = 15;
445 static const int MEDGAP = 3;
447 bigwid = cp->width + 2 * GAPBETWEEN - 2 * BIGGAP;
449 rpos = BIGGAP + (bigwid + BIGGAP) / 2;
450 lwid = rpos - 2 * BIGGAP;
451 rwid = bigwid + BIGGAP - rpos;
454 r.top = cp->ypos + (height - STATICHEIGHT) / 2;
456 r.bottom = STATICHEIGHT;
457 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
460 r.top = cp->ypos + (height - COMBOHEIGHT) / 2;
462 r.bottom = COMBOHEIGHT * 10;
463 doctl(cp, r, "COMBOBOX",
464 WS_CHILD | WS_VISIBLE | WS_TABSTOP |
465 CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", lid);
467 cp->ypos += height + MEDGAP + GAPBETWEEN;
473 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ,
478 * A static line, followed by an edit control on the left hand side
479 * and a button on the right.
481 void editbutton(struct ctlpos *cp, char *stext, int sid,
482 int eid, char *btext, int bid)
484 const int height = (EDITHEIGHT > PUSHBTNHEIGHT ?
485 EDITHEIGHT : PUSHBTNHEIGHT);
487 int lwid, rwid, rpos;
492 r.bottom = STATICHEIGHT;
493 cp->ypos += r.bottom + GAPWITHIN;
494 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
496 rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
497 lwid = rpos - 2 * GAPBETWEEN;
498 rwid = cp->width + GAPBETWEEN - rpos;
501 r.top = cp->ypos + (height - EDITHEIGHT) / 2;
503 r.bottom = EDITHEIGHT;
505 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
506 WS_EX_CLIENTEDGE, "", eid);
509 r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2;
511 r.bottom = PUSHBTNHEIGHT;
512 doctl(cp, r, "BUTTON",
513 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
516 cp->ypos += height + GAPBETWEEN;
520 * Special control which was hard to describe generically: the
521 * session-saver assembly. A static; below that an edit box; below
522 * that a list box. To the right of the list box, a column of
525 void sesssaver(struct ctlpos *cp, char *text,
526 int staticid, int editid, int listid, ...)
530 int lwid, rwid, rpos;
532 const int LISTDEFHEIGHT = 66;
534 rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4;
535 lwid = rpos - 2 * GAPBETWEEN;
536 rwid = cp->width + GAPBETWEEN - rpos;
538 /* The static control. */
542 r.bottom = STATICHEIGHT;
543 cp->ypos += r.bottom + GAPWITHIN;
544 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, staticid);
546 /* The edit control. */
550 r.bottom = EDITHEIGHT;
551 cp->ypos += r.bottom + GAPWITHIN;
553 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
554 WS_EX_CLIENTEDGE, "", editid);
557 * The buttons (we should hold off on the list box until we
558 * know how big the buttons are).
560 va_start(ap, listid);
563 char *btext = va_arg(ap, char *);
567 bid = va_arg(ap, int);
571 r.bottom = PUSHBTNHEIGHT;
572 y += r.bottom + GAPWITHIN;
573 doctl(cp, r, "BUTTON",
574 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
578 /* Compute list box height. LISTDEFHEIGHT, or height of buttons. */
581 if (y < LISTDEFHEIGHT)
587 cp->ypos += y + GAPBETWEEN;
588 doctl(cp, r, "LISTBOX",
589 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL |
590 LBS_NOTIFY | LBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", listid);
594 * Another special control: the environment-variable setter. A
595 * static line first; then a pair of edit boxes with associated
596 * statics, and two buttons; then a list box.
598 void envsetter(struct ctlpos *cp, char *stext, int sid,
599 char *e1stext, int e1sid, int e1id,
600 char *e2stext, int e2sid, int e2id,
601 int listid, char *b1text, int b1id, char *b2text, int b2id)
604 const int height = (STATICHEIGHT > EDITHEIGHT
606 PUSHBTNHEIGHT ? STATICHEIGHT : EDITHEIGHT >
607 PUSHBTNHEIGHT ? EDITHEIGHT : PUSHBTNHEIGHT);
608 const static int percents[] = { 20, 35, 10, 25 };
609 int i, j, xpos, percent;
610 const int LISTHEIGHT = 42;
612 /* The static control. */
616 r.bottom = STATICHEIGHT;
617 cp->ypos += r.bottom + GAPWITHIN;
618 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
620 /* The statics+edits+buttons. */
621 for (j = 0; j < 2; j++) {
623 for (i = 0; i < 4; i++) {
624 xpos = (cp->width + GAPBETWEEN) * percent / 100;
625 r.left = xpos + GAPBETWEEN;
626 percent += percents[i];
627 xpos = (cp->width + GAPBETWEEN) * percent / 100;
628 r.right = xpos - r.left;
630 r.bottom = (i == 0 ? STATICHEIGHT :
631 i == 1 ? EDITHEIGHT : PUSHBTNHEIGHT);
632 r.top += (height - r.bottom) / 2;
634 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0,
635 j == 0 ? e1stext : e2stext, j == 0 ? e1sid : e2sid);
638 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
639 WS_EX_CLIENTEDGE, "", j == 0 ? e1id : e2id);
641 doctl(cp, r, "BUTTON",
642 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
643 0, j == 0 ? b1text : b2text, j == 0 ? b1id : b2id);
646 cp->ypos += height + GAPWITHIN;
653 r.bottom = LISTHEIGHT;
654 cp->ypos += r.bottom + GAPBETWEEN;
655 doctl(cp, r, "LISTBOX",
656 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
657 | LBS_USETABSTOPS, WS_EX_CLIENTEDGE, "", listid);
661 * Yet another special control: the character-class setter. A
662 * static, then a list, then a line containing a
663 * button-and-static-and-edit.
665 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
666 char *btext, int bid, int eid, char *s2text, int s2id)
669 const int height = (STATICHEIGHT > EDITHEIGHT
671 PUSHBTNHEIGHT ? STATICHEIGHT : EDITHEIGHT >
672 PUSHBTNHEIGHT ? EDITHEIGHT : PUSHBTNHEIGHT);
673 const static int percents[] = { 30, 40, 30 };
674 int i, xpos, percent;
675 const int LISTHEIGHT = 66;
677 /* The static control. */
681 r.bottom = STATICHEIGHT;
682 cp->ypos += r.bottom + GAPWITHIN;
683 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
689 r.bottom = LISTHEIGHT;
690 cp->ypos += r.bottom + GAPWITHIN;
691 doctl(cp, r, "LISTBOX",
692 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
693 | LBS_USETABSTOPS, WS_EX_CLIENTEDGE, "", listid);
695 /* The button+static+edit. */
697 for (i = 0; i < 3; i++) {
698 r.left = xpos + GAPBETWEEN;
699 percent += percents[i];
700 xpos = (cp->width + GAPBETWEEN) * percent / 100;
701 r.right = xpos - r.left;
703 r.bottom = (i == 0 ? PUSHBTNHEIGHT :
704 i == 1 ? STATICHEIGHT : EDITHEIGHT);
705 r.top += (height - r.bottom) / 2;
707 doctl(cp, r, "BUTTON",
708 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
711 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_CENTER,
715 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
716 WS_EX_CLIENTEDGE, "", eid);
719 cp->ypos += height + GAPBETWEEN;
723 * A special control (horrors!). The colour editor. A static line;
724 * then on the left, a list box, and on the right, a sequence of
725 * two-part statics followed by a button.
727 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
728 char *btext, int bid, ...)
733 int lwid, rwid, rpos;
734 const int LISTHEIGHT = 66;
736 /* The static control. */
740 r.bottom = STATICHEIGHT;
741 cp->ypos += r.bottom + GAPWITHIN;
742 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
744 rpos = GAPBETWEEN + 2 * (cp->width + GAPBETWEEN) / 3;
745 lwid = rpos - 2 * GAPBETWEEN;
746 rwid = cp->width + GAPBETWEEN - rpos;
752 r.bottom = LISTHEIGHT;
753 doctl(cp, r, "LISTBOX",
754 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
755 | LBS_USETABSTOPS | LBS_NOTIFY, WS_EX_CLIENTEDGE, "", listid);
763 ltext = va_arg(ap, char *);
766 lid = va_arg(ap, int);
767 rid = va_arg(ap, int);
769 r.bottom = STATICHEIGHT;
770 y += r.bottom + GAPWITHIN;
773 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, ltext, lid);
774 r.left = rpos + r.right;
775 r.right = rwid - r.right;
776 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0, "",
782 r.top = y + 2 * GAPWITHIN;
783 r.bottom = PUSHBTNHEIGHT;
786 doctl(cp, r, "BUTTON",
787 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
790 cp->ypos += LISTHEIGHT + GAPBETWEEN;
794 * A special control for manipulating an ordered preference list
795 * (eg. for cipher selection).
796 * XXX: this is a rough hack and could be improved.
798 void prefslist(struct prefslist *hdl, struct ctlpos *cp, char *stext,
799 int sid, int listid, int upbid, int dnbid)
801 const static int percents[] = { 5, 75, 20 };
803 int xpos, percent = 0, i;
804 const int DEFLISTHEIGHT = 52; /* XXX configurable? */
805 const int BTNSHEIGHT = 2*PUSHBTNHEIGHT + GAPBETWEEN;
808 /* Squirrel away IDs. */
809 hdl->listid = listid;
813 /* The static label. */
817 r.bottom = STATICHEIGHT;
818 cp->ypos += r.bottom + GAPWITHIN;
819 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
821 /* XXX it'd be nice to centre the buttons wrt the listbox
822 * but we'd have to find out how high the latter actually is. */
823 if (DEFLISTHEIGHT > BTNSHEIGHT) {
824 totalheight = DEFLISTHEIGHT;
826 totalheight = BTNSHEIGHT;
829 for (i=0; i<3; i++) {
831 xpos = (cp->width + GAPBETWEEN) * percent / 100;
832 left = xpos + GAPBETWEEN;
833 percent += percents[i];
834 xpos = (cp->width + GAPBETWEEN) * percent / 100;
839 /* The drag list box. */
840 r.left = left; r.right = wid;
841 r.top = cp->ypos; r.bottom = totalheight;
844 ctl = doctl(cp, r, "LISTBOX",
845 WS_CHILD | WS_VISIBLE | WS_TABSTOP |
846 WS_VSCROLL | LBS_HASSTRINGS,
854 /* The "Up" and "Down" buttons. */
855 /* XXX worry about accelerators if we have more than one
856 * prefslist on a panel */
857 r.left = left; r.right = wid;
858 r.top = cp->ypos; r.bottom = PUSHBTNHEIGHT;
859 doctl(cp, r, "BUTTON",
860 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
863 r.left = left; r.right = wid;
864 r.top = cp->ypos + PUSHBTNHEIGHT + GAPBETWEEN;
865 r.bottom = PUSHBTNHEIGHT;
866 doctl(cp, r, "BUTTON",
867 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
875 cp->ypos += totalheight + GAPBETWEEN;
880 * Helper function for prefslist: move item in list box.
882 static void pl_moveitem(HWND hwnd, int listid, int src, int dst)
886 /* Get the item's data. */
887 tlen = SendDlgItemMessage (hwnd, listid, LB_GETTEXTLEN, src, 0);
888 txt = smalloc(tlen+1);
889 SendDlgItemMessage (hwnd, listid, LB_GETTEXT, src, (LPARAM) txt);
890 val = SendDlgItemMessage (hwnd, listid, LB_GETITEMDATA, src, 0);
891 /* Deselect old location. */
892 SendDlgItemMessage (hwnd, listid, LB_SETSEL, FALSE, src);
893 /* Delete it at the old location. */
894 SendDlgItemMessage (hwnd, listid, LB_DELETESTRING, src, 0);
895 /* Insert it at new location. */
896 SendDlgItemMessage (hwnd, listid, LB_INSERTSTRING, dst,
898 SendDlgItemMessage (hwnd, listid, LB_SETITEMDATA, dst,
901 SendDlgItemMessage (hwnd, listid, LB_SETCURSEL, dst, 0);
905 int pl_itemfrompt(HWND hwnd, POINT cursor, BOOL scroll)
908 POINT uppoint, downpoint;
909 int updist, downdist, upitem, downitem, i;
912 * Ghastly hackery to try to figure out not which
913 * _item_, but which _gap between items_, the user
914 * is pointing at. We do this by first working out
915 * which list item is under the cursor, and then
916 * working out how far the cursor would have to
917 * move up or down before the answer was different.
918 * Then we put the insertion point _above_ the
919 * current item if the upper edge is closer than
920 * the lower edge, or _below_ it if vice versa.
922 ret = LBItemFromPt(hwnd, cursor, scroll);
925 ret = LBItemFromPt(hwnd, cursor, FALSE);
926 updist = downdist = 0;
927 for (i = 1; i < 4096 && (!updist || !downdist); i++) {
928 uppoint = downpoint = cursor;
931 upitem = LBItemFromPt(hwnd, uppoint, FALSE);
932 downitem = LBItemFromPt(hwnd, downpoint, FALSE);
933 if (!updist && upitem != ret)
935 if (!downdist && downitem != ret)
938 if (downdist < updist)
944 * Handler for prefslist above.
946 int handle_prefslist(struct prefslist *hdl,
947 int *array, int maxmemb,
948 int is_dlmsg, HWND hwnd,
949 WPARAM wParam, LPARAM lParam)
956 if (wParam == hdl->listid) {
957 DRAGLISTINFO *dlm = (DRAGLISTINFO *)lParam;
959 switch (dlm->uNotification) {
962 SendDlgItemMessage(hwnd, hdl->listid,
963 LB_ADDSTRING, 0, (LPARAM) "");
965 hdl->srcitem = LBItemFromPt(dlm->hWnd, dlm->ptCursor, TRUE);
967 /* XXX hack Q183115 */
968 SetWindowLong(hwnd, DWL_MSGRESULT, TRUE);
971 DrawInsert(hwnd, dlm->hWnd, -1); /* Clear arrow */
972 SendDlgItemMessage(hwnd, hdl->listid,
973 LB_DELETESTRING, hdl->dummyitem, 0);
978 dest = pl_itemfrompt(dlm->hWnd, dlm->ptCursor, TRUE);
979 if (dest > hdl->dummyitem) dest = hdl->dummyitem;
980 DrawInsert (hwnd, dlm->hWnd, dest);
982 SetWindowLong(hwnd, DWL_MSGRESULT, DL_MOVECURSOR);
984 SetWindowLong(hwnd, DWL_MSGRESULT, DL_STOPCURSOR);
988 if (!hdl->dragging) break;
989 dest = pl_itemfrompt(dlm->hWnd, dlm->ptCursor, TRUE);
990 if (dest > hdl->dummyitem) dest = hdl->dummyitem;
991 DrawInsert (hwnd, dlm->hWnd, -1);
992 SendDlgItemMessage(hwnd, hdl->listid,
993 LB_DELETESTRING, hdl->dummyitem, 0);
996 /* Correct for "missing" item. This means you can't drag
997 * an item to the end, but that seems to be the way this
998 * control is used. */
999 if (dest > hdl->srcitem) dest--;
1000 pl_moveitem(hwnd, hdl->listid, hdl->srcitem, dest);
1009 if (((LOWORD(wParam) == hdl->upbid) ||
1010 (LOWORD(wParam) == hdl->dnbid)) &&
1011 ((HIWORD(wParam) == BN_CLICKED) ||
1012 (HIWORD(wParam) == BN_DOUBLECLICKED))) {
1013 /* Move an item up or down the list. */
1014 /* Get the current selection, if any. */
1015 int selection = SendDlgItemMessage (hwnd, hdl->listid, LB_GETCURSEL, 0, 0);
1016 if (selection == LB_ERR) {
1020 /* Get the total number of items. */
1021 nitems = SendDlgItemMessage (hwnd, hdl->listid, LB_GETCOUNT, 0, 0);
1022 /* Should we do anything? */
1023 if (LOWORD(wParam) == hdl->upbid && (selection > 0))
1024 pl_moveitem(hwnd, hdl->listid, selection, selection - 1);
1025 else if (LOWORD(wParam) == hdl->dnbid && (selection < nitems - 1))
1026 pl_moveitem(hwnd, hdl->listid, selection, selection + 1);
1033 /* Update array to match the list box. */
1034 for (i=0; i < maxmemb; i++)
1035 array[i] = SendDlgItemMessage (hwnd, hdl->listid, LB_GETITEMDATA,
1043 * A progress bar (from Common Controls). We like our progress bars
1044 * to be smooth and unbroken, without those ugly divisions; some
1045 * older compilers may not support that, but that's life.
1047 void progressbar(struct ctlpos *cp, int id)
1051 r.left = GAPBETWEEN;
1053 r.right = cp->width;
1054 r.bottom = PROGBARHEIGHT;
1055 cp->ypos += r.bottom + GAPBETWEEN;
1057 doctl(cp, r, PROGRESS_CLASS, WS_CHILD | WS_VISIBLE
1061 , WS_EX_CLIENTEDGE, "", id);
1065 * Another special control: the forwarding options setter. First a
1066 * list box; next a static header line, introducing a pair of edit
1067 * boxes with associated statics, another button, and a radio
1070 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
1071 char *e1stext, int e1sid, int e1id,
1072 char *e2stext, int e2sid, int e2id,
1073 char *btext, int bid)
1076 const int height = (STATICHEIGHT > EDITHEIGHT
1078 PUSHBTNHEIGHT ? STATICHEIGHT : EDITHEIGHT >
1079 PUSHBTNHEIGHT ? EDITHEIGHT : PUSHBTNHEIGHT);
1080 const static int percents[] = { 25, 35, 15, 25 };
1081 int i, j, xpos, percent;
1082 const int LISTHEIGHT = 42;
1085 r.left = GAPBETWEEN;
1087 r.right = cp->width;
1088 r.bottom = LISTHEIGHT;
1089 cp->ypos += r.bottom + GAPBETWEEN;
1090 doctl(cp, r, "LISTBOX",
1091 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS
1092 | LBS_USETABSTOPS, WS_EX_CLIENTEDGE, "", listid);
1094 /* The static control. */
1095 r.left = GAPBETWEEN;
1097 r.right = cp->width;
1098 r.bottom = STATICHEIGHT;
1099 cp->ypos += r.bottom + GAPWITHIN;
1100 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid);
1102 /* The statics+edits+buttons. */
1103 for (j = 0; j < 2; j++) {
1105 for (i = 0; i < (j ? 2 : 4); i++) {
1106 xpos = (cp->width + GAPBETWEEN) * percent / 100;
1107 r.left = xpos + GAPBETWEEN;
1108 percent += percents[i];
1109 if (j==1 && i==1) percent = 100;
1110 xpos = (cp->width + GAPBETWEEN) * percent / 100;
1111 r.right = xpos - r.left;
1113 r.bottom = (i == 0 ? STATICHEIGHT :
1114 i == 1 ? EDITHEIGHT : PUSHBTNHEIGHT);
1115 r.top += (height - r.bottom) / 2;
1117 doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0,
1118 j == 0 ? e1stext : e2stext, j == 0 ? e1sid : e2sid);
1119 } else if (i == 1) {
1120 doctl(cp, r, "EDIT",
1121 WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
1122 WS_EX_CLIENTEDGE, "", j == 0 ? e1id : e2id);
1123 } else if (i == 3) {
1124 doctl(cp, r, "BUTTON",
1125 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
1129 cp->ypos += height + GAPWITHIN;