From 86618248683fa4048192d15356c7e6b430e8dbb9 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 20 May 2019 12:34:52 +0100 Subject: tdf#109158 short-circuit text width measuring with fixed width columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id050bfa8b4dae70e2a3a45b2501bb071d82d14e5 Reviewed-on: https://gerrit.libreoffice.org/72601 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- cui/source/inc/autocdlg.hxx | 1 + cui/source/tabpages/autocdlg.cxx | 17 +++++++++-------- cui/uiconfig/ui/acorreplacepage.ui | 1 + include/vcl/weld.hxx | 10 ++++++++-- vcl/source/app/salvtables.cxx | 19 ++++++++++++++++++- vcl/unx/gtk3/gtk3gtkinst.cxx | 6 +++++- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/cui/source/inc/autocdlg.hxx b/cui/source/inc/autocdlg.hxx index 346c6a1e556c..bcb283f154e6 100644 --- a/cui/source/inc/autocdlg.hxx +++ b/cui/source/inc/autocdlg.hxx @@ -180,6 +180,7 @@ private: bool bReplaceEditChanged:1; bool bSWriter:1; + std::vector m_aReplaceFixedWidths; std::unique_ptr m_xTextOnlyCB; std::unique_ptr m_xShortED; std::unique_ptr m_xReplaceED; diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx index 9e65e501740d..00c409916d42 100644 --- a/cui/source/tabpages/autocdlg.cxx +++ b/cui/source/tabpages/autocdlg.cxx @@ -680,9 +680,9 @@ OfaAutocorrReplacePage::OfaAutocorrReplacePage(TabPageParent pParent, pCompareClass->loadDefaultCollator( aLanguageTag.getLocale(), 0 ); pCharClass.reset( new CharClass( aLanguageTag ) ); - std::vector aWidths; - aWidths.push_back(m_xReplaceTLB->get_approximate_digit_width() * 32); - m_xReplaceTLB->set_column_fixed_widths(aWidths); + auto nColWidth = m_xReplaceTLB->get_approximate_digit_width() * 32; + m_aReplaceFixedWidths.push_back(nColWidth); + m_aReplaceFixedWidths.push_back(nColWidth); m_xReplaceTLB->connect_changed( LINK(this, OfaAutocorrReplacePage, SelectHdl) ); m_xNewReplacePB->connect_clicked( LINK(this, OfaAutocorrReplacePage, NewDelButtonHdl) ); @@ -827,7 +827,7 @@ void OfaAutocorrReplacePage::RefillReplaceBox(bool bFromReset, { aFormatText.insert(rDouble.sShort); } - }); + }, &m_aReplaceFixedWidths); } else { @@ -853,7 +853,7 @@ void OfaAutocorrReplacePage::RefillReplaceBox(bool bFromReset, { aFormatText.insert(elem->GetShort()); } - }); + }, &m_aReplaceFixedWidths); m_xNewReplacePB->set_sensitive(false); m_xDeleteReplacePB->set_sensitive(false); } @@ -999,12 +999,13 @@ IMPL_LINK(OfaAutocorrReplacePage, NewDelActionHdl, weld::Entry&, rEdit, bool) IMPL_LINK_NOARG(OfaAutocorrReplacePage, EntrySizeAllocHdl, const Size&, void) { - std::vector aWidths; + m_aReplaceFixedWidths.clear(); int x, y, width, height; if (m_xReplaceED->get_extents_relative_to(*m_xReplaceTLB, x, y, width, height)) { - aWidths.push_back(x); - m_xReplaceTLB->set_column_fixed_widths(aWidths); + m_aReplaceFixedWidths.push_back(x); + m_aReplaceFixedWidths.push_back(width - 1); + m_xReplaceTLB->set_column_fixed_widths(m_aReplaceFixedWidths); } } diff --git a/cui/uiconfig/ui/acorreplacepage.ui b/cui/uiconfig/ui/acorreplacepage.ui index 326152eb2ca8..36808eb4ec4d 100644 --- a/cui/uiconfig/ui/acorreplacepage.ui +++ b/cui/uiconfig/ui/acorreplacepage.ui @@ -85,6 +85,7 @@ True True True + never in diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 8ba41b4e5851..71214ada80cf 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -775,9 +775,15 @@ public: // inserted with an arg of the index that this row will be when bulk insert // ends. // - // this enables inserting the entries backwards in models where that is faster + // this enables inserting the entries backwards in models where that is faster, + // + // pFixedWidths is optional, when present each matching entry col text + // width will not be measured, and the fixed width used instead. Use + // sparingly because wider text than the fixed width is clipped and cannot + // be scrolled into view horizontally. virtual void bulk_insert_for_each(int nSourceCount, - const std::function& func) + const std::function& func, + const std::vector* pFixedWidths = nullptr) = 0; void connect_expanding(const Link& rLink) { m_aExpandingHdl = rLink; } diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 3e375cd212ee..5c75d2f369a2 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -2768,7 +2769,9 @@ public: enable_notify_events(); } - virtual void bulk_insert_for_each(int nSourceCount, const std::function& func) override + virtual void bulk_insert_for_each(int nSourceCount, + const std::function& func, + const std::vector* pFixedWidths) override { freeze(); clear(); @@ -2776,11 +2779,25 @@ public: m_xTreeView->nTreeFlags |= SvTreeFlags::MANINS; + if (pFixedWidths) + set_column_fixed_widths(*pFixedWidths); + for (int i = 0; i < nSourceCount; ++i) { aVclIter.iter = new SvTreeListEntry; m_xTreeView->Insert(aVclIter.iter, nullptr, TREELIST_APPEND); func(aVclIter, i); + + if (!pFixedWidths) + continue; + + size_t nFixedWidths = std::min(pFixedWidths->size(), aVclIter.iter->ItemCount()); + for (size_t j = 0; j < nFixedWidths; ++j) + { + SvLBoxItem& rItem = aVclIter.iter->GetItem(j); + SvViewDataItem* pViewDataItem = m_xTreeView->GetViewDataItem(aVclIter.iter, &rItem); + pViewDataItem->mnWidth = (*pFixedWidths)[j]; + } } m_xTreeView->nTreeFlags &= ~SvTreeFlags::MANINS; diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index a39edc1abf07..fa8fbd554973 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -6710,12 +6710,16 @@ public: return aSearch.index; } - virtual void bulk_insert_for_each(int nSourceCount, const std::function& func) override + virtual void bulk_insert_for_each(int nSourceCount, const std::function& func, + const std::vector* pFixedWidths) override { freeze(); clear(); GtkInstanceTreeIter aGtkIter(nullptr); + if (pFixedWidths) + set_column_fixed_widths(*pFixedWidths); + while (nSourceCount) { // tdf#125241 inserting backwards is massively faster -- cgit