[Libreoffice-commits] core.git: vcl/source vcl/unx

Caolán McNamara caolanm at redhat.com
Wed Feb 28 20:26:17 UTC 2018


 vcl/source/app/salvtables.cxx |    3 +
 vcl/source/window/layout.cxx  |    6 ++-
 vcl/unx/gtk3/gtk3gtkinst.cxx  |   74 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+), 2 deletions(-)

New commits:
commit c456ce855ac1ee4775489485f9107bd43a0f1371
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Feb 27 16:45:44 2018 +0000

    use ok, cancel under kde vs cancel, ok under gnome
    
    for the native welded dialogs
    
    Change-Id: I34663616826c1eb084262ea1c830f8580785d50c
    Reviewed-on: https://gerrit.libreoffice.org/50458
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index d2f648a696c1..a2b5b13d15fc 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -404,6 +404,9 @@ public:
 
     virtual int run() override
     {
+        VclButtonBox* pActionArea = m_xDialog->get_action_area();
+        if (pActionArea)
+           pActionArea->sort_native_button_order();
         return m_xDialog->Execute();
     }
 
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index ae3663c9c75f..2839ab356385 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -829,20 +829,22 @@ struct ButtonOrder
 
 static int getButtonPriority(const OString &rType)
 {
-    static const size_t N_TYPES = 5;
+    static const size_t N_TYPES = 6;
     static const ButtonOrder aDiscardCancelSave[N_TYPES] =
     {
         { "/discard", 0 },
         { "/no", 0 },
         { "/cancel", 1 },
         { "/save", 2 },
-        { "/yes", 2 }
+        { "/yes", 2 },
+        { "/ok", 2 }
     };
 
     static const ButtonOrder aSaveDiscardCancel[N_TYPES] =
     {
         { "/save", 0 },
         { "/yes", 0 },
+        { "/ok", 0 },
         { "/discard", 1 },
         { "/no", 1 },
         { "/cancel", 2 }
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index e31606fffbad..c36895fffce1 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -1378,6 +1378,79 @@ public:
     }
 };
 
+namespace
+{
+    struct ButtonOrder
+    {
+        OString m_aType;
+        int m_nPriority;
+    };
+
+    int getButtonPriority(const OString &rType)
+    {
+        static const size_t N_TYPES = 6;
+        static const ButtonOrder aDiscardCancelSave[N_TYPES] =
+        {
+            { "/discard", 0 },
+            { "/no", 0 },
+            { "/cancel", 1 },
+            { "/save", 2 },
+            { "/yes", 2 },
+            { "/ok", 2 }
+        };
+
+        static const ButtonOrder aSaveDiscardCancel[N_TYPES] =
+        {
+            { "/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 GtkInstanceDialog : public GtkInstanceWindow, public virtual weld::Dialog
 {
 private:
@@ -1399,6 +1472,7 @@ public:
 
     virtual int run() override
     {
+        sort_native_button_order(GTK_BOX(gtk_dialog_get_action_area(m_pDialog)));
         int ret;
         while (true)
         {


More information about the Libreoffice-commits mailing list