Bug 94831. Convert locale stuff to generic module. r/sr=nobody: I am the devil.

git-svn-id: svn://10.0.0.236/trunk@101278 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
waterson%netscape.com 2001-08-17 05:52:48 +00:00
parent 541f0e0bd9
commit d11171b5e7
51 changed files with 369 additions and 3311 deletions

View File

@ -136,9 +136,6 @@ static NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kLocaleCID, NS_LOCALE_CID);
static NS_DEFINE_IID(kILocaleIID, NS_ILOCALE_IID);
// XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp
static const char kXULNameSpaceURI[]
= "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

View File

@ -54,7 +54,8 @@ enum
#define NS_SCRIPTABLEDATEFORMAT_CONTRACTID "@mozilla.org/intl/scriptabledateformat;1"
extern nsISupports *NEW_SCRIPTABLE_DATEFORMAT(void);
extern NS_IMETHODIMP
NS_NewScriptableDateFormat(nsISupports* aOuter, REFNSIID aIID, void** aResult);
%}
[scriptable, uuid(0c89efb0-1aae-11d3-9141-006008a6edf6)]

View File

@ -2,7 +2,6 @@ nsCollationCID.h
nsDateTimeFormatCID.h
nsICollation.h
nsIDateTimeFormat.h
nsILocaleFactory.h
nsLocaleCID.h
nsIMacLocale.h

View File

@ -33,9 +33,8 @@ EXPORTS = \
nsDateTimeFormatCID.h \
nsICollation.h \
nsIDateTimeFormat.h \
nsILocaleFactory.h \
nsIOS2Locale.h \
nsIPosixLocale.h \
nsIOS2Locale.h \
nsLocaleCID.h \
$(NULL)

View File

@ -30,7 +30,6 @@ EXPORTS=\
nsDateTimeFormatCID.h \
nsICollation.h \
nsIDateTimeFormat.h \
nsILocaleFactory.h \
nsLocaleCID.h \
nsIWin32Locale.h \
$(NULL)

View File

@ -1,57 +0,0 @@
/* -*- 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.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/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.
*
* Contributor(s):
*/
#ifndef nsILocaleManager_h__
#define nsILocaleManager_h__
#include "nsString.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsILocale.h"
// {00932BE1-B65A-11d2-AF0B-0060089FE59B}
#define NS_ILOCALEFACTORY_IID \
{ 0x932be1, 0xb65a, 0x11d2, \
{ 0xaf, 0xb, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
class nsILocaleFactory : public nsIFactory
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILOCALEFACTORY_IID)
NS_IMETHOD NewLocale(nsString** categoryList,nsString**
valueList, PRUint8 count, nsILocale** locale) = 0;
NS_IMETHOD NewLocale(const nsString* localeName, nsILocale** locale) = 0;
NS_IMETHOD GetSystemLocale(nsILocale** systemLocale) = 0;
NS_IMETHOD GetApplicationLocale(nsILocale** applicationLocale) = 0;
NS_IMETHOD GetLocaleFromAcceptLanguage(const char* acceptLanguage, nsILocale** acceptLocale) = 0;
};
#endif /* nsILocaleManager_h__ */

View File

