Debian Codegraph @

pod/pTk/GetCursor.pod

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