Debian Codegraph @

pTk/mTk/win/tkWinCursor.c

raw
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 * RCS: @(#) $Id: tkWinCursor.c,v 1.10.2.1 2003/07/19 01:02:51 hobbs Exp $
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 int argc;
91 Tcl_Obj **objv = NULL;
92
93 /*
94 * All cursor names are valid lists of one element (for
95 * Unix-compatability), even unadorned system cursor names.
96 */
97
98 Tcl_Obj *tmp = Tcl_NewStringObj(string,-1);
99 if (Tcl_ListObjGetElements(interp, tmp, &argc, &objv) != TCL_OK) {
100 Tcl_DecrRefCount(tmp);
101 return NULL;
102 }
103 if (argc == 0) {
104 goto badCursorSpec;
105 }
106 string = (Tk_Uid) Tcl_GetString(objv[0]);
107
108 cursorPtr = (TkWinCursor *) ckalloc(sizeof(TkWinCursor));
109 cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;
110 cursorPtr->winCursor = NULL;
111 cursorPtr->system = 0;
112
113 if (string[0] == '@') {
114 /*
115 * Check for system cursor of type @<filename>, where only
116 * the name is allowed. This accepts any of:
117 * -cursor @/winnt/cursors/globe.ani
118 * -cursor @C:/Winnt/cursors/E_arrow.cur
119 * -cursor {@C:/Program\ Files/Cursors/bart.ani}
120 * -cursor {{@C:/Program Files/Cursors/bart.ani}}
121 * -cursor [list @[file join "C:/Program Files" Cursors bart.ani]]
122 */
123
124 if (Tcl_IsSafe(interp)) {
125 Tcl_AppendResult(interp, "can't get cursor from a file in",
126 " a safe interpreter", (char *) NULL);
127 ckfree((char *) cursorPtr);
128 return NULL;
129 }
130 cursorPtr->winCursor = LoadCursorFromFile(&(string[1]));
131 } else {
132 /*
133 * Check for the cursor in the system cursor set.
134 */
135 for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
136 if (strcmp(namePtr->name, string) == 0) {
137 cursorPtr->winCursor = LoadCursor(NULL, namePtr->id);
138 break;
139 }
140 }
141
142 if (cursorPtr->winCursor == NULL) {
143 /*
144 * Hmm, it is not in the system cursor set. Check to see
145 * if it is one of our application resources.
146 */
147 #ifdef __OPEN32__
148 cursorPtr->winCursor = os2LoadCursor(TkWinGetTkModule(), string);
149 #else
150 cursorPtr->winCursor = LoadCursor(Tk_GetHINSTANCE(), string);
151 #endif
152 } else {
153 cursorPtr->system = 1;
154 }
155 }
156
157 if (cursorPtr->winCursor == NULL) {
158 ckfree((char *) cursorPtr);
159 badCursorSpec:
160 Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
161 (char *) NULL);
162 Tcl_DecrRefCount(tmp);
163 return NULL;
164 } else {
165 Tcl_DecrRefCount(tmp);
166 return (TkCursor *) cursorPtr;
167 }
168 }
169
170 /*
171 *----------------------------------------------------------------------
172 *
173 * TkCreateCursorFromData --
174 *
175 * Creates a cursor from the source and mask bits.
176 *
177 * Results:
178 * Returns a new cursor, or NULL on errors.
179 *
180 * Side effects:
181 * Allocates a new cursor.
182 *
183 *----------------------------------------------------------------------
184 */
185
186 TkCursor *
187 TkCreateCursorFromData(tkwin, source, mask, width, height, xHot, yHot,
188 fgColor, bgColor)
189 Tk_Window tkwin; /* Window in which cursor will be used. */
190 CONST char *source; /* Bitmap data for cursor shape. */
191 CONST char *mask; /* Bitmap data for cursor mask. */
192 int width, height; /* Dimensions of cursor. */
193 int xHot, yHot; /* Location of hot-spot in cursor. */
194 XColor fgColor; /* Foreground color for cursor. */
195 XColor bgColor; /* Background color for cursor. */
196 {
197 return NULL;
198 }
199
200 /*
201 *----------------------------------------------------------------------
202 *
203 * TkpFreeCursor --
204 *
205 * This procedure is called to release a cursor allocated by
206 * TkGetCursorByName.
207 *
208 * Results:
209 * None.
210 *
211 * Side effects:
212 * The cursor data structure is deallocated.
213 *
214 *----------------------------------------------------------------------
215 */
216
217 void
218 TkpFreeCursor(cursorPtr)
219 TkCursor *cursorPtr;
220 {
221 /* TkWinCursor *winCursorPtr = (TkWinCursor *) cursorPtr; */
222 }
223
224 /*
225 *----------------------------------------------------------------------
226 *
227 * TkpSetCursor --
228 *
229 * Set the global cursor. If the cursor is None, then use the
230 * default Tk cursor.
231 *
232 * Results:
233 * None.
234 *
235 * Side effects:
236 * Changes the mouse cursor.
237 *
238 *----------------------------------------------------------------------
239 */
240
241 void
242 TkpSetCursor(cursor)
243 TkpCursor cursor;
244 {
245 HCURSOR hcursor;
246 TkWinCursor *winCursor = (TkWinCursor *) cursor;
247
248 if (winCursor == NULL || winCursor->winCursor == NULL) {
249 hcursor = LoadCursor(NULL, TK_DEFAULT_CURSOR);
250 } else {
251 hcursor = winCursor->winCursor;
252 }
253
254 if (hcursor != NULL) {
255 SetCursor(hcursor);
256 }
257 }
258