8c3cd914 |
1 | /* |
2 | * winctrls.c: routines to self-manage the controls in a dialog |
3 | * box. |
4 | */ |
5 | |
6 | #include <windows.h> |
6e522441 |
7 | #include <commctrl.h> |
8c3cd914 |
8 | |
9 | #include "winstuff.h" |
10 | |
11 | #define GAPBETWEEN 3 |
12 | #define GAPWITHIN 1 |
13 | #define GAPXBOX 7 |
14 | #define GAPYBOX 4 |
15 | #define DLGWIDTH 168 |
16 | #define STATICHEIGHT 8 |
17 | #define CHECKBOXHEIGHT 8 |
18 | #define RADIOHEIGHT 8 |
19 | #define EDITHEIGHT 12 |
20 | #define COMBOHEIGHT 12 |
21 | #define PUSHBTNHEIGHT 14 |
6e522441 |
22 | #define PROGBARHEIGHT 14 |
8c3cd914 |
23 | |
24 | void ctlposinit(struct ctlpos *cp, HWND hwnd, |
25 | int leftborder, int rightborder, int topborder) { |
26 | RECT r, r2; |
27 | cp->hwnd = hwnd; |
28 | cp->font = SendMessage(hwnd, WM_GETFONT, 0, 0); |
29 | cp->ypos = topborder; |
30 | GetClientRect(hwnd, &r); |
31 | r2.left = r2.top = 0; |
32 | r2.right = 4; |
33 | r2.bottom = 8; |
34 | MapDialogRect(hwnd, &r2); |
35 | cp->dlu4inpix = r2.right; |
36 | cp->width = (r.right * 4) / (r2.right) - 2*GAPBETWEEN; |
37 | cp->xoff = leftborder; |
38 | cp->width -= leftborder + rightborder; |
39 | } |
40 | |
41 | void doctl(struct ctlpos *cp, RECT r, |
42 | char *wclass, int wstyle, int exstyle, |
43 | char *wtext, int wid) { |
44 | HWND ctl; |
45 | /* |
46 | * Note nonstandard use of RECT. This is deliberate: by |
47 | * transforming the width and height directly we arrange to |
48 | * have all supposedly same-sized controls really same-sized. |
49 | */ |
50 | |
51 | r.left += cp->xoff; |
52 | MapDialogRect(cp->hwnd, &r); |
53 | |
54 | ctl = CreateWindowEx(exstyle, wclass, wtext, wstyle, |
55 | r.left, r.top, r.right, r.bottom, |
56 | cp->hwnd, (HMENU)wid, hinst, NULL); |
57 | SendMessage(ctl, WM_SETFONT, cp->font, MAKELPARAM(TRUE, 0)); |
58 | } |
59 | |
60 | /* |
61 | * A title bar across the top of a sub-dialog. |
62 | */ |
63 | void bartitle(struct ctlpos *cp, char *name, int id) { |
64 | RECT r; |
65 | |
66 | r.left = GAPBETWEEN; r.right = cp->width; |
67 | r.top = cp->ypos; r.bottom = STATICHEIGHT; |
68 | cp->ypos += r.bottom + GAPBETWEEN; |
69 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, name, id); |
70 | } |
71 | |
72 | /* |
73 | * Begin a grouping box, with or without a group title. |
74 | */ |
3ac9cd9f |
75 | void beginbox(struct ctlpos *cp, char *name, int idbox) { |
8c3cd914 |
76 | cp->boxystart = cp->ypos; |
3ac9cd9f |
77 | if (!name) |
78 | cp->boxystart -= STATICHEIGHT/2; |
8c3cd914 |
79 | if (name) |
3ac9cd9f |
80 | cp->ypos += STATICHEIGHT; |
8c3cd914 |
81 | cp->ypos += GAPYBOX; |
82 | cp->width -= 2*GAPXBOX; |
83 | cp->xoff += GAPXBOX; |
84 | cp->boxid = idbox; |
8c3cd914 |
85 | cp->boxtext = name; |
86 | } |
87 | |
88 | /* |
89 | * End a grouping box. |
90 | */ |
91 | void endbox(struct ctlpos *cp) { |
92 | RECT r; |
93 | cp->xoff -= GAPXBOX; |
94 | cp->width += 2*GAPXBOX; |
95 | cp->ypos += GAPYBOX - GAPBETWEEN; |
96 | r.left = GAPBETWEEN; r.right = cp->width; |
97 | r.top = cp->boxystart; r.bottom = cp->ypos - cp->boxystart; |
3ac9cd9f |
98 | doctl(cp, r, "BUTTON", BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 0, |
99 | cp->boxtext ? cp->boxtext : "", cp->boxid); |
8c3cd914 |
100 | cp->ypos += GAPYBOX; |
101 | } |
102 | |
103 | /* |
104 | * Some edit boxes. Each one has a static above it. The percentages |
105 | * of the horizontal space are provided. |
106 | */ |
107 | void multiedit(struct ctlpos *cp, ...) { |
108 | RECT r; |
109 | va_list ap; |
110 | int percent, xpos; |
111 | |
112 | percent = xpos = 0; |
113 | va_start(ap, cp); |
114 | while (1) { |
115 | char *text; |
116 | int staticid, editid, pcwidth; |
117 | text = va_arg(ap, char *); |
118 | if (!text) |
119 | break; |
120 | staticid = va_arg(ap, int); |
121 | editid = va_arg(ap, int); |
122 | pcwidth = va_arg(ap, int); |
123 | |
124 | r.left = xpos + GAPBETWEEN; |
125 | percent += pcwidth; |
126 | xpos = (cp->width + GAPBETWEEN) * percent / 100; |
127 | r.right = xpos - r.left; |
128 | |
129 | r.top = cp->ypos; r.bottom = STATICHEIGHT; |
130 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, |
131 | text, staticid); |
132 | r.top = cp->ypos + 8 + GAPWITHIN; r.bottom = EDITHEIGHT; |
133 | doctl(cp, r, "EDIT", |
134 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, |
135 | WS_EX_CLIENTEDGE, |
136 | "", editid); |
137 | } |
138 | va_end(ap); |
139 | cp->ypos += 8+GAPWITHIN+12+GAPBETWEEN; |
140 | } |
141 | |
142 | /* |
143 | * A set of radio buttons on the same line, with a static above |
144 | * them. `nacross' dictates how many parts the line is divided into |
145 | * (you might want this not to equal the number of buttons if you |
146 | * needed to line up some 2s and some 3s to look good in the same |
147 | * panel). |
1cd48051 |
148 | * |
149 | * There's a bit of a hack in here to ensure that if nacross |
150 | * exceeds the actual number of buttons, the rightmost button |
151 | * really does get all the space right to the edge of the line, so |
152 | * you can do things like |
153 | * |
154 | * (*) Button1 (*) Button2 (*) ButtonWithReallyLongTitle |
8c3cd914 |
155 | */ |
156 | void radioline(struct ctlpos *cp, |
157 | char *text, int id, int nacross, ...) { |
158 | RECT r; |
159 | va_list ap; |
160 | int group; |
161 | int i; |
1cd48051 |
162 | char *btext; |
8c3cd914 |
163 | |
164 | r.left = GAPBETWEEN; r.top = cp->ypos; |
165 | r.right = cp->width; r.bottom = STATICHEIGHT; |
166 | cp->ypos += r.bottom + GAPWITHIN; |
167 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id); |
168 | va_start(ap, nacross); |
169 | group = WS_GROUP; |
170 | i = 0; |
1cd48051 |
171 | btext = va_arg(ap, char *); |
8c3cd914 |
172 | while (1) { |
1cd48051 |
173 | char *nextbtext; |
8c3cd914 |
174 | int bid; |
8c3cd914 |
175 | if (!btext) |
176 | break; |
f37caa11 |
177 | if (i==nacross) { |
178 | cp->ypos += r.bottom + GAPBETWEEN; |
179 | i=0; |
180 | } |
8c3cd914 |
181 | bid = va_arg(ap, int); |
1cd48051 |
182 | nextbtext = va_arg(ap, char *); |
8c3cd914 |
183 | r.left = GAPBETWEEN + i * (cp->width+GAPBETWEEN)/nacross; |
1cd48051 |
184 | if (nextbtext) |
185 | r.right = (i+1) * (cp->width+GAPBETWEEN)/nacross - r.left; |
186 | else |
187 | r.right = cp->width - r.left; |
8c3cd914 |
188 | r.top = cp->ypos; r.bottom = RADIOHEIGHT; |
189 | doctl(cp, r, "BUTTON", |
190 | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP | group, |
191 | 0, |
192 | btext, bid); |
193 | group = 0; |
194 | i++; |
1cd48051 |
195 | btext = nextbtext; |
8c3cd914 |
196 | } |
197 | va_end(ap); |
198 | cp->ypos += r.bottom + GAPBETWEEN; |
199 | } |
200 | |
201 | /* |
202 | * A set of radio buttons on multiple lines, with a static above |
203 | * them. |
204 | */ |
205 | void radiobig(struct ctlpos *cp, char *text, int id, ...) { |
206 | RECT r; |
207 | va_list ap; |
208 | int group; |
209 | |
210 | r.left = GAPBETWEEN; r.top = cp->ypos; |
211 | r.right = cp->width; r.bottom = STATICHEIGHT; |
212 | cp->ypos += r.bottom + GAPWITHIN; |
213 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id); |
214 | va_start(ap, id); |
215 | group = WS_GROUP; |
216 | while (1) { |
217 | char *btext; |
218 | int bid; |
219 | btext = va_arg(ap, char *); |
220 | if (!btext) |
221 | break; |
222 | bid = va_arg(ap, int); |
223 | r.left = GAPBETWEEN; r.top = cp->ypos; |
224 | r.right = cp->width; r.bottom = STATICHEIGHT; |
225 | cp->ypos += r.bottom + GAPWITHIN; |
226 | doctl(cp, r, "BUTTON", |
227 | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP | group, |
228 | 0, |
229 | btext, bid); |
230 | group = 0; |
231 | } |
232 | va_end(ap); |
233 | cp->ypos += GAPBETWEEN - GAPWITHIN; |
234 | } |
235 | |
236 | /* |
237 | * A single standalone checkbox. |
238 | */ |
239 | void checkbox(struct ctlpos *cp, char *text, int id) { |
240 | RECT r; |
241 | |
242 | r.left = GAPBETWEEN; r.top = cp->ypos; |
243 | r.right = cp->width; r.bottom = CHECKBOXHEIGHT; |
244 | cp->ypos += r.bottom + GAPBETWEEN; |
245 | doctl(cp, r, "BUTTON", |
246 | BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, |
247 | text, id); |
248 | } |
249 | |
250 | /* |
6e522441 |
251 | * A single standalone static text control. |
252 | */ |
253 | void statictext(struct ctlpos *cp, char *text, int id) { |
254 | RECT r; |
255 | |
256 | r.left = GAPBETWEEN; r.top = cp->ypos; |
257 | r.right = cp->width; r.bottom = STATICHEIGHT; |
258 | cp->ypos += r.bottom + GAPBETWEEN; |
259 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, id); |
260 | } |
261 | |
262 | /* |
8c3cd914 |
263 | * A button on the right hand side, with a static to its left. |
264 | */ |
265 | void staticbtn(struct ctlpos *cp, char *stext, int sid, |
266 | char *btext, int bid) { |
267 | const int height = (PUSHBTNHEIGHT > STATICHEIGHT ? |
268 | PUSHBTNHEIGHT : STATICHEIGHT); |
269 | RECT r; |
270 | int lwid, rwid, rpos; |
271 | |
272 | rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4; |
273 | lwid = rpos - 2*GAPBETWEEN; |
274 | rwid = cp->width + GAPBETWEEN - rpos; |
275 | |
276 | r.left = GAPBETWEEN; r.top = cp->ypos + (height-STATICHEIGHT)/2; |
277 | r.right = lwid; r.bottom = STATICHEIGHT; |
278 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
279 | |
280 | r.left = rpos; r.top = cp->ypos + (height-PUSHBTNHEIGHT)/2; |
281 | r.right = rwid; r.bottom = PUSHBTNHEIGHT; |
282 | doctl(cp, r, "BUTTON", |
283 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, |
284 | 0, |
285 | btext, bid); |
286 | |
287 | cp->ypos += height + GAPBETWEEN; |
288 | } |
289 | |
290 | /* |
291 | * An edit control on the right hand side, with a static to its left. |
292 | */ |
6e522441 |
293 | static void staticedit_internal(struct ctlpos *cp, char *stext, |
294 | int sid, int eid, int percentedit, |
295 | int style) { |
8c3cd914 |
296 | const int height = (EDITHEIGHT > STATICHEIGHT ? |
297 | EDITHEIGHT : STATICHEIGHT); |
298 | RECT r; |
299 | int lwid, rwid, rpos; |
300 | |
301 | rpos = GAPBETWEEN + (100-percentedit) * (cp->width + GAPBETWEEN) / 100; |
302 | lwid = rpos - 2*GAPBETWEEN; |
303 | rwid = cp->width + GAPBETWEEN - rpos; |
304 | |
305 | r.left = GAPBETWEEN; r.top = cp->ypos + (height-STATICHEIGHT)/2; |
306 | r.right = lwid; r.bottom = STATICHEIGHT; |
307 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
308 | |
309 | r.left = rpos; r.top = cp->ypos + (height-EDITHEIGHT)/2; |
310 | r.right = rwid; r.bottom = EDITHEIGHT; |
311 | doctl(cp, r, "EDIT", |
6e522441 |
312 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL | style, |
8c3cd914 |
313 | WS_EX_CLIENTEDGE, |
314 | "", eid); |
315 | |
316 | cp->ypos += height + GAPBETWEEN; |
317 | } |
318 | |
6e522441 |
319 | void staticedit(struct ctlpos *cp, char *stext, |
320 | int sid, int eid, int percentedit) { |
321 | staticedit_internal(cp, stext, sid, eid, percentedit, 0); |
322 | } |
323 | |
324 | void staticpassedit(struct ctlpos *cp, char *stext, |
325 | int sid, int eid, int percentedit) { |
326 | staticedit_internal(cp, stext, sid, eid, percentedit, ES_PASSWORD); |
327 | } |
328 | |
329 | /* |
330 | * A big multiline edit control with a static labelling it. |
331 | */ |
332 | void bigeditctrl(struct ctlpos *cp, char *stext, |
333 | int sid, int eid, int lines) { |
334 | RECT r; |
335 | |
336 | r.left = GAPBETWEEN; r.top = cp->ypos; |
337 | r.right = cp->width; r.bottom = STATICHEIGHT; |
338 | cp->ypos += r.bottom + GAPWITHIN; |
339 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
340 | |
341 | r.left = GAPBETWEEN; r.top = cp->ypos; |
342 | r.right = cp->width; r.bottom = EDITHEIGHT + (lines-1) * STATICHEIGHT; |
343 | cp->ypos += r.bottom + GAPBETWEEN; |
344 | doctl(cp, r, "EDIT", |
0c2986d0 |
345 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE, |
6e522441 |
346 | WS_EX_CLIENTEDGE, |
347 | "", eid); |
348 | } |
349 | |
8c3cd914 |
350 | /* |
351 | * A tab-control substitute when a real tab control is unavailable. |
352 | */ |
353 | void ersatztab(struct ctlpos *cp, char *stext, int sid, |
354 | int lid, int s2id) { |
355 | const int height = (COMBOHEIGHT > STATICHEIGHT ? |
356 | COMBOHEIGHT : STATICHEIGHT); |
357 | RECT r; |
358 | int bigwid, lwid, rwid, rpos; |
359 | static const int BIGGAP = 15; |
360 | static const int MEDGAP = 3; |
361 | |
362 | bigwid = cp->width + 2*GAPBETWEEN - 2*BIGGAP; |
363 | cp->ypos += MEDGAP; |
364 | rpos = BIGGAP + (bigwid + BIGGAP) / 2; |
365 | lwid = rpos - 2*BIGGAP; |
366 | rwid = bigwid + BIGGAP - rpos; |
367 | |
368 | r.left = BIGGAP; r.top = cp->ypos + (height-STATICHEIGHT)/2; |
369 | r.right = lwid; r.bottom = STATICHEIGHT; |
370 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
371 | |
372 | r.left = rpos; r.top = cp->ypos + (height-COMBOHEIGHT)/2; |
373 | r.right = rwid; r.bottom = COMBOHEIGHT*10; |
374 | doctl(cp, r, "COMBOBOX", |
375 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | |
376 | CBS_DROPDOWNLIST | CBS_HASSTRINGS, |
377 | WS_EX_CLIENTEDGE, |
378 | "", lid); |
379 | |
380 | cp->ypos += height + MEDGAP + GAPBETWEEN; |
381 | |
382 | r.left = GAPBETWEEN; r.top = cp->ypos; |
383 | r.right = cp->width; r.bottom = 2; |
384 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, |
385 | 0, "", s2id); |
386 | } |
387 | |
388 | /* |
389 | * A static line, followed by an edit control on the left hand side |
390 | * and a button on the right. |
391 | */ |
392 | void editbutton(struct ctlpos *cp, char *stext, int sid, |
393 | int eid, char *btext, int bid) { |
394 | const int height = (EDITHEIGHT > PUSHBTNHEIGHT ? |
395 | EDITHEIGHT : PUSHBTNHEIGHT); |
396 | RECT r; |
397 | int lwid, rwid, rpos; |
398 | |
399 | r.left = GAPBETWEEN; r.top = cp->ypos; |
400 | r.right = cp->width; r.bottom = STATICHEIGHT; |
401 | cp->ypos += r.bottom + GAPWITHIN; |
402 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
403 | |
404 | rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4; |
405 | lwid = rpos - 2*GAPBETWEEN; |
406 | rwid = cp->width + GAPBETWEEN - rpos; |
407 | |
408 | r.left = GAPBETWEEN; r.top = cp->ypos + (height-EDITHEIGHT)/2; |
409 | r.right = lwid; r.bottom = EDITHEIGHT; |
410 | doctl(cp, r, "EDIT", |
411 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, |
412 | WS_EX_CLIENTEDGE, |
413 | "", eid); |
414 | |
415 | r.left = rpos; r.top = cp->ypos + (height-PUSHBTNHEIGHT)/2; |
416 | r.right = rwid; r.bottom = PUSHBTNHEIGHT; |
417 | doctl(cp, r, "BUTTON", |
418 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, |
419 | 0, |
420 | btext, bid); |
421 | |
422 | cp->ypos += height + GAPBETWEEN; |
423 | } |
424 | |
425 | /* |
426 | * Special control which was hard to describe generically: the |
427 | * session-saver assembly. A static; below that an edit box; below |
428 | * that a list box. To the right of the list box, a column of |
429 | * buttons. |
430 | */ |
431 | void sesssaver(struct ctlpos *cp, char *text, |
432 | int staticid, int editid, int listid, ...) { |
433 | RECT r; |
434 | va_list ap; |
435 | int lwid, rwid, rpos; |
436 | int y; |
437 | const int LISTDEFHEIGHT = 66; |
438 | |
439 | rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4; |
440 | lwid = rpos - 2*GAPBETWEEN; |
441 | rwid = cp->width + GAPBETWEEN - rpos; |
442 | |
443 | /* The static control. */ |
444 | r.left = GAPBETWEEN; r.top = cp->ypos; |
445 | r.right = lwid; r.bottom = STATICHEIGHT; |
446 | cp->ypos += r.bottom + GAPWITHIN; |
447 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, text, staticid); |
448 | |
449 | /* The edit control. */ |
450 | r.left = GAPBETWEEN; r.top = cp->ypos; |
451 | r.right = lwid; r.bottom = EDITHEIGHT; |
452 | cp->ypos += r.bottom + GAPWITHIN; |
453 | doctl(cp, r, "EDIT", |
454 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, |
455 | WS_EX_CLIENTEDGE, |
456 | "", editid); |
457 | |
458 | /* |
459 | * The buttons (we should hold off on the list box until we |
460 | * know how big the buttons are). |
461 | */ |
462 | va_start(ap, listid); |
463 | y = cp->ypos; |
464 | while (1) { |
465 | char *btext = va_arg(ap, char *); |
466 | int bid; |
467 | if (!btext) break; |
468 | bid = va_arg(ap, int); |
469 | r.left = rpos; r.top = y; |
470 | r.right = rwid; r.bottom = PUSHBTNHEIGHT; |
471 | y += r.bottom + GAPWITHIN; |
472 | doctl(cp, r, "BUTTON", |
473 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, |
474 | 0, |
475 | btext, bid); |
476 | } |
477 | |
478 | /* Compute list box height. LISTDEFHEIGHT, or height of buttons. */ |
479 | y -= cp->ypos; |
480 | y -= GAPWITHIN; |
481 | if (y < LISTDEFHEIGHT) y = LISTDEFHEIGHT; |
482 | r.left = GAPBETWEEN; r.top = cp->ypos; |
483 | r.right = lwid; r.bottom = y; |
484 | cp->ypos += y + GAPBETWEEN; |
485 | doctl(cp, r, "LISTBOX", |
486 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | |
487 | LBS_NOTIFY | LBS_HASSTRINGS, |
488 | WS_EX_CLIENTEDGE, |
489 | "", listid); |
490 | } |
491 | |
492 | /* |
493 | * Another special control: the environment-variable setter. A |
494 | * static line first; then a pair of edit boxes with associated |
495 | * statics, and two buttons; then a list box. |
496 | */ |
497 | void envsetter(struct ctlpos *cp, char *stext, int sid, |
498 | char *e1stext, int e1sid, int e1id, |
499 | char *e2stext, int e2sid, int e2id, |
500 | int listid, |
501 | char *b1text, int b1id, char *b2text, int b2id) { |
502 | RECT r; |
503 | const int height = (STATICHEIGHT > EDITHEIGHT && STATICHEIGHT > PUSHBTNHEIGHT ? |
504 | STATICHEIGHT : |
505 | EDITHEIGHT > PUSHBTNHEIGHT ? |
506 | EDITHEIGHT : PUSHBTNHEIGHT); |
507 | const static int percents[] = { 20, 35, 10, 25 }; |
508 | int i, j, xpos, percent; |
509 | const int LISTHEIGHT = 42; |
510 | |
511 | /* The static control. */ |
512 | r.left = GAPBETWEEN; r.top = cp->ypos; |
513 | r.right = cp->width; r.bottom = STATICHEIGHT; |
514 | cp->ypos += r.bottom + GAPWITHIN; |
515 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
516 | |
517 | /* The statics+edits+buttons. */ |
518 | for (j = 0; j < 2; j++) { |
519 | percent = 10; |
520 | for (i = 0; i < 4; i++) { |
521 | xpos = (cp->width + GAPBETWEEN) * percent / 100; |
522 | r.left = xpos + GAPBETWEEN; |
523 | percent += percents[i]; |
524 | xpos = (cp->width + GAPBETWEEN) * percent / 100; |
525 | r.right = xpos - r.left; |
526 | r.top = cp->ypos; |
527 | r.bottom = (i==0 ? STATICHEIGHT : |
528 | i==1 ? EDITHEIGHT : |
529 | PUSHBTNHEIGHT); |
530 | r.top += (height-r.bottom)/2; |
531 | if (i==0) { |
532 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, |
533 | j==0 ? e1stext : e2stext, j==0 ? e1sid : e2sid); |
534 | } else if (i==1) { |
535 | doctl(cp, r, "EDIT", |
536 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, |
537 | WS_EX_CLIENTEDGE, |
538 | "", j==0 ? e1id : e2id); |
539 | } else if (i==3) { |
540 | doctl(cp, r, "BUTTON", |
541 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, |
542 | 0, |
543 | j==0 ? b1text : b2text, j==0 ? b1id : b2id); |
544 | } |
545 | } |
546 | cp->ypos += height + GAPWITHIN; |
547 | } |
548 | |
549 | /* The list box. */ |
550 | r.left = GAPBETWEEN; r.top = cp->ypos; |
551 | r.right = cp->width; r.bottom = LISTHEIGHT; |
552 | cp->ypos += r.bottom + GAPBETWEEN; |
553 | doctl(cp, r, "LISTBOX", |
554 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS | |
555 | LBS_USETABSTOPS, |
556 | WS_EX_CLIENTEDGE, |
557 | "", listid); |
558 | } |
559 | |
560 | /* |
561 | * Yet another special control: the character-class setter. A |
562 | * static, then a list, then a line containing a |
563 | * button-and-static-and-edit. |
564 | */ |
565 | void charclass(struct ctlpos *cp, char *stext, int sid, int listid, |
566 | char *btext, int bid, int eid, char *s2text, int s2id) { |
567 | RECT r; |
568 | const int height = (STATICHEIGHT > EDITHEIGHT && STATICHEIGHT > PUSHBTNHEIGHT ? |
569 | STATICHEIGHT : |
570 | EDITHEIGHT > PUSHBTNHEIGHT ? |
571 | EDITHEIGHT : PUSHBTNHEIGHT); |
572 | const static int percents[] = { 30, 40, 30 }; |
573 | int i, xpos, percent; |
574 | const int LISTHEIGHT = 66; |
575 | |
576 | /* The static control. */ |
577 | r.left = GAPBETWEEN; r.top = cp->ypos; |
578 | r.right = cp->width; r.bottom = STATICHEIGHT; |
579 | cp->ypos += r.bottom + GAPWITHIN; |
580 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
581 | |
582 | /* The list box. */ |
583 | r.left = GAPBETWEEN; r.top = cp->ypos; |
584 | r.right = cp->width; r.bottom = LISTHEIGHT; |
585 | cp->ypos += r.bottom + GAPWITHIN; |
586 | doctl(cp, r, "LISTBOX", |
587 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS | |
588 | LBS_USETABSTOPS, |
589 | WS_EX_CLIENTEDGE, |
590 | "", listid); |
591 | |
592 | /* The button+static+edit. */ |
593 | percent = xpos = 0; |
594 | for (i = 0; i < 3; i++) { |
595 | r.left = xpos + GAPBETWEEN; |
596 | percent += percents[i]; |
597 | xpos = (cp->width + GAPBETWEEN) * percent / 100; |
598 | r.right = xpos - r.left; |
599 | r.top = cp->ypos; |
600 | r.bottom = (i==0 ? PUSHBTNHEIGHT : |
601 | i==1 ? STATICHEIGHT : |
602 | EDITHEIGHT); |
603 | r.top += (height-r.bottom)/2; |
604 | if (i==0) { |
605 | doctl(cp, r, "BUTTON", |
606 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, |
607 | 0, btext, bid); |
608 | } else if (i==1) { |
609 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_CENTER, |
610 | 0, s2text, s2id); |
611 | } else if (i==2) { |
612 | doctl(cp, r, "EDIT", |
613 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, |
614 | WS_EX_CLIENTEDGE, "", eid); |
615 | } |
616 | } |
617 | cp->ypos += height + GAPBETWEEN; |
618 | } |
619 | |
620 | /* |
621 | * A special control (horrors!). The colour editor. A static line; |
622 | * then on the left, a list box, and on the right, a sequence of |
623 | * two-part statics followed by a button. |
624 | */ |
625 | void colouredit(struct ctlpos *cp, char *stext, int sid, int listid, |
626 | char *btext, int bid, ...) { |
627 | RECT r; |
628 | int y; |
629 | va_list ap; |
630 | int lwid, rwid, rpos; |
631 | const int LISTHEIGHT = 66; |
632 | |
633 | /* The static control. */ |
634 | r.left = GAPBETWEEN; r.top = cp->ypos; |
635 | r.right = cp->width; r.bottom = STATICHEIGHT; |
636 | cp->ypos += r.bottom + GAPWITHIN; |
637 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); |
638 | |
639 | rpos = GAPBETWEEN + 2 * (cp->width + GAPBETWEEN) / 3; |
640 | lwid = rpos - 2*GAPBETWEEN; |
641 | rwid = cp->width + GAPBETWEEN - rpos; |
642 | |
643 | /* The list box. */ |
644 | r.left = GAPBETWEEN; r.top = cp->ypos; |
645 | r.right = lwid; r.bottom = LISTHEIGHT; |
646 | doctl(cp, r, "LISTBOX", |
647 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_HASSTRINGS | |
b5333d89 |
648 | LBS_USETABSTOPS | LBS_NOTIFY, |
8c3cd914 |
649 | WS_EX_CLIENTEDGE, |
650 | "", listid); |
651 | |
652 | /* The statics. */ |
653 | y = cp->ypos; |
654 | va_start(ap, bid); |
655 | while (1) { |
656 | char *ltext; |
657 | int lid, rid; |
658 | ltext = va_arg(ap, char *); |
659 | if (!ltext) break; |
660 | lid = va_arg(ap, int); |
661 | rid = va_arg(ap, int); |
662 | r.top = y; r.bottom = STATICHEIGHT; |
663 | y += r.bottom + GAPWITHIN; |
664 | r.left = rpos; r.right = rwid/2; |
665 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, ltext, lid); |
666 | r.left = rpos + r.right; r.right = rwid - r.right; |
667 | doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0, "", rid); |
668 | } |
669 | va_end(ap); |
670 | |
671 | /* The button. */ |
672 | r.top = y + 2*GAPWITHIN; r.bottom = PUSHBTNHEIGHT; |
673 | r.left = rpos; r.right = rwid; |
674 | doctl(cp, r, "BUTTON", |
675 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, |
676 | 0, btext, bid); |
677 | |
678 | cp->ypos += LISTHEIGHT + GAPBETWEEN; |
679 | } |
680 | |
6e522441 |
681 | /* |
682 | * A progress bar (from Common Controls). We like our progress bars |
683 | * to be smooth and unbroken, without those ugly divisions; some |
684 | * older compilers may not support that, but that's life. |
685 | */ |
686 | void progressbar(struct ctlpos *cp, int id) { |
687 | RECT r; |
688 | |
689 | r.left = GAPBETWEEN; r.top = cp->ypos; |
690 | r.right = cp->width; r.bottom = PROGBARHEIGHT; |
691 | cp->ypos += r.bottom + GAPBETWEEN; |
692 | |
693 | doctl(cp, r, PROGRESS_CLASS, |
694 | WS_CHILD | WS_VISIBLE |
695 | #ifdef PBS_SMOOTH |
696 | | PBS_SMOOTH |
697 | #endif |
698 | , WS_EX_CLIENTEDGE, "", id); |
699 | } |