From df086e4a71ebe3c21eabbb7aa511803887ff800a Mon Sep 17 00:00:00 2001 From: "ftang%netscape.com" Date: Sun, 9 Jan 2000 23:52:02 +0000 Subject: [PATCH] fix window title conversion bug. r=jshin@pantheon.yale.edu convert PRUnichar* to the locale encoding before pass to gtk. git-svn-id: svn://10.0.0.236/trunk@57247 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/gtk/nsWindow.cpp | 53 ++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/mozilla/widget/src/gtk/nsWindow.cpp b/mozilla/widget/src/gtk/nsWindow.cpp index ad37323d40d..144f7577221 100644 --- a/mozilla/widget/src/gtk/nsWindow.cpp +++ b/mozilla/widget/src/gtk/nsWindow.cpp @@ -47,6 +47,10 @@ #include "nsClipboard.h" #include "nsIRollupListener.h" +#include "nsICharsetConverterManager.h" +#include "nsIPlatformCharset.h" +#include "nsIServiceManager.h" + #include "nsGtkUtils.h" // for nsGtkUtils::gdk_window_flash() #undef DEBUG_DND_XLATE @@ -1792,8 +1796,55 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsString& aTitle) if (!mShell) return NS_ERROR_FAILURE; - gtk_window_set_title(GTK_WINDOW(mShell), nsAutoCString(aTitle)); + nsresult result; + static nsIUnicodeEncoder* converter = nsnull; + static int initialized = 0; + if (!initialized) { + initialized = 1; + result = NS_ERROR_FAILURE; + NS_WITH_SERVICE(nsIPlatformCharset, platform, NS_PLATFORMCHARSET_PROGID, + &result); + if (platform && NS_SUCCEEDED(result)) { + nsAutoString charset(""); + result = platform->GetCharset(kPlatformCharsetSel_WindowManager, charset); + if (NS_SUCCEEDED(result) && (charset.Length() > 0)) { + NS_WITH_SERVICE(nsICharsetConverterManager, manager, + NS_CHARSETCONVERTERMANAGER_PROGID, &result); + if (manager && NS_SUCCEEDED(result)) { + result = manager->GetUnicodeEncoder(&charset, &converter); + if (NS_FAILED(result) && converter) { + NS_RELEASE(converter); + converter = nsnull; + } + else if (converter) { + result = converter->SetOutputErrorBehavior( + nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); + } + } + } + } + NS_ASSERTION(converter, "cannot get convert for window title"); + } + + if (converter) { + char titleStr[256]; + titleStr[0] = 0; + PRInt32 srcLen = aTitle.Length() + 1; + PRInt32 destLen = sizeof(titleStr); + titleStr[destLen] = 0; + result = converter->Convert(aTitle.GetUnicode(), &srcLen, titleStr, + &destLen); + NS_ASSERTION(NS_SUCCEEDED(result), "cannot convert title string"); + if (titleStr[0] && NS_SUCCEEDED(result)) { + titleStr[destLen] = 0; +printf("title string = [%s]\n", titleStr); + gtk_window_set_title(GTK_WINDOW(mShell), titleStr); + return NS_OK; + } + } + // fallback to use bad conversion + gtk_window_set_title(GTK_WINDOW(mShell), nsAutoCString(aTitle)); return NS_OK; }