Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | ttk state implementation improvements. This gives 32 possible flags in stead of only 16 |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | core-8-branch |
Files: | files | file ages | folders |
SHA3-256: |
7a3149d6a64f5ec0b49976a8fca195dd |
User & Date: | jan.nijtmans 2024-05-19 17:20:46 |
Original Comment: | ttk state implementation improvements. This gives 32 possible flags in stead of only 32 |
Context
2024-05-20
| ||
17:13 | Fix [527cb3cd5d]: Documentation of ttk states. user1/user2 are no longer misused for other (internal) purposes check-in: 602822d2 user: jan.nijtmans tags: core-8-branch | |
2024-05-19
| ||
17:24 | Merge 8.7 Closed-Leaf check-in: 71b559ec user: jan.nijtmans tags: bug-527cb3cd5d | |
17:20 | ttk state implementation improvements. This gives 32 possible flags in stead of only 16 check-in: 7a3149d6 user: jan.nijtmans tags: core-8-branch | |
17:09 | ttk state implementation improvements check-in: 95390ea2 user: jan.nijtmans tags: core-8-6-branch | |
2024-05-18
| ||
20:49 | Update changes.md check-in: f461f844 user: jan.nijtmans tags: core-8-branch | |
Changes
Changes to generic/ttk/ttkState.c.
1 2 3 4 5 6 7 8 9 10 11 | /* * Tk widget state utilities. * * Copyright © 2003 Joe English. Freely redistributable. * */ #include "tkInt.h" #include "ttkTheme.h" /* | | < | < > > > | > > | | | < < < | > | < > | | | | | | < > | | < < < > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | /* * Tk widget state utilities. * * Copyright © 2003 Joe English. Freely redistributable. * */ #include "tkInt.h" #include "ttkTheme.h" /* * Table of state names. */ 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} }; /*------------------------------------------------------------------------ * +++ StateSpec object type: * * 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 wideValue * to store the on bits and the lower half to store the off bits. * 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 StateSpecDupIntRep(Tcl_Obj *, Tcl_Obj *); static void StateSpecUpdateString(Tcl_Obj *); static const TkObjType StateSpecObjType = { {"StateSpec", 0, StateSpecDupIntRep, StateSpecUpdateString, StateSpecSetFromAny, TCL_OBJTYPE_V0}, 0 }; static void StateSpecDupIntRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr) { copyPtr->internalRep.wideValue = srcPtr->internalRep.wideValue; copyPtr->typePtr = &StateSpecObjType.objType; } static int StateSpecSetFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr) { int status; Tcl_Size i, objc; |
︙ | ︙ | |||
86 87 88 89 90 91 92 | if (*stateName == '!') { ++stateName; on = 0; } else { on = 1; } | | | | | | | | | | | | > | | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | if (*stateName == '!') { ++stateName; on = 0; } else { on = 1; } for (j = 0; stateNames[j].value; ++j) { if (strcmp(stateName, stateNames[j].name) == 0) break; } if (stateNames[j].value == 0) { if (interp) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Invalid state name %s", stateName)); Tcl_SetErrorCode(interp, "TTK", "VALUE", "STATE", NULL); } return TCL_ERROR; } if (on) { onbits |= stateNames[j].value; } else { offbits |= stateNames[j].value; } } /* Invalidate old intrep: */ if (objPtr->typePtr && objPtr->typePtr->freeIntRepProc) { objPtr->typePtr->freeIntRepProc(objPtr); } objPtr->typePtr = &StateSpecObjType.objType; objPtr->internalRep.wideValue = ((Tcl_WideInt)onbits << 32) | offbits; return TCL_OK; } static void StateSpecUpdateString(Tcl_Obj *objPtr) { unsigned int onbits = objPtr->internalRep.wideValue >> 32; unsigned int offbits = objPtr->internalRep.wideValue & 0xFFFFFFFFLL; unsigned int mask = onbits | offbits; Tcl_DString result; int i; int len; Tcl_DStringInit(&result); 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].name, TCL_INDEX_NONE); Tcl_DStringAppend(&result, " ", 1); } } len = Tcl_DStringLength(&result); if (len) { /* 'len' includes extra trailing ' ' */ |
︙ | ︙ | |||
162 163 164 165 166 167 168 | Tcl_Obj *Ttk_NewStateSpecObj(unsigned int onbits, unsigned int offbits) { Tcl_Obj *objPtr = Tcl_NewObj(); Tcl_InvalidateStringRep(objPtr); objPtr->typePtr = &StateSpecObjType.objType; | | | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | Tcl_Obj *Ttk_NewStateSpecObj(unsigned int onbits, unsigned int offbits) { Tcl_Obj *objPtr = Tcl_NewObj(); Tcl_InvalidateStringRep(objPtr); objPtr->typePtr = &StateSpecObjType.objType; objPtr->internalRep.wideValue = ((Tcl_WideInt)onbits << 32) | offbits; return objPtr; } int Ttk_GetStateSpecFromObj( Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_StateSpec *spec) { if (objPtr->typePtr != &StateSpecObjType.objType) { int status = StateSpecSetFromAny(interp, objPtr); if (status != TCL_OK) return status; } spec->onbits = objPtr->internalRep.wideValue >> 32; spec->offbits = objPtr->internalRep.wideValue & 0xFFFFFFFFLL; return TCL_OK; } /* * Tk_StateMapLookup -- * |
︙ | ︙ |