From 199d4675fda94dffe00bafa804ea9f5e38f0891b Mon Sep 17 00:00:00 2001 From: dkf Date: Sun, 5 Oct 2008 11:34:45 +0000 Subject: Backport of fix for [Bug 2112563] --- ChangeLog | 10 ++++++++++ generic/tkArgv.c | 4 ++-- generic/tkCanvText.c | 13 ++++++++---- generic/tkEntry.c | 22 ++++++++++++-------- generic/tkListbox.c | 53 +++++++++++++++++++++++++++++-------------------- generic/tkScrollbar.c | 6 +++--- macosx/tkMacOSXScrlbr.c | 53 ++++++++++++++++++++++++++++--------------------- win/tkWinScrlbr.c | 10 +++++----- 8 files changed, 105 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0f6c691..cd14df0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-10-05 Donal K. Fellows + + * win/tkWinScrlbr.c: Convert 'sprintf(..."%g"...)' to the + * macosx/tkMacOSXScrlbr.c: locale-insensitive Tcl_PrintDouble. + * generic/tkScrollbar.c: [Bug 2112563] + * generic/tkListbox.c: + * generic/tkEntry.c: + * generic/tkCanvText.c: + * generic/tkArgv.c: + 2008-08-25 Todd M. Helfter * library/menu.tcl: additional fix for [Bug 1023955] diff --git a/generic/tkArgv.c b/generic/tkArgv.c index 1a530b2..52ee080 100644 --- a/generic/tkArgv.c +++ b/generic/tkArgv.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkArgv.c,v 1.11.2.2 2008/04/07 22:27:21 hobbs Exp $ + * RCS: @(#) $Id: tkArgv.c,v 1.11.2.3 2008/10/05 11:34:46 dkf Exp $ */ #include "tkInt.h" @@ -380,7 +380,7 @@ PrintUsage( Tcl_AppendResult(interp, "\n\t\tDefault value: ", tmp, NULL); break; case TK_ARGV_FLOAT: - sprintf(tmp, "%g", *((double *) infoPtr->dst)); + Tcl_PrintDouble(NULL, *((double *) infoPtr->dst), tmp); Tcl_AppendResult(interp, "\n\t\tDefault value: ", tmp, NULL); break; case TK_ARGV_STRING: { diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c index 1dfdc7f..40ca817 100644 --- a/generic/tkCanvText.c +++ b/generic/tkCanvText.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvText.c,v 1.26 2007/12/13 15:24:13 dgp Exp $ + * RCS: @(#) $Id: tkCanvText.c,v 1.26.2.1 2008/10/05 11:34:46 dkf Exp $ */ #include @@ -1501,9 +1501,14 @@ TextToPostscript( } Tk_GetFontMetrics(textPtr->tkfont, &fm); - sprintf(buffer, "] %d %g %g %s %s DrawText\n", - fm.linespace, x / -2.0, y / 2.0, justify, - ((stipple == None) ? "false" : "true")); + sprintf(buffer, "] %d ", fm.linespace); + Tcl_AppendResult(interp, buffer, NULL); + Tcl_PrintDouble(NULL, x / -2.0, buffer); + Tcl_AppendResult(interp, buffer, NULL); + Tcl_PrintDouble(NULL, y / 2.0, buffer); + Tcl_AppendResult(interp, " ", buffer, NULL); + sprintf(buffer, " %s %s DrawText\n", + justify, ((stipple == None) ? "false" : "true")); Tcl_AppendResult(interp, buffer, NULL); return TCL_OK; diff --git a/generic/tkEntry.c b/generic/tkEntry.c index 62b0806..3ba727f 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkEntry.c,v 1.47 2007/12/13 15:24:14 dgp Exp $ + * RCS: @(#) $Id: tkEntry.c,v 1.47.2.1 2008/10/05 11:34:46 dkf Exp $ */ #include "tkInt.h" @@ -926,11 +926,13 @@ EntryWidgetObjCmd( if (objc == 2) { double first, last; - char buf[TCL_DOUBLE_SPACE * 2]; + char buf[TCL_DOUBLE_SPACE]; EntryVisibleRange(entryPtr, &first, &last); - sprintf(buf, "%g %g", first, last); + Tcl_PrintDouble(NULL, first, buf); Tcl_SetResult(interp, buf, TCL_VOLATILE); + Tcl_PrintDouble(NULL, last, buf); + Tcl_AppendResult(interp, " ", buf, NULL); goto done; } else if (objc == 3) { if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]), @@ -2928,7 +2930,7 @@ static void EntryUpdateScrollbar( Entry *entryPtr) /* Information about widget. */ { - char args[TCL_DOUBLE_SPACE * 2]; + char firstStr[TCL_DOUBLE_SPACE], lastStr[TCL_DOUBLE_SPACE]; int code; double first, last; Tcl_Interp *interp; @@ -2940,8 +2942,10 @@ EntryUpdateScrollbar( interp = entryPtr->interp; Tcl_Preserve((ClientData) interp); EntryVisibleRange(entryPtr, &first, &last); - sprintf(args, " %g %g", first, last); - code = Tcl_VarEval(interp, entryPtr->scrollCmd, args, NULL); + Tcl_PrintDouble(NULL, first, firstStr); + Tcl_PrintDouble(NULL, last, lastStr); + code = Tcl_VarEval(interp, entryPtr->scrollCmd, firstStr, " ", lastStr, + NULL); if (code != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (horizontal scrolling command executed by "); @@ -4041,11 +4045,13 @@ SpinboxWidgetObjCmd( if (objc == 2) { double first, last; - char buf[TCL_DOUBLE_SPACE * 2]; + char buf[TCL_DOUBLE_SPACE]; EntryVisibleRange(entryPtr, &first, &last); - sprintf(buf, "%g %g", first, last); + Tcl_PrintDouble(NULL, first, buf); Tcl_SetResult(interp, buf, TCL_VOLATILE); + Tcl_PrintDouble(NULL, last, buf); + Tcl_AppendResult(interp, " ", buf, NULL); goto done; } else if (objc == 3) { if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]), diff --git a/generic/tkListbox.c b/generic/tkListbox.c index f3d5c65..e970ac2 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkListbox.c,v 1.44 2007/12/13 15:24:15 dgp Exp $ + * RCS: @(#) $Id: tkListbox.c,v 1.44.2.1 2008/10/05 11:34:46 dkf Exp $ */ #include "default.h" @@ -1248,7 +1248,7 @@ ListboxXviewSubCmd( if (listPtr->maxWidth == 0) { Tcl_SetResult(interp, "0 1", TCL_STATIC); } else { - char buf[TCL_DOUBLE_SPACE * 2]; + char buf[TCL_DOUBLE_SPACE]; fraction = listPtr->xOffset/((double) listPtr->maxWidth); fraction2 = (listPtr->xOffset + windowWidth) @@ -1256,8 +1256,10 @@ ListboxXviewSubCmd( if (fraction2 > 1.0) { fraction2 = 1.0; } - sprintf(buf, "%g %g", fraction, fraction2); + Tcl_PrintDouble(NULL, fraction, buf); Tcl_SetResult(interp, buf, TCL_VOLATILE); + Tcl_PrintDouble(NULL, fraction2, buf); + Tcl_AppendResult(interp, " ", buf, NULL); } } else if (objc == 3) { if (Tcl_GetIntFromObj(interp, objv[2], &index) != TCL_OK) { @@ -1320,7 +1322,7 @@ ListboxYviewSubCmd( if (listPtr->nElements == 0) { Tcl_SetResult(interp, "0 1", TCL_STATIC); } else { - char buf[TCL_DOUBLE_SPACE * 2]; + char buf[TCL_DOUBLE_SPACE]; fraction = listPtr->topIndex/((double) listPtr->nElements); fraction2 = (listPtr->topIndex+listPtr->fullLines) @@ -1328,8 +1330,10 @@ ListboxYviewSubCmd( if (fraction2 > 1.0) { fraction2 = 1.0; } - sprintf(buf, "%g %g", fraction, fraction2); + Tcl_PrintDouble(NULL, fraction, buf); Tcl_SetResult(interp, buf, TCL_VOLATILE); + Tcl_PrintDouble(NULL, fraction2, buf); + Tcl_AppendResult(interp, " ", buf, NULL); } } else if (objc == 3) { if (GetListboxIndex(interp, listPtr, objv[2], 0, &index) != TCL_OK) { @@ -3244,7 +3248,7 @@ static void ListboxUpdateVScrollbar( register Listbox *listPtr) /* Information about widget. */ { - char string[TCL_DOUBLE_SPACE * 2]; + char firstStr[TCL_DOUBLE_SPACE+1], lastStr[TCL_DOUBLE_SPACE+1]; double first, last; int result; Tcl_Interp *interp; @@ -3256,14 +3260,16 @@ ListboxUpdateVScrollbar( first = 0.0; last = 1.0; } else { - first = listPtr->topIndex/((double) listPtr->nElements); - last = (listPtr->topIndex+listPtr->fullLines) - /((double) listPtr->nElements); + first = listPtr->topIndex / (double) listPtr->nElements; + last = (listPtr->topIndex + listPtr->fullLines) + / (double) listPtr->nElements; if (last > 1.0) { last = 1.0; } } - sprintf(string, " %g %g", first, last); + firstStr[0] = lastStr[0] = ' '; + Tcl_PrintDouble(NULL, first, firstStr+1); + Tcl_PrintDouble(NULL, last, lastStr+1); /* * We must hold onto the interpreter from the listPtr because the data at @@ -3271,14 +3277,15 @@ ListboxUpdateVScrollbar( */ interp = listPtr->interp; - Tcl_Preserve((ClientData) interp); - result = Tcl_VarEval(interp, listPtr->yScrollCmd, string, NULL); + Tcl_Preserve(interp); + result = Tcl_VarEval(interp, listPtr->yScrollCmd, firstStr, lastStr, + NULL); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (vertical scrolling command executed by listbox)"); Tcl_BackgroundError(interp); } - Tcl_Release((ClientData) interp); + Tcl_Release(interp); } /* @@ -3305,7 +3312,7 @@ static void ListboxUpdateHScrollbar( register Listbox *listPtr) /* Information about widget. */ { - char string[TCL_DOUBLE_SPACE * 2]; + char firstStr[TCL_DOUBLE_SPACE+1], lastStr[TCL_DOUBLE_SPACE+1]; int result, windowWidth; double first, last; Tcl_Interp *interp; @@ -3319,14 +3326,17 @@ ListboxUpdateHScrollbar( first = 0; last = 1.0; } else { - first = listPtr->xOffset/((double) listPtr->maxWidth); - last = (listPtr->xOffset + windowWidth) - /((double) listPtr->maxWidth); + register double maxWide = (double) listPtr->maxWidth; + + first = listPtr->xOffset / maxWide; + last = (listPtr->xOffset + windowWidth) / maxWide; if (last > 1.0) { last = 1.0; } } - sprintf(string, " %g %g", first, last); + firstStr[0] = lastStr[0] = ' '; + Tcl_PrintDouble(NULL, first, firstStr+1); + Tcl_PrintDouble(NULL, last, lastStr+1); /* * We must hold onto the interpreter because the data referred to at @@ -3334,14 +3344,15 @@ ListboxUpdateHScrollbar( */ interp = listPtr->interp; - Tcl_Preserve((ClientData) interp); - result = Tcl_VarEval(interp, listPtr->xScrollCmd, string, NULL); + Tcl_Preserve(interp); + result = Tcl_VarEval(interp, listPtr->xScrollCmd, firstStr, lastStr, + NULL); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (horizontal scrolling command executed by listbox)"); Tcl_BackgroundError(interp); } - Tcl_Release((ClientData) interp); + Tcl_Release(interp); } /* diff --git a/generic/tkScrollbar.c b/generic/tkScrollbar.c index 52e449f..ecbe729 100644 --- a/generic/tkScrollbar.c +++ b/generic/tkScrollbar.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkScrollbar.c,v 1.12 2007/12/13 15:24:16 dgp Exp $ + * RCS: @(#) $Id: tkScrollbar.c,v 1.12.2.1 2008/10/05 11:34:46 dkf Exp $ */ #include "tkInt.h" @@ -324,7 +324,7 @@ ScrollbarWidgetCmd( } else { fraction = ((double) pixels / (double) length); } - sprintf(buf, "%g", fraction); + Tcl_PrintDouble(NULL, fraction, buf); Tcl_SetResult(interp, buf, TCL_VOLATILE); } else if ((c == 'f') && (strncmp(argv[1], "fraction", length) == 0)) { int x, y, pos, length; @@ -359,7 +359,7 @@ ScrollbarWidgetCmd( } else if (fraction > 1.0) { fraction = 1.0; } - sprintf(buf, "%g", fraction); + Tcl_PrintDouble(NULL, fraction, buf); Tcl_SetResult(interp, buf, TCL_VOLATILE); } else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) { if (argc != 2) { diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c index ab56193..509e742 100644 --- a/macosx/tkMacOSXScrlbr.c +++ b/macosx/tkMacOSXScrlbr.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXScrlbr.c,v 1.26 2007/12/13 15:27:10 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXScrlbr.c,v 1.26.2.1 2008/10/05 11:34:46 dkf Exp $ */ #include "tkMacOSXPrivate.h" @@ -651,7 +651,7 @@ ThumbActionProc(ControlRef theControl, ControlPartCode partCode) * for the display to update. */ - sprintf(valueString, "%g", newFirstFraction); + Tcl_PrintDouble(NULL, newFirstFraction, valueString); Tcl_DStringSetLength(&cmdString, 0); Tcl_DStringAppend(&cmdString, scrollPtr->command, scrollPtr->commandSize); @@ -693,8 +693,8 @@ ScrollbarActionProc( ControlRef theControl, /* Handle to scrollbat control */ ControlPartCode partCode) /* Part of scrollbar that was "hit" */ { - TkScrollbar *scrollPtr = (TkScrollbar *)(intptr_t)GetControlReference( - theControl); + TkScrollbar *scrollPtr = (TkScrollbar *)(intptr_t) + GetControlReference(theControl); MacScrollbar *macScrollPtr = (MacScrollbar *) scrollPtr; Tcl_DString cmdString; @@ -702,7 +702,7 @@ ScrollbarActionProc( Tcl_DStringAppend(&cmdString, scrollPtr->command, scrollPtr->commandSize); - if ( partCode == kAppearancePartUpButton || + if (partCode == kAppearancePartUpButton || partCode == kAppearancePartDownButton ) { Tcl_DStringAppendElement(&cmdString, "scroll"); Tcl_DStringAppendElement(&cmdString, @@ -717,16 +717,16 @@ ScrollbarActionProc( } else if (partCode == kAppearancePartIndicator) { char valueString[TCL_DOUBLE_SPACE]; - sprintf(valueString, "%g", + Tcl_PrintDouble(NULL, (GetControl32BitValue(macScrollPtr->sbHandle) - - MIN_SCROLLBAR_VALUE) / SCROLLBAR_SCALING_VALUE); + MIN_SCROLLBAR_VALUE) / SCROLLBAR_SCALING_VALUE, valueString); Tcl_DStringAppendElement(&cmdString, "moveto"); Tcl_DStringAppendElement(&cmdString, valueString); } - Tcl_Preserve((ClientData) scrollPtr->interp); + Tcl_Preserve(scrollPtr->interp); Tcl_EvalEx(scrollPtr->interp, Tcl_DStringValue(&cmdString), Tcl_DStringLength(&cmdString), TCL_EVAL_GLOBAL); - Tcl_Release((ClientData) scrollPtr->interp); + Tcl_Release(scrollPtr->interp); Tcl_DStringFree(&cmdString); TkMacOSXRunTclEventLoop(); } @@ -756,11 +756,11 @@ ScrollbarBindProc( Tk_Window tkwin, /* Target window for event. */ KeySym keySym) /* The KeySym if a key event. */ { - TkWindow *winPtr = (TkWindow*)tkwin; + TkWindow *winPtr = (TkWindow *) tkwin; TkScrollbar *scrollPtr = (TkScrollbar *) winPtr->instanceData; MacScrollbar *macScrollPtr = (MacScrollbar *) winPtr->instanceData; - Tcl_Preserve((ClientData)scrollPtr); + Tcl_Preserve(scrollPtr); macScrollPtr->macFlags |= IN_MODAL_LOOP; if (eventPtr->type == ButtonPress) { @@ -772,10 +772,11 @@ ScrollbarBindProc( Window window; /* - * To call Macintosh control routines we must have the port - * set to the window containing the control. We will then test - * which part of the control was hit and act accordingly. + * To call Macintosh control routines we must have the port set to the + * window containing the control. We will then test which part of the + * control was hit and act accordingly. */ + destPort = TkMacOSXGetDrawablePort(Tk_WindowId(scrollPtr->tkwin)); portChanged = QDSwapPort(destPort, &savePort); TkMacOSXSetUpClippingRgn(Tk_WindowId(scrollPtr->tkwin)); @@ -787,9 +788,10 @@ ScrollbarBindProc( TkMacOSXTrackingLoop(1); if (part == kAppearancePartIndicator && scrollPtr->jump == false) { /* - * Case 1: In thumb, no jump scrolling. Call track control - * with the thumb action proc which will do most of the work. + * Case 1: In thumb, no jump scrolling. Call track control with + * the thumb action proc which will do most of the work. */ + mouseDownPoint.h = where.h; mouseDownPoint.v = where.v; part = HandleControlClick(macScrollPtr->sbHandle, where, @@ -797,18 +799,20 @@ ScrollbarBindProc( } else if (part == kAppearancePartIndicator) { /* * Case 2: in thumb with jump scrolling. Call HandleControlClick - * with a NULL action proc. Use the new value of the control - * to set update the control. + * with a NULL action proc. Use the new value of the control to + * set update the control. */ + part = HandleControlClick(macScrollPtr->sbHandle, where, TkMacOSXModifierState(), NULL); if (part == kAppearancePartIndicator) { Tcl_DString cmdString; char valueString[TCL_DOUBLE_SPACE]; - sprintf(valueString, "%g", + Tcl_PrintDouble(NULL, (GetControl32BitValue(macScrollPtr->sbHandle) - - MIN_SCROLLBAR_VALUE) / SCROLLBAR_SCALING_VALUE); + MIN_SCROLLBAR_VALUE) / SCROLLBAR_SCALING_VALUE, + valueString); Tcl_DStringInit(&cmdString); Tcl_DStringAppend(&cmdString, scrollPtr->command, strlen(scrollPtr->command)); @@ -816,10 +820,10 @@ ScrollbarBindProc( Tcl_DStringAppendElement(&cmdString, valueString); interp = scrollPtr->interp; - Tcl_Preserve((ClientData) interp); + Tcl_Preserve(interp); Tcl_EvalEx(interp, Tcl_DStringValue(&cmdString), Tcl_DStringLength(&cmdString), TCL_EVAL_GLOBAL); - Tcl_Release((ClientData) interp); + Tcl_Release(interp); Tcl_DStringFree(&cmdString); TkMacOSXRunTclEventLoop(); } @@ -829,12 +833,15 @@ ScrollbarBindProc( * HandleControlClick with the scrollActionProc which will do * most all the work. */ + HandleControlClick(macScrollPtr->sbHandle, where, TkMacOSXModifierState(), scrollActionProc); + /* * Workaround for Carbon bug where the scrollbar down arrow * sometimes gets "stuck" after the mousebutton has been released. */ + if (scrollPtr->tkwin) { TkMacOSXSetUpClippingRgn(Tk_WindowId(scrollPtr->tkwin)); } @@ -862,7 +869,7 @@ ScrollbarBindProc( macScrollPtr->sbHandle = NULL; } macScrollPtr->macFlags &= ~IN_MODAL_LOOP; - Tcl_Release((ClientData)scrollPtr); + Tcl_Release(scrollPtr); return TCL_OK; } diff --git a/win/tkWinScrlbr.c b/win/tkWinScrlbr.c index a6f19bc..4435d10 100644 --- a/win/tkWinScrlbr.c +++ b/win/tkWinScrlbr.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWinScrlbr.c,v 1.15 2007/12/14 15:56:09 patthoyts Exp $ + * RCS: @(#) $Id: tkWinScrlbr.c,v 1.15.2.1 2008/10/05 11:34:46 dkf Exp $ */ #include "tkWinInt.h" @@ -563,7 +563,7 @@ ScrollbarProc( break; } - sprintf(valueString, "%g", pos); + Tcl_PrintDouble(NULL, pos, valueString); Tcl_DStringAppendElement(&cmdString, "moveto"); Tcl_DStringAppendElement(&cmdString, valueString); } @@ -669,12 +669,12 @@ ModalLoopProc( Tk_Window tkwin, XEvent *eventPtr) { - TkWindow *winPtr = (TkWindow*)tkwin; + TkWindow *winPtr = (TkWindow *) tkwin; WinScrollbar *scrollPtr = (WinScrollbar *) winPtr->instanceData; int oldMode; if (scrollPtr->hwnd) { - Tcl_Preserve((ClientData)scrollPtr); + Tcl_Preserve(scrollPtr); scrollPtr->winFlags |= IN_MODAL_LOOP; oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); TkWinResendEvent(scrollPtr->oldProc, scrollPtr->hwnd, eventPtr); @@ -683,7 +683,7 @@ ModalLoopProc( if (scrollPtr->hwnd && scrollPtr->winFlags & ALREADY_DEAD) { DestroyWindow(scrollPtr->hwnd); } - Tcl_Release((ClientData)scrollPtr); + Tcl_Release(scrollPtr); } } -- cgit v0.12