source: trunk/src/helpers/_call_filedlg.c

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

Sources as of 1.0.1.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 KB
Line 
1#define OS2EMX_PLAIN_CHAR
2 // this is needed for "os2emx.h"; if this is defined,
3 // emx will define PSZ as _signed_ char, otherwise
4 // as unsigned char
5
6#define INCL_DOSPROCESS
7#define INCL_DOSMISC
8#define INCL_DOSERRORS
9
10#define INCL_WINWINDOWMGR
11#define INCL_WINFRAMEMGR
12#define INCL_WINMENUS
13#define INCL_WINBUTTONS
14#define INCL_WINPOINTERS
15#define INCL_WINSTDCNR
16#define INCL_WINSTDFILE
17#define INCL_WINTIMER
18
19#include <os2.h>
20
21#include <stdlib.h>
22#include <string.h>
23#include <stdio.h>
24
25#include "setup.h" // code generation and debugging options
26
27#include "..\..\..\xworkplace\include\xwpapi.h"
28
29#include "helpers\call_file_dlg.c"
30#include "helpers\cnrh.h"
31#include "helpers\comctl.h"
32#include "helpers\nls.h"
33#include "helpers\standards.h"
34#include "helpers\stringh.h"
35#include "helpers\winh.h"
36#include "helpers\gpih.h"
37
38PCSZ WC_CLIENT = "MyClient";
39
40/*
41 *@@ NewWinFileDlg:
42 * replacement for WinFileDlg. Use similarly.
43 */
44
45HWND APIENTRY NewWinFileDlg(HWND hwndOwner,
46 PFILEDLG pfd) // WinFileDlg
47{
48 HWND hwndReturn = NULLHANDLE;
49 BOOL fCallDefault = TRUE;
50
51 hwndReturn = ImplCallFileDlg(hwndOwner, pfd, &fCallDefault);
52
53 if (fCallDefault)
54 // something went wrong:
55 hwndReturn = WinFileDlg(HWND_DESKTOP,
56 hwndOwner,
57 pfd);
58
59 return hwndReturn;
60}
61
62/*
63 *@@ ShowFileDlg:
64 *
65 */
66
67VOID ShowFileDlg(HWND hwndFrame)
68{
69 FILEDLG fd;
70
71 memset(&fd, 0, sizeof(FILEDLG));
72 fd.cbSize = sizeof(FILEDLG);
73 fd.fl = FDS_CENTER | FDS_OPEN_DIALOG;
74
75 strcpy(fd.szFullFile, "C:\\*");
76
77 if (NewWinFileDlg(hwndFrame,
78 &fd))
79 {
80 CHAR sz[1000];
81 sprintf(sz, "got: \"%s\"", fd.szFullFile);
82 WinMessageBox(HWND_DESKTOP, hwndFrame,
83 sz,
84 "File:",
85 0,
86 MB_OK | MB_MOVEABLE);
87 }
88 else
89 WinMessageBox(HWND_DESKTOP, hwndFrame,
90 "file dlg returned FALSE",
91 "File:",
92 0,
93 MB_OK | MB_MOVEABLE);
94}
95
96/*
97 *@@ GROUPRECORD:
98 *
99 */
100
101typedef struct _GROUPRECORD
102{
103 RECORDCORE recc;
104
105 ULONG gid;
106 CHAR szGroupName[100]; // group name
107 PSZ pszMembers;
108
109} GROUPRECORD, *PGROUPRECORD;
110
111PFNWP G_pfnwpFrameOrig;
112
113#define RECORD_COUNT 20000
114
115PGROUPRECORD G_paRecs[RECORD_COUNT];
116
117CHAR G_szText[] = "Longer test string with increasing length";
118
119/*
120 *@@ fnwpSubclFrame:
121 *
122 */
123
124MRESULT EXPENTRY fnwpSubclFrame(HWND hwndFrame, ULONG msg, MPARAM mp1, MPARAM mp2)
125{
126 MRESULT mrc = 0;
127
128 switch (msg)
129 {
130 case WM_COMMAND:
131 if (SHORT1FROMMP(mp1) == 1000)
132 ShowFileDlg(hwndFrame);
133 break;
134
135 case WM_CONTROL:
136 if (SHORT1FROMMP(mp1) == FID_CLIENT)
137 {
138 switch (SHORT2FROMMP(mp1))
139 {
140 case CN_VIEWPORTCHANGED:
141 {
142 PCNRVIEWPORT pcvp = (PCNRVIEWPORT)mp2;
143
144 CHAR szTemp[100],
145 szNLS1[20],
146 szNLS2[20],
147 szNLS3[20],
148 szNLS4[20],
149 szNLS5[20],
150 szNLS6[20];
151 sprintf(szTemp,
152 "Win: (%s/%s), WArea: (%s/%s), scrl: (%s/%s)",
153 nlsThousandsULong(szNLS1,
154 pcvp->szlWin.cx,
155 '.'),
156 nlsThousandsULong(szNLS2,
157 pcvp->szlWin.cy,
158 '.'),
159 nlsThousandsULong(szNLS3,
160 pcvp->szlWorkarea.cx,
161 '.'),
162 nlsThousandsULong(szNLS4,
163 pcvp->szlWorkarea.cy,
164 '.'),
165 nlsThousandsULong(szNLS5,
166 pcvp->ptlScroll.x,
167 '.'),
168 nlsThousandsULong(szNLS6,
169 pcvp->ptlScroll.y,
170 '.'));
171 WinSetWindowText(WinWindowFromID(hwndFrame, FID_STATUSBAR),
172 szTemp);
173 }
174 break;
175
176 case CN_ENTER:
177 {
178 CHAR sz[100];
179 PCSZ pcsz;
180 PNOTIFYRECORDENTER pnre = (PNOTIFYRECORDENTER)mp2;
181 if (!pnre->pRecord)
182 pcsz = "Whitespace";
183 else
184 {
185 sprintf(sz, "group %d", ((PGROUPRECORD)pnre->pRecord)->gid);
186 pcsz = sz;
187 }
188 winhDebugBox(hwndFrame,
189 "Enter pressed",
190 pcsz);
191 }
192 break;
193 }
194 }
195 break;
196
197 case WM_TIMER:
198 if ((ULONG)mp1 == 1)
199 {
200 static ul = 0,
201 ul2 = 1;
202
203 HWND hwndCnr = WinWindowFromID(hwndFrame, FID_CLIENT);
204
205 PGROUPRECORD precThis = G_paRecs[ul];
206
207 ULONG ulTimeNow;
208 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT,
209 &ulTimeNow,
210 sizeof(ulTimeNow));
211
212 strhncpy0(precThis->szGroupName,
213 G_szText,
214 ul2++);
215
216 WinSendMsg(hwndCnr,
217 CM_INVALIDATERECORD,
218 (MPARAM)&precThis,
219 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
220
221 if (++ul >= RECORD_COUNT)
222 ul = 0;
223 if (ul2 > strlen(G_szText))
224 ul2 = 1;
225 }
226 else
227 mrc = G_pfnwpFrameOrig(hwndFrame, msg, mp1, mp2);
228 break;
229
230 default:
231 mrc = G_pfnwpFrameOrig(hwndFrame, msg, mp1, mp2);
232 break;
233
234 }
235
236 return mrc;
237}
238
239/*
240 *@@ main:
241 *
242 */
243
244int main(int argc, char *argv[])
245{
246 HAB hab;
247 HMQ hmq;
248
249 #undef TBBS_TEXT
250 #define TBBS_TEXT 0
251
252 #define TBBS_COMMON TBBS_AUTORESIZE | TBBS_FLAT | TBBS_HILITE | WS_VISIBLE
253
254 CHAR szOpen[200],
255 szExit[200];
256
257 TOOLBARCONTROL aControls[] =
258 {
259 /*
260 WC_CCTL_TBBUTTON,
261 szExit,
262 TBBS_COMMON | TBBS_BIGICON | TBBS_TEXT | TBBS_SYSCOMMAND,
263 SC_CLOSE,
264 10,
265 10,
266
267 WC_CCTL_TBBUTTON,
268 szExit,
269 TBBS_COMMON | TBBS_BIGICON,
270 0,
271 10,
272 10,
273
274 WC_CCTL_TBBUTTON,
275 szExit,
276 TBBS_COMMON | TBBS_MINIICON,
277 0,
278 10,
279 10,
280 */
281
282 WC_CCTL_TBBUTTON,
283 szOpen,
284 TBBS_COMMON | TBBS_MINIICON | TBBS_TEXT,
285 1000,
286 10,
287 10,
288
289 WC_CCTL_TBBUTTON,
290 "Toggle\ntest",
291 TBBS_COMMON | TBBS_TEXT | TBBS_CHECK,
292 1001,
293 10,
294 10,
295
296 WC_CCTL_SEPARATOR,
297 NULL,
298 WS_VISIBLE | SEPS_VERTICAL,
299 1002,
300 10,
301 10,
302
303 WC_CCTL_TBBUTTON,
304 "Group 1",
305 TBBS_COMMON | TBBS_TEXT | TBBS_RADIO | TBBS_CHECKINITIAL,
306 1101,
307 10,
308 10,
309
310 WC_CCTL_TBBUTTON,
311 "Group 2",
312 TBBS_COMMON | TBBS_TEXT | TBBS_RADIO,
313 1102,
314 10,
315 10,
316
317 WC_CCTL_TBBUTTON,
318 "Group 3",
319 TBBS_COMMON | TBBS_TEXT | TBBS_RADIO,
320 1103,
321 10,
322 10,
323
324 };
325
326 EXTFRAMECDATA xfd =
327 {
328 NULL, // pswpFrame
329 FCF_TITLEBAR
330 | FCF_SYSMENU
331 | FCF_MINMAX
332 | FCF_SIZEBORDER
333 | FCF_NOBYTEALIGN
334 | FCF_SHELLPOSITION
335 | FCF_TASKLIST,
336 XFCF_TOOLBAR | XFCF_FORCETBOWNER | XFCF_STATUSBAR,
337 WS_VISIBLE, // ulFrameStyle
338 "Test File Dialog", // pcszFrameTitle
339 0, // ulResourcesID
340#ifdef __USE_PM_CNR__
341 WC_CONTAINER,
342#else
343 WC_CCTL_CNR,
344#endif
345 WS_VISIBLE | CCS_EXTENDSEL, // flStyleClient
346 0, // ulID
347 NULL,
348 HINI_USER,
349 "XWorkplace Test Apps",
350 "CallFileDlgPos",
351
352 ARRAYITEMCOUNT(aControls),
353 aControls
354 };
355
356 HWND hwndFrame,
357 hwndClient,
358 hwndStatusBar,
359 hwndToolBar,
360 hwndMenu,
361 hwndSubmenu;
362 QMSG qmsg;
363
364 hab = WinInitialize(0);
365 hmq = WinCreateMsgQueue(hab, 0);
366
367 winhInitGlobals();
368
369 ctlRegisterToolbar(hab);
370 ctlRegisterSeparatorLine(hab);
371 ctlRegisterXCnr(hab);
372
373 sprintf(szOpen,
374 "#%d#Open",
375 WinQuerySysPointer(HWND_DESKTOP,
376 SPTR_ICONINFORMATION,
377 FALSE));
378
379 sprintf(szExit,
380 "#%d#Exit",
381 WinQuerySysPointer(HWND_DESKTOP,
382 SPTR_ICONWARNING,
383 FALSE));
384
385 hwndFrame = ctlCreateStdWindow(&xfd, &hwndClient);
386
387 hwndToolBar = WinWindowFromID(hwndFrame, FID_TOOLBAR);
388 hwndStatusBar = WinWindowFromID(hwndFrame, FID_STATUSBAR);
389
390 WinSetWindowText(hwndToolBar, "Tool bar");
391 WinSetWindowText(hwndStatusBar, "Status bar");
392
393 WinSendMsg(hwndFrame, WM_UPDATEFRAME, MPNULL, MPNULL);
394
395 if (G_pfnwpFrameOrig = WinSubclassWindow(hwndFrame, fnwpSubclFrame))
396 {
397 XFIELDINFO xfi[4];
398 PFIELDINFO pfi = NULL;
399 int i = 0;
400 PGROUPRECORD preccFirst;
401
402 CHAR szTest[12];
403 ULONG len;
404
405 len = strlcpy(szTest, "~Group name", sizeof(szTest));
406 strhKillChar(szTest, '~', &len);
407
408 // set up cnr details view
409 xfi[i].ulFieldOffset = FIELDOFFSET(GROUPRECORD, gid);
410 xfi[i].pszColumnTitle = "gid";
411 xfi[i].ulDataType = CFA_ULONG;
412 xfi[i++].ulOrientation = CFA_RIGHT;
413
414 xfi[i].ulFieldOffset = FIELDOFFSET(GROUPRECORD, recc.pszIcon);
415 xfi[i].pszColumnTitle = szTest; // "Group name"; // @@todo localize
416 xfi[i].ulDataType = CFA_STRING;
417 xfi[i++].ulOrientation = CFA_CENTER;
418
419 xfi[i].ulFieldOffset = FIELDOFFSET(GROUPRECORD, pszMembers);
420 xfi[i].pszColumnTitle = "Members"; // @@todo localize
421 xfi[i].ulDataType = CFA_STRING;
422 xfi[i++].ulOrientation = CFA_LEFT;
423
424 pfi = cnrhSetFieldInfos(hwndClient,
425 xfi,
426 i, // array item count
427 TRUE, // draw lines
428 0); // return first column
429
430 BEGIN_CNRINFO()
431 {
432 cnrhSetView(CV_DETAIL | CA_DETAILSVIEWTITLES);
433 CnrInfo_.cyLineSpacing = 10;
434 ulSendFlags_ |= CMA_LINESPACING;
435 } END_CNRINFO(hwndClient);
436
437 if (preccFirst = (PGROUPRECORD)cnrhAllocRecords(hwndClient,
438 sizeof(GROUPRECORD),
439 RECORD_COUNT))
440 {
441 PGROUPRECORD preccThis = preccFirst,
442 preccEmph;
443 ULONG ul = 0;
444 while (preccThis)
445 {
446 G_paRecs[ul] = preccThis;
447
448 if (ul & 1)
449 preccThis->recc.flRecordAttr |= CRA_FILTERED;
450
451 if (ul == 4)
452 preccEmph = preccThis;
453
454 preccThis->gid = ul++;
455 sprintf(preccThis->szGroupName, "group %d", preccThis->gid);
456 preccThis->recc.pszIcon = preccThis->szGroupName;
457
458 preccThis->pszMembers = "longer string than title";
459
460 preccThis = (PGROUPRECORD)preccThis->recc.preccNextRecord;
461 }
462
463 cnrhInsertRecords(hwndClient,
464 NULL,
465 (PRECORDCORE)preccFirst,
466 TRUE,
467 NULL,
468 CRA_RECORDREADONLY,
469 RECORD_COUNT);
470
471 WinSendMsg(hwndClient,
472 CM_SETRECORDEMPHASIS,
473 (MPARAM)preccEmph,
474 MPFROM2SHORT(TRUE, CRA_SELECTED));
475 }
476 }
477
478 WinStartTimer(hab, hwndFrame, 1, 100);
479
480 while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
481 WinDispatchMsg(hab, &qmsg);
482
483 WinDestroyMsgQueue(hmq);
484 WinTerminate(hab);
485
486 return 0;
487}
488
489
Note: See TracBrowser for help on using the repository browser.