vcl/inc/iconview.hxx | 1 vcl/source/treelist/iconview.cxx | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
New commits: commit 26f246c0203b7ee9f92a321f6bd7ed9173b85fc0 Author: Szymon Kłos <[email protected]> AuthorDate: Fri Jan 8 10:54:14 2021 +0100 Commit: Szymon Kłos <[email protected]> CommitDate: Thu Jan 14 10:22:43 2021 +0100 jsdialog: dump IconView Change-Id: I82df1f5e5f966e764b768044526b3401d55fc394 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108984 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Szymon Kłos <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109256 Tested-by: Jenkins diff --git a/vcl/inc/iconview.hxx b/vcl/inc/iconview.hxx index f10b0ed8a53e..c1e62bc2ec65 100644 --- a/vcl/inc/iconview.hxx +++ b/vcl/inc/iconview.hxx @@ -35,6 +35,7 @@ public: vcl::RenderContext& rRenderContext); virtual FactoryFunction GetUITestFactory() const override; + virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override; }; #endif diff --git a/vcl/source/treelist/iconview.cxx b/vcl/source/treelist/iconview.cxx index b6dd3da1c40a..7786a6976c2a 100644 --- a/vcl/source/treelist/iconview.cxx +++ b/vcl/source/treelist/iconview.cxx @@ -22,6 +22,11 @@ #include <iconview.hxx> #include "iconviewimpl.hxx" #include <vcl/uitest/uiobject.hxx> +#include <tools/json_writer.hxx> +#include <vcl/toolkit/svlbitm.hxx> +#include <tools/stream.hxx> +#include <vcl/cvtgrf.hxx> +#include <comphelper/base64.hxx> IconView::IconView(vcl::Window* pParent, WinBits nBits) : SvTreeListBox(pParent, nBits) @@ -218,4 +223,58 @@ void IconView::PaintEntry(SvTreeListEntry& rEntry, tools::Long nX, tools::Long n FactoryFunction IconView::GetUITestFactory() const { return IconViewUIObject::create; } +static OUString extractPngString(const SvLBoxContextBmp* pBmpItem) +{ + BitmapEx aImage = pBmpItem->GetBitmap1().GetBitmapEx(); + SvMemoryStream aOStm(65535, 65535); + if (GraphicConverter::Export(aOStm, aImage, ConvertDataFormat::PNG) == ERRCODE_NONE) + { + css::uno::Sequence<sal_Int8> aSeq(static_cast<sal_Int8 const*>(aOStm.GetData()), + aOStm.Tell()); + OUStringBuffer aBuffer("data:image/png;base64,"); + ::comphelper::Base64::encode(aBuffer, aSeq); + return aBuffer.makeStringAndClear(); + } + + return ""; +} + +static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, SvTreeListEntry* pEntry, + SvTreeListBox* pTabListBox) +{ + while (pEntry) + { + auto aNode = rJsonWriter.startStruct(); + + // simple listbox value + const SvLBoxItem* pIt = pEntry->GetFirstItem(SvLBoxItemType::String); + if (pIt) + rJsonWriter.put("text", static_cast<const SvLBoxString*>(pIt)->GetText()); + + pIt = pEntry->GetFirstItem(SvLBoxItemType::ContextBmp); + if (pIt) + { + const SvLBoxContextBmp* pBmpItem = static_cast<const SvLBoxContextBmp*>(pIt); + if (pBmpItem) + rJsonWriter.put("image", extractPngString(pBmpItem)); + } + + if (pTabListBox->IsSelected(pEntry)) + rJsonWriter.put("selected", "true"); + + rJsonWriter.put("row", + OString::number(pTabListBox->GetModel()->GetAbsPos(pEntry)).getStr()); + + pEntry = pEntry->NextSibling(); + } +} + +void IconView::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) +{ + SvTreeListBox::DumpAsPropertyTree(rJsonWriter); + rJsonWriter.put("type", "iconview"); + auto aNode = rJsonWriter.startArray("entries"); + lcl_DumpEntryAndSiblings(rJsonWriter, First(), this); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
