*---------------------------------------------------------------------- * * Tk_GetPixmap -- * * Given a string describing a bitmap or pixmap, locate (or create * if necessary) a pixmap that fits the description. * * Results: * The return value is the X identifer for the desired pixmap, * unless string couldn't be parsed correctly. In this case, * None is returned and an e
(interp, tkwin, string)
| 145 | * |
| 146 | *---------------------------------------------------------------------- |
| 147 | */ |
| 148 | Pixmap |
| 149 | Tk_GetPixmap(interp, tkwin, string) |
| 150 | Tcl_Interp *interp; /* Interpreter to use for error reporting. */ |
| 151 | Tk_Window tkwin; /* Window in which pixmap will be used. */ |
| 152 | Tk_Uid string; /* Description of pixmap. See manual entry |
| 153 | * for details on legal syntax. */ |
| 154 | { |
| 155 | NameKey key; |
| 156 | Tcl_HashEntry *nameHashPtr, *idHashPtr, *predefHashPtr; |
| 157 | register TkBitmap *bitmapPtr; |
| 158 | PredefBitmap *predefPtr; |
| 159 | int new; |
| 160 | Pixmap bitmap; |
| 161 | Pixmap bitmap_shape; |
| 162 | unsigned int width, height; |
| 163 | int dummy2; |
| 164 | XpmAttributes xpm_attributes; |
| 165 | Display *dpy = Tk_Display(tkwin); |
| 166 | |
| 167 | if (!initialized) { |
| 168 | PixmapInit(tkwin); |
| 169 | } |
| 170 | |
| 171 | key.name = string; |
| 172 | key.screen = Tk_Screen(tkwin); |
| 173 | nameHashPtr = Tcl_CreateHashEntry(&nameTable, (char *) &key, &new); |
| 174 | if (!new) { |
| 175 | bitmapPtr = (TkBitmap *) Tcl_GetHashValue(nameHashPtr); |
| 176 | bitmapPtr->refCount++; |
| 177 | return bitmapPtr->bitmap; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * No suitable bitmap exists. Create a new bitmap from the |
| 182 | * information contained in the string. If the string starts |
| 183 | * with "@" then the rest of the string is a file name containing |
| 184 | * the bitmap. Otherwise the string must refer to a bitmap |
| 185 | * defined by a call to Tk_DefinePixmap. |
| 186 | */ |
| 187 | |
| 188 | if (*string == '@') { |
| 189 | string = Tcl_TildeSubst(interp, string + 1); |
| 190 | if (string == NULL) { |
| 191 | goto error; |
| 192 | } |
| 193 | |
| 194 | if (XReadBitmapFile(dpy, RootWindowOfScreen(Tk_Screen(tkwin)), |
| 195 | string, &width, &height, &bitmap_shape, &dummy2, &dummy2) |
| 196 | != BitmapSuccess) |
| 197 | { |
| 198 | xpm_attributes.visual = Tk_DefaultVisual(Tk_Screen(tkwin)); |
| 199 | xpm_attributes.colormap = Tk_DefaultColormap(Tk_Screen(tkwin)); |
| 200 | xpm_attributes.depth = Tk_DefaultDepth(Tk_Screen(tkwin)); |
| 201 | xpm_attributes.valuemask = XpmVisual | XpmColormap | XpmDepth; |
| 202 | |
| 203 | if (XpmReadFileToPixmap(dpy, RootWindowOfScreen(Tk_Screen(tkwin)), |
| 204 | string, &bitmap, &bitmap_shape, |
no test coverage detected