[Libreoffice-commits] core.git: sfx2/source

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 9 17:03:03 UTC 2020


 sfx2/source/notebookbar/PriorityHBox.hxx       |    9 --
 sfx2/source/notebookbar/PriorityMergedHBox.cxx |  109 +++++++++++++++++++++++--
 2 files changed, 108 insertions(+), 10 deletions(-)

New commits:
commit 53d73d532281b6734a7d4614bb74fc6cc15510f0
Author:     Szymon Kłos <eszkadev at gmail.com>
AuthorDate: Wed Jun 3 15:26:50 2020 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Jun 9 19:02:25 2020 +0200

    notebookbar: simplify custom widgets
    
    Change-Id: I0176a9852a0f405fba7b6308e28abf2ca0ae280e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95900
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/sfx2/source/notebookbar/PriorityHBox.hxx b/sfx2/source/notebookbar/PriorityHBox.hxx
index 04b884ddffdf..7e797327642e 100644
--- a/sfx2/source/notebookbar/PriorityHBox.hxx
+++ b/sfx2/source/notebookbar/PriorityHBox.hxx
@@ -33,13 +33,14 @@
 
 class PriorityHBox : public VclHBox
 {
-private:
+protected:
     bool m_bInitialized;
 
     std::vector<vcl::IPrioritable*> m_aSortedChildren;
 
-protected:
-    int GetHiddenCount() const;
+    virtual int GetHiddenCount() const;
+
+    virtual void GetChildrenWithPriorities();
 
 public:
     explicit PriorityHBox(vcl::Window* pParent);
@@ -55,8 +56,6 @@ public:
     virtual void Resize() override;
 
     virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
-
-    void GetChildrenWithPriorities();
 };
 
 #endif
diff --git a/sfx2/source/notebookbar/PriorityMergedHBox.cxx b/sfx2/source/notebookbar/PriorityMergedHBox.cxx
index 8a5bcd014c4d..bd7fd55b176f 100644
--- a/sfx2/source/notebookbar/PriorityMergedHBox.cxx
+++ b/sfx2/source/notebookbar/PriorityMergedHBox.cxx
@@ -23,6 +23,10 @@
 #include <bitmaps.hlst>
 #include "PriorityHBox.hxx"
 #include "NotebookbarPopup.hxx"
+#include <sfx2/viewfrm.hxx>
+
+#define DUMMY_WIDTH 50
+#define BUTTON_WIDTH 30
 
 /*
 * PriorityMergedHBox is a VclHBox which hides its own children if there is no sufficient space.
@@ -54,7 +58,60 @@ public:
 
     virtual void Resize() override
     {
-        PriorityHBox::Resize();
+        if (!m_bInitialized && SfxViewFrame::Current())
+            Initialize();
+
+        if (!m_bInitialized)
+        {
+            return VclHBox::Resize();
+        }
+
+        long nWidth = GetSizePixel().Width();
+        long nCurrentWidth = VclHBox::calculateRequisition().getWidth() + BUTTON_WIDTH;
+
+        // Hide lower priority controls
+        for (int i = GetChildCount() - 1; i >= 0; i--)
+        {
+            vcl::Window* pWindow = GetChild(i);
+
+            if (nCurrentWidth <= nWidth)
+                break;
+
+            if (pWindow && pWindow->GetParent() == this && pWindow->IsVisible())
+            {
+                if (pWindow->GetOutputWidthPixel())
+                    nCurrentWidth -= pWindow->GetOutputWidthPixel();
+                else
+                    nCurrentWidth -= DUMMY_WIDTH;
+                pWindow->Hide();
+            }
+        }
+
+        // Show higher priority controls if we already have enough space
+        for (int i = 0; i < GetChildCount(); i++)
+        {
+            vcl::Window* pWindow = GetChild(i);
+
+            if (pWindow->GetParent() != this)
+            {
+                continue;
+            }
+
+            if (pWindow && !pWindow->IsVisible())
+            {
+                pWindow->Show();
+                nCurrentWidth += getLayoutRequisition(*pWindow).Width() + get_spacing();
+
+                if (nCurrentWidth > nWidth)
+                {
+                    pWindow->Hide();
+                    break;
+                }
+            }
+        }
+
+        VclHBox::Resize();
+
         if (GetHiddenCount())
             m_pButton->Show();
         else
@@ -68,6 +125,51 @@ public:
             m_pPopup.disposeAndClear();
         PriorityHBox::dispose();
     }
+
+    int GetHiddenCount() const override
+    {
+        int nCount = 0;
+
+        for (int i = GetChildCount() - 1; i >= 0; i--)
+        {
+            vcl::Window* pWindow = GetChild(i);
+            if (pWindow && pWindow->GetParent() == this && !pWindow->IsVisible())
+                nCount++;
+        }
+
+        return nCount;
+    }
+
+    Size calculateRequisition() const override
+    {
+        if (!m_bInitialized)
+        {
+            return VclHBox::calculateRequisition();
+        }
+
+        sal_uInt16 nVisibleChildren = 0;
+
+        Size aSize;
+        for (vcl::Window* pChild = GetWindow(GetWindowType::FirstChild); pChild;
+             pChild = pChild->GetWindow(GetWindowType::Next))
+        {
+            if (!pChild->IsVisible())
+                continue;
+            ++nVisibleChildren;
+            Size aChildSize = getLayoutRequisition(*pChild);
+
+            long nPrimaryDimension = getPrimaryDimension(aChildSize);
+            nPrimaryDimension += pChild->get_padding() * 2;
+            setPrimaryDimension(aChildSize, nPrimaryDimension);
+
+            accumulateMaxes(aChildSize, aSize);
+        }
+
+        setPrimaryDimension(aSize, 200);
+        return finalizeMaxes(aSize, nVisibleChildren);
+    }
+
+    void GetChildrenWithPriorities() override{};
 };
 }
 
@@ -83,11 +185,8 @@ IMPL_LINK(PriorityMergedHBox, PBClickHdl, Button*, /*pButton*/, void)
         vcl::Window* pWindow = GetChild(i);
         if (pWindow != m_pButton)
         {
-            vcl::IPrioritable* pChild = dynamic_cast<vcl::IPrioritable*>(pWindow);
-
-            if (pChild && pChild->IsHidden())
+            if (!pWindow->IsVisible())
             {
-                pChild->ShowContent();
                 pWindow->Show();
                 pWindow->SetParent(m_pPopup->getBox());
                 // count is decreased because we moved child


More information about the Libreoffice-commits mailing list