@ -22,59 +22,33 @@
#ifndef nsLocaleCID_h__
#define nsLocaleCID_h__
#include "nscore.h"
#include "nsISupports.h"
// {DAD86119-B643-11d2-AF0B-0060089FE59B}
#define NS_LOCALE_CID \
{ 0xdad86119, 0xb643, 0x11d2, \
{ 0xaf, 0xb, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
// {DAD86117-B643-11d2-AF0B-0060089FE59B}
#define NS_LOCALEFACTORY_CID \
{ 0xdad86117, 0xb643, 0x11d2, \
{ 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 } }
#define NS_WIN32LOCALE_CONTRACTID "@mozilla.org/locale/win32-locale;1"
// {D92D57C4-BA1D-11d2-AF0C-0060089FE59B}
#define NS_MACLOCALE_CID \
{ 0xd92d57c4, 0xba1d, 0x11d2, \
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
// {8C0E453F-EC7E-11d2-9E89-0060089FE59B}
#define NS_MACLOCALEFACTORY_CID \
{ 0x8c0e453f, 0xec7e, 0x11d2, \
{ 0x9e, 0x89, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
#define NS_MACLOCALE_CONTRACTID "@mozilla.org/locale/mac-locale;1"
// {D92D57C5-BA1D-11d2-AF0C-0060089FE59B}
#define NS_POSIXLOCALE_CID \
{ 0xd92d57c5, 0xba1d, 0x11d2, \
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
// {8C0E4531-EC7E-11d2-9E89-0060089FE59B}
#define NS_POSIXLOCALEFACTORY_CID \
{ 0x8c0e4531, 0xec7e, 0x11d2, \
{ 0x9e, 0x89, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
#define NS_POSIXLOCALE_CONTRACTID "@mozilla.org/locale/posix-locale;1"
// {F25F74F1-FB59-11d3-A9F2-00203522A03C}
#define NS_OS2LOCALE_CID \
{ 0xf25f74f1, 0xfb59, 0x11d3, \
{ 0xa9, 0xf2, 0x0, 0x20, 0x35, 0x22, 0xa0, 0x3c }}
// {F25F74F2-FB59-11d3-A9F2-00203522A03C}
#define NS_OS2LOCALEFACTORY_CID \
{ 0xf25f74f2, 0xfb59, 0x11d3, \
{ 0xa9, 0xf2, 0x0, 0x20, 0x35, 0x22, 0xa0, 0x3c }}
#define NS_OS2LOCALE_CONTRACTID "@mozilla.org/locale/os2-locale;1"
#endif // nsLocaleCID_h__
#endif // nsLocaleCID_h__

View File

@ -42,7 +42,6 @@ CPPSRCS = \
nsScriptableDateFormat.cpp \
nsLanguageAtomService.cpp \
nsLocale.cpp \
nsLocaleFactory.cpp \
nsLocaleService.cpp \
nsFontPackageService.cpp \
nsFontPackageHandler.cpp \
@ -50,7 +49,6 @@ CPPSRCS = \
EXPORTS = \
nsCollation.h \
nsLocaleFactory.h \
$(NULL)
EXPORT_RESOURCE = \

View File

@ -20,20 +20,10 @@
* Contributor(s):
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIModule.h"
class nsLocaleMacFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
nsLocaleMacFactory(const nsCID &aClass);
~nsLocaleMacFactory();
private:
nsCID mClassID;
};
void
XXXNotCalled()
{
NSGetModule(nsnull, nsnull, nsnull);
}

View File

@ -35,13 +35,6 @@
#include "nsIMacLocale.h"
#include "nsCOMPtr.h"
static NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
static NS_DEFINE_IID(kMacLocaleFactoryCID, NS_MACLOCALEFACTORY_CID);
static NS_DEFINE_IID(kIMacLocaleIID, NS_IMACLOCALE_IID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
////////////////////////////////////////////////////////////////////////////////
/* Copy from FE_StrColl(), macfe/utility/locale.cp. */
@ -115,7 +108,7 @@ inline unsigned char mac_sort_tbl_search(const unsigned char ch, const unsigned
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS(nsCollationMac, kICollationIID);
NS_IMPL_ISUPPORTS1(nsCollationMac, nsICollation);
nsCollationMac::nsCollationMac()
@ -150,7 +143,7 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
// get locale string, use app default if no locale specified
if (locale == nsnull) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(kLocaleServiceCID, &res);
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsILocale *appLocale;
res = localeService->GetApplicationLocale(&appLocale);
@ -169,7 +162,7 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
nsMemory::Free(aLocaleUnichar);
short scriptcode, langcode, regioncode;
nsCOMPtr <nsIMacLocale> macLocale = do_GetService(kMacLocaleFactoryCID, &res);
nsCOMPtr <nsIMacLocale> macLocale = do_GetService(NS_MACLOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
if (NS_SUCCEEDED(res = macLocale->GetPlatformLocale(&aLocale, &scriptcode, &langcode, &regioncode))) {
m_scriptcode = scriptcode;

View File

@ -37,13 +37,6 @@
#include "plstr.h"
#include "prmem.h"
static NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
static NS_DEFINE_CID(kMacLocaleFactoryCID, NS_MACLOCALEFACTORY_CID);
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
////////////////////////////////////////////////////////////////////////////////
static Intl1Hndl GetItl1Resource(short scriptcode, short regioncode)
@ -221,7 +214,7 @@ static void AbbrevWeekdayString(DateTimeRec &dateTime, Str255 weekdayString, Int
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_THREADSAFE_ISUPPORTS(nsDateTimeFormatMac, kIDateTimeFormatIID);
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatMac, nsIDateTimeFormat);
nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
{
@ -254,7 +247,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
// get application locale
nsCOMPtr<nsILocaleService> localeService =
do_GetService(kLocaleServiceCID, &res);
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsILocale *appLocale;
res = localeService->GetApplicationLocale(&appLocale);
@ -282,7 +275,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
mLocale.Assign(aLocaleUnichar); // cache locale name
nsMemory::Free(aLocaleUnichar);
nsCOMPtr <nsIMacLocale> macLocale = do_GetService(kMacLocaleFactoryCID, &res);
nsCOMPtr <nsIMacLocale> macLocale = do_GetService(NS_MACLOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = macLocale->GetPlatformLocale(&mLocale, &mScriptcode, &mLangcode, &mRegioncode);
}

View File

@ -1,106 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCollationMac.h"
#include "nsIScriptableDateFormat.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatMac.h"
#include "nsLocaleFactoryMac.h"
#include "nsLanguageAtomService.h"
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
nsLocaleMacFactory::nsLocaleMacFactory(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
nsLocaleMacFactory::~nsLocaleMacFactory()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocaleMacFactory, nsIFactory)
nsresult nsLocaleMacFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsISupports *inst = NULL;
if (aIID.Equals(kICollationFactoryIID)) {
NS_NEWXPCOM(inst, nsCollationFactory);
}
else if (aIID.Equals(kICollationIID)) {
NS_NEWXPCOM(inst, nsCollationMac);
}
else if (aIID.Equals(kIDateTimeFormatIID)) {
NS_NEWXPCOM(inst, nsDateTimeFormatMac);
}
else if (aIID.Equals(NS_GET_IID(nsIScriptableDateFormat))) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kScriptableDateFormatCID)) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kLanguageAtomServiceCID)) {
NS_NEWXPCOM(inst, nsLanguageAtomService);
}
else
{
return NS_NOINTERFACE;
}
if (NULL == inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst);
nsresult res = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
return res;
}
nsresult nsLocaleMacFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}

View File

@ -21,249 +21,80 @@
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsIComponentManager.h"
#include "nsCOMPtr.h"
#include "nsIFactory.h"
#include "nsILocaleFactory.h"
#include "nsLocaleFactory.h"
#include "nsILocaleService.h"
#include "nsLocaleCID.h"
#include "nsCollationMac.h"
#include "nsIScriptableDateFormat.h"
#include "nsDateTimeFormatMac.h"
#include "nsLocaleFactoryMac.h"
#include "nsDateTimeFormatCID.h"
#include "nsCollationCID.h"
#include "nsCollationMac.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatMac.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsILocaleService.h"
#include "nsIScriptableDateFormat.h"
#include "nsIServiceManager.h"
#include "nsMacLocaleFactory.h"
#include "nsILanguageAtomService.h"
#include "nsLanguageAtomService.h"
#include "nsLocaleCID.h"
#include "nsMacLocale.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
//
// kLocaleFactory for the nsILocaleFactory interface
//
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
NS_DEFINE_IID(kMacLocaleFactoryCID,NS_MACLOCALEFACTORY_CID);
NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
//
// for the language atom service
//
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
//
// for the collation and formatting interfaces
//
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID);
NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aContractID,
nsIFactory **aFactory);
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aContractID,
nsIFactory **aFactory)
{
nsIFactory* factoryInstance;
nsresult res;
if (aFactory == NULL) return NS_ERROR_NULL_POINTER;
*aFactory = NULL;
//
// first check for the nsILocaleFactory interfaces
//
if (aClass.Equals(kLocaleFactoryCID))
{
nsLocaleFactory *factory = new nsLocaleFactory();
if (NULL==factory)
{
*aFactory=NULL;
return NS_ERROR_OUT_OF_MEMORY;
}
res = factory->QueryInterface(kILocaleFactoryIID, (void **) aFactory);
if (NS_FAILED(res))
{
*aFactory = NULL;
delete factory;
}
#ifdef DEBUG
printf("returning nsLocaleFactory\n");
#endif
return res;
}
if (aClass.Equals(kLocaleServiceCID)) {
factoryInstance = new nsLocaleServiceFactory();
res = factoryInstance->QueryInterface(kIFactoryIID,(void**)aFactory);
if (NS_FAILED(res)) { *aFactory=NULL; delete factoryInstance; }
return res;
}
if (aClass.Equals(kMacLocaleFactoryCID))
{
nsMacLocaleFactory *mac_factory = new nsMacLocaleFactory();
if (NULL==mac_factory)
{
*aFactory=NULL;
return NS_ERROR_OUT_OF_MEMORY;
}
res = mac_factory->QueryInterface(kIFactoryIID,(void**) aFactory);
if (NS_FAILED(res))
{
*aFactory = NULL;
delete mac_factory;
}
return res;
}
//
// let the nsLocaleFactoryWin logic take over from here
//
factoryInstance = new nsLocaleMacFactory(aClass);
if(NULL == factoryInstance)
{
return NS_ERROR_OUT_OF_MEMORY;
}
res = factoryInstance->QueryInterface(kIFactoryIID, (void**)aFactory);
if (NS_FAILED(res))
{
*aFactory = NULL;
delete factoryInstance;
}
return res;
#define MAKE_CTOR(ctor_, iface_, func_) \
static NS_IMETHODIMP \
ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
{ \
*aResult = nsnull; \
if (aOuter) \
return NS_ERROR_NO_AGGREGATION; \
iface_* inst; \
nsresult rv = func_(&inst); \
if (NS_SUCCEEDED(rv)) { \
rv = inst->QueryInterface(aIID, aResult); \
NS_RELEASE(inst); \
} \
return rv; \
}
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char * path)
{
nsresult rv;
MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacLocale)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationMac)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDateTimeFormatMac)
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableDateTimeFormat)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLanguageAtomService)
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
// The list of components we register
static nsModuleComponentInfo gComponents[] = {
{ "nsLocaleService component",
NS_LOCALESERVICE_CID,
NS_LOCALESERVICE_CONTRACTID,
CreateLocaleService },
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
NS_GET_IID(nsIComponentManager),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
{ "Mac locale",
NS_MACLOCALE_CID,
NS_MACLOCALE_CONTRACTID,
nsMacLocaleConstructor },
//
// register the generic factory
//
rv = compMgr->RegisterComponent(kLocaleFactoryCID,"nsLocale component",
NS_LOCALE_CONTRACTID,path,PR_TRUE,PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: RegisterFactory failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the service
//
rv = compMgr->RegisterComponent(kLocaleServiceCID,"nsLocaleService component",
NS_LOCALESERVICE_CONTRACTID,path,PR_TRUE,PR_TRUE);
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
{ "Collation factory",
NS_COLLATIONFACTORY_CID,
NULL,
nsCollationFactoryConstructor },
//
// register the generic factory
//
rv = compMgr->RegisterComponent(kMacLocaleFactoryCID,NULL,NULL,path,PR_TRUE,PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: RegisterFactory failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
{ "Collation",
NS_COLLATION_CID,
NULL,
nsCollationMacConstructor },
//
// register the collation factory
//
rv = compMgr->RegisterComponent(kCollationFactoryCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register CollationFactory failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the collation interface
//
rv = compMgr->RegisterComponent(kCollationCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register Collation failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the date time formatter
//
rv = compMgr->RegisterComponent(kDateTimeFormatCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register DateTimeFormat failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
{ "Date/Time formatter",
NS_DATETIMEFORMAT_CID,
NULL,
nsDateTimeFormatMacConstructor },
//
// register the scriptable date time formatter
//
rv = compMgr->RegisterComponent(kScriptableDateFormatCID, "Scriptable Date Format",
NS_SCRIPTABLEDATEFORMAT_CONTRACTID, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register ScriptableDateFormat failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the language atom service
//
rv = compMgr->RegisterComponent(kLanguageAtomServiceCID, "Language Atom Service",
NS_LANGUAGEATOMSERVICE_CONTRACTID, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register LanguageAtomService failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
{ "Scriptable Date Format",
NS_SCRIPTABLEDATEFORMAT_CID,
NS_SCRIPTABLEDATEFORMAT_CONTRACTID,
NS_NewScriptableDateFormat },
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
{ "Language Atom Service",
NS_LANGUAGEATOMSERVICE_CID,
NS_LANGUAGEATOMSERVICE_CONTRACTID,
nsLanguageAtomServiceConstructor },
};
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char * path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
NS_GET_IID(nsIComponentManager),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kLocaleFactoryCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kCollationFactoryCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kCollationCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kDateTimeFormatCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kScriptableDateFormatCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kLanguageAtomServiceCID, path);
if (NS_FAILED(rv)) goto done;
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
NS_IMPL_NSGETMODULE(nsLocaleModule, gComponents)

View File

@ -1,113 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
*/
#include "nsIMacLocale.h"
#include "nsMacLocale.h"
#include "nsMacLocaleFactory.h"
#include "nsLocaleCID.h"
NS_DEFINE_IID(kIMacLocaleIID, NS_IMACLOCALE_IID);
NS_DEFINE_IID(kMacLocaleFactoryCID, NS_MACLOCALEFACTORY_CID);
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
nsMacLocaleFactory::nsMacLocaleFactory()
{
NS_INIT_REFCNT();
}
nsMacLocaleFactory::~nsMacLocaleFactory()
{
}
NS_IMETHODIMP
nsMacLocaleFactory::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;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIFactoryIID))
{
*aResult = (void *)(nsIFactory*)this;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIMacLocaleIID))
{
nsMacLocale *localeImpl = new nsMacLocale();
if(localeImpl)
localeImpl->AddRef();
*aResult = (void*)localeImpl;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
return NS_OK;
}
nsresult nsMacLocaleFactory::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
nsMacLocaleFactory::LockFactory(PRBool aBool)
{
return NS_OK;
}
NS_IMPL_ADDREF(nsMacLocaleFactory);
NS_IMPL_RELEASE(nsMacLocaleFactory);

View File

@ -1,51 +0,0 @@
/* -*- 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.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/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.
*
* Contributor(s):
*/
#ifndef nsMacLocaleFactory_h__
#define nsMacLocaleFactory_h__
#include "nsString.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIMacLocale.h"
#include "nsMacLocale.h"
class nsMacLocaleFactory : public nsIFactory
{
NS_DECL_ISUPPORTS
public:
nsMacLocaleFactory(void);
virtual ~nsMacLocaleFactory(void);
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif /* nsMacLocaleFactory_h__ */

View File

@ -35,8 +35,7 @@ DLLNAME = nslocale
DLL=.\$(OBJDIR)\$(DLLNAME).dll
#RESFILE = $(DLLNAME).res
CPPSRCS = nsLocale.cpp \
nsLocaleFactory.cpp \
CPPSRCS = nsLocale.cpp \
nsLocaleService.cpp \
nsFontPackageService.cpp \
nsFontPackageHandler.cpp \
@ -46,13 +45,13 @@ CPPSRCS = nsLocale.cpp \
CPP_OBJS = .\$(OBJDIR)\nsLocale.obj \
.\$(OBJDIR)\nsLocaleFactory.obj \
.\$(OBJDIR)\nsLocaleService.obj \
.\$(OBJDIR)\nsFontPackageService.obj \
.\$(OBJDIR)\nsFontPackageHandler.obj \
.\$(OBJDIR)\nsLanguageAtomService.obj \
.\$(OBJDIR)\nsScriptableDateFormat.obj \
.\$(OBJDIR)\nsCollation.obj
.\$(OBJDIR)\nsScriptableDateFormat.obj \
.\$(OBJDIR)\nsCollation.obj \
.\$(OBJDIR)\dlldeps.obj
LINCS = -I. \
-I$(PUBLIC)\raptor \

View File

@ -32,11 +32,8 @@
#define LOCALE_HASH_SIZE 0xFF
NS_DEFINE_IID(kILocaleIID, NS_ILOCALE_IID);
NS_DEFINE_IID(kLocaleCID, NS_LOCALE_CID);
/* nsILocale */
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocale,nsILocale)
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocale, nsILocale)
nsLocale::nsLocale(void)
: fHashtable(nsnull), fCategoryCount(0)

View File

@ -1,560 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
*/
#include "nsILocaleFactory.h"
#include "nsLocaleFactory.h"
#include "nsILocale.h"
#include "nsLocale.h"
#include "nsLocaleCID.h"
#include "nsIComponentManager.h"
#include <ctype.h> // for isalpha, tolower & isspace
#if defined(XP_WIN)
#include <windows.h>
#endif
#if defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_OS2)
#include <locale.h>
#include <stdlib.h>
#endif
#define NSILOCALE_MAX_ACCEPT_LANGUAGE 16
#define NSILOCALE_MAX_ACCEPT_LENGTH 18
NS_DEFINE_IID(kILocaleFactoryIID, NS_ILOCALEFACTORY_IID);
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
#if defined(XP_WIN)
NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
#endif
#ifdef XP_OS2
NS_DEFINE_CID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
NS_DEFINE_IID(kIOS2LocaleIID, NS_IOS2LOCALE_IID);
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
NS_DEFINE_CID(kPosixLocaleFactoryCID,NS_POSIXLOCALEFACTORY_CID);
NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID);
#endif
NS_IMPL_ISUPPORTS2(nsLocaleFactory,nsIFactory, nsILocaleFactory)
#define LOCALE_CATEGORY_LISTLEN 6
char* localeCategoryList[LOCALE_CATEGORY_LISTLEN] =
{
"NSILOCALE_COLLATE",
"NSILOCALE_CTYPE",
"NSILOCALE_MONETARY",
"NSILOCALE_NUMERIC",
"NSILOCALE_TIME",
"NSILOCALE_MESSAGES"
};
#if defined(XP_UNIX) || defined(XP_BEOS)
//
// of systems w/o LC_MESSAGE, we grab LC_CTYPE for the value of LC_MESSAGE
// i want NSILOCALE_MESSAGES to always exist in the XP version, and if it doesn't
// exist on a platform LC_CTYPE is probably the cloest approximation
//
int posix_locale_category[LOCALE_CATEGORY_LISTLEN] =
{
LC_TIME,
LC_COLLATE,
LC_CTYPE,
LC_MONETARY,
LC_NUMERIC,
#ifdef HAVE_I18N_LC_MESSAGES
LC_MESSAGES
#else
LC_CTYPE
#endif
};
#endif
nsLocaleFactory::nsLocaleFactory(void)
: fSystemLocale(NULL),
fApplicationLocale(NULL)
{
NS_ASSERTION(0, "obsoleted, use nsILocaleService instead.\n");
int i;
nsresult result;
NS_INIT_REFCNT();
fCategoryList = new nsString*[LOCALE_CATEGORY_LISTLEN];
for(i=0;i< LOCALE_CATEGORY_LISTLEN;i++) {
nsString* temp = new nsString;
temp->AssignWithConversion(localeCategoryList[i]);
fCategoryList[i] = temp;
}
#if defined(XP_WIN)
fWin32LocaleInterface = nsnull;
result = nsComponentManager::CreateInstance(kWin32LocaleFactoryCID,
NULL,
kIWin32LocaleIID,
(void**)&fWin32LocaleInterface);
NS_ASSERTION(fWin32LocaleInterface!=NULL,"nsLocaleFactory: factory_create_interface failed.\n");
#elif defined(XP_UNIX) || defined(XP_BEOS)
fPosixLocaleInterface = nsnull;
result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
NULL,
kIPosixLocaleIID,
(void**)&fPosixLocaleInterface);
NS_ASSERTION(fPosixLocaleInterface!=NULL,"nsLocaleFactory: factory_create_interface failed.\n");
#elif defined(XP_OS2)
fOS2LocaleInterface = nsnull;
result = nsComponentManager::CreateInstance(kOS2LocaleFactoryCID,
NULL,
kIOS2LocaleIID,
(void**)&fOS2LocaleInterface);
NS_ASSERTION(fOS2LocaleInterface!=NULL,"nsLocaleFactory: factory_create_interface failed.\n");
#endif
}
nsLocaleFactory::~nsLocaleFactory(void)
{
int i;
for(i=0;i< LOCALE_CATEGORY_LISTLEN;i++)
delete fCategoryList[i];
delete []fCategoryList;
if (fSystemLocale)
fSystemLocale->Release();
if (fApplicationLocale)
fApplicationLocale->Release();
#if defined(XP_WIN)
if (fWin32LocaleInterface)
fWin32LocaleInterface->Release();
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
if (fPosixLocaleInterface)
fPosixLocaleInterface->Release();
#endif
#ifdef XP_OS2
if (fOS2LocaleInterface)
fOS2LocaleInterface->Release();
#endif
}
NS_IMETHODIMP
nsLocaleFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult)
{
nsresult result;
result = this->GetApplicationLocale((nsILocale**)aResult);
return result;
}
NS_IMETHODIMP
nsLocaleFactory::LockFactory(PRBool aBool)
{
return NS_OK;
}
NS_IMETHODIMP
nsLocaleFactory::NewLocale(nsString** categoryList,nsString**
valueList, PRUint8 count, nsILocale** locale)
{
nsLocale* newLocale;
newLocale = new nsLocale(categoryList,valueList,count);
NS_ASSERTION(newLocale!=NULL,"nsLocaleFactory: failed to create nsLocale instance");
newLocale->AddRef();
*locale = (nsILocale*)newLocale;
return NS_OK;
}
NS_IMETHODIMP
nsLocaleFactory::NewLocale(const nsString* localeName, nsILocale** locale)
{
int i;
nsString** valueList;
nsLocale* newLocale;
valueList = new nsString*[LOCALE_CATEGORY_LISTLEN];
for(i=0;i< LOCALE_CATEGORY_LISTLEN;i++)
valueList[i] = new nsString(*localeName);
newLocale = new nsLocale(fCategoryList,valueList,LOCALE_CATEGORY_LISTLEN);
NS_ASSERTION(newLocale!=NULL,"nsLocaleFactory: failed to create nsLocale");
newLocale->AddRef();
//
// delete temporary strings
//
for(i=0;i<LOCALE_CATEGORY_LISTLEN;i++)
delete valueList[i];
delete [] valueList;
*locale = (nsILocale*)newLocale;
return NS_OK;
}
NS_IMETHODIMP
nsLocaleFactory::GetSystemLocale(nsILocale** systemLocale)
{
nsresult result;
if (fSystemLocale!=NULL)
{
fSystemLocale->AddRef();
*systemLocale = fSystemLocale;
return NS_OK;
}
//
// for Windows
//
#if defined(XP_WIN)
LCID sysLCID;
nsString* systemLocaleName;
sysLCID = GetSystemDefaultLCID();
if (sysLCID==0) {
*systemLocale = (nsILocale*)nsnull;
return NS_ERROR_FAILURE;
}
if (fWin32LocaleInterface==NULL) {
*systemLocale = (nsILocale*)nsnull;
return NS_ERROR_FAILURE;
}
systemLocaleName = new nsString();
result = fWin32LocaleInterface->GetXPLocale(sysLCID,systemLocaleName);
if (NS_FAILED(result)) {
delete systemLocaleName;
*systemLocale = (nsILocale*)nsnull;
return result;
}
result = this->NewLocale(systemLocaleName,&fSystemLocale);
if (NS_FAILED(result)) {
delete systemLocaleName;
*systemLocale=(nsILocale*)nsnull;
fSystemLocale=(nsILocale*)nsnull;
return result;
}
*systemLocale = fSystemLocale;
fSystemLocale->AddRef();
delete systemLocaleName;
return result;
#elif defined(XP_UNIX) || defined(XP_BEOS)
char* lc_all = setlocale(LC_ALL,"");
char* lc_temp;
char* tempvalue;
char* lang = getenv("LANG");
nsString* lc_values[LOCALE_CATEGORY_LISTLEN];
int i;
NS_ASSERTION(fPosixLocaleInterface!=nsnull,"nsLocale::GetSystemLocale failed");
if (lc_all!=nsnull) {
//
// create an XP_Locale using the value in lc_all
//
lc_values[0] = new nsString();
fPosixLocaleInterface->GetXPLocale(lc_all,lc_values[0]);
tempvalue = lc_values[0]->ToNewCString();
result = NewLocale(lc_values[0],&fSystemLocale);
if (NS_FAILED(result)) {
delete lc_values[0];
*systemLocale=(nsILocale*)nsnull;
fSystemLocale=(nsILocale*)nsnull;
return result;
}
fSystemLocale->AddRef();
*systemLocale = fSystemLocale;
return result;
}
//
// check to see if lang is null, if it is we can default to en
// and use the same logic
if (lang==NULL) {
lang = "en";
}
for(i=0;i<LOCALE_CATEGORY_LISTLEN;i++) {
lc_temp = setlocale(posix_locale_category[i],"");
if (lc_temp==NULL) lc_temp = lang;
lc_values[i] = new nsString();
fPosixLocaleInterface->GetXPLocale(lc_temp,lc_values[i]);
}
result = NewLocale(fCategoryList,(nsString**)lc_values,
LOCALE_CATEGORY_LISTLEN,&fSystemLocale);
if (NS_FAILED(result)) {
for(i=0;i<LOCALE_CATEGORY_LISTLEN;i++) {
delete lc_values[i];
}
*systemLocale = (nsILocale*)nsnull;
fSystemLocale = (nsILocale*)nsnull;
return result;
}
for(i=0;i<LOCALE_CATEGORY_LISTLEN;i++) {
delete lc_values[i];
}
*systemLocale = fSystemLocale;
fSystemLocale->AddRef();
return NS_OK;
#else
nsString* systemLocaleName;
systemLocaleName = new nsString; systemLocaleName->AssignWithConversion("en-US");
result = this->NewLocale(systemLocaleName,&fSystemLocale);
if (NS_FAILED(result)) {
delete systemLocaleName;
*systemLocale=(nsILocale*)nsnull;
fSystemLocale=(nsILocale*)nsnull;
return result;
}
*systemLocale = fSystemLocale;
fSystemLocale->AddRef();
delete systemLocaleName;
return result;
#endif
}
NS_IMETHODIMP
nsLocaleFactory::GetApplicationLocale(nsILocale** applicationLocale)
{
nsresult result;
if (fApplicationLocale!=NULL)
{
fApplicationLocale->AddRef();
*applicationLocale = fApplicationLocale;
return NS_OK;
}
//
// for now
//
//
// for Windows
//
#if defined(XP_WIN)
LCID appLCID;
nsString* applicationLocaleName;
appLCID = GetUserDefaultLCID();
if (appLCID==0) {
*applicationLocale = (nsILocale*)nsnull;
return NS_ERROR_FAILURE;
}
if (fWin32LocaleInterface==NULL) {
*applicationLocale = (nsILocale*)nsnull;
return NS_ERROR_FAILURE;
}
applicationLocaleName = new nsString();
result = fWin32LocaleInterface->GetXPLocale(appLCID,applicationLocaleName);
if (NS_FAILED(result)) {
delete applicationLocaleName;
*applicationLocale = (nsILocale*)nsnull;
return result;
}
result = this->NewLocale(applicationLocaleName,&fApplicationLocale);
if (NS_FAILED(result)) {
delete applicationLocaleName;
*applicationLocale=(nsILocale*)nsnull;
fApplicationLocale=(nsILocale*)nsnull;
return result;
}
*applicationLocale = fApplicationLocale;
fApplicationLocale->AddRef();
delete applicationLocaleName;
return result;
#elif defined(XP_UNIX) || defined(XP_BEOS)
result = GetSystemLocale(&fApplicationLocale);
*applicationLocale = fApplicationLocale;
fApplicationLocale->AddRef();
return result;
#else
nsString* applicationLocaleName;
applicationLocaleName = new nsString; applicationLocaleName->AssignWithConversion("en-US");
result = this->NewLocale(applicationLocaleName,&fApplicationLocale);
if (NS_FAILED(result)) {
delete applicationLocaleName;
*applicationLocale=(nsILocale*)nsnull;
fApplicationLocale=(nsILocale*)nsnull;
return result;
}
*applicationLocale = fApplicationLocale;
fApplicationLocale->AddRef();
delete applicationLocaleName;
return result;
#endif
}
NS_IMETHODIMP
nsLocaleFactory::GetLocaleFromAcceptLanguage(const char* acceptLanguage, nsILocale** acceptLocale)
{
char* input;
char* cPtr;
char* cPtr1;
char* cPtr2;
int i;
int j;
int countLang = 0;
char acceptLanguageList[NSILOCALE_MAX_ACCEPT_LANGUAGE][NSILOCALE_MAX_ACCEPT_LENGTH];
nsresult result;
nsString* localeName;
input = new char[strlen(acceptLanguage)+1];
NS_ASSERTION(input!=nsnull,"nsLocaleFactory::GetLocaleFromAcceptLanguage: memory allocation failed.");
if (input == (char*)NULL){ return NS_ERROR_OUT_OF_MEMORY; }
strcpy(input, acceptLanguage);
cPtr1 = input-1;
cPtr2 = input;
/* put in standard form */
while (*(++cPtr1)) {
if (isalpha(*cPtr1)) *cPtr2++ = tolower(*cPtr1); /* force lower case */
else if (isspace(*cPtr1)); /* ignore any space */
else if (*cPtr1=='-') *cPtr2++ = '_'; /* "-" -> "_" */
else if (*cPtr1=='*'); /* ignore "*" */
else *cPtr2++ = *cPtr1; /* else unchanged */
}
*cPtr2 = '\0';
countLang = 0;
if (strchr(input,';')) {
/* deal with the quality values */
float qvalue[NSILOCALE_MAX_ACCEPT_LANGUAGE];
float qSwap;
float bias = 0.0f;
char* ptrLanguage[NSILOCALE_MAX_ACCEPT_LANGUAGE];
char* ptrSwap;
cPtr = nsCRT::strtok(input,",",&cPtr2);
while (cPtr) {
qvalue[countLang] = 1.0f;
/* add extra parens to get rid of warning */
if ((cPtr1 = strchr(cPtr,';'))) {
sscanf(cPtr1,";q=%f",&qvalue[countLang]);
*cPtr1 = '\0';
}
if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LANGUAGE) { /* ignore if too long */
qvalue[countLang] -= (bias += 0.0001f); /* to insure original order */
ptrLanguage[countLang++] = cPtr;
if (countLang>=NSILOCALE_MAX_ACCEPT_LANGUAGE) break; /* quit if too many */
}
cPtr = nsCRT::strtok(cPtr2,",",&cPtr2);
}
/* sort according to decending qvalue */
/* not a very good algorithm, but count is not likely large */
for ( i=0 ; i<countLang-1 ; i++ ) {
for ( j=i+1 ; j<countLang ; j++ ) {
if (qvalue[i]<qvalue[j]) {
qSwap = qvalue[i];
qvalue[i] = qvalue[j];
qvalue[j] = qSwap;
ptrSwap = ptrLanguage[i];
ptrLanguage[i] = ptrLanguage[j];
ptrLanguage[j] = ptrSwap;
}
}
}
for ( i=0 ; i<countLang ; i++ ) {
strcpy(acceptLanguageList[i],ptrLanguage[i]);
}
} else {
/* simple case: no quality values */
cPtr = nsCRT::strtok(input,",",&cPtr2);
while (cPtr) {
if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LENGTH) { /* ignore if too long */
strcpy(acceptLanguageList[countLang++],cPtr);
if (countLang>=NSILOCALE_MAX_ACCEPT_LENGTH) break; /* quit if too many */
}
cPtr = nsCRT::strtok(cPtr2,",",&cPtr2);
}
}
//
// now create the locale
//
result = NS_ERROR_FAILURE;
if (countLang>0) {
localeName = new nsString; localeName->AssignWithConversion(acceptLanguageList[0]);
result = NewLocale(localeName,acceptLocale);
delete localeName;
}
//
// clean up
//
delete[] input;
return result;
}
#if defined(XP_WIN)
// XXX I had to add this because I changed the link order on Windows
void notCalled()
{
nsCID cid;
(void)NSGetFactory(nsnull, cid, nsnull, nsnull, nsnull);
}
#endif

