From 02374d05eb38101dacfa7789d26ab78272752e72 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 11 Oct 2024 22:21:10 +0000 Subject: [PATCH 1/2] Fix [f91aa24bbe] for "text": Use of Tcl_Obj vs char * in Widget storage --- generic/tkText.c | 59 ++++--- generic/tkText.h | 99 ++++++------ generic/tkTextBTree.c | 8 +- generic/tkTextDisp.c | 70 ++++----- generic/tkTextIndex.c | 24 +-- generic/tkTextTag.c | 347 +++++++++--------------------------------- generic/tkTextWind.c | 10 +- 7 files changed, 193 insertions(+), 424 deletions(-) diff --git a/generic/tkText.c b/generic/tkText.c index 7623802cd..4f1cbd53f 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -202,8 +202,7 @@ static const Tk_OptionSpec optionSpecs[] = { 0, DEF_TEXT_SELECT_MONO, 0}, {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth", "BorderWidth", DEF_TEXT_SELECT_BD_COLOR, - offsetof(TkText, selBorderWidthPtr), - offsetof(TkText, selBorderWidth), + offsetof(TkText, selBorderWidthObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, DEF_TEXT_SELECT_BD_MONO, 0}, {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background", DEF_TEXT_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(TkText, selFgColorPtr), @@ -212,13 +211,13 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_TEXT_SET_GRID, TCL_INDEX_NONE, offsetof(TkText, setGrid), 0, 0, 0}, {TK_OPTION_PIXELS, "-spacing1", "spacing1", "Spacing", DEF_TEXT_SPACING1, TCL_INDEX_NONE, offsetof(TkText, spacing1), - 0, 0 , TK_TEXT_LINE_GEOMETRY }, + 0, 0, TK_TEXT_LINE_GEOMETRY }, {TK_OPTION_PIXELS, "-spacing2", "spacing2", "Spacing", DEF_TEXT_SPACING2, TCL_INDEX_NONE, offsetof(TkText, spacing2), - 0, 0 , TK_TEXT_LINE_GEOMETRY }, + 0, 0, TK_TEXT_LINE_GEOMETRY }, {TK_OPTION_PIXELS, "-spacing3", "spacing3", "Spacing", DEF_TEXT_SPACING3, TCL_INDEX_NONE, offsetof(TkText, spacing3), - 0, 0 , TK_TEXT_LINE_GEOMETRY }, + 0, 0, TK_TEXT_LINE_GEOMETRY }, {TK_OPTION_CUSTOM, "-startline", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkText, start), TK_OPTION_NULL_OK, &lineOption, TK_TEXT_LINE_RANGE}, @@ -226,13 +225,13 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_TEXT_STATE, TCL_INDEX_NONE, offsetof(TkText, state), TK_OPTION_ENUM_VAR, &tkStateStrings[1], 0}, {TK_OPTION_STRING, "-tabs", "tabs", "Tabs", - DEF_TEXT_TABS, offsetof(TkText, tabOptionPtr), TCL_INDEX_NONE, + DEF_TEXT_TABS, offsetof(TkText, tabOptionObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, TK_TEXT_LINE_GEOMETRY}, {TK_OPTION_STRING_TABLE, "-tabstyle", "tabStyle", "TabStyle", DEF_TEXT_TABSTYLE, TCL_INDEX_NONE, offsetof(TkText, tabStyle), TK_OPTION_ENUM_VAR, tkTextTabStyleStrings, TK_TEXT_LINE_GEOMETRY}, {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", - DEF_TEXT_TAKE_FOCUS, TCL_INDEX_NONE, offsetof(TkText, takeFocus), + DEF_TEXT_TAKE_FOCUS, offsetof(TkText, takeFocusObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_BOOLEAN, "-undo", "undo", "Undo", DEF_TEXT_UNDO, TCL_INDEX_NONE, offsetof(TkText, undo), @@ -244,10 +243,10 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_TEXT_WRAP, TCL_INDEX_NONE, offsetof(TkText, wrapMode), TK_OPTION_ENUM_VAR, tkTextWrapStrings, TK_TEXT_LINE_GEOMETRY}, {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", - DEF_TEXT_XSCROLL_COMMAND, TCL_INDEX_NONE, offsetof(TkText, xScrollCmd), + DEF_TEXT_XSCROLL_COMMAND, offsetof(TkText, xScrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand", - DEF_TEXT_YSCROLL_COMMAND, TCL_INDEX_NONE, offsetof(TkText, yScrollCmd), + DEF_TEXT_YSCROLL_COMMAND, offsetof(TkText, yScrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0} }; @@ -605,7 +604,7 @@ CreateWidget( textPtr->undo = textPtr->sharedTextPtr->undo; textPtr->maxUndo = textPtr->sharedTextPtr->maxUndo; textPtr->autoSeparators = textPtr->sharedTextPtr->autoSeparators; - textPtr->tabOptionPtr = NULL; + textPtr->tabOptionObj = NULL; /* * Create the "sel" tag and the "current" and "insert" marks. @@ -613,8 +612,7 @@ CreateWidget( textPtr->selBorder = NULL; textPtr->inactiveSelBorder = NULL; - textPtr->selBorderWidth = 0; - textPtr->selBorderWidthPtr = NULL; + textPtr->selBorderWidthObj = NULL; textPtr->selFgColorPtr = NULL; /* @@ -623,9 +621,6 @@ CreateWidget( */ textPtr->selTagPtr = TkTextCreateTag(textPtr, "sel", NULL); - textPtr->selTagPtr->reliefString = (char *) - ckalloc(sizeof(DEF_TEXT_SELECT_RELIEF)); - strcpy(textPtr->selTagPtr->reliefString, DEF_TEXT_SELECT_RELIEF); Tk_GetRelief(interp, DEF_TEXT_SELECT_RELIEF, &textPtr->selTagPtr->relief); textPtr->currentMarkPtr = TkTextSetMark(textPtr, "current", &startIndex); textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &startIndex); @@ -2235,9 +2230,9 @@ ConfigureText( ckfree(textPtr->tabArrayPtr); textPtr->tabArrayPtr = NULL; } - if (textPtr->tabOptionPtr != NULL) { + if (textPtr->tabOptionObj != NULL) { textPtr->tabArrayPtr = TkTextGetTabs(interp, textPtr, - textPtr->tabOptionPtr); + textPtr->tabOptionObj); if (textPtr->tabArrayPtr == NULL) { Tcl_AddErrorInfo(interp,"\n (while processing -tabs option)"); Tk_RestoreSavedOptions(&savedOptions); @@ -2257,9 +2252,8 @@ ConfigureText( } else { textPtr->selTagPtr->selBorder = textPtr->selBorder; } - if (textPtr->selTagPtr->borderWidthPtr != textPtr->selBorderWidthPtr) { - textPtr->selTagPtr->borderWidthPtr = textPtr->selBorderWidthPtr; - textPtr->selTagPtr->borderWidth = textPtr->selBorderWidth; + if (textPtr->selTagPtr->borderWidthObj != textPtr->selBorderWidthObj) { + textPtr->selTagPtr->borderWidthObj = textPtr->selBorderWidthObj; } if (textPtr->selTagPtr->selFgColor == NULL) { textPtr->selTagPtr->fgColor = textPtr->selFgColorPtr; @@ -2268,16 +2262,16 @@ ConfigureText( } textPtr->selTagPtr->affectsDisplay = 0; textPtr->selTagPtr->affectsDisplayGeometry = 0; - if ((textPtr->selTagPtr->elide >= 0) + if ((textPtr->selTagPtr->elideObj != NULL) || (textPtr->selTagPtr->tkfont != NULL) || (textPtr->selTagPtr->justify != TK_JUSTIFY_NULL) - || (textPtr->selTagPtr->lMargin1 != INT_MIN) - || (textPtr->selTagPtr->lMargin2 != INT_MIN) - || (textPtr->selTagPtr->offset != INT_MIN) - || (textPtr->selTagPtr->rMargin != INT_MIN) - || (textPtr->selTagPtr->spacing1 != INT_MIN) - || (textPtr->selTagPtr->spacing2 != INT_MIN) - || (textPtr->selTagPtr->spacing3 != INT_MIN) + || (textPtr->selTagPtr->lMargin1Obj != NULL) + || (textPtr->selTagPtr->lMargin2Obj != NULL) + || (textPtr->selTagPtr->offsetObj != NULL) + || (textPtr->selTagPtr->rMarginObj != NULL) + || (textPtr->selTagPtr->spacing1Obj != NULL) + || (textPtr->selTagPtr->spacing2Obj != NULL) + || (textPtr->selTagPtr->spacing3Obj != NULL) || (textPtr->selTagPtr->tabStringPtr != NULL) || (textPtr->selTagPtr->tabStyle == TK_TEXT_TABSTYLE_TABULAR) || (textPtr->selTagPtr->tabStyle == TK_TEXT_TABSTYLE_WORDPROCESSOR) @@ -2294,9 +2288,9 @@ ConfigureText( || (textPtr->selTagPtr->fgColor != NULL) || (textPtr->selTagPtr->selFgColor != NULL) || (textPtr->selTagPtr->fgStipple != None) - || (textPtr->selTagPtr->overstrike >= 0) + || (textPtr->selTagPtr->overstrikeObj != NULL) || (textPtr->selTagPtr->overstrikeColor != NULL) - || (textPtr->selTagPtr->underline >= 0) + || (textPtr->selTagPtr->underlineObj != NULL) || (textPtr->selTagPtr->underlineColor != NULL) || (textPtr->selTagPtr->lMarginColor != NULL) || (textPtr->selTagPtr->rMarginColor != NULL)) { @@ -2489,7 +2483,7 @@ TextEventProc( } } else if (eventPtr->type == DestroyNotify) { /* - * NOTE: we must zero out selBorder, selBorderWidthPtr and + * NOTE: we must zero out selBorder, selBorderWidthObj and * selFgColorPtr: they are duplicates of information in the "sel" tag, * which will be freed up when we delete all tags. Hence we don't want * the automatic config options freeing process to delete them as @@ -2497,8 +2491,7 @@ TextEventProc( */ textPtr->selBorder = NULL; - textPtr->selBorderWidthPtr = NULL; - textPtr->selBorderWidth = 0; + textPtr->selBorderWidthObj = NULL; textPtr->selFgColorPtr = NULL; if (textPtr->setGrid) { Tk_UnsetGrid(textPtr->tkwin); diff --git a/generic/tkText.h b/generic/tkText.h index ca7aa4c16..1627096cf 100644 --- a/generic/tkText.h +++ b/generic/tkText.h @@ -114,8 +114,8 @@ typedef struct TkTextEmbWindow { * yet. */ TkTextLine *linePtr; /* Line structure that contains this * window. */ - char *create; /* Script to create window on-demand. NULL - * means no such script. Malloc-ed. */ + Tcl_Obj *createObj; /* Script to create window on-demand. NULL + * means no such script. */ TkAlignMode align; /* How to align window in vertical space. See * definitions in tkTextWind.c. */ int padX, padY; /* Padding to leave around each side of @@ -211,7 +211,7 @@ typedef struct TkTextIndex { typedef struct TkTextDispChunk TkTextDispChunk; -typedef void Tk_ChunkDisplayProc(struct TkText *textPtr, +typedef void Tk_ChunkDisplayProc(struct TkText *textPtr, TkTextDispChunk *chunkPtr, int x, int y, int height, int baseline, Display *display, Drawable dst, int screenY); @@ -343,10 +343,7 @@ typedef struct TkTextTag { Tk_3DBorder border; /* Used for drawing background. NULL means no * value specified here. */ - int borderWidth; /* Width of 3-D border for background. */ - Tcl_Obj *borderWidthPtr; /* Width of 3-D border for background. */ - char *reliefString; /* -relief option string (malloc-ed). NULL - * means option not specified. */ + Tcl_Obj *borderWidthObj; /* Width of 3-D border for background. */ int relief; /* 3-D relief for background. */ Pixmap bgStipple; /* Stipple bitmap for background. None means * no value specified here. */ @@ -357,75 +354,66 @@ typedef struct TkTextTag { Pixmap fgStipple; /* Stipple bitmap for text and other * foreground stuff. None means no value * specified here.*/ - char *justifyString; /* -justify option string (malloc-ed). NULL - * means option not specified. */ Tk_Justify justify; /* How to justify text: TK_JUSTIFY_CENTER, - * TK_JUSTIFY_LEFT, or TK_JUSTIFY_RIGHT. - * Only valid if justifyString is non-NULL. */ - char *lMargin1String; /* -lmargin1 option string (malloc-ed). NULL - * means option not specified. */ - int lMargin1; /* Left margin for first display line of each - * text line, in pixels. INT_MIN means option not specified. */ - char *lMargin2String; /* -lmargin2 option string (malloc-ed). NULL - * means option not specified. */ - int lMargin2; /* Left margin for second and later display lines - * of each text line, in pixels. INT_MIN means option not specified. */ + * TK_JUSTIFY_LEFT, or TK_JUSTIFY_RIGHT. */ + Tcl_Obj *lMargin1Obj; /* Left margin for first display line of each + * text line, in pixels. NULL means option not specified. */ + int lMargin1; /* No longer used, but kept for binary compatibility. */ + Tcl_Obj *lMargin2Obj; /* Left margin for second and later display lines + * of each text line, in pixels NULL means option not specified. */ + int lMargin2; /* No longer used, but kept for binary compatibility. */ Tk_3DBorder lMarginColor; /* Used for drawing background in left margins. * This is used for both lmargin1 and lmargin2. * NULL means no value specified here. */ - char *offsetString; /* -offset option string (malloc-ed). NULL - * means option not specified. */ - int offset; /* Vertical offset of text's baseline from + Tcl_Obj *offsetObj; /* Vertical offset of text's baseline from * baseline of line. Used for superscripts and - * subscripts. INT_MIN means option not specified. */ - char *overstrikeString; /* -overstrike option string (malloc-ed). NULL + * subscripts. NULL means option not specified. */ + int offset; /* No longer used, but kept for binary compatibility. */ + Tcl_Obj *overstrikeObj; /* -overstrike option. NULL * means option not specified. */ - int overstrike; /* > 0 means draw horizontal line through - * middle of text. -1 means not specified. */ + int overstrike; /* Non-zero means draw horizontal line through + * middle of text. Only valid if + * overstrikeObj is non-NULL. */ XColor *overstrikeColor; /* Color for the overstrike. NULL means same * color as foreground. */ - char *rMarginString; /* -rmargin option string (malloc-ed). NULL + Tcl_Obj *rMarginObj; /* Right margin for text, in pixels. NULL * means option not specified. */ - int rMargin; /* Right margin for text, in pixels. INT_MIN means option not specified. */ + int rMargin; /* No longer used, but kept for binary compatibility. */ Tk_3DBorder rMarginColor; /* Used for drawing background in right margin. * NULL means no value specified here. */ Tk_3DBorder selBorder; /* Used for drawing background for selected text. * NULL means no value specified here. */ XColor *selFgColor; /* Foreground color for selected text. NULL means * no value specified here. */ - char *spacing1String; /* -spacing1 option string (malloc-ed). NULL + Tcl_Obj *spacing1Obj; /* -spacing1 option object. NULL * means option not specified. */ - int spacing1; /* Extra spacing above first display line for - * text line. INT_MIN means option not specified. */ - char *spacing2String; /* -spacing2 option string (malloc-ed). NULL + Tcl_Obj *spacing2Obj; /* -spacing2 option object. NULL * means option not specified. */ - int spacing2; /* Extra spacing between display lines for the - * same text line. INT_MIN means option not specified. */ - char *spacing3String; /* -spacing3 option string (malloc-ed). NULL + Tcl_Obj *spacing3Obj; /* -spacing3 option object. NULL * means option not specified. */ - int spacing3; /* Extra spacing below last display line for - * text line. INT_MIN means option not specified. */ - Tcl_Obj *tabStringPtr; /* -tabs option string. NULL means option not + Tcl_Obj *tabStringPtr; /* -tabs option. NULL means option not * specified. */ struct TkTextTabArray *tabArrayPtr; /* Info about tabs for tag (malloc-ed) or - * NULL. Corresponds to tabString. */ - TkTextTabStyle tabStyle; /* One of TK_TEXT_TABSTYLE_TABULAR, TK_TEXT_TABSTYLE_WORDPROCESSOR - * or TK_TEXT_TABSTYLE_NONE. (if not specified)*/ - char *underlineString; /* -underline option string (malloc-ed). NULL + * NULL. Corresponds to tabStringPtr. */ + TkTextTabStyle tabStyle; /* One of TK_TEXT_TABSTYLE_TABULAR or TK_TEXT_TABSTYLE_WORDPROCESSOR + * or TK_TEXT_TABSTYLE_NULL (if not specified). */ + Tcl_Obj *underlineObj; /* -underline option. NULL * means option not specified. */ - int underline; /* > 0 means draw underline underneath - * text. -1 means not specified. */ + int underline; /* Non-zero means draw underline underneath + * text. Only valid if underlineObj is + * non-NULL. */ XColor *underlineColor; /* Color for the underline. NULL means same * color as foreground. */ TkWrapMode wrapMode; /* How to handle wrap-around for this tag. * Must be TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_WORD, * TEXT_WRAPMODE_NONE, or TEXT_WRAPMODE_NULL to * use wrapmode for whole widget. */ - char *elideString; /* -elide option string (malloc-ed). NULL + Tcl_Obj *elideObj; /* -elide option. NULL * means option not specified. */ - int elide; /* > 0 means that data under this tag - * should not be displayed. -1 means not specified. */ + int elide; /* Non-zero means that data under this tag + * should not be displayed. Only valid if elideObj is + * non-NULL. */ int affectsDisplay; /* Non-zero means that this tag affects the * way information is displayed on the screen * (so need to redisplay if tag changes). */ @@ -688,7 +676,7 @@ typedef struct TkText { * for the same text line. */ int spacing3; /* Default extra spacing below last display * line for each text line. */ - Tcl_Obj *tabOptionPtr; /* Value of -tabs option string. */ + Tcl_Obj *tabOptionObj; /* Value of -tabs option string. */ TkTextTabArray *tabArrayPtr; /* Information about tab stops (malloc'ed). * NULL means perform default tabbing @@ -727,8 +715,7 @@ typedef struct TkText { /* Border and background for selected * characters when they don't have the * focus. */ - int selBorderWidth; /* Width of border around selection. */ - Tcl_Obj *selBorderWidthPtr; /* Width of border around selection. */ + Tcl_Obj *selBorderWidthObj; /* Width of border around selection. */ XColor *selFgColorPtr; /* Foreground color for selected text. This is * a copy of information in *selTagPtr, so it * shouldn't be explicitly freed. */ @@ -779,13 +766,13 @@ typedef struct TkText { * Miscellaneous additional information: */ - char *takeFocus; /* Value of -takeFocus option; not used in the + Tcl_Obj *takeFocusObj; /* Value of -takeFocus option; not used in the * C code, but used by keyboard traversal - * scripts. Malloc'ed, but may be NULL. */ - char *xScrollCmd; /* Prefix of command to issue to update - * horizontal scrollbar when view changes. */ - char *yScrollCmd; /* Prefix of command to issue to update - * vertical scrollbar when view changes. */ + * scripts. May be NULL. */ + Tcl_Obj *xScrollCmdObj; /* Prefix of command to issue to update + * horizontal scrollbar when view changes. May be NULL. */ + Tcl_Obj *yScrollCmdObj; /* Prefix of command to issue to update + * vertical scrollbar when view changes. May be NULL. */ int flags; /* Miscellaneous flags; see below for * definitions. */ Tk_OptionTable optionTable; /* Token representing the configuration diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c index 7a65ee1aa..3b96330f6 100644 --- a/generic/tkTextBTree.c +++ b/generic/tkTextBTree.c @@ -3560,7 +3560,7 @@ TkTextIsElided( if ((segPtr->typePtr == &tkTextToggleOnType) || (segPtr->typePtr == &tkTextToggleOffType)) { tagPtr = segPtr->body.toggle.tagPtr; - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj != NULL) { infoPtr->tagPtrs[tagPtr->priority] = tagPtr; infoPtr->tagCnts[tagPtr->priority]++; } @@ -3600,7 +3600,7 @@ TkTextIsElided( if ((segPtr->typePtr == &tkTextToggleOnType) || (segPtr->typePtr == &tkTextToggleOffType)) { tagPtr = segPtr->body.toggle.tagPtr; - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj != NULL) { infoPtr->tagPtrs[tagPtr->priority] = tagPtr; infoPtr->tagCnts[tagPtr->priority]++; } @@ -3624,7 +3624,7 @@ TkTextIsElided( summaryPtr = summaryPtr->nextPtr) { if (summaryPtr->toggleCount & 1) { tagPtr = summaryPtr->tagPtr; - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj != NULL) { infoPtr->tagPtrs[tagPtr->priority] = tagPtr; infoPtr->tagCnts[tagPtr->priority] += summaryPtr->toggleCount; @@ -3642,7 +3642,7 @@ TkTextIsElided( infoPtr->elidePriority = -1; for (i = infoPtr->numTags-1; i >=0; i--) { if (infoPtr->tagCnts[i] & 1) { - infoPtr->elide = infoPtr->tagPtrs[i]->elide > 0; + infoPtr->elide = infoPtr->tagPtrs[i]->elideObj && infoPtr->tagPtrs[i]->elide != 0; /* * Note: i == infoPtr->tagPtrs[i]->priority diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index a432a241a..b9615b58b 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -867,10 +867,10 @@ GetStyle( styleValues.border = border; borderPrio = tagPtr->priority; } - if ((tagPtr->borderWidthPtr != NULL) - && (Tcl_GetString(tagPtr->borderWidthPtr)[0] != '\0') + if ((tagPtr->borderWidthObj != NULL) + && (Tcl_GetString(tagPtr->borderWidthObj)[0] != '\0') && (tagPtr->priority > borderWidthPrio)) { - styleValues.borderWidth = tagPtr->borderWidth; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->borderWidthObj, &styleValues.borderWidth); borderWidthPrio = tagPtr->priority; } if ((tagPtr->relief != TK_RELIEF_NULL) @@ -904,14 +904,14 @@ GetStyle( styleValues.justify = tagPtr->justify; justifyPrio = tagPtr->priority; } - if ((tagPtr->lMargin1 != INT_MIN) + if ((tagPtr->lMargin1Obj != NULL) && (tagPtr->priority > lMargin1Prio)) { - styleValues.lMargin1 = tagPtr->lMargin1; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->lMargin1Obj, &styleValues.lMargin1); lMargin1Prio = tagPtr->priority; } - if ((tagPtr->lMargin2 != INT_MIN) + if ((tagPtr->lMargin2Obj != NULL) && (tagPtr->priority > lMargin2Prio)) { - styleValues.lMargin2 = tagPtr->lMargin2; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->lMargin2Obj, &styleValues.lMargin2); lMargin2Prio = tagPtr->priority; } if ((tagPtr->lMarginColor != NULL) @@ -919,14 +919,14 @@ GetStyle( styleValues.lMarginColor = tagPtr->lMarginColor; lMarginColorPrio = tagPtr->priority; } - if ((tagPtr->offset != INT_MIN) + if ((tagPtr->offsetObj != NULL) && (tagPtr->priority > offsetPrio)) { - styleValues.offset = tagPtr->offset; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->offsetObj, &styleValues.offset); offsetPrio = tagPtr->priority; } - if ((tagPtr->overstrike >= 0) + if ((tagPtr->overstrikeObj != NULL) && (tagPtr->priority > overstrikePrio)) { - styleValues.overstrike = tagPtr->overstrike > 0; + styleValues.overstrike = tagPtr->overstrike != 0; overstrikePrio = tagPtr->priority; if (tagPtr->overstrikeColor != NULL) { styleValues.overstrikeColor = tagPtr->overstrikeColor; @@ -934,9 +934,9 @@ GetStyle( styleValues.overstrikeColor = fgColor; } } - if ((tagPtr->rMargin != INT_MIN) + if ((tagPtr->rMarginObj != NULL) && (tagPtr->priority > rMarginPrio)) { - styleValues.rMargin = tagPtr->rMargin; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->rMarginObj, &styleValues.rMargin); rMarginPrio = tagPtr->priority; } if ((tagPtr->rMarginColor != NULL) @@ -944,19 +944,19 @@ GetStyle( styleValues.rMarginColor = tagPtr->rMarginColor; rMarginColorPrio = tagPtr->priority; } - if ((tagPtr->spacing1 != INT_MIN) + if ((tagPtr->spacing1Obj != NULL) && (tagPtr->priority > spacing1Prio)) { - styleValues.spacing1 = tagPtr->spacing1; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->spacing1Obj, &styleValues.spacing1); spacing1Prio = tagPtr->priority; } - if ((tagPtr->spacing2 != INT_MIN) + if ((tagPtr->spacing2Obj != NULL) && (tagPtr->priority > spacing2Prio)) { - styleValues.spacing2 = tagPtr->spacing2; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->spacing2Obj, &styleValues.spacing2); spacing2Prio = tagPtr->priority; } - if ((tagPtr->spacing3 != INT_MIN) + if ((tagPtr->spacing3Obj != NULL) && (tagPtr->priority > spacing3Prio)) { - styleValues.spacing3 = tagPtr->spacing3; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->spacing3Obj, &styleValues.spacing3); spacing3Prio = tagPtr->priority; } if ((tagPtr->tabStringPtr != NULL) @@ -970,9 +970,9 @@ GetStyle( styleValues.tabStyle = tagPtr->tabStyle; tabStylePrio = tagPtr->priority; } - if ((tagPtr->underline >= 0) + if ((tagPtr->underlineObj != NULL) && (tagPtr->priority > underlinePrio)) { - styleValues.underline = tagPtr->underline > 0; + styleValues.underline = tagPtr->underline != 0; underlinePrio = tagPtr->priority; if (tagPtr->underlineColor != NULL) { styleValues.underlineColor = tagPtr->underlineColor; @@ -980,9 +980,9 @@ GetStyle( styleValues.underlineColor = fgColor; } } - if ((tagPtr->elide >= 0) + if ((tagPtr->elideObj != NULL) && (tagPtr->priority > elidePrio)) { - styleValues.elide = tagPtr->elide > 0; + styleValues.elide = tagPtr->elide != 0; elidePrio = tagPtr->priority; } if (((tagPtr->wrapMode == TEXT_WRAPMODE_CHAR) || (tagPtr->wrapMode == TEXT_WRAPMODE_NONE) @@ -1245,7 +1245,7 @@ LayoutDLine( * toggled off), or it's a new tag with higher priority. */ - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj != NULL) { info.tagCnts[tagPtr->priority]++; if (info.tagCnts[tagPtr->priority] & 1) { info.tagPtrs[tagPtr->priority] = tagPtr; @@ -1270,13 +1270,13 @@ LayoutDLine( elide = 0; while (--info.elidePriority > 0) { if (info.tagCnts[info.elidePriority] & 1) { - elide = info.tagPtrs[info.elidePriority] - ->elide > 0; + elide = info.tagPtrs[info.elidePriority]->elideObj + && (info.tagPtrs[info.elidePriority]->elide != 0); break; } } } else { - elide = tagPtr->elide > 0; + elide = tagPtr->elideObj && (tagPtr->elide != 0); info.elidePriority = tagPtr->priority; } } @@ -1392,9 +1392,9 @@ LayoutDLine( */ } else if ((segPtr->typePtr == &tkTextToggleOffType) || (segPtr->typePtr == &tkTextToggleOnType)) { - if (segPtr->body.toggle.tagPtr->elide >= 0) { + if (segPtr->body.toggle.tagPtr->elideObj) { elide = (segPtr->typePtr == &tkTextToggleOffType) - ^ (segPtr->body.toggle.tagPtr->elide > 0); + ^ (segPtr->body.toggle.tagPtr->elide != 0); } } @@ -4649,7 +4649,7 @@ DisplayText( doScrollbars: if (textPtr->flags & UPDATE_SCROLLBARS) { textPtr->flags &= ~UPDATE_SCROLLBARS; - if (textPtr->yScrollCmd != NULL) { + if (textPtr->yScrollCmdObj != NULL) { GetYView(textPtr->interp, textPtr, 1); } @@ -4665,7 +4665,7 @@ DisplayText( * Update the horizontal scrollbar, if any. */ - if (textPtr->xScrollCmd != NULL) { + if (textPtr->xScrollCmdObj != NULL) { GetXView(textPtr->interp, textPtr, 1); } } @@ -6530,7 +6530,7 @@ GetXView( } dInfoPtr->xScrollFirst = first; dInfoPtr->xScrollLast = last; - if (textPtr->xScrollCmd != NULL) { + if (textPtr->xScrollCmdObj != NULL) { char buf1[TCL_DOUBLE_SPACE+1]; char buf2[TCL_DOUBLE_SPACE+1]; Tcl_DString buf; @@ -6540,7 +6540,7 @@ GetXView( Tcl_PrintDouble(NULL, first, buf1+1); Tcl_PrintDouble(NULL, last, buf2+1); Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, textPtr->xScrollCmd, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(textPtr->xScrollCmdObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, buf1, TCL_INDEX_NONE); Tcl_DStringAppend(&buf, buf2, TCL_INDEX_NONE); code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); @@ -6815,7 +6815,7 @@ GetYView( dInfoPtr->yScrollFirst = first; dInfoPtr->yScrollLast = last; - if (textPtr->yScrollCmd != NULL) { + if (textPtr->yScrollCmdObj != NULL) { char buf1[TCL_DOUBLE_SPACE+1]; char buf2[TCL_DOUBLE_SPACE+1]; Tcl_DString buf; @@ -6825,7 +6825,7 @@ GetYView( Tcl_PrintDouble(NULL, first, buf1+1); Tcl_PrintDouble(NULL, last, buf2+1); Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, textPtr->yScrollCmd, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(textPtr->yScrollCmdObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, buf1, TCL_INDEX_NONE); Tcl_DStringAppend(&buf, buf2, TCL_INDEX_NONE); code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c index 5a4115ce6..3e5dd642a 100644 --- a/generic/tkTextIndex.c +++ b/generic/tkTextIndex.c @@ -1621,7 +1621,7 @@ TkTextIndexForwChars( * toggled off), or it's a new tag with higher priority. */ - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj) { infoPtr->tagCnts[tagPtr->priority]++; if (infoPtr->tagCnts[tagPtr->priority] & 1) { infoPtr->tagPtrs[tagPtr->priority] = tagPtr; @@ -1648,13 +1648,13 @@ TkTextIndexForwChars( while (--infoPtr->elidePriority > 0) { if (infoPtr->tagCnts[infoPtr->elidePriority] & 1) { - elide = infoPtr->tagPtrs - [infoPtr->elidePriority]->elide > 0; + elide = infoPtr->tagPtrs[infoPtr->elidePriority]->elideObj + && infoPtr->tagPtrs[infoPtr->elidePriority]->elide != 0; break; } } } else { - elide = tagPtr->elide > 0; + elide = tagPtr->elideObj && (tagPtr->elide != 0); infoPtr->elidePriority = tagPtr->priority; } } @@ -1871,7 +1871,7 @@ TkTextIndexCount( * toggled off), or it's a new tag with higher priority. */ - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj) { infoPtr->tagCnts[tagPtr->priority]++; if (infoPtr->tagCnts[tagPtr->priority] & 1) { infoPtr->tagPtrs[tagPtr->priority] = tagPtr; @@ -1898,13 +1898,13 @@ TkTextIndexCount( while (--infoPtr->elidePriority > 0) { if (infoPtr->tagCnts[ infoPtr->elidePriority] & 1) { - elide = infoPtr->tagPtrs[ - infoPtr->elidePriority]->elide > 0; + elide = infoPtr->tagPtrs[infoPtr->elidePriority]->elideObj + && (infoPtr->tagPtrs[infoPtr->elidePriority]->elide != 0); break; } } } else { - elide = tagPtr->elide > 0; + elide = tagPtr->elideObj && (tagPtr->elide != 0); infoPtr->elidePriority = tagPtr->priority; } } @@ -2160,7 +2160,7 @@ TkTextIndexBackChars( * it's a new tag with higher priority. */ - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj) { infoPtr->tagCnts[tagPtr->priority]++; if (infoPtr->tagCnts[tagPtr->priority] & 1) { infoPtr->tagPtrs[tagPtr->priority] = tagPtr; @@ -2185,13 +2185,13 @@ TkTextIndexBackChars( elide = 0; while (--infoPtr->elidePriority > 0) { if (infoPtr->tagCnts[infoPtr->elidePriority] & 1) { - elide = infoPtr->tagPtrs[ - infoPtr->elidePriority]->elide > 0; + elide = infoPtr->tagPtrs[infoPtr->elidePriority]->elideObj + && (infoPtr->tagPtrs[infoPtr->elidePriority]->elide != 0); break; } } } else { - elide = tagPtr->elide > 0; + elide = tagPtr->elideObj && (tagPtr->elide != 0); infoPtr->elidePriority = tagPtr->priority; } } diff --git a/generic/tkTextTag.c b/generic/tkTextTag.c index 4110e8f03..d1c52a0bc 100644 --- a/generic/tkTextTag.c +++ b/generic/tkTextTag.c @@ -27,274 +27,63 @@ typedef struct { Tk_Justify value; } JustifyStruct; -static int -ObjectIsEmpty( - Tcl_Obj *objPtr) /* Object to test. May be NULL. */ -{ - if (objPtr == NULL) { - return 1; - } - if (objPtr->bytes == NULL) { - Tcl_GetString(objPtr); - } - return (objPtr->length == 0); -} - -#define OPTION_NONNEG (1 << 10) - -static int -SetPixels( - TCL_UNUSED(void *), - Tcl_Interp *interp, - Tk_Window tkwin, - Tcl_Obj **value, - char *recordPtr, - Tcl_Size internalOffset, - char *oldInternalPtr, - int flags) -{ - IntStruct pixel = {NULL, INT_MIN}; - IntStruct *internalPtr = (IntStruct *)(recordPtr + internalOffset); - int nullOK = (flags & TK_OPTION_NULL_OK); - - if (!nullOK || !ObjectIsEmpty(*value)) { - if (Tk_GetPixelsFromObj(nullOK ? NULL : interp, tkwin, *value, &pixel.value) != TCL_OK) { - if (nullOK) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "expected screen distance or \"\" but got \"%.50s\"", Tcl_GetString(*value))); - Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", (char *)NULL); - } - return TCL_ERROR; - } - if ((flags & OPTION_NONNEG) && pixel.value < 0) { - pixel.value = 0; - } - pixel.string = (char *)ckalloc((*value)->length + 1); - strcpy(pixel.string, (*value)->bytes); - } - - *((char **)oldInternalPtr) = NULL; - *internalPtr = pixel; - return TCL_OK; -}; - -static int -SetBoolean( - TCL_UNUSED(void *), - Tcl_Interp *interp, - TCL_UNUSED(Tk_Window), - Tcl_Obj **value, - char *recordPtr, - Tcl_Size internalOffset, - char *oldInternalPtr, - int flags) -{ - IntStruct booleanVal = {NULL, -1}; - IntStruct *internalPtr = (IntStruct *)(recordPtr + internalOffset); - int nullOK = (flags & TK_OPTION_NULL_OK); - - if (!nullOK || !ObjectIsEmpty(*value)) { - if (Tcl_GetBooleanFromObj(nullOK ? NULL : interp, *value, &booleanVal.value) != TCL_OK) { - if (nullOK) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "expected boolean value or \"\" but got \"%s\"", Tcl_GetString(*value))); - } - return TCL_ERROR; - } - booleanVal.string = (char *)ckalloc((*value)->length + 1); - strcpy(booleanVal.string, (*value)->bytes); - } - - *((char **)oldInternalPtr) = NULL; - *internalPtr = booleanVal; - return TCL_OK; -}; - -static int -SetRelief( - TCL_UNUSED(void *), - Tcl_Interp *interp, - TCL_UNUSED(Tk_Window), - Tcl_Obj **value, - char *recordPtr, - Tcl_Size internalOffset, - char *oldInternalPtr, - int flags) -{ - IntStruct relief = {NULL, TK_RELIEF_NULL}; - IntStruct *internalPtr = (IntStruct *)(recordPtr + internalOffset); - int nullOK = (flags & TK_OPTION_NULL_OK); - - if (!nullOK || !ObjectIsEmpty(*value)) { - if (Tk_GetReliefFromObj(nullOK ? NULL : interp, *value, &relief.value) != TCL_OK) { - if (nullOK) { - Tcl_AppendResult(interp, "bad relief \"", - Tcl_GetString(*value), "\": must be flat, groove, raised, ridge, solid, sunken, or \"\"", (char *)NULL); - } - return TCL_ERROR; - } - relief.string = (char *)ckalloc((*value)->length + 1); - strcpy(relief.string, (*value)->bytes); - } - - *((char **)oldInternalPtr) = NULL; - *internalPtr = relief; - return TCL_OK; -}; - -static int -SetJustify( - TCL_UNUSED(void *), - Tcl_Interp *interp, - TCL_UNUSED(Tk_Window), - Tcl_Obj **value, - char *recordPtr, - Tcl_Size internalOffset, - char *oldInternalPtr, - int flags) -{ - JustifyStruct justify = {NULL, TK_JUSTIFY_NULL}; - JustifyStruct *internalPtr = (JustifyStruct *)(recordPtr + internalOffset); - int nullOK = (flags & TK_OPTION_NULL_OK); - - if (!nullOK || !ObjectIsEmpty(*value)) { - if (Tk_GetJustifyFromObj(nullOK ? NULL : interp, *value, &justify.value) != TCL_OK) { - if (nullOK) { - Tcl_AppendResult(interp, "bad justification \"", - Tcl_GetString(*value), "\": must be left, right, center, or \"\"", (char *)NULL); - } - return TCL_ERROR; - } - justify.string = (char *)ckalloc((*value)->length + 1); - strcpy(justify.string, (*value)->bytes); - } - - *((char **)oldInternalPtr) = NULL; - *internalPtr = justify; - return TCL_OK; -}; - -static Tcl_Obj *GetStruct( - TCL_UNUSED(void *), - TCL_UNUSED(Tk_Window), - char *recordPtr, - Tcl_Size internalOffset) -{ - char **structPtr = (char **)(recordPtr + internalOffset); - - if (*structPtr == NULL || **structPtr == '\0') { - return Tcl_NewObj(); - } - return Tcl_NewStringObj(*structPtr, TCL_INDEX_NONE); -}; - - -static void -FreeStruct( - TCL_UNUSED(void *), - TCL_UNUSED(Tk_Window), - char *internalPtr) -{ - char **structPtr = (char **)internalPtr; - if (*structPtr) { - ckfree(*structPtr); - *structPtr = NULL; - } -}; - -static const Tk_ObjCustomOption pixelsOption = { - "pixels", /* name */ - SetPixels, /* setProc */ - GetStruct, /* getProc */ - NULL, /* restoreProc */ - FreeStruct, /* freeProc */ - 0 -}; - -static const Tk_ObjCustomOption booleanOption = { - "boolean", /* name */ - SetBoolean, /* setProc */ - GetStruct, /* getProc */ - NULL, /* restoreProc */ - FreeStruct, /* freeProc */ - 0 -}; - -static const Tk_ObjCustomOption justifyOption = { - "justify", /* name */ - SetJustify, /* setProc */ - GetStruct, /* getProc */ - NULL, /* restoreProc */ - FreeStruct, /* freeProc */ - 0 -}; - -static const Tk_ObjCustomOption reliefOption = { - "relief", /* name */ - SetRelief, /* setProc */ - GetStruct, /* getProc */ - NULL, /* restoreProc */ - FreeStruct, /* freeProc */ - 0 -}; - static const Tk_OptionSpec tagOptionSpecs[] = { {TK_OPTION_BORDER, "-background", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, border), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_BITMAP, "-bgstipple", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, bgStipple), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-borderwidth", NULL, NULL, - NULL, offsetof(TkTextTag, borderWidthPtr), offsetof(TkTextTag, borderWidth), + NULL, offsetof(TkTextTag, borderWidthObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK, 0, 0}, + {TK_OPTION_BOOLEAN, "-elide", NULL, NULL, + NULL, offsetof(TkTextTag, elideObj), offsetof(TkTextTag, elide), TK_OPTION_NULL_OK, 0, 0}, - {TK_OPTION_CUSTOM, "-elide", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, elideString), - TK_OPTION_NULL_OK, &booleanOption, 0}, {TK_OPTION_BITMAP, "-fgstipple", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, fgStipple), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_FONT, "-font", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, tkfont), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_COLOR, "-foreground", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, fgColor), TK_OPTION_NULL_OK, 0, 0}, - {TK_OPTION_CUSTOM, "-justify", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, justifyString), TK_OPTION_NULL_OK, &justifyOption,0}, - {TK_OPTION_CUSTOM, "-lmargin1", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, lMargin1String), TK_OPTION_NULL_OK,&pixelsOption,0}, - {TK_OPTION_CUSTOM, "-lmargin2", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, lMargin2String), TK_OPTION_NULL_OK,&pixelsOption,0}, + {TK_OPTION_JUSTIFY, "-justify", NULL, NULL, + NULL, TCL_INDEX_NONE, offsetof(TkTextTag, justify), TK_OPTION_NULL_OK, 0,0}, + {TK_OPTION_PIXELS, "-lmargin1", NULL, NULL, + NULL, offsetof(TkTextTag, lMargin1Obj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, + {TK_OPTION_PIXELS, "-lmargin2", NULL, NULL, + NULL, offsetof(TkTextTag, lMargin2Obj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, {TK_OPTION_BORDER, "-lmargincolor", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, lMarginColor), TK_OPTION_NULL_OK, 0, 0}, - {TK_OPTION_CUSTOM, "-offset", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, offsetString), TK_OPTION_NULL_OK, &pixelsOption, 0}, - {TK_OPTION_CUSTOM, "-overstrike", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, overstrikeString), - TK_OPTION_NULL_OK, &booleanOption, 0}, + {TK_OPTION_PIXELS, "-offset", NULL, NULL, + NULL, offsetof(TkTextTag, offsetObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, + {TK_OPTION_BOOLEAN, "-overstrike", NULL, NULL, + NULL, offsetof(TkTextTag, overstrikeObj), offsetof(TkTextTag, overstrike), + TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_COLOR, "-overstrikefg", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, overstrikeColor), TK_OPTION_NULL_OK, 0, 0}, - {TK_OPTION_CUSTOM, "-relief", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, reliefString), TK_OPTION_NULL_OK, &reliefOption, 0}, - {TK_OPTION_CUSTOM, "-rmargin", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, rMarginString), TK_OPTION_NULL_OK, &pixelsOption,0}, + {TK_OPTION_RELIEF, "-relief", NULL, NULL, + NULL, TCL_INDEX_NONE, offsetof(TkTextTag, relief), TK_OPTION_NULL_OK, 0, 0}, + {TK_OPTION_PIXELS, "-rmargin", NULL, NULL, + NULL, offsetof(TkTextTag, rMarginObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0,0}, {TK_OPTION_BORDER, "-rmargincolor", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, rMarginColor), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_BORDER, "-selectbackground", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, selBorder), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_COLOR, "-selectforeground", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, selFgColor), TK_OPTION_NULL_OK, 0, 0}, - {TK_OPTION_CUSTOM, "-spacing1", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, spacing1String), TK_OPTION_NULL_OK|OPTION_NONNEG, &pixelsOption,0}, - {TK_OPTION_CUSTOM, "-spacing2", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, spacing2String), TK_OPTION_NULL_OK|OPTION_NONNEG, &pixelsOption,0}, - {TK_OPTION_CUSTOM, "-spacing3", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, spacing3String), TK_OPTION_NULL_OK|OPTION_NONNEG, &pixelsOption,0}, + {TK_OPTION_PIXELS, "-spacing1", NULL, NULL, + NULL, offsetof(TkTextTag, spacing1Obj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, + {TK_OPTION_PIXELS, "-spacing2", NULL, NULL, + NULL, offsetof(TkTextTag, spacing2Obj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, + {TK_OPTION_PIXELS, "-spacing3", NULL, NULL, + NULL, offsetof(TkTextTag, spacing3Obj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, {TK_OPTION_STRING, "-tabs", NULL, NULL, NULL, offsetof(TkTextTag, tabStringPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING_TABLE, "-tabstyle", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, tabStyle), TK_OPTION_NULL_OK|TK_OPTION_ENUM_VAR, tkTextTabStyleStrings, 0}, - {TK_OPTION_CUSTOM, "-underline", NULL, NULL, - NULL, TCL_INDEX_NONE, offsetof(TkTextTag, underlineString), - TK_OPTION_NULL_OK, &booleanOption, 0}, + {TK_OPTION_BOOLEAN, "-underline", NULL, NULL, + NULL, offsetof(TkTextTag, underlineObj), offsetof(TkTextTag, underline), + TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_COLOR, "-underlinefg", NULL, NULL, NULL, TCL_INDEX_NONE, offsetof(TkTextTag, underlineColor), TK_OPTION_NULL_OK, 0, 0}, @@ -384,7 +173,7 @@ TkTextTagCmd( return TCL_ERROR; } tagPtr = TkTextCreateTag(textPtr, Tcl_GetString(objv[3]), NULL); - if (tagPtr->elide > 0) { + if (tagPtr->elideObj && (tagPtr->elide != 0)) { /* * Indices are potentially obsolete after adding or removing * elided character ranges, especially indices having "display" @@ -585,8 +374,15 @@ TkTextTagCmd( * from "unspecified"). */ - if (tagPtr->borderWidth < 0) { - tagPtr->borderWidth = 0; + if (tagPtr->borderWidthObj) { + int borderWidth; + Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->borderWidthObj, &borderWidth); + if (borderWidth < 0) { + borderWidth = 0; + Tcl_DecrRefCount(tagPtr->borderWidthObj); + tagPtr->borderWidthObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(tagPtr->borderWidthObj); + } } if (tagPtr->tabArrayPtr != NULL) { ckfree(tagPtr->tabArrayPtr); @@ -599,7 +395,7 @@ TkTextTagCmd( return TCL_ERROR; } } - if (tagPtr->elide >= 0) { + if (tagPtr->elideObj) { /* * Indices are potentially obsolete after changing -elide, * especially those computed with "display" or "any" @@ -623,8 +419,7 @@ TkTextTagCmd( } else { textPtr->selBorder = tagPtr->selBorder; } - textPtr->selBorderWidth = tagPtr->borderWidth; - textPtr->selBorderWidthPtr = tagPtr->borderWidthPtr; + textPtr->selBorderWidthObj = tagPtr->borderWidthObj; if (tagPtr->selFgColor == NULL) { textPtr->selFgColorPtr = tagPtr->fgColor; } else { @@ -634,16 +429,16 @@ TkTextTagCmd( tagPtr->affectsDisplay = 0; tagPtr->affectsDisplayGeometry = 0; - if ((tagPtr->elide >= 0) + if ((tagPtr->elideObj) || (tagPtr->tkfont != NULL) || (tagPtr->justify != TK_JUSTIFY_NULL) - || (tagPtr->lMargin1 != INT_MIN) - || (tagPtr->lMargin2 != INT_MIN) - || (tagPtr->offset != INT_MIN) - || (tagPtr->rMargin != INT_MIN) - || (tagPtr->spacing1 != INT_MIN) - || (tagPtr->spacing2 != INT_MIN) - || (tagPtr->spacing3 != INT_MIN) + || (tagPtr->lMargin1Obj != NULL) + || (tagPtr->lMargin2Obj != NULL) + || (tagPtr->offsetObj != NULL) + || (tagPtr->rMarginObj != NULL) + || (tagPtr->spacing1Obj != NULL) + || (tagPtr->spacing2Obj != NULL) + || (tagPtr->spacing3Obj != NULL) || (tagPtr->tabStringPtr != NULL) || (tagPtr->tabStyle == TK_TEXT_TABSTYLE_TABULAR) || (tagPtr->tabStyle == TK_TEXT_TABSTYLE_WORDPROCESSOR) @@ -660,9 +455,9 @@ TkTextTagCmd( || (tagPtr->fgColor != NULL) || (tagPtr->selFgColor != NULL) || (tagPtr->fgStipple != None) - || (tagPtr->overstrike >= 0) + || (tagPtr->overstrikeObj != NULL) || (tagPtr->overstrikeColor != NULL) - || (tagPtr->underline >= 0) + || (tagPtr->underlineObj != NULL) || (tagPtr->underlineColor != NULL) || (tagPtr->lMarginColor != NULL) || (tagPtr->rMarginColor != NULL)) { @@ -1148,45 +943,39 @@ TkTextCreateTag( tagPtr->tagRootPtr = NULL; tagPtr->priority = textPtr->sharedTextPtr->numTags; tagPtr->border = NULL; - tagPtr->borderWidth = 0; - tagPtr->borderWidthPtr = NULL; - tagPtr->reliefString = NULL; + tagPtr->borderWidthObj = NULL; tagPtr->relief = TK_RELIEF_NULL; tagPtr->bgStipple = None; tagPtr->fgColor = NULL; tagPtr->tkfont = NULL; tagPtr->fgStipple = None; - tagPtr->justifyString = NULL; tagPtr->justify = TK_JUSTIFY_NULL; - tagPtr->lMargin1String = NULL; - tagPtr->lMargin1 = INT_MIN; - tagPtr->lMargin2String = NULL; - tagPtr->lMargin2 = INT_MIN; + tagPtr->lMargin1Obj = NULL; + tagPtr->lMargin1 = 0; + tagPtr->lMargin2Obj = NULL; + tagPtr->lMargin2 = 0; tagPtr->lMarginColor = NULL; - tagPtr->offsetString = NULL; - tagPtr->offset = INT_MIN; - tagPtr->overstrikeString = NULL; - tagPtr->overstrike = -1; + tagPtr->offsetObj = NULL; + tagPtr->offset = 0; + tagPtr->overstrikeObj = NULL; + tagPtr->overstrike = 0; tagPtr->overstrikeColor = NULL; - tagPtr->rMarginString = NULL; - tagPtr->rMargin = INT_MIN; + tagPtr->rMarginObj = NULL; + tagPtr->rMargin = 0; tagPtr->rMarginColor = NULL; tagPtr->selBorder = NULL; tagPtr->selFgColor = NULL; - tagPtr->spacing1String = NULL; - tagPtr->spacing1 = INT_MIN; - tagPtr->spacing2String = NULL; - tagPtr->spacing2 = INT_MIN; - tagPtr->spacing3String = NULL; - tagPtr->spacing3 = INT_MIN; + tagPtr->spacing1Obj = NULL; + tagPtr->spacing2Obj = NULL; + tagPtr->spacing3Obj = NULL; tagPtr->tabStringPtr = NULL; tagPtr->tabArrayPtr = NULL; tagPtr->tabStyle = TK_TEXT_TABSTYLE_NULL; - tagPtr->underlineString = NULL; - tagPtr->underline = -1; + tagPtr->underlineObj = NULL; + tagPtr->underline = 0; tagPtr->underlineColor = NULL; - tagPtr->elideString = NULL; - tagPtr->elide = -1; + tagPtr->elideObj = NULL; + tagPtr->elide = 0; tagPtr->wrapMode = TEXT_WRAPMODE_NULL; tagPtr->affectsDisplay = 0; tagPtr->affectsDisplayGeometry = 0; diff --git a/generic/tkTextWind.c b/generic/tkTextWind.c index 8c71e4830..b350710bc 100644 --- a/generic/tkTextWind.c +++ b/generic/tkTextWind.c @@ -98,7 +98,7 @@ static const Tk_OptionSpec optionSpecs[] = { "center", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, align), TK_OPTION_ENUM_VAR, 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}, {TK_OPTION_PIXELS, "-pady", NULL, NULL, @@ -290,7 +290,7 @@ 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.stretch = 0; @@ -845,7 +845,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 +853,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 +907,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); From 30e9b35e40897cc13bf79271deb7f00380506de9 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 13 Oct 2024 21:26:32 +0000 Subject: [PATCH 2/2] Improvements in canvas images and scrollbar --- generic/tkCanvImg.c | 52 ++++++++++++++-------------- generic/tkScrollbar.c | 29 +++++++++------- generic/tkScrollbar.h | 74 ++++++++++++++++++--------------------- generic/tkText.h | 80 +++++++++++++++++++++++++++++++------------ 4 files changed, 133 insertions(+), 102 deletions(-) diff --git a/generic/tkCanvImg.c b/generic/tkCanvImg.c index 08526d52d..4fe559d46 100644 --- a/generic/tkCanvImg.c +++ b/generic/tkCanvImg.c @@ -24,12 +24,11 @@ typedef struct ImageItem { double x, y; /* Coordinates of positioning point for * image. */ Tk_Anchor anchor; /* Where to anchor image relative to (x,y). */ - char *imageString; /* String describing -image option - * (malloc-ed). NULL means no image right - * now. */ - char *activeImageString; /* String describing -activeimage option. + Tcl_Obj *imageObj; /* -image option. * NULL means no image right now. */ - char *disabledImageString; /* String describing -disabledimage option. + Tcl_Obj *activeImageObj; /* -activeimage option. + * NULL means no image right now. */ + Tcl_Obj *disabledImageObj; /* -disabledimage option. * NULL means no image right now. */ Tk_Image image; /* Image to display in window, or NULL if no * image at present. */ @@ -52,13 +51,13 @@ static const Tk_CustomOption tagsOption = { static const Tk_ConfigSpec configSpecs[] = { {TK_CONFIG_STRING, "-activeimage", NULL, NULL, - NULL, offsetof(ImageItem, activeImageString), TK_CONFIG_NULL_OK, NULL}, + NULL, offsetof(ImageItem, activeImageObj), TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL, "center", offsetof(ImageItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL}, {TK_CONFIG_STRING, "-disabledimage", NULL, NULL, - NULL, offsetof(ImageItem, disabledImageString), TK_CONFIG_NULL_OK, NULL}, + NULL, offsetof(ImageItem, disabledImageObj), TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_STRING, "-image", NULL, NULL, - NULL, offsetof(ImageItem, imageString), TK_CONFIG_NULL_OK, NULL}, + NULL, offsetof(ImageItem, imageObj), TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_CUSTOM, "-state", NULL, NULL, NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption}, {TK_CONFIG_CUSTOM, "-tags", NULL, NULL, @@ -173,9 +172,9 @@ CreateImage( imgPtr->canvas = canvas; imgPtr->anchor = TK_ANCHOR_CENTER; - imgPtr->imageString = NULL; - imgPtr->activeImageString = NULL; - imgPtr->disabledImageString = NULL; + imgPtr->imageObj = NULL; + imgPtr->activeImageObj = NULL; + imgPtr->disabledImageObj = NULL; imgPtr->image = NULL; imgPtr->activeImage = NULL; imgPtr->disabledImage = NULL; @@ -302,7 +301,7 @@ ConfigureImage( tkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, - (const char **) objv, (char *) imgPtr, flags|TK_CONFIG_OBJS)) { + (const char **)objv, (char *)imgPtr, flags|TK_CONFIG_OBJS)) { return TCL_ERROR; } @@ -313,13 +312,13 @@ ConfigureImage( * changed. */ - if (imgPtr->activeImageString != NULL) { + if (imgPtr->activeImageObj != NULL) { itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT; } else { itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; } - if (imgPtr->imageString != NULL) { - image = Tk_GetImage(interp, tkwin, imgPtr->imageString, + if (imgPtr->imageObj != NULL) { + image = Tk_GetImage(interp, tkwin, Tcl_GetString(imgPtr->imageObj), ImageChangedProc, imgPtr); if (image == NULL) { return TCL_ERROR; @@ -331,8 +330,8 @@ ConfigureImage( Tk_FreeImage(imgPtr->image); } imgPtr->image = image; - if (imgPtr->activeImageString != NULL) { - image = Tk_GetImage(interp, tkwin, imgPtr->activeImageString, + if (imgPtr->activeImageObj != NULL) { + image = Tk_GetImage(interp, tkwin, Tcl_GetString(imgPtr->activeImageObj), ImageChangedProc, imgPtr); if (image == NULL) { return TCL_ERROR; @@ -344,8 +343,8 @@ ConfigureImage( Tk_FreeImage(imgPtr->activeImage); } imgPtr->activeImage = image; - if (imgPtr->disabledImageString != NULL) { - image = Tk_GetImage(interp, tkwin, imgPtr->disabledImageString, + if (imgPtr->disabledImageObj != NULL) { + image = Tk_GetImage(interp, tkwin, Tcl_GetString(imgPtr->disabledImageObj), ImageChangedProc, imgPtr); if (image == NULL) { return TCL_ERROR; @@ -386,14 +385,14 @@ DeleteImage( { ImageItem *imgPtr = (ImageItem *) itemPtr; - if (imgPtr->imageString != NULL) { - ckfree(imgPtr->imageString); + if (imgPtr->imageObj != NULL) { + Tcl_DecrRefCount(imgPtr->imageObj); } - if (imgPtr->activeImageString != NULL) { - ckfree(imgPtr->activeImageString); + if (imgPtr->activeImageObj != NULL) { + Tcl_DecrRefCount(imgPtr->activeImageObj); } - if (imgPtr->disabledImageString != NULL) { - ckfree(imgPtr->disabledImageString); + if (imgPtr->disabledImageObj != NULL) { + Tcl_DecrRefCount(imgPtr->disabledImageObj); } if (imgPtr->image != NULL) { Tk_FreeImage(imgPtr->image); @@ -526,7 +525,7 @@ static void DisplayImage( Tk_Canvas canvas, /* Canvas that contains item. */ Tk_Item *itemPtr, /* Item to be displayed. */ - Display *display, /* Display on which to draw item. */ + TCL_UNUSED(Display *), /* Display on which to draw item. */ Drawable drawable, /* Pixmap or window in which to draw item. */ int x, int y, int width, int height) /* Describes region of canvas that must be @@ -536,7 +535,6 @@ DisplayImage( short drawableX, drawableY; Tk_Image image; Tk_State state = itemPtr->state; - (void)display; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; diff --git a/generic/tkScrollbar.c b/generic/tkScrollbar.c index 01d8c7783..9ac47168c 100644 --- a/generic/tkScrollbar.c +++ b/generic/tkScrollbar.c @@ -51,8 +51,8 @@ static const Tk_ConfigSpec configSpecs[] = { {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", DEF_SCROLLBAR_BORDER_WIDTH, offsetof(TkScrollbar, borderWidth), 0, NULL}, {TK_CONFIG_STRING, "-command", "command", "Command", - DEF_SCROLLBAR_COMMAND, offsetof(TkScrollbar, command), - TK_CONFIG_NULL_OK, NULL}, + DEF_SCROLLBAR_COMMAND, offsetof(TkScrollbar, commandObj), + TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", DEF_SCROLLBAR_CURSOR, offsetof(TkScrollbar, cursor), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_PIXELS, "-elementborderwidth", "elementBorderWidth", @@ -79,8 +79,8 @@ static const Tk_ConfigSpec configSpecs[] = { {TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval", DEF_SCROLLBAR_REPEAT_INTERVAL, offsetof(TkScrollbar, repeatInterval), 0, NULL}, {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", - DEF_SCROLLBAR_TAKE_FOCUS, offsetof(TkScrollbar, takeFocus), - TK_CONFIG_NULL_OK, NULL}, + DEF_SCROLLBAR_TAKE_FOCUS, offsetof(TkScrollbar, takeFocusObj), + TK_CONFIG_NULL_OK|TK_CONFIG_OBJS, NULL}, {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background", DEF_SCROLLBAR_TROUGH_COLOR, offsetof(TkScrollbar, troughColorPtr), TK_CONFIG_COLOR_ONLY, NULL}, @@ -159,7 +159,7 @@ Tk_ScrollbarObjCmd( scrollPtr, ScrollbarCmdDeletedProc); scrollPtr->vertical = 0; scrollPtr->width = 0; - scrollPtr->command = NULL; + scrollPtr->commandObj = NULL; scrollPtr->commandSize = 0; scrollPtr->repeatDelay = 0; scrollPtr->repeatInterval = 0; @@ -179,6 +179,10 @@ Tk_ScrollbarObjCmd( scrollPtr->activeField = 0; scrollPtr->activeRelief = TK_RELIEF_RAISED; #ifndef TK_NO_DEPRECATED +#define totalUnits dummy1 +#define windowUnits dummy2 +#define firstUnit dummy3 +#define lastUnit dummy4 scrollPtr->totalUnits = 0; scrollPtr->windowUnits = 0; scrollPtr->firstUnit = 0; @@ -187,7 +191,7 @@ Tk_ScrollbarObjCmd( scrollPtr->firstFraction = 0.0; scrollPtr->lastFraction = 0.0; scrollPtr->cursor = NULL; - scrollPtr->takeFocus = NULL; + scrollPtr->takeFocusObj = NULL; scrollPtr->flags = 0; if (ConfigureScrollbar(interp, scrollPtr, objc-2, objv+2, 0) != TCL_OK) { @@ -323,11 +327,11 @@ ScrollbarWidgetObjCmd( if (scrollPtr->vertical) { pixels = yDelta; length = Tk_Height(scrollPtr->tkwin) - 1 - - 2*(scrollPtr->arrowLength + scrollPtr->inset); + - 2 * (scrollPtr->arrowLength + scrollPtr->inset); } else { pixels = xDelta; length = Tk_Width(scrollPtr->tkwin) - 1 - - 2*(scrollPtr->arrowLength + scrollPtr->inset); + - 2 * (scrollPtr->arrowLength + scrollPtr->inset); } if (length == 0) { fraction = 0.0; @@ -352,11 +356,11 @@ ScrollbarWidgetObjCmd( if (scrollPtr->vertical) { pos = y - (scrollPtr->arrowLength + scrollPtr->inset); length = Tk_Height(scrollPtr->tkwin) - 1 - - 2*(scrollPtr->arrowLength + scrollPtr->inset); + - 2 * (scrollPtr->arrowLength + scrollPtr->inset); } else { pos = x - (scrollPtr->arrowLength + scrollPtr->inset); length = Tk_Width(scrollPtr->tkwin) - 1 - - 2*(scrollPtr->arrowLength + scrollPtr->inset); + - 2 * (scrollPtr->arrowLength + scrollPtr->inset); } if (length == 0) { fraction = 0.0; @@ -379,6 +383,7 @@ ScrollbarWidgetObjCmd( goto error; } #ifndef TK_NO_DEPRECATED +# define OLD_STYLE_COMMANDS 2 if (scrollPtr->flags & OLD_STYLE_COMMANDS) { resObjs[0] = Tcl_NewWideIntObj(scrollPtr->totalUnits); resObjs[1] = Tcl_NewWideIntObj(scrollPtr->windowUnits); @@ -540,8 +545,8 @@ ConfigureScrollbar( * from a 3-D border. */ - if (scrollPtr->command != NULL) { - scrollPtr->commandSize = (int) strlen(scrollPtr->command); + if (scrollPtr->commandObj != NULL) { + scrollPtr->commandSize = (int) strlen(Tcl_GetString(scrollPtr->commandObj)); } else { scrollPtr->commandSize = 0; } diff --git a/generic/tkScrollbar.h b/generic/tkScrollbar.h index b5a743902..9ac3d249f 100644 --- a/generic/tkScrollbar.h +++ b/generic/tkScrollbar.h @@ -33,11 +33,16 @@ typedef struct TkScrollbar { Tcl_Command widgetCmd; /* Token for scrollbar's widget command. */ int vertical; /* Non-zero means vertical orientation * requested, zero means horizontal. */ +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *widthObj; /* Desired narrow dimension of scrollbar, in + * pixels. */ +#else int width; /* Desired narrow dimension of scrollbar, in * pixels. */ - char *command; /* Command prefix to use when invoking +#endif + Tcl_Obj *commandObj; /* Command prefix to use when invoking * scrolling commands. NULL means don't invoke - * commands. Malloc'ed. */ + * commands. */ int commandSize; /* Number of non-NULL bytes in command. */ int repeatDelay; /* How long to wait before auto-repeating on * scrolling actions (in ms). */ @@ -48,7 +53,11 @@ typedef struct TkScrollbar { * Information used when displaying widget: */ - int borderWidth; /* Width of 3-D borders. */ +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *borderWidthObj; /* Width of 3-D borders. */ +#else + int borderWidth; +#endif Tk_3DBorder bgBorder; /* Used for drawing background (all flat * surfaces except for trough). */ Tk_3DBorder activeBorder; /* For drawing backgrounds when active (i.e. @@ -56,9 +65,13 @@ typedef struct TkScrollbar { XColor *troughColorPtr; /* Color for drawing trough. */ int relief; /* Indicates whether window as a whole is * raised, sunken, or flat. */ - int highlightWidth; /* Width in pixels of highlight to draw around +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around * widget when it has the focus. <= 0 means * don't draw a highlight. */ +#else + int highlightWidth; +#endif XColor *highlightBgColorPtr; /* Color for drawing traversal highlight area * when highlight is off. */ @@ -68,9 +81,13 @@ typedef struct TkScrollbar { * Indicates how much interior stuff must be * offset from outside edges to leave room for * borders. */ - int elementBorderWidth; /* Width of border to draw around elements +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *elementBorderWidthObj; /* Width of border to draw around elements * inside scrollbar (arrows and slider). -1 * means use borderWidth. */ +#else + int elementBorderWidth; +#endif int arrowLength; /* Length of arrows along long dimension of * scrollbar, including space for a small gap * between the arrow and the slider. @@ -87,46 +104,28 @@ typedef struct TkScrollbar { * use for active element. */ /* - * Information describing the application related to the scrollbar. This - * information is provided by the application by invoking the "set" widget - * command. This information can now be provided in two ways: the "old" - * form (totalUnits, windowUnits, firstUnit, and lastUnit), or the "new" - * form (firstFraction and lastFraction). FirstFraction and lastFraction - * will always be valid, but the old-style information is only valid if - * the OLD_STYLE_COMMANDS flag is 1. + * Information describing the application related to the scrollbar, which + * is provided by the application by invoking the "set" widget command. + * It can be provided in two ways: the "new" form (firstFraction + * and lastFraction) or the "old" form. The "old" form is deprecated. */ -#ifndef TK_NO_DEPRECATED - int totalUnits; /* Total dimension of application, in units. - * Valid only if the OLD_STYLE_COMMANDS flag - * is set. */ - int windowUnits; /* Maximum number of units that can be - * displayed in the window at once. Valid only - * if the OLD_STYLE_COMMANDS flag is set. */ - int firstUnit; /* Number of last unit visible in - * application's window. Valid only if the - * OLD_STYLE_COMMANDS flag is set. */ - int lastUnit; /* Index of last unit visible in window. - * Valid only if the OLD_STYLE_COMMANDS flag - * isn't set. */ -#else - int dummy1,dummy2,dummy3,dummy4; /* sizeof(TkScrollbar) should not depend on TK_NO_DEPRECATED */ -#endif /* TK_NO_DEPRECATED */ +#if TK_MAJOR_VERSION < 9 + int dummy1, dummy2, dummy3, dummy4; /* deprecated, for "old" form. */ +#endif double firstFraction; /* Position of first visible thing in window, - * specified as a fraction between 0 and - * 1.0. */ + * specified as a fraction between 0 and 1.0. */ double lastFraction; /* Position of last visible thing in window, - * specified as a fraction between 0 and - * 1.0. */ + * specified as a fraction between 0 and 1.0. */ /* * Miscellaneous information: */ Tk_Cursor cursor; /* Current cursor for window, or NULL. */ - char *takeFocus; /* Value of -takefocus option; not used in the + Tcl_Obj *takeFocusObj; /* Value of -takefocus option; not used in the * C code, but used by keyboard traversal - * scripts. Malloc'ed, but may be NULL. */ + * scripts. May be NULL. */ int flags; /* Various flags; see below for * definitions. */ } TkScrollbar; @@ -148,18 +147,11 @@ typedef struct TkScrollbar { * * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has * already been queued to redraw this window. - * OLD_STYLE_COMMANDS: Non-zero means the old style of commands - * should be used to communicate with the widget: - * ".t yview 40", instead of - * ".t yview scroll 2 lines", for example. * GOT_FOCUS: Non-zero means this window has the input * focus. */ #define REDRAW_PENDING 1 -#ifndef TK_NO_DEPRECATED -# define OLD_STYLE_COMMANDS 2 -#endif /* TK_NO_DEPRECATED */ #define GOT_FOCUS 4 /* diff --git a/generic/tkText.h b/generic/tkText.h index 1627096cf..7c31b80c3 100644 --- a/generic/tkText.h +++ b/generic/tkText.h @@ -116,10 +116,14 @@ typedef struct TkTextEmbWindow { * window. */ Tcl_Obj *createObj; /* Script to create window on-demand. NULL * means no such script. */ +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *padXObj, *padYObj; /* Padding to leave around each side of window. */ +#endif TkAlignMode align; /* How to align window in vertical space. See * definitions in tkTextWind.c. */ - int padX, padY; /* Padding to leave around each side of - * window, in pixels. */ +#if TK_MAJOR_VERSION < 9 + int padX, padY; +#endif int stretch; /* Should window stretch to fill vertical * space of line (except for pady)? 0 or 1. */ Tk_OptionTable optionTable; /* Token representing the configuration @@ -148,10 +152,15 @@ typedef struct TkTextEmbImage { * the image. */ Tk_Image image; /* Image for this segment. NULL means that the * image hasn't been created yet. */ +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *padXObj, *padYObj; /* Padding to leave around each side of image, + * in pixels. */ +#endif TkAlignMode align; /* How to align image in vertical space. See * definitions in tkTextImage.c. */ - int padX, padY; /* Padding to leave around each side of image, - * in pixels. */ +#if TK_MAJOR_VERSION < 9 + int padX, padY; +#endif int chunkCount; /* Number of display chunks that refer to this * image. */ Tk_OptionTable optionTable; /* Token representing the configuration @@ -369,11 +378,12 @@ typedef struct TkTextTag { * baseline of line. Used for superscripts and * subscripts. NULL means option not specified. */ int offset; /* No longer used, but kept for binary compatibility. */ +#if TK_MAJOR_VERSION < 9 Tcl_Obj *overstrikeObj; /* -overstrike option. NULL * means option not specified. */ - int overstrike; /* Non-zero means draw horizontal line through - * middle of text. Only valid if - * overstrikeObj is non-NULL. */ +#endif + int overstrike; /* > 0 means draw horizontal line through + * middle of text. -1 means not specified. */ XColor *overstrikeColor; /* Color for the overstrike. NULL means same * color as foreground. */ Tcl_Obj *rMarginObj; /* Right margin for text, in pixels. NULL @@ -398,22 +408,24 @@ typedef struct TkTextTag { * NULL. Corresponds to tabStringPtr. */ TkTextTabStyle tabStyle; /* One of TK_TEXT_TABSTYLE_TABULAR or TK_TEXT_TABSTYLE_WORDPROCESSOR * or TK_TEXT_TABSTYLE_NULL (if not specified). */ +#if TK_MAJOR_VERSION < 9 Tcl_Obj *underlineObj; /* -underline option. NULL * means option not specified. */ - int underline; /* Non-zero means draw underline underneath - * text. Only valid if underlineObj is - * non-NULL. */ +#endif + int underline; /* > 0 means draw underline underneath + * text. -1 means not specified. */ XColor *underlineColor; /* Color for the underline. NULL means same * color as foreground. */ TkWrapMode wrapMode; /* How to handle wrap-around for this tag. * Must be TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_WORD, * TEXT_WRAPMODE_NONE, or TEXT_WRAPMODE_NULL to * use wrapmode for whole widget. */ +#if TK_MAJOR_VERSION < 9 Tcl_Obj *elideObj; /* -elide option. NULL * means option not specified. */ +#endif int elide; /* Non-zero means that data under this tag - * should not be displayed. Only valid if elideObj is - * non-NULL. */ + * should not be displayed. -1 means not specified. */ int affectsDisplay; /* Non-zero means that this tag affects the * way information is displayed on the screen * (so need to redisplay if tag changes). */ @@ -651,14 +663,23 @@ typedef struct TkText { Tk_3DBorder border; /* Structure used to draw 3-D border and * default background. */ - int borderWidth; /* Width of 3-D border to draw around entire +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *borderWidthObj; /* Width of 3-D border to draw around entire * widget. */ - int padX, padY; /* Padding between text and window border. */ + Tcl_Obj *padXObj, *padYObj; /* Padding between text and window border. */ +#else + int borderWidth; + int padX, padY; +#endif int relief; /* 3-d effect for border around entire widget: * TK_RELIEF_RAISED etc. */ - int highlightWidth; /* Width in pixels of highlight to draw around +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around * widget when it has the focus. <= 0 means * don't draw a highlight. */ +#else + int highlightWidth; +#endif XColor *highlightBgColorPtr; /* Color for drawing traversal highlight area * when highlight is off. */ @@ -670,12 +691,16 @@ typedef struct TkText { * font. */ int charHeight; /* Height of average character in default * font, including line spacing. */ - int spacing1; /* Default extra spacing above first display +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *spacing1Obj; /* Default extra spacing above first display * line for each text line. */ - int spacing2; /* Default extra spacing between display lines + Tcl_Obj *spacing2Obj; /* Default extra spacing between display lines * for the same text line. */ - int spacing3; /* Default extra spacing below last display + Tcl_Obj *spacing3Obj; /* Default extra spacing below last display * line for each text line. */ +#else + int spacing1, spacing2, spacing3; +#endif Tcl_Obj *tabOptionObj; /* Value of -tabs option string. */ TkTextTabArray *tabArrayPtr; /* Information about tab stops (malloc'ed). @@ -691,8 +716,12 @@ typedef struct TkText { * TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, or * TEXT_WRAPMODE_WORD, or TEXT_WRAPMODE_NULL to * use wrapmode for whole widget. */ - int width, height; /* Desired dimensions for window, measured in - * characters. */ + int width; /* Desired dimensions for window, measured in characters */ +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *heightObj; +#else + int height; +#endif int setGrid; /* Non-zero means pass gridding information to * window manager. */ int prevWidth, prevHeight; /* Last known dimensions of window; used to @@ -715,6 +744,9 @@ typedef struct TkText { /* Border and background for selected * characters when they don't have the * focus. */ +#if TK_MAJOR_VERSION < 8 + int selBorderWidth; +#endif Tcl_Obj *selBorderWidthObj; /* Width of border around selection. */ XColor *selFgColorPtr; /* Foreground color for selected text. This is * a copy of information in *selTagPtr, so it @@ -734,8 +766,12 @@ typedef struct TkText { /* Points to segment for "insert" mark. */ Tk_3DBorder insertBorder; /* Used to draw vertical bar for insertion * cursor. */ - int insertWidth; /* Total width of insert cursor. */ - int insertBorderWidth; /* Width of 3-D border around insert cursor */ +#if TK_MAJOR_VERSION > 8 + Tcl_Obj *insertWidthObj; /* Total width of insert cursor. */ + Tcl_Obj *insertBorderWidthObj; /* Width of 3-D border around insert cursor */ +#else + int insertWidth, insertBorderWidth; +#endif TkTextInsertUnfocussed insertUnfocussed; /* How to display the insert cursor when the * text widget does not have the focus. */