summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tkFocus.c6
-rw-r--r--generic/tkImgGIF.c2
-rw-r--r--generic/tkMain.c39
-rw-r--r--tests/unixButton.test2
-rw-r--r--unix/tkUnixMenu.c6
-rw-r--r--win/tkWinDialog.c7
-rw-r--r--win/tkWinMenu.c16
-rw-r--r--win/ttkWinXPTheme.c53
8 files changed, 82 insertions, 49 deletions
diff --git a/generic/tkFocus.c b/generic/tkFocus.c
index c621bf9..eae981e 100644
--- a/generic/tkFocus.c
+++ b/generic/tkFocus.c
@@ -630,7 +630,7 @@ TkSetFocusWin(
tlFocusPtr->focusWinPtr = winPtr;
if (topLevelPtr->flags & TK_EMBEDDED) {
-
+
/*
* We are assigning focus to an embedded toplevel. The platform
* specific function TkpClaimFocus needs to handle the job of
@@ -646,7 +646,7 @@ TkSetFocusWin(
* toplevel from a different application, clear the focus in that
* application.
*/
-
+
if (force) {
TkWindow *focusPtr = winPtr->dispPtr->focusPtr;
if (focusPtr && focusPtr->mainPtr != winPtr->mainPtr) {
@@ -660,7 +660,7 @@ TkSetFocusWin(
* Call the platform specific function TkpChangeFocus to move the
* window manager's focus to a new toplevel.
*/
-
+
serial = TkpChangeFocus(TkpGetWrapperWindow(topLevelPtr), force);
if (serial != 0) {
displayFocusPtr->focusSerial = serial;
diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c
index 67c6a06..da62d1f 100644
--- a/generic/tkImgGIF.c
+++ b/generic/tkImgGIF.c
@@ -1260,7 +1260,7 @@ ReadImage(
*
* The field "stack" is abused for temporary buffer. it has 4096 bytes
* and we need 256.
- *
+ *
* Loop until we hit a 0 length block which is the end sign.
*/
while ( 0 < (count = GetDataBlock(gifConfPtr, chan, stack)))
diff --git a/generic/tkMain.c b/generic/tkMain.c
index eb311ff..a52f1b3 100644
--- a/generic/tkMain.c
+++ b/generic/tkMain.c
@@ -71,22 +71,35 @@ extern const TclIntPlatStubs *tclIntPlatStubsPtr;
#endif
/*
- * Further on, in UNICODE mode, we need to use Tcl_NewUnicodeObj,
- * while otherwise NewNativeObj is needed (which provides proper
- * conversion from native encoding to UTF-8).
+ * Further on, in UNICODE mode we just use Tcl_NewUnicodeObj, otherwise
+ * NewNativeObj is needed (which provides proper conversion from native
+ * encoding to UTF-8).
*/
-#ifdef UNICODE
+
+#if defined(UNICODE) && (TCL_UTF_MAX <= 4)
# define NewNativeObj Tcl_NewUnicodeObj
-#else /* !UNICODE */
- static Tcl_Obj *NewNativeObj(char *string, int length) {
- Tcl_Obj *obj;
- Tcl_DString ds;
- Tcl_ExternalToUtfDString(NULL, string, length, &ds);
- obj = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
- Tcl_DStringFree(&ds);
- return obj;
+#else /* !UNICODE || (TCL_UTF_MAX > 4) */
+static inline Tcl_Obj *
+NewNativeObj(
+ TCHAR *string,
+ int length)
+{
+ Tcl_Obj *obj;
+ Tcl_DString ds;
+
+#ifdef UNICODE
+ if (length > 0) {
+ length *= sizeof(WCHAR);
+ }
+ Tcl_WinTCharToUtf(string, length, &ds);
+#else
+ Tcl_ExternalToUtfDString(NULL, (char *) string, length, &ds);
+#endif
+ obj = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
+ Tcl_DStringFree(&ds);
+ return obj;
}
-#endif /* !UNICODE */
+#endif /* !UNICODE || (TCL_UTF_MAX > 4) */
/*
* Declarations for various library functions and variables (don't want to
diff --git a/tests/unixButton.test b/tests/unixButton.test
index 9d54707..f0dcde5 100644
--- a/tests/unixButton.test
+++ b/tests/unixButton.test
@@ -200,7 +200,7 @@ test unixbutton-1.9 {TkpComputeButtonGeometry procedure} -constraints {
list [winfo reqwidth .b2] [winfo reqheight .b2]
} -cleanup {
deleteWindows
-} -result [list [expr {17 + $defaultBorder}] [expr {27 + $defaultBorder}]]
+} -result [list [expr {17 + $defaultBorder}] [expr {27 + $defaultBorder}]]
test unixbutton-1.10 {TkpComputeButtonGeometry procedure} -constraints {
unix
} -setup {
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index d62cd50..3b29a8c 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -856,11 +856,7 @@ DrawMenuUnderline(
if ((mePtr->underline >= 0) && (mePtr->labelPtr != NULL)) {
int len;
- /*
- * Do the unicode call just to prevent overruns.
- */
-
- Tcl_GetUnicodeFromObj(mePtr->labelPtr, &len);
+ len = Tcl_GetCharLength(mePtr->labelPtr);
if (mePtr->underline < len) {
int activeBorderWidth, leftEdge;
const char *label, *start, *end;
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index 11b556a..42a588b 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -2911,13 +2911,10 @@ Tk_MessageBoxObjCmd(
flags |= icon | type | MB_TASKMODAL | MB_SETFOREGROUND;
- tmpObj = messageObj ? Tcl_DuplicateObj(messageObj)
- : Tcl_NewUnicodeObj(NULL, 0);
+ tmpObj = messageObj ? Tcl_DuplicateObj(messageObj) : Tcl_NewObj();
Tcl_IncrRefCount(tmpObj);
if (detailObj) {
- const Tcl_UniChar twoNL[] = { '\n', '\n' };
-
- Tcl_AppendUnicodeToObj(tmpObj, twoNL, 2);
+ Tcl_AppendStringsToObj(tmpObj, "\n\n", NULL);
Tcl_AppendObjToObj(tmpObj, detailObj);
}
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c
index 1896474..779f68c 100644
--- a/win/tkWinMenu.c
+++ b/win/tkWinMenu.c
@@ -1249,7 +1249,9 @@ TkWinHandleMenuEvent(
if (hashEntryPtr != NULL) {
int i, len, underline;
Tcl_Obj *labelPtr;
- Tcl_UniChar *wlabel, menuChar;
+ WCHAR *wlabel;
+ Tcl_UniChar menuChar;
+ Tcl_DString ds;
*plResult = 0;
menuPtr = Tcl_GetHashValue(hashEntryPtr);
@@ -1259,6 +1261,7 @@ TkWinHandleMenuEvent(
*/
menuChar = Tcl_UniCharToUpper((Tcl_UniChar) LOWORD(*pwParam));
+ Tcl_DStringInit(&ds);
for (i = 0; i < menuPtr->numEntries; i++) {
underline = menuPtr->entries[i]->underline;
labelPtr = menuPtr->entries[i]->labelPtr;
@@ -1266,7 +1269,10 @@ TkWinHandleMenuEvent(
/*
* Ensure we don't exceed the label length, then check
*/
- wlabel = Tcl_GetUnicodeFromObj(labelPtr, &len);
+ const char *src = Tcl_GetStringFromObj(labelPtr, &len);
+
+ Tcl_DStringFree(&ds);
+ wlabel = (WCHAR *) Tcl_WinUtfToTChar(src, len, &ds);
if ((underline < len) && (menuChar ==
Tcl_UniCharToUpper(wlabel[underline]))) {
*plResult = (2 << 16) | i;
@@ -1275,6 +1281,7 @@ TkWinHandleMenuEvent(
}
}
}
+ Tcl_DStringFree(&ds);
}
break;
}
@@ -2070,8 +2077,7 @@ DrawMenuUnderline(
if ((mePtr->underline >= 0) && (mePtr->labelPtr != NULL)) {
int len;
- /* do the unicode call just to prevent overruns */
- Tcl_GetUnicodeFromObj(mePtr->labelPtr, &len);
+ len = Tcl_GetCharLength(mePtr->labelPtr);
if (mePtr->underline < len) {
const char *label, *start, *end;
@@ -2466,7 +2472,7 @@ DrawMenuEntryLabel(
XFillRectangle(menuPtr->display, d, menuPtr->disabledGC, x, y,
(unsigned) width, (unsigned) height);
} else if ((mePtr->image != NULL)
- && (menuPtr->disabledImageGC != NULL)) {
+ && menuPtr->disabledImageGC) {
XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC,
leftEdge + imageXOffset,
(int) (y + (mePtr->height - imageHeight)/2 + imageYOffset),
diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c
index 4f822a7..fd6571f 100644
--- a/win/ttkWinXPTheme.c
+++ b/win/ttkWinXPTheme.c
@@ -451,7 +451,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;
@@ -825,16 +825,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,
@@ -847,6 +852,7 @@ static void TextElementSize(
if (*widthPtr < 80) *widthPtr = 80;
if (*heightPtr < 20) *heightPtr = 20;
+ Tcl_DStringFree(&ds);
FreeElementData(elementData);
}
@@ -858,20 +864,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);
}
@@ -1098,7 +1111,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};
@@ -1107,6 +1120,7 @@ Ttk_CreateVsapiElement(
char *name;
LPWSTR wname;
Ttk_ElementSpec *elementSpec = &GenericElementSpec;
+ Tcl_DString classBuf;
static const char *const optionStrings[] =
{ "-padding","-width","-height","-margins", "-syssize",
@@ -1124,7 +1138,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) {
@@ -1136,54 +1151,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;
@@ -1197,7 +1212,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));
@@ -1213,6 +1228,7 @@ Ttk_CreateVsapiElement(
}
if (status != TCL_OK) {
ckfree(stateTable);
+ Tcl_DStringFree(&classBuf);
return status;
}
} else {
@@ -1233,7 +1249,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;
@@ -1243,7 +1259,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;
}
/*----------------------------------------------------------------------