summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-12-12 18:13:03 +0100
committerMichael Meeks <michael.meeks@collabora.com>2017-12-12 18:26:49 +0100
commitf01e4365be66e666b1671279b8605f0113dfd8fa (patch)
treec4baf2ff02995eb2e22d7bfef3304a053cf1cfe1
parent789c68003818fa1a5cb17d234d80035006c7e585 (diff)
lokdialog: Allow windows / dialogs in different languages.
Change-Id: I9f32161981aed73e6d97696e5f976af276d1625a Reviewed-on: https://gerrit.libreoffice.org/46327 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r--comphelper/source/misc/lok.cxx17
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx3
-rw-r--r--desktop/source/lib/init.cxx10
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h3
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx11
-rw-r--r--include/comphelper/lok.hxx7
-rw-r--r--include/sfx2/lokhelper.hxx2
-rw-r--r--include/sfx2/viewsh.hxx5
-rw-r--r--sfx2/source/view/lokhelper.cxx17
-rw-r--r--sfx2/source/view/viewsh.cxx1
-rw-r--r--vcl/source/window/builder.cxx10
11 files changed, 80 insertions, 6 deletions
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index b8324a4defcd..2e8624d1e8d0 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -27,6 +27,10 @@ static bool g_bTiledAnnotations(true);
static bool g_bRangeHeaders(false);
+static bool g_bLocalRendering(false);
+
+static LanguageTag g_aLanguageTag("en-US", true);
+
void setActive(bool bActive)
{
g_bActive = bActive;
@@ -87,8 +91,6 @@ bool isRangeHeaders()
return g_bRangeHeaders;
}
-static bool g_bLocalRendering(false);
-
void setLocalRendering(bool bLocalRendering)
{
g_bLocalRendering = bLocalRendering;
@@ -99,6 +101,17 @@ bool isLocalRendering()
return g_bLocalRendering;
}
+void setLanguageTag(const LanguageTag& languageTag)
+{
+ if (g_aLanguageTag != languageTag)
+ g_aLanguageTag = languageTag;
+}
+
+const LanguageTag& getLanguageTag()
+{
+ return g_aLanguageTag;
+}
+
static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr);
static void *pStatusIndicatorCallbackData(nullptr);
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index fb801879d370..83c5f3544e37 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2208,10 +2208,11 @@ void DesktopLOKTest::testABI()
CPPUNIT_ASSERT_EQUAL(documentClassOffset(36), offsetof(struct _LibreOfficeKitDocumentClass, postWindow));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(37), offsetof(struct _LibreOfficeKitDocumentClass, postWindowKeyEvent));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(38), offsetof(struct _LibreOfficeKitDocumentClass, postWindowMouseEvent));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(39), offsetof(struct _LibreOfficeKitDocumentClass, setViewLanguage));
// Extending is fine, update this, and add new assert for the offsetof the
// new method
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(39), sizeof(struct _LibreOfficeKitDocumentClass));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(40), sizeof(struct _LibreOfficeKitDocumentClass));
}
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index e339d3a40467..17a731837656 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -618,6 +618,7 @@ static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
static int doc_getView(LibreOfficeKitDocument* pThis);
static int doc_getViewsCount(LibreOfficeKitDocument* pThis);
static bool doc_getViewIds(LibreOfficeKitDocument* pThis, int* pArray, size_t nSize);
+static void doc_setViewLanguage(LibreOfficeKitDocument* pThis, int nId, const char* language);
static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis,
const char *pFontName,
const char *pChar,
@@ -683,6 +684,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->paintWindow = doc_paintWindow;
m_pDocumentClass->postWindow = doc_postWindow;
+ m_pDocumentClass->setViewLanguage = doc_setViewLanguage;
+
gDocumentClass = m_pDocumentClass;
}
pClass = m_pDocumentClass.get();
@@ -3166,6 +3169,13 @@ static bool doc_getViewIds(LibreOfficeKitDocument* /*pThis*/, int* pArray, size_
return SfxLokHelper::getViewIds(pArray, nSize);
}
+static void doc_setViewLanguage(LibreOfficeKitDocument* /*pThis*/, int nId, const char* language)
+{
+ SolarMutexGuard aGuard;
+
+ SfxLokHelper::setViewLanguage(nId, OStringToOUString(language, RTL_TEXTENCODING_UTF8));
+}
+
unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/,
const char* pFontName,
const char* pChar,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 7b80001be430..8ac97371c6c4 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -286,6 +286,9 @@ struct _LibreOfficeKitDocumentClass
int nButtons,
int nModifier);
+ /// @see lok::Document::setViewLanguage().
+ void (*setViewLanguage) (LibreOfficeKitDocument* pThis, int nId, const char* language);
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 7bdd2c470092..d7fa22b70ede 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -525,6 +525,17 @@ public:
return mpDoc->pClass->getViewIds(mpDoc, pArray, nSize);
}
+ /**
+ * Set the language tag of the window with the specified nId.
+ *
+ * @param nId a view ID, returned by createView().
+ * @param language Bcp47 languageTag, like en-US or so.
+ */
+ void setViewLanguage(int nId, const char* language)
+ {
+ mpDoc->pClass->setViewLanguage(mpDoc, nId, language);
+ }
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index c42a740822e0..e9634e77d6f9 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -12,6 +12,8 @@
#include <comphelper/comphelperdllapi.h>
+#include <i18nlangtag/languagetag.hxx>
+
// Interface between the LibreOfficeKit implementation called by LibreOfficeKit clients and other
// LibreOffice code.
@@ -65,6 +67,11 @@ COMPHELPER_DLLPUBLIC void setRangeHeaders(bool bTiledAnnotations);
/// Check if range based header data is enabled
COMPHELPER_DLLPUBLIC bool isRangeHeaders();
+/// Update the current LOK's language.
+COMPHELPER_DLLPUBLIC void setLanguageTag(const LanguageTag& languageTag);
+/// Get the current LOK's language.
+COMPHELPER_DLLPUBLIC const LanguageTag& getLanguageTag();
+
// Status indicator handling. Even if in theory there could be several status indicators active at
// the same time, in practice there is only one at a time, so we don't handle any identification of
// status indicator in this API.
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index b7600f015163..391d9965cb29 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -34,6 +34,8 @@ public:
static std::size_t getViewsCount();
/// Get viewIds of all existing views.
static bool getViewIds(int* pArray, size_t nSize);
+ /// Set language of the given view.
+ static void setViewLanguage(int nId, const OUString& rBcp47LanguageTag);
/// Iterate over any view shell, except pThisViewShell, passing it to the f function.
template<typename ViewShellType, typename FunctionType>
static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType f);
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 256f499f8547..023a37c98620 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -157,6 +157,7 @@ friend class SfxPrinterController;
VclPtr<vcl::Window> pWindow;
bool bNoNewWindow;
bool mbPrinterSettingsModified;
+ LanguageTag maLOKLanguageTag;
protected:
virtual void Activate(bool IsMDIActivate) override;
@@ -350,6 +351,10 @@ public:
/// See OutlinerViewShell::GetEditWindowForActiveOLEObj().
virtual vcl::Window* GetEditWindowForActiveOLEObj() const override;
+ /// Set the LibreOfficeKit language of this view.
+ void SetLOKLanguageTag(const OUString& rBcp47LanguageTag) { maLOKLanguageTag = LanguageTag(rBcp47LanguageTag, true); }
+ /// Get the LibreOfficeKit language of this view.
+ const LanguageTag& GetLOKLanguageTag() const { return maLOKLanguageTag; }
};
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 73e7a170412c..f91d757697a2 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -61,6 +61,9 @@ void SfxLokHelper::setView(int nId)
{
if (pViewShell->GetViewShellId() == nViewShellId)
{
+ // update the current LOK language for the dialog tunneling
+ comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag());
+
if (pViewShell == SfxViewShell::Current())
return;
@@ -108,6 +111,20 @@ bool SfxLokHelper::getViewIds(int* pArray, size_t nSize)
return true;
}
+void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag)
+{
+ SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+
+ for (SfxViewShell* pViewShell : rViewArr)
+ {
+ if (pViewShell->GetViewShellId() == static_cast<unsigned>(nId))
+ {
+ pViewShell->SetLOKLanguageTag(rBcp47LanguageTag);
+ return;
+ }
+ }
+}
+
void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell* pOtherView, int nType, const OString& rKey, const OString& rPayload)
{
OString aPayload = OString("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView(pThisView)) +
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 1dcc439f291c..e65d55e0be1b 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1105,6 +1105,7 @@ SfxViewShell::SfxViewShell
, pWindow(nullptr)
, bNoNewWindow( nFlags & SfxViewShellFlags::NO_NEWWINDOW )
, mbPrinterSettingsModified(false)
+, maLOKLanguageTag("en-US", true)
{
SetMargin( pViewFrame->GetMargin_Impl() );
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 32bd8b8e9d29..1809b7a8d711 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -9,6 +9,7 @@
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
+#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <osl/module.hxx>
#include <sal/log.hxx>
@@ -194,10 +195,13 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr
OUString sUri = sUIDir + sUIFile;
- const LanguageTag& rLanguageTag = Application::GetSettings().GetUILanguageTag();
- bool bEN_US = (rLanguageTag.getBcp47() == "en-US");
+ LanguageTag aLanguageTag = Application::GetSettings().GetUILanguageTag();
+ if (comphelper::LibreOfficeKit::isActive())
+ aLanguageTag = comphelper::LibreOfficeKit::getLanguageTag();
+
+ bool bEN_US = (aLanguageTag.getBcp47() == "en-US");
if (!bEN_US)
- loadTranslations(rLanguageTag, sUri);
+ loadTranslations(aLanguageTag, sUri);
try
{