diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-01-20 20:10:23 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-01-21 13:55:26 +0100 |
commit | b4b6daf8b70a5448d3e7aea440d56d95e19e7d2d (patch) | |
tree | 42214283987042a1ff296cf70d57c325b1ee041c /svx | |
parent | 1eaa1e2adeb50bb14d550e70fb77edfd2da11807 (diff) |
make gallery listview seem faster to populate
Change-Id: I25b692c9594d73be9d81ff12df6b61a44c5a8256
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87107
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/inc/galbrws2.hxx | 4 | ||||
-rw-r--r-- | svx/source/gallery2/galbrws2.cxx | 64 |
2 files changed, 46 insertions, 22 deletions
diff --git a/svx/inc/galbrws2.hxx b/svx/inc/galbrws2.hxx index 6b25012b6af4..a1e7732e1270 100644 --- a/svx/inc/galbrws2.hxx +++ b/svx/inc/galbrws2.hxx @@ -88,6 +88,8 @@ private: std::unique_ptr<weld::ToggleButton> mxIconButton; std::unique_ptr<weld::ToggleButton> mxListButton; std::unique_ptr<weld::Label> mxInfoBar; + VclPtr<VirtualDevice> mxDev; + Size maPreviewSize; rtl::Reference<GalleryTransferable> m_xHelper; sal_uInt32 mnCurActionPos; GalleryBrowserMode meMode; @@ -101,7 +103,7 @@ private: sal_uInt32 ImplGetSelectedItemId( const Point* pSelPosPixel, Point& rSelPos ); void ImplSelectItemId(sal_uInt32 nItemId); void ImplUpdateSelection(); - void UpdateVisibleRows(); + void UpdateRows(bool bVisibleOnly); // SfxListener virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; diff --git a/svx/source/gallery2/galbrws2.cxx b/svx/source/gallery2/galbrws2.cxx index d973a43596a9..2c477e0b1c9b 100644 --- a/svx/source/gallery2/galbrws2.cxx +++ b/svx/source/gallery2/galbrws2.cxx @@ -351,10 +351,14 @@ GalleryBrowser2::GalleryBrowser2(weld::Builder& rBuilder, Gallery* pGallery) , mxIconButton(rBuilder.weld_toggle_button("icon")) , mxListButton(rBuilder.weld_toggle_button("list")) , mxInfoBar(rBuilder.weld_label("label")) + , mxDev(mxListView->create_virtual_device()) + , maPreviewSize(28, 28) , mnCurActionPos ( 0xffffffff ) , meMode ( GALLERYBROWSERMODE_NONE ) , meLastMode ( GALLERYBROWSERMODE_NONE ) { + mxDev->SetOutputSizePixel(maPreviewSize); + m_xContext.set( ::comphelper::getProcessComponentContext() ); int nHeight = mxListView->get_height_rows(10); @@ -668,7 +672,7 @@ void GalleryBrowser2::SetMode( GalleryBrowserMode eMode ) GalleryPreview::PreviewMedia( INetURLObject() ); mxListView->show(); - UpdateVisibleRows(); + UpdateRows(true); mxIconButton->set_sensitive(true); mxListButton->set_sensitive(true); @@ -791,13 +795,26 @@ void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId ) if( mpCurTheme ) { + const int nAlwaysUpToDate = 15; + + mxListView->freeze(); + OUString sCreateOnDemand; - for (sal_uInt32 i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount; ++i) + sal_uInt32 nCount = mpCurTheme->GetObjectCount(); + for (sal_uInt32 i = 0; i < nCount; ++i) { mxIconView->InsertItem(i + 1); // skip reserved id 0 mxListView->append(OUString::number(i), sCreateOnDemand); // create on-demand in VisRowsScrolledHdl + + if (i == nAlwaysUpToDate) // fill in the first block + UpdateRows(false); } + if (nCount < nAlwaysUpToDate) // if less than block size, fill in all of them + UpdateRows(false); + + mxListView->thaw(); + ImplSelectItemId( std::min<sal_uInt16>( nSelectionId, mpCurTheme->GetObjectCount() ) ); } @@ -806,7 +823,7 @@ void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId ) case GALLERYBROWSERMODE_ICON: mxIconView->Show(); break; case GALLERYBROWSERMODE_LIST: mxListView->show(); - UpdateVisibleRows(); + UpdateRows(true); break; case GALLERYBROWSERMODE_PREVIEW: mxPreview->Show(); break; @@ -817,7 +834,7 @@ void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId ) ImplUpdateInfoBar(); } -void GalleryBrowser2::UpdateVisibleRows() +void GalleryBrowser2::UpdateRows(bool bVisibleOnly) { auto lambda = [this](weld::TreeIter& rEntry){ // id is non-null if the preview is pending creation @@ -826,9 +843,6 @@ void GalleryBrowser2::UpdateVisibleRows() return false; // get the icon for the listview - VclPtr<VirtualDevice> xDev = mxListView->create_virtual_device(); - const Size aSize(28, 28); - xDev->SetOutputSizePixel(aSize); BitmapEx aBitmapEx; Size aPreparedSize; @@ -839,7 +853,7 @@ void GalleryBrowser2::UpdateVisibleRows() mpCurTheme->GetPreviewBitmapExAndStrings(i, aBitmapEx, aPreparedSize, sItemTextTitle, sItemTextPath); bool bNeedToCreate(aBitmapEx.IsEmpty()); - if (!bNeedToCreate && (sItemTextTitle.isEmpty() || aPreparedSize != aSize)) + if (!bNeedToCreate && (sItemTextTitle.isEmpty() || aPreparedSize != maPreviewSize)) bNeedToCreate = true; if (bNeedToCreate) @@ -847,11 +861,11 @@ void GalleryBrowser2::UpdateVisibleRows() std::unique_ptr<SgaObject> xObj = mpCurTheme->AcquireObject(i); if (xObj) { - aBitmapEx = xObj->createPreviewBitmapEx(aSize); + aBitmapEx = xObj->createPreviewBitmapEx(maPreviewSize); sItemTextTitle = GalleryBrowser2::GetItemText(*xObj, GalleryItemFlags::Title); sItemTextPath = GalleryBrowser2::GetItemText(*xObj, GalleryItemFlags::Path); - mpCurTheme->SetPreviewBitmapExAndStrings(i, aBitmapEx, aSize, sItemTextTitle, sItemTextPath); + mpCurTheme->SetPreviewBitmapExAndStrings(i, aBitmapEx, maPreviewSize, sItemTextTitle, sItemTextPath); } } @@ -859,39 +873,47 @@ void GalleryBrowser2::UpdateVisibleRows() { const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel()); const Point aPos( - ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1), - ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1)); + ((maPreviewSize.Width() - aBitmapExSizePixel.Width()) >> 1), + ((maPreviewSize.Height() - aBitmapExSizePixel.Height()) >> 1)); + + mxDev->Erase(); if (aBitmapEx.IsTransparent()) { // draw checkered background - GalleryIconView::drawTransparenceBackground(*xDev, aPos, aBitmapExSizePixel); + GalleryIconView::drawTransparenceBackground(*mxDev, aPos, aBitmapExSizePixel); } - xDev->DrawBitmapEx(aPos, aBitmapEx); + mxDev->DrawBitmapEx(aPos, aBitmapEx); } mxListView->set_text(rEntry, sItemTextTitle); - mxListView->set_image(rEntry, *xDev); + mxListView->set_image(rEntry, *mxDev); mxListView->set_id(rEntry, OUString()); return false; }; - // ensure all visible entries are up to date - mxListView->visible_foreach(lambda); - // and ensure all selected entries are up to date - mxListView->selected_foreach(lambda); + if (bVisibleOnly) + { + // ensure all visible entries are up to date + mxListView->visible_foreach(lambda); + // and ensure all selected entries are up to date + mxListView->selected_foreach(lambda); + return; + } + + mxListView->all_foreach(lambda); } IMPL_LINK_NOARG(GalleryBrowser2, VisRowsScrolledHdl, weld::TreeView&, void) { - UpdateVisibleRows(); + UpdateRows(true); } IMPL_LINK_NOARG(GalleryBrowser2, SizeAllocHdl, const Size&, void) { - UpdateVisibleRows(); + UpdateRows(true); } void GalleryBrowser2::ImplUpdateInfoBar() |