summaryrefslogtreecommitdiffstats
path: root/win/tkWinDialog.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-05-05 13:55:47 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-05-05 13:55:47 (GMT)
commitfe2b88f2782fc8a4d6a9d7beda9900501f1548fd (patch)
tree62352d8b850165c0596647d8c111cbe3a2fbfd32 /win/tkWinDialog.c
parentba7ccfc695ea0f53f4afb2165fca6783d7dcfcd7 (diff)
downloadtk-fe2b88f2782fc8a4d6a9d7beda9900501f1548fd.zip
tk-fe2b88f2782fc8a4d6a9d7beda9900501f1548fd.tar.gz
tk-fe2b88f2782fc8a4d6a9d7beda9900501f1548fd.tar.bz2
On Windows, use Tcl_WinTCharToUtf() in stead of Tcl_NewUnicodeObj(), since Tcl_WinTCharToUtf() works correctly when TCL_UTF_MAX==6 while Tcl_NewUnicodeObj() doesn't.
All changes taken over from androwish. Thanks to Christian Werner! And ... on the go ... fixed a few memory leaks correctly detected by Christian.
Diffstat (limited to 'win/tkWinDialog.c')
-rw-r--r--win/tkWinDialog.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index a7d8c7d..635b9a3 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -1379,17 +1379,27 @@ static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr,
goto vamoose;
if (optsPtr->extObj != NULL) {
- wstr = Tcl_GetUnicode(optsPtr->extObj);
+ Tcl_DString ds;
+ const char *src;
+
+ src = Tcl_GetString(optsPtr->extObj);
+ wstr = (LPWSTR) Tcl_WinUtfToTChar(src, optsPtr->extObj->length, &ds);
if (wstr[0] == L'.')
++wstr;
hr = fdlgIf->lpVtbl->SetDefaultExtension(fdlgIf, wstr);
+ Tcl_DStringFree(&ds);
if (FAILED(hr))
goto vamoose;
}
if (optsPtr->titleObj != NULL) {
- hr = fdlgIf->lpVtbl->SetTitle(fdlgIf,
- Tcl_GetUnicode(optsPtr->titleObj));
+ Tcl_DString ds;
+ const char *src;
+
+ src = Tcl_GetString(optsPtr->titleObj);
+ wstr = (LPWSTR) Tcl_WinUtfToTChar(src, optsPtr->titleObj->length, &ds);
+ hr = fdlgIf->lpVtbl->SetTitle(fdlgIf, wstr);
+ Tcl_DStringFree(&ds);
if (FAILED(hr))
goto vamoose;
}
@@ -1464,12 +1474,14 @@ static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr,
SIGDN_FILESYSPATH, &wstr);
if (SUCCEEDED(hr)) {
Tcl_DString fnds;
+
ConvertExternalFilename(wstr, &fnds);
CoTaskMemFree(wstr);
Tcl_ListObjAppendElement(
interp, multiObj,
Tcl_NewStringObj(Tcl_DStringValue(&fnds),
Tcl_DStringLength(&fnds)));
+ Tcl_DStringFree(&fnds);
}
itemIf->lpVtbl->Release(itemIf);
if (FAILED(hr))
@@ -1490,10 +1502,12 @@ static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr,
&wstr);
if (SUCCEEDED(hr)) {
Tcl_DString fnds;
+
ConvertExternalFilename(wstr, &fnds);
resultObj = Tcl_NewStringObj(Tcl_DStringValue(&fnds),
Tcl_DStringLength(&fnds));
CoTaskMemFree(wstr);
+ Tcl_DStringFree(&fnds);
}
resultIf->lpVtbl->Release(resultIf);
}
@@ -1501,13 +1515,20 @@ static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr,
if (SUCCEEDED(hr)) {
if (filterPtr && optsPtr->typeVariableObj) {
UINT ftix;
+
hr = fdlgIf->lpVtbl->GetFileTypeIndex(fdlgIf, &ftix);
if (SUCCEEDED(hr)) {
/* Note ftix is a 1-based index */
if (ftix > 0 && ftix <= nfilters) {
+ Tcl_DString ftds;
+ Tcl_Obj *ftobj;
+
+ Tcl_WinTCharToUtf(filterPtr[ftix-1].pszName, -1, &ftds);
+ ftobj = Tcl_NewStringObj(Tcl_DStringValue(&ftds),
+ Tcl_DStringLength(&ftds));
Tcl_ObjSetVar2(interp, optsPtr->typeVariableObj, NULL,
- Tcl_NewUnicodeObj(filterPtr[ftix-1].pszName, -1),
- TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
+ ftobj, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
+ Tcl_DStringFree(&ftds);
}
}
}
@@ -2786,6 +2807,9 @@ Tk_MessageBoxObjCmd(
};
ThreadSpecificData *tsdPtr =
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ Tcl_DString titleBuf, tmpBuf;
+ WCHAR *titlePtr, *tmpPtr;
+ const char *src;
defaultBtn = -1;
detailObj = NULL;
@@ -2896,7 +2920,9 @@ Tk_MessageBoxObjCmd(
: Tcl_NewUnicodeObj(NULL, 0);
Tcl_IncrRefCount(tmpObj);
if (detailObj) {
- Tcl_AppendUnicodeToObj(tmpObj, L"\n\n", 2);
+ const Tcl_UniChar twoNL[] = { '\n', '\n' };
+
+ Tcl_AppendUnicodeToObj(tmpObj, twoNL, 2);
Tcl_AppendObjToObj(tmpObj, detailObj);
}
@@ -2915,8 +2941,18 @@ Tk_MessageBoxObjCmd(
tsdPtr->hBigIcon = TkWinGetIcon(parent, ICON_BIG);
tsdPtr->hMsgBoxHook = SetWindowsHookEx(WH_CBT, MsgBoxCBTProc, NULL,
GetCurrentThreadId());
- winCode = MessageBox(hWnd, Tcl_GetUnicode(tmpObj),
- titleObj ? Tcl_GetUnicode(titleObj) : L"", flags);
+ src = Tcl_GetString(tmpObj);
+ tmpPtr = Tcl_WinUtfToTChar(src, tmpObj->length, &tmpBuf);
+ if (titleObj != NULL) {
+ src = Tcl_GetString(titleObj);
+ titlePtr = Tcl_WinUtfToTChar(src, titleObj->length, &titleBuf);
+ } else {
+ titlePtr = L"";
+ Tcl_DStringInit(&titleBuf);
+ }
+ winCode = MessageBox(hWnd, tmpPtr, titlePtr, flags);
+ Tcl_DStringFree(&titleBuf);
+ Tcl_DStringFree(&tmpBuf);
UnhookWindowsHookEx(tsdPtr->hMsgBoxHook);
(void) Tcl_SetServiceMode(oldMode);