summaryrefslogtreecommitdiffstats
path: root/win/ttkWinXPTheme.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-03-15 20:24:47 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-03-15 20:24:47 (GMT)
commit5d3696a737a0d6cbfc1c3eda16547cff2f9078d7 (patch)
treead635935285c9cb8e34d1f1c7cb147700351236e /win/ttkWinXPTheme.c
parente7ffce5e2c326fd4b70d785a4cab86708aa9c9df (diff)
downloadtk-5d3696a737a0d6cbfc1c3eda16547cff2f9078d7.zip
tk-5d3696a737a0d6cbfc1c3eda16547cff2f9078d7.tar.gz
tk-5d3696a737a0d6cbfc1c3eda16547cff2f9078d7.tar.bz2
Make Tk run on win32/win64 using -DTCL_UTF_MAX=6. Adapted from androwish.
Diffstat (limited to 'win/ttkWinXPTheme.c')
-rw-r--r--win/ttkWinXPTheme.c53
1 files changed, 37 insertions, 16 deletions
diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c
index 3de1504..b828221 100644
--- a/win/ttkWinXPTheme.c
+++ b/win/ttkWinXPTheme.c
@@ -455,7 +455,7 @@ InitElementData(ElementData *elementData, Tk_Window tkwin, Drawable d)
{
Window win = Tk_WindowId(tkwin);
- if (win != None) {
+ if (win) {
elementData->hwnd = Tk_GetHWND(win);
} else {
elementData->hwnd = elementData->procs->stubWindow;
@@ -829,16 +829,21 @@ static void TextElementSize(
ElementData *elementData = clientData;
RECT rc = {0, 0};
HRESULT hr = S_OK;
+ const char *src;
+ int len;
+ Tcl_DString ds;
if (!InitElementData(elementData, tkwin, 0))
return;
+ src = Tcl_GetStringFromObj(element->textObj, &len);
+ Tcl_WinUtfToTChar(src, len, &ds);
hr = elementData->procs->GetThemeTextExtent(
elementData->hTheme,
elementData->hDC,
elementData->info->partId,
Ttk_StateTableLookup(elementData->info->statemap, 0),
- Tcl_GetUnicode(element->textObj),
+ (WCHAR *) Tcl_DStringValue(&ds),
-1,
DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
NULL,
@@ -851,6 +856,7 @@ static void TextElementSize(
if (*widthPtr < 80) *widthPtr = 80;
if (*heightPtr < 20) *heightPtr = 20;
+ Tcl_DStringFree(&ds);
FreeElementData(elementData);
}
@@ -862,20 +868,27 @@ static void TextElementDraw(
ElementData *elementData = clientData;
RECT rc = BoxToRect(b);
HRESULT hr = S_OK;
+ const char *src;
+ int len;
+ Tcl_DString ds;
if (!InitElementData(elementData, tkwin, d))
return;
+ src = Tcl_GetStringFromObj(element->textObj, &len);
+ Tcl_WinUtfToTChar(src, len, &ds);
hr = elementData->procs->DrawThemeText(
elementData->hTheme,
elementData->hDC,
elementData->info->partId,
Ttk_StateTableLookup(elementData->info->statemap, state),
- Tcl_GetUnicode(element->textObj),
+ (WCHAR *) Tcl_DStringValue(&ds),
-1,
DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
(state & TTK_STATE_DISABLED) ? DTT_GRAYED : 0,
&rc);
+
+ Tcl_DStringFree(&ds);
FreeElementData(elementData);
}
@@ -1102,7 +1115,7 @@ Ttk_CreateVsapiElement(
XPThemeData *themeData = clientData;
ElementInfo *elementPtr = NULL;
ClientData elementData;
- Tcl_UniChar *className;
+ WCHAR *className;
int partId = 0;
Ttk_StateTable *stateTable;
Ttk_Padding pad = {0, 0, 0, 0};
@@ -1111,6 +1124,7 @@ Ttk_CreateVsapiElement(
char *name;
LPWSTR wname;
Ttk_ElementSpec *elementSpec = &GenericElementSpec;
+ Tcl_DString classBuf;
static const char *optionStrings[] =
{ "-padding","-width","-height","-margins", "-syssize",
@@ -1128,7 +1142,8 @@ Ttk_CreateVsapiElement(
if (Tcl_GetIntFromObj(interp, objv[1], &partId) != TCL_OK) {
return TCL_ERROR;
}
- className = Tcl_GetUnicodeFromObj(objv[0], &length);
+ name = Tcl_GetStringFromObj(objv[0], &length);
+ className = (WCHAR *) Tcl_WinUtfToTChar(name, length, &classBuf);
/* flags or padding */
if (objc > 3) {
@@ -1140,54 +1155,54 @@ Ttk_CreateVsapiElement(
"Missing value for \"%s\".",
Tcl_GetString(objv[i])));
Tcl_SetErrorCode(interp, "TTK", "VSAPI", "MISSING", NULL);
- return TCL_ERROR;
+ goto retErr;
}
if (Tcl_GetIndexFromObjStruct(interp, objv[i], optionStrings,
sizeof(char *), "option", 0, &option) != TCL_OK)
- return TCL_ERROR;
+ goto retErr;
switch (option) {
case O_PADDING:
if (Ttk_GetBorderFromObj(interp, objv[i+1], &pad) != TCL_OK) {
- return TCL_ERROR;
+ goto retErr;
}
break;
case O_MARGINS:
if (Ttk_GetBorderFromObj(interp, objv[i+1], &pad) != TCL_OK) {
- return TCL_ERROR;
+ goto retErr;
}
flags |= PAD_MARGINS;
break;
case O_WIDTH:
if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
- return TCL_ERROR;
+ goto retErr;
}
pad.left = pad.right = tmp;
flags |= IGNORE_THEMESIZE;
break;
case O_HEIGHT:
if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
- return TCL_ERROR;
+ goto retErr;
}
pad.top = pad.bottom = tmp;
flags |= IGNORE_THEMESIZE;
break;
case O_SYSSIZE:
if (GetSysFlagFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
- return TCL_ERROR;
+ goto retErr;
}
elementSpec = &GenericSizedElementSpec;
flags |= (tmp & 0xFFFF);
break;
case O_HALFHEIGHT:
if (Tcl_GetBooleanFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
- return TCL_ERROR;
+ goto retErr;
}
if (tmp)
flags |= HALF_HEIGHT;
break;
case O_HALFWIDTH:
if (Tcl_GetBooleanFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
- return TCL_ERROR;
+ goto retErr;
}
if (tmp)
flags |= HALF_WIDTH;
@@ -1201,7 +1216,7 @@ Ttk_CreateVsapiElement(
Tcl_Obj **specs;
int n,j,count, status = TCL_OK;
if (Tcl_ListObjGetElements(interp, objv[2], &count, &specs) != TCL_OK)
- return TCL_ERROR;
+ goto retErr;
/* we over-allocate to ensure there is a terminating entry */
stateTable = ckalloc(sizeof(Ttk_StateTable) * (count + 1));
memset(stateTable, 0, sizeof(Ttk_StateTable) * (count + 1));
@@ -1217,6 +1232,7 @@ Ttk_CreateVsapiElement(
}
if (status != TCL_OK) {
ckfree(stateTable);
+ Tcl_DStringFree(&classBuf);
return status;
}
} else {
@@ -1237,7 +1253,7 @@ Ttk_CreateVsapiElement(
elementPtr->elementName = name;
/* set the class name to an allocated copy */
- wname = ckalloc(sizeof(WCHAR) * (length + 1));
+ wname = ckalloc(Tcl_DStringLength(&classBuf) + sizeof(WCHAR));
wcscpy(wname, className);
elementPtr->className = wname;
@@ -1247,7 +1263,12 @@ Ttk_CreateVsapiElement(
Ttk_RegisterCleanup(interp, elementData, DestroyElementData);
Tcl_SetObjResult(interp, Tcl_NewStringObj(elementName, -1));
+ Tcl_DStringFree(&classBuf);
return TCL_OK;
+
+retErr:
+ Tcl_DStringFree(&classBuf);
+ return TCL_ERROR;
}
/*----------------------------------------------------------------------