summaryrefslogtreecommitdiff
path: root/sfx2/source/notebookbar/PriorityHBox.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/source/notebookbar/PriorityHBox.cxx')
-rw-r--r--sfx2/source/notebookbar/PriorityHBox.cxx241
1 files changed, 130 insertions, 111 deletions
diff --git a/sfx2/source/notebookbar/PriorityHBox.cxx b/sfx2/source/notebookbar/PriorityHBox.cxx
index 913ef12495fa..83b6288afdcb 100644
--- a/sfx2/source/notebookbar/PriorityHBox.cxx
+++ b/sfx2/source/notebookbar/PriorityHBox.cxx
@@ -22,170 +22,189 @@
#include <sfx2/dllapi.h>
#include <sfx2/viewfrm.hxx>
#include "DropdownBox.hxx"
+#include "PriorityHBox.hxx"
-#include <vector>
+namespace
+{
+ bool lcl_comparePriority(const vcl::IPrioritable* a, const vcl::IPrioritable* b)
+ {
+ return a->GetPriority() < b->GetPriority();
+ }
+}
-bool lcl_comparePriority(const vcl::IPrioritable* a, const vcl::IPrioritable* b)
+PriorityHBox::PriorityHBox(vcl::Window *pParent)
+ : VclHBox(pParent)
+ , m_bInitialized(false)
{
- return a->GetPriority() < b->GetPriority();
}
-/*
- * PriorityHBox is a VclHBox which hides its own children if there is no sufficient space.
- * Hiding order can be modified using child's priorities. If a control have default
- * priority assigned (VCL_PRIORITY_DEFAULT), it is always shown.
- */
+PriorityHBox::~PriorityHBox()
+{
+ disposeOnce();
+}
-class SFX2_DLLPUBLIC PriorityHBox : public VclHBox
+void PriorityHBox::Initialize()
{
-private:
- bool m_bInitialized;
+ m_bInitialized = true;
- std::vector<vcl::IPrioritable*> m_aSortedChilds;
+ GetChildrenWithPriorities();
+ SetSizeFromParent();
+}
-public:
- explicit PriorityHBox(vcl::Window *pParent)
- : VclHBox(pParent)
- , m_bInitialized(false)
- {
- }
+int PriorityHBox::GetHiddenCount() const
+{
+ int nCount = 0;
- virtual ~PriorityHBox() override
- {
- disposeOnce();
- }
+ for (auto pWindow : m_aSortedChildren)
+ if (pWindow->IsHidden())
+ nCount++;
- void Initialize()
- {
- m_bInitialized = true;
+ return nCount;
+}
- GetChildrenWithPriorities();
- SetSizeFromParent();
+void PriorityHBox::SetSizeFromParent()
+{
+ vcl::Window* pParent = GetParent();
+ if (pParent)
+ {
+ Size aParentSize = pParent->GetSizePixel();
+ SetSizePixel(Size(aParentSize.getWidth(), aParentSize.getHeight()));
}
+}
- void SetSizeFromParent()
+Size PriorityHBox::calculateRequisition() const
+{
+ if (!m_bInitialized)
{
- vcl::Window* pParent = GetParent();
- if (pParent)
- {
- Size aParentSize = pParent->GetSizePixel();
- SetSizePixel(Size(aParentSize.getWidth(), aParentSize.getHeight()));
- }
+ return VclHBox::calculateRequisition();
}
- virtual Size calculateRequisition() const override
+ sal_uInt16 nVisibleChildren = 0;
+
+ Size aSize;
+ for (vcl::Window *pChild = GetWindow(GetWindowType::FirstChild); pChild; pChild = pChild->GetWindow(GetWindowType::Next))
{
- if (!m_bInitialized)
- {
- return VclHBox::calculateRequisition();
- }
+ if (!pChild->IsVisible())
+ continue;
+ ++nVisibleChildren;
+ Size aChildSize = getLayoutRequisition(*pChild);
- sal_uInt16 nVisibleChildren = 0;
+ bool bAllwaysExpanded = true;
- Size aSize;
- for (vcl::Window *pChild = GetWindow(GetWindowType::FirstChild); pChild; pChild = pChild->GetWindow(GetWindowType::Next))
- {
- if (!pChild->IsVisible())
- continue;
- ++nVisibleChildren;
- Size aChildSize = getLayoutRequisition(*pChild);
+ vcl::IPrioritable* pPrioritable = dynamic_cast<vcl::IPrioritable*>(pChild);
+ if (pPrioritable && pPrioritable->GetPriority() != VCL_PRIORITY_DEFAULT)
+ bAllwaysExpanded = false;
- bool bAllwaysExpanded = true;
+ if (bAllwaysExpanded)
+ {
+ long nPrimaryDimension = getPrimaryDimension(aChildSize);
+ nPrimaryDimension += pChild->get_padding() * 2;
+ setPrimaryDimension(aChildSize, nPrimaryDimension);
+ }
+ else
+ setPrimaryDimension(aChildSize, 0);
- vcl::IPrioritable* pPrioritable = dynamic_cast<vcl::IPrioritable*>(pChild);
- if (pPrioritable && pPrioritable->GetPriority() != VCL_PRIORITY_DEFAULT)
- bAllwaysExpanded = false;
+ accumulateMaxes(aChildSize, aSize);
+ }
- if (bAllwaysExpanded)
- {
- long nPrimaryDimension = getPrimaryDimension(aChildSize);
- nPrimaryDimension += pChild->get_padding() * 2;
- setPrimaryDimension(aChildSize, nPrimaryDimension);
- }
- else
- setPrimaryDimension(aChildSize, 0);
+ return finalizeMaxes(aSize, nVisibleChildren);
+}
- accumulateMaxes(aChildSize, aSize);
- }
+void PriorityHBox::Resize()
+{
+ if (!m_bInitialized && SfxViewFrame::Current())
+ Initialize();
- return finalizeMaxes(aSize, nVisibleChildren);
+ if (!m_bInitialized)
+ {
+ return VclHBox::Resize();
}
- virtual void Resize() override
+ long nWidth = GetSizePixel().Width();
+ long nCurrentWidth = VclHBox::calculateRequisition().getWidth();
+
+ // Hide lower priority controls
+ auto pChild = m_aSortedChildren.begin();
+ while (nCurrentWidth > nWidth && pChild != m_aSortedChildren.end())
{
- if (!m_bInitialized && SfxViewFrame::Current())
- Initialize();
+ vcl::Window* pWindow = dynamic_cast<vcl::Window*>(*pChild);
+ vcl::IPrioritable* pPrioritable = *pChild;
- if (!m_bInitialized)
+ if(pWindow->GetParent() != this)
{
- return VclHBox::Resize();
+ pChild++;
+ continue;
}
- long nWidth = GetSizePixel().Width();
- long nCurrentWidth = VclHBox::calculateRequisition().getWidth();
-
- // Hide lower priority controls
- auto pChild = m_aSortedChilds.begin();
- while (nCurrentWidth > nWidth && pChild != m_aSortedChilds.end())
+ if (pWindow)
{
- // ATM DropdownBox is the only one derived class from IPrioritable
- DropdownBox* pDropdownBox = static_cast<DropdownBox*>(*pChild);
+ nCurrentWidth -= pWindow->GetOutputWidthPixel() + get_spacing();
+ pWindow->Show();
+ pPrioritable->HideContent();
+ nCurrentWidth += pWindow->GetOutputWidthPixel() + get_spacing();
+ }
- nCurrentWidth -= pDropdownBox->GetOutputWidthPixel() + get_spacing();
- pDropdownBox->HideContent();
- nCurrentWidth += pDropdownBox->GetOutputWidthPixel() + get_spacing();
+ pChild++;
+ }
- pChild++;
- }
+ auto pChildR = m_aSortedChildren.rbegin();
+ // Show higher priority controls if we already have enough space
+ while (pChildR != m_aSortedChildren.rend())
+ {
+ vcl::Window* pWindow = dynamic_cast<vcl::Window*>(*pChildR);
+ vcl::IPrioritable* pPrioritable = *pChildR;
- auto pChildR = m_aSortedChilds.rbegin();
- // Show higher priority controls if we already have enough space
- while (pChildR != m_aSortedChilds.rend())
+ if(pWindow->GetParent() != this)
{
- DropdownBox* pBox = static_cast<DropdownBox*>(*pChildR);
+ pChildR++;
+ continue;
+ }
- nCurrentWidth -= pBox->GetOutputWidthPixel() + get_spacing();
- pBox->ShowContent();
- nCurrentWidth += getLayoutRequisition(*pBox).Width() + get_spacing();
+ if (pWindow)
+ {
+ nCurrentWidth -= pWindow->GetOutputWidthPixel() + get_spacing();
+ pWindow->Show();
+ pPrioritable->ShowContent();
+ nCurrentWidth += getLayoutRequisition(*pWindow).Width() + get_spacing();
if (nCurrentWidth > nWidth)
{
- pBox->HideContent();
+ pPrioritable->HideContent();
break;
}
-
- pChildR++;
}
- VclHBox::Resize();
+ pChildR++;
}
- virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override
- {
- if (!m_bInitialized && SfxViewFrame::Current())
- Initialize();
+ VclHBox::Resize();
+}
- VclHBox::Paint(rRenderContext, rRect);
- }
+void PriorityHBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
+{
+ if (!m_bInitialized && SfxViewFrame::Current())
+ Initialize();
- void GetChildrenWithPriorities()
+ VclHBox::Paint(rRenderContext, rRect);
+}
+
+void PriorityHBox::GetChildrenWithPriorities()
+{
+ for (sal_uInt16 i = 0; i < GetChildCount(); ++i)
{
- for (sal_uInt16 i = 0; i < GetChildCount(); ++i)
- {
- vcl::Window* pChild = GetChild(i);
+ vcl::Window* pChild = GetChild(i);
- // Add only containers which have explicitly assigned priority.
- vcl::IPrioritable* pPrioritable = dynamic_cast<vcl::IPrioritable*>(pChild);
- if (pPrioritable && pPrioritable->GetPriority() != VCL_PRIORITY_DEFAULT)
- m_aSortedChilds.push_back(pPrioritable);
- }
+ // Add only containers which have explicitly assigned priority.
+ vcl::IPrioritable* pPrioritable = dynamic_cast<vcl::IPrioritable*>(pChild);
+ if (pPrioritable && pPrioritable->GetPriority() != VCL_PRIORITY_DEFAULT)
+ m_aSortedChildren.push_back(pPrioritable);
+ }
- if (!m_aSortedChilds.size())
- m_bInitialized = false;
+ if (!m_aSortedChildren.size())
+ m_bInitialized = false;
- std::sort(m_aSortedChilds.begin(), m_aSortedChilds.end(), lcl_comparePriority);
- }
-};
+ std::sort(m_aSortedChildren.begin(), m_aSortedChildren.end(), lcl_comparePriority);
+}
VCL_BUILDER_FACTORY(PriorityHBox)