[356] | 1 | /***********************************************************************
|
---|
| 2 |
|
---|
| 3 | $Id: notify.c 1654 2012-01-08 18:16:08Z gyoung $
|
---|
| 4 |
|
---|
[1444] | 5 | Thread notes window and popup notifications over status line
|
---|
[356] | 6 |
|
---|
| 7 | Copyright (c) 1993-98 M. Kimes
|
---|
[1498] | 8 | Copyright (c) 2006, 2010 Steven H.Levine
|
---|
[356] | 9 |
|
---|
| 10 | 17 Jul 06 SHL Use Win_Error
|
---|
| 11 | 22 Jul 06 SHL Check more run time errors
|
---|
[593] | 12 | 30 Mar 07 GKY Remove GetPString for window class names
|
---|
[775] | 13 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
|
---|
[793] | 14 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[1002] | 15 | 16 Apr 08 SHL Comment and clean up logic
|
---|
[1335] | 16 | 10 Dec 08 SHL Integrate exception handler support
|
---|
[1391] | 17 | 11 Jan 09 GKY Replace font names in the string file with global set at compile in init.c
|
---|
[1395] | 18 | 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
|
---|
| 19 | 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
|
---|
[1444] | 20 | 13 Jul 09 SHL Sync with renames
|
---|
| 21 | 16 Jul 09 SHL Stop leaking hptrIcon
|
---|
[1654] | 22 | 17 Jan 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
|
---|
| 23 | 08 Jan 12 GKY Add support for changing PresParams in the notify status window
|
---|
[356] | 24 |
|
---|
| 25 | ***********************************************************************/
|
---|
| 26 |
|
---|
[2] | 27 | #include <stdlib.h>
|
---|
| 28 | #include <string.h>
|
---|
| 29 | #include <ctype.h>
|
---|
[1455] | 30 | #include <stddef.h> // _threadid
|
---|
[356] | 31 |
|
---|
[907] | 32 | #define INCL_DOS
|
---|
| 33 | #define INCL_WIN
|
---|
| 34 | #define INCL_GPI
|
---|
[1455] | 35 | #define INCL_LONGLONG // dircnrs.h
|
---|
[907] | 36 |
|
---|
[1211] | 37 | #include "fm3dll.h"
|
---|
[1225] | 38 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
[1211] | 39 | #include "collect.h" // Data declaration(s)
|
---|
| 40 | #include "grep.h" // Data declaration(s)
|
---|
| 41 | #include "notebook.h" // Data declaration(s)
|
---|
| 42 | #include "init.h" // Data declaration(s)
|
---|
[2] | 43 | #include "fm3dlg.h"
|
---|
| 44 | #include "fm3str.h"
|
---|
[1455] | 45 | #include "errutil.h" // Dos_Error...
|
---|
| 46 | #include "strutil.h" // GetPString
|
---|
[1163] | 47 | #include "notify.h"
|
---|
[1188] | 48 | #include "presparm.h" // SetPresParams
|
---|
[1211] | 49 | #include "mainwnd.h" // Data declaration(s)
|
---|
[1188] | 50 | #include "wrappers.h" // xmalloc
|
---|
| 51 | #include "misc.h" // PostMsg
|
---|
[1038] | 52 | #include "fortify.h"
|
---|
[1335] | 53 | #include "excputil.h" // xbeginthread
|
---|
[2] | 54 |
|
---|
| 55 | #pragma data_seg(DATA1)
|
---|
[356] | 56 |
|
---|
[1211] | 57 | // Data definitions
|
---|
[356] | 58 | static PSZ pszSrcFile = __FILE__;
|
---|
[1455] | 59 | static volatile HWND hwndNotify; // 16 Apr 08 SHL
|
---|
[1444] | 60 | static volatile PCSZ pszCachedNote; // 16 Jul 09 SHL
|
---|
[2] | 61 |
|
---|
[1211] | 62 | #pragma data_seg(GLOBAL1)
|
---|
| 63 | BOOL fThreadNotes;
|
---|
| 64 |
|
---|
[1444] | 65 | static VOID StartNotes(PCSZ pszNote);
|
---|
[1163] | 66 |
|
---|
[1002] | 67 | /**
|
---|
[1444] | 68 | * Notification message window procedure
|
---|
| 69 | * Displays timed message over status line
|
---|
[1002] | 70 | */
|
---|
| 71 |
|
---|
[551] | 72 | MRESULT EXPENTRY NotifyWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[356] | 73 | {
|
---|
[2] | 74 | static ULONG showing = 0;
|
---|
| 75 |
|
---|
[551] | 76 | switch (msg) {
|
---|
| 77 | case WM_CREATE:
|
---|
| 78 | showing++;
|
---|
| 79 | {
|
---|
[1002] | 80 | MRESULT rc = PFNWPStatic(hwnd, msg, mp1, mp2);
|
---|
[2] | 81 |
|
---|
[1444] | 82 | if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NOTIFY_TIMER, 5000)) {
|
---|
[1335] | 83 | Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinStartTimer");
|
---|
| 84 | WinDestroyWindow(hwnd);
|
---|
[551] | 85 | }
|
---|
| 86 | else {
|
---|
[1335] | 87 | if (hwndMain) {
|
---|
| 88 | if (hwndStatus)
|
---|
| 89 | WinShowWindow(hwndStatus, FALSE);
|
---|
| 90 | if (hwndStatus2)
|
---|
| 91 | WinShowWindow(hwndStatus2, FALSE);
|
---|
| 92 | }
|
---|
| 93 | PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
|
---|
[2] | 94 | }
|
---|
[551] | 95 | return rc;
|
---|
| 96 | }
|
---|
[2] | 97 |
|
---|
[551] | 98 | case UM_SETUP:
|
---|
| 99 | WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_SHOW);
|
---|
| 100 | WinInvalidateRect(hwnd, NULL, FALSE);
|
---|
[1654] | 101 | RestorePresParams(hwnd, PCSZ_NOTIFYWND);
|
---|
[551] | 102 | return 0;
|
---|
[2] | 103 |
|
---|
[551] | 104 | case WM_SETFOCUS:
|
---|
| 105 | if (mp2)
|
---|
| 106 | PostMsg(hwnd, UM_REPLACEFOCUS, mp1, MPVOID);
|
---|
| 107 | break;
|
---|
[2] | 108 |
|
---|
[551] | 109 | case UM_REPLACEFOCUS:
|
---|
| 110 | if (mp1)
|
---|
| 111 | WinSetFocus(HWND_DESKTOP, (HWND) mp1);
|
---|
| 112 | PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
|
---|
| 113 | return 0;
|
---|
[2] | 114 |
|
---|
[1654] | 115 | case WM_PRESPARAMCHANGED:
|
---|
| 116 | PresParamChanged(hwnd, PCSZ_NOTIFYWND, mp1, mp2);
|
---|
| 117 | break;
|
---|
| 118 |
|
---|
[551] | 119 | case WM_PAINT:
|
---|
| 120 | {
|
---|
| 121 | SWP swp;
|
---|
| 122 | POINTL ptl;
|
---|
[2] | 123 |
|
---|
[1002] | 124 | MRESULT mr = PFNWPStatic(hwnd, msg, mp1, mp2);
|
---|
| 125 | HPS hps = WinGetPS(hwnd);
|
---|
[551] | 126 | if (hps) {
|
---|
[1335] | 127 | if (WinQueryWindowPos(hwnd, &swp)) {
|
---|
| 128 | ptl.x = 0;
|
---|
| 129 | ptl.y = 0;
|
---|
| 130 | GpiMove(hps, &ptl);
|
---|
| 131 | GpiSetColor(hps, CLR_RED);
|
---|
| 132 | ptl.x = swp.cx - 1;
|
---|
| 133 | ptl.y = swp.cy - 1;
|
---|
| 134 | GpiBox(hps, DRO_OUTLINE, &ptl, 2, 2);
|
---|
| 135 | }
|
---|
| 136 | WinReleasePS(hwnd);
|
---|
[2] | 137 | }
|
---|
[551] | 138 | return mr;
|
---|
| 139 | }
|
---|
[2] | 140 |
|
---|
[551] | 141 | case WM_BUTTON1DOWN:
|
---|
| 142 | case WM_BUTTON2DOWN:
|
---|
| 143 | case WM_BUTTON3DOWN:
|
---|
| 144 | case WM_TIMER:
|
---|
| 145 | case WM_CLOSE:
|
---|
[1444] | 146 | WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NOTIFY_TIMER);
|
---|
[551] | 147 | WinDestroyWindow(hwnd);
|
---|
| 148 | return 0;
|
---|
[2] | 149 |
|
---|
[551] | 150 | case WM_DESTROY:
|
---|
| 151 | showing--;
|
---|
| 152 | if (!showing && hwndMain) {
|
---|
| 153 | if (hwndStatus)
|
---|
[1335] | 154 | WinShowWindow(hwndStatus, TRUE);
|
---|
[551] | 155 | if (hwndStatus2)
|
---|
[1335] | 156 | WinShowWindow(hwndStatus2, TRUE);
|
---|
[551] | 157 | }
|
---|
| 158 | break;
|
---|
[2] | 159 | }
|
---|
[551] | 160 | return PFNWPStatic(hwnd, msg, mp1, mp2);
|
---|
[2] | 161 | }
|
---|
| 162 |
|
---|
[1002] | 163 | /**
|
---|
[1444] | 164 | * Process UM_NOTIFY message to display timed message over status line
|
---|
[1002] | 165 | */
|
---|
| 166 |
|
---|
[1394] | 167 | HWND DoNotify(PCSZ str)
|
---|
[356] | 168 | {
|
---|
[551] | 169 | char *p;
|
---|
[1455] | 170 | HWND hwnd = (HWND)0, hwndP;
|
---|
[551] | 171 | LONG x, y, cx, cy;
|
---|
| 172 | SWP swp, swpS, swpS2;
|
---|
[2] | 173 | static USHORT id = NOTE_FRAME;
|
---|
| 174 |
|
---|
[551] | 175 | if (str && *str) {
|
---|
[1002] | 176 | // figure out what size the window should be and where it should be
|
---|
| 177 | hwndP = hwndMain ? WinQueryWindow(hwndMain, QW_PARENT) : HWND_DESKTOP;
|
---|
[551] | 178 | WinQueryWindowPos(hwndP, &swp);
|
---|
| 179 | if (hwndStatus)
|
---|
| 180 | WinQueryWindowPos(hwndStatus, &swpS);
|
---|
| 181 | if (hwndStatus2)
|
---|
| 182 | WinQueryWindowPos(hwndStatus2, &swpS2);
|
---|
[1002] | 183 | x = hwndMain ? (hwndStatus ? swpS.x - 1 :
|
---|
[1335] | 184 | WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER)) : 0;
|
---|
[1002] | 185 | y = hwndMain ? (hwndStatus ? swpS.y - 1 :
|
---|
[1335] | 186 | WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER)) : 0;
|
---|
[551] | 187 | if (hwndMain && hwndStatus) {
|
---|
| 188 | if (hwndStatus2)
|
---|
[1335] | 189 | cx = swpS2.cx + swpS.cx + 8;
|
---|
[2] | 190 | else
|
---|
[1335] | 191 | cx = swpS.cx + 6;
|
---|
[2] | 192 | }
|
---|
| 193 | else
|
---|
| 194 | cx = (swp.cx - ((x * 2) + 4));
|
---|
[1002] | 195 | cy = hwndMain ? (hwndStatus ? swpS.cy + 2 : 28) : 28;
|
---|
[2] | 196 |
|
---|
[1002] | 197 | // pretty-up the note by putting on a leading space
|
---|
[551] | 198 | if (*str != ' ') {
|
---|
| 199 | p = xmalloc(strlen(str) + 2, pszSrcFile, __LINE__);
|
---|
| 200 | if (!p)
|
---|
[1394] | 201 | p = (PSZ)str;
|
---|
[2] | 202 | else {
|
---|
[1335] | 203 | strcpy(p + 1, str);
|
---|
| 204 | *p = ' ';
|
---|
[2] | 205 | }
|
---|
| 206 | }
|
---|
| 207 | else
|
---|
[1394] | 208 | p = (PSZ)str;
|
---|
[2] | 209 |
|
---|
| 210 | hwnd = WinCreateWindow(hwndP,
|
---|
[1498] | 211 | (CHAR *) WC_ERRORWND,
|
---|
[1335] | 212 | p,
|
---|
| 213 | SS_TEXT | DT_LEFT | DT_VCENTER | WS_VISIBLE,
|
---|
| 214 | x, y, cx, cy, hwndP, HWND_TOP, id++, NULL, NULL);
|
---|
[1444] | 215 | if (!hwnd)
|
---|
[1395] | 216 | Win_Error(hwndP, hwndP, pszSrcFile, __LINE__,
|
---|
[1455] | 217 | PCSZ_WINCREATEWINDOW);
|
---|
[377] | 218 |
|
---|
[551] | 219 | if (p != str)
|
---|
[1039] | 220 | free(p);
|
---|
[551] | 221 | if (id > NOTE_MAX)
|
---|
[1444] | 222 | id = NOTE_FRAME; // Wrap
|
---|
[2] | 223 | }
|
---|
| 224 |
|
---|
[1444] | 225 | AddNote(str); // Add thread notes window
|
---|
[2] | 226 |
|
---|
| 227 | return hwnd;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[1002] | 230 | /**
|
---|
[1444] | 231 | * Display timed notification window over status line
|
---|
[1002] | 232 | */
|
---|
| 233 |
|
---|
[1394] | 234 | HWND Notify(PCSZ str)
|
---|
[356] | 235 | {
|
---|
[1002] | 236 | return (HWND)WinSendMsg(MainObjectHwnd, UM_NOTIFY, MPFROMP(str), MPVOID);
|
---|
[2] | 237 | }
|
---|
| 238 |
|
---|
[1002] | 239 | /**
|
---|
[1444] | 240 | * Notify on error
|
---|
| 241 | * Format message and pass to Notify
|
---|
[1002] | 242 | */
|
---|
| 243 |
|
---|
[1394] | 244 | VOID NotifyError(PCSZ filename, APIRET status)
|
---|
[356] | 245 | {
|
---|
[2] | 246 | CHAR errortext[512];
|
---|
| 247 |
|
---|
[551] | 248 | if (!filename)
|
---|
[2] | 249 | return;
|
---|
[1444] | 250 |
|
---|
[551] | 251 | sprintf(errortext, GetPString(IDS_ERRORACCESSTEXT), status, filename);
|
---|
| 252 | if (toupper(*filename) > 'B') {
|
---|
| 253 | if (status == 21)
|
---|
| 254 | strcat(errortext, GetPString(IDS_EMPTYREMOVETEXT));
|
---|
| 255 | else if (status == 27)
|
---|
[2] | 256 | strcat(errortext, GetPString(IDS_CDMUSICTEXT));
|
---|
[551] | 257 | else if (status == 19)
|
---|
| 258 | strcat(errortext, GetPString(IDS_WRITEPROTECTTEXT));
|
---|
| 259 | else if (status == 108)
|
---|
| 260 | strcat(errortext, GetPString(IDS_DRIVELOCKEDTEXT));
|
---|
[2] | 261 | }
|
---|
| 262 | else {
|
---|
[551] | 263 | if (status == 21)
|
---|
| 264 | strcat(errortext, GetPString(IDS_EMPTYFLOPPYTEXT));
|
---|
| 265 | else if (status == 27)
|
---|
| 266 | strcat(errortext, GetPString(IDS_UNFORMATEDTEXT));
|
---|
| 267 | else if (status == 107)
|
---|
[2] | 268 | sprintf(&errortext[strlen(errortext)],
|
---|
[1335] | 269 | GetPString(IDS_PHANTOMTEXT), toupper(*filename));
|
---|
[551] | 270 | else if (status == 19)
|
---|
| 271 | strcat(errortext, GetPString(IDS_DISKWRITEPROTEXTTEXT));
|
---|
| 272 | else if (status == 108)
|
---|
| 273 | strcat(errortext, GetPString(IDS_DISKLOCKEDTEXT));
|
---|
[2] | 274 | }
|
---|
[1395] | 275 | if (!fErrorBeepOff) {
|
---|
| 276 | DosBeep(250, 10);
|
---|
| 277 | DosBeep(500, 10);
|
---|
| 278 | DosBeep(250, 10);
|
---|
| 279 | DosBeep(500, 10);
|
---|
| 280 | }
|
---|
[2] | 281 | Notify(errortext);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[1002] | 284 | /**
|
---|
[1444] | 285 | * Thread notes window dialog procedure
|
---|
[1002] | 286 | */
|
---|
| 287 |
|
---|
[551] | 288 | MRESULT EXPENTRY NoteWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[356] | 289 | {
|
---|
[1444] | 290 | static HPOINTER hptrIcon;
|
---|
[2] | 291 |
|
---|
[551] | 292 | switch (msg) {
|
---|
| 293 | case WM_INITDLG:
|
---|
[1002] | 294 | if (hwndNotify != (HWND)0) {
|
---|
| 295 | // Already have notes dialog - pass message on
|
---|
[551] | 296 | if (mp2) {
|
---|
[1444] | 297 | AddNote((PCSZ)mp2); // 16 Jul 09 SHL was direct LM_INSERTITEM
|
---|
| 298 | xfree((PSZ)mp2, pszSrcFile, __LINE__);
|
---|
[2] | 299 | }
|
---|
[551] | 300 | WinDismissDlg(hwnd, 0);
|
---|
| 301 | break;
|
---|
| 302 | }
|
---|
| 303 | hwndNotify = hwnd;
|
---|
[1444] | 304 | // Remember showing for restart
|
---|
| 305 | fThreadNotes = TRUE;
|
---|
[1455] | 306 | PrfWriteProfileData(fmprof,
|
---|
[1505] | 307 | FM3Str,
|
---|
[1455] | 308 | "ThreadNotes",
|
---|
| 309 | &fThreadNotes,
|
---|
| 310 | sizeof(BOOL));
|
---|
| 311 | fThreadNotes = FALSE; // Optimize shutdown
|
---|
[1444] | 312 |
|
---|
| 313 | // 16 Jul 09 SHL Added
|
---|
| 314 | if (pszCachedNote) {
|
---|
| 315 | PCSZ p = pszCachedNote;
|
---|
| 316 | pszCachedNote = NULL;
|
---|
| 317 | AddNote(p);
|
---|
| 318 | xfree((PSZ)p, pszSrcFile, __LINE__);
|
---|
[551] | 319 | }
|
---|
[1444] | 320 |
|
---|
[551] | 321 | if (mp2) {
|
---|
[1444] | 322 | AddNote((PCSZ)mp2); // 16 Jul 09 SHL was direct LM_INSERTITEM
|
---|
| 323 | xfree((PSZ)mp2, pszSrcFile, __LINE__);
|
---|
[551] | 324 | }
|
---|
[1002] | 325 |
|
---|
[1444] | 326 | // Grab focus
|
---|
| 327 | PostMsg(hwnd,
|
---|
| 328 | UM_FOCUSME,
|
---|
| 329 | MPFROMLONG(WinQueryActiveWindow(HWND_DESKTOP)),
|
---|
| 330 | MPVOID);
|
---|
[1002] | 331 |
|
---|
[551] | 332 | hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, NOTE_FRAME);
|
---|
| 333 | if (hptrIcon)
|
---|
| 334 | WinDefDlgProc(hwnd, WM_SETICON, MPFROMLONG(hptrIcon), MPFROMLONG(0L));
|
---|
| 335 | break;
|
---|
[2] | 336 |
|
---|
[551] | 337 | case UM_FOCUSME:
|
---|
| 338 | {
|
---|
| 339 | ULONG size = sizeof(SWP),
|
---|
[1335] | 340 | fl = SWP_ZORDER | SWP_FOCUSDEACTIVATE | SWP_SHOW;
|
---|
[551] | 341 | SWP swp;
|
---|
[2] | 342 |
|
---|
[551] | 343 | if (PrfQueryProfileData(fmprof,
|
---|
[1505] | 344 | FM3Str, "NoteWndSwp", (PVOID) & swp, &size)) {
|
---|
[1335] | 345 | if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
|
---|
| 346 | fl |= SWP_MINIMIZE;
|
---|
| 347 | fl &= (~SWP_SHOW);
|
---|
| 348 | }
|
---|
| 349 | else
|
---|
| 350 | fl |= (SWP_MOVE | SWP_SIZE);
|
---|
[2] | 351 | }
|
---|
[551] | 352 | WinSetWindowPos(hwnd, HWND_BOTTOM, swp.x, swp.y, swp.cx, swp.cy, fl);
|
---|
| 353 | if (fl & SWP_MINIMIZE) {
|
---|
[1335] | 354 | WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT) swp.x);
|
---|
| 355 | WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT) swp.cx);
|
---|
| 356 | WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT) swp.y);
|
---|
| 357 | WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT) swp.cy);
|
---|
[551] | 358 | }
|
---|
| 359 | }
|
---|
| 360 | if (mp1)
|
---|
| 361 | WinSetActiveWindow(HWND_DESKTOP, (HWND) mp1);
|
---|
| 362 | return 0;
|
---|
[2] | 363 |
|
---|
[551] | 364 | case UM_STRETCH:
|
---|
| 365 | {
|
---|
| 366 | SWP swp;
|
---|
| 367 | LONG titl, szbx, szby;
|
---|
[2] | 368 |
|
---|
[551] | 369 | WinQueryWindowPos(hwnd, &swp);
|
---|
| 370 | if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
|
---|
[1335] | 371 | szbx = SysVal(SV_CXSIZEBORDER);
|
---|
| 372 | szby = SysVal(SV_CYSIZEBORDER);
|
---|
| 373 | titl = SysVal(SV_CYTITLEBAR);
|
---|
| 374 | WinSetWindowPos(WinWindowFromID(hwnd, NOTE_LISTBOX),
|
---|
| 375 | HWND_TOP,
|
---|
| 376 | szbx,
|
---|
| 377 | szby,
|
---|
| 378 | swp.cx - (szbx * 2L),
|
---|
| 379 | (swp.cy - titl) - (szby * 2L), SWP_MOVE | SWP_SIZE);
|
---|
[2] | 380 | }
|
---|
[551] | 381 | if (!(swp.fl & SWP_MAXIMIZE)) {
|
---|
[1335] | 382 | if (swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
|
---|
| 383 | swp.x = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
|
---|
| 384 | swp.y = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
|
---|
| 385 | swp.cx = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
|
---|
| 386 | swp.cy = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
|
---|
| 387 | }
|
---|
| 388 | PrfWriteProfileData(fmprof,
|
---|
[1505] | 389 | FM3Str, "NoteWndSwp", (PVOID) & swp, sizeof(SWP));
|
---|
[551] | 390 | }
|
---|
| 391 | }
|
---|
| 392 | return 0;
|
---|
[2] | 393 |
|
---|
[551] | 394 | case WM_ADJUSTWINDOWPOS:
|
---|
| 395 | PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
|
---|
| 396 | break;
|
---|
[2] | 397 |
|
---|
[551] | 398 | case UM_CONTAINER_FILLED:
|
---|
| 399 | {
|
---|
[1002] | 400 | SHORT y;
|
---|
| 401 | SHORT x = (SHORT)WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 402 | NOTE_LISTBOX,
|
---|
| 403 | LM_QUERYITEMCOUNT, MPVOID, MPVOID);
|
---|
[551] | 404 | if (x > 60) {
|
---|
[1335] | 405 | for (y = 0; y < x - 50; y++) {
|
---|
| 406 | WinSendDlgItemMsg(hwnd,
|
---|
| 407 | NOTE_LISTBOX,
|
---|
| 408 | LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
|
---|
| 409 | }
|
---|
[2] | 410 | }
|
---|
[551] | 411 | }
|
---|
| 412 | return 0;
|
---|
[2] | 413 |
|
---|
[551] | 414 | case UM_NOTIFY:
|
---|
| 415 | {
|
---|
[1002] | 416 | SHORT x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
[1335] | 417 | NOTE_LISTBOX,
|
---|
| 418 | LM_QUERYITEMCOUNT, MPVOID, MPVOID);
|
---|
[551] | 419 | if (x > 0)
|
---|
[1335] | 420 | WinSendDlgItemMsg(hwnd,
|
---|
| 421 | NOTE_LISTBOX,
|
---|
| 422 | LM_SETTOPINDEX, MPFROMSHORT(x), MPVOID);
|
---|
[551] | 423 | }
|
---|
| 424 | return 0;
|
---|
[2] | 425 |
|
---|
[551] | 426 | case UM_SHOWME:
|
---|
| 427 | WinSetWindowPos(hwnd,
|
---|
[1335] | 428 | HWND_TOP,
|
---|
| 429 | 0,
|
---|
| 430 | 0,
|
---|
| 431 | 0, 0, SWP_SHOW | SWP_RESTORE | SWP_ZORDER | SWP_ACTIVATE);
|
---|
[551] | 432 | return 0;
|
---|
[2] | 433 |
|
---|
[551] | 434 | case WM_COMMAND:
|
---|
| 435 | return 0;
|
---|
[2] | 436 |
|
---|
[551] | 437 | case WM_CLOSE:
|
---|
[1444] | 438 | if (pszCachedNote)
|
---|
[1521] | 439 | Runtime_Error(pszSrcFile, __LINE__, "pszCachedNote %p unexpected", pszCachedNote);
|
---|
[1444] | 440 | else {
|
---|
| 441 | // Cache last item for next open
|
---|
| 442 | SHORT ndx = (SHORT)WinSendDlgItemMsg(hwnd, NOTE_LISTBOX,
|
---|
| 443 | LM_QUERYITEMCOUNT, MPVOID, MPVOID);
|
---|
| 444 | if (ndx != LIT_NONE) {
|
---|
| 445 | SHORT len;
|
---|
| 446 | ndx--;
|
---|
| 447 | len = (SHORT)WinSendDlgItemMsg(hwnd, NOTE_LISTBOX,
|
---|
[1455] | 448 | LM_QUERYITEMTEXTLENGTH,
|
---|
[1444] | 449 | MPFROMSHORT(ndx), MPVOID);
|
---|
| 450 | if (len != LIT_ERROR) {
|
---|
| 451 | PSZ p;
|
---|
| 452 | len++;
|
---|
| 453 | p = xmalloc(len, pszSrcFile, __LINE__);
|
---|
| 454 | if (p) {
|
---|
| 455 | SHORT len2 = (SHORT)WinSendDlgItemMsg(hwnd, NOTE_LISTBOX,
|
---|
| 456 | LM_QUERYITEMTEXT,
|
---|
| 457 | MPFROM2SHORT(ndx, len), MPFROMP(p));
|
---|
| 458 | len--;
|
---|
| 459 | if (len2 != len) {
|
---|
| 460 | DbgMsg(pszSrcFile, __LINE__, "len %u unexpected - should be %u", len2, len); // 18 Jul 08 SHL fixme to be Runtime_Error
|
---|
| 461 | xfree((PSZ)p, pszSrcFile, __LINE__);
|
---|
| 462 | }
|
---|
| 463 | else
|
---|
| 464 | pszCachedNote = p;
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
[551] | 469 | WinDismissDlg(hwnd, 0);
|
---|
| 470 | return 0;
|
---|
[2] | 471 |
|
---|
[551] | 472 | case WM_DESTROY:
|
---|
| 473 | if (hwndNotify == hwnd) {
|
---|
[1455] | 474 | fThreadNotes = FALSE; // Remember not open
|
---|
[551] | 475 | PrfWriteProfileData(fmprof,
|
---|
[1505] | 476 | FM3Str, "ThreadNotes", &fThreadNotes, sizeof(BOOL));
|
---|
[1455] | 477 | hwndNotify = (HWND)0;
|
---|
[551] | 478 | }
|
---|
[1444] | 479 | if (hptrIcon) {
|
---|
[551] | 480 | WinDestroyPointer(hptrIcon);
|
---|
[1444] | 481 | hptrIcon = (HPOINTER)0; // 16 Jul 09 SHL
|
---|
| 482 | }
|
---|
[1455] | 483 | if (!PostMsg((HWND)0, WM_QUIT, MPVOID, MPVOID))
|
---|
| 484 | WinSendMsg((HWND)0, WM_QUIT, MPVOID, MPVOID);
|
---|
[551] | 485 | break;
|
---|
[2] | 486 | }
|
---|
[551] | 487 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 488 | }
|
---|
| 489 |
|
---|
[1002] | 490 | /**
|
---|
| 491 | * Thread notes dialog window thread
|
---|
| 492 | */
|
---|
| 493 |
|
---|
[1455] | 494 | static VOID NoteThread(VOID *args)
|
---|
[356] | 495 | {
|
---|
[1002] | 496 | HAB hab = WinInitialize(0);
|
---|
[1038] | 497 | # ifdef FORTIFY
|
---|
| 498 | Fortify_EnterScope();
|
---|
[1063] | 499 | # endif
|
---|
[1002] | 500 | if (hab) {
|
---|
| 501 | HMQ hmq = WinCreateMsgQueue(hab, 0);
|
---|
| 502 | if (hmq) {
|
---|
[551] | 503 | if (!hwndNotify)
|
---|
[1335] | 504 | WinDlgBox(HWND_DESKTOP,
|
---|
| 505 | HWND_DESKTOP,
|
---|
[1444] | 506 | NoteWndProc, FM3ModHandle, NOTE_FRAME, args);
|
---|
[1002] | 507 | WinDestroyMsgQueue(hmq);
|
---|
[2] | 508 | }
|
---|
[1002] | 509 | WinTerminate(hab);
|
---|
[2] | 510 | }
|
---|
[1038] | 511 | # ifdef FORTIFY
|
---|
[1063] | 512 | Fortify_LeaveScope();
|
---|
| 513 | # endif
|
---|
[2] | 514 | }
|
---|
| 515 |
|
---|
[1002] | 516 | /**
|
---|
| 517 | * Start thread notes dialog window thread
|
---|
| 518 | */
|
---|
| 519 |
|
---|
[1444] | 520 | static VOID StartNotes(PCSZ note)
|
---|
[356] | 521 | {
|
---|
| 522 | if (!hwndNotify) {
|
---|
[1335] | 523 | if (xbeginthread(NoteThread,
|
---|
| 524 | 65536,
|
---|
[1444] | 525 | (VOID*)note,
|
---|
[1335] | 526 | pszSrcFile,
|
---|
| 527 | __LINE__) != -1)
|
---|
| 528 | {
|
---|
[1002] | 529 | USHORT i;
|
---|
| 530 | for (i = 0; !hwndNotify && i < 10; i++)
|
---|
[1335] | 531 | DosSleep(10);
|
---|
[1002] | 532 | if (!hwndNotify)
|
---|
[1335] | 533 | Runtime_Error(pszSrcFile, __LINE__, "Can not create Notify window");
|
---|
[1002] | 534 | }
|
---|
[2] | 535 | }
|
---|
| 536 | }
|
---|
| 537 |
|
---|
[1002] | 538 | /**
|
---|
| 539 | * Add note to thread notes window or popup status window
|
---|
[1444] | 540 | * Open window if was open and first messages after restart
|
---|
| 541 | * Cache last note until window opened
|
---|
[1002] | 542 | */
|
---|
| 543 |
|
---|
[1444] | 544 | VOID AddNote(PCSZ note)
|
---|
[356] | 545 | {
|
---|
[1394] | 546 | PSZ s;
|
---|
| 547 | PCSZ p;
|
---|
[1444] | 548 | BOOL once = FALSE;
|
---|
[2] | 549 |
|
---|
[1444] | 550 | // Cache last note until window opened
|
---|
| 551 | // 16 Jul 09 SHL fixme to avoid FORTIFY complaints
|
---|
| 552 | if (!fThreadNotes && !hwndNotify && note) {
|
---|
| 553 | p = note + strspn(note, " \t"); // Skip leading white
|
---|
[551] | 554 | if (*p) {
|
---|
[1444] | 555 | if (pszCachedNote)
|
---|
| 556 | xfree((PSZ)pszCachedNote, pszSrcFile, __LINE__);
|
---|
| 557 | pszCachedNote = xstrdup(p, pszSrcFile, __LINE__);
|
---|
| 558 | }
|
---|
| 559 | return;
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 | if ((fThreadNotes || hwndNotify) && note) {
|
---|
| 563 | p = note + strspn(note, " \t"); // Skip leading white
|
---|
| 564 | if (*p) {
|
---|
| 565 | // If have cached note, output it first
|
---|
| 566 | if (pszCachedNote) {
|
---|
| 567 | PCSZ psz = pszCachedNote;
|
---|
| 568 | pszCachedNote = NULL;
|
---|
| 569 | AddNote(psz);
|
---|
| 570 | free((VOID*)psz);
|
---|
| 571 | }
|
---|
[551] | 572 | if (!hwndNotify) {
|
---|
[1444] | 573 | fThreadNotes = FALSE; // 16 Jul 09 SHL fixme to be gone?
|
---|
[1335] | 574 | StartNotes(NULL);
|
---|
[2] | 575 | }
|
---|
[551] | 576 | if (hwndNotify) {
|
---|
[1335] | 577 | s = xmalloc(strlen(p) + 14, pszSrcFile, __LINE__);
|
---|
| 578 | if (s) {
|
---|
| 579 | sprintf(s, "%08lx %s", _threadid, p);
|
---|
| 580 | while (!once) {
|
---|
| 581 | if ((SHORT) WinSendDlgItemMsg(hwndNotify,
|
---|
| 582 | NOTE_LISTBOX,
|
---|
| 583 | LM_INSERTITEM,
|
---|
| 584 | MPFROM2SHORT(LIT_END, 0),
|
---|
| 585 | MPFROMP(s)) >= 0) {
|
---|
| 586 | PostMsg(hwndNotify, UM_NOTIFY, MPVOID, MPVOID);
|
---|
| 587 | break;
|
---|
| 588 | }
|
---|
| 589 | PostMsg(hwndNotify, UM_CONTAINER_FILLED, MPVOID, MPVOID);
|
---|
| 590 | once = TRUE;
|
---|
| 591 | }
|
---|
| 592 | free(s);
|
---|
| 593 | }
|
---|
[2] | 594 | }
|
---|
| 595 | }
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 |
|
---|
[1002] | 599 | /**
|
---|
| 600 | * Close thread notes window
|
---|
| 601 | */
|
---|
| 602 |
|
---|
[551] | 603 | VOID EndNote(VOID)
|
---|
[356] | 604 | {
|
---|
[551] | 605 | if (hwndNotify)
|
---|
| 606 | if (!PostMsg(hwndNotify, WM_CLOSE, MPVOID, MPVOID))
|
---|
| 607 | WinSendMsg(hwndNotify, WM_CLOSE, MPVOID, MPVOID);
|
---|
[2] | 608 | }
|
---|
| 609 |
|
---|
[1002] | 610 | /**
|
---|
| 611 | * Pop up thread notes window
|
---|
| 612 | */
|
---|
| 613 |
|
---|
[551] | 614 | VOID ShowNote(VOID)
|
---|
[356] | 615 | {
|
---|
[551] | 616 | if (!hwndNotify)
|
---|
[2] | 617 | StartNotes(NULL);
|
---|
[551] | 618 | if (hwndNotify)
|
---|
| 619 | PostMsg(hwndNotify, UM_SHOWME, MPVOID, MPVOID);
|
---|
[2] | 620 | }
|
---|
| 621 |
|
---|
[1002] | 622 | /**
|
---|
| 623 | * Hide thread notes window
|
---|
| 624 | */
|
---|
| 625 |
|
---|
[551] | 626 | VOID HideNote(VOID)
|
---|
[356] | 627 | {
|
---|
[551] | 628 | if (hwndNotify)
|
---|
[2] | 629 | WinSetWindowPos(hwndNotify,
|
---|
[1335] | 630 | HWND_BOTTOM,
|
---|
| 631 | 0,
|
---|
| 632 | 0, 0, 0, SWP_MINIMIZE | SWP_ZORDER | SWP_FOCUSDEACTIVATE);
|
---|
[2] | 633 | }
|
---|
[793] | 634 |
|
---|
[1038] | 635 | #pragma alloc_text(NOTIFY,Notify,NotifyWndProc,StartNotify,NotifyError)
|
---|
[793] | 636 | #pragma alloc_text(NOTIFY2,AddNote,NoteThread,NoteWndProc)
|
---|
| 637 | #pragma alloc_text(NOTIFY3,StartNotes,EndNote,HideNote,ShowNote)
|
---|