home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Ports / mac / cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-06  |  3.2 KB  |  138 lines  |  [TEXT/????]

  1. /* MAC STDWIN -- MOUSE CURSORS. */
  2.  
  3. /* XXX Shouldn't named resources override the defaults? */
  4.  
  5. #include "macwin.h"
  6. #ifdef MPW
  7. #include <ToolUtils.h>
  8. #endif
  9. #ifdef THINK_C_PRE_5_0
  10. #include <ToolboxUtil.h>
  11. #endif
  12.  
  13. extern CursPtr handcursorptr;
  14.  
  15. /* Fetch a cursor by name.  This really returns a resource handle,
  16.    cast to the mythical type CURSOR *.
  17.    If no resource by that name exists, some standard cursors may
  18.    be returned. */
  19.  
  20. CURSOR *
  21. wfetchcursor(name)
  22.     char *name;
  23. {
  24.     CursHandle h = (CursHandle) GetNamedResource('CURS', name);
  25.     if (h == NULL) {
  26.         if (strcmp(name, "ibeam") == 0)
  27.             h = GetCursor(iBeamCursor);
  28.         else if (strcmp(name, "cross") == 0)
  29.             h = GetCursor(crossCursor);
  30.         else if (strcmp(name, "plus") == 0)
  31.             h = GetCursor(plusCursor);
  32.         else if (strcmp(name, "watch") == 0)
  33.             h = GetCursor(watchCursor);
  34. #if 0
  35.         else if (strcmp(name, "arrow") == 0) {
  36.             /* The arrow is only a quickdraw global,
  37.                which we can't use.
  38.                Should have it as a static variable... */
  39.             static CursPtr arrowptr;
  40.             arrowptr = &QD(arrow);
  41.             h = &arrowptr;
  42.         }
  43. #endif
  44.         else if (strcmp(name, "hand") == 0) {
  45.             /* The hand is hardcoded below */
  46.             h = &handcursorptr;
  47.         }
  48.     }
  49.     return (CURSOR *)h;
  50. }
  51.  
  52. void
  53. wsetwincursor(win, cursor)
  54.     WINDOW *win;
  55.     CURSOR *cursor;
  56. {
  57.     win->cursor = cursor;
  58.     if (win == active)
  59.         set_applcursor();
  60. }
  61.  
  62. /* Set the mouse cursor shape to the standard arrow.
  63.    This shape is used when the program is ready for input without
  64.    having the active window. */
  65.  
  66. void
  67. set_arrow()
  68. {
  69.     InitCursor();
  70. }
  71.  
  72. /* Set the mouse cursor shape to the standard watch.
  73.    This shape is used when a long task is being performed.
  74.    In practice always between two calls to wgetevent()
  75.    except when the mouse is down.
  76.    Note: this call is ignored when the application has
  77.    specified a cursor for the window; in this case it
  78.    is up to the application to set an arrow when it goes
  79.    away for a long time. */
  80.  
  81. void
  82. set_watch()
  83. {
  84.     if (active == NULL || active->cursor == NULL)
  85.         SetCursor(*GetCursor(watchCursor));
  86. }
  87.  
  88. /* Set the cursor to the standard cursor for the active window.
  89.    If there is no active window, use an arrow.
  90.    If a cursor is specified for the active window, use that,
  91.    otherwise use a default.
  92.    The default is normally a crosshair but can be changed by
  93.    setting the global variable _w_cursor to a cursor ID. */
  94.  
  95. int _w_cursor= crossCursor;
  96.  
  97. void
  98. set_applcursor()
  99. {
  100.     if (active == NULL)
  101.         set_arrow();
  102.     else if (active->cursor == NULL)
  103.         SetCursor(*GetCursor(_w_cursor));
  104.     else {
  105.         CursHandle h = (CursHandle) active->cursor;
  106.         if (*h == NULL)
  107.             LoadResource((Handle)h);
  108.         SetCursor(*h);
  109.     }
  110. }
  111.  
  112. /* Set the mouse cursor shape to a little hand icon.
  113.    This shape is used when scroll-dragging the document. */
  114.  
  115. static Cursor handcursor= {
  116.     {    /* Data: */
  117.         0x0180, 0x1a70, 0x2648, 0x264a, 
  118.         0x124d, 0x1249, 0x6809, 0x9801, 
  119.         0x8802, 0x4002, 0x2002, 0x2004, 
  120.         0x1004, 0x0808, 0x0408, 0x0408,
  121.     },
  122.     {    /* Mask: */
  123.         0x0180, 0x1bf0, 0x3ff8, 0x3ffa, 
  124.         0x1fff, 0x1fff, 0x7fff, 0xffff, 
  125.         0xfffe, 0x7ffe, 0x3ffe, 0x3ffc, 
  126.         0x1ffc, 0x0ff8, 0x07f8, 0x07f8,
  127.     },
  128.     {8, 8}    /* Hotspot */
  129. };
  130.  
  131. static CursPtr handcursorptr = &handcursor; /* For wfetchcursor */
  132.  
  133. void
  134. set_hand()
  135. {
  136.     SetCursor(&handcursor);
  137. }
  138.