Bug 635170 - DeCOM nsIWin32Locale. r=smontagu

--HG--
rename : intl/locale/public/nsIWin32Locale.h => intl/locale/public/nsWin32Locale.h
rename : intl/locale/src/windows/nsIWin32LocaleImpl.cpp => intl/locale/src/windows/nsWin32Locale.cpp
This commit is contained in:
Brandon Bohrer 2011-05-02 17:49:11 +09:00
parent 383c1ab2db
commit 05dece2bf6
11 changed files with 74 additions and 178 deletions

View File

@ -92,7 +92,6 @@ NS_DEFINE_NAMED_CID(NS_LANGUAGEATOMSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_CHARSETALIAS_CID);
NS_DEFINE_NAMED_CID(NS_PLATFORMCHARSET_CID);
#ifdef XP_WIN
NS_DEFINE_NAMED_CID(NS_WIN32LOCALE_CID);
NS_DEFINE_NAMED_CID(NS_COLLATION_CID);
NS_DEFINE_NAMED_CID(NS_DATETIMEFORMAT_CID);
#endif
@ -130,7 +129,6 @@ static const mozilla::Module::CIDEntry kIntlCIDs[] = {
{ &kNS_CHARSETALIAS_CID, false, NULL, nsCharsetAlias2Constructor },
{ &kNS_PLATFORMCHARSET_CID, false, NULL, nsPlatformCharsetConstructor },
#ifdef XP_WIN
{ &kNS_WIN32LOCALE_CID, false, NULL, nsIWin32LocaleImplConstructor },
{ &kNS_COLLATION_CID, false, NULL, nsCollationWinConstructor },
{ &kNS_DATETIMEFORMAT_CID, false, NULL, nsDateTimeFormatWinConstructor },
#endif
@ -170,7 +168,6 @@ static const mozilla::Module::ContractIDEntry kIntlContracts[] = {
{ NS_CHARSETALIAS_CONTRACTID, &kNS_CHARSETALIAS_CID },
{ NS_PLATFORMCHARSET_CONTRACTID, &kNS_PLATFORMCHARSET_CID },
#ifdef XP_WIN
{ NS_WIN32LOCALE_CONTRACTID, &kNS_WIN32LOCALE_CID },
{ NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID },
{ NS_DATETIMEFORMAT_CONTRACTID, &kNS_DATETIMEFORMAT_CID },
#endif

View File

@ -52,7 +52,7 @@ EXPORTS = \
nsIMacLocale.h \
nsIPosixLocale.h \
nsIOS2Locale.h \
nsIWin32Locale.h \
nsWin32Locale.h \
nsICharsetAlias.h \
nsIPlatformCharset.h \
nsLocaleCID.h \

View File

@ -34,29 +34,31 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIWin32Locale_h__
#define nsIWin32Locale_h__
#ifndef nsWin32Locale_h__
#define nsWin32Locale_h__
#include "nsISupports.h"
#include "nscore.h"
#include "nsString.h"
#include <windows.h>
// {D92D57C2-BA1D-11d2-AF0C-0060089FE59B}
#define NS_IWIN32LOCALE_IID \
{ 0xd92d57c2, 0xba1d, 0x11d2, \
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
class nsWin32Locale {
public:
static nsresult GetPlatformLocale(const nsAString& locale, LCID* winLCID);
static void GetXPLocale(LCID winLCID, nsAString& locale);
class nsIWin32Locale : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIN32LOCALE_IID)
private:
// Static class - Don't allow instantiation.
nsWin32Locale(void) {}
NS_IMETHOD GetPlatformLocale(const nsAString& locale, LCID* winLCID) = 0;
NS_IMETHOD GetXPLocale(LCID winLCID, nsAString& locale) = 0;
typedef LCID (WINAPI*LocaleNameToLCIDPtr)(LPCWSTR lpName, DWORD dwFlags);
typedef int (WINAPI*LCIDToLocaleNamePtr)(LCID Locale, LPWSTR lpName,
int cchName, DWORD dwFlags);
static LocaleNameToLCIDPtr localeNameToLCID;
static LCIDToLocaleNamePtr lcidToLocaleName;
static void initFunctionPointers ();
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIWin32Locale, NS_IWIN32LOCALE_IID)
#endif

View File

@ -59,7 +59,6 @@
#endif
#ifdef XP_WIN
#include "nsIwin32LocaleImpl.h"
#include "nsCollationWin.h"
#include "nsDateTimeFormatWin.h"
#endif
@ -107,7 +106,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsCharsetAlias2)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPlatformCharset, Init)
#ifdef XP_WIN
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIWin32LocaleImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationWin)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDateTimeFormatWin)
#endif

