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

Last change on this file since 157 was 157, 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.3 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 LOAD_STRING ((PCSZ)-1)
206
207 #define COMMON_SPACING 3
208
209 #define PM_GROUP_SPACING_X 16
210 #define PM_GROUP_SPACING_TOP 16
211
212 // the following require INCL_WINSTATICS
213
214 #define CONTROLDEF_GROUP(pcsz, id, cx, cy) { WC_STATIC, pcsz, \
215 WS_VISIBLE | SS_GROUPBOX | DT_MNEMONIC, \
216 id, CTL_COMMON_FONT, 0, { cx, cy }, 0 }
217
218 #define CDEF_GROUP_AUTO(id) CONTROLDEF_GROUP(LOAD_STRING, id, -1, -1)
219
220 #define CONTROLDEF_TEXT(pcsz, id, cx, cy) { WC_STATIC, pcsz, \
221 WS_VISIBLE | SS_TEXT | DT_LEFT | DT_VCENTER | DT_MNEMONIC, \
222 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
223
224 #define CONTROLDEF_TEXT_CENTER(pcsz, id, cx, cy) { WC_STATIC, pcsz, \
225 WS_VISIBLE | SS_TEXT | DT_CENTER | DT_VCENTER | DT_MNEMONIC, \
226 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
227
228 #define CONTROLDEF_TEXT_WORDBREAK(pcsz, id, cx) { WC_STATIC, pcsz, \
229 WS_VISIBLE | SS_TEXT | DT_LEFT | DT_TOP | DT_WORDBREAK, \
230 id, CTL_COMMON_FONT, 0, {cx, -1}, COMMON_SPACING }
231
232 #define CONTROLDEF_ICON(hptr, id) { WC_STATIC, (PCSZ)(hptr), \
233 WS_VISIBLE | SS_ICON | DT_LEFT | DT_VCENTER, \
234 id, CTL_COMMON_FONT, 0, {-1, -1}, COMMON_SPACING }
235
236 #define CONTROLDEF_BITMAP(hbm, id) { WC_STATIC, (PCSZ)(hbm), \
237 WS_VISIBLE | SS_BITMAP | DT_LEFT | DT_VCENTER, \
238 id, CTL_COMMON_FONT, 0, {-1, -1}, COMMON_SPACING }
239
240 // the following require INCL_WINBUTTONS
241
242 #define CONTROLDEF_DEFPUSHBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
243 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_DEFAULT, \
244 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
245
246 #define CONTROLDEF_PUSHBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
247 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, \
248 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
249
250 #define CONTROLDEF_DEFNOFOCUSBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
251 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_DEFAULT | BS_NOPOINTERFOCUS, \
252 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
253
254 #define CONTROLDEF_NOFOCUSBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
255 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_NOPOINTERFOCUS, \
256 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
257
258 #define CONTROLDEF_HELPPUSHBUTTON(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
259 WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_HELP, \
260 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
261
262 #define CONTROLDEF_AUTOCHECKBOX(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
263 WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, \
264 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
265
266 #define CDEF_AUTOCB_AUTO(id) CONTROLDEF_AUTOCHECKBOX(LOAD_STRING, id, -1, -1)
267
268 #define CONTROLDEF_FIRST_AUTORADIO(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
269 WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON | WS_GROUP, \
270 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
271
272 #define CONTROLDEF_NEXT_AUTORADIO(pcsz, id, cx, cy) { WC_BUTTON, pcsz, \
273 WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON, \
274 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
275
276 // the following require INCL_WINENTRYFIELDS
277
278 #define CONTROLDEF_ENTRYFIELD(pcsz, id, cx, cy) { WC_ENTRYFIELD, pcsz, \
279 WS_VISIBLE | WS_TABSTOP | ES_MARGIN | ES_AUTOSCROLL, \
280 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
281
282 #define CONTROLDEF_ENTRYFIELD_RO(pcsz, id, cx, cy) { WC_ENTRYFIELD, pcsz, \
283 WS_VISIBLE | WS_TABSTOP | ES_MARGIN | ES_READONLY | ES_AUTOSCROLL, \
284 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
285
286 // the following require INCL_WINMLE
287
288 #define CONTROLDEF_MLE(pcsz, id, cx, cy) { WC_MLE, pcsz, \
289 WS_VISIBLE | WS_TABSTOP | MLS_BORDER | MLS_IGNORETAB | MLS_WORDWRAP, \
290 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
291
292 // the following require INCL_WINLISTBOXES
293
294 #define CONTROLDEF_LISTBOX(id, cx, cy) { WC_LISTBOX, NULL, \
295 WS_VISIBLE | WS_TABSTOP | LS_HORZSCROLL | LS_NOADJUSTPOS, \
296 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
297
298 // the following require INCL_WINLISTBOXES and INCL_WINENTRYFIELDS
299
300 #define CONTROLDEF_DROPDOWN(id, cx, cy) { WC_COMBOBOX, NULL, \
301 WS_VISIBLE | WS_TABSTOP | LS_HORZSCROLL | CBS_DROPDOWN, \
302 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
303
304 #define CONTROLDEF_DROPDOWNLIST(id, cx, cy) { WC_COMBOBOX, NULL, \
305 WS_VISIBLE | WS_TABSTOP | LS_HORZSCROLL | CBS_DROPDOWNLIST, \
306 id, CTL_COMMON_FONT, 0, { cx, cy }, COMMON_SPACING }
307
308 // the following require INCL_WINSTDSPIN
309
310 #define CONTROLDEF_SPINBUTTON(id, cx, cy) { WC_SPINBUTTON, NULL, \
311 WS_VISIBLE | WS_TABSTOP | SPBS_MASTER | SPBS_NUMERICONLY | SPBS_JUSTCENTER | SPBS_FASTSPIN, \
312 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
313
314 // the following require INCL_WINSTDCNR
315
316 #define CONTROLDEF_CONTAINER(id, cx, cy) { WC_CONTAINER, NULL, \
317 WS_VISIBLE | WS_TABSTOP | 0, \
318 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING }
319
320 // the following require INCL_WINSTDSLIDER
321
322 #define CONTROLDEF_SLIDER(id, cx, cy, pctldata) { WC_SLIDER, NULL, \
323 WS_VISIBLE | WS_TABSTOP | WS_GROUP | SLS_HORIZONTAL | SLS_PRIMARYSCALE1 \
324 | SLS_BUTTONSRIGHT | SLS_SNAPTOINCREMENT, \
325 id, CTL_COMMON_FONT, 0, {cx, cy}, COMMON_SPACING, pctldata }
326
327 /* ******************************************************************
328 *
329 * Dialog formatter entry points
330 *
331 ********************************************************************/
332
333 #ifndef FCF_CLOSEBUTTON
334 #define FCF_CLOSEBUTTON 0x04000000L // toolkit 4 only
335 #endif
336
337 #define FCF_FIXED_DLG FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN | FCF_CLOSEBUTTON
338 #define FCF_SIZEABLE_DLG FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_NOBYTEALIGN | FCF_CLOSEBUTTON
339
340 APIRET XWPENTRY dlghCreateDlg(HWND *phwndDlg,
341 HWND hwndOwner,
342 ULONG flCreateFlags,
343 PFNWP pfnwpDialogProc,
344 PCSZ pcszDlgTitle,
345 PCDLGHITEM paDlgItems,
346 ULONG cDlgItems,
347 PVOID pCreateParams,
348 PCSZ pcszControlsFont);
349 typedef APIRET XWPENTRY DLGHCREATEDLG(HWND *phwndDlg,
350 HWND hwndOwner,
351 ULONG flCreateFlags,
352 PFNWP pfnwpDialogProc,
353 PCSZ pcszDlgTitle,
354 PCDLGHITEM paDlgItems,
355 ULONG cDlgItems,
356 PVOID pCreateParams,
357 PCSZ pcszControlsFont);
358 typedef DLGHCREATEDLG *PDLGHCREATEDLG;
359
360 #define DFFL_CREATECONTROLS 0x0002
361
362 APIRET dlghFormatDlg(HWND hwndDlg,
363 PCDLGHITEM paDlgItems,
364 ULONG cDlgItems,
365 PCSZ pcszControlsFont,
366 ULONG flFlags,
367 PSIZEL pszlClient,
368 PVOID *ppllControls);
369
370 VOID dlghResizeFrame(HWND hwndDlg,
371 PSIZEL pszlClient);
372
373 /* ******************************************************************
374 *
375 * Dialog arrays
376 *
377 ********************************************************************/
378
379 /*
380 *@@ DLGARRAY:
381 * dialog array structure used with dlghCreateArray.
382 * See remarks there.
383 *
384 *@@added V0.9.16 (2001-10-15) [umoeller]
385 */
386
387 typedef struct _DLGARRAY
388 {
389 DLGHITEM *paDlgItems; // array of DLGHITEM's, allocated once
390 // by dlghCreateArray
391 ULONG cDlgItemsMax, // copied from dlghCreateArray
392 cDlgItemsNow; // initially 0, raised after each
393 // dlghAppendToArray; pass this to the
394 // dialog formatter
395 } DLGARRAY, *PDLGARRAY;
396
397 APIRET dlghCreateArray(ULONG cMaxItems,
398 PDLGARRAY *ppArray);
399
400 APIRET dlghFreeArray(PDLGARRAY *ppArray);
401
402 APIRET dlghAppendToArray(PDLGARRAY pArray,
403 PCDLGHITEM paItems,
404 ULONG cItems);
405
406 /* ******************************************************************
407 *
408 * Standard dialogs
409 *
410 ********************************************************************/
411
412 /*
413 *@@ MSGBOXSTRINGS:
414 *
415 *@@added V0.9.13 (2001-06-21) [umoeller]
416 */
417
418 typedef struct _MSGBOXSTRINGS
419 {
420 const char *pcszYes, // "~Yes"
421 *pcszNo, // "~No"
422 *pcszOK, // "~OK"
423 *pcszCancel, // "~Cancel"
424 *pcszAbort, // "~Abort"
425 *pcszRetry, // "~Retry"
426 *pcszIgnore, // "~Ignore"
427 *pcszEnter,
428 *pcszYesToAll; // "Yes to ~all"
429 } MSGBOXSTRINGS, *PMSGBOXSTRINGS;
430
431 /* the following are in os2.h somewhere:
432 #define MB_OK 0x0000
433 #define MB_OKCANCEL 0x0001
434 #define MB_RETRYCANCEL 0x0002
435 #define MB_ABORTRETRYIGNORE 0x0003
436 #define MB_YESNO 0x0004
437 #define MB_YESNOCANCEL 0x0005
438 #define MB_CANCEL 0x0006
439 #define MB_ENTER 0x0007
440 #define MB_ENTERCANCEL 0x0008 */
441 // we add:
442 #define MB_YES_YES2ALL_NO 0x0009
443
444 /* the following are in os2.h somewhere:
445 #define MBID_OK 1
446 #define MBID_CANCEL 2
447 #define MBID_ABORT 3
448 #define MBID_RETRY 4
449 #define MBID_IGNORE 5
450 #define MBID_YES 6
451 #define MBID_NO 7
452 #define MBID_HELP 8
453 #define MBID_ENTER 9 */
454 // we add:
455 #define MBID_YES2ALL 10
456
457 APIRET dlghCreateMessageBox(HWND *phwndDlg,
458 HWND hwndOwner,
459 HPOINTER hptrIcon,
460 PCSZ pcszTitle,
461 PCSZ pcszMessage,
462 ULONG flFlags,
463 PCSZ pcszFont,
464 const MSGBOXSTRINGS *pStrings,
465 PULONG pulAlarmFlag);
466
467 ULONG dlghMessageBox(HWND hwndOwner,
468 HPOINTER hptrIcon,
469 PCSZ pcszTitle,
470 PCSZ pcszMessage,
471 ULONG flFlags,
472 PCSZ pcszFont,
473 const MSGBOXSTRINGS *pStrings);
474
475 #define TEBF_REMOVETILDE 0x0001
476 #define TEBF_REMOVEELLIPSE 0x0002
477 #define TEBF_SELECTALL 0x0004
478
479 PSZ dlghTextEntryBox(HWND hwndOwner,
480 PCSZ pcszTitle,
481 PCSZ pcszDescription,
482 PCSZ pcszDefault,
483 PCSZ pcszOK,
484 PCSZ pcszCancel,
485 ULONG ulMaxLen,
486 ULONG fl,
487 PCSZ pcszFont);
488
489 /* ******************************************************************
490 *
491 * Dialog input handlers
492 *
493 ********************************************************************/
494
495 VOID dlghSetPrevFocus(PVOID pvllWindows);
496
497 VOID dlghSetNextFocus(PVOID pvllWindows);
498
499 HWND dlghProcessMnemonic(PVOID pvllWindows,
500 USHORT usch);
501
502 BOOL dlghEnter(PVOID pvllWindows);
503
504#endif
505
506#if __cplusplus
507}
508#endif
509
Note: See TracBrowser for help on using the repository browser.