home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.002 / stk-3 / STk-3.1 / Tk / win / tkWinCursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-17  |  5.2 KB  |  218 lines

  1. /* 
  2.  * tkWinCursor.c --
  3.  *
  4.  *    This file contains Win32 specific cursor related routines.
  5.  *
  6.  * Copyright (c) 1995 Sun Microsystems, Inc.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * SCCS: @(#) tkWinCursor.c 1.6 96/02/15 18:56:06
  12.  */
  13.  
  14. #include "tkWinInt.h"
  15.  
  16. /*
  17.  * The following data structure contains the system specific data
  18.  * necessary to control Windows cursors.
  19.  */
  20.  
  21. typedef struct {
  22.     TkCursor info;        /* Generic cursor info used by tkCursor.c */
  23.     HCURSOR winCursor;        /* Win32 cursor handle. */
  24.     int system;            /* 1 if cursor is a system cursor, else 0. */
  25. } TkWinCursor;
  26.  
  27. /*
  28.  * The table below is used to map from the name of a predefined cursor
  29.  * to its resource identifier.
  30.  */
  31.  
  32. static struct CursorName {
  33.     char *name;
  34.     LPCTSTR id;
  35. } cursorNames[] = {
  36.     {"starting",        IDC_APPSTARTING},
  37.     {"arrow",            IDC_ARROW},
  38.     {"ibeam",            IDC_IBEAM},
  39.     {"icon",            IDC_ICON},
  40.     {"no",            IDC_NO},
  41.     {"size",            IDC_SIZE},
  42.     {"size_ne_sw",        IDC_SIZENESW},
  43.     {"size_ns",            IDC_SIZENS},
  44.     {"size_nw_se",        IDC_SIZENWSE},
  45.     {"size_we",            IDC_SIZEWE},
  46.     {"uparrow",            IDC_UPARROW},
  47.     {"wait",            IDC_WAIT},
  48.     {"crosshair",        IDC_CROSS},
  49.     {"fleur",            IDC_SIZE},
  50.     {"sb_v_double_arrow",    IDC_SIZENS},
  51.     {"sb_h_double_arrow",    IDC_SIZEWE},
  52.     {"center_ptr",        IDC_UPARROW},
  53.     {"watch",            IDC_WAIT},
  54.     {"xterm",            IDC_IBEAM},
  55.     {NULL,            0}
  56. };
  57.  
  58. /*
  59.  * The default cursor is used whenever no other cursor has been specified.
  60.  */
  61.  
  62. #define TK_DEFAULT_CURSOR    IDC_ARROW
  63.  
  64.  
  65. /*
  66.  *----------------------------------------------------------------------
  67.  *
  68.  * TkGetCursorByName --
  69.  *
  70.  *    Retrieve a system cursor by name.  
  71.  *
  72.  * Results:
  73.  *    Returns a new cursor, or NULL on errors.  
  74.  *
  75.  * Side effects:
  76.  *    Allocates a new cursor.
  77.  *
  78.  *----------------------------------------------------------------------
  79.  */
  80.  
  81. TkCursor *
  82. TkGetCursorByName(interp, tkwin, string)
  83.     Tcl_Interp *interp;        /* Interpreter to use for error reporting. */
  84.     Tk_Window tkwin;        /* Window in which cursor will be used. */
  85.     Tk_Uid string;        /* Description of cursor.  See manual entry
  86.                  * for details on legal syntax. */
  87. {
  88.     struct CursorName *namePtr;
  89.     TkWinCursor *cursorPtr;
  90.  
  91.     /*
  92.      * Check for the cursor in the system cursor set.
  93.      */
  94.  
  95.     for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
  96.     if (strcmp(namePtr->name, string) == 0) {
  97.         break;
  98.     }
  99.     }
  100.  
  101.     cursorPtr = (TkWinCursor *) ckalloc(sizeof(TkWinCursor));
  102.     cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;
  103.     if (namePtr->name != NULL) {
  104.     cursorPtr->winCursor = LoadCursor(NULL, namePtr->id);
  105.     cursorPtr->system = 1;
  106.     } else {
  107.     cursorPtr->winCursor = LoadCursor(TkWinGetTkModule(), string);
  108.     cursorPtr->system = 0;
  109.     }
  110.     if (cursorPtr->winCursor == NULL) {
  111.     ckfree((char *)cursorPtr);
  112.     Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
  113.         (char *) NULL);
  114.     return NULL;
  115.     } else {
  116.     return (TkCursor *) cursorPtr;
  117.     }
  118. }
  119.  
  120. /*
  121.  *----------------------------------------------------------------------
  122.  *
  123.  * TkCreateCursorFromData --
  124.  *
  125.  *    Creates a cursor from the source and mask bits.
  126.  *
  127.  * Results:
  128.  *    Returns a new cursor, or NULL on errors.
  129.  *
  130.  * Side effects:
  131.  *    Allocates a new cursor.
  132.  *
  133.  *----------------------------------------------------------------------
  134.  */
  135.  
  136. TkCursor *
  137. TkCreateCursorFromData(tkwin, source, mask, width, height, xHot, yHot,
  138.     fgColor, bgColor)
  139.     Tk_Window tkwin;        /* Window in which cursor will be used. */
  140.     char *source;        /* Bitmap data for cursor shape. */
  141.     char *mask;            /* Bitmap data for cursor mask. */
  142.     int width, height;        /* Dimensions of cursor. */
  143.     int xHot, yHot;        /* Location of hot-spot in cursor. */
  144.     XColor fgColor;        /* Foreground color for cursor. */
  145.     XColor bgColor;        /* Background color for cursor. */
  146. {
  147.     return NULL;
  148. }
  149.  
  150. /*
  151.  *----------------------------------------------------------------------
  152.  *
  153.  * TkFreeCursor --
  154.  *
  155.  *    This procedure is called to release a cursor allocated by
  156.  *    TkGetCursorByName.
  157.  *
  158.  * Results:
  159.  *    None.
  160.  *
  161.  * Side effects:
  162.  *    The cursor data structure is deallocated.
  163.  *
  164.  *----------------------------------------------------------------------
  165.  */
  166.  
  167. void
  168. TkFreeCursor(cursorPtr)
  169.     TkCursor *cursorPtr;
  170. {
  171.     TkWinCursor *winCursorPtr = (TkWinCursor *) cursorPtr;
  172.     ckfree((char *) winCursorPtr);
  173. }
  174.  
  175. /*
  176.  *----------------------------------------------------------------------
  177.  *
  178.  * TkWinUpdateCursor --
  179.  *
  180.  *    Set the windows global cursor to the cursor associated with
  181.  *    the given Tk window.
  182.  *
  183.  * Results:
  184.  *    None.
  185.  *
  186.  * Side effects:
  187.  *    Changes the mouse cursor.
  188.  *
  189.  *----------------------------------------------------------------------
  190.  */
  191.  
  192. void
  193. TkWinUpdateCursor(winPtr)
  194.     TkWindow *winPtr;
  195. {
  196.     HCURSOR cursor = NULL;
  197.  
  198.     /*
  199.      * A window inherits its cursor from its parent if it doesn't
  200.      * have one of its own.  Top level windows inherit the default
  201.      * cursor.
  202.      */
  203.  
  204.     while (winPtr != NULL) {
  205.     if (winPtr->atts.cursor != None) {
  206.         cursor = ((TkWinCursor *) winPtr->atts.cursor)->winCursor;
  207.         break;
  208.     } else if (winPtr->flags & TK_TOP_LEVEL) {
  209.         cursor = LoadCursor(NULL, TK_DEFAULT_CURSOR);
  210.         break;
  211.     }
  212.     winPtr = winPtr->parentPtr;
  213.     }
  214.     if (cursor != NULL) {
  215.     SetCursor(cursor);
  216.     }
  217. }
  218.