diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-12-07 16:00:28 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-12-07 22:58:09 +0000 |
commit | d327a3bf45808fc7575b7fffa681314e50b0adf8 (patch) | |
tree | 53465c0e4c64ed68d4ad96f785390aaac3340c2d /svx | |
parent | 62ae7be5aa20499c45e6f1b3f1dd2729483625b0 (diff) |
Resolves: tdf#152301 allow using an existing ColorListBox to speed init
Change-Id: I31fb350fd69831e68ca7c60ec758126aab086895
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143791
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/inc/palettes.hxx | 9 | ||||
-rw-r--r-- | svx/source/tbxctrls/Palette.cxx | 15 | ||||
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 19 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 16 |
4 files changed, 52 insertions, 7 deletions
diff --git a/svx/inc/palettes.hxx b/svx/inc/palettes.hxx index 12fdbb560f1d..abeccf0fe243 100644 --- a/svx/inc/palettes.hxx +++ b/svx/inc/palettes.hxx @@ -37,6 +37,7 @@ class PaletteASE final : public Palette ColorList maColors; void LoadPalette(); + PaletteASE(const PaletteASE&) = default; public: PaletteASE( OUString aFPath, OUString aFName ); virtual ~PaletteASE() override; @@ -46,6 +47,8 @@ public: virtual void LoadColorSet(SvxColorValueSet& rColorSet) override; virtual bool IsValid() override; + + virtual Palette* Clone() const override; }; // GPL - this is *not* GNU Public License, but is the Gimp PaLette @@ -62,6 +65,7 @@ class PaletteGPL final : public Palette bool ReadPaletteHeader(SvFileStream& rFileStream); void LoadPaletteHeader(); void LoadPalette(); + PaletteGPL(const PaletteGPL&) = default; public: PaletteGPL( OUString aFPath, OUString aFName ); virtual ~PaletteGPL() override; @@ -71,6 +75,8 @@ public: virtual void LoadColorSet(SvxColorValueSet& rColorSet) override; virtual bool IsValid() override; + + virtual Palette* Clone() const override; }; // SOC - Star Office Color-table @@ -81,6 +87,7 @@ class PaletteSOC final : public Palette OUString maFPath; OUString maSOCPaletteName; XColorListRef mpColorList; + PaletteSOC(const PaletteSOC&) = default; public: PaletteSOC( OUString aFPath, OUString aFName ); virtual ~PaletteSOC() override; @@ -90,6 +97,8 @@ public: virtual void LoadColorSet(SvxColorValueSet& rColorSet) override; virtual bool IsValid() override; + + virtual Palette* Clone() const override; }; #endif // INCLUDED_SVX_INC_PALETTE_HXX diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx index 64f2b648510e..63d1cf972c38 100644 --- a/svx/source/tbxctrls/Palette.cxx +++ b/svx/source/tbxctrls/Palette.cxx @@ -171,6 +171,11 @@ void PaletteASE::LoadPalette() mbValidPalette = true; } +Palette* PaletteASE::Clone() const +{ + return new PaletteASE(*this); +} + // PaletteGPL ------------------------------------------------------------------ static OString lcl_getToken(OStringBuffer& rStr, sal_Int32& index); @@ -286,6 +291,11 @@ void PaletteGPL::LoadPalette() } while (aFile.ReadLine(aLine)); } +Palette* PaletteGPL::Clone() const +{ + return new PaletteGPL(*this); +} + // finds first token in rStr from index, separated by whitespace // returns position of next token in index static OString lcl_getToken(OStringBuffer& rStr, sal_Int32& index) @@ -362,6 +372,11 @@ bool PaletteSOC::IsValid() return true; } +Palette* PaletteSOC::Clone() const +{ + return new PaletteSOC(*this); +} + namespace svx { NamedColor NamedThemedColor::ToNamedColor() const { return { m_aColor, m_aName }; } diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index 8f642e779b58..f5cb5d221e37 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -77,6 +77,25 @@ PaletteManager::PaletteManager() : } +PaletteManager::PaletteManager(const PaletteManager* pClone) + : mnMaxRecentColors(pClone->mnMaxRecentColors) + , mnNumOfPalettes(pClone->mnNumOfPalettes) + , mnCurrentPalette(pClone->mnCurrentPalette) + , mnColorCount(pClone->mnColorCount) + , mpBtnUpdater(nullptr) + , pColorList(pClone->pColorList) + , maRecentColors(pClone->maRecentColors) + , maColorSelectFunction(PaletteManager::DispatchColorCommand) +{ + for (const auto& a : pClone->m_Palettes) + m_Palettes.emplace_back(a->Clone()); +} + +PaletteManager* PaletteManager::Clone() const +{ + return new PaletteManager(this); +} + PaletteManager::~PaletteManager() { } diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 7dd2e7e55aa2..8df461642233 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -4229,7 +4229,7 @@ void ColorListBox::SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton) ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl, TopLevelParentFunction aTopLevelParentFunction, - int* pWidthRequestCache) + const ColorListBox* pCache) : m_xButton(std::move(pControl)) , m_aColorWrapper(this) , m_aAutoDisplayColor(Application::GetSettings().GetStyleSettings().GetDialogColor()) @@ -4239,12 +4239,14 @@ ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl, { m_xButton->connect_toggled(LINK(this, ColorListBox, ToggleHdl)); m_aSelectedColor = svx::NamedThemedColor::FromNamedColor(GetAutoColor(m_nSlotId)); - int nWidthRequest = pWidthRequestCache ? *pWidthRequestCache : -1; - if (nWidthRequest == -1) - nWidthRequest = CalcBestWidthRequest(); - LockWidthRequest(nWidthRequest); - if (pWidthRequestCache) - *pWidthRequestCache = nWidthRequest; + if (!pCache) + LockWidthRequest(CalcBestWidthRequest()); + else + { + LockWidthRequest(pCache->m_xButton->get_size_request().Width()); + m_xPaletteManager.reset(pCache->m_xPaletteManager->Clone()); + m_xPaletteManager->SetColorSelectFunction(std::ref(m_aColorWrapper)); + } ShowPreview(m_aSelectedColor.ToNamedColor()); } |