diff --git a/generic/tkEntry.c b/generic/tkEntry.c index b0d769465..8a88e3274 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -139,8 +139,7 @@ static const Tk_OptionSpec entryOptSpec[] = { 0, DEF_ENTRY_SELECT_MONO, 0}, {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth", "BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, TCL_INDEX_NONE, - offsetof(Entry, selBorderWidth), - 0, DEF_ENTRY_SELECT_BD_MONO, 0}, + offsetof(Entry, selBorderWidth), 0, DEF_ENTRY_SELECT_BD_MONO, 0}, {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background", DEF_ENTRY_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(Entry, selFgColorPtr), TK_OPTION_NULL_OK, DEF_ENTRY_SELECT_FG_MONO, 0}, @@ -252,8 +251,7 @@ static const Tk_OptionSpec sbOptSpec[] = { DEF_ENTRY_INSERT_BG, TCL_INDEX_NONE, offsetof(Entry, insertBorder), 0, 0, 0}, {TK_OPTION_PIXELS, "-insertborderwidth", "insertBorderWidth", "BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, TCL_INDEX_NONE, - offsetof(Entry, insertBorderWidth), 0, - DEF_ENTRY_INSERT_BD_MONO, 0}, + offsetof(Entry, insertBorderWidth), 0, DEF_ENTRY_INSERT_BD_MONO, 0}, {TK_OPTION_INT, "-insertofftime", "insertOffTime", "OffTime", DEF_ENTRY_INSERT_OFF_TIME, TCL_INDEX_NONE, offsetof(Entry, insertOffTime), 0, 0, 0}, @@ -291,8 +289,7 @@ static const Tk_OptionSpec sbOptSpec[] = { 0, DEF_ENTRY_SELECT_MONO, 0}, {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth", "BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, TCL_INDEX_NONE, - offsetof(Entry, selBorderWidth), - 0, DEF_ENTRY_SELECT_BD_MONO, 0}, + offsetof(Entry, selBorderWidth), 0, DEF_ENTRY_SELECT_BD_MONO, 0}, {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background", DEF_ENTRY_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(Entry, selFgColorPtr), TK_OPTION_NULL_OK, DEF_ENTRY_SELECT_FG_MONO, 0}, @@ -313,7 +310,7 @@ static const Tk_OptionSpec sbOptSpec[] = { {TK_OPTION_STRING, "-validatecommand", "validateCommand","ValidateCommand", NULL, offsetof(Entry, validateCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-values", "values", "Values", - DEF_SPINBOX_VALUES, TCL_INDEX_NONE, offsetof(Spinbox, valueStr), + DEF_SPINBOX_VALUES, offsetof(Spinbox, valueObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_SYNONYM, "-vcmd", NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, "-validatecommand", 0}, @@ -1118,7 +1115,7 @@ ConfigureEntry( Spinbox *sbPtr = (Spinbox *) entryPtr; /* Only used when this widget is of type * TK_SPINBOX */ - char *oldValues = NULL; + Tcl_Obj *oldValues = NULL; Tcl_Obj *oldFormat = NULL; int error; int oldExport = 0; @@ -1147,7 +1144,7 @@ ConfigureEntry( oldExport = (entryPtr->exportSelection) && (!Tcl_IsSafe(entryPtr->interp)); if (entryPtr->type == TK_SPINBOX) { - oldValues = sbPtr->valueStr; + oldValues = sbPtr->valueObj; oldFormat = sbPtr->reqFormatObj; oldFrom = sbPtr->fromValue; oldTo = sbPtr->toValue; @@ -1267,16 +1264,16 @@ ConfigureEntry( * See if we have to rearrange our listObj data. */ - if (oldValues != sbPtr->valueStr) { + if (oldValues != sbPtr->valueObj) { if (sbPtr->listObj != NULL) { Tcl_DecrRefCount(sbPtr->listObj); } sbPtr->listObj = NULL; - if (sbPtr->valueStr != NULL) { + if (sbPtr->valueObj != NULL) { Tcl_Obj *newObjPtr; Tcl_Size nelems; - newObjPtr = Tcl_NewStringObj(sbPtr->valueStr, TCL_INDEX_NONE); + newObjPtr = sbPtr->valueObj; if (Tcl_ListObjLength(interp, newObjPtr, &nelems) != TCL_OK) { valuesChanged = -1; @@ -1379,7 +1376,7 @@ ConfigureEntry( */ EntryValueChanged(entryPtr, Tcl_GetString(objPtr)); - } else if ((sbPtr->valueStr == NULL) + } else if ((sbPtr->valueObj == NULL) && !DOUBLES_EQ(sbPtr->fromValue, sbPtr->toValue) && (!DOUBLES_EQ(sbPtr->fromValue, oldFrom) || !DOUBLES_EQ(sbPtr->toValue, oldTo))) { @@ -1727,8 +1724,8 @@ DisplayEntry( Tk_Fill3DRectangle(tkwin, pixmap, entryPtr->selBorder, selStartX - entryPtr->selBorderWidth, baseY - fm.ascent - entryPtr->selBorderWidth, - (selEndX - selStartX) + 2*entryPtr->selBorderWidth, - (fm.ascent + fm.descent) + 2*entryPtr->selBorderWidth, + (selEndX - selStartX) + 2 * entryPtr->selBorderWidth, + (fm.ascent + fm.descent) + 2 * entryPtr->selBorderWidth, entryPtr->selBorderWidth, #ifndef MAC_OSX_TK TK_RELIEF_RAISED diff --git a/generic/tkEntry.h b/generic/tkEntry.h index 32b09167e..5d08e3fc7 100644 --- a/generic/tkEntry.h +++ b/generic/tkEntry.h @@ -235,7 +235,7 @@ typedef struct { * digits and other information; used for the * value. */ - char *valueStr; /* Values List. Malloc'ed. */ + Tcl_Obj *valueObj; /* Values List. */ Tcl_Obj *listObj; /* Pointer to the list object being used */ int eIndex; /* Holds the current index into elements */ int nElements; /* Holds the current count of elements */ diff --git a/generic/tkScale.c b/generic/tkScale.c index 80b08cbee..8f118c12e 100644 --- a/generic/tkScale.c +++ b/generic/tkScale.c @@ -52,7 +52,7 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_SCALE_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(TkScale, borderWidth), 0, 0, 0}, {TK_OPTION_STRING, "-command", "command", "Command", - DEF_SCALE_COMMAND, TCL_INDEX_NONE, offsetof(TkScale, command), + DEF_SCALE_COMMAND, offsetof(TkScale, commandObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", DEF_SCALE_CURSOR, TCL_INDEX_NONE, offsetof(TkScale, cursor), @@ -80,7 +80,7 @@ static const Tk_OptionSpec optionSpecs[] = { "HighlightThickness", DEF_SCALE_HIGHLIGHT_WIDTH, TCL_INDEX_NONE, offsetof(TkScale, highlightWidth), 0, 0, 0}, {TK_OPTION_STRING, "-label", "label", "Label", - DEF_SCALE_LABEL, TCL_INDEX_NONE, offsetof(TkScale, label), + DEF_SCALE_LABEL, offsetof(TkScale, labelObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-length", "length", "Length", DEF_SCALE_LENGTH, TCL_INDEX_NONE, offsetof(TkScale, length), 0, 0, 0}, @@ -291,10 +291,10 @@ Tk_ScaleObjCmd( scalePtr->resolution = 1.0; scalePtr->digits = 0; scalePtr->bigIncrement = 0.0; - scalePtr->command = NULL; + scalePtr->commandObj = NULL; scalePtr->repeatDelay = 0; scalePtr->repeatInterval = 0; - scalePtr->label = NULL; + scalePtr->labelObj = NULL; scalePtr->labelLength = 0; scalePtr->state = STATE_NORMAL; scalePtr->borderWidth = 0; @@ -669,8 +669,6 @@ ConfigureScale( ComputeFormat(scalePtr, 0); ComputeFormat(scalePtr, 1); - scalePtr->labelLength = scalePtr->label ? strlen(scalePtr->label) : 0; - Tk_SetBackgroundFromBorder(scalePtr->tkwin, scalePtr->bgBorder); if (scalePtr->highlightWidth < 0) { @@ -1024,7 +1022,7 @@ ComputeScaleGeometry( if (scalePtr->orient == ORIENT_HORIZONTAL) { y = scalePtr->inset; extraSpace = 0; - if (scalePtr->labelLength != 0) { + if (scalePtr->labelObj != NULL) { scalePtr->horizLabelY = y + SPACING; y += scalePtr->fontHeight; extraSpace = SPACING; @@ -1114,13 +1112,14 @@ ComputeScaleGeometry( } scalePtr->vertTroughX = x; x += 2*scalePtr->borderWidth + scalePtr->width; - if (scalePtr->labelLength == 0) { + if (scalePtr->labelObj == NULL) { scalePtr->vertLabelX = 0; } else { + Tcl_Size labelLength; + const char *label= Tcl_GetStringFromObj(scalePtr->labelObj, &labelLength); scalePtr->vertLabelX = x + fm.ascent/2; x = scalePtr->vertLabelX + fm.ascent/2 - + Tk_TextWidth(scalePtr->tkfont, scalePtr->label, - scalePtr->labelLength); + + Tk_TextWidth(scalePtr->tkfont, label, labelLength); } Tk_GeometryRequest(scalePtr->tkwin, x + scalePtr->inset, scalePtr->length + 2*scalePtr->inset); @@ -1457,7 +1456,7 @@ TkScaleSetValue( * configuring the widget -command option even if the value did not change. */ - if ((invokeCommand) && (scalePtr->command != NULL)) { + if ((invokeCommand) && (scalePtr->commandObj != NULL)) { scalePtr->flags |= INVOKE_COMMAND; } TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER); diff --git a/generic/tkScale.h b/generic/tkScale.h index 7ecf1a1de..3f4550d15 100644 --- a/generic/tkScale.h +++ b/generic/tkScale.h @@ -79,15 +79,15 @@ typedef struct TkScale { * tick interval. */ double bigIncrement; /* Amount to use for large increments to scale * value. (0 means we pick a value). */ - char *command; /* Command prefix to use when invoking Tcl + Tcl_Obj *commandObj; /* Command prefix to use when invoking Tcl * commands because the scale value changed. * NULL means don't invoke commands. */ int repeatDelay; /* How long to wait before auto-repeating on * scrolling actions (in ms). */ int repeatInterval; /* Interval between autorepeats (in ms). */ - char *label; /* Label to display above or to right of + Tcl_Obj *labelObj; /* Label to display above or to right of * scale; NULL means don't display a label. */ - Tcl_Size labelLength; /* Number of non-NULL chars. in label. */ + Tcl_Size labelLength; /* Not used any more. */ enum state state; /* Values are active, normal, or disabled. * Value of scale cannot be changed when * disabled. */ diff --git a/generic/tkTest.c b/generic/tkTest.c index f0ee30fbd..20434a343 100644 --- a/generic/tkTest.c +++ b/generic/tkTest.c @@ -824,7 +824,7 @@ TestobjconfigObjCmd( int boolValue; int integer; double doubleValue; - char *string; + Tcl_Obj *stringObj; int index; XColor *colorPtr; Tk_Font tkfont; @@ -851,7 +851,7 @@ TestobjconfigObjCmd( {TK_OPTION_DOUBLE, "-double", "double", "Double", "3.14159", TCL_INDEX_NONE, offsetof(InternalRecord, doubleValue), 0, 0, 0x4}, {TK_OPTION_STRING, "-string", "string", "String", "foo", - TCL_INDEX_NONE, offsetof(InternalRecord, string), + offsetof(InternalRecord, stringObj), TCL_INDEX_NONE, TK_CONFIG_NULL_OK, 0, 0x8}, {TK_OPTION_STRING_TABLE, "-stringtable", "StringTable", "stringTable", "one", @@ -912,7 +912,7 @@ TestobjconfigObjCmd( recordPtr->boolValue = 0; recordPtr->integer = 0; recordPtr->doubleValue = 0.0; - recordPtr->string = NULL; + recordPtr->stringObj = NULL; recordPtr->index = 0; recordPtr->colorPtr = NULL; recordPtr->tkfont = NULL; diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index a43e3f045..65e1d10b1 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -105,10 +105,10 @@ typedef struct { int exportSelection; /* Tie internal selection to X selection? */ VMODE validate; /* Validation mode */ - char *validateCmd; /* Validation script template */ - char *invalidCmd; /* Invalid callback script template */ + Tcl_Obj *validateCmdObj; /* Validation script template */ + Tcl_Obj *invalidCmdObj; /* Invalid callback script template */ - char *showChar; /* Used to derive displayString */ + Tcl_Obj *showCharObj; /* Used to derive displayString */ Tcl_Obj *fontObj; /* Text font to use */ Tcl_Obj *widthObj; /* Desired width of window (in avgchars) */ @@ -166,7 +166,7 @@ static const Tk_OptionSpec EntryOptionSpecs[] = { DEF_ENTRY_FONT, offsetof(Entry, entry.fontObj),TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.invalidCmd), + NULL, offsetof(Entry, entry.invalidCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", "left", TCL_INDEX_NONE, offsetof(Entry, entry.justify), @@ -175,7 +175,7 @@ static const Tk_OptionSpec EntryOptionSpecs[] = { NULL, offsetof(Entry, entry.placeholderObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-show", "show", "Show", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.showChar), + NULL, offsetof(Entry, entry.showCharObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-state", "state", "State", "normal", offsetof(Entry, entry.stateObj), TCL_INDEX_NONE, @@ -187,13 +187,13 @@ static const Tk_OptionSpec EntryOptionSpecs[] = { "none", TCL_INDEX_NONE, offsetof(Entry, entry.validate), TK_OPTION_ENUM_VAR, validateStrings, 0}, {TK_OPTION_STRING, "-validatecommand", "validateCommand", "ValidateCommand", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.validateCmd), + NULL, offsetof(Entry, entry.validateCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_INT, "-width", "width", "Width", DEF_ENTRY_WIDTH, offsetof(Entry, entry.widthObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.xscroll.scrollCmd), + NULL, offsetof(Entry, entry.xscroll.scrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, /* EntryStyleData options: @@ -604,7 +604,7 @@ EntryValidateChange( VMODE vmode = entryPtr->entry.validate; int code, change_ok; - if ((entryPtr->entry.validateCmd == NULL) + if ((entryPtr->entry.validateCmdObj == NULL) || (entryPtr->core.flags & VALIDATING) || !EntryNeedsValidation(vmode, reason)) { @@ -616,7 +616,7 @@ EntryValidateChange( /* Run -validatecommand and check return value: */ code = RunValidationScript(interp, entryPtr, - entryPtr->entry.validateCmd, "-validatecommand", + Tcl_GetString(entryPtr->entry.validateCmdObj), "-validatecommand", newValue, index, count, reason); if (code != TCL_OK) { goto done; @@ -632,9 +632,9 @@ EntryValidateChange( /* Run the -invalidcommand if validation failed: */ - if (!change_ok && entryPtr->entry.invalidCmd != NULL) { + if (!change_ok && entryPtr->entry.invalidCmdObj != NULL) { code = RunValidationScript(interp, entryPtr, - entryPtr->entry.invalidCmd, "-invalidcommand", + Tcl_GetString(entryPtr->entry.invalidCmdObj), "-invalidcommand", newValue, index, count, reason); if (code != TCL_OK) { goto done; @@ -764,8 +764,8 @@ EntryStoreValue(Entry *entryPtr, const char *value) entryPtr->entry.numChars = numChars; entryPtr->entry.displayString - = entryPtr->entry.showChar - ? EntryDisplayString(entryPtr->entry.showChar, numChars) + = entryPtr->entry.showCharObj + ? EntryDisplayString(Tcl_GetString(entryPtr->entry.showCharObj), numChars) : entryPtr->entry.string ; @@ -1059,8 +1059,8 @@ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask) ckfree(entryPtr->entry.displayString); entryPtr->entry.displayString - = entryPtr->entry.showChar - ? EntryDisplayString(entryPtr->entry.showChar, entryPtr->entry.numChars) + = entryPtr->entry.showCharObj + ? EntryDisplayString(Tcl_GetString(entryPtr->entry.showCharObj), entryPtr->entry.numChars) : entryPtr->entry.string ; diff --git a/generic/ttk/ttkScroll.c b/generic/ttk/ttkScroll.c index b14a0b2a0..1bbd7138c 100644 --- a/generic/ttk/ttkScroll.c +++ b/generic/ttk/ttkScroll.c @@ -82,7 +82,7 @@ static int UpdateScrollbar(Tcl_Interp *interp, ScrollHandle h) h->flags &= ~SCROLL_UPDATE_REQUIRED; - if (s->scrollCmd == NULL) { + if (s->scrollCmdObj == NULL) { return TCL_OK; } @@ -90,7 +90,7 @@ static int UpdateScrollbar(Tcl_Interp *interp, ScrollHandle h) Tcl_PrintDouble(interp, (double)s->first / s->total, arg1+1); Tcl_PrintDouble(interp, (double)s->last / s->total, arg2+1); Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, s->scrollCmd, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(s->scrollCmdObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, arg1, TCL_INDEX_NONE); Tcl_DStringAppend(&buf, arg2, TCL_INDEX_NONE); diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index d54f8b8ef..f925cad2b 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -550,10 +550,10 @@ static const Tk_OptionSpec TreeviewOptionSpecs[] = { 0, 0, GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", - NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.xscroll.scrollCmd), + NULL, offsetof(Treeview, tree.xscroll.scrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, {TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand", - NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.yscroll.scrollCmd), + NULL, offsetof(Treeview, tree.yscroll.scrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, WIDGET_TAKEFOCUS_TRUE, diff --git a/generic/ttk/ttkWidget.h b/generic/ttk/ttkWidget.h index 453b78822..62a628d86 100644 --- a/generic/ttk/ttkWidget.h +++ b/generic/ttk/ttkWidget.h @@ -186,7 +186,7 @@ typedef struct { int first; /* First visible item */ int last; /* Last visible item */ int total; /* Total #items */ - char *scrollCmd; /* Widget option */ + Tcl_Obj *scrollCmdObj; /* Widget option */ } Scrollable; typedef struct ScrollHandleRec *ScrollHandle; diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 30cfc602a..11421ccc2 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -524,9 +524,8 @@ TkMacOSXPutImage( bounds = CGRectMake(0, 0, image->width, image->height); srcRect = CGRectMake(src_x, src_y, width, height); dstRect = CGRectMake(dest_x, dest_y, width, height); - TkMacOSXDrawCGImage(drawable, gc, dc.context, - img, gc->foreground, gc->background, - bounds, srcRect, dstRect); + TkMacOSXDrawCGImage(drawable, gc, dc.context, img, + gc->foreground, gc->background, bounds, srcRect, dstRect); CFRelease(img); } else { TkMacOSXDbgMsg("Invalid source drawable"); @@ -648,7 +647,7 @@ CreateCGImageFromDrawableRect( } NSSize size = view.frame.size; NSUInteger view_width = size.width, view_height = size.height; - NSUInteger bytesPerPixel = 4, + NSUInteger bytesPerPixel = 4, bytesPerRow = bytesPerPixel * view_width, bitsPerComponent = 8; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); @@ -844,6 +843,7 @@ XGetImage( } } } + imagePtr = XCreateImage(display, NULL, depth, format, offset, (char*) bitmap, width, height, bitmap_pad, bytes_per_row); @@ -990,7 +990,7 @@ XCopyPlane( TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask; unsigned long imageBackground = gc->background; - if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP) { + if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP) { srcRect = CGRectMake(src_x, src_y, width, height); CGImageRef mask = CreateCGImageFromPixmap( clipPtr->value.pixmap); @@ -1100,8 +1100,8 @@ struct TkMacOSXNSImageModel { int ring; /* Thickness of the focus ring. */ double alpha; /* Transparency, between 0.0 and 1.0*/ char *imageName ; /* Malloc'ed image name. */ - char *source; /* Malloc'ed string describing the image. */ - char *as; /* Malloc'ed interpretation of source */ + Tcl_Obj *sourceObj; /* Describing the image. */ + Tcl_Obj *asObj; /* Interpretation of source */ int flags; /* Sundry flags, defined below. */ bool pressed; /* Image is for use in a pressed button.*/ bool templ; /* Image is for use as a template.*/ @@ -1163,24 +1163,24 @@ static Tk_ImageType TkMacOSXNSImageType = { static const Tk_OptionSpec systemImageOptions[] = { {TK_OPTION_STRING, "-source", NULL, NULL, DEF_SOURCE, - -1, offsetof(TkMacOSXNSImageModel, source), 0, NULL, 0}, + offsetof(TkMacOSXNSImageModel, sourceObj), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_STRING, "-as", NULL, NULL, DEF_AS, - -1, offsetof(TkMacOSXNSImageModel, as), 0, NULL, 0}, + offsetof(TkMacOSXNSImageModel, asObj), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_INT, "-width", NULL, NULL, DEF_WIDTH, - -1, offsetof(TkMacOSXNSImageModel, width), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMacOSXNSImageModel, width), 0, NULL, 0}, {TK_OPTION_INT, "-height", NULL, NULL, DEF_HEIGHT, - -1, offsetof(TkMacOSXNSImageModel, height), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMacOSXNSImageModel, height), 0, NULL, 0}, {TK_OPTION_INT, "-radius", NULL, NULL, DEF_RADIUS, - -1, offsetof(TkMacOSXNSImageModel, radius), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMacOSXNSImageModel, radius), 0, NULL, 0}, {TK_OPTION_INT, "-ring", NULL, NULL, DEF_RING, - -1, offsetof(TkMacOSXNSImageModel, ring), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMacOSXNSImageModel, ring), 0, NULL, 0}, {TK_OPTION_DOUBLE, "-alpha", NULL, NULL, DEF_ALPHA, - -1, offsetof(TkMacOSXNSImageModel, alpha), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMacOSXNSImageModel, alpha), 0, NULL, 0}, {TK_OPTION_BOOLEAN, "-pressed", NULL, NULL, DEF_PRESSED, - -1, offsetof(TkMacOSXNSImageModel, pressed), TK_OPTION_VAR(bool), NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMacOSXNSImageModel, pressed), TK_OPTION_VAR(bool), NULL, 0}, {TK_OPTION_BOOLEAN, "-template", NULL, NULL, DEF_TEMPLATE, - -1, offsetof(TkMacOSXNSImageModel, templ), TK_OPTION_VAR(bool), NULL, 0}, - {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, NULL, 0} + TCL_INDEX_NONE, offsetof(TkMacOSXNSImageModel, templ), TK_OPTION_VAR(bool), NULL, 0}, + {TK_OPTION_END, NULL, NULL, NULL, NULL, TCL_INDEX_NONE, TCL_INDEX_NONE, 0, NULL, 0} }; /* @@ -1296,7 +1296,7 @@ TkMacOSXNSImageConfigureModel( modelPtr->height = oldHeight; } - if (modelPtr->source == NULL || modelPtr->source[0] == '0') { + if (modelPtr->sourceObj == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("-source is required.", TCL_INDEX_NONE)); Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL); goto errorExit; @@ -1313,7 +1313,7 @@ TkMacOSXNSImageConfigureModel( goto errorExit; } - source = [[NSString alloc] initWithUTF8String: modelPtr->source]; + source = [[NSString alloc] initWithUTF8String: Tcl_GetString(modelPtr->sourceObj)]; switch (sourceInterpretation) { case NAME_SOURCE: newImage = [[NSImage imageNamed:source] copy]; @@ -1369,7 +1369,7 @@ TkMacOSXNSImageConfigureModel( case NAME_SOURCE: Tcl_SetObjResult(interp, Tcl_NewStringObj("Unknown named NSImage.\n" "Try omitting ImageName, " - "e.g. use NSCaution for NSImageNameCaution.", TCL_INDEX_NONE)); + "e.g. use NSCaution for NSImageNameCaution.", TCL_INDEX_NONE)); Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL); goto errorExit; case FILE_SOURCE: @@ -1473,9 +1473,9 @@ TkMacOSXNSImageObjCmd( objPtr = Tk_GetOptionValue(interp, (char *)modelPtr, optionTable, objv[2], NULL); if (objPtr == NULL) { - goto error; - } - Tcl_SetObjResult(interp, objPtr); + goto error; + } + Tcl_SetObjResult(interp, objPtr); break; case CONFIGURE: if (objc == 2) { @@ -1550,8 +1550,8 @@ TkMacOSXNSImageCreate( modelPtr->instancePtr = NULL; modelPtr->image = NULL; modelPtr->darkModeImage = NULL; - modelPtr->source = NULL; - modelPtr->as = NULL; + modelPtr->sourceObj = NULL; + modelPtr->asObj = NULL; /* * Process configuration options given in the image create command. @@ -1736,8 +1736,8 @@ TkMacOSXNSImageDelete( Tcl_DeleteCommand(modelPtr->interp, modelPtr->imageName); ckfree(modelPtr->imageName); - ckfree(modelPtr->source); - ckfree(modelPtr->as); + Tcl_DecrRefCount(modelPtr->sourceObj); + Tcl_DecrRefCount(modelPtr->asObj); [modelPtr->image release]; [modelPtr->darkModeImage release]; ckfree(modelPtr); diff --git a/macosx/tkMacOSXScale.c b/macosx/tkMacOSXScale.c index 96a61b8d2..1442236f7 100644 --- a/macosx/tkMacOSXScale.c +++ b/macosx/tkMacOSXScale.c @@ -167,14 +167,14 @@ TkpDisplayScale( */ Tcl_Preserve(scalePtr); - if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { + if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->commandObj != NULL)) { Tcl_Preserve(interp); - if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format, - scalePtr->value) < 0) { - string[TCL_DOUBLE_SPACE - 1] = '\0'; - } + if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format, + scalePtr->value) < 0) { + string[TCL_DOUBLE_SPACE - 1] = '\0'; + } Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, scalePtr->command, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(scalePtr->commandObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE); Tcl_DStringAppend(&buf, string, TCL_INDEX_NONE); result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index fc32a7bb6..0cc91a53e 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -868,7 +868,7 @@ TkWmProtocolEventProc( Tcl_Preserve(protPtr); interp = protPtr->interp; Tcl_Preserve(interp); - result = Tcl_EvalEx(interp, protPtr->command, TCL_INDEX_NONE, TCL_EVAL_GLOBAL); + result = Tcl_EvalEx(interp, Tcl_GetString(protPtr->commandObj), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); if (result != TCL_OK) { Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( "\n (command for \"%s\" window manager protocol)", diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 5c763a566..eb8a8ee53 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -3733,8 +3733,6 @@ WmProtocolCmd( WmInfo *wmPtr = winPtr->wmInfoPtr; ProtocolHandler *protPtr, *prevPtr; Atom protocol; - char *cmd; - Tcl_Size cmdLength; Tcl_Obj *resultObj; if ((objc < 3) || (objc > 5)) { @@ -3766,8 +3764,7 @@ WmProtocolCmd( for (protPtr = wmPtr->protPtr; protPtr != NULL; protPtr = protPtr->nextPtr) { if (protPtr->protocol == protocol) { - Tcl_SetObjResult(interp, - Tcl_NewStringObj(protPtr->command, TCL_INDEX_NONE)); + Tcl_SetObjResult(interp, protPtr->commandObj); return TCL_OK; } } @@ -3787,21 +3784,20 @@ WmProtocolCmd( } else { prevPtr->nextPtr = protPtr->nextPtr; } - if (protPtr->command) - ckfree(protPtr->command); + if (protPtr->commandObj) + Tcl_DecrRefCount(protPtr->commandObj); Tcl_EventuallyFree(protPtr, TCL_DYNAMIC); break; } } - cmd = Tcl_GetStringFromObj(objv[4], &cmdLength); - if (cmdLength > 0) { + if (Tcl_GetString(objv[4])[0]) { protPtr = (ProtocolHandler *)ckalloc(sizeof(ProtocolHandler)); protPtr->protocol = protocol; protPtr->nextPtr = wmPtr->protPtr; wmPtr->protPtr = protPtr; protPtr->interp = interp; - protPtr->command = (char *)ckalloc(cmdLength+1); - strcpy(protPtr->command, cmd); + protPtr->commandObj = objv[4]; + Tcl_IncrRefCount(protPtr->commandObj); } return TCL_OK; } @@ -6071,13 +6067,12 @@ Tk_MacOSXGetTkWindow( Window window = None; if ([(NSWindow *)w respondsToSelector: @selector (tkWindow)]) { window = [(TKWindow *)w tkWindow]; - } - if (window) { TkDisplay *dispPtr = TkGetDisplayList(); - return Tk_IdToWindow(dispPtr->display, window); - } else { - return NULL; + if (window && dispPtr && dispPtr->display) { + return Tk_IdToWindow(dispPtr->display, window); + } } + return NULL; } /* @@ -6102,7 +6097,10 @@ MODULE_SCOPE int TkMacOSXIsWindowZoomed( TkWindow *winPtr) { - NSWindow *macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window); + NSWindow *macWindow = nil; + if (winPtr && winPtr->window) { + macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window); + } return [macWindow isZoomed]; } @@ -7162,7 +7160,10 @@ TkpChangeFocus( * didn't originally belong to topLevelPtr's * application. */ { - if (winPtr->atts.override_redirect) { + if (!winPtr || + (winPtr->flags & TK_ALREADY_DEAD) || + !Tk_IsMapped(winPtr) || + winPtr->atts.override_redirect) { return 0; } diff --git a/macosx/tkMacOSXWm.h b/macosx/tkMacOSXWm.h index 12c4e8f9e..d243e762f 100644 --- a/macosx/tkMacOSXWm.h +++ b/macosx/tkMacOSXWm.h @@ -29,7 +29,7 @@ typedef struct ProtocolHandler { * same top-level window, or NULL for end of * list. */ Tcl_Interp *interp; /* Interpreter in which to invoke command. */ - char* command; /* Tcl command to invoke when a client message + Tcl_Obj* commandObj; /* Tcl command to invoke when a client message * for this protocol arrives. The actual size * of the structure varies to accommodate the * needs of the actual command. THIS MUST BE diff --git a/unix/tkUnixScale.c b/unix/tkUnixScale.c index 8f4d23b7c..bfed72b8a 100644 --- a/unix/tkUnixScale.c +++ b/unix/tkUnixScale.c @@ -123,8 +123,8 @@ DisplayVerticalScale( drawnAreaPtr->x = scalePtr->vertTickRightX; drawnAreaPtr->y = scalePtr->inset; drawnAreaPtr->width = scalePtr->vertTroughX + scalePtr->width - + 2*scalePtr->borderWidth - scalePtr->vertTickRightX; - drawnAreaPtr->height -= 2*scalePtr->inset; + + 2 * scalePtr->borderWidth - scalePtr->vertTickRightX; + drawnAreaPtr->height -= 2 * scalePtr->inset; } Tk_Fill3DRectangle(tkwin, drawable, scalePtr->bgBorder, drawnAreaPtr->x, drawnAreaPtr->y, drawnAreaPtr->width, @@ -187,25 +187,25 @@ DisplayVerticalScale( Tk_Draw3DRectangle(tkwin, drawable, scalePtr->bgBorder, scalePtr->vertTroughX, scalePtr->inset, - scalePtr->width + 2*scalePtr->borderWidth, - Tk_Height(tkwin) - 2*scalePtr->inset, scalePtr->borderWidth, + scalePtr->width + 2 * scalePtr->borderWidth, + Tk_Height(tkwin) - 2 * scalePtr->inset, scalePtr->borderWidth, TK_RELIEF_SUNKEN); XFillRectangle(scalePtr->display, drawable, scalePtr->troughGC, scalePtr->vertTroughX + scalePtr->borderWidth, scalePtr->inset + scalePtr->borderWidth, (unsigned) scalePtr->width, - (unsigned) (Tk_Height(tkwin) - 2*scalePtr->inset - - 2*scalePtr->borderWidth)); + (unsigned) (Tk_Height(tkwin) - 2 * scalePtr->inset + - 2 * scalePtr->borderWidth)); if (scalePtr->state == STATE_ACTIVE) { sliderBorder = scalePtr->activeBorder; } else { sliderBorder = scalePtr->bgBorder; } width = scalePtr->width; - height = scalePtr->sliderLength/2; + height = scalePtr->sliderLength / 2; x = scalePtr->vertTroughX + scalePtr->borderWidth; y = TkScaleValueToPixel(scalePtr, scalePtr->value) - height; - shadowWidth = scalePtr->borderWidth/2; + shadowWidth = scalePtr->borderWidth / 2; if (shadowWidth == 0) { shadowWidth = 1; } @@ -213,7 +213,7 @@ DisplayVerticalScale( 2*height, shadowWidth, scalePtr->sliderRelief); x += shadowWidth; y += shadowWidth; - width -= 2*shadowWidth; + width -= 2 * shadowWidth; height -= shadowWidth; Tk_Fill3DRectangle(tkwin, drawable, sliderBorder, x, y, width, height, shadowWidth, scalePtr->sliderRelief); @@ -224,13 +224,15 @@ DisplayVerticalScale( * Draw the label to the right of the scale. */ - if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) { + if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelObj != NULL)) { Tk_FontMetrics fm; + Tcl_Size labelLength; + const char *label = Tcl_GetStringFromObj(scalePtr->labelObj, &labelLength); Tk_GetFontMetrics(scalePtr->tkfont, &fm); Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC, - scalePtr->tkfont, scalePtr->label, - scalePtr->labelLength, scalePtr->vertLabelX, + scalePtr->tkfont, label, + labelLength, scalePtr->vertLabelX, scalePtr->inset + (3 * fm.ascent) / 2); } } @@ -339,7 +341,7 @@ DisplayHorizontalScale( drawnAreaPtr->y = scalePtr->horizValueY; drawnAreaPtr->width -= 2*scalePtr->inset; drawnAreaPtr->height = scalePtr->horizTroughY + scalePtr->width - + 2*scalePtr->borderWidth - scalePtr->horizValueY; + + 2 * scalePtr->borderWidth - scalePtr->horizValueY; } Tk_Fill3DRectangle(tkwin, drawable, scalePtr->bgBorder, drawnAreaPtr->x, drawnAreaPtr->y, drawnAreaPtr->width, @@ -410,25 +412,25 @@ DisplayHorizontalScale( y = scalePtr->horizTroughY; Tk_Draw3DRectangle(tkwin, drawable, scalePtr->bgBorder, scalePtr->inset, y, - Tk_Width(tkwin) - 2*scalePtr->inset, - scalePtr->width + 2*scalePtr->borderWidth, + Tk_Width(tkwin) - 2 * scalePtr->inset, + scalePtr->width + 2 * scalePtr->borderWidth, scalePtr->borderWidth, TK_RELIEF_SUNKEN); XFillRectangle(scalePtr->display, drawable, scalePtr->troughGC, scalePtr->inset + scalePtr->borderWidth, y + scalePtr->borderWidth, - (unsigned) (Tk_Width(tkwin) - 2*scalePtr->inset - - 2*scalePtr->borderWidth), + (unsigned) (Tk_Width(tkwin) - 2 * scalePtr->inset + - 2 * scalePtr->borderWidth), (unsigned) scalePtr->width); if (scalePtr->state == STATE_ACTIVE) { sliderBorder = scalePtr->activeBorder; } else { sliderBorder = scalePtr->bgBorder; } - width = scalePtr->sliderLength/2; + width = scalePtr->sliderLength / 2; height = scalePtr->width; x = TkScaleValueToPixel(scalePtr, scalePtr->value) - width; y += scalePtr->borderWidth; - shadowWidth = scalePtr->borderWidth/2; + shadowWidth = scalePtr->borderWidth / 2; if (shadowWidth == 0) { shadowWidth = 1; } @@ -447,13 +449,14 @@ DisplayHorizontalScale( * Draw the label at the top of the scale. */ - if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) { + if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelObj != NULL)) { Tk_FontMetrics fm; + Tcl_Size labelLength; + const char *label = Tcl_GetStringFromObj(scalePtr->labelObj, &labelLength); Tk_GetFontMetrics(scalePtr->tkfont, &fm); Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC, - scalePtr->tkfont, scalePtr->label, - scalePtr->labelLength, scalePtr->inset + fm.ascent/2, + scalePtr->tkfont, label, labelLength, scalePtr->inset + fm.ascent/2, scalePtr->horizLabelY + fm.ascent); } } @@ -565,14 +568,14 @@ TkpDisplayScale( */ Tcl_Preserve(scalePtr); - if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { + if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->commandObj != NULL)) { Tcl_Preserve(interp); if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->valueFormat, scalePtr->value) < 0) { string[TCL_DOUBLE_SPACE - 1] = '\0'; } Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, scalePtr->command, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(scalePtr->commandObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE); Tcl_DStringAppend(&buf, string, TCL_INDEX_NONE); result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); @@ -628,8 +631,8 @@ TkpDisplayScale( if (scalePtr->relief != TK_RELIEF_FLAT) { Tk_Draw3DRectangle(tkwin, pixmap, scalePtr->bgBorder, scalePtr->highlightWidth, scalePtr->highlightWidth, - Tk_Width(tkwin) - 2*scalePtr->highlightWidth, - Tk_Height(tkwin) - 2*scalePtr->highlightWidth, + Tk_Width(tkwin) - 2 * scalePtr->highlightWidth, + Tk_Height(tkwin) - 2 * scalePtr->highlightWidth, scalePtr->borderWidth, scalePtr->relief); } if (scalePtr->highlightWidth > 0) { @@ -688,7 +691,7 @@ TkpScaleElement( if (scalePtr->orient == ORIENT_VERTICAL) { if ((x < scalePtr->vertTroughX) - || (x >= (scalePtr->vertTroughX + 2*scalePtr->borderWidth + + || (x >= (scalePtr->vertTroughX + 2 * scalePtr->borderWidth + scalePtr->width))) { return OTHER; } @@ -708,7 +711,7 @@ TkpScaleElement( } if ((y < scalePtr->horizTroughY) - || (y >= (scalePtr->horizTroughY + 2*scalePtr->borderWidth + + || (y >= (scalePtr->horizTroughY + 2 * scalePtr->borderWidth + scalePtr->width))) { return OTHER; }