diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-01-06 14:21:38 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-01-07 14:53:35 +0100 |
commit | 7df337b3636f9df9bf05d7f493e6c89e43c3f5ca (patch) | |
tree | f7218aebd85e80dd647659225e0e6f2ce68fb3a9 | |
parent | 639419601a3730eb84d0922ef3a540c961b81910 (diff) |
tdf#146423 don't set a size-request during a size-alloc
and use a better width calculation
Change-Id: Ib873a8ed9e6424c09630650af352ba5a20c674b5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128051
Reviewed-by: Kevin Suo <suokunlong@126.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | cui/source/options/optcolor.cxx | 60 | ||||
-rw-r--r-- | cui/source/options/optcolor.hxx | 5 | ||||
-rw-r--r-- | cui/uiconfig/ui/colorconfigwin.ui | 1 | ||||
-rw-r--r-- | cui/uiconfig/ui/optappearancepage.ui | 4 |
4 files changed, 44 insertions, 26 deletions
diff --git a/cui/source/options/optcolor.cxx b/cui/source/options/optcolor.cxx index 3a180621fa21..81030a79e9c8 100644 --- a/cui/source/options/optcolor.cxx +++ b/cui/source/options/optcolor.cxx @@ -188,7 +188,10 @@ public: return *m_xBox; } - void AdjustExtraWidths(int nTextWidth); + int GetLabelIndent() const + { + return m_nCheckBoxLabelOffset; + } private: // Chapter -- horizontal group separator stripe with text @@ -207,10 +210,9 @@ private: { public: Entry(weld::Window* pTopLevel, weld::Builder& rBuilder, const char* pTextWidget, const char* pColorWidget, - const Color& rColor, tools::Long nCheckBoxLabelOffset, bool bCheckBox, bool bShow); + const Color& rColor, int nCheckBoxLabelOffset, bool bCheckBox, bool bShow); public: void SetText(const OUString& rLabel) { dynamic_cast<weld::Label&>(*m_xText).set_label(rLabel); } - void set_width_request(int nTextWidth) { m_xText->set_size_request(nTextWidth, -1); } int get_height_request() const { return std::max(m_xText->get_preferred_size().Height(), @@ -239,6 +241,7 @@ private: private: weld::Window* m_pTopLevel; + int m_nCheckBoxLabelOffset; std::unique_ptr<weld::Builder> m_xBuilder; std::unique_ptr<weld::Box> m_xBox; std::unique_ptr<weld::Widget> m_xWidget1; @@ -280,7 +283,7 @@ ColorConfigWindow_Impl::Chapter::Chapter(weld::Builder& rBuilder, const char* pL ColorConfigWindow_Impl::Entry::Entry(weld::Window* pTopLevel, weld::Builder& rBuilder, const char* pTextWidget, const char* pColorWidget, const Color& rColor, - tools::Long nCheckBoxLabelOffset, bool bCheckBox, bool bShow) + int nCheckBoxLabelOffset, bool bCheckBox, bool bShow) : m_xColorList(new ColorListBox(rBuilder.weld_menu_button(pColorWidget), [pTopLevel]{ return pTopLevel; })) , m_aDefaultColor(rColor) { @@ -365,8 +368,8 @@ ColorConfigWindow_Impl::ColorConfigWindow_Impl(weld::Window* pTopLevel, weld::Co : m_pTopLevel(pTopLevel) , m_xBuilder(Application::CreateBuilder(pParent, "cui/ui/colorconfigwin.ui")) , m_xBox(m_xBuilder->weld_box("ColorConfigWindow")) - , m_xWidget1(m_xBuilder->weld_widget("doccolor")) - , m_xWidget2(m_xBuilder->weld_widget("doccolor_lb")) + , m_xWidget1(m_xBuilder->weld_widget("docboundaries")) + , m_xWidget2(m_xBuilder->weld_widget("docboundaries_lb")) { CreateEntries(); } @@ -384,9 +387,8 @@ void ColorConfigWindow_Impl::CreateEntries() // Here we want to get the amount to add to the position of a FixedText to // get it to align its contents with that of a CheckBox - tools::Long nCheckBoxLabelOffset = 0; { - OUString sSampleText("X"); + OUString sSampleText("XXXXXX"); std::unique_ptr<weld::CheckButton> xCheckBox(m_xBuilder->weld_check_button("docboundaries")); std::unique_ptr<weld::Label> xFixedText(m_xBuilder->weld_label("doccolor")); OUString sOrigCheck(xCheckBox->get_label()); @@ -397,7 +399,7 @@ void ColorConfigWindow_Impl::CreateEntries() Size aFixedSize(xFixedText->get_preferred_size()); xCheckBox->set_label(sOrigCheck); xFixedText->set_label(sOrigFixed); - nCheckBoxLabelOffset = aCheckSize.Width() - aFixedSize.Width(); + m_nCheckBoxLabelOffset = aCheckSize.Width() - aFixedSize.Width(); } // creating entries @@ -407,7 +409,7 @@ void ColorConfigWindow_Impl::CreateEntries() vEntries.push_back(std::make_shared<Entry>(m_pTopLevel, *m_xBuilder, vEntryInfo[i].pText, vEntryInfo[i].pColor, ColorConfig::GetDefaultColor(static_cast<ColorConfigEntry>(i)), - nCheckBoxLabelOffset, + m_nCheckBoxLabelOffset, vEntryInfo[i].bCheckBox, aModulesInstalled[vEntryInfo[i].eGroup])); } @@ -441,18 +443,12 @@ void ColorConfigWindow_Impl::CreateEntries() aExtConfig.GetComponentColorConfigValue(sComponentName, i); vEntries.push_back(std::make_shared<Entry>(m_pTopLevel, *vExtBuilders.back(), "label", "button", aColorEntry.getDefaultColor(), - nCheckBoxLabelOffset, false, true)); + m_nCheckBoxLabelOffset, false, true)); vEntries.back()->SetText(aColorEntry.getDisplayName()); } } } -void ColorConfigWindow_Impl::AdjustExtraWidths(int nTextWidth) -{ - for (size_t i = SAL_N_ELEMENTS(vEntryInfo); i < vEntries.size(); ++i) - vEntries[i]->set_width_request(nTextWidth); -} - // SetLinks() void ColorConfigWindow_Impl::SetLinks(Link<weld::Toggleable&,void> const& aCheckLink, Link<ColorListBox&,void> const& aColorLink, @@ -591,7 +587,6 @@ class ColorConfigCtrl_Impl public: explicit ColorConfigCtrl_Impl(weld::Window* pTopLevel, weld::Builder& rbuilder); - void AdjustExtraWidths(int nTextWidth) { m_xScrollWindow->AdjustExtraWidths(nTextWidth); } void SetConfig (EditableColorConfig& rConfig) { pColorConfig = &rConfig; } void SetExtendedConfig (EditableExtendedColorConfig& rConfig) { pExtColorConfig = &rConfig; } void Update(); @@ -611,6 +606,10 @@ public: { return m_xScrollWindow->GetWidget2(); } + int GetLabelIndent() const + { + return m_xScrollWindow->GetLabelIndent(); + } }; ColorConfigCtrl_Impl::ColorConfigCtrl_Impl(weld::Window* pTopLevel, weld::Builder& rBuilder) @@ -689,6 +688,7 @@ IMPL_LINK(ColorConfigCtrl_Impl, ControlFocusHdl, weld::Widget&, rCtrl, void) SvxColorOptionsTabPage::SvxColorOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet) : SfxTabPage(pPage, pController, "cui/ui/optappearancepage.ui", "OptAppearancePage", &rCoreSet) , bFillItemSetCalled(false) + , m_nSizeAllocEventId(nullptr) , m_xColorSchemeLB(m_xBuilder->weld_combo_box("colorschemelb")) , m_xSaveSchemePB(m_xBuilder->weld_button("save")) , m_xDeleteSchemePB(m_xBuilder->weld_button("delete")) @@ -734,6 +734,8 @@ SvxColorOptionsTabPage::~SvxColorOptionsTabPage() pExtColorConfig.reset(); } m_xColorConfigCT.reset(); + if (m_nSizeAllocEventId) + Application::RemoveUserEvent(m_nSizeAllocEventId); } std::unique_ptr<SfxTabPage> SvxColorOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet) @@ -865,17 +867,29 @@ void SvxColorOptionsTabPage::FillUserData() IMPL_LINK_NOARG(SvxColorOptionsTabPage, AdjustHeaderBar, const Size&, void) { + if (m_nSizeAllocEventId) + return; + m_nSizeAllocEventId = Application::PostUserEvent(LINK(this, SvxColorOptionsTabPage, PostAdjustHeaderBar)); +} + +IMPL_LINK_NOARG(SvxColorOptionsTabPage, PostAdjustHeaderBar, void*, void) +{ + m_nSizeAllocEventId = nullptr; + // horizontal positions - int nX0 = 0, nX1, nX2, y, width, height; + int nX1, nX2, nX3, y, width, height; if (!m_rWidget1.get_extents_relative_to(*m_xTable, nX1, y, width, height)) return; if (!m_rWidget2.get_extents_relative_to(*m_xTable, nX2, y, width, height)) return; - auto nTextWidth1 = nX1 - nX0; - auto nTextWidth2 = nX2 - nX1; + if (!m_xTable->get_extents_relative_to(*m_xTable, nX3, y, width, height)) + return; + + // 6 is the column-spacing of the parent grid of these labels + auto nTextWidth1 = nX1 + m_xColorConfigCT->GetLabelIndent() - 6; m_xOnFT->set_size_request(nTextWidth1, -1); - m_xElementFT->set_size_request(nTextWidth2, -1); - m_xColorConfigCT->AdjustExtraWidths(nTextWidth2 - 12); + auto nTextWidth3 = width - nX2; + m_xColorFT->set_size_request(nTextWidth3, -1); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/options/optcolor.hxx b/cui/source/options/optcolor.hxx index de84e06b1405..ede03dc6b059 100644 --- a/cui/source/options/optcolor.hxx +++ b/cui/source/options/optcolor.hxx @@ -23,10 +23,14 @@ namespace svtools {class EditableColorConfig;class EditableExtendedColorConfig;} class ColorConfigCtrl_Impl; class AbstractSvxNameDialog; +struct ImplSVEvent; + class SvxColorOptionsTabPage : public SfxTabPage { bool bFillItemSetCalled; + ImplSVEvent* m_nSizeAllocEventId; + std::unique_ptr<weld::ComboBox> m_xColorSchemeLB; std::unique_ptr<weld::Button> m_xSaveSchemePB; std::unique_ptr<weld::Button> m_xDeleteSchemePB; @@ -45,6 +49,7 @@ class SvxColorOptionsTabPage : public SfxTabPage DECL_LINK(SaveDeleteHdl_Impl, weld::Button&, void); DECL_LINK(CheckNameHdl_Impl, AbstractSvxNameDialog&, bool); DECL_LINK(AdjustHeaderBar, const Size&, void); + DECL_LINK(PostAdjustHeaderBar, void *, void); void UpdateColorConfig(); public: diff --git a/cui/uiconfig/ui/colorconfigwin.ui b/cui/uiconfig/ui/colorconfigwin.ui index d640b0fe544c..2bde28f17598 100644 --- a/cui/uiconfig/ui/colorconfigwin.ui +++ b/cui/uiconfig/ui/colorconfigwin.ui @@ -8,6 +8,7 @@ <property name="margin-start">6</property> <property name="margin-end">6</property> <property name="margin-top">6</property> + <property name="hexpand">True</property> <property name="orientation">vertical</property> <property name="spacing">12</property> <child> diff --git a/cui/uiconfig/ui/optappearancepage.ui b/cui/uiconfig/ui/optappearancepage.ui index 9b94b8ad59e4..e6625ea29024 100644 --- a/cui/uiconfig/ui/optappearancepage.ui +++ b/cui/uiconfig/ui/optappearancepage.ui @@ -215,10 +215,10 @@ <property name="column_spacing">6</property> <child> <object class="GtkLabel" id="uielements"> - <property name="width_request">250</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="no_show_all">True</property> + <property name="hexpand">True</property> <property name="label" translatable="yes" context="optappearancepage|uielements">User interface elements</property> <property name="xalign">0</property> </object> @@ -229,11 +229,9 @@ </child> <child> <object class="GtkLabel" id="colorsetting"> - <property name="width_request">150</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="no_show_all">True</property> - <property name="hexpand">True</property> <property name="label" translatable="yes" context="optappearancepage|colorsetting">Color setting</property> <property name="xalign">0</property> </object> |