View File

@ -1,92 +0,0 @@
/* -*- 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.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/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.
*
* Contributor(s):
*/
#ifndef nsLocaleManager_h__
#define nsLocaleManager_h__
#include "nsString.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsILocale.h"
#include "nsILocaleFactory.h"
#ifdef XP_WIN
#include "nsIWin32Locale.h"
#elif defined(XP_OS2)
#include "nsIOS2Locale.h"
#elif defined(XP_UNIX) || defined(XP_BEOS)
#include "nsIPosixLocale.h"
#endif
class nsLocaleServiceFactory : public nsIFactory
{
public:
nsLocaleServiceFactory();
virtual ~nsLocaleServiceFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID, void** aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
class nsLocaleFactory : public nsILocaleFactory
{
NS_DECL_ISUPPORTS
private:
nsString** fCategoryList;
nsILocale* fSystemLocale;
nsILocale* fApplicationLocale;
#ifdef XP_WIN
nsIWin32Locale* fWin32LocaleInterface;
#elif defined(XP_OS2)
nsIOS2Locale* fOS2LocaleInterface;
#elif defined(XP_UNIX) || defined(XP_BEOS)
nsIPosixLocale* fPosixLocaleInterface;
#endif
public:
nsLocaleFactory(void);
virtual ~nsLocaleFactory(void);
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult);
NS_IMETHOD LockFactory(PRBool aLock);
NS_IMETHOD NewLocale(nsString** categoryList,nsString** valueList,
PRUint8 count, nsILocale** locale);
NS_IMETHOD NewLocale(const nsString* localeName, nsILocale** locale);
NS_IMETHOD GetSystemLocale(nsILocale** systemLocale);
NS_IMETHOD GetApplicationLocale(nsILocale** applicationLocale);
NS_IMETHOD GetLocaleFromAcceptLanguage(const char* acceptLanguage, nsILocale** acceptLocale);
};
#endif /* nsILocaleManager_h__ */

