source: trunk/dll/common.c@ 1833

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

A correct (I hope as always) fix for the direct edits. I don't need to reallocate pci-pszFileName or repoint pci->pszDisplayName because updatecnritems does it for me. I also got the tree container to update without using removecnritems. Ticket [557]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: common.c 1833 2015-07-13 23:07:26Z gyoung $
5
6 Common window functions
7
8 Copyright (c) 1993, 1998 M. Kimes
9 Copyright (c) 2001, 2010 Steven H. Levine
10
11 13 Aug 05 SHL Renames
12 22 Jul 06 SHL Check more run time errors
13 15 Aug 06 SHL Use Dos_Error
14 03 Nov 06 SHL Rework thread usage count logic
15 07 Jan 07 GKY Move error strings etc. to string file
16 07 Jan 07 GKY Updated Helv font to vector font Helvetica
17 22 Mar 07 GKY Use QWL_USER
18 30 Mar 07 GKY Remove GetPString for window class names
19 02 Aug 07 SHL Sync with CNRITEM mods
20 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
21 26 Aug 07 SHL Change to DosSleep(0)
22 29 Feb 08 GKY Use xfree where appropriate
23 06 Jul 08 GKY Update delete/undelete to include move to and open XWP trashcan
24 01 Jan 09 GKY Add option to rescan tree container on eject of removable media
25 11 Jan 09 GKY Replace font names in the string file with global set at compile in init.c
26 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
27 08 Mar 09 GKY Additional strings move to PCSZs in init.c
28 22 Jul 09 GKY Drivebar enhancements add refresh removable, rescan all drives, drive button
29 22 Jul 09 GKY Drivebar enhancements add refresh removable, rescan all drives, drive button
30 loads drive root directory in directory container or expands drive tree
31 and rescans drive in tree container depending on container focus, greyed out
32 inappropriate menu context choices
33 14 Sep 09 SHL Blink thread LEDs while threads working
34 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
35 13 Jul 15 GKY Fix CN_REALLOCPSZ file name editing code to: 1) Eliminate the possibility of
36 updating the container before CN_ENDEDIT is called. 2) Don't call RemoveCnrItems
37 for tree container and collector.
38
39***********************************************************************/
40
41#include <stdlib.h>
42#include <string.h>
43#include <ctype.h>
44
45#define INCL_DOS
46#define INCL_DOSERRORS
47#define INCL_WIN
48#define INCL_GPI
49#define INCL_LONGLONG // dircnrs.h
50
51#include "fm3dll.h"
52#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
53#include "mainwnd2.h" // Data declaration(s)
54#include "killproc.h" // Data declaration(s)
55#include "collect.h" // Data declaration(s)
56#include "grep.h" // Data declaration(s)
57#include "dircnrs.h" // Data declaration(s)
58#include "notebook.h" // Data declaration(s)
59#include "inis.h" // Data declaration(s)
60#include "init.h" // Data declaration(s)
61#include "treecnr.h" // Data declaration(s)
62#include "fm3dlg.h"
63#include "fm3str.h"
64#include "mle.h"
65#include "filldir.h" // RemoveCnrItems
66#include "errutil.h" // Dos_Error...
67#include "strutil.h" // GetPString
68#include "autoview.h" // AutoViewProc
69#include "mainwnd.h" // BuildDriveBarButtons, GetNextWindowPos, TopWindow
70#include "common.h"
71#include "dirsize.h" // DirSizeProc
72#include "info.h" // DrvInfoProc, SetDrvProc
73#include "seeall.h" // StartSeeAll
74#include "misc.h" // Broadcast
75#include "valid.h" // CheckDrive
76#include "mkdir.h" // PMMkDir
77#include "presparm.h" // SetPresParams
78#include "undel.h" // UndeleteDlgProc
79#include "systemf.h" // runemf2
80#include "wrappers.h" // xfree
81#include "fortify.h"
82
83// Data definitions
84#pragma data_seg(DATA1)
85static PSZ pszSrcFile = __FILE__;
86static HWND hwndLED;
87static HWND hwndLEDHdr;
88
89#pragma data_seg(GLOBAL1)
90HWND hwndBack;
91
92MRESULT EXPENTRY CommonFrameWndProc(USHORT id,
93 HWND hwnd,
94 ULONG msg, MPARAM mp1, MPARAM mp2)
95{
96 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
97
98 switch (msg) {
99 case UM_TIMER:
100 case UM_ACTION:
101 case UM_SHOWME:
102 case UM_OPENWINDOWFORME:
103 case UM_MINIMIZE:
104 case UM_MAXIMIZE:
105 case UM_CONTAINERDIR:
106 case UM_FILTER:
107 case UM_INITMENU:
108 case UM_COMMAND:
109 case UM_UPDATERECORD:
110 case UM_UPDATERECORDLIST:
111 case WM_COMMAND:
112 case MM_PORTHOLEINIT:
113 case WM_INITMENU:
114 case UM_CONTAINER_FILLED:
115 case UM_FILESMENU:
116 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
117
118 case UM_CONTEXTMENU:
119 PostMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
120 return 0;
121
122 case UM_CONTAINERHWND:
123 return MRFROMLONG(WinWindowFromID(hwnd, id));
124
125 case DM_DROP:
126 case DM_DRAGOVER:
127 case DM_DRAGLEAVE:
128 case DM_DROPHELP:
129 {
130 CNRDRAGINFO cnd;
131 USHORT dcmd;
132
133 switch (msg) {
134 case DM_DROP:
135 dcmd = CN_DROP;
136 break;
137 case DM_DRAGOVER:
138 dcmd = CN_DRAGOVER;
139 break;
140 case DM_DRAGLEAVE:
141 dcmd = CN_DRAGLEAVE;
142 break;
143 case DM_DROPHELP:
144 dcmd = CN_DROPHELP;
145 break;
146 }
147 cnd.pDragInfo = (PDRAGINFO) mp1;
148 cnd.pRecord = NULL;
149 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT),
150 WM_CONTROL, MPFROM2SHORT(id, dcmd), MPFROMP(&cnd));
151 }
152
153 case UM_RESCAN:
154 if (fAutoTile &&
155 !fAmClosing && !fNoTileUpdate && !ParentIsDesktop(hwnd, (HWND) 0))
156 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_RESCAN, MPVOID, MPVOID);
157 return 0;
158
159 case WM_MINMAXFRAME:
160 {
161 PSWP pswp = (PSWP) mp1;
162 MRESULT rc;
163
164 rc = oldproc(hwnd, msg, mp1, mp2);
165 if (pswp->fl & (SWP_MINIMIZE | SWP_HIDE | SWP_RESTORE))
166 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
167 return rc;
168 }
169
170 case WM_DESTROY:
171 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
172 break;
173 }
174 return oldproc(hwnd, msg, mp1, mp2);
175}
176
177MRESULT EXPENTRY CommonTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
178{
179 switch (msg) {
180 case WM_CREATE:
181 {
182 MRESULT rc;
183
184 rc = PFNWPStatic(hwnd, msg, mp1, mp2);
185 // 2014-06-11 SHL
186 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
187 case DIR_SORT:
188 case DIR_VIEW:
189 case DIR_FILTER:
190 //fixme to allow user to change presparams 1-10-09 GKY
191 SetPresParams(hwnd, &RGBGREY, &RGBBLACK, &RGBBLACK, FNT_8HELVETICA);
192 return rc;
193 }
194 }
195 } // switch msg
196 return PFNWPStatic(hwnd, msg, mp1, mp2);
197}
198
199void CommonTextPaint(HWND hwnd, HPS hps)
200{
201 int x;
202 USHORT ids[] = { DIR_FOLDERICON, DIR_TOTALS, DIR_SELECTED, DIR_VIEW,
203 DIR_FILTER, DIR_SORT, DIR_MAX, 0
204 };
205 BOOL bools[] = { TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE };
206
207 for (x = 0; ids[x]; x++) {
208 if (WinWindowFromID(hwnd, ids[x]) != (HWND) 0)
209 PaintRecessedWindow(WinWindowFromID(hwnd, ids[x]), hps,
210 bools[x], FALSE);
211 }
212}
213
214void CommonCreateTextChildren(HWND hwnd, PCSZ class, USHORT * ids)
215{
216 int x;
217 CHAR s[33];
218 ULONG attrs;
219 HWND hwndTmp;
220
221 if (!hwnd || !class || !ids) {
222 Runtime_Error(pszSrcFile, __LINE__, NULL);
223 return;
224 }
225
226 for (x = 0; ids[x]; x++) {
227 *s = 0;
228 switch (ids[x]) {
229 case DIR_SORT:
230 case DIR_FILTER:
231 case DIR_VIEW:
232 attrs = SS_TEXT | DT_LEFT | DT_VCENTER;
233 break;
234 case DIR_FOLDERICON:
235 case DIR_MAX:
236 attrs = SS_BITMAP;
237 sprintf(s, "#%d", ids[x]);
238 break;
239 default:
240 attrs = SS_TEXT | DT_CENTER | DT_VCENTER;
241 break;
242 }
243 hwndTmp = WinCreateWindow(hwnd, (CHAR *) class, s, attrs, 0, 0, 0, 0, hwnd,
244 HWND_TOP, ids[x], NULL, NULL);
245 if (!hwndTmp)
246 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
247 PCSZ_WINCREATEWINDOW);
248 } // for
249}
250
251void CommonDriveCmd(HWND hwnd, char *drive, USHORT cmd)
252{
253 char dv[CCHMAXPATH];
254
255 if (!drive || !*drive)
256 return;
257 strcpy(dv, drive);
258 MakeValidDir(dv);
259
260 switch (cmd) {
261 case IDM_MKDIR:
262 PMMkDir(hwnd, dv, FALSE);
263 break;
264 case IDM_INFO:
265 WinDlgBox(HWND_DESKTOP,
266 HWND_DESKTOP,
267 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) dv);
268 break;
269 case IDM_DRVFLAGS:
270 strcpy(dv, drive); // Must use original drive letter
271 if (WinDlgBox(HWND_DESKTOP,
272 hwnd,
273 SetDrvProc,
274 FM3ModHandle, DVS_FRAME, MPFROMP(dv)) && hwndTree)
275 if (!PostMsg(hwndTree, UM_SHOWME, MPFROMP(dv), MPVOID))
276 PostMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_UPDATE, 0), MPVOID);
277 break;
278 case IDM_SIZES:
279 WinDlgBox(HWND_DESKTOP,
280 HWND_DESKTOP, DirSizeProc, FM3ModHandle, DSZ_FRAME, dv);
281 break;
282 case IDM_SHOWALLFILES:
283 StartSeeAll(HWND_DESKTOP, FALSE, dv);
284 break;
285 case IDM_UNDELETE:
286 {
287 HOBJECT hObject;
288 HWND hwndDesktop;
289
290 hObject = WinQueryObject("<XWP_TRASHCAN>");
291 if (hObject != NULLHANDLE && fTrashCan) {
292 hwndDesktop = WinQueryDesktopWindow((HAB) 0, NULLHANDLE);
293 WinSetFocus(HWND_DESKTOP, hwndDesktop);
294 WinOpenObject(hObject, 0, TRUE);
295 }
296 else
297 WinDlgBox(HWND_DESKTOP,
298 hwnd,
299 UndeleteDlgProc,
300 FM3ModHandle, UNDEL_FRAME, MPFROMP(dv));
301 }
302 break;
303 case IDM_CHKDSK:
304 runemf2(SEPARATE | WINDOWED,
305 hwnd, pszSrcFile, __LINE__, NULL, NULL,
306 "PMCHKDSK.EXE %c:", toupper(*dv));
307 break;
308 case IDM_OPTIMIZE:
309 {
310 CHAR FileSystem[CCHMAXPATH];
311 ULONG type;
312
313 CheckDrive(*dv, FileSystem, &type);
314 if (*FileSystem) {
315 strcat(FileSystem, "OPT.CMD");
316 runemf2(SEPARATE | WINDOWED,
317 hwnd, pszSrcFile, __LINE__,
318 NULL,
319 NULL,
320 "%s /C %s %c:", GetCmdSpec(FALSE), FileSystem, toupper(*dv));
321 }
322 }
323 break;
324 case IDM_FORMAT:
325 runemf2(SEPARATE | WINDOWED,
326 hwnd, pszSrcFile, __LINE__, NULL, NULL,
327 "PMFORMAT.EXE %c:", toupper(*dv));
328 break;
329
330#if 0 // fixme to be gone?
331
332 case IDM_CLOSETRAY:
333 if (driveflags[*dv - 'A'] & DRIVE_CDROM) {
334
335 BYTE parm[4] = { "CD01" };
336 ULONGLONG dlen;
337 ULONG plen;
338 HFILE hfile;
339 APIRET rc;
340
341 dv[2] = 0;
342 rc = DosOpen(dv,
343 &hfile,
344 &dlen,
345 0,
346 0,
347 OPEN_ACTION_OPEN_IF_EXISTS |
348 OPEN_ACTION_CREATE_IF_NEW,
349 OPEN_FLAGS_DASD |
350 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYNONE, NULL);
351 if (rc)
352 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__, "DosOpen");
353 else {
354 dlen = 0;
355 plen = sizeof(parm);
356 rc = DosDevIOCtl(hfile,
357 0x80,
358 0x45, &parm, sizeof(parm), &plen, NULL, 0, &dlen);
359 DosClose(hfile);
360 if (rc)
361 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__, "DosDevIOCtl");
362 }
363 }
364 break;
365#endif // fixme to be gone?
366
367 case IDM_LOCK:
368 case IDM_UNLOCK:
369 case IDM_EJECT:
370 {
371 UCHAR parm[2];
372 ULONG plen = sizeof(parm), dlen = 0L;
373 APIRET rc;
374
375 switch (SHORT1FROMMP(cmd)) {
376 case IDM_LOCK:
377 parm[0] = 1;
378 break;
379 case IDM_UNLOCK:
380 parm[0] = 0;
381 break;
382 case IDM_EJECT:
383 parm[0] = 2;
384 break;
385 }
386 parm[1] = *dv - 'A';
387 DosError(FERR_DISABLEHARDERR);
388 rc = DosDevIOCtl(-1L, 8L, 0x40L, &parm, sizeof(parm), &plen, NULL, 0L, &dlen);
389 if (cmd == IDM_EJECT &&
390 (fEjectFlpyScan ? TRUE : parm[1] > 1) &&
391 (fEjectCDScan ? TRUE : !(driveflags[parm[1]] & DRIVE_CDROM)) &&
392 (fEjectRemovableScan ? TRUE : (parm[1] < 2 || driveflags[parm[1]] & DRIVE_CDROM))) {
393 BOOL toggleTree = FALSE;
394
395 if (!hwndTree) {
396 WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
397 toggleTree = TRUE;
398 }
399 WinSendMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_RESCAN, 0), MPVOID);
400 if (toggleTree)
401 WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
402 }
403 }
404 break;
405
406 case IDM_RESCAN:
407 {
408 BOOL toggleTree = FALSE;
409
410 if (!hwndTree) {
411 WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
412 toggleTree = TRUE;
413 }
414 WinSendMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_RESCAN, 0), MPVOID);
415 if (toggleTree)
416 WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
417 }
418 break;
419
420 case IDM_REFRESHREMOVABLES:
421 {
422 BOOL toggleTree = FALSE;
423
424 if (!hwndTree) {
425 WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
426 toggleTree = TRUE;
427 }
428 WinSendMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_REFRESHREMOVABLES, 0), MPVOID);
429 if (toggleTree)
430 WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
431 }
432 break;
433 }
434}
435
436void CommonCreateMainChildren(HWND hwnd, SWP * swp)
437{
438 HWND hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
439 HWND hwndTmp;
440 PFNWP oldproc;
441
442 // Create a children of frame window
443 // Left status window
444 hwndStatus = WinCreateWindow(hwndFrame,
445 (CHAR *) WC_STATUS,
446 "Status",
447 WS_VISIBLE | SS_TEXT | DT_LEFT |
448 DT_VCENTER,
449 swp->x + 4 +
450 WinQuerySysValue(HWND_DESKTOP,
451 SV_CXSIZEBORDER),
452 swp->y + 4 +
453 WinQuerySysValue(HWND_DESKTOP,
454 SV_CYSIZEBORDER),
455 ((swp->cx / 2) - 8) -
456 (WinQuerySysValue(HWND_DESKTOP,
457 SV_CXSIZEBORDER) * 2),
458 20,
459 hwndFrame, HWND_TOP, MAIN_STATUS, NULL, NULL);
460 if (!hwndStatus)
461 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
462 PCSZ_WINCREATEWINDOW);
463
464 // Right status window
465 hwndStatus2 = WinCreateWindow(hwndFrame,
466 (CHAR *) WC_STATUS,
467 "Status2",
468 WS_VISIBLE | SS_TEXT | DT_LEFT |
469 DT_VCENTER,
470 ((swp->cx / 2) + 4) +
471 WinQuerySysValue(HWND_DESKTOP,
472 SV_CXSIZEBORDER),
473 ((swp->cy / 2) + 4) +
474 WinQuerySysValue(HWND_DESKTOP,
475 SV_CYSIZEBORDER),
476 ((swp->cx / 2) - 8) -
477 (WinQuerySysValue(HWND_DESKTOP,
478 SV_CXSIZEBORDER) * 2),
479 20,
480 hwndFrame,
481 HWND_TOP, MAIN_STATUS2, NULL, NULL);
482 if (!hwndStatus2)
483 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
484 PCSZ_WINCREATEWINDOW);
485
486 hwndAttr = WinCreateWindow(hwndFrame,
487 (CHAR *) WC_STATUS,
488 "Attr",
489 WS_VISIBLE | SS_TEXT | DT_CENTER |
490 DT_VCENTER,
491 swp->x + 4 +
492 WinQuerySysValue(HWND_DESKTOP,
493 SV_CXSIZEBORDER),
494 swp->y + 4 + 24 +
495 WinQuerySysValue(HWND_DESKTOP,
496 SV_CYSIZEBORDER),
497 ((swp->cx / 4) - 8) -
498 (WinQuerySysValue(HWND_DESKTOP,
499 SV_CXSIZEBORDER) * 2),
500 20, hwndFrame, HWND_TOP, IDM_ATTRS, NULL, NULL);
501 if (!hwndAttr)
502 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
503 PCSZ_WINCREATEWINDOW);
504
505 hwndDate = WinCreateWindow(hwndFrame,
506 (CHAR *) WC_STATUS,
507 "Date",
508 WS_VISIBLE | SS_TEXT | DT_CENTER |
509 DT_VCENTER,
510 ((swp->x / 4) * 2) + 4 +
511 WinQuerySysValue(HWND_DESKTOP,
512 SV_CXSIZEBORDER),
513 swp->y + 4 + 24 +
514 WinQuerySysValue(HWND_DESKTOP,
515 SV_CYSIZEBORDER),
516 ((swp->cx / 4) - 8) -
517 (WinQuerySysValue(HWND_DESKTOP,
518 SV_CXSIZEBORDER) * 2),
519 20, hwndFrame, HWND_TOP, IDM_INFO, NULL, NULL);
520 if (!hwndDate)
521 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
522 PCSZ_WINCREATEWINDOW);
523
524 hwndName = WinCreateWindow(hwndFrame,
525 (CHAR *) WC_STATUS,
526 "Name",
527 WS_VISIBLE | SS_TEXT | DT_LEFT |
528 DT_VCENTER,
529 ((swp->x / 4) * 3) + 4 +
530 WinQuerySysValue(HWND_DESKTOP,
531 SV_CXSIZEBORDER),
532 swp->y + 4 +
533 WinQuerySysValue(HWND_DESKTOP,
534 SV_CYSIZEBORDER),
535 ((swp->cx / 4) - 8) -
536 (WinQuerySysValue(HWND_DESKTOP,
537 SV_CXSIZEBORDER) * 2),
538 20, hwndFrame, HWND_TOP, IDM_RENAME, NULL, NULL);
539 if (!hwndName)
540 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
541 PCSZ_WINCREATEWINDOW);
542
543 hwndTmp = WinCreateWindow(hwndFrame,
544 (CHAR *) WC_TOOLBACK,
545 NullStr,
546 WS_VISIBLE | SS_TEXT | DT_CENTER | DT_VCENTER,
547 swp->x +
548 WinQuerySysValue(HWND_DESKTOP,
549 SV_CXSIZEBORDER),
550 (swp->cy -
551 WinQuerySysValue(HWND_DESKTOP,
552 SV_CYSIZEBORDER)) - 30,
553 swp->cx -
554 (WinQuerySysValue(HWND_DESKTOP,
555 SV_CXSIZEBORDER) * 2),
556 30, hwndFrame, HWND_TOP, MAIN_TOOLS, NULL, NULL);
557 if (!hwndTmp)
558 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
559 PCSZ_WINCREATEWINDOW);
560
561 hwndBack = WinCreateWindow(hwndFrame,
562 (CHAR *) WC_DRIVEBACK,
563 NullStr,
564 WS_VISIBLE | SS_TEXT | DT_RIGHT | DT_BOTTOM,
565 swp->x +
566 WinQuerySysValue(HWND_DESKTOP,
567 SV_CXSIZEBORDER),
568 (swp->cy -
569 WinQuerySysValue(HWND_DESKTOP,
570 SV_CYSIZEBORDER)) -
571 (DRIVE_BUTTON_HEIGHT),
572 swp->cx -
573 (WinQuerySysValue(HWND_DESKTOP,
574 SV_CXSIZEBORDER) * 2),
575 DRIVE_BUTTON_HEIGHT,
576 hwndFrame, HWND_TOP, MAIN_DRIVES, NULL, NULL);
577
578 if (!hwndBack)
579 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
580 PCSZ_WINCREATEWINDOW);
581
582 hwndLED = WinCreateWindow(hwndFrame,
583 (CHAR *) WC_LED,
584 "#920", // LEDOFF_BMP
585 WS_VISIBLE | SS_BITMAP,
586 swp->cx - 58,
587 swp->y,
588 12,
589 12, hwndFrame, HWND_TOP, MAIN_LED, NULL, NULL);
590 if (!hwndLED)
591 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
592 PCSZ_WINCREATEWINDOW);
593
594 hwndLEDHdr = WinCreateWindow(hwndFrame,
595 (CHAR *) WC_LED,
596 "0",
597 WS_VISIBLE | SS_TEXT | DT_VCENTER |
598 DT_CENTER,
599 swp->cx - 58,
600 swp->y + 12,
601 12,
602 12,
603 hwndFrame, HWND_TOP, MAIN_LEDHDR, NULL, NULL);
604 if (!hwndLEDHdr)
605 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
606 PCSZ_WINCREATEWINDOW);
607
608 hwndAutoview = WinCreateWindow(hwndFrame,
609 (CHAR *) WC_AUTOVIEW,
610 NullStr,
611 WS_VISIBLE | SS_TEXT | DT_LEFT |
612 DT_TOP | DT_WORDBREAK,
613 swp->x + 4 +
614 WinQuerySysValue(HWND_DESKTOP,
615 SV_CXSIZEBORDER),
616 swp->y + 4 +
617 WinQuerySysValue(HWND_DESKTOP,
618 SV_CYSIZEBORDER) + 16,
619 (swp->cx - 8) -
620 (WinQuerySysValue(HWND_DESKTOP,
621 SV_CXSIZEBORDER) * 2),
622 48,
623 hwndFrame,
624 HWND_TOP, MAIN_AUTOVIEW, NULL, NULL);
625 if (!hwndAutoview)
626 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
627 PCSZ_WINCREATEWINDOW);
628
629 hwndAutoMLE = WinCreateWindow(hwndFrame,
630 // GetPString(IDS_WCAUTOVIEW),
631 (CHAR *) WC_MLE,
632 NullStr,
633 WS_VISIBLE | MLS_HSCROLL |
634 MLS_VSCROLL | MLS_BORDER,
635 swp->x + 4 +
636 WinQuerySysValue(HWND_DESKTOP,
637 SV_CXSIZEBORDER),
638 swp->y + 4 +
639 WinQuerySysValue(HWND_DESKTOP,
640 SV_CYSIZEBORDER) + 16,
641 (swp->cx - 8) -
642 (WinQuerySysValue(HWND_DESKTOP,
643 SV_CXSIZEBORDER) * 2),
644 48,
645 hwndFrame,
646 HWND_TOP, MAIN_AUTOVIEWMLE, NULL, NULL);
647 if (!hwndAutoMLE)
648 Win_Error(hwndFrame, hwnd, pszSrcFile, __LINE__,
649 PCSZ_WINCREATEWINDOW);
650
651 oldproc = WinSubclassWindow(hwndAutoMLE, AutoViewProc);
652 WinSetWindowPtr(hwndAutoMLE, QWL_USER, (PVOID) oldproc);
653 PostMsg(hwndAutoMLE, UM_SETUP, MPVOID, MPVOID);
654}
655
656/**
657 * Called by MainWndProc and MainWndProc2 to process messages
658 * common to both fm/2 and fm/2 lite main window
659 */
660
661MRESULT EXPENTRY CommonMainWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
662 MPARAM mp2)
663{
664 static BOOL fLedOn;
665 static LONG cWorkerThreads;
666
667 switch (msg) {
668 case UM_THREADUSE:
669 if (hbmLEDon && hbmLEDoff) {
670 CHAR sz[33];
671 if (mp1) {
672 cWorkerThreads++;
673 // 13 Sep 09 SHL fixme to be SMP safe
674 if (cWorkerThreads == 1) {
675 if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_LED_TIMER, 500))
676 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinStartTimer");
677 fLedOn = TRUE;
678 WinSendMsg(hwndLED, SM_SETHANDLE, MPFROMLONG(hbmLEDon), MPVOID);
679 }
680 }
681 else if (cWorkerThreads > 0)
682 cWorkerThreads--;
683
684 ltoa(cWorkerThreads, sz, 10);
685 WinSetWindowText(hwndLEDHdr, sz);
686 DosSleep(0);
687 }
688 return 0;
689
690 case WM_TIMER:
691 fLedOn = !fLedOn;
692 WinSendMsg(hwndLED,
693 SM_SETHANDLE,
694 fLedOn ? MPFROMLONG(hbmLEDon) : MPFROMLONG(hbmLEDoff),
695 MPVOID);
696 if (!fLedOn && cWorkerThreads == 0) {
697 if (!WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_LED_TIMER))
698 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinStartTimer");
699 }
700 break;
701
702 case UM_LOADFILE:
703 {
704 CHAR *s = NULL;
705 static CHAR lastfile[CCHMAXPATH] = "";
706
707 if (!fAutoView) {
708 if (*lastfile)
709 PostMsg((fComments) ? hwndAutoMLE : hwndAutoview,
710 UM_LOADFILE, MPVOID, MPVOID);
711 *lastfile = 0;
712 }
713 else {
714 if (mp1) {
715 if (!mp2 && !stricmp(lastfile, (CHAR *)mp1))
716 return 0;
717 strcpy(lastfile, (CHAR *)mp1);
718 s = xstrdup(lastfile, pszSrcFile, __LINE__);
719 }
720 else
721 *lastfile = 0;
722 if (!PostMsg((fComments) ? hwndAutoMLE : hwndAutoview,
723 UM_LOADFILE, MPFROMP(s), MPVOID)) {
724 xfree(s, pszSrcFile, __LINE__);
725 }
726 }
727 }
728 return 0;
729
730 case UM_BUILDDRIVEBAR:
731 BuildDriveBarButtons(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
732 MAIN_DRIVES));
733 return 0;
734 }
735 return WinDefWindowProc(hwnd, msg, mp1, mp2);
736}
737
738MRESULT EXPENTRY CommonTextButton(HWND hwnd, ULONG msg, MPARAM mp1,
739 MPARAM mp2)
740{
741 static HWND hwndLast = (HWND) 0;
742 static ULONG lastclick = 0;
743
744 switch (msg) {
745 case WM_MOUSEMOVE:
746 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
747 if (!fNoFinger) {
748 WinSetPointer(HWND_DESKTOP, hptrFinger);
749 return MRFROMLONG(TRUE);
750 }
751 break;
752
753 case WM_BUTTON1DOWN:
754 case WM_BUTTON3DOWN:
755 if (hwndBubble)
756 WinDestroyWindow(hwndBubble);
757 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
758 WinSetCapture(HWND_DESKTOP, hwnd);
759 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, FALSE);
760 break;
761
762 case WM_BUTTON2UP:
763 case WM_BUTTON2DOWN:
764 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
765 if (msg == WM_BUTTON2UP && hwndLast) {
766 PostMsg(hwnd, UM_FOCUSME, MPFROMP(hwndLast), MPVOID);
767 hwndLast = (HWND) 0;
768 }
769 break;
770
771 case WM_BUTTON1UP:
772 case WM_BUTTON3UP:
773 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
774 WinSetCapture(HWND_DESKTOP, (HWND) 0);
775 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
776 {
777 ULONG check;
778
779 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &check, sizeof(check));
780 if (check > lastclick + 500) {
781
782 RECTL rcl;
783 POINTS pts;
784
785 pts.x = SHORT1FROMMP(mp1);
786 pts.y = SHORT2FROMMP(mp1);
787 WinQueryWindowRect(hwnd, &rcl);
788 if (pts.x > 0 && pts.y > 0 && pts.x < rcl.xRight && pts.y < rcl.yTop)
789 PostMsg(hwnd, UM_CLICKED + (msg == WM_BUTTON3UP), mp1, mp2);
790 }
791 lastclick = check;
792 }
793 PostMsg(hwnd, UM_FOCUSME, MPFROMP(hwndLast), MPVOID);
794 hwndLast = (HWND) 0;
795 break;
796
797 case WM_SETFOCUS:
798 if (mp2)
799 hwndLast = (HWND) mp1;
800 break;
801
802 case UM_FOCUSME:
803 if (mp1) {
804
805 PID pid;
806 TID tid;
807
808 if (WinIsWindow(WinQueryAnchorBlock(hwnd), (HWND) mp1) &&
809 WinQueryWindowProcess((HWND) mp1, &pid, &tid) && pid == mypid) {
810 WinSetFocus(HWND_DESKTOP, (HWND) mp1);
811 return 0;
812 }
813 }
814 {
815 HWND htemp = (HWND) 0;
816
817 if (hwndMain)
818 htemp = TopWindow(hwndMain, (HWND) 0);
819 if (!htemp)
820 htemp = hwndTree;
821 if (htemp)
822 WinSetFocus(HWND_DESKTOP, htemp);
823 else
824 WinSetFocus(HWND_DESKTOP, WinQueryWindow(hwnd, QW_PARENT));
825 }
826 return 0;
827 }
828
829 return PFNWPStatic(hwnd, msg, mp1, mp2);
830}
831
832MRESULT EXPENTRY CommonCnrProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
833{
834 DIRCNRDATA *dcd = WinQueryWindowPtr(hwnd, QWL_USER);
835
836 switch (msg) {
837 case UM_FIXCNRMLE:
838 if (dcd) {
839
840 SWP swp, swpC;
841
842 if (WinQueryWindowPos(WinWindowFromID(hwnd, CID_MLE), &swp)) {
843 if (WinQueryWindowPos(hwnd, &swpC)) {
844 swpC.cx -= (WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL) + 4);
845 swpC.cx -= swp.x;
846 WinSetWindowPos(WinWindowFromID(hwnd, CID_MLE),
847 HWND_TOP, 0, 0, swpC.cx, swp.cy + 2, SWP_SIZE);
848 }
849 }
850 if (mp1)
851 WinSendMsg(WinWindowFromID(hwnd, CID_MLE),
852 MLM_SETTEXTLIMIT, mp1, MPVOID);
853 }
854 return 0;
855
856 case UM_FIXEDITNAME:
857 if (dcd) {
858 if (mp1 && (INT) mp1 != -1) {
859
860 CHAR *p;
861
862 WinSendMsg(hwnd, UM_FIXCNRMLE, MPFROMLONG(CCHMAXPATH), MPVOID);
863 MLEdelete(WinWindowFromID(hwnd, CID_MLE),
864 0, strlen((CHAR *)mp1) + 1);
865 WinSetDlgItemText(hwnd, CID_MLE, (CHAR *)mp1);
866 p = strrchr((CHAR *)mp1, '\\');
867 if (p) {
868 p++;
869 MLEsetcurposa(WinWindowFromID(hwnd, CID_MLE), (p - (CHAR *)mp1));
870 MLEsetcurposc(WinWindowFromID(hwnd, CID_MLE), strlen((CHAR *)mp1));
871 }
872 else
873 MLEsetcurpos(WinWindowFromID(hwnd, CID_MLE), strlen((CHAR *)mp1));
874 }
875 else if (mp2) {
876 Broadcast(WinQueryAnchorBlock(hwnd),
877 dcd->hwndParent, UM_UPDATERECORD, mp2, MPVOID);
878 xfree(mp2, pszSrcFile, __LINE__);
879 }
880 }
881 return 0;
882 }
883 return PFNWPCnr(hwnd, msg, mp1, mp2);
884}
885
886HWND OpenDirCnr(HWND hwnd, HWND hwndParent, HWND hwndRestore,
887 BOOL noautotile, char *directory)
888{
889 SWP swp;
890 HWND hwndDir;
891
892 if (ParentIsDesktop(hwnd, hwndParent) || *(ULONG *) realappname != FM3UL)
893 StartDirCnr(HWND_DESKTOP, directory, hwndRestore, 1);
894 else if (*(ULONG *) realappname == FM3UL) {
895 if (!fAutoTile)
896 GetNextWindowPos(hwndParent, &swp, NULL, NULL);
897 hwndDir = StartDirCnr(hwndParent, directory, hwndRestore, 1);
898 if (hwndDir) {
899 if (!fAutoTile)
900 WinSetWindowPos(hwndDir,
901 HWND_TOP,
902 swp.x,
903 swp.y,
904 swp.cx,
905 swp.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
906 else if (!noautotile)
907 TileChildren(hwndParent, TRUE);
908 WinSetWindowPos(hwndDir,
909 HWND_TOP,
910 0, 0, 0, 0, SWP_RESTORE | SWP_SHOW | SWP_ACTIVATE);
911 }
912 }
913 else {
914
915 char s[256];
916
917 assign_ignores(s);
918 runemf2(WINDOWED | SEPARATE,
919 hwnd, pszSrcFile, __LINE__,
920 NULL,
921 NULL,
922 "VDIR.EXE %s%s\"%s%s\"",
923 (*s) ? s : NullStr, (*s) ? " " : NullStr,
924 directory,
925 (directory[strlen(directory) - 1] == '\\') ? PCSZ_BACKSLASH : NullStr);
926 }
927 return hwndDir;
928}
929
930//= IncrThreadUsage() Increment thread usage counter ==
931
932VOID IncrThreadUsage(VOID)
933{
934 if (hwndMain)
935 WinPostMsg(hwndMain, UM_THREADUSE, MPFROMLONG(1), MPVOID);
936}
937
938//= DecrThreadUsage() Decrement thread usage counter ==
939
940VOID DecrThreadUsage(VOID)
941{
942 if (hwndMain)
943 WinPostMsg(hwndMain, UM_THREADUSE, MPVOID, MPVOID);
944}
945
946#pragma alloc_text(COMMON,CommonFrameWndProc,CommonTextProc,CommonTextPaint)
947#pragma alloc_text(COMMON1,CommonCreateTextChildren,CommonCreateMainChildren)
948#pragma alloc_text(COMMON2,CommonDriveCmd,CommonTextButton)
949#pragma alloc_text(COMMON3,CommonMainWndProc,IncrThreadUsage,DecrThreadUsage)
950#pragma alloc_text(COMMON4,CommonCnrProc)
951#pragma alloc_text(COMMON5,OpenDirCnr)
Note: See TracBrowser for help on using the repository browser.