home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / AESample.sit / AESample / sources / sample.alrt.c < prev    next >
Text File  |  1996-06-22  |  5KB  |  174 lines

  1. /*
  2.  *--------------------------------------------------------------
  3.  * sample.alrt.c
  4.  *--------------------------------------------------------------
  5.  */
  6. #include <Notification.h>
  7. #include <Icons.h>
  8.  
  9. #include "sample.h"
  10. #include "sample.alrt.h"
  11.  
  12. /*
  13.  *--------------------------------------------------------------
  14.  * static global for the notification
  15.  *--------------------------------------------------------------
  16.  */
  17. static NMRec    gMyRequest;
  18.  
  19. /*
  20.  *--------------------------------------------------------------
  21.  * static function prototype
  22.  *--------------------------------------------------------------
  23.  */
  24. static OSErr NotifyMyError(const short dialogID);
  25.  
  26. /*
  27.  *--------------------------------------------------------------
  28.  *    CheckMyErrors
  29.  *--------------------------------------------------------------
  30.  *     check a notification and show alert
  31.  *--------------------------------------------------------------
  32.  */
  33. short CheckMyErrors(void)
  34. {
  35.     short    answer = ok;
  36.     short    alertID;
  37.  
  38.     if (gNowBackGround == false) {
  39.         alertID = (short)gMyRequest.nmRefCon;
  40.         if (alertID != 0) {
  41.             /* remove the notification */
  42.             NMRemove(&gMyRequest);
  43.             gMyRequest.nmRefCon = 0;
  44.             /* now show the postponed alert */
  45.             answer = MyAlert(alertID);
  46.         }
  47.     }
  48.     return (answer);
  49. }
  50. /*
  51.  *--------------------------------------------------------------
  52.  * MyAlert
  53.  *--------------------------------------------------------------
  54.  *    In foreground, this routine shows a modal dialog immediately.
  55.  *    In background, post notification instead.
  56.  *--------------------------------------------------------------
  57.  */
  58. short MyAlert(const short theDlgID)
  59. {
  60.     short    itemHit = cancel;
  61.  
  62.     if (gNowBackGround) {
  63.         /* postpone the alert */
  64.         NotifyMyError(theDlgID);
  65.     } else {
  66.         /* show the alert dialog */
  67.         DialogRef    aDialog;
  68.  
  69.         aDialog = GetNewDialog(theDlgID, kInHeap, kFrontMost);
  70.         if (aDialog != nil) {
  71.  
  72.             WindowRef    aWindow;
  73.             GrafPtr        savePort;
  74.  
  75.             GetPort(&savePort);
  76.             aWindow = GetDialogWindow(aDialog);
  77.             SetPortWindowPort(aWindow);
  78.  
  79.             SetDialogDefaultItem(aDialog, kStdOkItemIndex);
  80.  
  81.             /* make the dialog appear */
  82.             ShowWindow(aWindow);
  83.             SelectWindow(aWindow);
  84.             SysBeep(1);    /* play a beep once */
  85.             InitCursor();
  86.  
  87.             do {
  88.                 ModalDialog(nil, &itemHit);
  89.             } while (itemHit != ok && itemHit != cancel);
  90.  
  91.             SetPort(savePort);
  92.             DisposeDialog(aDialog);
  93.         }
  94.     }
  95.     return (itemHit);
  96. }
  97. /*
  98.  *--------------------------------------------------------------
  99.  *    NotifyMyError
  100.  *--------------------------------------------------------------
  101.  *    install a data to notification queue
  102.  *    this is used in case the drag and drop occurred when this
  103.  *    program stays background
  104.  *--------------------------------------------------------------
  105.  */
  106. static OSErr NotifyMyError(const short theAlertID)
  107. {
  108.     Handle    aSuite;
  109.     OSErr    result = noErr;
  110.  
  111.     if (gNowBackGround) {
  112.         if (gMyRequest.nmRefCon != 0) {
  113.             NMRemove(&gMyRequest);
  114.         }
  115.         if (GetIconSuite(&aSuite, kMyIconID, svAllSmallData) != noErr) {
  116.             aSuite = nil;
  117.         }
  118.  
  119.         /* setup notification data record */
  120.         gMyRequest.qType    = nmType;
  121.         gMyRequest.nmMark    = 1;
  122.         gMyRequest.nmIcon    = aSuite;        /* show my icon in menu bar */
  123.         gMyRequest.nmSound    = (Handle)-1;    /* SysBeep */
  124.         gMyRequest.nmStr    = nil;            /* no dialog */
  125.         gMyRequest.nmResp    = nil;            /* no response procs */
  126.         gMyRequest.nmRefCon    = theAlertID;    /* set the alert ID */
  127.         result = NMInstall(&gMyRequest);
  128.     }
  129.     return (result);
  130. }
  131. /*
  132.  *--------------------------------------------------------------
  133.  * DoFileAlert
  134.  *--------------------------------------------------------------
  135.  *    show file handlig alert here
  136.  *--------------------------------------------------------------
  137.  */
  138. void DoFileAlert(StringPtr theFileName, OSErr theCode)
  139. {
  140.     Str15    codeStr;
  141.  
  142.     NumToString((long)theCode, codeStr);
  143.     ParamText(theFileName, codeStr, nil, nil);
  144.  
  145.     MyAlert(alrtFileID);
  146. }
  147. /*
  148.  *--------------------------------------------------------------
  149.  * DoAliasAlert
  150.  *--------------------------------------------------------------
  151.  *    show file handlig alert here
  152.  *--------------------------------------------------------------
  153.  */
  154. void DoAliasAlert(StringPtr theFileName, OSErr theCode)
  155. {
  156.     Str15    codeStr;
  157.  
  158.     NumToString((long)theCode, codeStr);
  159.     ParamText(theFileName, codeStr, nil, nil);
  160.  
  161.     MyAlert(alrtAliasID);
  162. }
  163. /*
  164.  *--------------------------------------------------------------
  165.  * FatalErrorAlert
  166.  *--------------------------------------------------------------
  167.  *    show some fatal error
  168.  *--------------------------------------------------------------
  169.  */
  170. void FatalErrorAlert(void)
  171. {
  172.     StopAlert(alrtFatalID, nil);
  173. }
  174.