desktop/qa/desktop_lib/test_desktop_lib.cxx | 27 ------- include/sfx2/bindings.hxx | 1 include/sfx2/lokhelper.hxx | 12 +++ include/sfx2/sidebar/AsynchronousCall.hxx | 4 - include/test/lokcallback.hxx | 4 + sc/qa/unit/tiledrendering/data/chart.ods |binary sc/qa/unit/tiledrendering/tiledrendering.cxx | 93 +++++++++++++++++++++++++++ sfx2/source/control/bindings.cxx | 10 ++ sfx2/source/control/unoctitm.cxx | 21 +++++- sfx2/source/sidebar/AsynchronousCall.cxx | 11 ++- sfx2/source/sidebar/SidebarController.cxx | 30 +++++++- sfx2/source/view/lokhelper.cxx | 29 ++++++++ test/source/lokcallback.cxx | 23 ++++++ 13 files changed, 232 insertions(+), 33 deletions(-)
New commits: commit 315867352d175b2f04ff54765424ae16057a4120 Author: Miklos Vajna <[email protected]> AuthorDate: Fri Jan 12 11:26:01 2024 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Jan 16 11:14:31 2024 +0100 CppunitTest_sc_tiledrendering: ignore invalid json payload for STATE_CHANGED The interesting case for this testsuite is when the json for LOK_CALLBACK_STATE_CHANGED has a commandName key, ignore it callback when that's not the case. See <https://gerrit.libreoffice.org/c/core/+/161691/4#message-73673a8cedce0a5f661839553dd463983d22250a> for a case where this can happen, the json payload was "{ \"state\": \"0\" } " Which can happen when SfxLokHelper::sendUnoStatus() thinks that the commandName value would be empty. (cherry picked from commit e5f80cc94fc0d8874e47e4425f2c58f0dde9debe) Change-Id: I398319f33288742b8f46f0d07b112fd61e9a9731 diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index c5de130ee735..737c1a534cce 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -596,7 +596,13 @@ public: boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); - std::string aCommandName = aTree.get<std::string>("commandName"); + auto it = aTree.find("commandName"); + if (it == aTree.not_found()) + { + break; + } + + std::string aCommandName = it->second.get_value<std::string>(); m_aStateChanges[aCommandName] = aTree; } break; commit 8a53156023be536acb644247e4aa5f929b6f9060 Author: Miklos Vajna <[email protected]> AuthorDate: Thu Jan 11 10:59:05 2024 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Jan 16 11:14:31 2024 +0100 cool#7492 sfx2 lok: set language/locale on async sidebar update Create two Calc views, set the first view language to English, second view language to German. Type in the English view, double-click on a chart in the German view. The sidebar in the German view will have English strings in it. This doesn't happen if there is no typing right after the chart activation in the English view. What happens is that the sidebar update is async, and sfx2::sidebar::SidebarController::notifyContextChangeEvent() gets called, which registers an aync event when it calls AsynchronousCall::RequestCall(). Then later this job gets scheduled, but possibly by that time the active view is the English one, leading to English strings when chart::ColumnChartDialogController::getName() calls SchResId(), which works from the language of the current view. Fix the problem similar to what commit fb7b0b944741e4efae8d92a6e305036aff906c7a (cool#7492 sfx2 lok: just set language/locale on async binding update, 2024-01-09), did: set the language/locale from the current view before executing the async job and restore the old value once we're done. Extract the now duplicated code to a new SfxLokLanguageGuard, so in case more places have a problem with incorrect l10n, then it's meant to be a one-liner to fix further places. (cherry picked from commit aaf6ce108e91b1504befe19afcee471e3316ae7a) Change-Id: I52724a24d93fb753175a3b9b99bc33178519d981 diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index cc4360807717..d9809cf56ce3 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -68,6 +68,7 @@ #include <vcl/filter/PDFiumLibrary.hxx> #include <svtools/colorcfg.hxx> #include <sal/types.h> +#include <test/lokcallback.hxx> #if USE_TLS_NSS #include <nss.h> @@ -3266,33 +3267,11 @@ void DesktopLOKTest::testMultiDocuments() } } -namespace -{ - SfxChildWindow* lcl_initializeSidebar() - { - // in init.cxx we do setupSidebar which creates the controller, do it here - - SfxViewShell* pViewShell = SfxViewShell::Current(); - CPPUNIT_ASSERT(pViewShell); - - SfxViewFrame& rViewFrame = pViewShell->GetViewFrame(); - SfxChildWindow* pSideBar = rViewFrame.GetChildWindow(SID_SIDEBAR); - CPPUNIT_ASSERT(pSideBar); - - auto pDockingWin = dynamic_cast<sfx2::sidebar::SidebarDockingWindow *>(pSideBar->GetWindow()); - CPPUNIT_ASSERT(pDockingWin); - - pDockingWin->GetOrCreateSidebarController(); // just to create the controller - - return pSideBar; - } -}; - void DesktopLOKTest::testControlState() { LibLODocument_Impl* pDocument = loadDoc("search.ods"); pDocument->pClass->postUnoCommand(pDocument, ".uno:StarShapes", nullptr, false); - lcl_initializeSidebar(); + TestLokCallbackWrapper::InitializeSidebar(); Scheduler::ProcessEventsToIdle(); boost::property_tree::ptree aState; @@ -3306,7 +3285,7 @@ void DesktopLOKTest::testMetricField() { LibLODocument_Impl* pDocument = loadDoc("search.ods"); pDocument->pClass->postUnoCommand(pDocument, ".uno:StarShapes", nullptr, false); - SfxChildWindow* pSideBar = lcl_initializeSidebar(); + SfxChildWindow* pSideBar = TestLokCallbackWrapper::InitializeSidebar(); Scheduler::ProcessEventsToIdle(); vcl::Window* pWin = pSideBar->GetWindow(); diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 3751d6758571..8ca9ce80da08 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -250,6 +250,18 @@ void SfxLokHelper::forEachOtherView(ViewShellType* pThisViewShell, FunctionType } } +/// If LOK is active, switch to the language/locale of the provided shell and back on delete. +class SfxLokLanguageGuard +{ + bool m_bSetLanguage; + const SfxViewShell* m_pOldShell; + const SfxViewShell* m_pNewShell; + +public: + SfxLokLanguageGuard(SfxViewShell* pNewShell); + ~SfxLokLanguageGuard(); +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/sidebar/AsynchronousCall.hxx b/include/sfx2/sidebar/AsynchronousCall.hxx index c7e522401d5a..9c9b2ee32909 100644 --- a/include/sfx2/sidebar/AsynchronousCall.hxx +++ b/include/sfx2/sidebar/AsynchronousCall.hxx @@ -23,6 +23,7 @@ #include <functional> struct ImplSVEvent; +class SfxViewFrame; namespace sfx2::sidebar { @@ -33,7 +34,7 @@ class AsynchronousCall public: typedef ::std::function<void()> Action; - AsynchronousCall(Action aAction); + AsynchronousCall(const SfxViewFrame* pViewFrame, Action aAction); ~AsynchronousCall(); void RequestCall(); @@ -43,6 +44,7 @@ public: private: Action maAction; ImplSVEvent* mnCallId; + const SfxViewFrame* mpViewFrame; DECL_LINK(HandleUserCall, void*, void); }; diff --git a/include/test/lokcallback.hxx b/include/test/lokcallback.hxx index bba7a392ae2d..7edf74311fcf 100644 --- a/include/test/lokcallback.hxx +++ b/include/test/lokcallback.hxx @@ -17,6 +17,8 @@ #include <vector> +class SfxChildWindow; + /** A helper to convert SfxLokCallbackInterface to a LIbreOfficeKitCallback for tests. @@ -44,6 +46,8 @@ public: virtual void Invoke() override; + static SfxChildWindow* InitializeSidebar(); + private: void callCallback(int nType, const char* pPayload, int nViewId); void startTimer(); diff --git a/sc/qa/unit/tiledrendering/data/chart.ods b/sc/qa/unit/tiledrendering/data/chart.ods new file mode 100644 index 000000000000..dcd1194811d7 Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/chart.ods differ diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 5398d905af3f..c5de130ee735 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -3202,6 +3202,32 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testStatusBarLocale) CPPUNIT_ASSERT_EQUAL(std::string("de-DE"), aLocale); } +CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testSidebarLocale) +{ + ScModelObj* pModelObj = createDoc("chart.ods"); + int nView1 = SfxLokHelper::getView(); + ViewCallback aView1; + SfxViewShell* pView1 = SfxViewShell::Current(); + pView1->SetLOKLocale("en-US"); + SfxLokHelper::createView(); + ViewCallback aView2; + SfxViewShell* pView2 = SfxViewShell::Current(); + pView2->SetLOKLocale("de-DE"); + TestLokCallbackWrapper::InitializeSidebar(); + Scheduler::ProcessEventsToIdle(); + aView2.m_aStateChanges.clear(); + + pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, /*x=*/1,/*y=*/1,/*count=*/2, /*buttons=*/1, /*modifier=*/0); + pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, /*x=*/1, /*y=*/1, /*count=*/2, /*buttons=*/1, /*modifier=*/0); + SfxLokHelper::setView(nView1); + Scheduler::ProcessEventsToIdle(); + + auto it = aView2.m_aStateChanges.find(".uno:Sidebar"); + CPPUNIT_ASSERT(it != aView2.m_aStateChanges.end()); + std::string aLocale = it->second.get<std::string>("locale"); + CPPUNIT_ASSERT_EQUAL(std::string("de-DE"), aLocale); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx index a7574c162073..957c9b737ce4 100644 --- a/sfx2/source/control/bindings.cxx +++ b/sfx2/source/control/bindings.cxx @@ -1214,30 +1214,10 @@ void SfxBindings::UpdateControllers_Impl IMPL_LINK( SfxBindings, NextJob, Timer *, pTimer, void ) { - bool bSetView = false; - SfxViewShell* pOldShell = nullptr; - if (comphelper::LibreOfficeKit::isActive() && pDispatcher) - { - SfxViewFrame* pFrame = pDispatcher->GetFrame(); - SfxViewShell* pNewShell = pFrame ? pFrame->GetViewShell() : nullptr; - pOldShell = SfxViewShell::Current(); - if (pNewShell && pNewShell != pOldShell) - { - // The current view ID is not the one that belongs to this frame, update - // language/locale. - comphelper::LibreOfficeKit::setLanguageTag(pNewShell->GetLOKLanguageTag()); - comphelper::LibreOfficeKit::setLocale(pNewShell->GetLOKLocale()); - bSetView = true; - } - } + SfxViewFrame* pFrame = pDispatcher ? pDispatcher->GetFrame() : nullptr; + SfxLokLanguageGuard aGuard(pFrame ? pFrame->GetViewShell() : nullptr); NextJob_Impl(pTimer); - - if (bSetView && pOldShell) - { - comphelper::LibreOfficeKit::setLanguageTag(pOldShell->GetLOKLanguageTag()); - comphelper::LibreOfficeKit::setLocale(pOldShell->GetLOKLocale()); - } } bool SfxBindings::NextJob_Impl(Timer const * pTimer) diff --git a/sfx2/source/sidebar/AsynchronousCall.cxx b/sfx2/source/sidebar/AsynchronousCall.cxx index fdb76d63d1ef..3377c1bb31c2 100644 --- a/sfx2/source/sidebar/AsynchronousCall.cxx +++ b/sfx2/source/sidebar/AsynchronousCall.cxx @@ -20,12 +20,15 @@ #include <sfx2/sidebar/AsynchronousCall.hxx> #include <utility> #include <vcl/svapp.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/lokhelper.hxx> namespace sfx2::sidebar { -AsynchronousCall::AsynchronousCall (Action aAction) +AsynchronousCall::AsynchronousCall (const SfxViewFrame* pViewFrame, Action aAction) : maAction(std::move(aAction)), - mnCallId(nullptr) + mnCallId(nullptr), + mpViewFrame(pViewFrame) { } @@ -55,6 +58,7 @@ void AsynchronousCall::CancelRequest() void AsynchronousCall::Sync() { if (mnCallId != nullptr) { + SfxLokLanguageGuard aGuard(mpViewFrame ? mpViewFrame->GetViewShell() : nullptr); maAction(); CancelRequest(); } @@ -64,7 +68,10 @@ IMPL_LINK_NOARG(AsynchronousCall, HandleUserCall, void*, void ) { mnCallId = nullptr; if (maAction) + { + SfxLokLanguageGuard aGuard(mpViewFrame ? mpViewFrame->GetViewShell() : nullptr); maAction(); + } } } // end of namespace sfx2::sidebar diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index 3e76cb2b14af..ba627e4d586d 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -17,6 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include <sfx2/sidebar/SidebarController.hxx> + +#include <boost/property_tree/json_parser.hpp> + #include <sfx2/sidebar/Deck.hxx> #include <sidebar/DeckDescriptor.hxx> #include <sidebar/DeckTitleBar.hxx> @@ -125,8 +128,8 @@ SidebarController::SidebarController ( mnRequestedForceFlags(SwitchFlag_NoForce), mbMinimumSidebarWidth(officecfg::Office::UI::Sidebar::General::MinimumWidth::get()), msCurrentDeckId(gsDefaultDeckId), - maPropertyChangeForwarder([this](){ return this->BroadcastPropertyChange(); }), - maContextChangeUpdate([this](){ return this->UpdateConfigurations(); }), + maPropertyChangeForwarder(mpViewFrame, [this](){ return this->BroadcastPropertyChange(); }), + maContextChangeUpdate(mpViewFrame, [this](){ return this->UpdateConfigurations(); }), mbFloatingDeckClosed(!pParentWindow->IsFloatingMode()), mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()), maFocusManager([this](const Panel& rPanel){ return this->ShowPanel(rPanel); }), @@ -805,18 +808,35 @@ void SidebarController::SwitchToDeck ( { if (const SfxViewShell* pViewShell = mpViewFrame->GetViewShell()) { + boost::property_tree::ptree aTree; + aTree.put("locale", comphelper::LibreOfficeKit::getLocale().getBcp47()); + bool bStateChanged = false; if (msCurrentDeckId != rDeckDescriptor.msId) { const std::string hide = UnoNameFromDeckId(msCurrentDeckId, GetCurrentContext()); if (!hide.empty()) - pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, - OString(hide + "=false")); + { + aTree.put("commandName", hide); + aTree.put("state", "false"); + bStateChanged = true; + } } const std::string show = UnoNameFromDeckId(rDeckDescriptor.msId, GetCurrentContext()); if (!show.empty()) + { + aTree.put("commandName", show); + aTree.put("state", "true"); + bStateChanged = true; + } + + if (bStateChanged) + { + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, - OString(show + "=true")); + OString(aStream.str())); + } } } diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 73473dd7640b..1df7a3b92d9a 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -1091,4 +1091,33 @@ void SfxLokHelper::sendNetworkAccessError(std::string_view rAction) } } +SfxLokLanguageGuard::SfxLokLanguageGuard(SfxViewShell* pNewShell) + : m_bSetLanguage(false) + , m_pOldShell(nullptr) + , m_pNewShell(pNewShell) +{ + m_pOldShell = SfxViewShell::Current(); + if (!comphelper::LibreOfficeKit::isActive() || !m_pNewShell || m_pNewShell == m_pOldShell) + { + return; + } + + // The current view ID is not the one that belongs to this frame, update + // language/locale. + comphelper::LibreOfficeKit::setLanguageTag(m_pNewShell->GetLOKLanguageTag()); + comphelper::LibreOfficeKit::setLocale(m_pNewShell->GetLOKLocale()); + m_bSetLanguage = true; +} + +SfxLokLanguageGuard::~SfxLokLanguageGuard() +{ + if (!m_bSetLanguage || !m_pOldShell) + { + return; + } + + comphelper::LibreOfficeKit::setLanguageTag(m_pOldShell->GetLOKLanguageTag()); + comphelper::LibreOfficeKit::setLocale(m_pOldShell->GetLOKLocale()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/lokcallback.cxx b/test/source/lokcallback.cxx index 767448c771ca..a979b8b50582 100644 --- a/test/source/lokcallback.cxx +++ b/test/source/lokcallback.cxx @@ -14,6 +14,10 @@ #include <tools/gen.hxx> #include <comphelper/lok.hxx> #include <sfx2/viewsh.hxx> +#include <sfx2/childwin.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/sfxsids.hrc> +#include <sfx2/sidebar/SidebarDockingWindow.hxx> TestLokCallbackWrapper::TestLokCallbackWrapper(LibreOfficeKitCallback callback, void* data) : Idle("TestLokCallbackWrapper flush timer") @@ -185,4 +189,23 @@ void TestLokCallbackWrapper::Invoke() flushLOKData(); } +SfxChildWindow* TestLokCallbackWrapper::InitializeSidebar() +{ + // in init.cxx we do setupSidebar which creates the controller, do it here + + SfxViewShell* pViewShell = SfxViewShell::Current(); + assert(pViewShell); + + SfxViewFrame& rViewFrame = pViewShell->GetViewFrame(); + SfxChildWindow* pSideBar = rViewFrame.GetChildWindow(SID_SIDEBAR); + assert(pSideBar); + + auto pDockingWin = dynamic_cast<sfx2::sidebar::SidebarDockingWindow*>(pSideBar->GetWindow()); + assert(pDockingWin); + + pDockingWin->GetOrCreateSidebarController(); // just to create the controller + + return pSideBar; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit f60841d3684525bead96135e1d85c0e57fee789d Author: Miklos Vajna <[email protected]> AuthorDate: Wed Jan 10 08:28:31 2024 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Jan 16 11:14:31 2024 +0100 CppunitTest_sc_tiledrendering: ignore non-json payload for STATE_CHANGED The payload can be both plain text and json here, but in practice we only care about json for now, and I never saw a plain text payload when running this suite locally. <https://gerrit.libreoffice.org/c/core/+/161691/4#message-d4772c1362bc5e059f8ea13b4163926d9b462535> reports that sometimes we get an .uno:InsertAnnotation=enabled, so just ignore that without feeding that not-well-formed JSON to the JSON parser. (cherry picked from commit 84a3401c28135735c7bbe324eb3642b31c7f26f5) Change-Id: Ic679ad20c453254237b906d4d2040824517d56e0 diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 5e5d47631ad4..5398d905af3f 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -589,6 +589,11 @@ public: case LOK_CALLBACK_STATE_CHANGED: { std::stringstream aStream(pPayload); + if (!aStream.str().starts_with("{")) + { + break; + } + boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); std::string aCommandName = aTree.get<std::string>("commandName"); commit d22a1fc934c5a5ed547bffc61c155d03b4683ee1 Author: Miklos Vajna <[email protected]> AuthorDate: Mon Jan 8 16:25:44 2024 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Jan 16 11:14:30 2024 +0100 cool#7492 sfx2 lok: just set language/locale on async binding update Trying to run online.git tests against commit 51d8a2ef54751403fa707816e27ddb4e7faa8231 (cool#7492 sfx2 lok: fix bad view id / statusbar string on async binding update, 2024-01-08), unit-tiletest failed. Manually trying to replace what the testSimultaneousTilesRenderedJustOnce test in that suite tries to do, it turned out that it can happen that the bindings are updated when a Writer view gets its focus, which is a problem, because the above commit started to switch views on binding updates, leading to a loop (bindings are updated about every second). Fix the problem by doing less work in SfxBindings::NextJob(): it's enough if the timer just switches languages and not views. That still keeps the Calc statusbar problem fixed from the above commit, but avoids the problematic view switching that broke unit-tiletest. (cherry picked from commit fb7b0b944741e4efae8d92a6e305036aff906c7a) Change-Id: I22cd9b3276c3f9987a2d90ad93f6026fdf6b8448 diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx index 3f50bfd289be..a7574c162073 100644 --- a/sfx2/source/control/bindings.cxx +++ b/sfx2/source/control/bindings.cxx @@ -1215,26 +1215,28 @@ void SfxBindings::UpdateControllers_Impl IMPL_LINK( SfxBindings, NextJob, Timer *, pTimer, void ) { bool bSetView = false; - int nOldId = -1; + SfxViewShell* pOldShell = nullptr; if (comphelper::LibreOfficeKit::isActive() && pDispatcher) { SfxViewFrame* pFrame = pDispatcher->GetFrame(); - SfxViewShell* pShell = pFrame ? pFrame->GetViewShell() : nullptr; - int nNewId = SfxLokHelper::getView(pShell); - nOldId = SfxLokHelper::getView(); - if (nNewId != -1 && nNewId != nOldId) + SfxViewShell* pNewShell = pFrame ? pFrame->GetViewShell() : nullptr; + pOldShell = SfxViewShell::Current(); + if (pNewShell && pNewShell != pOldShell) { - // The current view ID is not the one that belongs to this frame, switch to it. - SfxLokHelper::setView(nNewId); + // The current view ID is not the one that belongs to this frame, update + // language/locale. + comphelper::LibreOfficeKit::setLanguageTag(pNewShell->GetLOKLanguageTag()); + comphelper::LibreOfficeKit::setLocale(pNewShell->GetLOKLocale()); bSetView = true; } } NextJob_Impl(pTimer); - if (bSetView) + if (bSetView && pOldShell) { - SfxLokHelper::setView(nOldId); + comphelper::LibreOfficeKit::setLanguageTag(pOldShell->GetLOKLanguageTag()); + comphelper::LibreOfficeKit::setLocale(pOldShell->GetLOKLocale()); } } commit a1d1a5a27302742a62dff986ee831b4bad39d316 Author: Miklos Vajna <[email protected]> AuthorDate: Fri Jan 5 16:51:42 2024 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Jan 16 11:14:30 2024 +0100 cool#7492 sfx2 lok: fix bad view id / statusbar string on async binding update With two Calc views (first is an English one, second is a German one), type in the English view and in parallel to that, create a cell selection in the German view. Sometimes the status bar update about the selected cells arrives in English, in the German view. The root of the problem is that SfxBindings has a timer that does the expensive update of all the UNO commands only after a delay, but by the time this timer runs, possibly the current view is no longer the German one, which leads to English strings in the German view. Fix the problem somewhat similar to what commit ee7ca8e4ea8ed93655f99e77a9e77032ac830c46 (cool#7865 sfx2 lok: fix bad view id on async command dispatch, 2023-12-20) did in SfxHintPoster::DoEvent_Impl() by restoring the original view for the duration of the timer job execution. The test works even in case '--with-lang=en-US de' is not used, because it asserts the locale, which is not downgraded to English when translations are not available. This required turning the payload of the .uno:RowColSelCount status update into JSON, which is meant to be mostly backwards-compatible, given that we already have a mix of plain text and JSON for the various UNO commands. Another trouble is that the SfxBindings lazy update is a timer, so processing idles won't help and sleeping in test code is not ideal, either. Solve that by exposing the timer of SfxBindings, so test code can explicitly invoke the timer without waiting. (cherry picked from commit 51d8a2ef54751403fa707816e27ddb4e7faa8231) Conflicts: sc/qa/unit/tiledrendering/tiledrendering.cxx Change-Id: Iacf17f81c28b95ce41a0ee29ad25eb576db0d62a diff --git a/include/sfx2/bindings.hxx b/include/sfx2/bindings.hxx index 8cd92a24108d..2b85b4dbd065 100644 --- a/include/sfx2/bindings.hxx +++ b/include/sfx2/bindings.hxx @@ -188,6 +188,7 @@ public: SAL_DLLPRIVATE void SetRecorder_Impl( css::uno::Reference< css::frame::XDispatchRecorder > const & ); SAL_DLLPRIVATE void InvalidateSlotsInMap_Impl(); SAL_DLLPRIVATE void AddSlotToInvalidateSlotsMap_Impl( sal_uInt16 nId ); + Timer& GetTimer(); }; #ifdef DBG_UTIL diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 80dbe52427c1..5e5d47631ad4 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/frame/DispatchHelper.hpp> #include <com/sun/star/datatransfer/clipboard/LokClipboard.hpp> #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp> +#include <com/sun/star/util/URLTransformer.hpp> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/servicehelper.hxx> @@ -26,6 +27,8 @@ #include <comphelper/lok.hxx> #include <comphelper/propertyvalue.hxx> +#include <comphelper/dispatchcommand.hxx> +#include <sfx2/msgpool.hxx> #include <sfx2/childwin.hxx> #include <sfx2/lokhelper.hxx> #include <svx/svdpage.hxx> @@ -437,6 +440,7 @@ public: OString m_sInvalidateSheetGeometry; OString m_aHyperlinkClicked; OString m_ShapeSelection; + std::map<std::string, boost::property_tree::ptree> m_aStateChanges; TestLokCallbackWrapper m_callbackWrapper; ViewCallback(bool bDeleteListenerOnDestruct=true) @@ -581,6 +585,16 @@ public: { m_aTextSelectionResult.parseMessage(pPayload); } + break; + case LOK_CALLBACK_STATE_CHANGED: + { + std::stringstream aStream(pPayload); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + std::string aCommandName = aTree.get<std::string>("commandName"); + m_aStateChanges[aCommandName] = aTree; + } + break; } } }; @@ -3141,6 +3155,48 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testOpenURL) CPPUNIT_ASSERT(!aView2.m_aHyperlinkClicked.isEmpty()); } +CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testStatusBarLocale) +{ + // Given 2 views, the second's locale is set to German: + createDoc("empty.ods"); + int nView1 = SfxLokHelper::getView(); + ViewCallback aView1; + SfxLokHelper::createView(); + ViewCallback aView2; + SfxViewShell* pView2 = SfxViewShell::Current(); + pView2->SetLOKLocale("de-DE"); + { + SfxViewFrame& rFrame = pView2->GetViewFrame(); + SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(&rFrame); + uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext)); + util::URL aCommandURL; + aCommandURL.Complete = ".uno:RowColSelCount"; + xParser->parseStrict(aCommandURL); + const SfxSlot* pSlot = rSlotPool.GetUnoSlot(aCommandURL.Path); + rFrame.GetBindings().GetDispatch(pSlot, aCommandURL, false); + } + aView2.m_aStateChanges.clear(); + + // When creating a cell selection in the 2nd view and processing jobs with the 1st view set to + // active: + comphelper::dispatchCommand(".uno:GoDownSel", {}); + SfxLokHelper::setView(nView1); + pView2->GetViewFrame().GetBindings().GetTimer().Invoke(); + // Once more to hit the pImpl->bMsgDirty = false case in SfxBindings::NextJob_Impl(). + pView2->GetViewFrame().GetBindings().GetTimer().Invoke(); + + // Then make sure that the locale is taken into account while producing the state changed + // callback: + auto it = aView2.m_aStateChanges.find(".uno:RowColSelCount"); + CPPUNIT_ASSERT(it != aView2.m_aStateChanges.end()); + std::string aLocale = it->second.get<std::string>("locale"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: de-DE + // - Actual : en-US + // i.e. the 2nd view got its callback with the locale of the first view, which is buggy. + CPPUNIT_ASSERT_EQUAL(std::string("de-DE"), aLocale); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx index 47ddda28136f..3f50bfd289be 100644 --- a/sfx2/source/control/bindings.cxx +++ b/sfx2/source/control/bindings.cxx @@ -50,6 +50,8 @@ #include <sfx2/viewfrm.hxx> #include <sfx2/objsh.hxx> #include <sfx2/msgpool.hxx> +#include <sfx2/lokhelper.hxx> +#include <comphelper/lok.hxx> #include <cstddef> #include <memory> @@ -1212,7 +1214,28 @@ void SfxBindings::UpdateControllers_Impl IMPL_LINK( SfxBindings, NextJob, Timer *, pTimer, void ) { + bool bSetView = false; + int nOldId = -1; + if (comphelper::LibreOfficeKit::isActive() && pDispatcher) + { + SfxViewFrame* pFrame = pDispatcher->GetFrame(); + SfxViewShell* pShell = pFrame ? pFrame->GetViewShell() : nullptr; + int nNewId = SfxLokHelper::getView(pShell); + nOldId = SfxLokHelper::getView(); + if (nNewId != -1 && nNewId != nOldId) + { + // The current view ID is not the one that belongs to this frame, switch to it. + SfxLokHelper::setView(nNewId); + bSetView = true; + } + } + NextJob_Impl(pTimer); + + if (bSetView) + { + SfxLokHelper::setView(nOldId); + } } bool SfxBindings::NextJob_Impl(Timer const * pTimer) @@ -1771,4 +1794,9 @@ uno::Reference < frame::XDispatch > SfxBindings::GetDispatch( const SfxSlot* pSl return xRet; } +Timer& SfxBindings::GetTimer() +{ + return pImpl->aAutoTimer; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index c37544b2ecbd..54c2424ff249 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -1151,7 +1151,6 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 nSID, SfxViewFrame* pViewFra } } else if (aEvent.FeatureURL.Path == "StatusDocPos" || - aEvent.FeatureURL.Path == "RowColSelCount" || aEvent.FeatureURL.Path == "StatusPageStyle" || aEvent.FeatureURL.Path == "StateWordCount" || aEvent.FeatureURL.Path == "PageStyleName" || @@ -1167,6 +1166,26 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 nSID, SfxViewFrame* pViewFra aBuffer.append(aString); } } + else if (aEvent.FeatureURL.Path == "RowColSelCount") + { + OUString aString; + if (aEvent.IsEnabled) + { + aEvent.State >>= aString; + } + boost::property_tree::ptree aTree; + aTree.put("commandName", aEvent.FeatureURL.Complete); + aTree.put("locale", comphelper::LibreOfficeKit::getLocale().getBcp47()); + aTree.put("state", aString); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + const SfxViewShell* pShell = pViewFrame->GetViewShell(); + if (pShell) + { + pShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, OString(aStream.str())); + } + return; + } else if (aEvent.FeatureURL.Path == "StateTableCell") { if (aEvent.IsEnabled)