View File

@ -55,7 +55,7 @@
#include <ctype.h>
#if defined(XP_WIN)
# include "nsIWin32Locale.h"
# include "nsWin32Locale.h"
#elif defined(XP_OS2)
# include "unidef.h"
# include "nsIOS2Locale.h"
@ -138,34 +138,24 @@ nsLocaleService::nsLocaleService(void)
: mSystemLocale(0), mApplicationLocale(0)
{
#ifdef XP_WIN
nsCOMPtr<nsIWin32Locale> win32Converter = do_GetService(NS_WIN32LOCALE_CONTRACTID);
NS_ASSERTION(win32Converter, "nsLocaleService: can't get win32 converter\n");
nsAutoString xpLocale;
if (win32Converter) {
nsresult result;
//
// get the system LCID
//
LCID win_lcid = GetSystemDefaultLCID();
if (win_lcid==0) { return;}
result = win32Converter->GetXPLocale(win_lcid, xpLocale);
if (NS_FAILED(result)) { return;}
result = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
if (NS_FAILED(result)) { return;}
//
// get the system LCID
//
LCID win_lcid = GetSystemDefaultLCID();
NS_ENSURE_TRUE(win_lcid, );
nsWin32Locale::GetXPLocale(win_lcid, xpLocale);
nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
NS_ENSURE_SUCCESS(rv, );
//
// get the application LCID
//
win_lcid = GetUserDefaultLCID();
if (win_lcid==0) { return;}
result = win32Converter->GetXPLocale(win_lcid, xpLocale);
if (NS_FAILED(result)) { return;}
result = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale));
if (NS_FAILED(result)) { return;}
}
//
// get the application LCID
//
win_lcid = GetUserDefaultLCID();
NS_ENSURE_TRUE(win_lcid, );
nsWin32Locale::GetXPLocale(win_lcid, xpLocale);
rv = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale));
NS_ENSURE_SUCCESS(rv, );
#endif
#if defined(XP_UNIX) && !defined(XP_MACOSX)
nsCOMPtr<nsIPosixLocale> posixConverter = do_GetService(NS_POSIXLOCALE_CONTRACTID);

View File

@ -51,7 +51,7 @@ LIBXUL_LIBRARY = 1
CPPSRCS = \
nsCollationWin.cpp \
nsDateTimeFormatWin.cpp \
nsIWin32LocaleImpl.cpp \
nsWin32Locale.cpp \
nsWinCharset.cpp \
$(NULL)

View File

