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 /formula/source | |
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 'formula/source')
-rw-r--r-- | formula/source/core/api/FormulaCompiler.cxx | 4 | ||||
-rw-r--r-- | formula/source/core/inc/core_resource.hxx | 72 | ||||
-rw-r--r-- | formula/source/core/resource/core_resource.cxx | 60 | ||||
-rw-r--r-- | formula/source/ui/dlg/formula.cxx | 6 | ||||
-rw-r--r-- | formula/source/ui/dlg/funcpage.cxx | 1 | ||||
-rw-r--r-- | formula/source/ui/dlg/funcpage.hxx | 2 | ||||
-rw-r--r-- | formula/source/ui/dlg/funcutl.cxx | 6 | ||||
-rw-r--r-- | formula/source/ui/dlg/omoduleclient.cxx | 34 | ||||
-rw-r--r-- | formula/source/ui/dlg/parawin.cxx | 6 | ||||
-rw-r--r-- | formula/source/ui/dlg/parawin.hxx | 2 | ||||
-rw-r--r-- | formula/source/ui/dlg/structpg.cxx | 1 | ||||
-rw-r--r-- | formula/source/ui/dlg/structpg.hxx | 3 | ||||
-rw-r--r-- | formula/source/ui/inc/ModuleHelper.hxx | 66 | ||||
-rw-r--r-- | formula/source/ui/resource/ModuleHelper.cxx | 123 |
14 files changed, 15 insertions, 371 deletions
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index 5ff5067505c6..0377fd761df3 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -235,7 +235,7 @@ void OpCodeList::putDefaultOpCode( const FormulaCompiler::NonConstOpCodeMapPtr& } if (!pKey) return; - OUString sKey = !mbLocalized ? OUString::createFromAscii(pKey) : Translate::get(pKey, ResourceManager::getResLocale()); + OUString sKey = !mbLocalized ? OUString::createFromAscii(pKey) : ForResId(pKey); xMap->putOpCode(sKey, OpCode(nOp), pCharClass); } @@ -853,7 +853,6 @@ void lcl_fillNativeSymbols( FormulaCompiler::NonConstOpCodeMapPtr& xMap, bool bD aSymbolMap.mxSymbolMap.reset( new FormulaCompiler::OpCodeMap( SC_OPCODE_LAST_OPCODE_ID + 1, true, FormulaGrammar::GRAM_NATIVE_UI)); - OModuleClient aModuleClient; OpCodeList aOpCodeListSymbols(false, RID_STRLIST_FUNCTION_NAMES_SYMBOLS, aSymbolMap.mxSymbolMap); OpCodeList aOpCodeListNative(true, RID_STRLIST_FUNCTION_NAMES, aSymbolMap.mxSymbolMap); // No AddInMap for native core mapping. @@ -949,7 +948,6 @@ void FormulaCompiler::loadSymbols(const std::pair<const char*, int>* pSymbols, F { // not Core rxMap.reset( new OpCodeMap( SC_OPCODE_LAST_OPCODE_ID + 1, eGrammar != FormulaGrammar::GRAM_ODFF, eGrammar )); - OModuleClient aModuleClient; OpCodeList aOpCodeList(false, pSymbols, rxMap, eSepType); fillFromAddInMap( rxMap, eGrammar); diff --git a/formula/source/core/inc/core_resource.hxx b/formula/source/core/inc/core_resource.hxx deleted file mode 100644 index 3dc321b57834..000000000000 --- a/formula/source/core/inc/core_resource.hxx +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ - -#ifndef INCLUDED_FORMULA_SOURCE_CORE_INC_CORE_RESOURCE_HXX -#define INCLUDED_FORMULA_SOURCE_CORE_INC_CORE_RESOURCE_HXX - -#include <rtl/ustring.hxx> - -namespace formula -{ - - //= ResourceManager - //= handling resources within the FORMULA-Core library - - class ResourceManager - { - friend class OModuleClient; - static sal_Int32 s_nClients; /// number of registered clients - static std::locale* m_pImpl; - - private: - // no instantiation allowed - ResourceManager() = delete; - ~ResourceManager() { } - - protected: - static void ensureImplExists(); - /// register a client for the module - static void registerClient(); - /// revoke a client for the module - static void revokeClient(); - - public: - - static const std::locale& getResLocale(); - }; - - - //= OModuleClient - - /** base class for objects which uses any global module-specific resources - */ - class OModuleClient - { - public: - OModuleClient() { ResourceManager::registerClient(); } - ~OModuleClient() { ResourceManager::revokeClient(); } - }; - - -} // formula - - -#endif // INCLUDED_FORMULA_SOURCE_CORE_INC_CORE_RESOURCE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/formula/source/core/resource/core_resource.cxx b/formula/source/core/resource/core_resource.cxx index 5163d41b5ae7..d68ab6b193a8 100644 --- a/formula/source/core/resource/core_resource.cxx +++ b/formula/source/core/resource/core_resource.cxx @@ -16,63 +16,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - -#include "core_resource.hxx" - #include <unotools/resmgr.hxx> +#include "core_resource.hxx" -// ---- needed as long as we have no contexts for components --- -#include <rtl/instance.hxx> -#include <svl/solar.hrc> - - -namespace formula +OUString ForResId(const char *pId) { - - - //= ResourceManager - - namespace - { - // access safety - struct theResourceManagerMutex : public rtl::Static< osl::Mutex, theResourceManagerMutex > {}; - } - - sal_Int32 ResourceManager::s_nClients = 0; - std::locale* ResourceManager::m_pImpl = nullptr; - - void ResourceManager::ensureImplExists() - { - if (m_pImpl) - return; - - m_pImpl = new std::locale(Translate::Create("for")); - } - - void ResourceManager::registerClient() - { - ::osl::MutexGuard aGuard(theResourceManagerMutex::get()); - ++s_nClients; - } - - void ResourceManager::revokeClient() - { - ::osl::MutexGuard aGuard(theResourceManagerMutex::get()); - if (!--s_nClients && m_pImpl) - { - delete m_pImpl; - m_pImpl = nullptr; - } - } - - const std::locale& ResourceManager::getResLocale() - { - ensureImplExists(); - return *m_pImpl; - } - - -} // formula - + static std::locale loc = Translate::Create("for"); + return Translate::get(pId, loc); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx index 2290a98ac4a4..814184cbb628 100644 --- a/formula/source/ui/dlg/formula.cxx +++ b/formula/source/ui/dlg/formula.cxx @@ -50,8 +50,8 @@ #include "formula/formulahelper.hxx" #include "structpg.hxx" #include "parawin.hxx" -#include "ModuleHelper.hxx" #include "strings.hrc" +#include "core_resource.hxx" #include <com/sun/star/sheet/FormulaToken.hpp> #include <com/sun/star/sheet/FormulaLanguage.hpp> #include <com/sun/star/sheet/FormulaMapGroup.hpp> @@ -236,8 +236,8 @@ FormulaDlg_Impl::FormulaDlg_Impl(Dialog* pParent m_pTheRefButton (nullptr), m_pMEdit (nullptr), m_bUserMatrixFlag(false), - m_aTitle1 ( ModuleRes( STR_TITLE1 ) ), - m_aTitle2 ( ModuleRes( STR_TITLE2 ) ), + m_aTitle1 ( ForResId( STR_TITLE1 ) ), + m_aTitle2 ( ForResId( STR_TITLE2 ) ), m_aFormulaHelper(_pFunctionMgr), m_bIsShutDown (false), m_bMakingTree (false), diff --git a/formula/source/ui/dlg/funcpage.cxx b/formula/source/ui/dlg/funcpage.cxx index e017a9a6c543..8a12f389a73c 100644 --- a/formula/source/ui/dlg/funcpage.cxx +++ b/formula/source/ui/dlg/funcpage.cxx @@ -25,7 +25,6 @@ #include "formula/IFunctionDescription.hxx" #include "funcpage.hxx" -#include "ModuleHelper.hxx" #include <unotools/syslocale.hxx> #include <unotools/charclass.hxx> diff --git a/formula/source/ui/dlg/funcpage.hxx b/formula/source/ui/dlg/funcpage.hxx index efdd45b4f9bd..020f962a12cb 100644 --- a/formula/source/ui/dlg/funcpage.hxx +++ b/formula/source/ui/dlg/funcpage.hxx @@ -30,7 +30,6 @@ #include <svtools/treelistbox.hxx> #include <vector> -#include "formula/omoduleclient.hxx" namespace formula { @@ -58,7 +57,6 @@ typedef const IFunctionDescription* TFunctionDesc; class FuncPage : public TabPage { private: - OModuleClient m_aModuleClient; Link<FuncPage&,void> aDoubleClickLink; Link<FuncPage&,void> aSelectionLink; VclPtr<ListBox> m_pLbCategory; diff --git a/formula/source/ui/dlg/funcutl.cxx b/formula/source/ui/dlg/funcutl.cxx index e52628d867e6..0271e87956d0 100644 --- a/formula/source/ui/dlg/funcutl.cxx +++ b/formula/source/ui/dlg/funcutl.cxx @@ -26,9 +26,9 @@ #include "formula/funcutl.hxx" #include "formula/IControlReferenceHandler.hxx" #include "ControlHelper.hxx" -#include "ModuleHelper.hxx" #include "strings.hrc" #include "bitmaps.hlst" +#include "core_resource.hxx" #include "com/sun/star/accessibility/AccessibleRole.hpp" namespace formula @@ -521,8 +521,8 @@ RefButton::RefButton( vcl::Window* _pParent, WinBits nStyle ) : ImageButton(_pParent, nStyle), aImgRefStart(BitmapEx(RID_BMP_REFBTN1)), aImgRefDone(BitmapEx(RID_BMP_REFBTN2)), - aShrinkQuickHelp( ModuleRes( RID_STR_SHRINK ) ), - aExpandQuickHelp( ModuleRes( RID_STR_EXPAND ) ), + aShrinkQuickHelp( ForResId( RID_STR_SHRINK ) ), + aExpandQuickHelp( ForResId( RID_STR_EXPAND ) ), pAnyRefDlg( nullptr ), pRefEdit( nullptr ) { diff --git a/formula/source/ui/dlg/omoduleclient.cxx b/formula/source/ui/dlg/omoduleclient.cxx deleted file mode 100644 index 328287e1b4db..000000000000 --- a/formula/source/ui/dlg/omoduleclient.cxx +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ - -#include "sal/config.h" - -#include "formula/omoduleclient.hxx" - -#include "ModuleHelper.hxx" - -formula::OModuleClient::OModuleClient() { - OModule::registerClient(); -} - -formula::OModuleClient::~OModuleClient() { - OModule::revokeClient(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/formula/source/ui/dlg/parawin.cxx b/formula/source/ui/dlg/parawin.cxx index f066b40e82a5..128f81d9c475 100644 --- a/formula/source/ui/dlg/parawin.cxx +++ b/formula/source/ui/dlg/parawin.cxx @@ -26,9 +26,9 @@ #include "formula/formdata.hxx" #include "formula/IFunctionDescription.hxx" #include <formula/funcvarargs.h> -#include "ModuleHelper.hxx" #include "strings.hrc" #include "bitmaps.hlst" +#include "core_resource.hxx" namespace formula { @@ -38,8 +38,8 @@ ParaWin::ParaWin(vcl::Window* pParent,IControlReferenceHandler* _pDlg): TabPage (pParent, "ParameterPage", "formula/ui/parameter.ui"), pFuncDesc ( nullptr ), pMyParent (_pDlg), - m_sOptional ( ModuleRes( STR_OPTIONAL ) ), - m_sRequired ( ModuleRes( STR_REQUIRED ) ) + m_sOptional ( ForResId( STR_OPTIONAL ) ), + m_sRequired ( ForResId( STR_REQUIRED ) ) { get(m_pFtEditDesc, "editdesc"); get(m_pFtArgName, "parname"); diff --git a/formula/source/ui/dlg/parawin.hxx b/formula/source/ui/dlg/parawin.hxx index 6884b93a08a3..526b571bdc01 100644 --- a/formula/source/ui/dlg/parawin.hxx +++ b/formula/source/ui/dlg/parawin.hxx @@ -30,7 +30,6 @@ #include <vector> #include "formula/funcutl.hxx" -#include "formula/omoduleclient.hxx" #include "ControlHelper.hxx" namespace formula @@ -44,7 +43,6 @@ class IControlReferenceHandler; class ParaWin : public TabPage { private: - OModuleClient m_aModuleClient; Link<ParaWin&,void> aFxLink; Link<ParaWin&,void> aArgModifiedLink; diff --git a/formula/source/ui/dlg/structpg.cxx b/formula/source/ui/dlg/structpg.cxx index afebc0cba5c8..da566d673687 100644 --- a/formula/source/ui/dlg/structpg.cxx +++ b/formula/source/ui/dlg/structpg.cxx @@ -25,7 +25,6 @@ #include "structpg.hxx" #include "formula/formdata.hxx" #include "formula/formula.hxx" -#include "ModuleHelper.hxx" #include "formula/IFunctionDescription.hxx" #include "bitmaps.hlst" diff --git a/formula/source/ui/dlg/structpg.hxx b/formula/source/ui/dlg/structpg.hxx index b20fa265051d..c1ade7a5741a 100644 --- a/formula/source/ui/dlg/structpg.hxx +++ b/formula/source/ui/dlg/structpg.hxx @@ -27,8 +27,6 @@ #include <vcl/tabctrl.hxx> #include <svtools/treelistbox.hxx> #include "formula/IFunctionDescription.hxx" -#include "formula/omoduleclient.hxx" - namespace formula { @@ -65,7 +63,6 @@ public: class StructPage : public TabPage { private: - OModuleClient m_aModuleClient; Link<StructPage&,void> aSelLink; VclPtr<StructListBox> m_pTlbStruct; diff --git a/formula/source/ui/inc/ModuleHelper.hxx b/formula/source/ui/inc/ModuleHelper.hxx deleted file mode 100644 index 91cbb88a0b29..000000000000 --- a/formula/source/ui/inc/ModuleHelper.hxx +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ - -#ifndef INCLUDED_FORMULA_SOURCE_UI_INC_MODULEHELPER_HXX -#define INCLUDED_FORMULA_SOURCE_UI_INC_MODULEHELPER_HXX - -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <unotools/resmgr.hxx> - -namespace formula -{ - //= OModule - - class OModuleClient; - class OModuleImpl; - class OModule - { - friend class OModuleClient; - - private: - OModule() = delete; //TODO: get rid of this class - - protected: - static sal_Int32 s_nClients; /// number of registered clients - static OModuleImpl* s_pImpl; /// impl class. lives as long as at least one client for the module is registered - - public: - /// get the vcl res manager of the module - static const std::locale& getResLocale(); - protected: - /// register a client for the module - static void registerClient(); - /// revoke a client for the module - static void revokeClient(); - - private: - /** ensure that the impl class exists - @precond m_aMutex is guarded when this method gets called - */ - static void ensureImpl(); - }; - - //= ModuleRes - OUString ModuleRes(const char *pId); -} // namespace formula - -#endif // INCLUDED_FORMULA_SOURCE_UI_INC_MODULEHELPER_HXX - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/formula/source/ui/resource/ModuleHelper.cxx b/formula/source/ui/resource/ModuleHelper.cxx deleted file mode 100644 index 0b0ff18403b7..000000000000 --- a/formula/source/ui/resource/ModuleHelper.cxx +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ -#include <memory> -#include "ModuleHelper.hxx" -#include <comphelper/processfactory.hxx> -#include <osl/thread.h> -#include <com/sun/star/util/XMacroExpander.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/uno/XComponentContext.hpp> -#include <rtl/instance.hxx> -#include <rtl/uri.hxx> -#include <svl/solar.hrc> -#include <vcl/settings.hxx> -#include <vcl/svapp.hxx> - -#define ENTER_MOD_METHOD() \ - ::osl::MutexGuard aGuard(theOModuleMutex::get()); \ - ensureImpl() - - -namespace formula -{ - - using namespace ::com::sun::star; - -//= OModuleImpl - -/** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner -*/ -class OModuleImpl -{ - std::unique_ptr<std::locale> m_xResources; - -public: - /// ctor - OModuleImpl(); - - /// get the manager for the resources of the module - const std::locale& getResLocale(); -}; - -OModuleImpl::OModuleImpl() -{ -} - -const std::locale& OModuleImpl::getResLocale() -{ - // note that this method is not threadsafe, which counts for the whole class ! - - if (!m_xResources) - { - // create a manager with a fixed prefix - m_xResources.reset(new std::locale(Translate::Create("for"))); - } - return *m_xResources; -} - -//= OModule - -namespace -{ - // access safety - struct theOModuleMutex : public rtl::Static< osl::Mutex, theOModuleMutex > {}; -} -sal_Int32 OModule::s_nClients = 0; -OModuleImpl* OModule::s_pImpl = nullptr; - -const std::locale& OModule::getResLocale() -{ - ENTER_MOD_METHOD(); - return s_pImpl->getResLocale(); -} - -void OModule::registerClient() -{ - ::osl::MutexGuard aGuard(theOModuleMutex::get()); - ++s_nClients; -} - - -void OModule::revokeClient() -{ - ::osl::MutexGuard aGuard(theOModuleMutex::get()); - if (!--s_nClients && s_pImpl) - { - delete s_pImpl; - s_pImpl = nullptr; - } -} - - -void OModule::ensureImpl() -{ - if (s_pImpl) - return; - s_pImpl = new OModuleImpl(); -} - -OUString ModuleRes(const char *pId) -{ - return Translate::get(pId, OModule::getResLocale()); -}; - -} // namespace formula - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |