Changeset 1444 for trunk/dll/notify.c


Ignore:
Timestamp:
Jul 23, 2009, 1:24:23 AM (16 years ago)
Author:
Gregg Young
Message:

Rework of drivebar to rescan all drives and refresh media buttons and menu items grey out inappropriate menu items. Streamline Tree scan code and use semaphores to serialize access. Add NOEASUPPORT and LOCALHD driveflag; .LONGNAME usage fixes; (Tickets 377-386)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/notify.c

    r1395 r1444  
    33  $Id$
    44
    5   Thread notes window and popup notification status line
     5  Thread notes window and popup notifications over status line
    66
    77  Copyright (c) 1993-98 M. Kimes
     
    1818  07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
    1919  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
    2022
    2123***********************************************************************/
     
    2527#include <ctype.h>
    2628#include <stddef.h>                     // _threadid
    27 // #include <process.h>                 // _beginthread
    2829
    2930#define INCL_DOS
     
    5556static PSZ pszSrcFile = __FILE__;
    5657static volatile HWND hwndNotify;        // 16 Apr 08 SHL
     58static volatile PCSZ pszCachedNote;     // 16 Jul 09 SHL
    5759
    5860#pragma data_seg(GLOBAL1)
    5961BOOL fThreadNotes;
    6062
    61 VOID StartNotes(CHAR * s);
    62 
    63 /**
    64  * Popup notification message window procedure
    65  * Display timed message over status line
     63static VOID StartNotes(PCSZ pszNote);
     64
     65/**
     66 * Notification message window procedure
     67 * Displays timed message over status line
    6668 */
    6769
     
    7678      MRESULT rc = PFNWPStatic(hwnd, msg, mp1, mp2);
    7779
    78       if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER2, 5000)) {
     80      if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NOTIFY_TIMER, 5000)) {
    7981        Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinStartTimer");
    8082        WinDestroyWindow(hwnd);
     
    144146  case WM_TIMER:
    145147  case WM_CLOSE:
    146     WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER2);
     148    WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NOTIFY_TIMER);
    147149    WinDestroyWindow(hwnd);
    148150    return 0;
     
    162164
    163165/**
    164  * Display timed notification window over status line
     166 * Process UM_NOTIFY message to display timed message over status line
    165167 */
    166168
     
    213215                           SS_TEXT | DT_LEFT | DT_VCENTER | WS_VISIBLE,
    214216                           x, y, cx, cy, hwndP, HWND_TOP, id++, NULL, NULL);
    215     if (!hwndP)
     217    if (!hwnd)
    216218      Win_Error(hwndP, hwndP, pszSrcFile, __LINE__,
    217219                PCSZ_WINCREATEWINDOW);
     
    220222      free(p);
    221223    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
    226228
    227229  return hwnd;
     
    229231
    230232/**
    231  * Add message to thread notes window
     233 * Display timed notification window over status line
    232234 */
    233235
     
    238240
    239241/**
    240  * Add error message to thread notes window
     242 * Notify on error
     243 * Format message and pass to Notify
    241244 */
    242245
     
    247250  if (!filename)
    248251    return;
     252
    249253  sprintf(errortext, GetPString(IDS_ERRORACCESSTEXT), status, filename);
    250254  if (toupper(*filename) > 'B') {
     
    281285
    282286/**
    283  * Thread notes dialog window dialog procedure
     287 * Thread notes window dialog procedure
    284288 */
    285289
    286290MRESULT EXPENTRY NoteWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    287291{
    288   static HPOINTER hptrIcon = (HPOINTER) 0;
     292  static HPOINTER hptrIcon;
    289293
    290294  switch (msg) {
     
    293297      // Already have notes dialog - pass message on
    294298      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__);
    300301      }
    301302      WinDismissDlg(hwnd, 0);
     
    303304    }
    304305    hwndNotify = hwnd;
    305     fThreadNotes = FALSE;
    306     // Remember showing
    307     {
    308       BOOL dummy = TRUE;
     306    // Remember showing for restart
     307    fThreadNotes = TRUE;
    309308      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
    312320    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);
    324330
    325331    hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, NOTE_FRAME);
     
    429435
    430436  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    }
    431468    WinDismissDlg(hwnd, 0);
    432469    return 0;
     
    434471  case WM_DESTROY:
    435472    if (hwndNotify == hwnd) {
     473      // Remember not open
    436474      fThreadNotes = FALSE;
    437475      PrfWriteProfileData(fmprof,
     
    439477      hwndNotify = (HWND) 0;
    440478    }
    441     if (hptrIcon)
     479    if (hptrIcon) {
    442480      WinDestroyPointer(hptrIcon);
     481      hptrIcon = (HPOINTER)0;           // 16 Jul 09 SHL
     482    }
    443483    if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
    444484      WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
     
    464504        WinDlgBox(HWND_DESKTOP,
    465505                  HWND_DESKTOP,
    466                   NoteWndProc, FM3ModHandle, NOTE_FRAME, (CHAR *)args);
     506                  NoteWndProc, FM3ModHandle, NOTE_FRAME, args);
    467507      WinDestroyMsgQueue(hmq);
    468508    }
     
    478518 */
    479519
    480 VOID StartNotes(CHAR * note)
     520static VOID StartNotes(PCSZ note)
    481521{
    482522  if (!hwndNotify) {
    483523    if (xbeginthread(NoteThread,
    484524                     65536,
    485                      note,
     525                     (VOID*)note,
    486526                     pszSrcFile,
    487527                     __LINE__) != -1)
     
    498538/**
    499539 * 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
     544VOID AddNote(PCSZ note)
    503545{
    504546  PSZ s;
    505547  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
    512554    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      }
    513572      if (!hwndNotify) {
    514         fThreadNotes = FALSE;
     573        fThreadNotes = FALSE;           // 16 Jul 09 SHL fixme to be gone?
    515574        StartNotes(NULL);
    516575      }
     
    525584                                          MPFROM2SHORT(LIT_END, 0),
    526585                                          MPFROMP(s)) >= 0) {
    527               ret = TRUE;
    528586              PostMsg(hwndNotify, UM_NOTIFY, MPVOID, MPVOID);
    529587              break;
     
    537595    }
    538596  }
    539   return ret;
    540597}
    541598
Note: See TracChangeset for help on using the changeset viewer.