diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-01-08 10:54:14 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-01-14 10:22:43 +0100 |
commit | 26f246c0203b7ee9f92a321f6bd7ed9173b85fc0 (patch) | |
tree | 6b8c4631b041a8bae22cbf418c4958d95b4522f9 | |
parent | 95bddeaa8176ca4c79274632fce24181dcd8bc0a (diff) |
jsdialog: dump IconView
Change-Id: I82df1f5e5f966e764b768044526b3401d55fc394
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108984
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109256
Tested-by: Jenkins
-rw-r--r-- | vcl/inc/iconview.hxx | 1 | ||||
-rw-r--r-- | vcl/source/treelist/iconview.cxx | 59 |
2 files changed, 60 insertions, 0 deletions
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: */ |