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)                                    │
45                                             String  value  describes  desired │
46                                             bitmap; internal rep will be mod‐ │
47                                             ified to cache pointer to  corre‐ │
48                                             sponding Pixmap.                  │
49
50       CONST char      *info       (in)                                        │
51                                             Same as objPtr except description │
52                                             of bitmap is passed as  a  string │
53                                             and    resulting   Pixmap   isn't │
54                                             cached.
55
56       CONST char      *name       (in)      Name  for  new   bitmap   to   be
57                                             defined.
58
59       CONST char      *source     (in)      Data for bitmap, in standard bit‐
60                                             map format.  Must  be  stored  in
61                                             static  memory  whose  value will
62                                             never change.
63
64       int             width       (in)      Width of bitmap.
65
66       int             height      (in)      Height of bitmap.
67
68       int             *widthPtr   (out)     Pointer to word to fill  in  with
69                                             bitmap's width.
70
71       int             *heightPtr  (out)     Pointer  to  word to fill in with
72                                             bitmap's height.
73
74       Display         *display    (in)      Display  for  which  bitmap   was
75                                             allocated.
76
77       Pixmap          bitmap      (in)      Identifier for a bitmap allocated
78                                             by    Tk_AllocBitmapFromObj    or
79                                             Tk_GetBitmap.
80_________________________________________________________________
81
82

DESCRIPTION

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

BUGS

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

KEYWORDS

263       bitmap, pixmap
264
265
266
267Tk                                    8.1             Tk_AllocBitmapFromObj(3)
Impressum