Import Tk 8.6.11
This commit is contained in:
@@ -15,14 +15,14 @@
|
||||
* shellcc/platform/commctls/userex/refentry.asp >
|
||||
*/
|
||||
|
||||
#define WINVER 0x0501 /* Requires Windows XP APIs */
|
||||
|
||||
#include <tkWinInt.h>
|
||||
#ifndef HAVE_UXTHEME_H
|
||||
/* Stub for platforms that lack the XP theme API headers: */
|
||||
#include <tkWinInt.h>
|
||||
int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) { return TCL_OK; }
|
||||
#else
|
||||
|
||||
#define WINVER 0x0501 /* Requires Windows XP APIs */
|
||||
|
||||
#include <windows.h>
|
||||
#include <uxtheme.h>
|
||||
#if defined(HAVE_VSSYM32_H) || _MSC_VER > 1500
|
||||
@@ -31,8 +31,6 @@ int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) { return TCL_OK; }
|
||||
# include <tmschema.h>
|
||||
#endif
|
||||
|
||||
#include <tkWinInt.h>
|
||||
|
||||
#include "ttk/ttkTheme.h"
|
||||
|
||||
typedef HTHEME (STDAPICALLTYPE OpenThemeDataProc)(HWND hwnd,
|
||||
@@ -106,9 +104,9 @@ LoadXPThemeProcs(HINSTANCE *phlib)
|
||||
* We have successfully loaded the library. Proceed in storing the
|
||||
* addresses of the functions we want to use.
|
||||
*/
|
||||
XPThemeProcs *procs = ckalloc(sizeof(XPThemeProcs));
|
||||
XPThemeProcs *procs = (XPThemeProcs *)ckalloc(sizeof(XPThemeProcs));
|
||||
#define LOADPROC(name) \
|
||||
(0 != (procs->name = (name ## Proc *)GetProcAddress(handle, #name) ))
|
||||
(0 != (procs->name = (name ## Proc *)(void *)GetProcAddress(handle, #name) ))
|
||||
|
||||
if ( LOADPROC(OpenThemeData)
|
||||
&& LOADPROC(CloseThemeData)
|
||||
@@ -138,7 +136,7 @@ LoadXPThemeProcs(HINSTANCE *phlib)
|
||||
static void
|
||||
XPThemeDeleteProc(void *clientData)
|
||||
{
|
||||
XPThemeData *themeData = clientData;
|
||||
XPThemeData *themeData = (XPThemeData *)clientData;
|
||||
FreeLibrary(themeData->hlibrary);
|
||||
ckfree(clientData);
|
||||
}
|
||||
@@ -146,9 +144,11 @@ XPThemeDeleteProc(void *clientData)
|
||||
static int
|
||||
XPThemeEnabled(Ttk_Theme theme, void *clientData)
|
||||
{
|
||||
XPThemeData *themeData = clientData;
|
||||
XPThemeData *themeData = (XPThemeData *)clientData;
|
||||
int active = themeData->procs->IsThemeActive();
|
||||
int themed = themeData->procs->IsAppThemed();
|
||||
(void)theme;
|
||||
|
||||
return (active && themed);
|
||||
}
|
||||
|
||||
@@ -382,12 +382,12 @@ typedef struct /* XP element specifications */
|
||||
int partId; /* BP_PUSHBUTTON, BP_CHECKBUTTON, etc. */
|
||||
Ttk_StateTable *statemap; /* Map Tk states to XP states */
|
||||
Ttk_Padding padding; /* See NOTE-GetThemeMargins */
|
||||
int flags;
|
||||
# define IGNORE_THEMESIZE 0x80000000 /* See NOTE-GetThemePartSize */
|
||||
# define PAD_MARGINS 0x40000000 /* See NOTE-GetThemeMargins */
|
||||
# define HEAP_ELEMENT 0x20000000 /* ElementInfo is on heap */
|
||||
# define HALF_HEIGHT 0x10000000 /* Used by GenericSizedElements */
|
||||
# define HALF_WIDTH 0x08000000 /* Used by GenericSizedElements */
|
||||
unsigned flags;
|
||||
# define IGNORE_THEMESIZE 0x80000000U /* See NOTE-GetThemePartSize */
|
||||
# define PAD_MARGINS 0x40000000U /* See NOTE-GetThemeMargins */
|
||||
# define HEAP_ELEMENT 0x20000000U /* ElementInfo is on heap */
|
||||
# define HALF_HEIGHT 0x10000000U /* Used by GenericSizedElements */
|
||||
# define HALF_WIDTH 0x08000000U /* Used by GenericSizedElements */
|
||||
} ElementInfo;
|
||||
|
||||
typedef struct
|
||||
@@ -395,7 +395,7 @@ typedef struct
|
||||
/*
|
||||
* Static data, initialized when element is registered:
|
||||
*/
|
||||
ElementInfo *info;
|
||||
const ElementInfo *info;
|
||||
XPThemeProcs *procs; /* Pointer to theme procedure table */
|
||||
|
||||
/*
|
||||
@@ -411,9 +411,9 @@ typedef struct
|
||||
} ElementData;
|
||||
|
||||
static ElementData *
|
||||
NewElementData(XPThemeProcs *procs, ElementInfo *info)
|
||||
NewElementData(XPThemeProcs *procs, const ElementInfo *info)
|
||||
{
|
||||
ElementData *elementData = ckalloc(sizeof(ElementData));
|
||||
ElementData *elementData = (ElementData *)ckalloc(sizeof(ElementData));
|
||||
|
||||
elementData->procs = procs;
|
||||
elementData->info = info;
|
||||
@@ -429,12 +429,12 @@ NewElementData(XPThemeProcs *procs, ElementInfo *info)
|
||||
*/
|
||||
static void DestroyElementData(void *clientData)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
if (elementData->info->flags & HEAP_ELEMENT) {
|
||||
ckfree(elementData->info->statemap);
|
||||
ckfree(elementData->info->className);
|
||||
ckfree(elementData->info->elementName);
|
||||
ckfree(elementData->info);
|
||||
ckfree((char *)elementData->info->statemap);
|
||||
ckfree((char *)elementData->info->className);
|
||||
ckfree((char *)elementData->info->elementName);
|
||||
ckfree((char *)elementData->info);
|
||||
}
|
||||
ckfree(clientData);
|
||||
}
|
||||
@@ -497,9 +497,10 @@ static void GenericElementSize(
|
||||
void *clientData, void *elementRecord, Tk_Window tkwin,
|
||||
int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
HRESULT result;
|
||||
SIZE size;
|
||||
(void)elementRecord;
|
||||
|
||||
if (!InitElementData(elementData, tkwin, 0))
|
||||
return;
|
||||
@@ -507,7 +508,7 @@ static void GenericElementSize(
|
||||
if (!(elementData->info->flags & IGNORE_THEMESIZE)) {
|
||||
result = elementData->procs->GetThemePartSize(
|
||||
elementData->hTheme,
|
||||
elementData->hDC,
|
||||
NULL,
|
||||
elementData->info->partId,
|
||||
Ttk_StateTableLookup(elementData->info->statemap, 0),
|
||||
NULL /*RECT *prc*/,
|
||||
@@ -533,8 +534,9 @@ static void GenericElementDraw(
|
||||
void *clientData, void *elementRecord, Tk_Window tkwin,
|
||||
Drawable d, Ttk_Box b, unsigned int state)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
RECT rc;
|
||||
(void)elementRecord;
|
||||
|
||||
if (!InitElementData(elementData, tkwin, d)) {
|
||||
return;
|
||||
@@ -578,7 +580,7 @@ GenericSizedElementSize(
|
||||
void *clientData, void *elementRecord, Tk_Window tkwin,
|
||||
int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
|
||||
if (!InitElementData(elementData, tkwin, 0))
|
||||
return;
|
||||
@@ -614,7 +616,7 @@ SpinboxArrowElementSize(
|
||||
void *clientData, void *elementRecord, Tk_Window tkwin,
|
||||
int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
|
||||
if (!InitElementData(elementData, tkwin, 0))
|
||||
return;
|
||||
@@ -643,9 +645,10 @@ static void ThumbElementDraw(
|
||||
void *clientData, void *elementRecord, Tk_Window tkwin,
|
||||
Drawable d, Ttk_Box b, unsigned int state)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
unsigned stateId = Ttk_StateTableLookup(elementData->info->statemap, state);
|
||||
RECT rc = BoxToRect(b);
|
||||
(void)elementRecord;
|
||||
|
||||
/*
|
||||
* Don't draw the thumb if we are disabled.
|
||||
@@ -682,7 +685,7 @@ static void PbarElementSize(
|
||||
void *clientData, void *elementRecord, Tk_Window tkwin,
|
||||
int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
int nBars = 3;
|
||||
|
||||
GenericElementSize(clientData, elementRecord, tkwin,
|
||||
@@ -722,9 +725,10 @@ static void TabElementDraw(
|
||||
void *clientData, void *elementRecord, Tk_Window tkwin,
|
||||
Drawable d, Ttk_Box b, unsigned int state)
|
||||
{
|
||||
ElementData *elementData = clientData;
|
||||
ElementData *elementData = (ElementData *)clientData;
|
||||
int partId = elementData->info->partId;
|
||||
RECT rc = BoxToRect(b);
|
||||
(void)elementRecord;
|
||||
|
||||
if (!InitElementData(elementData, tkwin, d))
|
||||
return;
|
||||
@@ -793,7 +797,7 @@ static Ttk_ElementSpec TreeIndicatorElementSpec =
|
||||
TreeIndicatorElementDraw
|
||||
};
|
||||
|
||||
#if BROKEN_TEXT_ELEMENT
|
||||
#ifdef BROKEN_TEXT_ELEMENT
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
@@ -812,7 +816,7 @@ typedef struct
|
||||
Tcl_Obj *fontObj;
|
||||
} TextElement;
|
||||
|
||||
static Ttk_ElementOptionSpec TextElementOptions[] =
|
||||
static const Ttk_ElementOptionSpec TextElementOptions[] =
|
||||
{
|
||||
{ "-text", TK_OPTION_STRING,
|
||||
Tk_Offset(TextElement,textObj), "" },
|
||||
@@ -837,15 +841,15 @@ static void TextElementSize(
|
||||
return;
|
||||
|
||||
src = Tcl_GetStringFromObj(element->textObj, &len);
|
||||
Tcl_WinUtfToTChar(src, len, &ds);
|
||||
Tcl_DStringInit(&ds);
|
||||
hr = elementData->procs->GetThemeTextExtent(
|
||||
elementData->hTheme,
|
||||
elementData->hDC,
|
||||
elementData->info->partId,
|
||||
Ttk_StateTableLookup(elementData->info->statemap, 0),
|
||||
(WCHAR *) Tcl_DStringValue(&ds),
|
||||
Tcl_UtfToWCharDString(src, len, &ds),
|
||||
-1,
|
||||
DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
|
||||
DT_LEFT /* | DT_BOTTOM | DT_NOPREFIX */,
|
||||
NULL,
|
||||
&rc);
|
||||
|
||||
@@ -876,15 +880,15 @@ static void TextElementDraw(
|
||||
return;
|
||||
|
||||
src = Tcl_GetStringFromObj(element->textObj, &len);
|
||||
Tcl_WinUtfToTChar(src, len, &ds);
|
||||
Tcl_DStringInit(&ds);
|
||||
hr = elementData->procs->DrawThemeText(
|
||||
elementData->hTheme,
|
||||
elementData->hDC,
|
||||
elementData->info->partId,
|
||||
Ttk_StateTableLookup(elementData->info->statemap, state),
|
||||
(WCHAR *) Tcl_DStringValue(&ds),
|
||||
Tcl_UtfToWCharDString(src, len, &ds),
|
||||
-1,
|
||||
DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
|
||||
DT_LEFT /* | DT_BOTTOM | DT_NOPREFIX */,
|
||||
(state & TTK_STATE_DISABLED) ? DTT_GRAYED : 0,
|
||||
&rc);
|
||||
|
||||
@@ -917,8 +921,8 @@ TTK_LAYOUT("TButton",
|
||||
|
||||
TTK_LAYOUT("TMenubutton",
|
||||
TTK_NODE("Menubutton.dropdown", TTK_PACK_RIGHT|TTK_FILL_Y)
|
||||
TTK_GROUP("Menubutton.button", TTK_PACK_RIGHT|TTK_EXPAND|TTK_FILL_BOTH,
|
||||
TTK_GROUP("Menubutton.padding", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_X,
|
||||
TTK_GROUP("Menubutton.button", TTK_FILL_BOTH,
|
||||
TTK_GROUP("Menubutton.padding", TTK_FILL_X,
|
||||
TTK_NODE("Menubutton.label", 0))))
|
||||
|
||||
TTK_LAYOUT("Horizontal.TScrollbar",
|
||||
@@ -936,14 +940,14 @@ TTK_LAYOUT("Vertical.TScrollbar",
|
||||
TTK_NODE("Vertical.Scrollbar.grip", 0))))
|
||||
|
||||
TTK_LAYOUT("Horizontal.TScale",
|
||||
TTK_GROUP("Scale.focus", TTK_EXPAND|TTK_FILL_BOTH,
|
||||
TTK_GROUP("Horizontal.Scale.trough", TTK_EXPAND|TTK_FILL_BOTH,
|
||||
TTK_GROUP("Scale.focus", TTK_FILL_BOTH,
|
||||
TTK_GROUP("Horizontal.Scale.trough", TTK_FILL_BOTH,
|
||||
TTK_NODE("Horizontal.Scale.track", TTK_FILL_X)
|
||||
TTK_NODE("Horizontal.Scale.slider", TTK_PACK_LEFT) )))
|
||||
|
||||
TTK_LAYOUT("Vertical.TScale",
|
||||
TTK_GROUP("Scale.focus", TTK_EXPAND|TTK_FILL_BOTH,
|
||||
TTK_GROUP("Vertical.Scale.trough", TTK_EXPAND|TTK_FILL_BOTH,
|
||||
TTK_GROUP("Scale.focus", TTK_FILL_BOTH,
|
||||
TTK_GROUP("Vertical.Scale.trough", TTK_FILL_BOTH,
|
||||
TTK_NODE("Vertical.Scale.track", TTK_FILL_Y)
|
||||
TTK_NODE("Vertical.Scale.slider", TTK_PACK_TOP) )))
|
||||
|
||||
@@ -1029,7 +1033,7 @@ static ElementInfo ElementInfoTable[] = {
|
||||
{ "Menubutton.dropdown", &GenericElementSpec, L"TOOLBAR",
|
||||
TP_SPLITBUTTONDROPDOWN,toolbutton_statemap, NOPAD,0 },
|
||||
{ "Treeview.field", &GenericElementSpec, L"TREEVIEW",
|
||||
TVP_TREEITEM, treeview_statemap, PAD(1, 1, 1, 1), 0 },
|
||||
TVP_TREEITEM, treeview_statemap, PAD(1, 1, 1, 1), IGNORE_THEMESIZE },
|
||||
{ "Treeitem.indicator", &TreeIndicatorElementSpec, L"TREEVIEW",
|
||||
TVP_GLYPH, tvpglyph_statemap, PAD(1,1,6,0), PAD_MARGINS },
|
||||
{ "Treeheading.border", &GenericElementSpec, L"HEADER",
|
||||
@@ -1044,12 +1048,10 @@ static ElementInfo ElementInfoTable[] = {
|
||||
{ "Spinbox.downarrow", &SpinboxArrowElementSpec, L"SPIN",
|
||||
SPNP_DOWN, spinbutton_statemap, NOPAD,
|
||||
PAD_MARGINS | ((SM_CXVSCROLL << 8) | SM_CYVSCROLL) },
|
||||
|
||||
#if BROKEN_TEXT_ELEMENT
|
||||
#ifdef BROKEN_TEXT_ELEMENT
|
||||
{ "Labelframe.text", &TextElementSpec, L"BUTTON",
|
||||
BP_GROUPBOX, groupbox_statemap, NOPAD,0 },
|
||||
#endif
|
||||
|
||||
{ 0,0,0,0,0,NOPAD,0 }
|
||||
};
|
||||
#undef PAD
|
||||
@@ -1058,7 +1060,7 @@ static ElementInfo ElementInfoTable[] = {
|
||||
static int
|
||||
GetSysFlagFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr)
|
||||
{
|
||||
static const char *names[] = {
|
||||
static const char *const names[] = {
|
||||
"SM_CXBORDER", "SM_CYBORDER", "SM_CXVSCROLL", "SM_CYVSCROLL",
|
||||
"SM_CXHSCROLL", "SM_CYHSCROLL", "SM_CXMENUCHECK", "SM_CYMENUCHECK",
|
||||
"SM_CXMENUSIZE", "SM_CYMENUSIZE", "SM_CXSIZE", "SM_CYSIZE", "SM_CXSMSIZE",
|
||||
@@ -1112,7 +1114,7 @@ Ttk_CreateVsapiElement(
|
||||
int objc,
|
||||
Tcl_Obj *const objv[])
|
||||
{
|
||||
XPThemeData *themeData = clientData;
|
||||
XPThemeData *themeData = (XPThemeData *)clientData;
|
||||
ElementInfo *elementPtr = NULL;
|
||||
ClientData elementData;
|
||||
LPCWSTR className;
|
||||
@@ -1126,7 +1128,7 @@ Ttk_CreateVsapiElement(
|
||||
Ttk_ElementSpec *elementSpec = &GenericElementSpec;
|
||||
Tcl_DString classBuf;
|
||||
|
||||
static const char *optionStrings[] =
|
||||
static const char *const optionStrings[] =
|
||||
{ "-padding","-width","-height","-margins", "-syssize",
|
||||
"-halfheight", "-halfwidth", NULL };
|
||||
enum { O_PADDING, O_WIDTH, O_HEIGHT, O_MARGINS, O_SYSSIZE,
|
||||
@@ -1143,7 +1145,8 @@ Ttk_CreateVsapiElement(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
name = Tcl_GetStringFromObj(objv[0], &length);
|
||||
className = (LPCWSTR) Tcl_WinUtfToTChar(name, length, &classBuf);
|
||||
Tcl_DStringInit(&classBuf);
|
||||
className = Tcl_UtfToWCharDString(name, length, &classBuf);
|
||||
|
||||
/* flags or padding */
|
||||
if (objc > 3) {
|
||||
@@ -1218,7 +1221,7 @@ Ttk_CreateVsapiElement(
|
||||
if (Tcl_ListObjGetElements(interp, objv[2], &count, &specs) != TCL_OK)
|
||||
goto retErr;
|
||||
/* we over-allocate to ensure there is a terminating entry */
|
||||
stateTable = ckalloc(sizeof(Ttk_StateTable) * (count + 1));
|
||||
stateTable = (Ttk_StateTable *)ckalloc(sizeof(Ttk_StateTable) * (count + 1));
|
||||
memset(stateTable, 0, sizeof(Ttk_StateTable) * (count + 1));
|
||||
for (n = 0, j = 0; status == TCL_OK && n < count; n += 2, ++j) {
|
||||
Ttk_StateSpec spec = {0,0};
|
||||
@@ -1236,11 +1239,11 @@ Ttk_CreateVsapiElement(
|
||||
return status;
|
||||
}
|
||||
} else {
|
||||
stateTable = ckalloc(sizeof(Ttk_StateTable));
|
||||
stateTable = (Ttk_StateTable *)ckalloc(sizeof(Ttk_StateTable));
|
||||
memset(stateTable, 0, sizeof(Ttk_StateTable));
|
||||
}
|
||||
|
||||
elementPtr = ckalloc(sizeof(ElementInfo));
|
||||
elementPtr = (ElementInfo *)ckalloc(sizeof(ElementInfo));
|
||||
elementPtr->elementSpec = elementSpec;
|
||||
elementPtr->partId = partId;
|
||||
elementPtr->statemap = stateTable;
|
||||
@@ -1248,12 +1251,12 @@ Ttk_CreateVsapiElement(
|
||||
elementPtr->flags = HEAP_ELEMENT | flags;
|
||||
|
||||
/* set the element name to an allocated copy */
|
||||
name = ckalloc(strlen(elementName) + 1);
|
||||
name = (char *)ckalloc(strlen(elementName) + 1);
|
||||
strcpy(name, elementName);
|
||||
elementPtr->elementName = name;
|
||||
|
||||
/* set the class name to an allocated copy */
|
||||
wname = ckalloc(Tcl_DStringLength(&classBuf) + sizeof(WCHAR));
|
||||
wname = (LPWSTR)ckalloc(Tcl_DStringLength(&classBuf) + sizeof(WCHAR));
|
||||
wcscpy(wname, className);
|
||||
elementPtr->className = wname;
|
||||
|
||||
@@ -1281,11 +1284,7 @@ MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd)
|
||||
XPThemeProcs *procs;
|
||||
HINSTANCE hlibrary;
|
||||
Ttk_Theme themePtr, parentPtr, vistaPtr;
|
||||
ElementInfo *infoPtr;
|
||||
OSVERSIONINFOW os;
|
||||
|
||||
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
|
||||
GetVersionExW(&os);
|
||||
const ElementInfo *infoPtr;
|
||||
|
||||
procs = LoadXPThemeProcs(&hlibrary);
|
||||
if (!procs)
|
||||
@@ -1305,7 +1304,7 @@ MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd)
|
||||
* Set theme data and cleanup proc
|
||||
*/
|
||||
|
||||
themeData = ckalloc(sizeof(XPThemeData));
|
||||
themeData = (XPThemeData *)ckalloc(sizeof(XPThemeData));
|
||||
themeData->procs = procs;
|
||||
themeData->hlibrary = hlibrary;
|
||||
|
||||
@@ -1318,7 +1317,7 @@ MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd)
|
||||
* enable function. The theme itself is defined in script.
|
||||
*/
|
||||
|
||||
if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && os.dwMajorVersion > 5) {
|
||||
if (TkWinGetPlatformTheme() == TK_THEME_WIN_VISTA) {
|
||||
vistaPtr = Ttk_CreateTheme(interp, "vista", themePtr);
|
||||
if (vistaPtr) {
|
||||
Ttk_SetThemeEnabledProc(vistaPtr, XPThemeEnabled, themeData);
|
||||
|
||||
Reference in New Issue
Block a user