summaryrefslogtreecommitdiffstats
path: root/generic/ttk/ttkTheme.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/ttk/ttkTheme.c')
-rw-r--r--generic/ttk/ttkTheme.c408
1 files changed, 216 insertions, 192 deletions
diff --git a/generic/ttk/ttkTheme.c b/generic/ttk/ttkTheme.c
index 04dab19..c39d457 100644
--- a/generic/ttk/ttkTheme.c
+++ b/generic/ttk/ttkTheme.c
@@ -9,20 +9,16 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * $Id: ttkTheme.c,v 1.11.2.1 2009/03/25 09:10:04 dkf Exp $
+ * $Id: ttkTheme.c,v 1.11.2.2 2010/08/26 02:06:09 hobbs Exp $
*/
#include <stdlib.h>
#include <string.h>
#include <tk.h>
+#include <tkInt.h>
#include "ttkThemeInt.h"
-#ifdef NO_PRIVATE_HEADERS
-EXTERN CONST Tk_OptionSpec *TkGetOptionSpec (CONST char *name,
- Tk_OptionTable optionTable);
-#else
-#include <tkInt.h>
-#endif
+#define PKG_ASSOC_KEY "Ttk"
/*------------------------------------------------------------------------
* +++ Styles.
@@ -65,7 +61,7 @@ static void FreeStyle(Style *stylePtr)
entryPtr = Tcl_FirstHashEntry(&stylePtr->settingsTable, &search);
while (entryPtr != NULL) {
- Ttk_StateMap stateMap = (Ttk_StateMap)Tcl_GetHashValue(entryPtr);
+ Ttk_StateMap stateMap = Tcl_GetHashValue(entryPtr);
Tcl_DecrRefCount(stateMap);
entryPtr = Tcl_NextHashEntry(&search);
}
@@ -73,7 +69,7 @@ static void FreeStyle(Style *stylePtr)
entryPtr = Tcl_FirstHashEntry(&stylePtr->defaultsTable, &search);
while (entryPtr != NULL) {
- Tcl_Obj *defaultValue = (Ttk_StateMap)Tcl_GetHashValue(entryPtr);
+ Tcl_Obj *defaultValue = Tcl_GetHashValue(entryPtr);
Tcl_DecrRefCount(defaultValue);
entryPtr = Tcl_NextHashEntry(&search);
}
@@ -81,38 +77,39 @@ static void FreeStyle(Style *stylePtr)
Ttk_FreeLayoutTemplate(stylePtr->layoutTemplate);
- ckfree((char*)stylePtr);
+ ckfree((ClientData)stylePtr);
}
/*
- * LookupStateMap --
- * Look up dynamic resource settings in the in the specified style.
+ * Ttk_StyleMap --
+ * Look up state-specific option value from specified style.
*/
-
-static Ttk_StateMap LookupStateMap(Ttk_Style stylePtr, const char *optionName)
+Tcl_Obj *Ttk_StyleMap(Ttk_Style style, const char *optionName, Ttk_State state)
{
- while (stylePtr) {
+ while (style) {
Tcl_HashEntry *entryPtr =
- Tcl_FindHashEntry(&stylePtr->settingsTable, optionName);
- if (entryPtr)
- return (Ttk_StateMap)Tcl_GetHashValue(entryPtr);
- stylePtr = stylePtr->parentStyle;
+ Tcl_FindHashEntry(&style->settingsTable, optionName);
+ if (entryPtr) {
+ Ttk_StateMap stateMap = Tcl_GetHashValue(entryPtr);
+ return Ttk_StateMapLookup(NULL, stateMap, state);
+ }
+ style = style->parentStyle;
}
return 0;
}
/*
- * LookupDefault --
+ * Ttk_StyleDefault --
* Look up default resource setting the in the specified style.
*/
-static Tcl_Obj *LookupDefault(Ttk_Style stylePtr, const char *optionName)
+Tcl_Obj *Ttk_StyleDefault(Ttk_Style style, const char *optionName)
{
- while (stylePtr) {
+ while (style) {
Tcl_HashEntry *entryPtr =
- Tcl_FindHashEntry(&stylePtr->defaultsTable, optionName);
+ Tcl_FindHashEntry(&style->defaultsTable, optionName);
if (entryPtr)
- return (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
- stylePtr = stylePtr->parentStyle;
+ return Tcl_GetHashValue(entryPtr);
+ style= style->parentStyle;
}
return 0;
}
@@ -123,8 +120,7 @@ static Tcl_Obj *LookupDefault(Ttk_Style stylePtr, const char *optionName)
typedef const Tk_OptionSpec **OptionMap;
/* array of Tk_OptionSpecs mapping widget options to element options */
-typedef struct Ttk_ElementImpl_ /* Element implementation */
-{
+struct Ttk_ElementClass_ {
const char *name; /* Points to hash table key */
Ttk_ElementSpec *specPtr; /* Template provided during registration. */
void *clientData; /* Client data passed in at registration time */
@@ -132,7 +128,7 @@ typedef struct Ttk_ElementImpl_ /* Element implementation */
int nResources; /* #Element options */
Tcl_Obj **defaultValues; /* Array of option default values */
Tcl_HashTable optMapCache; /* Map: Tk_OptionTable * -> OptionMap */
-} ElementImpl;
+};
/* TTKGetOptionSpec --
* Look up a Tk_OptionSpec by name from a Tk_OptionTable,
@@ -183,14 +179,14 @@ static const Tk_OptionSpec *TTKGetOptionSpec(
* Construct the mapping from element options to widget options.
*/
static OptionMap
-BuildOptionMap(ElementImpl *elementImpl, Tk_OptionTable optionTable)
+BuildOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable)
{
OptionMap optionMap = (OptionMap)ckalloc(
- sizeof(const Tk_OptionSpec) * elementImpl->nResources + 1);
+ sizeof(const Tk_OptionSpec) * elementClass->nResources + 1);
int i;
- for (i = 0; i < elementImpl->nResources; ++i) {
- Ttk_ElementOptionSpec *e = elementImpl->specPtr->options+i;
+ for (i = 0; i < elementClass->nResources; ++i) {
+ Ttk_ElementOptionSpec *e = elementClass->specPtr->options+i;
optionMap[i] = TTKGetOptionSpec(e->optionName, optionTable, e->type);
}
@@ -202,71 +198,72 @@ BuildOptionMap(ElementImpl *elementImpl, Tk_OptionTable optionTable)
* for the specified element, creating it if necessary.
*/
static OptionMap
-GetOptionMap(ElementImpl *elementImpl, Tk_OptionTable optionTable)
+GetOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable)
{
OptionMap optionMap;
int isNew;
Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(
- &elementImpl->optMapCache, (ClientData)optionTable, &isNew);
+ &elementClass->optMapCache, (void*)optionTable, &isNew);
if (isNew) {
- optionMap = BuildOptionMap(elementImpl, optionTable);
+ optionMap = BuildOptionMap(elementClass, optionTable);
Tcl_SetHashValue(entryPtr, optionMap);
} else {
- optionMap = (OptionMap)(Tcl_GetHashValue(entryPtr));
+ optionMap = Tcl_GetHashValue(entryPtr);
}
return optionMap;
}
/*
- * NewElementImpl --
- * Allocate and initialize an element implementation record
+ * NewElementClass --
+ * Allocate and initialize an element class record
* from the specified element specification.
*/
-static ElementImpl *
-NewElementImpl(const char *name, Ttk_ElementSpec *specPtr,void *clientData)
+static Ttk_ElementClass *
+NewElementClass(const char *name, Ttk_ElementSpec *specPtr,void *clientData)
{
- ElementImpl *elementImpl = (ElementImpl*)ckalloc(sizeof(ElementImpl));
+ Ttk_ElementClass *elementClass =
+ (Ttk_ElementClass*)ckalloc(sizeof(Ttk_ElementClass));
int i;
- elementImpl->name = name;
- elementImpl->specPtr = specPtr;
- elementImpl->clientData = clientData;
- elementImpl->elementRecord = ckalloc(specPtr->elementSize);
+ elementClass->name = name;
+ elementClass->specPtr = specPtr;
+ elementClass->clientData = clientData;
+ elementClass->elementRecord = ckalloc(specPtr->elementSize);
/* Count #element resources:
*/
for (i = 0; specPtr->options[i].optionName != 0; ++i)
continue;
- elementImpl->nResources = i;
+ elementClass->nResources = i;
/* Initialize default values:
*/
- elementImpl->defaultValues = (Tcl_Obj**)
- ckalloc(elementImpl->nResources * sizeof(Tcl_Obj *) + 1);
- for (i=0; i < elementImpl->nResources; ++i) {
+ elementClass->defaultValues = (Tcl_Obj**)
+ ckalloc(elementClass->nResources * sizeof(Tcl_Obj *) + 1);
+ for (i=0; i < elementClass->nResources; ++i) {
const char *defaultValue = specPtr->options[i].defaultValue;
if (defaultValue) {
- elementImpl->defaultValues[i] = Tcl_NewStringObj(defaultValue,-1);
- Tcl_IncrRefCount(elementImpl->defaultValues[i]);
+ elementClass->defaultValues[i] = Tcl_NewStringObj(defaultValue,-1);
+ Tcl_IncrRefCount(elementClass->defaultValues[i]);
} else {
- elementImpl->defaultValues[i] = 0;
+ elementClass->defaultValues[i] = 0;
}
}
/* Initialize option map cache:
*/
- Tcl_InitHashTable(&elementImpl->optMapCache, TCL_ONE_WORD_KEYS);
+ Tcl_InitHashTable(&elementClass->optMapCache, TCL_ONE_WORD_KEYS);
- return elementImpl;
+ return elementClass;
}
/*
- * FreeElementImpl --
- * Release resources associated with an element implementation record.
+ * FreeElementClass --
+ * Release resources associated with an element class record.
*/
-static void FreeElementImpl(ElementImpl *elementImpl)
+static void FreeElementClass(Ttk_ElementClass *elementClass)
{
Tcl_HashSearch search;
Tcl_HashEntry *entryPtr;
@@ -275,28 +272,27 @@ static void FreeElementImpl(ElementImpl *elementImpl)
/*
* Free default values:
*/
- for (i = 0; i < elementImpl->nResources; ++i) {
- if (elementImpl->defaultValues[i]) {
- Tcl_DecrRefCount(elementImpl->defaultValues[i]);
+ for (i = 0; i < elementClass->nResources; ++i) {
+ if (elementClass->defaultValues[i]) {
+ Tcl_DecrRefCount(elementClass->defaultValues[i]);
}
}
- ckfree((ClientData)elementImpl->defaultValues);
+ ckfree((ClientData)elementClass->defaultValues);
/*
* Free option map cache:
*/
- entryPtr = Tcl_FirstHashEntry(&elementImpl->optMapCache, &search);
+ entryPtr = Tcl_FirstHashEntry(&elementClass->optMapCache, &search);
while (entryPtr != NULL) {
ckfree(Tcl_GetHashValue(entryPtr));
entryPtr = Tcl_NextHashEntry(&search);
}
- Tcl_DeleteHashTable(&elementImpl->optMapCache);
+ Tcl_DeleteHashTable(&elementClass->optMapCache);
- ckfree(elementImpl->elementRecord);
- ckfree((ClientData)elementImpl);
+ ckfree(elementClass->elementRecord);
+ ckfree((ClientData)elementClass);
}
-
/*------------------------------------------------------------------------
* +++ Themes.
*/
@@ -307,7 +303,7 @@ static int ThemeEnabled(Ttk_Theme theme, void *clientData) { return 1; }
typedef struct Ttk_Theme_
{
Ttk_Theme parentPtr; /* Parent theme. */
- Tcl_HashTable elementTable; /* Map element names to ElementImpls */
+ Tcl_HashTable elementTable; /* Map element names to class records */
Tcl_HashTable styleTable; /* Map style names to Styles */
Ttk_Style rootStyle; /* "." style, root of chain */
Ttk_ThemeEnabledProc *enabledProc; /* Function called by SetTheme */
@@ -333,10 +329,10 @@ static Theme *NewTheme(Ttk_ResourceCache cache, Ttk_Theme parent)
*/
entryPtr = Tcl_CreateHashEntry(&themePtr->styleTable, ".", &unused);
themePtr->rootStyle = NewStyle();
- themePtr->rootStyle->styleName =
+ themePtr->rootStyle->styleName =
Tcl_GetHashKey(&themePtr->styleTable, entryPtr);
themePtr->rootStyle->cache = themePtr->cache;
- Tcl_SetHashValue(entryPtr, (ClientData)themePtr->rootStyle);
+ Tcl_SetHashValue(entryPtr, themePtr->rootStyle);
return themePtr;
}
@@ -347,12 +343,12 @@ static void FreeTheme(Theme *themePtr)
Tcl_HashEntry *entryPtr;
/*
- * Free associated ElementImpl's
+ * Free element table:
*/
entryPtr = Tcl_FirstHashEntry(&themePtr->elementTable, &search);
while (entryPtr != NULL) {
- ElementImpl *elementImpl = (ElementImpl *)Tcl_GetHashValue(entryPtr);
- FreeElementImpl(elementImpl);
+ Ttk_ElementClass *elementClass = Tcl_GetHashValue(entryPtr);
+ FreeElementClass(elementClass);
entryPtr = Tcl_NextHashEntry(&search);
}
Tcl_DeleteHashTable(&themePtr->elementTable);
@@ -362,7 +358,7 @@ static void FreeTheme(Theme *themePtr)
*/
entryPtr = Tcl_FirstHashEntry(&themePtr->styleTable, &search);
while (entryPtr != NULL) {
- Style *stylePtr = (Style*)Tcl_GetHashValue(entryPtr);
+ Style *stylePtr = Tcl_GetHashValue(entryPtr);
FreeStyle(stylePtr);
entryPtr = Tcl_NextHashEntry(&search);
}
@@ -371,7 +367,7 @@ static void FreeTheme(Theme *themePtr)
/*
* Free theme record:
*/
- ckfree((char *)themePtr);
+ ckfree((ClientData)themePtr);
return;
}
@@ -415,10 +411,9 @@ static void ThemeChangedProc(ClientData); /* Forward */
*/
static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp)
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
Tcl_HashSearch search;
Tcl_HashEntry *entryPtr;
- Theme *themePtr;
Cleanup *cleanup;
/*
@@ -433,7 +428,7 @@ static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp)
*/
entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search);
while (entryPtr != NULL) {
- themePtr = (Theme *) Tcl_GetHashValue(entryPtr);
+ Theme *themePtr = Tcl_GetHashValue(entryPtr);
FreeTheme(themePtr);
entryPtr = Tcl_NextHashEntry(&search);
}
@@ -465,7 +460,7 @@ static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp)
cleanup = next;
}
- ckfree((char*)pkgPtr);
+ ckfree((ClientData)pkgPtr);
}
/*
@@ -475,7 +470,7 @@ static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp)
static StylePackageData *GetStylePackageData(Tcl_Interp *interp)
{
- return (StylePackageData*)Tcl_GetAssocData(interp, "StylePackage", NULL);
+ return Tcl_GetAssocData(interp, PKG_ASSOC_KEY, NULL);
}
/*
@@ -499,7 +494,7 @@ void Ttk_RegisterCleanup(
pkgPtr->cleanupList = cleanup;
}
-/* ThemeChangedProc --
+/* ThemeChangedProc --
* Notify all widgets that the theme has been changed.
* Scheduled as an idle callback; clientData is a StylePackageData *.
*
@@ -508,13 +503,13 @@ void Ttk_RegisterCleanup(
* which in turn recreates the layout.
*
* The Tk C API doesn't doesn't provide an easy way to traverse
- * the widget hierarchy, so this is done by evaluating a Tcl script.
+ * the widget hierarchy, so this is done by evaluating a Tcl script.
*/
static void ThemeChangedProc(ClientData clientData)
{
static char ThemeChangedScript[] = "ttk::ThemeChanged";
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
if (Tcl_GlobalEval(pkgPtr->interp, ThemeChangedScript) != TCL_OK) {
Tcl_BackgroundError(pkgPtr->interp);
@@ -567,12 +562,11 @@ Ttk_CreateTheme(
if (!parent) parent = pkgPtr->defaultTheme;
themePtr = NewTheme(pkgPtr->cache, parent);
- Tcl_SetHashValue(entryPtr, (ClientData) themePtr);
+ Tcl_SetHashValue(entryPtr, themePtr);
return themePtr;
}
-
/*
* Ttk_SetThemeEnabledProc --
* Sets a procedure that is used to check that this theme is available.
@@ -587,7 +581,7 @@ void Ttk_SetThemeEnabledProc(
/*
* LookupTheme --
- * Retrieve a registered theme by name. If not found,
+ * Retrieve a registered theme by name. If not found,
* returns NULL and leaves an error message in interp's result.
*/
@@ -605,7 +599,7 @@ static Ttk_Theme LookupTheme(
return NULL;
}
- return (Ttk_Theme)Tcl_GetHashValue(entryPtr);
+ return Tcl_GetHashValue(entryPtr);
}
/*
@@ -715,10 +709,10 @@ Ttk_Style Ttk_GetStyle(Ttk_Theme themePtr, const char *styleName)
stylePtr->styleName = Tcl_GetHashKey(&themePtr->styleTable, entryPtr);
stylePtr->cache = stylePtr->parentStyle->cache;
- Tcl_SetHashValue(entryPtr, (ClientData)stylePtr);
+ Tcl_SetHashValue(entryPtr, stylePtr);
return stylePtr;
}
- return (Style*)Tcl_GetHashValue(entryPtr);
+ return Tcl_GetHashValue(entryPtr);
}
/* FindLayoutTemplate --
@@ -749,12 +743,12 @@ const char *Ttk_StyleName(Ttk_Style stylePtr)
/*
* Ttk_GetElement --
- * Look up an element implementation by name in a given theme.
+ * Look up an element class by name in a given theme.
* If not found, try generic element names in this theme, then
* repeat the lookups in the parent theme.
* If not found, return the null element.
*/
-Ttk_ElementImpl Ttk_GetElement(Ttk_Theme themePtr, const char *elementName)
+Ttk_ElementClass *Ttk_GetElement(Ttk_Theme themePtr, const char *elementName)
{
Tcl_HashEntry *entryPtr;
const char *dot = elementName;
@@ -764,7 +758,7 @@ Ttk_ElementImpl Ttk_GetElement(Ttk_Theme themePtr, const char *elementName)
*/
entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, elementName);
if (entryPtr) {
- return (Ttk_ElementImpl)Tcl_GetHashValue(entryPtr);
+ return Tcl_GetHashValue(entryPtr);
}
/*
@@ -775,7 +769,7 @@ Ttk_ElementImpl Ttk_GetElement(Ttk_Theme themePtr, const char *elementName)
entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, dot);
}
if (entryPtr) {
- return (ElementImpl *)Tcl_GetHashValue(entryPtr);
+ return Tcl_GetHashValue(entryPtr);
}
/*
@@ -791,12 +785,12 @@ Ttk_ElementImpl Ttk_GetElement(Ttk_Theme themePtr, const char *elementName)
*/
entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, "");
/* ASSERT: entryPtr != 0 */
- return (Ttk_ElementImpl)Tcl_GetHashValue(entryPtr);
+ return Tcl_GetHashValue(entryPtr);
}
-const char *Ttk_ElementName(ElementImpl *elementImpl)
+const char *Ttk_ElementClassName(Ttk_ElementClass *elementClass)
{
- return elementImpl->name;
+ return elementClass->name;
}
/*
@@ -825,17 +819,16 @@ int Ttk_RegisterElementFactory(
return TCL_OK;
}
-
/* Ttk_CloneElement -- element factory procedure.
* (style element create $name) "from" $theme ?$element?
*/
static int Ttk_CloneElement(
Tcl_Interp *interp, void *clientData,
Ttk_Theme theme, const char *elementName,
- int objc, Tcl_Obj *CONST objv[])
+ int objc, Tcl_Obj *const objv[])
{
Ttk_Theme fromTheme;
- ElementImpl *fromElement;
+ Ttk_ElementClass *fromElement;
if (objc <= 0 || objc > 2) {
Tcl_WrongNumArgs(interp, 0, objv, "theme ?element?");
@@ -867,18 +860,18 @@ static int Ttk_CloneElement(
/* Ttk_RegisterElement--
* Register an element in the given theme.
* Returns: Element handle if successful, NULL otherwise.
- * On failure, leaves an error message in interp's result
+ * On failure, leaves an error message in interp's result
* if interp is non-NULL.
*/
-Ttk_ElementImpl Ttk_RegisterElement(
+Ttk_ElementClass *Ttk_RegisterElement(
Tcl_Interp *interp, /* Where to leave error messages */
Ttk_Theme theme, /* Style engine providing the implementation. */
const char *name, /* Name of new element */
Ttk_ElementSpec *specPtr, /* Static template information */
void *clientData) /* application-specific data */
{
- ElementImpl *elementImpl;
+ Ttk_ElementClass *elementClass;
Tcl_HashEntry *entryPtr;
int newEntry;
@@ -903,10 +896,10 @@ Ttk_ElementImpl Ttk_RegisterElement(
}
name = Tcl_GetHashKey(&theme->elementTable, entryPtr);
- elementImpl = NewElementImpl(name, specPtr, clientData);
- Tcl_SetHashValue(entryPtr, elementImpl);
+ elementClass = NewElementClass(name, specPtr, clientData);
+ Tcl_SetHashValue(entryPtr, elementClass);
- return elementImpl;
+ return elementClass;
}
/* Ttk_RegisterElementSpec (deprecated) --
@@ -915,7 +908,7 @@ Ttk_ElementImpl Ttk_RegisterElement(
int Ttk_RegisterElementSpec(Ttk_Theme theme,
const char *name, Ttk_ElementSpec *specPtr, void *clientData)
{
- return Ttk_RegisterElement(NULL, theme, name, specPtr, clientData)
+ return Ttk_RegisterElement(NULL, theme, name, specPtr, clientData)
? TCL_OK : TCL_ERROR;
}
@@ -975,32 +968,27 @@ static int AllocateResource(
static
int InitializeElementRecord(
- ElementImpl *element, /* Element instance to initialize */
+ Ttk_ElementClass *eclass, /* Element instance to initialize */
Ttk_Style style, /* Style table */
char *widgetRecord, /* Source of widget option values */
Tk_OptionTable optionTable, /* Option table describing widget record */
Tk_Window tkwin, /* Corresponding window */
Ttk_State state) /* Widget or element state */
{
- char *elementRecord = element->elementRecord;
- OptionMap optionMap = GetOptionMap(element,optionTable);
- int nResources = element->nResources;
+ char *elementRecord = eclass->elementRecord;
+ OptionMap optionMap = GetOptionMap(eclass,optionTable);
+ int nResources = eclass->nResources;
Ttk_ResourceCache cache = style->cache;
- Ttk_ElementOptionSpec *elementOption = element->specPtr->options;
+ Ttk_ElementOptionSpec *elementOption = eclass->specPtr->options;
int i;
for (i=0; i<nResources; ++i, ++elementOption) {
Tcl_Obj **dest = (Tcl_Obj **)
(elementRecord + elementOption->offset);
const char *optionName = elementOption->optionName;
- Tcl_Obj *stateMap = LookupStateMap(style, optionName);
- Tcl_Obj *dynamicSetting = 0;
+ Tcl_Obj *dynamicSetting = Ttk_StyleMap(style, optionName, state);
Tcl_Obj *widgetValue = 0;
- Tcl_Obj *elementDefault = element->defaultValues[i];
-
- if (stateMap) {
- dynamicSetting = Ttk_StateMapLookup(NULL, stateMap, state);
- }
+ Tcl_Obj *elementDefault = eclass->defaultValues[i];
if (optionMap[i]) {
widgetValue = *(Tcl_Obj **)
@@ -1012,7 +1000,7 @@ int InitializeElementRecord(
} else if (dynamicSetting) {
*dest = dynamicSetting;
} else {
- Tcl_Obj *styleDefault = LookupDefault(style, optionName);
+ Tcl_Obj *styleDefault = Ttk_StyleDefault(style, optionName);
*dest = styleDefault ? styleDefault : elementDefault;
}
@@ -1039,7 +1027,6 @@ Tcl_Obj *Ttk_QueryStyle(
const char *optionName, /* Option name */
Ttk_State state) /* Current state */
{
- Tcl_Obj *stateMap;
const Tk_OptionSpec *optionSpec;
Tcl_Obj *result;
@@ -1057,18 +1044,15 @@ Tcl_Obj *Ttk_QueryStyle(
/*
* Check dynamic settings:
*/
- stateMap = LookupStateMap(style, optionName);
- if (stateMap) {
- result = Ttk_StateMapLookup(NULL, stateMap, state);
- if (result) {
- return result;
- }
+ result = Ttk_StyleMap(style, optionName, state);
+ if (result) {
+ return result;
}
/*
* Use style default:
*/
- return LookupDefault(style, optionName);
+ return Ttk_StyleDefault(style, optionName);
}
/*
@@ -1078,7 +1062,7 @@ Tcl_Obj *Ttk_QueryStyle(
void
Ttk_ElementSize(
- ElementImpl *element, /* Element to query */
+ Ttk_ElementClass *eclass, /* Element to query */
Ttk_Style style, /* Style settings */
char *recordPtr, /* The widget record. */
Tk_OptionTable optionTable, /* Description of widget record */
@@ -1091,10 +1075,13 @@ Ttk_ElementSize(
paddingPtr->left = paddingPtr->right = paddingPtr->top = paddingPtr->bottom
= *widthPtr = *heightPtr = 0;
- if (!InitializeElementRecord(element, style, recordPtr, optionTable, tkwin, state))
+ if (!InitializeElementRecord(
+ eclass, style, recordPtr, optionTable, tkwin, state))
+ {
return;
- element->specPtr->size(
- element->clientData, element->elementRecord,
+ }
+ eclass->specPtr->size(
+ eclass->clientData, eclass->elementRecord,
tkwin, widthPtr, heightPtr, paddingPtr);
}
@@ -1105,7 +1092,7 @@ Ttk_ElementSize(
void
Ttk_DrawElement(
- ElementImpl *element, /* Element instance */
+ Ttk_ElementClass *eclass, /* Element instance */
Ttk_Style style, /* Style settings */
char *recordPtr, /* The widget record. */
Tk_OptionTable optionTable, /* Description of option table */
@@ -1116,10 +1103,13 @@ Ttk_DrawElement(
{
if (b.width <= 0 || b.height <= 0)
return;
- if (!InitializeElementRecord(element, style, recordPtr, optionTable, tkwin, state))
+ if (!InitializeElementRecord(
+ eclass, style, recordPtr, optionTable, tkwin, state))
+ {
return;
- element->specPtr->draw(
- element->clientData, element->elementRecord,
+ }
+ eclass->specPtr->draw(
+ eclass->clientData, eclass->elementRecord,
tkwin, d, b, state);
}
@@ -1128,7 +1118,7 @@ Ttk_DrawElement(
*/
/*
- * EnumerateHashTable --
+ * TtkEnumerateHashTable --
* Helper routine. Sets interp's result to the list of all keys
* in the hash table.
*
@@ -1136,7 +1126,8 @@ Ttk_DrawElement(
* Side effects: Sets interp's result.
*/
-static int EnumerateHashTable(Tcl_Interp *interp, Tcl_HashTable *ht)
+MODULE_SCOPE
+int TtkEnumerateHashTable(Tcl_Interp *interp, Tcl_HashTable *ht)
{
Tcl_HashSearch search;
Tcl_Obj *result = Tcl_NewListObj(0, NULL);
@@ -1153,7 +1144,7 @@ static int EnumerateHashTable(Tcl_Interp *interp, Tcl_HashTable *ht)
}
/* HashTableToDict --
- * Helper routine. Converts a TCL_STRING_KEYS Tcl_HashTable
+ * Helper routine. Converts a TCL_STRING_KEYS Tcl_HashTable
* with Tcl_Obj * entries into a dictionary.
*/
static Tcl_Obj* HashTableToDict(Tcl_HashTable *ht)
@@ -1164,7 +1155,7 @@ static Tcl_Obj* HashTableToDict(Tcl_HashTable *ht)
while (entryPtr != NULL) {
Tcl_Obj *nameObj = Tcl_NewStringObj(Tcl_GetHashKey(ht, entryPtr),-1);
- Tcl_Obj *valueObj = (Tcl_Obj*)Tcl_GetHashValue(entryPtr);
+ Tcl_Obj *valueObj = Tcl_GetHashValue(entryPtr);
Tcl_ListObjAppendElement(NULL, result, nameObj);
Tcl_ListObjAppendElement(NULL, result, valueObj);
entryPtr = Tcl_NextHashEntry(&search);
@@ -1183,9 +1174,9 @@ StyleMapCmd(
ClientData clientData, /* Master StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
- Tcl_Obj * CONST objv[]) /* Argument objects */
+ Tcl_Obj *const objv[]) /* Argument objects */
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
const char *styleName;
Style *stylePtr;
@@ -1208,7 +1199,7 @@ usage:
return TCL_OK;
} else if (objc == 4) { /* style map $styleName -option */
const char *optionName = Tcl_GetString(objv[3]);
- Tcl_HashEntry *entryPtr =
+ Tcl_HashEntry *entryPtr =
Tcl_FindHashEntry(&stylePtr->settingsTable, optionName);
if (entryPtr) {
Tcl_SetObjResult(interp, (Tcl_Obj*)Tcl_GetHashValue(entryPtr));
@@ -1247,9 +1238,9 @@ usage:
/* + style configure $style -option ?value...
*/
static int StyleConfigureCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
const char *styleName;
Style *stylePtr;
@@ -1269,7 +1260,7 @@ usage:
return TCL_OK;
} else if (objc == 4) { /* style default $styleName -option */
const char *optionName = Tcl_GetString(objv[3]);
- Tcl_HashEntry *entryPtr =
+ Tcl_HashEntry *entryPtr =
Tcl_FindHashEntry(&stylePtr->defaultsTable, optionName);
if (entryPtr) {
Tcl_SetObjResult(interp, (Tcl_Obj*)Tcl_GetHashValue(entryPtr));
@@ -1302,7 +1293,7 @@ usage:
/* + style lookup $style -option ?statespec? ?defaultValue?
*/
static int StyleLookupCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
@@ -1343,12 +1334,45 @@ static int StyleLookupCmd(
return TCL_OK;
}
+static int StyleThemeCurrentCmd(
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[])
+{
+ StylePackageData *pkgPtr = clientData;
+ Tcl_HashSearch search;
+ Tcl_HashEntry *entryPtr = NULL;
+ const char *name = NULL;
+
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 3, objv, "");
+ return TCL_ERROR;
+ }
+
+ entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search);
+ while (entryPtr != NULL) {
+ Theme *ptr = Tcl_GetHashValue(entryPtr);
+ if (ptr == pkgPtr->currentTheme) {
+ name = Tcl_GetHashKey(&pkgPtr->themeTable, entryPtr);
+ break;
+ }
+ entryPtr = Tcl_NextHashEntry(&search);
+ }
+
+ if (name == NULL) {
+ Tcl_SetObjResult(interp,
+ Tcl_NewStringObj("error: failed to get theme name", -1));
+ return TCL_ERROR;
+ }
+
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
+ return TCL_OK;
+}
+
/* + style theme create name ?-parent $theme? ?-settings { script }?
*/
static int StyleThemeCreateCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
static const char *optStrings[] =
{ "-parent", "-settings", NULL };
enum { OP_PARENT, OP_SETTINGS };
@@ -1358,7 +1382,7 @@ static int StyleThemeCreateCmd(
int i;
if (objc < 4 || objc % 2 != 0) {
- Tcl_WrongNumArgs(interp, 3, objv, "name ?options?");
+ Tcl_WrongNumArgs(interp, 3, objv, "name ?-option value ...?");
return TCL_ERROR;
}
@@ -1410,10 +1434,10 @@ static int StyleThemeCreateCmd(
* Return list of registered themes.
*/
static int StyleThemeNamesCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = clientData;
- return EnumerateHashTable(interp, &pkgPtr->themeTable);
+ return TtkEnumerateHashTable(interp, &pkgPtr->themeTable);
}
/* + style theme settings $theme $script
@@ -1426,9 +1450,9 @@ StyleThemeSettingsCmd(
ClientData clientData, /* Master StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
- Tcl_Obj * CONST objv[]) /* Argument objects */
+ Tcl_Obj *const objv[]) /* Argument objects */
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
Ttk_Theme oldTheme = pkgPtr->currentTheme;
Ttk_Theme newTheme;
int status;
@@ -1452,16 +1476,16 @@ StyleThemeSettingsCmd(
/* + style element create name type ? ...args ?
*/
static int StyleElementCreateCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
const char *elementName, *factoryName;
Tcl_HashEntry *entryPtr;
FactoryRec *recPtr;
if (objc < 5) {
- Tcl_WrongNumArgs(interp, 3, objv, "name type ?options...?");
+ Tcl_WrongNumArgs(interp, 3, objv, "name type ?-option value ...?");
return TCL_ERROR;
}
@@ -1474,7 +1498,7 @@ static int StyleElementCreateCmd(
return TCL_ERROR;
}
- recPtr = (FactoryRec *)Tcl_GetHashValue(entryPtr);
+ recPtr = Tcl_GetHashValue(entryPtr);
return recPtr->factory(interp, recPtr->clientData,
theme, elementName, objc - 5, objv + 5);
@@ -1484,28 +1508,28 @@ static int StyleElementCreateCmd(
* Return a list of elements defined in the current theme.
*/
static int StyleElementNamesCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 3, objv, NULL);
return TCL_ERROR;
}
- return EnumerateHashTable(interp, &theme->elementTable);
+ return TtkEnumerateHashTable(interp, &theme->elementTable);
}
/* + style element options $element --
* Return list of element options for specified element
*/
static int StyleElementOptionsCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
const char *elementName;
- ElementImpl *elementImpl;
+ Ttk_ElementClass *elementClass;
if (objc != 4) {
Tcl_WrongNumArgs(interp, 3, objv, "element");
@@ -1513,9 +1537,9 @@ static int StyleElementOptionsCmd(
}
elementName = Tcl_GetString(objv[3]);
- elementImpl = Ttk_GetElement(theme, elementName);
- if (elementImpl) {
- Ttk_ElementSpec *specPtr = elementImpl->specPtr;
+ elementClass = Ttk_GetElement(theme, elementName);
+ if (elementClass) {
+ Ttk_ElementSpec *specPtr = elementClass->specPtr;
Ttk_ElementOptionSpec *option = specPtr->options;
Tcl_Obj *result = Tcl_NewListObj(0,0);
@@ -1536,9 +1560,9 @@ static int StyleElementOptionsCmd(
/* + style layout name ?spec?
*/
static int StyleLayoutCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
+ ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
- StylePackageData *pkgPtr = (StylePackageData *)clientData;
+ StylePackageData *pkgPtr = clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
const char *layoutName;
Ttk_LayoutTemplate layoutTemplate;
@@ -1576,16 +1600,20 @@ StyleThemeUseCmd(
ClientData clientData, /* Master StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
- Tcl_Obj * CONST objv[]) /* Argument objects */
+ Tcl_Obj *const objv[]) /* Argument objects */
{
StylePackageData *pkgPtr = clientData;
Ttk_Theme theme;
- if (objc != 4) {
- Tcl_WrongNumArgs(interp, 3, objv, "theme");
+ if (objc < 3 || objc > 4) {
+ Tcl_WrongNumArgs(interp, 3, objv, "?theme?");
return TCL_ERROR;
}
+ if (objc == 3) {
+ return StyleThemeCurrentCmd(clientData, interp, objc, objv);
+ }
+
theme = LookupTheme(interp, pkgPtr, Tcl_GetString(objv[3]));
if (!theme) {
return TCL_ERROR;
@@ -1599,13 +1627,7 @@ StyleThemeUseCmd(
* Implementation of the [style] command.
*/
-struct Ensemble {
- const char *name; /* subcommand name */
- Tcl_ObjCmdProc *command; /* subcommand implementation, OR: */
- struct Ensemble *ensemble; /* subcommand ensemble */
-};
-
-static struct Ensemble StyleThemeEnsemble[] = {
+static const Ttk_Ensemble StyleThemeEnsemble[] = {
{ "create", StyleThemeCreateCmd, 0 },
{ "names", StyleThemeNamesCmd, 0 },
{ "settings", StyleThemeSettingsCmd, 0 },
@@ -1613,14 +1635,14 @@ static struct Ensemble StyleThemeEnsemble[] = {
{ NULL, 0, 0 }
};
-static struct Ensemble StyleElementEnsemble[] = {
+static const Ttk_Ensemble StyleElementEnsemble[] = {
{ "create", StyleElementCreateCmd, 0 },
{ "names", StyleElementNamesCmd, 0 },
{ "options", StyleElementOptionsCmd, 0 },
{ NULL, 0, 0 }
};
-static struct Ensemble StyleEnsemble[] = {
+static const Ttk_Ensemble StyleEnsemble[] = {
{ "configure", StyleConfigureCmd, 0 },
{ "map", StyleMapCmd, 0 },
{ "lookup", StyleLookupCmd, 0 },
@@ -1635,15 +1657,20 @@ StyleObjCmd(
ClientData clientData, /* Master StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
- Tcl_Obj * CONST objv[]) /* Argument objects */
+ Tcl_Obj *const objv[]) /* Argument objects */
{
- struct Ensemble *ensemble = StyleEnsemble;
- int optPtr = 1;
- int index;
+ return Ttk_InvokeEnsemble(StyleEnsemble, 1, clientData,interp,objc,objv);
+}
- while (optPtr < objc) {
+MODULE_SCOPE
+int Ttk_InvokeEnsemble( /* Run an ensemble command */
+ const Ttk_Ensemble *ensemble, int cmdIndex,
+ void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+{
+ while (cmdIndex < objc) {
+ int index;
if (Tcl_GetIndexFromObjStruct(interp,
- objv[optPtr], ensemble, sizeof(ensemble[0]),
+ objv[cmdIndex], ensemble, sizeof(ensemble[0]),
"command", 0, &index)
!= TCL_OK)
{
@@ -1654,9 +1681,9 @@ StyleObjCmd(
return ensemble[index].command(clientData, interp, objc, objv);
}
ensemble = ensemble[index].ensemble;
- ++optPtr;
+ ++cmdIndex;
}
- Tcl_WrongNumArgs(interp, optPtr, objv, "option ?arg arg...?");
+ Tcl_WrongNumArgs(interp, cmdIndex, objv, "option ?arg ...?");
return TCL_ERROR;
}
@@ -1680,8 +1707,7 @@ void Ttk_StylePkgInit(Tcl_Interp *interp)
pkgPtr->cache = Ttk_CreateResourceCache(interp);
pkgPtr->themeChangePending = 0;
- Tcl_SetAssocData(interp, "StylePackage", Ttk_StylePkgFree,
- (ClientData)pkgPtr);
+ Tcl_SetAssocData(interp, PKG_ASSOC_KEY, Ttk_StylePkgFree, pkgPtr);
/*
* Create the default system theme:
@@ -1702,11 +1728,9 @@ void Ttk_StylePkgInit(Tcl_Interp *interp)
/*
* Register commands:
*/
- Tcl_CreateObjCommand(interp, "::ttk::style", StyleObjCmd,
- (ClientData)pkgPtr, 0);
+ Tcl_CreateObjCommand(interp, "::ttk::style", StyleObjCmd, pkgPtr, 0);
- nsPtr = Tcl_FindNamespace(interp, "::ttk", (Tcl_Namespace *) NULL,
- TCL_LEAVE_ERR_MSG);
+ nsPtr = Tcl_FindNamespace(interp, "::ttk", NULL, TCL_LEAVE_ERR_MSG);
Tcl_Export(interp, nsPtr, "style", 0 /* dontResetList */);
Ttk_RegisterElementFactory(interp, "from", Ttk_CloneElement, 0);