source: trunk/dll/objcnr.c@ 1880

Last change on this file since 1880 was 1880, checked in by Gregg Young, 10 years ago

Remove dead code and comments from remaining c files. #if 0 and #if NEVER were not addressed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: objcnr.c 1880 2015-10-12 18:26:16Z gyoung $
5
6 Object containers
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2005, 2015 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 19 Oct 06 SHL Correct . and .. detect
15 03 Nov 06 SHL Renames
16 22 Mar 07 GKY Use QWL_USER
17 01 Aug 07 SHL Rework to sync with CNRITEM mods
18 03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
19 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
20 13 Aug 07 SHL Avoid realloc - not needed; sanitize code
21 13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
22 14 Aug 07 SHL Revert ProcessDir DosSleep to 0
23 29 Feb 08 GKY Use xfree where appropriate
24 10 Dec 08 SHL Integrate exception handler support
25 08 Mar 09 GKY Additional strings move to PCSZs
26 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
27 20 Sep 15 GKY Update for modified ExpandAll
28
29***********************************************************************/
30
31#include <stdlib.h>
32#include <string.h>
33#include <ctype.h>
34
35#define INCL_DOS
36#define INCL_WIN
37#define INCL_DOSERRORS
38#define INCL_LONGLONG
39
40#include "fm3dll.h"
41#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
42#include "draglist.h" // Data declaration(s)
43#include "info.h" // Data declaration(s)
44#include "init.h" // Data declaration(s)
45#include "notebook.h" // Data declaration(s)
46#include "newview.h" // Data declarations
47#include "fm3dlg.h"
48#include "fm3str.h"
49#include "errutil.h" // Dos_Error...
50#include "strutil.h" // GetPString
51#include "objcnr.h"
52#include "notify.h" // Notify
53#include "wrappers.h" // xDosFindNext
54#include "select.h" // ExpandAll
55#include "valid.h" // IsRoot
56#include "misc.h" // PostMsg
57#include "fortify.h"
58#include "excputil.h" // xbeginthread
59#include "pathutil.h" // AddBackslashToPath
60
61typedef struct
62{
63 CHAR *filename;
64 HWND hwndCnr;
65 CHAR *stopflag;
66}
67DIRSIZE;
68
69typedef struct
70{
71 CHAR *dirname;
72 CHAR stopflag;
73 BOOL dying;
74 BOOL working;
75}
76TEMP;
77
78#pragma data_seg(DATA1)
79
80static PSZ pszSrcFile = __FILE__;
81
82static HWND objcnrwnd;
83
84static VOID ProcessDir(HWND hwndCnr,
85 CHAR *filename,
86 PCNRITEM pciParent,
87 CHAR *stopflag)
88{
89 CHAR maskstr[CCHMAXPATH], *endpath, *p;
90 ULONG ulFindCnt, ulFindMax;
91 ULONG ulBufBytes;
92 HDIR hdir;
93 PFILEFINDBUF3L pffbArray;
94 APIRET rc;
95 RECORDINSERT ri;
96 PCNRITEM pciP;
97 HPOINTER hptr;
98
99 ulBufBytes = sizeof(FILEFINDBUF3L) * FilesToGet;
100 pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
101 if (!pffbArray)
102 return; // Error already reported
103 strcpy(maskstr, filename);
104 AddBackslashToPath(maskstr);
105 endpath = &maskstr[strlen(maskstr)];
106 strcat(maskstr, "*");
107 hdir = HDIR_CREATE;
108 ulFindCnt = 1;
109 rc = xDosFindFirst(filename, &hdir,
110 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
111 FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
112 pffbArray, ulBufBytes, &ulFindCnt, FIL_STANDARDL);
113 if (!rc)
114 DosFindClose(hdir);
115 // work around furshluginer FAT root bug
116 else if (IsRoot(filename))
117 rc = 0;
118
119 if ((!rc && (pffbArray->attrFile & FILE_DIRECTORY))) {
120 pciP = WinSendMsg(hwndCnr,
121 CM_ALLOCRECORD,
122 MPFROMLONG(EXTRA_RECORD_BYTES),
123 MPFROMLONG(1));
124 if (!pciP) {
125 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_CM_ALLOCRECORD);
126 free(pffbArray);
127 return;
128 }
129 pciP->pszFileName = xstrdup(filename, pszSrcFile, __LINE__);
130 pciP->pszDispAttr = NullStr;
131 pciP->pszSubject = NullStr;
132 pciP->pszLongName = NullStr;
133 if (strlen(filename) < 4)
134 pciP->pszDisplayName = pciP->pszFileName;
135 else {
136 p = strrchr(pciP->pszFileName, '\\');
137 if (!p)
138 pciP->pszDisplayName = pciP->pszFileName;
139 else if (*(p + 1))
140 p++;
141 pciP->pszDisplayName = p;
142 }
143 pciP->rc.pszIcon = pciP->pszDisplayName;
144 if (fForceUpper)
145 strupr(pciP->pszFileName);
146 else if (fForceLower)
147 strlwr(pciP->pszFileName);
148 pciP->rc.flRecordAttr |= CRA_RECORDREADONLY;
149 }
150 else {
151 free(pffbArray);
152 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
153 GetPString(IDS_CANTFINDDIRTEXT), filename);
154 return;
155 }
156
157 hptr = WinLoadFileIcon(pciP->pszFileName, FALSE);
158 if (hptr)
159 pciP->rc.hptrIcon = hptr;
160
161 if (!pciP->rc.hptrIcon || pciP->rc.hptrIcon == hptrFile) // OS/2 bug bug bug bug
162 pciP->rc.hptrIcon = hptrDir;
163
164 memset(&ri, 0, sizeof(RECORDINSERT));
165 ri.cb = sizeof(RECORDINSERT);
166 ri.pRecordOrder = (PRECORDCORE) CMA_END;
167 ri.pRecordParent = (PRECORDCORE) pciParent;
168 ri.zOrder = (USHORT) CMA_TOP;
169 ri.cRecordsInsert = 1;
170 ri.fInvalidateRecord = TRUE;
171 if (!WinSendMsg(hwndCnr, CM_INSERTRECORD, MPFROMP(pciP), MPFROMP(&ri))) {
172 free(pffbArray);
173 return;
174 }
175 hdir = HDIR_CREATE;
176 if (!isalpha(*maskstr) || maskstr[1] != ':' || maskstr[2] != '\\' ||
177 ((driveflags[toupper(*maskstr) - 'A'] & DRIVE_REMOTE) && fRemoteBug))
178 ulFindMax = 1;
179 else
180 ulFindMax = FilesToGet;
181 ulFindCnt = ulFindMax;
182 rc = xDosFindFirst(maskstr, &hdir,
183 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
184 FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
185 pffbArray, ulBufBytes, &ulFindCnt, FIL_STANDARDL);
186 if (!rc) {
187 PFILEFINDBUF3L pffbFile;
188 ULONG x;
189
190 while (!rc) {
191 pffbFile = pffbArray;
192 for (x = 0; x < ulFindCnt; x++) {
193 if (*stopflag)
194 break;
195 if ((pffbFile->attrFile & FILE_DIRECTORY) &&
196 // Skip . and ..
197 (pffbFile->achName[0] != '.' ||
198 (pffbFile->achName[1] &&
199 (pffbFile->achName[1] != '.' || pffbFile->achName[2])))) {
200 strcpy(endpath, pffbFile->achName);
201 ProcessDir(hwndCnr, maskstr, pciP, stopflag);
202 }
203 if (!pffbFile->oNextEntryOffset)
204 break;
205 pffbFile = (PFILEFINDBUF3L)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
206 } // for
207 DosSleep(0); // Let's others at same priority get some work done
208 if (*stopflag)
209 break;
210 ulFindCnt = ulFindMax;
211 rc = xDosFindNext(hdir, pffbArray, ulBufBytes, &ulFindCnt, FIL_STANDARDL);
212 } // while
213 DosFindClose(hdir);
214 }
215
216 if (rc && rc != ERROR_NO_MORE_FILES) {
217 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
218 GetPString(IDS_CANTFINDDIRTEXT), filename);
219 }
220
221 free(pffbArray);
222 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pciP),
223 MPFROM2SHORT(1, 0));
224}
225
226static VOID FillCnrsThread(VOID * args)
227{
228 HAB hab;
229 HMQ hmq;
230 DIRSIZE *dirsize = (DIRSIZE *)args;
231
232# ifdef FORTIFY
233 Fortify_EnterScope();
234# endif
235 if (!dirsize) {
236 Runtime_Error(pszSrcFile, __LINE__, NULL);
237 return;
238 }
239
240 DosError(FERR_DISABLEHARDERR);
241
242 hab = WinInitialize(0);
243 if (hab) {
244 hmq = WinCreateMsgQueue(hab, 0);
245 if (hmq) {
246 WinCancelShutdown(hmq, TRUE);
247 ProcessDir(dirsize->hwndCnr, dirsize->filename, (PCNRITEM) NULL,
248 dirsize->stopflag);
249 DosPostEventSem(CompactSem);
250 WinDestroyMsgQueue(hmq);
251 }
252 WinTerminate(hab);
253 }
254 PostMsg(WinQueryWindow(dirsize->hwndCnr, QW_PARENT), UM_CONTAINER_FILLED,
255 MPVOID, MPVOID);
256 free(dirsize);
257# ifdef FORTIFY
258 Fortify_LeaveScope();
259# endif
260}
261
262MRESULT EXPENTRY ObjCnrDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
263{
264 TEMP *data;
265
266 switch (msg) {
267 case WM_INITDLG:
268 if (objcnrwnd) {
269 Runtime_Error(pszSrcFile, __LINE__, "objcnrwnd set");
270 WinSetWindowPos(objcnrwnd, HWND_TOP, 0, 0, 0, 0,
271 SWP_RESTORE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER);
272 WinDismissDlg(hwnd, 0);
273 break;
274 }
275 if (!mp2) {
276 Runtime_Error(pszSrcFile, __LINE__, "mp2 NULL");
277 WinDismissDlg(hwnd, 0);
278 break;
279 }
280 objcnrwnd = hwnd;
281 data = xmallocz(sizeof(TEMP), pszSrcFile, __LINE__);
282 if (!data) {
283 WinDismissDlg(hwnd, 0);
284 break;
285 }
286 data->dirname = (CHAR *)mp2;
287 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) data);
288 if (*data->dirname)
289 WinSetDlgItemText(hwnd, OBJCNR_DIR, data->dirname);
290 {
291 DIRSIZE *dirsize;
292# ifdef FORTIFY
293 Fortify_EnterScope();
294# endif
295 dirsize = xmalloc(sizeof(DIRSIZE), pszSrcFile, __LINE__);
296 if (!dirsize) {
297 WinDismissDlg(hwnd, 0);
298 break;
299 }
300 dirsize->stopflag = (CHAR *)&data->stopflag;
301 dirsize->filename = data->dirname;
302 dirsize->hwndCnr = WinWindowFromID(hwnd, OBJCNR_CNR);
303 if (xbeginthread(FillCnrsThread,
304 65536 * 8,
305 dirsize,
306 pszSrcFile,
307 __LINE__) == -1)
308 {
309 free(dirsize);
310# ifdef FORTIFY
311 Fortify_LeaveScope();
312# endif
313 WinDismissDlg(hwnd, 0);
314 break;
315 }
316 else
317 data->working = TRUE;
318 }
319 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
320 break;
321
322 case UM_SETUP:
323 {
324 CNRINFO cnri;
325
326 memset(&cnri, 0, sizeof(CNRINFO));
327 cnri.cb = sizeof(CNRINFO);
328 WinSendDlgItemMsg(hwnd, OBJCNR_CNR, CM_QUERYCNRINFO,
329 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
330 cnri.cyLineSpacing = 0;
331 cnri.cxTreeIndent = 12L;
332 cnri.pszCnrTitle = (PSZ)GetPString(IDS_WORKINGTEXT);
333 cnri.flWindowAttr = CV_TREE | CV_FLOW |
334 CA_CONTAINERTITLE | CA_TITLESEPARATOR | CA_TREELINE;
335 if (WinQueryWindowUShort(hwnd, QWS_ID) == QTREE_FRAME)
336 cnri.flWindowAttr |= CV_MINI;
337 WinSendDlgItemMsg(hwnd, OBJCNR_CNR, CM_SETCNRINFO, MPFROMP(&cnri),
338 MPFROMLONG(CMA_FLWINDOWATTR | CMA_LINESPACING |
339 CMA_CXTREEINDENT));
340 }
341 return 0;
342
343 case UM_CONTAINER_FILLED:
344 WinSetDlgItemText(hwnd, OBJCNR_NOTE, NullStr);
345 WinSendDlgItemMsg(hwnd, OBJCNR_CNR, CM_INVALIDATERECORD, MPVOID,
346 MPFROM2SHORT(0, CMA_ERASE | CMA_INVALIDATE));
347 data = INSTDATA(hwnd);
348 if (data) {
349 data->working = FALSE;
350 if (data->dying)
351 WinDismissDlg(hwnd, 0);
352 {
353 PCNRITEM pci;
354 USHORT id;
355
356 id = WinQueryWindowUShort(hwnd, QWS_ID);
357 pci = (PCNRITEM) WinSendDlgItemMsg(hwnd, OBJCNR_CNR,
358 CM_QUERYRECORD,
359 MPVOID,
360 MPFROM2SHORT(CMA_FIRST,
361 CMA_ITEMORDER));
362 if (pci && (INT) pci != -1) {
363 ExpandAll(WinWindowFromID(hwnd, OBJCNR_CNR), 0, pci);
364 if (id == QTREE_FRAME)
365 pci = (PCNRITEM) WinSendDlgItemMsg(hwnd, OBJCNR_CNR,
366 CM_QUERYRECORD,
367 MPFROMP(pci),
368 MPFROM2SHORT(CMA_FIRSTCHILD,
369 CMA_ITEMORDER));
370 }
371 if ((!pci || (INT) pci == -1) && id == QTREE_FRAME) {
372 Notify(GetPString(IDS_NODIRSUNDERTEXT));
373 WinDismissDlg(hwnd, 0);
374 break;
375 }
376 }
377 }
378 return 0;
379
380 case WM_CONTROL:
381 switch (SHORT1FROMMP(mp1)) {
382 case OBJCNR_CNR:
383 if (SHORT2FROMMP(mp1) == CN_ENTER) {
384
385 PCNRITEM pci = (PCNRITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
386
387 if (pci && (INT) pci != -1)
388 WinSendDlgItemMsg(hwnd, DID_OK, BM_CLICK, MPVOID, MPVOID);
389 }
390 break;
391 }
392 return 0;
393
394 case WM_COMMAND:
395 switch (SHORT1FROMMP(mp1)) {
396 case IDM_HELP:
397 if (hwndHelp) {
398
399 USHORT id;
400
401 id = WinQueryWindowUShort(hwnd, QWS_ID);
402
403 if (id == QTREE_FRAME)
404 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
405 MPFROM2SHORT(HELP_QUICKTREE, 0),
406 MPFROMSHORT(HM_RESOURCEID));
407 else
408 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
409 MPFROM2SHORT(HELP_OBJECTPATH, 0),
410 MPFROMSHORT(HM_RESOURCEID));
411 }
412 break;
413
414 case OBJCNR_DESKTOP:
415 case DID_OK:
416 data = INSTDATA(hwnd);
417 if (data) {
418
419 PCNRITEM pci;
420
421 if (data->working) {
422 Runtime_Error(pszSrcFile, __LINE__, "working unexpected");
423 break;
424 }
425 if (SHORT1FROMMP(mp1) == OBJCNR_DESKTOP) {
426 WinDismissDlg(hwnd, 2);
427 break;
428 }
429 pci = (PCNRITEM) WinSendDlgItemMsg(hwnd, OBJCNR_CNR,
430 CM_QUERYRECORDEMPHASIS,
431 MPFROMLONG(CMA_FIRST),
432 MPFROMSHORT(CRA_CURSORED));
433 if (pci && (INT) pci != -1)
434 strcpy(data->dirname, pci->pszFileName);
435 WinDismissDlg(hwnd, 1);
436 }
437 break;
438
439 case DID_CANCEL:
440 data = INSTDATA(hwnd);
441 if (data) {
442 if (data->working) {
443 data->dying = (CHAR)TRUE;
444 data->stopflag = (CHAR)0xff;
445 break;
446 }
447 WinDismissDlg(hwnd, 0);
448 }
449 break;
450 }
451 return 0;
452
453 case WM_DESTROY:
454 objcnrwnd = (HWND) 0;
455 data = INSTDATA(hwnd);
456 xfree(data, pszSrcFile, __LINE__);
457 break;
458 }
459 return WinDefDlgProc(hwnd, msg, mp1, mp2);
460}
461
462#pragma alloc_text(OBJCNR,ProcessDir,FillCnrsThread,ObjCnrDlgProc)
Note: See TracBrowser for help on using the repository browser.