View File

@ -23,7 +23,6 @@
#include "nsCOMPtr.h"
#include "nsILocale.h"
#include "nsILocaleService.h"
#include "nsLocaleFactory.h"
#include "nsLocale.h"
#include "nsLocaleCID.h"
#include "nsIComponentManager.h"
@ -32,53 +31,17 @@
#include <ctype.h>
#if defined(XP_WIN)
#include "nsIWin32Locale.h"
#endif
#ifdef XP_OS2
#include "unidef.h"
#include "nsIOS2Locale.h"
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
#include <locale.h>
#include <stdlib.h>
#include "nsIPosixLocale.h"
#endif
#ifdef XP_MAC
#include <script.h>
#include "nsIMacLocale.h"
#endif
//
// iids
//
static NS_DEFINE_IID(kILocaleIID,NS_ILOCALE_IID);
#if defined(XP_WIN)
static NS_DEFINE_IID(kIWin32LocaleIID,NS_IWIN32LOCALE_IID);
#endif
#ifdef XP_OS2
static NS_DEFINE_IID(kIOS2LocaleIID,NS_IOS2LOCALE_IID);
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
static NS_DEFINE_IID(kIPosixLocaleIID,NS_IPOSIXLOCALE_IID);
#endif
#ifdef XP_MAC
static NS_DEFINE_IID(kIMacLocaleIID,NS_IMACLOCALE_IID);
#endif
//
// cids
//
#if defined(XP_WIN)
static NS_DEFINE_CID(kWin32LocaleFactoryCID,NS_WIN32LOCALEFACTORY_CID);
#endif
#ifdef XP_OS2
static NS_DEFINE_CID(kOS2LocaleFactoryCID,NS_OS2LOCALEFACTORY_CID);
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
static NS_DEFINE_CID(kPosixLocaleFactoryCID,NS_POSIXLOCALEFACTORY_CID);
#endif
#ifdef XP_MAC
static NS_DEFINE_CID(kMacLocaleFactoryCID,NS_MACLOCALEFACTORY_CID);
# include "nsIWin32Locale.h"
#elif defined(XP_OS2)
# include "unidef.h"
# include "nsIOS2Locale.h"
#elif defined(XP_UNIX) || defined(XP_BEOS)
# include <locale.h>
# include <stdlib.h>
# include "nsIPosixLocale.h"
#elif defined(XP_MAC)
# include <script.h>
# include "nsIMacLocale.h"
#endif
//
@ -181,49 +144,48 @@ nsLocaleService::nsLocaleService(void)
{
NS_INIT_REFCNT();
#if defined(XP_WIN)
nsIWin32Locale* win32Converter;
nsresult result;
nsCOMPtr<nsIWin32Locale> win32Converter
= do_CreateInstance(NS_WIN32LOCALE_CONTRACTID, &result);
nsString xpLocale;
nsresult result = nsComponentManager::CreateInstance(kWin32LocaleFactoryCID,
NULL,kIWin32LocaleIID,(void**)&win32Converter);
NS_ASSERTION(win32Converter!=NULL,"nsLocaleService: can't get win32 converter\n");
if (NS_SUCCEEDED(result) && win32Converter!=nsnull) {
if (NS_SUCCEEDED(result) && win32Converter) {
//
// get the system LCID
//
LCID win_lcid = GetSystemDefaultLCID();
if (win_lcid==0) { win32Converter->Release(); return;}
if (win_lcid==0) { return;}
result = win32Converter->GetXPLocale(win_lcid,&xpLocale);
if (NS_FAILED(result)) { win32Converter->Release(); return;}
if (NS_FAILED(result)) { return;}
result = NewLocale(xpLocale.get(), &mSystemLocale);
if (NS_FAILED(result)) { win32Converter->Release(); return;}
if (NS_FAILED(result)) { return;}
//
// get the application LCID
//
win_lcid = GetUserDefaultLCID();
if (win_lcid==0) { win32Converter->Release(); return;}
if (win_lcid==0) { return;}
result = win32Converter->GetXPLocale(win_lcid,&xpLocale);
if (NS_FAILED(result)) { win32Converter->Release(); return;}
if (NS_FAILED(result)) { return;}
result = NewLocale(xpLocale.get(), &mApplicationLocale);
if (NS_FAILED(result)) { win32Converter->Release(); return;}
win32Converter->Release();
if (NS_FAILED(result)) { return;}
}
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
nsIPosixLocale* posixConverter;
nsresult result;
nsCOMPtr<nsIPosixLocale> posixConverter =
do_CreateInstance(NS_POSIXLOCALE_CONTRACTID, &result);
nsAutoString xpLocale, platformLocale;
nsresult result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
NULL,kIPosixLocaleIID,(void**)&posixConverter);
if (NS_SUCCEEDED(result) && posixConverter!=nsnull) {
if (NS_SUCCEEDED(result) && posixConverter) {
nsAutoString category, category_platform;
nsLocale* resultLocale;
int i;
resultLocale = new nsLocale();
if ( resultLocale == NULL ) {
posixConverter->Release();
return;
}
for( i = 0; i < LocaleListLength; i++ ) {
@ -249,7 +211,6 @@ nsLocaleService::nsLocaleService(void)
}
}
if (NS_FAILED(result)) {
posixConverter->Release();
nsCRT::free(lc_temp);
return;
}
@ -257,18 +218,17 @@ nsLocaleService::nsLocaleService(void)
resultLocale->AddCategory(category_platform.get(),platformLocale.get());
nsCRT::free(lc_temp);
}
(void)resultLocale->QueryInterface(kILocaleIID,(void**)&mSystemLocale);
(void)resultLocale->QueryInterface(kILocaleIID,(void**)&mApplicationLocale);
posixConverter->Release();
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mSystemLocale);
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mApplicationLocale);
} // if ( NS_SUCCEEDED )...
#endif // XP_UNIX || XP_BEOS
#if defined(XP_OS2)
nsCOMPtr<nsIOS2Locale> os2Converter;
nsresult result;
nsCOMPtr<nsIOS2Locale> os2Converter
= do_CreateInstance(NS_OS2LOCALE_CONTRACTID, &result);
nsAutoString xpLocale;
nsresult result = nsComponentManager::CreateInstance(kOS2LocaleFactoryCID,
NULL,kIOS2LocaleIID,(void**)getter_AddRefs(os2Converter));
if (NS_SUCCEEDED(result) && os2Converter!=nsnull) {
if (NS_SUCCEEDED(result) && os2Converter) {
nsAutoString category;
nsLocale* resultLocale;
int i;
@ -311,8 +271,8 @@ nsLocaleService::nsLocaleService(void)
UniFreeMem(lc_temp);
}
UniFreeLocaleObject(locale_object);
(void)resultLocale->QueryInterface(kILocaleIID,(void**)&mSystemLocale);
(void)resultLocale->QueryInterface(kILocaleIID,(void**)&mApplicationLocale);
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mSystemLocale);
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mApplicationLocale);
} // if ( NS_SUCCEEDED )...
#endif
@ -321,10 +281,10 @@ nsLocaleService::nsLocaleService(void)
long script = GetScriptManagerVariable(smSysScript);
long lang = GetScriptVariable(smSystemScript,smScriptLang);
long region = GetScriptManagerVariable(smRegionCode);
nsCOMPtr<nsIMacLocale> macConverter;
nsresult result = nsComponentManager::CreateInstance(kMacLocaleFactoryCID,
NULL,kIMacLocaleIID,(void**)getter_AddRefs(macConverter));
if (NS_SUCCEEDED(result) && macConverter!=nsnull) {
nsresult result;
nsCOMPtr<nsIMacLocale> macConverter
= do_CreateInstance(NS_MACLOCALE_CONTRACTID, &result);
if (NS_SUCCEEDED(result) && macConverter) {
nsString xpLocale;
result = macConverter->GetXPLocale((short)script,(short)lang,(short)region,&xpLocale);
if (NS_SUCCEEDED(result)) {
@ -363,7 +323,7 @@ nsLocaleService::NewLocale(const PRUnichar *aLocale, nsILocale **_retval)
if (NS_FAILED(result)) { delete resultLocale; return result;}
}
return resultLocale->QueryInterface(kILocaleIID,(void**)_retval);
return resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)_retval);
}
@ -375,7 +335,7 @@ nsLocaleService::NewLocaleObject(nsILocaleDefinition *localeDefinition, nsILocal
nsLocale* new_locale = new nsLocale(NS_STATIC_CAST(nsLocaleDefinition*,localeDefinition)->mLocaleDefinition);
if (!new_locale) return NS_ERROR_OUT_OF_MEMORY;
return new_locale->QueryInterface(kILocaleIID,(void**)_retval);
return new_locale->QueryInterface(NS_GET_IID(nsILocale),(void**)_retval);
}
@ -535,7 +495,10 @@ NS_NewLocaleService(nsILocaleService** result)
if(!result)
return NS_ERROR_NULL_POINTER;
*result = new nsLocaleService();
return (nsnull == *result) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
if (! *result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*result);
return NS_OK;
}
@ -568,33 +531,3 @@ nsLocaleDefinition::SetLocaleCategory(const PRUnichar *category, const PRUnichar
return NS_ERROR_FAILURE;
}
nsLocaleServiceFactory::nsLocaleServiceFactory()
{
NS_INIT_REFCNT();
}
nsLocaleServiceFactory::~nsLocaleServiceFactory()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocaleServiceFactory,nsIFactory)
NS_IMETHODIMP
nsLocaleServiceFactory::CreateInstance(nsISupports* aOuter,
REFNSIID aIID, void** aResult)
{
nsILocaleService* locale_service;
NS_NewLocaleService(&locale_service);
return locale_service->QueryInterface(aIID,aResult);
}
NS_IMETHODIMP
nsLocaleServiceFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}

