From 1653bb9bffaa84a40b7d81a8277e887ea28df4e4 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 4 Mar 2021 17:22:14 +0000 Subject: remove intermediate containers in sidebars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tested extension sidebars of: a) Wollmux extension sidebars b) Analog Clock Extension demo https://wiki.openoffice.org/wiki/Sidebar_for_Developers#Example:_Analog_Clock_Extension Change-Id: If9729e20526681928137989f01a8ae733a9b0cb5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112035 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- sw/source/uibase/utlui/navipi.cxx | 100 ++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'sw/source/uibase/utlui/navipi.cxx') diff --git a/sw/source/uibase/utlui/navipi.cxx b/sw/source/uibase/utlui/navipi.cxx index 08ba46dae8e3..bbfc9b062fce 100644 --- a/sw/source/uibase/utlui/navipi.cxx +++ b/sw/source/uibase/utlui/navipi.cxx @@ -193,7 +193,7 @@ IMPL_LINK(SwNavigationPI, ToolBoxSelectHdl, const OString&, rCommand, void) } else if (rCommand == "listbox") { - if (ParentIsFloatingWindow(GetParent())) + if (ParentIsFloatingWindow(m_xNavigatorDlg)) { if (IsZoomedIn()) { @@ -394,7 +394,7 @@ void SwNavigationPI::ZoomOut() { if (!IsZoomedIn()) return; - SfxNavigator* pNav = dynamic_cast(GetParent()); + SfxNavigator* pNav = m_xNavigatorDlg.get(); if (!pNav) return; m_bIsZoomedIn = false; @@ -411,7 +411,8 @@ void SwNavigationPI::ZoomOut() m_xDocListBox->show(); } - Size aOptimalSize(m_xContainer->get_preferred_size()); + pNav->InvalidateChildSizeCache(); + Size aOptimalSize(pNav->GetOptimalSize()); Size aNewSize(pNav->GetOutputSizePixel()); aNewSize.setHeight( m_aExpandedSize.Height() ); pNav->SetMinOutputSizePixel(aOptimalSize); @@ -426,11 +427,11 @@ void SwNavigationPI::ZoomIn() { if (IsZoomedIn()) return; - SfxNavigator* pNav = dynamic_cast(GetParent()); + SfxNavigator* pNav = m_xNavigatorDlg.get(); if (!pNav) return; - m_aExpandedSize = GetSizePixel(); + m_aExpandedSize = m_xNavigatorDlg->GetSizePixel(); m_xContentBox->hide(); m_xContentTree->HideTree(); @@ -439,7 +440,8 @@ void SwNavigationPI::ZoomIn() m_xDocListBox->hide(); m_bIsZoomedIn = true; - Size aOptimalSize(m_xContainer->get_preferred_size()); + pNav->InvalidateChildSizeCache(); + Size aOptimalSize(pNav->GetOptimalSize()); Size aNewSize(pNav->GetOutputSizePixel()); aNewSize.setHeight( aOptimalSize.Height() ); pNav->SetMinOutputSizePixel(aOptimalSize); @@ -462,7 +464,7 @@ enum StatusIndex } -VclPtr SwNavigationPI::Create(vcl::Window* pParent, +std::unique_ptr SwNavigationPI::Create(weld::Widget* pParent, const css::uno::Reference& rxFrame, SfxBindings* pBindings) { @@ -472,13 +474,13 @@ VclPtr SwNavigationPI::Create(vcl::Window* pParent, throw css::lang::IllegalArgumentException("no XFrame given to SwNavigationPI::Create", nullptr, 0); if( pBindings == nullptr ) throw css::lang::IllegalArgumentException("no SfxBindings given to SwNavigationPI::Create", nullptr, 0); - return VclPtr::Create(pParent, rxFrame, pBindings); + return std::make_unique(pParent, rxFrame, pBindings, nullptr); } -SwNavigationPI::SwNavigationPI(vcl::Window* pParent, +SwNavigationPI::SwNavigationPI(weld::Widget* pParent, const css::uno::Reference& rxFrame, - SfxBindings* _pBindings) - : PanelLayout(pParent, "NavigatorPanel", "modules/swriter/ui/navigatorpanel.ui", rxFrame) + SfxBindings* _pBindings, SfxNavigator* pNavigatorDlg) + : PanelLayout(pParent, "NavigatorPanel", "modules/swriter/ui/navigatorpanel.ui") , m_aDocFullName(SID_DOCFULLNAME, *_pBindings, *this) , m_aPageStats(FN_STAT_PAGE, *_pBindings, *this) , m_xContent1ToolBox(m_xBuilder->weld_toolbar("content1")) @@ -500,6 +502,7 @@ SwNavigationPI::SwNavigationPI(vcl::Window* pParent, , m_xGlobalBox(m_xBuilder->weld_widget("globalbox")) , m_xGlobalTree(new SwGlobalTree(m_xBuilder->weld_tree_view("globaltree"), this)) , m_xDocListBox(m_xBuilder->weld_combo_box("documents")) + , m_xNavigatorDlg(pNavigatorDlg) , m_pContentView(nullptr) , m_pContentWrtShell(nullptr) , m_pActContView(nullptr) @@ -512,7 +515,7 @@ SwNavigationPI::SwNavigationPI(vcl::Window* pParent, { m_xContainer->connect_container_focus_changed(LINK(this, SwNavigationPI, SetFocusChildHdl)); - set_id("NavigatorPanelParent"); // for uitest/writer_tests5/tdf114724.py + UpdateInitShow(); GetCreateView(); @@ -562,7 +565,7 @@ SwNavigationPI::SwNavigationPI(vcl::Window* pParent, m_aStatusArr[3] = SwResId(STR_ACTIVE_VIEW); - bool bFloatingNavigator = ParentIsFloatingWindow(GetParent()); + bool bFloatingNavigator = ParentIsFloatingWindow(m_xNavigatorDlg); m_xContentTree->set_selection_mode(SelectionMode::Single); m_xContentTree->ShowTree(); @@ -622,16 +625,16 @@ SwNavigationPI::SwNavigationPI(vcl::Window* pParent, m_xDocListBox->set_accessible_name(m_aStatusArr[3]); m_aExpandedSize = m_xContainer->get_preferred_size(); - - m_pInitialFocusWidget = m_xContent1ToolBox.get(); } -SwNavigationPI::~SwNavigationPI() +weld::Window* SwNavigationPI::GetFrameWeld() const { - disposeOnce(); + if (m_xNavigatorDlg) + return m_xNavigatorDlg->GetFrameWeld(); + return PanelLayout::GetFrameWeld(); } -void SwNavigationPI::dispose() +SwNavigationPI::~SwNavigationPI() { if (IsGlobalDoc() && !IsGlobalMode()) { @@ -674,8 +677,6 @@ void SwNavigationPI::dispose() m_aDocFullName.dispose(); m_aPageStats.dispose(); - - PanelLayout::dispose(); } void SwNavigationPI::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState /*eState*/, @@ -717,24 +718,21 @@ void SwNavigationPI::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState /*eState*/, } } -void SwNavigationPI::StateChanged(StateChangedType nStateChange) +void SwNavigationPI::UpdateInitShow() { - PanelLayout::StateChanged(nStateChange); - if (nStateChange == StateChangedType::InitShow) + // if the parent isn't a float, then the navigator is displayed in + // the sidebar or is otherwise docked. While the navigator could change + // its size, the sidebar can not, and the navigator would just waste + // space. Therefore disable this button. + bool bParentIsFloatingWindow(ParentIsFloatingWindow(m_xNavigatorDlg)); + m_xContent6ToolBox->set_item_sensitive("listbox", bParentIsFloatingWindow); + // show content if docked + if (!bParentIsFloatingWindow && IsZoomedIn()) + ZoomOut(); + if (m_xContentTree) { - // if the parent isn't a float, then the navigator is displayed in - // the sidebar or is otherwise docked. While the navigator could change - // its size, the sidebar can not, and the navigator would just waste - // space. Therefore disable this button. - m_xContent6ToolBox->set_item_sensitive("listbox", ParentIsFloatingWindow(GetParent())); - // show content if docked - if (!ParentIsFloatingWindow(GetParent()) && IsZoomedIn()) - ZoomOut(); - if (m_xContentTree) - { - m_xContentTree->SetActiveShell(GetActiveWrtShell()); - m_xContentTree->UpdateTracking(); - } + m_xContentTree->SetActiveShell(GetActiveWrtShell()); + m_xContentTree->UpdateTracking(); } } @@ -1092,12 +1090,13 @@ SwView* SwNavigationPI::GetCreateView() const class SwNavigatorWin : public SfxNavigator { private: - VclPtr pNavi; + std::unique_ptr m_xNavi; public: SwNavigatorWin(SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* pParent); + virtual void StateChanged(StateChangedType nStateChange) override; virtual void dispose() override { - pNavi.disposeAndClear(); + m_xNavi.reset(); SfxNavigator::dispose(); } virtual ~SwNavigatorWin() override @@ -1108,9 +1107,8 @@ public: SwNavigatorWin::SwNavigatorWin(SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* pParent) : SfxNavigator(_pBindings, _pMgr, pParent) + , m_xNavi(std::make_unique(m_xContainer.get(), _pBindings->GetActiveFrame(), _pBindings, this)) { - Reference< XFrame > xFrame = _pBindings->GetActiveFrame(); - pNavi = VclPtr< SwNavigationPI >::Create( this, xFrame, _pBindings ); _pBindings->Invalidate(SID_NAVIGATOR); SwNavigationConfig* pNaviConfig = SW_MOD()->GetNavigationConfig(); @@ -1118,20 +1116,26 @@ SwNavigatorWin::SwNavigatorWin(SfxBindings* _pBindings, SfxChildWindow* _pMgr, v const ContentTypeId nRootType = pNaviConfig->GetRootType(); if( nRootType != ContentTypeId::UNKNOWN ) { - pNavi->m_xContentTree->SetRootType(nRootType); - pNavi->m_xContent5ToolBox->set_item_active("root", true); + m_xNavi->m_xContentTree->SetRootType(nRootType); + m_xNavi->m_xContent5ToolBox->set_item_active("root", true); if (nRootType == ContentTypeId::OUTLINE) { - pNavi->m_xContentTree->set_selection_mode(SelectionMode::Multiple); + m_xNavi->m_xContentTree->set_selection_mode(SelectionMode::Multiple); } } - pNavi->m_xContentTree->SetOutlineLevel( static_cast< sal_uInt8 >( pNaviConfig->GetOutlineLevel() ) ); - pNavi->SetRegionDropMode( pNaviConfig->GetRegionMode() ); - pNavi->Show(); + m_xNavi->m_xContentTree->SetOutlineLevel( static_cast< sal_uInt8 >( pNaviConfig->GetOutlineLevel() ) ); + m_xNavi->SetRegionDropMode( pNaviConfig->GetRegionMode() ); - SetMinOutputSizePixel(pNavi->GetOptimalSize()); + SetMinOutputSizePixel(GetOptimalSize()); if (pNaviConfig->IsSmall()) - pNavi->ZoomIn(); + m_xNavi->ZoomIn(); +} + +void SwNavigatorWin::StateChanged(StateChangedType nStateChange) +{ + SfxNavigator::StateChanged(nStateChange); + if (nStateChange == StateChangedType::InitShow) + m_xNavi->UpdateInitShow(); } SFX_IMPL_DOCKINGWINDOW(SwNavigatorWrapper, SID_NAVIGATOR); -- cgit