@ -43,7 +43,7 @@
#include "nsLocaleCID.h"
#include "nsILocaleService.h"
#include "nsIPlatformCharset.h"
#include "nsIWin32Locale.h"
#include "nsWin32Locale.h"
#include "nsCOMPtr.h"
#include "prmem.h"
#include "plstr.h"
@ -100,14 +100,10 @@ nsresult nsCollationWin::Initialize(nsILocale* locale)
}
// Get LCID and charset name from locale, if available
nsCOMPtr <nsIWin32Locale> win32Locale =
do_GetService(NS_WIN32LOCALE_CONTRACTID);
if (win32Locale) {
LCID lcid;
res = win32Locale->GetPlatformLocale(localeStr, &lcid);
if (NS_SUCCEEDED(res)) {
mLCID = lcid;
}
LCID lcid;
res = nsWin32Locale::GetPlatformLocale(localeStr, &lcid);
if (NS_SUCCEEDED(res)) {
mLCID = lcid;
}
nsCOMPtr <nsIPlatformCharset> platformCharset =

View File

@ -41,7 +41,7 @@
#include "nsIComponentManager.h"
#include "nsLocaleCID.h"
#include "nsILocaleService.h"
#include "nsIWin32Locale.h"
#include "nsWin32Locale.h"
#include "nsUnicharUtils.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
@ -102,11 +102,7 @@ nsresult nsDateTimeFormatWin::Initialize(nsILocale* locale)
// Get LCID and charset name from locale, if available
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
mLocale.Assign(localeStr); // cache locale name
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(NS_WIN32LOCALE_CONTRACTID);
if (win32Locale) {
res = win32Locale->GetPlatformLocale(mLocale, (LCID *) &mLCID);
}
res = nsWin32Locale::GetPlatformLocale(mLocale, (LCID *) &mLCID);
}
return res;

View File

@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIWin32LocaleImpl_h__
#define nsIWin32LocaleImpl_h__
#include "nsISupports.h"
#include "nscore.h"
#include "nsString.h"
#include "nsIWin32Locale.h"
#include <windows.h>
class nsIWin32LocaleImpl: public nsIWin32Locale
{
NS_DECL_ISUPPORTS
public:
nsIWin32LocaleImpl(void);
~nsIWin32LocaleImpl(void);
NS_IMETHOD GetPlatformLocale(const nsAString& locale, LCID* winLCID);
NS_IMETHOD GetXPLocale(LCID winLCID, nsAString& locale);
typedef LCID (WINAPI*LocaleNameToLCIDPtr)(LPCWSTR lpName, DWORD dwFlags);
typedef int (WINAPI*LCIDToLocaleNamePtr)(LCID Locale, LPWSTR lpName,
int cchName, DWORD dwFlags);
static LocaleNameToLCIDPtr localeNameToLCID;
static LCIDToLocaleNamePtr lcidToLocaleName;
private:
static HMODULE sKernelDLL;
};
#endif

View File