View File

@ -150,8 +150,19 @@ NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime(
return rv;
}
nsISupports *NEW_SCRIPTABLE_DATEFORMAT(void)
NS_IMETHODIMP
NS_NewScriptableDateFormat(nsISupports* aOuter, REFNSIID aIID, void** aResult)
{
return (nsISupports *) new nsScriptableDateFormat;
}
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsScriptableDateFormat* result = new nsScriptableDateFormat();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
nsresult rv = result->QueryInterface(aIID, aResult);
NS_RELEASE(result);
return rv;
}

View File

@ -33,10 +33,8 @@ REQUIRES = xpcom string unicharutil pref uconv
CPPSRCS = \
nsOS2Locale.cpp \
nsLocaleFactoryOS2.cpp \
nsCollationOS2.cpp \
nsDateTimeFormatOS2.cpp \
nsOS2LocaleFactory.cpp \
nsLocaleModule.cpp \
$(NULL)

View File

@ -42,13 +42,7 @@
#include "nsIPref.h"
static NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
static NS_DEFINE_CID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
static NS_DEFINE_IID(kIOS2LocaleIID, NS_IOS2LOCALE_IID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
NS_IMPL_ISUPPORTS(nsCollationOS2, kICollationIID)
NS_IMPL_ISUPPORTS1(nsCollationOS2, nsICollation)
nsCollationOS2::nsCollationOS2()
{
@ -94,7 +88,7 @@ nsresult nsCollationOS2::Initialize(nsILocale *locale)
// get locale string, use app default if no locale specified
if (locale == nsnull) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(kLocaleServiceCID, &res);
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsILocale *appLocale;
res = localeService->GetApplicationLocale(&appLocale);
@ -121,7 +115,7 @@ nsresult nsCollationOS2::Initialize(nsILocale *locale)
aLocale.AssignWithConversion("C");
}
nsCOMPtr <nsIOS2Locale> os2Locale = do_GetService(kOS2LocaleFactoryCID, &res);
nsCOMPtr <nsIOS2Locale> os2Locale = do_GetService(NS_OS2LOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
PRUnichar platformLocale[kPlatformLocaleLength+1];
res = os2Locale->GetPlatformLocale(platformLocale, kPlatformLocaleLength+1);

View File

@ -44,14 +44,7 @@
#include "nsCOMPtr.h"
#include "nsCRT.h"
static NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
static NS_DEFINE_CID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_IID(kICharsetConverterManagerIID, NS_ICHARSETCONVERTERMANAGER_IID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
NS_IMPL_THREADSAFE_ISUPPORTS(nsDateTimeFormatOS2,kIDateTimeFormatIID)
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatOS2,nsIDateTimeFormat)
nsresult nsDateTimeFormatOS2::FormatTime(nsILocale* locale,

View File

@ -1,114 +0,0 @@
/*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s): Henry Sobotka <sobotka@axess.com> 01/2000 review and update
*
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 07/05/2000 IBM Corp. Reworded file after unix model.
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCOMPtr.h"
#include "nsCollationOS2.h"
#include "nsIScriptableDateFormat.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatOS2.h"
#include "nsLocaleFactoryOS2.h"
#include "nsLanguageAtomService.h"
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
nsLocaleOS2Factory::nsLocaleOS2Factory(const nsCID &aClass)
{
NS_INIT_ISUPPORTS();
mClassID = aClass;
}
nsLocaleOS2Factory::~nsLocaleOS2Factory()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocaleOS2Factory, nsIFactory)
nsresult nsLocaleOS2Factory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsISupports *inst = NULL;
if (aIID.Equals(kICollationFactoryIID)) {
NS_NEWXPCOM(inst, nsCollationFactory);
}
else if (aIID.Equals(kICollationIID)) {
NS_NEWXPCOM(inst, nsCollationOS2);
}
else if (aIID.Equals(kIDateTimeFormatIID)) {
NS_NEWXPCOM(inst, nsDateTimeFormatOS2);
}
else if (aIID.Equals(NS_GET_IID(nsIScriptableDateFormat))) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kScriptableDateFormatCID)) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kLanguageAtomServiceCID)) {
NS_NEWXPCOM(inst, nsLanguageAtomService);
}
else
{
return NS_NOINTERFACE;
}
if (NULL == inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst);
nsresult ret = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
return ret;
}
nsresult nsLocaleOS2Factory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}

View File

@ -1,42 +0,0 @@
/*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCollationOS2.h"
#include "nsDateTimeFormatOS2.h"
class nsLocaleOS2Factory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
nsLocaleOS2Factory(const nsCID &aClass);
virtual ~nsLocaleOS2Factory();
private:
nsCID mClassID;
};

View File

@ -30,316 +30,81 @@
* 07/05/2000 IBM Corp. Reworked file after unix version.
*/
#include "nspr.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsIComponentManager.h"
#include "nsIFactory.h"
#include "nsILocaleService.h"
#include "nsILocaleFactory.h"
#include "nsLocaleFactory.h"
#include "nsLocaleCID.h"
#include "nsIOS2Locale.h"
#include "nsOS2Locale.h"
#include "nsOS2LocaleFactory.h"
#include "nsCollationOS2.h"
#include "nsIScriptableDateFormat.h"
#include "nsDateTimeFormatOS2.h"
#include "nsLocaleFactoryOS2.h"
#include "nsDateTimeFormatCID.h"
#include "nsCollationCID.h"
#include "nsCollationOS2.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatOS2.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsILocaleService.h"
#include "nsIScriptableDateFormat.h"
#include "nsIServiceManager.h"
#include "nsLanguageAtomService.h"
#include "nsLocaleCID.h"
#include "nsLocaleSO.h"
#include "nsOS2Locale.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
//
// kLocaleFactory for the nsILocaleFactory interface
//
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
NS_DEFINE_CID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
//
// for language atoms
//
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
//
// for the collation and formatting interfaces
//
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID);
NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
// Module implementation for the Locale library
class nsLocaleModule : public nsIModule
{
public:
nsLocaleModule();
virtual ~nsLocaleModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
};
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsLocaleModule::nsLocaleModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
#define MAKE_CTOR(ctor_, iface_, func_) \
static NS_IMETHODIMP \
ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
{ \
*aResult = nsnull; \
if (aOuter) \
return NS_ERROR_NO_AGGREGATION; \
iface_* inst; \
nsresult rv = func_(&inst); \
if (NS_SUCCEEDED(rv)) { \
rv = inst->QueryInterface(aIID, aResult); \
NS_RELEASE(inst); \
} \
return rv; \
}
nsLocaleModule::~nsLocaleModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsLocaleModule, kIModuleIID)
// Perform our one-time intialization for this module
nsresult
nsLocaleModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsLocaleModule::Shutdown()
{
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsLocaleModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
nsCOMPtr<nsIFactory> fact;
// first check for the nsILocaleFactory interfaces
if (aClass.Equals(kLocaleFactoryCID)) {
nsLocaleFactory *factory = new nsLocaleFactory();
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
else if (aClass.Equals(kLocaleServiceCID)) {
nsLocaleServiceFactory *factory = new nsLocaleServiceFactory();
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
else if (aClass.Equals(kOS2LocaleFactoryCID)) {
nsOS2LocaleFactory *factory = new nsOS2LocaleFactory();
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
else {
// let the nsLocaleFactory logic take over from here
nsLocaleOS2Factory* factory = new nsLocaleOS2Factory(aClass);
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mContractID;
};
MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsOS2Locale)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationOS2)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDateTimeFormatOS2)
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableDateTimeFormat)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLanguageAtomService)
// The list of components we register
static Components gComponents[] = {
{ "nsLocale component", &kLocaleFactoryCID,
NS_LOCALE_CONTRACTID, },
{ "nsLocaleService component", &kLocaleServiceCID,
NS_LOCALESERVICE_CONTRACTID, },
{ "OS/2 locale", &kOS2LocaleFactoryCID,
NULL, },
{ "Collation factory", &kCollationFactoryCID,
NULL, },
{ "Collation", &kCollationCID,
NULL, },
{ "Date/Time formatter", &kDateTimeFormatCID,
NULL, },
{ "Scriptable Date Format", &kScriptableDateFormatCID,
NS_SCRIPTABLEDATEFORMAT_CONTRACTID, },
{ "Language Atom Service", &kLanguageAtomServiceCID,
NS_LANGUAGEATOMSERVICE_CONTRACTID, },
static nsModuleComponentInfo gComponents[] = {
{ "nsLocaleService component",
NS_LOCALESERVICE_CID,
NS_LOCALESERVICE_CONTRACTID,
CreateLocaleService },
{ "OS/2 locale",
NS_OS2LOCALE_CID,
NS_OS2LOCALE_CONTRACTID,
nsOS2LocaleConstructor },
{ "Collation factory",
NS_COLLATIONFACTORY_CID,
NULL,
nsCollationFactoryConstructor },
{ "Collation",
NS_COLLATION_CID,
NULL,
nsCollationOS2Constructor },
{ "Date/Time formatter",
NS_DATETIMEFORMAT_CID,
NULL,
nsDateTimeFormatOS2Constructor },
{ "Scriptable Date Format",
NS_SCRIPTABLEDATEFORMAT_CID,
NS_SCRIPTABLEDATEFORMAT_CONTRACTID,
NS_NewScriptableDateFormat },
{ "Language Atom Service",
NS_LANGUAGEATOMSERVICE_CID,
NS_LANGUAGEATOMSERVICE_CONTRACTID,
nsLanguageAtomServiceConstructor },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsLocaleModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering locale components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentWithType(*cp->mCID, cp->mDescription,
cp->mContractID, aPath,
registryLocation, PR_TRUE,
PR_TRUE, componentType);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLocaleModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsLocaleModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering locale components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLocaleModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsLocaleModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsLocaleModule *gModule = NULL;
extern "C" NS_EXPORT
nsresult NSGETMODULE_ENTRY_POINT(nsLocaleModule)(nsIComponentManager *servMgr,
nsIFile* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsLocaleModule: Module already created.");
// Create and initialize the layout module instance
nsLocaleModule *m = new nsLocaleModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE(nsLocaleModule, gComponents)

View File

@ -1,123 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 07/05/2000 IBM Corp. created this file, modeled after its unix counter part: nsPosixLocaleFactory.cpp.
*
*/
#include "nsOS2Locale.h"
#include "nsOS2LocaleFactory.h"
#include "nsLocaleCID.h"
NS_DEFINE_IID(kIOS2LocaleIID, NS_IOS2LOCALE_IID);
NS_DEFINE_IID(kOS2LocaleFactoryCID, NS_OS2LOCALEFACTORY_CID);
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
nsOS2LocaleFactory::nsOS2LocaleFactory()
{
NS_INIT_REFCNT();
}
nsOS2LocaleFactory::~nsOS2LocaleFactory()
{
}
NS_IMETHODIMP
nsOS2LocaleFactory::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;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIFactoryIID))
{
*aResult = (void *)(nsIFactory*)this;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIOS2LocaleIID))
{
nsOS2Locale *localeImpl = new nsOS2Locale();
if(localeImpl)
localeImpl->AddRef();
*aResult = (void*)localeImpl;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
return NS_OK;
}
nsresult nsOS2LocaleFactory::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
nsOS2LocaleFactory::LockFactory(PRBool aBool)
{
return NS_OK;
}
NS_IMPL_ADDREF(nsOS2LocaleFactory);
NS_IMPL_RELEASE(nsOS2LocaleFactory);

