chart2/source/controller/dialogs/tp_ChartColorPalette.hxx | 2 chart2/source/controller/sidebar/ChartAreaPanel.cxx | 46 +++++++++++++- chart2/source/model/main/ChartModel.cxx | 12 +++ chart2/source/tools/ChartColorPaletteHelper.cxx | 12 +-- desktop/qa/desktop_lib/test_desktop_lib.cxx | 5 - 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 + include/svx/ChartColorPaletteType.hxx | 8 +- include/svx/chrtitem.hxx | 5 + sfx2/source/view/lokhelper.cxx | 14 ++++ sfx2/source/view/viewsh.cxx | 6 + svx/source/items/chrtitem.cxx | 4 - 15 files changed, 127 insertions(+), 18 deletions(-)
New commits: commit 150525a38ef011b7bc1f84179ff643874eb3d1c7 Author: Marco Cecchetti <marco.cecche...@collabora.com> AuthorDate: Mon May 26 19:28:58 2025 +0200 Commit: Marco Cecchetti <marco.cecche...@collabora.com> CommitDate: Sun Aug 24 23:21:44 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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190035 Tested-by: Jenkins Reviewed-by: Marco Cecchetti <marco.cecche...@collabora.com> diff --git a/chart2/source/controller/sidebar/ChartAreaPanel.cxx b/chart2/source/controller/sidebar/ChartAreaPanel.cxx index 87a49974eb8c..036c3ef1e87e 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 = static_cast<sal_uInt32>(-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 67b097301b67..2bf22ae82b2b 100644 --- a/chart2/source/model/main/ChartModel.cxx +++ b/chart2/source/model/main/ChartModel.cxx @@ -73,6 +73,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> @@ -1560,7 +1561,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 4c01c3bfe578..d997d9e8f673 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -4138,10 +4138,11 @@ 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, setAllowManageRedlines)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(79), offsetof(struct _LibreOfficeKitDocumentClass, setColorPreviewState)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(80), offsetof(struct _LibreOfficeKitDocumentClass, setAllowManageRedlines)); // As above - CPPUNIT_ASSERT_EQUAL(documentClassOffset(80), sizeof(struct _LibreOfficeKitDocumentClass)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(81), sizeof(struct _LibreOfficeKitDocumentClass)); } CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 779930428f47..f23261e8fb79 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1352,6 +1352,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 { @@ -1555,6 +1557,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; } @@ -7653,6 +7656,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 502d660229bb..7860adf3c66b 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -562,6 +562,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); + /// @see lok::Document::setAllowManageRedlines(). void (*setAllowManageRedlines)(LibreOfficeKitDocument* pThis, int nId, bool allow); diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index d53b7f8b97eb..b6cdd929cb95 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -953,6 +953,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 b9189f585161..b32f775db14b 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -143,6 +143,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 81430800350a..ee35c7195278 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -178,6 +178,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; @@ -454,6 +455,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 157742768f47..d27e0cbca0d9 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -429,6 +429,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 1bb9e79c2455..98d3ee3a237d 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -2745,6 +2745,7 @@ SfxViewShell::SfxViewShell , maLOKLocale(LANGUAGE_NONE) , maLOKDeviceFormFactor(LOKDeviceFormFactor::UNKNOWN) , mbLOKAccessibilityEnabled(false) +, mbLOKColorPreviewEnabled(false) { SetMargin( rViewFrame.GetMargin_Impl() ); @@ -3508,6 +3509,11 @@ void SfxViewShell::SetLOKAccessibilityState(bool bEnabled) } } +void SfxViewShell::SetLOKColorPreviewState(bool bEnabled) +{ + mbLOKColorPreviewEnabled = bEnabled; +} + void SfxViewShell::SetLOKLocale(const OUString& rBcp47LanguageTag) { maLOKLocale = LanguageTag(rBcp47LanguageTag, true).makeFallback(); commit 3fafbb522b06a1c23985922b77d0e4524a366ff3 Author: Marco Cecchetti <marco.cecche...@collabora.com> AuthorDate: Sun May 11 15:20:34 2025 +0200 Commit: Marco Cecchetti <marco.cecche...@collabora.com> CommitDate: Sun Aug 24 23:21:33 2025 +0200 chart color palette: it fixes some minor issues Change-Id: Idf40fc5360b8551a2e7ac28d193157b7ae69f488 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185171 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190034 Reviewed-by: Marco Cecchetti <marco.cecche...@collabora.com> Tested-by: Jenkins diff --git a/chart2/source/controller/dialogs/tp_ChartColorPalette.hxx b/chart2/source/controller/dialogs/tp_ChartColorPalette.hxx index 02cfe3cd5c94..53ea633585a6 100644 --- a/chart2/source/controller/dialogs/tp_ChartColorPalette.hxx +++ b/chart2/source/controller/dialogs/tp_ChartColorPalette.hxx @@ -27,6 +27,8 @@ namespace chart class ChartModel; class ChartColorPaletteHelper; +// This tab page is used to set up data series colors according to a given color palette +// It is present in the Chart Format Dialog for several chart elements. class ChartColorPaletteTabPage final : public SfxTabPage { public: diff --git a/chart2/source/tools/ChartColorPaletteHelper.cxx b/chart2/source/tools/ChartColorPaletteHelper.cxx index 109143ce851f..bfaf3ef82279 100644 --- a/chart2/source/tools/ChartColorPaletteHelper.cxx +++ b/chart2/source/tools/ChartColorPaletteHelper.cxx @@ -47,12 +47,12 @@ void ChartColorPaletteHelper::createBasePaletteFromTheme( { SAL_WARN("chart2", "ChartColorPaletteHelper::createBasePaletteFromTheme: no valid theme provided"); - mBasePalette[0] = Color::STRtoRGB(u"18A303"); - mBasePalette[1] = Color::STRtoRGB(u"0369A3"); - mBasePalette[2] = Color::STRtoRGB(u"A33E03"); - mBasePalette[3] = Color::STRtoRGB(u"8E03A3"); - mBasePalette[4] = Color::STRtoRGB(u"C99C00"); - mBasePalette[5] = Color::STRtoRGB(u"C9211E"); + mBasePalette[0] = 0x18A303; + mBasePalette[1] = 0x0369A3; + mBasePalette[2] = 0xA33E03; + mBasePalette[3] = 0x8E03A3; + mBasePalette[4] = 0xC99C00; + mBasePalette[5] = 0xC9211E; } } diff --git a/include/svx/ChartColorPaletteType.hxx b/include/svx/ChartColorPaletteType.hxx index 30f6844ee876..f87f395f8a20 100644 --- a/include/svx/ChartColorPaletteType.hxx +++ b/include/svx/ChartColorPaletteType.hxx @@ -20,11 +20,11 @@ constexpr size_t ChartColorPaletteSize = 6; typedef std::array<Color, ChartColorPaletteSize> ChartColorPalette; -enum class ChartColorPaletteType : sal_Int32 +enum class ChartColorPaletteType : sal_uInt8 { - Unknown = -1, - Colorful = 0, - Monochromatic = 1, + Unknown, + Colorful, + Monochromatic, }; struct ChartColorPaletteLayout diff --git a/include/svx/chrtitem.hxx b/include/svx/chrtitem.hxx index 5fa196fd5a50..41f043541fb8 100644 --- a/include/svx/chrtitem.hxx +++ b/include/svx/chrtitem.hxx @@ -26,7 +26,7 @@ #include <svl/poolitem.hxx> #include <svx/svxdllapi.h> -enum class ChartColorPaletteType: sal_Int32; +enum class ChartColorPaletteType: sal_uInt8; enum class SvxChartTextOrder { @@ -144,6 +144,9 @@ public: double GetValue() const { return m_fVal; } }; +// This SfxPoolItem is used to represent a chart color palette. +// A chart color palette is uniquely determined by its type and an index. +// Chart color palettes depends on current color theme and are generated by ChartColorPaletteHelper. class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC SvxChartColorPaletteItem final : public SfxPoolItem { ChartColorPaletteType meType; diff --git a/svx/source/items/chrtitem.cxx b/svx/source/items/chrtitem.cxx index 58363e96de8c..077c4d7107a2 100644 --- a/svx/source/items/chrtitem.cxx +++ b/svx/source/items/chrtitem.cxx @@ -201,7 +201,7 @@ bool SvxChartColorPaletteItem::QueryValue(uno::Any& rVal, const sal_uInt8 nMembe { if (nMemberId == MID_CHART_COLOR_PALETTE_TYPE) { - rVal <<= static_cast<sal_Int32>(meType); + rVal <<= static_cast<sal_uInt8>(meType); return true; } if (nMemberId == MID_CHART_COLOR_PALETTE_INDEX) @@ -216,7 +216,7 @@ bool SvxChartColorPaletteItem::PutValue(const uno::Any& rVal, const sal_uInt8 nM { if (nMemberId == MID_CHART_COLOR_PALETTE_TYPE) { - sal_Int32 nType = -1; + sal_uInt8 nType = 0; rVal >>= nType; meType = static_cast<ChartColorPaletteType>(nType); return true;