home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcltk805.zip / tcl805s.zip / tk8.0.5 / os2 / tkOS2Cursor.c < prev    next >
C/C++ Source or Header  |  2000-07-12  |  10KB  |  348 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-2000 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. static HPOINTER defCursor = NULLHANDLE;
  136.  
  137.  
  138. /*
  139.  *----------------------------------------------------------------------
  140.  *
  141.  * TkGetCursorByName --
  142.  *
  143.  *    Retrieve a system cursor by name.  
  144.  *
  145.  * Results:
  146.  *    Returns a new cursor, or NULL on errors.  
  147.  *
  148.  * Side effects:
  149.  *    Allocates a new cursor.
  150.  *
  151.  *----------------------------------------------------------------------
  152.  */
  153.  
  154. TkCursor *
  155. TkGetCursorByName(interp, tkwin, string)
  156.     Tcl_Interp *interp;        /* Interpreter to use for error reporting. */
  157.     Tk_Window tkwin;        /* Window in which cursor will be used. */
  158.     Tk_Uid string;        /* Description of cursor.  See manual entry
  159.                  * for details on legal syntax. */
  160. {
  161.     struct CursorName *namePtr;
  162.     TkOS2Cursor *cursorPtr;
  163.  
  164. #ifdef VERBOSE
  165.     printf("TkGetCursorByName %s\n", string);
  166. #endif
  167.  
  168.     /*
  169.      * Check for the cursor in the system cursor set.
  170.      */
  171.  
  172.     for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
  173.     if (strcmp(namePtr->name, string) == 0) {
  174.         break;
  175.     }
  176.     }
  177.  
  178.     cursorPtr = (TkOS2Cursor *) ckalloc(sizeof(TkOS2Cursor));
  179.     if (!cursorPtr) {
  180.     return NULL;
  181.     }
  182.  
  183.     cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;
  184.     cursorPtr->os2Pointer = NULLHANDLE;
  185.  
  186.     if (namePtr->name != NULL) {
  187.     /* Found a system cursor, make a reference (not a copy) */
  188.     cursorPtr->os2Pointer = WinQuerySysPointer(HWND_DESKTOP, namePtr->id,
  189.                                                FALSE);
  190.     cursorPtr->system = 1;
  191.     }
  192.     if (cursorPtr->os2Pointer == NULLHANDLE) {
  193.     /* Variable cursors comes from rc/cursors.h */
  194.     myCursor *curPtr = cursors;
  195.  
  196.     /* Added X-derived cursors by Ilya Zakharevich */
  197.     cursorPtr->system = 0;
  198.     while (curPtr->name) {
  199.         if (strcmp(curPtr->name, string) == 0) {
  200.             break;
  201.         }
  202.         curPtr++;
  203.     }
  204.     if (curPtr->name &&
  205.         (cursorPtr->os2Pointer = WinLoadPointer(HWND_DESKTOP,
  206.                                                 Tk_GetHMODULE(),
  207.                                                 curPtr->id))
  208.             != NULLHANDLE) {
  209.             cursorPtr->system = 0;
  210.         } else {
  211.         /* Not a known cursor */
  212.         cursorPtr->os2Pointer = NULLHANDLE;
  213.         cursorPtr->system = 1;
  214.         }
  215.     }
  216. #ifdef VERBOSE
  217.     printf("    cursorPtr->os2Pointer %x\n", cursorPtr->os2Pointer);
  218. #endif
  219.     if (cursorPtr->os2Pointer == NULLHANDLE) {
  220.     ckfree((char *)cursorPtr);
  221.     Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
  222.         (char *) NULL);
  223.     return NULL;
  224.     } else {
  225.     return (TkCursor *) cursorPtr;
  226.     }
  227. }
  228.  
  229. /*
  230.  *----------------------------------------------------------------------
  231.  *
  232.  * TkCreateCursorFromData --
  233.  *
  234.  *    Creates a cursor from the source and mask bits.
  235.  *
  236.  * Results:
  237.  *    Returns a new cursor, or NULL on errors.
  238.  *
  239.  * Side effects:
  240.  *    Allocates a new cursor.
  241.  *
  242.  *----------------------------------------------------------------------
  243.  */
  244.  
  245. TkCursor *
  246. TkCreateCursorFromData(tkwin, source, mask, width, height, xHot, yHot,
  247.     fgColor, bgColor)
  248.     Tk_Window tkwin;        /* Window in which cursor will be used. */
  249.     char *source;        /* Bitmap data for cursor shape. */
  250.     char *mask;            /* Bitmap data for cursor mask. */
  251.     int width, height;        /* Dimensions of cursor. */
  252.     int xHot, yHot;        /* Location of hot-spot in cursor. */
  253.     XColor fgColor;        /* Foreground color for cursor. */
  254.     XColor bgColor;        /* Background color for cursor. */
  255. {
  256.     return NULL;
  257. }
  258.  
  259. /*
  260.  *----------------------------------------------------------------------
  261.  *
  262.  * TkFreeCursor --
  263.  *
  264.  *    This procedure is called to release a cursor allocated by
  265.  *    TkGetCursorByName.
  266.  *
  267.  * Results:
  268.  *    None.
  269.  *
  270.  * Side effects:
  271.  *    The cursor data structure is deallocated.
  272.  *
  273.  *----------------------------------------------------------------------
  274.  */
  275.  
  276. void
  277. TkFreeCursor(cursorPtr)
  278.     TkCursor *cursorPtr;
  279. {
  280.     TkOS2Cursor *os2PointerPtr = (TkOS2Cursor *) cursorPtr;
  281.     if (os2PointerPtr->system != 1) {
  282.         rc = WinDestroyPointer(os2PointerPtr->os2Pointer);
  283. #ifdef VERBOSE
  284.         printf("TkFreeCursor %x, WinDestroyPointer %x returns %d\n", cursorPtr,
  285.                os2PointerPtr->os2Pointer, rc);
  286.     } else {
  287.         printf("TkFreeCursor %x, system pointer %x\n", cursorPtr,
  288.                os2PointerPtr->os2Pointer);
  289. #endif
  290.     }
  291.     ckfree((char *) os2PointerPtr);
  292. }
  293.  
  294. /*
  295.  *----------------------------------------------------------------------
  296.  *
  297.  * TkpSetCursor --
  298.  *
  299.  *    Set the global cursor. If the cursor is None, then use the
  300.  *    default Tk cursor.
  301.  *
  302.  * Results:
  303.  *    None.
  304.  *
  305.  * Side effects:
  306.  *    Changes the mouse cursor.
  307.  *
  308.  *----------------------------------------------------------------------
  309.  */
  310.  
  311. void
  312. TkpSetCursor(cursor)
  313.     TkpCursor cursor;
  314. {
  315.     HPOINTER hcursor = NULLHANDLE;
  316.     TkOS2Cursor *os2Cursor = (TkOS2Cursor *) cursor;
  317.  
  318. #ifdef VERBOSE
  319.     printf("TkOS2UpdateCursor os2Cursor %x, os2Pointer %x\n", os2Cursor,
  320.            os2Cursor == NULL ? 0 : os2Cursor->os2Pointer);
  321. #endif
  322.  
  323.     if (os2Cursor == NULL || os2Cursor->os2Pointer == NULLHANDLE) {
  324.         if (defCursor == NULLHANDLE) {
  325.             defCursor = WinQuerySysPointer(HWND_DESKTOP, TK_DEFAULT_CURSOR,
  326.                                            FALSE);
  327.         }
  328.         hcursor = defCursor;
  329.     } else {
  330.         hcursor = os2Cursor->os2Pointer;
  331.     }
  332. #ifdef VERBOSE
  333.     printf("    hcursor %x, old pointer %x\n", hcursor,
  334.            WinQueryPointer(HWND_DESKTOP));
  335. #endif
  336.     if (hcursor != NULLHANDLE && hcursor != WinQueryPointer(HWND_DESKTOP)) {
  337.     rc = WinSetPointer(HWND_DESKTOP, hcursor);
  338. #ifdef VERBOSE
  339.         if (rc != TRUE) {
  340.             printf("    WinSetPointer(%x) ERROR\n", hcursor,
  341.                    WinGetLastError(TclOS2GetHAB()));
  342.         } else {
  343.             printf("    WinSetPointer(%x) OK\n", hcursor);
  344.         }
  345. #endif
  346.     }
  347. }
  348.