Changeset 1444 for trunk/dll/notify.c
- Timestamp:
- Jul 23, 2009, 1:24:23 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/notify.c
r1395 r1444 3 3 $Id$ 4 4 5 Thread notes window and popup notification status line5 Thread notes window and popup notifications over status line 6 6 7 7 Copyright (c) 1993-98 M. Kimes … … 18 18 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook. 19 19 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error 20 13 Jul 09 SHL Sync with renames 21 16 Jul 09 SHL Stop leaking hptrIcon 20 22 21 23 ***********************************************************************/ … … 25 27 #include <ctype.h> 26 28 #include <stddef.h> // _threadid 27 // #include <process.h> // _beginthread28 29 29 30 #define INCL_DOS … … 55 56 static PSZ pszSrcFile = __FILE__; 56 57 static volatile HWND hwndNotify; // 16 Apr 08 SHL 58 static volatile PCSZ pszCachedNote; // 16 Jul 09 SHL 57 59 58 60 #pragma data_seg(GLOBAL1) 59 61 BOOL fThreadNotes; 60 62 61 VOID StartNotes(CHAR * s);62 63 /** 64 * Popup notification message window procedure65 * Display timed message over status line63 static VOID StartNotes(PCSZ pszNote); 64 65 /** 66 * Notification message window procedure 67 * Displays timed message over status line 66 68 */ 67 69 … … 76 78 MRESULT rc = PFNWPStatic(hwnd, msg, mp1, mp2); 77 79 78 if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_ TIMER2, 5000)) {80 if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NOTIFY_TIMER, 5000)) { 79 81 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinStartTimer"); 80 82 WinDestroyWindow(hwnd); … … 144 146 case WM_TIMER: 145 147 case WM_CLOSE: 146 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_ TIMER2);148 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NOTIFY_TIMER); 147 149 WinDestroyWindow(hwnd); 148 150 return 0; … … 162 164 163 165 /** 164 * Display timed notification windowover status line166 * Process UM_NOTIFY message to display timed message over status line 165 167 */ 166 168 … … 213 215 SS_TEXT | DT_LEFT | DT_VCENTER | WS_VISIBLE, 214 216 x, y, cx, cy, hwndP, HWND_TOP, id++, NULL, NULL); 215 if (!hwnd P)217 if (!hwnd) 216 218 Win_Error(hwndP, hwndP, pszSrcFile, __LINE__, 217 219 PCSZ_WINCREATEWINDOW); … … 220 222 free(p); 221 223 if (id > NOTE_MAX) 222 id = NOTE_FRAME; 223 } 224 225 AddNote(str); 224 id = NOTE_FRAME; // Wrap 225 } 226 227 AddNote(str); // Add thread notes window 226 228 227 229 return hwnd; … … 229 231 230 232 /** 231 * Add message to thread notes window233 * Display timed notification window over status line 232 234 */ 233 235 … … 238 240 239 241 /** 240 * Add error message to thread notes window 242 * Notify on error 243 * Format message and pass to Notify 241 244 */ 242 245 … … 247 250 if (!filename) 248 251 return; 252 249 253 sprintf(errortext, GetPString(IDS_ERRORACCESSTEXT), status, filename); 250 254 if (toupper(*filename) > 'B') { … … 281 285 282 286 /** 283 * Thread notes dialogwindow dialog procedure287 * Thread notes window dialog procedure 284 288 */ 285 289 286 290 MRESULT EXPENTRY NoteWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 287 291 { 288 static HPOINTER hptrIcon = (HPOINTER) 0;292 static HPOINTER hptrIcon; 289 293 290 294 switch (msg) { … … 293 297 // Already have notes dialog - pass message on 294 298 if (mp2) { 295 WinSendDlgItemMsg(hwndNotify, 296 NOTE_LISTBOX, 297 LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), mp2); 298 PostMsg(hwndNotify, UM_NOTIFY, MPVOID, MPVOID); 299 free((CHAR *)mp2); 299 AddNote((PCSZ)mp2); // 16 Jul 09 SHL was direct LM_INSERTITEM 300 xfree((PSZ)mp2, pszSrcFile, __LINE__); 300 301 } 301 302 WinDismissDlg(hwnd, 0); … … 303 304 } 304 305 hwndNotify = hwnd; 305 fThreadNotes = FALSE; 306 // Remember showing 307 { 308 BOOL dummy = TRUE; 306 // Remember showing for restart 307 fThreadNotes = TRUE; 309 308 PrfWriteProfileData(fmprof, 310 FM3Str, "ThreadNotes", &dummy, sizeof(BOOL)); 311 } 309 FM3Str, "ThreadNotes", &fThreadNotes, sizeof(BOOL)); 310 fThreadNotes = FALSE; // Optimize 311 312 // 16 Jul 09 SHL Added 313 if (pszCachedNote) { 314 PCSZ p = pszCachedNote; 315 pszCachedNote = NULL; 316 AddNote(p); 317 xfree((PSZ)p, pszSrcFile, __LINE__); 318 } 319 312 320 if (mp2) { 313 WinSendDlgItemMsg(hwnd, 314 NOTE_LISTBOX, 315 LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), mp2); 316 free((CHAR *)mp2); 317 } 318 319 { 320 // Return focus 321 HWND hwndActive = WinQueryActiveWindow(HWND_DESKTOP); 322 PostMsg(hwnd, UM_FOCUSME, MPFROMLONG(hwndActive), MPVOID); 323 } 321 AddNote((PCSZ)mp2); // 16 Jul 09 SHL was direct LM_INSERTITEM 322 xfree((PSZ)mp2, pszSrcFile, __LINE__); 323 } 324 325 // Grab focus 326 PostMsg(hwnd, 327 UM_FOCUSME, 328 MPFROMLONG(WinQueryActiveWindow(HWND_DESKTOP)), 329 MPVOID); 324 330 325 331 hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, NOTE_FRAME); … … 429 435 430 436 case WM_CLOSE: 437 if (pszCachedNote) 438 DbgMsg(pszSrcFile, __LINE__, "pszCachedNote %p unexpected", pszCachedNote); // 18 Jul 08 SHL fixme to be Runtime_Error 439 else { 440 // Cache last item for next open 441 SHORT ndx = (SHORT)WinSendDlgItemMsg(hwnd, NOTE_LISTBOX, 442 LM_QUERYITEMCOUNT, MPVOID, MPVOID); 443 if (ndx != LIT_NONE) { 444 SHORT len; 445 ndx--; 446 len = (SHORT)WinSendDlgItemMsg(hwnd, NOTE_LISTBOX, 447 LM_QUERYITEMTEXTLENGTH, 448 MPFROMSHORT(ndx), MPVOID); 449 if (len != LIT_ERROR) { 450 PSZ p; 451 len++; 452 p = xmalloc(len, pszSrcFile, __LINE__); 453 if (p) { 454 SHORT len2 = (SHORT)WinSendDlgItemMsg(hwnd, NOTE_LISTBOX, 455 LM_QUERYITEMTEXT, 456 MPFROM2SHORT(ndx, len), MPFROMP(p)); 457 len--; 458 if (len2 != len) { 459 DbgMsg(pszSrcFile, __LINE__, "len %u unexpected - should be %u", len2, len); // 18 Jul 08 SHL fixme to be Runtime_Error 460 xfree((PSZ)p, pszSrcFile, __LINE__); 461 } 462 else 463 pszCachedNote = p; 464 } 465 } 466 } 467 } 431 468 WinDismissDlg(hwnd, 0); 432 469 return 0; … … 434 471 case WM_DESTROY: 435 472 if (hwndNotify == hwnd) { 473 // Remember not open 436 474 fThreadNotes = FALSE; 437 475 PrfWriteProfileData(fmprof, … … 439 477 hwndNotify = (HWND) 0; 440 478 } 441 if (hptrIcon) 479 if (hptrIcon) { 442 480 WinDestroyPointer(hptrIcon); 481 hptrIcon = (HPOINTER)0; // 16 Jul 09 SHL 482 } 443 483 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID)) 444 484 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID); … … 464 504 WinDlgBox(HWND_DESKTOP, 465 505 HWND_DESKTOP, 466 NoteWndProc, FM3ModHandle, NOTE_FRAME, (CHAR *)args);506 NoteWndProc, FM3ModHandle, NOTE_FRAME, args); 467 507 WinDestroyMsgQueue(hmq); 468 508 } … … 478 518 */ 479 519 480 VOID StartNotes(CHAR *note)520 static VOID StartNotes(PCSZ note) 481 521 { 482 522 if (!hwndNotify) { 483 523 if (xbeginthread(NoteThread, 484 524 65536, 485 note,525 (VOID*)note, 486 526 pszSrcFile, 487 527 __LINE__) != -1) … … 498 538 /** 499 539 * Add note to thread notes window or popup status window 500 */ 501 502 BOOL AddNote(PCSZ note) 540 * Open window if was open and first messages after restart 541 * Cache last note until window opened 542 */ 543 544 VOID AddNote(PCSZ note) 503 545 { 504 546 PSZ s; 505 547 PCSZ p; 506 BOOL once = FALSE , ret = FALSE;507 508 if ((fThreadNotes || hwndNotify) && note && *note) {509 p = note;510 while (*p == ' ')511 p++;548 BOOL once = FALSE; 549 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 512 554 if (*p) { 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 } 513 572 if (!hwndNotify) { 514 fThreadNotes = FALSE; 573 fThreadNotes = FALSE; // 16 Jul 09 SHL fixme to be gone? 515 574 StartNotes(NULL); 516 575 } … … 525 584 MPFROM2SHORT(LIT_END, 0), 526 585 MPFROMP(s)) >= 0) { 527 ret = TRUE;528 586 PostMsg(hwndNotify, UM_NOTIFY, MPVOID, MPVOID); 529 587 break; … … 537 595 } 538 596 } 539 return ret;540 597 } 541 598
Note:
See TracChangeset
for help on using the changeset viewer.