summaryrefslogtreecommitdiffstats
path: root/generic/tkImage.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkImage.c')
-rw-r--r--generic/tkImage.c160
1 files changed, 82 insertions, 78 deletions
diff --git a/generic/tkImage.c b/generic/tkImage.c
index 6c7c9cd..5fa3671 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,8 @@ 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;
+ ThreadSpecificData *tsdPtr =
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
if (objc < 2) {
@@ -239,8 +241,10 @@ Tk_ImageObjCmd(
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;
}
@@ -278,6 +282,7 @@ Tk_ImageObjCmd(
if ((objc == 3) || (*(arg = Tcl_GetString(objv[3])) == '-')) {
Tcl_CmdInfo dummy;
+
do {
dispPtr->imageId++;
sprintf(idString, "image%d", dispPtr->imageId);
@@ -311,7 +316,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 +325,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 +333,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,30 +361,30 @@ 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,
@@ -394,7 +399,7 @@ Tk_ImageObjCmd(
if (hPtr == NULL) {
goto alreadyDeleted;
}
- masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr);
+ masterPtr = Tcl_GetHashValue(hPtr);
if (masterPtr->deleted) {
goto alreadyDeleted;
}
@@ -408,7 +413,7 @@ Tk_ImageObjCmd(
}
hPtr = Tcl_FirstHashEntry(&winPtr->mainPtr->imageTable, &search);
for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
- masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr);
+ masterPtr = Tcl_GetHashValue(hPtr);
if (masterPtr->deleted) {
continue;
}
@@ -451,7 +456,7 @@ Tk_ImageObjCmd(
if (hPtr == NULL) {
goto alreadyDeleted;
}
- masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr);
+ masterPtr = Tcl_GetHashValue(hPtr);
if (masterPtr->deleted) {
goto alreadyDeleted;
}
@@ -462,19 +467,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");
@@ -527,8 +533,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 +555,7 @@ Tk_ImageChanged(
*----------------------------------------------------------------------
*/
-CONST char *
+const char *
Tk_NameOfImage(
Tk_ImageMaster imageMaster) /* Token for image. */
{
@@ -589,7 +595,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 +609,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;
@@ -661,7 +667,7 @@ Tk_FreeImage(
*/
if (masterPtr->typePtr != NULL) {
- (*masterPtr->typePtr->freeProc)(imagePtr->instanceData,
+ masterPtr->typePtr->freeProc(imagePtr->instanceData,
imagePtr->display);
}
prevPtr = masterPtr->instancePtr;
@@ -673,7 +679,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 +690,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 +745,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 +766,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 +855,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 +910,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 +923,7 @@ Tk_DeleteImage(
if (hPtr == NULL) {
return;
}
- DeleteImage((ImageMaster *)Tcl_GetHashValue(hPtr));
+ DeleteImage(Tcl_GetHashValue(hPtr));
}
/*
@@ -950,20 +956,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 +1003,7 @@ EventuallyDeleteImage(
}
if (!masterPtr->deleted) {
masterPtr->deleted = 1;
- Tcl_EventuallyFree((ClientData) masterPtr,
- (Tcl_FreeProc *)DeleteImage);
+ Tcl_EventuallyFree(masterPtr, (Tcl_FreeProc *) DeleteImage);
}
}
@@ -1031,7 +1035,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 +1064,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;