LibreOffice Module vcl (master) 1
htmltransferable.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28#include <boost/property_tree/json_parser.hpp>
29
30using namespace ::com::sun::star;
31
33{
35 : data(sData)
36{
37}
38
40
41// css::uno::XInterface
43{
44 uno::Any aRet = ::cppu::queryInterface(rType, static_cast<datatransfer::XTransferable*>(this));
45 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface(rType));
46}
47
48// css::datatransfer::XTransferable
49uno::Any HtmlTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor)
50{
52 if (nT != SotClipboardFormatId::HTML)
53 {
54 throw datatransfer::UnsupportedFlavorException();
55 }
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);
60}
61
62uno::Sequence<datatransfer::DataFlavor> HtmlTransferable::getTransferDataFlavors()
63{
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;
70}
71
72sal_Bool HtmlTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor)
73{
75 return (nT == SotClipboardFormatId::HTML);
76}
77
78} // namespace vcl::unohelper
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor &aFlavor) override
css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &aFlavor) override
css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override
SotClipboardFormatId
size
bool hasValue()
unsigned char sal_Bool