diff options
-rw-r--r-- | comphelper/source/misc/lok.cxx | 17 | ||||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 10 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 3 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 11 | ||||
-rw-r--r-- | include/comphelper/lok.hxx | 7 | ||||
-rw-r--r-- | include/sfx2/lokhelper.hxx | 2 | ||||
-rw-r--r-- | include/sfx2/viewsh.hxx | 5 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 17 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 1 |
10 files changed, 73 insertions, 3 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 ba76a8ca532d..37c7755a0d08 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2289,10 +2289,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 5f18a457f241..13b072ec630f 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -598,6 +598,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, @@ -663,6 +664,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(); @@ -3153,6 +3156,13 @@ static bool doc_getViewIds(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis* return SfxLokHelper::getViewIds(pArray, nSize); } +static void doc_setViewLanguage(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis*/, int nId, const char* language) +{ + SolarMutexGuard aGuard; + + SfxLokHelper::setViewLanguage(nId, OStringToOUString(language, RTL_TEXTENCODING_UTF8)); +} + unsigned char* doc_renderFont(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis*/, const char* pFontName, const char* pChar, diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index ed8b295b3f09..d42bd3434689 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -297,6 +297,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 835710e07e91..310b9cfcee88 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -526,6 +526,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 52c9b9763eae..b2b6f9f09977 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 988e1d3490ec..0c83f5faee15 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -153,6 +153,7 @@ friend class SfxPrinterController; VclPtr<vcl::Window> pWindow; bool bNoNewWindow; bool mbPrinterSettingsModified; + LanguageTag maLOKLanguageTag; protected: virtual void Activate(bool IsMDIActivate) override; @@ -342,6 +343,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 135c36003192..cd672aaf91e1 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -69,6 +69,9 @@ void SfxLokHelper::setView(int nId) { if ((sal_Int32)pViewShell->GetViewShellId() == nViewShellId) { + // update the current LOK language for the dialog tunneling + comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag()); + if (pViewShell == SfxViewShell::Current()) return; @@ -120,6 +123,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() == ViewShellId(nId)) + { + pViewShell->SetLOKLanguageTag(rBcp47LanguageTag); + return; + } + } +} + void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* 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 7c3b25eedaa6..8060a330f132 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1059,6 +1059,7 @@ SfxViewShell::SfxViewShell , pWindow(nullptr) , bNoNewWindow( nFlags & SfxViewShellFlags::NO_NEWWINDOW ) , mbPrinterSettingsModified(false) +, maLOKLanguageTag("en-US", true) { SetMargin( pViewFrame->GetMargin_Impl() ); |