source: trunk/src/helpers/dialog.c@ 123

Last change on this file since 123 was 123, checked in by umoeller, 24 years ago

Lots of changes for icons and refresh.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 96.1 KB
Line 
1
2/*
3 *@@sourcefile dialog.c:
4 * contains PM helper functions to create and
5 * auto-format dialogs from control arrays in memory.
6 *
7 * See dlghCreateDlg for details.
8 *
9 * In addition, this has dlghMessageBox (a WinMessageBox
10 * replacement) and some helper functions for simulating
11 * dialog behavior in regular window procs (see
12 * dlghSetPrevFocus and others).
13 *
14 * Usage: All PM programs.
15 *
16 * Function prefixes (new with V0.81):
17 * -- dlg* Dialog functions
18 *
19 * Note: Version numbering in this file relates to XWorkplace version
20 * numbering.
21 *
22 *@@added V0.9.9 (2001-04-01) [umoeller]
23 *@@header "helpers\dialog.h"
24 */
25
26/*
27 * Copyright (C) 2001 Ulrich M”ller.
28 * This file is part of the "XWorkplace helpers" source package.
29 * This is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published
31 * by the Free Software Foundation, in version 2 as it comes in the
32 * "COPYING" file of the XWorkplace main distribution.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 */
38
39#define OS2EMX_PLAIN_CHAR
40 // this is needed for "os2emx.h"; if this is defined,
41 // emx will define PSZ as _signed_ char, otherwise
42 // as unsigned char
43
44#define INCL_DOSERRORS
45
46#define INCL_WINWINDOWMGR
47#define INCL_WINFRAMEMGR
48#define INCL_WINDIALOGS
49#define INCL_WININPUT
50#define INCL_WINSTATICS
51#define INCL_WINBUTTONS
52#define INCL_WINENTRYFIELDS
53#define INCL_WINSYS
54
55#define INCL_GPIPRIMITIVES
56#define INCL_GPIBITMAPS
57#define INCL_GPILCIDS
58#include <os2.h>
59
60#include <stdlib.h>
61#include <string.h>
62#include <stdio.h>
63
64#include "setup.h" // code generation and debugging options
65
66#include "helpers\comctl.h"
67#include "helpers\dialog.h"
68#include "helpers\gpih.h"
69#include "helpers\linklist.h"
70#include "helpers\standards.h"
71#include "helpers\stringh.h"
72#include "helpers\winh.h"
73#include "helpers\xstring.h"
74
75/*
76 *@@category: Helpers\PM helpers\Dialog templates
77 */
78
79/* ******************************************************************
80 *
81 * Private declarations
82 *
83 ********************************************************************/
84
85/*
86 *@@ DLGPRIVATE:
87 * private data to the dlg manager, allocated
88 * by dlghCreateDlg.
89 *
90 * This only exists while the dialog is being
91 * created and is not stored with the new dialog.
92 */
93
94typedef struct _DLGPRIVATE
95{
96 // public data
97 HWND hwndDlg;
98
99 // definition data (private)
100 LINKLIST llTables;
101
102 HWND hwndFirstFocus,
103 hwndDefPushbutton; // V0.9.14 (2001-08-21) [umoeller]
104
105 POINTL ptlTotalOfs;
106
107 LINKLIST llControls; // linked list of all PCOLUMNDEF structs,
108 // in the order in which windows were
109 // created
110
111 const char *pcszControlsFont; // from dlghCreateDlg
112
113 // V0.9.14 (2001-08-01) [umoeller]
114 HPS hps;
115 const char *pcszFontLast;
116 LONG lcidLast;
117 FONTMETRICS fmLast;
118
119} DLGPRIVATE, *PDLGPRIVATE;
120
121typedef struct _COLUMNDEF *PCOLUMNDEF;
122typedef struct _ROWDEF *PROWDEF;
123typedef struct _TABLEDEF *PTABLEDEF;
124
125/*
126 *@@ CONTROLPOS:
127 * control position. We don't want to use SWP.
128 */
129
130typedef struct _CONTROLPOS
131{
132 LONG x,
133 y,
134 cx,
135 cy;
136} CONTROLPOS, *PCONTROLPOS;
137
138/*
139 *@@ COLUMNDEF:
140 * representation of a table column.
141 * This is stored in a linked list in ROWDEF.
142 *
143 * A table column represents either a PM control
144 * window or another table, which may therefore
145 * be nested.
146 */
147
148typedef struct _COLUMNDEF
149{
150 PROWDEF pOwningRow; // row whose linked list this column belongs to
151
152 BOOL fIsNestedTable; // if TRUE, pvDefinition points to a nested TABLEDEF;
153 // if FALSE, pvDefinition points to a CONTROLDEF as
154 // specified by the caller
155
156 PVOID pvDefinition; // either a PTABLEDEF or a PCONTROLDEF
157
158 CONTROLPOS cpControl, // real pos and size of control
159 cpColumn; // pos and size of column; can be wider, spacings applied
160
161 HWND hwndControl; // created control; NULLHANDLE for tables always
162
163} COLUMNDEF;
164
165/*
166 *@@ ROWDEF:
167 *
168 */
169
170typedef struct _ROWDEF
171{
172 PTABLEDEF pOwningTable; // table whose linked list this row belongs to
173
174 LINKLIST llColumns; // contains COLUMNDEF structs, no auto-free
175
176 ULONG flRowFormat; // one of:
177 // -- ROW_VALIGN_BOTTOM 0x0000
178 // -- ROW_VALIGN_CENTER 0x0001
179 // -- ROW_VALIGN_TOP 0x0002
180
181 CONTROLPOS cpRow;
182
183} ROWDEF;
184
185/*
186 *@@ TABLEDEF:
187 *
188 */
189
190typedef struct _TABLEDEF
191{
192 LINKLIST llRows; // contains ROWDEF structs, no auto-free
193
194 PCONTROLDEF pCtlDef; // if != NULL, we create a PM control around the table
195
196 CONTROLPOS cpTable;
197
198} TABLEDEF;
199
200/*
201 *@@ PROCESSMODE:
202 *
203 */
204
205typedef enum _PROCESSMODE
206{
207 PROCESS_CALC_SIZES, // step 1
208 PROCESS_CALC_POSITIONS, // step 3
209 PROCESS_CREATE_CONTROLS // step 4
210} PROCESSMODE;
211
212/* ******************************************************************
213 *
214 * Worker routines
215 *
216 ********************************************************************/
217
218#define PM_GROUP_SPACING_X 16
219#define PM_GROUP_SPACING_TOP 20
220
221APIRET ProcessTable(PTABLEDEF pTableDef,
222 const CONTROLPOS *pcpTable,
223 PROCESSMODE ProcessMode,
224 PDLGPRIVATE pDlgData);
225
226/*
227 *@@ SetDlgFont:
228 *
229 *@@added V0.9.16 (2001-10-11) [umoeller]
230 */
231
232VOID SetDlgFont(PCONTROLDEF pControlDef,
233 PDLGPRIVATE pDlgData)
234{
235 LONG lPointSize = 0;
236 const char *pcszFontThis = pControlDef->pcszFont;
237 // can be NULL,
238 // or CTL_COMMON_FONT
239
240 if (pcszFontThis == CTL_COMMON_FONT)
241 pcszFontThis = pDlgData->pcszControlsFont;
242
243 if (!pDlgData->hps)
244 pDlgData->hps = WinGetPS(pDlgData->hwndDlg);
245
246 // check if we can reuse font data from last time
247 // V0.9.14 (2001-08-01) [umoeller]
248 if (strhcmp(pcszFontThis, // can be NULL!
249 pDlgData->pcszFontLast))
250 {
251 // different font than last time:
252
253 // delete old font?
254 if (pDlgData->lcidLast)
255 {
256 GpiSetCharSet(pDlgData->hps, LCID_DEFAULT); // LCID_DEFAULT == 0
257 GpiDeleteSetId(pDlgData->hps, pDlgData->lcidLast);
258 }
259
260 if (pcszFontThis)
261 {
262 // create new font
263 pDlgData->lcidLast = gpihFindPresFont(NULLHANDLE, // no window yet
264 FALSE,
265 pDlgData->hps,
266 pcszFontThis,
267 &pDlgData->fmLast,
268 &lPointSize);
269
270 GpiSetCharSet(pDlgData->hps, pDlgData->lcidLast);
271 if (pDlgData->fmLast.fsDefn & FM_DEFN_OUTLINE)
272 gpihSetPointSize(pDlgData->hps, lPointSize);
273 }
274 else
275 {
276 // use default font:
277 // @@todo handle presparams, maybe inherited?
278 GpiSetCharSet(pDlgData->hps, LCID_DEFAULT);
279 GpiQueryFontMetrics(pDlgData->hps,
280 sizeof(pDlgData->fmLast),
281 &pDlgData->fmLast);
282 }
283
284 pDlgData->pcszFontLast = pcszFontThis; // can be NULL
285 }
286}
287
288/*
289 *@@ CalcAutoSizeText:
290 *
291 *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed various things with statics
292 *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed broken fonts
293 *@@changed V0.9.14 (2001-08-01) [umoeller]: now caching fonts, which is significantly faster
294 *@@changed V0.9.16 (2001-10-15) [umoeller]: added APIRET
295 */
296
297APIRET CalcAutoSizeText(PCONTROLDEF pControlDef,
298 BOOL fMultiLine, // in: if TRUE, multiple lines
299 PSIZEL pszlAuto, // out: computed size
300 PDLGPRIVATE pDlgData)
301{
302 APIRET arc = NO_ERROR;
303
304 SetDlgFont(pControlDef, pDlgData);
305
306 pszlAuto->cy = pDlgData->fmLast.lMaxBaselineExt
307 + pDlgData->fmLast.lExternalLeading;
308
309 // ok, we FINALLY have a font now...
310 // get the control string and see how much space it needs
311 if ( (pControlDef->pcszText)
312 && (pControlDef->pcszText != (PCSZ)-1)
313 )
314 {
315 // do we have multiple lines?
316 if (fMultiLine)
317 {
318 RECTL rcl = {0, 0, 0, 0};
319 if (pControlDef->szlControlProposed.cx != -1)
320 rcl.xRight = pControlDef->szlControlProposed.cx; // V0.9.12 (2001-05-31) [umoeller]
321 else
322 rcl.xRight = winhQueryScreenCX() * 2 / 3;
323 if (pControlDef->szlControlProposed.cy != -1)
324 rcl.yTop = pControlDef->szlControlProposed.cy; // V0.9.12 (2001-05-31) [umoeller]
325 else
326 rcl.yTop = winhQueryScreenCY() * 2 / 3;
327
328 winhDrawFormattedText(pDlgData->hps,
329 &rcl,
330 pControlDef->pcszText,
331 DT_LEFT | DT_TOP | DT_WORDBREAK | DT_QUERYEXTENT);
332 pszlAuto->cx = rcl.xRight - rcl.xLeft;
333 pszlAuto->cy = rcl.yTop - rcl.yBottom;
334 }
335 else
336 {
337 POINTL aptl[TXTBOX_COUNT];
338 GpiQueryTextBox(pDlgData->hps,
339 strlen(pControlDef->pcszText),
340 (PCH)pControlDef->pcszText,
341 TXTBOX_COUNT,
342 aptl);
343 pszlAuto->cx = aptl[TXTBOX_TOPRIGHT].x - aptl[TXTBOX_BOTTOMLEFT].x;
344 }
345 }
346 else
347 arc = DLGERR_INVALID_CONTROL_TITLE;
348
349 return (arc);
350}
351
352/*
353 *@@ CalcAutoSize:
354 *
355 *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed various things with statics
356 *@@changed V0.9.16 (2001-10-15) [umoeller]: added APIRET
357 */
358
359APIRET CalcAutoSize(PCONTROLDEF pControlDef,
360 PSIZEL pszlAuto, // out: computed size
361 PDLGPRIVATE pDlgData)
362{
363 APIRET arc = NO_ERROR;
364
365 // dumb defaults
366 pszlAuto->cx = 100;
367 pszlAuto->cy = 30;
368
369 switch ((ULONG)pControlDef->pcszClass)
370 {
371 case 0xffff0003L: // WC_BUTTON:
372 if (!(arc = CalcAutoSizeText(pControlDef,
373 FALSE, // no multiline
374 pszlAuto,
375 pDlgData)))
376 {
377 if (pControlDef->flStyle & ( BS_AUTOCHECKBOX
378 | BS_AUTORADIOBUTTON
379 | BS_AUTO3STATE
380 | BS_3STATE
381 | BS_CHECKBOX
382 | BS_RADIOBUTTON))
383 {
384 // give a little extra width for the box bitmap
385 pszlAuto->cx += 20; // @@todo
386 // and height
387 pszlAuto->cy += 2;
388 }
389 else if (pControlDef->flStyle & BS_BITMAP)
390 ;
391 else if (pControlDef->flStyle & (BS_ICON | BS_MINIICON))
392 ;
393 // we can't test for BS_PUSHBUTTON because that's 0x0000
394 else if (!(pControlDef->flStyle & BS_USERBUTTON))
395 {
396 pszlAuto->cx += (2 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER) + 15);
397 pszlAuto->cy += (2 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER) + 15);
398 }
399 }
400 break;
401
402 case 0xffff0005L: // WC_STATIC:
403 if ((pControlDef->flStyle & 0x0F) == SS_TEXT)
404 arc = CalcAutoSizeText(pControlDef,
405 ((pControlDef->flStyle & DT_WORDBREAK) != 0),
406 pszlAuto,
407 pDlgData);
408 else if ((pControlDef->flStyle & 0x0F) == SS_BITMAP)
409 {
410 HBITMAP hbm;
411 if (hbm = (HBITMAP)pControlDef->pcszText)
412 {
413 BITMAPINFOHEADER2 bmih2;
414 ZERO(&bmih2);
415 bmih2.cbFix = sizeof(bmih2);
416 if (GpiQueryBitmapInfoHeader(hbm,
417 &bmih2))
418 {
419 pszlAuto->cx = bmih2.cx;
420 pszlAuto->cy = bmih2.cy;
421 }
422 else
423 arc = DLGERR_INVALID_STATIC_BITMAP;
424 }
425 }
426 else if ((pControlDef->flStyle & 0x0F) == SS_ICON)
427 {
428 pszlAuto->cx = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);
429 pszlAuto->cy = WinQuerySysValue(HWND_DESKTOP, SV_CYICON);
430 }
431 break;
432
433 default:
434 // any other control (just to be safe):
435 SetDlgFont(pControlDef, pDlgData);
436 pszlAuto->cx = 50;
437 pszlAuto->cy = pDlgData->fmLast.lMaxBaselineExt
438 + pDlgData->fmLast.lExternalLeading
439 + 5; // some space
440 }
441
442 return (arc);
443}
444
445/*
446 *@@ ColumnCalcSizes:
447 * implementation for PROCESS_CALC_SIZES in
448 * ProcessColumn.
449 *
450 *@@added V0.9.15 (2001-08-26) [umoeller]
451 *@@changed V0.9.16 (2001-10-15) [umoeller]: fixed ugly group table spacings
452 *@@changed V0.9.16 (2001-10-15) [umoeller]: added APIRET
453 */
454
455APIRET ColumnCalcSizes(PCOLUMNDEF pColumnDef,
456 PDLGPRIVATE pDlgData)
457{
458 APIRET arc = NO_ERROR;
459
460 ULONG ulXSpacing = 0,
461 ulYSpacing = 0;
462 if (pColumnDef->fIsNestedTable)
463 {
464 // nested table: recurse!!
465 PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
466 if (!(arc = ProcessTable(pTableDef,
467 NULL,
468 PROCESS_CALC_SIZES,
469 pDlgData)))
470 {
471 // store the size of the sub-table
472 pColumnDef->cpControl.cx = pTableDef->cpTable.cx;
473 pColumnDef->cpControl.cy = pTableDef->cpTable.cy;
474
475 // should we create a PM control around the table?
476 if (pTableDef->pCtlDef)
477 {
478 // yes: make this wider
479 ulXSpacing = 2 * PM_GROUP_SPACING_X;
480 ulYSpacing = // 3 * PM_GROUP_SPACING_X;
481 (PM_GROUP_SPACING_X + PM_GROUP_SPACING_TOP);
482 }
483 }
484 }
485 else
486 {
487 // no nested table, but control:
488 PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
489 PSIZEL pszl = &pControlDef->szlControlProposed;
490 SIZEL szlAuto;
491
492 if ( (pszl->cx == -1)
493 || (pszl->cy == -1)
494 )
495 {
496 arc = CalcAutoSize(pControlDef,
497 &szlAuto,
498 pDlgData);
499 }
500
501 if (!arc)
502 {
503 if (pszl->cx == -1)
504 pColumnDef->cpControl.cx = szlAuto.cx;
505 else
506 pColumnDef->cpControl.cx = pszl->cx;
507
508 if (pszl->cy == -1)
509 pColumnDef->cpControl.cy = szlAuto.cy;
510 else
511 pColumnDef->cpControl.cy = pszl->cy;
512
513 // @@todo hack sizes
514
515 ulXSpacing
516 = ulYSpacing
517 = (2 * pControlDef->ulSpacing);
518 }
519 }
520
521 pColumnDef->cpColumn.cx = pColumnDef->cpControl.cx
522 + ulXSpacing;
523 pColumnDef->cpColumn.cy = pColumnDef->cpControl.cy
524 + ulYSpacing;
525
526 return (arc);
527}
528
529/*
530 *@@ ColumnCalcPositions:
531 * implementation for PROCESS_CALC_POSITIONS in
532 * ProcessColumn.
533 *
534 *@@added V0.9.15 (2001-08-26) [umoeller]
535 *@@changed V0.9.16 (2001-10-15) [umoeller]: added APIRET
536 */
537
538APIRET ColumnCalcPositions(PCOLUMNDEF pColumnDef,
539 PROWDEF pOwningRow, // in: current row from ProcessRow
540 PLONG plX, // in/out: PROCESS_CALC_POSITIONS only
541 PDLGPRIVATE pDlgData)
542{
543 APIRET arc = NO_ERROR;
544
545 // calculate column position: this includes spacing
546 ULONG ulSpacing = 0;
547
548 // column position = *plX on ProcessRow stack
549 pColumnDef->cpColumn.x = *plX;
550 pColumnDef->cpColumn.y = pOwningRow->cpRow.y;
551
552 // check vertical alignment of row;
553 // we might need to increase column y
554 switch (pOwningRow->flRowFormat & ROW_VALIGN_MASK)
555 {
556 // case ROW_VALIGN_BOTTOM: // do nothing
557
558 case ROW_VALIGN_CENTER:
559 if (pColumnDef->cpColumn.cy < pOwningRow->cpRow.cy)
560 pColumnDef->cpColumn.y
561 += ( (pOwningRow->cpRow.cy - pColumnDef->cpColumn.cy)
562 / 2);
563 break;
564
565 case ROW_VALIGN_TOP:
566 if (pColumnDef->cpColumn.cy < pOwningRow->cpRow.cy)
567 pColumnDef->cpColumn.y
568 += (pOwningRow->cpRow.cy - pColumnDef->cpColumn.cy);
569 break;
570 }
571
572 if (pColumnDef->fIsNestedTable)
573 {
574 PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
575 // should we create a PM control around the table?
576 if (pTableDef->pCtlDef)
577 // yes:
578 ulSpacing = PM_GROUP_SPACING_X / 2; // V0.9.16 (2001-10-15) [umoeller]
579 }
580 else
581 {
582 // no nested table, but control:
583 PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
584 ulSpacing = pControlDef->ulSpacing;
585 }
586
587 // increase plX by column width
588 *plX += pColumnDef->cpColumn.cx;
589
590 // calculate CONTROL pos from COLUMN pos by applying spacing
591 pColumnDef->cpControl.x = pColumnDef->cpColumn.x
592 + ulSpacing;
593 pColumnDef->cpControl.y = pColumnDef->cpColumn.y
594 + ulSpacing;
595
596 if (pColumnDef->fIsNestedTable)
597 {
598 // nested table:
599 PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
600
601 // recurse!! to create windows for the sub-table
602 arc = ProcessTable(pTableDef,
603 &pColumnDef->cpControl, // start pos for new table
604 PROCESS_CALC_POSITIONS,
605 pDlgData);
606 }
607
608 return (arc);
609}
610
611/*
612 *@@ ColumnCreateControls:
613 * implementation for PROCESS_CREATE_CONTROLS in
614 * ProcessColumn.
615 *
616 *@@added V0.9.15 (2001-08-26) [umoeller]
617 *@@changed V0.9.16 (2001-10-15) [umoeller]: fixed ugly group table spacings
618 *@@changed V0.9.16 (2001-12-08) [umoeller]: fixed entry field ES_MARGIN positioning
619 */
620
621APIRET ColumnCreateControls(PCOLUMNDEF pColumnDef,
622 PDLGPRIVATE pDlgData)
623{
624 APIRET arc = NO_ERROR;
625
626 PCONTROLPOS pcp = NULL;
627 PCONTROLDEF pControlDef = NULL;
628 const char *pcszTitle = NULL;
629 ULONG flStyle = 0;
630 LHANDLE lHandleSet = NULLHANDLE;
631 ULONG flOld = 0;
632
633 LONG x, cx, y, cy; // for combo box hacks
634
635 if (pColumnDef->fIsNestedTable)
636 {
637 // nested table:
638 PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
639
640 // recurse!!
641 if (!(arc = ProcessTable(pTableDef,
642 NULL,
643 PROCESS_CREATE_CONTROLS,
644 pDlgData)))
645 {
646 // should we create a PM control around the table?
647 // (do this AFTER the other controls from recursing,
648 // otherwise the stupid container doesn't show up)
649 if (pTableDef->pCtlDef)
650 {
651 // yes:
652 pcp = &pColumnDef->cpColumn; // !! not control
653 pControlDef = pTableDef->pCtlDef;
654 pcszTitle = pControlDef->pcszText;
655 flStyle = pControlDef->flStyle;
656
657 x = pcp->x + pDlgData->ptlTotalOfs.x;
658 cx = pcp->cx - PM_GROUP_SPACING_X;
659 // note, just one spacing: for the _column_ size,
660 // we have specified 2 X spacings
661 y = pcp->y + pDlgData->ptlTotalOfs.y;
662 // cy = pcp->cy - PM_GROUP_SPACING_X;
663 cy = pcp->cy - /* PM_GROUP_SPACING_X - */ PM_GROUP_SPACING_TOP / 2;
664 }
665 }
666 }
667 else
668 {
669 // no nested table, but control:
670 pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
671 pcp = &pColumnDef->cpControl;
672 pcszTitle = pControlDef->pcszText;
673 flStyle = pControlDef->flStyle;
674
675 x = pcp->x + pDlgData->ptlTotalOfs.x;
676 cx = pcp->cx;
677 y = pcp->y + pDlgData->ptlTotalOfs.y;
678 cy = pcp->cy;
679
680 // now implement hacks for certain controls
681 switch ((ULONG)pControlDef->pcszClass)
682 {
683 case 0xffff0005L: // WC_STATIC:
684 // change the title if this is a static with SS_BITMAP;
685 // we have used a HBITMAP in there!
686 if ( ( ((flStyle & 0x0F) == SS_BITMAP)
687 || ((flStyle & 0x0F) == SS_ICON)
688 )
689 )
690 {
691 // change style flag to not use SS_BITMAP nor SS_ICON;
692 // control creation fails otherwise (stupid, stupid PM)
693 flOld = flStyle;
694 flStyle = ((flStyle & ~0x0F) | SS_FGNDFRAME);
695 pcszTitle = "";
696 lHandleSet = (LHANDLE)pControlDef->pcszText;
697 }
698 break;
699
700 case 0xffff0002L: // combobox
701 // hack the stupid drop-down combobox which doesn't
702 // expand otherwise (the size of the drop-down is
703 // the full size of the control... duh)
704 if (flStyle & (CBS_DROPDOWN | CBS_DROPDOWNLIST))
705 {
706 y -= 100;
707 cy += 100;
708 }
709 break;
710
711 case 0xffff0006L: // entry field
712 // the stupid entry field resizes itself if it has
713 // the ES_MARGIN style, so correlate that too... dammit
714 // V0.9.16 (2001-12-08) [umoeller]
715 if (flStyle & ES_MARGIN)
716 {
717 LONG cxMargin = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
718 LONG cyMargin = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
719
720 x += cxMargin;
721 y += cxMargin;
722 }
723 break;
724 } // end switch ((ULONG)pControlDef->pcszClass)
725 }
726
727 if (pcp && pControlDef)
728 {
729 // create something:
730 // PPRESPARAMS ppp = NULL;
731
732 const char *pcszFont = pControlDef->pcszFont;
733 // can be NULL, or CTL_COMMON_FONT
734 if (pcszFont == CTL_COMMON_FONT)
735 pcszFont = pDlgData->pcszControlsFont;
736
737 /* if (pcszFont)
738 winhStorePresParam(&ppp,
739 PP_FONTNAMESIZE,
740 strlen(pcszFont),
741 (PVOID)pcszFont); */
742
743 if (pColumnDef->hwndControl
744 = WinCreateWindow(pDlgData->hwndDlg, // parent
745 (PSZ)pControlDef->pcszClass,
746 (pcszTitle) // hacked
747 ? (PSZ)pcszTitle
748 : "",
749 flStyle, // hacked
750 x,
751 y,
752 cx,
753 cy,
754 pDlgData->hwndDlg, // owner
755 HWND_BOTTOM,
756 pControlDef->usID,
757 pControlDef->pvCtlData,
758 NULL))
759 {
760 if (lHandleSet)
761 {
762 // subclass the damn static
763 if ((flOld & 0x0F) == SS_ICON)
764 // this was a static:
765 ctlPrepareStaticIcon(pColumnDef->hwndControl,
766 1);
767 else
768 // this was a bitmap:
769 ctlPrepareStretchedBitmap(pColumnDef->hwndControl,
770 TRUE);
771
772 WinSendMsg(pColumnDef->hwndControl,
773 SM_SETHANDLE,
774 (MPARAM)lHandleSet,
775 0);
776 }
777 else
778 if (pcszFont)
779 // we must set the font explicitly here...
780 // doesn't always work with WinCreateWindow
781 // presparams parameter, for some reason
782 // V0.9.12 (2001-05-31) [umoeller]
783 winhSetWindowFont(pColumnDef->hwndControl,
784 pcszFont);
785
786 lstAppendItem(&pDlgData->llControls,
787 pColumnDef);
788
789 // if this is the first control with WS_TABSTOP,
790 // we give it the focus later
791 if ( (flStyle & WS_TABSTOP)
792 && (!pDlgData->hwndFirstFocus)
793 )
794 pDlgData->hwndFirstFocus = pColumnDef->hwndControl;
795
796 // if this is the first default push button,
797 // go store it too
798 // V0.9.14 (2001-08-21) [umoeller]
799 if ( (!pDlgData->hwndDefPushbutton)
800 && ((ULONG)pControlDef->pcszClass == 0xffff0003L)
801 && (pControlDef->flStyle & BS_DEFAULT)
802 )
803 pDlgData->hwndDefPushbutton = pColumnDef->hwndControl;
804 }
805 else
806 // V0.9.14 (2001-08-03) [umoeller]
807 arc = DLGERR_CANNOT_CREATE_CONTROL;
808 }
809
810 return (arc);
811}
812
813/*
814 *@@ ProcessColumn:
815 * processes a column, which per definition is either
816 * a control or a nested subtable.
817 *
818 * A column is part of a row, which in turn is part
819 * of a table. There can be several columns in a row,
820 * and several rows in a table.
821 *
822 * Since tables may be specified as columns, it is
823 * possible to produce complex dialog layouts by
824 * nesting tables.
825 *
826 * This does the following:
827 *
828 * -- PROCESS_CALC_SIZES: size is taken from control def,
829 * or for tables, this produces a recursive ProcessTable
830 * call.
831 * Preconditions: none.
832 *
833 * -- PROCESS_CALC_POSITIONS: position of each column
834 * is taken from *plX, which is increased by the
835 * column width by this call.
836 *
837 * Preconditions: Owning row must already have its
838 * y position properly set, or we can't compute
839 * ours. Besides, plX must point to the current X
840 * in the row and will be incremented by the columns
841 * size here.
842 *
843 * -- PROCESS_CREATE_CONTROLS: well, creates the controls.
844 *
845 * For tables, this recurses again. If the table has
846 * a string assigned, this also produces a group box
847 * after the recursion.
848 *
849 *@@changed V0.9.12 (2001-05-31) [umoeller]: added control data
850 *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed font problems
851 */
852
853APIRET ProcessColumn(PCOLUMNDEF pColumnDef,
854 PROWDEF pOwningRow, // in: current row from ProcessRow
855 PROCESSMODE ProcessMode, // in: processing mode (see ProcessAll)
856 PLONG plX, // in/out: PROCESS_CALC_POSITIONS only
857 PDLGPRIVATE pDlgData)
858{
859 APIRET arc = NO_ERROR;
860
861 pColumnDef->pOwningRow = pOwningRow;
862
863 switch (ProcessMode)
864 {
865 /*
866 * PROCESS_CALC_SIZES:
867 * step 1.
868 */
869
870 case PROCESS_CALC_SIZES:
871 arc = ColumnCalcSizes(pColumnDef,
872 pDlgData);
873 break;
874
875 /*
876 * PROCESS_CALC_POSITIONS:
877 * step 2.
878 */
879
880 case PROCESS_CALC_POSITIONS:
881 arc = ColumnCalcPositions(pColumnDef,
882 pOwningRow,
883 plX,
884 pDlgData);
885 break;
886
887 /*
888 * PROCESS_CREATE_CONTROLS:
889 * step 3.
890 */
891
892 case PROCESS_CREATE_CONTROLS:
893 arc = ColumnCreateControls(pColumnDef,
894 pDlgData);
895 break;
896 }
897
898 return (arc);
899}
900
901/*
902 *@@ ProcessRow:
903 * level-3 procedure (called from ProcessTable),
904 * which in turn calls ProcessColumn for each column
905 * in the row.
906 *
907 * See ProcessAll for the meaning of ProcessMode.
908 */
909
910APIRET ProcessRow(PROWDEF pRowDef,
911 PTABLEDEF pOwningTable, // in: current table from ProcessTable
912 PROCESSMODE ProcessMode, // in: processing mode (see ProcessAll)
913 PLONG plY, // in/out: current y position (decremented)
914 PDLGPRIVATE pDlgData)
915{
916 APIRET arc = NO_ERROR;
917 LONG lX;
918 PLISTNODE pNode;
919
920 pRowDef->pOwningTable = pOwningTable;
921
922 if (ProcessMode == PROCESS_CALC_SIZES)
923 {
924 pRowDef->cpRow.cx = 0;
925 pRowDef->cpRow.cy = 0;
926 }
927 else if (ProcessMode == PROCESS_CALC_POSITIONS)
928 {
929 // set up x and y so that the columns can
930 // base on that
931 pRowDef->cpRow.x = pOwningTable->cpTable.x;
932 // decrease y by row height
933 *plY -= pRowDef->cpRow.cy;
934 // and use that for our bottom position
935 pRowDef->cpRow.y = *plY;
936
937 // set lX to left of row; used by column calls below
938 lX = pRowDef->cpRow.x;
939 }
940
941 FOR_ALL_NODES(&pRowDef->llColumns, pNode)
942 {
943 PCOLUMNDEF pColumnDefThis = (PCOLUMNDEF)pNode->pItemData;
944
945 if (!(arc = ProcessColumn(pColumnDefThis, pRowDef, ProcessMode, &lX, pDlgData)))
946 {
947 if (ProcessMode == PROCESS_CALC_SIZES)
948 {
949 // row width = sum of all columns
950 pRowDef->cpRow.cx += pColumnDefThis->cpColumn.cx;
951
952 // row height = maximum height of a column
953 if (pRowDef->cpRow.cy < pColumnDefThis->cpColumn.cy)
954 pRowDef->cpRow.cy = pColumnDefThis->cpColumn.cy;
955 }
956 }
957 }
958
959 return (arc);
960}
961
962/*
963 *@@ ProcessTable:
964 * level-2 procedure (called from ProcessAll),
965 * which in turn calls ProcessRow for each row
966 * in the table (which in turn calls ProcessColumn
967 * for each column in the row).
968 *
969 * See ProcessAll for the meaning of ProcessMode.
970 *
971 * This routine is a bit sick because it can even be
972 * called recursively from ProcessColumn (!) if a
973 * nested table is found in a COLUMNDEF.
974 *
975 * With PROCESS_CALC_POSITIONS, pptl must specify
976 * the lower left corner of the table. For the
977 * root call, this will be {0, 0}; for nested calls,
978 * this must be the lower left corner of the column
979 * to which the nested table belongs.
980 *
981 */
982
983APIRET ProcessTable(PTABLEDEF pTableDef,
984 const CONTROLPOS *pcpTable, // in: table position with PROCESS_CALC_POSITIONS
985 PROCESSMODE ProcessMode, // in: processing mode (see ProcessAll)
986 PDLGPRIVATE pDlgData)
987{
988 APIRET arc = NO_ERROR;
989 LONG lY;
990 PLISTNODE pNode;
991
992 if (ProcessMode == PROCESS_CALC_SIZES)
993 {
994 pTableDef->cpTable.cx = 0;
995 pTableDef->cpTable.cy = 0;
996 }
997 else if (ProcessMode == PROCESS_CALC_POSITIONS)
998 {
999 pTableDef->cpTable.x = pcpTable->x;
1000 pTableDef->cpTable.y = pcpTable->y;
1001
1002 // start the rows on top
1003 lY = pcpTable->y + pTableDef->cpTable.cy;
1004 }
1005
1006 FOR_ALL_NODES(&pTableDef->llRows, pNode)
1007 {
1008 PROWDEF pRowDefThis = (PROWDEF)pNode->pItemData;
1009
1010 if (!(arc = ProcessRow(pRowDefThis, pTableDef, ProcessMode, &lY, pDlgData)))
1011 {
1012 if (ProcessMode == PROCESS_CALC_SIZES)
1013 {
1014 // table width = maximum width of a row
1015 if (pTableDef->cpTable.cx < pRowDefThis->cpRow.cx)
1016 pTableDef->cpTable.cx = pRowDefThis->cpRow.cx;
1017
1018 // table height = sum of all rows
1019 pTableDef->cpTable.cy += pRowDefThis->cpRow.cy;
1020 }
1021 }
1022 else
1023 break;
1024 }
1025
1026 return (arc);
1027}
1028
1029/*
1030 *@@ ProcessAll:
1031 * level-1 procedure, which in turn calls ProcessTable
1032 * for each root-level table found (which in turn
1033 * calls ProcessRow for each row in the table, which
1034 * in turn calls ProcessColumn for each column in
1035 * the row).
1036 *
1037 * The first trick to formatting is that ProcessAll will
1038 * get three times, thus going down the entire tree three
1039 * times, with ProcessMode being set to one of the
1040 * following for each call (in this order):
1041 *
1042 * -- PROCESS_CALC_SIZES: calculates the sizes
1043 * of all tables, rows, columns, and controls.
1044 *
1045 * After this first call, we know all the sizes
1046 * only and can then calculate the positions.
1047 *
1048 * -- PROCESS_CALC_POSITIONS: calculates the positions
1049 * based on the sizes calculated before.
1050 *
1051 * -- PROCESS_CREATE_CONTROLS: creates the controls with the
1052 * positions and sizes calculated before.
1053 *
1054 * The second trick is the precondition that tables may
1055 * nest by allowing another table definition in a column.
1056 * This way we can recurse from ProcessColumn back into
1057 * ProcessTable and thus know the size and position of a
1058 * nested table column just as if it were a regular control.
1059 */
1060
1061APIRET ProcessAll(PDLGPRIVATE pDlgData,
1062 PSIZEL pszlClient,
1063 PROCESSMODE ProcessMode)
1064{
1065 APIRET arc = NO_ERROR;
1066 PLISTNODE pNode;
1067 CONTROLPOS cpTable;
1068 ZERO(&cpTable);
1069
1070 switch (ProcessMode)
1071 {
1072 case PROCESS_CALC_SIZES:
1073 pszlClient->cx = 0;
1074 pszlClient->cy = 0;
1075 break;
1076
1077 case PROCESS_CALC_POSITIONS:
1078 // start with the table on top
1079 cpTable.y = pszlClient->cy;
1080 break;
1081 }
1082
1083 FOR_ALL_NODES(&pDlgData->llTables, pNode)
1084 {
1085 PTABLEDEF pTableDefThis = (PTABLEDEF)pNode->pItemData;
1086
1087 if (ProcessMode == PROCESS_CALC_POSITIONS)
1088 {
1089 cpTable.x = 0;
1090 cpTable.y -= pTableDefThis->cpTable.cy;
1091 }
1092
1093 if (!(arc = ProcessTable(pTableDefThis,
1094 &cpTable, // start pos
1095 ProcessMode,
1096 pDlgData)))
1097 {
1098 if (ProcessMode == PROCESS_CALC_SIZES)
1099 {
1100 pszlClient->cx += pTableDefThis->cpTable.cx;
1101 pszlClient->cy += pTableDefThis->cpTable.cy;
1102 }
1103 }
1104 }
1105
1106 return (arc);
1107}
1108
1109/*
1110 *@@ CreateColumn:
1111 *
1112 */
1113
1114APIRET CreateColumn(PROWDEF pCurrentRow,
1115 BOOL fIsNestedTable,
1116 PVOID pvDefinition, // in: either PTABLEDEF or PCONTROLDEF
1117 PCOLUMNDEF *ppColumnDef) // out: new COLUMNDEF
1118{
1119 APIRET arc = NO_ERROR;
1120
1121 if (!pCurrentRow)
1122 arc = DLGERR_CONTROL_BEFORE_ROW;
1123 else
1124 {
1125 // append the control def
1126 if (!pvDefinition)
1127 arc = DLGERR_NULL_CTL_DEF;
1128 else
1129 {
1130 // create column and store ctl def
1131 PCOLUMNDEF pColumnDef = NEW(COLUMNDEF);
1132 if (!pColumnDef)
1133 arc = ERROR_NOT_ENOUGH_MEMORY;
1134 else
1135 {
1136 memset(pColumnDef, 0, sizeof(COLUMNDEF));
1137 pColumnDef->pOwningRow = pCurrentRow;
1138 pColumnDef->fIsNestedTable = fIsNestedTable;
1139 pColumnDef->pvDefinition = pvDefinition;
1140
1141 *ppColumnDef = pColumnDef;
1142 }
1143 }
1144 }
1145
1146 return (arc);
1147}
1148
1149/*
1150 *@@ FreeTable:
1151 * frees the specified table and recurses
1152 * into nested tables, if necessary.
1153 *
1154 * This was added with V0.9.14 to fix the
1155 * bad memory leaks with nested tables.
1156 *
1157 *@@added V0.9.14 (2001-08-01) [umoeller]
1158 */
1159
1160VOID FreeTable(PTABLEDEF pTable)
1161{
1162 // for each table, clean up the rows
1163 PLISTNODE pRowNode;
1164 FOR_ALL_NODES(&pTable->llRows, pRowNode)
1165 {
1166 PROWDEF pRow = (PROWDEF)pRowNode->pItemData;
1167
1168 // for each row, clean up the columns
1169 PLISTNODE pColumnNode;
1170 FOR_ALL_NODES(&pRow->llColumns, pColumnNode)
1171 {
1172 PCOLUMNDEF pColumn = (PCOLUMNDEF)pColumnNode->pItemData;
1173
1174 if (pColumn->fIsNestedTable)
1175 {
1176 // nested table: recurse!
1177 PTABLEDEF pNestedTable = (PTABLEDEF)pColumn->pvDefinition;
1178 FreeTable(pNestedTable);
1179 }
1180
1181 free(pColumn);
1182 }
1183 lstClear(&pRow->llColumns);
1184
1185 free(pRow);
1186 }
1187 lstClear(&pTable->llRows);
1188
1189 free(pTable);
1190}
1191
1192/* ******************************************************************
1193 *
1194 * Dialog formatter engine
1195 *
1196 ********************************************************************/
1197
1198/*
1199 *@@ STACKITEM:
1200 *
1201 */
1202
1203typedef struct _STACKITEM
1204{
1205 PTABLEDEF pLastTable;
1206 PROWDEF pLastRow;
1207
1208} STACKITEM, *PSTACKITEM;
1209
1210#define SPACING 10
1211
1212/*
1213 *@@ Dlg0_Init:
1214 *
1215 *@@added V0.9.15 (2001-08-26) [umoeller]
1216 */
1217
1218APIRET Dlg0_Init(PDLGPRIVATE *ppDlgData,
1219 PCSZ pcszControlsFont)
1220{
1221 PDLGPRIVATE pDlgData;
1222 if (!(pDlgData = NEW(DLGPRIVATE)))
1223 return (ERROR_NOT_ENOUGH_MEMORY);
1224 ZERO(pDlgData);
1225 lstInit(&pDlgData->llTables, FALSE);
1226 lstInit(&pDlgData->llControls, FALSE);
1227
1228 pDlgData->pcszControlsFont = pcszControlsFont;
1229
1230 *ppDlgData = pDlgData;
1231
1232 return NO_ERROR;
1233}
1234
1235/*
1236 *@@ Dlg1_ParseTables:
1237 *
1238 *@@added V0.9.15 (2001-08-26) [umoeller]
1239 */
1240
1241APIRET Dlg1_ParseTables(PDLGPRIVATE pDlgData,
1242 PDLGHITEM paDlgItems, // in: definition array
1243 ULONG cDlgItems) // in: array item count (NOT array size)
1244{
1245 APIRET arc = NO_ERROR;
1246
1247 LINKLIST llStack;
1248 ULONG ul;
1249 PTABLEDEF pCurrentTable = NULL;
1250 PROWDEF pCurrentRow = NULL;
1251
1252 lstInit(&llStack, TRUE); // this is our stack for nested table definitions
1253
1254 for (ul = 0;
1255 ul < cDlgItems;
1256 ul++)
1257 {
1258 PDLGHITEM pItemThis = &paDlgItems[ul];
1259
1260 switch (pItemThis->Type)
1261 {
1262 /*
1263 * TYPE_START_NEW_TABLE:
1264 *
1265 */
1266
1267 case TYPE_START_NEW_TABLE:
1268 {
1269 // root table or nested?
1270 BOOL fIsRoot = (pCurrentTable == NULL);
1271
1272 // push the current table on the stack
1273 PSTACKITEM pStackItem;
1274 if (!(pStackItem = NEW(STACKITEM)))
1275 {
1276 arc = ERROR_NOT_ENOUGH_MEMORY;
1277 break;
1278 }
1279 else
1280 {
1281 pStackItem->pLastTable = pCurrentTable;
1282 pStackItem->pLastRow = pCurrentRow;
1283 lstPush(&llStack, pStackItem);
1284 }
1285
1286 // create new table
1287 if (!(pCurrentTable = NEW(TABLEDEF)))
1288 arc = ERROR_NOT_ENOUGH_MEMORY;
1289 else
1290 {
1291 ZERO(pCurrentTable);
1292
1293 lstInit(&pCurrentTable->llRows, FALSE);
1294
1295 if (pItemThis->ulData)
1296 // control specified: store it (this will become a PM group)
1297 pCurrentTable->pCtlDef = (PCONTROLDEF)pItemThis->ulData;
1298
1299 if (fIsRoot)
1300 // root table:
1301 // append to dialog data list
1302 lstAppendItem(&pDlgData->llTables, pCurrentTable);
1303 else
1304 {
1305 // nested table:
1306 // create "table" column for this
1307 PCOLUMNDEF pColumnDef;
1308 if (!(arc = CreateColumn(pCurrentRow,
1309 TRUE, // nested table
1310 pCurrentTable,
1311 &pColumnDef)))
1312 lstAppendItem(&pCurrentRow->llColumns,
1313 pColumnDef);
1314 }
1315 }
1316
1317 pCurrentRow = NULL;
1318 break; }
1319
1320 /*
1321 * TYPE_START_NEW_ROW:
1322 *
1323 */
1324
1325 case TYPE_START_NEW_ROW:
1326 {
1327 if (!pCurrentTable)
1328 arc = DLGERR_ROW_BEFORE_TABLE;
1329 else
1330 {
1331 // create new row
1332 if (!(pCurrentRow = NEW(ROWDEF)))
1333 arc = ERROR_NOT_ENOUGH_MEMORY;
1334 else
1335 {
1336 ZERO(pCurrentRow);
1337
1338 pCurrentRow->pOwningTable = pCurrentTable;
1339 lstInit(&pCurrentRow->llColumns, FALSE);
1340
1341 pCurrentRow->flRowFormat = pItemThis->ulData;
1342
1343 lstAppendItem(&pCurrentTable->llRows, pCurrentRow);
1344 }
1345 }
1346 break; }
1347
1348 /*
1349 * TYPE_CONTROL_DEF:
1350 *
1351 */
1352
1353 case TYPE_CONTROL_DEF:
1354 {
1355 PCOLUMNDEF pColumnDef;
1356 if (!(arc = CreateColumn(pCurrentRow,
1357 FALSE, // no nested table
1358 (PVOID)pItemThis->ulData,
1359 &pColumnDef)))
1360 lstAppendItem(&pCurrentRow->llColumns,
1361 pColumnDef);
1362 break; }
1363
1364 /*
1365 * TYPE_END_TABLE:
1366 *
1367 */
1368
1369 case TYPE_END_TABLE:
1370 {
1371 PLISTNODE pNode = lstPop(&llStack);
1372 if (!pNode)
1373 // nothing on the stack:
1374 arc = DLGERR_TOO_MANY_TABLES_CLOSED;
1375 else
1376 {
1377 PSTACKITEM pStackItem = (PSTACKITEM)pNode->pItemData;
1378 pCurrentTable = pStackItem->pLastTable;
1379 pCurrentRow = pStackItem->pLastRow;
1380
1381 lstRemoveNode(&llStack, pNode);
1382 }
1383 break; }
1384
1385 default:
1386 arc = DLGERR_INVALID_CODE;
1387 }
1388
1389 if (arc)
1390 break;
1391 }
1392
1393 if ((!arc) && (lstCountItems(&llStack)))
1394 arc = DLGERR_TABLE_NOT_CLOSED;
1395
1396 lstClear(&llStack);
1397
1398 return (arc);
1399}
1400
1401/*
1402 *@@ Dlg2_CalcSizes:
1403 *
1404 *@@added V0.9.15 (2001-08-26) [umoeller]
1405 */
1406
1407APIRET Dlg2_CalcSizes(PDLGPRIVATE pDlgData,
1408 PSIZEL pszlClient) // out: dialog's client size
1409{
1410 APIRET arc = ProcessAll(pDlgData,
1411 pszlClient,
1412 PROCESS_CALC_SIZES);
1413 // this goes into major recursions...
1414
1415 // free the cached font resources that
1416 // might have been created here
1417 if (pDlgData->hps)
1418 {
1419 if (pDlgData->lcidLast)
1420 {
1421 GpiSetCharSet(pDlgData->hps, LCID_DEFAULT);
1422 GpiDeleteSetId(pDlgData->hps, pDlgData->lcidLast);
1423 }
1424 WinReleasePS(pDlgData->hps);
1425 }
1426
1427 return (arc);
1428}
1429
1430/*
1431 *@@ Dlg3_PositionAndCreate:
1432 *
1433 *@@added V0.9.15 (2001-08-26) [umoeller]
1434 *@@changed V0.9.15 (2001-08-26) [umoeller]: BS_DEFAULT for other than first button was ignored, fixed
1435 */
1436
1437APIRET Dlg3_PositionAndCreate(PDLGPRIVATE pDlgData,
1438 PSIZEL pszlClient, // in: dialog's client size
1439 HWND *phwndFocusItem) // out: item to give focus to
1440{
1441 APIRET arc = NO_ERROR;
1442
1443 /*
1444 * 5) compute _positions_ of all controls
1445 *
1446 */
1447
1448 ProcessAll(pDlgData,
1449 pszlClient,
1450 PROCESS_CALC_POSITIONS);
1451
1452 /*
1453 * 6) create control windows, finally
1454 *
1455 */
1456
1457 pDlgData->ptlTotalOfs.x
1458 = pDlgData->ptlTotalOfs.y
1459 = SPACING;
1460
1461 ProcessAll(pDlgData,
1462 pszlClient,
1463 PROCESS_CREATE_CONTROLS);
1464
1465 if (pDlgData->hwndDefPushbutton)
1466 {
1467 // we had a default pushbutton:
1468 // go set it V0.9.14 (2001-08-21) [umoeller]
1469 WinSetWindowULong(pDlgData->hwndDlg,
1470 QWL_DEFBUTTON,
1471 pDlgData->hwndDefPushbutton);
1472 *phwndFocusItem = pDlgData->hwndDefPushbutton;
1473 // V0.9.15 (2001-08-26) [umoeller]
1474 }
1475 else
1476 *phwndFocusItem = (pDlgData->hwndFirstFocus)
1477 ? pDlgData->hwndFirstFocus
1478 : pDlgData->hwndDlg;
1479
1480 return (arc);
1481}
1482
1483/*
1484 *@@ Dlg9_Cleanup:
1485 *
1486 *@@added V0.9.15 (2001-08-26) [umoeller]
1487 */
1488
1489VOID Dlg9_Cleanup(PDLGPRIVATE *ppDlgData)
1490{
1491 PDLGPRIVATE pDlgData;
1492 if ( (ppDlgData)
1493 && (pDlgData = *ppDlgData)
1494 )
1495 {
1496 PLISTNODE pTableNode;
1497
1498 // in any case, clean up our mess:
1499
1500 // clean up the tables
1501 FOR_ALL_NODES(&pDlgData->llTables, pTableNode)
1502 {
1503 PTABLEDEF pTable = (PTABLEDEF)pTableNode->pItemData;
1504
1505 FreeTable(pTable);
1506 // this may recurse for nested tables
1507 }
1508
1509 lstClear(&pDlgData->llTables);
1510 lstClear(&pDlgData->llControls);
1511
1512 free(pDlgData);
1513
1514 *ppDlgData = NULL;
1515 }
1516}
1517
1518/* ******************************************************************
1519 *
1520 * Dialog formatter entry points
1521 *
1522 ********************************************************************/
1523
1524/*
1525 *@@ dlghCreateDlg:
1526 * replacement for WinCreateDlg/WinLoadDlg for creating a
1527 * dialog from a settings array in memory, which is
1528 * formatted automatically.
1529 *
1530 * This does NOT use regular dialog templates from
1531 * module resources. Instead, you pass in an array
1532 * of DLGHITEM structures, which define the controls
1533 * and how they are to be formatted.
1534 *
1535 * The main advantage compared to dialog resources is
1536 * that with this function, you will never have to
1537 * define control _positions_. Instead, you only specify
1538 * the control _sizes_, and all positions are computed
1539 * automatically here. Even better, for many controls,
1540 * auto-sizing is supported according to the control's
1541 * text (e.g. for statics and checkboxes).
1542 *
1543 * A regular standard dialog would use something like
1544 *
1545 + FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN
1546 *
1547 * for flCreateFlags. To make the dlg sizeable, specify
1548 * FCF_SIZEBORDER instead of FCF_DLGBORDER.
1549 *
1550 * <B>Usage:</B>
1551 *
1552 * Like WinLoadDlg, this creates a standard WC_FRAME and
1553 * subclasses it with fnwpMyDlgProc. It then sends WM_INITDLG
1554 * to the dialog with pCreateParams in mp2.
1555 *
1556 * If this func returns no error, you can then use
1557 * WinProcessDlg with the newly created dialog as usual. In
1558 * your dlg proc, use WinDefDlgProc as usual.
1559 *
1560 * There is NO run-time overhead for either code or memory
1561 * after dialog creation; after this function returns, the
1562 * dialog is a standard dialog as if loaded from WinLoadDlg.
1563 * The array of DLGHITEM structures defines how the
1564 * dialog is set up. All this is ONLY used by this function
1565 * and NOT needed after the dialog has been created.
1566 *
1567 * In DLGHITEM, the "Type" field determines what this
1568 * structure defines. A number of handy macros have been
1569 * defined to make this easier and to provide type-checking
1570 * at compile time. See dialog.h for more.
1571 *
1572 * Essentially, such a dialog item operates similarly to
1573 * HTML tables. There are rows and columns in the table,
1574 * and each control which is specified must be a column
1575 * in some table. Tables may also nest (see below).
1576 *
1577 * The macros are:
1578 *
1579 * -- START_TABLE starts a new table. The tables may nest,
1580 * but must each be properly terminated with END_TABLE.
1581 *
1582 * -- START_GROUP_TABLE(pDef) starts a group. This
1583 * behaves exacly like START_TABLE, but in addition,
1584 * it produces a static group control around the table.
1585 * Useful for group boxes. pDef must point to a
1586 * _CONTROLDEF describing the control to be used for
1587 * the group (usually a WC_STATIC with SS_GROUP style),
1588 * whose size parameter is ignored.
1589 *
1590 * As with START_TABLE, START_GROUP_TABLE must be
1591 * terminated with END_TABLE.
1592 *
1593 * -- START_ROW(fl) starts a new row in a table (regular
1594 * or group). This must also be the first item after
1595 * the (group) table tag.
1596 *
1597 * fl specifies formatting flags for the row. This
1598 * can be one of ROW_VALIGN_BOTTOM, ROW_VALIGN_CENTER,
1599 * ROW_VALIGN_TOP and affects all items in the row.
1600 *
1601 * -- CONTROL_DEF(pDef) defines a control in a table row.
1602 * pDef must point to a CONTROLDEF structure.
1603 *
1604 * Again, there is is NO information in
1605 * CONTROLDEF about a control's _position_.
1606 * Instead, the structure only contains the _size_
1607 * of the control. All positions are computed by
1608 * this function, depending on the sizes of the
1609 * controls and their nesting within the various tables.
1610 *
1611 * If you specify SZL_AUTOSIZE, the size of the
1612 * control is even computed automatically. Presently,
1613 * this only works for statics with SS_TEXT, SS_ICON,
1614 * and SS_BITMAP.
1615 *
1616 * Unless separated with START_ROW items, subsequent
1617 * control items will be considered to be in the same
1618 * row (== positioned next to each other).
1619 *
1620 * There are a few rules, whose violation will produce
1621 * an error:
1622 *
1623 * -- The entire array must be enclosed in a table
1624 * (the "root" table).
1625 *
1626 * -- After START_TABLE or START_GROUP_TABLE, there must
1627 * always be a START_ROW first.
1628 *
1629 * To create a dialog, set up arrays like the following:
1630 *
1631 + // control definitions referenced by DlgTemplate:
1632 + CONTROLDEF
1633 + (1) GroupDef = {
1634 + WC_STATIC, "", ....,
1635 + { 0, 0 }, // size, ignored for groups
1636 + 5 // spacing
1637 + },
1638 + (2) CnrDef = {
1639 + WC_CONTAINER, "", ....,
1640 + { 50, 50 }, // size
1641 + 5 // spacing
1642 + },
1643 + (3) Static = {
1644 + WC_STATIC, "Static below cnr", ...,
1645 + { SZL_AUTOSIZE, SZL_AUTOSIZE }, // size
1646 + 5 // spacing
1647 + },
1648 + (4) OKButton = {
1649 + WC_STATIC, "~OK", ...,
1650 + { 100, 30 }, // size
1651 + 5 // spacing
1652 + },
1653 + (5) CancelButton = {
1654 + WC_STATIC, "~Cancel", ...,
1655 + { 100, 30 }, // size
1656 + 5 // spacing
1657 + };
1658 +
1659 + DLGHITEM DlgTemplate[] =
1660 + {
1661 + START_TABLE, // root table, required
1662 + START_ROW(0), // row 1 in the root table, required
1663 + // create group on top
1664 + (1) START_GROUP_TABLE(&Group),
1665 + START_ROW(0),
1666 + (2) CONTROL_DEF(&CnrDef),
1667 + START_ROW(0),
1668 + (3) CONTROL_DEF(&Static),
1669 + END_TABLE, // end of group
1670 + START_ROW(0), // row 2 in the root table
1671 + // two buttons next to each other
1672 + (4) CONTROL_DEF(&OKButton),
1673 + (5) CONTROL_DEF(&CancelButton),
1674 + END_TABLE
1675 + }
1676 *
1677 * This will produce a dlg like this:
1678 *
1679 + ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
1680 + º º
1681 + º ÚÄ Group (1) ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ º
1682 + º ³ ³ º
1683 + º ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ º
1684 + º ³ ³ ³ ³ º
1685 + º ³ ³ Cnr inside group (2) ³ ³ º
1686 + º ³ ³ ³ ³ º
1687 + º ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ º
1688 + º ³ Static below cnr (3) ³ º
1689 + º ³ ³ º
1690 + º ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ º
1691 + º ÚÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ º
1692 + º ³ OK (4) ³ ³ Cancel (5) ³ º
1693 + º ÀÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ º
1694 + º º
1695 + ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ
1696 *
1697 * <B>Errors:</B>
1698 *
1699 * This does not return a HWND, but an APIRET. This will be
1700 * one of the following:
1701 *
1702 * -- NO_ERROR: only in that case, the phwndDlg ptr
1703 * receives the HWND of the new dialog, which can
1704 * then be given to WinProcessDlg. Don't forget
1705 * WinDestroyWindow.
1706 *
1707 * -- ERROR_NOT_ENOUGH_MEMORY
1708 *
1709 * -- DLGERR_ROW_BEFORE_TABLE: a row definition appeared
1710 * outside a table definition.
1711 *
1712 * -- DLGERR_CONTROL_BEFORE_ROW: a control definition
1713 * appeared right after a table definition. You must
1714 * specify a row first.
1715 *
1716 * -- DLGERR_NULL_CTL_DEF: TYPE_END_TABLE was specified,
1717 * but the CONTROLDEF ptr was NULL.
1718 *
1719 * -- DLGERR_CANNOT_CREATE_FRAME: unable to create the
1720 * WC_FRAME window. Maybe an invalid owner was specified.
1721 *
1722 * -- DLGERR_INVALID_CODE: invalid "Type" field in
1723 * DLGHITEM.
1724 *
1725 * -- DLGERR_TABLE_NOT_CLOSED, DLGERR_TOO_MANY_TABLES_CLOSED:
1726 * improper nesting of TYPE_START_NEW_TABLE and
1727 * TYPE_END_TABLE fields.
1728 *
1729 * <B>Example:</B>
1730 *
1731 * The typical calling sequence would be:
1732 *
1733 + HWND hwndDlg = NULLHANDLE;
1734 + if (NO_ERROR == dlghCreateDlg(&hwndDlg,
1735 + hwndOwner,
1736 + FCF_DLGBORDER | FCF_NOBYTEALIGN,
1737 + fnwpMyDlgProc,
1738 + "My Dlg Title",
1739 + DlgTemplate, // DLGHITEM array
1740 + ARRAYITEMCOUNT(DlgTemplate),
1741 + NULL, // mp2 for WM_INITDLG
1742 + "9.WarpSans")) // default font
1743 + {
1744 + ULONG idReturn = WinProcessDlg(hwndDlg);
1745 + WinDestroyWindow(hwndDlg);
1746 + }
1747 *
1748 *@@changed V0.9.14 (2001-07-07) [umoeller]: fixed disabled mouse with hwndOwner == HWND_DESKTOP
1749 *@@changed V0.9.14 (2001-08-01) [umoeller]: fixed major memory leaks with nested tables
1750 *@@changed V0.9.14 (2001-08-21) [umoeller]: fixed default push button problems
1751 *@@changed V0.9.16 (2001-12-06) [umoeller]: fixed bad owner if not direct desktop child
1752 */
1753
1754APIRET dlghCreateDlg(HWND *phwndDlg, // out: new dialog
1755 HWND hwndOwner,
1756 ULONG flCreateFlags, // in: standard FCF_* frame flags
1757 PFNWP pfnwpDialogProc,
1758 const char *pcszDlgTitle,
1759 PDLGHITEM paDlgItems, // in: definition array
1760 ULONG cDlgItems, // in: array item count (NOT array size)
1761 PVOID pCreateParams, // in: for mp2 of WM_INITDLG
1762 const char *pcszControlsFont) // in: font for ctls with CTL_COMMON_FONT
1763{
1764 APIRET arc = NO_ERROR;
1765
1766 ULONG ul;
1767
1768 PDLGPRIVATE pDlgData = NULL;
1769
1770 HWND hwndDesktop = WinQueryDesktopWindow(NULLHANDLE, NULLHANDLE);
1771 // works with a null HAB
1772
1773 /*
1774 * 1) parse the table and create structures from it
1775 *
1776 */
1777
1778 if (!(arc = Dlg0_Init(&pDlgData,
1779 pcszControlsFont)))
1780 {
1781 if (!(arc = Dlg1_ParseTables(pDlgData,
1782 paDlgItems,
1783 cDlgItems)))
1784 {
1785 /*
1786 * 2) create empty dialog frame
1787 *
1788 */
1789
1790 FRAMECDATA fcData = {0};
1791 ULONG flStyle = 0;
1792 HWND hwndOwnersParent;
1793
1794 fcData.cb = sizeof(FRAMECDATA);
1795 fcData.flCreateFlags = flCreateFlags | 0x40000000L;
1796
1797 if (flCreateFlags & FCF_SIZEBORDER)
1798 // dialog has size border:
1799 // add "clip siblings" style
1800 flStyle |= WS_CLIPSIBLINGS;
1801
1802 if (hwndOwner == HWND_DESKTOP)
1803 // there's some dumb XWorkplace code left
1804 // which uses this, and this disables the
1805 // mouse for some reason
1806 // V0.9.14 (2001-07-07) [umoeller]
1807 hwndOwner = NULLHANDLE;
1808
1809 // now, make sure the owner window is child of
1810 // HWND_DESKTOP... if it is not, we'll only disable
1811 // some dumb child window, which is not sufficient
1812 // V0.9.16 (2001-12-06) [umoeller]
1813 while ( (hwndOwner)
1814 && (hwndOwnersParent = WinQueryWindow(hwndOwner, QW_PARENT))
1815 && (hwndOwnersParent != hwndDesktop)
1816 )
1817 hwndOwner = hwndOwnersParent;
1818
1819 if (!(pDlgData->hwndDlg = WinCreateWindow(HWND_DESKTOP,
1820 WC_FRAME,
1821 (PSZ)pcszDlgTitle,
1822 flStyle, // style; invisible for now
1823 0, 0, 0, 0,
1824 hwndOwner,
1825 HWND_TOP,
1826 0, // ID
1827 &fcData,
1828 NULL))) // presparams
1829 arc = DLGERR_CANNOT_CREATE_FRAME;
1830 else
1831 {
1832 HWND hwndDlg = pDlgData->hwndDlg;
1833 HWND hwndFocusItem = NULLHANDLE;
1834 SIZEL szlClient = {0};
1835 RECTL rclClient;
1836
1837 /*
1838 * 3) compute size of all controls
1839 *
1840 */
1841
1842 Dlg2_CalcSizes(pDlgData,
1843 &szlClient);
1844
1845 WinSubclassWindow(hwndDlg, pfnwpDialogProc);
1846
1847 /*
1848 * 4) compute size of dialog client from total
1849 * size of all controls
1850 */
1851
1852 // calculate the frame size from the client size
1853 rclClient.xLeft = 10;
1854 rclClient.yBottom = 10;
1855 rclClient.xRight = szlClient.cx + 2 * SPACING;
1856 rclClient.yTop = szlClient.cy + 2 * SPACING;
1857 WinCalcFrameRect(hwndDlg,
1858 &rclClient,
1859 FALSE); // frame from client
1860
1861 WinSetWindowPos(hwndDlg,
1862 0,
1863 10,
1864 10,
1865 rclClient.xRight,
1866 rclClient.yTop,
1867 SWP_MOVE | SWP_SIZE | SWP_NOADJUST);
1868
1869 arc = Dlg3_PositionAndCreate(pDlgData,
1870 &szlClient,
1871 &hwndFocusItem);
1872
1873 /*
1874 * 7) WM_INITDLG, set focus
1875 *
1876 */
1877
1878 if (!WinSendMsg(pDlgData->hwndDlg,
1879 WM_INITDLG,
1880 (MPARAM)hwndFocusItem,
1881 (MPARAM)pCreateParams))
1882 {
1883 // if WM_INITDLG returns FALSE, this means
1884 // the dlg proc has not changed the focus;
1885 // we must then set the focus here
1886 WinSetFocus(HWND_DESKTOP, hwndFocusItem);
1887 }
1888 }
1889 }
1890
1891 if (arc)
1892 {
1893 // error: clean up
1894 if (pDlgData->hwndDlg)
1895 {
1896 WinDestroyWindow(pDlgData->hwndDlg);
1897 pDlgData->hwndDlg = NULLHANDLE;
1898 }
1899 }
1900 else
1901 // no error: output dialog
1902 *phwndDlg = pDlgData->hwndDlg;
1903
1904 Dlg9_Cleanup(&pDlgData);
1905 }
1906
1907 if (arc)
1908 {
1909 CHAR szErr[300];
1910 sprintf(szErr, "Error %d occured in " __FUNCTION__ ".", arc);
1911 winhDebugBox(hwndOwner,
1912 "Error in Dialog Manager",
1913 szErr);
1914 }
1915
1916 return (arc);
1917}
1918
1919/*
1920 *@@ dlghFormatDlg:
1921 * similar to dlghCreateDlg in that this can
1922 * dynamically format dialog items.
1923 *
1924 * The differences however are the following:
1925 *
1926 * -- This assumes that hwndDlg already points
1927 * to a valid dialog frame and that this
1928 * dialog should be modified according to
1929 * flFlags.
1930 *
1931 * This is what's used in XWorkplace for notebook
1932 * settings pages since these always have to be
1933 * based on a resource dialog (which is loaded
1934 * empty).
1935 *
1936 * flFlags can be any combination of the following:
1937 *
1938 * -- DFFL_CREATECONTROLS: paDlgItems points to
1939 * an array of cDlgItems DLGHITEM structures
1940 * (see dlghCreateDlg) which is used for creating
1941 * subwindows in hwndDlg. By using this flag, the
1942 * function will essentially work like dlghCreateDlg,
1943 * except that the frame is already created.
1944 *
1945 * -- DFFL_RESIZEFRAME: hwndDlg should be resized so
1946 * that it will properly surround the controls.
1947 *
1948 * This can only be used in conjunction with
1949 * DFFL_RESIZEFRAME.
1950 *
1951 *@@added V0.9.16 (2001-09-29) [umoeller]
1952 */
1953
1954APIRET dlghFormatDlg(HWND hwndDlg, // in: dialog frame to work on
1955 PDLGHITEM paDlgItems, // in: definition array
1956 ULONG cDlgItems, // in: array item count (NOT array size)
1957 const char *pcszControlsFont, // in: font for ctls with CTL_COMMON_FONT
1958 ULONG flFlags) // in: DFFL_* flags
1959{
1960 APIRET arc = NO_ERROR;
1961
1962 ULONG ul;
1963
1964 PDLGPRIVATE pDlgData = NULL;
1965
1966 /*
1967 * 1) parse the table and create structures from it
1968 *
1969 */
1970
1971 if (!(arc = Dlg0_Init(&pDlgData,
1972 pcszControlsFont)))
1973 {
1974 if (!(arc = Dlg1_ParseTables(pDlgData,
1975 paDlgItems,
1976 cDlgItems)))
1977 {
1978 /*
1979 * 2) create empty dialog frame
1980 *
1981 */
1982
1983 HWND hwndFocusItem = NULLHANDLE;
1984 SIZEL szlClient = {0};
1985 RECTL rclClient;
1986
1987 pDlgData->hwndDlg = hwndDlg;
1988
1989 /*
1990 * 3) compute size of all controls
1991 *
1992 */
1993
1994 Dlg2_CalcSizes(pDlgData,
1995 &szlClient);
1996
1997 // WinSubclassWindow(hwndDlg, pfnwpDialogProc);
1998
1999 /*
2000 * 4) compute size of dialog client from total
2001 * size of all controls
2002 */
2003
2004 if (flFlags & DFFL_RESIZEFRAME)
2005 {
2006 // calculate the frame size from the client size
2007 rclClient.xLeft = 10;
2008 rclClient.yBottom = 10;
2009 rclClient.xRight = szlClient.cx + 2 * SPACING;
2010 rclClient.yTop = szlClient.cy + 2 * SPACING;
2011 WinCalcFrameRect(hwndDlg,
2012 &rclClient,
2013 FALSE); // frame from client
2014
2015 WinSetWindowPos(hwndDlg,
2016 0,
2017 10,
2018 10,
2019 rclClient.xRight,
2020 rclClient.yTop,
2021 SWP_MOVE | SWP_SIZE | SWP_NOADJUST);
2022 }
2023
2024 if (flFlags & DFFL_CREATECONTROLS)
2025 {
2026 if (!(arc = Dlg3_PositionAndCreate(pDlgData,
2027 &szlClient,
2028 &hwndFocusItem)))
2029 WinSetFocus(HWND_DESKTOP, hwndFocusItem);
2030 }
2031 }
2032
2033 Dlg9_Cleanup(&pDlgData);
2034 }
2035
2036 if (arc)
2037 {
2038 CHAR szErr[300];
2039 sprintf(szErr, "Error %d occured in " __FUNCTION__ ".", arc);
2040 winhDebugBox(NULLHANDLE,
2041 "Error in Dialog Manager",
2042 szErr);
2043 }
2044
2045 return (arc);
2046}
2047
2048/* ******************************************************************
2049 *
2050 * Dialog arrays
2051 *
2052 ********************************************************************/
2053
2054/*
2055 *@@ dlghCreateArray:
2056 * creates a "dialog array" for dynamically
2057 * building a dialog template in memory.
2058 *
2059 * A dialog array is simply an array of
2060 * DLGHITEM structures, as you would normally
2061 * define them statically in the source.
2062 * However, there are situations where you
2063 * might want to leave out certain controls
2064 * depending on certain conditions, which
2065 * can be difficult with static arrays.
2066 *
2067 * As a result, these "array" functions have
2068 * been added to allow for adding static
2069 * DLGHITEM subarrays to a dynamic array in
2070 * memory, which can then be passed to the
2071 * formatter.
2072 *
2073 * Usage:
2074 *
2075 * 1) Call this function with the maximum
2076 * amount of DLGHITEM's that will need
2077 * to be allocated in cMaxItems. Set this
2078 * to the total sum of all DLGHITEM's
2079 * in all the subarrays.
2080 *
2081 * 2) For each of the subarrays, call
2082 * dlghAppendToArray to have the subarray
2083 * appended to the dialog array.
2084 * After each call, DLGARRAY.cDlgItemsNow
2085 * will contain the actual total count of
2086 * DLGHITEM's that were added.
2087 *
2088 * 3) Call dlghCreateDialog with the dialog
2089 * array.
2090 *
2091 * 4) Call dlghFreeArray.
2092 *
2093 * Sort of like this (error checking omitted):
2094 *
2095 + DLGHITEM dlgSampleFront = ... // always included
2096 + DLGHITEM dlgSampleSometimes = ... // not always included
2097 + DLGHITEM dlgSampleTail = ... // always included
2098 +
2099 + PDLGARRAY pArraySample = NULL;
2100 + dlghCreateArray( ARRAYITEMCOUNT(dlgSampleFront)
2101 + + ARRAYITEMCOUNT(dlgSampleSometimes)
2102 + + ARRAYITEMCOUNT(dlgSampleTail),
2103 + &pArraySample);
2104 +
2105 + // always include front
2106 + dlghAppendToArray(pArraySample,
2107 + dlgSampleFront,
2108 + ARRAYITEMCOUNT(dlgSampleFront));
2109 + // include "sometimes" conditionally
2110 + if (...)
2111 + dlghAppendToArray(pArraySample,
2112 + dlgSampleSometimes,
2113 + ARRAYITEMCOUNT(dlgSampleSometimes));
2114 + // include tail always
2115 + dlghAppendToArray(pArraySample,
2116 + dlgSampleTail,
2117 + ARRAYITEMCOUNT(dlgSampleTail));
2118 +
2119 + // now create the dialog from the array
2120 + dlghCreateDialog(&hwndDlg,
2121 + hwndOwner,
2122 + FCF_ ...
2123 + fnwpMyDialogProc,
2124 + "Title",
2125 + pArray->paDialogItems, // dialog array!
2126 + pArray->cDlgItemsNow, // real count of items!
2127 + NULL,
2128 + NULL);
2129 +
2130 + dlghFreeArray(&pArraySample);
2131 *
2132 *@@added V0.9.16 (2001-10-15) [umoeller]
2133 */
2134
2135APIRET dlghCreateArray(ULONG cMaxItems,
2136 PDLGARRAY *ppArray) // out: DLGARRAY
2137{
2138 APIRET arc = NO_ERROR;
2139 PDLGARRAY pArray;
2140
2141 if (pArray = NEW(DLGARRAY))
2142 {
2143 ULONG cb;
2144
2145 ZERO(pArray);
2146 if ( (cb = cMaxItems * sizeof(DLGHITEM))
2147 && (pArray->paDlgItems = (DLGHITEM*)malloc(cb))
2148 )
2149 {
2150 memset(pArray->paDlgItems, 0, cb);
2151 pArray->cDlgItemsMax = cMaxItems;
2152 *ppArray = pArray;
2153 }
2154 else
2155 arc = ERROR_NOT_ENOUGH_MEMORY;
2156
2157 if (arc)
2158 dlghFreeArray(&pArray);
2159 }
2160 else
2161 arc = ERROR_NOT_ENOUGH_MEMORY;
2162
2163 return arc;
2164}
2165
2166/*
2167 *@@ dlghFreeArray:
2168 * frees a dialog array created by dlghCreateArray.
2169 *
2170 *@@added V0.9.16 (2001-10-15) [umoeller]
2171 */
2172
2173APIRET dlghFreeArray(PDLGARRAY *ppArray)
2174{
2175 PDLGARRAY pArray;
2176 if ( (ppArray)
2177 && (pArray = *ppArray)
2178 )
2179 {
2180 if (pArray->paDlgItems)
2181 free(pArray->paDlgItems);
2182 free(pArray);
2183 }
2184 else
2185 return ERROR_INVALID_PARAMETER;
2186
2187 return NO_ERROR;
2188}
2189
2190/*
2191 *@@ dlghAppendToArray:
2192 * appends a subarray of DLGHITEM's to the
2193 * given DLGARRAY. See dlghCreateArray for
2194 * usage.
2195 *
2196 * Returns:
2197 *
2198 * -- NO_ERROR
2199 *
2200 * -- ERROR_INVALID_PARAMETER
2201 *
2202 * -- DLGERR_ARRAY_TOO_SMALL: pArray does not
2203 * have enough memory to hold the new items.
2204 * The cMaxItems parameter given to dlghCreateArray
2205 * wasn't large enough.
2206 *
2207 *@@added V0.9.16 (2001-10-15) [umoeller]
2208 */
2209
2210APIRET dlghAppendToArray(PDLGARRAY pArray, // in: dialog array created by dlghCreateArray
2211 DLGHITEM *paItems, // in: subarray to be appended
2212 ULONG cItems) // in: subarray item count (NOT array size)
2213{
2214 APIRET arc = NO_ERROR;
2215 if (pArray)
2216 {
2217 if ( (pArray->cDlgItemsMax >= cItems)
2218 && (pArray->cDlgItemsMax - pArray->cDlgItemsNow >= cItems)
2219 )
2220 {
2221 // enough space left in the array:
2222 memcpy(&pArray->paDlgItems[pArray->cDlgItemsNow],
2223 paItems, // source
2224 cItems * sizeof(DLGHITEM));
2225 pArray->cDlgItemsNow += cItems;
2226 }
2227 else
2228 arc = DLGERR_ARRAY_TOO_SMALL;
2229 }
2230 else
2231 arc = ERROR_INVALID_PARAMETER;
2232
2233 return (arc);
2234}
2235
2236/* ******************************************************************
2237 *
2238 * Standard dialogs
2239 *
2240 ********************************************************************/
2241
2242/*
2243 *@@ dlghCreateMessageBox:
2244 *
2245 *@@added V0.9.13 (2001-06-21) [umoeller]
2246 *@@changed V0.9.14 (2001-07-26) [umoeller]: fixed missing focus on buttons
2247 */
2248
2249APIRET dlghCreateMessageBox(HWND *phwndDlg,
2250 HWND hwndOwner,
2251 HPOINTER hptrIcon,
2252 const char *pcszTitle,
2253 const char *pcszMessage,
2254 ULONG flFlags,
2255 const char *pcszFont,
2256 const MSGBOXSTRINGS *pStrings,
2257 PULONG pulAlarmFlag) // out: alarm sound to be played
2258{
2259 CONTROLDEF
2260 Icon = {
2261 WC_STATIC,
2262 NULL, // text, set below
2263 WS_VISIBLE | SS_ICON,
2264 0, // ID
2265 NULL, // no font
2266 0,
2267 { SZL_AUTOSIZE, SZL_AUTOSIZE },
2268 5
2269 },
2270 InfoText =
2271 {
2272 WC_STATIC,
2273 NULL, // text, set below
2274 WS_VISIBLE | SS_TEXT | DT_WORDBREAK | DT_LEFT | DT_TOP,
2275 10, // ID
2276 CTL_COMMON_FONT,
2277 0,
2278 { 400, SZL_AUTOSIZE },
2279 5
2280 },
2281 Buttons[] = {
2282 {
2283 WC_BUTTON,
2284 NULL, // text, set below
2285 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
2286 1, // ID
2287 CTL_COMMON_FONT, // no font
2288 0,
2289 { 100, 30 },
2290 5
2291 },
2292 {
2293 WC_BUTTON,
2294 NULL, // text, set below
2295 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
2296 2, // ID
2297 CTL_COMMON_FONT, // no font
2298 0,
2299 { 100, 30 },
2300 5
2301 },
2302 {
2303 WC_BUTTON,
2304 NULL, // text, set below
2305 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
2306 3, // ID
2307 CTL_COMMON_FONT, // no font
2308 0,
2309 { 100, 30 },
2310 5
2311 }
2312 };
2313
2314 DLGHITEM MessageBox[] =
2315 {
2316 START_TABLE,
2317 START_ROW(ROW_VALIGN_CENTER),
2318 CONTROL_DEF(&Icon),
2319 START_TABLE,
2320 START_ROW(ROW_VALIGN_CENTER),
2321 CONTROL_DEF(&InfoText),
2322 START_ROW(ROW_VALIGN_CENTER),
2323 CONTROL_DEF(&Buttons[0]),
2324 CONTROL_DEF(&Buttons[1]),
2325 CONTROL_DEF(&Buttons[2]),
2326 END_TABLE,
2327 END_TABLE
2328 };
2329
2330 ULONG flButtons = flFlags & 0xF; // low nibble contains MB_YESNO etc.
2331
2332 const char *p0 = "Error",
2333 *p1 = NULL,
2334 *p2 = NULL;
2335
2336 Icon.pcszText = (const char *)hptrIcon;
2337 InfoText.pcszText = pcszMessage;
2338
2339 // now work on the three buttons of the dlg template:
2340 // give them proper titles or hide them
2341 if (flButtons == MB_OK)
2342 {
2343 p0 = pStrings->pcszOK;
2344 }
2345 else if (flButtons == MB_OKCANCEL)
2346 {
2347 p0 = pStrings->pcszOK;
2348 p1 = pStrings->pcszCancel;
2349 }
2350 else if (flButtons == MB_RETRYCANCEL)
2351 {
2352 p0 = pStrings->pcszRetry;
2353 p1 = pStrings->pcszCancel;
2354 }
2355 else if (flButtons == MB_ABORTRETRYIGNORE)
2356 {
2357 p0 = pStrings->pcszAbort;
2358 p1 = pStrings->pcszRetry;
2359 p2 = pStrings->pcszIgnore;
2360 }
2361 else if (flButtons == MB_YESNO)
2362 {
2363 p0 = pStrings->pcszYes;
2364 p1 = pStrings->pcszNo;
2365 }
2366 else if (flButtons == MB_YESNOCANCEL)
2367 {
2368 p0 = pStrings->pcszYes;
2369 p1 = pStrings->pcszNo;
2370 p2 = pStrings->pcszCancel;
2371 }
2372 else if (flButtons == MB_CANCEL)
2373 {
2374 p0 = pStrings->pcszCancel;
2375 }
2376 else if (flButtons == MB_ENTER)
2377 {
2378 p0 = pStrings->pcszEnter;
2379 }
2380 else if (flButtons == MB_ENTERCANCEL)
2381 {
2382 p0 = pStrings->pcszEnter;
2383 p1 = pStrings->pcszCancel;
2384 }
2385 else if (flButtons == MB_YES_YES2ALL_NO)
2386 {
2387 p0 = pStrings->pcszYes;
2388 p1 = pStrings->pcszYesToAll;
2389 p2 = pStrings->pcszNo;
2390 }
2391
2392 // now set strings and hide empty buttons
2393 Buttons[0].pcszText = p0;
2394
2395 if (p1)
2396 Buttons[1].pcszText = p1;
2397 else
2398 Buttons[1].flStyle &= ~WS_VISIBLE;
2399
2400 if (p2)
2401 Buttons[2].pcszText = p2;
2402 else
2403 Buttons[2].flStyle &= ~WS_VISIBLE;
2404
2405 // query default button IDs
2406 if (flFlags & MB_DEFBUTTON2)
2407 Buttons[1].flStyle |= BS_DEFAULT;
2408 else if (flFlags & MB_DEFBUTTON3)
2409 Buttons[2].flStyle |= BS_DEFAULT;
2410 else
2411 Buttons[0].flStyle |= BS_DEFAULT;
2412
2413 *pulAlarmFlag = WA_NOTE;
2414 if (flFlags & (MB_ICONHAND | MB_ERROR))
2415 *pulAlarmFlag = WA_ERROR;
2416 else if (flFlags & (MB_ICONEXCLAMATION | MB_WARNING))
2417 *pulAlarmFlag = WA_WARNING;
2418
2419 return (dlghCreateDlg(phwndDlg,
2420 hwndOwner,
2421 FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN,
2422 WinDefDlgProc,
2423 pcszTitle,
2424 MessageBox,
2425 ARRAYITEMCOUNT(MessageBox),
2426 NULL,
2427 pcszFont));
2428}
2429
2430/*
2431 *@@ dlghProcessMessageBox:
2432 *
2433 *@@added V0.9.13 (2001-06-21) [umoeller]
2434 */
2435
2436ULONG dlghProcessMessageBox(HWND hwndDlg,
2437 ULONG ulAlarmFlag,
2438 ULONG flFlags)
2439{
2440 ULONG ulrcDlg;
2441 ULONG flButtons = flFlags & 0xF; // low nibble contains MB_YESNO etc.
2442
2443 winhCenterWindow(hwndDlg);
2444
2445 if (flFlags & MB_SYSTEMMODAL)
2446 WinSetSysModalWindow(HWND_DESKTOP, hwndDlg);
2447
2448 if (ulAlarmFlag)
2449 WinAlarm(HWND_DESKTOP, ulAlarmFlag);
2450
2451 ulrcDlg = WinProcessDlg(hwndDlg);
2452
2453 WinDestroyWindow(hwndDlg);
2454
2455 if (flButtons == MB_OK)
2456 return MBID_OK;
2457 else if (flButtons == MB_OKCANCEL)
2458 switch (ulrcDlg)
2459 {
2460 case 1: return MBID_OK;
2461 default: return MBID_CANCEL;
2462 }
2463 else if (flButtons == MB_RETRYCANCEL)
2464 switch (ulrcDlg)
2465 {
2466 case 1: return MBID_RETRY;
2467 default: return MBID_CANCEL;
2468 }
2469 else if (flButtons == MB_ABORTRETRYIGNORE)
2470 switch (ulrcDlg)
2471 {
2472 case 2: return MBID_RETRY;
2473 case 3: return MBID_IGNORE;
2474 default: return MBID_ABORT;
2475 }
2476 else if (flButtons == MB_YESNO)
2477 switch (ulrcDlg)
2478 {
2479 case 1: return MBID_YES;
2480 default: return MBID_NO;
2481 }
2482 else if (flButtons == MB_YESNOCANCEL)
2483 switch (ulrcDlg)
2484 {
2485 case 1: return MBID_YES;
2486 case 2: return MBID_NO;
2487 default: return MBID_CANCEL;
2488 }
2489 else if (flButtons == MB_CANCEL)
2490 return MBID_CANCEL;
2491 else if (flButtons == MB_ENTER)
2492 return MBID_ENTER;
2493 else if (flButtons == MB_ENTERCANCEL)
2494 switch (ulrcDlg)
2495 {
2496 case 1: return MBID_ENTER;
2497 default: return MBID_CANCEL;
2498 }
2499 else if (flButtons == MB_YES_YES2ALL_NO)
2500 switch (ulrcDlg)
2501 {
2502 case 1: return MBID_YES;
2503 case 2: return MBID_YES2ALL;
2504 default: return MBID_NO;
2505 }
2506
2507 return (MBID_CANCEL);
2508}
2509
2510/*
2511 *@@ dlghMessageBox:
2512 * WinMessageBox replacement.
2513 *
2514 * This has all the flags of the standard call,
2515 * but looks much prettier. Besides, it allows
2516 * you to specify any icon to be displayed.
2517 *
2518 * Currently the following flStyle's are supported:
2519 *
2520 * -- MB_OK 0x0000
2521 * -- MB_OKCANCEL 0x0001
2522 * -- MB_RETRYCANCEL 0x0002
2523 * -- MB_ABORTRETRYIGNORE 0x0003
2524 * -- MB_YESNO 0x0004
2525 * -- MB_YESNOCANCEL 0x0005
2526 * -- MB_CANCEL 0x0006
2527 * -- MB_ENTER 0x0007 (not implemented yet)
2528 * -- MB_ENTERCANCEL 0x0008 (not implemented yet)
2529 *
2530 * -- MB_YES_YES2ALL_NO 0x0009
2531 * This is new: this has three buttons called "Yes"
2532 * (MBID_YES), "Yes to all" (MBID_YES2ALL), "No" (MBID_NO).
2533 *
2534 * -- MB_DEFBUTTON2 (for two-button styles)
2535 * -- MB_DEFBUTTON3 (for three-button styles)
2536 *
2537 * -- MB_ICONHAND
2538 * -- MB_ICONEXCLAMATION
2539 *
2540 * Returns MBID_* codes like WinMessageBox.
2541 *
2542 *@@added V0.9.13 (2001-06-21) [umoeller]
2543 */
2544
2545ULONG dlghMessageBox(HWND hwndOwner, // in: owner for msg box
2546 HPOINTER hptrIcon, // in: icon to display
2547 const char *pcszTitle, // in: title
2548 const char *pcszMessage, // in: message
2549 ULONG flFlags, // in: standard message box flags
2550 const char *pcszFont, // in: font (e.g. "9.WarpSans")
2551 const MSGBOXSTRINGS *pStrings) // in: strings array
2552{
2553 HWND hwndDlg;
2554 ULONG ulAlarmFlag;
2555 APIRET arc = dlghCreateMessageBox(&hwndDlg,
2556 hwndOwner,
2557 hptrIcon,
2558 pcszTitle,
2559 pcszMessage,
2560 flFlags,
2561 pcszFont,
2562 pStrings,
2563 &ulAlarmFlag);
2564
2565 if (!arc && hwndDlg)
2566 {
2567 // SHOW DIALOG
2568 return (dlghProcessMessageBox(hwndDlg,
2569 ulAlarmFlag,
2570 flFlags));
2571 }
2572 else
2573 {
2574 CHAR szMsg[100];
2575 sprintf(szMsg, "dlghCreateMessageBox reported error %u.", arc);
2576 WinMessageBox(HWND_DESKTOP,
2577 NULLHANDLE,
2578 "Error",
2579 szMsg,
2580 0,
2581 MB_CANCEL | MB_MOVEABLE);
2582 }
2583
2584 return (DID_CANCEL);
2585}
2586
2587/*
2588 *@@ cmnTextEntryBox:
2589 * common dialog for entering a text string.
2590 * The dialog has a descriptive text on top
2591 * with an entry field below and "OK" and "Cancel"
2592 * buttons.
2593 *
2594 * The string from the user is returned in a
2595 * new buffer, which must be free'd by the caller.
2596 * Returns NULL if the user pressed "Cancel".
2597 *
2598 * fl can be any combination of the following
2599 * flags:
2600 *
2601 * -- TEBF_REMOVETILDE: tilde ("~") characters
2602 * are removed from pcszTitle before setting
2603 * the title. Useful for reusing menu item
2604 * texts.
2605 *
2606 * -- TEBF_REMOVEELLIPSE: ellipse ("...") strings
2607 * are removed from pcszTitle before setting
2608 * the title. Useful for reusing menu item
2609 * texts.
2610 *
2611 * -- TEBF_SELECTALL: the default text in the
2612 * entry field is initially highlighted.
2613 *
2614 *@@added V0.9.15 (2001-09-14) [umoeller]
2615 */
2616
2617PSZ dlghTextEntryBox(HWND hwndOwner,
2618 const char *pcszTitle, // in: dlg title
2619 const char *pcszDescription, // in: descriptive text above entry field
2620 const char *pcszDefault, // in: default text for entry field or NULL
2621 const char *pcszOK, // in: "OK" string
2622 const char *pcszCancel, // in: "Cancel" string
2623 ULONG ulMaxLen, // in: maximum length for entry
2624 ULONG fl, // in: TEBF_* flags
2625 const char *pcszFont) // in: font (e.g. "9.WarpSans")
2626{
2627 CONTROLDEF
2628 Static = {
2629 WC_STATIC,
2630 NULL,
2631 WS_VISIBLE | SS_TEXT | DT_LEFT | DT_WORDBREAK,
2632 -1,
2633 CTL_COMMON_FONT,
2634 0,
2635 { 300, SZL_AUTOSIZE }, // size
2636 5 // spacing
2637 },
2638 Entry = {
2639 WC_ENTRYFIELD,
2640 NULL,
2641 WS_VISIBLE | WS_TABSTOP | ES_LEFT | ES_MARGIN | ES_AUTOSCROLL,
2642 999,
2643 CTL_COMMON_FONT,
2644 0,
2645 { 300, 20 }, // size
2646 5 // spacing
2647 },
2648 OKButton = {
2649 WC_BUTTON,
2650 NULL,
2651 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_DEFAULT,
2652 DID_OK,
2653 CTL_COMMON_FONT,
2654 0,
2655 { 100, 30 }, // size
2656 5 // spacing
2657 },
2658 CancelButton = {
2659 WC_BUTTON,
2660 NULL,
2661 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
2662 DID_CANCEL,
2663 CTL_COMMON_FONT,
2664 0,
2665 { 100, 30 }, // size
2666 5 // spacing
2667 };
2668 DLGHITEM DlgTemplate[] =
2669 {
2670 START_TABLE,
2671 START_ROW(0),
2672 CONTROL_DEF(&Static),
2673 START_ROW(0),
2674 CONTROL_DEF(&Entry),
2675 START_ROW(0),
2676 CONTROL_DEF(&OKButton),
2677 CONTROL_DEF(&CancelButton),
2678 END_TABLE
2679 };
2680
2681 HWND hwndDlg = NULLHANDLE;
2682 PSZ pszReturn = NULL;
2683 XSTRING strTitle;
2684
2685 xstrInitCopy(&strTitle, pcszTitle, 0);
2686
2687 if (fl & (TEBF_REMOVEELLIPSE | TEBF_REMOVETILDE))
2688 {
2689 ULONG ulOfs;
2690 if (fl & TEBF_REMOVEELLIPSE)
2691 {
2692 ulOfs = 0;
2693 while (xstrFindReplaceC(&strTitle,
2694 &ulOfs,
2695 "...",
2696 ""))
2697 ;
2698 }
2699
2700 if (fl & TEBF_REMOVETILDE)
2701 {
2702 ulOfs = 0;
2703 while (xstrFindReplaceC(&strTitle,
2704 &ulOfs,
2705 "~",
2706 ""))
2707 ;
2708 }
2709 }
2710
2711 Static.pcszText = pcszDescription;
2712
2713 OKButton.pcszText = pcszOK;
2714 CancelButton.pcszText = pcszCancel;
2715
2716 if (NO_ERROR == dlghCreateDlg(&hwndDlg,
2717 hwndOwner,
2718 FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN,
2719 WinDefDlgProc,
2720 strTitle.psz,
2721 DlgTemplate, // DLGHITEM array
2722 ARRAYITEMCOUNT(DlgTemplate),
2723 NULL,
2724 pcszFont))
2725 {
2726 HWND hwndEF = WinWindowFromID(hwndDlg, 999);
2727 winhCenterWindow(hwndDlg);
2728 winhSetEntryFieldLimit(hwndEF, ulMaxLen);
2729 if (pcszDefault)
2730 {
2731 WinSetWindowText(hwndEF, (PSZ)pcszDefault);
2732 if (fl & TEBF_SELECTALL)
2733 winhEntryFieldSelectAll(hwndEF);
2734 }
2735 WinSetFocus(HWND_DESKTOP, hwndEF);
2736 if (DID_OK == WinProcessDlg(hwndDlg))
2737 pszReturn = winhQueryWindowText(hwndEF);
2738
2739 WinDestroyWindow(hwndDlg);
2740 }
2741
2742 xstrClear(&strTitle);
2743
2744 return (pszReturn);
2745}
2746
2747/* ******************************************************************
2748 *
2749 * Dialog input handlers
2750 *
2751 ********************************************************************/
2752
2753/*
2754 *@@ dlghSetPrevFocus:
2755 * "backward" function for rotating the focus
2756 * in a dialog when the "shift+tab" keys get
2757 * pressed.
2758 *
2759 * pllWindows must be a linked list with the
2760 * plain HWND window handles of the focussable
2761 * controls in the dialog.
2762 */
2763
2764VOID dlghSetPrevFocus(PVOID pvllWindows)
2765{
2766 PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
2767
2768 // check current focus
2769 HWND hwndFocus = WinQueryFocus(HWND_DESKTOP);
2770
2771 PLISTNODE pNode = lstNodeFromItem(pllWindows, (PVOID)hwndFocus);
2772
2773 BOOL fRestart = FALSE;
2774
2775 while (pNode)
2776 {
2777 CHAR szClass[100];
2778
2779 // previos node
2780 pNode = pNode->pPrevious;
2781
2782 if ( (!pNode) // no next, or not found:
2783 && (!fRestart) // avoid infinite looping if bad list
2784 )
2785 {
2786 pNode = lstQueryLastNode(pllWindows);
2787 fRestart = TRUE;
2788 }
2789
2790 if (pNode)
2791 {
2792 // check if this is a focusable control
2793 if (WinQueryClassName((HWND)pNode->pItemData,
2794 sizeof(szClass),
2795 szClass))
2796 {
2797 if ( (strcmp(szClass, "#5")) // not static
2798 )
2799 break;
2800 // else: go for next then
2801 }
2802 }
2803 }
2804
2805 if (pNode)
2806 {
2807 WinSetFocus(HWND_DESKTOP,
2808 (HWND)pNode->pItemData);
2809 }
2810}
2811
2812/*
2813 *@@ dlghSetNextFocus:
2814 * "forward" function for rotating the focus
2815 * in a dialog when the "ab" key gets pressed.
2816 *
2817 * pllWindows must be a linked list with the
2818 * plain HWND window handles of the focussable
2819 * controls in the dialog.
2820 */
2821
2822VOID dlghSetNextFocus(PVOID pvllWindows)
2823{
2824 PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
2825
2826 // check current focus
2827 HWND hwndFocus = WinQueryFocus(HWND_DESKTOP);
2828
2829 PLISTNODE pNode = lstNodeFromItem(pllWindows, (PVOID)hwndFocus);
2830
2831 BOOL fRestart = FALSE;
2832
2833 while (pNode)
2834 {
2835 CHAR szClass[100];
2836
2837 // next focus in node
2838 pNode = pNode->pNext;
2839
2840 if ( (!pNode) // no next, or not found:
2841 && (!fRestart) // avoid infinite looping if bad list
2842 )
2843 {
2844 pNode = lstQueryFirstNode(pllWindows);
2845 fRestart = TRUE;
2846 }
2847
2848 if (pNode)
2849 {
2850 // check if this is a focusable control
2851 if (WinQueryClassName((HWND)pNode->pItemData,
2852 sizeof(szClass),
2853 szClass))
2854 {
2855 if ( (strcmp(szClass, "#5")) // not static
2856 )
2857 break;
2858 // else: go for next then
2859 }
2860 }
2861 }
2862
2863 if (pNode)
2864 {
2865 WinSetFocus(HWND_DESKTOP,
2866 (HWND)pNode->pItemData);
2867 }
2868}
2869
2870/*
2871 *@@ dlghProcessMnemonic:
2872 * finds the control which matches usch
2873 * and gives it the focus. If this is a
2874 * static control, the next control in the
2875 * list is given focus instead. (Standard
2876 * dialog behavior.)
2877 *
2878 * Pass in usch from WM_CHAR. It is assumed
2879 * that the caller has already tested for
2880 * the "alt" key to be depressed.
2881 *
2882 *@@added V0.9.9 (2001-03-17) [umoeller]
2883 */
2884
2885HWND dlghProcessMnemonic(PVOID pvllWindows,
2886 USHORT usch)
2887{
2888 PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
2889
2890 HWND hwndFound = NULLHANDLE;
2891 PLISTNODE pNode = lstQueryFirstNode(pllWindows);
2892 CHAR szClass[100];
2893
2894 while (pNode)
2895 {
2896 HWND hwnd = (HWND)pNode->pItemData;
2897
2898 if (WinSendMsg(hwnd,
2899 WM_MATCHMNEMONIC,
2900 (MPARAM)usch,
2901 0))
2902 {
2903 // according to the docs, only buttons and static
2904 // return TRUE to that msg;
2905 // if this is a static, give focus to the next
2906 // control
2907
2908 // _Pmpf((__FUNCTION__ ": hwnd 0x%lX", hwnd));
2909
2910 // check if this is a focusable control
2911 if (WinQueryClassName(hwnd,
2912 sizeof(szClass),
2913 szClass))
2914 {
2915 if (!strcmp(szClass, "#3"))
2916 // it's a button: click it
2917 WinSendMsg(hwnd, BM_CLICK, (MPARAM)TRUE, 0);
2918 else if (!strcmp(szClass, "#5"))
2919 {
2920 // it's a static: give focus to following control
2921 pNode = pNode->pNext;
2922 if (pNode)
2923 WinSetFocus(HWND_DESKTOP, (HWND)pNode->pItemData);
2924 }
2925 }
2926 else
2927 // any other control (are there any?): give them focus
2928 WinSetFocus(HWND_DESKTOP, hwnd);
2929
2930 // in any case, stop
2931 hwndFound = hwnd;
2932 break;
2933 }
2934
2935 pNode = pNode->pNext;
2936 }
2937
2938 return (hwndFound);
2939}
2940
2941/*
2942 *@@ dlghEnter:
2943 * presses the first button with BS_DEFAULT.
2944 */
2945
2946BOOL dlghEnter(PVOID pvllWindows)
2947{
2948 PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
2949
2950 PLISTNODE pNode = lstQueryFirstNode(pllWindows);
2951 CHAR szClass[100];
2952 while (pNode)
2953 {
2954 HWND hwnd = (HWND)pNode->pItemData;
2955 if (WinQueryClassName(hwnd,
2956 sizeof(szClass),
2957 szClass))
2958 {
2959 if (!strcmp(szClass, "#3")) // button
2960 {
2961 // _Pmpf((__FUNCTION__ ": found button"));
2962 if ( (WinQueryWindowULong(hwnd, QWL_STYLE) & (BS_PUSHBUTTON | BS_DEFAULT))
2963 == (BS_PUSHBUTTON | BS_DEFAULT)
2964 )
2965 {
2966 // _Pmpf((" is default!"));
2967 WinPostMsg(hwnd,
2968 BM_CLICK,
2969 (MPARAM)TRUE, // upclick
2970 0);
2971 return (TRUE);
2972 }
2973 }
2974 }
2975
2976 pNode = pNode->pNext;
2977 }
2978
2979 return (FALSE);
2980}
2981
2982
Note: See TracBrowser for help on using the repository browser.