1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: objcnr.c 488 2006-09-07 05:10:59Z root $
|
---|
5 |
|
---|
6 | Object containers
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2005, 2006 Steven H. Levine
|
---|
10 |
|
---|
11 | 24 May 05 SHL Rework for CNRITEM.szSubject
|
---|
12 | 13 Jul 06 SHL Use Runtime_Error
|
---|
13 | 01 Sep 06 SHL Do not complain for normal cancel
|
---|
14 |
|
---|
15 | ***********************************************************************/
|
---|
16 |
|
---|
17 | #define INCL_DOS
|
---|
18 | #define INCL_WIN
|
---|
19 | #include <os2.h>
|
---|
20 |
|
---|
21 | #include <stdio.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <ctype.h>
|
---|
25 |
|
---|
26 | #include "fm3dll.h"
|
---|
27 | #include "fm3dlg.h"
|
---|
28 | #include "fm3str.h"
|
---|
29 |
|
---|
30 | typedef struct {
|
---|
31 | CHAR *filename;
|
---|
32 | HWND hwndCnr;
|
---|
33 | CHAR *stopflag;
|
---|
34 | } DIRSIZE;
|
---|
35 |
|
---|
36 | typedef struct {
|
---|
37 | CHAR *dirname;
|
---|
38 | CHAR stopflag;
|
---|
39 | BOOL dying;
|
---|
40 | BOOL working;
|
---|
41 | } TEMP;
|
---|
42 |
|
---|
43 | #pragma data_seg(DATA1)
|
---|
44 |
|
---|
45 | static PSZ pszSrcFile = __FILE__;
|
---|
46 |
|
---|
47 | static HWND objcnrwnd;
|
---|
48 |
|
---|
49 | #pragma alloc_text(OBJCNR,ProcessDir,FillCnrs,ObjCnrDlgProc)
|
---|
50 |
|
---|
51 | static VOID ProcessDir(HWND hwndCnr,CHAR *filename,PCNRITEM pciParent,
|
---|
52 | CHAR *stopflag)
|
---|
53 | {
|
---|
54 | CHAR maskstr[CCHMAXPATH],*endpath,*p;
|
---|
55 | ULONG nm,ulM;
|
---|
56 | HDIR hdir;
|
---|
57 | FILEFINDBUF3 *ffb,*fft;
|
---|
58 | APIRET rc;
|
---|
59 | RECORDINSERT ri;
|
---|
60 | PCNRITEM pciP;
|
---|
61 |
|
---|
62 | ffb = xmalloc(sizeof(FILEFINDBUF3),pszSrcFile,__LINE__);
|
---|
63 | if(!ffb)
|
---|
64 | return;
|
---|
65 | strcpy(maskstr,filename);
|
---|
66 | if(maskstr[strlen(maskstr) - 1] != '\\')
|
---|
67 | strcat(maskstr,"\\");
|
---|
68 | endpath = &maskstr[strlen(maskstr)];
|
---|
69 | strcat(maskstr,"*");
|
---|
70 | hdir = HDIR_CREATE;
|
---|
71 | nm = 1L;
|
---|
72 | rc = DosFindFirst(filename, &hdir,
|
---|
73 | FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
|
---|
74 | FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
|
---|
75 | ffb,sizeof(FILEFINDBUF3),&nm,FIL_STANDARD);
|
---|
76 | if(!rc)
|
---|
77 | DosFindClose(hdir);
|
---|
78 |
|
---|
79 | if(rc) { /* work around furshluginer FAT bug... */
|
---|
80 | if(IsRoot(filename))
|
---|
81 | rc = 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 | if((!rc && (ffb->attrFile & FILE_DIRECTORY))) {
|
---|
85 | pciP = WinSendMsg(hwndCnr,CM_ALLOCRECORD,MPFROMLONG(EXTRA_RECORD_BYTES2),
|
---|
86 | MPFROMLONG(1L));
|
---|
87 | if(!pciP) {
|
---|
88 | free(ffb);
|
---|
89 | return;
|
---|
90 | }
|
---|
91 | strcpy(pciP->szFileName,filename);
|
---|
92 | pciP->pszDispAttr = pciP->szDispAttr;
|
---|
93 | pciP->pszSubject = pciP->szSubject;
|
---|
94 | pciP->pszLongname = pciP->szLongname;
|
---|
95 | pciP->pszDispAttr = pciP->szDispAttr;
|
---|
96 | *pciP->szDispAttr = *pciP->szLongname = *pciP->szSubject = 0;
|
---|
97 | if(strlen(filename) < 4)
|
---|
98 | pciP->pszFileName = pciP->szFileName;
|
---|
99 | else {
|
---|
100 | p = strrchr(pciP->szFileName,'\\');
|
---|
101 | if(!p)
|
---|
102 | pciP->pszFileName = pciP->szFileName;
|
---|
103 | else if(*(p + 1))
|
---|
104 | p++;
|
---|
105 | pciP->pszFileName = p;
|
---|
106 | }
|
---|
107 | pciP->rc.pszIcon = pciP->pszFileName;
|
---|
108 | if(fForceUpper)
|
---|
109 | strupr(pciP->szFileName);
|
---|
110 | else if(fForceLower)
|
---|
111 | strlwr(pciP->szFileName);
|
---|
112 | pciP->rc.flRecordAttr |= CRA_RECORDREADONLY;
|
---|
113 | }
|
---|
114 | else {
|
---|
115 | free(ffb);
|
---|
116 | Dos_Error(MB_ENTER,
|
---|
117 | rc,
|
---|
118 | HWND_DESKTOP,
|
---|
119 | pszSrcFile,
|
---|
120 | __LINE__,
|
---|
121 | GetPString(IDS_CANTFINDDIRTEXT),
|
---|
122 | filename);
|
---|
123 | return;
|
---|
124 | }
|
---|
125 | {
|
---|
126 | HPOINTER hptr;
|
---|
127 |
|
---|
128 | hptr = WinLoadFileIcon(pciP->szFileName, FALSE);
|
---|
129 | if(hptr)
|
---|
130 | pciP->rc.hptrIcon = hptr;
|
---|
131 | }
|
---|
132 | if(!pciP->rc.hptrIcon || pciP->rc.hptrIcon == hptrFile) /* OS/2 bug bug bug bug */
|
---|
133 | pciP->rc.hptrIcon = hptrDir;
|
---|
134 | memset(&ri,0,sizeof(RECORDINSERT));
|
---|
135 | ri.cb = sizeof(RECORDINSERT);
|
---|
136 | ri.pRecordOrder = (PRECORDCORE)CMA_END;
|
---|
137 | ri.pRecordParent = (PRECORDCORE)pciParent;
|
---|
138 | ri.zOrder = (USHORT)CMA_TOP;
|
---|
139 | ri.cRecordsInsert = 1L;
|
---|
140 | ri.fInvalidateRecord = TRUE;
|
---|
141 | if(!WinSendMsg(hwndCnr,CM_INSERTRECORD,MPFROMP(pciP),MPFROMP(&ri))) {
|
---|
142 | free(ffb);
|
---|
143 | return;
|
---|
144 | }
|
---|
145 | hdir = HDIR_CREATE;
|
---|
146 | if(!isalpha(*maskstr) || maskstr[1] != ':' || maskstr[2] != '\\' ||
|
---|
147 | ((driveflags[toupper(*maskstr) - 'A'] & DRIVE_REMOTE) && fRemoteBug))
|
---|
148 | ulM = 1L;
|
---|
149 | else
|
---|
150 | ulM = min(FilesToGet,225);
|
---|
151 | if(ulM > 1L) {
|
---|
152 | fft = xrealloc(ffb, sizeof(FILEFINDBUF3) * ulM,pszSrcFile,__LINE__);
|
---|
153 | if(!fft)
|
---|
154 | ulM = 1L;
|
---|
155 | else
|
---|
156 | ffb = fft;
|
---|
157 | }
|
---|
158 | nm = ulM;
|
---|
159 | rc = DosFindFirst(maskstr, &hdir,
|
---|
160 | FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
|
---|
161 | FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,ffb,
|
---|
162 | sizeof(FILEFINDBUF3) * ulM,&nm,FIL_STANDARD);
|
---|
163 | if(!rc) {
|
---|
164 |
|
---|
165 | register PBYTE fb = (PBYTE)ffb;
|
---|
166 | FILEFINDBUF3 *pffbFile;
|
---|
167 | ULONG x;
|
---|
168 |
|
---|
169 | while(!rc) {
|
---|
170 | for(x = 0L;x < nm;x++) {
|
---|
171 | pffbFile = (FILEFINDBUF3 *)fb;
|
---|
172 | if(*stopflag)
|
---|
173 | break;
|
---|
174 | if((pffbFile->attrFile & FILE_DIRECTORY) &&
|
---|
175 | (*pffbFile->achName != '.' || (pffbFile->achName[1] &&
|
---|
176 | pffbFile->achName[1] != '.'))) {
|
---|
177 | strcpy(endpath,pffbFile->achName);
|
---|
178 | ProcessDir(hwndCnr,maskstr,pciP,stopflag);
|
---|
179 | }
|
---|
180 | if(!pffbFile->oNextEntryOffset)
|
---|
181 | break;
|
---|
182 | fb += pffbFile->oNextEntryOffset;
|
---|
183 | }
|
---|
184 | DosSleep(0L);
|
---|
185 | if(*stopflag)
|
---|
186 | break;
|
---|
187 | nm = ulM;
|
---|
188 | rc = DosFindNext(hdir,ffb,sizeof(FILEFINDBUF3) * ulM,&nm);
|
---|
189 | }
|
---|
190 | DosFindClose(hdir);
|
---|
191 | }
|
---|
192 | free(ffb);
|
---|
193 | WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPFROMP(&pciP),
|
---|
194 | MPFROM2SHORT(1,0));
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | static VOID FillCnrs (VOID *args)
|
---|
199 | {
|
---|
200 | HAB hab;
|
---|
201 | HMQ hmq;
|
---|
202 | DIRSIZE *dirsize = (DIRSIZE *)args;
|
---|
203 |
|
---|
204 | if(!dirsize)
|
---|
205 | return;
|
---|
206 |
|
---|
207 | DosError(FERR_DISABLEHARDERR);
|
---|
208 |
|
---|
209 | hab = WinInitialize(0);
|
---|
210 | if(hab) {
|
---|
211 | hmq = WinCreateMsgQueue(hab,0);
|
---|
212 | if(hmq) {
|
---|
213 | WinCancelShutdown(hmq,TRUE);
|
---|
214 | ProcessDir(dirsize->hwndCnr,dirsize->filename,(PCNRITEM)NULL,
|
---|
215 | dirsize->stopflag);
|
---|
216 | DosPostEventSem(CompactSem);
|
---|
217 | WinDestroyMsgQueue(hmq);
|
---|
218 | }
|
---|
219 | WinTerminate(hab);
|
---|
220 | }
|
---|
221 | PostMsg(WinQueryWindow(dirsize->hwndCnr,QW_PARENT),UM_CONTAINER_FILLED,
|
---|
222 | MPVOID,MPVOID);
|
---|
223 | free(dirsize);
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | MRESULT EXPENTRY ObjCnrDlgProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
|
---|
228 | {
|
---|
229 | TEMP *data;
|
---|
230 |
|
---|
231 | switch(msg) {
|
---|
232 | case WM_INITDLG:
|
---|
233 | if(objcnrwnd) {
|
---|
234 | Runtime_Error(pszSrcFile, __LINE__, "objcnrwnd set");
|
---|
235 | WinSetWindowPos(objcnrwnd,HWND_TOP,0,0,0,0,
|
---|
236 | SWP_RESTORE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER);
|
---|
237 | WinDismissDlg(hwnd,0);
|
---|
238 | break;
|
---|
239 | }
|
---|
240 | if(!mp2) {
|
---|
241 | Runtime_Error(pszSrcFile, __LINE__, "mp2 NULL");
|
---|
242 | WinDismissDlg(hwnd,0);
|
---|
243 | break;
|
---|
244 | }
|
---|
245 | objcnrwnd = hwnd;
|
---|
246 | data = xmallocz(sizeof(TEMP),pszSrcFile,__LINE__);
|
---|
247 | if(!data) {
|
---|
248 | WinDismissDlg(hwnd,0);
|
---|
249 | break;
|
---|
250 | }
|
---|
251 | data->dirname = (CHAR *)mp2;
|
---|
252 | WinSetWindowPtr(hwnd,0,(PVOID)data);
|
---|
253 | if(*data->dirname)
|
---|
254 | WinSetDlgItemText(hwnd,OBJCNR_DIR,data->dirname);
|
---|
255 | {
|
---|
256 | DIRSIZE *dirsize;
|
---|
257 |
|
---|
258 | dirsize = xmalloc(sizeof(DIRSIZE),pszSrcFile,__LINE__);
|
---|
259 | if(!dirsize) {
|
---|
260 | WinDismissDlg(hwnd,0);
|
---|
261 | break;
|
---|
262 | }
|
---|
263 | dirsize->stopflag = (CHAR *)&data->stopflag;
|
---|
264 | dirsize->filename = data->dirname;
|
---|
265 | dirsize->hwndCnr = WinWindowFromID(hwnd,OBJCNR_CNR);
|
---|
266 | if (_beginthread(FillCnrs,NULL,65536 * 8,(PVOID)dirsize) == -1) {
|
---|
267 | Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_COULDNTSTARTTHREADTEXT));
|
---|
268 | free(dirsize);
|
---|
269 | WinDismissDlg(hwnd,0);
|
---|
270 | break;
|
---|
271 | }
|
---|
272 | else
|
---|
273 | data->working = TRUE;
|
---|
274 | }
|
---|
275 | PostMsg(hwnd,UM_SETUP,MPVOID,MPVOID);
|
---|
276 | break;
|
---|
277 |
|
---|
278 | case UM_SETUP:
|
---|
279 | // WinEnableWindowUpdate(WinWindowFromID(hwnd,OBJCNR_CNR),FALSE);
|
---|
280 | {
|
---|
281 | CNRINFO cnri;
|
---|
282 |
|
---|
283 | memset(&cnri,0,sizeof(CNRINFO));
|
---|
284 | cnri.cb = sizeof(CNRINFO);
|
---|
285 | WinSendDlgItemMsg(hwnd,OBJCNR_CNR,CM_QUERYCNRINFO,
|
---|
286 | MPFROMP(&cnri),MPFROMLONG(sizeof(CNRINFO)));
|
---|
287 | cnri.cyLineSpacing = 0;
|
---|
288 | cnri.cxTreeIndent = 12L;
|
---|
289 | cnri.pszCnrTitle = GetPString(IDS_WORKINGTEXT);
|
---|
290 | cnri.flWindowAttr = CV_TREE | CV_FLOW |
|
---|
291 | CA_CONTAINERTITLE | CA_TITLESEPARATOR |
|
---|
292 | CA_TREELINE;
|
---|
293 | if(WinQueryWindowUShort(hwnd,QWS_ID) == QTREE_FRAME)
|
---|
294 | cnri.flWindowAttr |= CV_MINI;
|
---|
295 | WinSendDlgItemMsg(hwnd,OBJCNR_CNR,CM_SETCNRINFO,MPFROMP(&cnri),
|
---|
296 | MPFROMLONG(CMA_FLWINDOWATTR | CMA_LINESPACING |
|
---|
297 | CMA_CXTREEINDENT));
|
---|
298 | }
|
---|
299 | return 0;
|
---|
300 |
|
---|
301 | case UM_CONTAINER_FILLED:
|
---|
302 | WinSetDlgItemText(hwnd,
|
---|
303 | OBJCNR_NOTE,
|
---|
304 | NullStr);
|
---|
305 | // WinEnableWindowUpdate(WinWindowFromID(hwnd,OBJCNR_CNR),TRUE);
|
---|
306 | WinSendDlgItemMsg(hwnd,OBJCNR_CNR,CM_INVALIDATERECORD,MPVOID,
|
---|
307 | MPFROM2SHORT(0,CMA_ERASE | CMA_INVALIDATE));
|
---|
308 | data = INSTDATA(hwnd);
|
---|
309 | if(data) {
|
---|
310 | data->working = FALSE;
|
---|
311 | if(data->dying)
|
---|
312 | WinDismissDlg(hwnd,0);
|
---|
313 | {
|
---|
314 | PCNRITEM pci;
|
---|
315 | USHORT id;
|
---|
316 |
|
---|
317 | id = WinQueryWindowUShort(hwnd,QWS_ID);
|
---|
318 | pci = (PCNRITEM)WinSendDlgItemMsg(hwnd,OBJCNR_CNR,
|
---|
319 | CM_QUERYRECORD,
|
---|
320 | MPVOID,
|
---|
321 | MPFROM2SHORT(CMA_FIRST,
|
---|
322 | CMA_ITEMORDER));
|
---|
323 | if(pci && (INT)pci != -1) {
|
---|
324 | ExpandAll(WinWindowFromID(hwnd,OBJCNR_CNR),TRUE,pci);
|
---|
325 | if(id == QTREE_FRAME)
|
---|
326 | pci = (PCNRITEM)WinSendDlgItemMsg(hwnd,OBJCNR_CNR,
|
---|
327 | CM_QUERYRECORD,
|
---|
328 | MPFROMP(pci),
|
---|
329 | MPFROM2SHORT(CMA_FIRSTCHILD,
|
---|
330 | CMA_ITEMORDER));
|
---|
331 | }
|
---|
332 | if((!pci || (INT)pci == -1) && id == QTREE_FRAME) {
|
---|
333 | Notify(GetPString(IDS_NODIRSUNDERTEXT));
|
---|
334 | WinDismissDlg(hwnd,0);
|
---|
335 | break;
|
---|
336 | }
|
---|
337 | }
|
---|
338 | }
|
---|
339 | return 0;
|
---|
340 |
|
---|
341 | case WM_CONTROL:
|
---|
342 | switch(SHORT1FROMMP(mp1)) {
|
---|
343 | case OBJCNR_CNR:
|
---|
344 | if(SHORT2FROMMP(mp1) == CN_ENTER) {
|
---|
345 |
|
---|
346 | PCNRITEM pci = (PCNRITEM)((PNOTIFYRECORDENTER)mp2)->pRecord;
|
---|
347 |
|
---|
348 | if(pci && (INT)pci != -1)
|
---|
349 | WinSendDlgItemMsg(hwnd,DID_OK,BM_CLICK,MPVOID,MPVOID);
|
---|
350 | }
|
---|
351 | break;
|
---|
352 | }
|
---|
353 | return 0;
|
---|
354 |
|
---|
355 | case WM_COMMAND:
|
---|
356 | switch(SHORT1FROMMP(mp1)) {
|
---|
357 | case IDM_HELP:
|
---|
358 | if(hwndHelp) {
|
---|
359 |
|
---|
360 | USHORT id;
|
---|
361 |
|
---|
362 | id = WinQueryWindowUShort(hwnd,QWS_ID);
|
---|
363 |
|
---|
364 | if(id == QTREE_FRAME)
|
---|
365 | WinSendMsg(hwndHelp,HM_DISPLAY_HELP,
|
---|
366 | MPFROM2SHORT(HELP_QUICKTREE,0),
|
---|
367 | MPFROMSHORT(HM_RESOURCEID));
|
---|
368 | else
|
---|
369 | WinSendMsg(hwndHelp,HM_DISPLAY_HELP,
|
---|
370 | MPFROM2SHORT(HELP_OBJECTPATH,0),
|
---|
371 | MPFROMSHORT(HM_RESOURCEID));
|
---|
372 | }
|
---|
373 | break;
|
---|
374 |
|
---|
375 | case OBJCNR_DESKTOP:
|
---|
376 | case DID_OK:
|
---|
377 | data = INSTDATA(hwnd);
|
---|
378 | if(data) {
|
---|
379 |
|
---|
380 | PCNRITEM pci;
|
---|
381 |
|
---|
382 | if(data->working) {
|
---|
383 | Runtime_Error(pszSrcFile, __LINE__, "working unexpected");
|
---|
384 | break;
|
---|
385 | }
|
---|
386 | if(SHORT1FROMMP(mp1) == OBJCNR_DESKTOP) {
|
---|
387 | WinDismissDlg(hwnd,2);
|
---|
388 | break;
|
---|
389 | }
|
---|
390 | pci = (PCNRITEM)WinSendDlgItemMsg(hwnd,OBJCNR_CNR,
|
---|
391 | CM_QUERYRECORDEMPHASIS,
|
---|
392 | MPFROMLONG(CMA_FIRST),
|
---|
393 | MPFROMSHORT(CRA_CURSORED));
|
---|
394 | if(pci && (INT)pci != -1)
|
---|
395 | strcpy(data->dirname,pci->szFileName);
|
---|
396 | WinDismissDlg(hwnd,1);
|
---|
397 | }
|
---|
398 | break;
|
---|
399 |
|
---|
400 | case DID_CANCEL:
|
---|
401 | data = INSTDATA(hwnd);
|
---|
402 | if(data) {
|
---|
403 | if(data->working) {
|
---|
404 | data->dying = TRUE;
|
---|
405 | data->stopflag = 0xff;
|
---|
406 | break;
|
---|
407 | }
|
---|
408 | WinDismissDlg(hwnd,0);
|
---|
409 | }
|
---|
410 | break;
|
---|
411 | }
|
---|
412 | return 0;
|
---|
413 |
|
---|
414 | case WM_DESTROY:
|
---|
415 | objcnrwnd = (HWND)0;
|
---|
416 | data = INSTDATA(hwnd);
|
---|
417 | if(data)
|
---|
418 | free(data);
|
---|
419 | break;
|
---|
420 | }
|
---|
421 | return WinDefDlgProc(hwnd,msg,mp1,mp2);
|
---|
422 | }
|
---|
423 |
|
---|