View File

@ -1,63 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 06/01/2000 IBM Corp. created this file modeled after its unix counter part: nsPosixLocaleFactory.cpp.
*
*/
#ifndef nsOS2LocaleFactory_h__
#define nsOS2LocaleFactory_h__
#include "nsString.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIOS2Locale.h"
#include "nsOS2Locale.h"
class nsOS2LocaleFactory : public nsIFactory
{
NS_DECL_ISUPPORTS
public:
nsOS2LocaleFactory(void);
virtual ~nsOS2LocaleFactory(void);
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif /* nsOS2LocaleFactory_h__ */

View File

@ -38,10 +38,8 @@ SHARED_LIBRARY_LIBS = ../libnslocale_s.a
CPPSRCS = \
nsCollationUnix.cpp \
nsDateTimeFormatUnix.cpp \
nsLocaleFactoryUnix.cpp \
nsLocaleModule.cpp \
nsPosixLocale.cpp \
nsPosixLocaleFactory.cpp \
$(NULL)
EXTRA_DSO_LDOPTS += \

View File

@ -34,15 +34,6 @@
#include "nsIPref.h"
//#define DEBUG_UNIX_COLLATION
static NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
static NS_DEFINE_CID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID);
static NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
NS_IMPL_ISUPPORTS(nsCollationUnix, kICollationIID);
inline void nsCollationUnix::DoSetLocale()
{
char *locale = setlocale(LC_COLLATE, NULL);
@ -74,6 +65,8 @@ nsCollationUnix::~nsCollationUnix()
delete mCollation;
}
NS_IMPL_ISUPPORTS1(nsCollationUnix, nsICollation)
nsresult nsCollationUnix::Initialize(nsILocale* locale)
{
#define kPlatformLocaleLength 64
@ -110,7 +103,7 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale)
// get locale string, use app default if no locale specified
if (locale == nsnull) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(kLocaleServiceCID, &res);
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsILocale *appLocale;
res = localeService->GetApplicationLocale(&appLocale);
@ -139,7 +132,7 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale)
aLocale.AssignWithConversion("C");
}
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(kPosixLocaleFactoryCID, &res);
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(NS_POSIXLOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
char platformLocale[kPlatformLocaleLength+1];
res = posixLocale->GetPlatformLocale(&aLocale, platformLocale, kPlatformLocaleLength+1);

View File

@ -42,6 +42,10 @@ protected:
void DoRestoreLocale();
public:
nsCollationUnix();
virtual ~nsCollationUnix();
NS_DECL_ISUPPORTS
// compare two strings
@ -70,10 +74,6 @@ public:
// init this interface to a specified locale (should only be called by collation factory)
//
NS_IMETHOD Initialize(nsILocale* locale);
nsCollationUnix();
virtual ~nsCollationUnix();
};
#endif /* nsCollationUnix_h__ */

View File

@ -32,14 +32,7 @@
#include "nsIPosixLocale.h"
#include "nsCRT.h"
static NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
static NS_DEFINE_CID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID);
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_IID(kICharsetConverterManagerIID, NS_ICHARSETCONVERTERMANAGER_IID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
NS_IMPL_THREADSAFE_ISUPPORTS(nsDateTimeFormatUnix, kIDateTimeFormatIID);
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatUnix, nsIDateTimeFormat);
// init this interface to a specified locale
nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
@ -72,7 +65,7 @@ nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
// get locale name string, use app default if no locale specified
if (NULL == locale) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(kLocaleServiceCID, &res);
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsILocale *appLocale;
res = localeService->GetApplicationLocale(&appLocale);
@ -95,7 +88,7 @@ nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
mLocale = aLocaleUnichar; // cache locale name
nsMemory::Free(aLocaleUnichar);
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(kPosixLocaleFactoryCID, &res);
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(NS_POSIXLOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = posixLocale->GetPlatformLocale(&mLocale, mPlatformLocale, kPlatformLocaleLength+1);
}

View File

@ -1,106 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCOMPtr.h"
#include "nsCollationUnix.h"
#include "nsIScriptableDateFormat.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatUnix.h"
#include "nsLocaleFactoryUnix.h"
#include "nsLanguageAtomService.h"
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
nsLocaleUnixFactory::nsLocaleUnixFactory(const nsCID &aClass)
{
NS_INIT_ISUPPORTS();
mClassID = aClass;
}
nsLocaleUnixFactory::~nsLocaleUnixFactory()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocaleUnixFactory, nsIFactory)
nsresult nsLocaleUnixFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsISupports *inst = NULL;
if (aIID.Equals(kICollationFactoryIID)) {
NS_NEWXPCOM(inst, nsCollationFactory);
}
else if (aIID.Equals(kICollationIID)) {
NS_NEWXPCOM(inst, nsCollationUnix);
}
else if (aIID.Equals(kIDateTimeFormatIID)) {
NS_NEWXPCOM(inst, nsDateTimeFormatUnix);
}
else if (aIID.Equals(NS_GET_IID(nsIScriptableDateFormat))) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kScriptableDateFormatCID)) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kLanguageAtomServiceCID)) {
NS_NEWXPCOM(inst, nsLanguageAtomService);
}
else
{
return NS_NOINTERFACE;
}
if (NULL == inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst);
nsresult ret = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
return ret;
}
nsresult nsLocaleUnixFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}

View File

@ -1,43 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCollationUnix.h"
#include "nsDateTimeFormatUnix.h"
class nsLocaleUnixFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
nsLocaleUnixFactory(const nsCID &aClass);
virtual ~nsLocaleUnixFactory();
private:
nsCID mClassID;
};

View File

