| 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_GetBitmap, Tk_DefineBitmap, Tk_NameOfBitmap, Tk_SizeOfBitmap, Tk_FreeBitmap, Tk_GetBitmapFromData - maintain database of single-plane pixmaps |
| 11 |
|
| 12 |
=for category C Programming |
| 13 |
|
| 14 |
=head1 SYNOPSIS |
| 15 |
|
| 16 |
B<#include E<lt>tk.hE<gt>> |
| 17 |
|
| 18 |
Pixmap |
| 19 |
B<Tk_GetBitmap(>I<interp, tkwin, id>B<)> |
| 20 |
|
| 21 |
int |
| 22 |
B<Tk_DefineBitmap(>I<interp, nameId, source, width, height>B<)> |
| 23 |
|
| 24 |
Tk_Uid |
| 25 |
B<Tk_NameOfBitmap(>I<display, bitmap>B<)> |
| 26 |
|
| 27 |
B<Tk_SizeOfBitmap(>I<display, bitmap, widthPtr, heightPtr>B<)> |
| 28 |
|
| 29 |
B<Tk_FreeBitmap(>I<display, bitmap>B<)> |
| 30 |
|
| 31 |
=head1 ARGUMENTS |
| 32 |
|
| 33 |
=over 4 |
| 34 |
|
| 35 |
=item Tcl_Interp *interp (in) |
| 36 |
|
| 37 |
Interpreter to use for error reporting. |
| 38 |
|
| 39 |
=item Tk_Window tkwin (in) |
| 40 |
|
| 41 |
Token for window in which the bitmap will be used. |
| 42 |
|
| 43 |
=item Tk_Uid id (in) |
| 44 |
|
| 45 |
Description of bitmap; see below for possible values. |
| 46 |
|
| 47 |
=item Tk_Uid nameId (in) |
| 48 |
|
| 49 |
Name for new bitmap to be defined. |
| 50 |
|
| 51 |
=item char *source (in) |
| 52 |
|
| 53 |
Data for bitmap, in standard bitmap format. |
| 54 |
Must be stored in static memory whose value will never change. |
| 55 |
|
| 56 |
=item "int" width (in) |
| 57 |
|
| 58 |
Width of bitmap. |
| 59 |
|
| 60 |
=item "int" height (in) |
| 61 |
|
| 62 |
Height of bitmap. |
| 63 |
|
| 64 |
=item "int" *widthPtr (out) |
| 65 |
|
| 66 |
Pointer to word to fill in with I<bitmap>'s width. |
| 67 |
|
| 68 |
=item "int" *heightPtr (out) |
| 69 |
|
| 70 |
Pointer to word to fill in with I<bitmap>'s height. |
| 71 |
|
| 72 |
=item Display *display (in) |
| 73 |
|
| 74 |
Display for which I<bitmap> was allocated. |
| 75 |
|
| 76 |
=item Pixmap bitmap (in) |
| 77 |
|
| 78 |
Identifier for a bitmap allocated by B<Tk_GetBitmap>. |
| 79 |
|
| 80 |
=back |
| 81 |
|
| 82 |
=head1 DESCRIPTION |
| 83 |
|
| 84 |
These procedures manage a collection of bitmaps (one-plane pixmaps) |
| 85 |
being used by an application. The procedures allow bitmaps to be |
| 86 |
re-used efficiently, thereby avoiding server overhead, and also |
| 87 |
allow bitmaps to be named with character strings. |
| 88 |
|
| 89 |
B<Tk_GetBitmap> takes as argument a Tk_Uid describing a bitmap. |
| 90 |
It returns a Pixmap identifier for a bitmap corresponding to the |
| 91 |
description. It re-uses an existing bitmap, if possible, and |
| 92 |
creates a new one otherwise. At present, I<id> must have |
| 93 |
one of the following forms: |
| 94 |
|
| 95 |
=over 4 |
| 96 |
|
| 97 |
=item B<@>I<fileName> |
| 98 |
|
| 99 |
I<FileName> must be the name of a file containing a bitmap |
| 100 |
description in the standard X11 or X10 format. |
| 101 |
|
| 102 |
=item I<name> |
| 103 |
|
| 104 |
I<Name> must be the name of a bitmap defined previously with |
| 105 |
a call to B<Tk_DefineBitmap>. The following names are pre-defined |
| 106 |
by Tk: |
| 107 |
|
| 108 |
=over 4 |
| 109 |
|
| 110 |
=item B<error> |
| 111 |
|
| 112 |
The international "don't" symbol: a circle with a diagonal line |
| 113 |
across it. |
| 114 |
|
| 115 |
=item B<gray75> |
| 116 |
|
| 117 |
75% gray: a checkerboard pattern where three out of four bits are on. |
| 118 |
|
| 119 |
=item B<gray50> |
| 120 |
|
| 121 |
50% gray: a checkerboard pattern where every other bit is on. |
| 122 |
|
| 123 |
=item B<gray25> |
| 124 |
|
| 125 |
25% gray: a checkerboard pattern where one out of every four bits is on. |
| 126 |
|
| 127 |
=item B<gray12> |
| 128 |
|
| 129 |
12.5% gray: a pattern where one-eighth of the bits are on, consisting of |
| 130 |
every fourth pixel in every other row. |
| 131 |
|
| 132 |
=item B<hourglass> |
| 133 |
|
| 134 |
An hourglass symbol. |
| 135 |
|
| 136 |
=item B<info> |
| 137 |
|
| 138 |
A large letter ``i''. |
| 139 |
|
| 140 |
=item B<questhead> |
| 141 |
|
| 142 |
The silhouette of a human head, with a question mark in it. |
| 143 |
|
| 144 |
=item B<question> |
| 145 |
|
| 146 |
A large question-mark. |
| 147 |
|
| 148 |
=item B<warning> |
| 149 |
|
| 150 |
A large exclamation point. |
| 151 |
|
| 152 |
In addition, the following pre-defined names are available only on the |
| 153 |
B<Macintosh> platform: |
| 154 |
|
| 155 |
=item B<document> |
| 156 |
|
| 157 |
A generic document. |
| 158 |
|
| 159 |
=item B<stationery> |
| 160 |
|
| 161 |
Document stationery. |
| 162 |
|
| 163 |
=item B<edition> |
| 164 |
|
| 165 |
The I<edition> symbol. |
| 166 |
|
| 167 |
=item B<application> |
| 168 |
|
| 169 |
Generic application icon. |
| 170 |
|
| 171 |
=item B<accessory> |
| 172 |
|
| 173 |
A desk accessory. |
| 174 |
|
| 175 |
=item B<folder> |
| 176 |
|
| 177 |
Generic folder icon. |
| 178 |
|
| 179 |
=item B<pfolder> |
| 180 |
|
| 181 |
A locked folder. |
| 182 |
|
| 183 |
=item B<trash> |
| 184 |
|
| 185 |
A trash can. |
| 186 |
|
| 187 |
=item B<floppy> |
| 188 |
|
| 189 |
A floppy disk. |
| 190 |
|
| 191 |
=item B<ramdisk> |
| 192 |
|
| 193 |
A floppy disk with chip. |
| 194 |
|
| 195 |
=item B<cdrom> |
| 196 |
|
| 197 |
A cd disk icon. |
| 198 |
|
| 199 |
=item B<preferences> |
| 200 |
|
| 201 |
A folder with prefs symbol. |
| 202 |
|
| 203 |
=item B<querydoc> |
| 204 |
|
| 205 |
A database document icon. |
| 206 |
|
| 207 |
=item B<stop> |
| 208 |
|
| 209 |
A stop sign. |
| 210 |
|
| 211 |
=item B<note> |
| 212 |
|
| 213 |
A face with ballon words. |
| 214 |
|
| 215 |
=item B<caution> |
| 216 |
|
| 217 |
A triangle with an exclamation point. |
| 218 |
|
| 219 |
=back |
| 220 |
|
| 221 |
=back |
| 222 |
|
| 223 |
Under normal conditions, B<Tk_GetBitmap> |
| 224 |
returns an identifier for the requested bitmap. If an error |
| 225 |
occurs in creating the bitmap, such as when I<id> refers |
| 226 |
to a non-existent file, then B<None> is returned and an error |
| 227 |
message is left in I<interp-E<gt>result>. |
| 228 |
|
| 229 |
B<Tk_DefineBitmap> associates a name with |
| 230 |
in-memory bitmap data so that the name can be used in later |
| 231 |
calls to B<Tk_GetBitmap>. The I<nameId> |
| 232 |
argument gives a name for the bitmap; it must not previously |
| 233 |
have been used in a call to B<Tk_DefineBitmap>. |
| 234 |
The arguments I<source>, I<width>, and I<height> |
| 235 |
describe the bitmap. |
| 236 |
B<Tk_DefineBitmap> normally returns TCL_OK; if an error occurs |
| 237 |
(e.g. a bitmap named I<nameId> has already been defined) then |
| 238 |
TCL_ERROR is returned and an error message is left in |
| 239 |
I<interp-E<gt>result>. |
| 240 |
Note: B<Tk_DefineBitmap> expects the memory pointed to by |
| 241 |
I<source> to be static: B<Tk_DefineBitmap> doesn't make |
| 242 |
a private copy of this memory, but uses the bytes pointed to |
| 243 |
by I<source> later in calls to B<Tk_GetBitmap>. |
| 244 |
|
| 245 |
Typically B<Tk_DefineBitmap> is used by B<#include>-ing a |
| 246 |
bitmap file directly into a C program and then referencing |
| 247 |
the variables defined by the file. |
| 248 |
For example, suppose there exists a file B<stip.bitmap>, |
| 249 |
which was created by the B<bitmap> program and contains |
| 250 |
a stipple pattern. |
| 251 |
The following code uses B<Tk_DefineBitmap> to define a |
| 252 |
new bitmap named B<foo>: |
| 253 |
|
| 254 |
Pixmap bitmap; |
| 255 |
#include "stip.bitmap" |
| 256 |
Tk_DefineBitmap(interp, Tk_GetUid("foo"), stip_bits, |
| 257 |
stip_width, stip_height); |
| 258 |
... |
| 259 |
bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid("foo")); |
| 260 |
|
| 261 |
This code causes the bitmap file to be read |
| 262 |
at compile-time and incorporates the bitmap information into |
| 263 |
the program's executable image. The same bitmap file could be |
| 264 |
read at run-time using B<Tk_GetBitmap>: |
| 265 |
|
| 266 |
Pixmap bitmap; |
| 267 |
bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid("@stip.bitmap")); |
| 268 |
|
| 269 |
The second form is a bit more flexible (the file could be modified |
| 270 |
after the program has been compiled, or a different string could be |
| 271 |
provided to read a different file), but it is a little slower and |
| 272 |
requires the bitmap file to exist separately from the program. |
| 273 |
|
| 274 |
B<Tk_GetBitmap> maintains a |
| 275 |
database of all the bitmaps that are currently in use. |
| 276 |
Whenever possible, it will return an existing bitmap rather |
| 277 |
than creating a new one. |
| 278 |
This approach can substantially reduce server overhead, so |
| 279 |
B<Tk_GetBitmap> should generally be used in preference to Xlib |
| 280 |
procedures like B<XReadBitmapFile>. |
| 281 |
|
| 282 |
The bitmaps returned by B<Tk_GetBitmap> |
| 283 |
are shared, so callers should never modify them. |
| 284 |
If a bitmap must be modified dynamically, then it should be |
| 285 |
created by calling Xlib procedures such as B<XReadBitmapFile> |
| 286 |
or B<XCreatePixmap> directly. |
| 287 |
|
| 288 |
The procedure B<Tk_NameOfBitmap> is roughly the inverse of |
| 289 |
B<Tk_GetBitmap>. |
| 290 |
Given an X Pixmap argument, it returns the I<id> that was |
| 291 |
passed to B<Tk_GetBitmap> when the bitmap was created. |
| 292 |
I<Bitmap> must have been the return value from a previous |
| 293 |
call to B<Tk_GetBitmap>. |
| 294 |
|
| 295 |
B<Tk_SizeOfBitmap> returns the dimensions of its I<bitmap> |
| 296 |
argument in the words pointed to by the I<widthPtr> and |
| 297 |
I<heightPtr> arguments. As with B<Tk_NameOfBitmap>, |
| 298 |
I<bitmap> must have been created by B<Tk_GetBitmap>. |
| 299 |
|
| 300 |
When a bitmap returned by B<Tk_GetBitmap> |
| 301 |
is no longer needed, B<Tk_FreeBitmap> should be called to release it. |
| 302 |
There should be exactly one call to B<Tk_FreeBitmap> for |
| 303 |
each call to B<Tk_GetBitmap>. |
| 304 |
When a bitmap is no longer in use anywhere (i.e. it has been freed as |
| 305 |
many times as it has been gotten) B<Tk_FreeBitmap> will release |
| 306 |
it to the X server and delete it from the database. |
| 307 |
|
| 308 |
=head1 BUGS |
| 309 |
|
| 310 |
In determining whether an existing bitmap can be used to satisfy |
| 311 |
a new request, B<Tk_GetBitmap> |
| 312 |
considers only the immediate value of its I<id> argument. For |
| 313 |
example, when a file name is passed to B<Tk_GetBitmap>, |
| 314 |
B<Tk_GetBitmap> will assume it is safe to re-use an existing |
| 315 |
bitmap created from the same file name: it will not check to |
| 316 |
see whether the file itself has changed, or whether the current |
| 317 |
directory has changed, thereby causing the name to refer to |
| 318 |
a different file. |
| 319 |
|
| 320 |
=head1 KEYWORDS |
| 321 |
|
| 322 |
bitmap, pixmap |