From 574d02a7a81f99d08512410fcd3262b41db8c209 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 14 Jun 2018 12:05:10 +0100 Subject: do setPreviewsToSamePlace at SfxTabDialogController display time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia38c1a577b7d054ab4e7e70a8f2cbce16a3573f5 Reviewed-on: https://gerrit.libreoffice.org/55793 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- include/sfx2/tabdlg.hxx | 2 ++ include/vcl/layout.hxx | 8 -------- include/vcl/vclenum.hxx | 7 +++++++ include/vcl/weld.hxx | 9 +++++++++ sfx2/source/dialog/tabdlg.cxx | 31 +++++++++++++++++++++++++++++ vcl/source/app/salvtables.cxx | 26 ++++++++++++++++++++++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 46 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 121 insertions(+), 8 deletions(-) diff --git a/include/sfx2/tabdlg.hxx b/include/sfx2/tabdlg.hxx index bdae835ffca2..163693d9fe9b 100644 --- a/include/sfx2/tabdlg.hxx +++ b/include/sfx2/tabdlg.hxx @@ -239,6 +239,7 @@ private: std::unique_ptr m_xUserBtn; std::unique_ptr m_xCancelBtn; std::unique_ptr m_xResetBtn; + std::unique_ptr m_xSizeGroup; SfxItemSet* m_pSet; std::unique_ptr m_pOutSet; @@ -250,6 +251,7 @@ private: DECL_DLLPRIVATE_LINK(DeactivatePageHdl, const OString&, bool); SAL_DLLPRIVATE void Init_Impl(bool bFmtFlag); SAL_DLLPRIVATE void CreatePages(); + SAL_DLLPRIVATE void setPreviewsToSamePlace(); protected: virtual short Ok(); diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx index d2fefe01f875..298601da6e8f 100644 --- a/include/vcl/layout.hxx +++ b/include/vcl/layout.hxx @@ -564,14 +564,6 @@ public: virtual void Command(const CommandEvent& rCEvt) override; }; -enum class VclSizeGroupMode -{ - NONE, - Horizontal, - Vertical, - Both -}; - class VCL_DLLPUBLIC VclSizeGroup { private: diff --git a/include/vcl/vclenum.hxx b/include/vcl/vclenum.hxx index 8697465af32d..0de6703f6aba 100644 --- a/include/vcl/vclenum.hxx +++ b/include/vcl/vclenum.hxx @@ -242,6 +242,13 @@ enum class VclMessageType Error }; +enum class VclSizeGroupMode +{ + NONE, + Horizontal, + Vertical, + Both +}; #endif // INCLUDED_VCL_VCLENUM_HXX diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 86718d52a642..d0c5c220f375 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -864,6 +864,14 @@ public: virtual ~Menu() {} }; +class VCL_DLLPUBLIC SizeGroup +{ +public: + virtual void add_widget(weld::Widget* pWidget) = 0; + virtual void set_mode(VclSizeGroupMode eMode) = 0; + virtual ~SizeGroup() {} +}; + class VCL_DLLPUBLIC Builder { private: @@ -914,6 +922,7 @@ public: void* pUserData = nullptr, bool bTakeOwnership = false) = 0; virtual Menu* weld_menu(const OString& id, bool bTakeOwnership = true) = 0; + virtual SizeGroup* create_size_group() = 0; virtual ~Builder() {} }; diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx index 5521fe9a0305..48e721c2baf7 100644 --- a/sfx2/source/dialog/tabdlg.cxx +++ b/sfx2/source/dialog/tabdlg.cxx @@ -1957,6 +1957,35 @@ void SfxTabDialogController::CreatePages() } } +void SfxTabDialogController::setPreviewsToSamePlace() +{ + //where tab pages have the same basic layout with a preview on the right, + //get both of their non-preview areas to request the same size so that the + //preview appears in the same place in each one so flipping between tabs + //isn't distracting as it jumps around + std::vector> aGrids; + for (auto pDataObject : m_pImpl->aData) + { + if (pDataObject->pTabPage) + continue; + if (!pDataObject->pTabPage->m_xBuilder) + continue; + weld::Widget* pGrid = pDataObject->pTabPage->m_xBuilder->weld_widget("maingrid"); + if (!pGrid) + continue; + aGrids.emplace_back(pGrid); + } + + m_xSizeGroup.reset(); + + if (aGrids.size() <= 1) + return; + + m_xSizeGroup.reset(m_xBuilder->create_size_group()); + for (auto& rGrid : aGrids) + m_xSizeGroup->add_widget(rGrid.get()); +} + void SfxTabDialogController::RemoveTabPage(const OString& rId) /* [Description] @@ -2000,6 +2029,8 @@ void SfxTabDialogController::Start_Impl() { CreatePages(); + setPreviewsToSamePlace(); + assert(m_pImpl->aData.size() == static_cast(m_xTabCtrl->get_n_pages()) && "not all pages registered"); diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 00ff6c6a9090..20f957af82d3 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -457,6 +457,27 @@ public: } }; +class SalInstanceSizeGroup : public weld::SizeGroup +{ +private: + std::shared_ptr m_xGroup; +public: + SalInstanceSizeGroup() + : m_xGroup(new VclSizeGroup) + { + } + virtual void add_widget(weld::Widget* pWidget) override + { + SalInstanceWidget* pVclWidget = dynamic_cast(pWidget); + assert(pVclWidget); + m_xGroup->insert(pVclWidget->getWidget()); + } + virtual void set_mode(VclSizeGroupMode eMode) override + { + m_xGroup->set_mode(eMode); + } +}; + class SalInstanceContainer : public SalInstanceWidget, public virtual weld::Container { private: @@ -2360,6 +2381,11 @@ public: return pMenu ? new SalInstanceMenu(pMenu, bTakeOwnership) : nullptr; } + virtual weld::SizeGroup* create_size_group() override + { + return new SalInstanceSizeGroup; + } + virtual ~SalInstanceBuilder() override { if (VclBuilderContainer* pOwnedToplevel = dynamic_cast(m_aOwnedToplevel.get())) diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index cc927fe89742..47ef69b4077a 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1747,6 +1747,47 @@ public: } }; +class GtkInstanceSizeGroup : public weld::SizeGroup +{ +private: + GtkSizeGroup* m_pGroup; +public: + GtkInstanceSizeGroup() + : m_pGroup(gtk_size_group_new(GTK_SIZE_GROUP_NONE)) + { + } + virtual void add_widget(weld::Widget* pWidget) override + { + GtkInstanceWidget* pVclWidget = dynamic_cast(pWidget); + assert(pVclWidget); + gtk_size_group_add_widget(m_pGroup, pVclWidget->getWidget()); + } + virtual void set_mode(VclSizeGroupMode eVclMode) override + { + GtkSizeGroupMode eGtkMode; + switch (eVclMode) + { + case VclSizeGroupMode::NONE: + eGtkMode = GTK_SIZE_GROUP_NONE; + break; + case VclSizeGroupMode::Horizontal: + eGtkMode = GTK_SIZE_GROUP_HORIZONTAL; + break; + case VclSizeGroupMode::Vertical: + eGtkMode = GTK_SIZE_GROUP_VERTICAL; + break; + case VclSizeGroupMode::Both: + eGtkMode = GTK_SIZE_GROUP_BOTH; + break; + } + gtk_size_group_set_mode(m_pGroup, eGtkMode); + } + virtual ~GtkInstanceSizeGroup() override + { + g_object_unref(m_pGroup); + } +}; + class GtkInstanceContainer : public GtkInstanceWidget, public virtual weld::Container { private: @@ -4885,6 +4926,11 @@ public: return nullptr; return new GtkInstanceMenu(pMenu, bTakeOwnership); } + + virtual weld::SizeGroup* create_size_group() override + { + return new GtkInstanceSizeGroup; + } }; void GtkInstanceWindow::help() -- cgit