vcl/unx/gtk3/gtkinst.cxx |   57 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 4 deletions(-)

New commits:
commit 4ac6cea4be724ade2e3ab672ff7443af82174ea0
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Jun 3 16:20:59 2021 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Jun 3 21:09:47 2021 +0200

    gtk4: transform always-show-image into a GtkBox child for the GtkButton
    
    and append a GtkLabel child in the GtkBox and move any existing label
    property into it.
    
    Change-Id: Icb5da08409155894d63adde6eb4ce552c1dd7553
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116676
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 22cf2860adc3..3a42aace7132 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -21096,13 +21096,19 @@ struct ConvertResult
     bool m_bChildCanFocus;
     bool m_bHasVisible;
     bool m_bHasIconName;
+    bool m_bAlwaysShowImage;
+    css::uno::Reference<css::xml::dom::XNode> m_xPropertyLabel;
 
     ConvertResult(bool bChildCanFocus,
                   bool bHasVisible,
-                  bool bHasIconName)
+                  bool bHasIconName,
+                  bool bAlwaysShowImage,
+                  const css::uno::Reference<css::xml::dom::XNode>& 
rPropertyLabel)
         : m_bChildCanFocus(bChildCanFocus)
         , m_bHasVisible(bHasVisible)
         , m_bHasIconName(bHasIconName)
+        , m_bAlwaysShowImage(bAlwaysShowImage)
+        , m_xPropertyLabel(rPropertyLabel)
     {
     }
 };
@@ -21111,7 +21117,7 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
 {
     css::uno::Reference<css::xml::dom::XNodeList> xNodeList = 
xNode->getChildNodes();
     if (!xNodeList.is())
-        return ConvertResult(false, false, false);
+        return ConvertResult(false, false, false, false, nullptr);
 
     std::vector<css::uno::Reference<css::xml::dom::XNode>> xRemoveList;
 
@@ -21119,6 +21125,8 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
     bool bChildCanFocus = false;
     bool bHasVisible = false;
     bool bHasIconName = false;
+    bool bAlwaysShowImage = false;
+    css::uno::Reference<css::xml::dom::XNode> xPropertyLabel;
     css::uno::Reference<css::xml::dom::XNode> xCantFocus;
 
     css::uno::Reference<css::xml::dom::XNode> xChild = xNode->getFirstChild();
@@ -21189,6 +21197,9 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
                 }
             }
 
+            if (sName == "label")
+                xPropertyLabel = xChild;
+
             if (sName == "visible")
                 bHasVisible = true;
 
@@ -21280,7 +21291,10 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
             {
                 if (GetParentObjectType(xChild) == "GtkButton")
                 {
-                    // TODO add an intermediate container ?
+                    // we will turn always-show-image into a GtkBox child for
+                    // GtkButton and a GtkLabel child for the GtkBox and move
+                    // the label property into it.
+                    bAlwaysShowImage = 
toBool(xChild->getFirstChild()->getNodeValue());
                     xRemoveList.push_back(xChild);
                 }
             }
@@ -21526,6 +21540,8 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
 
         bool bChildHasIconName = false;
         bool bChildHasVisible = false;
+        bool bChildAlwaysShowImage = false;
+        css::uno::Reference<css::xml::dom::XNode> xChildPropertyLabel;
         if (xChild->hasChildNodes())
         {
             auto aChildRes = Convert3To4(xChild);
@@ -21539,6 +21555,8 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
             {
                 bChildHasVisible = aChildRes.m_bHasVisible;
                 bChildHasIconName = aChildRes.m_bHasIconName;
+                bChildAlwaysShowImage = aChildRes.m_bAlwaysShowImage;
+                xChildPropertyLabel = aChildRes.m_xPropertyLabel;
             }
         }
 
@@ -21713,6 +21731,37 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
                 else
                     xChild->appendChild(xVisible);
             }
+
+            if (bChildAlwaysShowImage)
+            {
+                auto xImageCandidateNode = xChild->getLastChild();
+                if (xImageCandidateNode && xImageCandidateNode->getNodeName() 
!= "child")
+                    xImageCandidateNode.clear();
+                if (xImageCandidateNode)
+                    xChild->removeChild(xImageCandidateNode);
+
+                css::uno::Reference<css::xml::dom::XElement> xNewChildNode = 
xDoc->createElement("child");
+                css::uno::Reference<css::xml::dom::XElement> xNewObjectNode = 
xDoc->createElement("object");
+                css::uno::Reference<css::xml::dom::XAttr> xBoxClassName = 
xDoc->createAttribute("class");
+                xBoxClassName->setValue("GtkBox");
+                xNewObjectNode->setAttributeNode(xBoxClassName);
+                xNewChildNode->appendChild(xNewObjectNode);
+
+                xChild->appendChild(xNewChildNode);
+
+                css::uno::Reference<css::xml::dom::XElement> 
xNewLabelChildNode = xDoc->createElement("child");
+                css::uno::Reference<css::xml::dom::XElement> 
xNewChildObjectNode = xDoc->createElement("object");
+                css::uno::Reference<css::xml::dom::XAttr> xLabelClassName = 
xDoc->createAttribute("class");
+                xLabelClassName->setValue("GtkLabel");
+                xNewChildObjectNode->setAttributeNode(xLabelClassName);
+                if (xChildPropertyLabel)
+                    
xNewChildObjectNode->appendChild(xChildPropertyLabel->getParentNode()->removeChild(xChildPropertyLabel));
+                xNewLabelChildNode->appendChild(xNewChildObjectNode);
+
+                if (xImageCandidateNode)
+                    xNewObjectNode->appendChild(xImageCandidateNode);
+                xNewObjectNode->appendChild(xNewLabelChildNode);
+            }
         }
 
         xChild = xNextChild;
@@ -21724,7 +21773,7 @@ ConvertResult Convert3To4(const 
Reference<css::xml::dom::XNode>& xNode)
     for (auto& xRemove : xRemoveList)
         xNode->removeChild(xRemove);
 
-    return ConvertResult(bChildCanFocus, bHasVisible, bHasIconName);
+    return ConvertResult(bChildCanFocus, bHasVisible, bHasIconName, 
bAlwaysShowImage, xPropertyLabel);
 }
 #endif
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to