diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-05-19 17:20:46 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-05-19 17:20:46 (GMT) |
commit | ab2d4c37f1979a374d4dd394421dd2e2458684cd (patch) | |
tree | 1d48b2cc2c9c3650506477e5fdd3b971ccc8eacf /generic | |
parent | 6761b5b08c0051307ff12736329a3056d36df987 (diff) | |
parent | 36200326cd9b185dd6af14f0b7fc9b1e74873d99 (diff) | |
download | tk-ab2d4c37f1979a374d4dd394421dd2e2458684cd.zip tk-ab2d4c37f1979a374d4dd394421dd2e2458684cd.tar.gz tk-ab2d4c37f1979a374d4dd394421dd2e2458684cd.tar.bz2 |
ttk state implementation improvements. This gives 32 possible flags in stead of only 16
Diffstat (limited to 'generic')
-rw-r--r-- | generic/ttk/ttkState.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/generic/ttk/ttkState.c b/generic/ttk/ttkState.c index 595a3a6..be15fdb 100644 --- a/generic/ttk/ttkState.c +++ b/generic/ttk/ttkState.c @@ -9,28 +9,29 @@ #include "ttkTheme.h" /* - * Table of state names. Must be kept in sync with TTK_STATE_* - * #defines in ttkTheme.h. + * Table of state names. */ -static const char *const stateNames[] = -{ - "active", /* Mouse cursor is over widget or element */ - "disabled", /* Widget is disabled */ - "focus", /* Widget has keyboard focus */ - "pressed", /* Pressed or "armed" */ - "selected", /* "on", "true", "current", etc. */ - "background", /* Top-level window lost focus (Mac,Win "inactive") */ - "alternate", /* Widget-specific alternate display style */ - "invalid", /* Bad value */ - "readonly", /* Editing/modification disabled */ - "hover", /* Mouse cursor is over widget */ - "user6", /* User-definable state */ - "user5", /* User-definable state */ - "user4", /* User-definable state */ - "user3", /* User-definable state */ - "user2", /* User-definable state */ - "user1", /* User-definable state */ - NULL +static const struct { + char name[12]; + int value; +} stateNames[] = { + {"active", TTK_STATE_ACTIVE}, /* Mouse cursor is over widget or element */ + {"alternate", TTK_STATE_ALTERNATE}, /* Widget-specific alternate display style */ + {"background", TTK_STATE_BACKGROUND}, /* Top-level window lost focus (Mac,Win "inactive") */ + {"disabled", TTK_STATE_DISABLED}, /* Widget is disabled */ + {"focus", TTK_STATE_FOCUS}, /* Widget has keyboard focus */ + {"hover", TTK_STATE_HOVER}, /* Mouse cursor is over widget */ + {"invalid", TTK_STATE_INVALID}, /* Bad value */ + {"pressed", TTK_STATE_PRESSED}, /* Pressed or "armed" */ + {"readonly", TTK_STATE_READONLY}, /* Editing/modification disabled */ + {"selected", TTK_STATE_SELECTED}, /* "on", "true", "current", etc. */ + {"user1", TTK_STATE_USER1}, /* User-definable state */ + {"user2", TTK_STATE_USER2}, /* User-definable state */ + {"user3", TTK_STATE_USER3}, /* User-definable state */ + {"user4", TTK_STATE_USER4}, /* User-definable state */ + {"user5", TTK_STATE_USER5}, /* User-definable state */ + {"user6", TTK_STATE_USER6}, /* User-definable state */ + {"", 0} }; /*------------------------------------------------------------------------ @@ -39,14 +40,12 @@ static const char *const stateNames[] = * The string representation consists of a list of state names, * each optionally prefixed by an exclamation point (!). * - * The internal representation uses the upper half of the longValue + * The internal representation uses the upper half of the wideValue * to store the on bits and the lower half to store the off bits. - * If we ever get more than 16 states, this will need to be reconsidered... + * If we ever get more than 32 states, this will need to be reconsidered... */ static int StateSpecSetFromAny(Tcl_Interp *interp, Tcl_Obj *obj); -/* static void StateSpecFreeIntRep(Tcl_Obj *); */ -#define StateSpecFreeIntRep 0 /* not needed */ static void StateSpecDupIntRep(Tcl_Obj *, Tcl_Obj *); static void StateSpecUpdateString(Tcl_Obj *); @@ -54,7 +53,7 @@ static const TkObjType StateSpecObjType = { {"StateSpec", - StateSpecFreeIntRep, + 0, StateSpecDupIntRep, StateSpecUpdateString, StateSpecSetFromAny, @@ -64,7 +63,7 @@ TkObjType StateSpecObjType = static void StateSpecDupIntRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr) { - copyPtr->internalRep.longValue = srcPtr->internalRep.longValue; + copyPtr->internalRep.wideValue = srcPtr->internalRep.wideValue; copyPtr->typePtr = &StateSpecObjType.objType; } @@ -90,12 +89,12 @@ static int StateSpecSetFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr) on = 1; } - for (j = 0; stateNames[j] != 0; ++j) { - if (strcmp(stateName, stateNames[j]) == 0) + for (j = 0; stateNames[j].value; ++j) { + if (strcmp(stateName, stateNames[j].name) == 0) break; } - if (stateNames[j] == 0) { + if (stateNames[j].value == 0) { if (interp) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Invalid state name %s", stateName)); @@ -105,9 +104,9 @@ static int StateSpecSetFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr) } if (on) { - onbits |= (1<<j); + onbits |= stateNames[j].value; } else { - offbits |= (1<<j); + offbits |= stateNames[j].value; } } @@ -118,15 +117,15 @@ static int StateSpecSetFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr) } objPtr->typePtr = &StateSpecObjType.objType; - objPtr->internalRep.longValue = (onbits << 16) | offbits; + objPtr->internalRep.wideValue = ((Tcl_WideInt)onbits << 32) | offbits; return TCL_OK; } static void StateSpecUpdateString(Tcl_Obj *objPtr) { - unsigned int onbits = (objPtr->internalRep.longValue & 0xFFFF0000) >> 16; - unsigned int offbits = objPtr->internalRep.longValue & 0x0000FFFF; + unsigned int onbits = objPtr->internalRep.wideValue >> 32; + unsigned int offbits = objPtr->internalRep.wideValue & 0xFFFFFFFFLL; unsigned int mask = onbits | offbits; Tcl_DString result; int i; @@ -134,11 +133,12 @@ static void StateSpecUpdateString(Tcl_Obj *objPtr) Tcl_DStringInit(&result); - for (i=0; stateNames[i] != NULL; ++i) { - if (mask & (1<<i)) { - if (offbits & (1<<i)) + for (i=0; stateNames[i].value; ++i) { + if (mask & stateNames[i].value) { + if (offbits & stateNames[i].value) { Tcl_DStringAppend(&result, "!", 1); - Tcl_DStringAppend(&result, stateNames[i], TCL_INDEX_NONE); + } + Tcl_DStringAppend(&result, stateNames[i].name, TCL_INDEX_NONE); Tcl_DStringAppend(&result, " ", 1); } } @@ -166,7 +166,7 @@ Tcl_Obj *Ttk_NewStateSpecObj(unsigned int onbits, unsigned int offbits) Tcl_InvalidateStringRep(objPtr); objPtr->typePtr = &StateSpecObjType.objType; - objPtr->internalRep.longValue = (onbits << 16) | offbits; + objPtr->internalRep.wideValue = ((Tcl_WideInt)onbits << 32) | offbits; return objPtr; } @@ -182,8 +182,8 @@ int Ttk_GetStateSpecFromObj( return status; } - spec->onbits = (objPtr->internalRep.longValue & 0xFFFF0000) >> 16; - spec->offbits = objPtr->internalRep.longValue & 0x0000FFFF; + spec->onbits = objPtr->internalRep.wideValue >> 32; + spec->offbits = objPtr->internalRep.wideValue & 0xFFFFFFFFLL; return TCL_OK; } |