1Tk_AllocCursorFromObj(3) Tk Library Procedures Tk_AllocCursorFromObj(3)
2
3
4
5______________________________________________________________________________
6
8 Tk_AllocCursorFromObj, Tk_GetCursor, Tk_GetCursorFromObj, Tk_GetCursor‐
9 FromData, Tk_NameOfCursor, Tk_FreeCursorFromObj, Tk_FreeCursor - main‐
10 tain database of cursors
11
13 #include <tk.h>
14
15 Tk_Cursor
16 Tk_AllocCursorFromObj(interp, tkwin, objPtr)
17
18 Tk_Cursor
19 Tk_GetCursor(interp, tkwin, name)
20
21 Tk_Cursor
22 Tk_GetCursorFromObj(tkwin, objPtr)
23
24 Tk_Cursor
25 Tk_GetCursorFromData(interp, tkwin, source, mask, width, height, xHot, yHot, fg, bg)
26
27 const char *
28 Tk_NameOfCursor(display, cursor)
29
30 Tk_FreeCursorFromObj(tkwin, objPtr)
31
32 Tk_FreeCursor(display, cursor)
33
35 Tcl_Interp *interp (in) Interpreter to use for error
36 reporting.
37
38 Tk_Window tkwin (in) Token for window in which the
39 cursor will be used.
40
41 Tcl_Obj *objPtr (in/out) Description of cursor; see below
42 for possible values. Internal
43 rep will be modified to cache
44 pointer to corresponding Tk_Cur‐
45 sor.
46
47 char *name (in) Same as objPtr except description
48 of cursor is passed as a string
49 and resulting Tk_Cursor is not
50 cached.
51
52 const char *source (in) Data for cursor cursor, in stan‐
53 dard cursor format.
54
55 const char *mask (in) Data for mask cursor, in standard
56 cursor format.
57
58 int width (in) Width of source and mask.
59
60 int height (in) Height of source and mask.
61
62 int xHot (in) X-location of cursor hot-spot.
63
64 int yHot (in) Y-location of cursor hot-spot.
65
66 Tk_Uid fg (in) Textual description of foreground
67 color for cursor.
68
69 Tk_Uid bg (in) Textual description of background
70 color for cursor.
71
72 Display *display (in) Display for which cursor was
73 allocated.
74
75 Tk_Cursor cursor (in) Opaque Tk identifier for cursor.
76 If passed to Tk_FreeCursor, must
77 have been returned by some previ‐
78 ous call to Tk_GetCursor or
79 Tk_GetCursorFromData.
80______________________________________________________________________________
81
83 These procedures manage a collection of cursors being used by an appli‐
84 cation. The procedures allow cursors to be re-used efficiently,
85 thereby avoiding server overhead, and also allow cursors to be named
86 with character strings.
87
88 Tk_AllocCursorFromObj takes as argument an object describing a cursor,
89 and returns an opaque Tk identifier for a cursor corresponding to the
90 description. It re-uses an existing cursor if possible and creates a
91 new one otherwise. Tk_AllocCursorFromObj caches information about the
92 return value in objPtr, which speeds up future calls to procedures such
93 as Tk_AllocCursorFromObj and Tk_GetCursorFromObj. If an error occurs in
94 creating the cursor, such as when objPtr refers to a non-existent file,
95 then None is returned and an error message will be stored in interp's
96 result if interp is not NULL. ObjPtr must contain a standard Tcl list
97 with one of the following forms:
98
99 name [fgColor [bgColor]]
100 Name is the name of a cursor in the standard X cursor cursor,
101 i.e., any of the names defined in cursorcursor.h, without the
102 XC_. Some example values are X_cursor, hand2, or left_ptr. Ap‐
103 pendix B of “The X Window System” by Scheifler & Gettys has
104 illustrations showing what each of these cursors looks like. If
105 fgColor and bgColor are both specified, they give the foreground
106 and background colors to use for the cursor (any of the forms
107 acceptable to Tk_GetColor may be used). If only fgColor is
108 specified, then there will be no background color: the back‐
109 ground will be transparent. If no colors are specified, then
110 the cursor will use black for its foreground color and white for
111 its background color.
112
113 The Macintosh version of Tk supports all of the X cursors and
114 will also accept any of the standard Mac cursors including
115 ibeam, crosshair, watch, plus, and arrow. In addition, Tk will
116 load Macintosh cursor resources of the types crsr (color) and
117 CURS (black and white) by the name of the resource. The appli‐
118 cation and all its open dynamic library's resource files will be
119 searched for the named cursor. If there are conflicts color
120 cursors will always be loaded in preference to black and white
121 cursors.
122
123 @sourceName maskName fgColor bgColor
124 In this form, sourceName and maskName are the names of files
125 describing cursors for the cursor's source bits and mask. Each
126 file must be in standard X11 cursor format. FgColor and bgColor
127 indicate the colors to use for the cursor, in any of the forms
128 acceptable to Tk_GetColor. This form of the command will not
129 work on Macintosh or Windows computers.
130
131 @sourceName fgColor
132 This form is similar to the one above, except that the source is
133 used as mask also. This means that the cursor's background is
134 transparent. This form of the command will not work on Macin‐
135 tosh or Windows computers.
136
137 @sourceName
138 This form only works on Windows, and will load a Windows system
139 cursor (.ani or .cur) from the file specified in sourceName.
140
141 Tk_GetCursor is identical to Tk_AllocCursorFromObj except that the
142 description of the cursor is specified with a string instead of an
143 object. This prevents Tk_GetCursor from caching the return value, so
144 Tk_GetCursor is less efficient than Tk_AllocCursorFromObj.
145
146 Tk_GetCursorFromObj returns the token for an existing cursor, given the
147 window and description used to create the cursor. Tk_GetCursorFromObj
148 does not actually create the cursor; the cursor must already have been
149 created with a previous call to Tk_AllocCursorFromObj or Tk_GetCursor.
150 The return value is cached in objPtr, which speeds up future calls to
151 Tk_GetCursorFromObj with the same objPtr and tkwin.
152
153 Tk_GetCursorFromData allows cursors to be created from in-memory
154 descriptions of their source and mask cursors. Source points to stan‐
155 dard cursor data for the cursor's source bits, and mask points to stan‐
156 dard cursor data describing which pixels of source are to be drawn and
157 which are to be considered transparent. Width and height give the
158 dimensions of the cursor, xHot and yHot indicate the location of the
159 cursor's hot-spot (the point that is reported when an event occurs),
160 and fg and bg describe the cursor's foreground and background colors
161 textually (any of the forms suitable for Tk_GetColor may be used).
162 Typically, the arguments to Tk_GetCursorFromData are created by includ‐
163 ing a cursor file directly into the source code for a program, as in
164 the following example:
165 Tk_Cursor cursor;
166 #include "source.cursor"
167 #include "mask.cursor"
168 cursor = Tk_GetCursorFromData(interp, tkwin, source_bits,
169 mask_bits, source_width, source_height, source_x_hot,
170 source_y_hot, Tk_GetUid("red"), Tk_GetUid("blue"));
171
172 Under normal conditions Tk_GetCursorFromData will return an identifier
173 for the requested cursor. If an error occurs in creating the cursor
174 then None is returned and an error message will be stored in interp's
175 result.
176
177 Tk_AllocCursorFromObj, Tk_GetCursor, and Tk_GetCursorFromData maintain
178 a database of all the cursors they have created. Whenever possible, a
179 call to Tk_AllocCursorFromObj, Tk_GetCursor, or Tk_GetCursorFromData
180 will return an existing cursor rather than creating a new one. This
181 approach can substantially reduce server overhead, so the Tk procedures
182 should generally be used in preference to Xlib procedures like XCreate‐
183 FontCursor or XCreatePixmapCursor, which create a new cursor on each
184 call. The Tk procedures are also more portable than the lower-level X
185 procedures.
186
187 The procedure Tk_NameOfCursor is roughly the inverse of Tk_GetCursor.
188 If its cursor argument was created by Tk_GetCursor, then the return
189 value is the name argument that was passed to Tk_GetCursor to create
190 the cursor. If cursor was created by a call to Tk_GetCursorFromData,
191 or by any other mechanism, then the return value is a hexadecimal
192 string giving the X identifier for the cursor. Note: the string
193 returned by Tk_NameOfCursor is only guaranteed to persist until the
194 next call to Tk_NameOfCursor. Also, this call is not portable except
195 for cursors returned by Tk_GetCursor.
196
197 When a cursor returned by Tk_AllocCursorFromObj, Tk_GetCursor, or
198 Tk_GetCursorFromData is no longer needed, Tk_FreeCursorFromObj or
199 Tk_FreeCursor should be called to release it. For Tk_FreeCursorFromObj
200 the cursor to release is specified with the same information used to
201 create it; for Tk_FreeCursor the cursor to release is specified with
202 its Tk_Cursor token. There should be exactly one call to Tk_FreeCursor
203 for each call to Tk_AllocCursorFromObj, Tk_GetCursor, or Tk_GetCursor‐
204 FromData.
205
207 In determining whether an existing cursor can be used to satisfy a new
208 request, Tk_AllocCursorFromObj, Tk_GetCursor, and Tk_GetCursorFromData
209 consider only the immediate values of their arguments. For example,
210 when a file name is passed to Tk_GetCursor, Tk_GetCursor will assume it
211 is safe to re-use an existing cursor created from the same file name:
212 it will not check to see whether the file itself has changed, or
213 whether the current directory has changed, thereby causing the name to
214 refer to a different file. Similarly, Tk_GetCursorFromData assumes
215 that if the same source pointer is used in two different calls, then
216 the pointers refer to the same data; it does not check to see if the
217 actual data values have changed.
218
220 cursor
221
222
223
224Tk 8.1 Tk_AllocCursorFromObj(3)