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.c117
1 files changed, 73 insertions, 44 deletions
diff --git a/generic/ttk/ttkTheme.c b/generic/ttk/ttkTheme.c
index 730de5d..c60dd13 100644
--- a/generic/ttk/ttkTheme.c
+++ b/generic/ttk/ttkTheme.c
@@ -3,8 +3,8 @@
*
* This file implements the widget styles and themes support.
*
- * Copyright (c) 2002 Frederic Bonnet
- * Copyright (c) 2003 Joe English
+ * Copyright © 2002 Frederic Bonnet
+ * Copyright © 2003 Joe English
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
@@ -95,7 +95,7 @@ Tcl_Obj *Ttk_StyleMap(Ttk_Style style, const char *optionName, Ttk_State state)
/*
* Ttk_StyleDefault --
- * Look up default resource setting the in the specified style.
+ * Look up default resource setting in the specified style.
*/
Tcl_Obj *Ttk_StyleDefault(Ttk_Style style, const char *optionName)
{
@@ -117,7 +117,7 @@ typedef const Tk_OptionSpec **OptionMap;
struct Ttk_ElementClass_ {
const char *name; /* Points to hash table key */
- Ttk_ElementSpec *specPtr; /* Template provided during registration. */
+ const Ttk_ElementSpec *specPtr; /* Template provided during registration. */
void *clientData; /* Client data passed in at registration time */
void *elementRecord; /* Scratch buffer for element record storage */
int nResources; /* #Element options */
@@ -181,7 +181,7 @@ BuildOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable)
int i;
for (i = 0; i < elementClass->nResources; ++i) {
- Ttk_ElementOptionSpec *e = elementClass->specPtr->options+i;
+ const Ttk_ElementOptionSpec *e = elementClass->specPtr->options+i;
optionMap[i] = TTKGetOptionSpec(e->optionName, optionTable, e->type);
}
@@ -216,7 +216,7 @@ GetOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable)
* from the specified element specification.
*/
static Ttk_ElementClass *
-NewElementClass(const char *name, Ttk_ElementSpec *specPtr,void *clientData)
+NewElementClass(const char *name, const Ttk_ElementSpec *specPtr, void *clientData)
{
Ttk_ElementClass *elementClass = (Ttk_ElementClass *)ckalloc(sizeof(Ttk_ElementClass));
int i;
@@ -407,7 +407,7 @@ typedef struct
* Cleanup procedure for StylePackageData.
*/
static void Ttk_StylePkgFree(
- ClientData clientData,
+ void *clientData,
TCL_UNUSED(Tcl_Interp *))
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
@@ -475,7 +475,7 @@ static StylePackageData *GetStylePackageData(Tcl_Interp *interp)
*
*/
void Ttk_RegisterCleanup(
- Tcl_Interp *interp, ClientData clientData, Ttk_CleanupProc *cleanupProc)
+ Tcl_Interp *interp, void *clientData, Ttk_CleanupProc *cleanupProc)
{
StylePackageData *pkgPtr = GetStylePackageData(interp);
Cleanup *cleanup = (Cleanup *)ckalloc(sizeof(*cleanup));
@@ -498,7 +498,7 @@ void Ttk_RegisterCleanup(
* the widget hierarchy, so this is done by evaluating a Tcl script.
*/
-static void ThemeChangedProc(ClientData clientData)
+static void ThemeChangedProc(void *clientData)
{
static char ThemeChangedScript[] = "ttk::ThemeChanged";
StylePackageData *pkgPtr = (StylePackageData *)clientData;
@@ -516,6 +516,8 @@ static void ThemeChangedProc(ClientData clientData)
*/
static void ThemeChanged(StylePackageData *pkgPtr)
{
+ TtkSetBlinkCursorTimes(pkgPtr->interp);
+
if (!pkgPtr->themeChangePending) {
Tcl_DoWhenIdle(ThemeChangedProc, pkgPtr);
pkgPtr->themeChangePending = 1;
@@ -839,7 +841,7 @@ int Ttk_RegisterElementFactory(
static int Ttk_CloneElement(
Tcl_Interp *interp, TCL_UNUSED(void *),
Ttk_Theme theme, const char *elementName,
- int objc, Tcl_Obj *const objv[])
+ Tcl_Size objc, Tcl_Obj *const objv[])
{
Ttk_Theme fromTheme;
Ttk_ElementClass *fromElement;
@@ -882,7 +884,7 @@ 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 */
+ const Ttk_ElementSpec *specPtr, /* Static template information */
void *clientData) /* application-specific data */
{
Ttk_ElementClass *elementClass;
@@ -923,7 +925,7 @@ Ttk_ElementClass *Ttk_RegisterElement(
* Register a new element.
*/
int Ttk_RegisterElementSpec(Ttk_Theme theme,
- const char *name, Ttk_ElementSpec *specPtr, void *clientData)
+ const char *name, const Ttk_ElementSpec *specPtr, void *clientData)
{
return Ttk_RegisterElement(NULL, theme, name, specPtr, clientData)
? TCL_OK : TCL_ERROR;
@@ -987,16 +989,16 @@ static
int InitializeElementRecord(
Ttk_ElementClass *eclass, /* Element instance to initialize */
Ttk_Style style, /* Style table */
- char *widgetRecord, /* Source of widget option values */
+ void *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 = eclass->elementRecord;
+ void *elementRecord = eclass->elementRecord;
OptionMap optionMap = GetOptionMap(eclass,optionTable);
int nResources = eclass->nResources;
Ttk_ResourceCache cache = style->cache;
- Ttk_ElementOptionSpec *elementOption = eclass->specPtr->options;
+ const Ttk_ElementOptionSpec *elementOption = eclass->specPtr->options;
int i;
for (i=0; i<nResources; ++i, ++elementOption) {
@@ -1081,7 +1083,7 @@ void
Ttk_ElementSize(
Ttk_ElementClass *eclass, /* Element to query */
Ttk_Style style, /* Style settings */
- char *recordPtr, /* The widget record. */
+ void *recordPtr, /* The widget record. */
Tk_OptionTable optionTable, /* Description of widget record */
Tk_Window tkwin, /* The widget window. */
Ttk_State state, /* Current widget state */
@@ -1111,7 +1113,7 @@ void
Ttk_DrawElement(
Ttk_ElementClass *eclass, /* Element instance */
Ttk_Style style, /* Style settings */
- char *recordPtr, /* The widget record. */
+ void *recordPtr, /* The widget record. */
Tk_OptionTable optionTable, /* Description of option table */
Tk_Window tkwin, /* The widget window. */
Drawable d, /* Where to draw element. */
@@ -1188,9 +1190,9 @@ static Tcl_Obj* HashTableToDict(Tcl_HashTable *ht)
*/
static int
StyleMapCmd(
- ClientData clientData, /* StylePackageData pointer */
+ void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
- int objc, /* Number of arguments */
+ Tcl_Size objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
@@ -1255,7 +1257,7 @@ usage:
/* + style configure $style -option ?value...
*/
static int StyleConfigureCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
@@ -1272,10 +1274,10 @@ usage:
styleName = Tcl_GetString(objv[2]);
stylePtr = Ttk_GetStyle(theme, styleName);
- if (objc == 3) { /* style default $styleName */
+ if (objc == 3) { /* style configure $styleName */
Tcl_SetObjResult(interp, HashTableToDict(&stylePtr->defaultsTable));
return TCL_OK;
- } else if (objc == 4) { /* style default $styleName -option */
+ } else if (objc == 4) { /* style configure $styleName -option */
const char *optionName = Tcl_GetString(objv[3]);
Tcl_HashEntry *entryPtr =
Tcl_FindHashEntry(&stylePtr->defaultsTable, optionName);
@@ -1310,7 +1312,7 @@ usage:
/* + style lookup $style -option ?statespec? ?defaultValue?
*/
static int StyleLookupCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
@@ -1325,9 +1327,7 @@ static int StyleLookupCmd(
}
style = Ttk_GetStyle(theme, Tcl_GetString(objv[2]));
- if (!style) {
- return TCL_ERROR;
- }
+
optionName = Tcl_GetString(objv[3]);
if (objc >= 5) {
@@ -1352,7 +1352,7 @@ static int StyleLookupCmd(
}
static int StyleThemeCurrentCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj * const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Tcl_HashSearch search;
@@ -1388,7 +1388,7 @@ static int StyleThemeCurrentCmd(
/* + style theme create name ?-parent $theme? ?-settings { script }?
*/
static int StyleThemeCreateCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
static const char *const optStrings[] =
@@ -1452,10 +1452,10 @@ static int StyleThemeCreateCmd(
* Return list of registered themes.
*/
static int StyleThemeNamesCmd(
- ClientData clientData,
+ void *clientData,
Tcl_Interp *interp,
- TCL_UNUSED(int),
- TCL_UNUSED(Tcl_Obj *const *))
+ TCL_UNUSED(Tcl_Size), /* objc */
+ TCL_UNUSED(Tcl_Obj *const *)) /* objv */
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
@@ -1469,9 +1469,9 @@ static int StyleThemeNamesCmd(
*/
static int
StyleThemeSettingsCmd(
- ClientData clientData, /* StylePackageData pointer */
+ void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
- int objc, /* Number of arguments */
+ Tcl_Size objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
@@ -1498,7 +1498,7 @@ StyleThemeSettingsCmd(
/* + style element create name type ? ...args ?
*/
static int StyleElementCreateCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
@@ -1533,7 +1533,7 @@ 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[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
@@ -1549,7 +1549,7 @@ static int StyleElementNamesCmd(
* Return list of element options for specified element
*/
static int StyleElementOptionsCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
@@ -1564,8 +1564,8 @@ static int StyleElementOptionsCmd(
elementName = Tcl_GetString(objv[3]);
elementClass = Ttk_GetElement(theme, elementName);
if (elementClass) {
- Ttk_ElementSpec *specPtr = elementClass->specPtr;
- Ttk_ElementOptionSpec *option = specPtr->options;
+ const Ttk_ElementSpec *specPtr = elementClass->specPtr;
+ const Ttk_ElementOptionSpec *option = specPtr->options;
Tcl_Obj *result = Tcl_NewListObj(0,0);
while (option->optionName) {
@@ -1587,7 +1587,7 @@ static int StyleElementOptionsCmd(
/* + style layout name ?spec?
*/
static int StyleLayoutCmd(
- ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Ttk_Theme theme = pkgPtr->currentTheme;
@@ -1622,14 +1622,42 @@ static int StyleLayoutCmd(
return TCL_OK;
}
+/* + style theme styles ?$theme? --
+ * Return list of styles available in $theme.
+ * Use the current theme if $theme is omitted.
+ */
+static int StyleThemeStylesCmd(
+ TCL_UNUSED(void *),
+ Tcl_Interp *interp,
+ Tcl_Size objc,
+ Tcl_Obj *const objv[])
+{
+ Ttk_Theme themePtr;
+
+ if (objc < 3 || objc > 4) {
+ Tcl_WrongNumArgs(interp, 3, objv, "?theme?");
+ return TCL_ERROR;
+ }
+
+ if (objc == 3) {
+ themePtr = Ttk_GetCurrentTheme(interp);
+ } else {
+ themePtr = Ttk_GetTheme(interp, Tcl_GetString(objv[3]));
+ }
+ if (!themePtr)
+ return TCL_ERROR;
+
+ return TtkEnumerateHashTable(interp, &themePtr->styleTable);
+}
+
/* + style theme use $theme --
* Sets the current theme to $theme
*/
static int
StyleThemeUseCmd(
- ClientData clientData, /* StylePackageData pointer */
+ void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
- int objc, /* Number of arguments */
+ Tcl_Size objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
{
StylePackageData *pkgPtr = (StylePackageData *)clientData;
@@ -1661,6 +1689,7 @@ static const Ttk_Ensemble StyleThemeEnsemble[] = {
{ "create", StyleThemeCreateCmd, 0 },
{ "names", StyleThemeNamesCmd, 0 },
{ "settings", StyleThemeSettingsCmd, 0 },
+ { "styles", StyleThemeStylesCmd, 0 },
{ "use", StyleThemeUseCmd, 0 },
{ NULL, 0, 0 }
};
@@ -1684,7 +1713,7 @@ static const Ttk_Ensemble StyleEnsemble[] = {
static int
StyleObjCmd(
- ClientData clientData, /* StylePackageData pointer */
+ void *clientData, /* StylePackageData pointer */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
Tcl_Obj *const objv[]) /* Argument objects */
@@ -1694,8 +1723,8 @@ StyleObjCmd(
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[])
+ const Ttk_Ensemble *ensemble, Tcl_Size cmdIndex,
+ void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
while (cmdIndex < objc) {
int index;