source: trunk/include/helpers/dialog.h@ 155

Last change on this file since 155 was 155, checked in by umoeller, 23 years ago

Patches from Martin and Paul, plus regexp support.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 19.8 KB
Line 
1
2/*
3 *@@sourcefile dialog.h:
4 * header file for dialog.c. See remarks there.
5 *
6 * Note: Version numbering in this file relates to XWorkplace version
7 * numbering.
8 *
9 *@@added V0.9.9 (2001-04-01) [umoeller]
10 *@@include <os2.h>
11 *@@include #include "helpers\linklist.h" // for mnemonic helpers
12 *@@include #include "helpers\dialog.h"
13 */
14
15/* Copyright (C) 2001 Ulrich M”ller.
16 * This file is part of the "XWorkplace helpers" source package.
17 * This is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published
19 * by the Free Software Foundation, in version 2 as it comes in the
20 * "COPYING" file of the XWorkplace main distribution.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 */
26
27#if __cplusplus
28extern "C" {
29#endif
30
31#ifndef DIALOG_HEADER_INCLUDED
32 #define DIALOG_HEADER_INCLUDED
33
34 #ifndef NULL_POINT
35 #define NULL_POINT {0, 0}
36 #endif
37
38 /* ******************************************************************
39 *
40 * Error codes
41 *
42 ********************************************************************/
43
44 #define ERROR_DLG_FIRST 43000
45
46 #define DLGERR_ROW_BEFORE_TABLE (ERROR_DLG_FIRST)
47 #define DLGERR_CONTROL_BEFORE_ROW (ERROR_DLG_FIRST + 1)
48 #define DLGERR_NULL_CTL_DEF (ERROR_DLG_FIRST + 2)
49 #define DLGERR_CANNOT_CREATE_FRAME (ERROR_DLG_FIRST + 3)
50 #define DLGERR_INVALID_CODE (ERROR_DLG_FIRST + 4)
51 #define DLGERR_TABLE_NOT_CLOSED (ERROR_DLG_FIRST + 5)
52 #define DLGERR_TOO_MANY_TABLES_CLOSED (ERROR_DLG_FIRST + 6)
53 #define DLGERR_CANNOT_CREATE_CONTROL (ERROR_DLG_FIRST + 7)
54 #define DLGERR_ARRAY_TOO_SMALL (ERROR_DLG_FIRST + 8)
55 #define DLGERR_INVALID_CONTROL_TITLE (ERROR_DLG_FIRST + 9)
56 #define DLGERR_INVALID_STATIC_BITMAP (ERROR_DLG_FIRST + 10)
57
58 #define ERROR_DLG_LAST (ERROR_DLG_FIRST + 10)
59
60 /* ******************************************************************
61 *
62 * Structures
63 *
64 ********************************************************************/
65
66 #define SZL_AUTOSIZE (-1)
67
68 #define CTL_COMMON_FONT ((PCSZ)-1)
69
70 #define ROW_VALIGN_MASK 0x0003
71 #define ROW_VALIGN_BOTTOM 0x0000
72 #define ROW_VALIGN_CENTER 0x0001
73 #define ROW_VALIGN_TOP 0x0002
74
75 /*
76 *@@ CONTROLDEF:
77 * defines a single control. Used
78 * with the TYPE_CONTROL_DEF type in
79 * DLGHITEM.
80 *
81 *@@changed V0.9.12 (2001-05-31) [umoeller]: added control data
82 */
83
84 typedef struct _CONTROLDEF
85 {
86 const char *pcszClass; // registered PM window class
87 const char *pcszText;
88 // window text (class-specific)
89 // special hacks:
90 // -- For WS_STATIC with SS_BITMAP or SS_ICON set,
91 // you may specify the exact HPOINTER here.
92 // The dlg routine will then subclass the static
93 //
94
95 ULONG flStyle; // standard window styles
96
97 USHORT usID; // dlg item ID
98
99 const char *pcszFont; // font presparam, or NULL for no presparam,
100 // or CTL_COMMON_FONT for standard dialog
101 // font specified on input to dlghCreateDlg
102
103 USHORT usAdjustPosition;
104 // flags for winhAdjustControls; any combination of
105 // XAC_MOVEX, XAC_MOVEY, XAC_SIZEX, XAC_SIZEY
106 // @@todo not implemented yet
107
108 SIZEL szlControlProposed;
109 // proposed size; a number of special flags are
110 // available (per cx, cy field):
111 // -- SZL_AUTOSIZE (-1): determine size automatically.
112 // Works only for statics with SS_TEXT and
113 // SS_BITMAP.
114 // -- Any other _negative_ value is considered a
115 // percentage of the largest row width in the
116 // table. For example, -50 would mean 50% of
117 // the largest row in the table. This is valid
118 // for the CX field only.
119 // If the CONTROLDEF appears with a START_NEW_TABLE
120 // type in _DLGHITEM (to specify a group table)
121 // and they are not SZL_AUTOSIZE, they specify the
122 // size of the inner table of the group (to override
123 // the automatic formatting). Note that the dialog
124 // formatter adds COMMON_SPACING to both the left and
125 // the right of the table to center the table in the
126 // PM group control, so the actual group size will
127 // be the specified size + (2 * COMMON_SPACING).
128
129 ULONG ulSpacing; // spacing around control
130
131 PVOID pvCtlData; // for WinCreateWindow
132
133 } CONTROLDEF, *PCONTROLDEF;
134
135 typedef const struct _CONTROLDEF *PCCONTROLDEF;
136
137 /*
138 *@@ DLGHITEMTYPE:
139 *
140 */
141
142 typedef enum _DLGHITEMTYPE
143 {
144 TYPE_START_NEW_TABLE, // beginning of a new table; may nest
145 TYPE_START_NEW_ROW, // beginning of a new row in a table
146 TYPE_CONTROL_DEF, // control definition
147 TYPE_END_TABLE // end of a table
148 } DLGHITEMTYPE;
149
150 // a few handy macros for defining templates
151
152 #define START_TABLE { TYPE_START_NEW_TABLE, 0 }
153
154 // this macro is slightly insane, but performs type checking
155 // in case the user gives a pointer which is not of CONTROLDEF
156 #define START_GROUP_TABLE(pDef) { TYPE_START_NEW_TABLE, \
157 ( (ULONG)(&(pDef)->pcszClass) ) }
158
159 #define END_TABLE { TYPE_END_TABLE, 0 }
160
161 #define START_ROW(fl) { TYPE_START_NEW_ROW, fl }
162
163 #define CONTROL_DEF(pDef) { TYPE_CONTROL_DEF, \
164 ( (ULONG)(&(pDef)->pcszClass) ) }
165
166 /*
167 *@@ DLGHITEM:
168 * dialog format array item.
169 *
170 * An array of these must be passed to dlghCreateDlg
171 * to tell it what controls the dialog contains.
172 * See dlghCreateDlg for details.
173 *
174 */
175
176 typedef struct _DLGHITEM
177 {
178 DLGHITEMTYPE Type;
179 // one of:
180 // TYPE_START_NEW_TABLE, // beginning of a new table
181 // TYPE_START_NEW_ROW, // beginning of a new row in a table
182 // TYPE_CONTROL_DEF // control definition
183 // TYPE_END_TABLE // end of table
184
185 ULONG ulData;
186 // -- with TYPE_START_NEW_TABLE: if NULL, this starts
187 // an invisible table (for formatting only).
188 // Otherwise a _CONTROLDEF pointer to specify
189 // a control to be produced around the table.
190 // For example, you can specify a WC_STATIC
191 // with SS_GROUPBOX to create a group around
192 // the table.
193 // -- with TYPE_START_NEW_ROW: ROW_* formatting flags.
194 // -- with TYPE_CONTROL_DEF: _CONTROLDEF pointer to a control definition
195 } DLGHITEM, *PDLGHITEM;
196
197 typedef const struct _DLGHITEM *PCDLGHITEM;
198
199 /* ******************************************************************
200 *
201 * Macros
202 *
203 ********************************************************************/
204
205 #define COMMON_SPACING 3
206
207 #define PM_GROUP_SPACING_X 16
208 #define PM_GROUP_SPACING_TOP 16
209
210 // the following require INCL_WINSTATICS
211
212 #define CONTROLDEF_GROUP(pcsz, id, cx, cy) { WC_STATIC, pcsz, \
213 WS_VISIBLE | SS_GROUPBOX | DT_MNEMONIC, \
214 id, CTL_COMMON_FONT, 0, { cx, cy }, 0 }
215
216 #define CONTROLDEF_TEXT(pcsz, id, cx, cy) { WC_STATIC, pcsz, \
217 WS_VISIBLE | SS_TEXT | DT_LEFT | DT_VCENTER | DT_MNEMONIC, \
218 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
219
220 #define CONTROLDEF_TEXT_CENTER(pcsz, id, cx, cy) { WC_STATIC, pcsz, \
221 WS_VISIBLE | SS_TEXT | DT_CENTER | DT_VCENTER | DT_MNEMONIC, \
222 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
223
224 #define CONTROLDEF_TEXT_WORDBREAK(pcsz, id, cx) { WC_STATIC, pcsz, \
225 WS_VISIBLE | SS_TEXT | DT_LEFT | DT_TOP | DT_WORDBREAK, \
226 id, CTL_COMMON_FONT, 0, {cx, -1}, COMMON_SPACING }
227
228 #define CONTROLDEF_ICON(hptr, id) { WC_STATIC, (PCSZ)(hptr), \
229 WS_VISIBLE | SS_ICON | DT_LEFT | DT_VCENTER, \
230 id, CTL_COMMON_FONT, 0, {-1, -1}, COMMON_SPACING }
231
232 #define CONTROLDEF_BITMAP(hbm, id) { WC_STATIC, (PCSZ)(hbm), \
233 WS_VISIBLE | SS_BITMAP | DT_LEFT | DT_VCENTER, \
234 id, CTL_COMMON_FONT, 0, {-1, -1}, COMMON_SPACING }
235
236 // the following require INCL_WINBUTTONS
237
238 #define CONTROLDEF_DEFPUSHBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
239 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_DEFAULT, \
240 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
241
242 #define CONTROLDEF_PUSHBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
243 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, \
244 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
245
246 #define CONTROLDEF_DEFNOFOCUSBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
247 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_DEFAULT | BS_NOPOINTERFOCUS, \
248 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
249
250 #define CONTROLDEF_NOFOCUSBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
251 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_NOPOINTERFOCUS, \
252 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
253
254 #define CONTROLDEF_HELPPUSHBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
255 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_HELP, \
256 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
257
258 #define CONTROLDEF_AUTOCHECKBOX(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
259 WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, \
260 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
261
262 #define CONTROLDEF_FIRST_AUTORADIO(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
263 WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON | WS_GROUP, \
264 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
265
266 #define CONTROLDEF_NEXT_AUTORADIO(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
267 WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON, \
268 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
269
270 // the following require INCL_WINENTRYFIELDS
271
272 #define CONTROLDEF_ENTRYFIELD(pcsz, id, cx, cy) { WC_ENTRYFIELD, pcsz, \
273 WS_VISIBLE | WS_TABSTOP | ES_MARGIN | ES_AUTOSCROLL, \
274 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
275
276 #define CONTROLDEF_ENTRYFIELD_RO(pcsz, id, cx, cy) { WC_ENTRYFIELD, pcsz, \
277 WS_VISIBLE | WS_TABSTOP | ES_MARGIN | ES_READONLY | ES_AUTOSCROLL, \
278 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
279
280 // the following require INCL_WINMLE
281
282 #define CONTROLDEF_MLE(pcsz, id, cx, cy) { WC_MLE, pcsz, \
283 WS_VISIBLE | WS_TABSTOP | MLS_BORDER | MLS_IGNORETAB | MLS_WORDWRAP, \
284 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
285
286 // the following require INCL_WINLISTBOXES
287
288 #define CONTROLDEF_LISTBOX(id, cx, cy) { WC_LISTBOX, NULL, \
289 WS_VISIBLE | WS_TABSTOP | LS_HORZSCROLL | LS_NOADJUSTPOS, \
290 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
291
292 // the following require INCL_WINLISTBOXES and INCL_WINENTRYFIELDS
293
294 #define CONTROLDEF_DROPDOWN(id, cx, cy) { WC_COMBOBOX, NULL, \
295 WS_VISIBLE | WS_TABSTOP | LS_HORZSCROLL | CBS_DROPDOWN, \
296 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
297
298 #define CONTROLDEF_DROPDOWNLIST(id, cx, cy) { WC_COMBOBOX, NULL, \
299 WS_VISIBLE | WS_TABSTOP | LS_HORZSCROLL | CBS_DROPDOWNLIST, \
300 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
301
302 // the following require INCL_WINSTDSPIN
303
304 #define CONTROLDEF_SPINBUTTON(id, cx, cy) { WC_SPINBUTTON, NULL, \
305 WS_VISIBLE | WS_TABSTOP | SPBS_MASTER | SPBS_NUMERICONLY | SPBS_JUSTCENTER | SPBS_FASTSPIN, \
306 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
307
308 // the following require INCL_WINSTDCNR
309
310 #define CONTROLDEF_CONTAINER(id, cx, cy) { WC_CONTAINER, NULL, \
311 WS_VISIBLE | WS_TABSTOP | 0, \
312 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
313
314 /* ******************************************************************
315 *
316 * Dialog formatter entry points
317 *
318 ********************************************************************/
319
320 #ifndef FCF_CLOSEBUTTON
321 #define FCF_CLOSEBUTTON 0x04000000L // toolkit 4 only
322 #endif
323
324 #define FCF_FIXED_DLG FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN | FCF_CLOSEBUTTON
325 #define FCF_SIZEABLE_DLG FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_NOBYTEALIGN | FCF_CLOSEBUTTON
326
327 APIRET XWPENTRY dlghCreateDlg(HWND *phwndDlg,
328 HWND hwndOwner,
329 ULONG flCreateFlags,
330 PFNWP pfnwpDialogProc,
331 PCSZ pcszDlgTitle,
332 PCDLGHITEM paDlgItems,
333 ULONG cDlgItems,
334 PVOID pCreateParams,
335 PCSZ pcszControlsFont);
336 typedef APIRET XWPENTRY DLGHCREATEDLG(HWND *phwndDlg,
337 HWND hwndOwner,
338 ULONG flCreateFlags,
339 PFNWP pfnwpDialogProc,
340 PCSZ pcszDlgTitle,
341 PCDLGHITEM paDlgItems,
342 ULONG cDlgItems,
343 PVOID pCreateParams,
344 PCSZ pcszControlsFont);
345 typedef DLGHCREATEDLG *PDLGHCREATEDLG;
346
347 #define DFFL_CREATECONTROLS 0x0002
348
349 APIRET dlghFormatDlg(HWND hwndDlg,
350 PCDLGHITEM paDlgItems,
351 ULONG cDlgItems,
352 PCSZ pcszControlsFont,
353 ULONG flFlags,
354 PSIZEL pszlClient,
355 PVOID *ppllControls);
356
357 VOID dlghResizeFrame(HWND hwndDlg,
358 PSIZEL pszlClient);
359
360 /* ******************************************************************
361 *
362 * Dialog arrays
363 *
364 ********************************************************************/
365
366 /*
367 *@@ DLGARRAY:
368 * dialog array structure used with dlghCreateArray.
369 * See remarks there.
370 *
371 *@@added V0.9.16 (2001-10-15) [umoeller]
372 */
373
374 typedef struct _DLGARRAY
375 {
376 DLGHITEM *paDlgItems; // array of DLGHITEM's, allocated once
377 // by dlghCreateArray
378 ULONG cDlgItemsMax, // copied from dlghCreateArray
379 cDlgItemsNow; // initially 0, raised after each
380 // dlghAppendToArray; pass this to the
381 // dialog formatter
382 } DLGARRAY, *PDLGARRAY;
383
384 APIRET dlghCreateArray(ULONG cMaxItems,
385 PDLGARRAY *ppArray);
386
387 APIRET dlghFreeArray(PDLGARRAY *ppArray);
388
389 APIRET dlghAppendToArray(PDLGARRAY pArray,
390 PCDLGHITEM paItems,
391 ULONG cItems);
392
393 /* ******************************************************************
394 *
395 * Standard dialogs
396 *
397 ********************************************************************/
398
399 /*
400 *@@ MSGBOXSTRINGS:
401 *
402 *@@added V0.9.13 (2001-06-21) [umoeller]
403 */
404
405 typedef struct _MSGBOXSTRINGS
406 {
407 const char *pcszYes, // "~Yes"
408 *pcszNo, // "~No"
409 *pcszOK, // "~OK"
410 *pcszCancel, // "~Cancel"
411 *pcszAbort, // "~Abort"
412 *pcszRetry, // "~Retry"
413 *pcszIgnore, // "~Ignore"
414 *pcszEnter,
415 *pcszYesToAll; // "Yes to ~all"
416 } MSGBOXSTRINGS, *PMSGBOXSTRINGS;
417
418 /* the following are in os2.h somewhere:
419 #define MB_OK 0x0000
420 #define MB_OKCANCEL 0x0001
421 #define MB_RETRYCANCEL 0x0002
422 #define MB_ABORTRETRYIGNORE 0x0003
423 #define MB_YESNO 0x0004
424 #define MB_YESNOCANCEL 0x0005
425 #define MB_CANCEL 0x0006
426 #define MB_ENTER 0x0007
427 #define MB_ENTERCANCEL 0x0008 */
428 // we add:
429 #define MB_YES_YES2ALL_NO 0x0009
430
431 /* the following are in os2.h somewhere:
432 #define MBID_OK 1
433 #define MBID_CANCEL 2
434 #define MBID_ABORT 3
435 #define MBID_RETRY 4
436 #define MBID_IGNORE 5
437 #define MBID_YES 6
438 #define MBID_NO 7
439 #define MBID_HELP 8
440 #define MBID_ENTER 9 */
441 // we add:
442 #define MBID_YES2ALL 10
443
444 APIRET dlghCreateMessageBox(HWND *phwndDlg,
445 HWND hwndOwner,
446 HPOINTER hptrIcon,
447 PCSZ pcszTitle,
448 PCSZ pcszMessage,
449 ULONG flFlags,
450 PCSZ pcszFont,
451 const MSGBOXSTRINGS *pStrings,
452 PULONG pulAlarmFlag);
453
454 ULONG dlghMessageBox(HWND hwndOwner,
455 HPOINTER hptrIcon,
456 PCSZ pcszTitle,
457 PCSZ pcszMessage,
458 ULONG flFlags,
459 PCSZ pcszFont,
460 const MSGBOXSTRINGS *pStrings);
461
462 #define TEBF_REMOVETILDE 0x0001
463 #define TEBF_REMOVEELLIPSE 0x0002
464 #define TEBF_SELECTALL 0x0004
465
466 PSZ dlghTextEntryBox(HWND hwndOwner,
467 PCSZ pcszTitle,
468 PCSZ pcszDescription,
469 PCSZ pcszDefault,
470 PCSZ pcszOK,
471 PCSZ pcszCancel,
472 ULONG ulMaxLen,
473 ULONG fl,
474 PCSZ pcszFont);
475
476 /* ******************************************************************
477 *
478 * Dialog input handlers
479 *
480 ********************************************************************/
481
482 VOID dlghSetPrevFocus(PVOID pvllWindows);
483
484 VOID dlghSetNextFocus(PVOID pvllWindows);
485
486 HWND dlghProcessMnemonic(PVOID pvllWindows,
487 USHORT usch);
488
489 BOOL dlghEnter(PVOID pvllWindows);
490
491#endif
492
493#if __cplusplus
494}
495#endif
496
Note: See TracBrowser for help on using the repository browser.