diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-08-01 13:50:45 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-08-02 10:36:07 +0200 |
commit | 13fac4894f752e922727c6f22c6303712e06ba12 (patch) | |
tree | 5689829e917927bb13461d91988ec99e461f1831 /svtools | |
parent | 13cadf3fe38daa0b4cfddcfa68ec8631bc85f44a (diff) |
normalize resource locale ctor construction mechanisms
make them all the same and share std::locales more
various OModuleClient, etc, classes go away
Change-Id: I7e3ff01a69332eeacd22e3078f66a60318de62d5
Reviewed-on: https://gerrit.libreoffice.org/40634
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/misc/ehdl.cxx | 66 | ||||
-rw-r--r-- | svtools/source/misc/svtresid.cxx | 17 |
2 files changed, 27 insertions, 56 deletions
diff --git a/svtools/source/misc/ehdl.cxx b/svtools/source/misc/ehdl.cxx index 47a5689ec031..01498bb6ece5 100644 --- a/svtools/source/misc/ehdl.cxx +++ b/svtools/source/misc/ehdl.cxx @@ -139,15 +139,10 @@ static DialogMask aWndFunc( return nRet; } -SfxErrorHandler::SfxErrorHandler(const ErrMsgCode* pIdPs, ErrCode lStartP, ErrCode lEndP, const std::locale* pLocale) - : lStart(lStartP), lEnd(lEndP), pIds(pIdPs), pResLocale(pLocale) +SfxErrorHandler::SfxErrorHandler(const ErrMsgCode* pIdPs, ErrCode lStartP, ErrCode lEndP, const std::locale& rLocale) + : lStart(lStartP), lEnd(lEndP), pIds(pIdPs), rResLocale(rLocale) { ErrorRegistry::RegisterDisplay(&aWndFunc); - if (!pResLocale) - { - xFreeLocale.reset(new std::locale(Translate::Create("svt"))); - pResLocale = xFreeLocale.get(); - } } SfxErrorHandler::~SfxErrorHandler() @@ -197,12 +192,11 @@ void SfxErrorHandler::GetClassString(sal_uLong lClassId, OUString &rStr) */ { - std::locale loc(Translate::Create("svt")); for (const ErrMsgCode* pItem = getRID_ERRHDL(); pItem->second; ++pItem) { if (sal_uInt32(pItem->second) == lClassId) { - rStr = Translate::get(pItem->first, loc); + rStr = SvtResId(pItem->first); break; } } @@ -227,7 +221,7 @@ bool SfxErrorHandler::GetErrorString(ErrCode lErrId, OUString &rStr) const { if (pItem->second == nErrId) { - rStr = rStr.replaceAll("$(ERROR)", Translate::get(pItem->first, *pResLocale)); + rStr = rStr.replaceAll("$(ERROR)", Translate::get(pItem->first, rResLocale)); bRet = true; break; } @@ -247,8 +241,8 @@ bool SfxErrorHandler::GetErrorString(ErrCode lErrId, OUString &rStr) const } SfxErrorContext::SfxErrorContext( - sal_uInt16 nCtxIdP, vcl::Window *pWindow, const ErrMsgCode* pIdsP, const std::locale* pResLocaleP) -: ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP), pResLocale(pResLocaleP) + sal_uInt16 nCtxIdP, vcl::Window *pWindow, const ErrMsgCode* pIdsP, const std::locale& rResLocaleP) +: ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP), rResLocale(rResLocaleP) { if (!pIds) pIds = getRID_ERRCTX(); @@ -257,8 +251,8 @@ SfxErrorContext::SfxErrorContext( SfxErrorContext::SfxErrorContext( sal_uInt16 nCtxIdP, const OUString &aArg1P, vcl::Window *pWindow, - const ErrMsgCode* pIdsP, const std::locale* pResLocaleP) -: ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP), pResLocale(pResLocaleP), + const ErrMsgCode* pIdsP, const std::locale& rResLocaleP) +: ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP), rResLocale(rResLocaleP), aArg1(aArg1P) { if (!pIds) @@ -274,46 +268,32 @@ bool SfxErrorContext::GetString(ErrCode nErrId, OUString &rStr) { bool bRet = false; - std::locale* pFreeLocale = nullptr; - if (!pResLocale) - { - pFreeLocale = new std::locale(Translate::Create("svt")); - pResLocale = pFreeLocale; - } - if (pResLocale) + for (const ErrMsgCode* pItem = pIds; pItem->second; ++pItem) { - for (const ErrMsgCode* pItem = pIds; pItem->second; ++pItem) + if (sal_uInt32(pItem->second) == nCtxId) { - if (sal_uInt32(pItem->second) == nCtxId) - { - rStr = Translate::get(pItem->first, *pResLocale); - rStr = rStr.replaceAll("$(ARG1)", aArg1); - bRet = true; - break; - } + rStr = Translate::get(pItem->first, rResLocale); + rStr = rStr.replaceAll("$(ARG1)", aArg1); + bRet = true; + break; } + } - SAL_WARN_IF(!bRet, "svtools.misc", "ErrorContext cannot find the resource"); + SAL_WARN_IF(!bRet, "svtools.misc", "ErrorContext cannot find the resource"); - if ( bRet ) + if ( bRet ) + { + sal_uInt16 nId = nErrId.IsWarning() ? ERRCTX_WARNING : ERRCTX_ERROR; + for (const ErrMsgCode* pItem = getRID_ERRCTX(); pItem->second; ++pItem) { - sal_uInt16 nId = nErrId.IsWarning() ? ERRCTX_WARNING : ERRCTX_ERROR; - for (const ErrMsgCode* pItem = getRID_ERRCTX(); pItem->second; ++pItem) + if (sal_uInt32(pItem->second) == nId) { - if (sal_uInt32(pItem->second) == nId) - { - rStr = rStr.replaceAll("$(ERR)", Translate::get(pItem->first, *pResLocale)); - break; - } + rStr = rStr.replaceAll("$(ERR)", Translate::get(pItem->first, rResLocale)); + break; } } } - if (pFreeLocale) - { - delete pFreeLocale; - pResLocale = nullptr; - } return bRet; } diff --git a/svtools/source/misc/svtresid.cxx b/svtools/source/misc/svtresid.cxx index e6cac0b9b981..f7cfdf8ba0f3 100644 --- a/svtools/source/misc/svtresid.cxx +++ b/svtools/source/misc/svtresid.cxx @@ -18,26 +18,17 @@ */ #include <unotools/resmgr.hxx> -#include <tools/solar.h> #include <svtools/svtresid.hxx> -static std::locale* pResLocale=nullptr; - -std::locale* SvtResLocale::GetResLocale() -{ - if (!pResLocale) - pResLocale = new std::locale(Translate::Create("svt")); - return pResLocale; -} - -void SvtResLocale::DeleteResLocale() +const std::locale& SvtResLocale() { - DELETEZ(pResLocale); + static std::locale loc = Translate::Create("svt"); + return loc; } OUString SvtResId(const char* pId) { - return Translate::get(pId, *SvtResLocale::GetResLocale()); + return Translate::get(pId, SvtResLocale()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |