1Tk_AllocCursorFromObj(3)     Tk Library Procedures    Tk_AllocCursorFromObj(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tk_AllocCursorFromObj, Tk_GetCursor, Tk_GetCursorFromObj, Tk_GetCursor‐
9       FromData, Tk_NameOfCursor, Tk_FreeCursorFromObj, Tk_FreeCursor -  main‐
10       tain database of cursors
11

SYNOPSIS

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

ARGUMENTS

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
82

DESCRIPTION

84       These procedures manage a collection of cursors being used by an appli‐
85       cation.  The  procedures  allow  cursors  to  be  re-used  efficiently,
86       thereby  avoiding  server  overhead, and also allow cursors to be named
87       with character strings.
88
89       Tk_AllocCursorFromObj takes as argument an object describing a  cursor,
90       and  returns  an opaque Tk identifier for a cursor corresponding to the
91       description.  It re-uses an existing cursor if possible and  creates  a
92       new  one otherwise.  Tk_AllocCursorFromObj caches information about the
93       return value in objPtr, which speeds up future calls to procedures such
94       as Tk_AllocCursorFromObj and Tk_GetCursorFromObj. If an error occurs in
95       creating the cursor, such as when objPtr refers to a non-existent file,
96       then  None  is returned and an error message will be stored in interp's
97       result if interp is not NULL.  ObjPtr must contain a standard Tcl  list
98       with one of the following forms:
99
100       name [fgColor [bgColor]]
101              Name  is  the  name of a cursor in the standard X cursor cursor,
102              i.e., any of the names defined in  cursorcursor.h,  without  the
103              XC_.  Some example values are X_cursor, hand2, or left_ptr.  Ap‐
104              pendix B of “The X Window System”  by  Scheifler  &  Gettys  has
105              illustrations showing what each of these cursors looks like.  If
106              fgColor and bgColor are both specified, they give the foreground
107              and  background  colors  to use for the cursor (any of the forms
108              acceptable to Tk_GetColor may be  used).   If  only  fgColor  is
109              specified,  then  there  will be no background color:  the back‐
110              ground will be transparent.  If no colors  are  specified,  then
111              the cursor will use black for its foreground color and white for
112              its background color.
113
114              The Macintosh version of Tk supports all of the  X  cursors  and
115              will  also  accept  any  of  the  standard Mac cursors including
116              ibeam, crosshair, watch, plus, and arrow.  In addition, Tk  will
117              load  Macintosh  cursor  resources of the types crsr (color) and
118              CURS (black and white) by the name of the resource.  The  appli‐
119              cation and all its open dynamic library's resource files will be
120              searched for the named cursor.  If  there  are  conflicts  color
121              cursors  will  always be loaded in preference to black and white
122              cursors.
123
124       @sourceName maskName fgColor bgColor
125              In this form, sourceName and maskName are  the  names  of  files
126              describing  cursors for the cursor's source bits and mask.  Each
127              file must be in standard X11 or X10 cursor format.  FgColor  and
128              bgColor indicate the colors to use for the cursor, in any of the
129              forms acceptable to Tk_GetColor.  This form of the command  will
130              not work on Macintosh or Windows computers.
131
132       @sourceName fgColor
133              This form is similar to the one above, except that the source is
134              used as mask also.  This means that the cursor's  background  is
135              transparent.   This  form of the command will not work on Macin‐
136              tosh or Windows computers.
137
138       @sourceName
139              This form only works on Windows, and will load a Windows  system
140              cursor (.ani or .cur) from the file specified in sourceName.
141
142       Tk_GetCursor  is  identical  to  Tk_AllocCursorFromObj  except that the
143       description of the cursor is specified with  a  string  instead  of  an
144       object.   This  prevents Tk_GetCursor from caching the return value, so
145       Tk_GetCursor is less efficient than Tk_AllocCursorFromObj.
146
147       Tk_GetCursorFromObj returns the token for an existing cursor, given the
148       window  and description used to create the cursor.  Tk_GetCursorFromObj
149       does not actually create the cursor; the cursor must already have  been
150       created  with a previous call to Tk_AllocCursorFromObj or Tk_GetCursor.
151       The return value is cached in objPtr, which speeds up future  calls  to
152       Tk_GetCursorFromObj with the same objPtr and tkwin.
153
154       Tk_GetCursorFromData  allows  cursors  to  be  created  from  in-memory
155       descriptions of their source and mask cursors.  Source points to  stan‐
156       dard cursor data for the cursor's source bits, and mask points to stan‐
157       dard cursor data describing which pixels of source are to be drawn  and
158       which  are  to  be  considered  transparent.  Width and height give the
159       dimensions of the cursor, xHot and yHot indicate the  location  of  the
160       cursor's  hot-spot  (the  point that is reported when an event occurs),
161       and fg and bg describe the cursor's foreground  and  background  colors
162       textually  (any  of  the  forms  suitable for Tk_GetColor may be used).
163       Typically, the arguments to Tk_GetCursorFromData are created by includ‐
164       ing  a  cursor  file directly into the source code for a program, as in
165       the following example:
166              Tk_Cursor cursor;
167              #include "source.cursor"
168              #include "mask.cursor"
169              cursor = Tk_GetCursorFromData(interp, tkwin, source_bits,
170                  mask_bits, source_width, source_height, source_x_hot,
171                  source_y_hot, Tk_GetUid("red"), Tk_GetUid("blue"));
172
173       Under normal conditions Tk_GetCursorFromData will return an  identifier
174       for  the  requested  cursor.  If an error occurs in creating the cursor
175       then None is returned and an error message will be stored  in  interp's
176       result.
177
178       Tk_AllocCursorFromObj,  Tk_GetCursor, and Tk_GetCursorFromData maintain
179       a database of all the cursors they have created.  Whenever possible,  a
180       call  to  Tk_AllocCursorFromObj,  Tk_GetCursor, or Tk_GetCursorFromData
181       will return an existing cursor rather than creating a  new  one.   This
182       approach can substantially reduce server overhead, so the Tk procedures
183       should generally be used in preference to Xlib procedures like XCreate‐
184       FontCursor  or  XCreatePixmapCursor,  which create a new cursor on each
185       call.  The Tk procedures are also more portable than the lower-level  X
186       procedures.
187
188       The  procedure  Tk_NameOfCursor is roughly the inverse of Tk_GetCursor.
189       If its cursor argument was created by  Tk_GetCursor,  then  the  return
190       value  is  the  name argument that was passed to Tk_GetCursor to create
191       the cursor.  If cursor was created by a call  to  Tk_GetCursorFromData,
192       or  by  any  other  mechanism,  then  the return value is a hexadecimal
193       string giving the X identifier  for  the  cursor.   Note:   the  string
194       returned  by  Tk_NameOfCursor  is  only guaranteed to persist until the
195       next call to Tk_NameOfCursor.  Also, this call is not  portable  except
196       for cursors returned by Tk_GetCursor.
197
198       When  a  cursor  returned  by  Tk_AllocCursorFromObj,  Tk_GetCursor, or
199       Tk_GetCursorFromData  is  no  longer  needed,  Tk_FreeCursorFromObj  or
200       Tk_FreeCursor should be called to release it.  For Tk_FreeCursorFromObj
201       the cursor to release is specified with the same  information  used  to
202       create  it;  for  Tk_FreeCursor the cursor to release is specified with
203       its Tk_Cursor token.  There should be exactly one call to Tk_FreeCursor
204       for  each call to Tk_AllocCursorFromObj, Tk_GetCursor, or Tk_GetCursor‐
205       FromData.
206
207

BUGS

209       In determining whether an existing cursor can be used to satisfy a  new
210       request,  Tk_AllocCursorFromObj, Tk_GetCursor, and Tk_GetCursorFromData
211       consider only the immediate values of their  arguments.   For  example,
212       when a file name is passed to Tk_GetCursor, Tk_GetCursor will assume it
213       is safe to re-use an existing cursor created from the same  file  name:
214       it  will  not  check  to  see  whether  the file itself has changed, or
215       whether the current directory has changed, thereby causing the name  to
216       refer  to  a  different  file.  Similarly, Tk_GetCursorFromData assumes
217       that if the same source pointer is used in two  different  calls,  then
218       the  pointers  refer to the same data;  it does not check to see if the
219       actual data values have changed.
220
221

KEYWORDS

223       cursor
224
225
226
227Tk                                    8.1             Tk_AllocCursorFromObj(3)
Impressum