home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / asyncCursors.c next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.5 KB  |  192 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "client.h"
  20. #include "java.h"
  21.  
  22. #if defined(XP_MAC)
  23.  
  24. #include "asyncCursors.h"
  25.  
  26. /* private prototypes, so that this compiles without warnings. */
  27. static OSErr initAsyncCursors();
  28. static void spinCursor(acurHandle cursorsH);
  29. #if defined(powerc) || defined(__powerc)
  30. static void asyncCursorTask(VBLTaskWithA5Ptr theTaskPtr);
  31. #else
  32. static void asyncCursorTask(VBLTaskWithA5Ptr theTaskPtr:__A0);
  33. #endif
  34.  
  35.  
  36.         Boolean            taskInstalled = FALSE;
  37.         acurHandle        cursorsH = NULL;
  38.         VBLTaskWithA5Ptr    cursorTask = NULL;
  39.  
  40.  
  41.  
  42. OSErr
  43. initAsyncCursors()
  44. {
  45.         CursHandle        *workPtr;
  46.         OSErr            err = noErr;
  47.         short            cursorCount;
  48.  
  49.     if (cursorsH == NULL)    {                        // only initialize once
  50.         cursorsH = (acurHandle)GetResource('acur', ACUR_RESID);
  51.         if (cursorsH != NULL)    {
  52.             HNoPurge((Handle)cursorsH);
  53.             HUnlock((Handle)cursorsH);
  54.             HLockHi((Handle)cursorsH);
  55.             DetachResource((Handle)cursorsH);
  56.             cursorCount=(**cursorsH).numCursors;
  57.             (**cursorsH).index=0;
  58.             workPtr=(**cursorsH).cursors;
  59.             while(cursorCount--)    {
  60.                 *workPtr = (CursHandle)GetResource('CURS',*(short *)workPtr);
  61.                 if (*workPtr != NULL)    {
  62.                     HNoPurge((Handle)*workPtr);
  63.                     HUnlock((Handle)*workPtr);
  64.                     HLockHi((Handle)*workPtr);
  65.                     DetachResource((Handle)*workPtr);
  66.                     }
  67.                 ++workPtr;
  68.                 }
  69.             }
  70.         else    {
  71.             err = (err=ResError()) ? err:resNotFound;
  72.             }
  73.         }
  74.     return(err);
  75. }
  76.  
  77.  
  78.  
  79. void
  80. spinCursor(acurHandle cursorsH)
  81. {
  82.         short        nextIndex,theIndex;
  83.  
  84.     if (cursorsH != NULL)    {
  85.         theIndex = (**cursorsH).index;
  86.         nextIndex = theIndex + 1;
  87.         if (nextIndex >= (**cursorsH).numCursors)    {
  88.             nextIndex = 0;
  89.             }
  90.         (**cursorsH).index = nextIndex;
  91.         if ((**cursorsH).cursors[theIndex])    {
  92.             SetCursor(*(**cursorsH).cursors[theIndex]);
  93.             }
  94.         }
  95. }
  96.  
  97.  
  98.  
  99. #if defined(powerc) || defined(__powerc)
  100.  
  101. void
  102. asyncCursorTask(VBLTaskWithA5Ptr theTaskPtr)
  103.  
  104. #else
  105.  
  106. void
  107. asyncCursorTask(VBLTaskWithA5Ptr theTaskPtr:__A0)
  108. #endif
  109.  
  110. {
  111. #if defined(powerc) || defined(__powerc)
  112. #else
  113.         long        oldA5;
  114. #endif
  115.     if (LMGetCrsrBusy() == 0)    {
  116.  
  117. #if defined(powerc) || defined(__powerc)
  118. #else
  119.         oldA5 = SetA5(theTaskPtr->theA5);
  120. #endif
  121.         spinCursor(theTaskPtr->cursorsH);
  122.         theTaskPtr->theTask.vblCount = SPIN_CYCLE;
  123.         if (--cursorTask->numSpins <= 0)    {        // max spin time expired, stop spinning
  124.             (void)VRemove((QElemPtr)cursorTask);
  125.             taskInstalled = FALSE;
  126.             }
  127.  
  128. #if defined(powerc) || defined(__powerc)
  129. #else
  130.         (void)SetA5(oldA5);
  131. #endif
  132.         
  133.         }
  134. }
  135.  
  136.  
  137.  
  138. void
  139. startAsyncCursors()
  140. {
  141.     if (initAsyncCursors() != noErr)    return;
  142. //    if (LJ_GetJavaStatus() != LJJavaStatus_Enabled)    return;        // java enabled but not running?
  143.  
  144.     if (cursorTask == NULL)    {
  145.         cursorTask = (VBLTaskWithA5Ptr)NewPtrClear(sizeof(VBLTaskWithA5));
  146.         if (cursorTask != NULL)    {
  147.             cursorTask->theTask.qType = vType;
  148.             cursorTask->theTask.vblAddr = (void *)NewVBLProc(asyncCursorTask);
  149.             cursorTask->theTask.vblCount = SPIN_CYCLE;
  150.             cursorTask->theTask.vblPhase = 0;
  151.             cursorTask->theA5 = (long)LMGetCurrentA5();
  152.             cursorTask->cursorsH = cursorsH;
  153.             cursorTask->numSpins = MAX_NUM_SPINS;
  154.             
  155.             if (VInstall((QElemPtr)cursorTask) == noErr)    {
  156.                 taskInstalled = TRUE;
  157.                 }
  158.             else    {
  159.                 taskInstalled = FALSE;
  160.                 if (cursorTask->theTask.vblAddr)    {
  161.                     DisposeRoutineDescriptor(cursorTask->theTask.vblAddr);
  162.                     }
  163.                 DisposePtr((Ptr)cursorTask);
  164.                 cursorTask = NULL;
  165.                 }
  166.             }
  167.         }
  168. }
  169.  
  170.  
  171.  
  172. void
  173. stopAsyncCursors()
  174. {
  175.     if (cursorTask)    {
  176.         if (taskInstalled == TRUE)    {
  177.             (void)VRemove((QElemPtr)cursorTask);
  178.             taskInstalled = FALSE;
  179.             }
  180.         if (cursorTask->theTask.vblAddr)    {
  181.             DisposeRoutineDescriptor(cursorTask->theTask.vblAddr);
  182.             }
  183.         DisposePtr((Ptr)cursorTask);
  184.         cursorTask = NULL;
  185.         InitCursor();
  186.         }
  187. }
  188.  
  189.  
  190.  
  191. #endif
  192.