include/vcl/layout.hxx | 8 +- include/vcl/weld.hxx | 2 vcl/source/app/salvtables.cxx | 17 +++- vcl/source/window/layout.cxx | 8 +- vcl/unx/gtk3/gtk3gtkinst.cxx | 149 +++++++++++++++++++++--------------------- 5 files changed, 102 insertions(+), 82 deletions(-)
New commits: commit ea79a34ec7ffee6f86f16172c9e5fd75257539ca Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sun May 31 16:16:37 2020 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Mon Jun 1 19:38:11 2020 +0200 allow sorting buttons via weld::Box Change-Id: I315fe2dd2e40c976edd802c1e87b7ccdb0c298fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95221 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx index 8a5b881644e4..67e856fabdca 100644 --- a/include/vcl/layout.hxx +++ b/include/vcl/layout.hxx @@ -94,6 +94,10 @@ public: { m_bHomogeneous = bHomogeneous; } + bool get_orientation() const + { + return m_bVerticalContainer; + } virtual bool set_property(const OString &rKey, const OUString &rValue) override; virtual boost::property_tree::ptree DumpAsPropertyTree() override; protected: @@ -211,7 +215,6 @@ public: { } virtual bool set_property(const OString &rKey, const OUString &rValue) override; - void sort_native_button_order(); protected: virtual Size calculateRequisition() const override; virtual void setAllocation(const Size &rAllocation) override; @@ -853,6 +856,9 @@ Size getLegacyBestSizeForChildren(const vcl::Window &rWindow); //Get first parent which is not a layout widget vcl::Window* getNonLayoutParent(vcl::Window *pParent); +//Sort ok/cancel etc buttons in platform order +void sort_native_button_order(VclBox& rContainer); + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 58309c9e49ef..9d01a0fc7022 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -290,6 +290,8 @@ class VCL_DLLPUBLIC Box : virtual public Container public: // Moves child to a new position in the list of children virtual void reorder_child(weld::Widget* pWidget, int position) = 0; + // Sort ok/cancel etc buttons in platform order + virtual void sort_native_button_order() = 0; }; class VCL_DLLPUBLIC Paned : virtual public Container diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 6057ffbe6dd6..846bbfa98e46 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1134,9 +1134,12 @@ namespace { class SalInstanceBox : public SalInstanceContainer, public virtual weld::Box { +private: + VclPtr<VclBox> m_xBox; public: - SalInstanceBox(vcl::Window* pContainer, SalInstanceBuilder* pBuilder, bool bTakeOwnership) + SalInstanceBox(VclBox* pContainer, SalInstanceBuilder* pBuilder, bool bTakeOwnership) : SalInstanceContainer(pContainer, pBuilder, bTakeOwnership) + , m_xBox(pContainer) { } virtual void reorder_child(weld::Widget* pWidget, int nNewPosition) override @@ -1145,6 +1148,10 @@ public: assert(pVclWidget); pVclWidget->getWidget()->reorderWithinParent(nNewPosition); } + virtual void sort_native_button_order() override + { + ::sort_native_button_order(*m_xBox); + } }; void CollectChildren(const vcl::Window& rCurrent, const basegfx::B2IPoint& rTopLeft, @@ -1380,7 +1387,7 @@ bool SalInstanceDialog::runAsync(std::shared_ptr<weld::DialogController> aOwner, aCtx.maEndDialogFn = rEndDialogFn; VclButtonBox* pActionArea = m_xDialog->get_action_area(); if (pActionArea) - pActionArea->sort_native_button_order(); + sort_native_button_order(*pActionArea); return m_xDialog->StartExecuteAsync(aCtx); } @@ -1395,7 +1402,7 @@ bool SalInstanceDialog::runAsync(std::shared_ptr<Dialog> const& rxSelf, aCtx.maEndDialogFn = rEndDialogFn; VclButtonBox* pActionArea = m_xDialog->get_action_area(); if (pActionArea) - pActionArea->sort_native_button_order(); + sort_native_button_order(*pActionArea); return m_xDialog->StartExecuteAsync(aCtx); } @@ -1473,7 +1480,7 @@ int SalInstanceDialog::run() { VclButtonBox* pActionArea = m_xDialog->get_action_area(); if (pActionArea) - pActionArea->sort_native_button_order(); + sort_native_button_order(*pActionArea); return m_xDialog->Execute(); } @@ -6292,7 +6299,7 @@ std::unique_ptr<weld::Container> SalInstanceBuilder::weld_container(const OStrin std::unique_ptr<weld::Box> SalInstanceBuilder::weld_box(const OString& id, bool bTakeOwnership) { - vcl::Window* pContainer = m_xBuilder->get(id); + VclBox* pContainer = m_xBuilder->get<VclBox>(id); return pContainer ? std::make_unique<SalInstanceBox>(pContainer, this, bTakeOwnership) : nullptr; } diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index 9225c27b05a8..29c4cf0e7d41 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -789,10 +789,10 @@ bool sortButtons::operator()(const vcl::Window *pA, const vcl::Window *pB) const return getButtonPriority(pA->GetHelpId()) < getButtonPriority(pB->GetHelpId()); } -void VclButtonBox::sort_native_button_order() +void sort_native_button_order(VclBox& rContainer) { std::vector<vcl::Window*> aChilds; - for (vcl::Window* pChild = GetWindow(GetWindowType::FirstChild); pChild; + for (vcl::Window* pChild = rContainer.GetWindow(GetWindowType::FirstChild); pChild; pChild = pChild->GetWindow(GetWindowType::Next)) { aChilds.push_back(pChild); @@ -800,7 +800,7 @@ void VclButtonBox::sort_native_button_order() //sort child order within parent so that we match the platform //button order - std::stable_sort(aChilds.begin(), aChilds.end(), sortButtons(m_bVerticalContainer)); + std::stable_sort(aChilds.begin(), aChilds.end(), sortButtons(rContainer.get_orientation())); BuilderUtils::reorderWithinParent(aChilds, true); } @@ -2295,7 +2295,7 @@ void MessageDialog::create_message_area() break; } set_default_response(nDefaultResponse); - pButtonBox->sort_native_button_order(); + sort_native_button_order(*pButtonBox); m_pMessageBox->Show(); m_pGrid->Show(); } diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 57a2973743a3..c0bc216f0011 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -3688,6 +3688,78 @@ std::unique_ptr<weld::Container> GtkInstanceWidget::weld_parent() const namespace { +struct ButtonOrder +{ + const char * m_aType; + int m_nPriority; +}; + +int getButtonPriority(const OString &rType) +{ + static const size_t N_TYPES = 7; + static const ButtonOrder aDiscardCancelSave[N_TYPES] = + { + { "/discard", 0 }, + { "/cancel", 1 }, + { "/no", 2 }, + { "/open", 3 }, + { "/save", 3 }, + { "/yes", 3 }, + { "/ok", 3 } + }; + + static const ButtonOrder aSaveDiscardCancel[N_TYPES] = + { + { "/open", 0 }, + { "/save", 0 }, + { "/yes", 0 }, + { "/ok", 0 }, + { "/discard", 1 }, + { "/no", 1 }, + { "/cancel", 2 } + }; + + const ButtonOrder* pOrder = &aDiscardCancelSave[0]; + + const OUString &rEnv = Application::GetDesktopEnvironment(); + + if (rEnv.equalsIgnoreAsciiCase("windows") || + rEnv.equalsIgnoreAsciiCase("tde") || + rEnv.startsWithIgnoreAsciiCase("kde")) + { + pOrder = &aSaveDiscardCancel[0]; + } + + for (size_t i = 0; i < N_TYPES; ++i, ++pOrder) + { + if (rType.endsWith(pOrder->m_aType)) + return pOrder->m_nPriority; + } + + return -1; +} + +bool sortButtons(const GtkWidget* pA, const GtkWidget* pB) +{ + //order within groups according to platform rules + return getButtonPriority(::get_help_id(pA)) < getButtonPriority(::get_help_id(pB)); +} + +void sort_native_button_order(GtkBox* pContainer) +{ + std::vector<GtkWidget*> aChildren; + GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pContainer)); + for (GList* pChild = g_list_first(pChildren); pChild; pChild = g_list_next(pChild)) + aChildren.push_back(static_cast<GtkWidget*>(pChild->data)); + g_list_free(pChildren); + + //sort child order within parent so that we match the platform button order + std::stable_sort(aChildren.begin(), aChildren.end(), sortButtons); + + for (size_t pos = 0; pos < aChildren.size(); ++pos) + gtk_box_reorder_child(pContainer, aChildren[pos], pos); +} + class GtkInstanceBox : public GtkInstanceContainer, public virtual weld::Box { private: @@ -3707,6 +3779,11 @@ public: GtkWidget* pChild = pGtkWidget->getWidget(); gtk_box_reorder_child(m_pBox, pChild, nNewPosition); } + + virtual void sort_native_button_order() override + { + ::sort_native_button_order(m_pBox); + } }; void set_cursor(GtkWidget* pWidget, const char *pName) @@ -3724,78 +3801,6 @@ public: namespace { - struct ButtonOrder - { - const char * m_aType; - int m_nPriority; - }; - - int getButtonPriority(const OString &rType) - { - static const size_t N_TYPES = 7; - static const ButtonOrder aDiscardCancelSave[N_TYPES] = - { - { "/discard", 0 }, - { "/cancel", 1 }, - { "/no", 2 }, - { "/open", 3 }, - { "/save", 3 }, - { "/yes", 3 }, - { "/ok", 3 } - }; - - static const ButtonOrder aSaveDiscardCancel[N_TYPES] = - { - { "/open", 0 }, - { "/save", 0 }, - { "/yes", 0 }, - { "/ok", 0 }, - { "/discard", 1 }, - { "/no", 1 }, - { "/cancel", 2 } - }; - - const ButtonOrder* pOrder = &aDiscardCancelSave[0]; - - const OUString &rEnv = Application::GetDesktopEnvironment(); - - if (rEnv.equalsIgnoreAsciiCase("windows") || - rEnv.equalsIgnoreAsciiCase("tde") || - rEnv.startsWithIgnoreAsciiCase("kde")) - { - pOrder = &aSaveDiscardCancel[0]; - } - - for (size_t i = 0; i < N_TYPES; ++i, ++pOrder) - { - if (rType.endsWith(pOrder->m_aType)) - return pOrder->m_nPriority; - } - - return -1; - } - - bool sortButtons(const GtkWidget* pA, const GtkWidget* pB) - { - //order within groups according to platform rules - return getButtonPriority(::get_help_id(pA)) < getButtonPriority(::get_help_id(pB)); - } - - void sort_native_button_order(GtkBox* pContainer) - { - std::vector<GtkWidget*> aChildren; - GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pContainer)); - for (GList* pChild = g_list_first(pChildren); pChild; pChild = g_list_next(pChild)) - aChildren.push_back(static_cast<GtkWidget*>(pChild->data)); - g_list_free(pChildren); - - //sort child order within parent so that we match the platform button order - std::stable_sort(aChildren.begin(), aChildren.end(), sortButtons); - - for (size_t pos = 0; pos < aChildren.size(); ++pos) - gtk_box_reorder_child(pContainer, aChildren[pos], pos); - } - Point get_csd_offset(GtkWidget* pTopLevel) { // try and omit drawing CSD under wayland _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits