cui/source/options/optdict.cxx       |    4 ++--
 include/svtools/ehdl.hxx             |   10 +++++-----
 include/svx/ehdl.hxx                 |   24 ++++++++++++++++++++++++
 sd/source/ui/func/futhes.cxx         |    4 ++--
 svtools/source/misc/ehdl.cxx         |   17 +++++++++++------
 svx/Library_svx.mk                   |    1 +
 svx/source/items/ehdl.cxx            |   21 +++++++++++++++++++++
 sw/source/uibase/uiview/viewling.cxx |    8 +++-----
 8 files changed, 69 insertions(+), 20 deletions(-)

New commits:
commit ec366ca472b65afd26cbd90da78940a353f5e2a4
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Jan 15 20:18:13 2025 +0000
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Jan 16 14:39:35 2025 +0100

    defer creating std::locale until it is needed
    
    (if ever, seeing as it's only required if there is an error)
    
    Change-Id: Id8ba5ff495dfd2048401231023a09abba9bbf785
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180303
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/cui/source/options/optdict.cxx b/cui/source/options/optdict.cxx
index dbe7f80e3d6b..a898bd0e66b8 100644
--- a/cui/source/options/optdict.cxx
+++ b/cui/source/options/optdict.cxx
@@ -20,6 +20,7 @@
 #include <editeng/unolingu.hxx>
 #include <o3tl/safeint.hxx>
 #include <svx/dialmgr.hxx>
+#include <svx/ehdl.hxx>
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/linguistic2/XDictionary.hpp>
 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
@@ -190,8 +191,7 @@ IMPL_LINK_NOARG(SvxNewDictionaryDialog, OKHdl_Impl, 
weld::Button&, void)
     {
         m_xNewDic = nullptr;
         // error: couldn't create new dictionary
-        SfxErrorContext aContext( ERRCTX_SVX_LINGU_DICTIONARY, OUString(),
-            m_xDialog.get(), RID_SVXERRCTX, SvxResLocale() );
+        SvxErrorContext aContext(ERRCTX_SVX_LINGU_DICTIONARY, OUString(), 
m_xDialog.get());
         ErrorHandler::HandleError( ErrCodeMsg(
                 ERRCODE_SVX_LINGU_DICT_NOTWRITEABLE, sDict ) );
         m_xDialog->response(RET_CANCEL);
diff --git a/include/svtools/ehdl.hxx b/include/svtools/ehdl.hxx
index 1e70ee1ca55e..a8e7481e8c92 100644
--- a/include/svtools/ehdl.hxx
+++ b/include/svtools/ehdl.hxx
@@ -29,21 +29,21 @@ SVT_DLLPUBLIC extern const ErrMsgCode RID_ERRCTX[];
 
 namespace weld { class Window; }
 
-class SVT_DLLPUBLIC SfxErrorContext final : private ErrorContext
+class SVT_DLLPUBLIC SfxErrorContext : private ErrorContext
 {
 public:
     SfxErrorContext(
             sal_uInt16 nCtxIdP, weld::Window *pWin=nullptr,
-            const ErrMsgCode* pIds = nullptr, const std::locale& rResLocaleP = 
SvtResLocale());
+            const ErrMsgCode* pIds = nullptr);
     SfxErrorContext(
             sal_uInt16 nCtxIdP, OUString aArg1, weld::Window *pWin=nullptr,
-            const ErrMsgCode* pIds = nullptr, const std::locale& rResLocaleP = 
SvtResLocale());
+            const ErrMsgCode* pIds = nullptr);
     bool GetString(const ErrCodeMsg& nErrId, OUString &rStr) override;
-
+private:
+    virtual OUString Translate(TranslateId aId) const;
 private:
     sal_uInt16 nCtxId;
     const ErrMsgCode* pIds;
-    std::locale aResLocale;
     OUString aArg1;
 };
 
diff --git a/include/svx/ehdl.hxx b/include/svx/ehdl.hxx
new file mode 100644
index 000000000000..553f8420396f
--- /dev/null
+++ b/include/svx/ehdl.hxx
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include <svx/svxdllapi.h>
+#include <svtools/ehdl.hxx>
+
+class SVX_DLLPUBLIC SvxErrorContext : public SfxErrorContext
+{
+public:
+    SvxErrorContext(sal_uInt16 nCtxIdP, OUString aArg1, weld::Window* pWin);
+
+private:
+    virtual OUString Translate(TranslateId aId) const;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sd/source/ui/func/futhes.cxx b/sd/source/ui/func/futhes.cxx
index d978880039dd..a96b25e019a0 100644
--- a/sd/source/ui/func/futhes.cxx
+++ b/sd/source/ui/func/futhes.cxx
@@ -21,6 +21,7 @@
 
 #include <editeng/outliner.hxx>
 #include <sfx2/request.hxx>
+#include <svx/ehdl.hxx>
 #include <svx/svdobj.hxx>
 #include <svx/svdotext.hxx>
 #include <editeng/eeitem.hxx>
@@ -62,8 +63,7 @@ rtl::Reference<FuPoor> FuThesaurus::Create( ViewShell* 
pViewSh, ::sd::Window* pW
 
 void FuThesaurus::DoExecute(SfxRequest& rReq)
 {
-    SfxErrorContext aContext(ERRCTX_SVX_LINGU_THESAURUS, OUString(),
-                             mpWindow->GetFrameWeld(), RID_SVXERRCTX, 
SvxResLocale());
+    SvxErrorContext aContext(ERRCTX_SVX_LINGU_THESAURUS, OUString(), 
mpWindow->GetFrameWeld());
 
     if (dynamic_cast< DrawViewShell *>( mpViewShell ))
     {
diff --git a/svtools/source/misc/ehdl.cxx b/svtools/source/misc/ehdl.cxx
index 59613089a514..17d2827c1efa 100644
--- a/svtools/source/misc/ehdl.cxx
+++ b/svtools/source/misc/ehdl.cxx
@@ -230,8 +230,8 @@ bool SfxErrorHandler::GetErrorString(ErrCode lErrId, 
OUString &rStr) const
 }
 
 SfxErrorContext::SfxErrorContext(
-    sal_uInt16 nCtxIdP, weld::Window *pWindow, const ErrMsgCode* pIdsP, const 
std::locale& rResLocaleP)
-:   ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP), 
aResLocale(rResLocaleP)
+    sal_uInt16 nCtxIdP, weld::Window *pWindow, const ErrMsgCode* pIdsP)
+:   ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP)
 {
     if (!pIds)
         pIds = RID_ERRCTX;
@@ -240,14 +240,19 @@ SfxErrorContext::SfxErrorContext(
 
 SfxErrorContext::SfxErrorContext(
     sal_uInt16 nCtxIdP, OUString aArg1P, weld::Window *pWindow,
-    const ErrMsgCode* pIdsP, const std::locale& rResLocaleP)
-:   ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP), 
aResLocale(rResLocaleP),
+    const ErrMsgCode* pIdsP)
+:   ErrorContext(pWindow), nCtxId(nCtxIdP), pIds(pIdsP),
     aArg1(std::move(aArg1P))
 {
     if (!pIds)
         pIds = RID_ERRCTX;
 }
 
