Changeset 1002 for trunk/dll/notify.c


Ignore:
Timestamp:
Apr 18, 2008, 6:39:18 PM (17 years ago)
Author:
Steven Levine
Message:

Comment and clean up logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/notify.c

    r985 r1002  
    44  $Id$
    55
    6   Notifications
     6  Thread notes window and popup notification status line
    77
    88  Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2006 Steven H.Levine
     9  Copyright (c) 2006, 2008 Steven H.Levine
    1010
    1111  17 Jul 06 SHL Use Win_Error
     
    1515  20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
    1616  29 Feb 08 GKY Use xfree where appropriate
    17 
     17  16 Apr 08 SHL Comment and clean up logic
    1818
    1919***********************************************************************/
     
    4040static PSZ pszSrcFile = __FILE__;
    4141
    42 static HWND hwndNotify;
     42static volatile HWND hwndNotify;        // 16 Apr 08 SHL
     43
     44/**
     45 * Popup notification message window procedure
     46 * Display timed message over status line
     47 */
    4348
    4449MRESULT EXPENTRY NotifyWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     
    5055    showing++;
    5156    {
    52       MRESULT rc;
    53 
    54       rc = PFNWPStatic(hwnd, msg, mp1, mp2);
     57      MRESULT rc = PFNWPStatic(hwnd, msg, mp1, mp2);
     58
    5559      if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER2, 5000)) {
    5660        Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinStartTimer");
     
    9599  case WM_PAINT:
    96100    {
    97       MRESULT mr;
    98       HPS hps;
    99101      SWP swp;
    100102      POINTL ptl;
    101103
    102       mr = PFNWPStatic(hwnd, msg, mp1, mp2);
    103       hps = WinGetPS(hwnd);
     104      MRESULT mr = PFNWPStatic(hwnd, msg, mp1, mp2);
     105      HPS hps = WinGetPS(hwnd);
    104106      if (hps) {
    105107        if (WinQueryWindowPos(hwnd, &swp)) {
     
    139141}
    140142
     143/**
     144 * Display timed notification window over status line
     145 */
     146
    141147HWND DoNotify(char *str)
    142148{
     
    148154
    149155  if (str && *str) {
    150     /* figure out what size the window should be and where it should be */
    151     hwndP = (hwndMain) ? WinQueryWindow(hwndMain, QW_PARENT) : HWND_DESKTOP;
     156    // figure out what size the window should be and where it should be
     157    hwndP = hwndMain ? WinQueryWindow(hwndMain, QW_PARENT) : HWND_DESKTOP;
    152158    WinQueryWindowPos(hwndP, &swp);
    153159    if (hwndStatus)
     
    155161    if (hwndStatus2)
    156162      WinQueryWindowPos(hwndStatus2, &swpS2);
    157     x = (hwndMain) ? ((hwndStatus) ? swpS.x - 1 :
     163    x = hwndMain ? (hwndStatus ? swpS.x - 1 :
    158164                      WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER)) : 0;
    159     y = (hwndMain) ? ((hwndStatus) ? swpS.y - 1 :
     165    y = hwndMain ? (hwndStatus ? swpS.y - 1 :
    160166                      WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER)) : 0;
    161167    if (hwndMain && hwndStatus) {
     
    167173    else
    168174      cx = (swp.cx - ((x * 2) + 4));
    169     cy = (hwndMain) ? ((hwndStatus) ? swpS.cy + 2 : 28) : 28;
    170 
    171     /* pretty-up the note by putting on a leading space */
     175    cy = hwndMain ? (hwndStatus ? swpS.cy + 2 : 28) : 28;
     176
     177    // pretty-up the note by putting on a leading space
    172178    if (*str != ' ') {
    173179      p = xmalloc(strlen(str) + 2, pszSrcFile, __LINE__);
     
    201207}
    202208
     209/**
     210 * Add message to thread notes window
     211 */
     212
    203213HWND Notify(char *str)
    204214{
    205   return (HWND) WinSendMsg(MainObjectHwnd, UM_NOTIFY, MPFROMP(str), MPVOID);
    206 }
     215  return (HWND)WinSendMsg(MainObjectHwnd, UM_NOTIFY, MPFROMP(str), MPVOID);
     216}
     217
     218/**
     219 * Add error message to thread notes window
     220 */
    207221
    208222VOID NotifyError(CHAR * filename, APIRET status)
     
    243257}
    244258
     259/**
     260 * Thread notes dialog window dialog procedure
     261 */
     262
    245263MRESULT EXPENTRY NoteWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    246264{
     
    249267  switch (msg) {
    250268  case WM_INITDLG:
    251     if (hwndNotify != (HWND) 0) {
     269    if (hwndNotify != (HWND)0) {
     270      // Already have notes dialog - pass message on
    252271      if (mp2) {
    253272        WinSendDlgItemMsg(hwndNotify,
     
    262281    hwndNotify = hwnd;
    263282    fThreadNotes = FALSE;
     283    // Remember showing
    264284    {
    265285      BOOL dummy = TRUE;
    266 
    267286      PrfWriteProfileData(fmprof,
    268287                          FM3Str, "ThreadNotes", &dummy, sizeof(BOOL));
     
    274293      xfree((CHAR *) mp2);
    275294    }
    276     {
    277       HWND hwndActive;
    278 
    279       hwndActive = WinQueryActiveWindow(HWND_DESKTOP);
     295
     296    {
     297      // Return focus
     298      HWND hwndActive = WinQueryActiveWindow(HWND_DESKTOP);
    280299      PostMsg(hwnd, UM_FOCUSME, MPFROMLONG(hwndActive), MPVOID);
    281300    }
     301
    282302    hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, NOTE_FRAME);
    283303    if (hptrIcon)
     
    348368  case UM_CONTAINER_FILLED:
    349369    {
    350       SHORT x, y;
    351 
    352       x = (SHORT) WinSendDlgItemMsg(hwnd,
    353                                     NOTE_LISTBOX,
    354                                     LM_QUERYITEMCOUNT, MPVOID, MPVOID);
     370      SHORT y;
     371      SHORT x = (SHORT)WinSendDlgItemMsg(hwnd,
     372                                         NOTE_LISTBOX,
     373                                         LM_QUERYITEMCOUNT, MPVOID, MPVOID);
    355374      if (x > 60) {
    356         for (y = 0; y < x - 50; y++)
     375        for (y = 0; y < x - 50; y++) {
    357376          WinSendDlgItemMsg(hwnd,
    358377                            NOTE_LISTBOX,
    359378                            LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
     379        }
    360380      }
    361381    }
     
    364384  case UM_NOTIFY:
    365385    {
    366       SHORT x;
    367 
    368       x = (SHORT) WinSendDlgItemMsg(hwnd,
    369                                     NOTE_LISTBOX,
    370                                     LM_QUERYITEMCOUNT, MPVOID, MPVOID);
     386      SHORT x = (SHORT) WinSendDlgItemMsg(hwnd,
     387                                          NOTE_LISTBOX,
     388                                          LM_QUERYITEMCOUNT, MPVOID, MPVOID);
    371389      if (x > 0)
    372390        WinSendDlgItemMsg(hwnd,
     
    407425}
    408426
     427/**
     428 * Thread notes dialog window thread
     429 */
     430
    409431static VOID NoteThread(VOID * args)
    410432{
    411   HAB hab2;
    412   HMQ hmq2;
    413 
    414   hab2 = WinInitialize(0);
    415   if (hab2) {
    416     hmq2 = WinCreateMsgQueue(hab2, 0);
    417     if (hmq2) {
     433  HAB hab = WinInitialize(0);
     434
     435  if (hab) {
     436    HMQ hmq = WinCreateMsgQueue(hab, 0);
     437    if (hmq) {
    418438      if (!hwndNotify)
    419439        WinDlgBox(HWND_DESKTOP,
    420440                  HWND_DESKTOP,
    421                   NoteWndProc, FM3ModHandle, NOTE_FRAME, (CHAR *) args);
    422       WinDestroyMsgQueue(hmq2);
    423     }
    424     WinTerminate(hab2);
    425   }
    426 }
     441                  NoteWndProc, FM3ModHandle, NOTE_FRAME, (CHAR *)args);
     442      WinDestroyMsgQueue(hmq);
     443    }
     444    WinTerminate(hab);
     445  }
     446}
     447
     448/**
     449 * Start thread notes dialog window thread
     450 */
    427451
    428452VOID StartNotes(CHAR * note)
     
    430454  if (!hwndNotify) {
    431455    if (_beginthread(NoteThread, NULL, 65536, (PVOID) note) == -1)
    432       Runtime_Error(pszSrcFile, __LINE__,
    433                     GetPString(IDS_COULDNTSTARTTHREADTEXT));
    434   }
    435 }
     456      Runtime_Error2(pszSrcFile, __LINE__, IDS_COULDNTSTARTTHREADTEXT);
     457    else {
     458      USHORT i;
     459      for (i = 0; !hwndNotify && i < 10; i++)
     460        DosSleep(10);
     461      if (!hwndNotify)
     462        Runtime_Error(pszSrcFile, __LINE__, "Can not create Notify window");
     463    }
     464  }
     465}
     466
     467/**
     468 * Add note to thread notes window or popup status window
     469 */
    436470
    437471BOOL AddNote(CHAR * note)
     
    448482        fThreadNotes = FALSE;
    449483        StartNotes(NULL);
    450         if (!hwndNotify)
    451           DosSleep(16);//05 Aug 07 GKY 33
    452         if (!hwndNotify)
    453           DosSleep(16);//05 Aug 07 GKY 33
    454         if (!hwndNotify)
    455           DosSleep(16);//05 Aug 07 GKY 33
    456484      }
    457485      if (hwndNotify) {
     
    480508}
    481509
     510/**
     511 * Close thread notes window
     512 */
     513
    482514VOID EndNote(VOID)
    483515{
     
    487519}
    488520
     521/**
     522 * Pop up thread notes window
     523 */
     524
    489525VOID ShowNote(VOID)
    490526{
    491527  if (!hwndNotify)
    492528    StartNotes(NULL);
    493   if (!hwndNotify)
    494     DosSleep(16);//05 Aug 07 GKY 33
    495   if (!hwndNotify)
    496     DosSleep(16);//05 Aug 07 GKY 33
    497   if (!hwndNotify)
    498     DosSleep(16);//05 Aug 07 GKY 33
    499529  if (hwndNotify)
    500530    PostMsg(hwndNotify, UM_SHOWME, MPVOID, MPVOID);
    501531}
     532
     533/**
     534 * Hide thread notes window
     535 */
    502536
    503537VOID HideNote(VOID)
Note: See TracChangeset for help on using the changeset viewer.