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

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

Misc fixes.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 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 // the following require INCL_WINSTDSLIDER
315
316 #define CONTROLDEF_SLIDER(id, cx, cy, pctldata) { WC_SLIDER, NULL, \
317 WS_VISIBLE | WS_TABSTOP | WS_GROUP | SLS_HORIZONTAL | SLS_PRIMARYSCALE1 \
318 | SLS_BUTTONSRIGHT | SLS_SNAPTOINCREMENT, \
319 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING, pctldata }
320
321 /* ******************************************************************
322 *
323 * Dialog formatter entry points
324 *
325 ********************************************************************/
326
327 #ifndef FCF_CLOSEBUTTON
328 #define FCF_CLOSEBUTTON 0x04000000L // toolkit 4 only
329 #endif
330
331 #define FCF_FIXED_DLG FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN | FCF_CLOSEBUTTON
332 #define FCF_SIZEABLE_DLG FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_NOBYTEALIGN | FCF_CLOSEBUTTON
333
334 APIRET XWPENTRY dlghCreateDlg(HWND *phwndDlg,
335 HWND hwndOwner,
336 ULONG flCreateFlags,
337 PFNWP pfnwpDialogProc,
338 PCSZ pcszDlgTitle,
339 PCDLGHITEM paDlgItems,
340 ULONG cDlgItems,
341 PVOID pCreateParams,
342 PCSZ pcszControlsFont);
343 typedef APIRET XWPENTRY DLGHCREATEDLG(HWND *phwndDlg,
344 HWND hwndOwner,
345 ULONG flCreateFlags,
346 PFNWP pfnwpDialogProc,
347 PCSZ pcszDlgTitle,
348 PCDLGHITEM paDlgItems,
349 ULONG cDlgItems,
350 PVOID pCreateParams,
351 PCSZ pcszControlsFont);
352 typedef DLGHCREATEDLG *PDLGHCREATEDLG;
353
354 #define DFFL_CREATECONTROLS 0x0002
355
356 APIRET dlghFormatDlg(HWND hwndDlg,
357 PCDLGHITEM paDlgItems,
358 ULONG cDlgItems,
359 PCSZ pcszControlsFont,
360 ULONG flFlags,
361 PSIZEL pszlClient,
362 PVOID *ppllControls);
363
364 VOID dlghResizeFrame(HWND hwndDlg,
365 PSIZEL pszlClient);
366
367 /* ******************************************************************
368 *
369 * Dialog arrays
370 *
371 ********************************************************************/
372
373 /*
374 *@@ DLGARRAY:
375 * dialog array structure used with dlghCreateArray.
376 * See remarks there.
377 *
378 *@@added V0.9.16 (2001-10-15) [umoeller]
379 */
380
381 typedef struct _DLGARRAY
382 {
383 DLGHITEM *paDlgItems; // array of DLGHITEM's, allocated once
384 // by dlghCreateArray
385 ULONG cDlgItemsMax, // copied from dlghCreateArray
386 cDlgItemsNow; // initially 0, raised after each
387 // dlghAppendToArray; pass this to the
388 // dialog formatter
389 } DLGARRAY, *PDLGARRAY;
390
391 APIRET dlghCreateArray(ULONG cMaxItems,
392 PDLGARRAY *ppArray);
393
394 APIRET dlghFreeArray(PDLGARRAY *ppArray);
395
396 APIRET dlghAppendToArray(PDLGARRAY pArray,
397 PCDLGHITEM paItems,
398 ULONG cItems);
399
400 /* ******************************************************************
401 *
402 * Standard dialogs
403 *
404 ********************************************************************/
405
406 /*
407 *@@ MSGBOXSTRINGS:
408 *
409 *@@added V0.9.13 (2001-06-21) [umoeller]
410 */
411
412 typedef struct _MSGBOXSTRINGS
413 {
414 const char *pcszYes, // "~Yes"
415 *pcszNo, // "~No"
416 *pcszOK, // "~OK"
417 *pcszCancel, // "~Cancel"
418 *pcszAbort, // "~Abort"
419 *pcszRetry, // "~Retry"
420 *pcszIgnore, // "~Ignore"
421 *pcszEnter,
422 *pcszYesToAll; // "Yes to ~all"
423 } MSGBOXSTRINGS, *PMSGBOXSTRINGS;
424
425 /* the following are in os2.h somewhere:
426 #define MB_OK 0x0000
427 #define MB_OKCANCEL 0x0001
428 #define MB_RETRYCANCEL 0x0002
429 #define MB_ABORTRETRYIGNORE 0x0003
430 #define MB_YESNO 0x0004
431 #define MB_YESNOCANCEL 0x0005
432 #define MB_CANCEL 0x0006
433 #define MB_ENTER 0x0007
434 #define MB_ENTERCANCEL 0x0008 */
435 // we add:
436 #define MB_YES_YES2ALL_NO 0x0009
437
438 /* the following are in os2.h somewhere:
439 #define MBID_OK 1
440 #define MBID_CANCEL 2
441 #define MBID_ABORT 3
442 #define MBID_RETRY 4
443 #define MBID_IGNORE 5
444 #define MBID_YES 6
445 #define MBID_NO 7
446 #define MBID_HELP 8
447 #define MBID_ENTER 9 */
448 // we add:
449 #define MBID_YES2ALL 10
450
451 APIRET dlghCreateMessageBox(HWND *phwndDlg,
452 HWND hwndOwner,
453 HPOINTER hptrIcon,
454 PCSZ pcszTitle,
455 PCSZ pcszMessage,
456 ULONG flFlags,
457 PCSZ pcszFont,
458 const MSGBOXSTRINGS *pStrings,
459 PULONG pulAlarmFlag);
460
461 ULONG dlghMessageBox(HWND hwndOwner,
462 HPOINTER hptrIcon,
463 PCSZ pcszTitle,
464 PCSZ pcszMessage,
465 ULONG flFlags,
466 PCSZ pcszFont,
467 const MSGBOXSTRINGS *pStrings);
468
469 #define TEBF_REMOVETILDE 0x0001
470 #define TEBF_REMOVEELLIPSE 0x0002
471 #define TEBF_SELECTALL 0x0004
472
473 PSZ dlghTextEntryBox(HWND hwndOwner,
474 PCSZ pcszTitle,
475 PCSZ pcszDescription,
476 PCSZ pcszDefault,
477 PCSZ pcszOK,
478 PCSZ pcszCancel,
479 ULONG ulMaxLen,
480 ULONG fl,
481 PCSZ pcszFont);
482
483 /* ******************************************************************
484 *
485 * Dialog input handlers
486 *
487 ********************************************************************/
488
489 VOID dlghSetPrevFocus(PVOID pvllWindows);
490
491 VOID dlghSetNextFocus(PVOID pvllWindows);
492
493 HWND dlghProcessMnemonic(PVOID pvllWindows,
494 USHORT usch);
495
496 BOOL dlghEnter(PVOID pvllWindows);
497
498#endif
499
500#if __cplusplus
501}
502#endif
503
Note: See TracBrowser for help on using the repository browser.