📄 tkbitmap.c
字号:
* Results: * The words at *widthPtr and *heightPtr are filled in with * the dimenstions of bitmap. * * Side effects: * If bitmap isn't managed by this module then the procedure * panics.. * *-------------------------------------------------------------- */voidTk_SizeOfBitmap(display, bitmap, widthPtr, heightPtr) Display *display; /* Display for which bitmap was * allocated. */ Pixmap bitmap; /* Bitmap whose size is wanted. */ unsigned int *widthPtr; /* Store bitmap width here. */ unsigned int *heightPtr; /* Store bitmap height here. */{ IdKey idKey; Tcl_HashEntry *idHashPtr; TkBitmap *bitmapPtr; if (!initialized) { unknownBitmap: panic("Tk_SizeOfBitmap received unknown bitmap argument"); } idKey.display = display; idKey.pixmap = bitmap; idHashPtr = Tcl_FindHashEntry(&idTable, (char *) &idKey); if (idHashPtr == NULL) { goto unknownBitmap; } bitmapPtr = (TkBitmap *) Tcl_GetHashValue(idHashPtr); *widthPtr = bitmapPtr->width; *heightPtr = bitmapPtr->height;}/* *---------------------------------------------------------------------- * * Tk_FreeBitmap -- * * This procedure is called to release a bitmap allocated by * Tk_GetBitmap or TkGetBitmapFromData. * * Results: * None. * * Side effects: * The reference count associated with bitmap is decremented, and * it is officially deallocated if no-one is using it anymore. * *---------------------------------------------------------------------- */voidTk_FreeBitmap(display, bitmap) Display *display; /* Display for which bitmap was * allocated. */ Pixmap bitmap; /* Bitmap to be released. */{ Tcl_HashEntry *idHashPtr; register TkBitmap *bitmapPtr; IdKey idKey; if (!initialized) { panic("Tk_FreeBitmap called before Tk_GetBitmap"); } idKey.display = display; idKey.pixmap = bitmap; idHashPtr = Tcl_FindHashEntry(&idTable, (char *) &idKey); if (idHashPtr == NULL) {/* TAKE THIS OUT */ strcpy( (char*)0, "My baloney has a first name...\n" ); panic("Tk_FreeBitmap received unknown bitmap argument"); } bitmapPtr = (TkBitmap *) Tcl_GetHashValue(idHashPtr); bitmapPtr->refCount--; if (bitmapPtr->refCount == 0) { XFreePixmap(bitmapPtr->display, bitmapPtr->bitmap); Tcl_DeleteHashEntry(idHashPtr); Tcl_DeleteHashEntry(bitmapPtr->hashPtr); ckfree((char *) bitmapPtr); }}/* *---------------------------------------------------------------------- * * Tk_GetBitmapFromData -- * * Given a description of the bits for a bitmap, make a bitmap that * has the given properties. *** NOTE: this procedure is obsolete * and really shouldn't be used anymore. *** * * Results: * The return value is the X identifer for the desired bitmap * (a one-plane Pixmap), unless it couldn't be created properly. * In this case, None is returned and an error message is left in * interp->result. The caller should never modify the bitmap that * is returned, and should eventually call Tk_FreeBitmap when the * bitmap is no longer needed. * * Side effects: * The bitmap is added to an internal database with a reference count. * For each call to this procedure, there should eventually be a call * to Tk_FreeBitmap, so that the database can be cleaned up when bitmaps * aren't needed anymore. * *---------------------------------------------------------------------- */ /* ARGSUSED */PixmapTk_GetBitmapFromData(interp, tkwin, source, width, height) Tcl_Interp *interp; /* Interpreter to use for error reporting. */ Tk_Window tkwin; /* Window in which bitmap will be used. */ char *source; /* Bitmap data for bitmap shape. */ unsigned int width, height; /* Dimensions of bitmap. */{ DataKey nameKey; Tcl_HashEntry *dataHashPtr; Tk_Uid name = NULL; /* Initialization need only to prevent * compiler warning. */ int new; static autoNumber = 0; char string[20]; if (!initialized) { BitmapInit(); } nameKey.source = source; nameKey.width = width; nameKey.height = height; dataHashPtr = Tcl_CreateHashEntry(&dataTable, (char *) &nameKey, &new); if (!new) { name = (Tk_Uid) Tcl_GetHashValue(dataHashPtr); } else { autoNumber++; sprintf(string, "_tk%d", autoNumber); name = Tk_GetUid(string); Tcl_SetHashValue(dataHashPtr, name); if (Tk_DefineBitmap(interp, name, source, width, height) != TCL_OK) { Tcl_DeleteHashEntry(dataHashPtr); return TCL_ERROR; } } return Tk_GetBitmap(interp, tkwin, name);}/* *---------------------------------------------------------------------- * * BitmapInit -- * * Initialize the structures used for bitmap management. * * Results: * None. * * Side effects: * Read the code. * *---------------------------------------------------------------------- *//* Define UNSIGNED as <empty> or unsigned, depending on the prototype */#define UNSIGNEDstatic voidBitmapInit(){ Tcl_Interp *dummy; dummy = Tcl_CreateInterp(); initialized = 1; Tcl_InitHashTable(&nameTable, sizeof(NameKey)/sizeof(int)); Tcl_InitHashTable(&dataTable, sizeof(DataKey)/sizeof(int)); Tcl_InitHashTable(&predefTable, TCL_ONE_WORD_KEYS); /* * The call below is tricky: can't use sizeof(IdKey) because it * gets padded with extra unpredictable bytes on some 64-bit * machines. */ Tcl_InitHashTable(&idTable, (sizeof(Display *) + sizeof(Pixmap)) /sizeof(int)); Tk_DefineBitmap(dummy, Tk_GetUid("error"), (UNSIGNED char *)error_bits, error_width, error_height); Tk_DefineBitmap(dummy, Tk_GetUid("gray50"), (UNSIGNED char *)gray50_bits, gray50_width, gray50_height); Tk_DefineBitmap(dummy, Tk_GetUid("gray25"), (UNSIGNED char *)gray25_bits, gray25_width, gray25_height); Tk_DefineBitmap(dummy, Tk_GetUid("hourglass"), (UNSIGNED char *)hourglass_bits, hourglass_width, hourglass_height); Tk_DefineBitmap(dummy, Tk_GetUid("info"), (UNSIGNED char *)info_bits, info_width, info_height); Tk_DefineBitmap(dummy, Tk_GetUid("questhead"), (UNSIGNED char *)questhead_bits, questhead_width, questhead_height); Tk_DefineBitmap(dummy, Tk_GetUid("question"), (UNSIGNED char *)question_bits, question_width, question_height); Tk_DefineBitmap(dummy, Tk_GetUid("warning"), (UNSIGNED char *)warning_bits, warning_width, warning_height); Tcl_DeleteInterp(dummy);}#include "feather.h"Feather_Bitmap Feather_GetBitmap( interp, tkwin, string ) Tcl_Interp *interp; /* Interpreter to use for error reporting. */ Tk_Window tkwin; /* Window in which bitmap will be used. */ Tk_Uid string; /* Description of bitmap. See manual entry * for details on legal syntax. */{ NameKey nameKey; IdKey idKey; Tcl_HashEntry *nameHashPtr, *idHashPtr, *predefHashPtr; register TkBitmap *bitmapPtr; PredefBitmap *predefPtr; int new; Pixmap bitmap; unsigned int width, height; int dummy2; if (!initialized) { BitmapInit(); } nameKey.name = string; nameKey.display = Tk_Display(tkwin); nameHashPtr = Tcl_CreateHashEntry(&nameTable, (char *) &nameKey, &new); if (!new) { bitmapPtr = (TkBitmap *) Tcl_GetHashValue(nameHashPtr); bitmapPtr->refCount++; return (Feather_Bitmap)bitmapPtr;#if DEBUG fprintf( stderr, "returning bitmap %lu, %p, at %p\n", bitmapPtr->bitmap, bitmapPtr->display, bitmapPtr );#endif } /* * No suitable bitmap exists. Create a new bitmap from the * information contained in the string. If the string starts * with "@" then the rest of the string is a file name containing * the bitmap. Otherwise the string must refer to a bitmap * defined by a call to Tk_DefineBitmap. */ if (*string == '@') { Tcl_DString buffer; int result; string = Tcl_TildeSubst(interp, string + 1, &buffer); if (string == NULL) { goto error; } result = XReadBitmapFile(nameKey.display, RootWindowOfScreen(Tk_Screen(tkwin)), string, &width, &height, &bitmap, &dummy2, &dummy2); Tcl_DStringFree(&buffer); if (result != BitmapSuccess) { Tcl_AppendResult(interp, "error reading bitmap file \"", string, "\"", (char *) NULL); goto error; } } else { predefHashPtr = Tcl_FindHashEntry(&predefTable, string); if (predefHashPtr == NULL) { Tcl_AppendResult(interp, "bitmap \"", string, "\" not defined", (char *) NULL); goto error; } predefPtr = (PredefBitmap *) Tcl_GetHashValue(predefHashPtr); width = predefPtr->width; height = predefPtr->height; bitmap = XCreateBitmapFromData(nameKey.display, DefaultRootWindow(nameKey.display), predefPtr->source, width, height); } /* * Add information about this bitmap to our database. */ bitmapPtr = (TkBitmap *) ckalloc(sizeof(TkBitmap)); bitmapPtr->bitmap = bitmap; bitmapPtr->width = width; bitmapPtr->height = height; bitmapPtr->display = nameKey.display; bitmapPtr->refCount = 1; bitmapPtr->hashPtr = nameHashPtr; idKey.display = nameKey.display; idKey.pixmap = bitmap; idHashPtr = Tcl_CreateHashEntry(&idTable, (char *) &idKey, &new); if (!new) { panic("bitmap already registered in Tk_GetBitmap"); } Tcl_SetHashValue(nameHashPtr, bitmapPtr); Tcl_SetHashValue(idHashPtr, bitmapPtr);#if DEBUG fprintf( stderr, "returning bitmap %lu, %p, at %p\n", bitmapPtr->bitmap, bitmapPtr->display, bitmapPtr );#endif return (Feather_Bitmap) bitmapPtr; error: Tcl_DeleteHashEntry(nameHashPtr); return (Feather_Bitmap) 0;}Pixmap Feather_UseBitmap( bitmapVoid )Feather_Bitmap bitmapVoid;{ TkBitmap *bitmapPtr; bitmapPtr = (TkBitmap*)bitmapVoid; if (!bitmapPtr) return None; bitmapPtr->refCount++;#if DEBUG fprintf( stderr, "Using bitmap %ld\n", bitmapPtr->bitmap );#endif return bitmapPtr->bitmap;}void Feather_FreeBitmap( bitmapVoid )Feather_Bitmap bitmapVoid;{ TkBitmap *bitmapPtr; bitmapPtr = (TkBitmap*)bitmapVoid; if (bitmapPtr) Tk_FreeBitmap( bitmapPtr->display, bitmapPtr->bitmap );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -