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)                                    │
42                                             Description of cursor;  see below │
43                                             for  possible  values.   Internal │
44                                             rep  will  be  modified  to cache │
45                                             pointer to corresponding  Tk_Cur‐ │
46                                             sor.                              │
47
48       char            *name       (in)                                        │
49                                             Same as objPtr except description │
50                                             of cursor is passed as  a  string │
51                                             and   resulting  Tk_Cursor  isn't │
52                                             cached.
53
54       CONST char      *source     (in)      Data for cursor cursor, in  stan‐
55                                             dard cursor format.
56
57       CONST char      *mask       (in)      Data for mask cursor, in standard
58                                             cursor format.
59
60       int             width       (in)      Width of source and mask.
61
62       int             height      (in)      Height of source and mask.
63
64       int             xHot        (in)      X-location of cursor hot-spot.
65
66       int             yHot        (in)      Y-location of cursor hot-spot.
67
68       Tk_Uid          fg          (in)      Textual description of foreground
69                                             color for cursor.
70
71       Tk_Uid          bg          (in)      Textual description of background
72                                             color for cursor.
73
74       Display         *display    (in)      Display  for  which  cursor   was
75                                             allocated.
76
77       Tk_Cursor       cursor      (in)      Opaque  Tk identifier for cursor.
78                                             If passed to Tk_FreeCursor,  must
79                                             have been returned by some previ‐
80                                             ous  call  to   Tk_GetCursor   or
81                                             Tk_GetCursorFromData.
82_________________________________________________________________
83
84

DESCRIPTION

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

BUGS

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

KEYWORDS

225       cursor
226
227
228
229Tk                                    8.1             Tk_AllocCursorFromObj(3)
Impressum