@ -35,17 +35,15 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.h"
#include "nscore.h"
#include "nsString.h"
#include "nsXPCOMStrings.h"
#include "nsReadableUtils.h"
#include "nsIwin32LocaleImpl.h"
#include "nsWin32Locale.h"
#include "nsLocaleCID.h"
#include "prprf.h"
#include <windows.h>
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "nsXPCOMStrings.h"
struct iso_pair
{
@ -60,9 +58,8 @@ struct iso_map
iso_pair sublang_list[20];
};
HMODULE nsIWin32LocaleImpl::sKernelDLL = NULL;
nsIWin32LocaleImpl::LocaleNameToLCIDPtr nsIWin32LocaleImpl::localeNameToLCID = NULL;
nsIWin32LocaleImpl::LCIDToLocaleNamePtr nsIWin32LocaleImpl::lcidToLocaleName = NULL;
nsWin32Locale::LocaleNameToLCIDPtr nsWin32Locale::localeNameToLCID = NULL;
nsWin32Locale::LCIDToLocaleNamePtr nsWin32Locale::lcidToLocaleName = NULL;
// Older versions of VC++ and Win32 SDK and mingw don't have
// macros for languages and sublanguages recently added to Win32.
@ -606,34 +603,31 @@ iso_pair dbg_list[] =
#define CROATIAN_ISO_CODE "hr"
#define SERBIAN_ISO_CODE "sr"
/* nsIWin32LocaleImpl */
NS_IMPL_ISUPPORTS1(nsIWin32LocaleImpl,nsIWin32Locale)
nsIWin32LocaleImpl::nsIWin32LocaleImpl(void)
void
nsWin32Locale::initFunctionPointers(void)
{
static PRBool sInitialized = PR_FALSE;
// We use the Vista and above functions if we have them
sKernelDLL = LoadLibraryW(L"kernel32.dll");
if (sKernelDLL) {
localeNameToLCID = (LocaleNameToLCIDPtr) GetProcAddress(sKernelDLL, "LocaleNameToLCID");
lcidToLocaleName = (LCIDToLocaleNamePtr) GetProcAddress(sKernelDLL, "LCIDToLocaleName");
if (!sInitialized) {
HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
if (kernelDLL) {
localeNameToLCID = (LocaleNameToLCIDPtr) GetProcAddress(kernelDLL, "LocaleNameToLCID");
lcidToLocaleName = (LCIDToLocaleNamePtr) GetProcAddress(kernelDLL, "LCIDToLocaleName");
}
sInitialized = PR_TRUE;
}
}
nsIWin32LocaleImpl::~nsIWin32LocaleImpl(void)
{
if (sKernelDLL)
FreeLibrary(sKernelDLL);
}
//
// the mapping routines are a first approximation to get us going on
// the tier-1 languages. we are making an assumption that we can map
// language and country codes separately on Windows, which isn't true
//
NS_IMETHODIMP
nsIWin32LocaleImpl::GetPlatformLocale(const nsAString& locale,LCID* winLCID)
nsresult
nsWin32Locale::GetPlatformLocale(const nsAString& locale, LCID* winLCID)
{
initFunctionPointers ();
if (localeNameToLCID) {
nsAutoString locale_autostr(locale);
LCID lcid = localeNameToLCID(locale_autostr.get(), 0);
@ -683,9 +677,11 @@ nsIWin32LocaleImpl::GetPlatformLocale(const nsAString& locale,LCID* winLCID)
#define LOCALE_NAME_MAX_LENGTH 85
#endif
NS_IMETHODIMP
nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsAString& locale)
void
nsWin32Locale::GetXPLocale(LCID winLCID, nsAString& locale)
{
initFunctionPointers ();
if (lcidToLocaleName)
{
WCHAR ret_locale[LOCALE_NAME_MAX_LENGTH];
@ -695,7 +691,7 @@ nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsAString& locale)
if (rv != 0)
{
locale.Assign(ret_locale);
return NS_OK;
return;
}
}
@ -710,14 +706,12 @@ nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsAString& locale)
if (lang_id == LANG_NORWEGIAN) {
if (sublang_id == SUBLANG_NORWEGIAN_BOKMAL) {
locale.AssignASCII("nb-NO");
return NS_OK;
}
if (sublang_id == SUBLANG_NORWEGIAN_NYNORSK) {
} else if (sublang_id == SUBLANG_NORWEGIAN_NYNORSK) {
locale.AssignASCII("nn-NO");
return NS_OK;
} else {
locale.AssignASCII("no-NO");
}
locale.AssignASCII("no-NO");
return NS_OK;
return;
}
for(i=0;i<LENGTH_MAPPING_LIST;i++) {
@ -740,7 +734,7 @@ nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsAString& locale)
break;
}
}
return NS_OK;
return;
}
}
@ -749,8 +743,7 @@ nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsAString& locale)
// than unusable buttons without 'OK', 'Cancel', etc (bug 224546)
//
locale.AssignLiteral("en-US");
return NS_OK;
return;
}
#ifdef DEBUG

View File

@ -39,7 +39,7 @@
#include "nsUConvPropertySearch.h"
#include "pratom.h"
#include <windows.h>
#include "nsIWin32Locale.h"
#include "nsWin32Locale.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsLocaleCID.h"
@ -94,7 +94,6 @@ nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
NS_IMETHODIMP
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult)
{
nsCOMPtr<nsIWin32Locale> winLocale;
LCID localeAsLCID;
//
@ -103,10 +102,7 @@ nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACS
nsresult rv;
oResult.Truncate();
winLocale = do_GetService(NS_WIN32LOCALE_CONTRACTID, &rv);
if (NS_FAILED(rv)) { return rv; }
rv = winLocale->GetPlatformLocale(localeName, &localeAsLCID);
rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID);
if (NS_FAILED(rv)) { return rv; }
PRUnichar acp_name[6];