home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWOSMisc / Sources / FWCursor.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.7 KB  |  311 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWCursor.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWCURSOR_H
  13. #include "FWCursor.h"
  14. #endif
  15.  
  16. #ifndef FWEXCLIB_H
  17. #include "FWExcLib.h"
  18. #endif
  19.  
  20. #ifndef FWRESFIL_K
  21. #include "FWResFil.k"
  22. #endif
  23.  
  24. #ifndef FWRESFIL_H
  25. #include "FWResFil.h"
  26. #endif
  27.  
  28. #ifndef FWRESTYP_H
  29. #include "FWResTyp.h"
  30. #endif
  31.  
  32. #ifndef FWSTDDEF_H
  33. #include "FWStdDef.h"
  34. #endif
  35.  
  36. #ifndef FWCFMRES_H
  37. #include "FWCFMRes.h"
  38. #endif
  39.  
  40. #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
  41. #include <Resources.h>
  42. #endif
  43.  
  44. #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
  45. #include <ToolUtils.h>
  46. #endif
  47.  
  48. #if defined(FW_BUILD_MAC) && !defined(__LOWMEM__)
  49. #include <LowMem.h>
  50. #endif
  51.  
  52. //========================================================================================
  53. //    Runtime Informations
  54. //========================================================================================
  55.  
  56. #if FW_LIB_EXPORT_PRAGMAS
  57. #pragma lib_export on
  58. #endif
  59.  
  60. #ifdef FW_BUILD_MAC    
  61. #pragma segment fwosmisc
  62. #endif
  63.  
  64. //========================================================================================
  65. // CLASS FW_CCursor
  66. //========================================================================================
  67.  
  68. //----------------------------------------------------------------------------------------
  69. //  FW_CCursor::FW_CCursor 
  70. //----------------------------------------------------------------------------------------
  71. //  Create an arrow cursor
  72.  
  73. FW_CCursor::FW_CCursor() :
  74.     fCursorHandle(NULL),
  75.     fFromSystem(TRUE),
  76.     fCursorID(0),
  77. #ifdef FW_BUILD_WIN
  78.     fDeferred(TRUE),
  79.     fSystemCursorID(IDC_ARROW)
  80. #endif
  81. #ifdef FW_BUILD_MAC
  82.     fDeferred(FALSE),
  83.     fMacIsColor(FALSE)
  84. #endif
  85. {
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. //  FW_CCursor::FW_CCursor 
  90. //----------------------------------------------------------------------------------------
  91. //  Loads (immediatly) the cursor from the specified resources file
  92.  
  93. FW_CCursor::FW_CCursor(FW_CResourceFile& resourceFile,
  94.                        FW_ResourceId resId) :
  95.     fCursorHandle(NULL),
  96.     fDeferred(FALSE)
  97. {
  98.     PrivLoadCursor(resourceFile, resId);
  99.     
  100.     FW_END_CONSTRUCTOR
  101. }
  102.  
  103. #ifdef FW_BUILD_WIN
  104. //----------------------------------------------------------------------------------------
  105. //    FW_CCursor::FW_CCursor
  106. //----------------------------------------------------------------------------------------
  107. //    Loads (differed) the system cursor that has the specified ID.
  108.  
  109. FW_CCursor::FW_CCursor(FW_SystemCursorID systemCursorId) :
  110.     fCursorHandle(NULL),
  111.     fDeferred(TRUE),
  112.     fFromSystem(TRUE),
  113.     fCursorID(0),
  114.     fSystemCursorID(systemCursorId)
  115. {    
  116.     FW_END_CONSTRUCTOR
  117. }
  118. #endif
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CCursor::FW_CCursor
  122. //----------------------------------------------------------------------------------------
  123. //    Loads (differed) a cursor from the system or this dll.
  124.  
  125. FW_CCursor::FW_CCursor(FW_ResourceId resId, FW_Boolean fromSystem) :
  126.     fCursorHandle(NULL),
  127.     fDeferred(TRUE),
  128.     fFromSystem(fromSystem)
  129. #ifdef FW_BUILD_WIN
  130.     ,fSystemCursorID(NULL)
  131. #endif
  132. {
  133.     fCursorID = resId;
  134.  
  135.     FW_END_CONSTRUCTOR
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    FW_CCursor::~FW_CCursor
  140. //----------------------------------------------------------------------------------------
  141.  
  142. FW_CCursor::~FW_CCursor()
  143. {
  144.     FW_START_DESTRUCTOR
  145.     
  146.     if (fCursorHandle != NULL)
  147.     {
  148. #ifdef FW_BUILD_MAC
  149.     if(fMacIsColor)
  150.         ::DisposeCCursor((CCrsrHandle)fCursorHandle);
  151.     else
  152.         ::DisposeHandle((FW_PlatformHandle)fCursorHandle);
  153. #endif
  154. #ifdef FW_BUILD_WIN
  155.     ::DestroyCursor(fCursorHandle);
  156. #endif
  157.     }
  158.     
  159.     fCursorHandle = NULL;
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CCursor::PrivLoadSystemCursor
  164. //----------------------------------------------------------------------------------------
  165. //    Loads the system cursor that has the specified ID.
  166.  
  167. void FW_CCursor::PrivLoadSystemCursor(FW_SystemCursorID systemCursorId)
  168. {
  169.     // do not use the resource component because we're loading from the system
  170.  
  171. #ifdef FW_BUILD_MAC        
  172.     // try a mono cursor first
  173.     fCursorHandle = ::GetCursor(systemCursorId);
  174.     fMacIsColor = FALSE;
  175.  
  176.     if (fCursorHandle == NULL)
  177.     {
  178.         // no mono cursor, try a color cursor
  179.         fCursorHandle = (FW_PlatformCursorHandle) ::GetCCursor(systemCursorId);
  180.         fMacIsColor = TRUE;
  181.     }
  182.  
  183.     if (fCursorHandle == NULL)
  184.     {
  185.         FW_Failure(FW_xResourceNotFound);
  186.     }
  187.     else
  188.     {
  189.         // ----- We need to detache the resource because of CFM -----
  190.         ::DetachResource((FW_PlatformHandle)fCursorHandle);
  191.         ::HNoPurge((FW_PlatformHandle)fCursorHandle);    // The resource may have been tagged purgeable
  192.     }
  193. #endif
  194.  
  195. #ifdef FW_BUILD_WIN
  196.     fCursorHandle = ::LoadCursor(NULL, systemCursorId);
  197.  
  198.     if (fCursorHandle == NULL)
  199.     {
  200.         FW_Failure(FW_xResourceNotFound);
  201.     }
  202. #endif
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    FW_CCursor::PrivLoadCursor
  207. //----------------------------------------------------------------------------------------
  208. //  Loads the cursor from the specified resources file
  209.  
  210. void FW_CCursor::PrivLoadCursor(FW_CResourceFile& resourceFile,
  211.                                    FW_ResourceId resId)
  212. {
  213. #ifdef FW_BUILD_MAC
  214.     if(resourceFile.PrivHasSpecialResource(resId, FW_kCursor))
  215.     {
  216.         fMacIsColor = TRUE;
  217.         fCursorHandle = (FW_PlatformCursorHandle)resourceFile.PrivGetSpecialResource(resId, FW_kCursor);
  218.     }
  219.     else
  220.     {
  221.         fMacIsColor = FALSE;
  222.         fCursorHandle = (FW_PlatformCursorHandle)resourceFile.PrivGetSpecialResource(resId, FW_kBlackWhiteCursor);
  223.     }
  224.     
  225.     // ----- We need to detache the resource because of CFM -----
  226.     ::DetachResource((FW_PlatformHandle)fCursorHandle);
  227.     ::HNoPurge((FW_PlatformHandle)fCursorHandle);    // The resource may have been tagged purgeable
  228. #endif
  229.  
  230. #ifdef FW_BUILD_WIN
  231.     fCursorHandle = (FW_PlatformCursorHandle) resourceFile.PrivGetSpecialResource(resId, FW_kCursor);
  232. #endif
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. // FW_CCursor::Select
  237. //----------------------------------------------------------------------------------------
  238.  
  239. void FW_CCursor::Select() const
  240. {
  241.     FW_CCursor* self = (FW_CCursor*)this;
  242.     self->PrivDeferredLoad();
  243.     
  244. #ifdef FW_BUILD_MAC    
  245.     if (fCursorHandle != NULL)
  246.     {
  247.         if(fMacIsColor)
  248.             ::SetCCursor((CCrsrHandle)fCursorHandle);
  249.         else
  250.             ::SetCursor(*fCursorHandle);
  251.     }
  252.     else
  253.         ::SetCursor(&FW_QDGlobals.arrow);
  254.     
  255. #endif
  256.  
  257. #ifdef FW_BUILD_WIN
  258.     FW_ASSERT(fCursorHandle != NULL);
  259.     ::SetCursor(fCursorHandle);
  260. #endif
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    FW_CCursor::PrivDeferredLoad
  265. //----------------------------------------------------------------------------------------
  266.  
  267. void FW_CCursor::PrivDeferredLoad()
  268. {
  269.     if (fDeferred)
  270.     {
  271. #ifdef FW_BUILD_MAC
  272.         if (fFromSystem)
  273.             PrivLoadSystemCursor(fCursorID);
  274.         else
  275.         {
  276.             FW_CSharedLibraryResourceFile resFile;
  277.             PrivLoadCursor(resFile, fCursorID);
  278.         }
  279. #endif
  280.  
  281. #ifdef FW_BUILD_WIN
  282.         if (fFromSystem)
  283.             PrivLoadSystemCursor(fSystemCursorID);
  284.         else
  285.         {
  286.             FW_CSharedLibraryResourceFile resFile;
  287.             PrivLoadCursor(resFile, fCursorID);
  288.         }
  289. #endif
  290.         fDeferred = FALSE;
  291.     }
  292. }
  293.  
  294. //----------------------------------------------------------------------------------------
  295. //    FW_CCursor::GetHandle
  296. //----------------------------------------------------------------------------------------
  297. // On the Mac returns NULL for this arrow cursor
  298.  
  299. FW_PlatformCursorHandle FW_CCursor::GetHandle() const
  300. {
  301.     FW_CCursor* self = (FW_CCursor*)this;
  302.     self->PrivDeferredLoad();
  303.  
  304. #ifdef FW_BUILD_WIN
  305.     FW_ASSERT(fCursorHandle);
  306. #endif
  307.     
  308.     return fCursorHandle;
  309. }
  310.  
  311.