source: trunk/dll/datamin.c@ 1211

Last change on this file since 1211 was 1206, checked in by John Small, 17 years ago

Ticket 187: Move datadevlarations/definitions out of fm3dll.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: datamin.c 1206 2008-09-13 06:48:55Z jbs $
5
6 Minimized data bar
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2006 Steven H. Levine
10
11 14 Sep 02 SHL Handle large partitions
12 16 Oct 02 SHL Handle large partitions better
13 23 May 05 SHL Use QWL_USER
14 23 May 05 SHL Avoid delays for inaccessible drives
15 25 May 05 SHL Use ULONGLONG and CommaFmtULL
16 06 Jun 05 SHL Drop unused code
17 22 Jul 06 SHL Check more run time errors
18 02 Jan 07 GKY Changed drive information string formating to accomodate 6 char FS names
19 07 Jan 07 GKY Move error strings etc. to string file
20 30 Mar 07 GKY Remove GetPString for window class names
21 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
22 02 Sep 07 GKY Replaced DosQProcStatus with DosQuerySysState to fix trap in thunk code
23
24***********************************************************************/
25
26#include <string.h>
27#include <ctype.h>
28#include <limits.h>
29#include <process.h> // _beginthread
30
31#define INCL_DOS
32#define INCL_DOSERRORS
33#define INCL_WIN
34#define INCL_GPI
35#define INCL_LONGLONG
36
37#include "fm3dll.h"
38#include "info.h" // Data declaration(s)
39#include "notebook.h" // Data declaration(s)
40#include "inis.h" // Data declaration(s)
41#include "init.h" // Data declaration(s)
42#include "defview.h" // Data declaration(s)
43#include "fm3dlg.h"
44#include "fm3str.h"
45#include "procstat.h"
46#include "datamin.h"
47#include "errutil.h" // Dos_Error...
48#include "strutil.h" // GetPString
49#include "commafmt.h" // CommaFmtUL
50#include "killproc.h" // KillDlgProc
51#include "sysinfo.h" // SysInfoDlgProc
52#include "mainwnd.h" // TopWindowName
53#include "commafmt.h" // CommaFmtUL
54#include "common.h" // OpenDirCnr
55#include "shadow.h" // OpenObject
56#include "chklist.h" // PopupMenu
57#include "presparm.h" // SetPresParams
58#include "undel.h" // UndeleteDlgProc
59#include "misc.h" // GetCmdSpec
60#include "wrappers.h" // xDosFindFirst
61#include "systemf.h" // runemf2
62#include "fortify.h"
63
64APIRET16 APIENTRY16 Dos16MemAvail(PULONG pulAvailMem);
65
66static volatile HEV G_hevDataMin = NULLHANDLE;
67static volatile HWND G_hwndSingle = NULLHANDLE;
68
69static VOID dataminThread(VOID * pv);
70
71// Data definitions
72#pragma data_seg(GLOBAL1)
73HWND DataHwnd;
74BOOL fDataInclRemote;
75BOOL fDataShowDrives;
76BOOL fDataToFore;
77BOOL fDullMin;
78
79#pragma data_seg(DATA2)
80
81static PSZ pszSrcFile = __FILE__;
82
83long MINI_X = 208, MINI_Y = 16;
84
85//=== MiniTimeProc - time, swap and drive status mini windows procedure ===
86
87MRESULT EXPENTRY MiniTimeProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
88{
89 APIRET rc;
90
91 switch (msg) {
92 case WM_CREATE:
93 {
94 PVOID pv = xmalloc(sizeof(tDataMin), pszSrcFile, __LINE__);
95 if (pv)
96 WinSetWindowPtr(hwnd, QWL_DATAMIN_PTR, pv);
97 }
98 break;
99
100 case WM_BUTTON1CLICK:
101 {
102 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
103
104 if (id >= MINI_DRIVEA) {
105 if (G_hevDataMin != NULLHANDLE) {
106 G_hwndSingle = hwnd;
107 rc = DosPostEventSem(G_hevDataMin);
108 if (rc) {
109 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
110 GetPString(IDS_POSTSEMFAILED));
111 }
112 }
113 }
114 else if (id == MINI_TIME)
115 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_SETUP6, // Up time
116 MPVOID, MPVOID);
117 else if (id == MINI_PROC)
118 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
119 WM_SYSCOMMAND, MPFROM2SHORT(SC_TASKMANAGER, 0), MPVOID);
120 }
121 break;
122
123 case WM_BUTTON1DBLCLK:
124 {
125 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
126
127 if (id >= MINI_DRIVEA && !hwndMain) {
128 CHAR s[] = " :\\";
129
130 *s = (CHAR) (id - MINI_DRIVEA) + 'A';
131 OpenDirCnr((HWND) 0, HWND_DESKTOP, (HWND) 0, FALSE, s);
132 return MRFROMLONG(1L);
133 }
134 else if (id == MINI_TIME) {
135 OpenObject("<WP_CLOCK>",
136 (SHORT2FROMMP(mp2) & KC_SHIFT) ? Default : Settings, hwnd);
137 return MRFROMLONG(1L);
138 }
139
140#ifdef NEVER
141 else if (id == MINI_MEM) {
142 WinDlgBox(HWND_DESKTOP,
143 HWND_DESKTOP,
144 SysInfoDlgProc, FM3ModHandle, SYS_FRAME, NULL);
145 return MRFROMLONG(1L);
146 }
147#endif
148
149 else if (id == MINI_PROC || id == MINI_MEM) {
150 WinDlgBox(HWND_DESKTOP,
151 hwnd, KillDlgProc, FM3ModHandle, KILL_FRAME, NULL);
152 return MRFROMLONG(1L);
153 }
154 else if (id == MINI_SWAP && *SwapperDat) {
155
156 char s[5];
157
158 strncpy(s, SwapperDat, 4);
159 s[3] = 0;
160 WinDlgBox(HWND_DESKTOP,
161 hwndMain,
162 UndeleteDlgProc, FM3ModHandle, UNDEL_FRAME, MPFROMP(s));
163 return MRFROMLONG(1L);
164 }
165 }
166 break;
167
168 case WM_BUTTON1MOTIONSTART:
169 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
170 UM_BUTTON1MOTIONSTART, MPVOID, MPVOID);
171 break;
172
173 case WM_CONTEXTMENU:
174 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_CONTEXTMENU, MPVOID, MPVOID);
175 break;
176
177 case WM_PAINT:
178 {
179 MRESULT mr = 0;
180 USHORT id;
181
182 id = WinQueryWindowUShort(hwnd, QWS_ID);
183 if (id >= MINI_DRIVEA) {
184 HPS hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
185
186 if (hps) {
187 mr = WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
188 UM_PAINT, MPFROM2SHORT(id, 0), MPFROMLONG(hps));
189 WinEndPaint(hps);
190 return mr; // Bypass default paint
191 }
192 }
193 }
194 break;
195
196 case WM_DESTROY:
197 {
198 PVOID pv = WinQueryWindowPtr(hwnd, QWL_DATAMIN_PTR);
199
200 xfree(pv, pszSrcFile, __LINE__);
201 }
202 break;
203 }
204 return PFNWPStatic(hwnd, msg, mp1, mp2);
205
206} // MiniTimeProc
207
208//=== DataProc - databar client window procedure ===
209
210MRESULT EXPENTRY DataProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
211{
212 APIRET rc;
213
214 static ULONG counter;
215 static BOOL NoFloat, noqproc = FALSE, Positioned;
216 static HWND hwndMenu = (HWND) 0;
217
218 switch (msg) {
219 case WM_CREATE:
220 if (DataHwnd) {
221 WinSetWindowPos(DataHwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_SHOW);
222 return MRFROMLONG(1L);
223 }
224 DataHwnd = WinQueryWindow(hwnd, QW_PARENT);
225 NoFloat = FALSE;
226 Positioned = FALSE;
227 SetPresParams(hwnd,
228 &RGBGREY, &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVTEXT));
229 {
230 int c;
231 long x = 3;
232 USHORT ids[] = { MINI_TIME, MINI_MEM, MINI_SWAP, MINI_PROC, 0 };
233 POINTL aptl[TXTBOX_COUNT];
234 HPS hps;
235
236 hps = WinGetPS(hwnd);
237 if (hps) {
238 GpiQueryTextBox(hps,
239 34,
240 " -=03:08:22 SMW 1998/08/02=- ",
241 TXTBOX_COUNT, aptl);
242 WinReleasePS(hps);
243 MINI_X = aptl[TXTBOX_TOPRIGHT].x + 6;
244 MINI_Y = aptl[TXTBOX_TOPRIGHT].y + 6;
245 }
246 for (c = 0; ids[c]; c++) {
247 if (!WinCreateWindow(hwnd,
248 WC_MINITIME,
249 NullStr,
250 SS_TEXT | DT_CENTER | DT_VCENTER | WS_VISIBLE,
251 x,
252 3,
253 MINI_X,
254 MINI_Y, hwnd, HWND_TOP, ids[c], NULL, NULL)) {
255 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
256 }
257 x += (MINI_X + 4);
258 }
259 }
260 if (!hwndMain) {
261 SWCNTRL swctl;
262
263 memset(&swctl, 0, sizeof(swctl));
264 swctl.hwnd = WinQueryWindow(hwnd, QW_PARENT);
265 swctl.uchVisibility = SWL_VISIBLE;
266 swctl.fbJump = (fDataToFore) ? SWL_NOTJUMPABLE : SWL_JUMPABLE;
267 swctl.bProgType = PROG_PM;
268 strcpy(swctl.szSwtitle, GetPString(IDS_DATABARTITLETEXT));
269 WinCreateSwitchEntry(WinQueryAnchorBlock(hwnd), &swctl);
270 }
271 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
272 return 0;
273
274 case WM_MENUEND:
275 NoFloat = FALSE;
276 if (hwndMenu == (HWND) mp2) {
277 WinDestroyWindow(hwndMenu);
278 hwndMenu = (HWND) 0;
279 }
280 break;
281
282 case UM_RESTORE:
283 WinSetWindowPtr(hwnd, QWL_USER, mp1);
284 return 0;
285
286 case UM_SETUP:
287 {
288 long x, y;
289 SWP swp, swpD;
290 int c;
291 ULONG size = sizeof(SWP);
292 ULONG numdrives = 0;
293 ULONG drivestyle = (DRIVE_REMOVABLE | DRIVE_INVALID |
294 DRIVE_IGNORE | DRIVE_ZIPSTREAM | DRIVE_NOSTATS);
295 ULONG ulDriveNum, ulDriveMap;
296
297 if (!fDataInclRemote)
298 drivestyle |= DRIVE_REMOTE || DRIVE_VIRTUAL || DRIVE_RAMDISK;
299 if (fDataShowDrives) {
300 DosError(FERR_DISABLEHARDERR);
301 DosQCurDisk(&ulDriveNum, &ulDriveMap);
302 x = 3;
303 y = MINI_Y + 4;
304 // Drive status windows
305 for (c = 2; c < 26; c++) {
306 if ((ulDriveMap & (1L << c)) && !(driveflags[c] & drivestyle)) {
307 if (!WinCreateWindow(hwnd,
308 WC_MINITIME,
309 NullStr,
310 SS_TEXT | DT_CENTER | DT_VCENTER |
311 WS_VISIBLE, x, y, MINI_X, MINI_Y, hwnd,
312 HWND_TOP, MINI_DRIVEA + c, NULL, NULL)) {
313 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__,
314 IDS_WINCREATEWINDOW);
315 }
316 numdrives++;
317 x += (MINI_X + 4);
318 if ((numdrives % 4) == 0) {
319 y += (MINI_Y + 4);
320 x = 3;
321 }
322 }
323 }
324 }
325 x = (MINI_X * 4) + 18;
326 y = (MINI_Y + 4) + ((numdrives / 4) * (MINI_Y + 4)) +
327 (((numdrives % 4) != 0) * (MINI_Y + 4));
328 if (!Positioned) {
329 if (PrfQueryProfileData(fmprof, appname, "DataMinPos", &swp, &size)) {
330 WinQueryWindowPos(HWND_DESKTOP, &swpD);
331 if (swp.x > swpD.cx - 16)
332 swp.x = swpD.cx - 16;
333 if (swp.y > swpD.cy - 16)
334 swp.y = swpD.cy - 16;
335 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
336 HWND_TOP,
337 swp.x,
338 swp.y,
339 x, y, SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER);
340 }
341 else
342 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
343 HWND_TOP,
344 0,
345 0,
346 x, y, SWP_SHOW | SWP_SIZE | SWP_MOVE | SWP_ZORDER);
347 Positioned = TRUE;
348 }
349 else
350 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
351 HWND_TOP,
352 0, 0, x, y, SWP_SHOW | SWP_SIZE | SWP_ZORDER);
353 WinShowWindow(WinQueryWindow(hwnd, QW_PARENT), TRUE);
354 if (numdrives) {
355 if (_beginthread(dataminThread, NULL, 32768, (PVOID) hwnd) == -1) {
356 Runtime_Error(pszSrcFile, __LINE__,
357 GetPString(IDS_COULDNTSTARTTHREADTEXT));
358 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
359 }
360 }
361 counter = 0;
362 PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID);
363 }
364 return 0; // UM_SETUP
365
366 case WM_BUTTON1DBLCLK:
367 if (hwndMain)
368 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
369 break;
370
371 case UM_CONTEXTMENU:
372 case WM_CONTEXTMENU:
373 if (!hwndMenu)
374 hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, MINI_FRAME);
375 if (hwndMenu) {
376 WinCheckMenuItem(hwndMenu, MINI_FLOAT, fDataToFore);
377 WinCheckMenuItem(hwndMenu, MINI_SHOW, fDataShowDrives);
378 WinCheckMenuItem(hwndMenu, MINI_BORING, fDullMin);
379 WinCheckMenuItem(hwndMenu, MINI_INCLREMOTE, fDataInclRemote);
380 NoFloat = TRUE;
381 if (!PopupMenu(hwnd, hwnd, hwndMenu))
382 NoFloat = FALSE;
383 }
384 if (msg == UM_CONTEXTMENU)
385 return 0;
386 break;
387
388 case WM_BUTTON2DBLCLK:
389 if (!(SHORT2FROMMP(mp2) & KC_SHIFT)) {
390 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MINI_FLOAT, 0), MPVOID);
391 break;
392 }
393 /* else intentional fallthru */
394 case WM_CHORD:
395 case WM_BUTTON3DBLCLK:
396 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MINI_SHOW, 0), MPVOID);
397 break;
398
399 case UM_BUTTON1MOTIONSTART:
400 case WM_BUTTON1MOTIONSTART:
401 {
402 TRACKINFO TrackInfo;
403 SWP Position;
404
405 memset(&TrackInfo, 0, sizeof(TrackInfo));
406 TrackInfo.cxBorder = 1;
407 TrackInfo.cyBorder = 1;
408 TrackInfo.cxGrid = 1;
409 TrackInfo.cyGrid = 1;
410 TrackInfo.cxKeyboard = 8;
411 TrackInfo.cyKeyboard = 8;
412 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &Position);
413 TrackInfo.rclTrack.xLeft = Position.x;
414 TrackInfo.rclTrack.xRight = Position.x + Position.cx;
415 TrackInfo.rclTrack.yBottom = Position.y;
416 TrackInfo.rclTrack.yTop = Position.y + Position.cy;
417 WinQueryWindowPos(HWND_DESKTOP, &Position);
418 TrackInfo.rclBoundary.xLeft = Position.x;
419 TrackInfo.rclBoundary.xRight = Position.x + Position.cx;
420 TrackInfo.rclBoundary.yBottom = Position.y;
421 TrackInfo.rclBoundary.yTop = Position.y + Position.cy;
422 TrackInfo.ptlMinTrackSize.x = 0;
423 TrackInfo.ptlMinTrackSize.y = 0;
424 TrackInfo.ptlMaxTrackSize.x = Position.cx;
425 TrackInfo.ptlMaxTrackSize.y = Position.cy;
426 TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY;
427 if (WinTrackRect(HWND_DESKTOP, (HPS) 0, &TrackInfo)) {
428 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
429 HWND_TOP, TrackInfo.rclTrack.xLeft,
430 TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE);
431 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
432 }
433 }
434 break;
435
436 case WM_HELP:
437 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_HELP, 0), MPVOID);
438 break;
439
440 case WM_COMMAND:
441 switch (SHORT1FROMMP(mp1)) {
442 case IDM_COMMANDLINE:
443 case IDM_DOSCOMMANDLINE:
444 case IDM_WINFULLSCREEN:
445 {
446 CHAR *env = GetCmdSpec(FALSE), path[CCHMAXPATH];
447 INT type = SEPARATE | WINDOWED;
448
449 *path = 0;
450 TopWindowName(hwnd, (HWND) 0, path);
451 if (SHORT1FROMMP(mp1) == IDM_DOSCOMMANDLINE)
452 env = GetCmdSpec(TRUE);
453 else if (SHORT1FROMMP(mp1) != IDM_COMMANDLINE) {
454 env = "WINOS2.COM";
455 type = SEPARATE | FULLSCREEN;
456 }
457 runemf2(type, hwnd, pszSrcFile, __LINE__,
458 path, NULL, "%s", env);
459 }
460 break;
461
462 case IDM_HELP:
463 if (hwndHelp)
464 WinSendMsg(hwndHelp,
465 HM_DISPLAY_HELP,
466 MPFROM2SHORT(HELP_DATABAR, 0), MPFROMSHORT(HM_RESOURCEID));
467 break;
468
469 case MINI_CLOSE:
470 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
471 break;
472
473 case MINI_BORING:
474 fDullMin = (fDullMin) ? FALSE : TRUE;
475 PrfWriteProfileData(fmprof,
476 FM3Str, "DullDatabar", &fDullMin, sizeof(BOOL));
477 if (G_hevDataMin != NULLHANDLE) {
478 rc = DosPostEventSem(G_hevDataMin);
479 if (rc) {
480 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
481 GetPString(IDS_POSTSEMFAILED));
482 }
483 }
484
485 break;
486
487 case MINI_INCLREMOTE:
488 case MINI_SHOW:
489 if (SHORT1FROMMP(mp1) == MINI_SHOW) {
490 fDataShowDrives = (fDataShowDrives) ? FALSE : TRUE;
491 PrfWriteProfileData(fmprof,
492 appname,
493 "DataShowDrives", &fDataShowDrives, sizeof(BOOL));
494 }
495 else {
496 fDataInclRemote = (fDataInclRemote) ? FALSE : TRUE;
497 PrfWriteProfileData(fmprof,
498 appname,
499 "DataInclRemote", &fDataInclRemote, sizeof(BOOL));
500 }
501 {
502 HENUM henum;
503 HWND hwndChild;
504 USHORT id;
505
506 henum = WinBeginEnumWindows(hwnd);
507 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
508 id = WinQueryWindowUShort(hwndChild, QWS_ID);
509 if (id >= MINI_DRIVEA)
510 WinDestroyWindow(hwndChild);
511 }
512 WinEndEnumWindows(henum);
513 }
514 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
515 break;
516
517 case MINI_FLOAT:
518 fDataToFore = (fDataToFore) ? FALSE : TRUE;
519 PrfWriteProfileData(fmprof,
520 appname, "DataToFore", &fDataToFore, sizeof(BOOL));
521 if (!hwndMain) {
522
523 SWCNTRL swcntrl;
524 HSWITCH hswitch;
525
526 hswitch = (HSWITCH) WinQuerySwitchHandle(hwnd, (PID) 0);
527 if (hswitch) {
528 memset(&swcntrl, 0, sizeof(SWCNTRL));
529 if (!WinQuerySwitchEntry(hswitch, &swcntrl)) {
530 swcntrl.fbJump = (fDataToFore) ? SWL_NOTJUMPABLE : SWL_JUMPABLE;
531 WinChangeSwitchEntry(hswitch, &swcntrl);
532 }
533 }
534 }
535 break;
536 }
537 return 0;
538
539 case WM_SIZE:
540 WinSetWindowPos(hwnd,
541 HWND_TOP,
542 0,
543 0,
544 SHORT1FROMMP(mp2),
545 SHORT2FROMMP(mp2), SWP_MOVE | SWP_SIZE);
546 break;
547
548 case WM_PAINT:
549 {
550 HPS hps;
551 POINTL ptl;
552 SWP swp;
553 RECTL rcl;
554
555 hps = WinBeginPaint(hwnd, (HPS) 0, &rcl);
556 if (hps) {
557 WinFillRect(hps, (PRECTL) & rcl, CLR_PALEGRAY);
558 GpiSetMix(hps, FM_OVERPAINT);
559 GpiSetColor(hps, CLR_WHITE);
560 WinQueryWindowPos(hwnd, &swp);
561 ptl.x = 0;
562 ptl.y = 0;
563 GpiMove(hps, &ptl);
564 ptl.y = swp.cy - 1;
565 GpiLine(hps, &ptl);
566 ptl.x = swp.cx - 1;
567 GpiLine(hps, &ptl);
568 GpiSetColor(hps, CLR_DARKGRAY);
569 ptl.y = 0;
570 GpiLine(hps, &ptl);
571 ptl.x = 0;
572 GpiLine(hps, &ptl);
573 {
574 HENUM henum;
575 HWND hwndTemp;
576
577 henum = WinBeginEnumWindows(hwnd);
578 while ((hwndTemp = WinGetNextWindow(henum)) != NULLHANDLE) {
579 PaintRecessedWindow(hwndTemp,
580 hps, (WinQueryWindowUShort(hwndTemp, QWS_ID)
581 != MINI_TIME), FALSE);
582 }
583 WinEndEnumWindows(henum);
584 }
585 WinEndPaint(hps);
586 }
587 }
588 return 0;
589
590 case UM_PAINT:
591 {
592 CHAR s[90];
593 CHAR szFreeQty[38];
594 CHAR szDrvLtr[] = " :";
595 CHAR *pszFSystem;
596 ULONGLONG ullFreeQty;
597 ULONG ulPercentFree;
598 ULONG wasx;
599 HPS hps = (HPS) mp2;
600 HWND hwndChild;
601 USHORT id;
602 SWP swp;
603 POINTL ptl;
604 tDataMin *pDM;
605
606 id = SHORT1FROMMP(mp1);
607 if (id >= MINI_DRIVEA) {
608 hwndChild = WinWindowFromID(hwnd, id);
609 if (!hwndChild)
610 return 0;
611 if (!WinQueryWindowPos(hwndChild, &swp))
612 return 0;
613 pDM = WinQueryWindowPtr(hwndChild, QWL_DATAMIN_PTR);
614 if (!pDM || pDM->qfsi_rc) {
615 ullFreeQty = 0;
616 ulPercentFree = 0;
617 }
618 else {
619 ullFreeQty = (ULONGLONG) pDM->fsa.cUnitAvail *
620 (pDM->fsa.cSectorUnit * pDM->fsa.cbSector);
621
622 ulPercentFree = (pDM->fsa.cUnit && pDM->fsa.cUnitAvail) ?
623 (pDM->fsa.cUnitAvail * 100) / pDM->fsa.cUnit : 0;
624 }
625
626 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
627 *szDrvLtr = (CHAR) (id - MINI_DRIVEA) + 'A';
628
629 if (!pDM || pDM->qfsi_rc || pDM->qfsa_rc)
630 pszFSystem = "N/A";
631 else {
632 pszFSystem = (PCHAR)(pDM->fsqb2.szName) + pDM->fsqb2.cbName + 1;
633 pszFSystem[15] = 0;
634 }
635 sprintf(s,
636 "%s %13s %lu%%-%s %6s ",
637 szDrvLtr,
638 szFreeQty,
639 ulPercentFree, GetPString(IDS_FREETEXT), pszFSystem);
640 if (!hps)
641 hps = WinGetPS(hwndChild);
642 if (hps) {
643 if (!fDullMin) {
644 ptl.x = 0;
645 ptl.y = 0;
646 GpiMove(hps, &ptl);
647 GpiSetColor(hps, CLR_BLACK);
648 ptl.x = swp.cx - 1;
649 ptl.y = swp.cy - 1;
650 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
651 ptl.x = 1;
652 ptl.y = 1;
653 if (ulPercentFree) {
654 GpiMove(hps, &ptl);
655 GpiSetColor(hps,
656 (ulPercentFree < 11) ? CLR_DARKRED :
657 (ulPercentFree < 26) ? CLR_DARKBLUE :
658 CLR_DARKGREEN);
659 ptl.y = swp.cy - 2;
660 ptl.x = ((swp.cx - 2) * ulPercentFree) / 100;
661 wasx = ptl.x;
662 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
663 GpiSetColor(hps,
664 (ulPercentFree < 11) ? CLR_RED :
665 (ulPercentFree < 26) ? CLR_BLUE : CLR_GREEN);
666 ptl.x = wasx;
667 ptl.y = swp.cy - 2;
668 GpiMove(hps, &ptl);
669 ptl.x = 1;
670 GpiLine(hps, &ptl);
671 ptl.y = 2;
672 ptl.x = 1;
673 GpiLine(hps, &ptl);
674 ptl.x = wasx;
675 }
676 if (ulPercentFree < 99) {
677 GpiSetColor(hps, CLR_DARKGRAY);
678 wasx = ptl.x;
679 ptl.y = 2;
680 GpiMove(hps, &ptl);
681 ptl.y = swp.cy - 2;
682 ptl.x = swp.cx - 2;
683 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
684 ptl.x = wasx;
685 GpiMove(hps, &ptl);
686 GpiSetColor(hps, CLR_PALEGRAY);
687 ptl.x = swp.cx - 3;
688 GpiLine(hps, &ptl);
689 ptl.x = wasx;
690 ptl.y = 1;
691 GpiMove(hps, &ptl);
692 GpiSetColor(hps, CLR_BLACK);
693 ptl.x = swp.cx - 2;
694 GpiLine(hps, &ptl);
695 ptl.y = swp.cy - 3;
696 GpiLine(hps, &ptl);
697 }
698 GpiSetColor(hps, CLR_WHITE);
699 }
700 else {
701 GpiSetColor(hps, CLR_PALEGRAY);
702 ptl.x = 0;
703 ptl.y = 0;
704 GpiMove(hps, &ptl);
705 ptl.x = swp.cx - 1;
706 ptl.y = swp.cy - 1;
707 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
708 GpiSetColor(hps,
709 (ulPercentFree < 11) ? CLR_DARKRED : CLR_DARKBLUE);
710 }
711 GpiSetBackMix(hps, BM_LEAVEALONE);
712 GpiSetMix(hps, FM_OVERPAINT);
713 {
714 POINTL aptl[TXTBOX_COUNT];
715
716 GpiQueryTextBox(hps, strlen(s), s, TXTBOX_COUNT, aptl);
717 ptl.y = ((swp.cy / 2) -
718 ((aptl[TXTBOX_TOPRIGHT].y +
719 aptl[TXTBOX_BOTTOMLEFT].y) / 2));
720 ptl.y++;
721 ptl.x = (swp.cx / 2) - (aptl[TXTBOX_TOPRIGHT].x / 2);
722 if (ptl.x < 2)
723 ptl.x = 2;
724 GpiCharStringAt(hps, &ptl, strlen(s), s);
725 }
726 if (!mp2)
727 WinReleasePS(hps);
728 }
729 } // if drive window
730 }
731 return 0;
732
733 case UM_TIMER:
734 {
735 CHAR s[134];
736 DATETIME dt;
737
738 if (fDataToFore && !NoFloat)
739 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
740 HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
741 if (counter && (counter % 19) && (counter % 20)) {
742 if (!DosGetDateTime(&dt)) {
743 sprintf(s,
744 " %02hu:%02hu:%02hu %s %04u/%02u/%02u",
745 dt.hours,
746 dt.minutes,
747 dt.seconds,
748 GetPString(IDS_SUNDAY + dt.weekday),
749 dt.year, dt.month, dt.day);
750 WinSetDlgItemText(hwnd, MINI_TIME, s);
751 }
752 }
753 else if (!counter || !(counter % 19))
754 PostMsg(hwnd, UM_SETUP6, MPVOID, MPVOID); // Uptime
755 if (!(counter % 4)) {
756 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID); // Memory utilization
757 if (!(counter % 10)) {
758 PostMsg(hwnd, UM_SETUP5, MPVOID, MPVOID); // Process status
759 if (!(counter % 20)) {
760 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID); // Swapper
761 }
762 }
763 }
764 }
765 counter++;
766 return 0;
767
768 case UM_SETUP2:
769 {
770 CHAR s[134], szFileQty[38], szFreeQty[38];
771 FILEFINDBUF3L ffb;
772 ULONG nm = 1;
773 ULONGLONG ullFreeQty;
774 HDIR hdir = HDIR_CREATE;
775 FSALLOCATE fsa;
776
777 if (*SwapperDat) {
778 DosError(FERR_DISABLEHARDERR);
779 if (!xDosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_HIDDEN |
780 FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY,
781 &ffb, sizeof(ffb), &nm, FIL_STANDARDL)) {
782 priority_bumped();
783 DosFindClose(hdir);
784 DosError(FERR_DISABLEHARDERR);
785 if (!DosQueryFSInfo(toupper(*SwapperDat) - '@', FSIL_ALLOC,
786 &fsa, sizeof(FSALLOCATE))) {
787 ullFreeQty =
788 (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
789 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
790 }
791 else
792 *szFreeQty = 0;
793
794 CommaFmtULL(szFileQty, sizeof(szFileQty), ffb.cbFile, ' ');
795 sprintf(s, " %s %s%s%s",
796 GetPString(IDS_SWAPTITLETEXT),
797 szFileQty, *szFreeQty ? "/" : NullStr, szFreeQty);
798 WinSetDlgItemText(hwnd, MINI_SWAP, s);
799 }
800 }
801 }
802 return 0;
803
804 case UM_SETUP3: // Memory utilization
805 {
806 CHAR s[134], tm[38], szQty[38];
807 ULONG amem = 0;
808
809 if (!DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM,
810 (PVOID) & amem, (ULONG) sizeof(amem))) {
811 CommaFmtUL(tm, sizeof(tm), amem, 'M');
812 if (!Dos16MemAvail(&amem))
813 CommaFmtUL(szQty, sizeof(szQty), amem, 'M');
814 else
815 *szQty = 0;
816 sprintf(s, " %s%s%s%s",
817 GetPString(IDS_MEMTITLETEXT),
818 szQty, (*szQty) ? "/" : NullStr, tm);
819 WinSetDlgItemText(hwnd, MINI_MEM, s);
820 }
821 }
822 return 0;
823
824 case UM_SETUP5: // Process status
825 {
826 CHAR s[134], tm[38], szQty[38];
827
828 if (fUseQProcStat && !noqproc) {
829
830 PROCESSINFO *ppi;
831 BUFFHEADER *pbh = NULL;
832 MODINFO *pmi;
833 ULONG numprocs = 0, numthreads = 0;
834 APIRET rc;
835
836 rc = DosAllocMem((PVOID)&pbh, USHRT_MAX + 4096,
837 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
838 if (rc)
839 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
840 GetPString(IDS_OUTOFMEMORY));
841 else {
842 if (DosQProcStatus((ULONG *)pbh, USHRT_MAX))
843 noqproc = TRUE;
844 else {
845 ppi = pbh->ppi;
846 while (ppi->ulEndIndicator != PROCESS_END_INDICATOR) {
847 pmi = pbh->pmi;
848 while (pmi && ppi->hModRef != pmi->hMod)
849 pmi = pmi->pNext;
850 if (pmi) {
851 numprocs++;
852 numthreads += ppi->usThreadCount;
853 }
854 ppi = (PPROCESSINFO) (ppi->ptiFirst + ppi->usThreadCount);
855 }
856 commafmt(szQty, sizeof(szQty), numprocs);
857 commafmt(tm, sizeof(tm), numthreads);
858 sprintf(s,
859 " %s%s %s%s",
860 GetPString(IDS_PROCSTITLETEXT),
861 szQty, GetPString(IDS_THRDSTITLETEXT), tm);
862 WinSetDlgItemText(hwnd, MINI_PROC, s);
863 }
864 DosFreeMem(pbh);
865 }
866 }
867 else if (fUseQSysState && !noqproc) {
868
869 QSPREC *ppi;
870 QSPTRREC *pbh = NULL;
871 QSLREC *pmi;
872 ULONG numprocs = 0, numthreads = 0;
873 APIRET rc;
874
875 rc = DosAllocMem((PVOID) & pbh, USHRT_MAX + 4096,
876 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
877 if (rc)
878 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
879 GetPString(IDS_OUTOFMEMORY));
880 else { //2 Sep 07 GKY 0x05 = process & Mod data only
881 if (DosQuerySysState(QS_PROCESS | QS_MTE, 0, 0, 0, pbh, USHRT_MAX))
882 noqproc = TRUE;
883 else {
884 ppi = pbh->pProcRec;
885 while (ppi->RecType == 1) {
886 pmi = pbh->pLibRec;
887 while (pmi && ppi->hMte != pmi->hmte)
888 pmi = pmi->pNextRec;
889 if (pmi) {
890 numprocs++;
891 numthreads += ppi->cTCB;
892 }
893 ppi = (QSPREC *) (ppi->pThrdRec + ppi->cTCB);
894 }
895 commafmt(szQty, sizeof(szQty), numprocs);
896 commafmt(tm, sizeof(tm), numthreads);
897 sprintf(s,
898 " %s%s %s%s",
899 GetPString(IDS_PROCSTITLETEXT),
900 szQty, GetPString(IDS_THRDSTITLETEXT), tm);
901 WinSetDlgItemText(hwnd, MINI_PROC, s);
902 }
903 DosFreeMem(pbh);
904 }
905 }
906 else {
907 commafmt(szQty, sizeof(szQty),
908 WinQuerySwitchList(WinQueryAnchorBlock(hwnd), (PSWBLOCK) 0,
909 0));
910 sprintf(s, " %s%s", GetPString(IDS_TASKSTITLETEXT), szQty);
911 WinSetDlgItemText(hwnd, MINI_PROC, s);
912 }
913 }
914 return 0;
915
916 case UM_SETUP6: // Uptime
917 {
918 ULONG val = 0, numdays, nummins;
919 CHAR s[128];
920
921 if (!DosQuerySysInfo(QSV_MS_COUNT,
922 QSV_MS_COUNT,
923 (PVOID) & val, (ULONG) sizeof(val))) {
924 val /= 60000L;
925 numdays = val / (60L * 24L);
926 strcpy(s, GetPString(IDS_ELAPSEDTITLETEXT));
927 if (numdays)
928 sprintf(s + strlen(s),
929 " %lu %s%s, ",
930 numdays, GetPString(IDS_DAYTEXT), &"s"[numdays == 1L]);
931 nummins = val % (60L * 24L);
932 sprintf(s + strlen(s), " %lu:%02lu", nummins / 60, nummins % 60);
933 WinSetDlgItemText(hwnd, MINI_TIME, s);
934 }
935 }
936 return 0;
937
938 case WM_SAVEAPPLICATION:
939 {
940 SWP swp;
941
942 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
943 PrfWriteProfileData(fmprof, appname, "DataMinPos", &swp, sizeof(SWP));
944 }
945 break;
946
947 case WM_CLOSE:
948 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
949 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
950 return 0;
951
952 case WM_DESTROY:
953 if (DataHwnd == WinQueryWindow(hwnd, QW_PARENT)) {
954 DataHwnd = (HWND) 0;
955 if (hwndMenu)
956 WinDestroyWindow(hwndMenu);
957 hwndMenu = (HWND) 0;
958 }
959 if (hwndMain) {
960
961 SWP swp;
962 ULONG fl = SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE, ofl;
963
964 ofl = WinQueryWindowULong(hwnd, QWL_USER);
965 WinQueryWindowPos(WinQueryWindow(hwndMain, QW_PARENT), &swp);
966 if (swp.fl & SWP_MINIMIZE)
967 fl |= ((ofl & SWP_MAXIMIZE) ? SWP_MAXIMIZE : SWP_RESTORE);
968 WinSetWindowPos(WinQueryWindow(hwndMain, QW_PARENT),
969 HWND_TOP, 0, 0, 0, 0, fl);
970 }
971 else if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
972 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
973 break;
974 }
975 return WinDefWindowProc(hwnd, msg, mp1, mp2);
976
977} // DataProc
978
979//=== CreateDataBar - create databar windows ===
980
981HWND CreateDataBar(HWND hwndParent, ULONG fl)
982{
983 HWND hwndClient = (HWND) 0;
984 ULONG FrameFlags = 0;
985
986 if (WinCreateStdWindow(hwndParent,
987 WS_VISIBLE,
988 &FrameFlags,
989 WC_DATABAR,
990 NULL, WS_VISIBLE, 0, MINI_FRAME, &hwndClient)) {
991 WinSendMsg(hwndClient, UM_RESTORE, MPFROMLONG(fl), MPVOID);
992 }
993 return hwndClient;
994
995} // CreateDataBar
996
997//=== dataminThread - drive status thread ===
998
999static VOID dataminThread(VOID * pv)
1000{
1001 HAB hab = NULLHANDLE;
1002 HMQ hmq = NULLHANDLE;
1003 HWND hwndParent = (HWND) pv;
1004 HWND hwnd;
1005 HENUM henum;
1006 BOOL busy = TRUE;
1007 APIRET rc;
1008 USHORT id;
1009
1010# ifdef FORTIFY
1011 Fortify_EnterScope();
1012# endif
1013 if (G_hevDataMin == NULLHANDLE) {
1014 // Create just once for any thread that might use it
1015 // Kernel will clean up on exit
1016 rc = DosCreateEventSem(NULL, (PHEV) & G_hevDataMin, 0L, FALSE);
1017 if (rc) {
1018 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1019 GetPString(IDS_CREATESEMFAILED));
1020 busy = FALSE;
1021 }
1022 }
1023
1024 // fixme to report errors
1025 hab = WinInitialize(0);
1026 if (hab == NULLHANDLE)
1027 busy = FALSE;
1028 else {
1029 hmq = WinCreateMsgQueue(hab, 0);
1030 if (hmq == NULLHANDLE)
1031 busy = FALSE;
1032 else
1033 WinCancelShutdown(hmq, TRUE);
1034 }
1035
1036 while (busy) {
1037 HWND hwndSingle = G_hwndSingle;
1038
1039 G_hwndSingle = NULLHANDLE;
1040
1041 busy = FALSE;
1042
1043 if (!WinIsWindow(hab, hwndParent))
1044 break;
1045
1046 henum = WinBeginEnumWindows(hwndParent);
1047 while (henum && (hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
1048 if (!WinIsWindow(hab, hwnd))
1049 continue;
1050 if (hwndSingle && hwndSingle != hwnd)
1051 continue;
1052 id = WinQueryWindowUShort(hwnd, QWS_ID);
1053 if (id > MINI_DRIVEA) {
1054 ULONG dskNum = id - MINI_DRIVEA + 1;
1055 tDataMin *pDM = WinQueryWindowPtr(hwnd, QWL_DATAMIN_PTR);
1056 SWP swp;
1057 CHAR szPath[] = " :";
1058
1059 if (!pDM)
1060 continue;
1061 busy = TRUE;
1062 if (!WinQueryWindowPos(hwnd, &swp))
1063 continue;
1064
1065 DosError(FERR_DISABLEHARDERR);
1066 pDM->qfsi_rc = DosQueryFSInfo(dskNum,
1067 FSIL_ALLOC,
1068 &pDM->fsa, sizeof(FSALLOCATE));
1069
1070 if (!pDM->qfsi_rc) {
1071 *szPath = (CHAR) dskNum + 'A' - 1;
1072 pDM->qfsa_cb = sizeof(FSQBUFFER2) + 256; // se tDataMin
1073 DosError(FERR_DISABLEHARDERR);
1074 pDM->qfsa_rc = DosQueryFSAttach(szPath, 0, /* Ordinal */
1075 FSAIL_QUERYNAME,
1076 &pDM->fsqb2, &pDM->qfsa_cb);
1077 }
1078 WinInvalidateRect(hwnd, NULL, FALSE);
1079 } // if drive window
1080 } // while henum
1081 WinEndEnumWindows(henum);
1082
1083 if (busy) {
1084 ULONG clPosted;
1085
1086 rc = DosWaitEventSem(G_hevDataMin, 20000L);
1087 if (rc && rc != ERROR_TIMEOUT) {
1088 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1089 GetPString(IDS_POSTSEMFAILED));
1090 }
1091
1092 rc = DosResetEventSem(G_hevDataMin, &clPosted);
1093 if (rc && rc != ERROR_ALREADY_RESET) {
1094 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1095 GetPString(IDS_POSTSEMFAILED));
1096 }
1097 }
1098
1099 } // while
1100
1101 if (hmq != NULLHANDLE)
1102 WinDestroyMsgQueue(hmq);
1103
1104 if (hab != NULLHANDLE)
1105 WinTerminate(hab);
1106# ifdef FORTIFY
1107 Fortify_LeaveScope();
1108# endif
1109} // dataminThread
1110
1111#pragma alloc_text(DATAMIN,DataDlgProc,MiniTimeProc)
Note: See TracBrowser for help on using the repository browser.