diff options
author | Szymon Kłos <eszkadev@gmail.com> | 2017-02-14 12:08:03 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2017-02-24 08:58:58 +0000 |
commit | 3422dfc1b61c15d7d3a6b0e1ee16c50457946cc0 (patch) | |
tree | f9859409ebf5efa62d1d360922fbc42d5857d47a /sfx2/source/notebookbar/PriorityHBox.cxx | |
parent | c2a9e9abdc3df4a9e5bf5e3fc43a73d5847996ac (diff) |
Notebookbar: Better resize support
Change-Id: I0bb5a5600be60a68e53132f2c3c42f79c958b2b3
Reviewed-on: https://gerrit.libreoffice.org/34491
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2/source/notebookbar/PriorityHBox.cxx')
-rw-r--r-- | sfx2/source/notebookbar/PriorityHBox.cxx | 96 |
1 files changed, 54 insertions, 42 deletions
diff --git a/sfx2/source/notebookbar/PriorityHBox.cxx b/sfx2/source/notebookbar/PriorityHBox.cxx index c1f60ac26374..91d9fb877e87 100644 --- a/sfx2/source/notebookbar/PriorityHBox.cxx +++ b/sfx2/source/notebookbar/PriorityHBox.cxx @@ -40,9 +40,6 @@ class SFX2_DLLPUBLIC PriorityHBox : public VclHBox { private: bool m_bInitialized; - long m_nNeededWidth; - - ScopedVclPtr<SystemWindow> m_pSystemWindow; std::vector<IPrioritable*> m_aSortedChilds; @@ -50,7 +47,6 @@ public: explicit PriorityHBox(vcl::Window *pParent) : VclHBox(pParent) , m_bInitialized(false) - , m_nNeededWidth(0) { } @@ -59,36 +55,73 @@ public: disposeOnce(); } - virtual void dispose() override + virtual Size calculateRequisition() const override { - if (m_pSystemWindow) + sal_uInt16 nVisibleChildren = 0; + + Size aSize; + for (vcl::Window *pChild = GetWindow(GetWindowType::FirstChild); pChild; pChild = pChild->GetWindow(GetWindowType::Next)) { - m_pSystemWindow->RemoveEventListener(LINK(this, PriorityHBox, WindowEventListener)); - m_pSystemWindow.clear(); + if (!pChild->IsVisible()) + continue; + ++nVisibleChildren; + Size aChildSize = getLayoutRequisition(*pChild); + + bool bAllwaysExpanded = true; + + IPrioritable* pPrioritable = pChild->GetType() == WindowType::CONTAINER ? + dynamic_cast<IPrioritable*>(pChild) : nullptr; + if (pPrioritable && pPrioritable->GetPriority() != VCL_PRIORITY_DEFAULT) + bAllwaysExpanded = false; + + if (bAllwaysExpanded) + { + long nPrimaryDimension = getPrimaryDimension(aChildSize); + nPrimaryDimension += pChild->get_padding() * 2; + setPrimaryDimension(aChildSize, nPrimaryDimension); + } + else + setPrimaryDimension(aChildSize, 0); + + accumulateMaxes(aChildSize, aSize); } - VclHBox::dispose(); + + return finalizeMaxes(aSize, nVisibleChildren); } virtual void Resize() override { long nWidth = GetSizePixel().Width(); - long nCurrentWidth = m_nNeededWidth; + long nCurrentWidth = VclHBox::calculateRequisition().getWidth(); // Hide lower priority controls auto pChild = m_aSortedChilds.begin(); while (nCurrentWidth > nWidth && pChild != m_aSortedChilds.end()) { - DropdownBox* pContainer = static_cast<DropdownBox*>(*pChild); - nCurrentWidth -= pContainer->GetSizePixel().Width() + get_spacing(); - pContainer->HideContent(); - nCurrentWidth += pContainer->GetSizePixel().Width() + get_spacing(); + DropdownBox* pBox = static_cast<DropdownBox*>(*pChild); + + nCurrentWidth -= pBox->GetOutputWidthPixel() + get_spacing(); + pBox->HideContent(); + nCurrentWidth += pBox->GetOutputWidthPixel() + get_spacing(); + pChild++; } // Show higher priority controls if we already have enough space while (pChild != m_aSortedChilds.end()) { - static_cast<DropdownBox*>(*pChild)->ShowContent(); + DropdownBox* pBox = static_cast<DropdownBox*>(*pChild); + + nCurrentWidth -= pBox->GetOutputWidthPixel() + get_spacing(); + pBox->ShowContent(); + nCurrentWidth += getLayoutRequisition(*pBox).Width() + get_spacing(); + + if (nCurrentWidth > nWidth) + { + pBox->HideContent(); + break; + } + pChild++; } @@ -101,14 +134,12 @@ public: { m_bInitialized = true; - m_pSystemWindow = SfxViewFrame::Current()->GetFrame().GetSystemWindow(); - if (m_pSystemWindow) - { - m_pSystemWindow->AddEventListener(LINK(this, PriorityHBox, WindowEventListener)); - - CalcNeededWidth(); + GetChildrenWithPriorities(); - long nWidth = m_pSystemWindow->GetSizePixel().Width(); + SystemWindow* pSystemWindow = SfxViewFrame::Current()->GetFrame().GetSystemWindow(); + if (pSystemWindow) + { + long nWidth = pSystemWindow->GetSizePixel().Width(); SetSizePixel(Size(nWidth, GetSizePixel().Height())); } } @@ -116,14 +147,11 @@ public: VclHBox::Paint(rRenderContext, rRect); } - void CalcNeededWidth() + void GetChildrenWithPriorities() { - int spacing = get_spacing(); - for (sal_uInt16 i = 0; i < GetChildCount(); ++i) { vcl::Window* pChild = GetChild(i); - m_nNeededWidth += pChild->GetSizePixel().Width() + spacing; // Add only containers which have explicitly assigned priority. IPrioritable* pPrioritable = pChild->GetType() == WindowType::CONTAINER ? @@ -134,24 +162,8 @@ public: std::sort(m_aSortedChilds.begin(), m_aSortedChilds.end(), lcl_comparePriority); } - -private: - DECL_LINK( WindowEventListener, VclWindowEvent&, void ); }; -IMPL_LINK( PriorityHBox, WindowEventListener, VclWindowEvent&, rEvent, void ) -{ - if (rEvent.GetId() == VclEventId::WindowResize) - { - vcl::Window* pEventWindow = rEvent.GetWindow(); - - OSL_ENSURE(pEventWindow, "PriorityHBox::WindowEventListener: no window!"); - - long nWidth = pEventWindow->GetSizePixel().Width(); - SetSizePixel(Size(nWidth, GetSizePixel().Height())); - } -} - VCL_BUILDER_FACTORY(PriorityHBox) /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |