include/vcl/builder.hxx       |    3 
 vcl/source/window/builder.cxx |  147 +++++++++++++++++++-----------------------
 2 files changed, 70 insertions(+), 80 deletions(-)

New commits:
commit 73dbd4229b6a73a62ccb2923102d3eede9595ec7
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Sep 20 12:21:05 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Sep 21 09:07:47 2024 +0200

    tdf#130857 Refactor VclBuilder::handlePacking/applyPackingProperties
    
    Instead of doing XML parsing in
    `VclBuilder::applyPackingProperty`, call
    `BuilderBase::collectProperty` in
    `VclBuilder::handlePacking` to get a string map
    of the properties and pass that as a param
    to the renamed `VclBuilder::applyPackingProperties`
    that can then work with the key-value pairs right
    away.
    
    This is one step to split XML parsing out of methods
    that directly work with vcl::Window, in order to
    be able to reuse the logic for other implementations.
    
    (`git show --ignore-space-change` shows the
    "actual" change more clearly.)
    
    Change-Id: If29cbd7a13da2732c46e4a0b0b50d0963525e729
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173714
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 8c2181eef852..216b2f0d814c 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -295,7 +295,8 @@ private:
     VclPtr<vcl::Window> handleObject(vcl::Window *pParent, stringmap 
*pAtkProps, xmlreader::XmlReader &reader, bool bToolbarItem);
 
     void        handlePacking(vcl::Window *pCurrent, vcl::Window *pParent, 
xmlreader::XmlReader &reader);
-    void        applyPackingProperty(vcl::Window *pCurrent, vcl::Window 
*pParent, xmlreader::XmlReader &reader);
+    void applyPackingProperties(vcl::Window* pCurrent, vcl::Window* pParent,
+                                const stringmap& rPackingProperties);
 
     void        insertMenuObject(
                    Menu *pParent,
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 57d6036d1e78..ba8540feb329 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -3780,6 +3780,7 @@ void 
BuilderBase::handleInterfaceDomain(xmlreader::XmlReader& rReader)
 void VclBuilder::handlePacking(vcl::Window *pCurrent, vcl::Window *pParent, 
xmlreader::XmlReader &reader)
 {
     int nLevel = 1;
+    stringmap aPackingProperties;
 
     while(true)
     {
@@ -3796,7 +3797,7 @@ void VclBuilder::handlePacking(vcl::Window *pCurrent, 
vcl::Window *pParent, xmlr
         {
             ++nLevel;
             if (name == "property")
-                applyPackingProperty(pCurrent, pParent, reader);
+                collectProperty(reader, aPackingProperties);
         }
 
         if (res == xmlreader::XmlReader::Result::End)
@@ -3807,11 +3808,12 @@ void VclBuilder::handlePacking(vcl::Window *pCurrent, 
vcl::Window *pParent, xmlr
         if (!nLevel)
             break;
     }
+
+    applyPackingProperties(pCurrent, pParent, aPackingProperties);
 }
 
-void VclBuilder::applyPackingProperty(vcl::Window *pCurrent,
-    vcl::Window *pParent,
-    xmlreader::XmlReader &reader)
+void VclBuilder::applyPackingProperties(vcl::Window* pCurrent, vcl::Window* 
pParent,
+                                        const stringmap& rPackingProperties)
 {
     if (!pCurrent)
         return;
@@ -3822,9 +3824,6 @@ void VclBuilder::applyPackingProperty(vcl::Window 
*pCurrent,
     if (pCurrent == pParent)
         pToolBoxParent = dynamic_cast<ToolBox*>(pParent);
 
-    xmlreader::Span name;
-    int nsId;
-
     if (pCurrent->GetType() == WindowType::SCROLLWINDOW)
     {
         auto aFind = 
m_pVclParserState->m_aRedundantParentWidgets.find(VclPtr<vcl::Window>(pCurrent));
@@ -3835,79 +3834,69 @@ void VclBuilder::applyPackingProperty(vcl::Window 
*pCurrent,
         }
     }
 
-    while (reader.nextAttribute(&nsId, &name))
+    for (auto const& [rKey, rValue] : rPackingProperties)
     {
-        if (name == "name")
+        if (rKey == u"expand"_ustr || rKey == u"resize"_ustr)
         {
-            name = reader.getAttributeValue(false);
-            OUString sKey(name.begin, name.length, RTL_TEXTENCODING_UTF8);
-            sKey = sKey.replace('_', '-');
-            (void)reader.nextItem(
-                xmlreader::XmlReader::Text::Raw, &name, &nsId);
-            OUString sValue(name.begin, name.length, RTL_TEXTENCODING_UTF8);
-
-            if (sKey == u"expand"_ustr || sKey == u"resize"_ustr)
-            {
-                bool bTrue = toBool(sValue);
-                if (pToolBoxParent)
-                    
pToolBoxParent->SetItemExpand(m_pVclParserState->m_nLastToolbarId, bTrue);
-                else
-                    pCurrent->set_expand(bTrue);
-                continue;
-            }
-
+            bool bTrue = toBool(rValue);
             if (pToolBoxParent)
-                continue;
-
-            if (sKey == u"fill"_ustr)
-            {
-                pCurrent->set_fill(toBool(sValue));
-            }
-            else if (sKey == u"pack-type"_ustr)
-            {
-                VclPackType ePackType = (!sValue.isEmpty() && (sValue[0] == 
'e' || sValue[0] == 'E')) ? VclPackType::End : VclPackType::Start;
-                pCurrent->set_pack_type(ePackType);
-            }
-            else if (sKey == u"left-attach"_ustr)
-            {
-                pCurrent->set_grid_left_attach(sValue.toInt32());
-            }
-            else if (sKey == u"top-attach"_ustr)
-            {
-                pCurrent->set_grid_top_attach(sValue.toInt32());
-            }
-            else if (sKey == u"width"_ustr)
-            {
-                pCurrent->set_grid_width(sValue.toInt32());
-            }
-            else if (sKey == u"height"_ustr)
-            {
-                pCurrent->set_grid_height(sValue.toInt32());
-            }
-            else if (sKey == u"padding"_ustr)
-            {
-                pCurrent->set_padding(sValue.toInt32());
-            }
-            else if (sKey == u"position"_ustr)
-            {
-                set_window_packing_position(pCurrent, sValue.toInt32());
-            }
-            else if (sKey == u"secondary"_ustr)
-            {
-                pCurrent->set_secondary(toBool(sValue));
-            }
-            else if (sKey == u"non-homogeneous"_ustr)
-            {
-                pCurrent->set_non_homogeneous(toBool(sValue));
-            }
-            else if (sKey == "homogeneous")
-            {
-                pCurrent->set_non_homogeneous(!toBool(sValue));
-            }
+                
pToolBoxParent->SetItemExpand(m_pVclParserState->m_nLastToolbarId, bTrue);
             else
-            {
-                SAL_WARN_IF(sKey != "shrink", "vcl.builder", "unknown packing: 
" << sKey);
-            }
+                pCurrent->set_expand(bTrue);
+            continue;
+        }
+
+        if (pToolBoxParent)
+            continue;
+
+        if (rKey == u"fill"_ustr)
+        {
+            pCurrent->set_fill(toBool(rValue));
+        }
+        else if (rKey == u"pack-type"_ustr)
+        {
+            VclPackType ePackType = (!rValue.isEmpty() && (rValue[0] == 'e' || 
rValue[0] == 'E')) ? VclPackType::End : VclPackType::Start;
+            pCurrent->set_pack_type(ePackType);
+        }
+        else if (rKey == u"left-attach"_ustr)
+        {
+            pCurrent->set_grid_left_attach(rValue.toInt32());
+        }
+        else if (rKey == u"top-attach"_ustr)
+        {
+            pCurrent->set_grid_top_attach(rValue.toInt32());
+        }
+        else if (rKey == u"width"_ustr)
+        {
+            pCurrent->set_grid_width(rValue.toInt32());
+        }
+        else if (rKey == u"height"_ustr)
+        {
+            pCurrent->set_grid_height(rValue.toInt32());
+        }
+        else if (rKey == u"padding"_ustr)
+        {
+            pCurrent->set_padding(rValue.toInt32());
+        }
+        else if (rKey == u"position"_ustr)
+        {
+            set_window_packing_position(pCurrent, rValue.toInt32());
+        }
+        else if (rKey == u"secondary"_ustr)
+        {
+            pCurrent->set_secondary(toBool(rValue));
+        }
+        else if (rKey == u"non-homogeneous"_ustr)
+        {
+            pCurrent->set_non_homogeneous(toBool(rValue));
+        }
+        else if (rKey == "homogeneous")
+        {
+            pCurrent->set_non_homogeneous(!toBool(rValue));
+        }
+        else
+        {
+            SAL_WARN_IF(rKey != "shrink", "vcl.builder", "unknown packing: " 
<< rKey);
         }
     }
 }
commit f6ab08f6f463975d6651dc3296ec04c67b9151fd
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Sep 20 12:15:30 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Sep 21 09:07:38 2024 +0200

    tdf#130857 VclBuilder: Reduce var scope
    
    Change-Id: I20e48e308b2c25c3b328cc7c30271a05479da22b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173713
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 7369507515c0..57d6036d1e78 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -3779,13 +3779,13 @@ void 
BuilderBase::handleInterfaceDomain(xmlreader::XmlReader& rReader)
 
 void VclBuilder::handlePacking(vcl::Window *pCurrent, vcl::Window *pParent, 
xmlreader::XmlReader &reader)
 {
-    xmlreader::Span name;
-    int nsId;
-
     int nLevel = 1;
 
     while(true)
     {
+        xmlreader::Span name;
+        int nsId;
+
         xmlreader::XmlReader::Result res = reader.nextItem(
             xmlreader::XmlReader::Text::NONE, &name, &nsId);
 

Reply via email to