source: trunk/dll/objcnr.c@ 159

Last change on this file since 159 was 159, checked in by root, 20 years ago

Rework for CNRITEM.szSubject

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