fix encoding of window titles in apple events. b=448087 r=smichaud sr=roc

This commit is contained in:
Josh Aas 2008-09-03 21:21:46 -04:00
Родитель bac21bef2f
Коммит 7be29ef19f
2 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -36,7 +36,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <MacWindows.h> #include "nsWindowUtils.h"
#include "nsCommandLineServiceMac.h" #include "nsCommandLineServiceMac.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -61,7 +61,6 @@
#include "nsIXULWindow.h" #include "nsIXULWindow.h"
#include "nsString.h" #include "nsString.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsWindowUtils.h"
#include "nsMacUtils.h" #include "nsMacUtils.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsIXULWindow.h" #include "nsIXULWindow.h"
@ -407,6 +406,8 @@ TAEListIndex nsWindowUtils::GetWindowIndex(TWindowKind windowKind, WindowPtr the
//--------------------------------------------------------- //---------------------------------------------------------
void nsWindowUtils::GetCleanedWindowName(WindowPtr wind, char* outName, long maxLen) void nsWindowUtils::GetCleanedWindowName(WindowPtr wind, char* outName, long maxLen)
{ {
outName[0] = '\0';
nsCOMPtr<nsIXULWindow> xulWindow; nsCOMPtr<nsIXULWindow> xulWindow;
GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow)); GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow));
ThrowErrIfNil(xulWindow, paramErr); ThrowErrIfNil(xulWindow, paramErr);
@ -425,9 +426,13 @@ void nsWindowUtils::GetCleanedWindowName(WindowPtr wind, char* outName, long max
baseWindow->GetTitle(getter_Copies(title)); baseWindow->GetTitle(getter_Copies(title));
ThrowErrIfNil(title, paramErr); ThrowErrIfNil(title, paramErr);
const char* cTitle = NS_ConvertUTF16toUTF8(title).get(); // convert to MacRoman, which is what AppleEvents expects
strncpy(outName, cTitle, maxLen); CFStringRef windowTitleCFString = ::CFStringCreateWithCharacters(kCFAllocatorDefault, title.get(), kCFStringEncodingUTF16);
outName[maxLen - 1] = '\0'; if (windowTitleCFString) {
::CFStringGetCString(windowTitleCFString, outName, maxLen, kCFStringEncodingMacRoman);
outName[maxLen - 1] = '\0'; // in case it didn't get null terminated
::CFRelease(windowTitleCFString);
}
} }
//--------------------------------------------------------- //---------------------------------------------------------

Просмотреть файл

@ -40,8 +40,7 @@
#ifndef nsWindowUtils_h_ #ifndef nsWindowUtils_h_
#define nsWindowUtils_h_ #define nsWindowUtils_h_
#include <Quickdraw.h> #include <Carbon/Carbon.h>
#include <MacWindows.h>
#include "nsAEDefs.h" #include "nsAEDefs.h"