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

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

Lots of changes from the last three weeks.

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