From 01e37e3e5626551b6e8d261e357afcea1ba7c758 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 22 Jun 2020 16:45:03 +0200 Subject: use tools::JsonWriter for dumping property tree Change-Id: I8f55af19ba10b71bd621e69b27000ab7cb565309 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96677 Tested-by: Jenkins Reviewed-by: Noel Grandin --- vcl/source/app/salvtables.cxx | 2 +- vcl/source/control/button.cxx | 22 ++++++++++----------- vcl/source/control/field.cxx | 24 +++++++++++------------ vcl/source/control/fmtfield.cxx | 16 ++++++---------- vcl/source/control/listbox.cxx | 35 ++++++++++++++++------------------ vcl/source/control/tabctrl.cxx | 27 ++++++++++++-------------- vcl/source/window/layout.cxx | 33 +++++++++++++++----------------- vcl/source/window/toolbox2.cxx | 36 ++++++++++++++--------------------- vcl/source/window/window.cxx | 42 +++++++++++++++-------------------------- 9 files changed, 100 insertions(+), 137 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 9a9484397274..f395d5240182 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -501,7 +501,7 @@ css::uno::Reference SalInstanceWidget::get_ } void SalInstanceWidget::connect_get_property_tree( - const Link& rLink) + const Link& rLink) { m_xWidget->SetDumpAsPropertyTreeHdl(rLink); } diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index afc27c18dd5c..05e8aa46eca7 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -45,6 +45,7 @@ #include #include #include +#include using namespace css; @@ -552,11 +553,10 @@ FactoryFunction Button::GetUITestFactory() const return ButtonUIObject::create; } -boost::property_tree::ptree Button::DumpAsPropertyTree() +void Button::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(Control::DumpAsPropertyTree()); - aTree.put("text", GetText()); - return aTree; + Control::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("text", GetText()); } IMPL_STATIC_LINK( Button, dispatchCommandHandler, Button*, pButton, void ) @@ -2844,11 +2844,10 @@ void RadioButton::ShowFocus(const tools::Rectangle& rRect) Button::ShowFocus(rRect); } -boost::property_tree::ptree RadioButton::DumpAsPropertyTree() +void RadioButton::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(Button::DumpAsPropertyTree()); - aTree.put("checked", IsChecked()); - return aTree; + Button::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("checked", IsChecked()); } FactoryFunction RadioButton::GetUITestFactory() const @@ -3661,11 +3660,10 @@ void CheckBox::ShowFocus(const tools::Rectangle& rRect) Button::ShowFocus(rRect); } -boost::property_tree::ptree CheckBox::DumpAsPropertyTree() +void CheckBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(Button::DumpAsPropertyTree()); - aTree.put("checked", IsChecked()); - return aTree; + Button::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("checked", IsChecked()); } FactoryFunction CheckBox::GetUITestFactory() const diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index d81c3b3e2beb..e7a6472713fa 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -43,6 +43,7 @@ #include #include +#include using namespace ::com::sun::star; using namespace ::comphelper; @@ -871,12 +872,11 @@ void NumericField::Last() SpinField::Last(); } -boost::property_tree::ptree NumericField::DumpAsPropertyTree() +void NumericField::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(SpinField::DumpAsPropertyTree()); - aTree.put("min", GetMin()); - aTree.put("max", GetMax()); - return aTree; + SpinField::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("min", GetMin()); + rJsonWriter.put("max", GetMax()); } namespace @@ -1712,17 +1712,15 @@ void MetricField::Last() SpinField::Last(); } -boost::property_tree::ptree MetricField::DumpAsPropertyTree() +void MetricField::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(SpinField::DumpAsPropertyTree()); - aTree.put("min", GetMin()); - aTree.put("max", GetMax()); - aTree.put("unit", FieldUnitToString(GetUnit())); + SpinField::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("min", GetMin()); + rJsonWriter.put("max", GetMax()); + rJsonWriter.put("unit", FieldUnitToString(GetUnit())); OUString sValue = Application::GetSettings().GetNeutralLocaleDataWrapper(). getNum(GetValue(), GetDecimalDigits(), false, false); - aTree.put("value", sValue.toUtf8().getStr()); - - return aTree; + rJsonWriter.put("value", sValue); } FactoryFunction MetricField::GetUITestFactory() const diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx index 87ff8b7b68c9..c00a721250dc 100644 --- a/vcl/source/control/fmtfield.cxx +++ b/vcl/source/control/fmtfield.cxx @@ -38,6 +38,7 @@ #include #include #include +#include using namespace ::com::sun::star::lang; using namespace ::com::sun::star::util; @@ -1091,17 +1092,12 @@ void FormattedField::UseInputStringForFormatting() m_bUseInputStringForFormatting = true; } -boost::property_tree::ptree FormattedField::DumpAsPropertyTree() +void FormattedField::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(SpinField::DumpAsPropertyTree()); - aTree.put("min", rtl::math::doubleToString(GetMinValue(), - rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr()); - aTree.put("max", rtl::math::doubleToString(GetMaxValue(), - rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr()); - aTree.put("value", rtl::math::doubleToString(GetValue(), - rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr()); - - return aTree; + SpinField::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("min", GetMinValue()); + rJsonWriter.put("max", GetMaxValue()); + rJsonWriter.put("value", GetValue()); } FactoryFunction FormattedField::GetUITestFactory() const diff --git a/vcl/source/control/listbox.cxx b/vcl/source/control/listbox.cxx index 9b3cb51c1248..fc7806d732a7 100644 --- a/vcl/source/control/listbox.cxx +++ b/vcl/source/control/listbox.cxx @@ -33,6 +33,7 @@ #include #include +#include ListBox::ListBox(WindowType nType) : Control(nType) @@ -1394,33 +1395,29 @@ FactoryFunction ListBox::GetUITestFactory() const return ListBoxUIObject::create; } -boost::property_tree::ptree ListBox::DumpAsPropertyTree() +void ListBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(Control::DumpAsPropertyTree()); - boost::property_tree::ptree aEntries; + Control::DumpAsPropertyTree(rJsonWriter); - for (int i = 0; i < GetEntryCount(); ++i) { - boost::property_tree::ptree aEntry; - aEntry.put("", GetEntry(i)); - aEntries.push_back(std::make_pair("", aEntry)); + auto entriesNode = rJsonWriter.startNode("entries"); + for (int i = 0; i < GetEntryCount(); ++i) + { + auto entryNode = rJsonWriter.startNode(""); + rJsonWriter.put("", GetEntry(i)); + } } - aTree.add_child("entries", aEntries); + rJsonWriter.put("selectedCount", GetSelectedEntryCount()); - boost::property_tree::ptree aSelected; - - for (int i = 0; i < GetSelectedEntryCount(); ++i) { - boost::property_tree::ptree aEntry; - aEntry.put("", GetSelectedEntryPos(i)); - aSelected.push_back(std::make_pair("", aEntry)); + auto entriesNode = rJsonWriter.startNode("selectedEntries"); + for (int i = 0; i < GetSelectedEntryCount(); ++i) + { + auto entryNode = rJsonWriter.startNode(""); + rJsonWriter.put("", GetSelectedEntryPos(i)); + } } - - aTree.put("selectedCount", GetSelectedEntryCount()); - aTree.add_child("selectedEntries", aSelected); - - return aTree; } MultiListBox::MultiListBox( vcl::Window* pParent, WinBits nStyle ) : diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx index 0afb0008c9d3..728e4c379858 100644 --- a/vcl/source/control/tabctrl.cxx +++ b/vcl/source/control/tabctrl.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -2160,24 +2161,20 @@ FactoryFunction TabControl::GetUITestFactory() const return TabControlUIObject::create; } -boost::property_tree::ptree TabControl::DumpAsPropertyTree() +void TabControl::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree = Control::DumpAsPropertyTree(); - - boost::property_tree::ptree aTabs; - for(auto id : GetPageIDs()) + Control::DumpAsPropertyTree(rJsonWriter); { - boost::property_tree::ptree aTab; - aTab.put("text", GetPageText(id)); - aTab.put("id", id); - aTab.put("name", GetPageName(id)); - aTabs.push_back(std::make_pair("", aTab)); + auto tabsNode = rJsonWriter.startNode("tabs"); + for(auto id : GetPageIDs()) + { + auto tabNode = rJsonWriter.startNode(""); + rJsonWriter.put("text", GetPageText(id)); + rJsonWriter.put("id", id); + rJsonWriter.put("name", GetPageName(id)); + } } - - aTree.add_child("tabs", aTabs); - aTree.put("selected", GetCurPageId()); - - return aTree; + rJsonWriter.put("selected", GetCurPageId()); } sal_uInt16 NotebookbarTabControlBase::m_nHeaderHeight = 0; diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index af7208c52cb8..f09563fddaad 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -27,6 +27,7 @@ #include #include #include +#include VclContainer::VclContainer(vcl::Window *pParent, WinBits nStyle) : Window(WindowType::CONTAINER) @@ -360,11 +361,10 @@ bool VclBox::set_property(const OString &rKey, const OUString &rValue) return true; } -boost::property_tree::ptree VclBox::DumpAsPropertyTree() +void VclBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(VclContainer::DumpAsPropertyTree()); - aTree.put("vertical", m_bVerticalContainer); - return aTree; + VclContainer::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("vertical", m_bVerticalContainer); } sal_uInt16 VclBox::getDefaultAccessibleRole() const @@ -1308,11 +1308,10 @@ void VclGrid::setAllocation(const Size& rAllocation) } } -boost::property_tree::ptree VclGrid::DumpAsPropertyTree() +void VclGrid::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(VclContainer::DumpAsPropertyTree()); - aTree.put("type", "grid"); - return aTree; + VclContainer::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("type", "grid"); } bool toBool(const OUString &rValue) @@ -1493,11 +1492,10 @@ OUString VclFrame::getDefaultAccessibleName() const return VclBin::getDefaultAccessibleName(); } -boost::property_tree::ptree VclFrame::DumpAsPropertyTree() +void VclFrame::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(VclBin::DumpAsPropertyTree()); - aTree.put("type", "frame"); - return aTree; + VclBin::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("type", "frame"); } Size VclAlignment::calculateRequisition() const @@ -2855,25 +2853,24 @@ VclScrolledWindow::~VclScrolledWindow() disposeOnce(); } -boost::property_tree::ptree VclDrawingArea::DumpAsPropertyTree() +void VclDrawingArea::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(Control::DumpAsPropertyTree()); - aTree.put("type", "drawingarea"); + Control::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("type", "drawingarea"); + ScopedVclPtrInstance pDevice; pDevice->SetOutputSize( GetSizePixel() ); tools::Rectangle aRect(Point(0,0), GetSizePixel()); Paint(*pDevice, aRect); BitmapEx aImage = pDevice->GetBitmapEx( Point(0,0), GetSizePixel() ); SvMemoryStream aOStm(65535, 65535); - if(GraphicConverter::Export(aOStm, aImage, ConvertDataFormat::PNG) == ERRCODE_NONE) { css::uno::Sequence aSeq( static_cast(aOStm.GetData()), aOStm.Tell()); OUStringBuffer aBuffer("data:image/png;base64,"); ::comphelper::Base64::encode(aBuffer, aSeq); - aTree.put("image", aBuffer.makeStringAndClear()); + rJsonWriter.put("image", aBuffer.makeStringAndClear()); } - return aTree; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index 3d1bcd7d1739..6ee94e7b0ae5 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -39,6 +39,7 @@ #include #include +#include using namespace vcl; @@ -1745,34 +1746,25 @@ void ToolBox::WillUsePopupMode( bool b ) mpData->mbWillUsePopupMode = b; } -boost::property_tree::ptree ToolBox::DumpAsPropertyTree() +void ToolBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aTree(DockingWindow::DumpAsPropertyTree()); - boost::property_tree::ptree aChildren; + DockingWindow::DumpAsPropertyTree(rJsonWriter); - boost::property_tree::ptree::const_assoc_iterator found = aTree.find("children"); - if (found == aTree.not_found()) + auto childrenNode = rJsonWriter.startNode("children"); + for (ToolBox::ImplToolItems::size_type i = 0; i < GetItemCount(); ++i) { - for (ToolBox::ImplToolItems::size_type i = 0; i < GetItemCount(); ++i) + ToolBoxItemType type = GetItemType(i); + if (type == ToolBoxItemType::BUTTON) { - ToolBoxItemType type = GetItemType(i); - if (type == ToolBoxItemType::BUTTON) - { - boost::property_tree::ptree aEntry; - int nId = GetItemId(i); - if (!IsItemVisible(nId)) - continue; - aEntry.put("type", "toolitem"); - aEntry.put("text", GetItemText(nId)); - aEntry.put("command", GetItemCommand(nId)); - aChildren.push_back(std::make_pair("", aEntry)); - } + auto childNode = rJsonWriter.startNode(""); + int nId = GetItemId(i); + if (!IsItemVisible(nId)) + continue; + rJsonWriter.put("type", "toolitem"); + rJsonWriter.put("text", GetItemText(nId)); + rJsonWriter.put("command", GetItemCommand(nId)); } - - aTree.add_child("children", aChildren); } - - return aTree; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index c3baf5e6547c..e1c498de28ac 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -1768,7 +1769,7 @@ void Window::ImplNewInputContext() pFocusWin->ImplGetFrame()->SetInputContext( &aNewContext ); } -void Window::SetDumpAsPropertyTreeHdl(const Link& rLink) +void Window::SetDumpAsPropertyTreeHdl(const Link& rLink) { if (mpWindowImpl) // may be called after dispose { @@ -3380,47 +3381,34 @@ const char* windowTypeName(WindowType nWindowType) } -boost::property_tree::ptree Window::DumpAsPropertyTree() +void Window::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { - // This is for the code in sc/source/ui/sidebar/AlignmentPropertyPanel.cxx. - // Also see commit f27c6320e8496d690b5d341d3718430709263a1c - // "lok: remove complex rotation / alignment settings" - if (get_id() == "textorientbox") { - return boost::property_tree::ptree(); - } - - boost::property_tree::ptree aTree; - aTree.put("id", get_id()); // TODO could be missing - sort out - aTree.put("type", windowTypeName(GetType())); - aTree.put("text", GetText()); - aTree.put("enabled", IsEnabled()); + rJsonWriter.put("id", get_id()); // TODO could be missing - sort out + rJsonWriter.put("type", windowTypeName(GetType())); + rJsonWriter.put("text", GetText()); + rJsonWriter.put("enabled", IsEnabled()); - boost::property_tree::ptree aChildren; if (vcl::Window* pChild = mpWindowImpl->mpFirstChild) { + auto childrenNode = rJsonWriter.startNode("children"); while (pChild) { if (pChild->IsVisible()) { - boost::property_tree::ptree aSubTree = pChild->DumpAsPropertyTree(); - int nLeft = pChild->get_grid_left_attach(); - int nTop = pChild->get_grid_top_attach(); + auto childNode = rJsonWriter.startNode(""); + pChild->DumpAsPropertyTree(rJsonWriter); + sal_Int32 nLeft = pChild->get_grid_left_attach(); + sal_Int32 nTop = pChild->get_grid_top_attach(); if (nLeft != -1 && nTop != -1) { - OUString sLeft = OUString::number(nLeft); - OUString sTop = OUString::number(nTop); - aSubTree.put("left", sLeft); - aSubTree.put("top", sTop); + rJsonWriter.put("left", nLeft); + rJsonWriter.put("top", nTop); } - aChildren.push_back(std::make_pair("", aSubTree)); } pChild = pChild->mpWindowImpl->mpNext; } - aTree.add_child("children", aChildren); } - mpWindowImpl->maDumpAsPropertyTreeHdl.Call(aTree); - - return aTree; + mpWindowImpl->maDumpAsPropertyTreeHdl.Call(rJsonWriter); } void Window::ImplCallDeactivateListeners( vcl::Window *pNew ) -- cgit v1.2.3