source: trunk/dll/datamin.c@ 552

Last change on this file since 552 was 552, checked in by Gregg Young, 19 years ago

font cleanup; new image and archiver masks; messages moved to string file; new drive flags including David's icons mostly working

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