зеркало из https://github.com/mozilla/pjs.git
Added Windows specific locale interfaces and implementation
This commit is contained in:
Родитель
49961011bc
Коммит
8ffd3b76a9
|
@ -29,6 +29,7 @@ EXPORTS=\
|
||||||
nsILocale.h \
|
nsILocale.h \
|
||||||
nsILocaleFactory.h \
|
nsILocaleFactory.h \
|
||||||
nsLocaleCID.h \
|
nsLocaleCID.h \
|
||||||
|
nsIWin32Locale.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
include <$(DEPTH)/config/rules.mak>
|
include <$(DEPTH)/config/rules.mak>
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
#ifndef nsIWin32Locale_h__
|
||||||
|
#define nsIWin32Locale_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 nsIWin32Locale : public nsISupports {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
NS_IMETHOD GetPlatformLocale(const nsString* locale,LCID* winLCID) = 0;
|
||||||
|
NS_IMETHOD GetXPLocale(LCID winLCID,nsString* locale) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -32,5 +32,26 @@
|
||||||
{ 0xdad86117, 0xb643, 0x11d2, \
|
{ 0xdad86117, 0xb643, 0x11d2, \
|
||||||
{ 0xaf, 0xb, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
{ 0xaf, 0xb, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
||||||
|
|
||||||
|
// {D92D57C3-BA1D-11d2-AF0C-0060089FE59B}
|
||||||
|
#define NS_WIN32LOCALE_CID \
|
||||||
|
{ 0xd92d57c3, 0xba1d, 0x11d2, \
|
||||||
|
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
||||||
|
|
||||||
|
// {9ADEE891-BAF8-11d2-AF0C-0060089FE59B}
|
||||||
|
#define NS_WIN32LOCALEFACTORY_CID \
|
||||||
|
{ 0x9adee891, 0xbaf8, 0x11d2, \
|
||||||
|
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
||||||
|
|
||||||
|
// {D92D57C4-BA1D-11d2-AF0C-0060089FE59B}
|
||||||
|
#define NS_MACLOCALE_CID \
|
||||||
|
{ 0xd92d57c4, 0xba1d, 0x11d2, \
|
||||||
|
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
||||||
|
|
||||||
|
// {D92D57C5-BA1D-11d2-AF0C-0060089FE59B}
|
||||||
|
#define NS_POSIXLOCALE_CID \
|
||||||
|
{ 0xd92d57c5, 0xba1d, 0x11d2, \
|
||||||
|
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
|
||||||
|
|
||||||
|
|
||||||
#endif // nsLocaleCID_h__
|
#endif // nsLocaleCID_h__
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,13 @@ DEFINES=-DWIN32_LEAN_AND_MEAN
|
||||||
MISCDEP= \
|
MISCDEP= \
|
||||||
$(DIST)\lib\nslocale_s.lib
|
$(DIST)\lib\nslocale_s.lib
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
.\$(OBJDIR)\nsCollationWin.obj \
|
.\$(OBJDIR)\nsCollationWin.obj \
|
||||||
.\$(OBJDIR)\nsDateTimeFormatWin.obj \
|
.\$(OBJDIR)\nsDateTimeFormatWin.obj \
|
||||||
.\$(OBJDIR)\nsLocaleFactoryWin.obj \
|
.\$(OBJDIR)\nsLocaleFactoryWin.obj \
|
||||||
.\$(OBJDIR)\nsLocaleDLL.obj \
|
.\$(OBJDIR)\nsLocaleDLL.obj \
|
||||||
|
.\$(OBJDIR)\nsIWin32LocaleImpl.obj \
|
||||||
|
.\$(OBJDIR)\nsIWin32LocaleFactory.obj \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
LINCS= \
|
LINCS= \
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsIWin32Locale.h"
|
||||||
|
#include "nsIWin32LocaleImpl.h"
|
||||||
|
#include "nsIWin32LocaleFactory.h"
|
||||||
|
#include "nsLocaleCID.h"
|
||||||
|
|
||||||
|
NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
|
||||||
|
NS_DEFINE_IID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
|
||||||
|
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||||
|
|
||||||
|
|
||||||
|
nsIWin32LocaleFactory::nsIWin32LocaleFactory()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIWin32LocaleFactory::~nsIWin32LocaleFactory()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsIWin32LocaleFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
||||||
|
void** aResult)
|
||||||
|
{
|
||||||
|
if (aResult == NULL) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always NULL result, in case of failure
|
||||||
|
*aResult = NULL;
|
||||||
|
|
||||||
|
if (aIID.Equals(kISupportsIID))
|
||||||
|
{
|
||||||
|
*aResult = (void *)(nsISupports*)this;
|
||||||
|
} else if (aIID.Equals(kIFactoryIID))
|
||||||
|
{
|
||||||
|
*aResult = (void *)(nsIFactory*)this;
|
||||||
|
} else if (aIID.Equals(kIWin32LocaleIID))
|
||||||
|
{
|
||||||
|
*aResult = (void*)new nsIWin32LocaleImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*aResult == NULL) {
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_ADDREF_THIS(); // Increase reference count for caller
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult nsIWin32LocaleFactory::QueryInterface(const nsIID &aIID,
|
||||||
|
void **aResult)
|
||||||
|
{
|
||||||
|
if (aResult == NULL) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always NULL result, in case of failure
|
||||||
|
*aResult = NULL;
|
||||||
|
|
||||||
|
if (aIID.Equals(kISupportsIID)) {
|
||||||
|
*aResult = (void *)(nsISupports*)this;
|
||||||
|
} else if (aIID.Equals(kIFactoryIID)) {
|
||||||
|
*aResult = (void *)(nsIFactory*)this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*aResult == NULL) {
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_ADDREF_THIS(); // Increase reference count for caller
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsIWin32LocaleFactory::LockFactory(PRBool aBool)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nsrefcnt
|
||||||
|
nsIWin32LocaleFactory::AddRef()
|
||||||
|
{
|
||||||
|
return ++mRefCnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsrefcnt
|
||||||
|
nsIWin32LocaleFactory::Release()
|
||||||
|
{
|
||||||
|
if (--mRefCnt == 0) {
|
||||||
|
delete this;
|
||||||
|
return 0; // Don't access mRefCnt after deleting!
|
||||||
|
}
|
||||||
|
return mRefCnt;
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (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/NPL/
|
||||||
|
*
|
||||||
|
* 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 Communicator client code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Netscape Communications
|
||||||
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||||
|
* Netscape Communications Corporation. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsWin32LocaleFactory_h__
|
||||||
|
#define nsWin32LocaleFactory_h__
|
||||||
|
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsIFactory.h"
|
||||||
|
#include "nsIWin32Locale.h"
|
||||||
|
#include "nsIWin32LocaleImpl.h"
|
||||||
|
|
||||||
|
|
||||||
|
class nsIWin32LocaleFactory : public nsIFactory
|
||||||
|
{
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
nsIWin32LocaleFactory(void);
|
||||||
|
virtual ~nsIWin32LocaleFactory(void);
|
||||||
|
|
||||||
|
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
||||||
|
void** aResult);
|
||||||
|
|
||||||
|
NS_IMETHOD LockFactory(PRBool aLock);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* nsWin32LocaleFactory_h__ */
|
|
@ -0,0 +1,281 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nscore.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsILocale.h"
|
||||||
|
#include "nsIWin32LocaleImpl.h"
|
||||||
|
#include "nsLocaleCID.h"
|
||||||
|
#include "prprf.h"
|
||||||
|
|
||||||
|
NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
|
||||||
|
NS_DEFINE_IID(kIWin32LocaleImplCID, NS_WIN32LOCALE_CID);
|
||||||
|
|
||||||
|
struct iso_lang_mapping
|
||||||
|
{
|
||||||
|
char* iso_code;
|
||||||
|
DWORD lang_code;
|
||||||
|
};
|
||||||
|
typedef struct iso_lang_mapping iso_lang_mapping;
|
||||||
|
|
||||||
|
struct iso_country_mapping
|
||||||
|
{
|
||||||
|
char* iso_code;
|
||||||
|
DWORD country_code;
|
||||||
|
};
|
||||||
|
typedef struct iso_country_mapping iso_country_mapping;
|
||||||
|
|
||||||
|
//
|
||||||
|
// ISO <--> Windows 32 Mappings from www.unicode.org
|
||||||
|
//
|
||||||
|
iso_lang_mapping language_list[50] =
|
||||||
|
{
|
||||||
|
{"af", 0x0036},
|
||||||
|
{"sq", 0x001c},
|
||||||
|
{"ar", 0x0001},
|
||||||
|
{"eu", 0x002d},
|
||||||
|
{"bg", 0x0002},
|
||||||
|
{"be", 0x0023},
|
||||||
|
{"ca", 0x0003},
|
||||||
|
{"zh", 0x0004},
|
||||||
|
{"hr", 0x001a},
|
||||||
|
{"cs", 0x0005},
|
||||||
|
{"da", 0x0006},
|
||||||
|
{"nl", 0x0013},
|
||||||
|
{"en", 0x0009},
|
||||||
|
{"et", 0x0025},
|
||||||
|
{"fo", 0x0038},
|
||||||
|
{"fa", 0x0029},
|
||||||
|
{"fi", 0x000b},
|
||||||
|
{"de", 0x0007},
|
||||||
|
{"el", 0x0008},
|
||||||
|
{"iw", 0x000d},
|
||||||
|
{"he", 0x000d},
|
||||||
|
{"hi", 0x0039},
|
||||||
|
{"hu", 0x000e},
|
||||||
|
{"is", 0x000f},
|
||||||
|
{"in", 0x0021},
|
||||||
|
{"id", 0x0021},
|
||||||
|
{"it", 0x0010},
|
||||||
|
{"ja", 0x0011},
|
||||||
|
{"ko", 0x0012},
|
||||||
|
{"lv", 0x0026},
|
||||||
|
{"lt", 0x0027},
|
||||||
|
{"mk", 0x002f},
|
||||||
|
{"ms", 0x003e},
|
||||||
|
{"no", 0x0014},
|
||||||
|
{"pl", 0x0015},
|
||||||
|
{"pt", 0x0016},
|
||||||
|
{"ro", 0x0018},
|
||||||
|
{"ru", 0x0019},
|
||||||
|
{"sr", 0x001a},
|
||||||
|
{"sk", 0x001b},
|
||||||
|
{"sl", 0x0024},
|
||||||
|
{"es", 0x000a},
|
||||||
|
{"sw", 0x0041},
|
||||||
|
{"sv", 0x001d},
|
||||||
|
{"th", 0x001e},
|
||||||
|
{"tr", 0x001f},
|
||||||
|
{"uk", 0x0022},
|
||||||
|
{"ur", 0x0020},
|
||||||
|
{"vi", 0x002a}
|
||||||
|
};
|
||||||
|
|
||||||
|
iso_country_mapping country_list[94] =
|
||||||
|
{
|
||||||
|
{"AL",0x0400},
|
||||||
|
{"DZ",0x1400},
|
||||||
|
{"AR",0x2c00},
|
||||||
|
{"AU",0x0c00},
|
||||||
|
{"AT",0x0c00},
|
||||||
|
{"BH",0x3c00},
|
||||||
|
{"BY",0x0400},
|
||||||
|
{"BE",0x0800},
|
||||||
|
{"BZ",0x2800},
|
||||||
|
{"BO",0x4000},
|
||||||
|
{"BR",0x0400},
|
||||||
|
{"BN",0x0800},
|
||||||
|
{"BG",0x0400},
|
||||||
|
{"CA",0x1000},
|
||||||
|
{"CL",0x3400},
|
||||||
|
{"CN",0x0800},
|
||||||
|
{"CO",0x2400},
|
||||||
|
{"CR",0x1400},
|
||||||
|
{"CZ",0x0400},
|
||||||
|
{"DK",0x0400},
|
||||||
|
{"DO",0x1c00},
|
||||||
|
{"EC",0x3000},
|
||||||
|
{"EG",0x0c00},
|
||||||
|
{"SV",0x4400},
|
||||||
|
{"EE",0x0400},
|
||||||
|
{"FO",0x0400},
|
||||||
|
{"FI",0x0400},
|
||||||
|
{"DE",0x0400},
|
||||||
|
{"GR",0x0400},
|
||||||
|
{"GT",0x1000},
|
||||||
|
{"HN",0x4800},
|
||||||
|
{"HK",0x0c00},
|
||||||
|
{"HU",0x0400},
|
||||||
|
{"IS",0x0400},
|
||||||
|
{"IN",0x0400},
|
||||||
|
{"ID",0x0400},
|
||||||
|
{"IR",0x0400},
|
||||||
|
{"IQ",0x0800},
|
||||||
|
{"IE",0x1800},
|
||||||
|
{"IL",0x0400},
|
||||||
|
{"IT",0x0400},
|
||||||
|
{"JM",0x2000},
|
||||||
|
{"JP",0x0400},
|
||||||
|
{"JO",0x2c00},
|
||||||
|
{"KE",0x0400},
|
||||||
|
{"KR",0x0400},
|
||||||
|
{"KW",0x3400},
|
||||||
|
{"LV",0x0400},
|
||||||
|
{"LB",0x3000},
|
||||||
|
{"LY",0x1000},
|
||||||
|
{"LI",0x1400},
|
||||||
|
{"LT",0x0400},
|
||||||
|
{"LU",0x1000},
|
||||||
|
{"MO",0x1400},
|
||||||
|
{"MK",0x0400},
|
||||||
|
{"MY",0x0400},
|
||||||
|
{"MX",0x0800},
|
||||||
|
{"MC",0x1800},
|
||||||
|
{"MA",0x1800},
|
||||||
|
{"NL",0x0400},
|
||||||
|
{"NZ",0x1400},
|
||||||
|
{"NI",0x4c00},
|
||||||
|
{"NO",0x0400},
|
||||||
|
{"OM",0x2000},
|
||||||
|
{"PK",0x0400},
|
||||||
|
{"PA",0x1800},
|
||||||
|
{"PY",0x3c00},
|
||||||
|
{"PE",0x2800},
|
||||||
|
{"PH",0x3400},
|
||||||
|
{"PL",0x0400},
|
||||||
|
{"PT",0x0800},
|
||||||
|
{"PR",0x5000},
|
||||||
|
{"QA",0x4000},
|
||||||
|
{"RO",0x0400},
|
||||||
|
{"RU",0x0400},
|
||||||
|
{"SA",0x0400},
|
||||||
|
{"SG",0x1000},
|
||||||
|
{"SK",0x0400},
|
||||||
|
{"SI",0x0400},
|
||||||
|
{"ZA",0x0400},
|
||||||
|
{"ES",0x0400},
|
||||||
|
{"TH",0x0400},
|
||||||
|
{"TT",0x2c00},
|
||||||
|
{"TN",0x1c00},
|
||||||
|
{"TR",0x0400},
|
||||||
|
{"UA",0x0400},
|
||||||
|
{"AE",0x3800},
|
||||||
|
{"GB",0x0800},
|
||||||
|
{"US",0x0400},
|
||||||
|
{"UY",0x3800},
|
||||||
|
{"VE",0x2000},
|
||||||
|
{"VN",0x2400},
|
||||||
|
{"YE",0x2400},
|
||||||
|
{"ZW",0x3000}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* nsIWin32LocaleImpl */
|
||||||
|
NS_IMPL_ISUPPORTS(nsIWin32LocaleImpl,kIWin32LocaleIID)
|
||||||
|
|
||||||
|
nsIWin32LocaleImpl::nsIWin32LocaleImpl(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIWin32LocaleImpl::~nsIWin32LocaleImpl(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 nsString* locale,LCID* winLCID)
|
||||||
|
{
|
||||||
|
char* locale_string;
|
||||||
|
char language_code[3];
|
||||||
|
char country_code[3];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
locale_string = locale->ToNewCString();
|
||||||
|
if (locale_string!=NULL)
|
||||||
|
{
|
||||||
|
PR_sscanf("%s2-%s2-%s",language_code,country_code);
|
||||||
|
for(i=0;i<50;i++)
|
||||||
|
{
|
||||||
|
if(strcmp(language_code,language_list[i].iso_code))
|
||||||
|
{
|
||||||
|
|
||||||
|
*winLCID = MAKELCID(language_list[i].lang_code,SORT_DEFAULT);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsString* locale)
|
||||||
|
{
|
||||||
|
LCID lang_id, country_id;
|
||||||
|
char language_code[3];
|
||||||
|
char country_code[3];
|
||||||
|
char rfc_locale_string[9];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
|
||||||
|
language_code[0] = 0;
|
||||||
|
country_code[0] = 0;
|
||||||
|
|
||||||
|
lang_id = LANGIDFROMLCID(winLCID);
|
||||||
|
for(i=0;i<50;i++)
|
||||||
|
{
|
||||||
|
if (lang_id==language_list[i].lang_code)
|
||||||
|
{
|
||||||
|
strcpy(language_code,language_list[i].iso_code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0;i<94;i++)
|
||||||
|
{
|
||||||
|
if (winLCID==country_list[i].country_code)
|
||||||
|
{
|
||||||
|
strcpy(country_code,country_list[i].iso_code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PR_snprintf(rfc_locale_string,9,"%s-%s",language_code,country_code);
|
||||||
|
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsIWin32LocaleImpl_h__
|
||||||
|
#define nsIWin32LocaleImpl_h__
|
||||||
|
|
||||||
|
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nscore.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsILocale.h"
|
||||||
|
#include "nsIWin32Locale.h"
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
class nsIWin32LocaleImpl: public nsIWin32Locale
|
||||||
|
{
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
nsIWin32LocaleImpl(void);
|
||||||
|
~nsIWin32LocaleImpl(void);
|
||||||
|
|
||||||
|
NS_IMETHOD GetPlatformLocale(const nsString* locale,LCID* winLCID);
|
||||||
|
NS_IMETHOD GetXPLocale(LCID winLCID,nsString* locale);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -26,12 +26,16 @@
|
||||||
#include "nsCollationWin.h"
|
#include "nsCollationWin.h"
|
||||||
#include "nsDateTimeFormatWin.h"
|
#include "nsDateTimeFormatWin.h"
|
||||||
#include "nsLocaleFactoryWin.h"
|
#include "nsLocaleFactoryWin.h"
|
||||||
|
#include "nsIWin32LocaleImpl.h"
|
||||||
|
#include "nsIWin32LocaleFactory.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// kLocaleFactory for the nsILocaleFactory interface
|
// kLocaleFactory for the nsILocaleFactory interface and friends
|
||||||
//
|
//
|
||||||
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
|
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
|
||||||
NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
|
NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
|
||||||
|
NS_DEFINE_IID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
|
||||||
|
NS_DEFINE_IID(kIWin32LocaleIID,NS_IWIN32LOCALE_IID);
|
||||||
|
|
||||||
//
|
//
|
||||||
// for the collation and formatting interfaces
|
// for the collation and formatting interfaces
|
||||||
|
@ -55,18 +59,33 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID, nsISupports* servi
|
||||||
//
|
//
|
||||||
if (aCID.Equals(kLocaleFactoryCID))
|
if (aCID.Equals(kLocaleFactoryCID))
|
||||||
{
|
{
|
||||||
nsLocaleFactory *factory = new nsLocaleFactory();
|
factoryInstance = new nsLocaleFactory();
|
||||||
res = factory->QueryInterface(kILocaleFactoryIID, (void **) aFactory);
|
res = factoryInstance->QueryInterface(kILocaleFactoryIID, (void **) aFactory);
|
||||||
|
|
||||||
if (NS_FAILED(res))
|
if (NS_FAILED(res))
|
||||||
{
|
{
|
||||||
*aFactory = NULL;
|
*aFactory = NULL;
|
||||||
delete factory;
|
delete factoryInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// okay about bout nsIWin32LocaleManager
|
||||||
|
//
|
||||||
|
if (aCID.Equals(kWin32LocaleFactoryCID))
|
||||||
|
{
|
||||||
|
factoryInstance = new nsIWin32LocaleFactory();
|
||||||
|
res = factoryInstance->QueryInterface(kIFactoryIID,(void**)aFactory);
|
||||||
|
if (NS_FAILED(res))
|
||||||
|
{
|
||||||
|
*aFactory=NULL;
|
||||||
|
delete factoryInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// let the nsLocaleFactoryWin logic take over from here
|
// let the nsLocaleFactoryWin logic take over from here
|
||||||
//
|
//
|
||||||
|
|
|
@ -20,10 +20,14 @@
|
||||||
#include "nsILocaleFactory.h"
|
#include "nsILocaleFactory.h"
|
||||||
#include "nsLocaleCID.h"
|
#include "nsLocaleCID.h"
|
||||||
#include "nsRepository.h"
|
#include "nsRepository.h"
|
||||||
|
#include "nsIWin32Locale.h"
|
||||||
|
#ifdef XP_PC
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef XP_MAC
|
#ifdef XP_MAC
|
||||||
#define LOCALE_DLL_NAME "NSLOCALE_DLL"
|
#define LOCALE_DLL_NAME "NSLOCALE_DLL"
|
||||||
#elif defined(XP_WIN)
|
#elif defined(XP_PC)
|
||||||
#define LOCALE_DLL_NAME "NSLOCALE.DLL"
|
#define LOCALE_DLL_NAME "NSLOCALE.DLL"
|
||||||
#else
|
#else
|
||||||
#define LOCALE_DLL_NAME "libnslocale.so"
|
#define LOCALE_DLL_NAME "libnslocale.so"
|
||||||
|
@ -37,6 +41,12 @@ NS_DEFINE_IID(kILocaleIID, NS_ILOCALE_IID);
|
||||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||||
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
|
||||||
|
#ifdef XP_PC
|
||||||
|
NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
|
||||||
|
NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char* localeCatagoryList[6] = { "NSILOCALE_TIME",
|
char* localeCatagoryList[6] = { "NSILOCALE_TIME",
|
||||||
"NSILOCALE_COLLATE",
|
"NSILOCALE_COLLATE",
|
||||||
"NSILOCALE_CTYPE",
|
"NSILOCALE_CTYPE",
|
||||||
|
@ -271,8 +281,86 @@ factory_get_locale(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XP_PC
|
||||||
|
|
||||||
|
void
|
||||||
|
win32factory_create_interface(void)
|
||||||
|
{
|
||||||
|
nsresult result;
|
||||||
|
nsIFactory* factory;
|
||||||
|
nsIWin32Locale* win32Locale;
|
||||||
|
|
||||||
|
result = nsRepository::CreateInstance(kWin32LocaleFactoryCID,
|
||||||
|
NULL,
|
||||||
|
kIFactoryIID,
|
||||||
|
(void**)&factory);
|
||||||
|
NS_ASSERTION(factory!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||||
|
NS_ASSERTION(result==NS_OK,"nsLocaleTest: factory_create_interface failed");
|
||||||
|
|
||||||
|
factory->Release();
|
||||||
|
|
||||||
|
result = nsRepository::CreateInstance(kWin32LocaleFactoryCID,
|
||||||
|
NULL,
|
||||||
|
kIWin32LocaleIID,
|
||||||
|
(void**)&win32Locale);
|
||||||
|
NS_ASSERTION(win32Locale!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||||
|
NS_ASSERTION(result==NS_OK,"nsLocaleTest: factory_create_interface failed");
|
||||||
|
|
||||||
|
win32Locale->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
win32locale_test(void)
|
||||||
|
{
|
||||||
|
nsresult result;
|
||||||
|
nsIWin32Locale* win32Locale;
|
||||||
|
nsString* locale;
|
||||||
|
LCID loc_id;
|
||||||
|
|
||||||
|
//
|
||||||
|
// test with a simple locale
|
||||||
|
//
|
||||||
|
locale = new nsString("en-US");
|
||||||
|
loc_id = 0;
|
||||||
|
|
||||||
|
result = nsRepository::CreateInstance(kWin32LocaleFactoryCID,
|
||||||
|
NULL,
|
||||||
|
kIWin32LocaleIID,
|
||||||
|
(void**)&win32Locale);
|
||||||
|
NS_ASSERTION(win32Locale!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||||
|
NS_ASSERTION(result==NS_OK,"nsLocaleTest: factory_create_interface failed");
|
||||||
|
|
||||||
|
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||||
|
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||||
|
NS_ASSERTION(loc_id!=0,"nsLocaleTest: GetPlatformLocale failed.");
|
||||||
|
|
||||||
|
delete locale;
|
||||||
|
|
||||||
|
//
|
||||||
|
// test with a not so simple locale
|
||||||
|
//
|
||||||
|
locale = new nsString("x-netscape");
|
||||||
|
loc_id = 0;
|
||||||
|
|
||||||
|
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||||
|
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||||
|
NS_ASSERTION(loc_id!=0,"nsLocaleTest: GetPlatformLocale failed.");
|
||||||
|
|
||||||
|
delete locale;
|
||||||
|
|
||||||
|
locale = new nsString("en");
|
||||||
|
loc_id = 0;
|
||||||
|
|
||||||
|
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||||
|
NS_ASSERTION(result==NS_OK,"nsLocaleTest: GetPlatformLocale failed.");
|
||||||
|
NS_ASSERTION(loc_id!=0,"nsLocaleTest: GetPlatformLocale failed.");
|
||||||
|
|
||||||
|
delete locale;
|
||||||
|
win32Locale->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif XP_PC
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
|
@ -295,6 +383,18 @@ main(int argc, char** argv)
|
||||||
PR_FALSE);
|
PR_FALSE);
|
||||||
NS_ASSERTION(res==NS_OK,"nsLocaleTest: RegisterFactory failed.");
|
NS_ASSERTION(res==NS_OK,"nsLocaleTest: RegisterFactory failed.");
|
||||||
|
|
||||||
|
#ifdef XP_PC
|
||||||
|
|
||||||
|
//
|
||||||
|
// register the Windows specific factory
|
||||||
|
//
|
||||||
|
res = nsRepository::RegisterFactory(kWin32LocaleFactoryCID,
|
||||||
|
LOCALE_DLL_NAME,
|
||||||
|
PR_FALSE,
|
||||||
|
PR_FALSE);
|
||||||
|
NS_ASSERTION(res==NS_OK,"nsLocaleTest: Register nsIWin32LocaleFactory failed.");
|
||||||
|
|
||||||
|
#endif
|
||||||
//
|
//
|
||||||
// run the nsILocaleFactory tests (nsILocale gets tested in the prcoess)
|
// run the nsILocaleFactory tests (nsILocale gets tested in the prcoess)
|
||||||
//
|
//
|
||||||
|
@ -302,6 +402,17 @@ main(int argc, char** argv)
|
||||||
factory_get_locale();
|
factory_get_locale();
|
||||||
factory_new_locale();
|
factory_new_locale();
|
||||||
|
|
||||||
|
#ifdef XP_PC
|
||||||
|
|
||||||
|
//
|
||||||
|
// run the nsIWin32LocaleFactory tests
|
||||||
|
//
|
||||||
|
win32factory_create_interface();
|
||||||
|
win32locale_test();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// we done
|
// we done
|
||||||
//
|
//
|
||||||
|
|
Загрузка…
Ссылка в новой задаче