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