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

NAME

8       Tk_AllocBitmapFromObj,        Tk_GetBitmap,        Tk_GetBitmapFromObj,
9       Tk_DefineBitmap,  Tk_NameOfBitmap,  Tk_SizeOfBitmap,  Tk_FreeBitmapFro‐
10       mObj, Tk_FreeBitmap - maintain database of single-plane pixmaps
11

SYNOPSIS

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

ARGUMENTS

37       Tcl_Interp *interp (in)               Interpreter   to  use  for  error
38                                             reporting; 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
55                                             defined.
56
57       const char *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
73                                             allocated.
74
75       Pixmap bitmap (in)                    Identifier for a bitmap allocated
76                                             by    Tk_AllocBitmapFromObj    or
77                                             Tk_GetBitmap.
78_________________________________________________________________
79
80

DESCRIPTION

82       These  procedures  manage  a  collection of bitmaps (one-plane pixmaps)
83       being used by an application.  The procedures allow bitmaps to  be  re-
84       used efficiently, thereby avoiding server overhead, and also allow bit‐
85       maps to be named with character strings.
86
87       Tk_AllocBitmapFromObj returns a Pixmap identifier  for  a  bitmap  that
88       matches the description in objPtr and is suitable for use in tkwin.  It
89       re-uses an existing bitmap, if possible, and creates a new  one  other‐
90       wise.  ObjPtr's value must have one of the following forms:
91
92       @fileName           FileName  must  be  the name of a file containing a
93                           bitmap description in the standard X11 or X10  for‐
94                           mat.
95
96       name                Name  must  be  the name of a bitmap defined previ‐
97                           ously with a call to Tk_DefineBitmap.  The  follow‐
98                           ing names are pre-defined by Tk:
99
100                           error       The  international  “don't”  symbol:  a
101                                       circle with a diagonal line across it.
102
103                           gray75      75% gray: a checkerboard pattern  where
104                                       three out of four bits are on.
105
106                           gray50      50%  gray: a checkerboard pattern where
107                                       every other bit is on.
108
109                           gray25      25% gray: a checkerboard pattern  where
110                                       one out of every four bits is on.
111
112                           gray12      12.5%  gray: a pattern where one-eighth
113                                       of the bits are on, consisting of every
114                                       fourth pixel in every other row.
115
116                           hourglass   An hourglass symbol.
117
118                           info        A large letter “i”.
119
120                           questhead   The  silhouette of a human head, with a
121                                       question mark in it.
122
123                           question    A large question-mark.
124
125                           warning     A large exclamation point.
126
127                           In addition, the following  pre-defined  names  are
128                           available only on the Macintosh platform:
129
130                           document    A generic document.
131
132                           stationery  Document stationery.
133
134                           edition     The edition symbol.
135
136                           application Generic application icon.
137
138                           accessory   A desk accessory.
139
140                           folder      Generic folder icon.
141
142                           pfolder     A locked folder.
143
144                           trash       A trash can.
145
146                           floppy      A floppy disk.
147
148                           ramdisk     A floppy disk with chip.
149
150                           cdrom       A cd disk icon.
151
152                           preferences A folder with prefs symbol.
153
154                           querydoc    A database document icon.
155
156                           stop        A stop sign.
157
158                           note        A face with balloon words.
159
160                           caution     A triangle with an exclamation point.
161
162       Under  normal  conditions,  Tk_AllocBitmapFromObj returns an identifier
163       for the requested bitmap.  If an error occurs in creating  the  bitmap,
164       such  as  when  objPtr  refers  to  a  non-existent  file, then None is
165       returned and an error message is left in interp's result if  interp  is
166       not  NULL.  Tk_AllocBitmapFromObj  caches  information about the return
167       value in objPtr, which speeds up future calls  to  procedures  such  as
168       Tk_AllocBitmapFromObj and Tk_GetBitmapFromObj.
169
170       Tk_GetBitmap  is  identical  to  Tk_AllocBitmapFromObj  except that the
171       description of the bitmap is specified with  a  string  instead  of  an
172       object.   This  prevents Tk_GetBitmap from caching the return value, so
173       Tk_GetBitmap is less efficient than Tk_AllocBitmapFromObj.
174
175       Tk_GetBitmapFromObj returns the token for an existing bitmap, given the
176       window  and description used to create the bitmap.  Tk_GetBitmapFromObj
177       does not actually create the bitmap; the bitmap must already have  been
178       created  with a previous call to Tk_AllocBitmapFromObj or Tk_GetBitmap.
179       The return value is cached in objPtr, which speeds up future  calls  to
180       Tk_GetBitmapFromObj with the same objPtr and tkwin.
181
182       Tk_DefineBitmap  associates  a  name with in-memory bitmap data so that
183       the name can be used in later calls to Tk_AllocBitmapFromObj or Tk_Get‐
184       Bitmap.   The nameId argument gives a name for the bitmap;  it must not
185       previously have been used in a call to Tk_DefineBitmap.  The  arguments
186       source,  width,  and  height describe the bitmap.  Tk_DefineBitmap nor‐
187       mally returns TCL_OK; if an error occurs (e.g. a  bitmap  named  nameId
188       has  already been defined) then TCL_ERROR is returned and an error mes‐
189       sage is left in interp->result.   Note:   Tk_DefineBitmap  expects  the
190       memory  pointed  to  by  source to be static:  Tk_DefineBitmap does not
191       make a private copy of this memory, but uses the bytes  pointed  to  by
192       source later in calls to Tk_AllocBitmapFromObj or Tk_GetBitmap.
193
194       Typically  Tk_DefineBitmap  is  used  by  #include-ing  a  bitmap  file
195       directly into a C program and then referencing the variables defined by
196       the  file.  For example, suppose there exists a file stip.bitmap, which
197       was created by the bitmap program and contains a stipple pattern.   The
198       following code uses Tk_DefineBitmap to define a new bitmap named foo:
199              Pixmap bitmap;
200              #include "stip.bitmap"
201              Tk_DefineBitmap(interp, "foo", stip_bits,
202                  stip_width, stip_height);
203              ...
204              bitmap = Tk_GetBitmap(interp, tkwin, "foo");
205       This  code causes the bitmap file to be read at compile-time and incor‐
206       porates the bitmap information into  the  program's  executable  image.
207       The same bitmap file could be read at run-time using Tk_GetBitmap:
208              Pixmap bitmap;
209              bitmap = Tk_GetBitmap(interp, tkwin, "@stip.bitmap");
210       The  second  form  is  a  bit more flexible (the file could be modified
211       after the program has been compiled, or a  different  string  could  be
212       provided  to  read  a  different  file),  but it is a little slower and
213       requires the bitmap file to exist separately from the program.
214
215       Tk maintains a database of all the bitmaps that are currently  in  use.
216       Whenever possible, it will return an existing bitmap rather than creat‐
217       ing a new one.  When a bitmap is no longer used,  Tk  will  release  it
218       automatically.  This approach can substantially reduce server overhead,
219       so Tk_AllocBitmapFromObj and Tk_GetBitmap should generally be  used  in
220       preference to Xlib procedures like XReadBitmapFile.
221
222       The  bitmaps  returned  by  Tk_AllocBitmapFromObj  and Tk_GetBitmap are
223       shared, so callers should never modify them.  If a bitmap must be modi‐
224       fied  dynamically, then it should be created by calling Xlib procedures
225       such as XReadBitmapFile or XCreatePixmap directly.
226
227       The procedure Tk_NameOfBitmap is roughly the inverse  of  Tk_GetBitmap.
228       Given an X Pixmap argument, it returns the textual description that was
229       passed to Tk_GetBitmap when the bitmap was created.  Bitmap  must  have
230       been  the return value from a previous call to Tk_AllocBitmapFromObj or
231       Tk_GetBitmap.
232
233       Tk_SizeOfBitmap returns the dimensions of its bitmap  argument  in  the
234       words  pointed  to  by  the  widthPtr and heightPtr arguments.  As with
235       Tk_NameOfBitmap, bitmap must have been created by Tk_AllocBitmapFromObj
236       or Tk_GetBitmap.
237
238       When   a   bitmap   is   no   longer  needed,  Tk_FreeBitmapFromObj  or
239       Tk_FreeBitmap should be called to release it.  For Tk_FreeBitmapFromObj
240       the  bitmap  to  release is specified with the same information used to
241       create it; for Tk_FreeBitmap the bitmap to release  is  specified  with
242       its   Pixmap   token.    There   should   be   exactly   one   call  to
243       Tk_FreeBitmapFromObj   or    Tk_FreeBitmap    for    each    call    to
244       Tk_AllocBitmapFromObj or Tk_GetBitmap.
245
246

BUGS

248       In  determining whether an existing bitmap can be used to satisfy a new
249       request, Tk_AllocBitmapFromObj and Tk_GetBitmap consider only the imme‐
250       diate  value  of the string description.  For example, when a file name
251       is passed to Tk_GetBitmap, Tk_GetBitmap will assume it is safe  to  re-
252       use  an  existing  bitmap created from the same file name:  it will not
253       check to see whether the file itself has changed, or whether  the  cur‐
254       rent directory has changed, thereby causing the name to refer to a dif‐
255       ferent file.
256
257

KEYWORDS

259       bitmap, pixmap
260
261
262
263Tk                                    8.1             Tk_AllocBitmapFromObj(3)
Impressum