diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-11-25 14:25:28 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-11-27 00:27:42 +0100 |
commit | 05734503ed36cff64cfaac8afb7c6df5eced8873 (patch) | |
tree | dc6a3ed6297c4ba094c863b8c463f34da4747e39 | |
parent | 1cf1e9cc33327128f30c6781b4d8c16e20601540 (diff) |
tdf#126043 use another bulk_insert_for_each
Change-Id: I05c3fc6e708d000ba955981dbd8d11371ea99da2
Reviewed-on: https://gerrit.libreoffice.org/83686
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | cui/source/customize/SvxMenuConfigPage.cxx | 29 | ||||
-rw-r--r-- | cui/source/customize/SvxToolbarConfigPage.cxx | 12 | ||||
-rw-r--r-- | cui/source/customize/cfg.cxx | 57 | ||||
-rw-r--r-- | cui/source/inc/cfg.hxx | 9 | ||||
-rw-r--r-- | include/vcl/weld.hxx | 5 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 8 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 6 |
7 files changed, 81 insertions, 45 deletions
diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx index 218d087349ad..7289b3506a7c 100644 --- a/cui/source/customize/SvxMenuConfigPage.cxx +++ b/cui/source/customize/SvxMenuConfigPage.cxx @@ -263,22 +263,21 @@ short SvxMenuConfigPage::QueryReset() void SvxMenuConfigPage::SelectElement() { - m_xContentsListBox->clear(); + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); SvxConfigEntry* pMenuData = GetTopLevelSelection(); - - if ( pMenuData ) + if (!pMenuData) + rTreeView.clear(); + else { SvxEntries* pEntries = pMenuData->GetEntries(); - int i = 0; - for (auto const& entry : *pEntries) - { + rTreeView.bulk_insert_for_each(pEntries->size(), [this, &rTreeView, pEntries](weld::TreeIter& rIter, int nIdx) { + auto const& entry = (*pEntries)[nIdx]; OUString sId(OUString::number(reinterpret_cast<sal_Int64>(entry))); - m_xContentsListBox->insert(i, sId); - InsertEntryIntoUI(entry, i, 0); - ++i; - } + rTreeView.set_id(rIter, sId); + InsertEntryIntoUI(entry, rTreeView, rIter, 0); + }); } UpdateButtonStates(); @@ -364,9 +363,10 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, AddCommandHdl, weld::Button&, void ) int nPos = AddFunction(-1, /*bAllowDuplicates*/false); if (nPos == -1) return; + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); SvxConfigEntry* pEntry = - reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nPos).toInt64()); - InsertEntryIntoUI(pEntry, nPos, 0); + reinterpret_cast<SvxConfigEntry*>(rTreeView.get_id(nPos).toInt64()); + InsertEntryIntoUI(pEntry, rTreeView, nPos, 0); } IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveCommandHdl, weld::Button&, void ) @@ -380,12 +380,13 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveCommandHdl, weld::Button&, void ) IMPL_LINK(SvxMenuConfigPage, InsertHdl, const OString&, rIdent, void) { + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); if (rIdent == "insertseparator") { SvxConfigEntry* pNewEntryData = new SvxConfigEntry; pNewEntryData->SetUserDefined(); int nPos = AppendEntry(pNewEntryData, -1); - InsertEntryIntoUI(pNewEntryData, nPos, 0); + InsertEntryIntoUI(pNewEntryData, rTreeView, nPos, 0); } else if (rIdent == "insertsubmenu") { @@ -406,7 +407,7 @@ IMPL_LINK(SvxMenuConfigPage, InsertHdl, const OString&, rIdent, void) pNewEntryData->SetUserDefined(); int nPos = AppendEntry(pNewEntryData, -1); - InsertEntryIntoUI(pNewEntryData, nPos, 0); + InsertEntryIntoUI(pNewEntryData, rTreeView, nPos, 0); ReloadTopLevelListBox(); diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx index b8058df387f5..b30302d52ed3 100644 --- a/cui/source/customize/SvxToolbarConfigPage.cxx +++ b/cui/source/customize/SvxToolbarConfigPage.cxx @@ -463,7 +463,7 @@ IMPL_LINK(SvxToolbarConfigPage, InsertHdl, const OString&, rIdent, void) pNewEntryData->SetUserDefined(); int nPos = AppendEntry(pNewEntryData, -1); - InsertEntryIntoUI(pNewEntryData, nPos, 1); + InsertEntryIntoUI(pNewEntryData, m_xContentsListBox->get_widget(), nPos, 1); static_cast<ToolbarSaveInData*>( GetSaveInData())->ApplyToolbar( pToolbar ); @@ -561,7 +561,7 @@ IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void) OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); m_xContentsListBox->insert(nActEntry, sId); m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(pEntry, nActEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nActEntry, 1); m_xContentsListBox->select(nActEntry); m_xContentsListBox->scroll_to_row(nActEntry); @@ -601,7 +601,7 @@ IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void) OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); m_xContentsListBox->insert(nActEntry, sId); m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(pEntry, nActEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nActEntry, 1); m_xContentsListBox->select(nActEntry); m_xContentsListBox->scroll_to_row(nActEntry); @@ -658,7 +658,7 @@ IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void) m_xContentsListBox->insert(nActEntry, sId); m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(pEntry, nActEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nActEntry, 1); m_xContentsListBox->select(nActEntry); m_xContentsListBox->scroll_to_row(nActEntry); @@ -790,7 +790,7 @@ void SvxToolbarConfigPage::SelectElement() m_xContentsListBox->insert(i, sId); if (entry->IsBinding() && !entry->IsSeparator()) m_xContentsListBox->set_toggle(i, entry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(entry, i, 1); + InsertEntryIntoUI(entry, m_xContentsListBox->get_widget(), i, 1); ++i; } @@ -819,7 +819,7 @@ void SvxToolbarConfigPage::AddFunction(int nTarget) m_xContentsListBox->set_toggle(nNewLBEntry, TRISTATE_TRUE, 0); } - InsertEntryIntoUI(pEntry, nNewLBEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nNewLBEntry, 1); // Changes are not visible on the toolbar until this point // TODO: Figure out a way to show the changes on the toolbar, but revert if diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index 30dd22c71325..6c98193e799b 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -1506,34 +1506,49 @@ int SvxConfigPage::AppendEntry( return nNewEntry; } -void SvxConfigPage::InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, int nPos, int nStartCol) +namespace { - OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pNewEntryData))); - - m_xContentsListBox->set_id(nPos, sId); - - if (pNewEntryData->IsSeparator()) - { - m_xContentsListBox->set_text(nPos, "----------------------------------", nStartCol + 1); - } - else + template<typename itertype> void TmplInsertEntryIntoUI(SvxConfigEntry* pNewEntryData, weld::TreeView& rTreeView, itertype& rIter, int nStartCol, SaveInData* pSaveInData, VirtualDevice& rDropDown) { - auto xImage = GetSaveInData()->GetImage(pNewEntryData->GetCommand()); - if (xImage.is()) - m_xContentsListBox->set_image(nPos, xImage, nStartCol); - OUString aName = SvxConfigPageHelper::stripHotKey( pNewEntryData->GetName() ); - m_xContentsListBox->set_text(nPos, aName, nStartCol + 1); - } + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pNewEntryData))); - if (nStartCol == 0) // menus - { - if (pNewEntryData->IsPopup() || pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN) - m_xContentsListBox->set_dropdown(nPos, nStartCol + 2); + rTreeView.set_id(rIter, sId); + + if (pNewEntryData->IsSeparator()) + { + rTreeView.set_text(rIter, "----------------------------------", nStartCol + 1); + } else - m_xContentsListBox->set_image(nPos, nullptr, nStartCol + 2); + { + auto xImage = pSaveInData->GetImage(pNewEntryData->GetCommand()); + if (xImage.is()) + rTreeView.set_image(rIter, xImage, nStartCol); + OUString aName = SvxConfigPageHelper::stripHotKey( pNewEntryData->GetName() ); + rTreeView.set_text(rIter, aName, nStartCol + 1); + } + + if (nStartCol == 0) // menus + { + if (pNewEntryData->IsPopup() || pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN) + rTreeView.set_image(rIter, rDropDown, nStartCol + 2); + else + rTreeView.set_image(rIter, css::uno::Reference<css::graphic::XGraphic>(), nStartCol + 2); + } } } +void SvxConfigPage::InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, weld::TreeView& rTreeView, int nPos, int nStartCol) +{ + TmplInsertEntryIntoUI<int>(pNewEntryData, rTreeView, nPos, nStartCol, + GetSaveInData(), m_xContentsListBox->get_dropdown_image()); +} + +void SvxConfigPage::InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, weld::TreeView& rTreeView, weld::TreeIter& rIter, int nStartCol) +{ + TmplInsertEntryIntoUI<weld::TreeIter>(pNewEntryData, rTreeView, rIter, nStartCol, + GetSaveInData(), m_xContentsListBox->get_dropdown_image()); +} + IMPL_LINK(SvxConfigPage, MoveHdl, weld::Button&, rButton, void) { MoveEntry(&rButton == m_xMoveUpButton.get()); diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx index d5410a6ce667..fa825b92f207 100644 --- a/cui/source/inc/cfg.hxx +++ b/cui/source/inc/cfg.hxx @@ -325,6 +325,8 @@ public: SvxMenuEntriesListBox(std::unique_ptr<weld::TreeView> xControl, SvxConfigPage* pPage); virtual ~SvxMenuEntriesListBox(); + VirtualDevice& get_dropdown_image() const { return *m_xDropDown; } + int get_selected_index() const { return m_xControl->get_selected_index(); } OUString get_id(int nPos) const { return m_xControl->get_id(nPos); } void remove(int nPos) { m_xControl->remove(nPos); } @@ -451,7 +453,12 @@ protected: SvxConfigEntry const * pParentData ); void InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, - int nPos, int nStartCol); + weld::TreeView& rTreeView, int nPos, + int nStartCol); + void InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, + weld::TreeView& rTreeView, weld::TreeIter& rIter, + int nStartCol); + void InsertEntryIntoNotebookbarTabUI(const OUString& sClassId, const OUString& sUIItemId, const OUString& sUIItemCommand, weld::TreeView& rTreeView, weld::TreeIter& rIter, diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 194383e72bcc..abe71e42fedb 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -870,7 +870,6 @@ public: virtual void collapse_row(const TreeIter& rIter) = 0; virtual void set_text(const TreeIter& rIter, const OUString& rStr, int col = -1) = 0; virtual void set_sensitive(const TreeIter& rIter, bool bSensitive, int col = -1) = 0; - virtual void set_image(const TreeIter& rIter, const OUString& rImage, int col = -1) = 0; virtual void set_text_emphasis(const TreeIter& rIter, bool bOn, int col) = 0; virtual bool get_text_emphasis(const TreeIter& rIter, int col) const = 0; virtual void set_toggle(const TreeIter& rIter, TriState bOn, int col) = 0; @@ -878,8 +877,10 @@ public: virtual OUString get_text(const TreeIter& rIter, int col = -1) const = 0; virtual void set_id(const TreeIter& rIter, const OUString& rId) = 0; virtual OUString get_id(const TreeIter& rIter) const = 0; + virtual void set_image(const TreeIter& rIter, const OUString& rImage, int col = -1) = 0; + virtual void set_image(const TreeIter& rIter, VirtualDevice& rImage, int col = -1) = 0; virtual void set_image(const TreeIter& rIter, - const css::uno::Reference<css::graphic::XGraphic>& rImage, int col) + const css::uno::Reference<css::graphic::XGraphic>& rImage, int col = -1) = 0; virtual void set_font_color(const TreeIter& rIter, const Color& rColor) const = 0; virtual void scroll_to_row(const TreeIter& rIter) = 0; diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 729901d0fc33..b26f48579813 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -4098,13 +4098,19 @@ public: set_image(m_xTreeView->GetEntry(nullptr, pos), createImage(rImage), col); } + virtual void set_image(const weld::TreeIter& rIter, const OUString& rImage, int col) override + { + const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); + set_image(rVclIter.iter, createImage(rImage), col); + } + virtual void set_image(const weld::TreeIter& rIter, const css::uno::Reference<css::graphic::XGraphic>& rImage, int col) override { const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); set_image(rVclIter.iter, Image(rImage), col); } - virtual void set_image(const weld::TreeIter& rIter, const OUString& rImage, int col) override + virtual void set_image(const weld::TreeIter& rIter, VirtualDevice& rImage, int col) override { const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); set_image(rVclIter.iter, createImage(rImage), col); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index eaa83a421116..71242e134847 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -9116,6 +9116,12 @@ public: set_image(rGtkIter.iter, col, getPixbuf(rImage)); } + virtual void set_image(const weld::TreeIter& rIter, VirtualDevice& rImage, int col) override + { + const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter); + set_image(rGtkIter.iter, col, getPixbuf(rImage)); + } + virtual OUString get_id(int pos) const override { return get(pos, m_nIdCol); |