summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarshan-upadhyay1110 <darshan.upadhyay@collabora.com>2024-03-26 11:36:47 +0530
committerSzymon Kłos <szymon.klos@collabora.com>2024-04-22 13:49:58 +0200
commit5d7910f21e881998f142aef473b27ebfd29eb020 (patch)
tree5a121f39c862868bb9d69d12efe2b7435d841133
parent78cc308511cb334f8bf290d057889cee00426a18 (diff)
Online: send color preview JSON property to onlinecp-24.04.1-3
- Autofilter has submenus like `filter by font color` and `filter by bg color` - to display it's color preview in online we some data from core to identify that it's a color base dialog - this patch will help to add color preview of following Change-Id: I71c4e276f8c6dd35d6d318ce67cedf9c15a91d29 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165298 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r--vcl/source/treelist/svtabbx.cxx45
1 files changed, 45 insertions, 0 deletions
diff --git a/vcl/source/treelist/svtabbx.cxx b/vcl/source/treelist/svtabbx.cxx
index 6f309bb9a85f..feb4f0b2011f 100644
--- a/vcl/source/treelist/svtabbx.cxx
+++ b/vcl/source/treelist/svtabbx.cxx
@@ -35,6 +35,9 @@
#include <svdata.hxx>
#include <memory>
#include <tools/json_writer.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <vcl/filter/PngImageWriter.hxx>
+#include <comphelper/base64.hxx>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::accessibility;
@@ -42,6 +45,29 @@ using namespace ::com::sun::star::accessibility;
constexpr SvLBoxTabFlags MYTABMASK =
SvLBoxTabFlags::ADJUST_RIGHT | SvLBoxTabFlags::ADJUST_LEFT | SvLBoxTabFlags::ADJUST_CENTER | SvLBoxTabFlags::FORCE;
+namespace {
+ OString lcl_extractPngString(const BitmapEx& rImage)
+ {
+ SvMemoryStream aOStm(65535, 65535);
+ // Use fastest compression "1"
+ css::uno::Sequence<css::beans::PropertyValue> aFilterData{
+ comphelper::makePropertyValue("Compression", sal_Int32(1)),
+ };
+ vcl::PngImageWriter aPNGWriter(aOStm);
+ aPNGWriter.setParameters(aFilterData);
+ if (aPNGWriter.write(rImage))
+ {
+ css::uno::Sequence<sal_Int8> aSeq(static_cast<sal_Int8 const*>(aOStm.GetData()),
+ aOStm.Tell());
+ OStringBuffer aBuffer("data:image/png;base64,");
+ ::comphelper::Base64::encode(aBuffer, aSeq);
+ return aBuffer.makeStringAndClear();
+ }
+
+ return ""_ostr;
+ }
+}
+
static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter,
SvTreeListEntry* pEntry,
SvTabListBox* pTabListBox,
@@ -51,6 +77,7 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter,
{
auto aNode = rJsonWriter.startStruct();
+ // DEPRECATED
// simple listbox value
const SvLBoxItem* pIt = pEntry->GetFirstItem(SvLBoxItemType::String);
if (pIt)
@@ -79,6 +106,8 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter,
{
const OUString& rCollapsed = pBmpItem->GetBitmap1().GetStock();
const OUString& rExpanded = pBmpItem->GetBitmap2().GetStock();
+
+ // send identifier only, we will use svg icon
if (!o3tl::trim(rCollapsed).empty() || !o3tl::trim(rExpanded).empty())
{
auto aColumn = rJsonWriter.startStruct();
@@ -87,6 +116,22 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter,
if (!o3tl::trim(rExpanded).empty())
rJsonWriter.put("expanded", rExpanded);
}
+ // custom bitmap - send png
+ else
+ {
+ BitmapEx aCollapsedImage = pBmpItem->GetBitmap1().GetBitmapEx();
+ BitmapEx aExpandedImage = pBmpItem->GetBitmap2().GetBitmapEx();
+ bool bHasCollapsed = !aCollapsedImage.IsEmpty() && !aCollapsedImage.GetSizePixel().IsEmpty();
+ bool bHasExpanded = !aExpandedImage.IsEmpty() && !aExpandedImage.GetSizePixel().IsEmpty();
+ if (bHasCollapsed || bHasExpanded)
+ {
+ auto aColumn = rJsonWriter.startStruct();
+ if (bHasCollapsed)
+ rJsonWriter.put("collapsedimage", lcl_extractPngString(aCollapsedImage));
+ if (bHasExpanded)
+ rJsonWriter.put("collapsedimage", lcl_extractPngString(aExpandedImage));
+ }
+ }
}
}
}