2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2007-04-11 18:29:47 +00:00
|
|
|
|
2013-10-23 19:14:56 +02:00
|
|
|
#ifndef INCLUDED_SVL_ONDEMAND_HXX
|
|
|
|
#define INCLUDED_SVL_ONDEMAND_HXX
|
2007-04-11 18:29:47 +00:00
|
|
|
|
2009-10-12 11:49:13 +02:00
|
|
|
#include <unotools/syslocale.hxx>
|
2013-04-05 18:40:39 +02:00
|
|
|
#include <i18nlangtag/lang.h>
|
2007-04-11 18:29:47 +00:00
|
|
|
#include <unotools/localedatawrapper.hxx>
|
|
|
|
#include <unotools/calendarwrapper.hxx>
|
|
|
|
#include <unotools/collatorwrapper.hxx>
|
|
|
|
#include <com/sun/star/i18n/CollatorOptions.hpp>
|
|
|
|
#include <unotools/transliterationwrapper.hxx>
|
|
|
|
#include <com/sun/star/i18n/TransliterationModules.hpp>
|
|
|
|
#include <unotools/nativenumberwrapper.hxx>
|
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2012-11-05 16:42:31 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2012-11-02 09:46:12 +02:00
|
|
|
|
2007-04-11 18:29:47 +00:00
|
|
|
/*
|
2014-04-29 19:25:03 +00:00
|
|
|
On demand instantiation and initialization of several i18n wrappers,
|
2007-04-11 18:29:47 +00:00
|
|
|
helping the number formatter to not perform worse than it already does.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @short
|
|
|
|
Switch between LANGUAGE_SYSTEM and LANGUAGE_ENGLISH_US and any other
|
|
|
|
LocaleDataWrapper.
|
|
|
|
SvNumberformatter uses it upon switching locales.
|
|
|
|
|
|
|
|
@descr
|
|
|
|
Avoids reloading and analysing of locale data again and again.
|
|
|
|
|
|
|
|
@ATTENTION
|
|
|
|
If the default ctor is used the init() method MUST be called before
|
|
|
|
accessing any locale data. The passed parameters Locale and LanguageType
|
|
|
|
must match each other.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class OnDemandLocaleDataWrapper
|
|
|
|
{
|
2012-11-05 11:28:43 +02:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
|
2007-04-11 18:29:47 +00:00
|
|
|
SvtSysLocale aSysLocale;
|
|
|
|
LanguageType eCurrentLanguage;
|
|
|
|
LanguageType eLastAnyLanguage;
|
|
|
|
const LocaleDataWrapper* pSystem;
|
|
|
|
const LocaleDataWrapper* pEnglish;
|
|
|
|
LocaleDataWrapper* pAny;
|
|
|
|
const LocaleDataWrapper* pCurrent;
|
|
|
|
bool bInitialized;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OnDemandLocaleDataWrapper()
|
|
|
|
: eLastAnyLanguage( LANGUAGE_DONTKNOW )
|
|
|
|
, pEnglish(0)
|
|
|
|
, pAny(0)
|
|
|
|
, bInitialized(false)
|
|
|
|
{
|
|
|
|
pCurrent = pSystem = aSysLocale.GetLocaleDataPtr();
|
|
|
|
eCurrentLanguage = LANGUAGE_SYSTEM;
|
|
|
|
}
|
|
|
|
OnDemandLocaleDataWrapper(
|
2012-11-05 11:28:43 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
|
2012-11-23 23:06:10 +01:00
|
|
|
const LanguageTag& rLanguageTag
|
2007-04-11 18:29:47 +00:00
|
|
|
)
|
|
|
|
: pEnglish(0)
|
|
|
|
, pAny(0)
|
|
|
|
, pCurrent(0)
|
|
|
|
, bInitialized(false)
|
|
|
|
{
|
|
|
|
pSystem = aSysLocale.GetLocaleDataPtr();
|
2012-11-23 23:06:10 +01:00
|
|
|
init( rxContext, rLanguageTag );
|
2007-04-11 18:29:47 +00:00
|
|
|
}
|
|
|
|
~OnDemandLocaleDataWrapper()
|
|
|
|
{
|
|
|
|
delete pEnglish;
|
|
|
|
delete pAny;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInitialized() const { return bInitialized; }
|
|
|
|
|
|
|
|
bool is() const { return pCurrent != NULL; }
|
|
|
|
|
|
|
|
void init(
|
2012-11-05 11:28:43 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
|
2012-11-23 23:06:10 +01:00
|
|
|
const LanguageTag& rLanguageTag
|
2007-04-11 18:29:47 +00:00
|
|
|
)
|
|
|
|
{
|
2012-11-05 11:28:43 +02:00
|
|
|
m_xContext = rxContext;
|
2012-11-23 23:06:10 +01:00
|
|
|
changeLocale( rLanguageTag );
|
2007-04-11 18:29:47 +00:00
|
|
|
bInitialized = true;
|
|
|
|
}
|
|
|
|
|
2012-11-23 23:06:10 +01:00
|
|
|
void changeLocale( const LanguageTag& rLanguageTag )
|
2007-04-11 18:29:47 +00:00
|
|
|
{
|
2012-11-23 23:06:10 +01:00
|
|
|
LanguageType eLang = rLanguageTag.getLanguageType( false);
|
2007-04-11 18:29:47 +00:00
|
|
|
switch ( eLang )
|
|
|
|
{
|
|
|
|
case LANGUAGE_SYSTEM :
|
|
|
|
pCurrent = pSystem;
|
|
|
|
break;
|
|
|
|
case LANGUAGE_ENGLISH_US :
|
|
|
|
if ( !pEnglish )
|
2012-11-23 23:06:10 +01:00
|
|
|
pEnglish = new LocaleDataWrapper( m_xContext, rLanguageTag );
|
2007-04-11 18:29:47 +00:00
|
|
|
pCurrent = pEnglish;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ( !pAny )
|
|
|
|
{
|
2012-11-23 23:06:10 +01:00
|
|
|
pAny = new LocaleDataWrapper( m_xContext, rLanguageTag );
|
2007-04-11 18:29:47 +00:00
|
|
|
eLastAnyLanguage = eLang;
|
|
|
|
}
|
|
|
|
else if ( eLastAnyLanguage != eLang )
|
|
|
|
{
|
2012-11-23 23:06:10 +01:00
|
|
|
pAny->setLanguageTag( rLanguageTag );
|
2007-04-11 18:29:47 +00:00
|
|
|
eLastAnyLanguage = eLang;
|
|
|
|
}
|
|
|
|
pCurrent = pAny;
|
|
|
|
}
|
|
|
|
eCurrentLanguage = eLang;
|
|
|
|
}
|
|
|
|
|
|
|
|
LanguageType getCurrentLanguage() const
|
|
|
|
{ return eCurrentLanguage; }
|
|
|
|
|
|
|
|
LocaleDataWrapper* getAnyLocale()
|
|
|
|
{
|
|
|
|
if ( !pAny )
|
|
|
|
{
|
2012-11-23 23:06:10 +01:00
|
|
|
pAny = new LocaleDataWrapper( m_xContext, pCurrent->getLanguageTag() );
|
2007-04-11 18:29:47 +00:00
|
|
|
eLastAnyLanguage = eCurrentLanguage;
|
|
|
|
}
|
|
|
|
else if ( pCurrent != pAny )
|
|
|
|
{
|
2012-11-23 23:06:10 +01:00
|
|
|
pAny->setLanguageTag( pCurrent->getLanguageTag() );
|
2007-04-11 18:29:47 +00:00
|
|
|
eLastAnyLanguage = eCurrentLanguage;
|
|
|
|
}
|
|
|
|
return pAny;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LocaleDataWrapper* get() const { return pCurrent; }
|
|
|
|
const LocaleDataWrapper* operator->() const { return get(); }
|
|
|
|
const LocaleDataWrapper& operator*() const { return *get(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Load a calendar only if it's needed.
|
|
|
|
SvNumberformatter uses it upon switching locales.
|
|
|
|
@ATTENTION If the default ctor is used the init() method MUST be called
|
|
|
|
before accessing the calendar.
|
|
|
|
*/
|
|
|
|
class OnDemandCalendarWrapper
|
|
|
|
{
|
2012-10-25 17:18:13 +02:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
|
2007-04-11 18:29:47 +00:00
|
|
|
::com::sun::star::lang::Locale aLocale;
|
|
|
|
mutable CalendarWrapper* pPtr;
|
|
|
|
mutable bool bValid;
|
|
|
|
bool bInitialized;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OnDemandCalendarWrapper()
|
|
|
|
: pPtr(0)
|
|
|
|
, bValid(false)
|
|
|
|
, bInitialized(false)
|
|
|
|
{}
|
|
|
|
OnDemandCalendarWrapper(
|
2012-10-25 17:18:13 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
|
2007-04-11 18:29:47 +00:00
|
|
|
::com::sun::star::lang::Locale& rLocale
|
|
|
|
)
|
|
|
|
: bValid(false)
|
|
|
|
, bInitialized(false)
|
|
|
|
{
|
2012-10-25 17:18:13 +02:00
|
|
|
init( rxContext, rLocale );
|
2007-04-11 18:29:47 +00:00
|
|
|
}
|
|
|
|
~OnDemandCalendarWrapper()
|
|
|
|
{
|
|
|
|
delete pPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInitialized() const { return bInitialized; }
|
|
|
|
|
|
|
|
bool is() const { return pPtr != NULL; }
|
|
|
|
|
|
|
|
void init(
|
2012-10-25 17:18:13 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
|
2012-11-23 23:06:10 +01:00
|
|
|
const ::com::sun::star::lang::Locale& rLocale
|
2007-04-11 18:29:47 +00:00
|
|
|
)
|
|
|
|
{
|
2012-10-25 17:18:13 +02:00
|
|
|
m_xContext = rxContext;
|
2007-04-11 18:29:47 +00:00
|
|
|
changeLocale( rLocale );
|
|
|
|
if ( pPtr )
|
|
|
|
{
|
|
|
|
delete pPtr;
|
|
|
|
pPtr = NULL;
|
|
|
|
}
|
|
|
|
bInitialized = true;
|
|
|
|
}
|
|
|
|
|
2012-11-23 23:06:10 +01:00
|
|
|
void changeLocale( const ::com::sun::star::lang::Locale& rLocale )
|
2007-04-11 18:29:47 +00:00
|
|
|
{
|
|
|
|
bValid = false;
|
|
|
|
aLocale = rLocale;
|
|
|
|
}
|
|
|
|
|
|
|
|
CalendarWrapper* get() const
|
|
|
|
{
|
|
|
|
if ( !bValid )
|
|
|
|
{
|
|
|
|
if ( !pPtr )
|
2012-10-25 17:18:13 +02:00
|
|
|
pPtr = new CalendarWrapper( m_xContext );
|
2007-04-11 18:29:47 +00:00
|
|
|
pPtr->loadDefaultCalendar( aLocale );
|
|
|
|
bValid = true;
|
|
|
|
}
|
|
|
|
return pPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CalendarWrapper* operator->() { return get(); }
|
|
|
|
CalendarWrapper& operator*() { return *get(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Load a transliteration only if it's needed.
|
|
|
|
SvNumberformatter uses it upon switching locales.
|
|
|
|
@ATTENTION If the default ctor is used the init() method MUST be called
|
|
|
|
before accessing the transliteration.
|
|
|
|
*/
|
|
|
|
class OnDemandTransliterationWrapper
|
|
|
|
{
|
2012-11-05 11:28:43 +02:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
|
2007-04-11 18:29:47 +00:00
|
|
|
LanguageType eLanguage;
|
|
|
|
::com::sun::star::i18n::TransliterationModules nType;
|
|
|
|
mutable ::utl::TransliterationWrapper* pPtr;
|
|
|
|
mutable bool bValid;
|
|
|
|
bool bInitialized;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OnDemandTransliterationWrapper()
|
|
|
|
: eLanguage( LANGUAGE_SYSTEM )
|
2014-03-22 20:50:50 +00:00
|
|
|
, nType(::com::sun::star::i18n::TransliterationModules_END_OF_MODULE)
|
2007-04-11 18:29:47 +00:00
|
|
|
, pPtr(0)
|
|
|
|
, bValid(false)
|
|
|
|
, bInitialized(false)
|
|
|
|
{}
|
|
|
|
OnDemandTransliterationWrapper(
|
2012-11-05 11:28:43 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
|
2007-04-11 18:29:47 +00:00
|
|
|
LanguageType eLang,
|
|
|
|
::com::sun::star::i18n::TransliterationModules nTypeP
|
|
|
|
)
|
|
|
|
: bValid(false)
|
|
|
|
, bInitialized(false)
|
|
|
|
{
|
2012-11-05 11:28:43 +02:00
|
|
|
init( rxContext, eLang, nTypeP );
|
2007-04-11 18:29:47 +00:00
|
|
|
}
|
|
|
|
~OnDemandTransliterationWrapper()
|
|
|
|
{
|
|
|
|
delete pPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInitialized() const { return bInitialized; }
|
|
|
|
|
|
|
|
bool is() const { return pPtr != NULL; }
|
|
|
|
|
|
|
|
void init(
|
2012-11-05 11:28:43 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
|
2007-04-11 18:29:47 +00:00
|
|
|
LanguageType eLang,
|
|
|
|
::com::sun::star::i18n::TransliterationModules nTypeP
|
|
|
|
)
|
|
|
|
{
|
2012-11-05 11:28:43 +02:00
|
|
|
m_xContext = rxContext;
|
2007-04-11 18:29:47 +00:00
|
|
|
nType = nTypeP;
|
|
|
|
changeLocale( eLang );
|
|
|
|
if ( pPtr )
|
|
|
|
{
|
|
|
|
delete pPtr;
|
|
|
|
pPtr = NULL;
|
|
|
|
}
|
|
|
|
bInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeLocale( LanguageType eLang )
|
|
|
|
{
|
|
|
|
bValid = false;
|
|
|
|
eLanguage = eLang;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::utl::TransliterationWrapper* get() const
|
|
|
|
{
|
|
|
|
if ( !bValid )
|
|
|
|
{
|
|
|
|
if ( !pPtr )
|
2012-11-05 11:28:43 +02:00
|
|
|
pPtr = new ::utl::TransliterationWrapper( m_xContext, nType );
|
2007-04-11 18:29:47 +00:00
|
|
|
pPtr->loadModuleIfNeeded( eLanguage );
|
|
|
|
bValid = true;
|
|
|
|
}
|
|
|
|
return pPtr;
|
|
|
|
}
|
|
|
|
|
2013-07-05 16:25:03 -05:00
|
|
|
const ::utl::TransliterationWrapper* getForModule( const OUString& rModule, LanguageType eLang ) const
|
2007-04-11 18:29:47 +00:00
|
|
|
{
|
|
|
|
if ( !pPtr )
|
2012-11-05 11:28:43 +02:00
|
|
|
pPtr = new ::utl::TransliterationWrapper( m_xContext, nType );
|
2007-04-11 18:29:47 +00:00
|
|
|
pPtr->loadModuleByImplName( rModule, eLang );
|
|
|
|
bValid = false; // reforce settings change in get()
|
|
|
|
return pPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::utl::TransliterationWrapper* operator->() const { return get(); }
|
|
|
|
const ::utl::TransliterationWrapper& operator*() const { return *get(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Load a native number service wrapper only if it's needed.
|
|
|
|
SvNumberformatter uses it.
|
|
|
|
|
|
|
|
@ATTENTION
|
|
|
|
If the default ctor is used the init() method MUST be called
|
|
|
|
before accessing the native number supplier.
|
|
|
|
*/
|
|
|
|
class OnDemandNativeNumberWrapper
|
|
|
|
{
|
2012-11-05 15:07:20 +02:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
|
2007-04-11 18:29:47 +00:00
|
|
|
mutable NativeNumberWrapper* pPtr;
|
|
|
|
bool bInitialized;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OnDemandNativeNumberWrapper()
|
|
|
|
: pPtr(0)
|
|
|
|
, bInitialized(false)
|
|
|
|
{}
|
|
|
|
OnDemandNativeNumberWrapper(
|
2012-11-05 15:07:20 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
|
2007-04-11 18:29:47 +00:00
|
|
|
)
|
|
|
|
: pPtr(0)
|
|
|
|
, bInitialized(false)
|
|
|
|
{
|
2012-11-05 15:07:20 +02:00
|
|
|
init( rxContext );
|
2007-04-11 18:29:47 +00:00
|
|
|
}
|
|
|
|
~OnDemandNativeNumberWrapper()
|
|
|
|
{
|
|
|
|
delete pPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInitialized() const { return bInitialized; }
|
|
|
|
|
|
|
|
void init(
|
2012-11-05 15:07:20 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
|
2007-04-11 18:29:47 +00:00
|
|
|
)
|
|
|
|
{
|
2012-11-05 15:07:20 +02:00
|
|
|
m_xContext = rxContext;
|
2007-04-11 18:29:47 +00:00
|
|
|
if ( pPtr )
|
|
|
|
{
|
|
|
|
delete pPtr;
|
|
|
|
pPtr = NULL;
|
|
|
|
}
|
|
|
|
bInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is() const { return pPtr != NULL; }
|
|
|
|
|
|
|
|
NativeNumberWrapper* get() const
|
|
|
|
{
|
|
|
|
if ( !pPtr )
|
2012-11-05 15:07:20 +02:00
|
|
|
pPtr = new NativeNumberWrapper( m_xContext );
|
2007-04-11 18:29:47 +00:00
|
|
|
return pPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeNumberWrapper* operator->() { return get(); }
|
|
|
|
NativeNumberWrapper& operator*() { return *get(); }
|
|
|
|
};
|
|
|
|
|
2013-10-23 19:14:56 +02:00
|
|
|
#endif // INCLUDED_SVL_ONDEMAND_HXX
|
2007-04-11 18:29:47 +00:00
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|