+OUString SfxErrorContext::Translate(TranslateId aId) const
+{
+    return SvtResId(aId);
+}
+
 bool SfxErrorContext::GetString(const ErrCodeMsg& nErr, OUString &rStr)
 
 /*  [Description]
@@ -261,7 +266,7 @@ bool SfxErrorContext::GetString(const ErrCodeMsg& nErr, 
OUString &rStr)
     {
         if (sal_uInt32(pItem->second) == nCtxId)
         {
-            rStr = Translate::get(pItem->first, aResLocale);
+            rStr = Translate(pItem->first);
             rStr = rStr.replaceAll("$(ARG1)", aArg1);
             bRet = true;
             break;
@@ -277,7 +282,7 @@ bool SfxErrorContext::GetString(const ErrCodeMsg& nErr, 
OUString &rStr)
         {
             if (sal_uInt32(pItem->second) == nId)
             {
-                rStr = rStr.replaceAll("$(ERR)", Translate::get(pItem->first, 
aResLocale));
+                rStr = rStr.replaceAll("$(ERR)", Translate(pItem->first));
                 break;
             }
         }
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index 2240211e2c23..dcfd6be699bc 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -194,6 +194,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
     svx/source/form/tbxform \
     svx/source/items/algitem \
     svx/source/items/autoformathelper \
+       svx/source/items/ehdl \
     svx/source/items/hlnkitem \
     svx/source/items/numfmtsh \
     svx/source/items/legacyitem \
diff --git a/svx/source/items/ehdl.cxx b/svx/source/items/ehdl.cxx
new file mode 100644
index 000000000000..4cf6c4d3fa1c
--- /dev/null
+++ b/svx/source/items/ehdl.cxx
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include <svx/dialmgr.hxx>
+#include <svx/ehdl.hxx>
+#include <svx/svxerr.hxx>
+
+SvxErrorContext::SvxErrorContext(sal_uInt16 nCtxIdP, OUString aArgOne, 
weld::Window* pWin)
+    : SfxErrorContext(nCtxIdP, aArgOne, pWin, RID_SVXERRCTX)
+{
+}
+
+OUString SvxErrorContext::Translate(TranslateId aId) const { return 
SvxResId(aId); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/source/uibase/uiview/viewling.cxx 
b/sw/source/uibase/uiview/viewling.cxx
index a9f64d7bf760..289f63e5bb7f 100644
--- a/sw/source/uibase/uiview/viewling.cxx
+++ b/sw/source/uibase/uiview/viewling.cxx
@@ -31,11 +31,11 @@
 #include <comphelper/scopeguard.hxx>
 #include <toolkit/helper/vclunohelper.hxx>
 #include <vcl/weld.hxx>
-#include <svtools/ehdl.hxx>
 #include <sfx2/dispatch.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <sfx2/request.hxx>
 #include <svx/dialmgr.hxx>
+#include <svx/ehdl.hxx>
 #include <svx/svxerr.hxx>
 #include <svx/svxdlg.hxx>
 #include <osl/diagnose.h>
@@ -408,8 +408,7 @@ void SwView::HyphenateDocument()
         return;
     }
 
-    SfxErrorContext aContext( ERRCTX_SVX_LINGU_HYPHENATION, OUString(), 
m_pEditWin->GetFrameWeld(),
-         RID_SVXERRCTX, SvxResLocale() );
+    SvxErrorContext aContext(ERRCTX_SVX_LINGU_HYPHENATION, OUString(), 
m_pEditWin->GetFrameWeld());
 
     Reference< XHyphenator >  xHyph( ::GetHyphenator() );
     if (!xHyph.is())
@@ -532,8 +531,7 @@ void SwView::StartThesaurus()
     if (!IsValidSelectionForThesaurus())
         return;
 
-    SfxErrorContext aContext( ERRCTX_SVX_LINGU_THESAURUS, OUString(), 
m_pEditWin->GetFrameWeld(),
-         RID_SVXERRCTX, SvxResLocale() );
+    SvxErrorContext aContext(ERRCTX_SVX_LINGU_THESAURUS, OUString(), 
m_pEditWin->GetFrameWeld());
 
     // Determine language
     LanguageType eLang = m_pWrtShell->GetCurLang();

Reply via email to