diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | generic/tkArgv.c | 4 | ||||
-rw-r--r-- | generic/tkCanvText.c | 11 | ||||
-rw-r--r-- | generic/tkEntry.c | 117 | ||||
-rw-r--r-- | generic/tkListbox.c | 44 | ||||
-rw-r--r-- | generic/tkScrollbar.c | 10 | ||||
-rw-r--r-- | macosx/tkMacOSXScrlbr.c | 303 | ||||
-rw-r--r-- | win/tkWinScrlbr.c | 4 |
8 files changed, 267 insertions, 234 deletions
@@ -1,3 +1,11 @@ +2008-10-03 Donal K. Fellows <dkf@users.sf.net> + + * generic/tkArgv.c, generic/tkCanvText.c, generic/tkEntry.c: + * generic/tkListbox.c, generic/tkScrollbar.c, macosx/tkMacOSXScrlbr.c: + * win/tkWinScrlbr.c: Convert use of %g to Tcl_PrintDouble to create + string versions of floats so as to avoid trouble with some locales. + [Bug 2112563] + 2008-10-02 Joe Mistachkin <joe@mistachkin.com> * doc/canvas.n: Fix unmatched font change. diff --git a/generic/tkArgv.c b/generic/tkArgv.c index 039b4d1..95fbe21 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.14 2008/04/27 22:38:55 dkf Exp $ + * RCS: @(#) $Id: tkArgv.c,v 1.15 2008/10/03 13:13:31 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 34206ea..3450633 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.27 2008/04/27 22:38:55 dkf Exp $ + * RCS: @(#) $Id: tkCanvText.c,v 1.28 2008/10/03 13:13:31 dkf Exp $ */ #include <stdio.h> @@ -1501,8 +1501,13 @@ TextToPostscript( } Tk_GetFontMetrics(textPtr->tkfont, &fm); - sprintf(buffer, "] %d %g %g %s %s DrawText\n", - fm.linespace, x / -2.0, y / 2.0, justify, + 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); diff --git a/generic/tkEntry.c b/generic/tkEntry.c index 26249d4..fa0c07e 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.49 2008/07/23 23:24:23 nijtmans Exp $ + * RCS: @(#) $Id: tkEntry.c,v 1.50 2008/10/03 13:13:31 dkf Exp $ */ #include "tkInt.h" @@ -452,8 +452,7 @@ static Tk_ClassProcs entryClass = { sizeof(Tk_ClassProcs), /* size */ EntryWorldChanged, /* worldChangedProc */ }; - - + /* *-------------------------------------------------------------- * @@ -508,7 +507,7 @@ Tk_EntryObjCmd( * initialized as memset covers the rest. */ - entryPtr = (Entry *) ckalloc(sizeof(Entry)); + entryPtr = (Entry *) ckalloc(sizeof(Entry)); memset(entryPtr, 0, sizeof(Entry)); entryPtr->tkwin = tkwin; @@ -563,7 +562,7 @@ Tk_EntryObjCmd( Tcl_SetResult(interp, Tk_PathName(entryPtr->tkwin), TCL_STATIC); return TCL_OK; } - + /* *-------------------------------------------------------------- * @@ -926,11 +925,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]), @@ -987,7 +988,7 @@ EntryWidgetObjCmd( Tcl_Release(entryPtr); return TCL_ERROR; } - + /* *---------------------------------------------------------------------- * @@ -1053,7 +1054,7 @@ DestroyEntry( ckfree((char *) entryPtr); } - + /* *---------------------------------------------------------------------- * @@ -1114,12 +1115,12 @@ ConfigureEntry( * value. */ - oldExport = entryPtr->exportSelection; + oldExport = entryPtr->exportSelection; if (entryPtr->type == TK_SPINBOX) { - oldValues = sbPtr->valueStr; - oldFormat = sbPtr->reqFormat; - oldFrom = sbPtr->fromValue; - oldTo = sbPtr->toValue; + oldValues = sbPtr->valueStr; + oldFormat = sbPtr->reqFormat; + oldFrom = sbPtr->fromValue; + oldTo = sbPtr->toValue; } for (error = 0; error <= 1; error++) { @@ -1368,7 +1369,7 @@ ConfigureEntry( return TCL_OK; } } - + /* *--------------------------------------------------------------------------- * @@ -1420,8 +1421,8 @@ EntryWorldChanged( * the background may be overridden. */ - border = entryPtr->normalBorder; - colorPtr = entryPtr->fgColorPtr; + border = entryPtr->normalBorder; + colorPtr = entryPtr->fgColorPtr; switch (entryPtr->state) { case STATE_DISABLED: if (entryPtr->disabledBorder != NULL) { @@ -1468,7 +1469,7 @@ EntryWorldChanged( entryPtr->flags |= UPDATE_SCROLLBAR; EventuallyRedraw(entryPtr); } - + #ifndef MAC_OSX_TK /* *-------------------------------------------------------------- @@ -1498,7 +1499,7 @@ TkpDrawEntryBorderAndFocus( { return 0; } - + /* *-------------------------------------------------------------- * @@ -1527,7 +1528,7 @@ TkpDrawSpinboxButtons( return 0; } #endif /* Not MAC_OSX_TK */ - + /* *-------------------------------------------------------------- * @@ -1846,7 +1847,7 @@ DisplayEntry( #endif /* TK_NO_DOUBLE_BUFFERING */ entryPtr->flags &= ~BORDER_NEEDED; } - + /* *---------------------------------------------------------------------- * @@ -1982,7 +1983,7 @@ EntryComputeGeometry( Tk_GeometryRequest(entryPtr->tkwin, width, height); } - + /* *---------------------------------------------------------------------- * @@ -2022,7 +2023,7 @@ InsertChars( } newByteCount = entryPtr->numBytes + byteCount + 1; - newStr = (char *) ckalloc((unsigned) newByteCount); + newStr = ckalloc((unsigned) newByteCount); memcpy(newStr, string, byteIndex); strcpy(newStr + byteIndex, value); strcpy(newStr + byteIndex + byteCount, string + byteIndex); @@ -2082,7 +2083,7 @@ InsertChars( } EntryValueChanged(entryPtr, NULL); } - + /* *---------------------------------------------------------------------- * @@ -2122,11 +2123,11 @@ DeleteChars( byteCount = Tcl_UtfAtIndex(string + byteIndex, count) - (string+byteIndex); newByteCount = entryPtr->numBytes + 1 - byteCount; - newStr = (char *) ckalloc((unsigned) newByteCount); + newStr = ckalloc((unsigned) newByteCount); memcpy(newStr, string, (size_t) byteIndex); strcpy(newStr + byteIndex, string + byteIndex + byteCount); - toDelete = (char *) ckalloc((unsigned) (byteCount + 1)); + toDelete = ckalloc((unsigned) (byteCount + 1)); memcpy(toDelete, string + byteIndex, (size_t) byteCount); toDelete[byteCount] = '\0'; @@ -2197,7 +2198,7 @@ DeleteChars( } EntryValueChanged(entryPtr, NULL); } - + /* *---------------------------------------------------------------------- * @@ -2253,7 +2254,7 @@ EntryValueChanged( EventuallyRedraw(entryPtr); } } - + /* *---------------------------------------------------------------------- * @@ -2327,7 +2328,7 @@ EntrySetValue( if (malloced) { entryPtr->string = value; } else { - char *tmp = (char *) ckalloc((unsigned) (valueLen + 1)); + char *tmp = ckalloc((unsigned) (valueLen + 1)); strcpy(tmp, value); entryPtr->string = tmp; @@ -2363,7 +2364,7 @@ EntrySetValue( EntryComputeGeometry(entryPtr); EventuallyRedraw(entryPtr); } - + /* *-------------------------------------------------------------- * @@ -2445,7 +2446,7 @@ EntryEventProc( break; } } - + /* *---------------------------------------------------------------------- * @@ -2481,7 +2482,7 @@ EntryCmdDeletedProc( Tk_DestroyWindow(entryPtr->tkwin); } } - + /* *--------------------------------------------------------------------------- * @@ -2601,7 +2602,7 @@ GetEntryIndex( } return TCL_OK; } - + /* *---------------------------------------------------------------------- * @@ -2659,7 +2660,7 @@ EntryScanTo( EventuallyRedraw(entryPtr); } } - + /* *---------------------------------------------------------------------- * @@ -2720,7 +2721,7 @@ EntrySelectTo( entryPtr->selectLast = newLast; EventuallyRedraw(entryPtr); } - + /* *---------------------------------------------------------------------- * @@ -2815,7 +2816,7 @@ EntryLostSelection( EventuallyRedraw(entryPtr); } } - + /* *---------------------------------------------------------------------- * @@ -2854,7 +2855,7 @@ EventuallyRedraw( Tcl_DoWhenIdle(DisplayEntry, entryPtr); } } - + /* *---------------------------------------------------------------------- * @@ -2903,7 +2904,7 @@ EntryVisibleRange( / entryPtr->numChars; } } - + /* *---------------------------------------------------------------------- * @@ -2928,7 +2929,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 +2941,10 @@ EntryUpdateScrollbar( interp = entryPtr->interp; Tcl_Preserve(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 "); @@ -2952,7 +2955,7 @@ EntryUpdateScrollbar( Tcl_SetResult(interp, NULL, TCL_STATIC); Tcl_Release(interp); } - + /* *---------------------------------------------------------------------- * @@ -2993,7 +2996,7 @@ EntryBlinkProc( } EventuallyRedraw(entryPtr); } - + /* *---------------------------------------------------------------------- * @@ -3043,7 +3046,7 @@ EntryFocusProc( } EventuallyRedraw(entryPtr); } - + /* *-------------------------------------------------------------- * @@ -3110,7 +3113,7 @@ EntryTextVarProc( EntrySetValue(entryPtr, value); return NULL; } - + /* *-------------------------------------------------------------- * @@ -3171,7 +3174,7 @@ EntryValidate( Tcl_SetResult(interp, NULL, 0); return (bool ? TCL_OK : TCL_BREAK); } - + /* *-------------------------------------------------------------- * @@ -3308,7 +3311,7 @@ EntryValidateChange( return code; } - + /* *-------------------------------------------------------------- * @@ -3474,7 +3477,7 @@ ExpandPercents( Tcl_DStringSetLength(dsPtr, length + spaceNeeded); } } - + /* *-------------------------------------------------------------- * @@ -3530,7 +3533,7 @@ Tk_SpinboxObjCmd( * initialized as memset covers the rest. */ - sbPtr = (Spinbox *) ckalloc(sizeof(Spinbox)); + sbPtr = (Spinbox *) ckalloc(sizeof(Spinbox)); entryPtr = (Entry *) sbPtr; memset(sbPtr, 0, sizeof(Spinbox)); @@ -3604,7 +3607,7 @@ Tk_SpinboxObjCmd( Tk_DestroyWindow(entryPtr->tkwin); return TCL_ERROR; } - + /* *-------------------------------------------------------------- * @@ -4043,11 +4046,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]), @@ -4105,7 +4110,7 @@ SpinboxWidgetObjCmd( Tcl_Release(entryPtr); return TCL_ERROR; } - + /* *--------------------------------------------------------------------------- * @@ -4144,7 +4149,7 @@ GetSpinboxElement( } return SEL_ENTRY; } - + /* *-------------------------------------------------------------- * @@ -4310,7 +4315,7 @@ SpinboxInvoke( return TCL_OK; } - + /* *---------------------------------------------------------------------- * @@ -4399,7 +4404,7 @@ ComputeFormat( sbPtr->valueFormat = sbPtr->digitFormat; return TCL_OK; } - + /* * Local Variables: * mode: c diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 5f52f64..6a61416 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.45 2008/07/23 23:24:21 nijtmans Exp $ + * RCS: @(#) $Id: tkListbox.c,v 1.46 2008/10/03 13:13:31 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, fraction1, 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], lastStr[TCL_DOUBLE_SPACE]; double first, last; int result; Tcl_Interp *interp; @@ -3256,14 +3260,15 @@ 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); + Tcl_PrintDouble(NULL, first, firstStr); + Tcl_PrintDouble(NULL, last, lastStr); /* * We must hold onto the interpreter from the listPtr because the data at @@ -3271,14 +3276,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 +3311,7 @@ static void ListboxUpdateHScrollbar( register Listbox *listPtr) /* Information about widget. */ { - char string[TCL_DOUBLE_SPACE * 2]; + char firstStr[TCL_DOUBLE_SPACE], lastStr[TCL_DOUBLE_SPACE]; int result, windowWidth; double first, last; Tcl_Interp *interp; @@ -3326,7 +3332,8 @@ ListboxUpdateHScrollbar( last = 1.0; } } - sprintf(string, " %g %g", first, last); + Tcl_PrintDouble(NULL, first, firstStr); + Tcl_PrintDouble(NULL, last, lastStr); /* * We must hold onto the interpreter because the data referred to at @@ -3334,14 +3341,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 d736539..611da88 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.14 2008/07/23 23:24:21 nijtmans Exp $ + * RCS: @(#) $Id: tkScrollbar.c,v 1.15 2008/10/03 13:13:31 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) { @@ -370,8 +370,8 @@ ScrollbarWidgetCmd( if (scrollPtr->flags & NEW_STYLE_COMMANDS) { char first[TCL_DOUBLE_SPACE], last[TCL_DOUBLE_SPACE]; - Tcl_PrintDouble(interp, scrollPtr->firstFraction, first); - Tcl_PrintDouble(interp, scrollPtr->lastFraction, last); + Tcl_PrintDouble(NULL, scrollPtr->firstFraction, first); + Tcl_PrintDouble(NULL, scrollPtr->lastFraction, last); Tcl_AppendResult(interp, first, " ", last, NULL); } else { char buf[TCL_INTEGER_SPACE * 4]; diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c index ab56193..5419cb0 100644 --- a/macosx/tkMacOSXScrlbr.c +++ b/macosx/tkMacOSXScrlbr.c @@ -2,17 +2,17 @@ * tkMacOSXScrollbar.c -- * * This file implements the Macintosh specific portion of the scrollbar - * widget. The Macintosh scrollbar may also draw a windows grow - * region under certain cases. + * widget. The Macintosh scrollbar may also draw a windows grow region + * under certain cases. * * Copyright (c) 1996 by Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. * Copyright (c) 2006-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. + * 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.27 2008/10/03 13:13:31 dkf Exp $ */ #include "tkMacOSXPrivate.h" @@ -53,10 +53,10 @@ typedef struct MacScrollbar { */ static ControlActionUPP scrollActionProc = NULL; /* Pointer to func. */ static ControlActionUPP thumbActionProc = NULL; /* Pointer to func. */ -static Point mouseDownPoint; /* Used to store the coordinates where the */ - /* mouse was first pressed to begin */ - /* dragging the thumb, because */ - /* ThumbActionProc can't take any args. */ +static Point mouseDownPoint; /* Used to store the coordinates where the + * mouse was first pressed to begin dragging + * the thumb, because ThumbActionProc can't + * take any args. */ typedef struct ScrollbarMetrics { SInt32 width, minHeight, minThumbHeight; @@ -80,14 +80,16 @@ static char defWidth[TCL_INTEGER_SPACE]; * Forward declarations for procedures defined later in this file: */ -static pascal void ScrollbarActionProc(ControlRef theControl, - ControlPartCode partCode); -static pascal void ThumbActionProc(ControlRef theControl, - ControlPartCode partCode); -static int ScrollbarBindProc(ClientData clientData, Tcl_Interp *interp, - XEvent *eventPtr, Tk_Window tkwin, KeySym keySym); -static void ScrollbarEventProc(ClientData clientData, XEvent *eventPtr); -static void UpdateControlValues(MacScrollbar *macScrollPtr); +static pascal void ScrollbarActionProc(ControlRef theControl, + ControlPartCode partCode); +static pascal void ThumbActionProc(ControlRef theControl, + ControlPartCode partCode); +static int ScrollbarBindProc(ClientData clientData, + Tcl_Interp *interp, XEvent *eventPtr, + Tk_Window tkwin, KeySym keySym); +static void ScrollbarEventProc(ClientData clientData, + XEvent *eventPtr); +static void UpdateControlValues(MacScrollbar *macScrollPtr); /* * The class procedure table for the scrollbar widget. Leave the proc fields @@ -98,14 +100,13 @@ static void UpdateControlValues(MacScrollbar *macScrollPtr); Tk_ClassProcs tkpScrollbarProcs = { sizeof(Tk_ClassProcs) /* size */ }; - + /* *---------------------------------------------------------------------- * * TkMacOSXInitScrollbarMetrics -- * - * This function initializes the current system metrics for a - * scrollbar. + * This function initializes the current system metrics for a scrollbar. * * Results: * None. @@ -210,9 +211,9 @@ TkpCreateScrollbar( * * TkpDisplayScrollbar -- * - * This procedure redraws the contents of a scrollbar window. - * It is invoked as a do-when-idle handler, so it only runs - * when there's nothing else for the application to do. + * This procedure redraws the contents of a scrollbar window. It is + * invoked as a do-when-idle handler, so it only runs when there's + * nothing else for the application to do. * * Results: * None. @@ -304,7 +305,7 @@ TkpDisplayScrollbar( QDSwapPort(savePort, NULL); } - done: + done: scrollPtr->flags &= ~REDRAW_PENDING; } @@ -314,8 +315,8 @@ TkpDisplayScrollbar( * TkpConfigureScrollbar -- * * This procedure is called after the generic code has finished - * processing configuration options, in order to configure - * platform specific options. + * processing configuration options, in order to configure platform + * specific options. * * Results: * None. @@ -339,9 +340,9 @@ TkpConfigureScrollbar(scrollPtr) * * TkpComputeScrollbarGeometry -- * - * After changes in a scrollbar's size or configuration, this - * procedure recomputes various geometry information used in - * displaying the scrollbar. + * After changes in a scrollbar's size or configuration, this procedure + * recomputes various geometry information used in displaying the + * scrollbar. * * Results: * None. @@ -378,9 +379,9 @@ TkpComputeScrollbarGeometry( scrollPtr->sliderLast = fieldLength * scrollPtr->lastFraction; /* - * Adjust the slider so that some piece of it is always - * displayed in the scrollbar and so that it has at least - * a minimal width (so it can be grabbed with the mouse). + * Adjust the slider so that some piece of it is always displayed in the + * scrollbar and so that it has at least a minimal width (so it can be + * grabbed with the mouse). */ if (scrollPtr->sliderFirst > (fieldLength - 2*scrollPtr->borderWidth)) { @@ -403,10 +404,9 @@ TkpComputeScrollbarGeometry( metrics[variant].bottomArrowHeight; /* - * Register the desired geometry for the window (leave enough space - * for the two arrows plus a minimum-size slider, plus border around - * the whole window, if any). Then arrange for the window to be - * redisplayed. + * Register the desired geometry for the window (leave enough space for + * the two arrows plus a minimum-size slider, plus border around the whole + * window, if any). Then arrange for the window to be redisplayed. */ if (scrollPtr->vertical) { @@ -459,14 +459,12 @@ TkpDestroyScrollbar( * * TkpScrollbarPosition -- * - * Determine the scrollbar element corresponding to a - * given position. + * Determine the scrollbar element corresponding to a given position. * * Results: - * One of TOP_ARROW, TOP_GAP, etc., indicating which element - * of the scrollbar covers the position given by (x, y). If - * (x,y) is outside the scrollbar entirely, then OUTSIDE is - * returned. + * One of TOP_ARROW, TOP_GAP, etc., indicating which element of the + * scrollbar covers the position given by (x, y). If (x,y) is outside the + * scrollbar entirely, then OUTSIDE is returned. * * Side effects: * None. @@ -496,10 +494,9 @@ TkpScrollbarPosition( /* * All of the calculations in this procedure mirror those in - * DisplayScrollbar. Be sure to keep the two consistent. On the - * Macintosh we use the OS call TestControl to do this mapping. - * For TestControl to work, the scrollbar must be active and must - * be in the current port. + * DisplayScrollbar. Be sure to keep the two consistent. On the Macintosh + * we use the OS call TestControl to do this mapping. For TestControl to + * work, the scrollbar must be active and must be in the current port. */ destPort = TkMacOSXGetDrawablePort(Tk_WindowId(scrollPtr->tkwin)); @@ -520,18 +517,18 @@ TkpScrollbarPosition( QDSwapPort(savePort, NULL); } switch (part) { - case kAppearancePartUpButton: - return TOP_ARROW; - case kAppearancePartPageUpArea: - return TOP_GAP; - case kAppearancePartIndicator: - return SLIDER; - case kAppearancePartPageDownArea: - return BOTTOM_GAP; - case kAppearancePartDownButton: - return BOTTOM_ARROW; - default: - return OUTSIDE; + case kAppearancePartUpButton: + return TOP_ARROW; + case kAppearancePartPageUpArea: + return TOP_GAP; + case kAppearancePartIndicator: + return SLIDER; + case kAppearancePartPageDownArea: + return BOTTOM_GAP; + case kAppearancePartDownButton: + return BOTTOM_ARROW; + default: + return OUTSIDE; } } @@ -541,12 +538,11 @@ TkpScrollbarPosition( * ThumbActionProc -- * * Callback procedure used by the Macintosh toolbox call - * HandleControlClick. This call is used to track the - * thumb of the scrollbar. Unlike the - * ScrollbarActionProc function this function is called - * once and basically takes over tracking the scrollbar - * from the control. This is done to avoid conflicts with - * what the control plans to draw. + * HandleControlClick. This call is used to track the thumb of the + * scrollbar. Unlike the ScrollbarActionProc function this function is + * called once and basically takes over tracking the scrollbar from the + * control. This is done to avoid conflicts with what the control plans + * to draw. * * Results: * None. @@ -560,8 +556,8 @@ TkpScrollbarPosition( static pascal void ThumbActionProc(ControlRef theControl, ControlPartCode partCode) { - TkScrollbar *scrollPtr = (TkScrollbar *)(intptr_t)GetControlReference( - theControl); + TkScrollbar *scrollPtr = (TkScrollbar *)(intptr_t) + GetControlReference(theControl); MacScrollbar *macScrollPtr = (MacScrollbar *) scrollPtr; Tcl_DString cmdString; int origValue, variant; @@ -599,12 +595,11 @@ ThumbActionProc(ControlRef theControl, ControlPartCode partCode) /* * Track the mouse while the button is held down. If the mouse is moved, * we calculate the value that should be passed to the "command" part of - * the scrollbar. Since the mouse may move a distance too small to - * cause a change to the first fraction, each calculation must be done - * versus what the first fraction was when the mouse button was - * initially pressed. Otherwise, moving the mouse too slowly will - * cause the calculated fraction delta to be zero and the scrollbar - * won't respond. + * the scrollbar. Since the mouse may move a distance too small to cause a + * change to the first fraction, each calculation must be done versus what + * the first fraction was when the mouse button was initially pressed. + * Otherwise, moving the mouse too slowly will cause the calculated + * fraction delta to be zero and the scrollbar won't respond. */ oldFirstFraction = scrollPtr->firstFraction; @@ -616,17 +611,16 @@ ThumbActionProc(ControlRef theControl, ControlPartCode partCode) kEventDurationForever, ¤tPoint, NULL, &trackingResult); if ((err == noErr) && ((trackingResult == kMouseTrackingMouseDragged) || (trackingResult == kMouseTrackingMouseMoved))) { - /* - * Calculate where the scrollbar should move to, based on - * where the mouse button was pressed and where the scrollbar - * initially was at that time. Note that PtInRect() will - * return false if currentPoint or trackRect are not in - * is not in current graphics port, which may happen if any - * of the waiting idle events change the port (e.g. with - * SetPort()) but fail to restore it before returning and the - * scrollbar will lock in place. + * Calculate where the scrollbar should move to, based on where the + * mouse button was pressed and where the scrollbar initially was + * at that time. Note that PtInRect() will return false if + * currentPoint or trackRect are not in is not in current graphics + * port, which may happen if any of the waiting idle events change + * the port (e.g. with SetPort()) but fail to restore it before + * returning and the scrollbar will lock in place. */ + newFirstFraction = oldFirstFraction; if (PtInRect(currentPoint, &trackRect)) { short pixDiff; @@ -645,23 +639,23 @@ ThumbActionProc(ControlRef theControl, ControlPartCode partCode) } /* - * Move the scrollbar thumb to the new first fraction given - * its position when initially pressed and how far the mouse - * has moved. Process waiting idle tasks afterward to allow - * for the display to update. + * Move the scrollbar thumb to the new first fraction given its + * position when initially pressed and how far the mouse has + * moved. Process waiting idle tasks afterward to allow 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); + scrollPtr->commandSize); Tcl_DStringAppendElement(&cmdString, "moveto"); 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); TkMacOSXRunTclEventLoop(); } } while ((err == noErr) && trackingResult != kMouseTrackingMouseReleased); @@ -676,8 +670,8 @@ ThumbActionProc(ControlRef theControl, ControlPartCode partCode) * ScrollbarActionProc -- * * Callback procedure used by the Macintosh toolbox call - * HandleControlClick. This call will update the display - * while the scrollbar is being manipulated by the user. + * HandleControlClick. This call will update the display while the + * scrollbar is being manipulated by the user. * * Results: * None. @@ -693,8 +687,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; @@ -717,16 +711,15 @@ ScrollbarActionProc( } else if (partCode == kAppearancePartIndicator) { char valueString[TCL_DOUBLE_SPACE]; - sprintf(valueString, "%g", - (GetControl32BitValue(macScrollPtr->sbHandle) - - MIN_SCROLLBAR_VALUE) / SCROLLBAR_SCALING_VALUE); + Tcl_PrintDouble(NULL, (GetControl32BitValue(macScrollPtr->sbHandle) - + 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(); } @@ -736,8 +729,8 @@ ScrollbarActionProc( * * ScrollbarBindProc -- * - * This procedure is invoked when the default <ButtonPress> - * binding on the Scrollbar bind tag fires. + * This procedure is invoked when the default <ButtonPress> binding on + * the Scrollbar bind tag fires. * * Results: * None. @@ -756,11 +749,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 +765,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 +781,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 +792,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,25 +813,28 @@ 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(); } } else if (part != 0) { /* * Case 3: in any other part of the scrollbar. We call - * HandleControlClick with the scrollActionProc which will do - * most all the work. + * 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 +862,7 @@ ScrollbarBindProc( macScrollPtr->sbHandle = NULL; } macScrollPtr->macFlags &= ~IN_MODAL_LOOP; - Tcl_Release((ClientData)scrollPtr); + Tcl_Release(scrollPtr); return TCL_OK; } @@ -872,15 +872,15 @@ ScrollbarBindProc( * * ScrollbarEventProc -- * - * This procedure is invoked by the Tk dispatcher for various - * events on scrollbars. + * This procedure is invoked by the Tk dispatcher for various events on + * scrollbars. * * Results: * None. * * Side effects: - * When the window gets deleted, internal structures get - * cleaned up. When it gets exposed, it is redisplayed. + * When the window gets deleted, internal structures get cleaned up. When + * it gets exposed, it is redisplayed. * *-------------------------------------------------------------- */ @@ -911,8 +911,8 @@ ScrollbarEventProc( * * UpdateControlValues -- * - * This procedure updates the Macintosh scrollbar control - * to display the values defined by the Tk scrollbar. + * This procedure updates the Macintosh scrollbar control to display the + * values defined by the Tk scrollbar. * * Results: * None. @@ -929,7 +929,7 @@ UpdateControlValues( { TkScrollbar *scrollPtr = (TkScrollbar *) macScrollPtr; Tk_Window tkwin = scrollPtr->tkwin; - MacDrawable * macDraw = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin); + MacDrawable *macDraw = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin); double dViewSize; Rect contrlRect, portRect; int variant, active; @@ -940,13 +940,14 @@ UpdateControlValues( contrlRect.right = macDraw->xOff + Tk_Width(tkwin) - scrollPtr->inset; contrlRect.bottom = macDraw->yOff + Tk_Height(tkwin) - scrollPtr->inset; - GetPortBounds (GetWindowPort(GetControlOwner(macScrollPtr->sbHandle)), + GetPortBounds(GetWindowPort(GetControlOwner(macScrollPtr->sbHandle)), &portRect); /* - * If the scrollbar is flush against the bottom right hand corner then - * we leave space to draw the grow region for the window. + * If the scrollbar is flush against the bottom right hand corner then we + * leave space to draw the grow region for the window. */ + if (portRect.bottom == contrlRect.bottom && portRect.right == contrlRect.right) { TkMacOSXSetScrollbarGrow((TkWindow *) tkwin, true); @@ -955,16 +956,16 @@ UpdateControlValues( int growSize; switch (TkMacOSXWindowClass(macDraw->toplevel->winPtr)) { - case kFloatingWindowClass: - case kUtilityWindowClass: - growSize = metrics[1].width - 1; - break; - case kDocumentWindowClass: - case kMovableAlertWindowClass: - case kMovableModalWindowClass: - default: - growSize = metrics[0].width - 1; - break; + case kFloatingWindowClass: + case kUtilityWindowClass: + growSize = metrics[1].width - 1; + break; + case kDocumentWindowClass: + case kMovableAlertWindowClass: + case kMovableModalWindowClass: + default: + growSize = metrics[0].width - 1; + break; } if (scrollPtr->vertical) { contrlRect.bottom -= growSize; @@ -1000,23 +1001,21 @@ UpdateControlValues( } /* - * Ensure we set scrollbar control bounds only once all size - * adjustments have been computed. + * Ensure we set scrollbar control bounds only once all size adjustments + * have been computed. */ SetControlBounds(macScrollPtr->sbHandle, &contrlRect); /* - * Given the Tk parameters for the fractions of the start and - * end of the thumb, the following calculation determines the - * location for the Macintosh thumb. - * The Aqua scroll control works as follows. - * The scrollbar's value is the position of the left (or top) side of - * the view area in the content area being scrolled. - * The maximum value of the control is therefore the dimension of - * the content area less the size of the view area. - * Since these values are all integers, and Tk gives the thumb position - * as fractions, we have introduced a scaling factor. + * Given the Tk parameters for the fractions of the start and end of the + * thumb, the following calculation determines the location for the + * Macintosh thumb. The Aqua scroll control works as follows. The + * scrollbar's value is the position of the left (or top) side of the view + * area in the content area being scrolled. The maximum value of the + * control is therefore the dimension of the content area less the size of + * the view area. Since these values are all integers, and Tk gives the + * thumb position as fractions, we have introduced a scaling factor. */ dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction) @@ -1043,3 +1042,11 @@ UpdateControlValues( } SetControlVisibility(macScrollPtr->sbHandle, true, false); } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/win/tkWinScrlbr.c b/win/tkWinScrlbr.c index a6f19bc..0060a9f 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.16 2008/10/03 13:13:31 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); } |