diff options
Diffstat (limited to 'generic/tkImage.c')
-rw-r--r-- | generic/tkImage.c | 204 |
1 files changed, 109 insertions, 95 deletions
diff --git a/generic/tkImage.c b/generic/tkImage.c index 6c7c9cd..359d6c6 100644 --- a/generic/tkImage.c +++ b/generic/tkImage.c @@ -15,8 +15,8 @@ /* * Each call to Tk_GetImage returns a pointer to one of the following - * structures, which is used as a token by clients (widgets) that - * display images. + * structures, which is used as a token by clients (widgets) that display + * images. */ typedef struct Image { @@ -106,22 +106,22 @@ static void ImageTypeThreadExitProc( ClientData clientData) /* not used */ { - Tk_ImageType *freePtr; + Tk_ImageType *freePtr; ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); while (tsdPtr->oldImageTypeList != NULL) { freePtr = tsdPtr->oldImageTypeList; tsdPtr->oldImageTypeList = tsdPtr->oldImageTypeList->nextPtr; - ckfree((char *) freePtr); + ckfree(freePtr); } while (tsdPtr->imageTypeList != NULL) { freePtr = tsdPtr->imageTypeList; tsdPtr->imageTypeList = tsdPtr->imageTypeList->nextPtr; - ckfree((char *) freePtr); + ckfree(freePtr); } } - + /* *---------------------------------------------------------------------- * @@ -143,11 +143,12 @@ ImageTypeThreadExitProc( void Tk_CreateOldImageType( - Tk_ImageType *typePtr) /* Structure describing the type. All of the + const Tk_ImageType *typePtr) + /* Structure describing the type. All of the * fields except "nextPtr" must be filled in * by caller. */ { - Tk_ImageType *copyPtr; + Tk_ImageType *copyPtr; ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); @@ -155,7 +156,7 @@ Tk_CreateOldImageType( tsdPtr->initialized = 1; Tcl_CreateThreadExitHandler(ImageTypeThreadExitProc, NULL); } - copyPtr = (Tk_ImageType *) ckalloc(sizeof(Tk_ImageType)); + copyPtr = ckalloc(sizeof(Tk_ImageType)); *copyPtr = *typePtr; copyPtr->nextPtr = tsdPtr->oldImageTypeList; tsdPtr->oldImageTypeList = copyPtr; @@ -163,11 +164,12 @@ Tk_CreateOldImageType( void Tk_CreateImageType( - Tk_ImageType *typePtr) /* Structure describing the type. All of the + const Tk_ImageType *typePtr) + /* Structure describing the type. All of the * fields except "nextPtr" must be filled in * by caller. */ { - Tk_ImageType *copyPtr; + Tk_ImageType *copyPtr; ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); @@ -175,7 +177,7 @@ Tk_CreateImageType( tsdPtr->initialized = 1; Tcl_CreateThreadExitHandler(ImageTypeThreadExitProc, NULL); } - copyPtr = (Tk_ImageType *) ckalloc(sizeof(Tk_ImageType)); + copyPtr = ckalloc(sizeof(Tk_ImageType)); *copyPtr = *typePtr; copyPtr->nextPtr = tsdPtr->imageTypeList; tsdPtr->imageTypeList = copyPtr; @@ -203,9 +205,9 @@ Tk_ImageObjCmd( ClientData clientData, /* Main window associated with interpreter. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument strings. */ + Tcl_Obj *const objv[]) /* Argument strings. */ { - static CONST char *imageOptions[] = { + static const char *const imageOptions[] = { "create", "delete", "height", "inuse", "names", "type", "types", "width", NULL }; @@ -213,7 +215,7 @@ Tk_ImageObjCmd( IMAGE_CREATE, IMAGE_DELETE, IMAGE_HEIGHT, IMAGE_INUSE, IMAGE_NAMES, IMAGE_TYPE, IMAGE_TYPES, IMAGE_WIDTH }; - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; int i, isNew, firstOption, index; Tk_ImageType *typePtr; ImageMaster *masterPtr; @@ -222,8 +224,9 @@ Tk_ImageObjCmd( Tcl_HashSearch search; char idString[16 + TCL_INTEGER_SPACE]; TkDisplay *dispPtr = winPtr->dispPtr; - char *arg, *name; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + const char *arg, *name; + Tcl_Obj *resultObj; + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (objc < 2) { @@ -231,16 +234,18 @@ Tk_ImageObjCmd( return TCL_ERROR; } - if (Tcl_GetIndexFromObj(interp, objv[1], imageOptions, "option", 0, - &index) != TCL_OK) { + if (Tcl_GetIndexFromObjStruct(interp, objv[1], imageOptions, + sizeof(char *), "option", 0, &index) != TCL_OK) { return TCL_ERROR; } switch ((enum options) index) { case IMAGE_CREATE: { Tcl_Obj **args; int oldimage = 0; + if (objc < 3) { - Tcl_WrongNumArgs(interp, 2, objv, "type ?name? ?options?"); + Tcl_WrongNumArgs(interp, 2, objv, + "type ?name? ?-option value ...?"); return TCL_ERROR; } @@ -267,8 +272,9 @@ Tk_ImageObjCmd( } } if (typePtr == NULL) { - Tcl_AppendResult(interp, "image type \"", arg, "\" doesn't exist", - NULL); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "image type \"%s\" doesn't exist", arg)); + Tcl_SetErrorCode(interp, "TK", "LOOKUP", "IMAGE_TYPE", arg, NULL); return TCL_ERROR; } @@ -277,12 +283,11 @@ Tk_ImageObjCmd( */ if ((objc == 3) || (*(arg = Tcl_GetString(objv[3])) == '-')) { - Tcl_CmdInfo dummy; do { dispPtr->imageId++; sprintf(idString, "image%d", dispPtr->imageId); name = idString; - } while (Tcl_GetCommandInfo(interp, name, &dummy) != 0); + } while (Tcl_FindCommand(interp, name, NULL, 0) != NULL); firstOption = 3; } else { TkWindow *topWin; @@ -299,8 +304,10 @@ Tk_ImageObjCmd( topWin = (TkWindow *) TkToplevelWindowForCommand(interp, name); if (topWin != NULL && winPtr->mainPtr->winPtr == topWin) { - Tcl_AppendResult(interp, "images may not be named the ", - "same as the main window", NULL); + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "images may not be named the same as the main window", + -1)); + Tcl_SetErrorCode(interp, "TK", "IMAGE", "SMASH_MAIN", NULL); return TCL_ERROR; } } @@ -311,7 +318,7 @@ Tk_ImageObjCmd( hPtr = Tcl_CreateHashEntry(&winPtr->mainPtr->imageTable, name, &isNew); if (isNew) { - masterPtr = (ImageMaster *) ckalloc(sizeof(ImageMaster)); + masterPtr = ckalloc(sizeof(ImageMaster)); masterPtr->typePtr = NULL; masterPtr->masterData = NULL; masterPtr->width = masterPtr->height = 1; @@ -320,7 +327,7 @@ Tk_ImageObjCmd( masterPtr->instancePtr = NULL; masterPtr->deleted = 0; masterPtr->winPtr = winPtr->mainPtr->winPtr; - Tcl_Preserve((ClientData) masterPtr->winPtr); + Tcl_Preserve(masterPtr->winPtr); Tcl_SetHashValue(hPtr, masterPtr); } else { /* @@ -328,17 +335,17 @@ Tk_ImageObjCmd( * from the master. */ - masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); if (masterPtr->typePtr != NULL) { for (imagePtr = masterPtr->instancePtr; imagePtr != NULL; imagePtr = imagePtr->nextPtr) { - (*masterPtr->typePtr->freeProc)(imagePtr->instanceData, + masterPtr->typePtr->freeProc(imagePtr->instanceData, imagePtr->display); - (*imagePtr->changeProc)(imagePtr->widgetClientData, - 0, 0, masterPtr->width, masterPtr->height, + imagePtr->changeProc(imagePtr->widgetClientData, 0, 0, + masterPtr->width, masterPtr->height, masterPtr->width, masterPtr->height); } - (*masterPtr->typePtr->deleteProc)(masterPtr->masterData); + masterPtr->typePtr->deleteProc(masterPtr->masterData); masterPtr->typePtr = NULL; } masterPtr->deleted = 0; @@ -356,35 +363,34 @@ Tk_ImageObjCmd( if (oldimage) { int i; - args = (Tcl_Obj **) ckalloc((objc+1) * sizeof(char *)); + args = ckalloc((objc+1) * sizeof(char *)); for (i = 0; i < objc; i++) { args[i] = (Tcl_Obj *) Tcl_GetString(objv[i]); } args[objc] = NULL; } - Tcl_Preserve((ClientData) masterPtr); - if ((*typePtr->createProc)(interp, name, objc, args, typePtr, - (Tk_ImageMaster)masterPtr, &masterPtr->masterData) != TCL_OK) { + Tcl_Preserve(masterPtr); + if (typePtr->createProc(interp, name, objc, args, typePtr, + (Tk_ImageMaster)masterPtr, &masterPtr->masterData) != TCL_OK){ EventuallyDeleteImage(masterPtr, 0); - Tcl_Release((ClientData) masterPtr); + Tcl_Release(masterPtr); if (oldimage) { - ckfree((char *) args); + ckfree(args); } return TCL_ERROR; } - Tcl_Release((ClientData) masterPtr); + Tcl_Release(masterPtr); if (oldimage) { - ckfree((char *) args); + ckfree(args); } masterPtr->typePtr = typePtr; for (imagePtr = masterPtr->instancePtr; imagePtr != NULL; imagePtr = imagePtr->nextPtr) { - imagePtr->instanceData = (*typePtr->getProc)(imagePtr->tkwin, + imagePtr->instanceData = typePtr->getProc(imagePtr->tkwin, masterPtr->masterData); } - Tcl_SetResult(interp, - Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), - TCL_STATIC); + Tcl_SetObjResult(interp, Tcl_NewStringObj( + Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), -1)); break; } case IMAGE_DELETE: @@ -394,7 +400,7 @@ Tk_ImageObjCmd( if (hPtr == NULL) { goto alreadyDeleted; } - masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); if (masterPtr->deleted) { goto alreadyDeleted; } @@ -407,28 +413,34 @@ Tk_ImageObjCmd( return TCL_ERROR; } hPtr = Tcl_FirstHashEntry(&winPtr->mainPtr->imageTable, &search); + resultObj = Tcl_NewObj(); for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); if (masterPtr->deleted) { continue; } - Tcl_AppendElement(interp, Tcl_GetHashKey( - &winPtr->mainPtr->imageTable, hPtr)); + Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj( + Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), -1)); } + Tcl_SetObjResult(interp, resultObj); break; case IMAGE_TYPES: if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, NULL); return TCL_ERROR; } + resultObj = Tcl_NewObj(); for (typePtr = tsdPtr->imageTypeList; typePtr != NULL; typePtr = typePtr->nextPtr) { - Tcl_AppendElement(interp, typePtr->name); + Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj( + typePtr->name, -1)); } for (typePtr = tsdPtr->oldImageTypeList; typePtr != NULL; typePtr = typePtr->nextPtr) { - Tcl_AppendElement(interp, typePtr->name); + Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj( + typePtr->name, -1)); } + Tcl_SetObjResult(interp, resultObj); break; case IMAGE_HEIGHT: @@ -451,7 +463,7 @@ Tk_ImageObjCmd( if (hPtr == NULL) { goto alreadyDeleted; } - masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); if (masterPtr->deleted) { goto alreadyDeleted; } @@ -462,19 +474,20 @@ Tk_ImageObjCmd( switch ((enum options) index) { case IMAGE_HEIGHT: - Tcl_SetIntObj(Tcl_GetObjResult(interp), masterPtr->height); + Tcl_SetObjResult(interp, Tcl_NewIntObj(masterPtr->height)); break; case IMAGE_INUSE: - Tcl_SetBooleanObj(Tcl_GetObjResult(interp), - masterPtr->typePtr!=NULL && masterPtr->instancePtr!=NULL); + Tcl_SetObjResult(interp, Tcl_NewBooleanObj( + masterPtr->typePtr && masterPtr->instancePtr)); break; case IMAGE_TYPE: if (masterPtr->typePtr != NULL) { - Tcl_SetResult(interp, masterPtr->typePtr->name, TCL_STATIC); + Tcl_SetObjResult(interp, + Tcl_NewStringObj(masterPtr->typePtr->name, -1)); } break; case IMAGE_WIDTH: - Tcl_SetIntObj(Tcl_GetObjResult(interp), masterPtr->width); + Tcl_SetObjResult(interp, Tcl_NewIntObj(masterPtr->width)); break; default: Tcl_Panic("can't happen"); @@ -484,7 +497,8 @@ Tk_ImageObjCmd( return TCL_OK; alreadyDeleted: - Tcl_AppendResult(interp, "image \"", arg, "\" doesn't exist", NULL); + Tcl_SetObjResult(interp, Tcl_ObjPrintf("image \"%s\" doesn't exist",arg)); + Tcl_SetErrorCode(interp, "TK", "LOOKUP", "IMAGE", arg, NULL); return TCL_ERROR; } @@ -527,8 +541,8 @@ Tk_ImageChanged( masterPtr->height = imageHeight; for (imagePtr = masterPtr->instancePtr; imagePtr != NULL; imagePtr = imagePtr->nextPtr) { - (*imagePtr->changeProc)(imagePtr->widgetClientData, x, y, - width, height, imageWidth, imageHeight); + imagePtr->changeProc(imagePtr->widgetClientData, x, y, width, height, + imageWidth, imageHeight); } } @@ -549,7 +563,7 @@ Tk_ImageChanged( *---------------------------------------------------------------------- */ -CONST char * +const char * Tk_NameOfImage( Tk_ImageMaster imageMaster) /* Token for image. */ { @@ -589,7 +603,7 @@ Tk_GetImage( * be found. */ Tk_Window tkwin, /* Token for window in which image will be * used. */ - CONST char *name, /* Name of desired image. */ + const char *name, /* Name of desired image. */ Tk_ImageChangedProc *changeProc, /* Function to invoke when redisplay is needed * because image's pixels or size changed. */ @@ -603,19 +617,19 @@ Tk_GetImage( if (hPtr == NULL) { goto noSuchImage; } - masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); if (masterPtr->typePtr == NULL) { goto noSuchImage; } if (masterPtr->deleted) { goto noSuchImage; } - imagePtr = (Image *) ckalloc(sizeof(Image)); + imagePtr = ckalloc(sizeof(Image)); imagePtr->tkwin = tkwin; imagePtr->display = Tk_Display(tkwin); imagePtr->masterPtr = masterPtr; imagePtr->instanceData = - (*masterPtr->typePtr->getProc)(tkwin, masterPtr->masterData); + masterPtr->typePtr->getProc(tkwin, masterPtr->masterData); imagePtr->changeProc = changeProc; imagePtr->widgetClientData = clientData; imagePtr->nextPtr = masterPtr->instancePtr; @@ -624,7 +638,9 @@ Tk_GetImage( noSuchImage: if (interp) { - Tcl_AppendResult(interp, "image \"", name, "\" doesn't exist", NULL); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "image \"%s\" doesn't exist", name)); + Tcl_SetErrorCode(interp, "TK", "LOOKUP", "IMAGE", name, NULL); } return NULL; } @@ -661,7 +677,7 @@ Tk_FreeImage( */ if (masterPtr->typePtr != NULL) { - (*masterPtr->typePtr->freeProc)(imagePtr->instanceData, + masterPtr->typePtr->freeProc(imagePtr->instanceData, imagePtr->display); } prevPtr = masterPtr->instancePtr; @@ -673,7 +689,7 @@ Tk_FreeImage( } prevPtr->nextPtr = imagePtr->nextPtr; } - ckfree((char *) imagePtr); + ckfree(imagePtr); /* * If there are no more instances left for the master, and if the master @@ -684,8 +700,8 @@ Tk_FreeImage( if (masterPtr->hPtr != NULL) { Tcl_DeleteHashEntry(masterPtr->hPtr); } - Tcl_Release((ClientData) masterPtr->winPtr); - ckfree((char *) masterPtr); + Tcl_Release(masterPtr->winPtr); + ckfree(masterPtr); } } @@ -739,9 +755,9 @@ Tk_PostscriptImage( */ if (imagePtr->masterPtr->typePtr->postscriptProc != NULL) { - return (*imagePtr->masterPtr->typePtr->postscriptProc)( - imagePtr->masterPtr->masterData, interp, tkwin, psinfo, - x, y, width, height, prepass); + return imagePtr->masterPtr->typePtr->postscriptProc( + imagePtr->masterPtr->masterData, interp, tkwin, psinfo, + x, y, width, height, prepass); } if (prepass) { @@ -760,15 +776,15 @@ Tk_PostscriptImage( gcValues.foreground = WhitePixelOfScreen(Tk_Screen(tkwin)); newGC = Tk_GetGC(tkwin, GCForeground, &gcValues); if (newGC != None) { - XFillRectangle(Tk_Display(tkwin), pmap, newGC, - 0, 0, (unsigned int)width, (unsigned int)height); + XFillRectangle(Tk_Display(tkwin), pmap, newGC, 0, 0, + (unsigned) width, (unsigned) height); Tk_FreeGC(Tk_Display(tkwin), newGC); } Tk_RedrawImage(image, x, y, width, height, pmap, 0, 0); ximage = XGetImage(Tk_Display(tkwin), pmap, 0, 0, - (unsigned int)width, (unsigned int)height, AllPlanes, ZPixmap); + (unsigned) width, (unsigned) height, AllPlanes, ZPixmap); Tk_FreePixmap(Tk_Display(tkwin), pmap); @@ -849,9 +865,9 @@ Tk_RedrawImage( if ((imageY + height) > imagePtr->masterPtr->height) { height = imagePtr->masterPtr->height - imageY; } - (*imagePtr->masterPtr->typePtr->displayProc)( - imagePtr->instanceData, imagePtr->display, drawable, - imageX, imageY, width, height, drawableX, drawableY); + imagePtr->masterPtr->typePtr->displayProc(imagePtr->instanceData, + imagePtr->display, drawable, imageX, imageY, width, height, + drawableX, drawableY); } /* @@ -904,7 +920,7 @@ void Tk_DeleteImage( Tcl_Interp *interp, /* Interpreter in which the image was * created. */ - CONST char *name) /* Name of image. */ + const char *name) /* Name of image. */ { Tcl_HashEntry *hPtr; TkWindow *winPtr; @@ -917,7 +933,7 @@ Tk_DeleteImage( if (hPtr == NULL) { return; } - DeleteImage((ImageMaster *)Tcl_GetHashValue(hPtr)); + DeleteImage(Tcl_GetHashValue(hPtr)); } /* @@ -950,20 +966,19 @@ DeleteImage( if (typePtr != NULL) { for (imagePtr = masterPtr->instancePtr; imagePtr != NULL; imagePtr = imagePtr->nextPtr) { - (*typePtr->freeProc)(imagePtr->instanceData, - imagePtr->display); - (*imagePtr->changeProc)(imagePtr->widgetClientData, 0, 0, + typePtr->freeProc(imagePtr->instanceData, imagePtr->display); + imagePtr->changeProc(imagePtr->widgetClientData, 0, 0, masterPtr->width, masterPtr->height, masterPtr->width, masterPtr->height); } - (*typePtr->deleteProc)(masterPtr->masterData); + typePtr->deleteProc(masterPtr->masterData); } if (masterPtr->instancePtr == NULL) { if (masterPtr->hPtr != NULL) { Tcl_DeleteHashEntry(masterPtr->hPtr); } - Tcl_Release((ClientData) masterPtr->winPtr); - ckfree((char *) masterPtr); + Tcl_Release(masterPtr->winPtr); + ckfree(masterPtr); } else { masterPtr->deleted = 1; } @@ -998,8 +1013,7 @@ EventuallyDeleteImage( } if (!masterPtr->deleted) { masterPtr->deleted = 1; - Tcl_EventuallyFree((ClientData) masterPtr, - (Tcl_FreeProc *)DeleteImage); + Tcl_EventuallyFree(masterPtr, (Tcl_FreeProc *) DeleteImage); } } @@ -1031,7 +1045,7 @@ TkDeleteAllImages( for (hPtr = Tcl_FirstHashEntry(&mainPtr->imageTable, &search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - EventuallyDeleteImage((ImageMaster *) Tcl_GetHashValue(hPtr), 1); + EventuallyDeleteImage(Tcl_GetHashValue(hPtr), 1); } Tcl_DeleteHashTable(&mainPtr->imageTable); } @@ -1060,21 +1074,21 @@ ClientData Tk_GetImageMasterData( Tcl_Interp *interp, /* Interpreter in which the image was * created. */ - CONST char *name, /* Name of image. */ - Tk_ImageType **typePtrPtr) /* Points to location to fill in with pointer + const char *name, /* Name of image. */ + const Tk_ImageType **typePtrPtr) + /* Points to location to fill in with pointer * to type information for image. */ { + TkWindow *winPtr = (TkWindow *) Tk_MainWindow(interp); Tcl_HashEntry *hPtr; - TkWindow *winPtr; ImageMaster *masterPtr; - winPtr = (TkWindow *) Tk_MainWindow(interp); hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->imageTable, name); if (hPtr == NULL) { *typePtrPtr = NULL; return NULL; } - masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); if (masterPtr->deleted) { *typePtrPtr = NULL; return NULL; |