diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-06-11 17:08:05 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-06-11 22:05:19 +0200 |
commit | 0df9c8c3cd16d6485c4486d9c983715b647e7090 (patch) | |
tree | 85e94e9197ed5431854a7cd553c1861ad1afeeb2 | |
parent | 2020fc9c7d2c778e8206dcc891d5a77f92ac951c (diff) |
gtk4: build deeper levels of GMenuModel
Change-Id: Ia2cbe4fdc583d272152b4eaa9da9f9d2ff4af550
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117066
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | vcl/unx/gtk4/convert3to4.cxx | 128 |
1 files changed, 89 insertions, 39 deletions
diff --git a/vcl/unx/gtk4/convert3to4.cxx b/vcl/unx/gtk4/convert3to4.cxx index 04f803fc5b61..1a985877d32f 100644 --- a/vcl/unx/gtk4/convert3to4.cxx +++ b/vcl/unx/gtk4/convert3to4.cxx @@ -136,9 +136,11 @@ struct MenuEntry } }; -MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu, +MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xOutMenu, const css::uno::Reference<css::xml::dom::XNode>& xNode) { + css::uno::Reference<css::xml::dom::XNode> xMenu(xOutMenu); + bool bDrawAsRadio = false; css::uno::Reference<css::xml::dom::XNode> xPropertyLabel; @@ -163,6 +165,45 @@ MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu, auto xNextChild = xChild->getNextSibling(); + auto xCurrentMenu = xMenu; + + if (xChild->getNodeName() == "object") + { + auto xDoc = xChild->getOwnerDocument(); + + css::uno::Reference<css::xml::dom::XNamedNodeMap> xMap = xChild->getAttributes(); + css::uno::Reference<css::xml::dom::XNode> xClass = xMap->getNamedItem("class"); + OUString sClass(xClass->getNodeValue()); + + if (sClass == "GtkMenuItem" || sClass == "GtkRadioMenuItem") + { + /* <item> */ + css::uno::Reference<css::xml::dom::XElement> xItem = xDoc->createElement("item"); + xMenu->appendChild(xItem); + } + else if (sClass == "GtkMenu") + { + xMenu->removeChild(xMenu->getLastChild()); // remove preceding <item> + + css::uno::Reference<css::xml::dom::XElement> xSubMenu + = xDoc->createElement("submenu"); + css::uno::Reference<css::xml::dom::XAttr> xIdAttr = xDoc->createAttribute("id"); + + css::uno::Reference<css::xml::dom::XNode> xId = xMap->getNamedItem("id"); + OUString sId(xId->getNodeValue()); + + xIdAttr->setValue(sId); + xSubMenu->setAttributeNode(xIdAttr); + xMenu->appendChild(xSubMenu); + + css::uno::Reference<css::xml::dom::XElement> xSection + = xDoc->createElement("section"); + xSubMenu->appendChild(xSection); + + xMenu = xSubMenu; + } + } + bool bChildDrawAsRadio = false; css::uno::Reference<css::xml::dom::XNode> xChildPropertyLabel; if (xChild->hasChildNodes()) @@ -174,6 +215,8 @@ MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu, if (xChild->getNodeName() == "object") { + xMenu = xCurrentMenu; + auto xDoc = xChild->getOwnerDocument(); css::uno::Reference<css::xml::dom::XNamedNodeMap> xMap = xChild->getAttributes(); @@ -186,14 +229,11 @@ MenuEntry ConvertMenu(const css::uno::Reference<css::xml::dom::XNode>& xMenu, OUString sId = xId->getNodeValue(); /* - <item> <attribute name='label' translatable='yes'>whatever</attribute> <attribute name='action'>menu.action</attribute> <attribute name='target'>id</attribute> - </item> */ - css::uno::Reference<css::xml::dom::XElement> xItem = xDoc->createElement("item"); - xMenu->appendChild(xItem); + auto xItem = xMenu->getLastChild(); if (xChildPropertyLabel) { @@ -801,6 +841,50 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode auto xNextChild = xChild->getNextSibling(); + if (xChild->getNodeName() == "object") + { + auto xDoc = xChild->getOwnerDocument(); + + css::uno::Reference<css::xml::dom::XNamedNodeMap> xMap = xChild->getAttributes(); + css::uno::Reference<css::xml::dom::XNode> xClass = xMap->getNamedItem("class"); + OUString sClass(xClass->getNodeValue()); + + if (sClass == "GtkMenu") + { + css::uno::Reference<css::xml::dom::XNode> xId = xMap->getNamedItem("id"); + OUString sId(xId->getNodeValue() + "-menu-model"); + + // <menu id='menubar'> + css::uno::Reference<css::xml::dom::XElement> xMenu = xDoc->createElement("menu"); + css::uno::Reference<css::xml::dom::XAttr> xIdAttr = xDoc->createAttribute("id"); + xIdAttr->setValue(sId); + xMenu->setAttributeNode(xIdAttr); + xChild->getParentNode()->insertBefore(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) + { + auto xFirstChild = xChild->getFirstChild(); + if (!xFirstChild.is()) + break; + xChild->removeChild(xFirstChild); + } + + // change to GtkPopoverMenu + xClass->setNodeValue("GtkPopoverMenu"); + + // <property name="menu-model"> + xChild->appendChild(CreateProperty(xDoc, "menu-model", sId)); + xChild->appendChild(CreateProperty(xDoc, "visible", "False")); + } + } + bool bChildHasSymbolicIconName = false; bool bChildHasVisible = false; bool bChildAlwaysShowImage = false; @@ -1077,40 +1161,6 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode auto xVisible = CreateProperty(xDoc, "visible", "False"); insertAsFirstChild(xChild, xVisible); } - else if (sClass == "GtkMenu") - { - css::uno::Reference<css::xml::dom::XNode> xId = xMap->getNamedItem("id"); - OUString sId(xId->getNodeValue() + "-menu-model"); - - // <menu id='menubar'> - css::uno::Reference<css::xml::dom::XElement> xMenu = xDoc->createElement("menu"); - css::uno::Reference<css::xml::dom::XAttr> xIdAttr = xDoc->createAttribute("id"); - xIdAttr->setValue(sId); - xMenu->setAttributeNode(xIdAttr); - xChild->getParentNode()->insertBefore(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) - { - auto xFirstChild = xChild->getFirstChild(); - if (!xFirstChild.is()) - break; - xChild->removeChild(xFirstChild); - } - - // change to GtkPopoverMenu - xClass->setNodeValue("GtkPopoverMenu"); - - // <property name="menu-model"> - xChild->appendChild(CreateProperty(xDoc, "menu-model", sId)); - xChild->appendChild(CreateProperty(xDoc, "visible", "False")); - } // only create the child box for GtkButton/GtkToggleButton if (bChildAlwaysShowImage && sClass != "GtkMenuButton") |