home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2s.zip / tk4.2 / os2 / tkOS2Cursor.c < prev    next >
C/C++ Source or Header  |  1999-07-26  |  9KB  |  312 lines

  1. /* 
  2.  * tkOS2Cursor.c --
  3.  *
  4.  *    This file contains OS/2 PM specific cursor related routines.
  5.  *    Note: cursors for the mouse are called "POINTER" in Presentation
  6.  *    Manager, those in text are "CURSOR".
  7.  *
  8.  * Copyright (c) 1996-1998 Illya Vaes
  9.  * Copyright (c) 1995 Sun Microsystems, Inc.
  10.  *
  11.  * See the file "license.terms" for information on usage and redistribution
  12.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  */
  14.  
  15.  
  16. #include "tkOS2Int.h"
  17.  
  18. /*
  19.  * The following data structure contains the system specific data
  20.  * necessary to control OS/2 PM pointers.
  21.  */
  22.  
  23. typedef struct {
  24.     TkCursor info;        /* Generic cursor info used by tkCursor.c */
  25.     HPOINTER OS2Pointer;    /* OS/2 PM pointer handle */
  26.     int system;            /* 1 if cursor is a system cursor, else 0. */
  27. } TkOS2Cursor;
  28.  
  29. /*
  30.  * The table below is used to map from the name of a predefined cursor
  31.  * to its resource identifier.
  32.  */
  33.  
  34. static struct CursorName {
  35.     char *name;
  36.     LONG id;
  37. } cursorNames[] = {
  38. /*    {"X_cursor",        SPTR_ARROW}, */
  39.     {"arrow",            SPTR_ARROW},
  40. /*    {"based_arrow_down",    SPTR_SIZENS}, */
  41. /*    {"based_arrow_up",        SPTR_SIZENS}, */
  42. /*    {"bottom_left_corner",    SPTR_SIZENESW}, */
  43. /*    {"bottom_right_corner",    SPTR_SIZENWSE}, */
  44. /*    {"bottom_side",        SPTR_SIZENS}, */
  45. /*    {"bottom_tee",        SPTR_SIZENS}, */
  46. /*    {"center_ptr",        SPTR_MOVE}, */
  47. /*    {"clock",            SPTR_WAIT}, */
  48. /*    {"cross",            SPTR_ARROW}, */
  49. /*    {"cross_reverse",        SPTR_ARROW}, */
  50. /*    {"crosshair",        SPTR_TEXT}, */
  51. /*    {"diamond_cross",        SPTR_ARROW}, */
  52.     {"double_arrow",        SPTR_SIZEWE},
  53.     {"fleur",            SPTR_MOVE},
  54.     {"ibeam",            SPTR_TEXT},
  55.     {"left_ptr",        SPTR_ARROW},
  56.     {"left_side",        SPTR_SIZEWE},
  57.     {"left_tee",        SPTR_SIZEWE},
  58. /*    {"mouse",            SPTR_ARROW}, */
  59.     {"no",            SPTR_ILLEGAL},
  60. /*    {"plus",            SPTR_ARROW}, */
  61. /*    {"question_arrow",        SPTR_QUESICON}, */
  62. /*    {"right_ptr",        SPTR_SIZEWE}, */
  63. /*    {"right_side",        SPTR_SIZEWE}, */
  64. /*    {"right_tee",        SPTR_SIZEWE}, */
  65. /*    {"sb_down_arrow",        SPTR_SIZENS}, */
  66.     {"sb_h_double_arrow",    SPTR_SIZEWE},
  67. /*    {"sb_left_arrow",        SPTR_SIZEWE}, */
  68. /*    {"sb_right_arrow",        SPTR_SIZEWE}, */
  69. /*    {"sb_up_arrow",        SPTR_SIZENS}, */
  70.     {"sb_v_double_arrow",    SPTR_SIZENS},
  71.     {"size_nw_se",        SPTR_SIZENWSE},
  72.     {"size_ne_sw",        SPTR_SIZENESW},
  73.     {"size",            SPTR_MOVE},
  74.     {"starting",        SPTR_WAIT},
  75. /*    {"target",            SPTR_SIZE}, */
  76. /*    {"tcross",            SPTR_ARROW}, */
  77. /*    {"top_left_arrow",        SPTR_ARROW}, */
  78. /*    {"top_left_corner",        SPTR_SIZENWSE}, */
  79. /*    {"top_right_corner",    SPTR_SIZENESW}, */
  80. /*    {"top_side",        SPTR_SIZENS}, */
  81. /*    {"top_tee",            SPTR_SIZENS}, */
  82. /*    {"ul_angle",        SPTR_SIZENWSE}, */
  83.     {"uparrow",            SPTR_SIZENS},
  84. /*    {"ur_angle",        SPTR_SIZENESW}, */
  85.     {"watch",            SPTR_WAIT},
  86.     {"wait",            SPTR_WAIT},
  87.     {"xterm",            SPTR_TEXT},
  88.     /* cursors without moderately reasonable equivalents: question mark icon */
  89. /*
  90.     {"boat",            SPTR_QUESICON},
  91.     {"bogosity",        SPTR_QUESICON},
  92.     {"box_spiral",        SPTR_QUESICON},
  93.     {"circle",            SPTR_QUESICON},
  94.     {"coffee_mug",        SPTR_QUESICON},
  95.     {"dot",            SPTR_QUESICON},
  96.     {"dotbox",            SPTR_QUESICON},
  97.     {"draft_large",        SPTR_QUESICON},
  98.     {"draft_small",        SPTR_QUESICON},
  99.     {"draped_box",        SPTR_QUESICON},
  100.     {"exchange",        SPTR_QUESICON},
  101.     {"gobbler",            SPTR_QUESICON},
  102.     {"gumby",            SPTR_QUESICON},
  103.     {"hand1",            SPTR_QUESICON},
  104.     {"hand2",            SPTR_QUESICON},
  105.     {"heart",            SPTR_QUESICON},
  106.     {"icon",            SPTR_QUESICON},
  107.     {"iron_cross",        SPTR_QUESICON},
  108.     {"leftbutton",        SPTR_QUESICON},
  109.     {"ll_angle",        SPTR_QUESICON},
  110.     {"lr_angle",        SPTR_QUESICON},
  111.     {"man",            SPTR_QUESICON},
  112.     {"middlebutton",        SPTR_QUESICON},
  113.     {"pencil",            SPTR_QUESICON},
  114.     {"pirate",            SPTR_QUESICON},
  115.     {"rightbutton",        SPTR_QUESICON},
  116.     {"rtl_logo",        SPTR_QUESICON},
  117.     {"sailboat",        SPTR_QUESICON},
  118.     {"shuttle",            SPTR_QUESICON},
  119.     {"spider",            SPTR_QUESICON},
  120.     {"spraycan",        SPTR_QUESICON},
  121.     {"star",            SPTR_QUESICON},
  122.     {"trek",            SPTR_QUESICON},
  123.     {"umbrella",        SPTR_QUESICON},
  124. */
  125.     {NULL,            0}
  126. };
  127. /* Include cursors; done by Ilya Zakharevich */
  128. #include "rc/cursors.h"
  129.  
  130. /*
  131.  * The default cursor is used whenever no other cursor has been specified.
  132.  */
  133.  
  134. #define TK_DEFAULT_CURSOR    SPTR_ARROW
  135.  
  136.  
  137. /*
  138.  *----------------------------------------------------------------------
  139.  *
  140.  * TkGetCursorByName --
  141.  *
  142.  *    Retrieve a system cursor by name.  
  143.  *
  144.  * Results:
  145.  *    Returns a new cursor, or NULL on errors.  
  146.  *
  147.  * Side effects:
  148.  *    Allocates a new cursor.
  149.  *
  150.  *----------------------------------------------------------------------
  151.  */
  152.  
  153. TkCursor *
  154. TkGetCursorByName(interp, tkwin, string)
  155.     Tcl_Interp *interp;        /* Interpreter to use for error reporting. */
  156.     Tk_Window tkwin;        /* Window in which cursor will be used. */
  157.     Tk_Uid string;        /* Description of cursor.  See manual entry
  158.                  * for details on legal syntax. */
  159. {
  160.     struct CursorName *namePtr;
  161.     TkOS2Cursor *cursorPtr;
  162.  
  163.     /*
  164.      * Check for the cursor in the system cursor set.
  165.      */
  166.  
  167.     for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
  168.     if (strcmp(namePtr->name, string) == 0) {
  169.         break;
  170.     }
  171.     }
  172.  
  173.     cursorPtr = (TkOS2Cursor *) ckalloc(sizeof(TkOS2Cursor));
  174.     cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;
  175.     if (namePtr->name != NULL) {
  176.     /* Found a system cursor, make a reference (not a copy) */
  177.     cursorPtr->OS2Pointer = WinQuerySysPointer(HWND_DESKTOP, namePtr->id,
  178.                                                FALSE);
  179.     cursorPtr->system = 1;
  180.     } else {
  181.     myCursor *curPtr = cursors;
  182.  
  183.     /* Added X-derived cursors by Ilya Zakharevich */
  184.     cursorPtr->system = 0;
  185.     while (curPtr->name) {
  186.         if (strcmp(curPtr->name, string) == 0) {
  187.             break;
  188.         }
  189.         curPtr++;
  190.     }
  191.     if (curPtr->name &&
  192.         (cursorPtr->OS2Pointer = WinLoadPointer(HWND_DESKTOP,
  193.                                                 TkOS2GetTkModule(),
  194.                                                 curPtr->id))
  195.             != NULLHANDLE) {
  196.            cursorPtr->system = 0;
  197.         } else {
  198.         /* Not a known cursor */
  199.         cursorPtr->OS2Pointer = NULLHANDLE;
  200.         cursorPtr->system = 1;
  201.         }
  202.     }
  203.     if (cursorPtr->OS2Pointer == NULLHANDLE) {
  204.     ckfree((char *)cursorPtr);
  205.     Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
  206.         (char *) NULL);
  207.     return NULL;
  208.     } else {
  209.     return (TkCursor *) cursorPtr;
  210.     }
  211. }
  212.  
  213. /*
  214.  *----------------------------------------------------------------------
  215.  *
  216.  * TkCreateCursorFromData --
  217.  *
  218.  *    Creates a cursor from the source and mask bits.
  219.  *
  220.  * Results:
  221.  *    Returns a new cursor, or NULL on errors.
  222.  *
  223.  * Side effects:
  224.  *    Allocates a new cursor.
  225.  *
  226.  *----------------------------------------------------------------------
  227.  */
  228.  
  229. TkCursor *
  230. TkCreateCursorFromData(tkwin, source, mask, width, height, xHot, yHot,
  231.     fgColor, bgColor)
  232.     Tk_Window tkwin;        /* Window in which cursor will be used. */
  233.     char *source;        /* Bitmap data for cursor shape. */
  234.     char *mask;            /* Bitmap data for cursor mask. */
  235.     int width, height;        /* Dimensions of cursor. */
  236.     int xHot, yHot;        /* Location of hot-spot in cursor. */
  237.     XColor fgColor;        /* Foreground color for cursor. */
  238.     XColor bgColor;        /* Background color for cursor. */
  239. {
  240.     return NULL;
  241. }
  242.  
  243. /*
  244.  *----------------------------------------------------------------------
  245.  *
  246.  * TkFreeCursor --
  247.  *
  248.  *    This procedure is called to release a cursor allocated by
  249.  *    TkGetCursorByName.
  250.  *
  251.  * Results:
  252.  *    None.
  253.  *
  254.  * Side effects:
  255.  *    The cursor data structure is deallocated.
  256.  *
  257.  *----------------------------------------------------------------------
  258.  */
  259.  
  260. void
  261. TkFreeCursor(cursorPtr)
  262.     TkCursor *cursorPtr;
  263. {
  264.     TkOS2Cursor *OS2PointerPtr = (TkOS2Cursor *) cursorPtr;
  265.     rc = WinDestroyPointer(OS2PointerPtr->OS2Pointer);
  266.     ckfree((char *) OS2PointerPtr);
  267. }
  268.  
  269. /*
  270.  *----------------------------------------------------------------------
  271.  *
  272.  * TkOS2UpdateCursor --
  273.  *
  274.  *    Set the PM global cursor to the cursor associated with the given
  275.  *      Tk window.
  276.  *
  277.  * Results:
  278.  *    None.
  279.  *
  280.  * Side effects:
  281.  *    Changes the mouse cursor.
  282.  *
  283.  *----------------------------------------------------------------------
  284.  */
  285.  
  286. void
  287. TkOS2UpdateCursor(winPtr)
  288.     TkWindow *winPtr;
  289. {
  290.     HPOINTER cursor = NULLHANDLE;
  291.  
  292.     /*
  293.      * A window inherits its cursor from its parent if it doesn't
  294.      * have one of its own.  Top level windows inherit the default
  295.      * cursor.
  296.      */
  297.  
  298.     while (winPtr != NULL) {
  299.     if (winPtr->atts.cursor != None) {
  300.         cursor = ((TkOS2Cursor *) (winPtr->atts.cursor))->OS2Pointer;
  301.         break;
  302.     } else if (winPtr->flags & TK_TOP_LEVEL) {
  303.         cursor = WinQuerySysPointer(HWND_DESKTOP, TK_DEFAULT_CURSOR, FALSE);
  304.         break;
  305.     }
  306.     winPtr = winPtr->parentPtr;
  307.     }
  308.     if (cursor != NULLHANDLE) {
  309.     WinSetPointer(HWND_DESKTOP, cursor);
  310.     }
  311. }
  312.