diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-06-11 11:50:16 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-06-11 14:42:55 +0200 |
commit | 0dd193126a60be3324673fdd3992013fc8c42b9e (patch) | |
tree | 600b5a6727b8b17d2cd32768ff00ca8893e10383 /vcl | |
parent | 8ce77cbd706ffd60dfcd79d82779025ef8d6782c (diff) |
gtk4: process sections and submenus of toplevel menumodel
and place initial contents into a section by default
Change-Id: I1e7bb20bf5efb481e4f7ed0f38c8b46c06f7a7d5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117050
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 74 | ||||
-rw-r--r-- | vcl/unx/gtk4/convert3to4.cxx | 6 |
2 files changed, 47 insertions, 33 deletions
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 270f50e17e13..acc35bc28542 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -9413,6 +9413,47 @@ private: #endif #if GTK_CHECK_VERSION(4, 0, 0) + void process_menu_model(GMenuModel* pMenuModel) + { + for (int i = 0, nCount = g_menu_model_get_n_items(pMenuModel); i < nCount; ++i) + { + OString sAction, sTarget; + char *id; + if (g_menu_model_get_item_attribute(pMenuModel, i, "action", "s", &id)) + { + assert(OString(id).startsWith("menu.")); + + sAction = OString(id + 5); + + auto res = m_aInsertedActions.insert(sAction); + if (res.second) + { + // the const char* arg isn't copied by anything so it must continue to exist for the life time of + // the action group + 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); + } + + if (g_menu_model_get_item_attribute(pMenuModel, i, "target", "s", &id)) + { + sTarget = OString(id); + g_free(id); + } + + m_aIdToAction[sTarget] = sAction; + + if (GMenuModel* pSectionModel = g_menu_model_get_item_link(pMenuModel, i, G_MENU_LINK_SECTION)) + process_menu_model(pSectionModel); + if (GMenuModel* pSubMenuModel = g_menu_model_get_item_link(pMenuModel, i, G_MENU_LINK_SUBMENU)) + process_menu_model(pSubMenuModel); + } + } + // build an action group for the menu, "action" is the normal menu entry case // the others are radiogroups void update_action_group_from_popover_model() @@ -9424,38 +9465,7 @@ private: gtk_popover_menu_get_menu_model(GTK_POPOVER_MENU(pPopover)) : nullptr) { - for (int i = 0, nCount = g_menu_model_get_n_items(pMenuModel); i < nCount; ++i) - { - OString sAction, sTarget; - char *id; - if (g_menu_model_get_item_attribute(pMenuModel, i, "action", "s", &id)) - { - assert(OString(id).startsWith("menu.")); - - sAction = OString(id + 5); - - auto res = m_aInsertedActions.insert(sAction); - if (res.second) - { - // the const char* arg isn't copied by anything so it must continue to exist for the life time of - // the action group - 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); - } - - if (g_menu_model_get_item_attribute(pMenuModel, i, "target", "s", &id)) - { - sTarget = OString(id); - g_free(id); - } - - m_aIdToAction[sTarget] = sAction; - } + process_menu_model(pMenuModel); } g_action_map_add_action_entries(G_ACTION_MAP(m_pActionGroup), m_aActionEntries.data(), m_aActionEntries.size(), this); diff --git a/vcl/unx/gtk4/convert3to4.cxx b/vcl/unx/gtk4/convert3to4.cxx index 53c39853b9f7..04f803fc5b61 100644 --- a/vcl/unx/gtk4/convert3to4.cxx +++ b/vcl/unx/gtk4/convert3to4.cxx @@ -1089,7 +1089,11 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode xMenu->setAttributeNode(xIdAttr); xChild->getParentNode()->insertBefore(xMenu, xChild); - ConvertMenu(xMenu, xChild); + css::uno::Reference<css::xml::dom::XElement> xSection + = xDoc->createElement("section"); + xMenu->appendChild(xSection); + + ConvertMenu(xSection, xChild); // now remove GtkMenu contents while (true) |