@ -20,318 +20,82 @@
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nspr.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIComponentManager.h"
#include "nsIFactory.h"
#include "nsIGenericFactory.h"
#include "nsILocaleService.h"
#include "nsILocaleFactory.h"
#include "nsLocaleFactory.h"
#include "nsLocaleCID.h"
#include "nsIPosixLocale.h"
#include "nsPosixLocale.h"
#include "nsPosixLocaleFactory.h"
#include "nsCollationUnix.h"
#include "nsIScriptableDateFormat.h"
#include "nsDateTimeFormatUnix.h"
#include "nsLocaleFactoryUnix.h"
#include "nsDateTimeFormatCID.h"
#include "nsCollationCID.h"
#include "nsLocaleSO.h"
#include "nsCollationUnix.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatUnix.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsILocaleService.h"
#include "nsIScriptableDateFormat.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsLanguageAtomService.h"
#include "nsLocaleCID.h"
#include "nsLocaleSO.h"
#include "nsPosixLocale.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
//
// kLocaleFactory for the nsILocaleFactory interface
//
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
NS_DEFINE_CID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID);
NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
//
// for language atoms
//
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
//
// for the collation and formatting interfaces
//
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID);
NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
// Module implementation for the Locale library
class nsLocaleModule : public nsIModule
{
public:
nsLocaleModule();
virtual ~nsLocaleModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
};
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsLocaleModule::nsLocaleModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
#define MAKE_CTOR(ctor_, iface_, func_) \
static NS_IMETHODIMP \
ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
{ \
*aResult = nsnull; \
if (aOuter) \
return NS_ERROR_NO_AGGREGATION; \
iface_* inst; \
nsresult rv = func_(&inst); \
if (NS_SUCCEEDED(rv)) { \
rv = inst->QueryInterface(aIID, aResult); \
NS_RELEASE(inst); \
} \
return rv; \
}
nsLocaleModule::~nsLocaleModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsLocaleModule, kIModuleIID)
// Perform our one-time intialization for this module
nsresult
nsLocaleModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsLocaleModule::Shutdown()
{
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsLocaleModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
nsCOMPtr<nsIFactory> fact;
// first check for the nsILocaleFactory interfaces
if (aClass.Equals(kLocaleFactoryCID)) {
nsLocaleFactory *factory = new nsLocaleFactory();
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
else if (aClass.Equals(kLocaleServiceCID)) {
nsLocaleServiceFactory *factory = new nsLocaleServiceFactory();
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
else if (aClass.Equals(kPosixLocaleFactoryCID)) {
nsPosixLocaleFactory *factory = new nsPosixLocaleFactory();
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
else {
// let the nsLocaleUnixFactory logic take over from here
nsLocaleUnixFactory* factory = new nsLocaleUnixFactory(aClass);
if (!factory) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
fact = do_QueryInterface(factory, &rv);
if (!fact) {
delete factory;
}
}
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mContractID;
};
MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPosixLocale)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationUnix)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDateTimeFormatUnix)
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableDateTimeFormat)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLanguageAtomService)
// The list of components we register
static Components gComponents[] = {
{ "nsLocale component", &kLocaleFactoryCID,
NS_LOCALE_CONTRACTID, },
{ "nsLocaleService component", &kLocaleServiceCID,
NS_LOCALESERVICE_CONTRACTID, },
{ "Posix locale", &kPosixLocaleFactoryCID,
NULL, },
{ "Collation factory", &kCollationFactoryCID,
NULL, },
{ "Collation", &kCollationCID,
NULL, },
{ "Date/Time formatter", &kDateTimeFormatCID,
NULL, },
{ "Scriptable Date Format", &kScriptableDateFormatCID,
NS_SCRIPTABLEDATEFORMAT_CONTRACTID, },
{ "Language Atom Service", &kLanguageAtomServiceCID,
NS_LANGUAGEATOMSERVICE_CONTRACTID, },
static nsModuleComponentInfo gComponents[] = {
{ "nsLocaleService component",
NS_LOCALESERVICE_CID,
NS_LOCALESERVICE_CONTRACTID,
CreateLocaleService },
{ "Platform locale",
NS_POSIXLOCALE_CID,
NS_POSIXLOCALE_CONTRACTID,
nsPosixLocaleConstructor },
{ "Collation factory",
NS_COLLATIONFACTORY_CID,
NULL,
nsCollationFactoryConstructor },
{ "Collation",
NS_COLLATION_CID,
NULL,
nsCollationUnixConstructor },
{ "Date/Time formatter",
NS_DATETIMEFORMAT_CID,
NULL,
nsDateTimeFormatUnixConstructor },
{ "Scriptable Date Format",
NS_SCRIPTABLEDATEFORMAT_CID,
NS_SCRIPTABLEDATEFORMAT_CONTRACTID,
NS_NewScriptableDateFormat },
{ "Language Atom Service",
NS_LANGUAGEATOMSERVICE_CID,
NS_LANGUAGEATOMSERVICE_CONTRACTID,
nsLanguageAtomServiceConstructor },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsLocaleModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering locale components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentWithType(*cp->mCID, cp->mDescription,
cp->mContractID, aPath,
registryLocation, PR_TRUE,
PR_TRUE, componentType);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLocaleModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsLocaleModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering locale components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLocaleModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsLocaleModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsLocaleModule *gModule = NULL;
extern "C" NS_EXPORT
nsresult NSGETMODULE_ENTRY_POINT(nsLocaleModule)(nsIComponentManager *servMgr,
nsIFile* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsLocaleModule: Module already created.");
// Create an initialize the layout module instance
nsLocaleModule *m = new nsLocaleModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE(nsLocaleModule, gComponents)

View File

@ -29,11 +29,8 @@
#include "prprf.h"
#include "nsFileSpec.h"
NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID);
NS_DEFINE_IID(kPosixLocaleCID, NS_POSIXLOCALE_CID);
/* nsPosixLocale ISupports */
NS_IMPL_ISUPPORTS(nsPosixLocale,kIPosixLocaleIID)
NS_IMPL_ISUPPORTS1(nsPosixLocale, nsIPosixLocale)
nsPosixLocale::nsPosixLocale(void)
{

View File

@ -1,113 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
*/
#include "nsIPosixLocale.h"
#include "nsPosixLocale.h"
#include "nsPosixLocaleFactory.h"
#include "nsLocaleCID.h"
NS_DEFINE_IID(kIPosixLocaleIID, NS_IPOSIXLOCALE_IID);
NS_DEFINE_IID(kPosixLocaleFactoryCID, NS_POSIXLOCALEFACTORY_CID);
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
nsPosixLocaleFactory::nsPosixLocaleFactory()
{
NS_INIT_REFCNT();
}
nsPosixLocaleFactory::~nsPosixLocaleFactory()
{
}
NS_IMETHODIMP
nsPosixLocaleFactory::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;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIFactoryIID))
{
*aResult = (void *)(nsIFactory*)this;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIPosixLocaleIID))
{
nsPosixLocale *localeImpl = new nsPosixLocale();
if(localeImpl)
localeImpl->AddRef();
*aResult = (void*)localeImpl;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
return NS_OK;
}
nsresult nsPosixLocaleFactory::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
nsPosixLocaleFactory::LockFactory(PRBool aBool)
{
return NS_OK;
}
NS_IMPL_ADDREF(nsPosixLocaleFactory);
NS_IMPL_RELEASE(nsPosixLocaleFactory);

View File

@ -1,51 +0,0 @@
/* -*- 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.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/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.
*
* Contributor(s):
*/
#ifndef nsPosixLocaleFactory_h__
#define nsPosixLocaleFactory_h__
#include "nsString.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIPosixLocale.h"
#include "nsPosixLocale.h"
class nsPosixLocaleFactory : public nsIFactory
{
NS_DECL_ISUPPORTS
public:
nsPosixLocaleFactory(void);
virtual ~nsPosixLocaleFactory(void);
NS_IMETHOD CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif /* nsPosixLocaleFactory_h__ */

View File

@ -30,10 +30,8 @@ DEFINES=-DWIN32_LEAN_AND_MEAN
OBJS = \
.\$(OBJDIR)\nsCollationWin.obj \
.\$(OBJDIR)\nsDateTimeFormatWin.obj \
.\$(OBJDIR)\nsLocaleFactoryWin.obj \
.\$(OBJDIR)\nsLocaleDLL.obj \
.\$(OBJDIR)\nsIWin32LocaleImpl.obj \
.\$(OBJDIR)\nsIWin32LocaleFactory.obj \
$(NULL)
LINCS= \

View File

@ -35,12 +35,6 @@
#include <windows.h>
static NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
static NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
static NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
NS_IMPL_ISUPPORTS1(nsCollationWin, nsICollation);
@ -90,7 +84,7 @@ nsresult nsCollationWin::Initialize(nsILocale* locale)
// get locale string, use app default if no locale specified
if (locale == nsnull) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(kLocaleServiceCID, &res);
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsILocale *appLocale;
res = localeService->GetApplicationLocale(&appLocale);
@ -112,7 +106,7 @@ nsresult nsCollationWin::Initialize(nsILocale* locale)
nsMemory::Free(aLocaleUnichar);
}
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(kWin32LocaleFactoryCID, &res);
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(NS_WIN32LOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
LCID lcid;
res = win32Locale->GetPlatformLocale(&aLocale, &lcid);

View File

@ -34,11 +34,6 @@
#define NSDATETIMEFORMAT_BUFFER_LEN 80
static NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
static NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatWin, nsIDateTimeFormat);
@ -84,7 +79,7 @@ nsresult nsDateTimeFormatWin::Initialize(nsILocale* locale)
// get locale string, use app default if no locale specified
if (NULL == locale) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(kLocaleServiceCID, &res);
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsILocale *appLocale;
res = localeService->GetApplicationLocale(&appLocale);
@ -106,7 +101,7 @@ nsresult nsDateTimeFormatWin::Initialize(nsILocale* locale)
mLocale.Assign(aLocaleUnichar); // cache locale name
nsMemory::Free(aLocaleUnichar);
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(kWin32LocaleFactoryCID, &res);
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(NS_WIN32LOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = win32Locale->GetPlatformLocale(&mLocale, (LCID *) &mLCID);
}

View File

@ -1,86 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
*/
#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()
{
NS_INIT_REFCNT();
}
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;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIFactoryIID))
{
*aResult = (void *)(nsIFactory*)this;
NS_ADDREF_THIS(); // Increase reference count for caller
} else if (aIID.Equals(kIWin32LocaleIID))
{
nsIWin32LocaleImpl *localeImpl = new nsIWin32LocaleImpl();
if(localeImpl)
NS_ADDREF(localeImpl);
*aResult = (void*)localeImpl;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
return NS_OK;
}
NS_IMETHODIMP
nsIWin32LocaleFactory::LockFactory(PRBool aBool)
{
return NS_OK;
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsIWin32LocaleFactory,nsIFactory)

View File

@ -1,51 +0,0 @@
/* -*- 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.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/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.
*
* Contributor(s):
*/
#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__ */

View File

