diff options
Diffstat (limited to 'generic/tkTextImage.c')
-rw-r--r-- | generic/tkTextImage.c | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/generic/tkTextImage.c b/generic/tkTextImage.c index 41dd448..bc2b7c4 100644 --- a/generic/tkTextImage.c +++ b/generic/tkTextImage.c @@ -54,7 +54,7 @@ static void EmbImageProc(ClientData clientData, int x, int y, * The following structure declares the "embedded image" segment type. */ -const Tk_SegType tkTextEmbImageType = { +static const Tk_SegType tkTextEmbImageType = { "image", /* name */ 0, /* leftGravity */ NULL, /* splitProc */ @@ -69,7 +69,7 @@ const Tk_SegType tkTextEmbImageType = { * Definitions for alignment values: */ -static const char *const alignStrings[] = { +static const char *alignStrings[] = { "baseline", "bottom", "center", "top", NULL }; @@ -84,7 +84,7 @@ typedef enum { static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_STRING_TABLE, "-align", NULL, NULL, "center", -1, Tk_Offset(TkTextEmbImage, align), - 0, alignStrings, 0}, + 0, (ClientData) alignStrings, 0}, {TK_OPTION_PIXELS, "-padx", NULL, NULL, "0", -1, Tk_Offset(TkTextEmbImage, padX), 0, 0, 0}, {TK_OPTION_PIXELS, "-pady", NULL, NULL, @@ -95,8 +95,9 @@ static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_STRING, "-name", NULL, NULL, NULL, -1, Tk_Offset(TkTextEmbImage, imageName), TK_OPTION_NULL_OK, 0, 0}, - {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0} + {TK_OPTION_END} }; + /* *-------------------------------------------------------------- @@ -127,7 +128,7 @@ TkTextImageCmd( int idx; register TkTextSegment *eiPtr; TkTextIndex index; - static const char *const optionStrings[] = { + static const char *optionStrings[] = { "cget", "configure", "create", "names", NULL }; enum opts { @@ -135,11 +136,11 @@ TkTextImageCmd( }; if (objc < 3) { - Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?"); + Tcl_WrongNumArgs(interp, 2, objv, "option ?arg arg ...?"); return TCL_ERROR; } - if (Tcl_GetIndexFromObjStruct(interp, objv[2], optionStrings, - sizeof(char *), "option", 0, &idx) != TCL_OK) { + if (Tcl_GetIndexFromObj(interp, objv[2], optionStrings, "option", 0, + &idx) != TCL_OK) { return TCL_ERROR; } switch ((enum opts) idx) { @@ -155,10 +156,8 @@ TkTextImageCmd( } eiPtr = TkTextIndexToSeg(&index, NULL); if (eiPtr->typePtr != &tkTextEmbImageType) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "no embedded image at index \"%s\"", - Tcl_GetString(objv[3]))); - Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_IMAGE", NULL); + Tcl_AppendResult(interp, "no embedded image at index \"", + Tcl_GetString(objv[3]), "\"", NULL); return TCL_ERROR; } objPtr = Tk_GetOptionValue(interp, (char *) &eiPtr->body.ei, @@ -172,7 +171,7 @@ TkTextImageCmd( } case CMD_CONF: if (objc < 4) { - Tcl_WrongNumArgs(interp, 3, objv, "index ?-option value ...?"); + Tcl_WrongNumArgs(interp, 3, objv, "index ?option value ...?"); return TCL_ERROR; } if (TkTextGetObjIndex(interp, textPtr, objv[3], &index) != TCL_OK) { @@ -180,17 +179,14 @@ TkTextImageCmd( } eiPtr = TkTextIndexToSeg(&index, NULL); if (eiPtr->typePtr != &tkTextEmbImageType) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "no embedded image at index \"%s\"", - Tcl_GetString(objv[3]))); - Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_IMAGE", NULL); + Tcl_AppendResult(interp, "no embedded image at index \"", + Tcl_GetString(objv[3]), "\"", NULL); return TCL_ERROR; } if (objc <= 5) { Tcl_Obj *objPtr = Tk_GetOptionInfo(interp, (char *) &eiPtr->body.ei, eiPtr->body.ei.optionTable, (objc == 5) ? objv[4] : NULL, textPtr->tkwin); - if (objPtr == NULL) { return TCL_ERROR; } else { @@ -219,7 +215,7 @@ TkTextImageCmd( */ if (objc < 4) { - Tcl_WrongNumArgs(interp, 3, objv, "index ?-option value ...?"); + Tcl_WrongNumArgs(interp, 3, objv, "index ?option value ...?"); return TCL_ERROR; } if (TkTextGetObjIndex(interp, textPtr, objv[3], &index) != TCL_OK) { @@ -242,7 +238,7 @@ TkTextImageCmd( * Create the new image segment and initialize it. */ - eiPtr = ckalloc(EI_SEG_SIZE); + eiPtr = (TkTextSegment *) ckalloc(EI_SEG_SIZE); eiPtr->typePtr = &tkTextEmbImageType; eiPtr->size = 1; eiPtr->body.ei.sharedTextPtr = textPtr->sharedTextPtr; @@ -277,20 +273,16 @@ TkTextImageCmd( case CMD_NAMES: { Tcl_HashSearch search; Tcl_HashEntry *hPtr; - Tcl_Obj *resultObj; if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); return TCL_ERROR; } - resultObj = Tcl_NewObj(); for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->imageTable, &search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj( - Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr), - -1)); + Tcl_AppendElement(interp, + Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr)); } - Tcl_SetObjResult(interp, resultObj); return TCL_OK; } default: @@ -332,12 +324,11 @@ EmbImageConfigure( Tcl_HashEntry *hPtr; Tcl_HashSearch search; char *name; - int dummy; int count = 0; /* The counter for picking a unique name */ int conflict = 0; /* True if we have a name conflict */ - size_t len; /* length of image name */ + size_t len; /* length of image name */ - if (Tk_SetOptions(textPtr->interp, (char *) &eiPtr->body.ei, + if (Tk_SetOptions(textPtr->interp, (char*)&eiPtr->body.ei, eiPtr->body.ei.optionTable, objc, objv, textPtr->tkwin, NULL, NULL) != TCL_OK) { return TCL_ERROR; @@ -352,7 +343,7 @@ EmbImageConfigure( if (eiPtr->body.ei.imageString != NULL) { image = Tk_GetImage(textPtr->interp, textPtr->tkwin, - eiPtr->body.ei.imageString, EmbImageProc, eiPtr); + eiPtr->body.ei.imageString, EmbImageProc, (ClientData) eiPtr); if (image == NULL) { return TCL_ERROR; } @@ -379,11 +370,9 @@ EmbImageConfigure( name = eiPtr->body.ei.imageString; } if (name == NULL) { - Tcl_SetObjResult(textPtr->interp, Tcl_NewStringObj( - "Either a \"-name\" or a \"-image\" argument must be" - " provided to the \"image create\" subcommand", -1)); - Tcl_SetErrorCode(textPtr->interp, "TK", "TEXT", "IMAGE_CREATE_USAGE", - NULL); + Tcl_AppendResult(textPtr->interp, "Either a \"-name\" ", + "or a \"-image\" argument must be provided ", + "to the \"image create\" subcommand.", NULL); return TCL_ERROR; } len = strlen(name); @@ -415,11 +404,15 @@ EmbImageConfigure( Tcl_DStringAppend(&newName, buf, -1); } name = Tcl_DStringValue(&newName); - hPtr = Tcl_CreateHashEntry(&textPtr->sharedTextPtr->imageTable, name, - &dummy); + { + int dummy; + + hPtr = Tcl_CreateHashEntry(&textPtr->sharedTextPtr->imageTable, name, + &dummy); + } Tcl_SetHashValue(hPtr, eiPtr); - Tcl_SetObjResult(textPtr->interp, Tcl_NewStringObj(name, -1)); - eiPtr->body.ei.name = ckalloc(Tcl_DStringLength(&newName) + 1); + Tcl_AppendResult(textPtr->interp, name, NULL); + eiPtr->body.ei.name = ckalloc((unsigned) Tcl_DStringLength(&newName)+1); strcpy(eiPtr->body.ei.name, name); Tcl_DStringFree(&newName); @@ -480,7 +473,7 @@ EmbImageDeleteProc( if (eiPtr->body.ei.name) { ckfree(eiPtr->body.ei.name); } - ckfree(eiPtr); + ckfree((char *) eiPtr); return 0; } @@ -593,7 +586,7 @@ EmbImageLayoutProc( chunkPtr->width = width; chunkPtr->breakIndex = -1; chunkPtr->breakIndex = 1; - chunkPtr->clientData = eiPtr; + chunkPtr->clientData = (ClientData) eiPtr; eiPtr->body.ei.chunkCount += 1; return 1; } @@ -665,7 +658,7 @@ EmbImageDisplayProc( int screenY) /* Y-coordinate in text window that * corresponds to y. */ { - TkTextSegment *eiPtr = chunkPtr->clientData; + TkTextSegment *eiPtr = (TkTextSegment *) chunkPtr->clientData; int lineX, imageX, imageY, width, height; Tk_Image image; @@ -729,7 +722,7 @@ EmbImageBboxProc( int *heightPtr) /* Gets filled in with height of image, in * pixels. */ { - TkTextSegment *eiPtr = chunkPtr->clientData; + TkTextSegment *eiPtr = (TkTextSegment *) chunkPtr->clientData; Tk_Image image; image = eiPtr->body.ei.image; @@ -794,7 +787,7 @@ TkTextImageIndex( if (hPtr == NULL) { return 0; } - eiPtr = Tcl_GetHashValue(hPtr); + eiPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); indexPtr->tree = textPtr->sharedTextPtr->tree; indexPtr->linePtr = eiPtr->body.ei.linePtr; indexPtr->byteIndex = TkTextSegToOffset(eiPtr, indexPtr->linePtr); @@ -828,7 +821,7 @@ EmbImageProc( int imgWidth, int imgHeight)/* New dimensions of image. */ { - TkTextSegment *eiPtr = clientData; + TkTextSegment *eiPtr = (TkTextSegment *) clientData; TkTextIndex index; index.tree = eiPtr->body.ei.sharedTextPtr->tree; |