diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-12-07 12:56:10 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-12-07 22:57:57 +0000 |
commit | 62ae7be5aa20499c45e6f1b3f1dd2729483625b0 (patch) | |
tree | b811a06fda99b0231da7c5232c6f387e599e63b4 /svx/source/tbxctrls | |
parent | 5d77fe6e7a386efda32a19d3bca587b1ad12715d (diff) |
Related: tdf#152301 cache color widget width
Change-Id: I0030980e2259715aa1fa624eb0ee82d5dfc51810
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143778
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx/source/tbxctrls')
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 173d6b3e4f32..7dd2e7e55aa2 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -4227,7 +4227,9 @@ void ColorListBox::SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton) createColorWindow(); } -ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl, TopLevelParentFunction aTopLevelParentFunction) +ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl, + TopLevelParentFunction aTopLevelParentFunction, + int* pWidthRequestCache) : m_xButton(std::move(pControl)) , m_aColorWrapper(this) , m_aAutoDisplayColor(Application::GetSettings().GetStyleSettings().GetDialogColor()) @@ -4237,7 +4239,12 @@ ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl, TopLevelP { m_xButton->connect_toggled(LINK(this, ColorListBox, ToggleHdl)); m_aSelectedColor = svx::NamedThemedColor::FromNamedColor(GetAutoColor(m_nSlotId)); - LockWidthRequest(); + int nWidthRequest = pWidthRequestCache ? *pWidthRequestCache : -1; + if (nWidthRequest == -1) + nWidthRequest = CalcBestWidthRequest(); + LockWidthRequest(nWidthRequest); + if (pWidthRequestCache) + *pWidthRequestCache = nWidthRequest; ShowPreview(m_aSelectedColor.ToNamedColor()); } @@ -4319,7 +4326,7 @@ void ColorListBox::Selected(const svx::NamedThemedColor& rColor) //to avoid the box resizing every time the color is changed to //the optimal size of the individual color, get the longest //standard color and stick with that as the size for all -void ColorListBox::LockWidthRequest() +int ColorListBox::CalcBestWidthRequest() { NamedColor aLongestColor; tools::Long nMaxStandardColorTextWidth = 0; @@ -4335,7 +4342,12 @@ void ColorListBox::LockWidthRequest() } } ShowPreview(aLongestColor); - m_xButton->set_size_request(m_xButton->get_preferred_size().Width(), -1); + return m_xButton->get_preferred_size().Width(); +} + +void ColorListBox::LockWidthRequest(int nWidth) +{ + m_xButton->set_size_request(nWidth, -1); } void ColorListBox::ShowPreview(const NamedColor &rColor) |