diff options
Diffstat (limited to 'generic/ttk/ttkEntry.c')
-rw-r--r-- | generic/ttk/ttkEntry.c | 179 |
1 files changed, 95 insertions, 84 deletions
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index f7ee557..025a0f6 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -143,12 +143,12 @@ typedef struct { /* * Default option values: */ -#define DEF_SELECT_BG "#000000" -#define DEF_SELECT_FG "#ffffff" -#define DEF_INSERT_BG "black" -#define DEF_ENTRY_WIDTH "20" -#define DEF_ENTRY_FONT "TkTextFont" -#define DEF_LIST_HEIGHT "10" +#define DEF_SELECT_BG "#000000" +#define DEF_SELECT_FG "#FFFFFF" +#define DEF_INSERT_BG "black" +#define DEF_ENTRY_WIDTH "20" +#define DEF_ENTRY_FONT "TkTextFont" +#define DEF_LIST_HEIGHT "10" static Tk_OptionSpec EntryOptionSpecs[] = { {TK_OPTION_BOOLEAN, "-exportselection", "exportSelection", @@ -174,7 +174,7 @@ static Tk_OptionSpec EntryOptionSpecs[] = { TK_OPTION_NULL_OK,0,TEXTVAR_CHANGED}, {TK_OPTION_STRING_TABLE, "-validate", "validate", "Validate", "none", -1, Tk_Offset(Entry, entry.validate), - 0, (ClientData) validateStrings, 0}, + 0, (void *) validateStrings, 0}, {TK_OPTION_STRING, "-validatecommand", "validateCommand", "ValidateCommand", NULL, -1, Tk_Offset(Entry, entry.validateCmd), TK_OPTION_NULL_OK, 0, 0}, @@ -283,7 +283,7 @@ static char *EntryDisplayString(const char *showChar, int numChars) TkUtfToUniChar(showChar, &ch); size = TkUniCharToUtf(ch, buf); - p = displayString = ckalloc(numChars * size + 1); + p = displayString = (char *)ckalloc(numChars * size + 1); while (numChars--) { memcpy(p, buf, size); @@ -328,7 +328,7 @@ static int EntryFetchSelection( ClientData clientData, int offset, char *buffer, int maxBytes) { - Entry *entryPtr = (Entry *) clientData; + Entry *entryPtr = (Entry *)clientData; int byteCount; const char *string; const char *selStart, *selEnd; @@ -361,7 +361,7 @@ EntryFetchSelection( */ static void EntryLostSelection(ClientData clientData) { - Entry *entryPtr = (Entry *) clientData; + Entry *entryPtr = (Entry *)clientData; entryPtr->core.flags &= ~GOT_SELECTION; entryPtr->entry.selectFirst = entryPtr->entry.selectLast = -1; TtkRedisplayWidget(&entryPtr->core); @@ -377,7 +377,7 @@ static void EntryOwnSelection(Entry *entryPtr) && (!Tcl_IsSafe(entryPtr->core.interp)) && !(entryPtr->core.flags & GOT_SELECTION)) { Tk_OwnSelection(entryPtr->core.tkwin, XA_PRIMARY, EntryLostSelection, - (ClientData) entryPtr); + entryPtr); entryPtr->core.flags |= GOT_SELECTION; } } @@ -393,8 +393,8 @@ static void EntryOwnSelection(Entry *entryPtr) static void ExpandPercents( Entry *entryPtr, /* Entry that needs validation. */ - const char *template, /* Script template */ - const char *new, /* Potential new value of entry string */ + const char *templ, /* Script template */ + const char *newValue, /* Potential new value of entry string */ int index, /* index of insert/delete */ int count, /* #changed characters */ VREASON reason, /* Reason for change */ @@ -407,28 +407,28 @@ ExpandPercents( int ch; char numStorage[2*TCL_INTEGER_SPACE]; - while (*template) { + while (*templ) { /* Find everything up to the next % character and append it * to the result string. */ - string = Tcl_UtfFindFirst(template, '%'); + string = Tcl_UtfFindFirst(templ, '%'); if (string == NULL) { /* No more %-sequences to expand. * Copy the rest of the template. */ - Tcl_DStringAppend(dsPtr, template, -1); + Tcl_DStringAppend(dsPtr, templ, -1); return; } - if (string != template) { - Tcl_DStringAppend(dsPtr, template, string - template); - template = string; + if (string != templ) { + Tcl_DStringAppend(dsPtr, templ, string - templ); + templ = string; } /* There's a percent sequence here. Process it. */ - ++template; /* skip over % */ - if (*template != '\0') { - template += TkUtfToUniChar(template, &ch); + ++templ; /* skip over % */ + if (*templ != '\0') { + templ += TkUtfToUniChar(templ, &ch); } else { ch = '%'; } @@ -451,14 +451,14 @@ ExpandPercents( string = numStorage; break; case 'P': /* 'Peeked' new value of the string */ - string = new; + string = newValue; break; case 's': /* Current string value */ string = entryPtr->entry.string; break; case 'S': /* string to be inserted/deleted, if any */ if (reason == VALIDATE_INSERT) { - string = TkUtfAtIndex(new, index); + string = TkUtfAtIndex(newValue, index); stringLength = TkUtfAtIndex(string, count) - string; } else if (reason == VALIDATE_DELETE) { string = TkUtfAtIndex(entryPtr->entry.string, index); @@ -502,9 +502,9 @@ ExpandPercents( static int RunValidationScript( Tcl_Interp *interp, /* Interpreter to use */ Entry *entryPtr, /* Entry being validated */ - const char *template, /* Script template */ + const char *templ, /* Script template */ const char *optionName, /* "-validatecommand", "-invalidcommand" */ - const char *new, /* Potential new value of entry string */ + const char *newValue, /* Potential new value of entry string */ int index, /* index of insert/delete */ int count, /* #changed characters */ VREASON reason) /* Reason for change */ @@ -513,7 +513,7 @@ static int RunValidationScript( int code; Tcl_DStringInit(&script); - ExpandPercents(entryPtr, template, new, index, count, reason, &script); + ExpandPercents(entryPtr, templ, newValue, index, count, reason, &script); code = Tcl_EvalEx(interp, Tcl_DStringValue(&script), Tcl_DStringLength(&script), TCL_EVAL_GLOBAL); @@ -574,9 +574,9 @@ EntryValidateChange( VMODE vmode = entryPtr->entry.validate; int code, change_ok; - if ( (entryPtr->entry.validateCmd == NULL) + if ((entryPtr->entry.validateCmd == NULL) || (entryPtr->core.flags & VALIDATING) - || !EntryNeedsValidation(vmode, reason) ) + || !EntryNeedsValidation(vmode, reason)) { return TCL_OK; } @@ -630,7 +630,10 @@ done: * Returns: * TCL_OK if valid, TCL_BREAK if invalid, TCL_ERROR on error. */ -static int EntryRevalidate(Tcl_Interp *interp, Entry *entryPtr, VREASON reason) +static int EntryRevalidate( + TCL_UNUSED(Tcl_Interp *), + Entry *entryPtr, + VREASON reason) { int code = EntryValidateChange( entryPtr, entryPtr->entry.string, -1,0, reason); @@ -725,7 +728,7 @@ EntryStoreValue(Entry *entryPtr, const char *value) /* Store new value: */ - entryPtr->entry.string = ckalloc(numBytes + 1); + entryPtr->entry.string = (char *)ckalloc(numBytes + 1); strcpy(entryPtr->entry.string, value); entryPtr->entry.numBytes = numBytes; entryPtr->entry.numChars = numChars; @@ -782,7 +785,7 @@ static int EntrySetValue(Entry *entryPtr, const char *value) */ static void EntryTextVariableTrace(void *recordPtr, const char *value) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (WidgetDestroyed(&entryPtr->core)) { return; @@ -816,29 +819,29 @@ InsertChars( size_t byteCount = strlen(value); int charsAdded = Tcl_NumUtfChars(value, byteCount); size_t newByteCount = entryPtr->entry.numBytes + byteCount + 1; - char *new; + char *newBytes; int code; if (byteCount == 0) { return TCL_OK; } - new = ckalloc(newByteCount); - memcpy(new, string, byteIndex); - strcpy(new + byteIndex, value); - strcpy(new + byteIndex + byteCount, string + byteIndex); + newBytes = (char *)ckalloc(newByteCount); + memcpy(newBytes, string, byteIndex); + strcpy(newBytes + byteIndex, value); + strcpy(newBytes + byteIndex + byteCount, string + byteIndex); code = EntryValidateChange( - entryPtr, new, index, charsAdded, VALIDATE_INSERT); + entryPtr, newBytes, index, charsAdded, VALIDATE_INSERT); if (code == TCL_OK) { AdjustIndices(entryPtr, index, charsAdded); - code = EntrySetValue(entryPtr, new); + code = EntrySetValue(entryPtr, newBytes); } else if (code == TCL_BREAK) { code = TCL_OK; } - ckfree(new); + ckfree(newBytes); return code; } @@ -853,13 +856,13 @@ DeleteChars( { char *string = entryPtr->entry.string; size_t byteIndex, byteCount, newByteCount; - char *new; + char *newBytes; int code; if (index < 0) { index = 0; } - if (count > entryPtr->entry.numChars - index) { + if (count + index > entryPtr->entry.numChars) { count = entryPtr->entry.numChars - index; } if (count <= 0) { @@ -870,20 +873,20 @@ DeleteChars( byteCount = TkUtfAtIndex(string+byteIndex, count) - (string+byteIndex); newByteCount = entryPtr->entry.numBytes + 1 - byteCount; - new = ckalloc(newByteCount); - memcpy(new, string, byteIndex); - strcpy(new + byteIndex, string + byteIndex + byteCount); + newBytes = (char *)ckalloc(newByteCount); + memcpy(newBytes, string, byteIndex); + strcpy(newBytes + byteIndex, string + byteIndex + byteCount); code = EntryValidateChange( - entryPtr, new, index, count, VALIDATE_DELETE); + entryPtr, newBytes, index, count, VALIDATE_DELETE); if (code == TCL_OK) { AdjustIndices(entryPtr, index, -count); - code = EntrySetValue(entryPtr, new); + code = EntrySetValue(entryPtr, newBytes); } else if (code == TCL_BREAK) { code = TCL_OK; } - ckfree(new); + ckfree(newBytes); return code; } @@ -900,7 +903,7 @@ DeleteChars( static void EntryEventProc(ClientData clientData, XEvent *eventPtr) { - Entry *entryPtr = (Entry *) clientData; + Entry *entryPtr = (Entry *)clientData; Tcl_Preserve(clientData); switch (eventPtr->type) { @@ -923,17 +926,19 @@ EntryEventProc(ClientData clientData, XEvent *eventPtr) */ static void -EntryInitialize(Tcl_Interp *interp, void *recordPtr) +EntryInitialize( + TCL_UNUSED(Tcl_Interp *), + void *recordPtr) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; Tk_CreateEventHandler( entryPtr->core.tkwin, EntryEventMask, EntryEventProc, entryPtr); Tk_CreateSelHandler(entryPtr->core.tkwin, XA_PRIMARY, XA_STRING, - EntryFetchSelection, (ClientData) entryPtr, XA_STRING); + EntryFetchSelection, entryPtr, XA_STRING); TtkBlinkCursor(&entryPtr->core); - entryPtr->entry.string = ckalloc(1); + entryPtr->entry.string = (char *)ckalloc(1); *entryPtr->entry.string = '\0'; entryPtr->entry.displayString = entryPtr->entry.string; entryPtr->entry.textVariableTrace = 0; @@ -952,7 +957,7 @@ EntryInitialize(Tcl_Interp *interp, void *recordPtr) static void EntryCleanup(void *recordPtr) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (entryPtr->entry.textVariableTrace) Ttk_UntraceVariable(entryPtr->entry.textVariableTrace); @@ -974,7 +979,7 @@ EntryCleanup(void *recordPtr) */ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; Tcl_Obj *textVarName = entryPtr->entry.textVariableObj; Ttk_TraceHandle *vt = 0; @@ -1038,9 +1043,12 @@ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask) /* EntryPostConfigure -- * Post-configuration hook for entry widgets. */ -static int EntryPostConfigure(Tcl_Interp *interp, void *recordPtr, int mask) +static int EntryPostConfigure( + TCL_UNUSED(Tcl_Interp *), + void *recordPtr, + int mask) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int status = TCL_OK; if ((mask & TEXTVAR_CHANGED) && entryPtr->entry.textVariableTrace != NULL) { @@ -1079,7 +1087,7 @@ EntryCharPosition(Entry *entryPtr, int index) static void EntryDoLayout(void *recordPtr) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; WidgetCore *corePtr = &entryPtr->core; Tk_TextLayout textLayout = entryPtr->entry.textLayout; int leftIndex = entryPtr->entry.xscroll.first; @@ -1166,7 +1174,7 @@ static GC EntryGetGC(Entry *entryPtr, Tcl_Obj *colorObj, TkRegion clip) */ static void EntryDisplay(void *clientData, Drawable d) { - Entry *entryPtr = clientData; + Entry *entryPtr = (Entry *)clientData; Tk_Window tkwin = entryPtr->core.tkwin; int leftIndex = entryPtr->entry.xscroll.first, rightIndex = entryPtr->entry.xscroll.last + 1, @@ -1428,7 +1436,7 @@ static int EntryBBoxCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; Ttk_Box b; int index; @@ -1458,7 +1466,7 @@ static int EntryDeleteCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int first, last; if ((objc < 3) || (objc > 4)) { @@ -1487,7 +1495,7 @@ static int EntryGetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, NULL); return TCL_ERROR; @@ -1503,7 +1511,7 @@ static int EntryICursorCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "pos"); return TCL_ERROR; @@ -1523,7 +1531,7 @@ static int EntryIndexCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int index; if (objc != 3) { @@ -1545,7 +1553,7 @@ static int EntryInsertCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int index; if (objc != 4) { @@ -1567,7 +1575,7 @@ EntryInsertCommand( static int EntrySelectionClearCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); @@ -1584,7 +1592,7 @@ static int EntrySelectionClearCommand( static int EntrySelectionPresentCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); return TCL_ERROR; @@ -1600,13 +1608,13 @@ static int EntrySelectionPresentCommand( static int EntrySelectionRangeCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int start, end; if (objc != 5) { Tcl_WrongNumArgs(interp, 3, objv, "start end"); return TCL_ERROR; } - if ( EntryIndex(interp, entryPtr, objv[3], &start) != TCL_OK + if (EntryIndex(interp, entryPtr, objv[3], &start) != TCL_OK || EntryIndex(interp, entryPtr, objv[4], &end) != TCL_OK) { return TCL_ERROR; } @@ -1638,7 +1646,7 @@ static const Ttk_Ensemble EntrySelectionCommands[] = { static int EntrySetCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "value"); return TCL_ERROR; @@ -1654,7 +1662,7 @@ static int EntrySetCommand( static int EntryValidateCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; int code; if (objc != 2) { @@ -1676,7 +1684,7 @@ static int EntryValidateCommand( static int EntryXViewCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Entry *entryPtr = recordPtr; + Entry *entryPtr = (Entry *)recordPtr; if (objc == 3) { int newFirst; if (EntryIndex(interp, entryPtr, objv[2], &newFirst) != TCL_OK) { @@ -1743,7 +1751,7 @@ typedef struct { Tcl_Obj *postCommandObj; Tcl_Obj *valuesObj; Tcl_Obj *heightObj; - int currentIndex; + int currentIndex; } ComboboxPart; typedef struct { @@ -1771,7 +1779,7 @@ static Tk_OptionSpec ComboboxOptionSpecs[] = { static void ComboboxInitialize(Tcl_Interp *interp, void *recordPtr) { - Combobox *cb = recordPtr; + Combobox *cb = (Combobox *)recordPtr; cb->combobox.currentIndex = -1; TtkTrackElementState(&cb->core); @@ -1784,7 +1792,7 @@ ComboboxInitialize(Tcl_Interp *interp, void *recordPtr) static int ComboboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Combobox *cbPtr = recordPtr; + Combobox *cbPtr = (Combobox *)recordPtr; int unused; /* Make sure -values is a valid list: @@ -1804,13 +1812,13 @@ ComboboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask) static int ComboboxCurrentCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - Combobox *cbPtr = recordPtr; + Combobox *cbPtr = (Combobox *)recordPtr; int currentIndex = cbPtr->combobox.currentIndex; const char *currentValue = cbPtr->entry.string; int nValues; Tcl_Obj **values; - Tcl_ListObjGetElements(interp,cbPtr->combobox.valuesObj,&nValues,&values); + Tcl_ListObjGetElements(interp, cbPtr->combobox.valuesObj, &nValues, &values); if (objc == 2) { /* Check if currentIndex still valid: @@ -1861,7 +1869,6 @@ static int ComboboxCurrentCommand( Tcl_Panic("Unknown named index"); return TCL_ERROR; } - } else { /* @@ -1987,7 +1994,7 @@ static Tk_OptionSpec SpinboxOptionSpecs[] = { static void SpinboxInitialize(Tcl_Interp *interp, void *recordPtr) { - Spinbox *sb = recordPtr; + Spinbox *sb = (Spinbox *)recordPtr; TtkTrackElementState(&sb->core); EntryInitialize(interp, recordPtr); } @@ -1998,7 +2005,7 @@ SpinboxInitialize(Tcl_Interp *interp, void *recordPtr) static int SpinboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { - Spinbox *sb = recordPtr; + Spinbox *sb = (Spinbox *)recordPtr; int unused; /* Make sure -values is a valid list: @@ -2060,14 +2067,18 @@ static Ttk_ElementOptionSpec TextareaElementOptions[] = { Tk_Offset(TextareaElement,fontObj), DEF_ENTRY_FONT }, { "-width", TK_OPTION_INT, Tk_Offset(TextareaElement,widthObj), "20" }, - { NULL, 0, 0, NULL } + { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; static void TextareaElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) + TCL_UNUSED(void *), + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + TCL_UNUSED(Ttk_Padding *)) { - TextareaElement *textarea = elementRecord; + TextareaElement *textarea = (TextareaElement *)elementRecord; Tk_Font font = Tk_GetFontFromObj(tkwin, textarea->fontObj); int avgWidth = Tk_TextWidth(font, "0", 1); Tk_FontMetrics fm; |