diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-06-30 15:03:31 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-06-30 20:53:38 +0200 |
commit | 714b2b617e9baef02510c482c6fd028e6e72acd8 (patch) | |
tree | 4473d35fd6e1b6538767e28ef1616383cc3c7d46 /sc | |
parent | 907b60b37f089e952ae2e80499c7b168296469a4 (diff) |
tdf#134270 rearrange so we know the final treeview width
so we can unconditionally use the treeview width as the optimized
pre-calculated row width hint and then fix up the gen fixed column
settings to take account of the auto CHK_BTN mode
Change-Id: I2e1eaf4b1121d5e705eb7db3464f123c038db246
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97532
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/cctrl/checklistmenu.cxx | 66 | ||||
-rw-r--r-- | sc/source/ui/inc/checklistmenu.hxx | 10 |
2 files changed, 45 insertions, 31 deletions
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx index 242750c61b1a..123cc1824bdf 100644 --- a/sc/source/ui/cctrl/checklistmenu.cxx +++ b/sc/source/ui/cctrl/checklistmenu.cxx @@ -167,7 +167,7 @@ ScCheckListMenuWindow* ScCheckListMenuControl::addSubMenuItem(const OUString& rT MenuItemData aItem; aItem.mbEnabled = bEnabled; vcl::Window *pContainer = mxFrame->GetWindow(GetWindowType::FirstChild); - aItem.mxSubMenuWin.reset(VclPtr<ScCheckListMenuWindow>::Create(pContainer, mpDoc, false, -1, mxFrame->GetMenuStackLevel()+1, mxFrame.get())); + aItem.mxSubMenuWin.reset(VclPtr<ScCheckListMenuWindow>::Create(pContainer, mpDoc, false, -1, mxFrame.get())); maMenuItems.emplace_back(std::move(aItem)); mxMenu->append_text(rText); @@ -443,25 +443,60 @@ ScCheckListMenuControl::ScCheckListMenuControl(ScCheckListMenuWindow* pParent, v , maOpenTimer(this) , maCloseTimer(this) { - if (nWidth != -1) + bool bIsSubMenu = pParent->GetParentMenu(); + + int nChecksHeight = mxChecks->get_height_rows(9); + if (!bIsSubMenu && nWidth != -1) + { mnCheckWidthReq = nWidth - mxFrame->get_border_width() * 2 - 4; + mxChecks->set_size_request(mnCheckWidthReq, nChecksHeight); + } // sort ok/cancel into native order, if this was a dialog they would be auto-sorted, but this // popup isn't a true dialog mxButtonBox->sort_native_button_order(); - mxChecks->enable_toggle_buttons(weld::ColumnToggleType::Check); + if (!bIsSubMenu) + { + mxChecks->enable_toggle_buttons(weld::ColumnToggleType::Check); + + mxBox->show(); + mxEdSearch->show(); + mxButtonBox->show(); + } mxContainer->connect_focus_in(LINK(this, ScCheckListMenuControl, FocusHdl)); mxMenu->connect_row_activated(LINK(this, ScCheckListMenuControl, RowActivatedHdl)); mxMenu->connect_changed(LINK(this, ScCheckListMenuControl, SelectHdl)); mxMenu->connect_key_press(LINK(this, ScCheckListMenuControl, MenuKeyInputHdl)); + if (!bIsSubMenu) + { + mxBtnOk->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); + mxBtnCancel->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); + mxEdSearch->connect_changed(LINK(this, ScCheckListMenuControl, EdModifyHdl)); + mxEdSearch->connect_activate(LINK(this, ScCheckListMenuControl, EdActivateHdl)); + mxChecks->connect_toggled(LINK(this, ScCheckListMenuControl, CheckHdl)); + mxChecks->connect_key_press(LINK(this, ScCheckListMenuControl, KeyInputHdl)); + mxChkToggleAll->connect_toggled(LINK(this, ScCheckListMenuControl, TriStateHdl)); + mxBtnSelectSingle->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); + mxBtnUnselectSingle->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); + } + if (mbCanHaveSubMenu) { CreateDropDown(); mxMenu->connect_size_allocate(LINK(this, ScCheckListMenuControl, TreeSizeAllocHdl)); } + + if (!bIsSubMenu) + { + // determine what width the checklist will end up with + mnCheckWidthReq = mxContainer->get_preferred_size().Width(); + // make that size fixed now, we can now use mnCheckWidthReq to speed up + // bulk_insert_for_each + mxChecks->set_size_request(mnCheckWidthReq, nChecksHeight); + } } IMPL_LINK_NOARG(ScCheckListMenuControl, FocusHdl, weld::Widget&, void) @@ -493,11 +528,10 @@ ScCheckListMenuControl::~ScCheckListMenuControl() } ScCheckListMenuWindow::ScCheckListMenuWindow(vcl::Window* pParent, ScDocument* pDoc, bool bCanHaveSubMenu, - int nWidth, sal_uInt16 nMenuStackLevel, ScCheckListMenuWindow* pParentMenu) + int nWidth, ScCheckListMenuWindow* pParentMenu) : DockingWindow(pParent, "InterimDockParent", "svx/ui/interimdockparent.ui") , mxParentMenu(pParentMenu) , mxBox(get("box")) - , mnMenuStackLevel(nMenuStackLevel) { setDeferredProperties(); mxControl.reset(new ScCheckListMenuControl(this, mxBox.get(), pDoc, bCanHaveSubMenu, nWidth)); @@ -537,24 +571,8 @@ void ScCheckListMenuWindow::GetFocus() mxControl->GrabFocus(); } -void ScCheckListMenuControl::packWindow() +void ScCheckListMenuControl::prepWindow() { - mxBox->show(); - mxEdSearch->show(); - mxButtonBox->show(); - - mxBtnOk->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); - mxBtnCancel->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); - mxEdSearch->connect_changed(LINK(this, ScCheckListMenuControl, EdModifyHdl)); - mxEdSearch->connect_activate(LINK(this, ScCheckListMenuControl, EdActivateHdl)); - mxChecks->connect_toggled(LINK(this, ScCheckListMenuControl, CheckHdl)); - mxChecks->connect_key_press(LINK(this, ScCheckListMenuControl, KeyInputHdl)); - mxChkToggleAll->connect_toggled(LINK(this, ScCheckListMenuControl, TriStateHdl)); - mxBtnSelectSingle->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); - mxBtnUnselectSingle->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl)); - - mxChecks->set_size_request(mnCheckWidthReq, mxChecks->get_height_rows(9)); - mxMenu->set_size_request(-1, mxMenu->get_preferred_size().Height() + 2); mnSelectedMenu = 0; mxMenu->set_cursor(mnSelectedMenu); @@ -1161,7 +1179,7 @@ size_t ScCheckListMenuControl::initMembers() insertMember(*mxChecks, rIter, maMembers[i]); if (maMembers[i].mbVisible) ++nVisMemCount; - }, mnCheckWidthReq != -1 ? &aFixedWidths : nullptr); + }, &aFixedWidths); } else { @@ -1276,7 +1294,7 @@ void ScCheckListMenuControl::getResult(ResultType& rResult) void ScCheckListMenuControl::launch(const tools::Rectangle& rRect) { - packWindow(); + prepWindow(); if (!maConfig.mbAllowEmptySet) // We need to have at least one member selected. mxBtnOk->set_sensitive(GetCheckedEntryCount() != 0); diff --git a/sc/source/ui/inc/checklistmenu.hxx b/sc/source/ui/inc/checklistmenu.hxx index a6fc2e56fc93..5703c1d90830 100644 --- a/sc/source/ui/inc/checklistmenu.hxx +++ b/sc/source/ui/inc/checklistmenu.hxx @@ -183,10 +183,9 @@ private: }; /** - * Calculate the appropriate window size, the position and size of each - * control based on the menu items. + * Calculate the appropriate window size based on the menu items. */ - void packWindow(); + void prepWindow(); void setAllMemberState(bool bSet); void selectCurrentMemberOnly(bool bSet); void updateMemberParents(const weld::TreeIter* pLeaf, size_t nIdx); @@ -312,7 +311,7 @@ class ScCheckListMenuWindow : public DockingWindow { public: explicit ScCheckListMenuWindow(vcl::Window* pParent, ScDocument* pDoc, bool bCanHaveSubMenu, int nWidth = -1, - sal_uInt16 nMenuStackLevel = 0, ScCheckListMenuWindow* pParentMenu = nullptr); + ScCheckListMenuWindow* pParentMenu = nullptr); virtual void dispose() override; virtual ~ScCheckListMenuWindow() override; @@ -322,13 +321,10 @@ public: ScCheckListMenuWindow* GetParentMenu() { return mxParentMenu; } ScCheckListMenuControl& get_widget() { return *mxControl; } - sal_uInt16 GetMenuStackLevel() const { return mnMenuStackLevel; } - private: VclPtr<ScCheckListMenuWindow> mxParentMenu; VclPtr<vcl::Window> mxBox; std::unique_ptr<ScCheckListMenuControl> mxControl; - sal_uInt16 mnMenuStackLevel; }; #endif |