summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-09-20 12:21:05 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2024-09-21 09:07:47 +0200
commit73dbd4229b6a73a62ccb2923102d3eede9595ec7 (patch)
treecbc7597e7919d8b4e18bea85911e6b71efbdaf7a /vcl
parentf6ab08f6f463975d6651dc3296ec04c67b9151fd (diff)
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.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/window/builder.cxx141
1 files changed, 65 insertions, 76 deletions
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);
}
}
}