diff options
Diffstat (limited to 'generic/ttk')
36 files changed, 1866 insertions, 2579 deletions
diff --git a/generic/ttk/ttk.decls b/generic/ttk/ttk.decls index e668a2a..1c98b23 100644 --- a/generic/ttk/ttk.decls +++ b/generic/ttk/ttk.decls @@ -25,7 +25,7 @@ declare 5 { int Ttk_RegisterElementSpec( Ttk_Theme theme, const char *elementName, - Ttk_ElementSpec *elementSpec, + const Ttk_ElementSpec *elementSpec, void *clientData) } @@ -34,7 +34,7 @@ declare 6 { Tcl_Interp *interp, Ttk_Theme theme, const char *elementName, - Ttk_ElementSpec *elementSpec, + const Ttk_ElementSpec *elementSpec, void *clientData) } @@ -72,7 +72,7 @@ declare 13 { } declare 14 { int Ttk_StateTableLookup( - Ttk_StateTable map[], Ttk_State state) + const Ttk_StateTable *map, Ttk_State state) } @@ -143,7 +143,7 @@ declare 35 { # # Utilities. # -declare 40 { +declare 40 {deprecated {}} { int Ttk_GetOrientFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *orient) } diff --git a/generic/ttk/ttkBlink.c b/generic/ttk/ttkBlink.c index a7d4a9a..fc48af9 100644 --- a/generic/ttk/ttkBlink.c +++ b/generic/ttk/ttkBlink.c @@ -34,9 +34,11 @@ typedef struct /* CursorManagerDeleteProc -- * InterpDeleteProc for cursor manager. */ -static void CursorManagerDeleteProc(ClientData clientData, Tcl_Interp *interp) +static void CursorManagerDeleteProc(ClientData clientData, Tcl_Interp *dummy) { CursorManager *cm = (CursorManager*)clientData; + (void)dummy; + if (cm->timer) { Tcl_DeleteTimerHandler(cm->timer); } @@ -49,10 +51,10 @@ static void CursorManagerDeleteProc(ClientData clientData, Tcl_Interp *interp) static CursorManager *GetCursorManager(Tcl_Interp *interp) { static const char *cm_key = "ttk::CursorManager"; - CursorManager *cm = Tcl_GetAssocData(interp, cm_key,0); + CursorManager *cm = (CursorManager *)Tcl_GetAssocData(interp, cm_key,0); if (!cm) { - cm = ckalloc(sizeof(*cm)); + cm = (CursorManager *)ckalloc(sizeof(*cm)); cm->timer = 0; cm->owner = 0; cm->onTime = DEF_CURSOR_ON_TIME; @@ -68,7 +70,7 @@ static CursorManager *GetCursorManager(Tcl_Interp *interp) static void CursorBlinkProc(ClientData clientData) { - CursorManager *cm = (CursorManager*)clientData; + CursorManager *cm = (CursorManager *)clientData; int blinkTime; if (cm->owner->flags & CURSOR_ON) { diff --git a/generic/ttk/ttkButton.c b/generic/ttk/ttkButton.c index f4ef7bc..e179a7f 100644 --- a/generic/ttk/ttkButton.c +++ b/generic/ttk/ttkButton.c @@ -22,6 +22,7 @@ typedef struct * Text element resources: */ Tcl_Obj *textObj; + Tcl_Obj *justifyObj; Tcl_Obj *textVariableObj; Tcl_Obj *underlineObj; Tcl_Obj *widthObj; @@ -53,45 +54,48 @@ typedef struct BasePart base; } Base; -static Tk_OptionSpec BaseOptionSpecs[] = +static const Tk_OptionSpec BaseOptionSpecs[] = { + {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", + "left", offsetof(Base,base.justifyObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-text", "text", "Text", "", - Tk_Offset(Base,base.textObj), -1, + offsetof(Base,base.textObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable", "", - Tk_Offset(Base,base.textVariableObj), -1, + offsetof(Base,base.textVariableObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_INT, "-underline", "underline", "Underline", - "-1", Tk_Offset(Base,base.underlineObj), -1, + "-1", offsetof(Base,base.underlineObj), TCL_INDEX_NONE, 0,0,0 }, /* SB: OPTION_INT, see <<NOTE-NULLOPTIONS>> */ {TK_OPTION_STRING, "-width", "width", "Width", - NULL, Tk_Offset(Base,base.widthObj), -1, + NULL, offsetof(Base,base.widthObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, /* * Image options */ {TK_OPTION_STRING, "-image", "image", "Image", NULL/*default*/, - Tk_Offset(Base,base.imageObj), -1, + offsetof(Base,base.imageObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, /* * Compound base/image options */ {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound", - NULL, Tk_Offset(Base,base.compoundObj), -1, - TK_OPTION_NULL_OK, (void *)ttkCompoundStrings, - GEOMETRY_CHANGED }, + NULL, offsetof(Base,base.compoundObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK, (void *)ttkCompoundStrings, + GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-padding", "padding", "Pad", - NULL, Tk_Offset(Base,base.paddingObj), -1, + NULL, offsetof(Base,base.paddingObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED}, /* * Compatibility/legacy options */ {TK_OPTION_STRING, "-state", "state", "State", - "normal", Tk_Offset(Base,base.stateObj), -1, + "normal", offsetof(Base,base.stateObj), TCL_INDEX_NONE, 0,0,STATE_CHANGED }, WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs) @@ -237,31 +241,31 @@ typedef struct LabelPart label; } Label; -static Tk_OptionSpec LabelOptionSpecs[] = +static const Tk_OptionSpec LabelOptionSpecs[] = { {TK_OPTION_BORDER, "-background", "frameColor", "FrameColor", - NULL, Tk_Offset(Label,label.backgroundObj), -1, + NULL, offsetof(Label,label.backgroundObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor", - NULL, Tk_Offset(Label,label.foregroundObj), -1, + NULL, offsetof(Label,label.foregroundObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_FONT, "-font", "font", "Font", - NULL, Tk_Offset(Label,label.fontObj), -1, + NULL, offsetof(Label,label.fontObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", - NULL, Tk_Offset(Label,label.borderWidthObj), -1, + NULL, offsetof(Label,label.borderWidthObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", - NULL, Tk_Offset(Label,label.reliefObj), -1, + NULL, offsetof(Label,label.reliefObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", - NULL, Tk_Offset(Label,label.anchorObj), -1, + NULL, offsetof(Label,label.anchorObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED}, {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", - NULL, Tk_Offset(Label, label.justifyObj), -1, + NULL, offsetof(Label, label.justifyObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength", - NULL, Tk_Offset(Label, label.wrapLengthObj), -1, + NULL, offsetof(Label, label.wrapLengthObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED /*SB: SIZE_CHANGED*/ }, WIDGET_TAKEFOCUS_FALSE, @@ -277,7 +281,7 @@ static const Ttk_Ensemble LabelCommands[] = { { 0,0,0 } }; -static WidgetSpec LabelWidgetSpec = +static const WidgetSpec LabelWidgetSpec = { "TLabel", /* className */ sizeof(Label), /* recordSize */ @@ -320,12 +324,12 @@ typedef struct /* * Option specifications: */ -static Tk_OptionSpec ButtonOptionSpecs[] = +static const Tk_OptionSpec ButtonOptionSpecs[] = { {TK_OPTION_STRING, "-command", "command", "Command", - "", Tk_Offset(Button, button.commandObj), -1, 0,0,0}, + "", offsetof(Button, button.commandObj), TCL_INDEX_NONE, 0,0,0}, {TK_OPTION_STRING_TABLE, "-default", "default", "Default", - "normal", Tk_Offset(Button, button.defaultStateObj), -1, + "normal", offsetof(Button, button.defaultStateObj), TCL_INDEX_NONE, 0, (void *)ttkDefaultStrings, DEFAULTSTATE_CHANGED}, WIDGET_TAKEFOCUS_TRUE, @@ -343,7 +347,7 @@ static int ButtonConfigure(Tcl_Interp *interp, void *recordPtr, int mask) /* Handle "-default" option: */ if (mask & DEFAULTSTATE_CHANGED) { - int defaultState = TTK_BUTTON_DEFAULT_DISABLED; + Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED; Ttk_GetButtonDefaultStateFromObj( NULL, buttonPtr->button.defaultStateObj, &defaultState); if (defaultState == TTK_BUTTON_DEFAULT_ACTIVE) { @@ -383,7 +387,7 @@ static const Ttk_Ensemble ButtonCommands[] = { { 0,0,0 } }; -static WidgetSpec ButtonWidgetSpec = +static const WidgetSpec ButtonWidgetSpec = { "TButton", /* className */ sizeof(Button), /* recordSize */ @@ -430,19 +434,19 @@ typedef struct /* * Option specifications: */ -static Tk_OptionSpec CheckbuttonOptionSpecs[] = +static const Tk_OptionSpec CheckbuttonOptionSpecs[] = { {TK_OPTION_STRING, "-variable", "variable", "Variable", - NULL, Tk_Offset(Checkbutton, checkbutton.variableObj), -1, + NULL, offsetof(Checkbutton, checkbutton.variableObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, {TK_OPTION_STRING, "-onvalue", "onValue", "OnValue", - "1", Tk_Offset(Checkbutton, checkbutton.onValueObj), -1, + "1", offsetof(Checkbutton, checkbutton.onValueObj), TCL_INDEX_NONE, 0,0,0}, {TK_OPTION_STRING, "-offvalue", "offValue", "OffValue", - "0", Tk_Offset(Checkbutton, checkbutton.offValueObj), -1, + "0", offsetof(Checkbutton, checkbutton.offValueObj), TCL_INDEX_NONE, 0,0,0}, {TK_OPTION_STRING, "-command", "command", "Command", - "", Tk_Offset(Checkbutton, checkbutton.commandObj), -1, + "", offsetof(Checkbutton, checkbutton.commandObj), TCL_INDEX_NONE, 0,0,0}, WIDGET_TAKEFOCUS_TRUE, @@ -591,7 +595,7 @@ static const Ttk_Ensemble CheckbuttonCommands[] = { { 0,0,0 } }; -static WidgetSpec CheckbuttonWidgetSpec = +static const WidgetSpec CheckbuttonWidgetSpec = { "TCheckbutton", /* className */ sizeof(Checkbutton), /* recordSize */ @@ -638,16 +642,16 @@ typedef struct /* * Option specifications: */ -static Tk_OptionSpec RadiobuttonOptionSpecs[] = +static const Tk_OptionSpec RadiobuttonOptionSpecs[] = { {TK_OPTION_STRING, "-variable", "variable", "Variable", - "::selectedButton", Tk_Offset(Radiobutton, radiobutton.variableObj),-1, + "::selectedButton", offsetof(Radiobutton, radiobutton.variableObj),TCL_INDEX_NONE, 0,0,0}, {TK_OPTION_STRING, "-value", "Value", "Value", - "1", Tk_Offset(Radiobutton, radiobutton.valueObj), -1, + "1", offsetof(Radiobutton, radiobutton.valueObj), TCL_INDEX_NONE, 0,0,0}, {TK_OPTION_STRING, "-command", "command", "Command", - "", Tk_Offset(Radiobutton, radiobutton.commandObj), -1, + "", offsetof(Radiobutton, radiobutton.commandObj), TCL_INDEX_NONE, 0,0,0}, WIDGET_TAKEFOCUS_TRUE, @@ -767,7 +771,7 @@ static const Ttk_Ensemble RadiobuttonCommands[] = { { 0,0,0 } }; -static WidgetSpec RadiobuttonWidgetSpec = +static const WidgetSpec RadiobuttonWidgetSpec = { "TRadiobutton", /* className */ sizeof(Radiobutton), /* recordSize */ @@ -813,12 +817,12 @@ typedef struct static const char *const directionStrings[] = { "above", "below", "left", "right", "flush", NULL }; -static Tk_OptionSpec MenubuttonOptionSpecs[] = +static const Tk_OptionSpec MenubuttonOptionSpecs[] = { {TK_OPTION_STRING, "-menu", "menu", "Menu", - "", Tk_Offset(Menubutton, menubutton.menuObj), -1, 0,0,0}, + "", offsetof(Menubutton, menubutton.menuObj), TCL_INDEX_NONE, 0,0,0}, {TK_OPTION_STRING_TABLE, "-direction", "direction", "Direction", - "below", Tk_Offset(Menubutton, menubutton.directionObj), -1, + "below", offsetof(Menubutton, menubutton.directionObj), TCL_INDEX_NONE, 0, (void *)directionStrings, GEOMETRY_CHANGED}, WIDGET_TAKEFOCUS_TRUE, @@ -834,7 +838,7 @@ static const Ttk_Ensemble MenubuttonCommands[] = { { 0,0,0 } }; -static WidgetSpec MenubuttonWidgetSpec = +static const WidgetSpec MenubuttonWidgetSpec = { "TMenubutton", /* className */ sizeof(Menubutton), /* recordSize */ diff --git a/generic/ttk/ttkCache.c b/generic/ttk/ttkCache.c index e7f885f..9059c55 100644 --- a/generic/ttk/ttkCache.c +++ b/generic/ttk/ttkCache.c @@ -28,7 +28,6 @@ * but this will be a transient effect. */ -#include <stdio.h> /* for sprintf */ #include "tkInt.h" #include "ttkTheme.h" @@ -49,7 +48,7 @@ struct Ttk_ResourceCache_ { */ Ttk_ResourceCache Ttk_CreateResourceCache(Tcl_Interp *interp) { - Ttk_ResourceCache cache = ckalloc(sizeof(*cache)); + Ttk_ResourceCache cache = (Ttk_ResourceCache)ckalloc(sizeof(*cache)); cache->tkwin = NULL; /* initialized later */ cache->interp = interp; @@ -76,7 +75,7 @@ static void Ttk_ClearCache(Ttk_ResourceCache cache) */ entryPtr = Tcl_FirstHashEntry(&cache->fontTable, &search); while (entryPtr != NULL) { - Tcl_Obj *fontObj = Tcl_GetHashValue(entryPtr); + Tcl_Obj *fontObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); if (fontObj) { Tk_FreeFontFromObj(cache->tkwin, fontObj); Tcl_DecrRefCount(fontObj); @@ -91,7 +90,7 @@ static void Ttk_ClearCache(Ttk_ResourceCache cache) */ entryPtr = Tcl_FirstHashEntry(&cache->colorTable, &search); while (entryPtr != NULL) { - Tcl_Obj *colorObj = Tcl_GetHashValue(entryPtr); + Tcl_Obj *colorObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); if (colorObj) { Tk_FreeColorFromObj(cache->tkwin, colorObj); Tcl_DecrRefCount(colorObj); @@ -106,7 +105,7 @@ static void Ttk_ClearCache(Ttk_ResourceCache cache) */ entryPtr = Tcl_FirstHashEntry(&cache->borderTable, &search); while (entryPtr != NULL) { - Tcl_Obj *borderObj = Tcl_GetHashValue(entryPtr); + Tcl_Obj *borderObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); if (borderObj) { Tk_Free3DBorderFromObj(cache->tkwin, borderObj); Tcl_DecrRefCount(borderObj); @@ -121,7 +120,7 @@ static void Ttk_ClearCache(Ttk_ResourceCache cache) */ entryPtr = Tcl_FirstHashEntry(&cache->imageTable, &search); while (entryPtr != NULL) { - Tk_Image image = Tcl_GetHashValue(entryPtr); + Tk_Image image = (Tk_Image)Tcl_GetHashValue(entryPtr); if (image) { Tk_FreeImage(image); } @@ -154,7 +153,7 @@ void Ttk_FreeResourceCache(Ttk_ResourceCache cache) */ entryPtr = Tcl_FirstHashEntry(&cache->namedColors, &search); while (entryPtr != NULL) { - Tcl_Obj *colorNameObj = Tcl_GetHashValue(entryPtr); + Tcl_Obj *colorNameObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); Tcl_DecrRefCount(colorNameObj); entryPtr = Tcl_NextHashEntry(&search); } @@ -169,7 +168,7 @@ void Ttk_FreeResourceCache(Ttk_ResourceCache cache) */ static void CacheWinEventHandler(ClientData clientData, XEvent *eventPtr) { - Ttk_ResourceCache cache = clientData; + Ttk_ResourceCache cache = (Ttk_ResourceCache)clientData; if (eventPtr->type != DestroyNotify) { return; @@ -217,7 +216,7 @@ void Ttk_RegisterNamedColor( entryPtr = Tcl_CreateHashEntry(&cache->namedColors, colorName, &newEntry); if (!newEntry) { - Tcl_Obj *oldColor = Tcl_GetHashValue(entryPtr); + Tcl_Obj *oldColor = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); Tcl_DecrRefCount(oldColor); } @@ -235,7 +234,7 @@ static Tcl_Obj *CheckNamedColor(Ttk_ResourceCache cache, Tcl_Obj *objPtr) Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&cache->namedColors, Tcl_GetString(objPtr)); if (entryPtr) { /* Use named color instead */ - objPtr = Tcl_GetHashValue(entryPtr); + objPtr = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); } return objPtr; } @@ -258,7 +257,7 @@ static Tcl_Obj *Ttk_Use( Tcl_Obj *cacheObj; if (!newEntry) { - return Tcl_GetHashValue(entryPtr); + return (Tcl_Obj *)Tcl_GetHashValue(entryPtr); } cacheObj = Tcl_DuplicateObj(objPtr); @@ -315,9 +314,17 @@ Tcl_Obj *Ttk_UseBorder( * Tk_ImageChangedProc for Ttk_UseImage */ -static void NullImageChanged(ClientData clientData, +static void NullImageChanged(ClientData dummy, int x, int y, int width, int height, int imageWidth, int imageHeight) -{ /* No-op */ } +{ /* No-op */ + (void)dummy; + (void)x; + (void)y; + (void)width; + (void)height; + (void)imageWidth; + (void)imageHeight; +} /* * Ttk_UseImage -- @@ -334,7 +341,7 @@ Tk_Image Ttk_UseImage(Ttk_ResourceCache cache, Tk_Window tkwin, Tcl_Obj *objPtr) InitCacheWindow(cache, tkwin); if (!newEntry) { - return Tcl_GetHashValue(entryPtr); + return (Tk_Image)Tcl_GetHashValue(entryPtr); } image = Tk_GetImage(cache->interp, tkwin, imageName, NullImageChanged,0); diff --git a/generic/ttk/ttkClamTheme.c b/generic/ttk/ttkClamTheme.c index 733a391..035cabc 100644 --- a/generic/ttk/ttkClamTheme.c +++ b/generic/ttk/ttkClamTheme.c @@ -106,17 +106,17 @@ typedef struct { Tcl_Obj *borderWidthObj; /* See <<NOTE-BORDERWIDTH>> */ } BorderElement; -static Ttk_ElementOptionSpec BorderElementOptions[] = { +static const Ttk_ElementOptionSpec BorderElementOptions[] = { { "-bordercolor", TK_OPTION_COLOR, - Tk_Offset(BorderElement,borderColorObj), DARKEST_COLOR }, + offsetof(BorderElement,borderColorObj), DARKEST_COLOR }, { "-lightcolor", TK_OPTION_COLOR, - Tk_Offset(BorderElement,lightColorObj), LIGHT_COLOR }, + offsetof(BorderElement,lightColorObj), LIGHT_COLOR }, { "-darkcolor", TK_OPTION_COLOR, - Tk_Offset(BorderElement,darkColorObj), DARK_COLOR }, + offsetof(BorderElement,darkColorObj), DARK_COLOR }, { "-relief", TK_OPTION_RELIEF, - Tk_Offset(BorderElement,reliefObj), "flat" }, + offsetof(BorderElement,reliefObj), "flat" }, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(BorderElement,borderWidthObj), "2" }, + offsetof(BorderElement,borderWidthObj), "2" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -183,7 +183,7 @@ static void BorderElementDraw( DrawSmoothBorder(tkwin, d, b, outer, upper, lower); } -static Ttk_ElementSpec BorderElementSpec = { +static const Ttk_ElementSpec BorderElementSpec = { TK_STYLE_VERSION_2, sizeof(BorderElement), BorderElementOptions, @@ -202,15 +202,15 @@ typedef struct { Tcl_Obj *backgroundObj; } FieldElement; -static Ttk_ElementOptionSpec FieldElementOptions[] = { +static const Ttk_ElementOptionSpec FieldElementOptions[] = { { "-bordercolor", TK_OPTION_COLOR, - Tk_Offset(FieldElement,borderColorObj), DARKEST_COLOR }, + offsetof(FieldElement,borderColorObj), DARKEST_COLOR }, { "-lightcolor", TK_OPTION_COLOR, - Tk_Offset(FieldElement,lightColorObj), LIGHT_COLOR }, + offsetof(FieldElement,lightColorObj), LIGHT_COLOR }, { "-darkcolor", TK_OPTION_COLOR, - Tk_Offset(FieldElement,darkColorObj), DARK_COLOR }, + offsetof(FieldElement,darkColorObj), DARK_COLOR }, { "-fieldbackground", TK_OPTION_BORDER, - Tk_Offset(FieldElement,backgroundObj), "white" }, + offsetof(FieldElement,backgroundObj), "white" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -244,7 +244,7 @@ static void FieldElementDraw( tkwin, d, bg, f.x, f.y, f.width, f.height, 0, TK_RELIEF_SUNKEN); } -static Ttk_ElementSpec FieldElementSpec = { +static const Ttk_ElementSpec FieldElementSpec = { TK_STYLE_VERSION_2, sizeof(FieldElement), FieldElementOptions, @@ -271,7 +271,7 @@ static void ComboboxFieldElementDraw( b.x + b.width - 1, b.y + b.height - 1 + WIN32_XDRAWLINE_HACK); } -static Ttk_ElementSpec ComboboxFieldElementSpec = { +static const Ttk_ElementSpec ComboboxFieldElementSpec = { TK_STYLE_VERSION_2, sizeof(FieldElement), FieldElementOptions, @@ -292,19 +292,19 @@ typedef struct { Tcl_Obj *lowerColorObj; } IndicatorElement; -static Ttk_ElementOptionSpec IndicatorElementOptions[] = { +static const Ttk_ElementOptionSpec IndicatorElementOptions[] = { { "-indicatorsize", TK_OPTION_PIXELS, - Tk_Offset(IndicatorElement,sizeObj), "10" }, + offsetof(IndicatorElement,sizeObj), "10" }, { "-indicatormargin", TK_OPTION_STRING, - Tk_Offset(IndicatorElement,marginObj), "1" }, + offsetof(IndicatorElement,marginObj), "1" }, { "-indicatorbackground", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,backgroundObj), "white" }, + offsetof(IndicatorElement,backgroundObj), "white" }, { "-indicatorforeground", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,foregroundObj), "black" }, + offsetof(IndicatorElement,foregroundObj), "black" }, { "-upperbordercolor", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,upperColorObj), DARKEST_COLOR }, + offsetof(IndicatorElement,upperColorObj), DARKEST_COLOR }, { "-lowerbordercolor", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,lowerColorObj), DARK_COLOR }, + offsetof(IndicatorElement,lowerColorObj), DARK_COLOR }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -395,7 +395,7 @@ static void CheckIndicatorElementDraw( } } -static Ttk_ElementSpec RadioIndicatorElementSpec = { +static const Ttk_ElementSpec RadioIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(IndicatorElement), IndicatorElementOptions, @@ -403,7 +403,7 @@ static Ttk_ElementSpec RadioIndicatorElementSpec = { RadioIndicatorElementDraw }; -static Ttk_ElementSpec CheckIndicatorElementSpec = { +static const Ttk_ElementSpec CheckIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(IndicatorElement), IndicatorElementOptions, @@ -419,16 +419,16 @@ typedef struct { Tcl_Obj *paddingObj; } MenuIndicatorElement; -static Ttk_ElementOptionSpec MenuIndicatorElementOptions[] = +static const Ttk_ElementOptionSpec MenuIndicatorElementOptions[] = { { "-arrowsize", TK_OPTION_PIXELS, - Tk_Offset(MenuIndicatorElement,sizeObj), + offsetof(MenuIndicatorElement,sizeObj), STR(MENUBUTTON_ARROW_SIZE)}, { "-arrowcolor",TK_OPTION_COLOR, - Tk_Offset(MenuIndicatorElement,colorObj), + offsetof(MenuIndicatorElement,colorObj), "black" }, { "-arrowpadding",TK_OPTION_STRING, - Tk_Offset(MenuIndicatorElement,paddingObj), + offsetof(MenuIndicatorElement,paddingObj), "3" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -469,7 +469,7 @@ static void MenuIndicatorElementDraw( TtkFillArrow(Tk_Display(tkwin), d, gc, b, ARROW_DOWN); } -static Ttk_ElementSpec MenuIndicatorElementSpec = +static const Ttk_ElementSpec MenuIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(MenuIndicatorElement), @@ -484,23 +484,19 @@ static Ttk_ElementSpec MenuIndicatorElementSpec = * TODO: factor this with ThumbElementDraw */ -static Ttk_Orient GripClientData[] = { - TTK_ORIENT_HORIZONTAL, TTK_ORIENT_VERTICAL -}; - typedef struct { Tcl_Obj *lightColorObj; Tcl_Obj *borderColorObj; Tcl_Obj *gripCountObj; } GripElement; -static Ttk_ElementOptionSpec GripElementOptions[] = { +static const Ttk_ElementOptionSpec GripElementOptions[] = { { "-lightcolor", TK_OPTION_COLOR, - Tk_Offset(GripElement,lightColorObj), LIGHT_COLOR }, + offsetof(GripElement,lightColorObj), LIGHT_COLOR }, { "-bordercolor", TK_OPTION_COLOR, - Tk_Offset(GripElement,borderColorObj), DARKEST_COLOR }, + offsetof(GripElement,borderColorObj), DARKEST_COLOR }, { "-gripcount", TK_OPTION_INT, - Tk_Offset(GripElement,gripCountObj), "5" }, + offsetof(GripElement,gripCountObj), "5" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -508,14 +504,14 @@ static void GripElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData); GripElement *grip = (GripElement *)elementRecord; int gripCount = 0; (void)tkwin; (void)paddingPtr; Tcl_GetIntFromObj(NULL, grip->gripCountObj, &gripCount); - if (horizontal) { + if (orient == TTK_ORIENT_HORIZONTAL) { *widthPtr = 2*gripCount; } else { *heightPtr = 2*gripCount; @@ -527,16 +523,17 @@ static void GripElementDraw( Drawable d, Ttk_Box b, unsigned state) { const int w = WIN32_XDRAWLINE_HACK; - int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData); GripElement *grip = (GripElement *)elementRecord; GC lightGC = Ttk_GCForColor(tkwin,grip->lightColorObj,d); GC darkGC = Ttk_GCForColor(tkwin,grip->borderColorObj,d); int gripPad = 1, gripCount = 0; int i; + (void)state; Tcl_GetIntFromObj(NULL, grip->gripCountObj, &gripCount); - if (horizontal) { + if (orient == TTK_ORIENT_HORIZONTAL) { int x = b.x + b.width / 2 - gripCount; int y1 = b.y + gripPad, y2 = b.y + b.height - gripPad - 1 + w; for (i=0; i<gripCount; ++i) { @@ -553,7 +550,7 @@ static void GripElementDraw( } } -static Ttk_ElementSpec GripElementSpec = { +static const Ttk_ElementSpec GripElementSpec = { TK_STYLE_VERSION_2, sizeof(GripElement), GripElementOptions, @@ -581,27 +578,27 @@ typedef struct { /* Common element record for scrollbar elements */ Tcl_Obj *sliderlengthObj; } ScrollbarElement; -static Ttk_ElementOptionSpec ScrollbarElementOptions[] = { +static const Ttk_ElementOptionSpec ScrollbarElementOptions[] = { { "-orient", TK_OPTION_ANY, - Tk_Offset(ScrollbarElement, orientObj), "horizontal" }, + offsetof(ScrollbarElement, orientObj), "horizontal" }, { "-background", TK_OPTION_BORDER, - Tk_Offset(ScrollbarElement,backgroundObj), FRAME_COLOR }, + offsetof(ScrollbarElement,backgroundObj), FRAME_COLOR }, { "-bordercolor", TK_OPTION_COLOR, - Tk_Offset(ScrollbarElement,borderColorObj), DARKEST_COLOR }, + offsetof(ScrollbarElement,borderColorObj), DARKEST_COLOR }, { "-troughcolor", TK_OPTION_COLOR, - Tk_Offset(ScrollbarElement,troughColorObj), DARKER_COLOR }, + offsetof(ScrollbarElement,troughColorObj), DARKER_COLOR }, { "-lightcolor", TK_OPTION_COLOR, - Tk_Offset(ScrollbarElement,lightColorObj), LIGHT_COLOR }, + offsetof(ScrollbarElement,lightColorObj), LIGHT_COLOR }, { "-darkcolor", TK_OPTION_COLOR, - Tk_Offset(ScrollbarElement,darkColorObj), DARK_COLOR }, + offsetof(ScrollbarElement,darkColorObj), DARK_COLOR }, { "-arrowcolor", TK_OPTION_COLOR, - Tk_Offset(ScrollbarElement,arrowColorObj), "#000000" }, + offsetof(ScrollbarElement,arrowColorObj), "#000000" }, { "-arrowsize", TK_OPTION_PIXELS, - Tk_Offset(ScrollbarElement,arrowSizeObj), STR(SCROLLBAR_THICKNESS) }, + offsetof(ScrollbarElement,arrowSizeObj), STR(SCROLLBAR_THICKNESS) }, { "-gripcount", TK_OPTION_INT, - Tk_Offset(ScrollbarElement,gripCountObj), "5" }, + offsetof(ScrollbarElement,gripCountObj), "5" }, { "-sliderlength", TK_OPTION_INT, - Tk_Offset(ScrollbarElement,sliderlengthObj), "30" }, + offsetof(ScrollbarElement,sliderlengthObj), "30" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -619,7 +616,7 @@ static void TroughElementDraw( XDrawRectangle(Tk_Display(tkwin), d, gcb, b.x, b.y, b.width-1, b.height-1); } -static Ttk_ElementSpec TroughElementSpec = { +static const Ttk_ElementSpec TroughElementSpec = { TK_STYLE_VERSION_2, sizeof(ScrollbarElement), ScrollbarElementOptions, @@ -647,7 +644,7 @@ static void ThumbElementDraw( { ScrollbarElement *sb = (ScrollbarElement *)elementRecord; int gripCount = 0; - int orient = TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = TTK_ORIENT_HORIZONTAL; GC lightGC, darkGC; int x1, y1, x2, y2, dx, dy, i; const int w = WIN32_XDRAWLINE_HACK; @@ -663,7 +660,7 @@ static void ThumbElementDraw( /* * Draw grip: */ - Ttk_GetOrientFromObj(NULL, sb->orientObj, &orient); + TtkGetOrientFromObj(NULL, sb->orientObj, &orient); Tcl_GetIntFromObj(NULL, sb->gripCountObj, &gripCount); lightGC = Ttk_GCForColor(tkwin,sb->lightColorObj,d); darkGC = Ttk_GCForColor(tkwin,sb->borderColorObj,d); @@ -688,7 +685,7 @@ static void ThumbElementDraw( } } -static Ttk_ElementSpec ThumbElementSpec = { +static const Ttk_ElementSpec ThumbElementSpec = { TK_STYLE_VERSION_2, sizeof(ScrollbarElement), ScrollbarElementOptions, @@ -705,12 +702,12 @@ static void SliderElementSize( { ScrollbarElement *sb = (ScrollbarElement *)elementRecord; int length, thickness; - int orient; + Ttk_Orient orient; (void)dummy; (void)paddingPtr; length = thickness = SCROLLBAR_THICKNESS; - Ttk_GetOrientFromObj(NULL, sb->orientObj, &orient); + TtkGetOrientFromObj(NULL, sb->orientObj, &orient); Tcl_GetIntFromObj(NULL, sb->arrowSizeObj, &thickness); Tk_GetPixelsFromObj(NULL, tkwin, sb->sliderlengthObj, &length); if (orient == TTK_ORIENT_VERTICAL) { @@ -723,7 +720,7 @@ static void SliderElementSize( } -static Ttk_ElementSpec SliderElementSpec = { +static const Ttk_ElementSpec SliderElementSpec = { TK_STYLE_VERSION_2, sizeof(ScrollbarElement), ScrollbarElementOptions, @@ -763,7 +760,7 @@ static void PbarElementDraw( } } -static Ttk_ElementSpec PbarElementSpec = { +static const Ttk_ElementSpec PbarElementSpec = { TK_STYLE_VERSION_2, sizeof(ScrollbarElement), ScrollbarElementOptions, @@ -775,8 +772,6 @@ static Ttk_ElementSpec PbarElementSpec = { /*------------------------------------------------------------------------ * +++ Scrollbar arrows. */ -static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT }; - static void ArrowElementSize( void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) @@ -795,10 +790,11 @@ static void ArrowElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned state) { - ArrowDirection direction = *(ArrowDirection*)clientData; + ArrowDirection direction = (ArrowDirection)PTR2INT(clientData); ScrollbarElement *sb = (ScrollbarElement *)elementRecord; GC gc = Ttk_GCForColor(tkwin,sb->arrowColorObj, d); int h, cx, cy; + (void)state; DrawSmoothBorder(tkwin, d, b, sb->borderColorObj, sb->lightColorObj, sb->darkColorObj); @@ -815,7 +811,7 @@ static void ArrowElementDraw( TtkFillArrow(Tk_Display(tkwin), d, gc, b, direction); } -static Ttk_ElementSpec ArrowElementSpec = { +static const Ttk_ElementSpec ArrowElementSpec = { TK_STYLE_VERSION_2, sizeof(ScrollbarElement), ScrollbarElementOptions, @@ -838,15 +834,15 @@ typedef struct { Tcl_Obj *darkColorObj; } NotebookElement; -static Ttk_ElementOptionSpec NotebookElementOptions[] = { +static const Ttk_ElementOptionSpec NotebookElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(NotebookElement,backgroundObj), FRAME_COLOR }, + offsetof(NotebookElement,backgroundObj), FRAME_COLOR }, { "-bordercolor", TK_OPTION_COLOR, - Tk_Offset(NotebookElement,borderColorObj), DARKEST_COLOR }, + offsetof(NotebookElement,borderColorObj), DARKEST_COLOR }, { "-lightcolor", TK_OPTION_COLOR, - Tk_Offset(NotebookElement,lightColorObj), LIGHT_COLOR }, + offsetof(NotebookElement,lightColorObj), LIGHT_COLOR }, { "-darkcolor", TK_OPTION_COLOR, - Tk_Offset(NotebookElement,darkColorObj), DARK_COLOR }, + offsetof(NotebookElement,darkColorObj), DARK_COLOR }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -903,7 +899,7 @@ static void TabElementDraw( XDrawLine(display,d,gc, x1+1,y1+1, x2-1+w,y1+1); } -static Ttk_ElementSpec TabElementSpec = +static const Ttk_ElementSpec TabElementSpec = { TK_STYLE_VERSION_2, sizeof(NotebookElement), @@ -942,7 +938,7 @@ static void ClientElementDraw( ce->borderColorObj, ce->lightColorObj, ce->darkColorObj); } -static Ttk_ElementSpec ClientElementSpec = +static const Ttk_ElementSpec ClientElementSpec = { TK_STYLE_VERSION_2, sizeof(NotebookElement), @@ -997,13 +993,13 @@ TtkClamTheme_Init(Tcl_Interp *interp) Ttk_RegisterElement(interp, theme, "thumb", &ThumbElementSpec, NULL); Ttk_RegisterElement(interp, - theme, "uparrow", &ArrowElementSpec, &ArrowElements[0]); + theme, "uparrow", &ArrowElementSpec, INT2PTR(ARROW_UP)); Ttk_RegisterElement(interp, - theme, "downarrow", &ArrowElementSpec, &ArrowElements[1]); + theme, "downarrow", &ArrowElementSpec, INT2PTR(ARROW_DOWN)); Ttk_RegisterElement(interp, - theme, "leftarrow", &ArrowElementSpec, &ArrowElements[2]); + theme, "leftarrow", &ArrowElementSpec, INT2PTR(ARROW_LEFT)); Ttk_RegisterElement(interp, - theme, "rightarrow", &ArrowElementSpec, &ArrowElements[3]); + theme, "rightarrow", &ArrowElementSpec, INT2PTR(ARROW_RIGHT)); Ttk_RegisterElement(interp, theme, "Radiobutton.indicator", &RadioIndicatorElementSpec, NULL); @@ -1020,9 +1016,9 @@ TtkClamTheme_Init(Tcl_Interp *interp) Ttk_RegisterElement(interp, theme, "pbar", &PbarElementSpec, NULL); Ttk_RegisterElement(interp, theme, "hgrip", - &GripElementSpec, &GripClientData[0]); + &GripElementSpec, INT2PTR(TTK_ORIENT_HORIZONTAL)); Ttk_RegisterElement(interp, theme, "vgrip", - &GripElementSpec, &GripClientData[1]); + &GripElementSpec, INT2PTR(TTK_ORIENT_VERTICAL)); Ttk_RegisterLayouts(theme, LayoutTable); diff --git a/generic/ttk/ttkClassicTheme.c b/generic/ttk/ttkClassicTheme.c index 8436aec..be7d74b 100644 --- a/generic/ttk/ttkClassicTheme.c +++ b/generic/ttk/ttkClassicTheme.c @@ -21,11 +21,11 @@ typedef struct { Tcl_Obj *highlightThicknessObj; } HighlightElement; -static Ttk_ElementOptionSpec HighlightElementOptions[] = { +static const Ttk_ElementOptionSpec HighlightElementOptions[] = { { "-highlightcolor",TK_OPTION_COLOR, - Tk_Offset(HighlightElement,highlightColorObj), DEFAULT_BACKGROUND }, + offsetof(HighlightElement,highlightColorObj), DEFAULT_BACKGROUND }, { "-highlightthickness",TK_OPTION_PIXELS, - Tk_Offset(HighlightElement,highlightThicknessObj), "0" }, + offsetof(HighlightElement,highlightThicknessObj), "0" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -62,7 +62,7 @@ static void HighlightElementDraw( } } -static Ttk_ElementSpec HighlightElementSpec = +static const Ttk_ElementSpec HighlightElementSpec = { TK_STYLE_VERSION_2, sizeof(HighlightElement), @@ -88,16 +88,16 @@ typedef struct { Tcl_Obj *defaultStateObj; } ButtonBorderElement; -static Ttk_ElementOptionSpec ButtonBorderElementOptions[] = +static const Ttk_ElementOptionSpec ButtonBorderElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(ButtonBorderElement,borderObj), DEFAULT_BACKGROUND }, + offsetof(ButtonBorderElement,borderObj), DEFAULT_BACKGROUND }, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(ButtonBorderElement,borderWidthObj), DEFAULT_BORDERWIDTH }, + offsetof(ButtonBorderElement,borderWidthObj), DEFAULT_BORDERWIDTH }, { "-relief", TK_OPTION_RELIEF, - Tk_Offset(ButtonBorderElement,reliefObj), "flat" }, + offsetof(ButtonBorderElement,reliefObj), "flat" }, { "-default", TK_OPTION_ANY, - Tk_Offset(ButtonBorderElement,defaultStateObj), "disabled" }, + offsetof(ButtonBorderElement,defaultStateObj), "disabled" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -106,7 +106,7 @@ static void ButtonBorderElementSize( int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { ButtonBorderElement *bd = (ButtonBorderElement *)elementRecord; - int defaultState = TTK_BUTTON_DEFAULT_DISABLED; + Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED; int borderWidth = 0; (void)dummy; (void)tkwin; @@ -134,7 +134,7 @@ static void ButtonBorderElementDraw( ButtonBorderElement *bd = (ButtonBorderElement *)elementRecord; Tk_3DBorder border = NULL; int borderWidth = 1, relief = TK_RELIEF_FLAT; - int defaultState = TTK_BUTTON_DEFAULT_DISABLED; + Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED; int inset = 0; (void)dummy; (void)state; @@ -183,7 +183,7 @@ static void ButtonBorderElementDraw( } } -static Ttk_ElementSpec ButtonBorderElementSpec = +static const Ttk_ElementSpec ButtonBorderElementSpec = { TK_STYLE_VERSION_2, sizeof(ButtonBorderElement), @@ -199,7 +199,6 @@ static Ttk_ElementSpec ButtonBorderElementSpec = * clientData is an enum ArrowDirection pointer. */ -static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT }; typedef struct { Tcl_Obj *sizeObj; @@ -208,15 +207,15 @@ typedef struct Tcl_Obj *reliefObj; } ArrowElement; -static Ttk_ElementOptionSpec ArrowElementOptions[] = +static const Ttk_ElementOptionSpec ArrowElementOptions[] = { - { "-arrowsize", TK_OPTION_PIXELS, Tk_Offset(ArrowElement,sizeObj), + { "-arrowsize", TK_OPTION_PIXELS, offsetof(ArrowElement,sizeObj), DEFAULT_ARROW_SIZE }, - { "-background", TK_OPTION_BORDER, Tk_Offset(ArrowElement,borderObj), + { "-background", TK_OPTION_BORDER, offsetof(ArrowElement,borderObj), DEFAULT_BACKGROUND }, - { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(ArrowElement,borderWidthObj), + { "-borderwidth", TK_OPTION_PIXELS, offsetof(ArrowElement,borderWidthObj), DEFAULT_BORDERWIDTH }, - { "-relief", TK_OPTION_RELIEF, Tk_Offset(ArrowElement,reliefObj),"raised" }, + { "-relief", TK_OPTION_RELIEF, offsetof(ArrowElement,reliefObj),"raised" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -237,7 +236,7 @@ static void ArrowElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - int direction = *(int *)clientData; + ArrowDirection direction = (ArrowDirection)PTR2INT(clientData); ArrowElement *arrow = (ArrowElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj); int borderWidth = 2; @@ -282,7 +281,7 @@ static void ArrowElementDraw( Tk_Fill3DPolygon(tkwin, d, border, points, 3, borderWidth, relief); } -static Ttk_ElementSpec ArrowElementSpec = +static const Ttk_ElementSpec ArrowElementSpec = { TK_STYLE_VERSION_2, sizeof(ArrowElement), @@ -306,10 +305,6 @@ static Ttk_ElementSpec ArrowElementSpec = * -sashrelief raised, but that looks wrong to me. */ -static Ttk_Orient SashClientData[] = { - TTK_ORIENT_HORIZONTAL, TTK_ORIENT_VERTICAL -}; - typedef struct { Tcl_Obj *borderObj; /* background color */ Tcl_Obj *sashReliefObj; /* sash relief */ @@ -319,19 +314,19 @@ typedef struct { Tcl_Obj *handlePadObj; /* handle's distance from edge */ } SashElement; -static Ttk_ElementOptionSpec SashOptions[] = { +static const Ttk_ElementOptionSpec SashOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(SashElement,borderObj), DEFAULT_BACKGROUND }, + offsetof(SashElement,borderObj), DEFAULT_BACKGROUND }, { "-sashrelief", TK_OPTION_RELIEF, - Tk_Offset(SashElement,sashReliefObj), "sunken" }, + offsetof(SashElement,sashReliefObj), "sunken" }, { "-sashthickness", TK_OPTION_PIXELS, - Tk_Offset(SashElement,sashThicknessObj), "6" }, + offsetof(SashElement,sashThicknessObj), "6" }, { "-sashpad", TK_OPTION_PIXELS, - Tk_Offset(SashElement,sashPadObj), "2" }, + offsetof(SashElement,sashPadObj), "2" }, { "-handlesize", TK_OPTION_PIXELS, - Tk_Offset(SashElement,handleSizeObj), "8" }, + offsetof(SashElement,handleSizeObj), "8" }, { "-handlepad", TK_OPTION_PIXELS, - Tk_Offset(SashElement,handlePadObj), "8" }, + offsetof(SashElement,handlePadObj), "8" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -341,7 +336,8 @@ static void SashElementSize( { SashElement *sash = (SashElement *)elementRecord; int sashPad = 2, sashThickness = 6, handleSize = 8; - int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData); + (void)paddingPtr; (void)paddingPtr; Tk_GetPixelsFromObj(NULL, tkwin, sash->sashThicknessObj, &sashThickness); @@ -351,7 +347,7 @@ static void SashElementSize( if (sashThickness < handleSize + 2*sashPad) sashThickness = handleSize + 2*sashPad; - if (horizontal) + if (orient == TTK_ORIENT_HORIZONTAL) *heightPtr = sashThickness; else *widthPtr = sashThickness; @@ -366,7 +362,7 @@ static void SashElementDraw( GC gc1,gc2; int relief = TK_RELIEF_RAISED; int handleSize = 8, handlePad = 8; - int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData); Ttk_Box hb; (void)state; @@ -394,7 +390,7 @@ static void SashElementDraw( /* Draw sash line: */ - if (horizontal) { + if (orient == TTK_ORIENT_HORIZONTAL) { int y = b.y + b.height/2 - 1; XDrawLine(Tk_Display(tkwin), d, gc1, b.x, y, b.x+b.width, y); ++y; XDrawLine(Tk_Display(tkwin), d, gc2, b.x, y, b.x+b.width, y); @@ -407,7 +403,7 @@ static void SashElementDraw( /* Draw handle: */ if (handleSize >= 0) { - if (horizontal) { + if (orient == TTK_ORIENT_HORIZONTAL) { hb = Ttk_StickBox(b, handleSize, handleSize, TTK_STICK_W); hb.x += handlePad; } else { @@ -419,7 +415,7 @@ static void SashElementDraw( } } -static Ttk_ElementSpec SashElementSpec = { +static const Ttk_ElementSpec SashElementSpec = { TK_STYLE_VERSION_2, sizeof(SashElement), SashOptions, @@ -501,20 +497,20 @@ MODULE_SCOPE int TtkClassicTheme_Init(Tcl_Interp *interp) &ButtonBorderElementSpec, NULL); Ttk_RegisterElement(interp, theme, "uparrow", - &ArrowElementSpec, &ArrowElements[0]); + &ArrowElementSpec, INT2PTR(ARROW_UP)); Ttk_RegisterElement(interp, theme, "downarrow", - &ArrowElementSpec, &ArrowElements[1]); + &ArrowElementSpec, INT2PTR(ARROW_DOWN)); Ttk_RegisterElement(interp, theme, "leftarrow", - &ArrowElementSpec, &ArrowElements[2]); + &ArrowElementSpec, INT2PTR(ARROW_LEFT)); Ttk_RegisterElement(interp, theme, "rightarrow", - &ArrowElementSpec, &ArrowElements[3]); + &ArrowElementSpec, INT2PTR(ARROW_RIGHT)); Ttk_RegisterElement(interp, theme, "arrow", - &ArrowElementSpec, &ArrowElements[0]); + &ArrowElementSpec, INT2PTR(ARROW_UP)); Ttk_RegisterElement(interp, theme, "hsash", - &SashElementSpec, &SashClientData[0]); + &SashElementSpec, INT2PTR(TTK_ORIENT_HORIZONTAL)); Ttk_RegisterElement(interp, theme, "vsash", - &SashElementSpec, &SashClientData[1]); + &SashElementSpec, INT2PTR(TTK_ORIENT_VERTICAL)); /* * Register layouts: diff --git a/generic/ttk/ttkDecls.h b/generic/ttk/ttkDecls.h index 6701724..5f76634 100644 --- a/generic/ttk/ttkDecls.h +++ b/generic/ttk/ttkDecls.h @@ -17,6 +17,15 @@ extern const char *TtkInitializeStubs( #endif +#if !defined(BUILD_tk) +# define TTK_DEPRECATED(msg) TTKAPI TCL_DEPRECATED_API(msg) +#elif defined(TK_NO_DEPRECATED) +# define TTK_DEPRECATED(msg) MODULE_SCOPE +#else +# define TTK_DEPRECATED(msg) TTKAPI +#endif + + /* !BEGIN!: Do not edit below this line. */ @@ -47,12 +56,12 @@ TTKAPI void Ttk_RegisterCleanup(Tcl_Interp *interp, /* 5 */ TTKAPI int Ttk_RegisterElementSpec(Ttk_Theme theme, const char *elementName, - Ttk_ElementSpec *elementSpec, + const Ttk_ElementSpec *elementSpec, void *clientData); /* 6 */ TTKAPI Ttk_ElementClass * Ttk_RegisterElement(Tcl_Interp *interp, Ttk_Theme theme, const char *elementName, - Ttk_ElementSpec *elementSpec, + const Ttk_ElementSpec *elementSpec, void *clientData); /* 7 */ TTKAPI int Ttk_RegisterElementFactory(Tcl_Interp *interp, @@ -77,7 +86,7 @@ TTKAPI Ttk_StateMap Ttk_GetStateMapFromObj(Tcl_Interp *interp, TTKAPI Tcl_Obj * Ttk_StateMapLookup(Tcl_Interp *interp, Ttk_StateMap map, Ttk_State state); /* 14 */ -TTKAPI int Ttk_StateTableLookup(Ttk_StateTable map[], +TTKAPI int Ttk_StateTableLookup(const Ttk_StateTable *map, Ttk_State state); /* Slot 15 is reserved */ /* Slot 16 is reserved */ @@ -130,7 +139,8 @@ TTKAPI Tcl_Obj * Ttk_NewBoxObj(Ttk_Box box); /* Slot 38 is reserved */ /* Slot 39 is reserved */ /* 40 */ -TTKAPI int Ttk_GetOrientFromObj(Tcl_Interp *interp, +TTK_DEPRECATED("") +int Ttk_GetOrientFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *orient); typedef struct TtkStubs { @@ -144,8 +154,8 @@ typedef struct TtkStubs { Ttk_Theme (*ttk_GetCurrentTheme) (Tcl_Interp *interp); /* 2 */ Ttk_Theme (*ttk_CreateTheme) (Tcl_Interp *interp, const char *name, Ttk_Theme parent); /* 3 */ void (*ttk_RegisterCleanup) (Tcl_Interp *interp, void *deleteData, Ttk_CleanupProc *cleanupProc); /* 4 */ - int (*ttk_RegisterElementSpec) (Ttk_Theme theme, const char *elementName, Ttk_ElementSpec *elementSpec, void *clientData); /* 5 */ - Ttk_ElementClass * (*ttk_RegisterElement) (Tcl_Interp *interp, Ttk_Theme theme, const char *elementName, Ttk_ElementSpec *elementSpec, void *clientData); /* 6 */ + int (*ttk_RegisterElementSpec) (Ttk_Theme theme, const char *elementName, const Ttk_ElementSpec *elementSpec, void *clientData); /* 5 */ + Ttk_ElementClass * (*ttk_RegisterElement) (Tcl_Interp *interp, Ttk_Theme theme, const char *elementName, const Ttk_ElementSpec *elementSpec, void *clientData); /* 6 */ int (*ttk_RegisterElementFactory) (Tcl_Interp *interp, const char *name, Ttk_ElementFactory factoryProc, void *clientData); /* 7 */ void (*ttk_RegisterLayout) (Ttk_Theme theme, const char *className, Ttk_LayoutSpec layoutSpec); /* 8 */ void (*reserved9)(void); @@ -153,7 +163,7 @@ typedef struct TtkStubs { Tcl_Obj * (*ttk_NewStateSpecObj) (unsigned int onbits, unsigned int offbits); /* 11 */ Ttk_StateMap (*ttk_GetStateMapFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr); /* 12 */ Tcl_Obj * (*ttk_StateMapLookup) (Tcl_Interp *interp, Ttk_StateMap map, Ttk_State state); /* 13 */ - int (*ttk_StateTableLookup) (Ttk_StateTable map[], Ttk_State state); /* 14 */ + int (*ttk_StateTableLookup) (const Ttk_StateTable *map, Ttk_State state); /* 14 */ void (*reserved15)(void); void (*reserved16)(void); void (*reserved17)(void); @@ -179,7 +189,7 @@ typedef struct TtkStubs { void (*reserved37)(void); void (*reserved38)(void); void (*reserved39)(void); - int (*ttk_GetOrientFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int *orient); /* 40 */ + TCL_DEPRECATED_API("") int (*ttk_GetOrientFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int *orient); /* 40 */ } TtkStubs; extern const TtkStubs *ttkStubsPtr; diff --git a/generic/ttk/ttkDefaultTheme.c b/generic/ttk/ttkDefaultTheme.c index 89bf028..a614894 100644 --- a/generic/ttk/ttkDefaultTheme.c +++ b/generic/ttk/ttkDefaultTheme.c @@ -37,7 +37,7 @@ static const int WIN32_XDRAWLINE_HACK = 0; enum BorderColor { FLAT = 1, LITE = 2, DARK = 3, BRDR = 4 }; /* top-left outer, top-left inner, bottom-right inner, bottom-right outer */ -static int const shadowColors[6][4] = { +static const enum BorderColor shadowColors[6][4] = { { FLAT, FLAT, FLAT, FLAT }, /* TK_RELIEF_FLAT = 0*/ { DARK, LITE, DARK, LITE }, /* TK_RELIEF_GROOVE = 1*/ { LITE, FLAT, DARK, BRDR }, /* TK_RELIEF_RAISED = 2*/ @@ -47,7 +47,7 @@ static int const shadowColors[6][4] = { }; /* top-left, bottom-right */ -static int const thinShadowColors[6][4] = { +static const enum BorderColor thinShadowColors[6][4] = { { FLAT, FLAT }, /* TK_RELIEF_FLAT = 0*/ { DARK, LITE }, /* TK_RELIEF_GROOVE = 1*/ { LITE, DARK }, /* TK_RELIEF_RAISED = 2*/ @@ -116,21 +116,19 @@ static void DrawBorder( /* Alternate shadow colors for entry fields: * NOTE: FLAT color is normally white, and the LITE color is a darker shade. */ -static int fieldShadowColors[4] = { DARK, BRDR, LITE, FLAT }; - static void DrawFieldBorder( Tk_Window tkwin, Drawable d, Tk_3DBorder border, XColor *borderColor, Ttk_Box b) { GC borderGC = Tk_GCForColor(borderColor, d); DrawCorner(tkwin, d, border, borderGC, - b.x, b.y, b.width, b.height, 0,fieldShadowColors[0]); + b.x, b.y, b.width, b.height, 0, DARK); DrawCorner(tkwin, d, border, borderGC, - b.x+1, b.y+1, b.width-2, b.height-2, 0,fieldShadowColors[1]); + b.x+1, b.y+1, b.width-2, b.height-2, 0, BRDR); DrawCorner(tkwin, d, border, borderGC, - b.x+1, b.y+1, b.width-2, b.height-2, 1,fieldShadowColors[2]); + b.x+1, b.y+1, b.width-2, b.height-2, 1, LITE); DrawCorner(tkwin, d, border, borderGC, - b.x, b.y, b.width, b.height, 1,fieldShadowColors[3]); + b.x, b.y, b.width, b.height, 1, FLAT); return; } @@ -138,11 +136,11 @@ static void DrawFieldBorder( * ArrowPoints -- * Compute points of arrow polygon. */ -static void ArrowPoints(Ttk_Box b, ArrowDirection dir, XPoint points[4]) +static void ArrowPoints(Ttk_Box b, ArrowDirection direction, XPoint points[4]) { int cx, cy, h; - switch (dir) { + switch (direction) { case ARROW_UP: h = (b.width - 1)/2; cx = b.x + h; @@ -186,9 +184,9 @@ static void ArrowPoints(Ttk_Box b, ArrowDirection dir, XPoint points[4]) } /*public*/ -void TtkArrowSize(int h, ArrowDirection dir, int *widthPtr, int *heightPtr) +void TtkArrowSize(int h, ArrowDirection direction, int *widthPtr, int *heightPtr) { - switch (dir) { + switch (direction) { case ARROW_UP: case ARROW_DOWN: *widthPtr = 2*h+1; *heightPtr = h+1; break; case ARROW_LEFT: @@ -202,10 +200,10 @@ void TtkArrowSize(int h, ArrowDirection dir, int *widthPtr, int *heightPtr) */ /*public*/ void TtkFillArrow( - Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection dir) + Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection direction) { XPoint points[4]; - ArrowPoints(b, dir, points); + ArrowPoints(b, direction, points); XFillPolygon(display, d, gc, points, 3, Convex, CoordModeOrigin); XDrawLines(display, d, gc, points, 4, CoordModeOrigin); @@ -215,10 +213,10 @@ void TtkFillArrow( /*public*/ void TtkDrawArrow( - Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection dir) + Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection direction) { XPoint points[4]; - ArrowPoints(b, dir, points); + ArrowPoints(b, direction, points); XDrawLines(display, d, gc, points, 4, CoordModeOrigin); /* Work around bug [77527326e5] - ttk artifacts on Ubuntu */ @@ -244,27 +242,31 @@ typedef struct { Tcl_Obj *defaultStateObj; /* for buttons */ } BorderElement; -static Ttk_ElementOptionSpec BorderElementOptions[] = { - { "-background", TK_OPTION_BORDER, Tk_Offset(BorderElement,borderObj), +static const Ttk_ElementOptionSpec BorderElementOptions[] = { + { "-background", TK_OPTION_BORDER, offsetof(BorderElement,borderObj), DEFAULT_BACKGROUND }, { "-bordercolor",TK_OPTION_COLOR, - Tk_Offset(BorderElement,borderColorObj), "black" }, - { "-default", TK_OPTION_ANY, Tk_Offset(BorderElement,defaultStateObj), + offsetof(BorderElement,borderColorObj), "black" }, + { "-default", TK_OPTION_ANY, offsetof(BorderElement,defaultStateObj), "disabled" }, - { "-borderwidth",TK_OPTION_PIXELS,Tk_Offset(BorderElement,borderWidthObj), + { "-borderwidth",TK_OPTION_PIXELS, offsetof(BorderElement,borderWidthObj), STRINGIFY(BORDERWIDTH) }, - { "-relief", TK_OPTION_RELIEF, Tk_Offset(BorderElement,reliefObj), + { "-relief", TK_OPTION_RELIEF, offsetof(BorderElement,reliefObj), "flat" }, - { NULL, 0, 0, NULL } + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void BorderElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - BorderElement *bd = elementRecord; + BorderElement *bd = (BorderElement *)elementRecord; int borderWidth = 0; - int defaultState = TTK_BUTTON_DEFAULT_DISABLED; + Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED; + (void)dummy; + (void)tkwin; + (void)widthPtr; + (void)heightPtr; Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth); Ttk_GetButtonDefaultStateFromObj(NULL, bd->defaultStateObj, &defaultState); @@ -277,15 +279,17 @@ static void BorderElementSize( } static void BorderElementDraw( - void *clientData, void *elementRecord, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - BorderElement *bd = elementRecord; + BorderElement *bd = (BorderElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, bd->borderObj); XColor *borderColor = Tk_GetColorFromObj(tkwin, bd->borderColorObj); int borderWidth = 2; int relief = TK_RELIEF_FLAT; - int defaultState = TTK_BUTTON_DEFAULT_DISABLED; + Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED; + (void)dummy; + (void)state; /* * Get option values. @@ -307,7 +311,7 @@ static void BorderElementDraw( DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief); } -static Ttk_ElementSpec BorderElementSpec = { +static const Ttk_ElementSpec BorderElementSpec = { TK_STYLE_VERSION_2, sizeof(BorderElement), BorderElementOptions, @@ -324,35 +328,43 @@ typedef struct { Tcl_Obj *borderColorObj; /* Extra border color */ } FieldElement; -static Ttk_ElementOptionSpec FieldElementOptions[] = { - { "-fieldbackground", TK_OPTION_BORDER, Tk_Offset(FieldElement,borderObj), +static const Ttk_ElementOptionSpec FieldElementOptions[] = { + { "-fieldbackground", TK_OPTION_BORDER, offsetof(FieldElement,borderObj), "white" }, - { "-bordercolor",TK_OPTION_COLOR, Tk_Offset(FieldElement,borderColorObj), + { "-bordercolor",TK_OPTION_COLOR, offsetof(FieldElement,borderColorObj), "black" }, - { NULL, 0, 0, NULL } + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void FieldElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { + (void)dummy; + (void)elementRecord; + (void)tkwin; + (void)widthPtr; + (void)heightPtr; + *paddingPtr = Ttk_UniformPadding(2); } static void FieldElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - FieldElement *field = elementRecord; + FieldElement *field = (FieldElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, field->borderObj); XColor *borderColor = Tk_GetColorFromObj(tkwin, field->borderColorObj); + (void)dummy; + (void)state; Tk_Fill3DRectangle( tkwin, d, border, b.x, b.y, b.width, b.height, 0, TK_RELIEF_SUNKEN); DrawFieldBorder(tkwin, d, border, borderColor, b); } -static Ttk_ElementSpec FieldElementSpec = { +static const Ttk_ElementSpec FieldElementSpec = { TK_STYLE_VERSION_2, sizeof(FieldElement), FieldElementOptions, @@ -375,7 +387,7 @@ typedef struct { int height; /* Height of each image */ int nimages; /* #images / row */ const char *const *pixels; /* array[height] of char[width*nimage] */ - Ttk_StateTable *map;/* used to look up image index by state */ + const Ttk_StateTable *map;/* used to look up image index by state */ } IndicatorSpec; #if 0 @@ -395,7 +407,7 @@ static const char *const button_images[] = { }; #endif -static Ttk_StateTable checkbutton_states[] = { +static const Ttk_StateTable checkbutton_states[] = { { 0, 0, TTK_STATE_SELECTED|TTK_STATE_DISABLED }, { 1, TTK_STATE_SELECTED, TTK_STATE_DISABLED }, { 2, TTK_STATE_DISABLED, TTK_STATE_SELECTED }, @@ -425,7 +437,7 @@ static IndicatorSpec checkbutton_spec = { checkbutton_states }; -static Ttk_StateTable radiobutton_states[] = { +static const Ttk_StateTable radiobutton_states[] = { { 0, 0, TTK_STATE_SELECTED|TTK_STATE_DISABLED }, { 1, TTK_STATE_SELECTED, TTK_STATE_DISABLED }, { 2, TTK_STATE_DISABLED, TTK_STATE_SELECTED }, @@ -465,31 +477,33 @@ typedef struct { Tcl_Obj *marginObj; } IndicatorElement; -static Ttk_ElementOptionSpec IndicatorElementOptions[] = { +static const Ttk_ElementOptionSpec IndicatorElementOptions[] = { { "-background", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND }, + offsetof(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND }, { "-foreground", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,foregroundObj), DEFAULT_FOREGROUND }, + offsetof(IndicatorElement,foregroundObj), DEFAULT_FOREGROUND }, { "-indicatorcolor", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,colorObj), "#FFFFFF" }, + offsetof(IndicatorElement,colorObj), "#FFFFFF" }, { "-lightcolor", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,lightColorObj), "#DDDDDD" }, + offsetof(IndicatorElement,lightColorObj), "#DDDDDD" }, { "-shadecolor", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,shadeColorObj), "#888888" }, + offsetof(IndicatorElement,shadeColorObj), "#888888" }, { "-bordercolor", TK_OPTION_COLOR, - Tk_Offset(IndicatorElement,borderColorObj), "black" }, + offsetof(IndicatorElement,borderColorObj), "black" }, { "-indicatormargin", TK_OPTION_STRING, - Tk_Offset(IndicatorElement,marginObj), "0 2 4 2" }, - { NULL, 0, 0, NULL } + offsetof(IndicatorElement,marginObj), "0 2 4 2" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void IndicatorElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - IndicatorSpec *spec = clientData; - IndicatorElement *indicator = elementRecord; + IndicatorSpec *spec = (IndicatorSpec *)clientData; + IndicatorElement *indicator = (IndicatorElement *)elementRecord; Ttk_Padding margins; + (void)paddingPtr; + Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins); *widthPtr = spec->width + Ttk_PaddingWidth(margins); *heightPtr = spec->height + Ttk_PaddingHeight(margins); @@ -499,8 +513,8 @@ static void IndicatorElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - IndicatorSpec *spec = clientData; - IndicatorElement *indicator = elementRecord; + IndicatorSpec *spec = (IndicatorSpec *)clientData; + IndicatorElement *indicator = (IndicatorElement *)elementRecord; Display *display = Tk_Display(tkwin); Ttk_Padding padding; XColor *fgColor, *frameColor, *shadeColor, *indicatorColor, *borderColor; @@ -579,7 +593,7 @@ static void IndicatorElementDraw( #if defined(IGNORES_VISUAL) - img->data = ckalloc(img->bytes_per_line * img->height); + img->data = (char *)ckalloc(img->bytes_per_line * img->height); if (img->data == NULL) { XDestroyImage(img); return; @@ -628,7 +642,7 @@ static void IndicatorElementDraw( XDestroyImage(img); } -static Ttk_ElementSpec IndicatorElementSpec = { +static const Ttk_ElementSpec IndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(IndicatorElement), IndicatorElementOptions, @@ -643,7 +657,6 @@ static Ttk_ElementSpec IndicatorElementSpec = { * clientData is an enum ArrowDirection pointer. */ -static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT }; typedef struct { Tcl_Obj *sizeObj; Tcl_Obj *borderObj; @@ -652,18 +665,18 @@ typedef struct { Tcl_Obj *colorObj; /* Arrow color */ } ArrowElement; -static Ttk_ElementOptionSpec ArrowElementOptions[] = { +static const Ttk_ElementOptionSpec ArrowElementOptions[] = { { "-arrowsize", TK_OPTION_PIXELS, - Tk_Offset(ArrowElement,sizeObj), STRINGIFY(SCROLLBAR_WIDTH) }, + offsetof(ArrowElement,sizeObj), STRINGIFY(SCROLLBAR_WIDTH) }, { "-background", TK_OPTION_BORDER, - Tk_Offset(ArrowElement,borderObj), DEFAULT_BACKGROUND }, + offsetof(ArrowElement,borderObj), DEFAULT_BACKGROUND }, { "-bordercolor", TK_OPTION_COLOR, - Tk_Offset(ArrowElement,borderColorObj), "black" }, + offsetof(ArrowElement,borderColorObj), "black" }, { "-relief", TK_OPTION_RELIEF, - Tk_Offset(ArrowElement,reliefObj),"raised"}, + offsetof(ArrowElement,reliefObj),"raised"}, { "-arrowcolor", TK_OPTION_COLOR, - Tk_Offset(ArrowElement,colorObj),"black"}, - { NULL, 0, 0, NULL } + offsetof(ArrowElement,colorObj),"black"}, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; /* @@ -671,15 +684,16 @@ static Ttk_ElementOptionSpec ArrowElementOptions[] = { * top/left padding is 1 less than bottom/right, * since in this theme 2-pixel borders are asymmetric. */ -static Ttk_Padding ArrowPadding = { 3,3,4,4 }; +static const Ttk_Padding ArrowPadding = { 3,3,4,4 }; static void ArrowElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ArrowElement *arrow = elementRecord; - int direction = *(int *)clientData; + ArrowElement *arrow = (ArrowElement *)elementRecord; + ArrowDirection direction = (ArrowDirection)PTR2INT(clientData); int width = SCROLLBAR_WIDTH; + (void)paddingPtr; Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &width); width -= Ttk_PaddingWidth(ArrowPadding); @@ -692,13 +706,14 @@ static void ArrowElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - int direction = *(int *)clientData; - ArrowElement *arrow = elementRecord; + ArrowDirection direction = (ArrowDirection)PTR2INT(clientData); + ArrowElement *arrow = (ArrowElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj); XColor *borderColor = Tk_GetColorFromObj(tkwin, arrow->borderColorObj); XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj); int relief = TK_RELIEF_RAISED; int borderWidth = 2; + (void)state; Tk_GetReliefFromObj(NULL, arrow->reliefObj, &relief); @@ -710,7 +725,7 @@ static void ArrowElementDraw( Ttk_PadBox(b, ArrowPadding), direction); } -static Ttk_ElementSpec ArrowElementSpec = { +static const Ttk_ElementSpec ArrowElementSpec = { TK_STYLE_VERSION_2, sizeof(ArrowElement), ArrowElementOptions, @@ -731,29 +746,32 @@ typedef struct { Tcl_Obj *colorObj; } MenubuttonArrowElement; -static const char *directionStrings[] = { /* See also: button.c */ +static const char *const directionStrings[] = { /* See also: button.c */ "above", "below", "left", "right", "flush", NULL }; enum { POST_ABOVE, POST_BELOW, POST_LEFT, POST_RIGHT, POST_FLUSH }; -static Ttk_ElementOptionSpec MenubuttonArrowElementOptions[] = { +static const Ttk_ElementOptionSpec MenubuttonArrowElementOptions[] = { { "-direction", TK_OPTION_STRING, - Tk_Offset(MenubuttonArrowElement,directionObj), "below" }, + offsetof(MenubuttonArrowElement,directionObj), "below" }, { "-arrowsize", TK_OPTION_PIXELS, - Tk_Offset(MenubuttonArrowElement,sizeObj), STRINGIFY(MENUBUTTON_ARROW_SIZE)}, + offsetof(MenubuttonArrowElement,sizeObj), STRINGIFY(MENUBUTTON_ARROW_SIZE)}, { "-arrowcolor",TK_OPTION_COLOR, - Tk_Offset(MenubuttonArrowElement,colorObj), "black"}, - { NULL, 0, 0, NULL } + offsetof(MenubuttonArrowElement,colorObj), "black"}, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; -static Ttk_Padding MenubuttonArrowPadding = { 3, 0, 3, 0 }; +static const Ttk_Padding MenubuttonArrowPadding = { 3, 0, 3, 0 }; static void MenubuttonArrowElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - MenubuttonArrowElement *arrow = elementRecord; + MenubuttonArrowElement *arrow = (MenubuttonArrowElement *)elementRecord; int size = MENUBUTTON_ARROW_SIZE; + (void)dummy; + (void)paddingPtr; + Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size); *widthPtr = *heightPtr = 2 * size + 1; *widthPtr += Ttk_PaddingWidth(MenubuttonArrowPadding); @@ -761,16 +779,18 @@ static void MenubuttonArrowElementSize( } static void MenubuttonArrowElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - MenubuttonArrowElement *arrow = elementRecord; + MenubuttonArrowElement *arrow = (MenubuttonArrowElement *)elementRecord; XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj); GC gc = Tk_GCForColor(arrowColor, d); int size = MENUBUTTON_ARROW_SIZE; int postDirection = POST_BELOW; ArrowDirection arrowDirection = ARROW_DOWN; int width = 0, height = 0; + (void)dummy; + (void)state; Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size); Tcl_GetIndexFromObjStruct(NULL, arrow->directionObj, directionStrings, @@ -791,7 +811,7 @@ static void MenubuttonArrowElementDraw( TtkFillArrow(Tk_Display(tkwin), d, gc, b, arrowDirection); } -static Ttk_ElementSpec MenubuttonArrowElementSpec = { +static const Ttk_ElementSpec MenubuttonArrowElementSpec = { TK_STYLE_VERSION_2, sizeof(MenubuttonArrowElement), MenubuttonArrowElementOptions, @@ -820,26 +840,29 @@ typedef struct { Tcl_Obj *orientObj; } TroughElement; -static Ttk_ElementOptionSpec TroughElementOptions[] = { +static const Ttk_ElementOptionSpec TroughElementOptions[] = { { "-orient", TK_OPTION_ANY, - Tk_Offset(TroughElement, orientObj), "horizontal" }, + offsetof(TroughElement, orientObj), "horizontal" }, { "-troughborderwidth", TK_OPTION_PIXELS, - Tk_Offset(TroughElement,borderWidthObj), "1" }, + offsetof(TroughElement,borderWidthObj), "1" }, { "-troughcolor", TK_OPTION_BORDER, - Tk_Offset(TroughElement,colorObj), DEFAULT_BACKGROUND }, + offsetof(TroughElement,colorObj), DEFAULT_BACKGROUND }, { "-troughrelief",TK_OPTION_RELIEF, - Tk_Offset(TroughElement,reliefObj), "sunken" }, + offsetof(TroughElement,reliefObj), "sunken" }, { "-groovewidth", TK_OPTION_PIXELS, - Tk_Offset(TroughElement,grooveWidthObj), "-1" }, - { NULL, 0, 0, NULL } + offsetof(TroughElement,grooveWidthObj), "-1" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void TroughElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - TroughElement *troughPtr = elementRecord; + TroughElement *troughPtr = (TroughElement *)elementRecord; int borderWidth = 2, grooveWidth = 0; + (void)dummy; + (void)widthPtr; + (void)heightPtr; Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth); Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->grooveWidthObj, &grooveWidth); @@ -850,15 +873,18 @@ static void TroughElementSize( } static void TroughElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - TroughElement *troughPtr = elementRecord; + TroughElement *troughPtr = (TroughElement *)elementRecord; Tk_3DBorder border = NULL; - int borderWidth = 2, relief = TK_RELIEF_SUNKEN, groove = -1, orient; + int borderWidth = 2, relief = TK_RELIEF_SUNKEN, groove = -1; + Ttk_Orient orient; + (void)dummy; + (void)state; border = Tk_Get3DBorderFromObj(tkwin, troughPtr->colorObj); - Ttk_GetOrientFromObj(NULL, troughPtr->orientObj, &orient); + TtkGetOrientFromObj(NULL, troughPtr->orientObj, &orient); Tk_GetReliefFromObj(NULL, troughPtr->reliefObj, &relief); Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth); Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->grooveWidthObj, &groove); @@ -877,7 +903,7 @@ static void TroughElementDraw( borderWidth, relief); } -static Ttk_ElementSpec TroughElementSpec = { +static const Ttk_ElementSpec TroughElementSpec = { TK_STYLE_VERSION_2, sizeof(TroughElement), TroughElementOptions, @@ -900,26 +926,30 @@ typedef struct { Tcl_Obj *orientObj; } ThumbElement; -static Ttk_ElementOptionSpec ThumbElementOptions[] = { - { "-width", TK_OPTION_PIXELS, Tk_Offset(ThumbElement,sizeObj), +static const Ttk_ElementOptionSpec ThumbElementOptions[] = { + { "-width", TK_OPTION_PIXELS, offsetof(ThumbElement,sizeObj), STRINGIFY(SCROLLBAR_WIDTH) }, - { "-background", TK_OPTION_BORDER, Tk_Offset(ThumbElement,borderObj), + { "-background", TK_OPTION_BORDER, offsetof(ThumbElement,borderObj), DEFAULT_BACKGROUND }, - { "-bordercolor", TK_OPTION_COLOR, Tk_Offset(ThumbElement,borderColorObj), + { "-bordercolor", TK_OPTION_COLOR, offsetof(ThumbElement,borderColorObj), "black" }, - { "-relief", TK_OPTION_RELIEF,Tk_Offset(ThumbElement,reliefObj),"raised" }, - { "-orient", TK_OPTION_ANY,Tk_Offset(ThumbElement,orientObj),"horizontal"}, - { NULL, 0, 0, NULL } + { "-relief", TK_OPTION_RELIEF, offsetof(ThumbElement,reliefObj),"raised" }, + { "-orient", TK_OPTION_ANY, offsetof(ThumbElement,orientObj),"horizontal"}, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void ThumbElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ThumbElement *thumb = elementRecord; - int orient, size; + ThumbElement *thumb = (ThumbElement *)elementRecord; + Ttk_Orient orient; + int size; + (void)dummy; + (void)paddingPtr; + Tk_GetPixelsFromObj(NULL, tkwin, thumb->sizeObj, &size); - Ttk_GetOrientFromObj(NULL, thumb->orientObj, &orient); + TtkGetOrientFromObj(NULL, thumb->orientObj, &orient); if (orient == TTK_ORIENT_VERTICAL) { *widthPtr = size; @@ -931,14 +961,16 @@ static void ThumbElementSize( } static void ThumbElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - ThumbElement *thumb = elementRecord; + ThumbElement *thumb = (ThumbElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, thumb->borderObj); XColor *borderColor = Tk_GetColorFromObj(tkwin, thumb->borderColorObj); int relief = TK_RELIEF_RAISED; int borderWidth = 2; + (void)dummy; + (void)state; /* * Don't draw the thumb if we are disabled. @@ -954,7 +986,7 @@ static void ThumbElementDraw( DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief); } -static Ttk_ElementSpec ThumbElementSpec = { +static const Ttk_ElementSpec ThumbElementSpec = { TK_STYLE_VERSION_2, sizeof(ThumbElement), ThumbElementOptions, @@ -983,32 +1015,35 @@ typedef struct { Tcl_Obj *orientObj; /* Orientation of overall slider */ } SliderElement; -static Ttk_ElementOptionSpec SliderElementOptions[] = { - { "-sliderlength", TK_OPTION_PIXELS, Tk_Offset(SliderElement,lengthObj), +static const Ttk_ElementOptionSpec SliderElementOptions[] = { + { "-sliderlength", TK_OPTION_PIXELS, offsetof(SliderElement,lengthObj), "15" }, - { "-sliderthickness",TK_OPTION_PIXELS,Tk_Offset(SliderElement,thicknessObj), + { "-sliderthickness",TK_OPTION_PIXELS, offsetof(SliderElement,thicknessObj), "15" }, - { "-sliderrelief", TK_OPTION_RELIEF, Tk_Offset(SliderElement,reliefObj), + { "-sliderrelief", TK_OPTION_RELIEF, offsetof(SliderElement,reliefObj), "raised" }, - { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(SliderElement,borderWidthObj), + { "-borderwidth", TK_OPTION_PIXELS, offsetof(SliderElement,borderWidthObj), STRINGIFY(BORDERWIDTH) }, - { "-background", TK_OPTION_BORDER, Tk_Offset(SliderElement,borderObj), + { "-background", TK_OPTION_BORDER, offsetof(SliderElement,borderObj), DEFAULT_BACKGROUND }, - { "-bordercolor", TK_OPTION_COLOR, Tk_Offset(ThumbElement,borderColorObj), + { "-bordercolor", TK_OPTION_COLOR, offsetof(ThumbElement,borderColorObj), "black" }, - { "-orient", TK_OPTION_ANY, Tk_Offset(SliderElement,orientObj), + { "-orient", TK_OPTION_ANY, offsetof(SliderElement,orientObj), "horizontal" }, - { NULL, 0, 0, NULL } + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void SliderElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - SliderElement *slider = elementRecord; - int orient, length, thickness, borderWidth; + SliderElement *slider = (SliderElement *)elementRecord; + Ttk_Orient orient; + int length, thickness, borderWidth; + (void)dummy; + (void)paddingPtr; - Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient); + TtkGetOrientFromObj(NULL, slider->orientObj, &orient); Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth); Tk_GetPixelsFromObj(NULL, tkwin, slider->lengthObj, &length); Tk_GetPixelsFromObj(NULL, tkwin, slider->thicknessObj, &thickness); @@ -1027,13 +1062,15 @@ static void SliderElementSize( } static void SliderElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - SliderElement *slider = elementRecord; + SliderElement *slider = (SliderElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, slider->borderObj); XColor *borderColor = Tk_GetColorFromObj(tkwin, slider->borderColorObj); int relief = TK_RELIEF_RAISED, borderWidth = 2; + (void)dummy; + (void)state; Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth); Tk_GetReliefFromObj(NULL, slider->reliefObj, &relief); @@ -1044,7 +1081,7 @@ static void SliderElementDraw( DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief); } -static Ttk_ElementSpec SliderElementSpec = { +static const Ttk_ElementSpec SliderElementSpec = { TK_STYLE_VERSION_2, sizeof(SliderElement), SliderElementOptions, @@ -1065,23 +1102,25 @@ typedef struct { Tcl_Obj *diameterObj; } TreeitemIndicator; -static Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = { +static const Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = { { "-foreground", TK_OPTION_COLOR, - Tk_Offset(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND }, + offsetof(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND }, { "-diameter", TK_OPTION_PIXELS, - Tk_Offset(TreeitemIndicator,diameterObj), "9" }, + offsetof(TreeitemIndicator,diameterObj), "9" }, { "-indicatormargins", TK_OPTION_STRING, - Tk_Offset(TreeitemIndicator,marginObj), "2 2 4 2" }, - { NULL, 0, 0, NULL } + offsetof(TreeitemIndicator,marginObj), "2 2 4 2" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void TreeitemIndicatorSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - TreeitemIndicator *indicator = elementRecord; + TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord; int diameter = 0; Ttk_Padding margins; + (void)dummy; + (void)paddingPtr; Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins); Tk_GetPixelsFromObj(NULL, tkwin, indicator->diameterObj, &diameter); @@ -1090,15 +1129,16 @@ static void TreeitemIndicatorSize( } static void TreeitemIndicatorDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - TreeitemIndicator *indicator = elementRecord; + TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord; XColor *color = Tk_GetColorFromObj(tkwin, indicator->colorObj); GC gc = Tk_GCForColor(color, d); Ttk_Padding padding = Ttk_UniformPadding(0); int w = WIN32_XDRAWLINE_HACK; int cx, cy; + (void)dummy; if (state & TTK_STATE_LEAF) { /* don't draw anything ... */ @@ -1121,7 +1161,7 @@ static void TreeitemIndicatorDraw( } } -static Ttk_ElementSpec TreeitemIndicatorElementSpec = { +static const Ttk_ElementSpec TreeitemIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(TreeitemIndicator), TreeitemIndicatorOptions, @@ -1157,18 +1197,15 @@ MODULE_SCOPE int TtkAltTheme_Init(Tcl_Interp *interp) Ttk_RegisterElement(interp, theme, "slider", &SliderElementSpec, NULL); Ttk_RegisterElement(interp, theme, "uparrow", - &ArrowElementSpec, &ArrowElements[0]); + &ArrowElementSpec, INT2PTR(ARROW_UP)); Ttk_RegisterElement(interp, theme, "downarrow", - &ArrowElementSpec, &ArrowElements[1]); + &ArrowElementSpec, INT2PTR(ARROW_DOWN)); Ttk_RegisterElement(interp, theme, "leftarrow", - &ArrowElementSpec, &ArrowElements[2]); + &ArrowElementSpec, INT2PTR(ARROW_LEFT)); Ttk_RegisterElement(interp, theme, "rightarrow", - &ArrowElementSpec, &ArrowElements[3]); - Ttk_RegisterElement(interp, theme, "arrow", - &ArrowElementSpec, &ArrowElements[0]); - + &ArrowElementSpec, INT2PTR(ARROW_RIGHT)); Ttk_RegisterElement(interp, theme, "arrow", - &ArrowElementSpec, &ArrowElements[0]); + &ArrowElementSpec, INT2PTR(ARROW_UP)); Ttk_RegisterElement(interp, theme, "Treeitem.indicator", &TreeitemIndicatorElementSpec, 0); diff --git a/generic/ttk/ttkElements.c b/generic/ttk/ttkElements.c index c4469dc..a1cac4d 100644 --- a/generic/ttk/ttkElements.c +++ b/generic/ttk/ttkElements.c @@ -6,7 +6,6 @@ */ #include "tkInt.h" -#include <string.h> #include "ttkTheme.h" #include "ttkWidget.h" @@ -20,20 +19,32 @@ * and may be used in other engines. */ -/* public */ Ttk_ElementOptionSpec TtkNullElementOptions[] = { { NULL, 0, 0, NULL } }; +/* public */ const Ttk_ElementOptionSpec TtkNullElementOptions[] = { { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; /* public */ void TtkNullElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { + (void)dummy; + (void)elementRecord; + (void)tkwin; + (void)widthPtr; + (void)heightPtr; + (void)paddingPtr; } /* public */ void TtkNullElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { + (void)dummy; + (void)elementRecord; + (void)tkwin; + (void)d; + (void)b; + (void)state; } /* public */ Ttk_ElementSpec ttkNullElementSpec = { @@ -57,18 +68,20 @@ typedef struct { Tcl_Obj *backgroundObj; } BackgroundElement; -static Ttk_ElementOptionSpec BackgroundElementOptions[] = { +static const Ttk_ElementOptionSpec BackgroundElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(BackgroundElement,backgroundObj), DEFAULT_BACKGROUND }, - { NULL, 0, 0, NULL } + offsetof(BackgroundElement,backgroundObj), DEFAULT_BACKGROUND }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void FillElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - BackgroundElement *bg = elementRecord; + BackgroundElement *bg = (BackgroundElement *)elementRecord; Tk_3DBorder backgroundPtr = Tk_Get3DBorderFromObj(tkwin,bg->backgroundObj); + (void)dummy; + (void)state; XFillRectangle(Tk_Display(tkwin), d, Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC), @@ -79,12 +92,14 @@ static void BackgroundElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { + (void)b; + FillElementDraw( clientData, elementRecord, tkwin, d, Ttk_WinBox(tkwin), state); } -static Ttk_ElementSpec FillElementSpec = { +static const Ttk_ElementSpec FillElementSpec = { TK_STYLE_VERSION_2, sizeof(BackgroundElement), BackgroundElementOptions, @@ -92,7 +107,7 @@ static Ttk_ElementSpec FillElementSpec = { FillElementDraw }; -static Ttk_ElementSpec BackgroundElementSpec = { +static const Ttk_ElementSpec BackgroundElementSpec = { TK_STYLE_VERSION_2, sizeof(BackgroundElement), BackgroundElementOptions, @@ -110,33 +125,40 @@ typedef struct { Tcl_Obj *reliefObj; } BorderElement; -static Ttk_ElementOptionSpec BorderElementOptions[] = { +static const Ttk_ElementOptionSpec BorderElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(BorderElement,borderObj), DEFAULT_BACKGROUND }, + offsetof(BorderElement,borderObj), DEFAULT_BACKGROUND }, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(BorderElement,borderWidthObj), DEFAULT_BORDERWIDTH }, + offsetof(BorderElement,borderWidthObj), DEFAULT_BORDERWIDTH }, { "-relief", TK_OPTION_RELIEF, - Tk_Offset(BorderElement,reliefObj), "flat" }, - { NULL, 0, 0, NULL } + offsetof(BorderElement,reliefObj), "flat" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void BorderElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - BorderElement *bd = elementRecord; + BorderElement *bd = (BorderElement *)elementRecord; int borderWidth = 0; + (void)dummy; + (void)tkwin; + (void)widthPtr; + (void)heightPtr; + Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth); *paddingPtr = Ttk_UniformPadding((short)borderWidth); } static void BorderElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - BorderElement *bd = elementRecord; + BorderElement *bd = (BorderElement *)elementRecord; Tk_3DBorder border = NULL; int borderWidth = 1, relief = TK_RELIEF_FLAT; + (void)dummy; + (void)state; border = Tk_Get3DBorderFromObj(tkwin, bd->borderObj); Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth); @@ -148,7 +170,7 @@ static void BorderElementDraw( } } -static Ttk_ElementSpec BorderElementSpec = { +static const Ttk_ElementSpec BorderElementSpec = { TK_STYLE_VERSION_2, sizeof(BorderElement), BorderElementOptions, @@ -165,38 +187,44 @@ typedef struct { Tcl_Obj *borderWidthObj; } FieldElement; -static Ttk_ElementOptionSpec FieldElementOptions[] = { +static const Ttk_ElementOptionSpec FieldElementOptions[] = { { "-fieldbackground", TK_OPTION_BORDER, - Tk_Offset(FieldElement,borderObj), "white" }, + offsetof(FieldElement,borderObj), "white" }, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(FieldElement,borderWidthObj), "2" }, - { NULL, 0, 0, NULL } + offsetof(FieldElement,borderWidthObj), "2" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void FieldElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - FieldElement *field = elementRecord; + FieldElement *field = (FieldElement *)elementRecord; int borderWidth = 2; + (void)dummy; + (void)widthPtr; + (void)heightPtr; + Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj, &borderWidth); *paddingPtr = Ttk_UniformPadding((short)borderWidth); } static void FieldElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - FieldElement *field = elementRecord; + FieldElement *field = (FieldElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, field->borderObj); int borderWidth = 2; + (void)dummy; + (void)state; Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj, &borderWidth); Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height, borderWidth, TK_RELIEF_SUNKEN); } -static Ttk_ElementSpec FieldElementSpec = { +static const Ttk_ElementSpec FieldElementSpec = { TK_STYLE_VERSION_2, sizeof(FieldElement), FieldElementOptions, @@ -221,24 +249,27 @@ typedef struct { Tcl_Obj *shiftreliefObj; } PaddingElement; -static Ttk_ElementOptionSpec PaddingElementOptions[] = { +static const Ttk_ElementOptionSpec PaddingElementOptions[] = { { "-padding", TK_OPTION_STRING, - Tk_Offset(PaddingElement,paddingObj), "0" }, + offsetof(PaddingElement,paddingObj), "0" }, { "-relief", TK_OPTION_RELIEF, - Tk_Offset(PaddingElement,reliefObj), "flat" }, + offsetof(PaddingElement,reliefObj), "flat" }, { "-shiftrelief", TK_OPTION_INT, - Tk_Offset(PaddingElement,shiftreliefObj), "0" }, - { NULL, 0, 0, NULL } + offsetof(PaddingElement,shiftreliefObj), "0" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void PaddingElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - PaddingElement *padding = elementRecord; + PaddingElement *padding = (PaddingElement *)elementRecord; int shiftRelief = 0; int relief = TK_RELIEF_FLAT; Ttk_Padding pad; + (void)dummy; + (void)widthPtr; + (void)heightPtr; Tk_GetReliefFromObj(NULL, padding->reliefObj, &relief); Tcl_GetIntFromObj(NULL, padding->shiftreliefObj, &shiftRelief); @@ -246,7 +277,7 @@ static void PaddingElementSize( *paddingPtr = Ttk_RelievePadding(pad, relief, shiftRelief); } -static Ttk_ElementSpec PaddingElementSpec = { +static const Ttk_ElementSpec PaddingElementSpec = { TK_STYLE_VERSION_2, sizeof(PaddingElement), PaddingElementOptions, @@ -287,31 +318,36 @@ static void DrawFocusRing( Tk_FreeGC(Tk_Display(tkwin), gc); } -static Ttk_ElementOptionSpec FocusElementOptions[] = { +static const Ttk_ElementOptionSpec FocusElementOptions[] = { { "-focuscolor",TK_OPTION_COLOR, - Tk_Offset(FocusElement,focusColorObj), "black" }, + offsetof(FocusElement,focusColorObj), "black" }, { "-focusthickness",TK_OPTION_PIXELS, - Tk_Offset(FocusElement,focusThicknessObj), "1" }, - { NULL, 0, 0, NULL } + offsetof(FocusElement,focusThicknessObj), "1" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void FocusElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - FocusElement *focus = elementRecord; + FocusElement *focus = (FocusElement *)elementRecord; int focusThickness = 0; + (void)dummy; + (void)tkwin; + (void)widthPtr; + (void)heightPtr; Tcl_GetIntFromObj(NULL, focus->focusThicknessObj, &focusThickness); *paddingPtr = Ttk_UniformPadding((short)focusThickness); } static void FocusElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - FocusElement *focus = elementRecord; + FocusElement *focus = (FocusElement *)elementRecord; int focusThickness = 0; + (void)dummy; if (state & TTK_STATE_FOCUS) { Tcl_GetIntFromObj(NULL,focus->focusThicknessObj,&focusThickness); @@ -319,7 +355,7 @@ static void FocusElementDraw( } } -static Ttk_ElementSpec FocusElementSpec = { +static const Ttk_ElementSpec FocusElementSpec = { TK_STYLE_VERSION_2, sizeof(FocusElement), FocusElementOptions, @@ -339,42 +375,51 @@ typedef struct { Tcl_Obj *borderObj; } SeparatorElement; -static Ttk_ElementOptionSpec SeparatorElementOptions[] = { +static const Ttk_ElementOptionSpec SeparatorElementOptions[] = { { "-orient", TK_OPTION_ANY, - Tk_Offset(SeparatorElement, orientObj), "horizontal" }, + offsetof(SeparatorElement, orientObj), "horizontal" }, { "-background", TK_OPTION_BORDER, - Tk_Offset(SeparatorElement,borderObj), DEFAULT_BACKGROUND }, - { NULL, 0, 0, NULL } + offsetof(SeparatorElement,borderObj), DEFAULT_BACKGROUND }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void SeparatorElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { + (void)dummy; + (void)elementRecord; + (void)tkwin; + (void)paddingPtr; + *widthPtr = *heightPtr = 2; } static void HorizontalSeparatorElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - SeparatorElement *separator = elementRecord; + SeparatorElement *separator = (SeparatorElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, separator->borderObj); GC lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC); GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC); + (void)dummy; + (void)state; XDrawLine(Tk_Display(tkwin), d, darkGC, b.x, b.y, b.x + b.width, b.y); XDrawLine(Tk_Display(tkwin), d, lightGC, b.x, b.y+1, b.x + b.width, b.y+1); } static void VerticalSeparatorElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - SeparatorElement *separator = elementRecord; + SeparatorElement *separator = (SeparatorElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, separator->borderObj); GC lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC); GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC); + (void)dummy; + (void)state; XDrawLine(Tk_Display(tkwin), d, darkGC, b.x, b.y, b.x, b.y + b.height); XDrawLine(Tk_Display(tkwin), d, lightGC, b.x+1, b.y, b.x+1, b.y+b.height); @@ -384,9 +429,10 @@ static void GeneralSeparatorElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - SeparatorElement *separator = elementRecord; - int orient; - Ttk_GetOrientFromObj(NULL, separator->orientObj, &orient); + SeparatorElement *separator = (SeparatorElement *)elementRecord; + Ttk_Orient orient; + + TtkGetOrientFromObj(NULL, separator->orientObj, &orient); switch (orient) { case TTK_ORIENT_HORIZONTAL: HorizontalSeparatorElementDraw( @@ -399,7 +445,7 @@ static void GeneralSeparatorElementDraw( } } -static Ttk_ElementSpec HorizontalSeparatorElementSpec = { +static const Ttk_ElementSpec HorizontalSeparatorElementSpec = { TK_STYLE_VERSION_2, sizeof(SeparatorElement), SeparatorElementOptions, @@ -407,7 +453,7 @@ static Ttk_ElementSpec HorizontalSeparatorElementSpec = { HorizontalSeparatorElementDraw }; -static Ttk_ElementSpec VerticalSeparatorElementSpec = { +static const Ttk_ElementSpec VerticalSeparatorElementSpec = { TK_STYLE_VERSION_2, sizeof(SeparatorElement), SeparatorElementOptions, @@ -415,7 +461,7 @@ static Ttk_ElementSpec VerticalSeparatorElementSpec = { HorizontalSeparatorElementDraw }; -static Ttk_ElementSpec SeparatorElementSpec = { +static const Ttk_ElementSpec SeparatorElementSpec = { TK_STYLE_VERSION_2, sizeof(SeparatorElement), SeparatorElementOptions, @@ -431,30 +477,37 @@ typedef struct { Tcl_Obj *backgroundObj; } SizegripElement; -static Ttk_ElementOptionSpec SizegripOptions[] = { +static const Ttk_ElementOptionSpec SizegripOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(SizegripElement,backgroundObj), DEFAULT_BACKGROUND }, - {0,0,0,0} + offsetof(SizegripElement,backgroundObj), DEFAULT_BACKGROUND }, + {0,TK_OPTION_BOOLEAN,0,0} }; static void SizegripSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { int gripCount = 3, gripSpace = 2, gripThickness = 3; + (void)dummy; + (void)elementRecord; + (void)tkwin; + (void)paddingPtr; + *widthPtr = *heightPtr = gripCount * (gripSpace + gripThickness); } static void SizegripDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - SizegripElement *grip = elementRecord; + SizegripElement *grip = (SizegripElement *)elementRecord; int gripCount = 3, gripSpace = 2; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, grip->backgroundObj); GC lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC); GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC); int x1 = b.x + b.width-1, y1 = b.y + b.height-1, x2 = x1, y2 = y1; + (void)dummy; + (void)state; while (gripCount--) { x1 -= gripSpace; y2 -= gripSpace; @@ -464,7 +517,7 @@ static void SizegripDraw( } } -static Ttk_ElementSpec SizegripElementSpec = { +static const Ttk_ElementSpec SizegripElementSpec = { TK_STYLE_VERSION_2, sizeof(SizegripElement), SizegripOptions, @@ -492,32 +545,35 @@ typedef struct { Tcl_Obj *borderWidthObj; } IndicatorElement; -static Ttk_ElementOptionSpec IndicatorElementOptions[] = { +static const Ttk_ElementOptionSpec IndicatorElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND }, + offsetof(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND }, { "-indicatorcolor", TK_OPTION_BORDER, - Tk_Offset(IndicatorElement,colorObj), DEFAULT_BACKGROUND }, + offsetof(IndicatorElement,colorObj), DEFAULT_BACKGROUND }, { "-indicatorrelief", TK_OPTION_RELIEF, - Tk_Offset(IndicatorElement,reliefObj), "raised" }, + offsetof(IndicatorElement,reliefObj), "raised" }, { "-indicatordiameter", TK_OPTION_PIXELS, - Tk_Offset(IndicatorElement,diameterObj), "12" }, + offsetof(IndicatorElement,diameterObj), "12" }, { "-indicatormargin", TK_OPTION_STRING, - Tk_Offset(IndicatorElement,marginObj), "0 2 4 2" }, + offsetof(IndicatorElement,marginObj), "0 2 4 2" }, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(IndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH }, - { NULL, 0, 0, NULL } + offsetof(IndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; /* * Checkbutton indicators (default): 3-D square. */ static void SquareIndicatorElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - IndicatorElement *indicator = elementRecord; + IndicatorElement *indicator = (IndicatorElement *)elementRecord; Ttk_Padding margins; int diameter = 0; + (void)dummy; + (void)paddingPtr; + Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins); Tk_GetPixelsFromObj(NULL, tkwin, indicator->diameterObj, &diameter); *widthPtr = diameter + Ttk_PaddingWidth(margins); @@ -525,15 +581,17 @@ static void SquareIndicatorElementSize( } static void SquareIndicatorElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - IndicatorElement *indicator = elementRecord; + IndicatorElement *indicator = (IndicatorElement *)elementRecord; Tk_3DBorder border = 0, interior = 0; int relief = TK_RELIEF_RAISED; Ttk_Padding padding; int borderWidth = 2; int diameter; + (void)dummy; + (void)state; interior = Tk_Get3DBorderFromObj(tkwin, indicator->colorObj); border = Tk_Get3DBorderFromObj(tkwin, indicator->backgroundObj); @@ -554,12 +612,15 @@ static void SquareIndicatorElementDraw( * Radiobutton indicators: 3-D diamond. */ static void DiamondIndicatorElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - IndicatorElement *indicator = elementRecord; + IndicatorElement *indicator = (IndicatorElement *)elementRecord; Ttk_Padding margins; int diameter = 0; + (void)dummy; + (void)paddingPtr; + Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins); Tk_GetPixelsFromObj(NULL, tkwin, indicator->diameterObj, &diameter); *widthPtr = diameter + 3 + Ttk_PaddingWidth(margins); @@ -567,16 +628,18 @@ static void DiamondIndicatorElementSize( } static void DiamondIndicatorElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - IndicatorElement *indicator = elementRecord; + IndicatorElement *indicator = (IndicatorElement *)elementRecord; Tk_3DBorder border = 0, interior = 0; int borderWidth = 2; int relief = TK_RELIEF_RAISED; int diameter, radius; XPoint points[4]; Ttk_Padding padding; + (void)dummy; + (void)state; interior = Tk_Get3DBorderFromObj(tkwin, indicator->colorObj); border = Tk_Get3DBorderFromObj(tkwin, indicator->backgroundObj); @@ -602,7 +665,7 @@ static void DiamondIndicatorElementDraw( Tk_Draw3DPolygon(tkwin,d,border,points,4,borderWidth,relief); } -static Ttk_ElementSpec CheckbuttonIndicatorElementSpec = { +static const Ttk_ElementSpec CheckbuttonIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(IndicatorElement), IndicatorElementOptions, @@ -610,7 +673,7 @@ static Ttk_ElementSpec CheckbuttonIndicatorElementSpec = { SquareIndicatorElementDraw }; -static Ttk_ElementSpec RadiobuttonIndicatorElementSpec = { +static const Ttk_ElementSpec RadiobuttonIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(IndicatorElement), IndicatorElementOptions, @@ -638,28 +701,31 @@ typedef struct { Tcl_Obj *marginObj; } MenuIndicatorElement; -static Ttk_ElementOptionSpec MenuIndicatorElementOptions[] = { +static const Ttk_ElementOptionSpec MenuIndicatorElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(MenuIndicatorElement,backgroundObj), DEFAULT_BACKGROUND }, + offsetof(MenuIndicatorElement,backgroundObj), DEFAULT_BACKGROUND }, { "-indicatorwidth", TK_OPTION_PIXELS, - Tk_Offset(MenuIndicatorElement,widthObj), "4.0m" }, + offsetof(MenuIndicatorElement,widthObj), "4.0m" }, { "-indicatorheight", TK_OPTION_PIXELS, - Tk_Offset(MenuIndicatorElement,heightObj), "1.7m" }, + offsetof(MenuIndicatorElement,heightObj), "1.7m" }, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(MenuIndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH }, + offsetof(MenuIndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH }, { "-indicatorrelief", TK_OPTION_RELIEF, - Tk_Offset(MenuIndicatorElement,reliefObj),"raised" }, + offsetof(MenuIndicatorElement,reliefObj),"raised" }, { "-indicatormargin", TK_OPTION_STRING, - Tk_Offset(MenuIndicatorElement,marginObj), "5 0" }, - { NULL, 0, 0, NULL } + offsetof(MenuIndicatorElement,marginObj), "5 0" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void MenuIndicatorElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - MenuIndicatorElement *mi = elementRecord; + MenuIndicatorElement *mi = (MenuIndicatorElement *)elementRecord; Ttk_Padding margins; + (void)dummy; + (void)paddingPtr; + Tk_GetPixelsFromObj(NULL, tkwin, mi->widthObj, widthPtr); Tk_GetPixelsFromObj(NULL, tkwin, mi->heightObj, heightPtr); Ttk_GetPaddingFromObj(NULL,tkwin,mi->marginObj, &margins); @@ -668,13 +734,15 @@ static void MenuIndicatorElementSize( } static void MenuIndicatorElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - MenuIndicatorElement *mi = elementRecord; + MenuIndicatorElement *mi = (MenuIndicatorElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, mi->backgroundObj); Ttk_Padding margins; int borderWidth = 2; + (void)dummy; + (void)state; Ttk_GetPaddingFromObj(NULL,tkwin,mi->marginObj,&margins); b = Ttk_PadBox(b, margins); @@ -683,7 +751,7 @@ static void MenuIndicatorElementDraw( borderWidth, TK_RELIEF_RAISED); } -static Ttk_ElementSpec MenuIndicatorElementSpec = { +static const Ttk_ElementSpec MenuIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(MenuIndicatorElement), MenuIndicatorElementOptions, @@ -698,7 +766,6 @@ static Ttk_ElementSpec MenuIndicatorElementSpec = { * clientData is an enum ArrowDirection pointer. */ -static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT }; typedef struct { Tcl_Obj *borderObj; Tcl_Obj *borderWidthObj; @@ -707,29 +774,30 @@ typedef struct { Tcl_Obj *colorObj; } ArrowElement; -static Ttk_ElementOptionSpec ArrowElementOptions[] = { +static const Ttk_ElementOptionSpec ArrowElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(ArrowElement,borderObj), DEFAULT_BACKGROUND }, + offsetof(ArrowElement,borderObj), DEFAULT_BACKGROUND }, { "-relief",TK_OPTION_RELIEF, - Tk_Offset(ArrowElement,reliefObj),"raised"}, + offsetof(ArrowElement,reliefObj),"raised"}, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(ArrowElement,borderWidthObj), "1" }, + offsetof(ArrowElement,borderWidthObj), "1" }, { "-arrowcolor",TK_OPTION_COLOR, - Tk_Offset(ArrowElement,colorObj),"black"}, + offsetof(ArrowElement,colorObj),"black"}, { "-arrowsize", TK_OPTION_PIXELS, - Tk_Offset(ArrowElement,sizeObj), "14" }, - { NULL, 0, 0, NULL } + offsetof(ArrowElement,sizeObj), "14" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; -static Ttk_Padding ArrowMargins = { 3,3,3,3 }; +static const Ttk_Padding ArrowMargins = { 3,3,3,3 }; static void ArrowElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ArrowElement *arrow = elementRecord; - int direction = *(int *)clientData; + ArrowElement *arrow = (ArrowElement *)elementRecord; + ArrowDirection direction = (ArrowDirection)PTR2INT(clientData); int width = 14; + (void)paddingPtr; Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &width); width -= Ttk_PaddingWidth(ArrowMargins); @@ -742,23 +810,24 @@ static void ArrowElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - int direction = *(int *)clientData; - ArrowElement *arrow = elementRecord; + ArrowDirection direction = (ArrowDirection)PTR2INT(clientData); + ArrowElement *arrow = (ArrowElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj); XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj); int relief = TK_RELIEF_RAISED; int borderWidth = 1; + (void)state; Tk_GetReliefFromObj(NULL, arrow->reliefObj, &relief); - Tk_Fill3DRectangle( - tkwin, d, border, b.x, b.y, b.width, b.height, borderWidth, relief); + Tk_Fill3DRectangle( tkwin, d, border, b.x, b.y, b.width, b.height, + borderWidth, relief); TtkFillArrow(Tk_Display(tkwin), d, Tk_GCForColor(arrowColor, d), - Ttk_PadBox(b, ArrowMargins), direction); + Ttk_PadBox(b, ArrowMargins), direction); } -static Ttk_ElementSpec ArrowElementSpec = { +static const Ttk_ElementSpec ArrowElementSpec = { TK_STYLE_VERSION_2, sizeof(ArrowElement), ArrowElementOptions, @@ -778,34 +847,39 @@ typedef struct { Tcl_Obj *reliefObj; } TroughElement; -static Ttk_ElementOptionSpec TroughElementOptions[] = { +static const Ttk_ElementOptionSpec TroughElementOptions[] = { { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(TroughElement,borderWidthObj), DEFAULT_BORDERWIDTH }, + offsetof(TroughElement,borderWidthObj), DEFAULT_BORDERWIDTH }, { "-troughcolor", TK_OPTION_BORDER, - Tk_Offset(TroughElement,colorObj), DEFAULT_BACKGROUND }, + offsetof(TroughElement,colorObj), DEFAULT_BACKGROUND }, { "-troughrelief",TK_OPTION_RELIEF, - Tk_Offset(TroughElement,reliefObj), "sunken" }, - { NULL, 0, 0, NULL } + offsetof(TroughElement,reliefObj), "sunken" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void TroughElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - TroughElement *troughPtr = elementRecord; + TroughElement *troughPtr = (TroughElement *)elementRecord; int borderWidth = 2; + (void)dummy; + (void)widthPtr; + (void)heightPtr; Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth); *paddingPtr = Ttk_UniformPadding((short)borderWidth); } static void TroughElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - TroughElement *troughPtr = elementRecord; + TroughElement *troughPtr = (TroughElement *)elementRecord; Tk_3DBorder border = NULL; int borderWidth = 2, relief = TK_RELIEF_SUNKEN; + (void)dummy; + (void)state; border = Tk_Get3DBorderFromObj(tkwin, troughPtr->colorObj); Tk_GetReliefFromObj(NULL, troughPtr->reliefObj, &relief); @@ -815,7 +889,7 @@ static void TroughElementDraw( borderWidth, relief); } -static Ttk_ElementSpec TroughElementSpec = { +static const Ttk_ElementSpec TroughElementSpec = { TK_STYLE_VERSION_2, sizeof(TroughElement), TroughElementOptions, @@ -838,29 +912,32 @@ typedef struct { Tcl_Obj *borderWidthObj; } ThumbElement; -static Ttk_ElementOptionSpec ThumbElementOptions[] = { +static const Ttk_ElementOptionSpec ThumbElementOptions[] = { { "-orient", TK_OPTION_ANY, - Tk_Offset(ThumbElement, orientObj), "horizontal" }, + offsetof(ThumbElement, orientObj), "horizontal" }, { "-width", TK_OPTION_PIXELS, - Tk_Offset(ThumbElement,thicknessObj), DEFAULT_ARROW_SIZE }, + offsetof(ThumbElement,thicknessObj), DEFAULT_ARROW_SIZE }, { "-relief", TK_OPTION_RELIEF, - Tk_Offset(ThumbElement,reliefObj), "raised" }, + offsetof(ThumbElement,reliefObj), "raised" }, { "-background", TK_OPTION_BORDER, - Tk_Offset(ThumbElement,borderObj), DEFAULT_BACKGROUND }, + offsetof(ThumbElement,borderObj), DEFAULT_BACKGROUND }, { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(ThumbElement,borderWidthObj), DEFAULT_BORDERWIDTH }, - { NULL, 0, 0, NULL } + offsetof(ThumbElement,borderWidthObj), DEFAULT_BORDERWIDTH }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void ThumbElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ThumbElement *thumb = elementRecord; - int orient, thickness; + ThumbElement *thumb = (ThumbElement *)elementRecord; + Ttk_Orient orient; + int thickness; + (void)dummy; + (void)paddingPtr; Tk_GetPixelsFromObj(NULL, tkwin, thumb->thicknessObj, &thickness); - Ttk_GetOrientFromObj(NULL, thumb->orientObj, &orient); + TtkGetOrientFromObj(NULL, thumb->orientObj, &orient); if (orient == TTK_ORIENT_VERTICAL) { *widthPtr = thickness; @@ -872,12 +949,14 @@ static void ThumbElementSize( } static void ThumbElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - ThumbElement *thumb = elementRecord; + ThumbElement *thumb = (ThumbElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, thumb->borderObj); int borderWidth = 2, relief = TK_RELIEF_RAISED; + (void)dummy; + (void)state; Tk_GetPixelsFromObj(NULL, tkwin, thumb->borderWidthObj, &borderWidth); Tk_GetReliefFromObj(NULL, thumb->reliefObj, &relief); @@ -885,7 +964,7 @@ static void ThumbElementDraw( borderWidth, relief); } -static Ttk_ElementSpec ThumbElementSpec = { +static const Ttk_ElementSpec ThumbElementSpec = { TK_STYLE_VERSION_2, sizeof(ThumbElement), ThumbElementOptions, @@ -909,30 +988,33 @@ typedef struct { Tcl_Obj *borderWidthObj; /* the size of the border */ } SliderElement; -static Ttk_ElementOptionSpec SliderElementOptions[] = { - { "-sliderlength", TK_OPTION_PIXELS, Tk_Offset(SliderElement,lengthObj), +static const Ttk_ElementOptionSpec SliderElementOptions[] = { + { "-sliderlength", TK_OPTION_PIXELS, offsetof(SliderElement,lengthObj), "30" }, - { "-sliderthickness",TK_OPTION_PIXELS,Tk_Offset(SliderElement,thicknessObj), + { "-sliderthickness",TK_OPTION_PIXELS, offsetof(SliderElement,thicknessObj), "15" }, - { "-sliderrelief", TK_OPTION_RELIEF, Tk_Offset(SliderElement,reliefObj), + { "-sliderrelief", TK_OPTION_RELIEF, offsetof(SliderElement,reliefObj), "raised" }, - { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(SliderElement,borderWidthObj), + { "-borderwidth", TK_OPTION_PIXELS, offsetof(SliderElement,borderWidthObj), DEFAULT_BORDERWIDTH }, - { "-background", TK_OPTION_BORDER, Tk_Offset(SliderElement,borderObj), + { "-background", TK_OPTION_BORDER, offsetof(SliderElement,borderObj), DEFAULT_BACKGROUND }, - { "-orient", TK_OPTION_ANY, Tk_Offset(SliderElement,orientObj), + { "-orient", TK_OPTION_ANY, offsetof(SliderElement,orientObj), "horizontal" }, - { NULL, 0, 0, NULL } + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void SliderElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - SliderElement *slider = elementRecord; - int orient, length, thickness; + SliderElement *slider = (SliderElement *)elementRecord; + Ttk_Orient orient; + int length, thickness; + (void)dummy; + (void)paddingPtr; - Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient); + TtkGetOrientFromObj(NULL, slider->orientObj, &orient); Tk_GetPixelsFromObj(NULL, tkwin, slider->lengthObj, &length); Tk_GetPixelsFromObj(NULL, tkwin, slider->thicknessObj, &thickness); @@ -950,15 +1032,18 @@ static void SliderElementSize( } static void SliderElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - SliderElement *slider = elementRecord; + SliderElement *slider = (SliderElement *)elementRecord; Tk_3DBorder border = NULL; - int relief = TK_RELIEF_RAISED, borderWidth = 2, orient; + int relief = TK_RELIEF_RAISED, borderWidth = 2; + Ttk_Orient orient; + (void)dummy; + (void)state; border = Tk_Get3DBorderFromObj(tkwin, slider->borderObj); - Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient); + TtkGetOrientFromObj(NULL, slider->orientObj, &orient); Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth); Tk_GetReliefFromObj(NULL, slider->reliefObj, &relief); @@ -991,7 +1076,7 @@ static void SliderElementDraw( } } -static Ttk_ElementSpec SliderElementSpec = { +static const Ttk_ElementSpec SliderElementSpec = { TK_STYLE_VERSION_2, sizeof(SliderElement), SliderElementOptions, @@ -1020,30 +1105,33 @@ typedef struct { Tcl_Obj *borderWidthObj; /* thickness of the border */ } PbarElement; -static Ttk_ElementOptionSpec PbarElementOptions[] = { - { "-orient", TK_OPTION_ANY, Tk_Offset(PbarElement,orientObj), +static const Ttk_ElementOptionSpec PbarElementOptions[] = { + { "-orient", TK_OPTION_ANY, offsetof(PbarElement,orientObj), "horizontal" }, - { "-thickness", TK_OPTION_PIXELS, Tk_Offset(PbarElement,thicknessObj), + { "-thickness", TK_OPTION_PIXELS, offsetof(PbarElement,thicknessObj), DEFAULT_PBAR_THICKNESS }, - { "-barsize", TK_OPTION_PIXELS, Tk_Offset(PbarElement,lengthObj), + { "-barsize", TK_OPTION_PIXELS, offsetof(PbarElement,lengthObj), DEFAULT_PBAR_LENGTH }, - { "-pbarrelief", TK_OPTION_RELIEF, Tk_Offset(PbarElement,reliefObj), + { "-pbarrelief", TK_OPTION_RELIEF, offsetof(PbarElement,reliefObj), "raised" }, - { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(PbarElement,borderWidthObj), + { "-borderwidth", TK_OPTION_PIXELS, offsetof(PbarElement,borderWidthObj), DEFAULT_BORDERWIDTH }, - { "-background", TK_OPTION_BORDER, Tk_Offset(PbarElement,borderObj), + { "-background", TK_OPTION_BORDER, offsetof(PbarElement,borderObj), DEFAULT_BACKGROUND }, - { NULL, 0, 0, NULL } + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void PbarElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - PbarElement *pbar = elementRecord; - int orient, thickness = 15, length = 30, borderWidth = 2; + PbarElement *pbar = (PbarElement *)elementRecord; + Ttk_Orient orient; + int thickness = 15, length = 30, borderWidth = 2; + (void)dummy; + (void)paddingPtr; - Ttk_GetOrientFromObj(NULL, pbar->orientObj, &orient); + TtkGetOrientFromObj(NULL, pbar->orientObj, &orient); Tk_GetPixelsFromObj(NULL, tkwin, pbar->thicknessObj, &thickness); Tk_GetPixelsFromObj(NULL, tkwin, pbar->lengthObj, &length); Tk_GetPixelsFromObj(NULL, tkwin, pbar->borderWidthObj, &borderWidth); @@ -1061,12 +1149,14 @@ static void PbarElementSize( } static void PbarElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - PbarElement *pbar = elementRecord; + PbarElement *pbar = (PbarElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, pbar->borderObj); int relief = TK_RELIEF_RAISED, borderWidth = 2; + (void)dummy; + (void)state; Tk_GetPixelsFromObj(NULL, tkwin, pbar->borderWidthObj, &borderWidth); Tk_GetReliefFromObj(NULL, pbar->reliefObj, &relief); @@ -1076,7 +1166,7 @@ static void PbarElementDraw( borderWidth, relief); } -static Ttk_ElementSpec PbarElementSpec = { +static const Ttk_ElementSpec PbarElementSpec = { TK_STYLE_VERSION_2, sizeof(PbarElement), PbarElementOptions, @@ -1093,35 +1183,40 @@ typedef struct { Tcl_Obj *backgroundObj; } TabElement; -static Ttk_ElementOptionSpec TabElementOptions[] = { +static const Ttk_ElementOptionSpec TabElementOptions[] = { { "-borderwidth", TK_OPTION_PIXELS, - Tk_Offset(TabElement,borderWidthObj),"1" }, + offsetof(TabElement,borderWidthObj),"1" }, { "-background", TK_OPTION_BORDER, - Tk_Offset(TabElement,backgroundObj), DEFAULT_BACKGROUND }, - {0,0,0,0} + offsetof(TabElement,backgroundObj), DEFAULT_BACKGROUND }, + {0,TK_OPTION_BOOLEAN,0,0} }; static void TabElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - TabElement *tab = elementRecord; + TabElement *tab = (TabElement *)elementRecord; int borderWidth = 1; + (void)dummy; + (void)widthPtr; + (void)heightPtr; + Tk_GetPixelsFromObj(0, tkwin, tab->borderWidthObj, &borderWidth); paddingPtr->top = paddingPtr->left = paddingPtr->right = borderWidth; paddingPtr->bottom = 0; } static void TabElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - TabElement *tab = elementRecord; + TabElement *tab = (TabElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj); int borderWidth = 1; int cut = 2; XPoint pts[6]; int n = 0; + (void)dummy; Tcl_GetIntFromObj(NULL, tab->borderWidthObj, &borderWidth); @@ -1164,7 +1259,7 @@ static void TabElementDraw( } -static Ttk_ElementSpec TabElementSpec = { +static const Ttk_ElementSpec TabElementSpec = { TK_STYLE_VERSION_2, sizeof(TabElement), TabElementOptions, @@ -1180,12 +1275,14 @@ typedef TabElement ClientElement; #define ClientElementOptions TabElementOptions static void ClientElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - ClientElement *ce = elementRecord; + ClientElement *ce = (ClientElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, ce->backgroundObj); int borderWidth = 1; + (void)dummy; + (void)state; Tcl_GetIntFromObj(NULL, ce->borderWidthObj, &borderWidth); @@ -1194,16 +1291,20 @@ static void ClientElementDraw( } static void ClientElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ClientElement *ce = elementRecord; + ClientElement *ce = (ClientElement *)elementRecord; int borderWidth = 1; + (void)dummy; + (void)widthPtr; + (void)heightPtr; + Tk_GetPixelsFromObj(0, tkwin, ce->borderWidthObj, &borderWidth); *paddingPtr = Ttk_UniformPadding((short)borderWidth); } -static Ttk_ElementSpec ClientElementSpec = { +static const Ttk_ElementSpec ClientElementSpec = { TK_STYLE_VERSION_2, sizeof(ClientElement), ClientElementOptions, @@ -1244,15 +1345,15 @@ void TtkElements_Init(Tcl_Interp *interp) Ttk_RegisterElement(interp, theme, "indicator", &ttkNullElementSpec,NULL); Ttk_RegisterElement(interp, theme, "uparrow", - &ArrowElementSpec, &ArrowElements[0]); + &ArrowElementSpec, INT2PTR(ARROW_UP)); Ttk_RegisterElement(interp, theme, "downarrow", - &ArrowElementSpec, &ArrowElements[1]); + &ArrowElementSpec, INT2PTR(ARROW_DOWN)); Ttk_RegisterElement(interp, theme, "leftarrow", - &ArrowElementSpec, &ArrowElements[2]); + &ArrowElementSpec, INT2PTR(ARROW_LEFT)); Ttk_RegisterElement(interp, theme, "rightarrow", - &ArrowElementSpec, &ArrowElements[3]); + &ArrowElementSpec, INT2PTR(ARROW_RIGHT)); Ttk_RegisterElement(interp, theme, "arrow", - &ArrowElementSpec, &ArrowElements[0]); + &ArrowElementSpec, INT2PTR(ARROW_UP)); Ttk_RegisterElement(interp, theme, "trough", &TroughElementSpec, NULL); Ttk_RegisterElement(interp, theme, "thumb", &ThumbElementSpec, NULL); diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index 1d8137b..946b7fc 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -69,6 +69,7 @@ static const char *const validateReasonStrings[] = { /* Style parameters: */ typedef struct { + Tcl_Obj *placeholderForegroundObj;/* Foreground color for placeholder text */ Tcl_Obj *foregroundObj; /* Foreground color for normal text */ Tcl_Obj *backgroundObj; /* Entry widget background color */ Tcl_Obj *selBorderObj; /* Border and background for selection */ @@ -83,12 +84,12 @@ typedef struct { * Internal state: */ char *string; /* Storage for string (malloced) */ - int numBytes; /* Length of string in bytes. */ - int numChars; /* Length of string in characters. */ + TkSizeT numBytes; /* Length of string in bytes. */ + TkSizeT numChars; /* Length of string in characters. */ - int insertPos; /* Insert index */ - int selectFirst; /* Index of start of selection, or -1 */ - int selectLast; /* Index of end of selection, or -1 */ + TkSizeT insertPos; /* Insert index */ + TkSizeT selectFirst; /* Index of start of selection, or TCL_INDEX_NONE */ + TkSizeT selectLast; /* Index of end of selection, or TCL_INDEX_NONE */ Scrollable xscroll; /* Current scroll position */ ScrollHandle xscrollHandle; @@ -114,6 +115,8 @@ typedef struct { Tcl_Obj *stateObj; /* Compatibility option -- see CheckStateObj */ + Tcl_Obj *placeholderObj; /* Text to display for placeholder text */ + /* * Derived resources: */ @@ -143,55 +146,63 @@ typedef struct { /* * Default option values: */ -#define DEF_SELECT_BG "#000000" -#define DEF_SELECT_FG "#ffffff" -#define DEF_INSERT_BG "black" -#define DEF_ENTRY_WIDTH "20" -#define DEF_ENTRY_FONT "TkTextFont" -#define DEF_LIST_HEIGHT "10" +#define DEF_SELECT_BG "#000000" +#define DEF_SELECT_FG "#ffffff" +#define DEF_PLACEHOLDER_FG "#b3b3b3" +#define DEF_INSERT_BG "black" +#define DEF_ENTRY_WIDTH "20" +#define DEF_ENTRY_FONT "TkTextFont" +#define DEF_LIST_HEIGHT "10" -static Tk_OptionSpec EntryOptionSpecs[] = { +static const Tk_OptionSpec EntryOptionSpecs[] = { {TK_OPTION_BOOLEAN, "-exportselection", "exportSelection", - "ExportSelection", "1", -1, Tk_Offset(Entry, entry.exportSelection), + "ExportSelection", "1", TCL_INDEX_NONE, offsetof(Entry, entry.exportSelection), 0,0,0 }, {TK_OPTION_FONT, "-font", "font", "Font", - DEF_ENTRY_FONT, Tk_Offset(Entry, entry.fontObj),-1, + DEF_ENTRY_FONT, offsetof(Entry, entry.fontObj),TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand", - NULL, -1, Tk_Offset(Entry, entry.invalidCmd), + NULL, TCL_INDEX_NONE, offsetof(Entry, entry.invalidCmd), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", - "left", -1, Tk_Offset(Entry, entry.justify), + "left", TCL_INDEX_NONE, offsetof(Entry, entry.justify), 0, 0, GEOMETRY_CHANGED}, + {TK_OPTION_STRING, "-placeholder", "placeHolder", "PlaceHolder", + NULL, offsetof(Entry, entry.placeholderObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-show", "show", "Show", - NULL, -1, Tk_Offset(Entry, entry.showChar), + NULL, TCL_INDEX_NONE, offsetof(Entry, entry.showChar), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-state", "state", "State", - "normal", Tk_Offset(Entry, entry.stateObj), -1, + "normal", offsetof(Entry, entry.stateObj), TCL_INDEX_NONE, 0,0,STATE_CHANGED}, {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable", - NULL, Tk_Offset(Entry, entry.textVariableObj), -1, + NULL, offsetof(Entry, entry.textVariableObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,TEXTVAR_CHANGED}, {TK_OPTION_STRING_TABLE, "-validate", "validate", "Validate", - "none", -1, Tk_Offset(Entry, entry.validate), - 0, (ClientData) validateStrings, 0}, + "none", TCL_INDEX_NONE, offsetof(Entry, entry.validate), + 0, (void *) validateStrings, 0}, {TK_OPTION_STRING, "-validatecommand", "validateCommand", "ValidateCommand", - NULL, -1, Tk_Offset(Entry, entry.validateCmd), + NULL, TCL_INDEX_NONE, offsetof(Entry, entry.validateCmd), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_INT, "-width", "width", "Width", - DEF_ENTRY_WIDTH, Tk_Offset(Entry, entry.widthObj), -1, + DEF_ENTRY_WIDTH, offsetof(Entry, entry.widthObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", - NULL, -1, Tk_Offset(Entry, entry.xscroll.scrollCmd), + NULL, TCL_INDEX_NONE, offsetof(Entry, entry.xscroll.scrollCmd), TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, /* EntryStyleData options: */ + {TK_OPTION_COLOR, "-background", "windowColor", "WindowColor", + NULL, offsetof(Entry, entry.styleData.backgroundObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK,0,0}, {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor", - NULL, Tk_Offset(Entry, entry.styleData.foregroundObj), -1, + NULL, offsetof(Entry, entry.styleData.foregroundObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, - {TK_OPTION_COLOR, "-background", "windowColor", "WindowColor", - NULL, Tk_Offset(Entry, entry.styleData.backgroundObj), -1, + {TK_OPTION_COLOR, "-placeholderforeground", "placeholderForeground", + "PlaceholderForeground", NULL, + offsetof(Entry, entry.styleData.placeholderForegroundObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, WIDGET_TAKEFOCUS_TRUE, @@ -212,6 +223,7 @@ static void EntryInitStyleDefaults(EntryStyleData *es) #define INIT(member, value) \ es->member = Tcl_NewStringObj(value, -1); \ Tcl_IncrRefCount(es->member); + INIT(placeholderForegroundObj, DEF_PLACEHOLDER_FG) INIT(foregroundObj, DEFAULT_FOREGROUND) INIT(selBorderObj, DEF_SELECT_BG) INIT(selForegroundObj, DEF_SELECT_FG) @@ -223,6 +235,7 @@ static void EntryInitStyleDefaults(EntryStyleData *es) static void EntryFreeStyleDefaults(EntryStyleData *es) { + Tcl_DecrRefCount(es->placeholderForegroundObj); Tcl_DecrRefCount(es->foregroundObj); Tcl_DecrRefCount(es->selBorderObj); Tcl_DecrRefCount(es->selForegroundObj); @@ -249,6 +262,7 @@ static void EntryInitStyleData(Entry *entryPtr, EntryStyleData *es) # define INIT(member, name) \ if ((tmp=Ttk_QueryOption(entryPtr->core.layout,name,state))) \ es->member=tmp; + INIT(placeholderForegroundObj, "-placeholderforeground"); INIT(foregroundObj, "-foreground"); INIT(selBorderObj, "-selectbackground") INIT(selBorderWidthObj, "-selectborderwidth") @@ -259,6 +273,7 @@ static void EntryInitStyleData(Entry *entryPtr, EntryStyleData *es) /* Reacquire color & border resources from resource cache. */ + es->placeholderForegroundObj = Ttk_UseColor(cache, tkwin, es->placeholderForegroundObj); es->foregroundObj = Ttk_UseColor(cache, tkwin, es->foregroundObj); es->selForegroundObj = Ttk_UseColor(cache, tkwin, es->selForegroundObj); es->insertColorObj = Ttk_UseColor(cache, tkwin, es->insertColorObj); @@ -283,7 +298,7 @@ static char *EntryDisplayString(const char *showChar, int numChars) TkUtfToUniChar(showChar, &ch); size = TkUniCharToUtf(ch, buf); - p = displayString = ckalloc(numChars * size + 1); + p = displayString = (char *)ckalloc(numChars * size + 1); while (numChars--) { memcpy(p, buf, size); @@ -300,12 +315,23 @@ static char *EntryDisplayString(const char *showChar, int numChars) */ static void EntryUpdateTextLayout(Entry *entryPtr) { + TkSizeT length; + char *text; Tk_FreeTextLayout(entryPtr->entry.textLayout); - entryPtr->entry.textLayout = Tk_ComputeTextLayout( + if ((entryPtr->entry.numChars != 0) || (entryPtr->entry.placeholderObj == NULL)) { + entryPtr->entry.textLayout = Tk_ComputeTextLayout( Tk_GetFontFromObj(entryPtr->core.tkwin, entryPtr->entry.fontObj), entryPtr->entry.displayString, entryPtr->entry.numChars, 0/*wraplength*/, entryPtr->entry.justify, TK_IGNORE_NEWLINES, &entryPtr->entry.layoutWidth, &entryPtr->entry.layoutHeight); + } else { + text = TkGetStringFromObj(entryPtr->entry.placeholderObj, &length); + entryPtr->entry.textLayout = Tk_ComputeTextLayout( + Tk_GetFontFromObj(entryPtr->core.tkwin, entryPtr->entry.fontObj), + text, length, + 0/*wraplength*/, entryPtr->entry.justify, TK_IGNORE_NEWLINES, + &entryPtr->entry.layoutWidth, &entryPtr->entry.layoutHeight); + } } /* EntryEditable -- @@ -324,32 +350,32 @@ EntryEditable(Entry *entryPtr) /* EntryFetchSelection -- * Selection handler for entry widgets. */ -static int +static TkSizeT EntryFetchSelection( - ClientData clientData, int offset, char *buffer, int maxBytes) + ClientData clientData, TkSizeT offset, char *buffer, TkSizeT maxBytes) { - Entry *entryPtr = (Entry *) clientData; - int byteCount; + Entry *entryPtr = (Entry *)clientData; + TkSizeT byteCount; const char *string; const char *selStart, *selEnd; - if (entryPtr->entry.selectFirst < 0 || (!entryPtr->entry.exportSelection) + if (entryPtr->entry.selectFirst == TCL_INDEX_NONE || (!entryPtr->entry.exportSelection) || Tcl_IsSafe(entryPtr->core.interp)) { - return -1; + return TCL_INDEX_NONE; } string = entryPtr->entry.displayString; - selStart = TkUtfAtIndex(string, entryPtr->entry.selectFirst); - selEnd = TkUtfAtIndex(selStart, + selStart = Tcl_UtfAtIndex(string, entryPtr->entry.selectFirst); + selEnd = Tcl_UtfAtIndex(selStart, entryPtr->entry.selectLast - entryPtr->entry.selectFirst); + if (selEnd <= selStart + offset) { + return 0; + } byteCount = selEnd - selStart - offset; if (byteCount > maxBytes) { /* @@@POSSIBLE BUG: Can transfer partial UTF-8 sequences. Is this OK? */ byteCount = maxBytes; } - if (byteCount <= 0) { - return 0; - } memcpy(buffer, selStart + offset, byteCount); buffer[byteCount] = '\0'; return byteCount; @@ -361,9 +387,9 @@ EntryFetchSelection( */ static void EntryLostSelection(ClientData clientData) { - Entry *entryPtr = (Entry *) clientData; + Entry *entryPtr = (Entry *)clientData; entryPtr->core.flags &= ~GOT_SELECTION; - entryPtr->entry.selectFirst = entryPtr->entry.selectLast = -1; + entryPtr->entry.selectFirst = entryPtr->entry.selectLast = TCL_INDEX_NONE; TtkRedisplayWidget(&entryPtr->core); } @@ -377,7 +403,7 @@ static void EntryOwnSelection(Entry *entryPtr) && (!Tcl_IsSafe(entryPtr->core.interp)) && !(entryPtr->core.flags & GOT_SELECTION)) { Tk_OwnSelection(entryPtr->core.tkwin, XA_PRIMARY, EntryLostSelection, - (ClientData) entryPtr); + entryPtr); entryPtr->core.flags |= GOT_SELECTION; } } @@ -393,9 +419,9 @@ static void EntryOwnSelection(Entry *entryPtr) static void ExpandPercents( Entry *entryPtr, /* Entry that needs validation. */ - const char *template, /* Script template */ - const char *new, /* Potential new value of entry string */ - int index, /* index of insert/delete */ + const char *templ, /* Script template */ + const char *newValue, /* Potential new value of entry string */ + TkSizeT index, /* index of insert/delete */ int count, /* #changed characters */ VREASON reason, /* Reason for change */ Tcl_DString *dsPtr) /* Result of %-substitutions */ @@ -407,28 +433,28 @@ ExpandPercents( int ch; char numStorage[2*TCL_INTEGER_SPACE]; - while (*template) { + while (*templ) { /* Find everything up to the next % character and append it * to the result string. */ - string = Tcl_UtfFindFirst(template, '%'); + string = Tcl_UtfFindFirst(templ, '%'); if (string == NULL) { /* No more %-sequences to expand. * Copy the rest of the template. */ - Tcl_DStringAppend(dsPtr, template, -1); + Tcl_DStringAppend(dsPtr, templ, -1); return; } - if (string != template) { - Tcl_DStringAppend(dsPtr, template, string - template); - template = string; + if (string != templ) { + Tcl_DStringAppend(dsPtr, templ, string - templ); + templ = string; } /* There's a percent sequence here. Process it. */ - ++template; /* skip over % */ - if (*template != '\0') { - template += TkUtfToUniChar(template, &ch); + ++templ; /* skip over % */ + if (*templ != '\0') { + templ += TkUtfToUniChar(templ, &ch); } else { ch = '%'; } @@ -447,22 +473,22 @@ ExpandPercents( string = numStorage; break; case 'i': /* index of insert/delete */ - sprintf(numStorage, "%d", index); + sprintf(numStorage, "%d", (int)index); string = numStorage; break; case 'P': /* 'Peeked' new value of the string */ - string = new; + string = newValue; break; case 's': /* Current string value */ string = entryPtr->entry.string; break; case 'S': /* string to be inserted/deleted, if any */ if (reason == VALIDATE_INSERT) { - string = TkUtfAtIndex(new, index); - stringLength = TkUtfAtIndex(string, count) - string; + string = Tcl_UtfAtIndex(newValue, index); + stringLength = Tcl_UtfAtIndex(string, count) - string; } else if (reason == VALIDATE_DELETE) { - string = TkUtfAtIndex(entryPtr->entry.string, index); - stringLength = TkUtfAtIndex(string, count) - string; + string = Tcl_UtfAtIndex(entryPtr->entry.string, index); + stringLength = Tcl_UtfAtIndex(string, count) - string; } else { string = ""; stringLength = 0; @@ -502,18 +528,18 @@ ExpandPercents( static int RunValidationScript( Tcl_Interp *interp, /* Interpreter to use */ Entry *entryPtr, /* Entry being validated */ - const char *template, /* Script template */ + const char *templ, /* Script template */ const char *optionName, /* "-validatecommand", "-invalidcommand" */ - const char *new, /* Potential new value of entry string */ - int index, /* index of insert/delete */ - int count, /* #changed characters */ + const char *newValue, /* Potential new value of entry string */ + TkSizeT index, /* index of insert/delete */ + TkSizeT count, /* #changed characters */ VREASON reason) /* Reason for change */ { Tcl_DString script; int code; Tcl_DStringInit(&script); - ExpandPercents(entryPtr, template, new, index, count, reason, &script); + ExpandPercents(entryPtr, templ, newValue, index, count, reason, &script); code = Tcl_EvalEx(interp, Tcl_DStringValue(&script), Tcl_DStringLength(&script), TCL_EVAL_GLOBAL); @@ -557,7 +583,7 @@ static int EntryNeedsValidation(VMODE vmode, VREASON reason) * Returns: * TCL_OK if the change is accepted * TCL_BREAK if the change is rejected - * TCL_ERROR if any errors occurred + * TCL_ERROR if any errors occurred * * The change will be rejected if -validatecommand returns 0, * or if -validatecommand or -invalidcommand modifies the value. @@ -566,17 +592,17 @@ static int EntryValidateChange( Entry *entryPtr, /* Entry that needs validation. */ const char *newValue, /* Potential new value of entry string */ - int index, /* index of insert/delete, -1 otherwise */ - int count, /* #changed characters */ + TkSizeT index, /* index of insert/delete, TCL_INDEX_NONE otherwise */ + TkSizeT count, /* #changed characters */ VREASON reason) /* Reason for change */ { Tcl_Interp *interp = entryPtr->core.interp; VMODE vmode = entryPtr->entry.validate; int code, change_ok; - if ( (entryPtr->entry.validateCmd == NULL) + if ((entryPtr->entry.validateCmd == NULL) || (entryPtr->core.flags & VALIDATING) - || !EntryNeedsValidation(vmode, reason) ) + || !EntryNeedsValidation(vmode, reason)) { return TCL_OK; } @@ -630,10 +656,11 @@ done: * Returns: * TCL_OK if valid, TCL_BREAK if invalid, TCL_ERROR on error. */ -static int EntryRevalidate(Tcl_Interp *interp, Entry *entryPtr, VREASON reason) +static int EntryRevalidate(Tcl_Interp *dummy, Entry *entryPtr, VREASON reason) { int code = EntryValidateChange( entryPtr, entryPtr->entry.string, -1,0, reason); + (void)dummy; if (code == TCL_BREAK) { TtkWidgetChangeState(&entryPtr->core, TTK_STATE_INVALID, 0); @@ -693,8 +720,8 @@ static void AdjustIndices(Entry *entryPtr, int index, int nChars) e->selectLast = AdjustIndex(e->selectLast, index+g, nChars); e->xscroll.first= AdjustIndex(e->xscroll.first, index+g, nChars); - if (e->selectLast <= e->selectFirst) - e->selectFirst = e->selectLast = -1; + if (e->selectLast + 1 <= e->selectFirst + 1) + e->selectFirst = e->selectLast = TCL_INDEX_NONE; } /* EntryStoreValue -- @@ -707,7 +734,7 @@ static void EntryStoreValue(Entry *entryPtr, const char *value) { size_t numBytes = strlen(value); - int numChars = Tcl_NumUtfChars(value, numBytes); + TkSizeT numChars = Tcl_NumUtfChars(value, numBytes); if (entryPtr->core.flags & VALIDATING) entryPtr->core.flags |= VALIDATION_SET_VALUE; @@ -725,7 +752,7 @@ EntryStoreValue(Entry *entryPtr, const char *value) /* Store new value: */ - entryPtr->entry.string = ckalloc(numBytes + 1); + entryPtr->entry.string = (char *)ckalloc(numBytes + 1); strcpy(entryPtr->entry.string, value); entryPtr->entry.numBytes = numBytes; entryPtr->entry.numChars = numChars; @@ -782,7 +809,7 @@ static int EntrySetValue(Entry *entryPtr, const char *value) */ static void EntryTextVariableTrace(void *recordPtr, const char *value) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (WidgetDestroyed(&entryPtr->core)) { return; @@ -808,37 +835,37 @@ static void EntryTextVariableTrace(void *recordPtr, const char *value) static int InsertChars( Entry *entryPtr, /* Entry that is to get the new elements. */ - int index, /* Insert before this index */ + TkSizeT index, /* Insert before this index */ const char *value) /* New characters to add */ { char *string = entryPtr->entry.string; - size_t byteIndex = TkUtfAtIndex(string, index) - string; + size_t byteIndex = Tcl_UtfAtIndex(string, index) - string; size_t byteCount = strlen(value); int charsAdded = Tcl_NumUtfChars(value, byteCount); size_t newByteCount = entryPtr->entry.numBytes + byteCount + 1; - char *new; + char *newBytes; int code; if (byteCount == 0) { return TCL_OK; } - new = ckalloc(newByteCount); - memcpy(new, string, byteIndex); - strcpy(new + byteIndex, value); - strcpy(new + byteIndex + byteCount, string + byteIndex); + newBytes = (char *)ckalloc(newByteCount); + memcpy(newBytes, string, byteIndex); + strcpy(newBytes + byteIndex, value); + strcpy(newBytes + byteIndex + byteCount, string + byteIndex); code = EntryValidateChange( - entryPtr, new, index, charsAdded, VALIDATE_INSERT); + entryPtr, newBytes, index, charsAdded, VALIDATE_INSERT); if (code == TCL_OK) { AdjustIndices(entryPtr, index, charsAdded); - code = EntrySetValue(entryPtr, new); + code = EntrySetValue(entryPtr, newBytes); } else if (code == TCL_BREAK) { code = TCL_OK; } - ckfree(new); + ckfree(newBytes); return code; } @@ -848,42 +875,42 @@ InsertChars( static int DeleteChars( Entry *entryPtr, /* Entry widget to modify. */ - int index, /* Index of first character to delete. */ - int count) /* How many characters to delete. */ + TkSizeT index, /* Index of first character to delete. */ + TkSizeT count) /* How many characters to delete. */ { char *string = entryPtr->entry.string; size_t byteIndex, byteCount, newByteCount; - char *new; + char *newBytes; int code; - if (index < 0) { + if (index == TCL_INDEX_NONE) { index = 0; } - if (count > entryPtr->entry.numChars - index) { + if (count + index + 1 > entryPtr->entry.numChars + 1) { count = entryPtr->entry.numChars - index; } - if (count <= 0) { + if (count + 1 <= 1) { return TCL_OK; } - byteIndex = TkUtfAtIndex(string, index) - string; - byteCount = TkUtfAtIndex(string+byteIndex, count) - (string+byteIndex); + byteIndex = Tcl_UtfAtIndex(string, index) - string; + byteCount = Tcl_UtfAtIndex(string+byteIndex, count) - (string+byteIndex); newByteCount = entryPtr->entry.numBytes + 1 - byteCount; - new = ckalloc(newByteCount); - memcpy(new, string, byteIndex); - strcpy(new + byteIndex, string + byteIndex + byteCount); + newBytes = (char *)ckalloc(newByteCount); + memcpy(newBytes, string, byteIndex); + strcpy(newBytes + byteIndex, string + byteIndex + byteCount); code = EntryValidateChange( - entryPtr, new, index, count, VALIDATE_DELETE); + entryPtr, newBytes, index, count, VALIDATE_DELETE); if (code == TCL_OK) { AdjustIndices(entryPtr, index, -count); - code = EntrySetValue(entryPtr, new); + code = EntrySetValue(entryPtr, newBytes); } else if (code == TCL_BREAK) { code = TCL_OK; } - ckfree(new); + ckfree(newBytes); return code; } @@ -900,7 +927,7 @@ DeleteChars( static void EntryEventProc(ClientData clientData, XEvent *eventPtr) { - Entry *entryPtr = (Entry *) clientData; + Entry *entryPtr = (Entry *)clientData; Tcl_Preserve(clientData); switch (eventPtr->type) { @@ -923,17 +950,18 @@ EntryEventProc(ClientData clientData, XEvent *eventPtr) */ static void -EntryInitialize(Tcl_Interp *interp, void *recordPtr) +EntryInitialize(Tcl_Interp *dummy, void *recordPtr) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; + (void)dummy; Tk_CreateEventHandler( entryPtr->core.tkwin, EntryEventMask, EntryEventProc, entryPtr); Tk_CreateSelHandler(entryPtr->core.tkwin, XA_PRIMARY, XA_STRING, - EntryFetchSelection, (ClientData) entryPtr, XA_STRING); + EntryFetchSelection, entryPtr, XA_STRING); TtkBlinkCursor(&entryPtr->core); - entryPtr->entry.string = ckalloc(1); + entryPtr->entry.string = (char *)ckalloc(1); *entryPtr->entry.string = '\0'; entryPtr->entry.displayString = entryPtr->entry.string; entryPtr->entry.textVariableTrace = 0; @@ -945,14 +973,14 @@ EntryInitialize(Tcl_Interp *interp, void *recordPtr) TtkCreateScrollHandle(&entryPtr->core, &entryPtr->entry.xscroll); entryPtr->entry.insertPos = 0; - entryPtr->entry.selectFirst = -1; - entryPtr->entry.selectLast = -1; + entryPtr->entry.selectFirst = TCL_INDEX_NONE; + entryPtr->entry.selectLast = TCL_INDEX_NONE; } static void EntryCleanup(void *recordPtr) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (entryPtr->entry.textVariableTrace) Ttk_UntraceVariable(entryPtr->entry.textVariableTrace); @@ -974,7 +1002,7 @@ EntryCleanup(void *recordPtr) */ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; Tcl_Obj *textVarName = entryPtr->entry.textVariableObj; Ttk_TraceHandle *vt = 0; @@ -1001,7 +1029,7 @@ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask) /* Claim the selection, in case we've suddenly started exporting it. */ - if (entryPtr->entry.exportSelection && (entryPtr->entry.selectFirst != -1) + if (entryPtr->entry.exportSelection && (entryPtr->entry.selectFirst != TCL_INDEX_NONE) && (!Tcl_IsSafe(entryPtr->core.interp))) { EntryOwnSelection(entryPtr); } @@ -1038,10 +1066,11 @@ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask) /* EntryPostConfigure -- * Post-configuration hook for entry widgets. */ -static int EntryPostConfigure(Tcl_Interp *interp, void *recordPtr, int mask) +static int EntryPostConfigure(Tcl_Interp *dummy, void *recordPtr, int mask) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int status = TCL_OK; + (void)dummy; if ((mask & TEXTVAR_CHANGED) && entryPtr->entry.textVariableTrace != NULL) { status = Ttk_FireTrace(entryPtr->entry.textVariableTrace); @@ -1059,7 +1088,7 @@ static int EntryPostConfigure(Tcl_Interp *interp, void *recordPtr, int mask) * Precondition: textLayout and layoutX up-to-date. */ static int -EntryCharPosition(Entry *entryPtr, int index) +EntryCharPosition(Entry *entryPtr, TkSizeT index) { int xPos; Tk_CharBbox(entryPtr->entry.textLayout, index, &xPos, NULL, NULL, NULL); @@ -1079,7 +1108,7 @@ EntryCharPosition(Entry *entryPtr, int index) static void EntryDoLayout(void *recordPtr) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; WidgetCore *corePtr = &entryPtr->core; Tk_TextLayout textLayout = entryPtr->entry.textLayout; int leftIndex = entryPtr->entry.xscroll.first; @@ -1166,9 +1195,9 @@ static GC EntryGetGC(Entry *entryPtr, Tcl_Obj *colorObj, TkRegion clip) */ static void EntryDisplay(void *clientData, Drawable d) { - Entry *entryPtr = clientData; + Entry *entryPtr = (Entry *)clientData; Tk_Window tkwin = entryPtr->core.tkwin; - int leftIndex = entryPtr->entry.xscroll.first, + TkSizeT leftIndex = entryPtr->entry.xscroll.first, rightIndex = entryPtr->entry.xscroll.last + 1, selFirst = entryPtr->entry.selectFirst, selLast = entryPtr->entry.selectLast; @@ -1178,6 +1207,7 @@ static void EntryDisplay(void *clientData, Drawable d) Ttk_Box textarea; TkRegion clipRegion; XRectangle rect; + Tcl_Obj *foregroundObj; EntryInitStyleData(entryPtr, &es); @@ -1185,22 +1215,21 @@ static void EntryDisplay(void *clientData, Drawable d) showCursor = (entryPtr->core.flags & CURSOR_ON) && EntryEditable(entryPtr) - && entryPtr->entry.insertPos >= leftIndex - && entryPtr->entry.insertPos <= rightIndex + && entryPtr->entry.insertPos + 1 >= leftIndex + 1 + && entryPtr->entry.insertPos + 1 <= rightIndex + 1 ; showSelection = !(entryPtr->core.state & TTK_STATE_DISABLED) - && selFirst > -1 - && selLast > leftIndex - && selFirst <= rightIndex - ; + && selFirst != TCL_INDEX_NONE + && selLast + 1 > leftIndex + 1 + && selFirst + 1 <= rightIndex + 1; /* Adjust selection range to keep in display bounds. */ if (showSelection) { - if (selFirst < leftIndex) + if (selFirst + 1 < leftIndex + 1) selFirst = leftIndex; - if (selLast > rightIndex) + if (selLast + 1 > rightIndex + 1) selLast = rightIndex; } @@ -1273,7 +1302,21 @@ static void EntryDisplay(void *clientData, Drawable d) /* Draw the text: */ - gc = EntryGetGC(entryPtr, es.foregroundObj, clipRegion); + if ((*(entryPtr->entry.displayString) == '\0') + && (entryPtr->entry.placeholderObj != NULL)) { + /* No text displayed, but -placeholder is given */ + if (Tcl_GetCharLength(es.placeholderForegroundObj) > 0) { + foregroundObj = es.placeholderForegroundObj; + } else { + foregroundObj = es.foregroundObj; + } + /* Use placeholder text width */ + leftIndex = 0; + (void)TkGetStringFromObj(entryPtr->entry.placeholderObj, &rightIndex); + } else { + foregroundObj = es.foregroundObj; + } + gc = EntryGetGC(entryPtr, foregroundObj, clipRegion); if (showSelection) { /* Draw the selected and unselected portions separately. @@ -1343,22 +1386,30 @@ EntryIndex( Tcl_Interp *interp, /* For error messages. */ Entry *entryPtr, /* Entry widget to query */ Tcl_Obj *indexObj, /* Symbolic index name */ - int *indexPtr) /* Return value */ + TkSizeT *indexPtr) /* Return value */ { # define EntryWidth(e) (Tk_Width(entryPtr->core.tkwin)) /* Not Right */ - const char *string = Tcl_GetString(indexObj); - size_t length = indexObj->length; + TkSizeT length, idx; + const char *string; + + if (TCL_OK == TkGetIntForIndex(indexObj, entryPtr->entry.numChars - 1, 1, &idx)) { + if ((idx != TCL_INDEX_NONE) && (idx > entryPtr->entry.numChars)) { + idx = entryPtr->entry.numChars; + } + *indexPtr = idx; + return TCL_OK; + } + + string = TkGetStringFromObj(indexObj, &length); - if (strncmp(string, "end", length) == 0) { - *indexPtr = entryPtr->entry.numChars; - } else if (strncmp(string, "insert", length) == 0) { + if (strncmp(string, "insert", length) == 0) { *indexPtr = entryPtr->entry.insertPos; } else if (strncmp(string, "left", length) == 0) { /* for debugging */ *indexPtr = entryPtr->entry.xscroll.first; } else if (strncmp(string, "right", length) == 0) { /* for debugging */ *indexPtr = entryPtr->entry.xscroll.last; } else if (strncmp(string, "sel.", 4) == 0) { - if (entryPtr->entry.selectFirst < 0) { + if (entryPtr->entry.selectFirst == TCL_INDEX_NONE) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "selection isn't in widget %s", Tk_PathName(entryPtr->core.tkwin))); @@ -1388,7 +1439,7 @@ EntryIndex( x - entryPtr->entry.layoutX, 0); TtkUpdateScrollInfo(entryPtr->entry.xscrollHandle); - if (*indexPtr < entryPtr->entry.xscroll.first) { + if (*indexPtr + 1 < (TkSizeT)entryPtr->entry.xscroll.first + 1) { *indexPtr = entryPtr->entry.xscroll.first; } @@ -1399,18 +1450,11 @@ EntryIndex( * last character to be selected, for example. */ - if (roundUp && (*indexPtr < entryPtr->entry.numChars)) { + if (roundUp && ((TkSizeT)*indexPtr + 1 < entryPtr->entry.numChars + 1 )) { *indexPtr += 1; } } else { - if (Tcl_GetIntFromObj(interp, indexObj, indexPtr) != TCL_OK) { - goto badIndex; - } - if (*indexPtr < 0) { - *indexPtr = 0; - } else if (*indexPtr > entryPtr->entry.numChars) { - *indexPtr = entryPtr->entry.numChars; - } + goto badIndex; } return TCL_OK; @@ -1428,9 +1472,9 @@ static int EntryBBoxCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; Ttk_Box b; - int index; + TkSizeT index; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "index"); @@ -1439,7 +1483,7 @@ EntryBBoxCommand( if (EntryIndex(interp, entryPtr, objv[2], &index) != TCL_OK) { return TCL_ERROR; } - if ((index == entryPtr->entry.numChars) && (index > 0)) { + if ((index == entryPtr->entry.numChars) && (index + 1 > 1)) { index--; } Tk_CharBbox(entryPtr->entry.textLayout, index, @@ -1458,8 +1502,8 @@ static int EntryDeleteCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; - int first, last; + Entry *entryPtr = (Entry *)recordPtr; + TkSizeT first, last; if ((objc < 3) || (objc > 4)) { Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?"); @@ -1474,7 +1518,7 @@ EntryDeleteCommand( return TCL_ERROR; } - if (last >= first && EntryEditable(entryPtr)) { + if (last + 1 >= first + 1 && EntryEditable(entryPtr)) { return DeleteChars(entryPtr, first, last - first); } return TCL_OK; @@ -1487,7 +1531,7 @@ static int EntryGetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, NULL); return TCL_ERROR; @@ -1503,7 +1547,7 @@ static int EntryICursorCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "pos"); return TCL_ERROR; @@ -1523,8 +1567,8 @@ static int EntryIndexCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; - int index; + Entry *entryPtr = (Entry *)recordPtr; + TkSizeT index; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "string"); @@ -1533,7 +1577,7 @@ EntryIndexCommand( if (EntryIndex(interp, entryPtr, objv[2], &index) != TCL_OK) { return TCL_ERROR; } - Tcl_SetObjResult(interp, Tcl_NewIntObj(index)); + Tcl_SetObjResult(interp, TkNewIndexObj(index)); return TCL_OK; } @@ -1545,8 +1589,8 @@ static int EntryInsertCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; - int index; + Entry *entryPtr = (Entry *)recordPtr; + TkSizeT index; if (objc != 4) { Tcl_WrongNumArgs(interp, 2, objv, "index text"); @@ -1567,13 +1611,13 @@ EntryInsertCommand( static int EntrySelectionClearCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); return TCL_ERROR; } - entryPtr->entry.selectFirst = entryPtr->entry.selectLast = -1; + entryPtr->entry.selectFirst = entryPtr->entry.selectLast = TCL_INDEX_NONE; TtkRedisplayWidget(&entryPtr->core); return TCL_OK; } @@ -1584,13 +1628,13 @@ static int EntrySelectionClearCommand( static int EntrySelectionPresentCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); return TCL_ERROR; } Tcl_SetObjResult(interp, - Tcl_NewBooleanObj(entryPtr->entry.selectFirst >= 0)); + Tcl_NewWideIntObj(entryPtr->entry.selectFirst != TCL_INDEX_NONE)); return TCL_OK; } @@ -1600,13 +1644,13 @@ static int EntrySelectionPresentCommand( static int EntrySelectionRangeCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; - int start, end; + Entry *entryPtr = (Entry *)recordPtr; + TkSizeT start, end; if (objc != 5) { Tcl_WrongNumArgs(interp, 3, objv, "start end"); return TCL_ERROR; } - if ( EntryIndex(interp, entryPtr, objv[3], &start) != TCL_OK + if (EntryIndex(interp, entryPtr, objv[3], &start) != TCL_OK || EntryIndex(interp, entryPtr, objv[4], &end) != TCL_OK) { return TCL_ERROR; } @@ -1614,8 +1658,8 @@ static int EntrySelectionRangeCommand( return TCL_OK; } - if (start >= end) { - entryPtr->entry.selectFirst = entryPtr->entry.selectLast = -1; + if (start + 1 >= end + 1 ) { + entryPtr->entry.selectFirst = entryPtr->entry.selectLast = TCL_INDEX_NONE; } else { entryPtr->entry.selectFirst = start; entryPtr->entry.selectLast = end; @@ -1638,7 +1682,7 @@ static const Ttk_Ensemble EntrySelectionCommands[] = { static int EntrySetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "value"); return TCL_ERROR; @@ -1654,7 +1698,7 @@ static int EntrySetCommand( static int EntryValidateCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int code; if (objc != 2) { @@ -1676,9 +1720,9 @@ static int EntryValidateCommand( static int EntryXViewCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc == 3) { - int newFirst; + TkSizeT newFirst; if (EntryIndex(interp, entryPtr, objv[2], &newFirst) != TCL_OK) { return TCL_ERROR; } @@ -1710,7 +1754,7 @@ static const Ttk_Ensemble EntryCommands[] = { * +++ Entry widget definition. */ -static WidgetSpec EntryWidgetSpec = { +static const WidgetSpec EntryWidgetSpec = { "TEntry", /* className */ sizeof(Entry), /* recordSize */ EntryOptionSpecs, /* optionSpecs */ @@ -1726,16 +1770,6 @@ static WidgetSpec EntryWidgetSpec = { }; /*------------------------------------------------------------------------ - * Named indices for the combobox "current" command - */ -static const char *const comboboxCurrentIndexNames[] = { - "end", NULL -}; -enum comboboxCurrentIndices { - INDEX_END -}; - -/*------------------------------------------------------------------------ * +++ Combobox widget record. */ @@ -1743,7 +1777,7 @@ typedef struct { Tcl_Obj *postCommandObj; Tcl_Obj *valuesObj; Tcl_Obj *heightObj; - int currentIndex; + TkSizeT currentIndex; } ComboboxPart; typedef struct { @@ -1752,15 +1786,15 @@ typedef struct { ComboboxPart combobox; } Combobox; -static Tk_OptionSpec ComboboxOptionSpecs[] = { +static const Tk_OptionSpec ComboboxOptionSpecs[] = { {TK_OPTION_STRING, "-height", "height", "Height", - DEF_LIST_HEIGHT, Tk_Offset(Combobox, combobox.heightObj), -1, + DEF_LIST_HEIGHT, offsetof(Combobox, combobox.heightObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-postcommand", "postCommand", "PostCommand", - "", Tk_Offset(Combobox, combobox.postCommandObj), -1, + "", offsetof(Combobox, combobox.postCommandObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-values", "values", "Values", - "", Tk_Offset(Combobox, combobox.valuesObj), -1, + "", offsetof(Combobox, combobox.valuesObj), TCL_INDEX_NONE, 0,0,0 }, WIDGET_INHERIT_OPTIONS(EntryOptionSpecs) }; @@ -1771,9 +1805,9 @@ static Tk_OptionSpec ComboboxOptionSpecs[] = { static void ComboboxInitialize(Tcl_Interp *interp, void *recordPtr) { - Combobox *cb = recordPtr; + Combobox *cb = (Combobox *)recordPtr; - cb->combobox.currentIndex = -1; + cb->combobox.currentIndex = TCL_INDEX_NONE; TtkTrackElementState(&cb->core); EntryInitialize(interp, recordPtr); } @@ -1784,7 +1818,7 @@ ComboboxInitialize(Tcl_Interp *interp, void *recordPtr) static int ComboboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Combobox *cbPtr = recordPtr; + Combobox *cbPtr = (Combobox *)recordPtr; int unused; /* Make sure -values is a valid list: @@ -1804,78 +1838,58 @@ ComboboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask) static int ComboboxCurrentCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Combobox *cbPtr = recordPtr; - int currentIndex = cbPtr->combobox.currentIndex; + Combobox *cbPtr = (Combobox *)recordPtr; + TkSizeT currentIndex = cbPtr->combobox.currentIndex; const char *currentValue = cbPtr->entry.string; int nValues; Tcl_Obj **values; - Tcl_ListObjGetElements(interp,cbPtr->combobox.valuesObj,&nValues,&values); + Tcl_ListObjGetElements(interp, cbPtr->combobox.valuesObj, &nValues, &values); if (objc == 2) { /* Check if currentIndex still valid: */ - if ( currentIndex < 0 - || currentIndex >= nValues + if (currentIndex == TCL_INDEX_NONE + || currentIndex >= (TkSizeT)nValues || strcmp(currentValue,Tcl_GetString(values[currentIndex])) ) { /* Not valid. Check current value against each element in -values: */ - for (currentIndex = 0; currentIndex < nValues; ++currentIndex) { + for (currentIndex = 0; currentIndex < (TkSizeT)nValues; ++currentIndex) { if (!strcmp(currentValue,Tcl_GetString(values[currentIndex]))) { break; } } - if (currentIndex >= nValues) { + if (currentIndex >= (TkSizeT)nValues) { /* Not found */ - currentIndex = -1; + currentIndex = TCL_INDEX_NONE; } } cbPtr->combobox.currentIndex = currentIndex; - Tcl_SetObjResult(interp, Tcl_NewIntObj(currentIndex)); + Tcl_SetObjResult(interp, TkNewIndexObj(currentIndex)); return TCL_OK; } else if (objc == 3) { - int result, index; - - result = Tcl_GetIndexFromObj(NULL, objv[2], comboboxCurrentIndexNames, - "", 0, &index); - if (result == TCL_OK) { - - /* - * The index is one of the named indices. - */ + TkSizeT idx; - switch (index) { - case INDEX_END: - /* "end" index */ - currentIndex = nValues - 1; - break; - } - } else { - - /* - * The index should be just an integer. - */ - - if (Tcl_GetIntFromObj(NULL, objv[2], ¤tIndex) != TCL_OK) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Incorrect index %s", Tcl_GetString(objv[2]))); - Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_VALUE", NULL); - return TCL_ERROR; - } - - if (currentIndex < 0 || currentIndex >= nValues) { + if (TCL_OK == TkGetIntForIndex(objv[2], nValues - 1, 0, &idx)) { + if (idx == TCL_INDEX_NONE || idx > (TkSizeT)nValues) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Index %s out of range", Tcl_GetString(objv[2]))); + "index \"%s\" out of range", Tcl_GetString(objv[2]))); Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_RANGE", NULL); return TCL_ERROR; } - } + currentIndex = idx; + } else { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Incorrect index %s", Tcl_GetString(objv[2]))); + Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_VALUE", NULL); + return TCL_ERROR; + } cbPtr->combobox.currentIndex = currentIndex; - return EntrySetValue(recordPtr, Tcl_GetString(values[currentIndex])); + return EntrySetValue((Entry *)recordPtr, Tcl_GetString(values[currentIndex])); } else { Tcl_WrongNumArgs(interp, 2, objv, "?newIndex?"); return TCL_ERROR; @@ -1906,7 +1920,7 @@ static const Ttk_Ensemble ComboboxCommands[] = { { 0,0,0 } }; -static WidgetSpec ComboboxWidgetSpec = { +static const WidgetSpec ComboboxWidgetSpec = { "TCombobox", /* className */ sizeof(Combobox), /* recordSize */ ComboboxOptionSpecs, /* optionSpecs */ @@ -1943,29 +1957,29 @@ typedef struct { SpinboxPart spinbox; } Spinbox; -static Tk_OptionSpec SpinboxOptionSpecs[] = { +static const Tk_OptionSpec SpinboxOptionSpecs[] = { {TK_OPTION_STRING, "-values", "values", "Values", - "", Tk_Offset(Spinbox, spinbox.valuesObj), -1, + "", offsetof(Spinbox, spinbox.valuesObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_DOUBLE, "-from", "from", "From", - "0", Tk_Offset(Spinbox,spinbox.fromObj), -1, + "0", offsetof(Spinbox,spinbox.fromObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_DOUBLE, "-to", "to", "To", - "0", Tk_Offset(Spinbox,spinbox.toObj), -1, + "0", offsetof(Spinbox,spinbox.toObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_DOUBLE, "-increment", "increment", "Increment", - "1", Tk_Offset(Spinbox,spinbox.incrementObj), -1, + "1", offsetof(Spinbox,spinbox.incrementObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-format", "format", "Format", - "", Tk_Offset(Spinbox, spinbox.formatObj), -1, + "", offsetof(Spinbox, spinbox.formatObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-command", "command", "Command", - "", Tk_Offset(Spinbox, spinbox.commandObj), -1, + "", offsetof(Spinbox, spinbox.commandObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_BOOLEAN, "-wrap", "wrap", "Wrap", - "0", Tk_Offset(Spinbox,spinbox.wrapObj), -1, + "0", offsetof(Spinbox,spinbox.wrapObj), TCL_INDEX_NONE, 0,0,0 }, WIDGET_INHERIT_OPTIONS(EntryOptionSpecs) @@ -1977,7 +1991,7 @@ static Tk_OptionSpec SpinboxOptionSpecs[] = { static void SpinboxInitialize(Tcl_Interp *interp, void *recordPtr) { - Spinbox *sb = recordPtr; + Spinbox *sb = (Spinbox *)recordPtr; TtkTrackElementState(&sb->core); EntryInitialize(interp, recordPtr); } @@ -1988,7 +2002,7 @@ SpinboxInitialize(Tcl_Interp *interp, void *recordPtr) static int SpinboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Spinbox *sb = recordPtr; + Spinbox *sb = (Spinbox *)recordPtr; int unused; /* Make sure -values is a valid list: @@ -2018,7 +2032,7 @@ static const Ttk_Ensemble SpinboxCommands[] = { { 0,0,0 } }; -static WidgetSpec SpinboxWidgetSpec = { +static const WidgetSpec SpinboxWidgetSpec = { "TSpinbox", /* className */ sizeof(Spinbox), /* recordSize */ SpinboxOptionSpecs, /* optionSpecs */ @@ -2045,23 +2059,25 @@ typedef struct { Tcl_Obj *widthObj; } TextareaElement; -static Ttk_ElementOptionSpec TextareaElementOptions[] = { +static const Ttk_ElementOptionSpec TextareaElementOptions[] = { { "-font", TK_OPTION_FONT, - Tk_Offset(TextareaElement,fontObj), DEF_ENTRY_FONT }, + offsetof(TextareaElement,fontObj), DEF_ENTRY_FONT }, { "-width", TK_OPTION_INT, - Tk_Offset(TextareaElement,widthObj), "20" }, - { NULL, 0, 0, NULL } + offsetof(TextareaElement,widthObj), "20" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void TextareaElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - TextareaElement *textarea = elementRecord; + TextareaElement *textarea = (TextareaElement *)elementRecord; Tk_Font font = Tk_GetFontFromObj(tkwin, textarea->fontObj); int avgWidth = Tk_TextWidth(font, "0", 1); Tk_FontMetrics fm; int prefWidth = 1; + (void)dummy; + (void)paddingPtr; Tk_GetFontMetrics(font, &fm); Tcl_GetIntFromObj(NULL, textarea->widthObj, &prefWidth); @@ -2072,7 +2088,7 @@ static void TextareaElementSize( *widthPtr = prefWidth * avgWidth; } -static Ttk_ElementSpec TextareaElementSpec = { +static const Ttk_ElementSpec TextareaElementSpec = { TK_STYLE_VERSION_2, sizeof(TextareaElement), TextareaElementOptions, diff --git a/generic/ttk/ttkFrame.c b/generic/ttk/ttkFrame.c index 931c037..9e8fc82 100644 --- a/generic/ttk/ttkFrame.c +++ b/generic/ttk/ttkFrame.c @@ -26,21 +26,21 @@ typedef struct { FramePart frame; } Frame; -static Tk_OptionSpec FrameOptionSpecs[] = { +static const Tk_OptionSpec FrameOptionSpecs[] = { {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", NULL, - Tk_Offset(Frame,frame.borderWidthObj), -1, + offsetof(Frame,frame.borderWidthObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-padding", "padding", "Pad", NULL, - Tk_Offset(Frame,frame.paddingObj), -1, + offsetof(Frame,frame.paddingObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", NULL, - Tk_Offset(Frame,frame.reliefObj), -1, + offsetof(Frame,frame.reliefObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_PIXELS, "-width", "width", "Width", "0", - Tk_Offset(Frame,frame.widthObj), -1, + offsetof(Frame,frame.widthObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED }, {TK_OPTION_PIXELS, "-height", "height", "Height", "0", - Tk_Offset(Frame,frame.heightObj), -1, + offsetof(Frame,frame.heightObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED }, WIDGET_TAKEFOCUS_FALSE, @@ -90,7 +90,10 @@ static Ttk_Padding FrameMargins(Frame *framePtr) */ static int FrameSize(void *recordPtr, int *widthPtr, int *heightPtr) { - Frame *framePtr = recordPtr; + Frame *framePtr = (Frame *)recordPtr; + (void)widthPtr; + (void)heightPtr; + Ttk_SetMargins(framePtr->core.tkwin, FrameMargins(framePtr)); return 0; } @@ -111,7 +114,7 @@ static int FrameSize(void *recordPtr, int *widthPtr, int *heightPtr) static int FrameConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Frame *framePtr = recordPtr; + Frame *framePtr = (Frame *)recordPtr; int width, height; /* @@ -145,7 +148,7 @@ static int FrameConfigure(Tcl_Interp *interp, void *recordPtr, int mask) return TtkCoreConfigure(interp, recordPtr, mask); } -static WidgetSpec FrameWidgetSpec = { +static const WidgetSpec FrameWidgetSpec = { "TFrame", /* className */ sizeof(Frame), /* recordSize */ FrameOptionSpecs, /* optionSpecs */ @@ -247,18 +250,18 @@ typedef struct { #define LABELWIDGET_CHANGED 0x100 -static Tk_OptionSpec LabelframeOptionSpecs[] = { +static const Tk_OptionSpec LabelframeOptionSpecs[] = { {TK_OPTION_STRING, "-labelanchor", "labelAnchor", "LabelAnchor", - "nw", Tk_Offset(Labelframe, label.labelAnchorObj),-1, + "nw", offsetof(Labelframe, label.labelAnchorObj),TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-text", "text", "Text", "", - Tk_Offset(Labelframe,label.textObj), -1, + offsetof(Labelframe,label.textObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED }, {TK_OPTION_INT, "-underline", "underline", "Underline", - "-1", Tk_Offset(Labelframe,label.underlineObj), -1, + "-1", offsetof(Labelframe,label.underlineObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_WINDOW, "-labelwidget", "labelWidget", "LabelWidget", NULL, - -1, Tk_Offset(Labelframe,label.labelWidget), + TCL_INDEX_NONE, offsetof(Labelframe,label.labelWidget), TK_OPTION_NULL_OK,0,LABELWIDGET_CHANGED|GEOMETRY_CHANGED }, WIDGET_INHERIT_OPTIONS(FrameOptionSpecs) @@ -339,11 +342,13 @@ LabelframeLabelSize(Labelframe *lframePtr, int *widthPtr, int *heightPtr) */ static int LabelframeSize(void *recordPtr, int *widthPtr, int *heightPtr) { - Labelframe *lframePtr = recordPtr; + Labelframe *lframePtr = (Labelframe *)recordPtr; WidgetCore *corePtr = &lframePtr->core; Ttk_Padding margins; LabelframeStyle style; int labelWidth, labelHeight; + (void)widthPtr; + (void)heightPtr; LabelframeStyleOptions(lframePtr, &style); @@ -384,7 +389,7 @@ static int LabelframeSize(void *recordPtr, int *widthPtr, int *heightPtr) static Ttk_Layout LabelframeGetLayout( Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr) { - Labelframe *lf = recordPtr; + Labelframe *lf = (Labelframe *)recordPtr; Ttk_Layout frameLayout = TtkWidgetGetLayout(interp, theme, recordPtr); Ttk_Layout labelLayout; @@ -415,7 +420,7 @@ static Ttk_Layout LabelframeGetLayout( static void LabelframeDoLayout(void *recordPtr) { - Labelframe *lframePtr = recordPtr; + Labelframe *lframePtr = (Labelframe *)recordPtr; WidgetCore *corePtr = &lframePtr->core; int lw, lh; /* Label width and height */ LabelframeStyle style; @@ -461,7 +466,7 @@ static void LabelframeDoLayout(void *recordPtr) static void LabelframeDisplay(void *recordPtr, Drawable d) { - Labelframe *lframePtr = recordPtr; + Labelframe *lframePtr = (Labelframe *)recordPtr; Ttk_DrawLayout(lframePtr->core.layout, lframePtr->core.state, d); if (lframePtr->label.labelLayout) { Ttk_DrawLayout(lframePtr->label.labelLayout, lframePtr->core.state, d); @@ -476,7 +481,7 @@ static void LabelframeDisplay(void *recordPtr, Drawable d) */ static void LabelframePlaceContent(void *recordPtr) { - Labelframe *lframe = recordPtr; + Labelframe *lframe = (Labelframe *)recordPtr; if (Ttk_NumberContent(lframe->label.mgr) == 1) { Ttk_Box b; @@ -487,12 +492,13 @@ static void LabelframePlaceContent(void *recordPtr) } } -static int LabelRequest( - void *managerData, - int index, - int width, - int height) +static int LabelRequest(void *managerData, TkSizeT index, int width, int height) { + (void)managerData; + (void)index; + (void)width; + (void)height; + return 1; } @@ -501,13 +507,14 @@ static int LabelRequest( * * <<NOTE-LABELREMOVED>>: * This routine is also called when the widget voluntarily forgets - * the slave in LabelframeConfigure. + * the window in LabelframeConfigure. */ static void LabelRemoved( void *managerData, - TCL_UNUSED(int)) + TCL_UNUSED(TkSizeT)) { - Labelframe *lframe = managerData; + Labelframe *lframe = (Labelframe *)managerData; + lframe->label.labelWidget = 0; } @@ -522,9 +529,10 @@ static Ttk_ManagerSpec LabelframeManagerSpec = { /* LabelframeInitialize -- * Initialization hook. */ -static void LabelframeInitialize(Tcl_Interp *interp, void *recordPtr) +static void LabelframeInitialize(Tcl_Interp *dummy, void *recordPtr) { - Labelframe *lframe = recordPtr; + Labelframe *lframe = (Labelframe *)recordPtr; + (void)dummy; lframe->label.mgr = Ttk_CreateManager( &LabelframeManagerSpec, lframe, lframe->core.tkwin); @@ -538,7 +546,7 @@ static void LabelframeInitialize(Tcl_Interp *interp, void *recordPtr) */ static void LabelframeCleanup(void *recordPtr) { - Labelframe *lframe = recordPtr; + Labelframe *lframe = (Labelframe *)recordPtr; Ttk_DeleteManager(lframe->label.mgr); if (lframe->label.labelLayout) { Ttk_FreeLayout(lframe->label.labelLayout); @@ -569,7 +577,7 @@ static void RaiseLabelWidget(Labelframe *lframe) */ static int LabelframeConfigure(Tcl_Interp *interp,void *recordPtr,int mask) { - Labelframe *lframePtr = recordPtr; + Labelframe *lframePtr = (Labelframe *)recordPtr; Tk_Window labelWidget = lframePtr->label.labelWidget; Ttk_PositionSpec unused; @@ -617,7 +625,7 @@ static int LabelframeConfigure(Tcl_Interp *interp,void *recordPtr,int mask) return TCL_OK; } -static WidgetSpec LabelframeWidgetSpec = { +static const WidgetSpec LabelframeWidgetSpec = { "TLabelframe", /* className */ sizeof(Labelframe), /* recordSize */ LabelframeOptionSpecs, /* optionSpecs */ diff --git a/generic/ttk/ttkGenStubs.tcl b/generic/ttk/ttkGenStubs.tcl deleted file mode 100644 index 8047e3f..0000000 --- a/generic/ttk/ttkGenStubs.tcl +++ /dev/null @@ -1,963 +0,0 @@ -# ttkGenStubs.tcl -- -# -# This script generates a set of stub files for a given -# interface. -# -# -# Copyright (c) 1998-1999 by Scriptics Corporation. -# Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net> -# -# See the file "license.terms" for information on usage and redistribution -# of this file, and for a DISCLAIMER OF ALL WARRANTIES. -# -# SOURCE: tcl/tools/genStubs.tcl, revision 1.44 -# -# CHANGES: -# + Second argument to "declare" is used as a status guard -# instead of a platform guard. -# + Allow trailing semicolon in function declarations -# - -namespace eval genStubs { - # libraryName -- - # - # The name of the entire library. This value is used to compute - # the USE_*_STUBS macro and the name of the init file. - - variable libraryName "UNKNOWN" - - # interfaces -- - # - # An array indexed by interface name that is used to maintain - # the set of valid interfaces. The value is empty. - - array set interfaces {} - - # curName -- - # - # The name of the interface currently being defined. - - variable curName "UNKNOWN" - - # scspec -- - # - # Storage class specifier for external function declarations. - # Normally "EXTERN", may be set to something like XYZAPI - # - variable scspec "EXTERN" - - # epoch, revision -- - # - # The epoch and revision numbers of the interface currently being defined. - # (@@@TODO: should be an array mapping interface names -> numbers) - # - - variable epoch {} - variable revision 0 - - # hooks -- - # - # An array indexed by interface name that contains the set of - # subinterfaces that should be defined for a given interface. - - array set hooks {} - - # stubs -- - # - # This three dimensional array is indexed first by interface name, - # second by field name, and third by a numeric offset or the - # constant "lastNum". The lastNum entry contains the largest - # numeric offset used for a given interface. - # - # Field "decl,$i" contains the C function specification that - # should be used for the given entry in the stub table. The spec - # consists of a list in the form returned by parseDecl. - # Other fields TBD later. - - array set stubs {} - - # outDir -- - # - # The directory where the generated files should be placed. - - variable outDir . -} - -# genStubs::library -- -# -# This function is used in the declarations file to set the name -# of the library that the interfaces are associated with (e.g. "tcl"). -# This value will be used to define the inline conditional macro. -# -# Arguments: -# name The library name. -# -# Results: -# None. - -proc genStubs::library {name} { - variable libraryName $name -} - -# genStubs::interface -- -# -# This function is used in the declarations file to set the name -# of the interface currently being defined. -# -# Arguments: -# name The name of the interface. -# -# Results: -# None. - -proc genStubs::interface {name} { - variable curName $name - variable interfaces - variable stubs - - set interfaces($name) {} - set stubs($name,lastNum) 0 - return -} - -# genStubs::scspec -- -# -# Define the storage class macro used for external function declarations. -# Typically, this will be a macro like XYZAPI or EXTERN that -# expands to either DLLIMPORT or DLLEXPORT, depending on whether -# -DBUILD_XYZ has been set. -# -proc genStubs::scspec {value} { - variable scspec $value -} - -# genStubs::epoch -- -# -# Define the epoch number for this library. The epoch -# should be incrememented when a release is made that -# contains incompatible changes to the public API. -# -proc genStubs::epoch {value} { - variable epoch $value -} - -# genStubs::hooks -- -# -# This function defines the subinterface hooks for the current -# interface. -# -# Arguments: -# names The ordered list of interfaces that are reachable through the -# hook vector. -# -# Results: -# None. - -proc genStubs::hooks {names} { - variable curName - variable hooks - - set hooks($curName) $names - return -} - -# genStubs::declare -- -# -# This function is used in the declarations file to declare a new -# interface entry. -# -# Arguments: -# index The index number of the interface. -# status Status of the interface: one of "current", -# "deprecated", or "obsolete". -# decl The C function declaration, or {} for an undefined -# entry. -# -# Results: -# None. - -proc genStubs::declare {args} { - variable stubs - variable curName - variable revision - - incr revision - if {[llength $args] == 2} { - lassign $args index decl - set status current - } elseif {[llength $args] == 3} { - lassign $args index status decl - } else { - puts stderr "wrong # args: declare $args" - return - } - - # Check for duplicate declarations, then add the declaration and - # bump the lastNum counter if necessary. - - if {[info exists stubs($curName,decl,$index)]} { - puts stderr "Duplicate entry: $index" - } - regsub -all "\[ \t\n\]+" [string trim $decl] " " decl - set decl [parseDecl $decl] - - set stubs($curName,status,$index) $status - set stubs($curName,decl,$index) $decl - - if {$index > $stubs($curName,lastNum)} { - set stubs($curName,lastNum) $index - } - return -} - -# genStubs::export -- -# -# This function is used in the declarations file to declare a symbol -# that is exported from the library but is not in the stubs table. -# -# Arguments: -# decl The C function declaration, or {} for an undefined -# entry. -# -# Results: -# None. - -proc genStubs::export {args} { - if {[llength $args] != 1} { - puts stderr "wrong # args: export $args" - } - return -} - -# genStubs::rewriteFile -- -# -# This function replaces the machine generated portion of the -# specified file with new contents. It looks for the !BEGIN! and -# !END! comments to determine where to place the new text. -# -# Arguments: -# file The name of the file to modify. -# text The new text to place in the file. -# -# Results: -# None. - -proc genStubs::rewriteFile {file text} { - if {![file exists $file]} { - puts stderr "Cannot find file: $file" - return - } - set in [open ${file} r] - set out [open ${file}.new w] - fconfigure $out -translation lf - - while {![eof $in]} { - set line [gets $in] - if {[string match "*!BEGIN!*" $line]} { - break - } - puts $out $line - } - puts $out "/* !BEGIN!: Do not edit below this line. */" - puts $out $text - while {![eof $in]} { - set line [gets $in] - if {[string match "*!END!*" $line]} { - break - } - } - puts $out "/* !END!: Do not edit above this line. */" - puts -nonewline $out [read $in] - close $in - close $out - file rename -force ${file}.new ${file} - return -} - -# genStubs::addPlatformGuard -- -# -# Wrap a string inside a platform #ifdef. -# -# Arguments: -# plat Platform to test. -# -# Results: -# Returns the original text inside an appropriate #ifdef. - -proc genStubs::addPlatformGuard {plat iftxt {eltxt {}}} { - set text "" - switch $plat { - win { - append text "#ifdef _WIN32 /* WIN */\n${iftxt}" - if {$eltxt ne ""} { - append text "#else /* WIN */\n${eltxt}" - } - append text "#endif /* WIN */\n" - } - unix { - append text "#if !defined(_WIN32) && !defined(MAC_OSX_TCL)\ - /* UNIX */\n${iftxt}" - if {$eltxt ne ""} { - append text "#else /* UNIX */\n${eltxt}" - } - append text "#endif /* UNIX */\n" - } - macosx { - append text "#ifdef MAC_OSX_TCL /* MACOSX */\n${iftxt}" - if {$eltxt ne ""} { - append text "#else /* MACOSX */\n${eltxt}" - } - append text "#endif /* MACOSX */\n" - } - aqua { - append text "#ifdef MAC_OSX_TK /* AQUA */\n${iftxt}" - if {$eltxt ne ""} { - append text "#else /* AQUA */\n${eltxt}" - } - append text "#endif /* AQUA */\n" - } - x11 { - append text "#if !(defined(_WIN32) || defined(MAC_OSX_TK))\ - /* X11 */\n${iftxt}" - if {$eltxt ne ""} { - append text "#else /* X11 */\n${eltxt}" - } - append text "#endif /* X11 */\n" - } - default { - append text "${iftxt}${eltxt}" - } - } - return $text -} - -# genStubs::emitSlots -- -# -# Generate the stub table slots for the given interface. If there -# are no generic slots, then one table is generated for each -# platform, otherwise one table is generated for all platforms. -# -# Arguments: -# name The name of the interface being emitted. -# textVar The variable to use for output. -# -# Results: -# None. - -proc genStubs::emitSlots {name textVar} { - upvar $textVar text - - forAllStubs $name makeSlot noGuard text {" void (*reserved$i)(void);\n"} - return -} - -# genStubs::parseDecl -- -# -# Parse a C function declaration into its component parts. -# -# Arguments: -# decl The function declaration. -# -# Results: -# Returns a list of the form {returnType name args}. The args -# element consists of a list of type/name pairs, or a single -# element "void". If the function declaration is malformed -# then an error is displayed and the return value is {}. - -proc genStubs::parseDecl {decl} { - if {![regexp {^(.*)\((.*)\);?$} $decl all prefix args]} { - set prefix $decl - set args {} - } - set prefix [string trim $prefix] - if {![regexp {^(.+[ ][*]*)([^ *]+)$} $prefix all rtype fname]} { - puts stderr "Bad return type: $decl" - return - } - set rtype [string trim $rtype] - if {$args eq ""} { - return [list $rtype $fname {}] - } - foreach arg [split $args ,] { - lappend argList [string trim $arg] - } - if {![string compare [lindex $argList end] "..."]} { - set args TCL_VARARGS - foreach arg [lrange $argList 0 end-1] { - set argInfo [parseArg $arg] - if {[llength $argInfo] == 2 || [llength $argInfo] == 3} { - lappend args $argInfo - } else { - puts stderr "Bad argument: '$arg' in '$decl'" - return - } - } - } else { - set args {} - foreach arg $argList { - set argInfo [parseArg $arg] - if {![string compare $argInfo "void"]} { - lappend args "void" - break - } elseif {[llength $argInfo] == 2 || [llength $argInfo] == 3} { - lappend args $argInfo - } else { - puts stderr "Bad argument: '$arg' in '$decl'" - return - } - } - } - return [list $rtype $fname $args] -} - -# genStubs::parseArg -- -# -# This function parses a function argument into a type and name. -# -# Arguments: -# arg The argument to parse. -# -# Results: -# Returns a list of type and name with an optional third array -# indicator. If the argument is malformed, returns "". - -proc genStubs::parseArg {arg} { - if {![regexp {^(.+[ ][*]*)([^][ *]+)(\[\])?$} $arg all type name array]} { - if {$arg eq "void"} { - return $arg - } else { - return - } - } - set result [list [string trim $type] $name] - if {$array ne ""} { - lappend result $array - } - return $result -} - -# genStubs::makeDecl -- -# -# Generate the prototype for a function. -# -# Arguments: -# name The interface name. -# decl The function declaration. -# index The slot index for this function. -# -# Results: -# Returns the formatted declaration string. - -proc genStubs::makeDecl {name decl index} { - variable scspec - lassign $decl rtype fname args - - append text "/* $index */\n" - set line "$scspec $rtype" - set count [expr {2 - ([string length $line] / 8)}] - append line [string range "\t\t\t" 0 $count] - set pad [expr {24 - [string length $line]}] - if {$pad <= 0} { - append line " " - set pad 0 - } - if {$args eq ""} { - append line $fname - append text $line - append text ";\n" - return $text - } - append line $fname - - set arg1 [lindex $args 0] - switch -exact $arg1 { - void { - append line "(void)" - } - TCL_VARARGS { - set sep "(" - foreach arg [lrange $args 1 end] { - append line $sep - set next {} - append next [lindex $arg 0] - if {[string index $next end] ne "*"} { - append next " " - } - append next [lindex $arg 1] [lindex $arg 2] - if {[string length $line] + [string length $next] \ - + $pad > 76} { - append text [string trimright $line] \n - set line "\t\t\t\t" - set pad 28 - } - append line $next - set sep ", " - } - append line ", ...)" - } - default { - set sep "(" - foreach arg $args { - append line $sep - set next {} - append next [lindex $arg 0] - if {[string index $next end] ne "*"} { - append next " " - } - append next [lindex $arg 1] [lindex $arg 2] - if {[string length $line] + [string length $next] \ - + $pad > 76} { - append text [string trimright $line] \n - set line "\t\t\t\t" - set pad 28 - } - append line $next - set sep ", " - } - append line ")" - } - } - return "$text$line;\n" -} - -# genStubs::makeMacro -- -# -# Generate the inline macro for a function. -# -# Arguments: -# name The interface name. -# decl The function declaration. -# index The slot index for this function. -# -# Results: -# Returns the formatted macro definition. - -proc genStubs::makeMacro {name decl index} { - lassign $decl rtype fname args - - set lfname [string tolower [string index $fname 0]] - append lfname [string range $fname 1 end] - - set text "#define $fname \\\n\t(" - if {$args eq ""} { - append text "*" - } - append text "${name}StubsPtr->$lfname)" - append text " /* $index */\n" - return $text -} - -# genStubs::makeSlot -- -# -# Generate the stub table entry for a function. -# -# Arguments: -# name The interface name. -# decl The function declaration. -# index The slot index for this function. -# -# Results: -# Returns the formatted table entry. - -proc genStubs::makeSlot {name decl index} { - lassign $decl rtype fname args - - set lfname [string tolower [string index $fname 0]] - append lfname [string range $fname 1 end] - - set text " " - if {$args eq ""} { - append text $rtype " *" $lfname "; /* $index */\n" - return $text - } - if {[string range $rtype end-8 end] eq "__stdcall"} { - append text [string trim [string range $rtype 0 end-9]] " (__stdcall *" $lfname ") " - } else { - append text $rtype " (*" $lfname ") " - } - set arg1 [lindex $args 0] - switch -exact $arg1 { - void { - append text "(void)" - } - TCL_VARARGS { - set sep "(" - foreach arg [lrange $args 1 end] { - append text $sep [lindex $arg 0] - if {[string index $text end] ne "*"} { - append text " " - } - append text [lindex $arg 1] [lindex $arg 2] - set sep ", " - } - append text ", ...)" - } - default { - set sep "(" - foreach arg $args { - append text $sep [lindex $arg 0] - if {[string index $text end] ne "*"} { - append text " " - } - append text [lindex $arg 1] [lindex $arg 2] - set sep ", " - } - append text ")" - } - } - - append text "; /* $index */\n" - return $text -} - -# genStubs::makeInit -- -# -# Generate the prototype for a function. -# -# Arguments: -# name The interface name. -# decl The function declaration. -# index The slot index for this function. -# -# Results: -# Returns the formatted declaration string. - -proc genStubs::makeInit {name decl index} { - if {[lindex $decl 2] eq ""} { - append text " &" [lindex $decl 1] ", /* " $index " */\n" - } else { - append text " " [lindex $decl 1] ", /* " $index " */\n" - } - return $text -} - -# genStubs::forAllStubs -- -# -# This function iterates over all of the slots and invokes -# a callback for each slot. The result of the callback is then -# placed inside appropriate guards. -# -# Arguments: -# name The interface name. -# slotProc The proc to invoke to handle the slot. It will -# have the interface name, the declaration, and -# the index appended. -# guardProc The proc to invoke to add guards. It will have -# the slot status and text appended. -# textVar The variable to use for output. -# skipString The string to emit if a slot is skipped. This -# string will be subst'ed in the loop so "$i" can -# be used to substitute the index value. -# -# Results: -# None. - -proc genStubs::forAllStubs {name slotProc guardProc textVar - {skipString {"/* Slot $i is reserved */\n"}}} { - variable stubs - upvar $textVar text - - set lastNum $stubs($name,lastNum) - - for {set i 0} {$i <= $lastNum} {incr i} { - if {[info exists stubs($name,decl,$i)]} { - append text [$guardProc $stubs($name,status,$i) \ - [$slotProc $name $stubs($name,decl,$i) $i]] - } else { - eval {append text} $skipString - } - } -} - -proc genStubs::noGuard {status text} { return $text } - -proc genStubs::addGuard {status text} { - variable libraryName - set upName [string toupper $libraryName] - - switch -- $status { - current { - # No change - } - deprecated { - set text [ifdeffed "${upName}_DEPRECATED" $text] - } - obsolete { - set text "" - } - default { - puts stderr "Unrecognized status code $status" - } - } - return $text -} - -proc genStubs::ifdeffed {macro text} { - join [list "#ifdef $macro" $text "#endif" ""] \n -} - -# genStubs::emitDeclarations -- -# -# This function emits the function declarations for this interface. -# -# Arguments: -# name The interface name. -# textVar The variable to use for output. -# -# Results: -# None. - -proc genStubs::emitDeclarations {name textVar} { - upvar $textVar text - - append text "\n/*\n * Exported function declarations:\n */\n\n" - forAllStubs $name makeDecl noGuard text - return -} - -# genStubs::emitMacros -- -# -# This function emits the inline macros for an interface. -# -# Arguments: -# name The name of the interface being emitted. -# textVar The variable to use for output. -# -# Results: -# None. - -proc genStubs::emitMacros {name textVar} { - variable libraryName - upvar $textVar text - - set upName [string toupper $libraryName] - append text "\n#if defined(USE_${upName}_STUBS)\n" - append text "\n/*\n * Inline function declarations:\n */\n\n" - - forAllStubs $name makeMacro addGuard text - - append text "\n#endif /* defined(USE_${upName}_STUBS) */\n" - return -} - -# genStubs::emitHeader -- -# -# This function emits the body of the <name>Decls.h file for -# the specified interface. -# -# Arguments: -# name The name of the interface being emitted. -# -# Results: -# None. - -proc genStubs::emitHeader {name} { - variable outDir - variable hooks - variable epoch - variable revision - - set capName [string toupper [string index $name 0]] - append capName [string range $name 1 end] - - if {$epoch ne ""} { - set CAPName [string toupper $name] - append text "\n" - append text "#define ${CAPName}_STUBS_EPOCH $epoch\n" - append text "#define ${CAPName}_STUBS_REVISION $revision\n" - } - - append text "\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n" - - emitDeclarations $name text - - if {[info exists hooks($name)]} { - append text "\ntypedef struct {\n" - foreach hook $hooks($name) { - set capHook [string toupper [string index $hook 0]] - append capHook [string range $hook 1 end] - append text " const struct ${capHook}Stubs *${hook}Stubs;\n" - } - append text "} ${capName}StubHooks;\n" - } - append text "\ntypedef struct ${capName}Stubs {\n" - append text " int magic;\n" - if {$epoch ne ""} { - append text " int epoch;\n" - append text " int revision;\n" - } - if {[info exists hooks($name)]} { - append text " const ${capName}StubHooks *hooks;\n\n" - } else { - append text " void *hooks;\n\n" - } - - emitSlots $name text - - append text "} ${capName}Stubs;\n\n" - - append text "extern const ${capName}Stubs *${name}StubsPtr;\n\n" - append text "#ifdef __cplusplus\n}\n#endif\n" - - emitMacros $name text - - rewriteFile [file join $outDir ${name}Decls.h] $text - return -} - -# genStubs::emitInit -- -# -# Generate the table initializers for an interface. -# -# Arguments: -# name The name of the interface to initialize. -# textVar The variable to use for output. -# -# Results: -# Returns the formatted output. - -proc genStubs::emitInit {name textVar} { - variable hooks - variable interfaces - variable epoch - upvar $textVar text - set root 1 - - set capName [string toupper [string index $name 0]] - append capName [string range $name 1 end] - - if {[info exists hooks($name)]} { - append text "\nstatic const ${capName}StubHooks ${name}StubHooks = \{\n" - set sep " " - foreach sub $hooks($name) { - append text $sep "&${sub}Stubs" - set sep ",\n " - } - append text "\n\};\n" - } - foreach intf [array names interfaces] { - if {[info exists hooks($intf)]} { - if {[lsearch -exact $hooks($intf) $name] >= 0} { - set root 0 - break - } - } - } - - append text "\n" - if {!$root} { - append text "static " - } - append text "const ${capName}Stubs ${name}Stubs = \{\n TCL_STUB_MAGIC,\n" - if {$epoch ne ""} { - set CAPName [string toupper $name] - append text " ${CAPName}_STUBS_EPOCH,\n" - append text " ${CAPName}_STUBS_REVISION,\n" - } - if {[info exists hooks($name)]} { - append text " &${name}StubHooks,\n" - } else { - append text " 0,\n" - } - - forAllStubs $name makeInit noGuard text {" 0, /* $i */\n"} - - append text "\};\n" - return -} - -# genStubs::emitInits -- -# -# This function emits the body of the <name>StubInit.c file for -# the specified interface. -# -# Arguments: -# name The name of the interface being emitted. -# -# Results: -# None. - -proc genStubs::emitInits {} { - variable hooks - variable outDir - variable libraryName - variable interfaces - - # Assuming that dependencies only go one level deep, we need to emit - # all of the leaves first to avoid needing forward declarations. - - set leaves {} - set roots {} - foreach name [lsort [array names interfaces]] { - if {[info exists hooks($name)]} { - lappend roots $name - } else { - lappend leaves $name - } - } - foreach name $leaves { - emitInit $name text - } - foreach name $roots { - emitInit $name text - } - - rewriteFile [file join $outDir ${libraryName}StubInit.c] $text -} - -# genStubs::init -- -# -# This is the main entry point. -# -# Arguments: -# None. -# -# Results: -# None. - -proc genStubs::init {} { - global argv argv0 - variable outDir - variable interfaces - - if {[llength $argv] < 2} { - puts stderr "usage: $argv0 outDir declFile ?declFile...?" - exit 1 - } - - set outDir [lindex $argv 0] - - foreach file [lrange $argv 1 end] { - source $file - } - - foreach name [lsort [array names interfaces]] { - puts "Emitting $name" - emitHeader $name - } - - emitInits -} - -# lassign -- -# -# This function emulates the TclX lassign command. -# -# Arguments: -# valueList A list containing the values to be assigned. -# args The list of variables to be assigned. -# -# Results: -# Returns any values that were not assigned to variables. - -if {[string length [namespace which lassign]] == 0} { - proc lassign {valueList args} { - if {[llength $args] == 0} { - error "wrong # args: should be \"lassign list varName ?varName ...?\"" - } - uplevel [list foreach $args $valueList {break}] - return [lrange $valueList [llength $args] end] - } -} - -genStubs::init diff --git a/generic/ttk/ttkImage.c b/generic/ttk/ttkImage.c index 5c2a55f..e6ad27d 100644 --- a/generic/ttk/ttkImage.c +++ b/generic/ttk/ttkImage.c @@ -10,7 +10,6 @@ * [style map]. */ -#include <string.h> #include "tkInt.h" #include "ttkTheme.h" @@ -32,9 +31,17 @@ struct TtkImageSpec { /* NullImageChanged -- * Do-nothing Tk_ImageChangedProc. */ -static void NullImageChanged(ClientData clientData, +static void NullImageChanged(ClientData dummy, int x, int y, int width, int height, int imageWidth, int imageHeight) -{ /* No-op */ } +{ /* No-op */ + (void)dummy; + (void)x; + (void)y; + (void)width; + (void)height; + (void)imageWidth; + (void)imageHeight; +} /* ImageSpecImageChanged -- * Image changes should trigger a repaint. @@ -75,7 +82,7 @@ TtkGetImageSpecEx(Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, int i = 0, n = 0, objc; Tcl_Obj **objv; - imageSpec = ckalloc(sizeof(*imageSpec)); + imageSpec = (Ttk_ImageSpec *)ckalloc(sizeof(*imageSpec)); imageSpec->baseImage = 0; imageSpec->mapCount = 0; imageSpec->states = 0; @@ -98,8 +105,8 @@ TtkGetImageSpecEx(Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, } n = (objc - 1) / 2; - imageSpec->states = ckalloc(n * sizeof(Ttk_StateSpec)); - imageSpec->images = ckalloc(n * sizeof(Tk_Image *)); + imageSpec->states = (Ttk_StateSpec *)ckalloc(n * sizeof(Ttk_StateSpec)); + imageSpec->images = (Tk_Image *)ckalloc(n * sizeof(Tk_Image)); /* Get base image: */ @@ -206,6 +213,7 @@ static void Ttk_Fill( int dr = dst.x + dst.width; int db = dst.y + dst.height; int x,y; + (void)tkwin; if (!(src.width && src.height && dst.width && dst.height)) return; @@ -263,7 +271,7 @@ typedef struct { /* ClientData for image elements */ static void FreeImageData(void *clientData) { - ImageData *imageData = clientData; + ImageData *imageData = (ImageData *)clientData; if (imageData->imageSpec) { TtkFreeImageSpec(imageData->imageSpec); } #if TILE_07_COMPAT if (imageData->imageMap) { Tcl_DecrRefCount(imageData->imageMap); } @@ -275,8 +283,10 @@ static void ImageElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ImageData *imageData = clientData; + ImageData *imageData = (ImageData *)clientData; Tk_Image image = imageData->imageSpec->baseImage; + (void)elementRecord; + (void)tkwin; if (image) { Tk_SizeOfImage(image, widthPtr, heightPtr); @@ -295,10 +305,11 @@ static void ImageElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - ImageData *imageData = clientData; + ImageData *imageData = (ImageData *)clientData; Tk_Image image = 0; int imgWidth, imgHeight; Ttk_Box src, dst; + (void)elementRecord; #if TILE_07_COMPAT if (imageData->imageMap) { @@ -325,7 +336,7 @@ static void ImageElementDraw( Ttk_Tile(tkwin, d, image, src, dst, imageData->border); } -static Ttk_ElementSpec ImageElementSpec = +static const Ttk_ElementSpec ImageElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), @@ -340,12 +351,12 @@ static Ttk_ElementSpec ImageElementSpec = static int Ttk_CreateImageElement( Tcl_Interp *interp, - void *clientData, + void *dummy, Ttk_Theme theme, const char *elementName, int objc, Tcl_Obj *const objv[]) { - static const char *optionStrings[] = + static const char *const optionStrings[] = { "-border","-height","-padding","-sticky","-width",NULL }; enum { O_BORDER, O_HEIGHT, O_PADDING, O_STICKY, O_WIDTH }; @@ -353,6 +364,7 @@ Ttk_CreateImageElement( ImageData *imageData = 0; int padding_specified = 0; int i; + (void)dummy; if (objc <= 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj( @@ -366,7 +378,7 @@ Ttk_CreateImageElement( return TCL_ERROR; } - imageData = ckalloc(sizeof(*imageData)); + imageData = (ImageData *)ckalloc(sizeof(*imageData)); imageData->imageSpec = imageSpec; imageData->minWidth = imageData->minHeight = -1; imageData->sticky = TTK_FILL_BOTH; diff --git a/generic/ttk/ttkInit.c b/generic/ttk/ttkInit.c index f1b6e26..4a43253 100644 --- a/generic/ttk/ttkInit.c +++ b/generic/ttk/ttkInit.c @@ -4,7 +4,6 @@ * Ttk package: initialization routine and miscellaneous utilities. */ -#include <string.h> #include "tkInt.h" #include "ttkTheme.h" #include "ttkWidget.h" @@ -13,43 +12,50 @@ * Legal values for the button -default option. * See also: enum Ttk_ButtonDefaultState. */ -const char *ttkDefaultStrings[] = { +const char *const ttkDefaultStrings[] = { "normal", "active", "disabled", NULL }; int Ttk_GetButtonDefaultStateFromObj( - Tcl_Interp *interp, Tcl_Obj *objPtr, int *statePtr) + Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_ButtonDefaultState *statePtr) { - *statePtr = TTK_BUTTON_DEFAULT_DISABLED; - return Tcl_GetIndexFromObjStruct(interp, objPtr, ttkDefaultStrings, - sizeof(char *), "default state", 0, statePtr); + int state = (int)TTK_BUTTON_DEFAULT_DISABLED; + int result = Tcl_GetIndexFromObjStruct(interp, objPtr, ttkDefaultStrings, + sizeof(char *), "default state", 0, &state); + + *statePtr = (Ttk_ButtonDefaultState)state; + return result; } /* * Legal values for the -compound option. * See also: enum Ttk_Compound. */ -const char *ttkCompoundStrings[] = { +const char *const ttkCompoundStrings[] = { "none", "text", "image", "center", "top", "bottom", "left", "right", NULL }; int Ttk_GetCompoundFromObj( - Tcl_Interp *interp, Tcl_Obj *objPtr, int *statePtr) + Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Compound *compoundPtr) { - *statePtr = TTK_COMPOUND_NONE; - return Tcl_GetIndexFromObjStruct(interp, objPtr, ttkCompoundStrings, - sizeof(char *), "compound layout", 0, statePtr); + int compound = (int)TTK_COMPOUND_NONE; + int result = Tcl_GetIndexFromObjStruct(interp, objPtr, ttkCompoundStrings, + sizeof(char *), "compound layout", 0, &compound); + + *compoundPtr = (Ttk_Compound)compound; + return result; } /* * Legal values for the -orient option. * See also: enum Ttk_Orient. */ -const char *ttkOrientStrings[] = { +const char *const ttkOrientStrings[] = { "horizontal", "vertical", NULL }; +#if !defined(TK_NO_DEPRECATED) && TK_MAJOR_VERSION < 9 int Ttk_GetOrientFromObj( Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr) { @@ -57,12 +63,24 @@ int Ttk_GetOrientFromObj( return Tcl_GetIndexFromObjStruct(interp, objPtr, ttkOrientStrings, sizeof(char *), "orientation", 0, resultPtr); } +#endif + +int TtkGetOrientFromObj( + Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Orient *resultPtr) +{ + int orient = (int)TTK_ORIENT_HORIZONTAL; + int result = Tcl_GetIndexFromObjStruct(interp, objPtr, ttkOrientStrings, + sizeof(char *), "orientation", 0, &orient); + + *resultPtr = (Ttk_Orient)orient; + return result; +} /* * Recognized values for the -state compatibility option. * Other options are accepted and interpreted as synonyms for "normal". */ -static const char *ttkStateStrings[] = { +static const char *const ttkStateStrings[] = { "normal", "readonly", "disabled", "active", NULL }; enum { @@ -106,28 +124,6 @@ void TtkCheckStateOption(WidgetCore *corePtr, Tcl_Obj *objPtr) # undef SETFLAGS } -/* TtkSendVirtualEvent -- - * Send a virtual event notification to the specified target window. - * Equivalent to "event generate $tgtWindow <<$eventName>>" - * - * Note that we use Tk_QueueWindowEvent, not Tk_HandleEvent, - * so this routine does not reenter the interpreter. - */ -void TtkSendVirtualEvent(Tk_Window tgtWin, const char *eventName) -{ - union {XEvent general; XVirtualEvent virt;} event; - - memset(&event, 0, sizeof(event)); - event.general.xany.type = VirtualEvent; - event.general.xany.serial = NextRequest(Tk_Display(tgtWin)); - event.general.xany.send_event = False; - event.general.xany.window = Tk_WindowId(tgtWin); - event.general.xany.display = Tk_Display(tgtWin); - event.virt.name = Tk_GetUid(eventName); - - Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL); -} - /* TtkEnumerateOptions, TtkGetOptionValue -- * Common factors for data accessor commands. */ @@ -149,7 +145,7 @@ int TtkEnumerateOptions( if (specPtr->type == TK_OPTION_END && specPtr->clientData != NULL) { /* Chain to next option spec array: */ - specPtr = specPtr->clientData; + specPtr = (const Tk_OptionSpec *)specPtr->clientData; } } Tcl_SetObjResult(interp, result); @@ -176,14 +172,14 @@ int TtkGetOptionValue( */ /* public */ -Tk_OptionSpec ttkCoreOptionSpecs[] = +const Tk_OptionSpec ttkCoreOptionSpecs[] = { {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", NULL, - Tk_Offset(WidgetCore, cursorObj), -1, TK_OPTION_NULL_OK,0,0 }, + offsetof(WidgetCore, cursorObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_STRING, "-style", "style", "Style", "", - Tk_Offset(WidgetCore,styleObj), -1, 0,0,STYLE_CHANGED}, + offsetof(WidgetCore,styleObj), TCL_INDEX_NONE, 0,0,STYLE_CHANGED}, {TK_OPTION_STRING, "-class", "", "", NULL, - Tk_Offset(WidgetCore,classObj), -1, 0,0,READONLY_OPTION}, + offsetof(WidgetCore,classObj), TCL_INDEX_NONE, 0,0,READONLY_OPTION}, {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0} }; diff --git a/generic/ttk/ttkLabel.c b/generic/ttk/ttkLabel.c index 6f32299..a4dbf96 100644 --- a/generic/ttk/ttkLabel.c +++ b/generic/ttk/ttkLabel.c @@ -46,25 +46,25 @@ typedef struct { /* Text element options table. * NB: Keep in sync with label element option table. */ -static Ttk_ElementOptionSpec TextElementOptions[] = { +static const Ttk_ElementOptionSpec TextElementOptions[] = { { "-text", TK_OPTION_STRING, - Tk_Offset(TextElement,textObj), "" }, + offsetof(TextElement,textObj), "" }, { "-font", TK_OPTION_FONT, - Tk_Offset(TextElement,fontObj), DEFAULT_FONT }, + offsetof(TextElement,fontObj), DEFAULT_FONT }, { "-foreground", TK_OPTION_COLOR, - Tk_Offset(TextElement,foregroundObj), "black" }, + offsetof(TextElement,foregroundObj), "black" }, { "-underline", TK_OPTION_INT, - Tk_Offset(TextElement,underlineObj), "-1"}, + offsetof(TextElement,underlineObj), "-1"}, { "-width", TK_OPTION_INT, - Tk_Offset(TextElement,widthObj), "-1"}, + offsetof(TextElement,widthObj), "-1"}, { "-anchor", TK_OPTION_ANCHOR, - Tk_Offset(TextElement,anchorObj), "w"}, + offsetof(TextElement,anchorObj), "w"}, { "-justify", TK_OPTION_JUSTIFY, - Tk_Offset(TextElement,justifyObj), "left" }, + offsetof(TextElement,justifyObj), "left" }, { "-wraplength", TK_OPTION_PIXELS, - Tk_Offset(TextElement,wrapLengthObj), "0" }, + offsetof(TextElement,wrapLengthObj), "0" }, { "-embossed", TK_OPTION_INT, - Tk_Offset(TextElement,embossedObj), "0"}, + offsetof(TextElement,embossedObj), "0"}, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -225,7 +225,7 @@ static void TextElementDraw( } } -static Ttk_ElementSpec TextElementSpec = { +static const Ttk_ElementSpec TextElementSpec = { TK_STYLE_VERSION_2, sizeof(TextElement), TextElementOptions, @@ -251,13 +251,13 @@ typedef struct { /* ===> NB: Keep in sync with label element option table. <=== */ -static Ttk_ElementOptionSpec ImageElementOptions[] = { +static const Ttk_ElementOptionSpec ImageElementOptions[] = { { "-image", TK_OPTION_STRING, - Tk_Offset(ImageElement,imageObj), "" }, + offsetof(ImageElement,imageObj), "" }, { "-stipple", TK_OPTION_STRING, /* Really: TK_OPTION_BITMAP */ - Tk_Offset(ImageElement,stippleObj), "gray50" }, + offsetof(ImageElement,stippleObj), "gray50" }, { "-background", TK_OPTION_COLOR, - Tk_Offset(ImageElement,backgroundObj), DEFAULT_BACKGROUND }, + offsetof(ImageElement,backgroundObj), DEFAULT_BACKGROUND }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -392,7 +392,7 @@ static void ImageElementDraw( } } -static Ttk_ElementSpec ImageElementSpec = { +static const Ttk_ElementSpec ImageElementSpec = { TK_STYLE_VERSION_2, sizeof(ImageElement), ImageElementOptions, @@ -448,43 +448,43 @@ typedef struct { int totalWidth, totalHeight; } LabelElement; -static Ttk_ElementOptionSpec LabelElementOptions[] = { +static const Ttk_ElementOptionSpec LabelElementOptions[] = { { "-compound", TK_OPTION_ANY, - Tk_Offset(LabelElement,compoundObj), "none" }, + offsetof(LabelElement,compoundObj), "none" }, { "-space", TK_OPTION_PIXELS, - Tk_Offset(LabelElement,spaceObj), "4" }, + offsetof(LabelElement,spaceObj), "4" }, /* Text element part: * NB: Keep in sync with TextElementOptions. */ { "-text", TK_OPTION_STRING, - Tk_Offset(LabelElement,text.textObj), "" }, + offsetof(LabelElement,text.textObj), "" }, { "-font", TK_OPTION_FONT, - Tk_Offset(LabelElement,text.fontObj), DEFAULT_FONT }, + offsetof(LabelElement,text.fontObj), DEFAULT_FONT }, { "-foreground", TK_OPTION_COLOR, - Tk_Offset(LabelElement,text.foregroundObj), "black" }, + offsetof(LabelElement,text.foregroundObj), "black" }, { "-underline", TK_OPTION_INT, - Tk_Offset(LabelElement,text.underlineObj), "-1"}, + offsetof(LabelElement,text.underlineObj), "-1"}, { "-width", TK_OPTION_INT, - Tk_Offset(LabelElement,text.widthObj), ""}, + offsetof(LabelElement,text.widthObj), ""}, { "-anchor", TK_OPTION_ANCHOR, - Tk_Offset(LabelElement,text.anchorObj), "w"}, + offsetof(LabelElement,text.anchorObj), "w"}, { "-justify", TK_OPTION_JUSTIFY, - Tk_Offset(LabelElement,text.justifyObj), "left" }, + offsetof(LabelElement,text.justifyObj), "left" }, { "-wraplength", TK_OPTION_PIXELS, - Tk_Offset(LabelElement,text.wrapLengthObj), "0" }, + offsetof(LabelElement,text.wrapLengthObj), "0" }, { "-embossed", TK_OPTION_INT, - Tk_Offset(LabelElement,text.embossedObj), "0"}, + offsetof(LabelElement,text.embossedObj), "0"}, /* Image element part: * NB: Keep in sync with ImageElementOptions. */ { "-image", TK_OPTION_STRING, - Tk_Offset(LabelElement,image.imageObj), "" }, + offsetof(LabelElement,image.imageObj), "" }, { "-stipple", TK_OPTION_STRING, /* Really: TK_OPTION_BITMAP */ - Tk_Offset(LabelElement,image.stippleObj), "gray50" }, + offsetof(LabelElement,image.stippleObj), "gray50" }, { "-background", TK_OPTION_COLOR, - Tk_Offset(LabelElement,image.backgroundObj), DEFAULT_BACKGROUND }, + offsetof(LabelElement,image.backgroundObj), DEFAULT_BACKGROUND }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -503,7 +503,7 @@ static void LabelSetup( Ttk_Compound *compoundPtr = &c->compound; Tk_GetPixelsFromObj(NULL, tkwin, c->spaceObj, &c->space); - Ttk_GetCompoundFromObj(NULL, c->compoundObj, (int *)compoundPtr); + Ttk_GetCompoundFromObj(NULL, c->compoundObj, compoundPtr); /* * Deal with TTK_COMPOUND_NONE. @@ -617,7 +617,7 @@ static void LabelElementSize( */ static void DrawCompound( LabelElement *l, Ttk_Box b, Tk_Window tkwin, Drawable d, Ttk_State state, - int imageSide, int textSide) + Ttk_Side imageSide, Ttk_Side textSide) { Ttk_Box imageBox = Ttk_PlaceBox(&b, l->image.width, l->image.height, imageSide, 0); @@ -684,7 +684,7 @@ static void LabelElementDraw( LabelCleanup(l); } -static Ttk_ElementSpec LabelElementSpec = { +static const Ttk_ElementSpec LabelElementSpec = { TK_STYLE_VERSION_2, sizeof(LabelElement), LabelElementOptions, diff --git a/generic/ttk/ttkLayout.c b/generic/ttk/ttkLayout.c index fdbeacf..a971d23 100644 --- a/generic/ttk/ttkLayout.c +++ b/generic/ttk/ttkLayout.c @@ -6,7 +6,6 @@ * Copyright (c) 2003 Joe English. Freely redistributable. */ -#include <string.h> #include "tkInt.h" #include "ttkThemeInt.h" @@ -37,10 +36,10 @@ Ttk_NewBoxObj(Ttk_Box box) { Tcl_Obj *result[4]; - result[0] = Tcl_NewIntObj(box.x); - result[1] = Tcl_NewIntObj(box.y); - result[2] = Tcl_NewIntObj(box.width); - result[3] = Tcl_NewIntObj(box.height); + result[0] = Tcl_NewWideIntObj(box.x); + result[1] = Tcl_NewWideIntObj(box.y); + result[2] = Tcl_NewWideIntObj(box.width); + result[3] = Tcl_NewWideIntObj(box.height); return Tcl_NewListObj(4, result); } @@ -525,7 +524,7 @@ struct Ttk_LayoutNode_ static Ttk_LayoutNode *Ttk_NewLayoutNode( unsigned flags, Ttk_ElementClass *elementClass) { - Ttk_LayoutNode *node = ckalloc(sizeof(*node)); + Ttk_LayoutNode *node = (Ttk_LayoutNode *)ckalloc(sizeof(*node)); node->flags = flags; node->eclass = elementClass; @@ -558,8 +557,8 @@ struct Ttk_TemplateNode_ { static Ttk_TemplateNode *Ttk_NewTemplateNode(const char *name, unsigned flags) { - Ttk_TemplateNode *op = ckalloc(sizeof(*op)); - op->name = ckalloc(strlen(name) + 1); strcpy(op->name, name); + Ttk_TemplateNode *op = (Ttk_TemplateNode *)ckalloc(sizeof(*op)); + op->name = (char *)ckalloc(strlen(name) + 1); strcpy(op->name, name); op->flags = flags; op->next = op->child = 0; return op; @@ -604,13 +603,13 @@ Ttk_InstantiateLayout(Ttk_Theme theme, Ttk_TemplateNode *op) */ /* NB: This must match bit definitions TTK_PACK_LEFT etc. */ -static const char *packSideStrings[] = +static const char *const packSideStrings[] = { "left", "right", "top", "bottom", NULL }; Ttk_LayoutTemplate Ttk_ParseLayoutTemplate(Tcl_Interp *interp, Tcl_Obj *objPtr) { enum { OP_SIDE, OP_STICKY, OP_EXPAND, OP_BORDER, OP_UNIT, OP_CHILDREN }; - static const char *optStrings[] = { + static const char *const optStrings[] = { "-side", "-sticky", "-expand", "-border", "-unit", "-children", 0 }; int i = 0, objc; @@ -844,7 +843,7 @@ static Ttk_Layout TTKNewLayout( void *recordPtr,Tk_OptionTable optionTable, Tk_Window tkwin, Ttk_LayoutNode *root) { - Ttk_Layout layout = ckalloc(sizeof(*layout)); + Ttk_Layout layout = (Ttk_Layout)ckalloc(sizeof(*layout)); layout->style = style; layout->recordPtr = recordPtr; layout->optionTable = optionTable; diff --git a/generic/ttk/ttkManager.c b/generic/ttk/ttkManager.c index 8fa7860..0a3f13c 100644 --- a/generic/ttk/ttkManager.c +++ b/generic/ttk/ttkManager.c @@ -4,7 +4,6 @@ * Support routines for geometry managers. */ -#include <string.h> #include "tkInt.h" #include "ttkManager.h" @@ -35,9 +34,9 @@ * (2) Manager voluntarily relinquishes control * (3) Content window is destroyed * - * In case (1), Tk calls the manager's lostSlaveProc. + * In case (1), Tk calls the manager's lostContentProc. * Case (2) is performed by calling Tk_ManageGeometry(slave,NULL,0); - * in this case Tk does _not_ call the LostSlaveProc (documented behavior). + * in this case Tk does _not_ call the lostContentProc (documented behavior). * Tk doesn't handle case (3) either; to account for that we * register an event handler on the slave widget to track <Destroy> events. */ @@ -60,9 +59,9 @@ struct TtkManager_ { Ttk_ManagerSpec *managerSpec; void *managerData; - Tk_Window containerWindow; + Tk_Window window; unsigned flags; - int nContent; + TkSizeT nManaged; Ttk_Content **content; }; @@ -96,7 +95,7 @@ static void RecomputeSize(Ttk_Manager *mgr) int width = 1, height = 1; if (mgr->managerSpec->RequestedSize(mgr->managerData, &width, &height)) { - Tk_GeometryRequest(mgr->containerWindow, width, height); + Tk_GeometryRequest(mgr->window, width, height); ScheduleUpdate(mgr, MGR_RELAYOUT_REQUIRED); } mgr->flags &= ~MGR_RESIZE_REQUIRED; @@ -143,7 +142,7 @@ static const int ManagerEventMask = StructureNotifyMask; static void ManagerEventHandler(ClientData clientData, XEvent *eventPtr) { Ttk_Manager *mgr = (Ttk_Manager *)clientData; - int i; + TkSizeT i; switch (eventPtr->type) { @@ -151,7 +150,7 @@ static void ManagerEventHandler(ClientData clientData, XEvent *eventPtr) RecomputeLayout(mgr); break; case MapNotify: - for (i = 0; i < mgr->nContent; ++i) { + for (i = 0; i < mgr->nManaged; ++i) { Ttk_Content *slave = mgr->content[i]; if (slave->flags & CONTENT_MAPPED) { Tk_MapWindow(slave->contentWindow); @@ -159,7 +158,7 @@ static void ManagerEventHandler(ClientData clientData, XEvent *eventPtr) } break; case UnmapNotify: - for (i = 0; i < mgr->nContent; ++i) { + for (i = 0; i < mgr->nManaged; ++i) { Ttk_Content *slave = mgr->content[i]; Tk_UnmapWindow(slave->contentWindow); } @@ -167,16 +166,15 @@ static void ManagerEventHandler(ClientData clientData, XEvent *eventPtr) } } -/* ++ LostContentEventHandler -- - * Notifies manager when a slave is destroyed +/* ++ ContentLostEventHandler -- + * Notifies manager when a content window is destroyed * (see <<NOTE-LOSTCONTENT>>). */ -static const unsigned SlaveEventMask = StructureNotifyMask; -static void LostContentEventHandler(ClientData clientData, XEvent *eventPtr) +static void ContentLostEventHandler(void *clientData, XEvent *eventPtr) { Ttk_Content *slave = (Ttk_Content *)clientData; if (eventPtr->type == DestroyNotify) { - slave->manager->managerSpec->tkGeomMgr.lostSlaveProc( + slave->manager->managerSpec->tkGeomMgr.lostContentProc( slave->manager, slave->contentWindow); } } @@ -208,19 +206,19 @@ static void DeleteSlave(Ttk_Content *content) */ Ttk_Manager *Ttk_CreateManager( - Ttk_ManagerSpec *managerSpec, void *managerData, Tk_Window containerWindow) + Ttk_ManagerSpec *managerSpec, void *managerData, Tk_Window window) { Ttk_Manager *mgr = (Ttk_Manager *)ckalloc(sizeof(*mgr)); mgr->managerSpec = managerSpec; mgr->managerData = managerData; - mgr->containerWindow = containerWindow; - mgr->nContent = 0; + mgr->window = window; + mgr->nManaged = 0; mgr->content = NULL; mgr->flags = 0; Tk_CreateEventHandler( - mgr->containerWindow, ManagerEventMask, ManagerEventHandler, mgr); + mgr->window, ManagerEventMask, ManagerEventHandler, mgr); return mgr; } @@ -228,10 +226,10 @@ Ttk_Manager *Ttk_CreateManager( void Ttk_DeleteManager(Ttk_Manager *mgr) { Tk_DeleteEventHandler( - mgr->containerWindow, ManagerEventMask, ManagerEventHandler, mgr); + mgr->window, ManagerEventMask, ManagerEventHandler, mgr); - while (mgr->nContent > 0) { - Ttk_ForgetContent(mgr, mgr->nContent - 1); + while (mgr->nManaged > 0) { + Ttk_ForgetContent(mgr, mgr->nManaged - 1); } if (mgr->content) { ckfree(mgr->content); @@ -249,10 +247,10 @@ void Ttk_DeleteManager(Ttk_Manager *mgr) /* ++ InsertContent -- * Adds content to the list of managed windows. */ -static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, int index) +static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, TkSizeT index) { - int endIndex = mgr->nContent++; - mgr->content = (Ttk_Content **)ckrealloc(mgr->content, mgr->nContent * sizeof(Ttk_Content *)); + TkSizeT endIndex = mgr->nManaged++; + mgr->content = (Ttk_Content **)ckrealloc(mgr->content, mgr->nManaged * sizeof(Ttk_Content *)); while (endIndex > index) { mgr->content[endIndex] = mgr->content[endIndex - 1]; @@ -265,7 +263,7 @@ static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, int index) &mgr->managerSpec->tkGeomMgr, mgr); Tk_CreateEventHandler(content->contentWindow, - SlaveEventMask, LostContentEventHandler, content); + StructureNotifyMask, ContentLostEventHandler, content); ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED); } @@ -278,10 +276,10 @@ static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, int index) * [1] It's safe to call Tk_UnmapWindow / Tk_UnmaintainGeometry even if this * routine is called from the slave's DestroyNotify event handler. */ -static void RemoveSlave(Ttk_Manager *mgr, int index) +static void RemoveSlave(Ttk_Manager *mgr, TkSizeT index) { Ttk_Content *slave = mgr->content[index]; - int i; + TkSizeT i; /* Notify manager: */ @@ -289,18 +287,18 @@ static void RemoveSlave(Ttk_Manager *mgr, int index) /* Remove from array: */ - --mgr->nContent; - for (i = index ; i < mgr->nContent; ++i) { + --mgr->nManaged; + for (i = index ; i < mgr->nManaged; ++i) { mgr->content[i] = mgr->content[i+1]; } /* Clean up: */ Tk_DeleteEventHandler( - slave->contentWindow, SlaveEventMask, LostContentEventHandler, slave); + slave->contentWindow, StructureNotifyMask, ContentLostEventHandler, slave); /* Note [1] */ - Tk_UnmaintainGeometry(slave->contentWindow, mgr->containerWindow); + Tk_UnmaintainGeometry(slave->contentWindow, mgr->window); Tk_UnmapWindow(slave->contentWindow); DeleteSlave(slave); @@ -315,7 +313,7 @@ static void RemoveSlave(Ttk_Manager *mgr, int index) void Ttk_GeometryRequestProc(ClientData clientData, Tk_Window contentWindow) { Ttk_Manager *mgr = (Ttk_Manager *)clientData; - int index = Ttk_ContentIndex(mgr, contentWindow); + TkSizeT index = Ttk_ContentIndex(mgr, contentWindow); int reqWidth = Tk_ReqWidth(contentWindow); int reqHeight= Tk_ReqHeight(contentWindow); @@ -329,7 +327,7 @@ void Ttk_GeometryRequestProc(ClientData clientData, Tk_Window contentWindow) void Ttk_LostContentProc(ClientData clientData, Tk_Window contentWindow) { Ttk_Manager *mgr = (Ttk_Manager *)clientData; - int index = Ttk_ContentIndex(mgr, contentWindow); + TkSizeT index = Ttk_ContentIndex(mgr, contentWindow); /* ASSERT: index >= 0 */ RemoveSlave(mgr, index); @@ -343,7 +341,7 @@ void Ttk_LostContentProc(ClientData clientData, Tk_Window contentWindow) * Add a new content window at the specified index. */ void Ttk_InsertContent( - Ttk_Manager *mgr, int index, Tk_Window tkwin, void *data) + Ttk_Manager *mgr, TkSizeT index, Tk_Window tkwin, void *data) { Ttk_Content *slave = NewContent(mgr, tkwin, data); InsertContent(mgr, slave, index); @@ -352,7 +350,7 @@ void Ttk_InsertContent( /* ++ Ttk_ForgetContent -- * Unmanage the specified content window. */ -void Ttk_ForgetContent(Ttk_Manager *mgr, int index) +void Ttk_ForgetContent(Ttk_Manager *mgr, TkSizeT index) { Tk_Window contentWindow = mgr->content[index]->contentWindow; RemoveSlave(mgr, index); @@ -367,12 +365,12 @@ void Ttk_ForgetContent(Ttk_Manager *mgr, int index) * map the content window. */ void Ttk_PlaceContent( - Ttk_Manager *mgr, int index, int x, int y, int width, int height) + Ttk_Manager *mgr, TkSizeT index, int x, int y, int width, int height) { Ttk_Content *slave = mgr->content[index]; - Tk_MaintainGeometry(slave->contentWindow,mgr->containerWindow,x,y,width,height); + Tk_MaintainGeometry(slave->contentWindow,mgr->window,x,y,width,height); slave->flags |= CONTENT_MAPPED; - if (Tk_IsMapped(mgr->containerWindow)) { + if (Tk_IsMapped(mgr->window)) { Tk_MapWindow(slave->contentWindow); } } @@ -380,10 +378,10 @@ void Ttk_PlaceContent( /* ++ Ttk_UnmapContent -- * Unmap the specified content window, but leave it managed. */ -void Ttk_UnmapContent(Ttk_Manager *mgr, int index) +void Ttk_UnmapContent(Ttk_Manager *mgr, TkSizeT index) { Ttk_Content *slave = mgr->content[index]; - Tk_UnmaintainGeometry(slave->contentWindow, mgr->containerWindow); + Tk_UnmaintainGeometry(slave->contentWindow, mgr->window); slave->flags &= ~CONTENT_MAPPED; /* Contrary to documentation, Tk_UnmaintainGeometry doesn't always * unmap the content window: @@ -406,15 +404,15 @@ void Ttk_ManagerSizeChanged(Ttk_Manager *mgr) /* +++ Accessors. */ -int Ttk_NumberContent(Ttk_Manager *mgr) +TkSizeT Ttk_NumberContent(Ttk_Manager *mgr) { - return mgr->nContent; + return mgr->nManaged; } -void *Ttk_ContentData(Ttk_Manager *mgr, int index) +void *Ttk_ContentData(Ttk_Manager *mgr, TkSizeT index) { return mgr->content[index]->data; } -Tk_Window Ttk_ContentWindow(Ttk_Manager *mgr, int index) +Tk_Window Ttk_ContentWindow(Ttk_Manager *mgr, TkSizeT index) { return mgr->content[index]->contentWindow; } @@ -426,13 +424,13 @@ Tk_Window Ttk_ContentWindow(Ttk_Manager *mgr, int index) /* ++ Ttk_ContentIndex -- * Returns the index of specified content window, -1 if not found. */ -int Ttk_ContentIndex(Ttk_Manager *mgr, Tk_Window contentWindow) +TkSizeT Ttk_ContentIndex(Ttk_Manager *mgr, Tk_Window contentWindow) { - int index; - for (index = 0; index < mgr->nContent; ++index) + TkSizeT index; + for (index = 0; index < mgr->nManaged; ++index) if (mgr->content[index]->contentWindow == contentWindow) return index; - return -1; + return TCL_INDEX_NONE; } /* ++ Ttk_GetContentIndexFromObj(interp, mgr, objPtr, indexPtr) -- @@ -445,19 +443,19 @@ int Ttk_ContentIndex(Ttk_Manager *mgr, Tk_Window contentWindow) */ int Ttk_GetContentIndexFromObj( - Tcl_Interp *interp, Ttk_Manager *mgr, Tcl_Obj *objPtr, int *indexPtr) + Tcl_Interp *interp, Ttk_Manager *mgr, Tcl_Obj *objPtr, TkSizeT *indexPtr) { const char *string = Tcl_GetString(objPtr); - int index = 0; + TkSizeT index = 0; Tk_Window tkwin; /* Try interpreting as an integer first: */ - if (Tcl_GetIntFromObj(NULL, objPtr, &index) == TCL_OK) { - if (index < 0 || index >= mgr->nContent) { + if (TkGetIntForIndex(objPtr, mgr->nManaged - 1, 1, &index) == TCL_OK) { + if (index + 1 > mgr->nManaged + 1) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Slave index %d out of bounds", index)); - Tcl_SetErrorCode(interp, "TTK", "SLAVE", "INDEX", NULL); + "Managed window index %d out of bounds", (int)index)); + Tcl_SetErrorCode(interp, "TTK", "MANAGED", "INDEX", NULL); return TCL_ERROR; } *indexPtr = index; @@ -467,13 +465,13 @@ int Ttk_GetContentIndexFromObj( /* Try interpreting as a slave window name; */ if ((*string == '.') && - (tkwin = Tk_NameToWindow(interp, string, mgr->containerWindow))) { + (tkwin = Tk_NameToWindow(interp, string, mgr->window))) { index = Ttk_ContentIndex(mgr, tkwin); - if (index < 0) { + if (index == TCL_INDEX_NONE) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "%s is not managed by %s", string, - Tk_PathName(mgr->containerWindow))); - Tcl_SetErrorCode(interp, "TTK", "SLAVE", "MANAGER", NULL); + Tk_PathName(mgr->window))); + Tcl_SetErrorCode(interp, "TTK", "MANAGED", "MANAGER", NULL); return TCL_ERROR; } *indexPtr = index; @@ -481,15 +479,15 @@ int Ttk_GetContentIndexFromObj( } Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Invalid slave specification %s", string)); - Tcl_SetErrorCode(interp, "TTK", "SLAVE", "SPEC", NULL); + "Invalid managed window specification %s", string)); + Tcl_SetErrorCode(interp, "TTK", "MANAGED", "SPEC", NULL); return TCL_ERROR; } /* ++ Ttk_ReorderContent(mgr, fromIndex, toIndex) -- * Change content window order. */ -void Ttk_ReorderContent(Ttk_Manager *mgr, int fromIndex, int toIndex) +void Ttk_ReorderContent(Ttk_Manager *mgr, TkSizeT fromIndex, TkSizeT toIndex) { Ttk_Content *moved = mgr->content[fromIndex]; diff --git a/generic/ttk/ttkManager.h b/generic/ttk/ttkManager.h index c4c46ed..edcbb09 100644 --- a/generic/ttk/ttkManager.h +++ b/generic/ttk/ttkManager.h @@ -31,14 +31,14 @@ typedef struct { /* Manager hooks */ int (*RequestedSize)(void *managerData, int *widthPtr, int *heightPtr); void (*PlaceSlaves)(void *managerData); - int (*SlaveRequest)(void *managerData, int index, int w, int h); - void (*SlaveRemoved)(void *managerData, int index); + int (*SlaveRequest)(void *managerData, TkSizeT index, int w, int h); + void (*SlaveRemoved)(void *managerData, TkSizeT index); } Ttk_ManagerSpec; /* * Default implementations for Tk_GeomMgr hooks: */ -#define Ttk_LostContentProc Ttk_LostSlaveProc +#define Ttk_LostSlaveProc Ttk_LostContentProc MODULE_SCOPE void Ttk_GeometryRequestProc(ClientData, Tk_Window slave); MODULE_SCOPE void Ttk_LostContentProc(ClientData, Tk_Window slave); @@ -49,25 +49,25 @@ MODULE_SCOPE Ttk_Manager *Ttk_CreateManager( Ttk_ManagerSpec *, void *managerData, Tk_Window window); MODULE_SCOPE void Ttk_DeleteManager(Ttk_Manager *); -#define Ttk_InsertContent Ttk_InsertSlave +#define Ttk_InsertSlave Ttk_InsertContent MODULE_SCOPE void Ttk_InsertContent( - Ttk_Manager *, int position, Tk_Window, void *data); + Ttk_Manager *, TkSizeT position, Tk_Window, void *slaveData); -#define Ttk_ForgetContent Ttk_ForgetSlave -MODULE_SCOPE void Ttk_ForgetContent(Ttk_Manager *, int index); +#define Ttk_ForgetSlave Ttk_ForgetContent +MODULE_SCOPE void Ttk_ForgetContent(Ttk_Manager *, TkSizeT slaveIndex); -#define Ttk_ReorderContent Ttk_ReorderSlave -MODULE_SCOPE void Ttk_ReorderContent(Ttk_Manager *, int fromIndex, int toIndex); - /* Rearrange content window positions */ +#define Ttk_ReorderSlave Ttk_ReorderContent +MODULE_SCOPE void Ttk_ReorderContent(Ttk_Manager *, TkSizeT fromIndex, TkSizeT toIndex); + /* Rearrange content positions */ -#define Ttk_PlaceContent Ttk_PlaceSlave +#define Ttk_PlaceSlave Ttk_PlaceContent MODULE_SCOPE void Ttk_PlaceContent( - Ttk_Manager *, int index, int x, int y, int width, int height); - /* Position and map the content window */ + Ttk_Manager *, TkSizeT index, int x, int y, int width, int height); + /* Position and map the slave */ -#define Ttk_UnmapContent Ttk_UnmapSlave -MODULE_SCOPE void Ttk_UnmapContent(Ttk_Manager *, int index); - /* Unmap the content window */ +#define Ttk_UnmapSlave Ttk_UnmapContent +MODULE_SCOPE void Ttk_UnmapContent(Ttk_Manager *, TkSizeT slaveIndex); + /* Unmap the slave */ MODULE_SCOPE void Ttk_ManagerSizeChanged(Ttk_Manager *); MODULE_SCOPE void Ttk_ManagerLayoutChanged(Ttk_Manager *); @@ -75,26 +75,26 @@ MODULE_SCOPE void Ttk_ManagerLayoutChanged(Ttk_Manager *); /* Utilities: */ -#define Ttk_ContentIndex Ttk_SlaveIndex -MODULE_SCOPE int Ttk_ContentIndex(Ttk_Manager *, Tk_Window); - /* Returns: index in slave array of specified window, -1 if not found */ +#define Ttk_SlaveIndex Ttk_ContentIndex +MODULE_SCOPE TkSizeT Ttk_ContentIndex(Ttk_Manager *, Tk_Window); + /* Returns: index in content array of specified window, TCL_INDEX_NONE if not found */ -#define Ttk_GetContentIndexFromObj Ttk_GetSlaveIndexFromObj +#define Ttk_GetSlaveIndexFromObj Ttk_GetContentIndexFromObj MODULE_SCOPE int Ttk_GetContentIndexFromObj( - Tcl_Interp *, Ttk_Manager *, Tcl_Obj *, int *indexPtr); + Tcl_Interp *, Ttk_Manager *, Tcl_Obj *, TkSizeT *indexPtr); /* Accessor functions: */ -#define Ttk_NumberContent Ttk_NumberSlaves -MODULE_SCOPE int Ttk_NumberContent(Ttk_Manager *); - /* Returns: number of managed content windows */ +#define Ttk_NumberSlaves Ttk_NumberContent +MODULE_SCOPE TkSizeT Ttk_NumberContent(Ttk_Manager *); + /* Returns: number of managed windows */ -#define Ttk_ContentData Ttk_SlaveData -MODULE_SCOPE void *Ttk_ContentData(Ttk_Manager *, int index); - /* Returns: client data associated with content window */ +#define Ttk_SlaveData Ttk_ContentData +MODULE_SCOPE void *Ttk_ContentData(Ttk_Manager *, TkSizeT index); + /* Returns: client data associated with managed window */ -#define Ttk_ContentWindow Ttk_SlaveWindow -MODULE_SCOPE Tk_Window Ttk_ContentWindow(Ttk_Manager *, int index); +#define Ttk_SlaveWindow Ttk_ContentWindow +MODULE_SCOPE Tk_Window Ttk_ContentWindow(Ttk_Manager *, TkSizeT slaveIndex); /* Returns: content window */ MODULE_SCOPE int Ttk_Maintainable(Tcl_Interp *, Tk_Window content, Tk_Window container); diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c index d94b4ed..fa3881e 100644 --- a/generic/ttk/ttkNotebook.c +++ b/generic/ttk/ttkNotebook.c @@ -2,11 +2,7 @@ * Copyright (c) 2004, Joe English */ -#include <string.h> -#include <ctype.h> -#include <stdio.h> #include "tkInt.h" - #include "ttkTheme.h" #include "ttkWidget.h" #include "ttkManager.h" @@ -59,29 +55,29 @@ typedef struct * PaneOptionSpecs includes additional options for child window placement * and is used to configure the slave. */ -static Tk_OptionSpec TabOptionSpecs[] = +static const Tk_OptionSpec TabOptionSpecs[] = { {TK_OPTION_STRING_TABLE, "-state", "", "", - "normal", -1,Tk_Offset(Tab,state), + "normal", TCL_INDEX_NONE, offsetof(Tab,state), 0, (void *)TabStateStrings, 0 }, {TK_OPTION_STRING, "-text", "text", "Text", "", - Tk_Offset(Tab,textObj), -1, 0,0,GEOMETRY_CHANGED }, + offsetof(Tab,textObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-image", "image", "Image", NULL/*default*/, - Tk_Offset(Tab,imageObj), -1, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, + offsetof(Tab,imageObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED }, {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound", - NULL, Tk_Offset(Tab,compoundObj), -1, - TK_OPTION_NULL_OK, (void *)ttkCompoundStrings, GEOMETRY_CHANGED }, + NULL, offsetof(Tab,compoundObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK,(void *)ttkCompoundStrings,GEOMETRY_CHANGED }, {TK_OPTION_INT, "-underline", "underline", "Underline", "-1", - Tk_Offset(Tab,underlineObj), -1, 0,0,GEOMETRY_CHANGED }, + offsetof(Tab,underlineObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED }, {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0 } }; -static Tk_OptionSpec PaneOptionSpecs[] = +static const Tk_OptionSpec PaneOptionSpecs[] = { {TK_OPTION_STRING, "-padding", "padding", "Padding", "0", - Tk_Offset(Tab,paddingObj), -1, 0,0,GEOMETRY_CHANGED }, + offsetof(Tab,paddingObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-sticky", "sticky", "Sticky", "nsew", - Tk_Offset(Tab,stickyObj), -1, 0,0,GEOMETRY_CHANGED }, + offsetof(Tab,stickyObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED }, WIDGET_INHERIT_OPTIONS(TabOptionSpecs) }; @@ -98,8 +94,8 @@ typedef struct Ttk_Manager *mgr; /* Geometry manager */ Tk_OptionTable tabOptionTable; /* Tab options */ Tk_OptionTable paneOptionTable; /* Tab+pane options */ - int currentIndex; /* index of currently selected tab */ - int activeIndex; /* index of currently active tab */ + TkSizeT currentIndex; /* index of currently selected tab */ + TkSizeT activeIndex; /* index of currently active tab */ Ttk_Layout tabLayout; /* Sublayout for tabs */ Ttk_Box clientArea; /* Where to pack slave widgets */ @@ -111,16 +107,16 @@ typedef struct NotebookPart notebook; } Notebook; -static Tk_OptionSpec NotebookOptionSpecs[] = +static const Tk_OptionSpec NotebookOptionSpecs[] = { {TK_OPTION_INT, "-width", "width", "Width", "0", - Tk_Offset(Notebook,notebook.widthObj),-1, + offsetof(Notebook,notebook.widthObj),TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED }, {TK_OPTION_INT, "-height", "height", "Height", "0", - Tk_Offset(Notebook,notebook.heightObj),-1, + offsetof(Notebook,notebook.heightObj),TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-padding", "padding", "Padding", NULL, - Tk_Offset(Notebook,notebook.paddingObj),-1, + offsetof(Notebook,notebook.paddingObj),TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, WIDGET_TAKEFOCUS_TRUE, @@ -194,7 +190,7 @@ static void NotebookStyleOptions(Notebook *nb, NotebookStyle *nbstyle) static Tab *CreateTab(Tcl_Interp *interp, Notebook *nb, Tk_Window slaveWindow) { Tk_OptionTable optionTable = nb->notebook.paneOptionTable; - void *record = ckalloc(sizeof(Tab)); + Tab *record = (Tab *)ckalloc(sizeof(Tab)); memset(record, 0, sizeof(Tab)); if (Tk_InitOptions(interp, record, optionTable, slaveWindow) != TCL_OK) { @@ -221,7 +217,7 @@ static int ConfigureTab( Tk_SavedOptions savedOptions; int mask = 0; - if (Tk_SetOptions(interp, (void *)tab, nb->notebook.paneOptionTable, + if (Tk_SetOptions(interp, tab, nb->notebook.paneOptionTable, objc, objv, slaveWindow, &savedOptions, &mask) != TCL_OK) { return TCL_ERROR; @@ -258,25 +254,25 @@ error: * Return the index of the tab at point x,y, * or -1 if no tab at that point. */ -static int IdentifyTab(Notebook *nb, int x, int y) +static TkSizeT IdentifyTab(Notebook *nb, int x, int y) { - int index; + TkSizeT index; for (index = 0; index < Ttk_NumberContent(nb->notebook.mgr); ++index) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr,index); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr,index); if ( tab->state != TAB_STATE_HIDDEN && Ttk_BoxContains(tab->parcel, x,y)) { return index; } } - return -1; + return TCL_INDEX_NONE; } /* * ActivateTab -- * Set the active tab index, redisplay if necessary. */ -static void ActivateTab(Notebook *nb, int index) +static void ActivateTab(Notebook *nb, TkSizeT index) { if (index != nb->notebook.activeIndex) { nb->notebook.activeIndex = index; @@ -291,11 +287,11 @@ static void ActivateTab(Notebook *nb, int index) * The USER1 bit is set for the leftmost visible tab, and USER2 * is set for the rightmost visible tab. */ -static Ttk_State TabState(Notebook *nb, int index) +static Ttk_State TabState(Notebook *nb, TkSizeT index) { Ttk_State state = nb->core.state; - Tab *tab = Ttk_ContentData(nb->notebook.mgr, index); - int i = 0; + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); + TkSizeT i = 0; if (index == nb->notebook.currentIndex) { state |= TTK_STATE_SELECTED; @@ -307,7 +303,7 @@ static Ttk_State TabState(Notebook *nb, int index) state |= TTK_STATE_ACTIVE; } for (i = 0; i < Ttk_NumberContent(nb->notebook.mgr); ++i) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, i); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i); if (tab->state == TAB_STATE_HIDDEN) { continue; } @@ -316,8 +312,8 @@ static Ttk_State TabState(Notebook *nb, int index) } break; } - for (i = Ttk_NumberContent(nb->notebook.mgr) - 1; i >= 0; --i) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, i); + for (i = Ttk_NumberContent(nb->notebook.mgr) - 1; i != TCL_INDEX_NONE; --i) { + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i); if (tab->state == TAB_STATE_HIDDEN) { continue; } @@ -355,10 +351,10 @@ static void TabrowSize( { Ttk_Layout tabLayout = nb->notebook.tabLayout; int tabrowWidth = 0, tabrowHeight = 0; - int i; + TkSizeT i; for (i = 0; i < Ttk_NumberContent(nb->notebook.mgr); ++i) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, i); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i); Ttk_State tabState = TabState(nb,i); Ttk_RebindSublayout(tabLayout, tab); @@ -388,14 +384,14 @@ static void TabrowSize( static int NotebookSize(void *clientData, int *widthPtr, int *heightPtr) { - Notebook *nb = clientData; + Notebook *nb = (Notebook *)clientData; NotebookStyle nbstyle; Ttk_Padding padding; Ttk_Element clientNode = Ttk_FindElement(nb->core.layout, "client"); int clientWidth = 0, clientHeight = 0, reqWidth = 0, reqHeight = 0, tabrowWidth = 0, tabrowHeight = 0; - int i; + TkSizeT i; NotebookStyleOptions(nb, &nbstyle); @@ -403,7 +399,7 @@ static int NotebookSize(void *clientData, int *widthPtr, int *heightPtr) */ for (i = 0; i < Ttk_NumberContent(nb->notebook.mgr); ++i) { Tk_Window slaveWindow = Ttk_ContentWindow(nb->notebook.mgr, i); - Tab *tab = Ttk_ContentData(nb->notebook.mgr, i); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i); int slaveWidth = Tk_ReqWidth(slaveWindow) + Ttk_PaddingWidth(tab->padding); int slaveHeight @@ -474,7 +470,7 @@ static void SqueezeTabs( int i; for (i = 0; i < nTabs; ++i) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr,i); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr,i); double ad = slack + tab->width * delta; tab->width += (int)ad; slack = ad - (int)ad; @@ -493,7 +489,7 @@ static void PlaceTabs( int i; for (i = 0; i < nTabs; ++i) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, i); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i); Ttk_State tabState = TabState(nb, i); if (tab->state != TAB_STATE_HIDDEN) { @@ -521,7 +517,7 @@ static void PlaceTabs( */ static void NotebookDoLayout(void *recordPtr) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; Tk_Window nbwin = nb->core.tkwin; Ttk_Box cavity = Ttk_WinBox(nbwin); int tabrowWidth = 0, tabrowHeight = 0; @@ -575,9 +571,9 @@ static void NotebookDoLayout(void *recordPtr) * Set the position and size of a child widget * based on the current client area and content window options: */ -static void NotebookPlaceContent(Notebook *nb, int index) +static void NotebookPlaceContent(Notebook *nb, TkSizeT index) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, index); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); Tk_Window slaveWindow = Ttk_ContentWindow(nb->notebook.mgr, index); Ttk_Box slaveBox = Ttk_StickBox(Ttk_PadBox(nb->notebook.clientArea, tab->padding), @@ -592,9 +588,9 @@ static void NotebookPlaceContent(Notebook *nb, int index) */ static void NotebookPlaceContents(void *recordPtr) { - Notebook *nb = recordPtr; - int currentIndex = nb->notebook.currentIndex; - if (currentIndex >= 0) { + Notebook *nb = (Notebook *)recordPtr; + TkSizeT currentIndex = nb->notebook.currentIndex; + if (currentIndex != TCL_INDEX_NONE) { NotebookDoLayout(nb); NotebookPlaceContent(nb, currentIndex); } @@ -604,10 +600,10 @@ static void NotebookPlaceContents(void *recordPtr) * SelectTab(nb, index) -- * Change the currently-selected tab. */ -static void SelectTab(Notebook *nb, int index) +static void SelectTab(Notebook *nb, TkSizeT index) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr,index); - int currentIndex = nb->notebook.currentIndex; + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); + TkSizeT currentIndex = nb->notebook.currentIndex; if (index == currentIndex) { return; @@ -623,7 +619,7 @@ static void SelectTab(Notebook *nb, int index) tab->state = TAB_STATE_NORMAL; } - if (currentIndex >= 0) { + if (currentIndex != TCL_INDEX_NONE) { Ttk_UnmapContent(nb->notebook.mgr, currentIndex); } @@ -635,7 +631,7 @@ static void SelectTab(Notebook *nb, int index) NotebookPlaceContent(nb, index); TtkRedisplayWidget(&nb->core); - TtkSendVirtualEvent(nb->core.tkwin, "NotebookTabChanged"); + Tk_SendVirtualEvent(nb->core.tkwin, "NotebookTabChanged", NULL); } /* NextTab -- @@ -645,13 +641,13 @@ static void SelectTab(Notebook *nb, int index) */ static int NextTab(Notebook *nb, int index) { - int nTabs = Ttk_NumberContent(nb->notebook.mgr); - int nextIndex; + TkSizeT nTabs = Ttk_NumberContent(nb->notebook.mgr); + TkSizeT nextIndex; /* Scan forward for following usable tab: */ - for (nextIndex = index + 1; nextIndex < nTabs; ++nextIndex) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, nextIndex); + for (nextIndex = index + 1; nextIndex + 1 < nTabs + 1; ++nextIndex) { + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, nextIndex); if (tab->state == TAB_STATE_NORMAL) { return nextIndex; } @@ -659,8 +655,8 @@ static int NextTab(Notebook *nb, int index) /* Not found -- scan backwards. */ - for (nextIndex = index - 1; nextIndex >= 0; --nextIndex) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, nextIndex); + for (nextIndex = index - 1; nextIndex != TCL_INDEX_NONE; --nextIndex) { + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, nextIndex); if (tab->state == TAB_STATE_NORMAL) { return nextIndex; } @@ -680,14 +676,14 @@ static int NextTab(Notebook *nb, int index) */ static void SelectNearestTab(Notebook *nb) { - int currentIndex = nb->notebook.currentIndex; - int nextIndex = NextTab(nb, currentIndex); + TkSizeT currentIndex = nb->notebook.currentIndex; + TkSizeT nextIndex = NextTab(nb, currentIndex); - if (currentIndex >= 0) { + if (currentIndex != TCL_INDEX_NONE) { Ttk_UnmapContent(nb->notebook.mgr, currentIndex); } if (currentIndex != nextIndex) { - TtkSendVirtualEvent(nb->core.tkwin, "NotebookTabChanged"); + Tk_SendVirtualEvent(nb->core.tkwin, "NotebookTabChanged", NULL); } nb->notebook.currentIndex = nextIndex; @@ -699,16 +695,16 @@ static void SelectNearestTab(Notebook *nb) * Select the next tab if the current one is being removed. * Adjust currentIndex to account for removed slave. */ -static void TabRemoved(void *managerData, int index) +static void TabRemoved(void *managerData, TkSizeT index) { - Notebook *nb = managerData; - Tab *tab = Ttk_ContentData(nb->notebook.mgr, index); + Notebook *nb = (Notebook *)managerData; + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); if (index == nb->notebook.currentIndex) { SelectNearestTab(nb); } - if (index < nb->notebook.currentIndex) { + if (index + 1 < nb->notebook.currentIndex + 1) { --nb->notebook.currentIndex; } @@ -717,8 +713,13 @@ static void TabRemoved(void *managerData, int index) TtkRedisplayWidget(&nb->core); } -static int TabRequest(void *managerData, int index, int width, int height) +static int TabRequest(void *managerData, TkSizeT index, int width, int height) { + (void)managerData; + (void)index; + (void)width; + (void)height; + return 1; } @@ -727,7 +728,7 @@ static int TabRequest(void *managerData, int index, int width, int height) */ static int AddTab( Tcl_Interp *interp, Notebook *nb, - int destIndex, Tk_Window slaveWindow, + TkSizeT destIndex, Tk_Window slaveWindow, int objc, Tcl_Obj *const objv[]) { Tab *tab; @@ -735,7 +736,7 @@ static int AddTab( return TCL_ERROR; } #if 0 /* can't happen */ - if (Ttk_ContentIndex(nb->notebook.mgr, slaveWindow) >= 0) { + if (Ttk_ContentIndex(nb->notebook.mgr, slaveWindow) != TCL_INDEX_NONE) { Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s already added", Tk_PathName(slaveWindow))); Tcl_SetErrorCode(interp, "TTK", "NOTEBOOK", "PRESENT", NULL); @@ -758,9 +759,9 @@ static int AddTab( /* Adjust indices and/or autoselect first tab: */ - if (nb->notebook.currentIndex < 0) { + if (nb->notebook.currentIndex == TCL_INDEX_NONE) { SelectTab(nb, destIndex); - } else if (nb->notebook.currentIndex >= destIndex) { + } else if (nb->notebook.currentIndex + 1 >= destIndex + 1) { ++nb->notebook.currentIndex; } @@ -789,13 +790,13 @@ static const int NotebookEventMask ; static void NotebookEventHandler(ClientData clientData, XEvent *eventPtr) { - Notebook *nb = clientData; + Notebook *nb = (Notebook *)clientData; if (eventPtr->type == DestroyNotify) { /* Remove self */ Tk_DeleteEventHandler(nb->core.tkwin, NotebookEventMask, NotebookEventHandler, clientData); } else if (eventPtr->type == MotionNotify) { - int index = IdentifyTab(nb, eventPtr->xmotion.x, eventPtr->xmotion.y); + TkSizeT index = IdentifyTab(nb, eventPtr->xmotion.x, eventPtr->xmotion.y); ActivateTab(nb, index); } else if (eventPtr->type == LeaveNotify) { ActivateTab(nb, -1); @@ -823,12 +824,12 @@ static void NotebookEventHandler(ClientData clientData, XEvent *eventPtr) * See also: GetTabIndex. */ static int FindTabIndex( - Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, int *index_rtn) + Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, TkSizeT *index_rtn) { const char *string = Tcl_GetString(objPtr); int x, y; - *index_rtn = -1; + *index_rtn = TCL_INDEX_NONE; /* Check for @x,y ... */ @@ -851,6 +852,12 @@ static int FindTabIndex( { return TCL_OK; } + if (*index_rtn == Ttk_NumberContent(nb->notebook.mgr)) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Invalid slave specification %s", string)); + Tcl_SetErrorCode(interp, "TTK", "SLAVE", "SPEC", NULL); + return TCL_ERROR; + } /* Nothing matched; Ttk_GetContentIndexFromObj will have left error message. */ @@ -863,11 +870,17 @@ static int FindTabIndex( * Returns TCL_ERROR if the tab does not exist. */ static int GetTabIndex( - Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, int *index_rtn) + Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, TkSizeT *index_rtn) { int status = FindTabIndex(interp, nb, objPtr, index_rtn); + if (status == TCL_OK && *index_rtn + 1 >= Ttk_NumberContent(nb->notebook.mgr) + 1) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Slave index %s out of bounds", Tcl_GetString(objPtr))); + Tcl_SetErrorCode(interp, "TTK", "SLAVE", "INDEX", NULL); + return TCL_ERROR; + } - if (status == TCL_OK && *index_rtn < 0) { + if (status == TCL_OK && *index_rtn == TCL_INDEX_NONE) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "tab '%s' not found", Tcl_GetString(objPtr))); Tcl_SetErrorCode(interp, "TTK", "NOTEBOOK", "TAB", NULL); @@ -885,7 +898,7 @@ static int GetTabIndex( static int NotebookAddCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; Tk_Window slaveWindow; int index; Tab *tab; @@ -905,7 +918,7 @@ static int NotebookAddCommand( return AddTab(interp, nb, Ttk_NumberContent(nb->notebook.mgr), slaveWindow, objc-3,objv+3); } - tab = Ttk_ContentData(nb->notebook.mgr, index); + tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); if (tab->state == TAB_STATE_HIDDEN) { tab->state = TAB_STATE_NORMAL; } @@ -924,19 +937,17 @@ static int NotebookAddCommand( static int NotebookInsertCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; - int current = nb->notebook.currentIndex; - int nContent = Ttk_NumberContent(nb->notebook.mgr); - int srcIndex, destIndex; + Notebook *nb = (Notebook *)recordPtr; + TkSizeT current = nb->notebook.currentIndex; + TkSizeT nSlaves = Ttk_NumberContent(nb->notebook.mgr); + TkSizeT srcIndex, destIndex; if (objc < 4) { Tcl_WrongNumArgs(interp, 2,objv, "index slave ?-option value ...?"); return TCL_ERROR; } - if (!strcmp(Tcl_GetString(objv[2]), "end")) { - destIndex = Ttk_NumberContent(nb->notebook.mgr); - } else if (TCL_OK != Ttk_GetContentIndexFromObj( + if (TCL_OK != Ttk_GetContentIndexFromObj( interp, nb->notebook.mgr, objv[2], &destIndex)) { return TCL_ERROR; } @@ -952,38 +963,40 @@ static int NotebookInsertCommand( } srcIndex = Ttk_ContentIndex(nb->notebook.mgr, slaveWindow); - if (srcIndex < 0) { /* New slave */ + if (srcIndex == TCL_INDEX_NONE) { /* New slave */ return AddTab(interp, nb, destIndex, slaveWindow, objc-4,objv+4); } } else if (Ttk_GetContentIndexFromObj( interp, nb->notebook.mgr, objv[3], &srcIndex) != TCL_OK) { return TCL_ERROR; + } else if (srcIndex + 1 >= Ttk_NumberContent(nb->notebook.mgr) + 1) { + srcIndex = Ttk_NumberContent(nb->notebook.mgr) - 1; } /* Move existing slave: */ if (ConfigureTab(interp, nb, - Ttk_ContentData(nb->notebook.mgr,srcIndex), - Ttk_ContentWindow(nb->notebook.mgr,srcIndex), + (Tab *)Ttk_ContentData(nb->notebook.mgr, srcIndex), + Ttk_ContentWindow(nb->notebook.mgr, srcIndex), objc-4,objv+4) != TCL_OK) { return TCL_ERROR; } - if (destIndex >= nContent) { - destIndex = nContent - 1; + if (destIndex + 1 >= nSlaves + 1) { + destIndex = nSlaves - 1; } Ttk_ReorderContent(nb->notebook.mgr, srcIndex, destIndex); /* Adjust internal indexes: */ - nb->notebook.activeIndex = -1; + nb->notebook.activeIndex = TCL_INDEX_NONE; if (current == srcIndex) { nb->notebook.currentIndex = destIndex; - } else if (destIndex <= current && current < srcIndex) { + } else if (destIndex + 1 <= current + 1 && current + 1 < srcIndex + 1) { ++nb->notebook.currentIndex; - } else if (srcIndex < current && current <= destIndex) { + } else if (srcIndex + 1 < current + 1 && current + 1 <= destIndex + 1) { --nb->notebook.currentIndex; } @@ -998,8 +1011,8 @@ static int NotebookInsertCommand( static int NotebookForgetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; - int index; + Notebook *nb = (Notebook *)recordPtr; + TkSizeT index; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "tab"); @@ -1022,8 +1035,8 @@ static int NotebookForgetCommand( static int NotebookHideCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; - int index; + Notebook *nb = (Notebook *)recordPtr; + TkSizeT index; Tab *tab; if (objc != 3) { @@ -1035,7 +1048,7 @@ static int NotebookHideCommand( return TCL_ERROR; } - tab = Ttk_ContentData(nb->notebook.mgr, index); + tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); tab->state = TAB_STATE_HIDDEN; if (index == nb->notebook.currentIndex) { SelectNearestTab(nb); @@ -1052,19 +1065,20 @@ static int NotebookHideCommand( static int NotebookIdentifyCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - static const char *whatTable[] = { "element", "tab", NULL }; + static const char *const whatTable[] = { "element", "tab", NULL }; enum { IDENTIFY_ELEMENT, IDENTIFY_TAB }; int what = IDENTIFY_ELEMENT; - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; Ttk_Element element = NULL; - int x, y, tabIndex; + int x, y; + TkSizeT tabIndex; if (objc < 4 || objc > 5) { Tcl_WrongNumArgs(interp, 2,objv, "?what? x y"); return TCL_ERROR; } - if ( Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK + if (Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK || Tcl_GetIntFromObj(interp, objv[objc-1], &y) != TCL_OK || (objc == 5 && Tcl_GetIndexFromObjStruct(interp, objv[2], whatTable, sizeof(char *), "option", 0, &what) != TCL_OK) @@ -1073,8 +1087,8 @@ static int NotebookIdentifyCommand( } tabIndex = IdentifyTab(nb, x, y); - if (tabIndex >= 0) { - Tab *tab = Ttk_ContentData(nb->notebook.mgr, tabIndex); + if (tabIndex != TCL_INDEX_NONE) { + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, tabIndex); Ttk_State state = TabState(nb, tabIndex); Ttk_Layout tabLayout = nb->notebook.tabLayout; @@ -1093,9 +1107,8 @@ static int NotebookIdentifyCommand( } break; case IDENTIFY_TAB: - if (tabIndex >= 0) { - Tcl_SetObjResult(interp, Tcl_NewIntObj(tabIndex)); - } + if (tabIndex != TCL_INDEX_NONE) + Tcl_SetObjResult(interp, TkNewIndexObj(tabIndex)); break; } return TCL_OK; @@ -1109,26 +1122,19 @@ static int NotebookIdentifyCommand( static int NotebookIndexCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; - int index, status; + Notebook *nb = (Notebook *)recordPtr; + TkSizeT index; + int status; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "tab"); return TCL_ERROR; } - /* - * Special-case for "end": - */ - if (!strcmp("end", Tcl_GetString(objv[2]))) { - int nContent = Ttk_NumberContent(nb->notebook.mgr); - Tcl_SetObjResult(interp, Tcl_NewIntObj(nContent)); - return TCL_OK; - } - status = FindTabIndex(interp, nb, objv[2], &index); - if (status == TCL_OK && index >= 0) { - Tcl_SetObjResult(interp, Tcl_NewIntObj(index)); + if (status == TCL_OK) { + if (index != TCL_INDEX_NONE) + Tcl_SetObjResult(interp, TkNewIndexObj(index)); } return status; @@ -1141,17 +1147,18 @@ static int NotebookIndexCommand( static int NotebookSelectCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; if (objc == 2) { - if (nb->notebook.currentIndex >= 0) { + if (nb->notebook.currentIndex != TCL_INDEX_NONE) { Tk_Window pane = Ttk_ContentWindow( nb->notebook.mgr, nb->notebook.currentIndex); Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(pane), -1)); } return TCL_OK; } else if (objc == 3) { - int index, status = GetTabIndex(interp, nb, objv[2], &index); + TkSizeT index; + int status = GetTabIndex(interp, nb, objv[2], &index); if (status == TCL_OK) { SelectTab(nb, index); } @@ -1167,10 +1174,10 @@ static int NotebookSelectCommand( static int NotebookTabsCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; Ttk_Manager *mgr = nb->notebook.mgr; Tcl_Obj *result; - int i; + TkSizeT i; if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, ""); @@ -1192,9 +1199,9 @@ static int NotebookTabsCommand( static int NotebookTabCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; Ttk_Manager *mgr = nb->notebook.mgr; - int index; + TkSizeT index; Tk_Window slaveWindow; Tab *tab; @@ -1207,7 +1214,7 @@ static int NotebookTabCommand( return TCL_ERROR; } - tab = Ttk_ContentData(mgr, index); + tab = (Tab *)Ttk_ContentData(mgr, index); slaveWindow = Ttk_ContentWindow(mgr, index); if (objc == 3) { @@ -1257,7 +1264,7 @@ static const Ttk_Ensemble NotebookCommands[] = { static void NotebookInitialize(Tcl_Interp *interp, void *recordPtr) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; nb->notebook.mgr = Ttk_CreateManager( &NotebookManagerSpec, recordPtr, nb->core.tkwin); @@ -1265,8 +1272,8 @@ static void NotebookInitialize(Tcl_Interp *interp, void *recordPtr) nb->notebook.tabOptionTable = Tk_CreateOptionTable(interp,TabOptionSpecs); nb->notebook.paneOptionTable = Tk_CreateOptionTable(interp,PaneOptionSpecs); - nb->notebook.currentIndex = -1; - nb->notebook.activeIndex = -1; + nb->notebook.currentIndex = TCL_INDEX_NONE; + nb->notebook.activeIndex = TCL_INDEX_NONE; nb->notebook.tabLayout = 0; nb->notebook.clientArea = Ttk_MakeBox(0,0,1,1); @@ -1277,7 +1284,7 @@ static void NotebookInitialize(Tcl_Interp *interp, void *recordPtr) static void NotebookCleanup(void *recordPtr) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; Ttk_DeleteManager(nb->notebook.mgr); if (nb->notebook.tabLayout) @@ -1286,7 +1293,7 @@ static void NotebookCleanup(void *recordPtr) static int NotebookConfigure(Tcl_Interp *interp, void *clientData, int mask) { - Notebook *nb = clientData; + Notebook *nb = (Notebook *)clientData; /* * Error-checks: @@ -1310,7 +1317,7 @@ static int NotebookConfigure(Tcl_Interp *interp, void *clientData, int mask) static Ttk_Layout NotebookGetLayout( Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr) { - Notebook *nb = recordPtr; + Notebook *nb = (Notebook *)recordPtr; Ttk_Layout notebookLayout = TtkWidgetGetLayout(interp, theme, recordPtr); Ttk_Layout tabLayout; @@ -1338,7 +1345,7 @@ static Ttk_Layout NotebookGetLayout( static void DisplayTab(Notebook *nb, int index, Drawable d) { Ttk_Layout tabLayout = nb->notebook.tabLayout; - Tab *tab = Ttk_ContentData(nb->notebook.mgr, index); + Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); Ttk_State state = TabState(nb, index); if (tab->state != TAB_STATE_HIDDEN) { @@ -1350,9 +1357,9 @@ static void DisplayTab(Notebook *nb, int index, Drawable d) static void NotebookDisplay(void *clientData, Drawable d) { - Notebook *nb = clientData; - int nContent = Ttk_NumberContent(nb->notebook.mgr); - int index; + Notebook *nb = (Notebook *)clientData; + TkSizeT nContent = Ttk_NumberContent(nb->notebook.mgr); + TkSizeT index; /* Draw notebook background (base layout): */ @@ -1366,7 +1373,7 @@ static void NotebookDisplay(void *clientData, Drawable d) DisplayTab(nb, index, d); } } - if (nb->notebook.currentIndex >= 0) { + if (nb->notebook.currentIndex != TCL_INDEX_NONE) { DisplayTab(nb, nb->notebook.currentIndex, d); } } @@ -1375,7 +1382,7 @@ static void NotebookDisplay(void *clientData, Drawable d) * +++ Widget specification and layout definitions. */ -static WidgetSpec NotebookWidgetSpec = +static const WidgetSpec NotebookWidgetSpec = { "TNotebook", /* className */ sizeof(Notebook), /* recordSize */ diff --git a/generic/ttk/ttkPanedwindow.c b/generic/ttk/ttkPanedwindow.c index 85f0b26..5c67ace 100644 --- a/generic/ttk/ttkPanedwindow.c +++ b/generic/ttk/ttkPanedwindow.c @@ -6,7 +6,6 @@ * TODO: track active/pressed sash. */ -#include <string.h> #include "tkInt.h" #include "ttkManager.h" #include "ttkTheme.h" @@ -75,16 +74,16 @@ typedef struct { /* @@@ NOTE: -orient is readonly 'cause dynamic oriention changes NYI */ -static Tk_OptionSpec PanedOptionSpecs[] = { +static const Tk_OptionSpec PanedOptionSpecs[] = { {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "vertical", - Tk_Offset(Paned,paned.orientObj), Tk_Offset(Paned,paned.orient), - 0,(void *)ttkOrientStrings,READONLY_OPTION|STYLE_CHANGED }, + offsetof(Paned,paned.orientObj), offsetof(Paned,paned.orient), + 0, (void *)ttkOrientStrings, READONLY_OPTION|STYLE_CHANGED }, {TK_OPTION_INT, "-width", "width", "Width", "0", - -1,Tk_Offset(Paned,paned.width), - 0,0,GEOMETRY_CHANGED }, + TCL_INDEX_NONE, offsetof(Paned, paned.width), + 0, 0, GEOMETRY_CHANGED }, {TK_OPTION_INT, "-height", "height", "Height", "0", - -1,Tk_Offset(Paned,paned.height), - 0,0,GEOMETRY_CHANGED }, + TCL_INDEX_NONE, offsetof(Paned, paned.height), + 0, 0, GEOMETRY_CHANGED }, WIDGET_TAKEFOCUS_FALSE, WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs) @@ -99,10 +98,10 @@ typedef struct { int weight; /* Pane -weight, for resizing */ } Pane; -static Tk_OptionSpec PaneOptionSpecs[] = { +static const Tk_OptionSpec PaneOptionSpecs[] = { {TK_OPTION_INT, "-weight", "weight", "Weight", "0", - -1,Tk_Offset(Pane,weight), 0,0,GEOMETRY_CHANGED }, - {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0} + TCL_INDEX_NONE, offsetof(Pane,weight), 0,0,GEOMETRY_CHANGED }, + {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0} }; /* CreatePane -- @@ -112,7 +111,7 @@ static Pane *CreatePane(Tcl_Interp *interp, Paned *pw, Tk_Window slaveWindow) { Tk_OptionTable optionTable = pw->paned.paneOptionTable; void *record = ckalloc(sizeof(Pane)); - Pane *pane = record; + Pane *pane = (Pane *)record; memset(record, 0, sizeof(Pane)); if (Tk_InitOptions(interp, record, optionTable, slaveWindow) != TCL_OK) { @@ -148,7 +147,7 @@ static int ConfigurePane( Tk_SavedOptions savedOptions; int mask = 0; - if (Tk_SetOptions(interp, (void*)pane, pw->paned.paneOptionTable, + if (Tk_SetOptions(interp, pane, pw->paned.paneOptionTable, objc, objv, slaveWindow, &savedOptions, &mask) != TCL_OK) { return TCL_ERROR; @@ -189,14 +188,14 @@ error: static int ShoveUp(Paned *pw, int i, int pos) { - Pane *pane = Ttk_ContentData(pw->paned.mgr, i); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, i); int sashThickness = pw->paned.sashThickness; if (i == 0) { if (pos < 0) pos = 0; } else { - Pane *prevPane = Ttk_ContentData(pw->paned.mgr, i-1); + Pane *prevPane = (Pane *)Ttk_ContentData(pw->paned.mgr, i-1); if (pos < prevPane->sashPos + sashThickness) pos = ShoveUp(pw, i-1, pos - sashThickness) + sashThickness; } @@ -207,15 +206,15 @@ static int ShoveUp(Paned *pw, int i, int pos) * Same as ShoveUp, but going in the opposite direction * and stopping at the sentinel sash. */ -static int ShoveDown(Paned *pw, int i, int pos) +static int ShoveDown(Paned *pw, TkSizeT i, int pos) { - Pane *pane = Ttk_ContentData(pw->paned.mgr,i); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr,i); int sashThickness = pw->paned.sashThickness; if (i == Ttk_NumberContent(pw->paned.mgr) - 1) { pos = pane->sashPos; /* Sentinel value == container window size */ } else { - Pane *nextPane = Ttk_ContentData(pw->paned.mgr,i+1); + Pane *nextPane = (Pane *)Ttk_ContentData(pw->paned.mgr,i+1); if (pos + sashThickness > nextPane->sashPos) pos = ShoveDown(pw, i+1, pos + sashThickness) - sashThickness; } @@ -230,7 +229,7 @@ static int ShoveDown(Paned *pw, int i, int pos) */ static int PanedSize(void *recordPtr, int *widthPtr, int *heightPtr) { - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; int nPanes = Ttk_NumberContent(pw->paned.mgr); int nSashes = nPanes - 1; int sashThickness = pw->paned.sashThickness; @@ -239,7 +238,7 @@ static int PanedSize(void *recordPtr, int *widthPtr, int *heightPtr) if (pw->paned.orient == TTK_ORIENT_HORIZONTAL) { for (index = 0; index < nPanes; ++index) { - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); Tk_Window slaveWindow = Ttk_ContentWindow(pw->paned.mgr, index); if (height < Tk_ReqHeight(slaveWindow)) @@ -249,7 +248,7 @@ static int PanedSize(void *recordPtr, int *widthPtr, int *heightPtr) width += nSashes * sashThickness; } else { for (index = 0; index < nPanes; ++index) { - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); Tk_Window slaveWindow = Ttk_ContentWindow(pw->paned.mgr, index); if (width < Tk_ReqWidth(slaveWindow)) @@ -276,10 +275,10 @@ static void AdjustPanes(Paned *pw) { int sashThickness = pw->paned.sashThickness; int pos = 0; - int index; + TkSizeT index; for (index = 0; index < Ttk_NumberContent(pw->paned.mgr); ++index) { - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); int size = pane->sashPos - pos; pane->reqSize = size >= 0 ? size : 0; pos = pane->sashPos + sashThickness; @@ -317,7 +316,7 @@ static void PlaceSashes(Paned *pw, int width, int height) /* Compute total required size and total available weight: */ for (i = 0; i < nPanes; ++i) { - Pane *pane = Ttk_ContentData(mgr, i); + Pane *pane = (Pane *)Ttk_ContentData(mgr, i); reqSize += pane->reqSize; totalWeight += pane->weight * (pane->reqSize != 0); } @@ -341,7 +340,7 @@ static void PlaceSashes(Paned *pw, int width, int height) */ pos = 0; for (i = 0; i < nPanes; ++i) { - Pane *pane = Ttk_ContentData(mgr, i); + Pane *pane = (Pane *)Ttk_ContentData(mgr, i); int weight = pane->weight * (pane->reqSize != 0); int size = pane->reqSize + delta * weight; @@ -373,10 +372,10 @@ static void PlacePanes(Paned *pw) int width = Tk_Width(pw->core.tkwin), height = Tk_Height(pw->core.tkwin); int sashThickness = pw->paned.sashThickness; int pos = 0; - int index; + TkSizeT index; for (index = 0; index < Ttk_NumberContent(pw->paned.mgr); ++index) { - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); int size = pane->sashPos - pos; if (size > 0) { @@ -399,15 +398,15 @@ static void PlacePanes(Paned *pw) static void PanedPlaceContent(void *managerData) { - Paned *pw = managerData; + Paned *pw = (Paned *)managerData; PlaceSashes(pw, Tk_Width(pw->core.tkwin), Tk_Height(pw->core.tkwin)); PlacePanes(pw); } -static void PaneRemoved(void *managerData, int index) +static void PaneRemoved(void *managerData, TkSizeT index) { - Paned *pw = managerData; - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Paned *pw = (Paned *)managerData; + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); DestroyPane(pw, pane); } @@ -420,7 +419,7 @@ static int AddPane( if (!Ttk_Maintainable(interp, slaveWindow, pw->core.tkwin)) { return TCL_ERROR; } - if (Ttk_ContentIndex(pw->paned.mgr, slaveWindow) >= 0) { + if (Ttk_ContentIndex(pw->paned.mgr, slaveWindow) != TCL_INDEX_NONE) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "%s already added", Tk_PathName(slaveWindow))); Tcl_SetErrorCode(interp, "TTK", "PANE", "PRESENT", NULL); @@ -442,14 +441,14 @@ static int AddPane( /* PaneRequest -- * Only update pane request size if slave is currently unmapped. - * Geometry requests from mapped slaves are not directly honored + * Geometry requests from mapped panes are not directly honored * in order to avoid unexpected pane resizes (esp. while the * user is dragging a sash [#1325286]). */ -static int PaneRequest(void *managerData, int index, int width, int height) +static int PaneRequest(void *managerData, TkSizeT index, int width, int height) { - Paned *pw = managerData; - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Paned *pw = (Paned *)managerData; + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); Tk_Window slaveWindow = Ttk_ContentWindow(pw->paned.mgr, index); int horizontal = pw->paned.orient == TTK_ORIENT_HORIZONTAL; @@ -483,11 +482,11 @@ static Ttk_ManagerSpec PanedManagerSpec = { static const unsigned PanedEventMask = LeaveWindowMask; static void PanedEventProc(ClientData clientData, XEvent *eventPtr) { - WidgetCore *corePtr = clientData; + WidgetCore *corePtr = (WidgetCore *)clientData; if ( eventPtr->type == LeaveNotify && eventPtr->xcrossing.detail == NotifyInferior) { - TtkSendVirtualEvent(corePtr->tkwin, "EnteredChild"); + Tk_SendVirtualEvent(corePtr->tkwin, "EnteredChild", NULL); } } @@ -497,7 +496,7 @@ static void PanedEventProc(ClientData clientData, XEvent *eventPtr) static void PanedInitialize(Tcl_Interp *interp, void *recordPtr) { - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; Tk_CreateEventHandler(pw->core.tkwin, PanedEventMask, PanedEventProc, recordPtr); @@ -509,7 +508,7 @@ static void PanedInitialize(Tcl_Interp *interp, void *recordPtr) static void PanedCleanup(void *recordPtr) { - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; if (pw->paned.sashLayout) Ttk_FreeLayout(pw->paned.sashLayout); @@ -520,9 +519,10 @@ static void PanedCleanup(void *recordPtr) /* Post-configuration hook. */ -static int PanedPostConfigure(Tcl_Interp *interp, void *clientData, int mask) +static int PanedPostConfigure(Tcl_Interp *dummy, void *clientData, int mask) { - Paned *pw = clientData; + Paned *pw = (Paned *)clientData; + (void)dummy; if (mask & GEOMETRY_CHANGED) { /* User has changed -width or -height. @@ -543,7 +543,7 @@ static int PanedPostConfigure(Tcl_Interp *interp, void *clientData, int mask) static Ttk_Layout PanedGetLayout( Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr) { - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; Ttk_Layout panedLayout = TtkWidgetGetLayout(interp, themePtr, recordPtr); if (panedLayout) { @@ -581,7 +581,7 @@ static Ttk_Layout PanedGetLayout( */ static Ttk_Layout SashLayout(Paned *pw, int index) { - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); int thickness = pw->paned.sashThickness, height = Tk_Height(pw->core.tkwin), width = Tk_Width(pw->core.tkwin), @@ -603,12 +603,12 @@ static void DrawSash(Paned *pw, int index, Drawable d) static void PanedDisplay(void *recordPtr, Drawable d) { - Paned *pw = recordPtr; - int i, nSashes = Ttk_NumberContent(pw->paned.mgr) - 1; + Paned *pw = (Paned *)recordPtr; + TkSizeT i, nSlaves = Ttk_NumberContent(pw->paned.mgr); TtkWidgetDisplay(recordPtr, d); - for (i = 0; i < nSashes; ++i) { - DrawSash(pw, i, d); + for (i = 1; i < nSlaves; ++i) { + DrawSash(pw, i - 1, d); } } @@ -621,7 +621,7 @@ static void PanedDisplay(void *recordPtr, Drawable d) static int PanedAddCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; Tk_Window slaveWindow; if (objc < 3) { @@ -646,9 +646,9 @@ static int PanedAddCommand( static int PanedInsertCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Paned *pw = recordPtr; - int nContent = Ttk_NumberContent(pw->paned.mgr); - int srcIndex, destIndex; + Paned *pw = (Paned *)recordPtr; + TkSizeT nSlaves = Ttk_NumberContent(pw->paned.mgr); + TkSizeT srcIndex, destIndex; Tk_Window slaveWindow; if (objc < 4) { @@ -662,28 +662,26 @@ static int PanedInsertCommand( return TCL_ERROR; } - if (!strcmp(Tcl_GetString(objv[2]), "end")) { - destIndex = Ttk_NumberContent(pw->paned.mgr); - } else if (TCL_OK != Ttk_GetContentIndexFromObj( - interp,pw->paned.mgr,objv[2],&destIndex)) + if (TCL_OK != Ttk_GetContentIndexFromObj( + interp,pw->paned.mgr, objv[2], &destIndex)) { return TCL_ERROR; } srcIndex = Ttk_ContentIndex(pw->paned.mgr, slaveWindow); - if (srcIndex < 0) { /* New slave: */ + if (srcIndex == TCL_INDEX_NONE) { /* New slave: */ return AddPane(interp, pw, destIndex, slaveWindow, objc-4, objv+4); } /* else -- move existing slave: */ - if (destIndex >= nContent) - destIndex = nContent - 1; + if (destIndex + 1 >= nSlaves + 1) + destIndex = nSlaves - 1; Ttk_ReorderContent(pw->paned.mgr, srcIndex, destIndex); return objc == 4 ? TCL_OK : ConfigurePane(interp, pw, - Ttk_ContentData(pw->paned.mgr, destIndex), + (Pane *)Ttk_ContentData(pw->paned.mgr, destIndex), Ttk_ContentWindow(pw->paned.mgr, destIndex), - objc-4,objv+4); + objc-4, objv+4); } /* $pw forget $pane @@ -691,8 +689,8 @@ static int PanedInsertCommand( static int PanedForgetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Paned *pw = recordPtr; - int paneIndex; + Paned *pw = (Paned *)recordPtr; + TkSizeT paneIndex; if (objc != 3) { Tcl_WrongNumArgs(interp, 2,objv, "pane"); @@ -703,6 +701,8 @@ static int PanedForgetCommand( interp, pw->paned.mgr, objv[2], &paneIndex)) { return TCL_ERROR; + } else if (paneIndex + 1 >= Ttk_NumberContent(pw->paned.mgr) + 1) { + paneIndex = Ttk_NumberContent(pw->paned.mgr) - 1; } Ttk_ForgetContent(pw->paned.mgr, paneIndex); @@ -715,10 +715,10 @@ static int PanedForgetCommand( static int PanedIdentifyCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - static const char *whatTable[] = { "element", "sash", NULL }; + static const char *const whatTable[] = { "element", "sash", NULL }; enum { IDENTIFY_ELEMENT, IDENTIFY_SASH }; int what = IDENTIFY_SASH; - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; int sashThickness = pw->paned.sashThickness; int nSashes = Ttk_NumberContent(pw->paned.mgr) - 1; int x, y, pos; @@ -739,12 +739,12 @@ static int PanedIdentifyCommand( pos = pw->paned.orient == TTK_ORIENT_HORIZONTAL ? x : y; for (index = 0; index < nSashes; ++index) { - Pane *pane = Ttk_ContentData(pw->paned.mgr, index); + Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index); if (pane->sashPos <= pos && pos <= pane->sashPos + sashThickness) { /* Found it. */ switch (what) { case IDENTIFY_SASH: - Tcl_SetObjResult(interp, Tcl_NewIntObj(index)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(index)); return TCL_OK; case IDENTIFY_ELEMENT: { @@ -769,8 +769,8 @@ static int PanedIdentifyCommand( static int PanedPaneCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Paned *pw = recordPtr; - int paneIndex; + Paned *pw = (Paned *)recordPtr; + TkSizeT paneIndex; Tk_Window slaveWindow; Pane *pane; @@ -780,12 +780,14 @@ static int PanedPaneCommand( } if (TCL_OK != Ttk_GetContentIndexFromObj( - interp,pw->paned.mgr,objv[2],&paneIndex)) + interp,pw->paned.mgr, objv[2], &paneIndex)) { return TCL_ERROR; + } else if (paneIndex + 1 >= Ttk_NumberContent(pw->paned.mgr) + 1) { + paneIndex = Ttk_NumberContent(pw->paned.mgr) - 1; } - pane = Ttk_ContentData(pw->paned.mgr, paneIndex); + pane = (Pane *)Ttk_ContentData(pw->paned.mgr, paneIndex); slaveWindow = Ttk_ContentWindow(pw->paned.mgr, paneIndex); switch (objc) { @@ -806,10 +808,10 @@ static int PanedPaneCommand( static int PanedPanesCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; Ttk_Manager *mgr = pw->paned.mgr; Tcl_Obj *panes; - int i; + TkSizeT i; if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, ""); @@ -833,7 +835,7 @@ static int PanedPanesCommand( static int PanedSashposCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Paned *pw = recordPtr; + Paned *pw = (Paned *)recordPtr; int sashIndex, position = -1; Pane *pane; @@ -844,17 +846,17 @@ static int PanedSashposCommand( if (Tcl_GetIntFromObj(interp, objv[2], &sashIndex) != TCL_OK) { return TCL_ERROR; } - if (sashIndex < 0 || sashIndex >= Ttk_NumberContent(pw->paned.mgr) - 1) { + if (sashIndex < 0 || (TkSizeT)sashIndex + 1 >= Ttk_NumberContent(pw->paned.mgr)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "sash index %d out of range", sashIndex)); Tcl_SetErrorCode(interp, "TTK", "PANE", "SASH_INDEX", NULL); return TCL_ERROR; } - pane = Ttk_ContentData(pw->paned.mgr, sashIndex); + pane = (Pane *)Ttk_ContentData(pw->paned.mgr, sashIndex); if (objc == 3) { - Tcl_SetObjResult(interp, Tcl_NewIntObj(pane->sashPos)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pane->sashPos)); return TCL_OK; } /* else -- set new sash position */ @@ -872,7 +874,7 @@ static int PanedSashposCommand( AdjustPanes(pw); Ttk_ManagerLayoutChanged(pw->paned.mgr); - Tcl_SetObjResult(interp, Tcl_NewIntObj(pane->sashPos)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pane->sashPos)); return TCL_OK; } @@ -895,7 +897,7 @@ static const Ttk_Ensemble PanedCommands[] = { * +++ Widget specification. */ -static WidgetSpec PanedWidgetSpec = +static const WidgetSpec PanedWidgetSpec = { "TPanedwindow", /* className */ sizeof(Paned), /* recordSize */ @@ -921,23 +923,27 @@ typedef struct { Tcl_Obj *thicknessObj; } SashElement; -static Ttk_ElementOptionSpec SashElementOptions[] = { +static const Ttk_ElementOptionSpec SashElementOptions[] = { { "-sashthickness", TK_OPTION_INT, - Tk_Offset(SashElement,thicknessObj), "5" }, - { NULL, 0, 0, NULL } + offsetof(SashElement,thicknessObj), "5" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void SashElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - SashElement *sash = elementRecord; + SashElement *sash = (SashElement *)elementRecord; int thickness = DEFAULT_SASH_THICKNESS; + (void)dummy; + (void)tkwin; + (void)paddingPtr; + Tcl_GetIntFromObj(NULL, sash->thicknessObj, &thickness); *widthPtr = *heightPtr = thickness; } -static Ttk_ElementSpec SashElementSpec = { +static const Ttk_ElementSpec SashElementSpec = { TK_STYLE_VERSION_2, sizeof(SashElement), SashElementOptions, diff --git a/generic/ttk/ttkProgress.c b/generic/ttk/ttkProgress.c index ae945ae..a025885 100644 --- a/generic/ttk/ttkProgress.c +++ b/generic/ttk/ttkProgress.c @@ -4,7 +4,6 @@ * ttk::progressbar widget. */ -#include <math.h> #include "tkInt.h" #include "ttkTheme.h" #include "ttkWidget.h" @@ -22,13 +21,19 @@ static const char *const ProgressbarModeStrings[] = { }; typedef struct { - Tcl_Obj *orientObj; + Tcl_Obj *anchorObj; + Tcl_Obj *fontObj; + Tcl_Obj *foregroundObj; + Tcl_Obj *justifyObj; Tcl_Obj *lengthObj; - Tcl_Obj *modeObj; - Tcl_Obj *variableObj; Tcl_Obj *maximumObj; - Tcl_Obj *valueObj; + Tcl_Obj *modeObj; + Tcl_Obj *orientObj; Tcl_Obj *phaseObj; + Tcl_Obj *textObj; + Tcl_Obj *valueObj; + Tcl_Obj *variableObj; + Tcl_Obj *wrapLengthObj; int mode; Ttk_TraceHandle *variableTrace; /* Trace handle for -variable option */ @@ -43,30 +48,48 @@ typedef struct { ProgressbarPart progress; } Progressbar; -static Tk_OptionSpec ProgressbarOptionSpecs[] = +static const Tk_OptionSpec ProgressbarOptionSpecs[] = { - {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", - "horizontal", Tk_Offset(Progressbar,progress.orientObj), -1, - 0, (void *)ttkOrientStrings, STYLE_CHANGED }, + {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", + "w", offsetof(Progressbar,progress.anchorObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED}, + {TK_OPTION_FONT, "-font", "font", "Font", + DEFAULT_FONT, offsetof(Progressbar,progress.fontObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, + {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor", + "black", offsetof(Progressbar,progress.foregroundObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK,0,0 }, + {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", + "left", offsetof(Progressbar,progress.justifyObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_PIXELS, "-length", "length", "Length", - DEF_PROGRESSBAR_LENGTH, Tk_Offset(Progressbar,progress.lengthObj), -1, + DEF_PROGRESSBAR_LENGTH, offsetof(Progressbar,progress.lengthObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED }, + {TK_OPTION_DOUBLE, "-maximum", "maximum", "Maximum", + "100", offsetof(Progressbar,progress.maximumObj), TCL_INDEX_NONE, + 0, 0, 0 }, {TK_OPTION_STRING_TABLE, "-mode", "mode", "ProgressMode", "determinate", - Tk_Offset(Progressbar,progress.modeObj), - Tk_Offset(Progressbar,progress.mode), + offsetof(Progressbar,progress.modeObj), + offsetof(Progressbar,progress.mode), 0, (void *)ProgressbarModeStrings, 0 }, - {TK_OPTION_DOUBLE, "-maximum", "maximum", "Maximum", - "100", Tk_Offset(Progressbar,progress.maximumObj), -1, + {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", + "horizontal", offsetof(Progressbar,progress.orientObj), TCL_INDEX_NONE, + 0, (void *)ttkOrientStrings, STYLE_CHANGED }, + {TK_OPTION_INT, "-phase", "phase", "Phase", + "0", offsetof(Progressbar,progress.phaseObj), TCL_INDEX_NONE, 0, 0, 0 }, - {TK_OPTION_STRING, "-variable", "variable", "Variable", - NULL, Tk_Offset(Progressbar,progress.variableObj), -1, - TK_OPTION_NULL_OK, 0, 0 }, + {TK_OPTION_STRING, "-text", "text", "Text", "", + offsetof(Progressbar,progress.textObj), TCL_INDEX_NONE, + 0,0,GEOMETRY_CHANGED }, {TK_OPTION_DOUBLE, "-value", "value", "Value", - "0.0", Tk_Offset(Progressbar,progress.valueObj), -1, - 0, 0, 0 }, - {TK_OPTION_INT, "-phase", "phase", "Phase", - "0", Tk_Offset(Progressbar,progress.phaseObj), -1, + "0.0", offsetof(Progressbar,progress.valueObj), TCL_INDEX_NONE, 0, 0, 0 }, + {TK_OPTION_STRING, "-variable", "variable", "Variable", + NULL, offsetof(Progressbar,progress.variableObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK, 0, 0 }, + {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength", + "0", offsetof(Progressbar, progress.wrapLengthObj), TCL_INDEX_NONE, + TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED}, WIDGET_TAKEFOCUS_FALSE, WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs) @@ -114,7 +137,7 @@ static void AnimateProgressProc(ClientData clientData) if (pb->progress.maxPhase) phase %= pb->progress.maxPhase; Tcl_DecrRefCount(pb->progress.phaseObj); - pb->progress.phaseObj = Tcl_NewIntObj(phase); + pb->progress.phaseObj = Tcl_NewWideIntObj(phase); Tcl_IncrRefCount(pb->progress.phaseObj); /* @@ -271,14 +294,14 @@ static int ProgressbarSize(void *recordPtr, int *widthPtr, int *heightPtr) { Progressbar *pb = (Progressbar *)recordPtr; int length = 100; - int orient = TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = TTK_ORIENT_HORIZONTAL; TtkWidgetSize(recordPtr, widthPtr, heightPtr); /* Override requested width (height) based on -length and -orient */ Tk_GetPixelsFromObj(NULL, pb->core.tkwin, pb->progress.lengthObj, &length); - Ttk_GetOrientFromObj(NULL, pb->progress.orientObj, &orient); + TtkGetOrientFromObj(NULL, pb->progress.orientObj, &orient); if (orient == TTK_ORIENT_HORIZONTAL) { *widthPtr = length; @@ -342,7 +365,7 @@ static void ProgressbarDoLayout(void *recordPtr) WidgetCore *corePtr = &pb->core; Ttk_Element pbar = Ttk_FindElement(corePtr->layout, "pbar"); double value = 0.0, maximum = 100.0; - int orient = TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = TTK_ORIENT_HORIZONTAL; Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin)); @@ -351,7 +374,7 @@ static void ProgressbarDoLayout(void *recordPtr) Tcl_GetDoubleFromObj(NULL, pb->progress.valueObj, &value); Tcl_GetDoubleFromObj(NULL, pb->progress.maximumObj, &maximum); - Ttk_GetOrientFromObj(NULL, pb->progress.orientObj, &orient); + TtkGetOrientFromObj(NULL, pb->progress.orientObj, &orient); if (pbar) { double fraction = value / maximum; @@ -506,7 +529,7 @@ static const Ttk_Ensemble ProgressbarCommands[] = { /* * Widget specification: */ -static WidgetSpec ProgressbarWidgetSpec = +static const WidgetSpec ProgressbarWidgetSpec = { "TProgressbar", /* className */ sizeof(Progressbar), /* recordSize */ @@ -532,7 +555,8 @@ TTK_END_LAYOUT TTK_BEGIN_LAYOUT(HorizontalProgressbarLayout) TTK_GROUP("Horizontal.Progressbar.trough", TTK_FILL_BOTH, - TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y)) + TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y) + TTK_NODE("Horizontal.Progressbar.text", TTK_PACK_LEFT)) TTK_END_LAYOUT /* diff --git a/generic/ttk/ttkScale.c b/generic/ttk/ttkScale.c index 4d05f97..9f27245 100644 --- a/generic/ttk/ttkScale.c +++ b/generic/ttk/ttkScale.c @@ -4,8 +4,7 @@ * ttk::scale widget. */ -#include <string.h> -#include <stdio.h> +#include "tkInt.h" #include "tkInt.h" #include "ttkTheme.h" #include "ttkWidget.h" @@ -52,32 +51,32 @@ typedef struct ScalePart scale; } Scale; -static Tk_OptionSpec ScaleOptionSpecs[] = +static const Tk_OptionSpec ScaleOptionSpecs[] = { {TK_OPTION_STRING, "-command", "command", "Command", "", - Tk_Offset(Scale,scale.commandObj), -1, + offsetof(Scale,scale.commandObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0}, {TK_OPTION_STRING, "-variable", "variable", "Variable", "", - Tk_Offset(Scale,scale.variableObj), -1, - 0,0,0}, + offsetof(Scale,scale.variableObj), TCL_INDEX_NONE, + 0, 0, 0}, {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "horizontal", - Tk_Offset(Scale,scale.orientObj), - Tk_Offset(Scale,scale.orient), 0, + offsetof(Scale,scale.orientObj), + offsetof(Scale,scale.orient), 0, (void *)ttkOrientStrings, STYLE_CHANGED }, {TK_OPTION_DOUBLE, "-from", "from", "From", "0", - Tk_Offset(Scale,scale.fromObj), -1, 0, 0, 0}, + offsetof(Scale,scale.fromObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_DOUBLE, "-to", "to", "To", "1.0", - Tk_Offset(Scale,scale.toObj), -1, 0, 0, 0}, + offsetof(Scale,scale.toObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_DOUBLE, "-value", "value", "Value", "0", - Tk_Offset(Scale,scale.valueObj), -1, 0, 0, 0}, + offsetof(Scale,scale.valueObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_PIXELS, "-length", "length", "Length", - DEF_SCALE_LENGTH, Tk_Offset(Scale,scale.lengthObj), -1, 0, 0, + DEF_SCALE_LENGTH, offsetof(Scale,scale.lengthObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-state", "state", "State", - "normal", Tk_Offset(Scale,scale.stateObj), -1, - 0,0,STATE_CHANGED}, + "normal", offsetof(Scale,scale.stateObj), TCL_INDEX_NONE, + 0, 0, STATE_CHANGED}, WIDGET_TAKEFOCUS_TRUE, WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs) @@ -378,8 +377,8 @@ ScaleCoordsCommand( if (r == TCL_OK) { Tcl_Obj *point[2]; XPoint pt = ValueToPoint(scalePtr, value); - point[0] = Tcl_NewIntObj(pt.x); - point[1] = Tcl_NewIntObj(pt.y); + point[0] = Tcl_NewWideIntObj(pt.x); + point[1] = Tcl_NewWideIntObj(pt.y); Tcl_SetObjResult(interp, Tcl_NewListObj(2, point)); } return r; @@ -494,7 +493,7 @@ static const Ttk_Ensemble ScaleCommands[] = { { 0,0,0 } }; -static WidgetSpec ScaleWidgetSpec = +static const WidgetSpec ScaleWidgetSpec = { "TScale", /* Class name */ sizeof(Scale), /* record size */ diff --git a/generic/ttk/ttkScroll.c b/generic/ttk/ttkScroll.c index 9cf8eae..69370c9 100644 --- a/generic/ttk/ttkScroll.c +++ b/generic/ttk/ttkScroll.c @@ -55,7 +55,7 @@ struct ScrollHandleRec */ ScrollHandle TtkCreateScrollHandle(WidgetCore *corePtr, Scrollable *scrollPtr) { - ScrollHandle h = ckalloc(sizeof(*h)); + ScrollHandle h = (ScrollHandle)ckalloc(sizeof(*h)); h->flags = 0; h->corePtr = corePtr; @@ -130,12 +130,12 @@ static void UpdateScrollbarBG(ClientData clientData) int code; h->flags &= ~SCROLL_UPDATE_PENDING; - Tcl_Preserve((ClientData) interp); + Tcl_Preserve(interp); code = UpdateScrollbar(interp, h); if (code == TCL_ERROR && !Tcl_InterpDeleted(interp)) { Tcl_BackgroundException(interp, code); } - Tcl_Release((ClientData) interp); + Tcl_Release(interp); } /* TtkScrolled -- @@ -167,7 +167,7 @@ void TtkScrolled(ScrollHandle h, int first, int last, int total) s->total = total; if (!(h->flags & SCROLL_UPDATE_PENDING)) { - Tcl_DoWhenIdle(UpdateScrollbarBG, (ClientData)h); + Tcl_DoWhenIdle(UpdateScrollbarBG, h); h->flags |= SCROLL_UPDATE_PENDING; } } @@ -274,7 +274,7 @@ void TtkScrollTo(ScrollHandle h, int newFirst, int updateScrollInfo) void TtkFreeScrollHandle(ScrollHandle h) { if (h->flags & SCROLL_UPDATE_PENDING) { - Tcl_CancelIdleCall(UpdateScrollbarBG, (ClientData)h); + Tcl_CancelIdleCall(UpdateScrollbarBG, h); } ckfree(h); } diff --git a/generic/ttk/ttkScrollbar.c b/generic/ttk/ttkScrollbar.c index 5ffd671..54923ff 100644 --- a/generic/ttk/ttkScrollbar.c +++ b/generic/ttk/ttkScrollbar.c @@ -31,14 +31,14 @@ typedef struct ScrollbarPart scrollbar; } Scrollbar; -static Tk_OptionSpec ScrollbarOptionSpecs[] = +static const Tk_OptionSpec ScrollbarOptionSpecs[] = { {TK_OPTION_STRING, "-command", "command", "Command", "", - Tk_Offset(Scrollbar,scrollbar.commandObj), -1, 0,0,0}, + offsetof(Scrollbar, scrollbar.commandObj), TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "vertical", - Tk_Offset(Scrollbar,scrollbar.orientObj), - Tk_Offset(Scrollbar,scrollbar.orient), + offsetof(Scrollbar, scrollbar.orientObj), + offsetof(Scrollbar, scrollbar.orient), 0, (void *)ttkOrientStrings, STYLE_CHANGED }, WIDGET_TAKEFOCUS_FALSE, @@ -296,7 +296,7 @@ static const Ttk_Ensemble ScrollbarCommands[] = { /*------------------------------------------------------------------------ * +++ Widget specification. */ -static WidgetSpec ScrollbarWidgetSpec = +static const WidgetSpec ScrollbarWidgetSpec = { "TScrollbar", /* className */ sizeof(Scrollbar), /* recordSize */ diff --git a/generic/ttk/ttkSeparator.c b/generic/ttk/ttkSeparator.c index a0ae596..e86ee5c 100644 --- a/generic/ttk/ttkSeparator.c +++ b/generic/ttk/ttkSeparator.c @@ -22,10 +22,10 @@ typedef struct SeparatorPart separator; } Separator; -static Tk_OptionSpec SeparatorOptionSpecs[] = { +static const Tk_OptionSpec SeparatorOptionSpecs[] = { {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "horizontal", - Tk_Offset(Separator,separator.orientObj), - Tk_Offset(Separator,separator.orient), + offsetof(Separator,separator.orientObj), + offsetof(Separator,separator.orient), 0, (void *)ttkOrientStrings, STYLE_CHANGED }, WIDGET_TAKEFOCUS_FALSE, @@ -39,7 +39,7 @@ static Tk_OptionSpec SeparatorOptionSpecs[] = { static Ttk_Layout SeparatorGetLayout( Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr) { - Separator *sep = recordPtr; + Separator *sep = (Separator *)recordPtr; return TtkWidgetGetOrientedLayout( interp, theme, recordPtr, sep->separator.orientObj); } @@ -59,7 +59,7 @@ static const Ttk_Ensemble SeparatorCommands[] = { /* * Widget specification: */ -static WidgetSpec SeparatorWidgetSpec = +static const WidgetSpec SeparatorWidgetSpec = { "TSeparator", /* className */ sizeof(Separator), /* recordSize */ @@ -83,7 +83,7 @@ TTK_END_LAYOUT * Has no options or methods other than the standard ones. */ -static Tk_OptionSpec SizegripOptionSpecs[] = { +static const Tk_OptionSpec SizegripOptionSpecs[] = { WIDGET_TAKEFOCUS_FALSE, WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs) }; @@ -97,7 +97,7 @@ static const Ttk_Ensemble SizegripCommands[] = { { 0,0,0 } }; -static WidgetSpec SizegripWidgetSpec = +static const WidgetSpec SizegripWidgetSpec = { "TSizegrip", /* className */ sizeof(WidgetCore), /* recordSize */ diff --git a/generic/ttk/ttkSquare.c b/generic/ttk/ttkSquare.c index bd2a8c7..422afc3 100644 --- a/generic/ttk/ttkSquare.c +++ b/generic/ttk/ttkSquare.c @@ -48,31 +48,31 @@ typedef struct * defined for all widgets. */ -static Tk_OptionSpec SquareOptionSpecs[] = +static const Tk_OptionSpec SquareOptionSpecs[] = { {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", - DEFAULT_BORDERWIDTH, Tk_Offset(Square,square.borderWidthObj), -1, + DEFAULT_BORDERWIDTH, offsetof(Square,square.borderWidthObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED }, {TK_OPTION_BORDER, "-foreground", "foreground", "Foreground", - DEFAULT_BACKGROUND, Tk_Offset(Square,square.foregroundObj), - -1, 0, 0, 0}, + DEFAULT_BACKGROUND, offsetof(Square,square.foregroundObj), + TCL_INDEX_NONE, 0, 0, 0}, {TK_OPTION_PIXELS, "-width", "width", "Width", - "50", Tk_Offset(Square,square.widthObj), -1, 0, 0, + "50", offsetof(Square,square.widthObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED}, {TK_OPTION_PIXELS, "-height", "height", "Height", - "50", Tk_Offset(Square,square.heightObj), -1, 0, 0, + "50", offsetof(Square,square.heightObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-padding", "padding", "Pad", NULL, - Tk_Offset(Square,square.paddingObj), -1, + offsetof(Square,square.paddingObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", - NULL, Tk_Offset(Square,square.reliefObj), -1, TK_OPTION_NULL_OK, 0, 0}, + NULL, offsetof(Square,square.reliefObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", - NULL, Tk_Offset(Square,square.anchorObj), -1, TK_OPTION_NULL_OK, 0, 0}, + NULL, offsetof(Square,square.anchorObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, WIDGET_TAKEFOCUS_TRUE, WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs) @@ -143,7 +143,7 @@ static const Ttk_Ensemble SquareCommands[] = { * with Tk in the package initialization code (see bottom). */ -static WidgetSpec SquareWidgetSpec = +static const WidgetSpec SquareWidgetSpec = { "TSquare", /* className */ sizeof(Square), /* recordSize */ @@ -176,18 +176,18 @@ typedef struct Tcl_Obj *heightObj; } SquareElement; -static Ttk_ElementOptionSpec SquareElementOptions[] = +static const Ttk_ElementOptionSpec SquareElementOptions[] = { - { "-background", TK_OPTION_BORDER, Tk_Offset(SquareElement,borderObj), + { "-background", TK_OPTION_BORDER, offsetof(SquareElement,borderObj), DEFAULT_BACKGROUND }, - { "-foreground", TK_OPTION_BORDER, Tk_Offset(SquareElement,foregroundObj), + { "-foreground", TK_OPTION_BORDER, offsetof(SquareElement,foregroundObj), DEFAULT_BACKGROUND }, - { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(SquareElement,borderWidthObj), + { "-borderwidth", TK_OPTION_PIXELS, offsetof(SquareElement,borderWidthObj), DEFAULT_BORDERWIDTH }, - { "-relief", TK_OPTION_RELIEF, Tk_Offset(SquareElement,reliefObj), + { "-relief", TK_OPTION_RELIEF, offsetof(SquareElement,reliefObj), "raised" }, - { "-width", TK_OPTION_PIXELS, Tk_Offset(SquareElement,widthObj), "20"}, - { "-height", TK_OPTION_PIXELS, Tk_Offset(SquareElement,heightObj), "20"}, + { "-width", TK_OPTION_PIXELS, offsetof(SquareElement,widthObj), "20"}, + { "-height", TK_OPTION_PIXELS, offsetof(SquareElement,heightObj), "20"}, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -233,7 +233,7 @@ static void SquareElementDraw( b.x, b.y, b.width, b.height, borderWidth, relief); } -static Ttk_ElementSpec SquareElementSpec = +static const Ttk_ElementSpec SquareElementSpec = { TK_STYLE_VERSION_2, sizeof(SquareElement), diff --git a/generic/ttk/ttkState.c b/generic/ttk/ttkState.c index d37f7f6..a704fa4 100644 --- a/generic/ttk/ttkState.c +++ b/generic/ttk/ttkState.c @@ -5,7 +5,6 @@ * */ -#include <string.h> #include "tkInt.h" #include "ttkTheme.h" @@ -146,14 +145,14 @@ static void StateSpecUpdateString(Tcl_Obj *objPtr) len = Tcl_DStringLength(&result); if (len) { /* 'len' includes extra trailing ' ' */ - objPtr->bytes = ckalloc(len); + objPtr->bytes = (char *)ckalloc(len); objPtr->length = len-1; strncpy(objPtr->bytes, Tcl_DStringValue(&result), len-1); objPtr->bytes[len-1] = '\0'; } else { /* empty string */ objPtr->length = 0; - objPtr->bytes = ckalloc(1); + objPtr->bytes = (char *)ckalloc(1); *objPtr->bytes = '\0'; } @@ -262,7 +261,7 @@ Ttk_StateMap Ttk_GetStateMapFromObj( * Ttk_StateTableLooup -- * Look up an index from a statically allocated state table. */ -int Ttk_StateTableLookup(Ttk_StateTable *map, unsigned int state) +int Ttk_StateTableLookup(const Ttk_StateTable *map, unsigned int state) { while ((state & map->onBits) != map->onBits || (~state & map->offBits) != map->offBits) diff --git a/generic/ttk/ttkStubInit.c b/generic/ttk/ttkStubInit.c index 0039585..dc11b4c 100644 --- a/generic/ttk/ttkStubInit.c +++ b/generic/ttk/ttkStubInit.c @@ -8,6 +8,18 @@ MODULE_SCOPE const TtkStubs ttkStubs; +#if defined(TK_NO_DEPRECATED) || TCL_MAJOR_VERSION > 8 +#define Ttk_GetOrientFromObj 0 +#endif + +#ifdef __GNUC__ +/* + * The rest of this file shouldn't warn about deprecated functions; they're + * there because we intend them to be so and know that this file is OK to + * touch those fields. + */ +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif /* !BEGIN!: Do not edit below this line. */ const TtkStubs ttkStubs = { diff --git a/generic/ttk/ttkTagSet.c b/generic/ttk/ttkTagSet.c index fc026cb..e99c76f 100644 --- a/generic/ttk/ttkTagSet.c +++ b/generic/ttk/ttkTagSet.c @@ -4,9 +4,7 @@ * Copyright (C) 2005, Joe English. Freely redistributable. */ -#include <string.h> /* for memset() */ #include "tkInt.h" - #include "ttkTheme.h" #include "ttkWidget.h" @@ -21,7 +19,7 @@ struct TtkTag { struct TtkTagTable { Tk_Window tkwin; /* owner window */ - Tk_OptionSpec *optionSpecs; /* ... */ + const Tk_OptionSpec *optionSpecs; /* ... */ Tk_OptionTable optionTable; /* ... */ int recordSize; /* size of tag record */ int nTags; /* #tags defined so far */ @@ -55,7 +53,7 @@ static void DeleteTag(Ttk_TagTable tagTable, Ttk_Tag tag) Ttk_TagTable Ttk_CreateTagTable( Tcl_Interp *interp, Tk_Window tkwin, - Tk_OptionSpec optionSpecs[], int recordSize) + const Tk_OptionSpec *optionSpecs, int recordSize) { Ttk_TagTable tagTable = (Ttk_TagTable)ckalloc(sizeof(*tagTable)); tagTable->tkwin = tkwin; @@ -82,6 +80,17 @@ void Ttk_DeleteTagTable(Ttk_TagTable tagTable) ckfree(tagTable); } +void Ttk_DeleteTagFromTable(Ttk_TagTable tagTable, Ttk_Tag tag) +{ + Tcl_HashEntry *entryPtr; + + entryPtr = Tcl_FindHashEntry(&tagTable->tags, tag->tagName); + if (entryPtr != NULL) { + DeleteTag(tagTable, tag); + Tcl_DeleteHashEntry(entryPtr); + } +} + Ttk_Tag Ttk_GetTag(Ttk_TagTable tagTable, const char *tagName) { int isNew = 0; @@ -271,8 +280,8 @@ void Ttk_TagSetValues(Ttk_TagTable tagTable, Ttk_TagSet tagSet, void *record) memset(record, 0, tagTable->recordSize); for (i = 0; tagTable->optionSpecs[i].type != TK_OPTION_END; ++i) { - Tk_OptionSpec *optionSpec = tagTable->optionSpecs + i; - int offset = optionSpec->objOffset; + const Tk_OptionSpec *optionSpec = tagTable->optionSpecs + i; + TkSizeT offset = optionSpec->objOffset; int prio = LOWEST_PRIORITY; for (j = 0; j < tagSet->nTags; ++j) { @@ -288,10 +297,10 @@ void Ttk_TagSetValues(Ttk_TagTable tagTable, Ttk_TagSet tagSet, void *record) void Ttk_TagSetApplyStyle( Ttk_TagTable tagTable, Ttk_Style style, Ttk_State state, void *record) { - Tk_OptionSpec *optionSpec = tagTable->optionSpecs; + const Tk_OptionSpec *optionSpec = tagTable->optionSpecs; while (optionSpec->type != TK_OPTION_END) { - int offset = optionSpec->objOffset; + TkSizeT offset = optionSpec->objOffset; const char *optionName = optionSpec->optionName; Tcl_Obj *val = Ttk_StyleMap(style, optionName, state); if (val) { diff --git a/generic/ttk/ttkTheme.c b/generic/ttk/ttkTheme.c index 8723b94..d06426f 100644 --- a/generic/ttk/ttkTheme.c +++ b/generic/ttk/ttkTheme.c @@ -37,7 +37,7 @@ typedef struct Ttk_Style_ static Style *NewStyle(void) { - Style *stylePtr = ckalloc(sizeof(Style)); + Style *stylePtr = (Style *)ckalloc(sizeof(Style)); stylePtr->styleName = NULL; stylePtr->parentStyle = NULL; @@ -56,7 +56,7 @@ static void FreeStyle(Style *stylePtr) entryPtr = Tcl_FirstHashEntry(&stylePtr->settingsTable, &search); while (entryPtr != NULL) { - Ttk_StateMap stateMap = Tcl_GetHashValue(entryPtr); + Ttk_StateMap stateMap = (Ttk_StateMap)Tcl_GetHashValue(entryPtr); Tcl_DecrRefCount(stateMap); entryPtr = Tcl_NextHashEntry(&search); } @@ -64,7 +64,7 @@ static void FreeStyle(Style *stylePtr) entryPtr = Tcl_FirstHashEntry(&stylePtr->defaultsTable, &search); while (entryPtr != NULL) { - Tcl_Obj *defaultValue = Tcl_GetHashValue(entryPtr); + Tcl_Obj *defaultValue = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); Tcl_DecrRefCount(defaultValue); entryPtr = Tcl_NextHashEntry(&search); } @@ -85,7 +85,7 @@ Tcl_Obj *Ttk_StyleMap(Ttk_Style style, const char *optionName, Ttk_State state) Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&style->settingsTable, optionName); if (entryPtr) { - Ttk_StateMap stateMap = Tcl_GetHashValue(entryPtr); + Ttk_StateMap stateMap = (Ttk_StateMap)Tcl_GetHashValue(entryPtr); return Ttk_StateMapLookup(NULL, stateMap, state); } style = style->parentStyle; @@ -103,7 +103,7 @@ Tcl_Obj *Ttk_StyleDefault(Ttk_Style style, const char *optionName) Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&style->defaultsTable, optionName); if (entryPtr) - return Tcl_GetHashValue(entryPtr); + return (Tcl_Obj *)Tcl_GetHashValue(entryPtr); style= style->parentStyle; } return 0; @@ -117,7 +117,7 @@ typedef const Tk_OptionSpec **OptionMap; struct Ttk_ElementClass_ { const char *name; /* Points to hash table key */ - Ttk_ElementSpec *specPtr; /* Template provided during registration. */ + const Ttk_ElementSpec *specPtr; /* Template provided during registration. */ void *clientData; /* Client data passed in at registration time */ void *elementRecord; /* Scratch buffer for element record storage */ int nResources; /* #Element options */ @@ -142,7 +142,7 @@ static const Tk_OptionSpec *TTKGetOptionSpec( /* Make sure widget option has a Tcl_Obj* entry: */ - if (optionSpec->objOffset < 0) { + if (optionSpec->objOffset == TCL_INDEX_NONE) { return 0; } @@ -176,12 +176,12 @@ static const Tk_OptionSpec *TTKGetOptionSpec( static OptionMap BuildOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable) { - OptionMap optionMap = ckalloc( + OptionMap optionMap = (OptionMap)ckalloc( sizeof(const Tk_OptionSpec) * elementClass->nResources + 1); int i; for (i = 0; i < elementClass->nResources; ++i) { - Ttk_ElementOptionSpec *e = elementClass->specPtr->options+i; + const Ttk_ElementOptionSpec *e = elementClass->specPtr->options+i; optionMap[i] = TTKGetOptionSpec(e->optionName, optionTable, e->type); } @@ -204,7 +204,7 @@ GetOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable) optionMap = BuildOptionMap(elementClass, optionTable); Tcl_SetHashValue(entryPtr, optionMap); } else { - optionMap = Tcl_GetHashValue(entryPtr); + optionMap = (OptionMap)Tcl_GetHashValue(entryPtr); } return optionMap; @@ -216,9 +216,9 @@ GetOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable) * from the specified element specification. */ static Ttk_ElementClass * -NewElementClass(const char *name, Ttk_ElementSpec *specPtr,void *clientData) +NewElementClass(const char *name, const Ttk_ElementSpec *specPtr, void *clientData) { - Ttk_ElementClass *elementClass = ckalloc(sizeof(Ttk_ElementClass)); + Ttk_ElementClass *elementClass = (Ttk_ElementClass *)ckalloc(sizeof(Ttk_ElementClass)); int i; elementClass->name = name; @@ -234,7 +234,7 @@ NewElementClass(const char *name, Ttk_ElementSpec *specPtr,void *clientData) /* Initialize default values: */ - elementClass->defaultValues = + elementClass->defaultValues = (Tcl_Obj **) ckalloc(elementClass->nResources * sizeof(Tcl_Obj *) + 1); for (i=0; i < elementClass->nResources; ++i) { const char *defaultValue = specPtr->options[i].defaultValue; @@ -291,8 +291,14 @@ static void FreeElementClass(Ttk_ElementClass *elementClass) * +++ Themes. */ -static int ThemeEnabled(Ttk_Theme theme, void *clientData) { return 1; } +static int ThemeEnabled(Ttk_Theme theme, void *dummy) +{ + (void)theme; + (void)dummy; + /* Default ThemeEnabledProc -- always return true */ + return 1; +} typedef struct Ttk_Theme_ { @@ -307,7 +313,7 @@ typedef struct Ttk_Theme_ static Theme *NewTheme(Ttk_ResourceCache cache, Ttk_Theme parent) { - Theme *themePtr = ckalloc(sizeof(Theme)); + Theme *themePtr = (Theme *)ckalloc(sizeof(Theme)); Tcl_HashEntry *entryPtr; int unused; @@ -324,7 +330,7 @@ static Theme *NewTheme(Ttk_ResourceCache cache, Ttk_Theme parent) entryPtr = Tcl_CreateHashEntry(&themePtr->styleTable, ".", &unused); themePtr->rootStyle = NewStyle(); themePtr->rootStyle->styleName = - Tcl_GetHashKey(&themePtr->styleTable, entryPtr); + (const char *)Tcl_GetHashKey(&themePtr->styleTable, entryPtr); themePtr->rootStyle->cache = themePtr->cache; Tcl_SetHashValue(entryPtr, themePtr->rootStyle); @@ -341,7 +347,7 @@ static void FreeTheme(Theme *themePtr) */ entryPtr = Tcl_FirstHashEntry(&themePtr->elementTable, &search); while (entryPtr != NULL) { - Ttk_ElementClass *elementClass = Tcl_GetHashValue(entryPtr); + Ttk_ElementClass *elementClass = (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr); FreeElementClass(elementClass); entryPtr = Tcl_NextHashEntry(&search); } @@ -352,7 +358,7 @@ static void FreeTheme(Theme *themePtr) */ entryPtr = Tcl_FirstHashEntry(&themePtr->styleTable, &search); while (entryPtr != NULL) { - Style *stylePtr = Tcl_GetHashValue(entryPtr); + Style *stylePtr = (Style *)Tcl_GetHashValue(entryPtr); FreeStyle(stylePtr); entryPtr = Tcl_NextHashEntry(&search); } @@ -403,12 +409,13 @@ static void ThemeChangedProc(void *); /* Forward */ /* Ttk_StylePkgFree -- * Cleanup procedure for StylePackageData. */ -static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp) +static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *dummy) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Tcl_HashSearch search; Tcl_HashEntry *entryPtr; Cleanup *cleanup; + (void)dummy; /* * Cancel any pending ThemeChanged calls: @@ -422,7 +429,7 @@ static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp) */ entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search); while (entryPtr != NULL) { - Theme *themePtr = Tcl_GetHashValue(entryPtr); + Theme *themePtr = (Theme *)Tcl_GetHashValue(entryPtr); FreeTheme(themePtr); entryPtr = Tcl_NextHashEntry(&search); } @@ -464,7 +471,7 @@ static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp) static StylePackageData *GetStylePackageData(Tcl_Interp *interp) { - return Tcl_GetAssocData(interp, PKG_ASSOC_KEY, NULL); + return (StylePackageData *)Tcl_GetAssocData(interp, PKG_ASSOC_KEY, NULL); } /* @@ -479,8 +486,8 @@ static StylePackageData *GetStylePackageData(Tcl_Interp *interp) void Ttk_RegisterCleanup( Tcl_Interp *interp, ClientData clientData, Ttk_CleanupProc *cleanupProc) { - StylePackageData *pkgPtr = GetStylePackageData(interp); - Cleanup *cleanup = ckalloc(sizeof(*cleanup)); + StylePackageData *pkgPtr = (StylePackageData *)GetStylePackageData(interp); + Cleanup *cleanup = (Cleanup *)ckalloc(sizeof(*cleanup)); cleanup->clientData = clientData; cleanup->cleanupProc = cleanupProc; @@ -503,7 +510,7 @@ void Ttk_RegisterCleanup( static void ThemeChangedProc(ClientData clientData) { static char ThemeChangedScript[] = "ttk::ThemeChanged"; - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; int code = Tcl_EvalEx(pkgPtr->interp, ThemeChangedScript, -1, TCL_EVAL_GLOBAL); if (code != TCL_OK) { @@ -596,7 +603,7 @@ static Ttk_Theme LookupTheme( return NULL; } - return Tcl_GetHashValue(entryPtr); + return (Ttk_Theme)Tcl_GetHashValue(entryPtr); } /* @@ -704,12 +711,12 @@ Ttk_Style Ttk_GetStyle(Ttk_Theme themePtr, const char *styleName) stylePtr->parentStyle = themePtr->rootStyle; } - stylePtr->styleName = Tcl_GetHashKey(&themePtr->styleTable, entryPtr); + stylePtr->styleName = (const char *)Tcl_GetHashKey(&themePtr->styleTable, entryPtr); stylePtr->cache = stylePtr->parentStyle->cache; Tcl_SetHashValue(entryPtr, stylePtr); return stylePtr; } - return Tcl_GetHashValue(entryPtr); + return (Ttk_Style)Tcl_GetHashValue(entryPtr); } /* FindLayoutTemplate -- @@ -755,7 +762,7 @@ Ttk_ElementClass *Ttk_GetElement(Ttk_Theme themePtr, const char *elementName) */ entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, elementName); if (entryPtr) { - return Tcl_GetHashValue(entryPtr); + return (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr); } /* @@ -766,7 +773,7 @@ Ttk_ElementClass *Ttk_GetElement(Ttk_Theme themePtr, const char *elementName) entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, dot); } if (entryPtr) { - return Tcl_GetHashValue(entryPtr); + return (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr); } /* @@ -782,7 +789,7 @@ Ttk_ElementClass *Ttk_GetElement(Ttk_Theme themePtr, const char *elementName) */ entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, ""); /* ASSERT: entryPtr != 0 */ - return Tcl_GetHashValue(entryPtr); + return (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr); } const char *Ttk_ElementClassName(Ttk_ElementClass *elementClass) @@ -799,7 +806,7 @@ int Ttk_RegisterElementFactory( Ttk_ElementFactory factory, void *clientData) { StylePackageData *pkgPtr = GetStylePackageData(interp); - FactoryRec *recPtr = ckalloc(sizeof(*recPtr)); + FactoryRec *recPtr = (FactoryRec *)ckalloc(sizeof(*recPtr)); Tcl_HashEntry *entryPtr; int newEntry; @@ -820,12 +827,13 @@ int Ttk_RegisterElementFactory( * (style element create $name) "from" $theme ?$element? */ static int Ttk_CloneElement( - Tcl_Interp *interp, void *clientData, + Tcl_Interp *interp, void *dummy, Ttk_Theme theme, const char *elementName, int objc, Tcl_Obj *const objv[]) { Ttk_Theme fromTheme; Ttk_ElementClass *fromElement; + (void)dummy; if (objc <= 0 || objc > 2) { Tcl_WrongNumArgs(interp, 0, objv, "theme ?element?"); @@ -865,7 +873,7 @@ Ttk_ElementClass *Ttk_RegisterElement( Tcl_Interp *interp, /* Where to leave error messages */ Ttk_Theme theme, /* Style engine providing the implementation. */ const char *name, /* Name of new element */ - Ttk_ElementSpec *specPtr, /* Static template information */ + const Ttk_ElementSpec *specPtr, /* Static template information */ void *clientData) /* application-specific data */ { Ttk_ElementClass *elementClass; @@ -895,7 +903,7 @@ Ttk_ElementClass *Ttk_RegisterElement( return 0; } - name = Tcl_GetHashKey(&theme->elementTable, entryPtr); + name = (char *)Tcl_GetHashKey(&theme->elementTable, entryPtr); elementClass = NewElementClass(name, specPtr, clientData); Tcl_SetHashValue(entryPtr, elementClass); @@ -906,7 +914,7 @@ Ttk_ElementClass *Ttk_RegisterElement( * Register a new element. */ int Ttk_RegisterElementSpec(Ttk_Theme theme, - const char *name, Ttk_ElementSpec *specPtr, void *clientData) + const char *name, const Ttk_ElementSpec *specPtr, void *clientData) { return Ttk_RegisterElement(NULL, theme, name, specPtr, clientData) ? TCL_OK : TCL_ERROR; @@ -970,21 +978,21 @@ static int InitializeElementRecord( Ttk_ElementClass *eclass, /* Element instance to initialize */ Ttk_Style style, /* Style table */ - char *widgetRecord, /* Source of widget option values */ + void *widgetRecord, /* Source of widget option values */ Tk_OptionTable optionTable, /* Option table describing widget record */ Tk_Window tkwin, /* Corresponding window */ Ttk_State state) /* Widget or element state */ { - char *elementRecord = eclass->elementRecord; + void *elementRecord = eclass->elementRecord; OptionMap optionMap = GetOptionMap(eclass,optionTable); int nResources = eclass->nResources; Ttk_ResourceCache cache = style->cache; - Ttk_ElementOptionSpec *elementOption = eclass->specPtr->options; + const Ttk_ElementOptionSpec *elementOption = eclass->specPtr->options; int i; for (i=0; i<nResources; ++i, ++elementOption) { Tcl_Obj **dest = (Tcl_Obj **) - (elementRecord + elementOption->offset); + ((char *)elementRecord + elementOption->offset); const char *optionName = elementOption->optionName; Tcl_Obj *dynamicSetting = Ttk_StyleMap(style, optionName, state); Tcl_Obj *widgetValue = 0; @@ -992,7 +1000,7 @@ int InitializeElementRecord( if (optionMap[i]) { widgetValue = *(Tcl_Obj **) - (widgetRecord + optionMap[i]->objOffset); + ((char *)widgetRecord + optionMap[i]->objOffset); } if (widgetValue) { @@ -1064,7 +1072,7 @@ void Ttk_ElementSize( Ttk_ElementClass *eclass, /* Element to query */ Ttk_Style style, /* Style settings */ - char *recordPtr, /* The widget record. */ + void *recordPtr, /* The widget record. */ Tk_OptionTable optionTable, /* Description of widget record */ Tk_Window tkwin, /* The widget window. */ Ttk_State state, /* Current widget state */ @@ -1094,7 +1102,7 @@ void Ttk_DrawElement( Ttk_ElementClass *eclass, /* Element instance */ Ttk_Style style, /* Style settings */ - char *recordPtr, /* The widget record. */ + void *recordPtr, /* The widget record. */ Tk_OptionTable optionTable, /* Description of option table */ Tk_Window tkwin, /* The widget window. */ Drawable d, /* Where to draw element. */ @@ -1134,7 +1142,7 @@ int TtkEnumerateHashTable(Tcl_Interp *interp, Tcl_HashTable *ht) Tcl_HashEntry *entryPtr = Tcl_FirstHashEntry(ht, &search); while (entryPtr != NULL) { - Tcl_Obj *nameObj = Tcl_NewStringObj(Tcl_GetHashKey(ht, entryPtr),-1); + Tcl_Obj *nameObj = Tcl_NewStringObj((const char *)Tcl_GetHashKey(ht, entryPtr),-1); Tcl_ListObjAppendElement(interp, result, nameObj); entryPtr = Tcl_NextHashEntry(&search); } @@ -1154,8 +1162,8 @@ static Tcl_Obj* HashTableToDict(Tcl_HashTable *ht) Tcl_HashEntry *entryPtr = Tcl_FirstHashEntry(ht, &search); while (entryPtr != NULL) { - Tcl_Obj *nameObj = Tcl_NewStringObj(Tcl_GetHashKey(ht, entryPtr),-1); - Tcl_Obj *valueObj = Tcl_GetHashValue(entryPtr); + Tcl_Obj *nameObj = Tcl_NewStringObj((const char *)Tcl_GetHashKey(ht, entryPtr),-1); + Tcl_Obj *valueObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr); Tcl_ListObjAppendElement(NULL, result, nameObj); Tcl_ListObjAppendElement(NULL, result, valueObj); entryPtr = Tcl_NextHashEntry(&search); @@ -1176,7 +1184,7 @@ StyleMapCmd( int objc, /* Number of arguments */ Tcl_Obj *const objv[]) /* Argument objects */ { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme = pkgPtr->currentTheme; const char *styleName; Style *stylePtr; @@ -1240,7 +1248,7 @@ usage: static int StyleConfigureCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme = pkgPtr->currentTheme; const char *styleName; Style *stylePtr; @@ -1295,7 +1303,7 @@ usage: static int StyleLookupCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme = pkgPtr->currentTheme; Ttk_Style style = NULL; const char *optionName; @@ -1337,7 +1345,7 @@ static int StyleLookupCmd( static int StyleThemeCurrentCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Tcl_HashSearch search; Tcl_HashEntry *entryPtr = NULL; const char *name = NULL; @@ -1349,9 +1357,9 @@ static int StyleThemeCurrentCmd( entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search); while (entryPtr != NULL) { - Theme *ptr = Tcl_GetHashValue(entryPtr); + Theme *ptr = (Theme *)Tcl_GetHashValue(entryPtr); if (ptr == pkgPtr->currentTheme) { - name = Tcl_GetHashKey(&pkgPtr->themeTable, entryPtr); + name = (char *)Tcl_GetHashKey(&pkgPtr->themeTable, entryPtr); break; } entryPtr = Tcl_NextHashEntry(&search); @@ -1373,8 +1381,8 @@ static int StyleThemeCurrentCmd( static int StyleThemeCreateCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; - static const char *optStrings[] = + StylePackageData *pkgPtr = (StylePackageData *)clientData; + static const char *const optStrings[] = { "-parent", "-settings", NULL }; enum { OP_PARENT, OP_SETTINGS }; Ttk_Theme parentTheme = pkgPtr->defaultTheme, newTheme; @@ -1437,7 +1445,10 @@ static int StyleThemeCreateCmd( static int StyleThemeNamesCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; + (void)objc; + (void)objv; + return TtkEnumerateHashTable(interp, &pkgPtr->themeTable); } @@ -1453,7 +1464,7 @@ StyleThemeSettingsCmd( int objc, /* Number of arguments */ Tcl_Obj *const objv[]) /* Argument objects */ { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme oldTheme = pkgPtr->currentTheme; Ttk_Theme newTheme; int status; @@ -1479,7 +1490,7 @@ StyleThemeSettingsCmd( static int StyleElementCreateCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme = pkgPtr->currentTheme; const char *elementName, *factoryName; Tcl_HashEntry *entryPtr; @@ -1502,7 +1513,7 @@ static int StyleElementCreateCmd( return TCL_ERROR; } - recPtr = Tcl_GetHashValue(entryPtr); + recPtr = (FactoryRec *)Tcl_GetHashValue(entryPtr); return recPtr->factory(interp, recPtr->clientData, theme, elementName, objc - 5, objv + 5); @@ -1514,7 +1525,7 @@ static int StyleElementCreateCmd( static int StyleElementNamesCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme = pkgPtr->currentTheme; if (objc != 3) { @@ -1530,7 +1541,7 @@ static int StyleElementNamesCmd( static int StyleElementOptionsCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme = pkgPtr->currentTheme; const char *elementName; Ttk_ElementClass *elementClass; @@ -1543,8 +1554,8 @@ static int StyleElementOptionsCmd( elementName = Tcl_GetString(objv[3]); elementClass = Ttk_GetElement(theme, elementName); if (elementClass) { - Ttk_ElementSpec *specPtr = elementClass->specPtr; - Ttk_ElementOptionSpec *option = specPtr->options; + const Ttk_ElementSpec *specPtr = elementClass->specPtr; + const Ttk_ElementOptionSpec *option = specPtr->options; Tcl_Obj *result = Tcl_NewListObj(0,0); while (option->optionName) { @@ -1568,7 +1579,7 @@ static int StyleElementOptionsCmd( static int StyleLayoutCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme = pkgPtr->currentTheme; const char *layoutName; Ttk_LayoutTemplate layoutTemplate; @@ -1611,7 +1622,7 @@ StyleThemeUseCmd( int objc, /* Number of arguments */ Tcl_Obj *const objv[]) /* Argument objects */ { - StylePackageData *pkgPtr = clientData; + StylePackageData *pkgPtr = (StylePackageData *)clientData; Ttk_Theme theme; if (objc < 3 || objc > 4) { @@ -1706,7 +1717,7 @@ void Ttk_StylePkgInit(Tcl_Interp *interp) { Tcl_Namespace *nsPtr; - StylePackageData *pkgPtr = ckalloc(sizeof(StylePackageData)); + StylePackageData *pkgPtr = (StylePackageData *)ckalloc(sizeof(StylePackageData)); pkgPtr->interp = interp; Tcl_InitHashTable(&pkgPtr->themeTable, TCL_STRING_KEYS); diff --git a/generic/ttk/ttkTheme.h b/generic/ttk/ttkTheme.h index cf0a07c..7f9f6e9 100644 --- a/generic/ttk/ttkTheme.h +++ b/generic/ttk/ttkTheme.h @@ -75,17 +75,11 @@ typedef struct #define Ttk_ModifyState(state, spec) \ (((state) & ~(spec)->offbits) | (spec)->onbits) -TTKAPI int Ttk_GetStateSpecFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_StateSpec *); -TTKAPI Tcl_Obj *Ttk_NewStateSpecObj(unsigned int onbits,unsigned int offbits); - /*------------------------------------------------------------------------ * +++ State maps and state tables. */ typedef Tcl_Obj *Ttk_StateMap; -TTKAPI Ttk_StateMap Ttk_GetStateMapFromObj(Tcl_Interp *, Tcl_Obj *); -TTKAPI Tcl_Obj *Ttk_StateMapLookup(Tcl_Interp*, Ttk_StateMap, Ttk_State); - /* * Table for looking up an integer index based on widget state: */ @@ -96,8 +90,6 @@ typedef struct unsigned int offBits; /* Bits which must be cleared */ } Ttk_StateTable; -TTKAPI int Ttk_StateTableLookup(Ttk_StateTable map[], Ttk_State); - /*------------------------------------------------------------------------ * +++ Padding. * Used to represent internal padding and borders. @@ -110,14 +102,6 @@ typedef struct short bottom; } Ttk_Padding; -TTKAPI int Ttk_GetPaddingFromObj(Tcl_Interp*,Tk_Window,Tcl_Obj*,Ttk_Padding*); -TTKAPI int Ttk_GetBorderFromObj(Tcl_Interp*,Tcl_Obj*,Ttk_Padding*); - -TTKAPI Ttk_Padding Ttk_MakePadding(short l, short t, short r, short b); -TTKAPI Ttk_Padding Ttk_UniformPadding(short borderWidth); -TTKAPI Ttk_Padding Ttk_AddPadding(Ttk_Padding, Ttk_Padding); -TTKAPI Ttk_Padding Ttk_RelievePadding(Ttk_Padding, int relief, int n); - #define Ttk_PaddingWidth(p) ((p).left + (p).right) #define Ttk_PaddingHeight(p) ((p).top + (p).bottom) @@ -136,9 +120,6 @@ typedef struct /* Hey, this is an XRectangle! */ int height; } Ttk_Box; -TTKAPI Ttk_Box Ttk_MakeBox(int x, int y, int width, int height); -TTKAPI int Ttk_BoxContains(Ttk_Box, int x, int y); - #define Ttk_WinBox(tkwin) Ttk_MakeBox(0,0,Tk_Width(tkwin),Tk_Height(tkwin)) /*------------------------------------------------------------------------ @@ -165,7 +146,6 @@ typedef unsigned int Ttk_Sticky; #define TTK_FILL_Y (0xC) /* -sticky ns */ #define TTK_FILL_BOTH (0xF) /* -sticky nswe */ -TTKAPI int Ttk_GetStickyFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_Sticky *); TTKAPI Tcl_Obj *Ttk_NewStickyObj(Ttk_Sticky); /* @@ -192,12 +172,6 @@ typedef unsigned int Ttk_PositionSpec; /* See below */ #define _TTK_MASK_STICK (0x0F) /* See Ttk_UnparseLayout() */ #define _TTK_MASK_PACK (0xF0) /* See Ttk_UnparseLayout(), packStrings */ -TTKAPI Ttk_Box Ttk_PackBox(Ttk_Box *cavity, int w, int h, Ttk_Side side); -TTKAPI Ttk_Box Ttk_StickBox(Ttk_Box parcel, int w, int h, Ttk_Sticky sticky); -TTKAPI Ttk_Box Ttk_AnchorBox(Ttk_Box parcel, int w, int h, Tk_Anchor anchor); -TTKAPI Ttk_Box Ttk_PadBox(Ttk_Box b, Ttk_Padding p); -TTKAPI Ttk_Box Ttk_ExpandBox(Ttk_Box b, Ttk_Padding p); -TTKAPI Ttk_Box Ttk_PlaceBox(Ttk_Box *cavity, int w,int h, Ttk_Side,Ttk_Sticky); TTKAPI Ttk_Box Ttk_PositionBox(Ttk_Box *cavity, int w, int h, Ttk_PositionSpec); /*------------------------------------------------------------------------ @@ -211,21 +185,12 @@ typedef struct Ttk_Layout_ *Ttk_Layout; typedef struct Ttk_LayoutNode_ *Ttk_Element; typedef struct Ttk_Style_ *Ttk_Style; -TTKAPI Ttk_Theme Ttk_GetTheme(Tcl_Interp *interp, const char *name); -TTKAPI Ttk_Theme Ttk_GetDefaultTheme(Tcl_Interp *interp); -TTKAPI Ttk_Theme Ttk_GetCurrentTheme(Tcl_Interp *interp); - -TTKAPI Ttk_Theme Ttk_CreateTheme( - Tcl_Interp *interp, const char *name, Ttk_Theme parent); - typedef int (Ttk_ThemeEnabledProc)(Ttk_Theme theme, void *clientData); MODULE_SCOPE void Ttk_SetThemeEnabledProc(Ttk_Theme, Ttk_ThemeEnabledProc, void *); MODULE_SCOPE int Ttk_UseTheme(Tcl_Interp *, Ttk_Theme); typedef void (Ttk_CleanupProc)(void *clientData); -TTKAPI void Ttk_RegisterCleanup( - Tcl_Interp *interp, void *deleteData, Ttk_CleanupProc *cleanupProc); /*------------------------------------------------------------------------ * +++ Elements. @@ -238,11 +203,19 @@ typedef void (Ttk_ElementSizeProc)(void *clientData, void *elementRecord, typedef void (Ttk_ElementDrawProc)(void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state); +#ifndef TkSizeT +# if TCL_MAJOR_VERSION > 8 +# define TkSizeT size_t +# else +# define TkSizeT int +# endif +#endif + typedef struct Ttk_ElementOptionSpec { const char *optionName; /* Command-line name of the widget option */ Tk_OptionType type; /* Accepted option types */ - int offset; /* Offset of Tcl_Obj* field in element record */ + TkSizeT offset; /* Offset of Tcl_Obj* field in element record */ const char *defaultValue; /* Default value to used if resource missing */ } Ttk_ElementOptionSpec; @@ -251,22 +224,15 @@ typedef struct Ttk_ElementOptionSpec typedef struct Ttk_ElementSpec { enum TTKStyleVersion2 version; /* Version of the style support. */ size_t elementSize; /* Size of element record */ - Ttk_ElementOptionSpec *options; /* List of options, NULL-terminated */ + const Ttk_ElementOptionSpec *options; /* List of options, NULL-terminated */ Ttk_ElementSizeProc *size; /* Compute min size and padding */ Ttk_ElementDrawProc *draw; /* Draw the element */ } Ttk_ElementSpec; -TTKAPI Ttk_ElementClass *Ttk_RegisterElement( - Tcl_Interp *interp, Ttk_Theme theme, const char *elementName, - Ttk_ElementSpec *, void *clientData); - typedef int (*Ttk_ElementFactory) (Tcl_Interp *, void *clientData, Ttk_Theme, const char *elementName, int objc, Tcl_Obj *const objv[]); -TTKAPI int Ttk_RegisterElementFactory( - Tcl_Interp *, const char *name, Ttk_ElementFactory, void *clientData); - /* * Null element implementation: * has no geometry or layout; may be used as a stub or placeholder. @@ -280,7 +246,7 @@ MODULE_SCOPE void TtkNullElementSize (void *, void *, Tk_Window, int *, int *, Ttk_Padding *); MODULE_SCOPE void TtkNullElementDraw (void *, void *, Tk_Window, Drawable, Ttk_Box, Ttk_State); -MODULE_SCOPE Ttk_ElementOptionSpec TtkNullElementOptions[]; +MODULE_SCOPE const Ttk_ElementOptionSpec TtkNullElementOptions[]; MODULE_SCOPE Ttk_ElementSpec ttkNullElementSpec; /*------------------------------------------------------------------------ @@ -307,9 +273,6 @@ typedef struct { #define TTK_BEGIN_LAYOUT(name) static TTKLayoutInstruction name[] = { #define TTK_END_LAYOUT { 0, _TTK_LAYOUT_END } }; -TTKAPI void Ttk_RegisterLayout( - Ttk_Theme theme, const char *className, Ttk_LayoutSpec layoutSpec); - TTKAPI void Ttk_RegisterLayouts( Ttk_Theme theme, Ttk_LayoutSpec layoutTable); @@ -392,7 +355,7 @@ typedef enum /* -default option values */ TTK_BUTTON_DEFAULT_DISABLED /* not defaultable */ } Ttk_ButtonDefaultState; -TTKAPI int Ttk_GetButtonDefaultStateFromObj(Tcl_Interp *, Tcl_Obj *, int *); +TTKAPI int Ttk_GetButtonDefaultStateFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_ButtonDefaultState *); typedef enum /* -compound option values */ { @@ -406,13 +369,16 @@ typedef enum /* -compound option values */ TTK_COMPOUND_RIGHT /* image to right of text */ } Ttk_Compound; -TTKAPI int Ttk_GetCompoundFromObj(Tcl_Interp *, Tcl_Obj *, int *); +TTKAPI int Ttk_GetCompoundFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_Compound *); typedef enum { /* -orient option values */ TTK_ORIENT_HORIZONTAL, TTK_ORIENT_VERTICAL } Ttk_Orient; +MODULE_SCOPE int TtkGetOrientFromObj(Tcl_Interp *interp, + Tcl_Obj *objPtr, Ttk_Orient *orient); + /*------------------------------------------------------------------------ * +++ Utilities. */ diff --git a/generic/ttk/ttkThemeInt.h b/generic/ttk/ttkThemeInt.h index 3aaada8..25a5fdf 100644 --- a/generic/ttk/ttkThemeInt.h +++ b/generic/ttk/ttkThemeInt.h @@ -15,11 +15,11 @@ MODULE_SCOPE Ttk_ElementClass *Ttk_GetElement(Ttk_Theme, const char *name); MODULE_SCOPE const char *Ttk_ElementClassName(Ttk_ElementClass *); MODULE_SCOPE void Ttk_ElementSize( - Ttk_ElementClass *, Ttk_Style, char *recordPtr, Tk_OptionTable, + Ttk_ElementClass *, Ttk_Style, void *recordPtr, Tk_OptionTable, Tk_Window tkwin, Ttk_State state, int *widthPtr, int *heightPtr, Ttk_Padding*); MODULE_SCOPE void Ttk_DrawElement( - Ttk_ElementClass *, Ttk_Style, char *recordPtr, Tk_OptionTable, + Ttk_ElementClass *, Ttk_Style, void *recordPtr, Tk_OptionTable, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state); MODULE_SCOPE Tcl_Obj *Ttk_QueryStyle( diff --git a/generic/ttk/ttkTrack.c b/generic/ttk/ttkTrack.c index fa2a7e0..b9aa776 100644 --- a/generic/ttk/ttkTrack.c +++ b/generic/ttk/ttkTrack.c @@ -16,11 +16,11 @@ * and is normally set to the ACTIVE state unless another element * is currently being pressed. * - * The active element becomes "pressed" on <ButtonPress> events, + * The active element becomes "pressed" on <Button> events, * and remains "active" and "pressed" until the corresponding * <ButtonRelease> event. * - * TODO: Handle "chords" properly (e.g., <B1-ButtonPress-2>) + * TODO: Handle "chords" properly (e.g., <B1-Button-2>) */ #include "tkInt.h" @@ -118,7 +118,7 @@ static const unsigned ElementStateMask = static void ElementStateEventProc(ClientData clientData, XEvent *ev) { - ElementStateTracker *es = clientData; + ElementStateTracker *es = (ElementStateTracker *)clientData; Ttk_Layout layout = es->corePtr->layout; Ttk_Element element; @@ -173,7 +173,7 @@ ElementStateEventProc(ClientData clientData, XEvent *ev) void TtkTrackElementState(WidgetCore *corePtr) { - ElementStateTracker *es = ckalloc(sizeof(*es)); + ElementStateTracker *es = (ElementStateTracker *)ckalloc(sizeof(*es)); es->corePtr = corePtr; es->tracking = 0; es->activeElement = es->pressedElement = 0; diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index 0a156a5..4ea4c17 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -4,8 +4,6 @@ * ttk::treeview widget implementation. */ -#include <string.h> -#include <stdio.h> #include "tkInt.h" #include "ttkTheme.h" #include "ttkWidget.h" @@ -61,32 +59,35 @@ struct TreeItemRec { #define ITEM_OPTION_TAGS_CHANGED 0x100 #define ITEM_OPTION_IMAGE_CHANGED 0x200 -static Tk_OptionSpec ItemOptionSpecs[] = { +static const Tk_OptionSpec ItemOptionSpecs[] = { {TK_OPTION_STRING, "-text", "text", "Text", - "", Tk_Offset(TreeItem,textObj), -1, + "", offsetof(TreeItem,textObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-image", "image", "Image", - NULL, Tk_Offset(TreeItem,imageObj), -1, + NULL, offsetof(TreeItem,imageObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,ITEM_OPTION_IMAGE_CHANGED }, {TK_OPTION_STRING, "-values", "values", "Values", - NULL, Tk_Offset(TreeItem,valuesObj), -1, + NULL, offsetof(TreeItem,valuesObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_BOOLEAN, "-open", "open", "Open", - "0", Tk_Offset(TreeItem,openObj), -1, + "0", offsetof(TreeItem,openObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-tags", "tags", "Tags", - NULL, Tk_Offset(TreeItem,tagsObj), -1, + NULL, offsetof(TreeItem,tagsObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,ITEM_OPTION_TAGS_CHANGED }, - {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0} + {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0} }; +/* Forward declaration */ +static void RemoveTag(TreeItem *, Ttk_Tag); + /* + NewItem -- * Allocate a new, uninitialized, unlinked item */ static TreeItem *NewItem(void) { - TreeItem *item = ckalloc(sizeof(*item)); + TreeItem *item = (TreeItem *)ckalloc(sizeof(*item)); item->entryPtr = 0; item->parent = item->children = item->next = item->prev = NULL; @@ -121,7 +122,7 @@ static void FreeItem(TreeItem *item) ckfree(item); } -static void FreeItemCB(void *clientData) { FreeItem(clientData); } +static void FreeItemCB(void *clientData) { FreeItem((TreeItem *)clientData); } /* + DetachItem -- * Unlink an item from the tree. @@ -189,27 +190,27 @@ typedef struct { Tcl_Obj *fontObj; } DisplayItem; -static Tk_OptionSpec TagOptionSpecs[] = { +static const Tk_OptionSpec TagOptionSpecs[] = { {TK_OPTION_STRING, "-text", "text", "Text", - NULL, Tk_Offset(DisplayItem,textObj), -1, + NULL, offsetof(DisplayItem,textObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_STRING, "-image", "image", "Image", - NULL, Tk_Offset(DisplayItem,imageObj), -1, + NULL, offsetof(DisplayItem,imageObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", - NULL, Tk_Offset(DisplayItem,anchorObj), -1, + NULL, offsetof(DisplayItem,anchorObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED}, /* <<NOTE-ANCHOR>> */ {TK_OPTION_COLOR, "-background", "windowColor", "WindowColor", - NULL, Tk_Offset(DisplayItem,backgroundObj), -1, + NULL, offsetof(DisplayItem,backgroundObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor", - NULL, Tk_Offset(DisplayItem,foregroundObj), -1, + NULL, offsetof(DisplayItem,foregroundObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_FONT, "-font", "font", "Font", - NULL, Tk_Offset(DisplayItem,fontObj), -1, + NULL, offsetof(DisplayItem,fontObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, - {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0} + {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0} }; /*------------------------------------------------------------------------ @@ -273,42 +274,42 @@ static void FreeColumn(TreeColumn *column) /* Don't touch column->data, it's scratch storage */ } -static Tk_OptionSpec ColumnOptionSpecs[] = { +static const Tk_OptionSpec ColumnOptionSpecs[] = { {TK_OPTION_INT, "-width", "width", "Width", - DEF_COLWIDTH, -1, Tk_Offset(TreeColumn,width), + DEF_COLWIDTH, TCL_INDEX_NONE, offsetof(TreeColumn,width), 0,0,GEOMETRY_CHANGED }, {TK_OPTION_INT, "-minwidth", "minWidth", "MinWidth", - DEF_MINWIDTH, -1, Tk_Offset(TreeColumn,minWidth), + DEF_MINWIDTH, TCL_INDEX_NONE, offsetof(TreeColumn,minWidth), 0,0,0 }, {TK_OPTION_BOOLEAN, "-stretch", "stretch", "Stretch", - "1", -1, Tk_Offset(TreeColumn,stretch), + "1", TCL_INDEX_NONE, offsetof(TreeColumn,stretch), 0,0,GEOMETRY_CHANGED }, {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", - "w", Tk_Offset(TreeColumn,anchorObj), -1, /* <<NOTE-ANCHOR>> */ + "w", offsetof(TreeColumn,anchorObj), TCL_INDEX_NONE, /* <<NOTE-ANCHOR>> */ 0,0,0 }, {TK_OPTION_STRING, "-id", "id", "ID", - NULL, Tk_Offset(TreeColumn,idObj), -1, + NULL, offsetof(TreeColumn,idObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,READONLY_OPTION }, - {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0} + {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0} }; -static Tk_OptionSpec HeadingOptionSpecs[] = { +static const Tk_OptionSpec HeadingOptionSpecs[] = { {TK_OPTION_STRING, "-text", "text", "Text", - "", Tk_Offset(TreeColumn,headingObj), -1, + "", offsetof(TreeColumn,headingObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-image", "image", "Image", - "", Tk_Offset(TreeColumn,headingImageObj), -1, + "", offsetof(TreeColumn,headingImageObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", - "center", Tk_Offset(TreeColumn,headingAnchorObj), -1, + "center", offsetof(TreeColumn,headingAnchorObj), TCL_INDEX_NONE, 0,0,0 }, {TK_OPTION_STRING, "-command", "", "", - "", Tk_Offset(TreeColumn,headingCommandObj), -1, + "", offsetof(TreeColumn,headingCommandObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 }, {TK_OPTION_STRING, "state", "", "", - "", Tk_Offset(TreeColumn,headingStateObj), -1, + "", offsetof(TreeColumn,headingStateObj), TCL_INDEX_NONE, 0,0,STATE_CHANGED }, - {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0} + {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0} }; /*------------------------------------------------------------------------ @@ -321,14 +322,14 @@ static Tk_OptionSpec HeadingOptionSpecs[] = { #define DEFAULT_SHOW "tree headings" -static const char *showStrings[] = { +static const char *const showStrings[] = { "tree", "headings", NULL }; static int GetEnumSetFromObj( Tcl_Interp *interp, Tcl_Obj *objPtr, - const char *table[], + const char *const table[], unsigned *resultPtr) { unsigned result = 0; @@ -435,35 +436,35 @@ typedef struct { #define SCROLLCMD_CHANGED (USER_MASK<<2) #define SHOW_CHANGED (USER_MASK<<3) -static const char *SelectModeStrings[] = { "none", "browse", "extended", NULL }; +static const char *const SelectModeStrings[] = { "none", "browse", "extended", NULL }; -static Tk_OptionSpec TreeviewOptionSpecs[] = { +static const Tk_OptionSpec TreeviewOptionSpecs[] = { {TK_OPTION_STRING, "-columns", "columns", "Columns", - "", Tk_Offset(Treeview,tree.columnsObj), -1, - 0,0,COLUMNS_CHANGED | GEOMETRY_CHANGED /*| READONLY_OPTION*/ }, + "", offsetof(Treeview,tree.columnsObj), TCL_INDEX_NONE, + 0, 0,COLUMNS_CHANGED | GEOMETRY_CHANGED /*| READONLY_OPTION*/ }, {TK_OPTION_STRING, "-displaycolumns","displayColumns","DisplayColumns", - "#all", Tk_Offset(Treeview,tree.displayColumnsObj), -1, - 0,0,DCOLUMNS_CHANGED | GEOMETRY_CHANGED }, + "#all", offsetof(Treeview,tree.displayColumnsObj), TCL_INDEX_NONE, + 0, 0,DCOLUMNS_CHANGED | GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-show", "show", "Show", - DEFAULT_SHOW, Tk_Offset(Treeview,tree.showObj), -1, - 0,0,SHOW_CHANGED | GEOMETRY_CHANGED }, + DEFAULT_SHOW, offsetof(Treeview,tree.showObj), TCL_INDEX_NONE, + 0, 0,SHOW_CHANGED | GEOMETRY_CHANGED }, {TK_OPTION_STRING_TABLE, "-selectmode", "selectMode", "SelectMode", - "extended", Tk_Offset(Treeview,tree.selectModeObj), -1, - 0,(ClientData)SelectModeStrings,0 }, + "extended", offsetof(Treeview,tree.selectModeObj), TCL_INDEX_NONE, + 0, (void *)SelectModeStrings, 0 }, {TK_OPTION_PIXELS, "-height", "height", "Height", - DEF_TREE_ROWS, Tk_Offset(Treeview,tree.heightObj), -1, - 0,0,GEOMETRY_CHANGED}, + DEF_TREE_ROWS, offsetof(Treeview,tree.heightObj), TCL_INDEX_NONE, + 0, 0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-padding", "padding", "Pad", - NULL, Tk_Offset(Treeview,tree.paddingObj), -1, + NULL, offsetof(Treeview,tree.paddingObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED }, {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", - NULL, -1, Tk_Offset(Treeview, tree.xscroll.scrollCmd), + NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.xscroll.scrollCmd), TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, {TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand", - NULL, -1, Tk_Offset(Treeview, tree.yscroll.scrollCmd), + NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.yscroll.scrollCmd), TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, WIDGET_TAKEFOCUS_TRUE, @@ -527,7 +528,7 @@ static TreeColumn *GetColumn( entryPtr = Tcl_FindHashEntry( &tv->tree.columnNames, Tcl_GetString(columnIDObj)); if (entryPtr) { - return Tcl_GetHashValue(entryPtr); + return (TreeColumn *)Tcl_GetHashValue(entryPtr); } /* Check for number: @@ -588,7 +589,7 @@ static TreeItem *FindItem( Tcl_SetErrorCode(interp, "TTK", "TREE", "ITEM", NULL); return 0; } - return Tcl_GetHashValue(entryPtr); + return (TreeItem *)Tcl_GetHashValue(entryPtr); } /* + GetItemListFromObj -- @@ -609,7 +610,7 @@ static TreeItem **GetItemListFromObj( return NULL; } - items = ckalloc((nElements + 1)*sizeof(TreeItem*)); + items = (TreeItem **)ckalloc((nElements + 1)*sizeof(TreeItem*)); for (i = 0; i < nElements; ++i) { items[i] = FindItem(interp, tv, elements[i]); if (!items[i]) { @@ -626,7 +627,7 @@ static TreeItem **GetItemListFromObj( */ static const char *ItemName(Treeview *tv, TreeItem *item) { - return Tcl_GetHashKey(&tv->tree.items, item->entryPtr); + return (const char *)Tcl_GetHashKey(&tv->tree.items, item->entryPtr); } /* + ItemID -- @@ -684,7 +685,7 @@ static int TreeviewInitColumns(Tcl_Interp *interp, Treeview *tv) * Initialize columns array and columnNames hash table: */ tv->tree.nColumns = ncols; - tv->tree.columns = ckalloc(tv->tree.nColumns * sizeof(TreeColumn)); + tv->tree.columns = (TreeColumn *)ckalloc(tv->tree.nColumns * sizeof(TreeColumn)); for (i = 0; i < ncols; ++i) { int isNew; @@ -729,12 +730,12 @@ static int TreeviewInitDisplayColumns(Tcl_Interp *interp, Treeview *tv) if (!strcmp(Tcl_GetString(tv->tree.displayColumnsObj), "#all")) { ndcols = tv->tree.nColumns; - displayColumns = ckalloc((ndcols+1) * sizeof(TreeColumn*)); + displayColumns = (TreeColumn **)ckalloc((ndcols+1) * sizeof(TreeColumn*)); for (index = 0; index < ndcols; ++index) { displayColumns[index+1] = tv->tree.columns + index; } } else { - displayColumns = ckalloc((ndcols+1) * sizeof(TreeColumn*)); + displayColumns = (TreeColumn **)ckalloc((ndcols+1) * sizeof(TreeColumn*)); for (index = 0; index < ndcols; ++index) { displayColumns[index+1] = GetColumn(interp, tv, dcolumns[index]); if (!displayColumns[index+1]) { @@ -791,9 +792,8 @@ static int PickupSlack(Treeview *tv, int extra) { int newSlack = tv->tree.slack + extra; - if ( (newSlack < 0 && 0 <= tv->tree.slack) - || (newSlack > 0 && 0 >= tv->tree.slack)) - { + if ((newSlack < 0 && 0 <= tv->tree.slack) + || (newSlack > 0 && 0 >= tv->tree.slack)) { tv->tree.slack = 0; return newSlack; } else { @@ -932,7 +932,7 @@ static const unsigned long TreeviewBindEventMask = static void TreeviewBindEventProc(void *clientData, XEvent *event) { - Treeview *tv = clientData; + Treeview *tv = (Treeview *)clientData; TreeItem *item = NULL; Ttk_TagSet tagset; @@ -984,7 +984,7 @@ static void TreeviewBindEventProc(void *clientData, XEvent *event) static void TreeviewInitialize(Tcl_Interp *interp, void *recordPtr) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; int unused; tv->tree.itemOptionTable = @@ -1051,7 +1051,7 @@ static void TreeviewInitialize(Tcl_Interp *interp, void *recordPtr) static void TreeviewCleanup(void *recordPtr) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Tk_DeleteEventHandler(tv->core.tkwin, TreeviewBindEventMask, TreeviewBindEventProc, tv); @@ -1084,7 +1084,7 @@ static void TreeviewCleanup(void *recordPtr) static int TreeviewConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; unsigned showFlags = tv->tree.showFlags; if (mask & COLUMNS_CHANGED) { @@ -1100,10 +1100,9 @@ TreeviewConfigure(Tcl_Interp *interp, void *recordPtr, int mask) TtkScrollbarUpdateRequired(tv->tree.xscrollHandle); TtkScrollbarUpdateRequired(tv->tree.yscrollHandle); } - if ( (mask & SHOW_CHANGED) - && GetEnumSetFromObj( - interp,tv->tree.showObj,showStrings,&showFlags) != TCL_OK) - { + if ((mask & SHOW_CHANGED) + && GetEnumSetFromObj( + interp,tv->tree.showObj,showStrings,&showFlags) != TCL_OK) { return TCL_ERROR; } @@ -1131,7 +1130,7 @@ static int ConfigureItem( Ttk_ImageSpec *newImageSpec = NULL; Ttk_TagSet newTagSet = NULL; - if (Tk_SetOptions(interp, (ClientData)item, tv->tree.itemOptionTable, + if (Tk_SetOptions(interp, item, tv->tree.itemOptionTable, objc, objv, tv->core.tkwin, &savedOptions, &mask) != TCL_OK) { @@ -1211,7 +1210,7 @@ static int ConfigureColumn( Tk_SavedOptions savedOptions; int mask; - if (Tk_SetOptions(interp, (ClientData)column, + if (Tk_SetOptions(interp, column, tv->tree.columnOptionTable, objc, objv, tv->core.tkwin, &savedOptions,&mask) != TCL_OK) { @@ -1257,7 +1256,7 @@ static int ConfigureHeading( Tk_SavedOptions savedOptions; int mask; - if (Tk_SetOptions(interp, (ClientData)column, + if (Tk_SetOptions(interp, column, tv->tree.headingOptionTable, objc, objv, tv->core.tkwin, &savedOptions,&mask) != TCL_OK) { @@ -1503,7 +1502,7 @@ typedef enum { REGION_CELL } TreeRegion; -static const char *regionStrings[] = { +static const char *const regionStrings[] = { "nothing", "heading", "separator", "tree", "cell", 0 }; @@ -1563,7 +1562,7 @@ static Ttk_Layout GetSublayout( static Ttk_Layout TreeviewGetLayout( Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Ttk_Layout treeLayout = TtkWidgetGetLayout(interp, themePtr, recordPtr); Tcl_Obj *objPtr; int unused; @@ -1612,7 +1611,7 @@ static Ttk_Layout TreeviewGetLayout( */ static void TreeviewDoLayout(void *clientData) { - Treeview *tv = clientData; + Treeview *tv = (Treeview *)clientData; int visibleRows; Ttk_PlaceLayout(tv->core.layout,tv->core.state,Ttk_WinBox(tv->core.tkwin)); @@ -1646,7 +1645,7 @@ static void TreeviewDoLayout(void *clientData) */ static int TreeviewSize(void *clientData, int *widthPtr, int *heightPtr) { - Treeview *tv = clientData; + Treeview *tv = (Treeview *)clientData; int nRows, padHeight, padWidth; Ttk_LayoutSize(tv->core.layout, tv->core.state, &padWidth, &padHeight); @@ -1834,7 +1833,7 @@ static int DrawForest( */ static void TreeviewDisplay(void *clientData, Drawable d) { - Treeview *tv = clientData; + Treeview *tv = (Treeview *)clientData; Ttk_DrawLayout(tv->core.layout, tv->core.state, d); if (tv->tree.showFlags & SHOW_HEADINGS) { @@ -1948,7 +1947,7 @@ static TreeItem *DeleteItems(TreeItem *item, TreeItem *delq) static int TreeviewChildrenCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item; Tcl_Obj *result; @@ -2028,7 +2027,7 @@ static int TreeviewChildrenCommand( static int TreeviewParentCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item; if (objc != 3) { @@ -2056,7 +2055,7 @@ static int TreeviewParentCommand( static int TreeviewNextCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item; if (objc != 3) { @@ -2081,7 +2080,7 @@ static int TreeviewNextCommand( static int TreeviewPrevCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item; if (objc != 3) { @@ -2106,9 +2105,9 @@ static int TreeviewPrevCommand( static int TreeviewIndexCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item; - int index = 0; + TkSizeT index = 0; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "item"); @@ -2124,7 +2123,7 @@ static int TreeviewIndexCommand( item = item->prev; } - Tcl_SetObjResult(interp, Tcl_NewIntObj(index)); + Tcl_SetObjResult(interp, TkNewIndexObj(index)); return TCL_OK; } @@ -2134,7 +2133,7 @@ static int TreeviewIndexCommand( static int TreeviewExistsCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Tcl_HashEntry *entryPtr; if (objc != 3) { @@ -2143,7 +2142,7 @@ static int TreeviewExistsCommand( } entryPtr = Tcl_FindHashEntry(&tv->tree.items, Tcl_GetString(objv[2])); - Tcl_SetObjResult(interp, Tcl_NewBooleanObj(entryPtr != 0)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(entryPtr != 0)); return TCL_OK; } @@ -2153,7 +2152,7 @@ static int TreeviewExistsCommand( static int TreeviewBBoxCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item = 0; TreeColumn *column = 0; Ttk_Box bbox; @@ -2196,12 +2195,12 @@ static int TreeviewHorribleIdentify( int dColumnNumber; char dcolbuf[16]; int x, y, x1; + (void)objc; /* ASSERT: objc == 4 */ - if ( Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK - || Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK - ) { + if (Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK + || Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK) { return TCL_ERROR; } @@ -2265,11 +2264,11 @@ done: static int TreeviewIdentifyCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - static const char *submethodStrings[] = + static const char *const submethodStrings[] = { "region", "item", "column", "row", "element", NULL }; enum { I_REGION, I_ITEM, I_COLUMN, I_ROW, I_ELEMENT }; - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; int submethod; int x, y; @@ -2371,11 +2370,11 @@ static int TreeviewIdentifyCommand( static int TreeviewItemCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item; if (objc < 3) { - Tcl_WrongNumArgs(interp, 2, objv, "item ?option ?value??..."); + Tcl_WrongNumArgs(interp, 2, objv, "item ?-option ?value??..."); return TCL_ERROR; } if (!(item = FindItem(interp, tv, objv[2]))) { @@ -2399,7 +2398,7 @@ static int TreeviewItemCommand( static int TreeviewColumnCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeColumn *column; if (objc < 3) { @@ -2427,7 +2426,7 @@ static int TreeviewColumnCommand( static int TreeviewHeadingCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Tk_OptionTable optionTable = tv->tree.headingOptionTable; Tk_Window tkwin = tv->core.tkwin; TreeColumn *column; @@ -2457,7 +2456,7 @@ static int TreeviewHeadingCommand( static int TreeviewSetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item; TreeColumn *column; int columnNumber; @@ -2551,7 +2550,7 @@ static int TreeviewSetCommand( static int TreeviewInsertCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *parent, *sibling, *newItem; Tcl_HashEntry *entryPtr; int isNew; @@ -2632,7 +2631,7 @@ static int TreeviewInsertCommand( static int TreeviewDetachCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem **items; int i; @@ -2679,7 +2678,7 @@ static int TreeviewDetachCommand( static int TreeviewDeleteCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem **items, *delq; int i, selItemDeleted = 0; @@ -2728,7 +2727,7 @@ static int TreeviewDeleteCommand( ckfree(items); if (selItemDeleted) { - TtkSendVirtualEvent(tv->core.tkwin, "TreeviewSelect"); + Tk_SendVirtualEvent(tv->core.tkwin, "TreeviewSelect", NULL); } TtkRedisplayWidget(&tv->core); return TCL_OK; @@ -2740,7 +2739,7 @@ static int TreeviewDeleteCommand( static int TreeviewMoveCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item, *parent; TreeItem *sibling; @@ -2748,9 +2747,8 @@ static int TreeviewMoveCommand( Tcl_WrongNumArgs(interp, 2, objv, "item parent index"); return TCL_ERROR; } - if ( (item = FindItem(interp, tv, objv[2])) == 0 - || (parent = FindItem(interp, tv, objv[3])) == 0) - { + if ((item = FindItem(interp, tv, objv[2])) == 0 + || (parent = FindItem(interp, tv, objv[3])) == 0) { return TCL_ERROR; } @@ -2803,14 +2801,14 @@ static int TreeviewMoveCommand( static int TreeviewXViewCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; return TtkScrollviewCommand(interp, objc, objv, tv->tree.xscrollHandle); } static int TreeviewYViewCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; return TtkScrollviewCommand(interp, objc, objv, tv->tree.yscrollHandle); } @@ -2820,7 +2818,7 @@ static int TreeviewYViewCommand( static int TreeviewSeeCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; TreeItem *item, *parent; int rowNumber; @@ -2866,7 +2864,7 @@ static int TreeviewSeeCommand( static int TreeviewDragCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; int left = tv->tree.treeArea.x - tv->tree.xscroll.first; int i = FirstColumn(tv); TreeColumn *column; @@ -2877,9 +2875,8 @@ static int TreeviewDragCommand( return TCL_ERROR; } - if ( (column = FindColumn(interp, tv, objv[2])) == 0 - || Tcl_GetIntFromObj(interp, objv[3], &newx) != TCL_OK) - { + if ((column = FindColumn(interp, tv, objv[2])) == 0 + || Tcl_GetIntFromObj(interp, objv[3], &newx) != TCL_OK) { return TCL_ERROR; } @@ -2903,7 +2900,7 @@ static int TreeviewDragCommand( static int TreeviewDropCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "drop"); @@ -2923,7 +2920,7 @@ static int TreeviewDropCommand( static int TreeviewFocusCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; if (objc == 2) { if (tv->tree.focus) { @@ -2951,17 +2948,17 @@ static int TreeviewSelectionCommand( enum { SELECTION_SET, SELECTION_ADD, SELECTION_REMOVE, SELECTION_TOGGLE }; - static const char *selopStrings[] = { + static const char *const selopStrings[] = { "set", "add", "remove", "toggle", NULL }; - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; int selop, i; TreeItem *item, **items; if (objc == 2) { Tcl_Obj *result = Tcl_NewListObj(0,0); - for (item = tv->tree.root->children; item; item=NextPreorder(item)) { + for (item = tv->tree.root->children; item; item = NextPreorder(item)) { if (item->state & TTK_STATE_SELECTED) Tcl_ListObjAppendElement(NULL, result, ItemID(tv, item)); } @@ -2987,7 +2984,7 @@ static int TreeviewSelectionCommand( switch (selop) { case SELECTION_SET: - for (item=tv->tree.root; item; item=NextPreorder(item)) { + for (item=tv->tree.root; item; item = NextPreorder(item)) { item->state &= ~TTK_STATE_SELECTED; } /*FALLTHRU*/ @@ -3009,7 +3006,7 @@ static int TreeviewSelectionCommand( } ckfree(items); - TtkSendVirtualEvent(tv->core.tkwin, "TreeviewSelect"); + Tk_SendVirtualEvent(tv->core.tkwin, "TreeviewSelect", NULL); TtkRedisplayWidget(&tv->core); return TCL_OK; @@ -3024,7 +3021,7 @@ static int TreeviewSelectionCommand( static int TreeviewTagBindCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Ttk_TagTable tagTable = tv->tree.tagTable; Tk_BindingTable bindingTable = tv->tree.bindingTable; Ttk_Tag tag; @@ -3077,7 +3074,7 @@ static int TreeviewTagBindCommand( static int TreeviewTagConfigureCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Ttk_TagTable tagTable = tv->tree.tagTable; Ttk_Tag tag; @@ -3103,12 +3100,40 @@ static int TreeviewTagConfigureCommand( return Ttk_ConfigureTag(interp, tagTable, tag, objc - 4, objv + 4); } +/* + $tv tag delete $tag + */ +static int TreeviewTagDeleteCommand( + void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) +{ + Treeview *tv = (Treeview *)recordPtr; + Ttk_TagTable tagTable = tv->tree.tagTable; + TreeItem *item = tv->tree.root; + Ttk_Tag tag; + + if (objc != 4) { + Tcl_WrongNumArgs(interp, 3, objv, "tagName"); + return TCL_ERROR; + } + + tag = Ttk_GetTagFromObj(tagTable, objv[3]); + /* remove the tag from all items */ + while (item) { + RemoveTag(item, tag); + item = NextPreorder(item); + } + /* then remove the tag from the tag table */ + Ttk_DeleteTagFromTable(tagTable, tag); + TtkRedisplayWidget(&tv->core); + + return TCL_OK; +} + /* + $tv tag has $tag ?$item? */ static int TreeviewTagHasCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; if (objc == 4) { /* Return list of all items with tag */ Ttk_Tag tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[3]); @@ -3131,7 +3156,7 @@ static int TreeviewTagHasCommand( return TCL_ERROR; } Tcl_SetObjResult(interp, - Tcl_NewBooleanObj(Ttk_TagSetContains(item->tagset, tag))); + Tcl_NewWideIntObj(Ttk_TagSetContains(item->tagset, tag))); return TCL_OK; } else { Tcl_WrongNumArgs(interp, 3, objv, "tagName ?item?"); @@ -3144,7 +3169,7 @@ static int TreeviewTagHasCommand( static int TreeviewTagNamesCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, ""); @@ -3168,7 +3193,7 @@ static void AddTag(TreeItem *item, Ttk_Tag tag) static int TreeviewTagAddCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Ttk_Tag tag; TreeItem **items; int i; @@ -3208,7 +3233,7 @@ static void RemoveTag(TreeItem *item, Ttk_Tag tag) static int TreeviewTagRemoveCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Treeview *tv = recordPtr; + Treeview *tv = (Treeview *)recordPtr; Ttk_Tag tag; if (objc < 4) { @@ -3232,7 +3257,7 @@ static int TreeviewTagRemoveCommand( TreeItem *item = tv->tree.root; while (item) { RemoveTag(item, tag); - item=NextPreorder(item); + item = NextPreorder(item); } } @@ -3245,6 +3270,7 @@ static const Ttk_Ensemble TreeviewTagCommands[] = { { "add", TreeviewTagAddCommand,0 }, { "bind", TreeviewTagBindCommand,0 }, { "configure", TreeviewTagConfigureCommand,0 }, + { "delete", TreeviewTagDeleteCommand,0 }, { "has", TreeviewTagHasCommand,0 }, { "names", TreeviewTagNamesCommand,0 }, { "remove", TreeviewTagRemoveCommand,0 }, @@ -3290,7 +3316,7 @@ static const Ttk_Ensemble TreeviewCommands[] = { * +++ Widget definition. */ -static WidgetSpec TreeviewWidgetSpec = { +static const WidgetSpec TreeviewWidgetSpec = { "Treeview", /* className */ sizeof(Treeview), /* recordSize */ TreeviewOptionSpecs, /* optionSpecs */ @@ -3348,23 +3374,25 @@ typedef struct { Tcl_Obj *marginsObj; } TreeitemIndicator; -static Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = { +static const Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = { { "-foreground", TK_OPTION_COLOR, - Tk_Offset(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND }, + offsetof(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND }, { "-indicatorsize", TK_OPTION_PIXELS, - Tk_Offset(TreeitemIndicator,sizeObj), "12" }, + offsetof(TreeitemIndicator,sizeObj), "12" }, { "-indicatormargins", TK_OPTION_STRING, - Tk_Offset(TreeitemIndicator,marginsObj), "2 2 4 2" }, - { NULL, 0, 0, NULL } + offsetof(TreeitemIndicator,marginsObj), "2 2 4 2" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void TreeitemIndicatorSize( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - TreeitemIndicator *indicator = elementRecord; + TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord; Ttk_Padding margins; int size = 0; + (void)dummy; + (void)paddingPtr; Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginsObj, &margins); Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size); @@ -3374,15 +3402,16 @@ static void TreeitemIndicatorSize( } static void TreeitemIndicatorDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - TreeitemIndicator *indicator = elementRecord; + TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord; ArrowDirection direction = (state & TTK_STATE_OPEN) ? ARROW_DOWN : ARROW_RIGHT; Ttk_Padding margins; XColor *borderColor = Tk_GetColorFromObj(tkwin, indicator->colorObj); XGCValues gcvalues; GC gc; unsigned mask; + (void)dummy; if (state & TTK_STATE_LEAF) /* don't draw anything */ return; @@ -3400,7 +3429,7 @@ static void TreeitemIndicatorDraw( Tk_FreeGC(Tk_Display(tkwin), gc); } -static Ttk_ElementSpec TreeitemIndicatorElementSpec = { +static const Ttk_ElementSpec TreeitemIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(TreeitemIndicator), TreeitemIndicatorOptions, @@ -3417,26 +3446,29 @@ typedef struct { Tcl_Obj *rowNumberObj; } RowElement; -static Ttk_ElementOptionSpec RowElementOptions[] = { +static const Ttk_ElementOptionSpec RowElementOptions[] = { { "-background", TK_OPTION_COLOR, - Tk_Offset(RowElement,backgroundObj), DEFAULT_BACKGROUND }, + offsetof(RowElement,backgroundObj), DEFAULT_BACKGROUND }, { "-rownumber", TK_OPTION_INT, - Tk_Offset(RowElement,rowNumberObj), "0" }, - { NULL, 0, 0, NULL } + offsetof(RowElement,rowNumberObj), "0" }, + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void RowElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, + void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - RowElement *row = elementRecord; + RowElement *row = (RowElement *)elementRecord; XColor *color = Tk_GetColorFromObj(tkwin, row->backgroundObj); GC gc = Tk_GCForColor(color, d); + (void)dummy; + (void)state; + XFillRectangle(Tk_Display(tkwin), d, gc, b.x, b.y, b.width, b.height); } -static Ttk_ElementSpec RowElementSpec = { +static const Ttk_ElementSpec RowElementSpec = { TK_STYLE_VERSION_2, sizeof(RowElement), RowElementOptions, diff --git a/generic/ttk/ttkWidget.c b/generic/ttk/ttkWidget.c index 9992d27..6726e17 100644 --- a/generic/ttk/ttkWidget.c +++ b/generic/ttk/ttkWidget.c @@ -4,7 +4,6 @@ * Core widget utilities. */ -#include <string.h> #include "tkInt.h" #include "ttkTheme.h" #include "ttkWidget.h" @@ -86,7 +85,7 @@ static void EndDrawing(Tk_Window tkwin, Drawable d) #else /* No double-buffering: draw directly into the window. */ static Drawable BeginDrawing(Tk_Window tkwin) { return Tk_WindowId(tkwin); } -static void EndDrawing(Tk_Window tkwin, Drawable d) { } +static void EndDrawing(Tk_Window tkwin, Drawable d) { (void)tkwin; (void)d;} #endif /* DrawWidget -- @@ -94,7 +93,7 @@ static void EndDrawing(Tk_Window tkwin, Drawable d) { } */ static void DrawWidget(ClientData recordPtr) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; corePtr->flags &= ~REDISPLAY_PENDING; if (Tk_IsMapped(corePtr->tkwin)) { @@ -153,7 +152,7 @@ static int WidgetInstanceObjCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - WidgetCore *corePtr = clientData; + WidgetCore *corePtr = (WidgetCore *)clientData; const Ttk_Ensemble *commands = corePtr->widgetSpec->commands; int status; @@ -188,7 +187,7 @@ WidgetInstanceObjCmd( static void WidgetInstanceObjCmdDeleted(ClientData clientData) { - WidgetCore *corePtr = clientData; + WidgetCore *corePtr = (WidgetCore *)clientData; corePtr->widgetCmd = NULL; if (corePtr->tkwin != NULL) Tk_DestroyWindow(corePtr->tkwin); @@ -214,7 +213,7 @@ DestroyWidget(WidgetCore *corePtr) corePtr->widgetSpec->cleanupProc(corePtr); Tk_FreeConfigOptions( - (ClientData)corePtr, corePtr->optionTable, corePtr->tkwin); + corePtr, corePtr->optionTable, corePtr->tkwin); if (corePtr->layout) { Ttk_FreeLayout(corePtr->layout); @@ -333,12 +332,12 @@ static void CoreEventProc(ClientData clientData, XEvent *eventPtr) */ static void WidgetWorldChanged(ClientData clientData) { - WidgetCore *corePtr = clientData; + WidgetCore *corePtr = (WidgetCore *)clientData; SizeChanged(corePtr); TtkRedisplayWidget(corePtr); } -static Tk_ClassProcs widgetClassProcs = { +static const Tk_ClassProcs widgetClassProcs = { sizeof(Tk_ClassProcs), /* size */ WidgetWorldChanged, /* worldChangedProc */ NULL, /* createProc */ @@ -353,7 +352,7 @@ static Tk_ClassProcs widgetClassProcs = { int TtkWidgetConstructorObjCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - WidgetSpec *widgetSpec = clientData; + WidgetSpec *widgetSpec = (WidgetSpec *)clientData; const char *className = widgetSpec->className; Tk_OptionTable optionTable = Tk_CreateOptionTable(interp, widgetSpec->optionSpecs); @@ -389,7 +388,7 @@ int TtkWidgetConstructorObjCmd( */ recordPtr = ckalloc(widgetSpec->recordSize); memset(recordPtr, 0, widgetSpec->recordSize); - corePtr = recordPtr; + corePtr = (WidgetCore *)recordPtr; corePtr->tkwin = tkwin; corePtr->interp = interp; @@ -464,7 +463,7 @@ error: Ttk_Layout TtkWidgetGetLayout( Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; const char *styleName = 0; if (corePtr->styleObj) @@ -486,17 +485,17 @@ Ttk_Layout TtkWidgetGetLayout( Ttk_Layout TtkWidgetGetOrientedLayout( Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr, Tcl_Obj *orientObj) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; const char *baseStyleName = 0; Tcl_DString styleName; - int orient = TTK_ORIENT_HORIZONTAL; + Ttk_Orient orient = TTK_ORIENT_HORIZONTAL; Ttk_Layout layout; Tcl_DStringInit(&styleName); /* Prefix: */ - Ttk_GetOrientFromObj(NULL, orientObj, &orient); + TtkGetOrientFromObj(NULL, orientObj, &orient); if (orient == TTK_ORIENT_HORIZONTAL) Tcl_DStringAppend(&styleName, "Horizontal.", -1); else @@ -526,6 +525,8 @@ Ttk_Layout TtkWidgetGetOrientedLayout( */ void TtkNullInitialize(Tcl_Interp *interp, void *recordPtr) { + (void)interp; + (void)recordPtr; } /* TtkNullPostConfigure -- @@ -533,6 +534,10 @@ void TtkNullInitialize(Tcl_Interp *interp, void *recordPtr) */ int TtkNullPostConfigure(Tcl_Interp *interp, void *clientData, int mask) { + (void)interp; + (void)clientData; + (void)mask; + return TCL_OK; } @@ -542,7 +547,7 @@ int TtkNullPostConfigure(Tcl_Interp *interp, void *clientData, int mask) */ int TtkCoreConfigure(Tcl_Interp *interp, void *clientData, int mask) { - WidgetCore *corePtr = clientData; + WidgetCore *corePtr = (WidgetCore *)clientData; int status = TCL_OK; if (mask & STYLE_CHANGED) { @@ -557,6 +562,7 @@ int TtkCoreConfigure(Tcl_Interp *interp, void *clientData, int mask) */ void TtkNullCleanup(void *recordPtr) { + (void)recordPtr; return; } @@ -565,7 +571,7 @@ void TtkNullCleanup(void *recordPtr) */ void TtkWidgetDoLayout(void *clientData) { - WidgetCore *corePtr = clientData; + WidgetCore *corePtr = (WidgetCore *)clientData; Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin)); } @@ -574,7 +580,7 @@ void TtkWidgetDoLayout(void *clientData) */ void TtkWidgetDisplay(void *recordPtr, Drawable d) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; Ttk_DrawLayout(corePtr->layout, corePtr->state, d); } @@ -583,7 +589,7 @@ void TtkWidgetDisplay(void *recordPtr, Drawable d) */ int TtkWidgetSize(void *recordPtr, int *widthPtr, int *heightPtr) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; Ttk_LayoutSize(corePtr->layout, corePtr->state, widthPtr, heightPtr); return 1; } @@ -597,7 +603,7 @@ int TtkWidgetSize(void *recordPtr, int *widthPtr, int *heightPtr) int TtkWidgetCgetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; Tcl_Obj *result; if (objc != 3) { @@ -617,7 +623,7 @@ int TtkWidgetCgetCommand( int TtkWidgetConfigureCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; Tcl_Obj *result; if (objc == 2) { @@ -687,7 +693,7 @@ int TtkWidgetConfigureCommand( int TtkWidgetStateCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; Ttk_StateSpec spec; int status; Ttk_State oldState, changed; @@ -727,7 +733,7 @@ int TtkWidgetStateCommand( int TtkWidgetInstateCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; Ttk_State state = corePtr->state; Ttk_StateSpec spec; int status = TCL_OK; @@ -742,7 +748,7 @@ int TtkWidgetInstateCommand( if (objc == 3) { Tcl_SetObjResult(interp, - Tcl_NewBooleanObj(Ttk_StateMatches(state,&spec))); + Tcl_NewWideIntObj(Ttk_StateMatches(state,&spec))); } else if (objc == 4) { if (Ttk_StateMatches(state,&spec)) { status = Tcl_EvalObjEx(interp, objv[3], 0); @@ -758,9 +764,9 @@ int TtkWidgetInstateCommand( int TtkWidgetIdentifyCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - WidgetCore *corePtr = recordPtr; + WidgetCore *corePtr = (WidgetCore *)recordPtr; Ttk_Element element; - static const char *whatTable[] = { "element", NULL }; + static const char *const whatTable[] = { "element", NULL }; int x, y, what; if (objc < 4 || objc > 5) { diff --git a/generic/ttk/ttkWidget.h b/generic/ttk/ttkWidget.h index 6cd691b..2eeab4e 100644 --- a/generic/ttk/ttkWidget.h +++ b/generic/ttk/ttkWidget.h @@ -117,21 +117,21 @@ MODULE_SCOPE int TtkWidgetConstructorObjCmd( */ #define WIDGET_TAKEFOCUS_TRUE \ {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", \ - "ttk::takefocus", Tk_Offset(WidgetCore, takeFocusPtr), -1, 0,0,0 } + "ttk::takefocus", offsetof(WidgetCore, takeFocusPtr), TCL_INDEX_NONE, 0,0,0 } #define WIDGET_TAKEFOCUS_FALSE \ {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", \ - "", Tk_Offset(WidgetCore, takeFocusPtr), -1, 0,0,0 } + "", offsetof(WidgetCore, takeFocusPtr), TCL_INDEX_NONE, 0,0,0 } /* WIDGET_INHERIT_OPTIONS(baseOptionSpecs) -- * Add this at the end of an OptionSpecs table to inherit * the options from 'baseOptionSpecs'. */ #define WIDGET_INHERIT_OPTIONS(baseOptionSpecs) \ - {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0, (ClientData)baseOptionSpecs, 0} + {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0, baseOptionSpecs, 0} /* All widgets should inherit from ttkCoreOptionSpecs[]. */ -MODULE_SCOPE Tk_OptionSpec ttkCoreOptionSpecs[]; +MODULE_SCOPE const Tk_OptionSpec ttkCoreOptionSpecs[]; /* * Useful routines for use inside widget implementations: @@ -165,11 +165,6 @@ MODULE_SCOPE void Ttk_UntraceVariable(Ttk_TraceHandle *); MODULE_SCOPE int Ttk_FireTrace(Ttk_TraceHandle *); /* - * Virtual events: - */ -MODULE_SCOPE void TtkSendVirtualEvent(Tk_Window tgtWin, const char *eventName); - -/* * Helper routines for data accessor commands: */ MODULE_SCOPE int TtkEnumerateOptions( @@ -212,7 +207,7 @@ typedef struct TtkTagSet { /* TODO: make opaque */ } *Ttk_TagSet; MODULE_SCOPE Ttk_TagTable Ttk_CreateTagTable( - Tcl_Interp *, Tk_Window tkwin, Tk_OptionSpec[], int recordSize); + Tcl_Interp *, Tk_Window tkwin, const Tk_OptionSpec *, int recordSize); MODULE_SCOPE void Ttk_DeleteTagTable(Ttk_TagTable); MODULE_SCOPE Ttk_Tag Ttk_GetTag(Ttk_TagTable, const char *tagName); @@ -226,6 +221,8 @@ MODULE_SCOPE int Ttk_EnumerateTagOptions( MODULE_SCOPE int Ttk_EnumerateTags(Tcl_Interp *, Ttk_TagTable); +MODULE_SCOPE void Ttk_DeleteTagFromTable(Ttk_TagTable, Ttk_Tag); + MODULE_SCOPE int Ttk_ConfigureTag( Tcl_Interp *interp, Ttk_TagTable tagTable, Ttk_Tag tag, int objc, Tcl_Obj *const objv[]); @@ -247,9 +244,9 @@ MODULE_SCOPE void Ttk_TagSetApplyStyle(Ttk_TagTable,Ttk_Style,Ttk_State,void*); * String tables for widget resource specifications: */ -MODULE_SCOPE const char *ttkOrientStrings[]; -MODULE_SCOPE const char *ttkCompoundStrings[]; -MODULE_SCOPE const char *ttkDefaultStrings[]; +MODULE_SCOPE const char *const ttkOrientStrings[]; +MODULE_SCOPE const char *const ttkCompoundStrings[]; +MODULE_SCOPE const char *const ttkDefaultStrings[]; /* * ... other option types... |