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