home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / LNotificationTask / LNotificationTask.cp < prev    next >
Encoding:
Text File  |  1995-08-27  |  5.7 KB  |  240 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    LNotificationTask.cp            © 1995, Éric Forget. All rights reserved.
  3. // ===========================================================================
  4. //    
  5. //    ************************************************************************
  6. //    *                                                                      *
  7. //    *    Before using this code you should read the "License Agreement"     *
  8. //    *    document and agree with it.                                        *
  9. //    *                                                                      *
  10. //    ************************************************************************
  11. //
  12. //    LNotificationTask is a wrapper class for the Notification Manager.
  13. //
  14. // ---------------------------------------------------------------------------
  15. //
  16. //    Instruction Notes:
  17. //    -----------------
  18. //
  19. //    1) Create a LNotificationTask object with the right arguments. That's all!
  20. //
  21. // ---------------------------------------------------------------------------
  22.  
  23. #include    "LNotificationTask.h"
  24.  
  25. #include    <String_Utils.h>
  26. #include    <UMemoryMgr.h>
  27.  
  28.  
  29.  
  30. // ---------------------------------------------------------------------------
  31. //        • Static members
  32. // ---------------------------------------------------------------------------
  33.  
  34. NMUPP    LNotificationTask::sTaskUPP = NewNMProc(LNotificationTask::TaskUPP);
  35.  
  36.  
  37. // ---------------------------------------------------------------------------
  38. //        • LNotificationTask
  39. // ---------------------------------------------------------------------------
  40.  
  41. LNotificationTask::LNotificationTask(
  42.     StringPtr        inDescriptor,
  43.     ResIDT            inStringID,
  44.     ResIDT            inIconFamilyID,
  45.     Handle            inSoundH,
  46.     Int16            inMark,
  47.     Boolean         inDeleteOnCompletion)
  48.         
  49.         : LTask(0, 0, inDeleteOnCompletion)
  50. {
  51.     Handle        iconHandle = nil;
  52.     
  53.     
  54.     if(inDescriptor != nil) {
  55.     
  56.         ::CopyPStr(inDescriptor, mDescriptor);
  57.     
  58.     } else if(inStringID != 0) {
  59.     
  60.         StringHandle    stringH = ::GetString(inStringID);
  61.         StHandleLocker    locker((Handle)stringH);
  62.         
  63.         ::CopyPStr(*stringH, mDescriptor);
  64.         
  65.     } else {
  66.     
  67.         mDescriptor[0] = 0;
  68.     }
  69.     
  70.     
  71.     if(inIconFamilyID != -1) {
  72.     
  73.         ::GetIconSuite(&iconHandle, inIconFamilyID, svAllSmallData);
  74.     }
  75.     
  76.     mNoteTask.task.nmResp        = sTaskUPP;
  77.     mNoteTask.task.qType        = nmType;
  78.     mNoteTask.task.nmIcon        = iconHandle;
  79.     mNoteTask.task.nmMark        = inMark;
  80.     mNoteTask.task.nmSound        = inSoundH;
  81.     mNoteTask.task.nmRefCon        = 0;
  82.     mNoteTask.task.nmStr        = mDescriptor[0] ? mDescriptor : nil;
  83.     
  84.     
  85. #if !GENERATINGCFM
  86.     mNoteTask.A5World = ::SetCurrentA5();
  87. #endif
  88.     mNoteTask.noteTask = this;
  89.     
  90.     ::GetCurrentProcess(&mApplicationPSN);
  91. }
  92.  
  93.  
  94. // ---------------------------------------------------------------------------
  95. //        • ~LNotificationTask
  96. // ---------------------------------------------------------------------------
  97.  
  98. LNotificationTask::~LNotificationTask()
  99. {
  100.     
  101. }
  102.  
  103.  
  104. // ---------------------------------------------------------------------------
  105. //        • StartTask
  106. // ---------------------------------------------------------------------------
  107.  
  108. void
  109. LNotificationTask::StartTask()
  110. {
  111.     if(!IsExecuting()) {
  112.     
  113.         LTask::StartTask();
  114.         
  115.         mUserHasSeenNote = false;
  116.         ::NMInstall((NMRecPtr)&mNoteTask);
  117.     }
  118. }
  119.  
  120.  
  121. // ---------------------------------------------------------------------------
  122. //        • StopTask
  123. // ---------------------------------------------------------------------------
  124.  
  125. void
  126. LNotificationTask::StopTask()
  127. {
  128.     if(IsExecuting()) {
  129.     
  130.         ::NMRemove((NMRecPtr)&mNoteTask);
  131.         
  132.         LTask::StopTask();
  133.     }
  134. }
  135.  
  136.  
  137. // ---------------------------------------------------------------------------
  138. //        • TaskUPP
  139. // ---------------------------------------------------------------------------
  140.  
  141. pascal void
  142. LNotificationTask::TaskUPP(
  143.     SNoteTaskT    *inNoteTaskPtr)
  144. {
  145. #if !GENERATINGCFM
  146.     Int32    oldA5 = ::SetA5(inNoteTaskPtr->A5World);
  147. #endif
  148.     
  149.     inNoteTaskPtr->noteTask->ExecuteTask();
  150.     
  151. #if !GENERATINGCFM
  152.     ::SetA5(oldA5);
  153. #endif
  154. }
  155.  
  156.  
  157. // ---------------------------------------------------------------------------
  158. //        • ContinueTask
  159. // ---------------------------------------------------------------------------
  160. //    Nothing to do with a notification!!!    
  161.  
  162. void
  163. LNotificationTask::ContinueTask()
  164. {
  165. }
  166.  
  167.  
  168. // ---------------------------------------------------------------------------
  169. //        • StartTaskSelf
  170. // ---------------------------------------------------------------------------
  171. //    Most of the time, with a Notification, there is nothing to do...
  172.  
  173. void
  174. LNotificationTask::StartTaskSelf()
  175. {
  176. }
  177.  
  178.  
  179. // ---------------------------------------------------------------------------
  180. //        • ExecuteTaskSelf
  181. // ---------------------------------------------------------------------------
  182. //    Most of the time, with a Notification, there is nothing to do...
  183.  
  184. void
  185. LNotificationTask::ExecuteTaskSelf(
  186.     Boolean &ioLastCall)
  187. {
  188.     Boolean                sameProcess = false;
  189.     ProcessSerialNumber    currentProcess;
  190.     
  191.     
  192.     ::GetFrontProcess(¤tProcess);
  193.     ::SameProcess(&mApplicationPSN, ¤tProcess, &sameProcess);
  194.     
  195.     if(sameProcess) {
  196.     
  197.         mUserHasSeenNote = true;
  198.         ioLastCall = true;
  199.     
  200.     } else {
  201.     
  202.         StartIdling();
  203.     }
  204. }
  205.  
  206.  
  207. // ---------------------------------------------------------------------------
  208. //        • StopTaskSelf
  209. // ---------------------------------------------------------------------------
  210. //    Most of the time, with a Notification, there is nothing to do...
  211.  
  212. void
  213. LNotificationTask::StopTaskSelf()
  214. {
  215. }
  216.  
  217.  
  218. // ---------------------------------------------------------------------------
  219. //        • SpendTime
  220. // ---------------------------------------------------------------------------
  221.  
  222. void
  223. LNotificationTask::SpendTime(
  224.     const EventRecord &/*inMacEvent*/)
  225. {
  226.     Boolean                sameProcess = false;
  227.     ProcessSerialNumber    currentProcess;
  228.     
  229.     
  230.     ::GetFrontProcess(¤tProcess);
  231.     ::SameProcess(&mApplicationPSN, ¤tProcess, &sameProcess);
  232.     
  233.     if(sameProcess) {
  234.         
  235.         mUserHasSeenNote = true;
  236.         StopTask();
  237.         StopIdling();
  238.     }
  239. }
  240.