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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 9 08:16:15 UTC 2021


 vcl/unx/gtk3/gtkinst.cxx     |   62 ++++++++++++++++++++++++++++++-------------
 vcl/unx/gtk4/convert3to4.cxx |   22 ++-------------
 2 files changed, 48 insertions(+), 36 deletions(-)

New commits:
commit 49dfd2245b58c5b7e2c2115bb68d5f40289d40fb
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Jun 8 20:32:49 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Jun 9 10:15:17 2021 +0200

    gtk4: implement some more of the menu requirements
    
    just give each radiobutton its own group
    
    Change-Id: I0239a3f1364cde91a668fe890a4178e4ce73f78b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116864
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 470ada586aa2..270f50e17e13 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -9419,9 +9419,6 @@ private:
     {
         clear_actions();
 
-        m_aActionEntries.push_back({"action", action_activated, "s", nullptr, nullptr, {}});
-        m_aInsertedActions.insert("action");
-
         GtkPopover* pPopover = gtk_menu_button_get_popover(m_pMenuButton);
         if (GMenuModel* pMenuModel = GTK_IS_POPOVER_MENU(pPopover) ?
                                      gtk_popover_menu_get_menu_model(GTK_POPOVER_MENU(pPopover)) :
@@ -9442,7 +9439,10 @@ private:
                     {
                         // the const char* arg isn't copied by anything so it must continue to exist for the life time of
                         // the action group
-                        m_aActionEntries.push_back({res.first->getStr(), action_activated, "s", "'none'", nullptr, {}});
+                        if (sAction.startsWith("radio."))
+                            m_aActionEntries.push_back({res.first->getStr(), action_activated, "s", "'none'", nullptr, {}});
+                        else
+                            m_aActionEntries.push_back({res.first->getStr(), action_activated, "s", nullptr, nullptr, {}});
                     }
 
                     g_free(id);
@@ -9606,9 +9606,28 @@ public:
 #if !GTK_CHECK_VERSION(4, 0, 0)
         MenuHelper::insert_item(pos, rId, rStr, pIconName, pImageSurface, eCheckRadioFalse);
 #else
-        // TODO see g_menu_item_set_action_and_target
-        (void)pos; (void)rId; (void) rStr; (void)pIconName; (void)pImageSurface; (void)eCheckRadioFalse;
-        std::abort();
+        (void)pIconName; (void)pImageSurface;
+
+        GtkPopover* pPopover = gtk_menu_button_get_popover(m_pMenuButton);
+        if (GMenuModel* pMenuModel = GTK_IS_POPOVER_MENU(pPopover) ?
+                                     gtk_popover_menu_get_menu_model(GTK_POPOVER_MENU(pPopover)) :
+                                     nullptr)
+        {
+            GMenu* pMenu = G_MENU(pMenuModel);
+            // action with a target value ... the action name and target value are separated by a double
+            // colon ... For example: "app.action::target"
+            OUString sActionAndTarget;
+            if (eCheckRadioFalse == TRISTATE_INDET)
+                sActionAndTarget = "menu.normal." + rId + "::" + rId;
+            else
+                sActionAndTarget = "menu.radio." + rId + "::" + rId;
+            g_menu_insert(pMenu, pos, MapToGtkAccelerator(rStr).getStr(), sActionAndTarget.toUtf8().getStr());
+
+            assert(eCheckRadioFalse == TRISTATE_INDET); // come back to this later
+
+            // TODO not redo entire group
+            update_action_group_from_popover_model();
+        }
 #endif
     }
 
@@ -9617,8 +9636,17 @@ public:
 #if !GTK_CHECK_VERSION(4, 0, 0)
         MenuHelper::insert_separator(pos, rId);
 #else
-        (void)pos; (void)rId;
-        std::abort();
+        (void)rId;
+
+        GtkPopover* pPopover = gtk_menu_button_get_popover(m_pMenuButton);
+        if (GMenuModel* pMenuModel = GTK_IS_POPOVER_MENU(pPopover) ?
+                                     gtk_popover_menu_get_menu_model(GTK_POPOVER_MENU(pPopover)) :
+                                     nullptr)
+        {
+            GMenu* pMenu = G_MENU(pMenuModel);
+            g_menu_insert(pMenu, pos, "SEPARATOR", "menu.action");
+        }
+
 #endif
     }
 
