chart2/source/controller/sidebar/ChartAreaPanel.cxx | 46 +++++++++++++++++++- chart2/source/model/main/ChartModel.cxx | 12 ++++- desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 - desktop/source/lib/init.cxx | 10 ++++ include/LibreOfficeKit/LibreOfficeKit.h | 3 + include/LibreOfficeKit/LibreOfficeKit.hxx | 11 ++++ include/sfx2/lokhelper.hxx | 2 include/sfx2/viewsh.hxx | 5 ++ sfx2/source/view/lokhelper.cxx | 14 ++++++ sfx2/source/view/viewsh.cxx | 6 ++ 10 files changed, 108 insertions(+), 4 deletions(-)
New commits: commit 4370d0d2e22f41321cb90a4add9a374e21faefa2 Author: Marco Cecchetti <marco.cecche...@collabora.com> AuthorDate: Mon May 26 19:28:58 2025 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Jun 12 07:41:15 2025 +0200 lok: color preview: avoid chart color palette reset on preview Notify color preview state: enabled/disabled Avoid current color palette to be cleared if user is just previewing a color for a data series or a data point with the color picker. Change-Id: I8b5fcd7e675d34f68b0323703ec509493fc48492 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186337 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/chart2/source/controller/sidebar/ChartAreaPanel.cxx b/chart2/source/controller/sidebar/ChartAreaPanel.cxx index 87a49974eb8c..e4e8d2d92e2a 100644 --- a/chart2/source/controller/sidebar/ChartAreaPanel.cxx +++ b/chart2/source/controller/sidebar/ChartAreaPanel.cxx @@ -17,9 +17,12 @@ #include <ChartModel.hxx> #include <ViewElementListProvider.hxx> #include <PropertyHelper.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <chartview/DrawModelWrapper.hxx> #include <com/sun/star/chart2/XDiagram.hpp> +#include <comphelper/lok.hxx> +#include <sfx2/viewsh.hxx> #include <sfx2/weldutils.hxx> #include <svx/xfltrit.hxx> @@ -519,8 +522,47 @@ void ChartAreaPanel::modelInvalid() void ChartAreaPanel::selectionChanged(bool bCorrectType) { - if (bCorrectType) - updateData(); + if (!bCorrectType) + return; + + // set the initial correct color for the color picker + if (comphelper::LibreOfficeKit::isActive()) + { + css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel); + if (xPropSet.is()) + { + css::uno::Reference<css::beans::XPropertySetInfo> xInfo(xPropSet->getPropertySetInfo()); + if (xInfo.is()) + { + SolarMutexGuard aGuard; + if (xInfo->hasPropertyByName(u"FillStyle"_ustr)) + { + css::drawing::FillStyle eFillStyle = css::drawing::FillStyle::FillStyle_NONE; + xPropSet->getPropertyValue(u"FillStyle"_ustr) >>= eFillStyle; + if (eFillStyle == css::drawing::FillStyle_SOLID) + { + if (xInfo->hasPropertyByName(u"FillColor"_ustr)) + { + sal_uInt32 nFillColor = -1; + xPropSet->getPropertyValue(u"FillColor"_ustr) >>= nFillColor; + if (nFillColor != static_cast<sal_uInt32>(-1)) + { + if (SfxViewShell* pViewShell = SfxViewShell::Current()) + { + const OString sCommand = ".uno:FillColor"_ostr; + pViewShell->libreOfficeKitViewCallback( + LOK_CALLBACK_STATE_CHANGED, + sCommand + "=" + OString::number(nFillColor)); + } + } + } + } + } + } + } + } + + updateData(); } void ChartAreaPanel::doUpdateModel(const rtl::Reference<::chart::ChartModel>& xModel) diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx index 3daa4a8dbca2..1fed581d8bf7 100644 --- a/chart2/source/model/main/ChartModel.cxx +++ b/chart2/source/model/main/ChartModel.cxx @@ -71,6 +71,7 @@ #include <libxml/xmlwriter.h> #include <sfx2/objsh.hxx> +#include <sfx2/viewsh.hxx> #include <com/sun/star/util/XTheme.hpp> #include <docmodel/uno/UnoTheme.hxx> #include <docmodel/theme/Theme.hxx> @@ -1434,7 +1435,16 @@ void ChartModel::setColorPalette(ChartColorPaletteType eType, sal_uInt32 nIndex) m_nColorPaletteIndex = nIndex; } -void ChartModel::clearColorPalette() { setColorPalette(ChartColorPaletteType::Unknown, 0); } +void ChartModel::clearColorPalette() +{ + // Not reset the selected palette if user is just previewing a color + // for a data series or a data point + SfxViewShell* pCurrentShell = SfxViewShell::Current(); + if (pCurrentShell && pCurrentShell->IsLOKColorPreviewEnabled()) + return; + + setColorPalette(ChartColorPaletteType::Unknown, 0); +} bool ChartModel::usesColorPalette() const { diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 8cb3b8d11058..903b99cb17f1 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3981,9 +3981,10 @@ void DesktopLOKTest::testABI() CPPUNIT_ASSERT_EQUAL(documentClassOffset(76), offsetof(struct _LibreOfficeKitDocumentClass, postSlideshowCleanup)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(77), offsetof(struct _LibreOfficeKitDocumentClass, renderNextSlideLayer)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(78), offsetof(struct _LibreOfficeKitDocumentClass, setViewOption)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(79), offsetof(struct _LibreOfficeKitDocumentClass, setColorPreviewState)); // As above - CPPUNIT_ASSERT_EQUAL(documentClassOffset(79), sizeof(struct _LibreOfficeKitDocumentClass)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(80), sizeof(struct _LibreOfficeKitDocumentClass)); } CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index a51f0e8d2704..e9f55f0bc09f 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1349,6 +1349,8 @@ static bool doc_renderNextSlideLayer( static void doc_setViewOption(LibreOfficeKitDocument* pDoc, const char* pOption, const char* pValue); +static void doc_setColorPreviewState(LibreOfficeKitDocument* pThis, int nId, bool bEnabled); + } // extern "C" namespace { @@ -1551,6 +1553,7 @@ LibLODocument_Impl::LibLODocument_Impl(uno::Reference <css::lang::XComponent> xC m_pDocumentClass->postSlideshowCleanup = doc_postSlideshowCleanup; m_pDocumentClass->renderNextSlideLayer = doc_renderNextSlideLayer; m_pDocumentClass->setViewOption = doc_setViewOption; + m_pDocumentClass->setColorPreviewState = doc_setColorPreviewState; gDocumentClass = m_pDocumentClass; } @@ -7615,6 +7618,13 @@ static void doc_setAccessibilityState(SAL_UNUSED_PARAMETER LibreOfficeKitDocumen SfxLokHelper::setAccessibilityState(nId, nEnabled); } +static void doc_setColorPreviewState(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* pThis, int nId, + bool bEnabled) +{ + SolarMutexGuard aGuard; + SfxLokHelper::setColorPreviewState(nId, bEnabled); +} + static char* lo_getError (LibreOfficeKit *pThis) { comphelper::ProfileZone aZone("lo_getError"); diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 66ff0418e326..7f933aa29a4b 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -559,6 +559,9 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::setViewOption void (*setViewOption)(LibreOfficeKitDocument* pThis, const char* pOption, const char* pValue); + /// @see lok::Document::setColorPreviewState(). + void (*setColorPreviewState) (LibreOfficeKitDocument* pThis, int nId, bool nEnabled); + #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index f6f581c1ca43..8de0898817fb 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -943,6 +943,17 @@ public: mpDoc->pClass->setViewOption(mpDoc, pOption, pValue); } + /** + * Set color preview state for the window with the specified nId. + * + * @param nId a view ID, returned by createView(). + * @param nEnabled true/false + */ + void setColorPreviewState(int nId, bool nEnabled) + { + mpDoc->pClass->setColorPreviewState(mpDoc, nId, nEnabled); + } + #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 2f87faf82e78..d8cc5af06214 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -135,6 +135,8 @@ public: static LOKDeviceFormFactor getDeviceFormFactor(); /// Set the device form factor that should be used for a new view. static void setDeviceFormFactor(std::u16string_view rDeviceFormFactor); + /// Set color preview state for the given view. + static void setColorPreviewState(int nId, bool nEnabled); /// Set timezone of the given view. /// @isSet true to use @rTimezone, even if it's empty. Otherwise, no timezone. diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index ad988db09b4c..2a9af514b956 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -182,6 +182,7 @@ friend class SfxPrinterController; std::unordered_set<OUString> mvLOKBlockedCommandList; OUString maLOKTimezone; bool maLOKIsTimezoneSet; + bool mbLOKColorPreviewEnabled; /// Used to set the DocId at construction time. See SetCurrentDocId. static ViewShellDocId mnCurrentDocId; @@ -455,6 +456,10 @@ public: void SetLOKAccessibilityState(bool bEnabled); /// Get LibreOfficeKit AT support state for this view. bool GetLOKAccessibilityState() const { return mbLOKAccessibilityEnabled; } + /// Set LibreOfficeKit color preview state for this view. + void SetLOKColorPreviewState(bool bEnabled); + /// Return LibreOfficeKit color preview state for this view. + bool IsLOKColorPreviewEnabled() const { return mbLOKColorPreviewEnabled; } /// Get the LibreOfficeKit timezone of this view. See @SetLOKTimezone. std::pair<bool, OUString> GetLOKTimezone() const diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 0ea04c16238f..b16b7c7ff292 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -428,6 +428,20 @@ void SfxLokHelper::setDeviceFormFactor(std::u16string_view rDeviceFormFactor) g_deviceFormFactor = LOKDeviceFormFactor::UNKNOWN; } +void SfxLokHelper::setColorPreviewState(int nId, bool nEnabled) +{ + std::vector<SfxViewShell*>& rViewArr = SfxGetpApp()->GetViewShells_Impl(); + + for (SfxViewShell* pViewShell : rViewArr) + { + if (pViewShell && pViewShell->GetViewShellId() == ViewShellId(nId)) + { + pViewShell->SetLOKColorPreviewState(nEnabled); + return; + } + } +} + void SfxLokHelper::setDefaultTimezone(bool isSet, const OUString& rTimezone) { g_isDefaultTimezoneSet = isSet; diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 5a5f642a5077..621919c3bb4d 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -2744,6 +2744,7 @@ SfxViewShell::SfxViewShell , maLOKLocale(LANGUAGE_NONE) , maLOKDeviceFormFactor(LOKDeviceFormFactor::UNKNOWN) , mbLOKAccessibilityEnabled(false) +, mbLOKColorPreviewEnabled(false) { SetMargin( rViewFrame.GetMargin_Impl() ); @@ -3503,6 +3504,11 @@ void SfxViewShell::SetLOKAccessibilityState(bool bEnabled) } } +void SfxViewShell::SetLOKColorPreviewState(bool bEnabled) +{ + mbLOKColorPreviewEnabled = bEnabled; +} + void SfxViewShell::SetLOKLocale(const OUString& rBcp47LanguageTag) { maLOKLocale = LanguageTag(rBcp47LanguageTag, true).makeFallback();