[Libreoffice-commits] core.git: include/vcl svtools/source vcl/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon May 20 19:45:13 UTC 2019


 include/vcl/svlbitm.hxx             |    2 ++
 include/vcl/treelistbox.hxx         |    3 ++-
 include/vcl/viewdataentry.hxx       |    2 ++
 svtools/source/contnr/iconview.cxx  |    5 ++---
 vcl/source/treelist/svlbitm.cxx     |    7 ++++++-
 vcl/source/treelist/treelistbox.cxx |   25 +++++++++++++++++++++----
 6 files changed, 35 insertions(+), 9 deletions(-)

New commits:
commit 5c8de864f72c4e077b7be5871a2e51f02f69c0e9
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon May 20 11:05:46 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon May 20 21:44:12 2019 +0200

    calc item width on request
    
    Change-Id: Ifa56a903b3c3a3962fd2ecf76ff101976e17fc05
    Reviewed-on: https://gerrit.libreoffice.org/72600
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/svlbitm.hxx b/include/vcl/svlbitm.hxx
index 16665dd8c73e..8d267e0754af 100644
--- a/include/vcl/svlbitm.hxx
+++ b/include/vcl/svlbitm.hxx
@@ -119,6 +119,8 @@ public:
                               SvTreeListEntry* pEntry,
                               SvViewDataItem* pViewData = nullptr) override;
 
+    virtual int CalcWidth(const SvTreeListBox* pView) const override;
+
     void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; }
     bool IsEmphasized() const { return mbEmphasized; }
 
diff --git a/include/vcl/treelistbox.hxx b/include/vcl/treelistbox.hxx
index d9c09d086b31..4cfd06a37937 100644
--- a/include/vcl/treelistbox.hxx
+++ b/include/vcl/treelistbox.hxx
@@ -140,9 +140,10 @@ public:
                         SvLBoxItem();
     virtual             ~SvLBoxItem();
     virtual SvLBoxItemType GetType() const = 0;
