1Tk_AllocBitmapFromObj(3) Tk Library Procedures Tk_AllocBitmapFromObj(3)
2
3
4
5______________________________________________________________________________
6
8 Tk_AllocBitmapFromObj, Tk_GetBitmap, Tk_GetBitmapFromObj, Tk_De‐
9 fineBitmap, Tk_NameOfBitmap, Tk_SizeOfBitmap, Tk_FreeBitmapFromObj,
10 Tk_FreeBitmap - maintain database of single-plane pixmaps
11
13 #include <tk.h>
14
15 Pixmap
16 Tk_AllocBitmapFromObj(interp, tkwin, objPtr)
17
18 Pixmap
19 Tk_GetBitmap(interp, tkwin, info)
20
21 Pixmap
22 Tk_GetBitmapFromObj(tkwin, objPtr)
23
24 int
25 Tk_DefineBitmap(interp, name, source, width, height)
26
27 const char *
28 Tk_NameOfBitmap(display, bitmap)
29
30 Tk_SizeOfBitmap(display, bitmap, widthPtr, heightPtr)
31
32 Tk_FreeBitmapFromObj(tkwin, objPtr)
33
34 Tk_FreeBitmap(display, bitmap)
35
37 Tcl_Interp *interp (in) Interpreter to use for error re‐
38 porting; if NULL then no error
39 message is left after errors.
40
41 Tk_Window tkwin (in) Token for window in which the
42 bitmap will be used.
43
44 Tcl_Obj *objPtr (in/out) String value describes desired
45 bitmap; internal rep will be mod‐
46 ified to cache pointer to corre‐
47 sponding Pixmap.
48
49 const char *info (in) Same as objPtr except description
50 of bitmap is passed as a string
51 and resulting Pixmap is not
52 cached.
53
54 const char *name (in) Name for new bitmap to be de‐
55 fined.
56
57 const void *source (in) Data for bitmap, in standard bit‐
58 map format. Must be stored in
59 static memory whose value will
60 never change.
61
62 int width (in) Width of bitmap.
63
64 int height (in) Height of bitmap.
65
66 int *widthPtr (out) Pointer to word to fill in with
67 bitmap's width.
68
69 int *heightPtr (out) Pointer to word to fill in with
70 bitmap's height.
71
72 Display *display (in) Display for which bitmap was al‐
73 located.
74
75 Pixmap bitmap (in) Identifier for a bitmap allocated
76 by Tk_AllocBitmapFromObj or
77 Tk_GetBitmap.
78______________________________________________________________________________
79
81 These procedures manage a collection of bitmaps (one-plane pixmaps) be‐
82 ing used by an application. The procedures allow bitmaps to be re-used
83 efficiently, thereby avoiding server overhead, and also allow bitmaps
84 to be named with character strings.
85
86 Tk_AllocBitmapFromObj returns a Pixmap identifier for a bitmap that
87 matches the description in objPtr and is suitable for use in tkwin. It
88 re-uses an existing bitmap, if possible, and creates a new one other‐
89 wise. ObjPtr's value must have one of the following forms:
90
91 @fileName FileName must be the name of a file containing a
92 bitmap description in the standard X11 format.
93
94 name Name must be the name of a bitmap defined previ‐
95 ously with a call to Tk_DefineBitmap. The follow‐
96 ing names are pre-defined by Tk:
97
98 error The international “don't” symbol: a
99 circle with a diagonal line across it.
100
101 gray75 75% gray: a checkerboard pattern where
102 three out of four bits are on.
103
104 gray50 50% gray: a checkerboard pattern where
105 every other bit is on.
106
107 gray25 25% gray: a checkerboard pattern where
108 one out of every four bits is on.
109
110 gray12 12.5% gray: a pattern where one-eighth
111 of the bits are on, consisting of every
112 fourth pixel in every other row.
113
114 hourglass An hourglass symbol.
115
116 info A large letter “i”.
117
118 questhead The silhouette of a human head, with a
119 question mark in it.
120
121 question A large question-mark.
122
123 warning A large exclamation point.
124
125 In addition, the following pre-defined names are
126 available only on the Macintosh platform:
127
128 document A generic document.
129
130 stationery Document stationery.
131
132 edition The edition symbol.
133
134 application Generic application icon.
135
136 accessory A desk accessory.
137
138 folder Generic folder icon.
139
140 pfolder A locked folder.
141
142 trash A trash can.
143
144 floppy A floppy disk.
145
146 ramdisk A floppy disk with chip.
147
148 cdrom A cd disk icon.
149
150 preferences A folder with prefs symbol.
151
152 querydoc A database document icon.
153
154 stop A stop sign.
155
156 note A face with balloon words.
157
158 caution A triangle with an exclamation point.
159
160 Under normal conditions, Tk_AllocBitmapFromObj returns an identifier
161 for the requested bitmap. If an error occurs in creating the bitmap,
162 such as when objPtr refers to a non-existent file, then None is re‐
163 turned and an error message is left in interp's result if interp is not
164 NULL. Tk_AllocBitmapFromObj caches information about the return value
165 in objPtr, which speeds up future calls to procedures such as Tk_Al‐
166 locBitmapFromObj and Tk_GetBitmapFromObj.
167
168 Tk_GetBitmap is identical to Tk_AllocBitmapFromObj except that the de‐
169 scription of the bitmap is specified with a string instead of an ob‐
170 ject. This prevents Tk_GetBitmap from caching the return value, so
171 Tk_GetBitmap is less efficient than Tk_AllocBitmapFromObj.
172
173 Tk_GetBitmapFromObj returns the token for an existing bitmap, given the
174 window and description used to create the bitmap. Tk_GetBitmapFromObj
175 does not actually create the bitmap; the bitmap must already have been
176 created with a previous call to Tk_AllocBitmapFromObj or Tk_GetBitmap.
177 The return value is cached in objPtr, which speeds up future calls to
178 Tk_GetBitmapFromObj with the same objPtr and tkwin.
179
180 Tk_DefineBitmap associates a name with in-memory bitmap data so that
181 the name can be used in later calls to Tk_AllocBitmapFromObj or Tk_Get‐
182 Bitmap. The nameId argument gives a name for the bitmap; it must not
183 previously have been used in a call to Tk_DefineBitmap. The arguments
184 source, width, and height describe the bitmap. Tk_DefineBitmap nor‐
185 mally returns TCL_OK; if an error occurs (e.g. a bitmap named nameId
186 has already been defined) then TCL_ERROR is returned and an error mes‐
187 sage is left in interpreter interp's result. Note: Tk_DefineBitmap
188 expects the memory pointed to by source to be static: Tk_DefineBitmap
189 does not make a private copy of this memory, but uses the bytes pointed
190 to by source later in calls to Tk_AllocBitmapFromObj or Tk_GetBitmap.
191
192 Typically Tk_DefineBitmap is used by #include-ing a bitmap file di‐
193 rectly into a C program and then referencing the variables defined by
194 the file. For example, suppose there exists a file stip.bitmap, which
195 was created by the bitmap program and contains a stipple pattern. The
196 following code uses Tk_DefineBitmap to define a new bitmap named foo:
197 Pixmap bitmap;
198 #include "stip.bitmap"
199 Tk_DefineBitmap(interp, "foo", stip_bits,
200 stip_width, stip_height);
201 ...
202 bitmap = Tk_GetBitmap(interp, tkwin, "foo");
203 This code causes the bitmap file to be read at compile-time and incor‐
204 porates the bitmap information into the program's executable image.
205 The same bitmap file could be read at run-time using Tk_GetBitmap:
206 Pixmap bitmap;
207 bitmap = Tk_GetBitmap(interp, tkwin, "@stip.bitmap");
208 The second form is a bit more flexible (the file could be modified af‐
209 ter the program has been compiled, or a different string could be pro‐
210 vided to read a different file), but it is a little slower and requires
211 the bitmap file to exist separately from the program.
212
213 Tk maintains a database of all the bitmaps that are currently in use.
214 Whenever possible, it will return an existing bitmap rather than creat‐
215 ing a new one. When a bitmap is no longer used, Tk will release it au‐
216 tomatically. This approach can substantially reduce server overhead,
217 so Tk_AllocBitmapFromObj and Tk_GetBitmap should generally be used in
218 preference to Xlib procedures like XReadBitmapFile.
219
220 The bitmaps returned by Tk_AllocBitmapFromObj and Tk_GetBitmap are
221 shared, so callers should never modify them. If a bitmap must be modi‐
222 fied dynamically, then it should be created by calling Xlib procedures
223 such as XReadBitmapFile or XCreatePixmap directly.
224
225 The procedure Tk_NameOfBitmap is roughly the inverse of Tk_GetBitmap.
226 Given an X Pixmap argument, it returns the textual description that was
227 passed to Tk_GetBitmap when the bitmap was created. Bitmap must have
228 been the return value from a previous call to Tk_AllocBitmapFromObj or
229 Tk_GetBitmap.
230
231 Tk_SizeOfBitmap returns the dimensions of its bitmap argument in the
232 words pointed to by the widthPtr and heightPtr arguments. As with
233 Tk_NameOfBitmap, bitmap must have been created by Tk_AllocBitmapFromObj
234 or Tk_GetBitmap.
235
236 When a bitmap is no longer needed, Tk_FreeBitmapFromObj or
237 Tk_FreeBitmap should be called to release it. For Tk_FreeBitmapFromObj
238 the bitmap to release is specified with the same information used to
239 create it; for Tk_FreeBitmap the bitmap to release is specified with
240 its Pixmap token. There should be exactly one call to
241 Tk_FreeBitmapFromObj or Tk_FreeBitmap for each call to Tk_Al‐
242 locBitmapFromObj or Tk_GetBitmap.
243
245 In determining whether an existing bitmap can be used to satisfy a new
246 request, Tk_AllocBitmapFromObj and Tk_GetBitmap consider only the imme‐
247 diate value of the string description. For example, when a file name
248 is passed to Tk_GetBitmap, Tk_GetBitmap will assume it is safe to re-
249 use an existing bitmap created from the same file name: it will not
250 check to see whether the file itself has changed, or whether the cur‐
251 rent directory has changed, thereby causing the name to refer to a dif‐
252 ferent file.
253
255 bitmap, pixmap
256
257
258
259Tk 8.1 Tk_AllocBitmapFromObj(3)