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 Mller.
|
---|
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_WINBUTTONS
|
---|
51 | #define INCL_WINSTATICS
|
---|
52 | #define INCL_WINSYS
|
---|
53 |
|
---|
54 | #define INCL_GPIPRIMITIVES
|
---|
55 | #define INCL_GPIBITMAPS
|
---|
56 | #define INCL_GPILCIDS
|
---|
57 | #include <os2.h>
|
---|
58 |
|
---|
59 | #include <stdlib.h>
|
---|
60 | #include <string.h>
|
---|
61 | #include <stdio.h>
|
---|
62 |
|
---|
63 | #include "setup.h" // code generation and debugging options
|
---|
64 |
|
---|
65 | #include "helpers\comctl.h"
|
---|
66 | #include "helpers\dialog.h"
|
---|
67 | #include "helpers\gpih.h"
|
---|
68 | #include "helpers\linklist.h"
|
---|
69 | #include "helpers\standards.h"
|
---|
70 | #include "helpers\stringh.h"
|
---|
71 | #include "helpers\winh.h"
|
---|
72 |
|
---|
73 | /*
|
---|
74 | *@@category: Helpers\PM helpers\Dialog templates
|
---|
75 | */
|
---|
76 |
|
---|
77 | /* ******************************************************************
|
---|
78 | *
|
---|
79 | * Private declarations
|
---|
80 | *
|
---|
81 | ********************************************************************/
|
---|
82 |
|
---|
83 | /*
|
---|
84 | *@@ DLGPRIVATE:
|
---|
85 | * private data to the dlg manager, allocated
|
---|
86 | * by dlghCreateDlg. This is what is really
|
---|
87 | * used, even though the prototype only
|
---|
88 | * declares DIALOGDATA.
|
---|
89 | *
|
---|
90 | * This only exists while the dialog is being
|
---|
91 | * created and is not stored with the new dialog.
|
---|
92 | */
|
---|
93 |
|
---|
94 | typedef struct _DLGPRIVATE
|
---|
95 | {
|
---|
96 | // public data
|
---|
97 | HWND hwndDlg;
|
---|
98 |
|
---|
99 | // definition data (private)
|
---|
100 | LINKLIST llTables;
|
---|
101 |
|
---|
102 | HWND hwndFirstFocus;
|
---|
103 |
|
---|
104 | POINTL ptlTotalOfs;
|
---|
105 |
|
---|
106 | LINKLIST llControls; // linked list of all PCOLUMNDEF structs,
|
---|
107 | // in the order in which windows were
|
---|
108 | // created
|
---|
109 |
|
---|
110 | const char *pcszControlsFont; // from dlghCreateDlg
|
---|
111 |
|
---|
112 | HPS hps;
|
---|
113 | /* const char *pcszFontLast;
|
---|
114 | LONG lcidLast; */
|
---|
115 | } DLGPRIVATE, *PDLGPRIVATE;
|
---|
116 |
|
---|
117 | typedef struct _COLUMNDEF *PCOLUMNDEF;
|
---|
118 | typedef struct _ROWDEF *PROWDEF;
|
---|
119 | typedef struct _TABLEDEF *PTABLEDEF;
|
---|
120 |
|
---|
121 | /*
|
---|
122 | *@@ CONTROLPOS:
|
---|
123 | * control position. We don't want to use SWP.
|
---|
124 | */
|
---|
125 |
|
---|
126 | typedef struct _CONTROLPOS
|
---|
127 | {
|
---|
128 | LONG x,
|
---|
129 | y,
|
---|
130 | cx,
|
---|
131 | cy;
|
---|
132 | } CONTROLPOS, *PCONTROLPOS;
|
---|
133 |
|
---|
134 | /*
|
---|
135 | *@@ COLUMNDEF:
|
---|
136 | * representation of a table column.
|
---|
137 | * This is stored in a linked list in ROWDEF.
|
---|
138 | *
|
---|
139 | * A table column represents either a PM control
|
---|
140 | * window or another table, which may therefore
|
---|
141 | * be nested.
|
---|
142 | */
|
---|
143 |
|
---|
144 | typedef struct _COLUMNDEF
|
---|
145 | {
|
---|
146 | PROWDEF pOwningRow; // row whose linked list this column belongs to
|
---|
147 |
|
---|
148 | BOOL fIsNestedTable; // if TRUE, pvDefinition points to a nested TABLEDEF;
|
---|
149 | // if FALSE, pvDefinition points to a CONTROLDEF as
|
---|
150 | // specified by the user
|
---|
151 |
|
---|
152 | PVOID pvDefinition; // either a PTABLEDEF or a PCONTROLDEF
|
---|
153 |
|
---|
154 | CONTROLPOS cpControl, // real pos and size of control
|
---|
155 | cpColumn; // pos and size of column; can be wider, spacings applied
|
---|
156 |
|
---|
157 | HWND hwndControl; // created control; NULLHANDLE for tables always
|
---|
158 |
|
---|
159 | } COLUMNDEF;
|
---|
160 |
|
---|
161 | /*
|
---|
162 | *@@ ROWDEF:
|
---|
163 | *
|
---|
164 | */
|
---|
165 |
|
---|
166 | typedef struct _ROWDEF
|
---|
167 | {
|
---|
168 | PTABLEDEF pOwningTable; // table whose linked list this row belongs to
|
---|
169 |
|
---|
170 | LINKLIST llColumns; // contains COLUMNDEF structs, no auto-free
|
---|
171 |
|
---|
172 | ULONG flRowFormat; // one of:
|
---|
173 | // -- ROW_VALIGN_BOTTOM 0x0000
|
---|
174 | // -- ROW_VALIGN_CENTER 0x0001
|
---|
175 | // -- ROW_VALIGN_TOP 0x0002
|
---|
176 |
|
---|
177 | CONTROLPOS cpRow;
|
---|
178 |
|
---|
179 | } ROWDEF;
|
---|
180 |
|
---|
181 | /*
|
---|
182 | *@@ TABLEDEF:
|
---|
183 | *
|
---|
184 | */
|
---|
185 |
|
---|
186 | typedef struct _TABLEDEF
|
---|
187 | {
|
---|
188 | LINKLIST llRows; // contains ROWDEF structs, no auto-free
|
---|
189 |
|
---|
190 | PCONTROLDEF pCtlDef; // if != NULL, we create a PM control around the table
|
---|
191 |
|
---|
192 | CONTROLPOS cpTable;
|
---|
193 |
|
---|
194 | } TABLEDEF;
|
---|
195 |
|
---|
196 | /*
|
---|
197 | *@@ PROCESSMODE:
|
---|
198 | *
|
---|
199 | */
|
---|
200 |
|
---|
201 | typedef enum _PROCESSMODE
|
---|
202 | {
|
---|
203 | PROCESS_CALC_SIZES, // step 1
|
---|
204 | PROCESS_CALC_POSITIONS, // step 3
|
---|
205 | PROCESS_CREATE_CONTROLS // step 4
|
---|
206 | } PROCESSMODE;
|
---|
207 |
|
---|
208 | /* ******************************************************************
|
---|
209 | *
|
---|
210 | * Worker routines
|
---|
211 | *
|
---|
212 | ********************************************************************/
|
---|
213 |
|
---|
214 | #define PM_GROUP_SPACING_X 10
|
---|
215 | #define PM_GROUP_SPACING_TOP 20
|
---|
216 |
|
---|
217 | VOID ProcessTable(PTABLEDEF pTableDef,
|
---|
218 | const CONTROLPOS *pcpTable,
|
---|
219 | PROCESSMODE ProcessMode,
|
---|
220 | PDLGPRIVATE pDlgData);
|
---|
221 |
|
---|
222 | /*
|
---|
223 | *@@ CalcAutoSizeText:
|
---|
224 | *
|
---|
225 | *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed various things with statics
|
---|
226 | *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed broken fonts
|
---|
227 | */
|
---|
228 |
|
---|
229 | VOID CalcAutoSizeText(PCONTROLDEF pControlDef,
|
---|
230 | BOOL fMultiLine, // in: if TRUE, multiple lines
|
---|
231 | PSIZEL pszlAuto, // out: computed size
|
---|
232 | PDLGPRIVATE pDlgData)
|
---|
233 | {
|
---|
234 | BOOL fFind = FALSE;
|
---|
235 | RECTL rclText;
|
---|
236 | LONG lcid = 0;
|
---|
237 |
|
---|
238 | const char *pcszFontThis = pControlDef->pcszFont;
|
---|
239 | // can be NULL,
|
---|
240 | // or CTL_COMMON_FONT
|
---|
241 |
|
---|
242 | if (pcszFontThis == CTL_COMMON_FONT)
|
---|
243 | pcszFontThis = pDlgData->pcszControlsFont;
|
---|
244 |
|
---|
245 | if (!pDlgData->hps)
|
---|
246 | pDlgData->hps = WinGetPS(pDlgData->hwndDlg);
|
---|
247 |
|
---|
248 | if (pcszFontThis)
|
---|
249 | {
|
---|
250 | FONTMETRICS fm;
|
---|
251 | LONG lPointSize = 0;
|
---|
252 |
|
---|
253 | // create new font
|
---|
254 | lcid = gpihFindPresFont(NULLHANDLE, // no window yet
|
---|
255 | FALSE,
|
---|
256 | pDlgData->hps,
|
---|
257 | pcszFontThis,
|
---|
258 | &fm,
|
---|
259 | &lPointSize);
|
---|
260 | GpiSetCharSet(pDlgData->hps, lcid);
|
---|
261 | if (fm.fsDefn & FM_DEFN_OUTLINE)
|
---|
262 | gpihSetPointSize(pDlgData->hps, lPointSize);
|
---|
263 |
|
---|
264 | pszlAuto->cy = fm.lMaxBaselineExt + fm.lExternalLeading;
|
---|
265 | }
|
---|
266 |
|
---|
267 | // ok, we FINALLY have a font now...
|
---|
268 | // get the control string and see how much space it needs
|
---|
269 | if (pControlDef->pcszText)
|
---|
270 | {
|
---|
271 | // do we have multiple lines?
|
---|
272 | if (fMultiLine)
|
---|
273 | {
|
---|
274 | RECTL rcl = {0, 0, 0, 0};
|
---|
275 | if (pControlDef->szlControlProposed.cx != -1)
|
---|
276 | rcl.xRight = pControlDef->szlControlProposed.cx; // V0.9.12 (2001-05-31) [umoeller]
|
---|
277 | else
|
---|
278 | rcl.xRight = winhQueryScreenCX() * 2 / 3;
|
---|
279 | if (pControlDef->szlControlProposed.cy != -1)
|
---|
280 | rcl.yTop = pControlDef->szlControlProposed.cy; // V0.9.12 (2001-05-31) [umoeller]
|
---|
281 | else
|
---|
282 | rcl.yTop = winhQueryScreenCY() * 2 / 3;
|
---|
283 |
|
---|
284 | winhDrawFormattedText(pDlgData->hps,
|
---|
285 | &rcl,
|
---|
286 | pControlDef->pcszText,
|
---|
287 | DT_LEFT | DT_TOP | DT_WORDBREAK | DT_QUERYEXTENT);
|
---|
288 | pszlAuto->cx = rcl.xRight - rcl.xLeft;
|
---|
289 | pszlAuto->cy = rcl.yTop - rcl.yBottom;
|
---|
290 | }
|
---|
291 | else
|
---|
292 | {
|
---|
293 | POINTL aptl[TXTBOX_COUNT];
|
---|
294 | GpiQueryTextBox(pDlgData->hps,
|
---|
295 | strlen(pControlDef->pcszText),
|
---|
296 | (PCH)pControlDef->pcszText,
|
---|
297 | TXTBOX_COUNT,
|
---|
298 | aptl);
|
---|
299 | pszlAuto->cx = aptl[TXTBOX_TOPRIGHT].x - aptl[TXTBOX_BOTTOMLEFT].x;
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | /* if (lcid)
|
---|
304 | {
|
---|
305 | GpiSetCharSet(pDlgData->hps, LCID_DEFAULT);
|
---|
306 | GpiDeleteSetId(pDlgData->hps, lcid);
|
---|
307 | } */
|
---|
308 |
|
---|
309 | }
|
---|
310 |
|
---|
311 | /*
|
---|
312 | *@@ CalcAutoSize:
|
---|
313 | *
|
---|
314 | *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed various things with statics
|
---|
315 | */
|
---|
316 |
|
---|
317 | VOID CalcAutoSize(PCONTROLDEF pControlDef,
|
---|
318 | PSIZEL pszlAuto, // out: computed size
|
---|
319 | PDLGPRIVATE pDlgData)
|
---|
320 | {
|
---|
321 | // dumb defaults
|
---|
322 | pszlAuto->cx = 100;
|
---|
323 | pszlAuto->cy = 30;
|
---|
324 |
|
---|
325 | switch ((ULONG)pControlDef->pcszClass)
|
---|
326 | {
|
---|
327 | case 0xffff0003L: // WC_BUTTON:
|
---|
328 | CalcAutoSizeText(pControlDef,
|
---|
329 | FALSE, // no multiline
|
---|
330 | pszlAuto,
|
---|
331 | pDlgData);
|
---|
332 | if (pControlDef->flStyle & ( BS_AUTOCHECKBOX
|
---|
333 | | BS_AUTORADIOBUTTON
|
---|
334 | | BS_AUTO3STATE
|
---|
335 | | BS_3STATE
|
---|
336 | | BS_CHECKBOX
|
---|
337 | | BS_RADIOBUTTON))
|
---|
338 | pszlAuto->cx += 20; // @@todo
|
---|
339 | else if (pControlDef->flStyle & BS_BITMAP)
|
---|
340 | ;
|
---|
341 | else if (pControlDef->flStyle & (BS_ICON | BS_MINIICON))
|
---|
342 | ;
|
---|
343 | // we can't test for BS_PUSHBUTTON because that's 0x0000
|
---|
344 | else if (!(pControlDef->flStyle & BS_USERBUTTON))
|
---|
345 | {
|
---|
346 | pszlAuto->cx += (2 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER) + 15);
|
---|
347 | pszlAuto->cy += (2 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER) + 15);
|
---|
348 | }
|
---|
349 | break;
|
---|
350 |
|
---|
351 | case 0xffff0005L: // WC_STATIC:
|
---|
352 | if ((pControlDef->flStyle & 0x0F) == SS_TEXT)
|
---|
353 | CalcAutoSizeText(pControlDef,
|
---|
354 | ((pControlDef->flStyle & DT_WORDBREAK) != 0),
|
---|
355 | pszlAuto,
|
---|
356 | pDlgData);
|
---|
357 | else if ((pControlDef->flStyle & 0x0F) == SS_BITMAP)
|
---|
358 | {
|
---|
359 | HBITMAP hbm = (HBITMAP)pControlDef->pcszText;
|
---|
360 | if (hbm)
|
---|
361 | {
|
---|
362 | BITMAPINFOHEADER2 bmih2;
|
---|
363 | ZERO(&bmih2);
|
---|
364 | bmih2.cbFix = sizeof(bmih2);
|
---|
365 | if (GpiQueryBitmapInfoHeader(hbm,
|
---|
366 | &bmih2))
|
---|
367 | {
|
---|
368 | pszlAuto->cx = bmih2.cx;
|
---|
369 | pszlAuto->cy = bmih2.cy;
|
---|
370 | }
|
---|
371 | }
|
---|
372 | }
|
---|
373 | else if ((pControlDef->flStyle & 0x0F) == SS_ICON)
|
---|
374 | {
|
---|
375 | pszlAuto->cx = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);
|
---|
376 | pszlAuto->cy = WinQuerySysValue(HWND_DESKTOP, SV_CYICON);
|
---|
377 | }
|
---|
378 | break;
|
---|
379 | }
|
---|
380 | }
|
---|
381 |
|
---|
382 | /*
|
---|
383 | *@@ ProcessColumn:
|
---|
384 | * processes a column, which per definition is either
|
---|
385 | * a control or a nested subtable.
|
---|
386 | *
|
---|
387 | * A column is part of a row, which in turn is part
|
---|
388 | * of a table. There can be several columns in a row,
|
---|
389 | * and several rows in a table.
|
---|
390 | *
|
---|
391 | * Since tables may be specified as columns, it is
|
---|
392 | * possible to produce complex dialog layouts by
|
---|
393 | * nesting tables.
|
---|
394 | *
|
---|
395 | * This does the following:
|
---|
396 | *
|
---|
397 | * -- PROCESS_CALC_SIZES: size is taken from control def,
|
---|
398 | * or for tables, this produces a recursive ProcessTable
|
---|
399 | * call.
|
---|
400 | * Preconditions: none.
|
---|
401 | *
|
---|
402 | * -- PROCESS_CALC_POSITIONS: position of each column
|
---|
403 | * is taken from *plX, which is increased by the
|
---|
404 | * column width by this call.
|
---|
405 | *
|
---|
406 | * Preconditions: Owning row must already have its
|
---|
407 | * y position properly set, or we can't compute
|
---|
408 | * ours. Besides, plX must point to the current X
|
---|
409 | * in the row and will be incremented by the columns
|
---|
410 | * size here.
|
---|
411 | *
|
---|
412 | * -- PROCESS_CREATE_CONTROLS: well, creates the controls.
|
---|
413 | *
|
---|
414 | * For tables, this recurses again. If the table has
|
---|
415 | * a string assigned, this also produces a group box
|
---|
416 | * after the recursion.
|
---|
417 | *
|
---|
418 | *@@changed V0.9.12 (2001-05-31) [umoeller]: added control data
|
---|
419 | *@@changed V0.9.12 (2001-05-31) [umoeller]: fixed font problems
|
---|
420 | */
|
---|
421 |
|
---|
422 | VOID ProcessColumn(PCOLUMNDEF pColumnDef,
|
---|
423 | PROWDEF pOwningRow, // in: current row from ProcessRow
|
---|
424 | PROCESSMODE ProcessMode, // in: processing mode (see ProcessAll)
|
---|
425 | PLONG plX, // in/out: PROCESS_CALC_POSITIONS only
|
---|
426 | PDLGPRIVATE pDlgData)
|
---|
427 | {
|
---|
428 | pColumnDef->pOwningRow = pOwningRow;
|
---|
429 |
|
---|
430 | switch (ProcessMode)
|
---|
431 | {
|
---|
432 | /*
|
---|
433 | * PROCESS_CALC_SIZES:
|
---|
434 | * step 1.
|
---|
435 | */
|
---|
436 |
|
---|
437 | case PROCESS_CALC_SIZES:
|
---|
438 | {
|
---|
439 | ULONG ulXSpacing = 0,
|
---|
440 | ulYSpacing = 0;
|
---|
441 | if (pColumnDef->fIsNestedTable)
|
---|
442 | {
|
---|
443 | // nested table: recurse!!
|
---|
444 | PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
|
---|
445 | ProcessTable(pTableDef,
|
---|
446 | NULL,
|
---|
447 | ProcessMode,
|
---|
448 | pDlgData);
|
---|
449 |
|
---|
450 | // store the size of the sub-table
|
---|
451 | pColumnDef->cpControl.cx = pTableDef->cpTable.cx;
|
---|
452 | pColumnDef->cpControl.cy = pTableDef->cpTable.cy;
|
---|
453 |
|
---|
454 | // should we create a PM control around the table?
|
---|
455 | if (pTableDef->pCtlDef)
|
---|
456 | {
|
---|
457 | // yes: make this wider
|
---|
458 | ulXSpacing = (2 * PM_GROUP_SPACING_X);
|
---|
459 | ulYSpacing = (PM_GROUP_SPACING_X + PM_GROUP_SPACING_TOP);
|
---|
460 | }
|
---|
461 | }
|
---|
462 | else
|
---|
463 | {
|
---|
464 | // no nested table, but control:
|
---|
465 | PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
|
---|
466 | PSIZEL pszl = &pControlDef->szlControlProposed;
|
---|
467 | SIZEL szlAuto;
|
---|
468 |
|
---|
469 | if ( (pszl->cx == -1)
|
---|
470 | || (pszl->cy == -1)
|
---|
471 | )
|
---|
472 | {
|
---|
473 | CalcAutoSize(pControlDef,
|
---|
474 | &szlAuto,
|
---|
475 | pDlgData);
|
---|
476 | }
|
---|
477 |
|
---|
478 | if (pszl->cx == -1)
|
---|
479 | pColumnDef->cpControl.cx = szlAuto.cx;
|
---|
480 | else
|
---|
481 | pColumnDef->cpControl.cx = pszl->cx;
|
---|
482 |
|
---|
483 | if (pszl->cy == -1)
|
---|
484 | pColumnDef->cpControl.cy = szlAuto.cy;
|
---|
485 | else
|
---|
486 | pColumnDef->cpControl.cy = pszl->cy;
|
---|
487 |
|
---|
488 | // @@todo hack sizes
|
---|
489 |
|
---|
490 | ulXSpacing = ulYSpacing = (2 * pControlDef->ulSpacing);
|
---|
491 | }
|
---|
492 |
|
---|
493 | pColumnDef->cpColumn.cx = pColumnDef->cpControl.cx
|
---|
494 | + ulXSpacing;
|
---|
495 | pColumnDef->cpColumn.cy = pColumnDef->cpControl.cy
|
---|
496 | + ulYSpacing;
|
---|
497 | break; }
|
---|
498 |
|
---|
499 | /*
|
---|
500 | * PROCESS_CALC_POSITIONS:
|
---|
501 | * step 2.
|
---|
502 | */
|
---|
503 |
|
---|
504 | case PROCESS_CALC_POSITIONS:
|
---|
505 | {
|
---|
506 | // calculate column position: this includes spacing
|
---|
507 | ULONG ulSpacing = 0;
|
---|
508 |
|
---|
509 | // column position = *plX on ProcessRow stack
|
---|
510 | pColumnDef->cpColumn.x = *plX;
|
---|
511 | pColumnDef->cpColumn.y = pOwningRow->cpRow.y;
|
---|
512 |
|
---|
513 | // check vertical alignment of row;
|
---|
514 | // we might need to increase column y
|
---|
515 | switch (pOwningRow->flRowFormat & ROW_VALIGN_MASK)
|
---|
516 | {
|
---|
517 | // case ROW_VALIGN_BOTTOM: // do nothing
|
---|
518 |
|
---|
519 | case ROW_VALIGN_CENTER:
|
---|
520 | if (pColumnDef->cpColumn.cy < pOwningRow->cpRow.cy)
|
---|
521 | pColumnDef->cpColumn.y
|
---|
522 | += ( (pOwningRow->cpRow.cy - pColumnDef->cpColumn.cy)
|
---|
523 | / 2);
|
---|
524 | break;
|
---|
525 |
|
---|
526 | case ROW_VALIGN_TOP:
|
---|
527 | if (pColumnDef->cpColumn.cy < pOwningRow->cpRow.cy)
|
---|
528 | pColumnDef->cpColumn.y
|
---|
529 | += (pOwningRow->cpRow.cy - pColumnDef->cpColumn.cy);
|
---|
530 | break;
|
---|
531 | }
|
---|
532 |
|
---|
533 | if (pColumnDef->fIsNestedTable)
|
---|
534 | {
|
---|
535 | PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
|
---|
536 | // should we create a PM control around the table?
|
---|
537 | if (pTableDef->pCtlDef)
|
---|
538 | // yes:
|
---|
539 | ulSpacing = PM_GROUP_SPACING_X;
|
---|
540 | }
|
---|
541 | else
|
---|
542 | {
|
---|
543 | // no nested table, but control:
|
---|
544 | PCONTROLDEF pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
|
---|
545 | ulSpacing = pControlDef->ulSpacing;
|
---|
546 | }
|
---|
547 |
|
---|
548 | // increase plX by column width
|
---|
549 | *plX += pColumnDef->cpColumn.cx;
|
---|
550 |
|
---|
551 | // calculate CONTROL pos from COLUMN pos by applying spacing
|
---|
552 | pColumnDef->cpControl.x = pColumnDef->cpColumn.x
|
---|
553 | + ulSpacing;
|
---|
554 | pColumnDef->cpControl.y = pColumnDef->cpColumn.y
|
---|
555 | + ulSpacing;
|
---|
556 |
|
---|
557 | if (pColumnDef->fIsNestedTable)
|
---|
558 | {
|
---|
559 | // nested table:
|
---|
560 | PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
|
---|
561 |
|
---|
562 | // recurse!! to create windows for the sub-table
|
---|
563 | ProcessTable(pTableDef,
|
---|
564 | &pColumnDef->cpControl, // start pos for new table
|
---|
565 | ProcessMode,
|
---|
566 | pDlgData);
|
---|
567 | }
|
---|
568 | break; }
|
---|
569 |
|
---|
570 | /*
|
---|
571 | * PROCESS_CREATE_CONTROLS:
|
---|
572 | * step 3.
|
---|
573 | */
|
---|
574 |
|
---|
575 | case PROCESS_CREATE_CONTROLS:
|
---|
576 | {
|
---|
577 | PCONTROLPOS pcp = NULL;
|
---|
578 | PCONTROLDEF pControlDef = NULL;
|
---|
579 | const char *pcszTitle = NULL;
|
---|
580 | ULONG flStyle = 0;
|
---|
581 | LHANDLE lHandleSet = NULLHANDLE;
|
---|
582 | ULONG flOld = 0;
|
---|
583 |
|
---|
584 | if (pColumnDef->fIsNestedTable)
|
---|
585 | {
|
---|
586 | // nested table:
|
---|
587 | PTABLEDEF pTableDef = (PTABLEDEF)pColumnDef->pvDefinition;
|
---|
588 |
|
---|
589 | // recurse!!
|
---|
590 | ProcessTable(pTableDef,
|
---|
591 | NULL,
|
---|
592 | ProcessMode,
|
---|
593 | pDlgData);
|
---|
594 |
|
---|
595 | // should we create a PM control around the table?
|
---|
596 | // (do this AFTER the other controls from recursing,
|
---|
597 | // otherwise the stupid container doesn't show up)
|
---|
598 | if (pTableDef->pCtlDef)
|
---|
599 | {
|
---|
600 | // yes:
|
---|
601 | pcp = &pColumnDef->cpColumn; // !! not control
|
---|
602 | pControlDef = pTableDef->pCtlDef;
|
---|
603 | pcszTitle = pControlDef->pcszText;
|
---|
604 | flStyle = pControlDef->flStyle;
|
---|
605 | }
|
---|
606 | }
|
---|
607 | else
|
---|
608 | {
|
---|
609 | // no nested table, but control:
|
---|
610 | pControlDef = (PCONTROLDEF)pColumnDef->pvDefinition;
|
---|
611 | pcp = &pColumnDef->cpControl;
|
---|
612 | pcszTitle = pControlDef->pcszText;
|
---|
613 | flStyle = pControlDef->flStyle;
|
---|
614 |
|
---|
615 | // change the title if this is a static with SS_BITMAP;
|
---|
616 | // we have used a HBITMAP in there!
|
---|
617 | if ( ((ULONG)pControlDef->pcszClass == 0xffff0005L) // WC_STATIC:
|
---|
618 | && ( ((flStyle & 0x0F) == SS_BITMAP)
|
---|
619 | || ((flStyle & 0x0F) == SS_ICON)
|
---|
620 | )
|
---|
621 | )
|
---|
622 | {
|
---|
623 | // change style flag to not use SS_BITMAP nor SS_ICON;
|
---|
624 | // control creation fails otherwise (stupid, stupid PM)
|
---|
625 | flOld = flStyle;
|
---|
626 | flStyle = ((flStyle & ~0x0F) | SS_FGNDFRAME);
|
---|
627 | pcszTitle = "";
|
---|
628 | lHandleSet = (LHANDLE)pControlDef->pcszText;
|
---|
629 | }
|
---|
630 | }
|
---|
631 |
|
---|
632 | if (pcp && pControlDef)
|
---|
633 | {
|
---|
634 | // create something:
|
---|
635 | // PPRESPARAMS ppp = NULL;
|
---|
636 |
|
---|
637 | const char *pcszFont = pControlDef->pcszFont;
|
---|
638 | // can be NULL, or CTL_COMMON_FONT
|
---|
639 | if (pcszFont == CTL_COMMON_FONT)
|
---|
640 | pcszFont = pDlgData->pcszControlsFont;
|
---|
641 |
|
---|
642 | /* if (pcszFont)
|
---|
643 | winhStorePresParam(&ppp,
|
---|
644 | PP_FONTNAMESIZE,
|
---|
645 | strlen(pcszFont),
|
---|
646 | (PVOID)pcszFont); */
|
---|
647 |
|
---|
648 | pColumnDef->hwndControl
|
---|
649 | = WinCreateWindow(pDlgData->hwndDlg, // parent
|
---|
650 | (PSZ)pControlDef->pcszClass,
|
---|
651 | (pcszTitle) // hacked
|
---|
652 | ? (PSZ)pcszTitle
|
---|
653 | : "",
|
---|
654 | flStyle, // hacked
|
---|
655 | pcp->x + pDlgData->ptlTotalOfs.x,
|
---|
656 | pcp->y + pDlgData->ptlTotalOfs.y,
|
---|
657 | pcp->cx,
|
---|
658 | pcp->cy,
|
---|
659 | pDlgData->hwndDlg, // owner
|
---|
660 | HWND_BOTTOM,
|
---|
661 | pControlDef->usID,
|
---|
662 | pControlDef->pvCtlData,
|
---|
663 | NULL); // ppp);
|
---|
664 |
|
---|
665 | if ((pColumnDef->hwndControl) && (lHandleSet))
|
---|
666 | {
|
---|
667 | // subclass the damn static
|
---|
668 | if ((flOld & 0x0F) == SS_ICON)
|
---|
669 | // this was a static:
|
---|
670 | ctlPrepareStaticIcon(pColumnDef->hwndControl,
|
---|
671 | 1);
|
---|
672 | else
|
---|
673 | // this was a bitmap:
|
---|
674 | ctlPrepareStretchedBitmap(pColumnDef->hwndControl,
|
---|
675 | TRUE);
|
---|
676 |
|
---|
677 | WinSendMsg(pColumnDef->hwndControl,
|
---|
678 | SM_SETHANDLE,
|
---|
679 | (MPARAM)lHandleSet,
|
---|
680 | 0);
|
---|
681 | }
|
---|
682 | else
|
---|
683 | if (pcszFont)
|
---|
684 | // we must set the font explicitly here...
|
---|
685 | // doesn't always work with WinCreateWindow
|
---|
686 | // presparams parameter, for some reason
|
---|
687 | // V0.9.12 (2001-05-31) [umoeller]
|
---|
688 | winhSetWindowFont(pColumnDef->hwndControl,
|
---|
689 | pcszFont);
|
---|
690 |
|
---|
691 | if (pColumnDef->hwndControl)
|
---|
692 | {
|
---|
693 | lstAppendItem(&pDlgData->llControls,
|
---|
694 | pColumnDef);
|
---|
695 |
|
---|
696 | // if this is the first control with WS_TABSTOP,
|
---|
697 | // we give it the focus later
|
---|
698 | if ( (flStyle & WS_TABSTOP)
|
---|
699 | && (!pDlgData->hwndFirstFocus)
|
---|
700 | )
|
---|
701 | pDlgData->hwndFirstFocus = pColumnDef->hwndControl;
|
---|
702 | }
|
---|
703 | }
|
---|
704 | break; }
|
---|
705 | }
|
---|
706 |
|
---|
707 | }
|
---|
708 |
|
---|
709 | /*
|
---|
710 | *@@ ProcessRow:
|
---|
711 | * level-3 procedure (called from ProcessTable),
|
---|
712 | * which in turn calls ProcessColumn for each column
|
---|
713 | * in the row.
|
---|
714 | *
|
---|
715 | * See ProcessAll for the meaning of ProcessMode.
|
---|
716 | */
|
---|
717 |
|
---|
718 | VOID ProcessRow(PROWDEF pRowDef,
|
---|
719 | PTABLEDEF pOwningTable, // in: current table from ProcessTable
|
---|
720 | PROCESSMODE ProcessMode, // in: processing mode (see ProcessAll)
|
---|
721 | PLONG plY, // in/out: current y position (decremented)
|
---|
722 | PDLGPRIVATE pDlgData)
|
---|
723 | {
|
---|
724 | ULONG ul;
|
---|
725 | LONG lX;
|
---|
726 | PLISTNODE pNode;
|
---|
727 |
|
---|
728 | pRowDef->pOwningTable = pOwningTable;
|
---|
729 |
|
---|
730 | if (ProcessMode == PROCESS_CALC_SIZES)
|
---|
731 | {
|
---|
732 | pRowDef->cpRow.cx = 0;
|
---|
733 | pRowDef->cpRow.cy = 0;
|
---|
734 | }
|
---|
735 | else if (ProcessMode == PROCESS_CALC_POSITIONS)
|
---|
736 | {
|
---|
737 | // set up x and y so that the columns can
|
---|
738 | // base on that
|
---|
739 | pRowDef->cpRow.x = pOwningTable->cpTable.x;
|
---|
740 | // decrease y by row height
|
---|
741 | *plY -= pRowDef->cpRow.cy;
|
---|
742 | // and use that for our bottom position
|
---|
743 | pRowDef->cpRow.y = *plY;
|
---|
744 |
|
---|
745 | // set lX to left of row; used by column calls below
|
---|
746 | lX = pRowDef->cpRow.x;
|
---|
747 | }
|
---|
748 |
|
---|
749 | FOR_ALL_NODES(&pRowDef->llColumns, pNode)
|
---|
750 | {
|
---|
751 | PCOLUMNDEF pColumnDefThis = (PCOLUMNDEF)pNode->pItemData;
|
---|
752 |
|
---|
753 | ProcessColumn(pColumnDefThis, pRowDef, ProcessMode, &lX, pDlgData);
|
---|
754 |
|
---|
755 | if (ProcessMode == PROCESS_CALC_SIZES)
|
---|
756 | {
|
---|
757 | // row width = sum of all columns
|
---|
758 | pRowDef->cpRow.cx += pColumnDefThis->cpColumn.cx;
|
---|
759 |
|
---|
760 | // row height = maximum height of a column
|
---|
761 | if (pRowDef->cpRow.cy < pColumnDefThis->cpColumn.cy)
|
---|
762 | pRowDef->cpRow.cy = pColumnDefThis->cpColumn.cy;
|
---|
763 | }
|
---|
764 | }
|
---|
765 | }
|
---|
766 |
|
---|
767 | /*
|
---|
768 | *@@ ProcessTable:
|
---|
769 | * level-2 procedure (called from ProcessAll),
|
---|
770 | * which in turn calls ProcessRow for each row
|
---|
771 | * in the table (which in turn calls ProcessColumn
|
---|
772 | * for each column in the row).
|
---|
773 | *
|
---|
774 | * See ProcessAll for the meaning of ProcessMode.
|
---|
775 | *
|
---|
776 | * This routine is a bit sick because it can even be
|
---|
777 | * called recursively from ProcessColumn (!) if a
|
---|
778 | * nested table is found in a COLUMNDEF.
|
---|
779 | *
|
---|
780 | * With PROCESS_CALC_POSITIONS, pptl must specify
|
---|
781 | * the lower left corner of the table. For the
|
---|
782 | * root call, this will be {0, 0}; for nested calls,
|
---|
783 | * this must be the lower left corner of the column
|
---|
784 | * to which the nested table belongs.
|
---|
785 | *
|
---|
786 | */
|
---|
787 |
|
---|
788 | VOID ProcessTable(PTABLEDEF pTableDef,
|
---|
789 | const CONTROLPOS *pcpTable, // in: table position with PROCESS_CALC_POSITIONS
|
---|
790 | PROCESSMODE ProcessMode, // in: processing mode (see ProcessAll)
|
---|
791 | PDLGPRIVATE pDlgData)
|
---|
792 | {
|
---|
793 | ULONG ul;
|
---|
794 | LONG lY;
|
---|
795 | PLISTNODE pNode;
|
---|
796 |
|
---|
797 | if (ProcessMode == PROCESS_CALC_SIZES)
|
---|
798 | {
|
---|
799 | pTableDef->cpTable.cx = 0;
|
---|
800 | pTableDef->cpTable.cy = 0;
|
---|
801 | }
|
---|
802 | else if (ProcessMode == PROCESS_CALC_POSITIONS)
|
---|
803 | {
|
---|
804 | pTableDef->cpTable.x = pcpTable->x;
|
---|
805 | pTableDef->cpTable.y = pcpTable->y;
|
---|
806 |
|
---|
807 | // start the rows on top
|
---|
808 | lY = pcpTable->y + pTableDef->cpTable.cy;
|
---|
809 | }
|
---|
810 |
|
---|
811 | FOR_ALL_NODES(&pTableDef->llRows, pNode)
|
---|
812 | {
|
---|
813 | PROWDEF pRowDefThis = (PROWDEF)pNode->pItemData;
|
---|
814 |
|
---|
815 | ProcessRow(pRowDefThis, pTableDef, ProcessMode, &lY, pDlgData);
|
---|
816 |
|
---|
817 | if (ProcessMode == PROCESS_CALC_SIZES)
|
---|
818 | {
|
---|
819 | // table width = maximum width of a row
|
---|
820 | if (pTableDef->cpTable.cx < pRowDefThis->cpRow.cx)
|
---|
821 | pTableDef->cpTable.cx = pRowDefThis->cpRow.cx;
|
---|
822 |
|
---|
823 | // table height = sum of all rows
|
---|
824 | pTableDef->cpTable.cy += pRowDefThis->cpRow.cy;
|
---|
825 | }
|
---|
826 | }
|
---|
827 | }
|
---|
828 |
|
---|
829 | /*
|
---|
830 | *@@ ProcessAll:
|
---|
831 | * level-1 procedure, which in turn calls ProcessTable
|
---|
832 | * for each root-level table found (which in turn
|
---|
833 | * calls ProcessRow for each row in the table, which
|
---|
834 | * in turn calls ProcessColumn for each column in
|
---|
835 | * the row).
|
---|
836 | *
|
---|
837 | * The first trick to formatting is that ProcessAll will
|
---|
838 | * get three times, thus going down the entire tree three
|
---|
839 | * times, with ProcessMode being set to one of the
|
---|
840 | * following for each call (in this order):
|
---|
841 | *
|
---|
842 | * -- PROCESS_CALC_SIZES: calculates the sizes
|
---|
843 | * of all tables, rows, columns, and controls.
|
---|
844 | *
|
---|
845 | * After this first call, we know all the sizes
|
---|
846 | * only and then then calculate the positions.
|
---|
847 | *
|
---|
848 | * -- PROCESS_CALC_POSITIONS: calculates the positions
|
---|
849 | * based on the sizes calculated before.
|
---|
850 | *
|
---|
851 | * -- PROCESS_CREATE_CONTROLS: creates the controls with the
|
---|
852 | * positions and sizes calculated before.
|
---|
853 | *
|
---|
854 | * The second trick is the precondition that tables may
|
---|
855 | * nest by allowing a table definition instead of a
|
---|
856 | * control definition in a column. This way we can
|
---|
857 | * recurse from columns back into tables and thus
|
---|
858 | * know the size and position of a nested table column
|
---|
859 | * just as if it were a regular control.
|
---|
860 | */
|
---|
861 |
|
---|
862 | VOID ProcessAll(PDLGPRIVATE pDlgData,
|
---|
863 | PSIZEL pszlClient,
|
---|
864 | PROCESSMODE ProcessMode)
|
---|
865 | {
|
---|
866 | ULONG ul;
|
---|
867 | PLISTNODE pNode;
|
---|
868 | CONTROLPOS cpTable;
|
---|
869 | ZERO(&cpTable);
|
---|
870 |
|
---|
871 | switch (ProcessMode)
|
---|
872 | {
|
---|
873 | case PROCESS_CALC_SIZES:
|
---|
874 | pszlClient->cx = 0;
|
---|
875 | pszlClient->cy = 0;
|
---|
876 | break;
|
---|
877 |
|
---|
878 | case PROCESS_CALC_POSITIONS:
|
---|
879 | // start with the table on top
|
---|
880 | cpTable.y = pszlClient->cy;
|
---|
881 | break;
|
---|
882 | }
|
---|
883 |
|
---|
884 | FOR_ALL_NODES(&pDlgData->llTables, pNode)
|
---|
885 | {
|
---|
886 | PTABLEDEF pTableDefThis = (PTABLEDEF)pNode->pItemData;
|
---|
887 |
|
---|
888 | if (ProcessMode == PROCESS_CALC_POSITIONS)
|
---|
889 | {
|
---|
890 | cpTable.x = 0;
|
---|
891 | cpTable.y -= pTableDefThis->cpTable.cy;
|
---|
892 | }
|
---|
893 |
|
---|
894 | ProcessTable(pTableDefThis,
|
---|
895 | &cpTable, // start pos
|
---|
896 | ProcessMode,
|
---|
897 | pDlgData);
|
---|
898 |
|
---|
899 | if (ProcessMode == PROCESS_CALC_SIZES)
|
---|
900 | {
|
---|
901 | pszlClient->cx += pTableDefThis->cpTable.cx;
|
---|
902 | pszlClient->cy += pTableDefThis->cpTable.cy;
|
---|
903 | }
|
---|
904 | }
|
---|
905 | }
|
---|
906 |
|
---|
907 | /*
|
---|
908 | *@@ CreateColumn:
|
---|
909 | *
|
---|
910 | */
|
---|
911 |
|
---|
912 | APIRET CreateColumn(PROWDEF pCurrentRow,
|
---|
913 | BOOL fIsNestedTable,
|
---|
914 | PVOID pvDefinition, // in: either PTABLEDEF or PCONTROLDEF
|
---|
915 | PCOLUMNDEF *ppColumnDef) // out: new COLUMNDEF
|
---|
916 | {
|
---|
917 | APIRET arc = NO_ERROR;
|
---|
918 |
|
---|
919 | if (!pCurrentRow)
|
---|
920 | arc = DLGERR_CONTROL_BEFORE_ROW;
|
---|
921 | else
|
---|
922 | {
|
---|
923 | // append the control def
|
---|
924 | if (!pvDefinition)
|
---|
925 | arc = DLGERR_NULL_CTL_DEF;
|
---|
926 | else
|
---|
927 | {
|
---|
928 | // create column and store ctl def
|
---|
929 | PCOLUMNDEF pColumnDef = NEW(COLUMNDEF);
|
---|
930 | if (!pColumnDef)
|
---|
931 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
932 | else
|
---|
933 | {
|
---|
934 | memset(pColumnDef, 0, sizeof(COLUMNDEF));
|
---|
935 | pColumnDef->pOwningRow = pCurrentRow;
|
---|
936 | pColumnDef->fIsNestedTable = fIsNestedTable;
|
---|
937 | pColumnDef->pvDefinition = pvDefinition;
|
---|
938 |
|
---|
939 | *ppColumnDef = pColumnDef;
|
---|
940 | }
|
---|
941 | }
|
---|
942 | }
|
---|
943 |
|
---|
944 | return (arc);
|
---|
945 | }
|
---|
946 |
|
---|
947 | /* ******************************************************************
|
---|
948 | *
|
---|
949 | * Public APIs
|
---|
950 | *
|
---|
951 | ********************************************************************/
|
---|
952 |
|
---|
953 | /*
|
---|
954 | *@@ STACKITEM:
|
---|
955 | *
|
---|
956 | */
|
---|
957 |
|
---|
958 | typedef struct _STACKITEM
|
---|
959 | {
|
---|
960 | PTABLEDEF pLastTable;
|
---|
961 | PROWDEF pLastRow;
|
---|
962 |
|
---|
963 | } STACKITEM, *PSTACKITEM;
|
---|
964 |
|
---|
965 | /*
|
---|
966 | *@@ dlghCreateDlg:
|
---|
967 | * replacement for WinCreateDlg/WinLoadDlg for creating a
|
---|
968 | * dialog from a settings array in memory, which is
|
---|
969 | * formatted automatically.
|
---|
970 | *
|
---|
971 | * This does NOT use regular dialog templates from
|
---|
972 | * module resources. Instead, you pass in an array
|
---|
973 | * of _DLGHITEM structures, which define the controls
|
---|
974 | * and how they are to be formatted.
|
---|
975 | *
|
---|
976 | * A regular standard dialog would use something like
|
---|
977 | *
|
---|
978 | + FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN
|
---|
979 | *
|
---|
980 | * for flCreateFlags. To make the dlg sizeable, specify
|
---|
981 | * FCF_SIZEBORDER instead of FCF_DLGBORDER.
|
---|
982 | *
|
---|
983 | * <B>Usage:</B>
|
---|
984 | *
|
---|
985 | * Like WinLoadDlg, this creates a standard WC_FRAME and
|
---|
986 | * subclasses it with fnwpMyDlgProc. It then sends WM_INITDLG
|
---|
987 | * to the dialog with pCreateParams in mp2.
|
---|
988 | *
|
---|
989 | * If this func returns no error, you can then use
|
---|
990 | * WinProcessDlg with the newly created dialog as usual. In
|
---|
991 | * your dlg proc, use WinDefDlgProc as usual.
|
---|
992 | *
|
---|
993 | * There is NO run-time overhead after creation; after this
|
---|
994 | * function returns, the dialog is a standard dialog as if
|
---|
995 | * loaded from WinLoadDlg.
|
---|
996 | *
|
---|
997 | * The array of _DLGHITEM structures defines how the
|
---|
998 | * dialog is set up. All this is ONLY used by this function
|
---|
999 | * and NOT needed after the dialog has been created.
|
---|
1000 | *
|
---|
1001 | * In _DLGHITEM, the "Type" field determines what this
|
---|
1002 | * structure defines. A number of handy macros have been
|
---|
1003 | * defined to make this easier and to provide type-checking
|
---|
1004 | * at compile time.
|
---|
1005 | *
|
---|
1006 | * Essentially, such a dialog item operates similarly to
|
---|
1007 | * HTML tables. There are rows and columns in the table,
|
---|
1008 | * and each control which is specified must be a column
|
---|
1009 | * in some table. Tables may also nest (see below).
|
---|
1010 | *
|
---|
1011 | * The macros are:
|
---|
1012 | *
|
---|
1013 | * -- START_TABLE starts a new table. The tables may nest,
|
---|
1014 | * but must each be properly terminated with END_TABLE.
|
---|
1015 | *
|
---|
1016 | * -- START_GROUP_TABLE(pDef) starts a group. This
|
---|
1017 | * behaves exacly like START_TABLE, but in addition,
|
---|
1018 | * it produces a static group control around the table.
|
---|
1019 | * Useful for group boxes. pDef must point to a
|
---|
1020 | * _CONTROLDEF describing the control to be used for
|
---|
1021 | * the group (usually a WC_STATIC with SS_GROUP style),
|
---|
1022 | * whose size parameter is ignored.
|
---|
1023 | *
|
---|
1024 | * As with START_TABLE, START_GROUP_TABLE must be
|
---|
1025 | * terminated with END_TABLE.
|
---|
1026 | *
|
---|
1027 | * -- START_ROW(fl) starts a new row in a table (regular
|
---|
1028 | * or group). This must also be the first item after
|
---|
1029 | * the (group) table tag.
|
---|
1030 | *
|
---|
1031 | * fl specifies formatting flags for the row. This
|
---|
1032 | * can be one of ROW_VALIGN_BOTTOM, ROW_VALIGN_CENTER,
|
---|
1033 | * ROW_VALIGN_TOP and affects all items in the control.
|
---|
1034 | *
|
---|
1035 | * -- CONTROL_DEF(pDef) defines a control in a table row.
|
---|
1036 | * pDef must point to a _CONTROLDEF structure.
|
---|
1037 | *
|
---|
1038 | * The main difference (and advantage) of this
|
---|
1039 | * function is that there is NO information in
|
---|
1040 | * _CONTROLDEF about a control's _position_.
|
---|
1041 | * Instead, the structure only contains the _size_
|
---|
1042 | * of the control. All positions are computed by
|
---|
1043 | * this function, depending on the sizes of the
|
---|
1044 | * controls and their nesting within the various tables.
|
---|
1045 | *
|
---|
1046 | * If you specify SZL_AUTOSIZE, the size of the
|
---|
1047 | * control is even computed automatically. Presently,
|
---|
1048 | * this only works for statics with SS_TEXT, SS_ICON,
|
---|
1049 | * and SS_BITMAP.
|
---|
1050 | *
|
---|
1051 | * Unless separated with START_ROW items, subsequent
|
---|
1052 | * control items will be considered to be in the same
|
---|
1053 | * row (== positioned next to each other).
|
---|
1054 | *
|
---|
1055 | * There are a few rules, whose violation will produce
|
---|
1056 | * an error:
|
---|
1057 | *
|
---|
1058 | * -- The entire array must be enclosed in a table
|
---|
1059 | * (the "root" table).
|
---|
1060 | *
|
---|
1061 | * -- After START_TABLE or START_GROUP_TABLE, there must
|
---|
1062 | * always be a START_ROW first.
|
---|
1063 | *
|
---|
1064 | * To create a dialog, set up arrays like the following:
|
---|
1065 | *
|
---|
1066 | + // control definitions referenced by DlgTemplate:
|
---|
1067 | + CONTROLDEF
|
---|
1068 | + (1) GroupDef = {
|
---|
1069 | + WC_STATIC, "", ....,
|
---|
1070 | + { 0, 0 }, // size, ignored for groups
|
---|
1071 | + 5 // spacing
|
---|
1072 | + },
|
---|
1073 | + (2) CnrDef = {
|
---|
1074 | + WC_CONTAINER, "", ....,
|
---|
1075 | + { 50, 50 }, // size
|
---|
1076 | + 5 // spacing
|
---|
1077 | + },
|
---|
1078 | + (3) Static = {
|
---|
1079 | + WC_STATIC, "Static below cnr", ...,
|
---|
1080 | + { SZL_AUTOSIZE, SZL_AUTOSIZE }, // size
|
---|
1081 | + 5 // spacing
|
---|
1082 | + },
|
---|
1083 | + (4) OKButton = {
|
---|
1084 | + WC_STATIC, "~OK", ...,
|
---|
1085 | + { 100, 30 }, // size
|
---|
1086 | + 5 // spacing
|
---|
1087 | + },
|
---|
1088 | + (5) CancelButton = {
|
---|
1089 | + WC_STATIC, "~Cancel", ...,
|
---|
1090 | + { 100, 30 }, // size
|
---|
1091 | + 5 // spacing
|
---|
1092 | + };
|
---|
1093 | +
|
---|
1094 | + DLGHITEM DlgTemplate[] =
|
---|
1095 | + {
|
---|
1096 | + START_TABLE, // root table, required
|
---|
1097 | + START_ROW(0), // row 1 in the root table, required
|
---|
1098 | + // create group on top
|
---|
1099 | + (1) START_GROUP_TABLE(&Group),
|
---|
1100 | + START_ROW(0),
|
---|
1101 | + (2) CONTROL_DEF(&CnrDef),
|
---|
1102 | + START_ROW(0),
|
---|
1103 | + (3) CONTROL_DEF(&Static),
|
---|
1104 | + END_TABLE, // end of group
|
---|
1105 | + START_ROW(0), // row 2 in the root table
|
---|
1106 | + // two buttons next to each other
|
---|
1107 | + (4) CONTROL_DEF(&OKButton),
|
---|
1108 | + (5) CONTROL_DEF(&CancelButton),
|
---|
1109 | + END_TABLE
|
---|
1110 | + }
|
---|
1111 | *
|
---|
1112 | * This will produce a dlg like this:
|
---|
1113 | *
|
---|
1114 | + ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
|
---|
1115 | + º º
|
---|
1116 | + º ÚÄ Group (1) ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ º
|
---|
1117 | + º ³ ³ º
|
---|
1118 | + º ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ º
|
---|
1119 | + º ³ ³ ³ ³ º
|
---|
1120 | + º ³ ³ Cnr inside group (2) ³ ³ º
|
---|
1121 | + º ³ ³ ³ ³ º
|
---|
1122 | + º ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ º
|
---|
1123 | + º ³ Static below cnr (3) ³ º
|
---|
1124 | + º ³ ³ º
|
---|
1125 | + º ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ º
|
---|
1126 | + º ÚÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ º
|
---|
1127 | + º ³ OK (4) ³ ³ Cancel (5) ³ º
|
---|
1128 | + º ÀÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ º
|
---|
1129 | + º º
|
---|
1130 | + ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ
|
---|
1131 | *
|
---|
1132 | * <B>Errors:</B>
|
---|
1133 | *
|
---|
1134 | * This does not return a HWND, but an APIRET. This will be
|
---|
1135 | * one of the following:
|
---|
1136 | *
|
---|
1137 | * -- NO_ERROR: only in that case, the phwndDlg ptr
|
---|
1138 | * receives the HWND of the new dialog, which can
|
---|
1139 | * then be given to WinProcessDlg. Don't forget
|
---|
1140 | * WinDestroyWindow.
|
---|
1141 | *
|
---|
1142 | * -- ERROR_NOT_ENOUGH_MEMORY
|
---|
1143 | *
|
---|
1144 | * -- DLGERR_ROW_BEFORE_TABLE: a row definition appeared
|
---|
1145 | * outside a table definition.
|
---|
1146 | *
|
---|
1147 | * -- DLGERR_CONTROL_BEFORE_ROW: a control definition
|
---|
1148 | * appeared right after a table definition. You must
|
---|
1149 | * specify a row first.
|
---|
1150 | *
|
---|
1151 | * -- DLGERR_NULL_CTL_DEF: TYPE_END_TABLE was specified,
|
---|
1152 | * but the CONTROLDEF ptr was NULL.
|
---|
1153 | *
|
---|
1154 | * -- DLGERR_CANNOT_CREATE_FRAME: unable to create the
|
---|
1155 | * WC_FRAME window. Maybe an invalid owner was specified.
|
---|
1156 | *
|
---|
1157 | * -- DLGERR_INVALID_CODE: invalid "Type" field in
|
---|
1158 | * DLGHITEM.
|
---|
1159 | *
|
---|
1160 | * -- DLGERR_TABLE_NOT_CLOSED, DLGERR_TOO_MANY_TABLES_CLOSED:
|
---|
1161 | * improper nesting of TYPE_START_NEW_TABLE and
|
---|
1162 | * TYPE_END_TABLE fields.
|
---|
1163 | *
|
---|
1164 | * <B>Example:</B>
|
---|
1165 | *
|
---|
1166 | * The typical calling sequence would be:
|
---|
1167 | *
|
---|
1168 | + HWND hwndDlg = NULLHANDLE;
|
---|
1169 | + if (NO_ERROR == dlghCreateDlg(&hwndDlg,
|
---|
1170 | + hwndOwner,
|
---|
1171 | + FCF_DLGBORDER | FCF_NOBYTEALIGN,
|
---|
1172 | + fnwpMyDlgProc,
|
---|
1173 | + "My Dlg Title",
|
---|
1174 | + DlgTemplate, // DLGHITEM array
|
---|
1175 | + ARRAYITEMCOUNT(DlgTemplate),
|
---|
1176 | + NULL))
|
---|
1177 | + {
|
---|
1178 | + ULONG idReturn = WinProcessDlg(hwndDlg);
|
---|
1179 | + WinDestroyWindow(hwndDlg);
|
---|
1180 | + }
|
---|
1181 | *
|
---|
1182 | *
|
---|
1183 | */
|
---|
1184 |
|
---|
1185 | APIRET dlghCreateDlg(HWND *phwndDlg, // out: new dialog
|
---|
1186 | HWND hwndOwner,
|
---|
1187 | ULONG flCreateFlags, // in: standard FCF_* frame flags
|
---|
1188 | PFNWP pfnwpDialogProc,
|
---|
1189 | const char *pcszDlgTitle,
|
---|
1190 | PDLGHITEM paDlgItems, // in: definition array
|
---|
1191 | ULONG cDlgItems, // in: array item count (NOT array size)
|
---|
1192 | PVOID pCreateParams, // in: for mp2 of WM_INITDLG
|
---|
1193 | const char *pcszControlsFont) // in: font for ctls with CTL_COMMON_FONT
|
---|
1194 | {
|
---|
1195 | APIRET arc = NO_ERROR;
|
---|
1196 |
|
---|
1197 | #define SPACING 10
|
---|
1198 |
|
---|
1199 | PTABLEDEF pCurrentTable = NULL;
|
---|
1200 | PROWDEF pCurrentRow = NULL;
|
---|
1201 | ULONG ul;
|
---|
1202 | LINKLIST llStack;
|
---|
1203 |
|
---|
1204 | PDLGPRIVATE pDlgData = NEW(DLGPRIVATE);
|
---|
1205 |
|
---|
1206 | if (!pDlgData)
|
---|
1207 | return (ERROR_NOT_ENOUGH_MEMORY);
|
---|
1208 |
|
---|
1209 | ZERO(pDlgData);
|
---|
1210 | lstInit(&pDlgData->llTables, FALSE);
|
---|
1211 | lstInit(&pDlgData->llControls, FALSE);
|
---|
1212 |
|
---|
1213 | pDlgData->pcszControlsFont = pcszControlsFont;
|
---|
1214 |
|
---|
1215 | /*
|
---|
1216 | * 1) parse the table and create structures from it
|
---|
1217 | *
|
---|
1218 | */
|
---|
1219 |
|
---|
1220 | lstInit(&llStack, TRUE); // this is our stack for nested table definitions
|
---|
1221 |
|
---|
1222 | for (ul = 0;
|
---|
1223 | ul < cDlgItems;
|
---|
1224 | ul++)
|
---|
1225 | {
|
---|
1226 | PDLGHITEM pItemThis = &paDlgItems[ul];
|
---|
1227 |
|
---|
1228 | switch (pItemThis->Type)
|
---|
1229 | {
|
---|
1230 | /*
|
---|
1231 | * TYPE_START_NEW_TABLE:
|
---|
1232 | *
|
---|
1233 | */
|
---|
1234 |
|
---|
1235 | case TYPE_START_NEW_TABLE:
|
---|
1236 | {
|
---|
1237 | // root table or nested?
|
---|
1238 | BOOL fIsRoot = (pCurrentTable == NULL);
|
---|
1239 |
|
---|
1240 | // push the current table on the stack
|
---|
1241 | PSTACKITEM pStackItem = NEW(STACKITEM);
|
---|
1242 | if (pStackItem)
|
---|
1243 | {
|
---|
1244 | pStackItem->pLastTable = pCurrentTable;
|
---|
1245 | pStackItem->pLastRow = pCurrentRow;
|
---|
1246 | lstPush(&llStack, pStackItem);
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | // create new table
|
---|
1250 | pCurrentTable = NEW(TABLEDEF);
|
---|
1251 | if (!pCurrentTable)
|
---|
1252 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
1253 | else
|
---|
1254 | {
|
---|
1255 | ZERO(pCurrentTable);
|
---|
1256 |
|
---|
1257 | lstInit(&pCurrentTable->llRows, FALSE);
|
---|
1258 |
|
---|
1259 | if (pItemThis->ulData)
|
---|
1260 | // control specified: store it (this will become a PM group)
|
---|
1261 | pCurrentTable->pCtlDef = (PCONTROLDEF)pItemThis->ulData;
|
---|
1262 |
|
---|
1263 | if (fIsRoot)
|
---|
1264 | // root table:
|
---|
1265 | // append to dialog data list
|
---|
1266 | lstAppendItem(&pDlgData->llTables, pCurrentTable);
|
---|
1267 | else
|
---|
1268 | {
|
---|
1269 | // nested table:
|
---|
1270 | // create "table" column for this
|
---|
1271 | PCOLUMNDEF pColumnDef;
|
---|
1272 | arc = CreateColumn(pCurrentRow,
|
---|
1273 | TRUE, // nested table
|
---|
1274 | pCurrentTable,
|
---|
1275 | &pColumnDef);
|
---|
1276 | if (!arc)
|
---|
1277 | lstAppendItem(&pCurrentRow->llColumns, pColumnDef);
|
---|
1278 | }
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | pCurrentRow = NULL;
|
---|
1282 | break; }
|
---|
1283 |
|
---|
1284 | /*
|
---|
1285 | * TYPE_START_NEW_ROW:
|
---|
1286 | *
|
---|
1287 | */
|
---|
1288 |
|
---|
1289 | case TYPE_START_NEW_ROW:
|
---|
1290 | {
|
---|
1291 | if (!pCurrentTable)
|
---|
1292 | arc = DLGERR_ROW_BEFORE_TABLE;
|
---|
1293 | else
|
---|
1294 | {
|
---|
1295 | // create new row
|
---|
1296 | pCurrentRow = NEW(ROWDEF);
|
---|
1297 | if (!pCurrentRow)
|
---|
1298 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
1299 | else
|
---|
1300 | {
|
---|
1301 | ZERO(pCurrentRow);
|
---|
1302 |
|
---|
1303 | pCurrentRow->pOwningTable = pCurrentTable;
|
---|
1304 | lstInit(&pCurrentRow->llColumns, FALSE);
|
---|
1305 |
|
---|
1306 | pCurrentRow->flRowFormat = pItemThis->ulData;
|
---|
1307 |
|
---|
1308 | lstAppendItem(&pCurrentTable->llRows, pCurrentRow);
|
---|
1309 | }
|
---|
1310 | }
|
---|
1311 | break; }
|
---|
1312 |
|
---|
1313 | /*
|
---|
1314 | * TYPE_CONTROL_DEF:
|
---|
1315 | *
|
---|
1316 | */
|
---|
1317 |
|
---|
1318 | case TYPE_CONTROL_DEF:
|
---|
1319 | {
|
---|
1320 | PCOLUMNDEF pColumnDef;
|
---|
1321 | arc = CreateColumn(pCurrentRow,
|
---|
1322 | FALSE, // no nested table
|
---|
1323 | (PVOID)pItemThis->ulData,
|
---|
1324 | &pColumnDef);
|
---|
1325 | if (!arc)
|
---|
1326 | lstAppendItem(&pCurrentRow->llColumns, pColumnDef);
|
---|
1327 | break; }
|
---|
1328 |
|
---|
1329 | /*
|
---|
1330 | * TYPE_END_TABLE:
|
---|
1331 | *
|
---|
1332 | */
|
---|
1333 |
|
---|
1334 | case TYPE_END_TABLE:
|
---|
1335 | {
|
---|
1336 | PLISTNODE pNode = lstPop(&llStack);
|
---|
1337 | if (!pNode)
|
---|
1338 | // nothing on the stack:
|
---|
1339 | arc = DLGERR_TOO_MANY_TABLES_CLOSED;
|
---|
1340 | else
|
---|
1341 | {
|
---|
1342 | PSTACKITEM pStackItem = (PSTACKITEM)pNode->pItemData;
|
---|
1343 | pCurrentTable = pStackItem->pLastTable;
|
---|
1344 | pCurrentRow = pStackItem->pLastRow;
|
---|
1345 |
|
---|
1346 | lstRemoveNode(&llStack, pNode);
|
---|
1347 | }
|
---|
1348 | break; }
|
---|
1349 |
|
---|
1350 | default:
|
---|
1351 | arc = DLGERR_INVALID_CODE;
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | if (arc)
|
---|
1355 | break;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | if (arc == NO_ERROR)
|
---|
1359 | if (lstCountItems(&llStack))
|
---|
1360 | arc = DLGERR_TABLE_NOT_CLOSED;
|
---|
1361 |
|
---|
1362 | lstClear(&llStack);
|
---|
1363 |
|
---|
1364 | if (arc == NO_ERROR)
|
---|
1365 | {
|
---|
1366 | /*
|
---|
1367 | * 2) create empty dialog frame
|
---|
1368 | *
|
---|
1369 | */
|
---|
1370 |
|
---|
1371 | FRAMECDATA fcData = {0};
|
---|
1372 | ULONG flStyle = 0;
|
---|
1373 |
|
---|
1374 | #define FCF_DIALOGBOX 0x40000000L
|
---|
1375 |
|
---|
1376 | fcData.cb = sizeof(FRAMECDATA);
|
---|
1377 | fcData.flCreateFlags = flCreateFlags | FCF_DIALOGBOX;
|
---|
1378 |
|
---|
1379 | if (flCreateFlags & FCF_SIZEBORDER)
|
---|
1380 | // dialog has size border:
|
---|
1381 | // add "clip siblings" style
|
---|
1382 | flStyle |= WS_CLIPSIBLINGS;
|
---|
1383 |
|
---|
1384 | pDlgData->hwndDlg = WinCreateWindow(HWND_DESKTOP,
|
---|
1385 | WC_FRAME,
|
---|
1386 | (PSZ)pcszDlgTitle,
|
---|
1387 | flStyle, // style; invisible for now
|
---|
1388 | 0, 0, 0, 0,
|
---|
1389 | hwndOwner,
|
---|
1390 | HWND_TOP,
|
---|
1391 | 0, // ID
|
---|
1392 | &fcData,
|
---|
1393 | NULL); // presparams
|
---|
1394 |
|
---|
1395 | if (!pDlgData->hwndDlg)
|
---|
1396 | arc = DLGERR_CANNOT_CREATE_FRAME;
|
---|
1397 | else
|
---|
1398 | {
|
---|
1399 | HWND hwndDlg = pDlgData->hwndDlg;
|
---|
1400 | SIZEL szlClient = {0};
|
---|
1401 | RECTL rclClient;
|
---|
1402 | HWND hwndFocusItem = NULLHANDLE;
|
---|
1403 |
|
---|
1404 | /*
|
---|
1405 | * 3) compute size of all controls
|
---|
1406 | *
|
---|
1407 | */
|
---|
1408 |
|
---|
1409 | ProcessAll(pDlgData,
|
---|
1410 | &szlClient,
|
---|
1411 | PROCESS_CALC_SIZES);
|
---|
1412 |
|
---|
1413 | if (pDlgData->hps)
|
---|
1414 | WinReleasePS(pDlgData->hps);
|
---|
1415 |
|
---|
1416 | /*
|
---|
1417 | * 4) compute size of dialog client from total
|
---|
1418 | * size of all controls
|
---|
1419 | */
|
---|
1420 |
|
---|
1421 | WinSubclassWindow(hwndDlg, pfnwpDialogProc);
|
---|
1422 |
|
---|
1423 | // calculate the frame size from the client size
|
---|
1424 | rclClient.xLeft = 10;
|
---|
1425 | rclClient.yBottom = 10;
|
---|
1426 | rclClient.xRight = szlClient.cx + 2 * SPACING;
|
---|
1427 | rclClient.yTop = szlClient.cy + 2 * SPACING;
|
---|
1428 | WinCalcFrameRect(hwndDlg,
|
---|
1429 | &rclClient,
|
---|
1430 | FALSE); // frame from client
|
---|
1431 |
|
---|
1432 | WinSetWindowPos(hwndDlg,
|
---|
1433 | 0,
|
---|
1434 | 10,
|
---|
1435 | 10,
|
---|
1436 | rclClient.xRight,
|
---|
1437 | rclClient.yTop,
|
---|
1438 | SWP_MOVE | SWP_SIZE | SWP_NOADJUST);
|
---|
1439 |
|
---|
1440 | /*
|
---|
1441 | * 5) compute _positions_ of all controls
|
---|
1442 | *
|
---|
1443 | */
|
---|
1444 |
|
---|
1445 | ProcessAll(pDlgData,
|
---|
1446 | &szlClient,
|
---|
1447 | PROCESS_CALC_POSITIONS);
|
---|
1448 |
|
---|
1449 | /*
|
---|
1450 | * 6) create control windows, finally
|
---|
1451 | *
|
---|
1452 | */
|
---|
1453 |
|
---|
1454 | pDlgData->ptlTotalOfs.x = SPACING;
|
---|
1455 | pDlgData->ptlTotalOfs.y = SPACING;
|
---|
1456 |
|
---|
1457 | ProcessAll(pDlgData,
|
---|
1458 | &szlClient,
|
---|
1459 | PROCESS_CREATE_CONTROLS);
|
---|
1460 |
|
---|
1461 | /*
|
---|
1462 | * 7) WM_INITDLG, set focus
|
---|
1463 | *
|
---|
1464 | */
|
---|
1465 |
|
---|
1466 | hwndFocusItem = (pDlgData->hwndFirstFocus)
|
---|
1467 | ? pDlgData->hwndFirstFocus
|
---|
1468 | : hwndDlg;
|
---|
1469 | if (!WinSendMsg(hwndDlg,
|
---|
1470 | WM_INITDLG,
|
---|
1471 | (MPARAM)hwndFocusItem,
|
---|
1472 | (MPARAM)pCreateParams))
|
---|
1473 | {
|
---|
1474 | // if WM_INITDLG returns FALSE, this means
|
---|
1475 | // the dlg proc has not changed the focus;
|
---|
1476 | // we must then set the focus here
|
---|
1477 | WinSetFocus(HWND_DESKTOP, hwndFocusItem);
|
---|
1478 | }
|
---|
1479 | }
|
---|
1480 | }
|
---|
1481 |
|
---|
1482 | if (pDlgData)
|
---|
1483 | {
|
---|
1484 | PLISTNODE pTableNode;
|
---|
1485 |
|
---|
1486 | if (arc)
|
---|
1487 | {
|
---|
1488 | // error: clean up
|
---|
1489 | if (pDlgData->hwndDlg)
|
---|
1490 | WinDestroyWindow(pDlgData->hwndDlg);
|
---|
1491 | }
|
---|
1492 | else
|
---|
1493 | // no error: output dialog
|
---|
1494 | *phwndDlg = pDlgData->hwndDlg;
|
---|
1495 |
|
---|
1496 | // in any case, clean up our mess:
|
---|
1497 |
|
---|
1498 | // clean up the tables
|
---|
1499 | FOR_ALL_NODES(&pDlgData->llTables, pTableNode)
|
---|
1500 | {
|
---|
1501 | PTABLEDEF pTable = (PTABLEDEF)pTableNode->pItemData;
|
---|
1502 |
|
---|
1503 | // for each table, clean up the rows
|
---|
1504 | PLISTNODE pRowNode;
|
---|
1505 | FOR_ALL_NODES(&pTable->llRows, pRowNode)
|
---|
1506 | {
|
---|
1507 | PROWDEF pRow = (PROWDEF)pRowNode->pItemData;
|
---|
1508 |
|
---|
1509 | // for each row, clean up the columns
|
---|
1510 | PLISTNODE pColumnNode;
|
---|
1511 | FOR_ALL_NODES(&pRow->llColumns, pColumnNode)
|
---|
1512 | {
|
---|
1513 | PCOLUMNDEF pColumn = (PCOLUMNDEF)pColumnNode->pItemData;
|
---|
1514 | free(pColumn);
|
---|
1515 | }
|
---|
1516 | lstClear(&pRow->llColumns);
|
---|
1517 |
|
---|
1518 | free(pRow);
|
---|
1519 | }
|
---|
1520 | lstClear(&pTable->llRows);
|
---|
1521 |
|
---|
1522 | free(pTable);
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 | lstClear(&pDlgData->llTables);
|
---|
1526 | lstClear(&pDlgData->llControls);
|
---|
1527 |
|
---|
1528 | free(pDlgData);
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | return (arc);
|
---|
1532 | }
|
---|
1533 |
|
---|
1534 | /*
|
---|
1535 | *@@ dlghCreateMessageBox:
|
---|
1536 | *
|
---|
1537 | *@@added V0.9.13 (2001-06-21) [umoeller]
|
---|
1538 | */
|
---|
1539 |
|
---|
1540 | APIRET dlghCreateMessageBox(HWND *phwndDlg,
|
---|
1541 | HWND hwndOwner,
|
---|
1542 | HPOINTER hptrIcon,
|
---|
1543 | const char *pcszTitle,
|
---|
1544 | const char *pcszMessage,
|
---|
1545 | ULONG flFlags,
|
---|
1546 | const char *pcszFont,
|
---|
1547 | const MSGBOXSTRINGS *pStrings,
|
---|
1548 | PULONG pulAlarmFlag) // out: alarm sound to be played
|
---|
1549 | {
|
---|
1550 | CONTROLDEF
|
---|
1551 | Icon = {
|
---|
1552 | WC_STATIC,
|
---|
1553 | NULL, // text, set below
|
---|
1554 | WS_VISIBLE | SS_ICON,
|
---|
1555 | 0, // ID
|
---|
1556 | NULL, // no font
|
---|
1557 | 0,
|
---|
1558 | { SZL_AUTOSIZE, SZL_AUTOSIZE },
|
---|
1559 | 5
|
---|
1560 | },
|
---|
1561 | InfoText =
|
---|
1562 | {
|
---|
1563 | WC_STATIC,
|
---|
1564 | NULL, // text, set below
|
---|
1565 | WS_VISIBLE | SS_TEXT | DT_WORDBREAK | DT_LEFT | DT_TOP,
|
---|
1566 | 10, // ID
|
---|
1567 | CTL_COMMON_FONT,
|
---|
1568 | 0,
|
---|
1569 | { 400, SZL_AUTOSIZE },
|
---|
1570 | 5
|
---|
1571 | },
|
---|
1572 | Buttons[] = {
|
---|
1573 | {
|
---|
1574 | WC_BUTTON,
|
---|
1575 | NULL, // text, set below
|
---|
1576 | WS_VISIBLE | BS_PUSHBUTTON,
|
---|
1577 | 1, // ID
|
---|
1578 | CTL_COMMON_FONT, // no font
|
---|
1579 | 0,
|
---|
1580 | { 100, 30 },
|
---|
1581 | 5
|
---|
1582 | },
|
---|
1583 | {
|
---|
1584 | WC_BUTTON,
|
---|
1585 | NULL, // text, set below
|
---|
1586 | WS_VISIBLE | BS_PUSHBUTTON,
|
---|
1587 | 2, // ID
|
---|
1588 | CTL_COMMON_FONT, // no font
|
---|
1589 | 0,
|
---|
1590 | { 100, 30 },
|
---|
1591 | 5
|
---|
1592 | },
|
---|
1593 | {
|
---|
1594 | WC_BUTTON,
|
---|
1595 | NULL, // text, set below
|
---|
1596 | WS_VISIBLE | BS_PUSHBUTTON,
|
---|
1597 | 3, // ID
|
---|
1598 | CTL_COMMON_FONT, // no font
|
---|
1599 | 0,
|
---|
1600 | { 100, 30 },
|
---|
1601 | 5
|
---|
1602 | }
|
---|
1603 | };
|
---|
1604 |
|
---|
1605 | DLGHITEM MessageBox[] =
|
---|
1606 | {
|
---|
1607 | START_TABLE,
|
---|
1608 | START_ROW(ROW_VALIGN_CENTER),
|
---|
1609 | CONTROL_DEF(&Icon),
|
---|
1610 | START_TABLE,
|
---|
1611 | START_ROW(ROW_VALIGN_CENTER),
|
---|
1612 | CONTROL_DEF(&InfoText),
|
---|
1613 | START_ROW(ROW_VALIGN_CENTER),
|
---|
1614 | CONTROL_DEF(&Buttons[0]),
|
---|
1615 | CONTROL_DEF(&Buttons[1]),
|
---|
1616 | CONTROL_DEF(&Buttons[2]),
|
---|
1617 | END_TABLE,
|
---|
1618 | END_TABLE
|
---|
1619 | };
|
---|
1620 |
|
---|
1621 | ULONG flButtons = flFlags & 0xF; // low nibble contains MB_YESNO etc.
|
---|
1622 |
|
---|
1623 | const char *p0 = "Error",
|
---|
1624 | *p1 = NULL,
|
---|
1625 | *p2 = NULL;
|
---|
1626 |
|
---|
1627 | Icon.pcszText = (const char *)hptrIcon;
|
---|
1628 | InfoText.pcszText = pcszMessage;
|
---|
1629 |
|
---|
1630 | // now work on the three buttons of the dlg template:
|
---|
1631 | // give them proper titles or hide them
|
---|
1632 | if (flButtons == MB_OK)
|
---|
1633 | {
|
---|
1634 | p0 = pStrings->pcszOK;
|
---|
1635 | }
|
---|
1636 | else if (flButtons == MB_OKCANCEL)
|
---|
1637 | {
|
---|
1638 | p0 = pStrings->pcszOK;
|
---|
1639 | p1 = pStrings->pcszCancel;
|
---|
1640 | }
|
---|
1641 | else if (flButtons == MB_RETRYCANCEL)
|
---|
1642 | {
|
---|
1643 | p0 = pStrings->pcszRetry;
|
---|
1644 | p1 = pStrings->pcszCancel;
|
---|
1645 | }
|
---|
1646 | else if (flButtons == MB_ABORTRETRYIGNORE)
|
---|
1647 | {
|
---|
1648 | p0 = pStrings->pcszAbort;
|
---|
1649 | p1 = pStrings->pcszRetry;
|
---|
1650 | p2 = pStrings->pcszIgnore;
|
---|
1651 | }
|
---|
1652 | else if (flButtons == MB_YESNO)
|
---|
1653 | {
|
---|
1654 | p0 = pStrings->pcszYes;
|
---|
1655 | p1 = pStrings->pcszNo;
|
---|
1656 | }
|
---|
1657 | else if (flButtons == MB_YESNOCANCEL)
|
---|
1658 | {
|
---|
1659 | p0 = pStrings->pcszYes;
|
---|
1660 | p1 = pStrings->pcszNo;
|
---|
1661 | p2 = pStrings->pcszCancel;
|
---|
1662 | }
|
---|
1663 | else if (flButtons == MB_CANCEL)
|
---|
1664 | {
|
---|
1665 | p0 = pStrings->pcszCancel;
|
---|
1666 | }
|
---|
1667 | else if (flButtons == MB_ENTER)
|
---|
1668 | {
|
---|
1669 | p0 = pStrings->pcszEnter;
|
---|
1670 | }
|
---|
1671 | else if (flButtons == MB_ENTERCANCEL)
|
---|
1672 | {
|
---|
1673 | p0 = pStrings->pcszEnter;
|
---|
1674 | p1 = pStrings->pcszCancel;
|
---|
1675 | }
|
---|
1676 | else if (flButtons == MB_YES_YES2ALL_NO)
|
---|
1677 | {
|
---|
1678 | p0 = pStrings->pcszYes;
|
---|
1679 | p1 = pStrings->pcszYesToAll;
|
---|
1680 | p2 = pStrings->pcszNo;
|
---|
1681 | }
|
---|
1682 |
|
---|
1683 | // now set strings and hide empty buttons
|
---|
1684 | Buttons[0].pcszText = p0;
|
---|
1685 |
|
---|
1686 | if (p1)
|
---|
1687 | Buttons[1].pcszText = p1;
|
---|
1688 | else
|
---|
1689 | Buttons[1].flStyle &= ~WS_VISIBLE;
|
---|
1690 |
|
---|
1691 | if (p2)
|
---|
1692 | Buttons[2].pcszText = p2;
|
---|
1693 | else
|
---|
1694 | Buttons[2].flStyle &= ~WS_VISIBLE;
|
---|
1695 |
|
---|
1696 | // query default button IDs
|
---|
1697 | if (flFlags & MB_DEFBUTTON2)
|
---|
1698 | Buttons[1].flStyle |= BS_DEFAULT;
|
---|
1699 | else if (flFlags & MB_DEFBUTTON3)
|
---|
1700 | Buttons[2].flStyle |= BS_DEFAULT;
|
---|
1701 | else
|
---|
1702 | Buttons[0].flStyle |= BS_DEFAULT;
|
---|
1703 |
|
---|
1704 | *pulAlarmFlag = WA_NOTE;
|
---|
1705 | if (flFlags & (MB_ICONHAND | MB_ERROR))
|
---|
1706 | *pulAlarmFlag = WA_ERROR;
|
---|
1707 | else if (flFlags & (MB_ICONEXCLAMATION | MB_WARNING))
|
---|
1708 | *pulAlarmFlag = WA_WARNING;
|
---|
1709 |
|
---|
1710 | return (dlghCreateDlg(phwndDlg,
|
---|
1711 | hwndOwner,
|
---|
1712 | FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN,
|
---|
1713 | WinDefDlgProc,
|
---|
1714 | pcszTitle,
|
---|
1715 | MessageBox,
|
---|
1716 | ARRAYITEMCOUNT(MessageBox),
|
---|
1717 | NULL,
|
---|
1718 | pcszFont));
|
---|
1719 | }
|
---|
1720 |
|
---|
1721 | /*
|
---|
1722 | *@@ dlghProcessMessageBox:
|
---|
1723 | *
|
---|
1724 | *@@added V0.9.13 (2001-06-21) [umoeller]
|
---|
1725 | */
|
---|
1726 |
|
---|
1727 | ULONG dlghProcessMessageBox(HWND hwndDlg,
|
---|
1728 | ULONG ulAlarmFlag,
|
---|
1729 | ULONG flFlags)
|
---|
1730 | {
|
---|
1731 | ULONG ulrcDlg;
|
---|
1732 | ULONG flButtons = flFlags & 0xF; // low nibble contains MB_YESNO etc.
|
---|
1733 |
|
---|
1734 | winhCenterWindow(hwndDlg);
|
---|
1735 |
|
---|
1736 | if (flFlags & MB_SYSTEMMODAL)
|
---|
1737 | WinSetSysModalWindow(HWND_DESKTOP, hwndDlg);
|
---|
1738 |
|
---|
1739 | if (ulAlarmFlag)
|
---|
1740 | WinAlarm(HWND_DESKTOP, ulAlarmFlag);
|
---|
1741 |
|
---|
1742 | ulrcDlg = WinProcessDlg(hwndDlg);
|
---|
1743 |
|
---|
1744 | WinDestroyWindow(hwndDlg);
|
---|
1745 |
|
---|
1746 | if (flButtons == MB_OK)
|
---|
1747 | return MBID_OK;
|
---|
1748 | else if (flButtons == MB_OKCANCEL)
|
---|
1749 | switch (ulrcDlg)
|
---|
1750 | {
|
---|
1751 | case 1: return MBID_OK;
|
---|
1752 | default: return MBID_CANCEL;
|
---|
1753 | }
|
---|
1754 | else if (flButtons == MB_RETRYCANCEL)
|
---|
1755 | switch (ulrcDlg)
|
---|
1756 | {
|
---|
1757 | case 1: return MBID_RETRY;
|
---|
1758 | default: return MBID_CANCEL;
|
---|
1759 | }
|
---|
1760 | else if (flButtons == MB_ABORTRETRYIGNORE)
|
---|
1761 | switch (ulrcDlg)
|
---|
1762 | {
|
---|
1763 | case 2: return MBID_RETRY;
|
---|
1764 | case 3: return MBID_IGNORE;
|
---|
1765 | default: return MBID_ABORT;
|
---|
1766 | }
|
---|
1767 | else if (flButtons == MB_YESNO)
|
---|
1768 | switch (ulrcDlg)
|
---|
1769 | {
|
---|
1770 | case 1: return MBID_YES;
|
---|
1771 | default: return MBID_NO;
|
---|
1772 | }
|
---|
1773 | else if (flButtons == MB_YESNOCANCEL)
|
---|
1774 | switch (ulrcDlg)
|
---|
1775 | {
|
---|
1776 | case 1: return MBID_YES;
|
---|
1777 | case 2: return MBID_NO;
|
---|
1778 | default: return MBID_CANCEL;
|
---|
1779 | }
|
---|
1780 | else if (flButtons == MB_CANCEL)
|
---|
1781 | return MBID_CANCEL;
|
---|
1782 | else if (flButtons == MB_ENTER)
|
---|
1783 | return MBID_ENTER;
|
---|
1784 | else if (flButtons == MB_ENTERCANCEL)
|
---|
1785 | switch (ulrcDlg)
|
---|
1786 | {
|
---|
1787 | case 1: return MBID_ENTER;
|
---|
1788 | default: return MBID_CANCEL;
|
---|
1789 | }
|
---|
1790 | else if (flButtons == MB_YES_YES2ALL_NO)
|
---|
1791 | switch (ulrcDlg)
|
---|
1792 | {
|
---|
1793 | case 1: return MBID_YES;
|
---|
1794 | case 2: return MBID_YES2ALL;
|
---|
1795 | default: return MBID_NO;
|
---|
1796 | }
|
---|
1797 |
|
---|
1798 | return (MBID_CANCEL);
|
---|
1799 | }
|
---|
1800 |
|
---|
1801 | /*
|
---|
1802 | *@@ dlghMessageBox:
|
---|
1803 | * WinMessageBox replacement.
|
---|
1804 | *
|
---|
1805 | * This has all the flags of the standard call,
|
---|
1806 | * but looks much prettier. Besides, it allows
|
---|
1807 | * you to specify any icon to be displayed.
|
---|
1808 | *
|
---|
1809 | * Currently the following flStyle's are supported:
|
---|
1810 | *
|
---|
1811 | * -- MB_OK 0x0000
|
---|
1812 | * -- MB_OKCANCEL 0x0001
|
---|
1813 | * -- MB_RETRYCANCEL 0x0002
|
---|
1814 | * -- MB_ABORTRETRYIGNORE 0x0003
|
---|
1815 | * -- MB_YESNO 0x0004
|
---|
1816 | * -- MB_YESNOCANCEL 0x0005
|
---|
1817 | * -- MB_CANCEL 0x0006
|
---|
1818 | * -- MB_ENTER 0x0007 (not implemented yet)
|
---|
1819 | * -- MB_ENTERCANCEL 0x0008 (not implemented yet)
|
---|
1820 | *
|
---|
1821 | * -- MB_YES_YES2ALL_NO 0x0009
|
---|
1822 | * This is new: this has three buttons called "Yes"
|
---|
1823 | * (MBID_YES), "Yes to all" (MBID_YES2ALL), "No" (MBID_NO).
|
---|
1824 | *
|
---|
1825 | * -- MB_DEFBUTTON2 (for two-button styles)
|
---|
1826 | * -- MB_DEFBUTTON3 (for three-button styles)
|
---|
1827 | *
|
---|
1828 | * -- MB_ICONHAND
|
---|
1829 | * -- MB_ICONEXCLAMATION
|
---|
1830 | *
|
---|
1831 | * Returns MBID_* codes like WinMessageBox.
|
---|
1832 | *
|
---|
1833 | *@@added V0.9.13 (2001-06-21) [umoeller]
|
---|
1834 | */
|
---|
1835 |
|
---|
1836 | ULONG dlghMessageBox(HWND hwndOwner, // in: owner for msg box
|
---|
1837 | HPOINTER hptrIcon, // in: icon to display
|
---|
1838 | const char *pcszTitle, // in: title
|
---|
1839 | const char *pcszMessage, // in: message
|
---|
1840 | ULONG flFlags, // in: standard message box flags
|
---|
1841 | const char *pcszFont, // in: font (e.g. "9.WarpSans")
|
---|
1842 | const MSGBOXSTRINGS *pStrings) // in: strings array
|
---|
1843 | {
|
---|
1844 | HWND hwndDlg;
|
---|
1845 | ULONG ulAlarmFlag;
|
---|
1846 | APIRET arc = dlghCreateMessageBox(&hwndDlg,
|
---|
1847 | hwndOwner,
|
---|
1848 | hptrIcon,
|
---|
1849 | pcszTitle,
|
---|
1850 | pcszMessage,
|
---|
1851 | flFlags,
|
---|
1852 | pcszFont,
|
---|
1853 | pStrings,
|
---|
1854 | &ulAlarmFlag);
|
---|
1855 |
|
---|
1856 | if (!arc && hwndDlg)
|
---|
1857 | {
|
---|
1858 | // SHOW DIALOG
|
---|
1859 | return (dlghProcessMessageBox(hwndDlg,
|
---|
1860 | ulAlarmFlag,
|
---|
1861 | flFlags));
|
---|
1862 | }
|
---|
1863 | else
|
---|
1864 | {
|
---|
1865 | CHAR szMsg[100];
|
---|
1866 | sprintf(szMsg, "dlghCreateMessageBox reported error %u.", arc);
|
---|
1867 | WinMessageBox(HWND_DESKTOP,
|
---|
1868 | NULLHANDLE,
|
---|
1869 | "Error",
|
---|
1870 | szMsg,
|
---|
1871 | 0,
|
---|
1872 | MB_CANCEL | MB_MOVEABLE);
|
---|
1873 | }
|
---|
1874 |
|
---|
1875 | return (DID_CANCEL);
|
---|
1876 | }
|
---|
1877 |
|
---|
1878 | /*
|
---|
1879 | *@@ dlghSetPrevFocus:
|
---|
1880 | * "backward" function for rotating the focus
|
---|
1881 | * in a dialog when the "shift+tab" keys get
|
---|
1882 | * pressed.
|
---|
1883 | *
|
---|
1884 | * pllWindows must be a linked list with the
|
---|
1885 | * plain HWND window handles of the focussable
|
---|
1886 | * controls in the dialog.
|
---|
1887 | */
|
---|
1888 |
|
---|
1889 | VOID dlghSetPrevFocus(PVOID pvllWindows)
|
---|
1890 | {
|
---|
1891 | PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
|
---|
1892 |
|
---|
1893 | // check current focus
|
---|
1894 | HWND hwndFocus = WinQueryFocus(HWND_DESKTOP);
|
---|
1895 |
|
---|
1896 | PLISTNODE pNode = lstNodeFromItem(pllWindows, (PVOID)hwndFocus);
|
---|
1897 |
|
---|
1898 | BOOL fRestart = FALSE;
|
---|
1899 |
|
---|
1900 | while (pNode)
|
---|
1901 | {
|
---|
1902 | CHAR szClass[100];
|
---|
1903 |
|
---|
1904 | // previos node
|
---|
1905 | pNode = pNode->pPrevious;
|
---|
1906 |
|
---|
1907 | if ( (!pNode) // no next, or not found:
|
---|
1908 | && (!fRestart) // avoid infinite looping if bad list
|
---|
1909 | )
|
---|
1910 | {
|
---|
1911 | pNode = lstQueryLastNode(pllWindows);
|
---|
1912 | fRestart = TRUE;
|
---|
1913 | }
|
---|
1914 |
|
---|
1915 | if (pNode)
|
---|
1916 | {
|
---|
1917 | // check if this is a focusable control
|
---|
1918 | if (WinQueryClassName((HWND)pNode->pItemData,
|
---|
1919 | sizeof(szClass),
|
---|
1920 | szClass))
|
---|
1921 | {
|
---|
1922 | if ( (strcmp(szClass, "#5")) // not static
|
---|
1923 | )
|
---|
1924 | break;
|
---|
1925 | // else: go for next then
|
---|
1926 | }
|
---|
1927 | }
|
---|
1928 | }
|
---|
1929 |
|
---|
1930 | if (pNode)
|
---|
1931 | {
|
---|
1932 | WinSetFocus(HWND_DESKTOP,
|
---|
1933 | (HWND)pNode->pItemData);
|
---|
1934 | }
|
---|
1935 | }
|
---|
1936 |
|
---|
1937 | /*
|
---|
1938 | *@@ dlghSetNextFocus:
|
---|
1939 | * "forward" function for rotating the focus
|
---|
1940 | * in a dialog when the "ab" key gets pressed.
|
---|
1941 | *
|
---|
1942 | * pllWindows must be a linked list with the
|
---|
1943 | * plain HWND window handles of the focussable
|
---|
1944 | * controls in the dialog.
|
---|
1945 | */
|
---|
1946 |
|
---|
1947 | VOID dlghSetNextFocus(PVOID pvllWindows)
|
---|
1948 | {
|
---|
1949 | PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
|
---|
1950 |
|
---|
1951 | // check current focus
|
---|
1952 | HWND hwndFocus = WinQueryFocus(HWND_DESKTOP);
|
---|
1953 |
|
---|
1954 | PLISTNODE pNode = lstNodeFromItem(pllWindows, (PVOID)hwndFocus);
|
---|
1955 |
|
---|
1956 | BOOL fRestart = FALSE;
|
---|
1957 |
|
---|
1958 | while (pNode)
|
---|
1959 | {
|
---|
1960 | CHAR szClass[100];
|
---|
1961 |
|
---|
1962 | // next focus in node
|
---|
1963 | pNode = pNode->pNext;
|
---|
1964 |
|
---|
1965 | if ( (!pNode) // no next, or not found:
|
---|
1966 | && (!fRestart) // avoid infinite looping if bad list
|
---|
1967 | )
|
---|
1968 | {
|
---|
1969 | pNode = lstQueryFirstNode(pllWindows);
|
---|
1970 | fRestart = TRUE;
|
---|
1971 | }
|
---|
1972 |
|
---|
1973 | if (pNode)
|
---|
1974 | {
|
---|
1975 | // check if this is a focusable control
|
---|
1976 | if (WinQueryClassName((HWND)pNode->pItemData,
|
---|
1977 | sizeof(szClass),
|
---|
1978 | szClass))
|
---|
1979 | {
|
---|
1980 | if ( (strcmp(szClass, "#5")) // not static
|
---|
1981 | )
|
---|
1982 | break;
|
---|
1983 | // else: go for next then
|
---|
1984 | }
|
---|
1985 | }
|
---|
1986 | }
|
---|
1987 |
|
---|
1988 | if (pNode)
|
---|
1989 | {
|
---|
1990 | WinSetFocus(HWND_DESKTOP,
|
---|
1991 | (HWND)pNode->pItemData);
|
---|
1992 | }
|
---|
1993 | }
|
---|
1994 |
|
---|
1995 | /*
|
---|
1996 | *@@ MatchMnemonic:
|
---|
1997 | * returns TRUE if the specified control matches
|
---|
1998 | *
|
---|
1999 | *
|
---|
2000 | *@@added V0.9.9 (2001-03-17) [umoeller]
|
---|
2001 | */
|
---|
2002 |
|
---|
2003 | /*
|
---|
2004 | *@@ dlghProcessMnemonic:
|
---|
2005 | * finds the control which matches usch
|
---|
2006 | * and gives it the focus. If this is a
|
---|
2007 | * static control, the next control in the
|
---|
2008 | * list is given focus instead. (Standard
|
---|
2009 | * dialog behavior.)
|
---|
2010 | *
|
---|
2011 | * Pass in usch from WM_CHAR. It is assumed
|
---|
2012 | * that the caller has already tested for
|
---|
2013 | * the "alt" key to be depressed.
|
---|
2014 | *
|
---|
2015 | *@@added V0.9.9 (2001-03-17) [umoeller]
|
---|
2016 | */
|
---|
2017 |
|
---|
2018 | HWND dlghProcessMnemonic(PVOID pvllWindows,
|
---|
2019 | USHORT usch)
|
---|
2020 | {
|
---|
2021 | PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
|
---|
2022 |
|
---|
2023 | HWND hwndFound = NULLHANDLE;
|
---|
2024 | PLISTNODE pNode = lstQueryFirstNode(pllWindows);
|
---|
2025 | CHAR szClass[100];
|
---|
2026 |
|
---|
2027 | while (pNode)
|
---|
2028 | {
|
---|
2029 | HWND hwnd = (HWND)pNode->pItemData;
|
---|
2030 |
|
---|
2031 | if (WinSendMsg(hwnd,
|
---|
2032 | WM_MATCHMNEMONIC,
|
---|
2033 | (MPARAM)usch,
|
---|
2034 | 0))
|
---|
2035 | {
|
---|
2036 | // according to the docs, only buttons and static
|
---|
2037 | // return TRUE to that msg;
|
---|
2038 | // if this is a static, give focus to the next
|
---|
2039 | // control
|
---|
2040 |
|
---|
2041 | // _Pmpf((__FUNCTION__ ": hwnd 0x%lX", hwnd));
|
---|
2042 |
|
---|
2043 | // check if this is a focusable control
|
---|
2044 | if (WinQueryClassName(hwnd,
|
---|
2045 | sizeof(szClass),
|
---|
2046 | szClass))
|
---|
2047 | {
|
---|
2048 | if (!strcmp(szClass, "#3"))
|
---|
2049 | // it's a button: click it
|
---|
2050 | WinSendMsg(hwnd, BM_CLICK, (MPARAM)TRUE, 0);
|
---|
2051 | else if (!strcmp(szClass, "#5"))
|
---|
2052 | {
|
---|
2053 | // it's a static: give focus to following control
|
---|
2054 | pNode = pNode->pNext;
|
---|
2055 | if (pNode)
|
---|
2056 | WinSetFocus(HWND_DESKTOP, (HWND)pNode->pItemData);
|
---|
2057 | }
|
---|
2058 | }
|
---|
2059 | else
|
---|
2060 | // any other control (are there any?): give them focus
|
---|
2061 | WinSetFocus(HWND_DESKTOP, hwnd);
|
---|
2062 |
|
---|
2063 | // in any case, stop
|
---|
2064 | hwndFound = hwnd;
|
---|
2065 | break;
|
---|
2066 | }
|
---|
2067 |
|
---|
2068 | pNode = pNode->pNext;
|
---|
2069 | }
|
---|
2070 |
|
---|
2071 | return (hwndFound);
|
---|
2072 | }
|
---|
2073 |
|
---|
2074 | /*
|
---|
2075 | *@@ dlghEnter:
|
---|
2076 | * presses the first button with BS_DEFAULT.
|
---|
2077 | */
|
---|
2078 |
|
---|
2079 | BOOL dlghEnter(PVOID pvllWindows)
|
---|
2080 | {
|
---|
2081 | PLINKLIST pllWindows = (PLINKLIST)pvllWindows;
|
---|
2082 |
|
---|
2083 | PLISTNODE pNode = lstQueryFirstNode(pllWindows);
|
---|
2084 | CHAR szClass[100];
|
---|
2085 | while (pNode)
|
---|
2086 | {
|
---|
2087 | HWND hwnd = (HWND)pNode->pItemData;
|
---|
2088 | if (WinQueryClassName(hwnd,
|
---|
2089 | sizeof(szClass),
|
---|
2090 | szClass))
|
---|
2091 | {
|
---|
2092 | if (!strcmp(szClass, "#3")) // button
|
---|
2093 | {
|
---|
2094 | // _Pmpf((__FUNCTION__ ": found button"));
|
---|
2095 | if ( (WinQueryWindowULong(hwnd, QWL_STYLE) & (BS_PUSHBUTTON | BS_DEFAULT))
|
---|
2096 | == (BS_PUSHBUTTON | BS_DEFAULT)
|
---|
2097 | )
|
---|
2098 | {
|
---|
2099 | // _Pmpf((" is default!"));
|
---|
2100 | WinPostMsg(hwnd,
|
---|
2101 | BM_CLICK,
|
---|
2102 | (MPARAM)TRUE, // upclick
|
---|
2103 | 0);
|
---|
2104 | return (TRUE);
|
---|
2105 | }
|
---|
2106 | }
|
---|
2107 | }
|
---|
2108 |
|
---|
2109 | pNode = pNode->pNext;
|
---|
2110 | }
|
---|
2111 |
|
---|
2112 | return (FALSE);
|
---|
2113 | }
|
---|
2114 |
|
---|
2115 |
|
---|