@@ -9651,12 +9679,8 @@ public:
     virtual void set_item_active(const OString& rIdent, bool bActive) override
     {
 #if GTK_CHECK_VERSION(4, 0, 0)
-        if (bActive)
-        {
-            g_action_group_change_action_state(m_pActionGroup, m_aIdToAction[rIdent].getStr(),
-                                               g_variant_new_string(rIdent.getStr()));
-        }
-        // TODO checkboxes vs radiobuttons
+        g_action_group_change_action_state(m_pActionGroup, m_aIdToAction[rIdent].getStr(),
+                                           g_variant_new_string(bActive ? rIdent.getStr() : "'none'"));
 #else
         MenuHelper::set_item_active(rIdent, bActive);
 #endif
@@ -9665,7 +9689,7 @@ public:
     virtual void set_item_sensitive(const OString& rIdent, bool bSensitive) override
     {
 #if GTK_CHECK_VERSION(4, 0, 0)
-        GAction* pAction = g_action_map_lookup_action(G_ACTION_MAP(m_pActionGroup), rIdent.getStr());
+        GAction* pAction = g_action_map_lookup_action(G_ACTION_MAP(m_pActionGroup), m_aIdToAction[rIdent].getStr());
         g_simple_action_set_enabled(G_SIMPLE_ACTION(pAction), bSensitive);
 #else
         MenuHelper::set_item_sensitive(rIdent, bSensitive);
@@ -9699,8 +9723,9 @@ public:
 #if !GTK_CHECK_VERSION(4, 0, 0)
         MenuHelper::set_item_visible(rIdent, bVisible);
 #else
-        (void)rIdent; (void)bVisible;
-        std::abort();
+        // TODO visibility vs sensitivity
+        GAction* pAction = g_action_map_lookup_action(G_ACTION_MAP(m_pActionGroup), m_aIdToAction[rIdent].getStr());
+        g_simple_action_set_enabled(G_SIMPLE_ACTION(pAction), bVisible);
 #endif
     }
 
@@ -22051,6 +22076,7 @@ weld::Builder* GtkInstance::CreateBuilder(weld::Widget* pParent, const OUString&
         rUIFile != "sfx/ui/documentfontspage.ui" &&
         rUIFile != "sfx/ui/documentinfopage.ui" &&
         rUIFile != "sfx/ui/documentpropertiesdialog.ui" &&
+        rUIFile != "sfx/ui/inputdialog.ui" &&
         rUIFile != "sfx/ui/querysavedialog.ui" &&
         rUIFile != "sfx/ui/licensedialog.ui" &&
         rUIFile != "sfx/ui/linefragment.ui" &&
diff --git a/vcl/unx/gtk4/convert3to4.cxx b/vcl/unx/gtk4/convert3to4.cxx
index 46f5c831b828..53c39853b9f7 100644
--- a/vcl/unx/gtk4/convert3to4.cxx
+++ b/vcl/unx/gtk4/convert3to4.cxx
@@ -127,13 +127,10 @@ void AddBorderAsMargins(const css::uno::Reference<css::xml::dom::XNode>& xNode,
 struct MenuEntry
 {
     bool m_bDrawAsRadio;
-    OUString m_sRadioGroup;
     css::uno::Reference<css::xml::dom::XNode> m_xPropertyLabel;
 
-    MenuEntry(bool bDrawAsRadio, const OUString& rRadioGroup,
-              const css::uno::Reference<css::xml::dom::XNode>& rPropertyLabel)
+    MenuEntry(bool bDrawAsRadio, const css::uno::Reference<css::xml::dom::XNode>& rPropertyLabel)
         : m_bDrawAsRadio(bDrawAsRadio)
-        , m_sRadioGroup(rRadioGroup)
         , m_xPropertyLabel(rPropertyLabel)
     {
     }
@@ -143,7 +140,6 @@ MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu,
                       const css::uno::Reference<css::xml::dom::XNode>& xNode)
 {
     bool bDrawAsRadio = false;
-    OUString sRadioGroup;
     css::uno::Reference<css::xml::dom::XNode> xPropertyLabel;
 
     css::uno::Reference<css::xml::dom::XNode> xChild = xNode->getFirstChild();
@@ -163,22 +159,16 @@ MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu,
             {
                 bDrawAsRadio = toBool(xChild->getFirstChild()->getNodeValue());
             }
-            else if (sName == "group")
-            {
-                sRadioGroup = xChild->getFirstChild()->getNodeValue();
-            }
         }
 
         auto xNextChild = xChild->getNextSibling();
 
         bool bChildDrawAsRadio = false;
-        OUString sChildRadioGroup;
         css::uno::Reference<css::xml::dom::XNode> xChildPropertyLabel;
         if (xChild->hasChildNodes())
         {
             MenuEntry aEntry = ConvertMenu(xMenu, xChild);
             bChildDrawAsRadio = aEntry.m_bDrawAsRadio;
-            sChildRadioGroup = aEntry.m_sRadioGroup;
             xChildPropertyLabel = aEntry.m_xPropertyLabel;
         }
 
@@ -236,13 +226,9 @@ MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu,
                 xActionName->setValue("action");
                 xActionAttr->setAttributeNode(xActionName);
                 if (bChildDrawAsRadio)
-                {
-                    if (sChildRadioGroup.isEmpty())
-                        sChildRadioGroup = sId;
-                    xActionAttr->appendChild(xDoc->createTextNode("menu." + sChildRadioGroup));
-                }
+                    xActionAttr->appendChild(xDoc->createTextNode("menu.radio." + sId));
                 else
-                    xActionAttr->appendChild(xDoc->createTextNode("menu.action"));
+                    xActionAttr->appendChild(xDoc->createTextNode("menu.normal." + sId));
                 xItem->appendChild(xActionAttr);
 
                 css::uno::Reference<css::xml::dom::XElement> xTargetAttr
@@ -259,7 +245,7 @@ MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu,
         xChild = xNextChild;
     }
 
-    return MenuEntry(bDrawAsRadio, sRadioGroup, xPropertyLabel);
+    return MenuEntry(bDrawAsRadio, xPropertyLabel);
 }
 
 struct ConvertResult


More information about the Libreoffice-commits mailing list