include/vcl/notebookbar.hxx | 1 sfx2/source/notebookbar/PriorityHBox.cxx | 96 ++++++----- sw/uiconfig/swriter/ui/notebookbar.ui | 269 +++++++++++++++++++------------ vcl/source/control/notebookbar.cxx | 15 + vcl/source/control/tabctrl.cxx | 6 5 files changed, 241 insertions(+), 146 deletions(-)
New commits: commit 3422dfc1b61c15d7d3a6b0e1ee16c50457946cc0 Author: Szymon KÅos <[email protected]> Date: Tue Feb 14 12:08:03 2017 +0100 Notebookbar: Better resize support Change-Id: I0bb5a5600be60a68e53132f2c3c42f79c958b2b3 Reviewed-on: https://gerrit.libreoffice.org/34491 Tested-by: Jenkins <[email protected]> Reviewed-by: Samuel Mehrbrodt <[email protected]> diff --git a/include/vcl/notebookbar.hxx b/include/vcl/notebookbar.hxx index cf01dc6..9a41152 100644 --- a/include/vcl/notebookbar.hxx +++ b/include/vcl/notebookbar.hxx @@ -30,6 +30,7 @@ public: virtual bool PreNotify( NotifyEvent& rNEvt ) override; virtual Size GetOptimalSize() const SAL_OVERRIDE; virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags = PosSizeFlags::All) SAL_OVERRIDE; + virtual void Resize() override; void SetIconClickHdl(Link<NotebookBar*, void> aHdl); diff --git a/sfx2/source/notebookbar/PriorityHBox.cxx b/sfx2/source/notebookbar/PriorityHBox.cxx index c1f60ac..91d9fb8 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: */ diff --git a/sw/uiconfig/swriter/ui/notebookbar.ui b/sw/uiconfig/swriter/ui/notebookbar.ui index 1c8d5ef..b64a2d3 100644 --- a/sw/uiconfig/swriter/ui/notebookbar.ui +++ b/sw/uiconfig/swriter/ui/notebookbar.ui @@ -2374,14 +2374,57 @@ <property name="can_focus">False</property> <property name="tooltip_text" translatable="yes">Links</property> <child> - <object class="vcllo-SmallButton" id="hyperlinkdialog"> + <object class="GtkBox"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">.uno:HyperlinkDialog</property> - <property name="image">HyperlinkDialogImg</property> - <property name="relief">none</property> - <property name="image_position">top</property> + <property name="can_focus">False</property> + <child> + <object class="vcllo-SmallButton" id="hyperlinkdialog"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">.uno:HyperlinkDialog</property> + <property name="image">HyperlinkDialogImg</property> + <property name="relief">none</property> + <property name="image_position">top</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="vcllo-SmallButton" id="bookmark"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">.uno:InsertBookmark</property> + <property name="image">InsertBookmarkImg</property> + <property name="relief">none</property> + <property name="image_position">top</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="vcllo-SmallButton" id="insertreferencefield"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">.uno:InsertReferenceField</property> + <property name="image">InsertReferenceFieldImg</property> + <property name="relief">none</property> + <property name="image_position">top</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> @@ -2389,38 +2432,6 @@ <property name="position">0</property> </packing> </child> - <child> - <object class="vcllo-SmallButton" id="bookmark"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">.uno:InsertBookmark</property> - <property name="image">InsertBookmarkImg</property> - <property name="relief">none</property> - <property name="image_position">top</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="vcllo-SmallButton" id="insertreferencefield"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">.uno:InsertReferenceField</property> - <property name="image">InsertReferenceFieldImg</property> - <property name="relief">none</property> - <property name="image_position">top</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">2</property> - </packing> - </child> <style> <class name="priority-3"/> </style> @@ -3874,6 +3885,9 @@ <property name="position">3</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -4026,6 +4040,9 @@ <property name="position">1</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -4040,57 +4057,84 @@ <property name="tooltip_text" translatable="yes">Zoom</property> <property name="valign">center</property> <child> - <object class="vcllo-SmallButton" id="Zoom100Percent"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">.uno:Zoom100Percent</property> - <property name="image">Zoom100PercentImg</property> - <property name="relief">none</property> - <property name="image_position">top</property> - <property name="always_show_image">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="vcllo-SmallButton" id="ZoomOptimal"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">.uno:ZoomOptimal</property> - <property name="image">ZoomOptimalImg</property> - <property name="relief">none</property> - <property name="image_position">top</property> - <property name="always_show_image">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkBox" id="box85"> + <object class="GtkBox" id="box"> <property name="visible">True</property> <property name="can_focus">False</property> <child> - <object class="GtkBox" id="box117"> + <object class="vcllo-SmallButton" id="Zoom100Percent"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">.uno:Zoom100Percent</property> + <property name="image">Zoom100PercentImg</property> + <property name="relief">none</property> + <property name="image_position">top</property> + <property name="always_show_image">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="vcllo-SmallButton" id="ZoomOptimal"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">.uno:ZoomOptimal</property> + <property name="image">ZoomOptimalImg</property> + <property name="relief">none</property> + <property name="image_position">top</property> + <property name="always_show_image">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box85"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="orientation">vertical</property> <child> - <object class="GtkButton" id="ZoomPage"> + <object class="GtkBox" id="box117"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">.uno:ZoomPage</property> - <property name="relief">none</property> - <property name="xalign">0</property> - <property name="always_show_image">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkButton" id="ZoomPage"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">.uno:ZoomPage</property> + <property name="relief">none</property> + <property name="xalign">0</property> + <property name="always_show_image">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="ZoomPageWidth"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">.uno:ZoomPageWidth</property> + <property name="relief">none</property> + <property name="xalign">0</property> + <property name="always_show_image">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> @@ -4099,14 +4143,10 @@ </packing> </child> <child> - <object class="GtkButton" id="ZoomPageWidth"> + <object class="GtkSeparator" id="separator13"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">.uno:ZoomPageWidth</property> - <property name="relief">none</property> - <property name="xalign">0</property> - <property name="always_show_image">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> </object> <packing> <property name="expand">False</property> @@ -4118,26 +4158,14 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkSeparator" id="separator13"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="orientation">vertical</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">2</property> + <property name="position">0</property> </packing> </child> <style> @@ -4218,6 +4246,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -4455,6 +4486,9 @@ <property name="position">3</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -4521,6 +4555,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -4854,6 +4891,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -4885,6 +4925,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -4963,6 +5006,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -5134,6 +5180,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -5212,6 +5261,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -5300,6 +5352,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -5376,6 +5431,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> @@ -5452,6 +5510,9 @@ <property name="position">0</property> </packing> </child> + <style> + <class name="priority-3"/> + </style> </object> <packing> <property name="expand">False</property> diff --git a/vcl/source/control/notebookbar.cxx b/vcl/source/control/notebookbar.cxx index 6f4108d..4532360 100644 --- a/vcl/source/control/notebookbar.cxx +++ b/vcl/source/control/notebookbar.cxx @@ -105,6 +105,21 @@ void NotebookBar::setPosSizePixel(long nX, long nY, long nWidth, long nHeight, P VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight)); } +void NotebookBar::Resize() +{ + if(m_pUIBuilder && m_pUIBuilder->get_widget_root()) + { + vcl::Window* pWindow = m_pUIBuilder->get_widget_root()->GetChild(0); + if (pWindow) + { + Size aSize = pWindow->GetSizePixel(); + aSize.Width() = GetSizePixel().Width(); + pWindow->SetSizePixel(aSize); + } + } + Control::Resize(); +} + void NotebookBar::SetIconClickHdl(Link<NotebookBar*, void> aHdl) { if (m_pContextContainer) diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx index 989da8f..5268fbd 100644 --- a/vcl/source/control/tabctrl.cxx +++ b/vcl/source/control/tabctrl.cxx @@ -2273,13 +2273,19 @@ void NotebookbarTabControl::SelectTabPage( sal_uInt16 nPageId ) if ( nPageId == 1 ) m_aIconClickHdl.Call( static_cast<NotebookBar*>(GetParent()) ); else + { TabControl::SelectTabPage( nPageId ); + Resize(); + } } void NotebookbarTabControl::SetCurPageId( sal_uInt16 nPageId ) { if ( nPageId != 1 ) + { TabControl::SetCurPageId( nPageId ); + Resize(); + } if ( nPageId == GetPageCount() ) ImplActivateTabPage( true ); }
_______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
