summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2020-06-03 15:26:50 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2020-06-09 19:02:25 +0200
commit53d73d532281b6734a7d4614bb74fc6cc15510f0 (patch)
tree9867965d96f478f87de686ef1456f89691ac239a /sfx2
parent362b949a3bd907d6cb1ed94ef415696c88d838a8 (diff)
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@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/notebookbar/PriorityHBox.hxx9
-rw-r--r--sfx2/source/notebookbar/PriorityMergedHBox.cxx109
2 files changed, 108 insertions, 10 deletions
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