bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / app / htmltransferable.cxx
blob24f65fe929b1ac7cb839c6dbbf0bb32760f17d62
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/htmltransferable.hxx>
21 #include <sot/exchange.hxx>
22 #include <sot/formats.hxx>
23 #include <vcl/svapp.hxx>
24 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
25 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <boost/property_tree/json_parser.hpp>
30 using namespace ::com::sun::star;
32 namespace vcl::unohelper
34 HtmlTransferable::HtmlTransferable(OString sData)
35 : data(sData)
39 HtmlTransferable::~HtmlTransferable() {}
41 // css::uno::XInterface
42 uno::Any HtmlTransferable::queryInterface(const uno::Type& rType)
44 uno::Any aRet = ::cppu::queryInterface(rType, static_cast<datatransfer::XTransferable*>(this));
45 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface(rType));
48 // css::datatransfer::XTransferable
49 uno::Any HtmlTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor)
51 SotClipboardFormatId nT = SotExchange::GetFormat(rFlavor);
52 if (nT != SotClipboardFormatId::HTML)
54 throw datatransfer::UnsupportedFlavorException();
56 size_t size = data.getLength();
57 uno::Sequence<sal_Int8> sData(size);
58 std::memcpy(sData.getArray(), data.getStr(), size);
59 return uno::Any(sData);
62 uno::Sequence<datatransfer::DataFlavor> HtmlTransferable::getTransferDataFlavors()
64 uno::Sequence<datatransfer::DataFlavor> aDataFlavors(1);
65 auto ref = aDataFlavors.getArray()[0];
66 ref.MimeType = "text/html";
67 ref.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get();
68 SotExchange::GetFormatDataFlavor(SotClipboardFormatId::HTML, aDataFlavors.getArray()[0]);
69 return aDataFlavors;
72 sal_Bool HtmlTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor)
74 SotClipboardFormatId nT = SotExchange::GetFormat(rFlavor);
75 return (nT == SotClipboardFormatId::HTML);
78 } // namespace vcl::unohelper