diff options
Diffstat (limited to 'generic/tkTextWind.c')
| -rw-r--r-- | generic/tkTextWind.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/generic/tkTextWind.c b/generic/tkTextWind.c index 8c71e48..d336877 100644 --- a/generic/tkTextWind.c +++ b/generic/tkTextWind.c @@ -96,13 +96,13 @@ static const char *const alignStrings[] = { static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_STRING_TABLE, "-align", NULL, NULL, "center", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, align), - TK_OPTION_ENUM_VAR, alignStrings, 0}, + (TCL_MAJOR_VERSION > 8) ? TK_OPTION_ENUM_VAR : 0, alignStrings, 0}, {TK_OPTION_STRING, "-create", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextEmbWindow, create), TK_OPTION_NULL_OK, 0, 0}, + NULL, offsetof(TkTextEmbWindow, createObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-padx", NULL, NULL, - "0", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, padX), 0, 0, 0}, + "0", offsetof(TkTextEmbWindow, padXObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_PIXELS, "-pady", NULL, NULL, - "0", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, padY), 0, 0, 0}, + "0", offsetof(TkTextEmbWindow, padYObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_BOOLEAN, "-stretch", NULL, NULL, "0", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, stretch), 0, 0, 0}, {TK_OPTION_WINDOW, "-window", NULL, NULL, @@ -290,9 +290,9 @@ TkTextWindowCmd( ewPtr->body.ew.sharedTextPtr = textPtr->sharedTextPtr; ewPtr->body.ew.linePtr = NULL; ewPtr->body.ew.tkwin = NULL; - ewPtr->body.ew.create = NULL; + ewPtr->body.ew.createObj = NULL; ewPtr->body.ew.align = TK_ALIGN_CENTER; - ewPtr->body.ew.padX = ewPtr->body.ew.padY = 0; + ewPtr->body.ew.padXObj = ewPtr->body.ew.padYObj = NULL; ewPtr->body.ew.stretch = 0; ewPtr->body.ew.optionTable = Tk_CreateOptionTable(interp, optionSpecs); @@ -833,6 +833,7 @@ EmbWinLayoutProc( { int width, height; TkTextEmbWindowClient *client; + int padX = 0, padY = 0; if (offset != 0) { Tcl_Panic("Non-zero offset in EmbWinLayoutProc"); @@ -845,7 +846,7 @@ EmbWinLayoutProc( ewPtr->body.ew.tkwin = client->tkwin; } - if ((ewPtr->body.ew.tkwin == NULL) && (ewPtr->body.ew.create != NULL)) { + if ((ewPtr->body.ew.tkwin == NULL) && (ewPtr->body.ew.createObj != NULL)) { int code, isNew; Tk_Window ancestor; Tcl_HashEntry *hPtr; @@ -853,7 +854,7 @@ EmbWinLayoutProc( Tcl_DString buf, *dsPtr = NULL; Tcl_Obj *nameObj; - before = ewPtr->body.ew.create; + before = Tcl_GetString(ewPtr->body.ew.createObj); /* * Find everything up to the next % character and append it to the @@ -907,7 +908,7 @@ EmbWinLayoutProc( code = Tcl_EvalEx(textPtr->interp, Tcl_DStringValue(dsPtr), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); Tcl_DStringFree(dsPtr); } else { - code = Tcl_EvalEx(textPtr->interp, ewPtr->body.ew.create, TCL_INDEX_NONE, TCL_EVAL_GLOBAL); + code = Tcl_EvalEx(textPtr->interp, Tcl_GetString(ewPtr->body.ew.createObj), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); } if (code != TCL_OK) { Tcl_BackgroundException(textPtr->interp, code); @@ -988,8 +989,14 @@ EmbWinLayoutProc( width = 0; height = 0; } else { - width = Tk_ReqWidth(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padX; - height = Tk_ReqHeight(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padY; + if (ewPtr->body.ew.padXObj) { + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, ewPtr->body.ew.padXObj, &padX); + } + if (ewPtr->body.ew.padYObj) { + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, ewPtr->body.ew.padYObj, &padY); + } + width = Tk_ReqWidth(ewPtr->body.ew.tkwin) + 2 * padX; + height = Tk_ReqHeight(ewPtr->body.ew.tkwin) + 2 * padY; } if ((width > (maxX - chunkPtr->x)) && !noCharsYet && (textPtr->wrapMode != TEXT_WRAPMODE_NONE)) { @@ -1006,8 +1013,8 @@ EmbWinLayoutProc( chunkPtr->bboxProc = EmbWinBboxProc; chunkPtr->numBytes = 1; if (ewPtr->body.ew.align == TK_ALIGN_BASELINE) { - chunkPtr->minAscent = height - ewPtr->body.ew.padY; - chunkPtr->minDescent = ewPtr->body.ew.padY; + chunkPtr->minAscent = height - padY; + chunkPtr->minDescent = padY; chunkPtr->minHeight = 0; } else { chunkPtr->minAscent = 0; @@ -1238,6 +1245,7 @@ EmbWinBboxProc( Tk_Window tkwin; TkTextSegment *ewPtr = (TkTextSegment *)chunkPtr->clientData; TkTextEmbWindowClient *client = EmbWinGetClient(textPtr, ewPtr); + int padX = 0, padY = 0; if (client == NULL) { tkwin = NULL; @@ -1251,23 +1259,29 @@ EmbWinBboxProc( *widthPtr = 0; *heightPtr = 0; } - *xPtr = chunkPtr->x + ewPtr->body.ew.padX; + if (ewPtr->body.ew.padXObj) { + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, ewPtr->body.ew.padXObj, &padX); + } + if (ewPtr->body.ew.padYObj) { + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, ewPtr->body.ew.padYObj, &padY); + } + *xPtr = chunkPtr->x + padX; if (ewPtr->body.ew.stretch) { if (ewPtr->body.ew.align == TK_ALIGN_BASELINE) { - *heightPtr = baseline - ewPtr->body.ew.padY; + *heightPtr = baseline - padY; } else { - *heightPtr = lineHeight - 2*ewPtr->body.ew.padY; + *heightPtr = lineHeight - 2 * padY; } } switch (ewPtr->body.ew.align) { case TK_ALIGN_BOTTOM: - *yPtr = y + (lineHeight - *heightPtr - ewPtr->body.ew.padY); + *yPtr = y + (lineHeight - *heightPtr - padY); break; case TK_ALIGN_CENTER: *yPtr = y + (lineHeight - *heightPtr)/2; break; case TK_ALIGN_TOP: - *yPtr = y + ewPtr->body.ew.padY; + *yPtr = y + padY; break; case TK_ALIGN_BASELINE: *yPtr = y + (baseline - *heightPtr); |
