source: trunk/dll/mainwnd2.c@ 908

Last change on this file since 908 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: mainwnd2.c 907 2008-01-06 07:26:17Z stevenhl $
5
6 fm/4 main window
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2005, 2008 Steven H. Levine
10
11 23 May 05 SHL Use datamin.h
12 26 May 05 SHL Comments and localize code
13 06 Aug 05 SHL Renames
14 02 Jan 06 SHL Use QWL_USER more
15 02 Jan 06 SHL Map IDM_WINDOWDLG to match IBM_TWODIRS
16 17 Jul 06 SHL Use Runtime_Error
17 30 Mar 07 GKY Remove GetPString for window class names
18 12 May 07 SHL Pass ulItemsToUnHilite to UnHilite
19 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
20 07 Aug 07 SHL Use BldQuotedFileName
21 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
22
23***********************************************************************/
24
25#include <stdlib.h>
26#include <string.h>
27#include <share.h>
28#include <process.h> // _beginthread
29
30#define INCL_DOS
31#define INCL_WIN
32#define INCL_GPI
33#define INCL_LONGLONG
34
35#include "fm3dlg.h"
36#include "fm3str.h"
37#include "tools.h"
38#include "datamin.h"
39#include "comp.h" // COMPARE
40#include "arccnrs.h" // BldQuotedFileName
41#include "errutil.h" // Dos_Error...
42#include "strutil.h" // GetPString
43#include "fm3dll.h"
44
45typedef struct
46{
47 USHORT size;
48 USHORT dummy;
49 HWND hwndDir1;
50 HWND hwndDir2;
51 HWND hwndCurr;
52 HWND hwndLastDir;
53 HWND hwndMax;
54}
55PERSON1DATA;
56
57static PSZ pszSrcFile = __FILE__;
58
59static MRESULT EXPENTRY MainFrameWndProc2(HWND hwnd, ULONG msg, MPARAM mp1,
60 MPARAM mp2)
61{
62 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
63
64 switch (msg) {
65 case WM_ADJUSTWINDOWPOS:
66 {
67 SWP *pswp;
68
69 pswp = (SWP *) mp1;
70 if (pswp->fl & (SWP_SHOW | SWP_RESTORE))
71 PostMsg(WinWindowFromID(hwnd, FID_CLIENT), UM_SIZE, MPVOID, MPVOID);
72 if (fDataMin && !fAmClosing) {
73 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE)) {
74
75 SWP swp;
76
77 WinQueryWindowPos(hwnd, &swp);
78 PostMsg(hwnd, UM_FOCUSME, MPFROMLONG(swp.fl), MPVOID);
79 HideNote();
80 }
81 else if (pswp->fl & (SWP_SHOW | SWP_RESTORE)) {
82 if (DataHwnd)
83 PostMsg(DataHwnd, WM_CLOSE, MPVOID, MPVOID);
84 }
85 }
86 if (!fAmClosing) {
87 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE))
88 HideNote();
89 }
90 }
91 break;
92
93 case UM_FOCUSME:
94 CreateDataBar(HWND_DESKTOP, (ULONG) mp1);
95 return 0;
96
97 case WM_BUTTON1UP:
98 case WM_BUTTON2UP:
99 case WM_BUTTON3UP:
100 case WM_MOUSEMOVE:
101 case WM_CHORD:
102 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
103 break;
104
105 case WM_CHAR:
106 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
107 break;
108
109 case WM_CONTROL:
110 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), UM_CONTROL, mp1,
111 mp2);
112
113 case WM_COMMAND:
114 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
115
116 case WM_CALCFRAMERECT:
117 {
118 MRESULT mr;
119 PRECTL prectl;
120 LONG sheight = 20, bheight = 20;
121
122 mr = (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
123 PFNWPFrame(hwnd, msg, mp1, mp2);
124
125 /*
126 * Calculate the position of the client rectangle.
127 * Otherwise, we'll see a lot of redraw when we move the
128 * client during WM_FORMATFRAME.
129 */
130
131 if (mr && mp2) {
132 prectl = (PRECTL) mp1;
133 if (prectl->yBottom != prectl->yTop) {
134 {
135 HPS hps;
136 POINTL aptl[TXTBOX_COUNT];
137
138 hps = WinGetPS(hwndStatus);
139 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
140 WinReleasePS(hps);
141 sheight = aptl[TXTBOX_TOPLEFT].y + 6;
142 hps = WinGetPS(hwndName);
143 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
144 WinReleasePS(hps);
145 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
146 }
147 prectl->yBottom += (sheight + 4);
148 prectl->yTop -= (sheight + 4);
149 prectl->yBottom += (bheight + 4);
150 prectl->yTop -= (bheight + 4);
151 if (fToolbar) {
152 if (!fTextTools)
153 prectl->yTop -= ((fToolTitles) ? 50 : 40);
154 else
155 prectl->yTop -= 32;
156 }
157 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES),
158 ((prectl->xRight -
159 (WinQuerySysValue(HWND_DESKTOP,
160 SV_CYSIZEBORDER) * 2)) - 4));
161 prectl->yTop -= (16 * (DriveLines * 18));
162 prectl->yTop -= 2;
163 if (fAutoView) {
164 AutoviewHeight = min(AutoviewHeight,
165 (prectl->yTop - prectl->yBottom) - 116);
166 AutoviewHeight = max(AutoviewHeight, 36);
167 prectl->yBottom += (AutoviewHeight + 6);
168 }
169 }
170 }
171 return mr;
172 }
173
174 case WM_FORMATFRAME:
175 {
176 SHORT sCount, soldCount;
177 PSWP pswp, pswpClient, pswpNew;
178 SWP swpClient;
179 ULONG theight = 48L, dheight = 20, bheight = 20, sheight = 20;
180 LONG width, lastx;
181
182 sCount = (SHORT) ((oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
183 PFNWPFrame(hwnd, msg, mp1, mp2));
184 soldCount = sCount;
185 /*
186 * Reformat the frame to "squeeze" the client
187 * and make room for status window sibling beneath
188 * and toolbar above (if toolbar's on) and userlists
189 * (if userlists are on).
190 */
191
192 pswp = (PSWP) mp1;
193 {
194 SHORT x;
195
196 for (x = 0; x < sCount; x++) {
197 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_CLIENT) {
198 pswpClient = pswp;
199 break;
200 }
201 pswp++;
202 }
203 }
204
205 {
206 HPS hps;
207 POINTL aptl[TXTBOX_COUNT];
208
209 hps = WinGetPS(hwndStatus);
210 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
211 WinReleasePS(hps);
212 bheight = sheight = aptl[TXTBOX_TOPLEFT].y + 6;
213 hps = WinGetPS(hwndName);
214 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
215 WinReleasePS(hps);
216 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
217 }
218
219 pswpNew = (PSWP) mp1 + soldCount;
220 *pswpNew = *pswpClient;
221 swpClient = *pswpClient;
222 pswpNew->hwnd = hwndStatus;
223 pswpNew->x = swpClient.x + 3;
224 pswpNew->y = swpClient.y + 2;
225 width = (swpClient.cx / 2) - 6;
226 width = max(width, 10);
227 pswpNew->cx = width - 6;
228 pswpNew->cy = sheight;
229 pswpClient->y = pswpNew->y + pswpNew->cy + 3;
230 pswpClient->cy = (swpClient.cy - pswpNew->cy) - 3;
231 sCount++;
232
233 pswpNew = (PSWP) mp1 + (soldCount + 1);
234 *pswpNew = *pswpClient;
235 pswpNew->hwnd = hwndStatus2;
236 pswpNew->x = width + 8;
237 pswpNew->y = swpClient.y + 2;
238 pswpNew->cx = width - 6;
239 pswpNew->cy = sheight;
240 sCount++;
241
242 if (fToolbar) {
243 if (fTextTools)
244 theight = 32L;
245 else if (!fToolTitles)
246 theight = 40L;
247 pswpNew = (PSWP) mp1 + (soldCount + 2);
248 *pswpNew = *pswpClient;
249 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_TOOLS);
250 pswpNew->x = swpClient.x + 2;
251 pswpNew->y = (swpClient.y + swpClient.cy) - (theight - 2);
252 pswpNew->cx = swpClient.cx - 4;
253 pswpNew->cy = theight - 4;
254 pswpClient->cy -= theight;
255 sCount++;
256 }
257 else
258 WinShowWindow(WinWindowFromID(hwnd, MAIN_TOOLS), FALSE);
259
260 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES), pswpClient->cx - 4);
261 pswpNew = (PSWP) mp1 + (soldCount + 2 + (fToolbar != FALSE));
262 *pswpNew = *pswpClient;
263 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_DRIVES);
264 pswpNew->x = swpClient.x + 2;
265 dheight += ((dheight - 2) * DriveLines);
266 pswpNew->y = (swpClient.y + swpClient.cy) - (dheight - 2);
267 if (fToolbar)
268 pswpNew->y -= theight;
269 pswpNew->cx = swpClient.cx - 4;
270 pswpNew->cy = dheight - 4;
271 pswpClient->cy -= dheight;
272 pswpClient->cy -= 2;
273 sCount++;
274
275 if (fAutoView) {
276 pswpNew = (PSWP) mp1 + (soldCount + 3 + (fToolbar != FALSE));
277 *pswpNew = *pswpClient;
278 pswpNew->hwnd = (fComments) ? hwndAutoMLE : hwndAutoview;
279 pswpNew->x = pswpClient->x + 3;
280 pswpNew->y = pswpClient->y + 3;
281 if (fMoreButtons)
282 pswpNew->y += (bheight + 4);
283 pswpNew->cx = pswpClient->cx - 6;
284 AutoviewHeight = min(AutoviewHeight, pswpClient->cy - 116);
285 AutoviewHeight = max(AutoviewHeight, 36);
286 pswpNew->cy = AutoviewHeight;
287 pswpClient->y += (AutoviewHeight + 6);
288 pswpClient->cy -= (AutoviewHeight + 6);
289 sCount++;
290 WinShowWindow((fComments) ? hwndAutoview : hwndAutoMLE, FALSE);
291 }
292 else {
293 WinShowWindow(hwndAutoview, FALSE);
294 WinShowWindow(hwndAutoMLE, FALSE);
295 }
296
297 pswpNew = (PSWP) mp1 + (soldCount + 3 + (fToolbar != FALSE) +
298 (fAutoView != FALSE));
299 *pswpNew = *pswpClient;
300 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LED);
301 pswpNew->x = (swpClient.x + swpClient.cx) - 12;
302 pswpNew->y = swpClient.y;
303 pswpNew->cx = 12;
304 pswpNew->cy = 12;
305 sCount++;
306
307 pswpNew = (PSWP) mp1 + (soldCount + 4 + (fToolbar != FALSE) +
308 (fAutoView != FALSE));
309 *pswpNew = *pswpClient;
310 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LEDHDR);
311 pswpNew->x = (swpClient.x + swpClient.cx) - 12;
312 pswpNew->y = swpClient.y + 12;
313 pswpNew->cx = 12;
314 pswpNew->cy = sheight - 8;
315 sCount++;
316
317 pswpNew = (PSWP) mp1 + (soldCount + 5 + (fToolbar != FALSE) +
318 (fAutoView != FALSE));
319 *pswpNew = *pswpClient;
320 pswpNew->hwnd = hwndName;
321 pswpNew->x = swpClient.x + 3;
322 pswpNew->y = swpClient.y + (sheight + 6);
323 pswpNew->cx = ((swpClient.cx / 2) + (swpClient.cx / 5)) - 3;
324 lastx = pswpNew->x + pswpNew->cx;
325 pswpNew->cy = bheight;
326 pswpClient->y += (bheight + 4);
327 pswpClient->cy -= (bheight + 4);
328 sCount++;
329
330 pswpNew = (PSWP) mp1 + (soldCount + 6 + (fToolbar != FALSE) +
331 (fAutoView != FALSE));
332 *pswpNew = *pswpClient;
333 pswpNew->hwnd = hwndDate;
334 pswpNew->x = lastx + 3;
335 pswpNew->y = swpClient.y + (sheight + 6);
336 pswpNew->cx = (swpClient.cx / 6) + (swpClient.cx / 16) - 3;
337 lastx = pswpNew->x + pswpNew->cx;
338 pswpNew->cy = bheight;
339 sCount++;
340
341 pswpNew = (PSWP) mp1 + (soldCount + 7 + (fToolbar != FALSE) +
342 (fAutoView != FALSE));
343 *pswpNew = *pswpClient;
344 pswpNew->hwnd = hwndAttr;
345 pswpNew->x = lastx + 3;
346 pswpNew->y = swpClient.y + (sheight + 6);
347 pswpNew->cx = (swpClient.cx - pswpNew->x) - 1;
348 pswpNew->cy = bheight;
349 sCount++;
350
351 return MRFROMSHORT(sCount);
352 }
353
354 case WM_QUERYFRAMECTLCOUNT:
355 {
356 SHORT sCount;
357
358 sCount = (SHORT) ((oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
359 PFNWPFrame(hwnd, msg, mp1, mp2));
360 sCount += 8;
361 if (fToolbar)
362 sCount++;
363 if (fAutoView)
364 sCount++;
365 return MRFROMSHORT(sCount);
366 }
367
368 case WM_CLOSE:
369 WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
370 return 0;
371 }
372 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
373 PFNWPFrame(hwnd, msg, mp1, mp2);
374}
375
376static MRESULT EXPENTRY MainWMCommand2(HWND hwnd, ULONG msg, MPARAM mp1,
377 MPARAM mp2)
378{
379 PERSON1DATA *pd;
380
381 SetShiftState();
382 switch (SHORT1FROMMP(mp1)) {
383 case IDM_TOAUTOMLE:
384 case IDM_CLI:
385 case IDM_CREATETOOL:
386 case IDM_ABOUT:
387 case IDM_WINFULLSCREEN:
388 case IDM_DOSCOMMANDLINE:
389 case IDM_INIVIEWER:
390 case IDM_EDITASSOC:
391 case IDM_COMMANDLINE:
392 case IDM_KILLPROC:
393 case IDM_TOOLBAR:
394 case IDM_TEXTTOOLS:
395 case IDM_TOOLTITLES:
396 case IDM_TOOLLEFT:
397 case IDM_TOOLRIGHT:
398 case IDM_AUTOVIEWCOMMENTS:
399 case IDM_AUTOVIEWFILE:
400 case IDM_AUTOVIEW:
401// case IDM_SYSINFO:
402 case IDM_HIDENOTEWND:
403 case IDM_SHOWNOTEWND:
404 case IDM_INSTANT:
405 case IDM_HELPCONTEXT:
406 case IDM_HELPHINTS:
407 case IDM_HELPPIX:
408 case IDM_KILLME:
409 case IDM_EXIT:
410 case IDM_HELPTUTOR:
411 case IDM_HELPCONTENTS:
412 case IDM_HELPGENERAL:
413 case IDM_HELPKEYS:
414 case IDM_HELPMOUSE:
415 case IDM_HELP:
416 return MainWMCommand(hwnd, msg, mp1, mp2);
417
418 case IDM_REMAP:
419 WinDlgBox(HWND_DESKTOP,
420 hwnd, RemapDlgProc, FM3ModHandle, MAP_FRAME, NULL);
421 break;
422
423 case IDM_TWODIRS: // Menu action
424 case IDM_WINDOWDLG: // Toolbar action
425 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
426 if (pd) {
427
428 WALK2 wa;
429
430 memset(&wa, 0, sizeof(wa));
431 wa.size = sizeof(wa);
432 *wa.szCurrentPath1 = 0;
433 WinSendMsg(pd->hwndDir1,
434 UM_CONTAINERDIR, MPFROMP(wa.szCurrentPath1), MPVOID);
435 MakeValidDir(wa.szCurrentPath1);
436 *wa.szCurrentPath2 = 0;
437 WinSendMsg(pd->hwndDir2,
438 UM_CONTAINERDIR, MPFROMP(wa.szCurrentPath2), MPVOID);
439 MakeValidDir(wa.szCurrentPath2);
440 if (WinDlgBox(HWND_DESKTOP,
441 hwnd,
442 WalkTwoSetDlgProc,
443 FM3ModHandle,
444 WALK2_FRAME,
445 MPFROMP(&wa)) &&
446 (IsRoot(wa.szCurrentPath1) ||
447 !IsFile(wa.szCurrentPath1)) &&
448 (IsRoot(wa.szCurrentPath2) || !IsFile(wa.szCurrentPath2))) {
449 WinSendMsg(WinWindowFromID(WinWindowFromID(pd->hwndDir1,
450 FID_CLIENT), DIR_CNR),
451 UM_SETDIR, MPFROMP(wa.szCurrentPath1), MPVOID);
452 WinSendMsg(WinWindowFromID(WinWindowFromID(pd->hwndDir2,
453 FID_CLIENT), DIR_CNR),
454 UM_SETDIR, MPFROMP(wa.szCurrentPath2), MPVOID);
455 }
456 }
457 break;
458
459 case IDM_COMPARE:
460 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
461 if (pd) {
462
463 WALK2 wa;
464
465 memset(&wa, 0, sizeof(wa));
466 wa.size = sizeof(wa);
467 *wa.szCurrentPath1 = 0;
468 WinSendMsg(pd->hwndDir1,
469 UM_CONTAINERDIR, MPFROMP(wa.szCurrentPath1), MPVOID);
470 MakeValidDir(wa.szCurrentPath1);
471 *wa.szCurrentPath2 = 0;
472 WinSendMsg(pd->hwndDir2,
473 UM_CONTAINERDIR, MPFROMP(wa.szCurrentPath2), MPVOID);
474 MakeValidDir(wa.szCurrentPath2);
475 if (WinDlgBox(HWND_DESKTOP,
476 hwnd,
477 WalkTwoCmpDlgProc,
478 FM3ModHandle,
479 WALK2_FRAME,
480 MPFROMP(&wa)) &&
481 (IsRoot(wa.szCurrentPath1) ||
482 !IsFile(wa.szCurrentPath1)) &&
483 (IsRoot(wa.szCurrentPath2) || !IsFile(wa.szCurrentPath2))) {
484 if (!*dircompare) {
485
486 COMPARE *cmp;
487
488 cmp = xmallocz(sizeof(COMPARE), pszSrcFile, __LINE__);
489 if (cmp) {
490 cmp->size = sizeof(COMPARE);
491 strcpy(cmp->leftdir, wa.szCurrentPath1);
492 strcpy(cmp->rightdir, wa.szCurrentPath2);
493 cmp->hwndParent = hwnd;
494 cmp->dcd.hwndParent = hwnd;
495 WinDlgBox(HWND_DESKTOP,
496 HWND_DESKTOP,
497 CompareDlgProc, FM3ModHandle, COMP_FRAME, MPFROMP(cmp));
498 }
499 }
500 else {
501 CHAR szPath1[CCHMAXPATH];
502 CHAR szPath2[CCHMAXPATH];
503 runemf2(SEPARATE,
504 HWND_DESKTOP, pszSrcFile, __LINE__,
505 NULL, NULL,
506 "%s %s %s",
507 dircompare,
508 BldQuotedFileName(szPath1, wa.szCurrentPath1),
509 BldQuotedFileName(szPath2, wa.szCurrentPath2));
510 }
511 }
512 }
513 break;
514
515 case IDM_VTREE:
516 WinSendMsg(hwnd, UM_SETUP2, MPFROMLONG(1), MPVOID);
517 if (hwndTree) {
518 WinShowWindow(hwndTree, FALSE);
519 PostMsg(hwndTree, WM_CLOSE, MPVOID, MPVOID);
520 hwndTree = (HWND) 0;
521 }
522 else {
523
524 ULONG size = sizeof(ULONG);
525
526 hwndTree = StartTreeCnr(hwnd, 3);
527 PrfQueryProfileData(fmprof,
528 realappname,
529 "FM/4 TreeWidth", (PVOID) & TreeWidth, &size);
530 TreeWidth = max(TreeWidth, 80);
531 }
532 {
533 BOOL dummy = (hwndTree != (HWND) 0);
534
535 PrfWriteProfileData(fmprof,
536 realappname,
537 "FM/4 TreeUp", (PVOID) & dummy, sizeof(dummy));
538 }
539 PostMsg(hwnd, UM_SIZE, MPVOID, MPVOID);
540 break;
541
542 case IDM_TILEBACKWARDS:
543 WinSendMsg(hwnd, UM_SETUP2, MPFROMLONG(1), MPVOID);
544 fTileBackwards = (fTileBackwards) ? FALSE : TRUE;
545 PrfWriteProfileData(fmprof,
546 FM3Str,
547 "TileBackwards",
548 (PVOID) & fTileBackwards, sizeof(BOOL));
549 PostMsg(hwnd, UM_SIZE, MPVOID, MPVOID);
550 break;
551
552 case IDM_NEXTWINDOW:
553 case IDM_PREVWINDOW:
554 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
555 if (pd) {
556
557 HWND hwndFocus;
558
559 if (hwndTree) {
560 if (pd->hwndMax) {
561 if (hwndTree == pd->hwndCurr)
562 hwndFocus = pd->hwndMax;
563 else
564 hwndFocus = hwndTree;
565 }
566 else {
567 if (hwndTree == pd->hwndCurr)
568 hwndFocus = (SHORT1FROMMP(mp1) == IDM_PREVWINDOW) ?
569 pd->hwndDir1 : pd->hwndDir2;
570 else if (pd->hwndDir1 == pd->hwndCurr)
571 hwndFocus = (SHORT1FROMMP(mp1) == IDM_PREVWINDOW) ?
572 pd->hwndDir2 : hwndTree;
573 else
574 hwndFocus = (SHORT1FROMMP(mp1) == IDM_PREVWINDOW) ?
575 hwndTree : pd->hwndDir1;
576 }
577 }
578 else {
579 if (pd->hwndMax)
580 hwndFocus = pd->hwndMax;
581 else
582 hwndFocus = (pd->hwndCurr == pd->hwndDir1) ?
583 pd->hwndDir2 : pd->hwndDir1;
584 }
585 WinSetFocus(HWND_DESKTOP, hwndFocus);
586 }
587 break;
588
589 case IDM_NOTEBOOK:
590 WinDlgBox(HWND_DESKTOP,
591 hwnd,
592 CfgDlgProc, FM3ModHandle, CFG_FRAME, MPFROMP(realappname));
593 PostMsg(hwnd, UM_SIZE, MPVOID, MPVOID);
594 break;
595
596 case IDM_SEEALL:
597 case IDM_GREP:
598 case IDM_COLLECTOR:
599 {
600 HWND hwndC;
601
602 hwndC = StartCollector(HWND_DESKTOP, 4);
603 if (hwndC) {
604 WinSetWindowPos(hwndC,
605 HWND_TOP,
606 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE | SWP_ACTIVATE);
607 if (SHORT1FROMMP(mp1) == IDM_GREP)
608 PostMsg(WinWindowFromID(hwndC, FID_CLIENT),
609 WM_COMMAND, MPFROM2SHORT(IDM_GREP, 0), MPVOID);
610 if (SHORT1FROMMP(mp1) == IDM_SEEALL)
611 PostMsg(WinWindowFromID(hwndC, FID_CLIENT),
612 WM_COMMAND, MPFROM2SHORT(IDM_SEEALL, 0), MPVOID);
613 }
614 }
615 break;
616
617 case IDM_EDITCOMMANDS:
618 EditCommands(hwnd);
619 break;
620
621 default:
622 if (SHORT1FROMMP(mp1) >= IDM_SWITCHSTART &&
623 SHORT1FROMMP(mp1) < IDM_SWITCHSTART + 499) {
624 if (SHORT1FROMMP(mp1) - IDM_SWITCHSTART < numswitches)
625 WinSwitchToProgram(switches[SHORT1FROMMP(mp1) - IDM_SWITCHSTART]);
626 break;
627 }
628 else if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
629 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
630
631 INT x;
632 HWND hwndCnr;
633
634 if (!cmdloaded)
635 load_commands();
636 hwndCnr = TopWindow(hwnd, (HWND) 0);
637 hwndCnr = (HWND) WinSendMsg(WinWindowFromID(hwndCnr, FID_CLIENT),
638 UM_CONTAINERHWND, MPVOID, MPVOID);
639 if (!hwndCnr) {
640 Runtime_Error2(pszSrcFile, __LINE__, IDS_NOWINDOWTEXT);
641 break;
642 }
643 x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
644 if (x >= 0) {
645 x++;
646 RunCommand(hwndCnr, x);
647 if (fUnHilite) {
648
649 PCNRITEM pci;
650 DIRCNRDATA *dcd = NULL;
651
652 if (WinQueryWindowUShort(hwndCnr, QWS_ID) != TREE_CNR)
653 dcd = INSTDATA(hwndCnr);
654 pci = (PCNRITEM) WinSendMsg(hwndCnr,
655 CM_QUERYRECORDEMPHASIS,
656 MPFROMLONG(CMA_FIRST),
657 MPFROMSHORT(CRA_CURSORED));
658 if (pci && (INT) pci != -1 && (pci->rc.flRecordAttr & CRA_SELECTED)) {
659 UnHilite(hwnd,
660 TRUE,
661 dcd ? &dcd->lastselection : NULL,
662 dcd ? dcd->ulItemsToUnHilite : 0);
663 }
664 }
665 }
666 }
667 else if (SHORT1FROMMP(mp1) >= IDM_QUICKTOOLSTART &&
668 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART + 50) {
669 if (!qtloaded)
670 load_quicktools();
671 if (quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]) {
672 if (fToolsChanged)
673 save_tools(NULL);
674 if (!load_tools(quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]))
675 load_tools(NULL);
676 else {
677 strcpy(lasttoolbox,
678 quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]);
679 PrfWriteProfileString(fmprof, FM3Str, "LastToolBox", lasttoolbox);
680 }
681 BuildTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
682 MAIN_TOOLS), TRUE);
683 }
684 }
685 else {
686
687 HWND hwndActive;
688
689 hwndActive = TopWindow(hwnd, (HWND) 0);
690 if (hwndActive)
691 PostMsg(WinWindowFromID(hwndActive, FID_CLIENT), msg, mp1, mp2);
692 }
693 break;
694 }
695 return 0;
696}
697
698static MRESULT EXPENTRY MainWMOnce2(HWND hwnd, ULONG msg, MPARAM mp1,
699 MPARAM mp2)
700{
701 PERSON1DATA *pd;
702
703 switch (msg) {
704 case WM_CREATE:
705 {
706 TID tid;
707
708 WinQueryWindowProcess(hwnd, &mypid, &tid);
709 }
710 hwndMain = hwnd;
711 WinSetWindowUShort(hwnd, QWL_USER + 8, 0);
712 WinSetWindowUShort(hwnd, QWL_USER + 10, 0);
713 WinSetWindowUShort(hwnd, QWL_USER + 12, 0);
714 WinSetWindowUShort(hwnd, QWL_USER + 16, 0);
715 if (_beginthread(MakeMainObjWin, NULL, 245760, MPVOID) == -1) {
716 Runtime_Error(pszSrcFile, __LINE__,
717 GetPString(IDS_COULDNTSTARTTHREADTEXT));
718 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
719 return 0;
720 }
721 else
722 DosSleep(32);//05 Aug 07 GKY 64
723
724 pd = xmallocz(sizeof(PERSON1DATA), pszSrcFile, __LINE__);
725 if (!pd)
726 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
727 else {
728 pd->size = sizeof(PERSON1DATA);
729 WinSetWindowPtr(hwnd, QWL_USER + 4, (PVOID) pd);
730 }
731 {
732 SWP swp;
733 PFNWP oldproc;
734
735 /*
736 * create frame children (not client children, frame children)
737 */
738 DosSleep(1);
739 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
740 oldproc = WinSubclassWindow(WinQueryWindow(hwnd, QW_PARENT),
741 (PFNWP) MainFrameWndProc2);
742 if (oldproc)
743 WinSetWindowPtr(WinQueryWindow(hwnd, QW_PARENT), QWL_USER, (PVOID) oldproc);
744 CommonCreateMainChildren(hwnd, &swp);
745
746 {
747 HWND hwndMenu;
748
749 hwndMenu = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_MENU);
750 WinSetWindowULong(hwnd, 0, hwndMenu);
751 SetConditionalCascade(hwndMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
752 SetConditionalCascade(hwndMenu, IDM_TOOLSUBMENU, IDM_TOOLBAR);
753 }
754 }
755 WinSetWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
756 FID_TITLEBAR), "FM/2 Lite");
757 FixSwitchList(WinQueryWindow(hwnd, QW_PARENT), NULL);
758 SetSysMenu(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_SYSMENU));
759 break;
760
761 case UM_SETUP:
762 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
763 if (pd) {
764
765 CHAR s[CCHMAXPATH];
766 ULONG size;
767 DIRCNRDATA *dcd;
768 HWND hwndC;
769 BOOL dummy = TRUE;
770
771 size = sizeof(BOOL);
772 PrfQueryProfileData(fmprof,
773 realappname, "FM/4 TreeUp", (PVOID) & dummy, &size);
774 if (dummy) {
775 size = sizeof(ULONG);
776 hwndTree = StartTreeCnr(hwnd, 3);
777 PrfQueryProfileData(fmprof,
778 realappname,
779 "FM/4 TreeWidth", (PVOID) & TreeWidth, &size);
780 TreeWidth = max(TreeWidth, 80);
781 }
782 size = sizeof(BOOL);
783 if (PrfQueryProfileData(fmprof,
784 FM3Str,
785 "Toolbar", &dummy, &size) && size && !dummy)
786 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_TOOLBAR, 0), MPVOID);
787
788 size = sizeof(s);
789 *s = 0;
790 if (PrfQueryProfileData(fmprof,
791 realappname, "FM/4 Dir1", s, &size) && *s)
792 MakeValidDir(s);
793 else
794 save_dir(s);
795 pd->hwndLastDir = pd->hwndCurr = pd->hwndDir1 =
796 StartDirCnr(hwnd, s, (HWND) 0, 3);
797 size = sizeof(s);
798 *s = 0;
799 if (PrfQueryProfileData(fmprof,
800 realappname, "FM/4 Dir2", s, &size) && *s)
801 MakeValidDir(s);
802 else
803 save_dir(s);
804 pd->hwndDir2 = StartDirCnr(hwnd, s, (HWND) 0, 3);
805 WinSetFocus(HWND_DESKTOP, pd->hwndCurr);
806
807 hwndC = WinWindowFromID(pd->hwndDir1, FID_CLIENT);
808 if (hwndC) {
809 dcd = WinQueryWindowPtr(WinWindowFromID(hwndC, DIR_CNR), QWL_USER);
810 if (dcd) {
811 size = sizeof(INT);
812 if (PrfQueryProfileData(fmprof,
813 realappname,
814 "FM/4 Dir1.Sort",
815 (PVOID) & dcd->sortFlags,
816 &size) && size == sizeof(INT)) {
817 if (!dcd->sortFlags)
818 dcd->sortFlags = SORT_PATHNAME;
819 }
820 size = sizeof(MASK);
821 if (PrfQueryProfileData(fmprof,
822 realappname,
823 "FM/4 Dir1.Filter",
824 (PVOID) & dcd->mask, &size) && size) {
825 if (*dcd->mask.szMask)
826 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
827 UM_FILTER, MPFROMP(dcd->mask.szMask), MPVOID);
828 }
829 *(dcd->mask.prompt) = 0;
830 size = sizeof(ULONG);
831 if (PrfQueryProfileData(fmprof,
832 realappname,
833 "FM/4 Dir1.View",
834 (PVOID) & dcd->flWindowAttr,
835 &size) && size == sizeof(ULONG)) {
836
837 CNRINFO cnri;
838
839 memset(&cnri, 0, sizeof(CNRINFO));
840 cnri.cb = sizeof(CNRINFO);
841 if (WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
842 CM_QUERYCNRINFO,
843 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)))) {
844 cnri.flWindowAttr = dcd->flWindowAttr;
845 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
846 CM_SETCNRINFO,
847 MPFROMP(&cnri), MPFROMLONG(CMA_FLWINDOWATTR));
848 }
849 }
850 }
851 }
852
853 hwndC = WinWindowFromID(pd->hwndDir2, FID_CLIENT);
854 if (hwndC) {
855 dcd = WinQueryWindowPtr(WinWindowFromID(hwndC, DIR_CNR), QWL_USER);
856 if (dcd) {
857 size = sizeof(INT);
858 if (PrfQueryProfileData(fmprof,
859 realappname,
860 "FM/4 Dir2.Sort",
861 (PVOID) & dcd->sortFlags,
862 &size) && size == sizeof(INT)) {
863 if (!dcd->sortFlags)
864 dcd->sortFlags = SORT_PATHNAME;
865 }
866 size = sizeof(MASK);
867 if (PrfQueryProfileData(fmprof,
868 realappname,
869 "FM/4 Dir2.Filter",
870 (PVOID) & dcd->mask, &size) && size) {
871 if (*dcd->mask.szMask)
872 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
873 UM_FILTER, MPFROMP(dcd->mask.szMask), MPVOID);
874 }
875 *(dcd->mask.prompt) = 0;
876 size = sizeof(ULONG);
877 if (PrfQueryProfileData(fmprof,
878 realappname,
879 "FM/4 Dir2.View",
880 (PVOID) & dcd->flWindowAttr,
881 &size) && size == sizeof(ULONG)) {
882
883 CNRINFO cnri;
884
885 memset(&cnri, 0, sizeof(CNRINFO));
886 cnri.cb = sizeof(CNRINFO);
887 if (WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
888 CM_QUERYCNRINFO,
889 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)))) {
890 cnri.flWindowAttr = dcd->flWindowAttr;
891 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
892 CM_SETCNRINFO,
893 MPFROMP(&cnri), MPFROMLONG(CMA_FLWINDOWATTR));
894 }
895 }
896 }
897 }
898 }
899 {
900 ULONG which = 0, size = sizeof(ULONG);
901
902 if (PrfQueryProfileData(fmprof,
903 realappname,
904 "FM/4 Max",
905 (PVOID) & which,
906 &size) && size == sizeof(ULONG) && which) {
907 PostMsg(hwnd,
908 UM_MAXIMIZE,
909 MPFROMLONG(((which == 1) ?
910 pd->hwndDir1 : pd->hwndDir2)), MPVOID);
911 }
912 }
913 PostMsg(hwnd, UM_SIZE, MPVOID, MPVOID);
914 if (!hwndTree)
915 PostMsg(hwnd, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
916 load_tools(NULL);
917 BuildTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
918 MAIN_TOOLS), TRUE);
919 fRunning = TRUE;
920 return 0;
921
922 case WM_SAVEAPPLICATION:
923 WinStoreWindowPos(FM2Str,
924 "MainWindowPos2", WinQueryWindow(hwnd, QW_PARENT));
925 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
926 if (pd) {
927
928 CHAR s[CCHMAXPATH];
929 HWND hwndC;
930 DIRCNRDATA *dcd;
931 ULONG flWindowAttr;
932
933 *s = 0;
934 WinSendMsg(pd->hwndDir1, UM_CONTAINERDIR, MPFROMP(s), MPVOID);
935 if (*s) {
936 MakeValidDir(s);
937 PrfWriteProfileString(fmprof, realappname, "FM/4 Dir1", s);
938 }
939 *s = 0;
940 WinSendMsg(pd->hwndDir2, UM_CONTAINERDIR, MPFROMP(s), MPVOID);
941 if (*s) {
942 MakeValidDir(s);
943 PrfWriteProfileString(fmprof, realappname, "FM/4 Dir2", s);
944 }
945 flWindowAttr = (pd->hwndMax == pd->hwndDir1) ?
946 1 : (pd->hwndMax == pd->hwndDir2) ? 2 : 0;
947 PrfWriteProfileData(fmprof,
948 realappname,
949 "FM/4 Max", &flWindowAttr, sizeof(flWindowAttr));
950 hwndC = WinWindowFromID(pd->hwndDir1, FID_CLIENT);
951 if (hwndC) {
952 dcd = WinQueryWindowPtr(WinWindowFromID(hwndC, DIR_CNR), QWL_USER);
953 if (dcd) {
954 flWindowAttr = dcd->flWindowAttr;
955 if (!fLeaveTree && (flWindowAttr & CV_TREE)) {
956 flWindowAttr &= (~(CV_TREE | CV_ICON | CV_DETAIL | CV_TEXT));
957 if (dcd->lastattr) {
958 if (dcd->lastattr & CV_TEXT)
959 flWindowAttr |= CV_TEXT;
960 else if (dcd->lastattr & CV_DETAIL)
961 flWindowAttr |= CV_DETAIL;
962 else if (dcd->lastattr & CV_ICON)
963 flWindowAttr |= CV_ICON;
964 else
965 flWindowAttr |= CV_NAME;
966 }
967 else
968 flWindowAttr |= CV_NAME;
969 }
970 PrfWriteProfileData(fmprof,
971 realappname,
972 "FM/4 Dir1.Sort",
973 (PVOID) & dcd->sortFlags, sizeof(INT));
974 PrfWriteProfileData(fmprof,
975 realappname,
976 "FM/4 Dir1.Filter",
977 (PVOID) & dcd->mask, sizeof(MASK));
978 PrfWriteProfileData(fmprof,
979 realappname,
980 "FM/4 Dir1.View",
981 (PVOID) & flWindowAttr, sizeof(ULONG));
982 }
983 }
984
985 hwndC = WinWindowFromID(pd->hwndDir2, FID_CLIENT);
986 if (hwndC) {
987 dcd = WinQueryWindowPtr(WinWindowFromID(hwndC, DIR_CNR), QWL_USER);
988 if (dcd) {
989 flWindowAttr = dcd->flWindowAttr;
990 if (!fLeaveTree && (flWindowAttr & CV_TREE)) {
991 flWindowAttr &= (~(CV_TREE | CV_ICON | CV_DETAIL | CV_TEXT));
992 if (dcd->lastattr) {
993 if (dcd->lastattr & CV_TEXT)
994 flWindowAttr |= CV_TEXT;
995 else if (dcd->lastattr & CV_DETAIL)
996 flWindowAttr |= CV_DETAIL;
997 else if (dcd->lastattr & CV_ICON)
998 flWindowAttr |= CV_ICON;
999 else
1000 flWindowAttr |= CV_NAME;
1001 }
1002 else
1003 flWindowAttr |= CV_NAME;
1004 }
1005 PrfWriteProfileData(fmprof,
1006 realappname,
1007 "FM/4 Dir2.Sort",
1008 (PVOID) & dcd->sortFlags, sizeof(INT));
1009 PrfWriteProfileData(fmprof,
1010 realappname,
1011 "FM/4 Dir2.Filter",
1012 (PVOID) & dcd->mask, sizeof(MASK));
1013 PrfWriteProfileData(fmprof,
1014 realappname,
1015 "FM/4 Dir2.View",
1016 (PVOID) & flWindowAttr, sizeof(ULONG));
1017 }
1018 }
1019 }
1020 break;
1021 }
1022 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1023}
1024
1025MRESULT EXPENTRY MainWndProc2(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1026{
1027 PERSON1DATA *pd;
1028
1029 switch (msg) {
1030 case WM_SAVEAPPLICATION:
1031 case UM_SETUP:
1032 case WM_CREATE:
1033 return MainWMOnce2(hwnd, msg, mp1, mp2);
1034
1035 case UM_THREADUSE:
1036 case UM_LOADFILE:
1037 case UM_BUILDDRIVEBAR:
1038 return CommonMainWndProc(hwnd, msg, mp1, mp2);
1039
1040 case UM_SETUP2:
1041 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
1042 if (pd) {
1043 if (mp1) {
1044 if (pd->hwndDir1 && (!pd->hwndMax || pd->hwndMax == pd->hwndDir1))
1045 BoxWindow(pd->hwndDir1, (HPS) 0, CLR_PALEGRAY);
1046 if (pd->hwndDir2 && (!pd->hwndMax || pd->hwndMax == pd->hwndDir2))
1047 BoxWindow(pd->hwndDir2, (HPS) 0, CLR_PALEGRAY);
1048 if (hwndTree)
1049 BoxWindow(hwndTree, (HPS) 0, CLR_PALEGRAY);
1050 }
1051 else {
1052 if (hwndTree)
1053 BoxWindow(hwndTree,
1054 (HPS) 0,
1055 (pd->hwndCurr == hwndTree) ? CLR_RED : CLR_WHITE);
1056 if (!pd->hwndMax || pd->hwndMax == pd->hwndDir1)
1057 BoxWindow(pd->hwndDir1,
1058 (HPS) 0,
1059 (pd->hwndDir1 == pd->hwndCurr) ?
1060 CLR_RED :
1061 (pd->hwndDir1 == pd->hwndLastDir) ?
1062 CLR_DARKRED : CLR_PALEGRAY);
1063 if (!pd->hwndMax || pd->hwndMax == pd->hwndDir2)
1064 BoxWindow(pd->hwndDir2,
1065 (HPS) 0,
1066 (pd->hwndDir2 == pd->hwndCurr) ?
1067 CLR_RED :
1068 (pd->hwndDir2 == pd->hwndLastDir) ?
1069 CLR_DARKRED : CLR_PALEGRAY);
1070 }
1071 }
1072 return 0;
1073
1074 case WM_BUTTON1DOWN:
1075 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
1076 if (hwndTree) {
1077
1078 SWP swp;
1079
1080 WinQueryWindowPos(hwndTree, &swp);
1081 if (SHORT1FROMMP(mp1) > (swp.x + swp.cx) - 3 &&
1082 SHORT1FROMMP(mp1) < (swp.x + swp.cx) + 3) {
1083
1084 SWP swpC;
1085 TRACKINFO track;
1086
1087 WinQueryWindowPos(hwnd, &swpC);
1088 track.cxBorder = 4;
1089 track.cyBorder = 4;
1090 track.cxGrid = 1;
1091 track.cyGrid = 1;
1092 track.cxKeyboard = 8;
1093 track.cyKeyboard = 8;
1094 track.rclTrack.yBottom = 2;
1095 track.rclTrack.yTop = swpC.cy - 4;
1096 track.rclTrack.xLeft = 2;
1097 track.rclTrack.xRight = swp.x + swp.cx + 2;
1098 track.rclBoundary = track.rclTrack;
1099 track.rclBoundary.xRight = swpC.cx - 80;
1100 track.ptlMinTrackSize.x = 80;
1101 track.ptlMinTrackSize.y = swpC.cy - 4;
1102 track.ptlMaxTrackSize.x = swpC.cx - 80;
1103 track.ptlMaxTrackSize.y = swpC.cy - 4;
1104 track.fs = TF_RIGHT;
1105 if (WinTrackRect(hwnd, (HPS) 0, &track)) {
1106 TreeWidth = track.rclTrack.xRight - track.rclTrack.xLeft;
1107 PrfWriteProfileData(fmprof,
1108 realappname,
1109 "FM/4 TreeWidth", &TreeWidth, sizeof(ULONG));
1110 WinSendMsg(hwnd, UM_SETUP2, MPFROMLONG(1), MPVOID);
1111 PostMsg(hwnd, UM_SIZE, MPVOID, MPVOID);
1112 }
1113 return (MRESULT) TRUE;
1114 }
1115 }
1116 break;
1117
1118 case WM_MOUSEMOVE:
1119 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
1120 if (hwndTree) {
1121
1122 SWP swp;
1123
1124 if (WinQueryWindowPos(hwndTree, &swp)) {
1125 if (SHORT1FROMMP(mp1) > (swp.x + swp.cx) - 3 &&
1126 SHORT1FROMMP(mp1) < (swp.x + swp.cx) + 3)
1127 WinSetPointer(HWND_DESKTOP, hptrEW);
1128 else
1129 WinSetPointer(HWND_DESKTOP, hptrArrow);
1130 }
1131 else
1132 WinSetPointer(HWND_DESKTOP, hptrArrow);
1133 }
1134 return (MRESULT) TRUE;
1135
1136 case WM_BUTTON1UP:
1137 case WM_BUTTON2UP:
1138 case WM_BUTTON3UP:
1139 case WM_CHAR:
1140 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
1141 break;
1142
1143 case UM_ADVISEFOCUS:
1144 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
1145 if (mp1 && pd && (HWND) mp1 != pd->hwndCurr) {
1146 if ((HWND) mp1 != hwndTree)
1147 pd->hwndLastDir = (HWND) mp1;
1148 pd->hwndCurr = (HWND) mp1;
1149 WinSendMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
1150 }
1151 return 0;
1152
1153 case UM_MAXIMIZE:
1154 if (mp1) {
1155 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
1156 if (pd) {
1157 WinSendMsg(hwnd, UM_SETUP2, MPFROMLONG(1), MPVOID);
1158 if (pd->hwndMax != (HWND) mp1) {
1159 pd->hwndMax = (HWND) mp1;
1160 WinSetFocus(HWND_DESKTOP, pd->hwndMax);
1161 }
1162 else
1163 pd->hwndMax = (HWND) 0;
1164 PostMsg(hwnd, UM_SIZE, MPVOID, MPVOID);
1165 }
1166 }
1167 return 0;
1168
1169 case WM_INITMENU:
1170 switch (SHORT1FROMMP(mp1)) {
1171 case IDM_FILESMENU:
1172 case IDM_VIEWSMENU:
1173 case IDM_DETAILSSETUP:
1174 case IDM_COMMANDSMENU:
1175 case IDM_SORTSUBMENU:
1176 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
1177 if (pd)
1178 WinSendMsg(pd->hwndCurr, UM_INITMENU, mp1, mp2);
1179 break;
1180 case IDM_CONFIGMENU:
1181 WinCheckMenuItem((HWND) mp2, IDM_TOOLSUBMENU, fToolbar);
1182 WinCheckMenuItem((HWND) mp2, IDM_AUTOVIEW, fAutoView);
1183 break;
1184 case IDM_TOOLSUBMENU:
1185 WinCheckMenuItem((HWND) mp2, IDM_TOOLBAR, fToolbar);
1186 WinCheckMenuItem((HWND) mp2, IDM_TEXTTOOLS, fTextTools);
1187 WinCheckMenuItem((HWND) mp2, IDM_TOOLTITLES, fToolTitles);
1188 break;
1189 case IDM_WINDOWSMENU:
1190 WinCheckMenuItem((HWND) mp2, IDM_VTREE, (hwndTree != (HWND) 0));
1191 WinCheckMenuItem((HWND) mp2, IDM_TILEBACKWARDS, fTileBackwards);
1192 SetupWinList((HWND) mp2, hwnd, WinQueryWindow(hwnd, QW_PARENT));
1193 break;
1194 }
1195 break;
1196
1197 case WM_SETFOCUS:
1198 if (mp2)
1199 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
1200 break;
1201
1202 case UM_FOCUSME:
1203 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
1204 if (pd)
1205 WinSetFocus(HWND_DESKTOP, pd->hwndCurr);
1206 return 0;
1207
1208 case UM_RESCAN:
1209 return 0;
1210
1211 case UM_SIZE:
1212 {
1213 SWP swp;
1214
1215 if (WinQueryWindowPos(hwnd, &swp)) {
1216 mp1 = MPFROM2SHORT(swp.cx, swp.cy);
1217 mp2 = MPFROM2SHORT(swp.cx, swp.cy);
1218 }
1219 else
1220 return 0;
1221 }
1222 /* intentional fallthru */
1223 case WM_SIZE:
1224 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
1225 if (mp1 && mp2 && pd && pd->hwndDir1 && pd->hwndDir2) {
1226 if (hwndTree)
1227 WinSetWindowPos(hwndTree,
1228 HWND_TOP,
1229 2,
1230 2,
1231 TreeWidth - 4,
1232 SHORT2FROMMP(mp2) - 4,
1233 SWP_SHOW | SWP_MOVE | SWP_SIZE);
1234 else
1235 TreeWidth = 0;
1236 if (!pd->hwndMax) {
1237 if (fTileBackwards) {
1238 WinSetWindowPos(pd->hwndDir1, HWND_TOP,
1239 (((SHORT1FROMMP(mp2) - TreeWidth) / 2) +
1240 TreeWidth) + 2,
1241 2,
1242 ((SHORT1FROMMP(mp2) - TreeWidth) / 2) - 4,
1243 SHORT2FROMMP(mp2) - 4,
1244 SWP_SHOW | SWP_MOVE | SWP_SIZE);
1245 WinSetWindowPos(pd->hwndDir2, HWND_TOP,
1246 TreeWidth + 2,
1247 2,
1248 ((SHORT1FROMMP(mp2) - TreeWidth) / 2) - 4,
1249 SHORT2FROMMP(mp2) - 4,
1250 SWP_SHOW | SWP_MOVE | SWP_SIZE);
1251 }
1252 else {
1253 WinSetWindowPos(pd->hwndDir1, HWND_TOP,
1254 TreeWidth + 2,
1255 2,
1256 (SHORT1FROMMP(mp2) - TreeWidth) - 4,
1257 (SHORT2FROMMP(mp2) / 2) - 4,
1258 SWP_SHOW | SWP_MOVE | SWP_SIZE);
1259 WinSetWindowPos(pd->hwndDir2, HWND_TOP,
1260 TreeWidth + 2,
1261 (SHORT2FROMMP(mp2) / 2) + 2,
1262 (SHORT1FROMMP(mp2) - TreeWidth) - 4,
1263 (SHORT2FROMMP(mp2) / 2) - 4,
1264 SWP_SHOW | SWP_MOVE | SWP_SIZE);
1265 }
1266 }
1267 else {
1268
1269 HWND hwndOther;
1270
1271 WinSetWindowPos(pd->hwndMax, HWND_TOP,
1272 TreeWidth + 2,
1273 2,
1274 (SHORT1FROMMP(mp2) - TreeWidth) - 4,
1275 SHORT2FROMMP(mp2) - 4,
1276 SWP_SHOW | SWP_MOVE | SWP_SIZE);
1277 hwndOther = (pd->hwndMax == pd->hwndDir1) ?
1278 pd->hwndDir2 : pd->hwndDir1;
1279 WinSetWindowPos(hwndOther, HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDE);
1280 }
1281 WinSendMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
1282 }
1283 if (msg == UM_SIZE)
1284 return 0;
1285 break;
1286
1287 case WM_ERASEBACKGROUND:
1288 WinFillRect((HPS) mp1, (PRECTL) mp2, 0x00d0d0d0);
1289 return 0;
1290
1291 case WM_PAINT:
1292 {
1293 HPS hps;
1294 RECTL rcl;
1295
1296 hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
1297 if (hps) {
1298 WinQueryWindowRect(hwnd, &rcl);
1299 WinFillRect(hps, (PRECTL) & rcl, CLR_PALEGRAY);
1300 WinEndPaint(hps);
1301 WinSendMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
1302 }
1303 }
1304 break;
1305
1306 case UM_COMMAND:
1307 case WM_COMMAND:
1308 return MainWMCommand2(hwnd, msg, mp1, mp2);
1309
1310 case WM_CLOSE:
1311 fAmClosing = TRUE;
1312 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
1313 CloseChildren(hwnd);
1314 PostMsg(hwnd, UM_CLOSE, MPVOID, MPVOID);
1315 DosSleep(1);
1316 return 0;
1317
1318 case UM_CLOSE:
1319 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
1320 return 0;
1321
1322 case WM_DESTROY:
1323 hwndMain = (HWND) 0;
1324 pd = WinQueryWindowPtr(hwnd, QWL_USER + 4);
1325 if (pd)
1326 free(pd);
1327 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
1328 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
1329 break;
1330 }
1331 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1332}
1333
1334HWND StartFM32(HAB hab, INT argc, CHAR ** argv)
1335{
1336 HWND hwndFrame, hwndClient;
1337 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
1338 FCF_SIZEBORDER | FCF_MINMAX |
1339 FCF_ACCELTABLE | FCF_MENU | FCF_ICON | FCF_TASKLIST | FCF_NOBYTEALIGN;
1340
1341 {
1342 INT x;
1343
1344 for (x = 1; x < argc; x++) {
1345 if (*argv[x] == '+' && !argv[x][1])
1346 fLogFile = TRUE;
1347 if (*argv[x] == '-') {
1348 if (argv[x][1])
1349 strcpy(profile, &argv[x][1]);
1350 }
1351 }
1352 }
1353 {
1354 CHAR inipath[CCHMAXPATH], fullpath[CCHMAXPATH];
1355 FILESTATUS3 fsa;
1356
1357 if (PrfQueryProfileString(HINI_USERPROFILE,
1358 FM2Str,
1359 "Home", NULL, inipath, sizeof(inipath))) {
1360 if (!DosQueryPathInfo(inipath, FIL_STANDARD, &fsa, sizeof(fsa))) {
1361 if (fsa.attrFile & FILE_DIRECTORY) {
1362 if (DosQueryPathInfo(inipath,
1363 FIL_QUERYFULLNAME, fullpath, sizeof(fullpath)))
1364 strcpy(fullpath, inipath);
1365 switch_to(fullpath);
1366 }
1367 }
1368 }
1369 }
1370
1371 hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
1372 WS_VISIBLE,
1373 &FrameFlags,
1374 WC_MAINWND2,
1375 NULL,
1376 WS_VISIBLE | WS_ANIMATE,
1377 FM3ModHandle, MAIN2_FRAME, &hwndClient);
1378 if (hwndFrame) {
1379 hwndMainMenu = WinWindowFromID(hwndFrame, FID_MENU);
1380 if (!WinRestoreWindowPos(FM2Str, "MainWindowPos2", hwndFrame)) {
1381
1382 ULONG fl = SWP_MOVE | SWP_SIZE;
1383 RECTL rcl;
1384 ULONG icz = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 3L;
1385 ULONG bsz = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
1386
1387 WinQueryWindowRect(HWND_DESKTOP, &rcl);
1388 rcl.yBottom += icz;
1389 rcl.yTop -= bsz;
1390 rcl.xLeft += bsz;
1391 rcl.xRight -= bsz;
1392 WinSetWindowPos(hwndFrame,
1393 HWND_TOP,
1394 rcl.xLeft,
1395 rcl.yBottom,
1396 rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom, fl);
1397 }
1398 if (fLogFile)
1399 LogFileHandle = _fsopen("FM2.LOG", "a+", SH_DENYWR);
1400 if (hwndHelp)
1401 WinAssociateHelpInstance(hwndHelp, hwndFrame);
1402 PostMsg(hwndClient, UM_SETUP, MPFROMLONG(argc), MPFROMP(argv));
1403 }
1404 return hwndFrame;
1405}
1406
1407#pragma alloc_text(PERSON11,MainFrameWndProc2,MainWndProc2)
1408#pragma alloc_text(PERSON12,StartFM32,MainWMOnce2)
1409#pragma alloc_text(PERSON13,MainWMCommand2)
Note: See TracBrowser for help on using the repository browser.