home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / LProgressIndicator & Friends / LAnimateCursor / LCursor.cp < prev    next >
Encoding:
Text File  |  1996-04-20  |  1.6 KB  |  118 lines  |  [TEXT/CWIE]

  1. #pragma once
  2. /*
  3.     File:        LCursor.cp
  4.     
  5.     Contains:    Base cursor class.
  6.                 LCursor framework.
  7.  
  8.     Copyright:    ©1995 Chris K. Thomas.  All Rights Reserved.
  9.  
  10.     Version:    2.1
  11. */
  12.  
  13. #include "LCursor.h"
  14.  
  15. //
  16. // • static member variables
  17. //
  18.  
  19. Boolean        LCursor::sCursorLocked = false;
  20. LCursor        *LCursor::sCurrentCursor = NULL;
  21.  
  22. //
  23. // construct
  24. //
  25. LCursor::LCursor(UInt16 inCursorID)
  26. {
  27.     mIsColor = false;
  28.     if(inCursorID == 0)
  29.     {
  30.         mCursorHandle = NULL;
  31.     }
  32.     else
  33.     {
  34.         short resLoad = ::LMGetResLoad();
  35.         
  36.         //
  37.         // ≠ mess to check whether or not a color version of the
  38.         // cursor exists
  39.         //
  40.         
  41.         ::SetResLoad(false);
  42.         mCursorHandle = ::GetResource('crsr', inCursorID);
  43.         ::SetResLoad(resLoad);
  44.         if(mCursorHandle)
  45.         {
  46.             mIsColor = true;
  47.             ::ReleaseResource(mCursorHandle);
  48.             //
  49.             // ≠ end mess
  50.             //
  51.             
  52.             mCursorHandle = (Handle)::GetCCursor(inCursorID);
  53.         }
  54.         else
  55.             mCursorHandle = ::GetResource('CURS', inCursorID);
  56.         
  57.         ThrowIfResError_();
  58.         Assert_(mCursorHandle);
  59.     }
  60.     
  61. }
  62.  
  63. LCursor::~LCursor()
  64. {
  65.     if(mCursorHandle)
  66.     {
  67.         if(!mIsColor)
  68.             ::ReleaseResource(mCursorHandle);
  69.         else
  70.             ::DisposeCCursor((CCrsrHandle)mCursorHandle);
  71.     }
  72.         
  73.     if(sCurrentCursor == this)
  74.     {
  75.         sCurrentCursor = NULL;
  76.     }
  77. }
  78.  
  79.  
  80. //
  81. // use
  82. //
  83.  
  84. void
  85. LCursor::Set()
  86. {
  87.     if(mCursorHandle)
  88.     {
  89.         HLockHi((Handle)mCursorHandle);
  90.         
  91.         //
  92.         // take care of the previously current cursor
  93.         //
  94.         if(sCurrentCursor)
  95.             sCurrentCursor->Unset();
  96.         
  97.         sCurrentCursor = this;
  98.         
  99.         if(!mIsColor)
  100.             SetCursor(*(CursHandle)mCursorHandle);
  101.         else
  102.             SetCCursor((CCrsrHandle)mCursorHandle);
  103.     }
  104.     else
  105.     {
  106.         InitCursor();
  107.     }
  108. }
  109.  
  110. void
  111. LCursor::Unset()
  112. {
  113.     if(mCursorHandle)
  114.     {
  115.         HUnlock((Handle)mCursorHandle);
  116.     }
  117. }
  118.