+    virtual int CalcWidth(const SvTreeListBox* pView) const;
     int GetWidth(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const;
+    int GetWidth(const SvTreeListBox* pView, const SvViewDataEntry* pData, sal_uInt16 nItemPos);
     int GetHeight(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const;
-    static int GetWidth(const SvViewDataEntry* pData, sal_uInt16 nItemPos);
     static int GetHeight(const SvViewDataEntry* pData, sal_uInt16 nItemPos);
     void Enable(bool bEnabled) { mbDisabled = !bEnabled; }
 
diff --git a/include/vcl/viewdataentry.hxx b/include/vcl/viewdataentry.hxx
index 7967f131b6c6..74d7d22b98de 100644
--- a/include/vcl/viewdataentry.hxx
+++ b/include/vcl/viewdataentry.hxx
@@ -26,6 +26,8 @@
 
 #include <vector>
 
+class SvTreeListBox;
+
 struct SvViewDataItem
 {
     int mnWidth = 0;
diff --git a/svtools/source/contnr/iconview.cxx b/svtools/source/contnr/iconview.cxx
index 7138efdbddeb..4f94a21b87cf 100644
--- a/svtools/source/contnr/iconview.cxx
+++ b/svtools/source/contnr/iconview.cxx
@@ -206,7 +206,8 @@ void IconView::PaintEntry(SvTreeListEntry& rEntry, long nX, long nY,
     // draw icon
     if(nIconItem != nItemCount && nIconItem < nItemCount)
     {
-        auto nItemWidth = SvLBoxItem::GetWidth(pViewDataEntry, nIconItem);
+        SvLBoxItem* pItem = &rEntry.GetItem(nIconItem);
+        auto nItemWidth = pItem->GetWidth(this, pViewDataEntry, nIconItem);
         auto nItemHeight = SvLBoxItem::GetHeight(pViewDataEntry, nIconItem);
 
         aEntryPos.setX( nX );
@@ -219,8 +220,6 @@ void IconView::PaintEntry(SvTreeListEntry& rEntry, long nX, long nY,
 
         aEntryPos.AdjustY( -10 );
 
-        SvLBoxItem* pItem = &rEntry.GetItem(nIconItem);
-
         pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
     }
 
diff --git a/vcl/source/treelist/svlbitm.cxx b/vcl/source/treelist/svlbitm.cxx
index 764c8d6878df..56b4f016d9e9 100644
--- a/vcl/source/treelist/svlbitm.cxx
+++ b/vcl/source/treelist/svlbitm.cxx
@@ -244,13 +244,18 @@ void SvLBoxString::InitViewData(
         pView->Control::SetFont( aFont );
     }
 
-    pViewData->mnWidth = pView->GetTextWidth(maText);
+    pViewData->mnWidth = -1; // calc on demand
     pViewData->mnHeight = pView->GetTextHeight();
 
     if (mbEmphasized)
         pView->Pop();
 }
 
+int SvLBoxString::CalcWidth(const SvTreeListBox* pView) const
+{
+    return pView->GetTextWidth(maText);
+}
+
 // ***************************************************************
 // class SvLBoxButton
 // ***************************************************************
diff --git a/vcl/source/treelist/treelistbox.cxx b/vcl/source/treelist/treelistbox.cxx
index de328f8dde39..f42aac4983af 100644
--- a/vcl/source/treelist/treelistbox.cxx
+++ b/vcl/source/treelist/treelistbox.cxx
@@ -306,7 +306,13 @@ SvLBoxItem::~SvLBoxItem()
 int SvLBoxItem::GetWidth(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const
 {
     const SvViewDataItem* pViewData = pView->GetViewDataItem( pEntry, this );
-    return pViewData->mnWidth;
+    int nWidth = pViewData->mnWidth;
+    if (nWidth == -1)
+    {
+        nWidth = CalcWidth(pView);
+        const_cast<SvViewDataItem*>(pViewData)->mnWidth = nWidth;
+    }
+    return nWidth;
 }
 
 int SvLBoxItem::GetHeight(const SvTreeListBox* pView, const SvTreeListEntry* pEntry) const
@@ -315,10 +321,16 @@ int SvLBoxItem::GetHeight(const SvTreeListBox* pView, const SvTreeListEntry* pEn
     return pViewData->mnHeight;
 }
 
-int SvLBoxItem::GetWidth(const SvViewDataEntry* pData, sal_uInt16 nItemPos)
+int SvLBoxItem::GetWidth(const SvTreeListBox* pView, const SvViewDataEntry* pData, sal_uInt16 nItemPos)
 {
     const SvViewDataItem& rIData = pData->GetItem(nItemPos);
-    return rIData.mnWidth;
+    int nWidth = rIData.mnWidth;
+    if (nWidth == -1)
+    {
+        nWidth = CalcWidth(pView);
+        const_cast<SvViewDataItem&>(rIData).mnWidth = nWidth;
+    }
+    return nWidth;
 }
 
 int SvLBoxItem::GetHeight(const SvViewDataEntry* pData, sal_uInt16 nItemPos)
@@ -327,6 +339,11 @@ int SvLBoxItem::GetHeight(const SvViewDataEntry* pData, sal_uInt16 nItemPos)
     return rIData.mnHeight;
 }
 
+int SvLBoxItem::CalcWidth(const SvTreeListBox* /*pView*/) const
+{
+    return 0;
+}
+
 struct SvTreeListBoxImpl
 {
     bool m_bIsEmptyTextAllowed:1;
@@ -2645,7 +2662,7 @@ void SvTreeListBox::PaintEntry1(SvTreeListEntry& rEntry, long nLine, vcl::Render
         SvLBoxItem& rItem = rEntry.GetItem(nCurItem);
 
         SvLBoxTabFlags nFlags = pTab->nFlags;
-        Size aSize(SvLBoxItem::GetWidth(pViewDataEntry, nCurItem),
+        Size aSize(rItem.GetWidth(this, pViewDataEntry, nCurItem),
                    SvLBoxItem::GetHeight(pViewDataEntry, nCurItem));
         long nTabPos = GetTabPos(&rEntry, pTab);
 


More information about the Libreoffice-commits mailing list