@ -21,276 +21,80 @@
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsIComponentManager.h"
#include "nsCOMPtr.h"
#include "nsIFactory.h"
#include "nsILocaleService.h"
#include "nsILocaleFactory.h"
#include "nsLocaleFactory.h"
#include "nsLocaleCID.h"
#include "nsCollationWin.h"
#include "nsDateTimeFormatWin.h"
#include "nsIScriptableDateFormat.h"
#include "nsLocaleFactoryWin.h"
#include "nsIWin32LocaleImpl.h"
#include "nsIWin32LocaleFactory.h"
#include "nsDateTimeFormatCID.h"
#include "nsCollationCID.h"
#include "nsIServiceManager.h"
#include "nsILanguageAtomService.h"
#include "nsCollationWin.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatWin.h"
#include "nsIFontPackageService.h"
#include "nsIGenericFactory.h"
#include "nsILocaleService.h"
#include "nsIScriptableDateFormat.h"
#include "nsIServiceManager.h"
#include "nsLanguageAtomService.h"
#include "nsLocaleCID.h"
#include "nsIWin32LocaleImpl.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
//
// kLocaleFactory for the nsILocaleFactory interface and friends
//
NS_DEFINE_IID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
NS_DEFINE_IID(kILocaleFactoryIID,NS_ILOCALEFACTORY_IID);
NS_DEFINE_IID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
NS_DEFINE_IID(kIWin32LocaleIID,NS_IWIN32LOCALE_IID);
NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
//
// for language atoms
//
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
//
// for font package service
//
NS_DEFINE_CID(kFontPackageServiceCID, NS_FONTPACKAGESERVICE_CID);
//
// for the collation and formatting interfaces
//
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID);
NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
//
// private entry points used for debugging
//
#ifdef DEBUG
void test_internal_tables(void);
#endif
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aContractID,
nsIFactory **aFactory)
{
nsIFactory* factoryInstance;
nsresult res;
#ifdef DEBUG_tague
test_internal_tables();
#endif
if (aFactory == NULL) return NS_ERROR_NULL_POINTER;
//
// first check for the nsILocaleFactory interfaces
//
if (aClass.Equals(kLocaleFactoryCID))
{
factoryInstance = new nsLocaleFactory();
res = CallQueryInterface(factoryInstance, aFactory);
if (NS_FAILED(res))
{
*aFactory = NULL;
delete factoryInstance;
}
return res;
}
if (aClass.Equals(kLocaleServiceCID)) {
factoryInstance = new nsLocaleServiceFactory();
res = CallQueryInterface(factoryInstance, aFactory);
if (NS_FAILED(res)) { *aFactory=NULL; delete factoryInstance; }
return res;
}
//
// okay about bout nsIWin32LocaleManager
//
if (aClass.Equals(kWin32LocaleFactoryCID))
{
factoryInstance = new nsIWin32LocaleFactory();
res = CallQueryInterface(factoryInstance, aFactory);
if (NS_FAILED(res))
{
*aFactory=NULL;
delete factoryInstance;
}
return res;
}
//
// let the nsLocaleFactoryWin logic take over from here
//
factoryInstance = new nsLocaleWinFactory(aClass);
if(NULL == factoryInstance)
{
return NS_ERROR_OUT_OF_MEMORY;
}
res = CallQueryInterface(factoryInstance, aFactory);
if (NS_FAILED(res))
{
*aFactory = NULL;
delete factoryInstance;
}
return res;
#define MAKE_CTOR(ctor_, iface_, func_) \
static NS_IMETHODIMP \
ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
{ \
*aResult = nsnull; \
if (aOuter) \
return NS_ERROR_NO_AGGREGATION; \
iface_* inst; \
nsresult rv = func_(&inst); \
if (NS_SUCCEEDED(rv)) { \
rv = inst->QueryInterface(aIID, aResult); \
NS_RELEASE(inst); \
} \
return rv; \
}
//
// From bug #5564, it looks likes these functions are no longer needed on Windows and actually case
// performance problems, so I'm ifdef-ing them out.
//
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char * path)
{
nsresult rv;
MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIWin32LocaleImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationWin)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDateTimeFormatWin)
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableDateTimeFormat)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLanguageAtomService)
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
// The list of components we register
static nsModuleComponentInfo gComponents[] = {
{ "nsLocaleService component",
NS_LOCALESERVICE_CID,
NS_LOCALESERVICE_CONTRACTID,
CreateLocaleService },
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
NS_GET_IID(nsIComponentManager),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
{ "Platform locale",
NS_WIN32LOCALE_CID,
NS_WIN32LOCALE_CONTRACTID,
nsIWin32LocaleImplConstructor },
//
// register the generic factory
//
rv = compMgr->RegisterComponent(kLocaleFactoryCID,"nsLocale component",
NS_LOCALE_CONTRACTID,path,PR_TRUE,PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: RegisterFactory failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
{ "Collation factory",
NS_COLLATIONFACTORY_CID,
NULL,
nsCollationFactoryConstructor },
//
// register the service
//
rv = compMgr->RegisterComponent(kLocaleServiceCID,"nsLocaleService component",
NS_LOCALESERVICE_CONTRACTID,path,PR_TRUE,PR_TRUE);
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
{ "Collation",
NS_COLLATION_CID,
NULL,
nsCollationWinConstructor },
{ "Date/Time formatter",
NS_DATETIMEFORMAT_CID,
NULL,
nsDateTimeFormatWinConstructor },
//
// register the windows specific factory
//
rv = compMgr->RegisterComponent(kWin32LocaleFactoryCID,NULL,NULL,path,PR_TRUE,PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register nsIWin32LocaleFactory failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
{ "Scriptable Date Format",
NS_SCRIPTABLEDATEFORMAT_CID,
NS_SCRIPTABLEDATEFORMAT_CONTRACTID,
NS_NewScriptableDateFormat },
//
// register the collation factory
//
rv = compMgr->RegisterComponent(kCollationFactoryCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register CollationFactory failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the collation interface
//
rv = compMgr->RegisterComponent(kCollationCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register Collation failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the date time formatter
//
rv = compMgr->RegisterComponent(kDateTimeFormatCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register DateTimeFormat failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the scriptable date time formatter
//
rv = compMgr->RegisterComponent(kScriptableDateFormatCID, "Scriptable Date Format",
NS_SCRIPTABLEDATEFORMAT_CONTRACTID, path, PR_TRUE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),"nsLocaleTest: Register ScriptableDateFormat failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the language atom service
//
rv = compMgr->RegisterComponent(kLanguageAtomServiceCID,
"Language Atom Service", NS_LANGUAGEATOMSERVICE_CONTRACTID, path, PR_TRUE,
PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),
"nsLocaleTest: Register LanguageAtomService failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
//
// register the font package service
//
rv = compMgr->RegisterComponent(kFontPackageServiceCID,
"Font Package Service", NS_FONTPACKAGESERVICE_CONTRACTID, path, PR_TRUE,
PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv),
"nsLocaleTest: Register FontPackageService failed.");
if (NS_FAILED(rv) && (NS_ERROR_FACTORY_EXISTS != rv)) goto done;
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char * path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
NS_GET_IID(nsIComponentManager),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kLocaleFactoryCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kLocaleServiceCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kWin32LocaleFactoryCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kCollationFactoryCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kCollationCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kDateTimeFormatCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kScriptableDateFormatCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kLanguageAtomServiceCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kFontPackageServiceCID, path);
if (NS_FAILED(rv)) goto done;
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
{ "Language Atom Service",
NS_LANGUAGEATOMSERVICE_CID,
NS_LANGUAGEATOMSERVICE_CONTRACTID,
nsLanguageAtomServiceConstructor },
};
NS_IMPL_NSGETMODULE(nsLocaleModule, gComponents)

View File

@ -1,116 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Frank Yung-Fong Tang <ftang@netscape.com>
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCollationWin.h"
#include "nsDateTimeFormatCID.h"
#include "nsDateTimeFormatWin.h"
#include "nsIScriptableDateFormat.h"
#include "nsLocalefactoryWin.h"
#include "nsLanguageAtomService.h"
#include "nsFontPackageService.h"
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_DEFINE_CID(kScriptableDateFormatCID, NS_SCRIPTABLEDATEFORMAT_CID);
NS_DEFINE_CID(kLanguageAtomServiceCID, NS_LANGUAGEATOMSERVICE_CID);
static NS_DEFINE_CID(kFontPackageServiceCID, NS_FONTPACKAGESERVICE_CID);
nsLocaleWinFactory::nsLocaleWinFactory(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
nsLocaleWinFactory::~nsLocaleWinFactory()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocaleWinFactory, nsIFactory)
nsresult nsLocaleWinFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsISupports *inst = NULL;
if (aIID.Equals(kICollationFactoryIID)) {
NS_NEWXPCOM(inst, nsCollationFactory);
}
else if (aIID.Equals(kICollationIID)) {
NS_NEWXPCOM(inst, nsCollationWin);
}
else if (aIID.Equals(kIDateTimeFormatIID)) {
NS_NEWXPCOM(inst, nsDateTimeFormatWin);
}
else if (aIID.Equals(NS_GET_IID(nsIScriptableDateFormat))) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kScriptableDateFormatCID)) {
inst = NEW_SCRIPTABLE_DATEFORMAT();
}
else if (mClassID.Equals(kLanguageAtomServiceCID)) {
NS_NEWXPCOM(inst, nsLanguageAtomService);
}
else if (mClassID.Equals(kFontPackageServiceCID)) {
nsIFontPackageService * pt = nsnull;
NS_NEWXPCOM(pt, nsFontPackageService);
inst = pt;
}
else
{
return NS_NOINTERFACE;
}
if (NULL == inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst); // Stabilize
nsresult res = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst); // Destabilize and avoid leaks. Avoid calling delete <interface pointer>
return res;
}
nsresult nsLocaleWinFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}

View File

@ -1,40 +0,0 @@
/* -*- 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.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/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.org 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.
*
* Contributor(s):
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsCollationWin.h"
#include "nsDateTimeFormatWin.h"
class nsLocaleWinFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
nsLocaleWinFactory(const nsCID &aClass);
~nsLocaleWinFactory();
private:
nsCID mClassID;
};

View File

@ -30,10 +30,6 @@
#include "nsIMacLocale.h"
#include "nsLocaleCID.h"
NS_DEFINE_IID(kIPlatformCharsetIID, NS_IPLATFORMCHARSET_IID);
NS_DEFINE_IID(kMacLocaleIID,NS_IMACLOCALE_IID);
NS_DEFINE_CID(kMacLocaleFactoryCID,NS_MACLOCALEFACTORY_CID);
static nsURLProperties *gInfo = nsnull;
static PRInt32 gCnt;
@ -53,7 +49,7 @@ private:
nsString mCharset;
};
NS_IMPL_ISUPPORTS(nsMacCharset, kIPlatformCharsetIID);
NS_IMPL_ISUPPORTS1(nsMacCharset, nsIPlatformCharset);
nsMacCharset::nsMacCharset()
{
@ -115,8 +111,8 @@ nsMacCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar*
nsString localeAsString(localeName), charset; charset.AssignWithConversion("x-mac-roman");
short script, language, region;
nsresult rv = nsComponentManager::CreateInstance(kMacLocaleFactoryCID,nsnull,kMacLocaleIID,
getter_AddRefs(pMacLocale));
nsresult rv;
pMacLocale = do_CreateInstance(NS_MACLOCALE_CONTRACTID, &rv);
if (NS_FAILED(rv)) { *_retValue = charset.ToNewUnicode(); return rv; }
rv = pMacLocale->GetPlatformLocale(&localeAsString,&script,&language,&region);

View File

@ -33,9 +33,6 @@
#include "nsLocaleCID.h"
#include "nsIComponentManager.h"
NS_DEFINE_IID(kIOS2LocaleIID,NS_IOS2LOCALE_IID);
NS_DEFINE_CID(kOS2LocaleFactoryCID,NS_OS2LOCALEFACTORY_CID);
static nsURLProperties *gInfo = nsnull;
static PRInt32 gCnt= 0;

View File

@ -25,7 +25,6 @@
#include "pratom.h"
#include "nsURLProperties.h"
#include "nsCOMPtr.h"
#include "nsIPosixLocale.h"
#include "nsLocaleCID.h"
#include "nsUConvDll.h"
#include "nsIComponentManager.h"
@ -44,10 +43,6 @@
#include <langinfo.h>
#endif
// {84B0F181-C6C7-11d2-B3B0-00805F8A6670}
static NS_DEFINE_IID(kIPosixLocaleIID,NS_IPOSIXLOCALE_IID);
static NS_DEFINE_CID(kPosixLocaleFactoryCID,NS_POSIXLOCALEFACTORY_CID);
class nsUNIXCharset : public nsIPlatformCharset
{
NS_DECL_ISUPPORTS

View File

@ -30,9 +30,6 @@
#include "nsLocaleCID.h"
#include "nsIComponentManager.h"
NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
static nsURLProperties *gInfo = nsnull;
static PRInt32 gCnt= 0;
@ -112,8 +109,8 @@ nsWinCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar*
//
// convert locale name to a code page (through the LCID)
//
nsresult result = nsComponentManager::CreateInstance(kWin32LocaleFactoryCID,nsnull,kIWin32LocaleIID,
getter_AddRefs(winLocale));
nsresult result;
winLocale = do_CreateInstance(NS_WIN32LOCALE_CONTRACTID, &result);
result = winLocale->GetPlatformLocale(&localeAsNSString,&localeAsLCID);
if (NS_FAILED(result)) { *_retValue = charset.ToNewUnicode(); return result; }