Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svtools/source/misc/stringtransfer.cxx
Line
Count
Source
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
20
#include <sal/config.h>
21
22
#include <rtl/ref.hxx>
23
#include <sot/exchange.hxx>
24
#include <svtools/stringtransfer.hxx>
25
#include <utility>
26
27
28
namespace svt
29
{
30
31
32
    using namespace ::com::sun::star::datatransfer;
33
34
35
    //= OStringTransferable
36
    OStringTransferable::OStringTransferable(OUString aContent)
37
0
        : TransferDataContainer()
38
0
        , m_sContent(std::move(aContent))
39
0
    {
40
0
    }
41
42
    void OStringTransferable::AddSupportedFormats()
43
0
    {
44
0
        AddFormat(SotClipboardFormatId::STRING);
45
0
    }
46
47
    void OStringTransferable::SetData(const OUString& rContent)
48
0
    {
49
0
        m_sContent = rContent;
50
0
        ClearFormats(); // invalidate m_aAny so new data will take effect
51
0
    }
52
53
    bool OStringTransferable::GetData( const DataFlavor& _rFlavor, const OUString& /*rDestDoc*/ )
54
0
    {
55
0
        SotClipboardFormatId nFormat = SotExchange::GetFormat( _rFlavor );
56
0
        if (SotClipboardFormatId::STRING == nFormat)
57
0
            return SetString( m_sContent );
58
59
0
        return false;
60
0
    }
61
62
    //= OStringTransfer
63
    void OStringTransfer::CopyString( const OUString& _rContent, vcl::Window* _pWindow )
64
0
    {
65
0
        rtl::Reference<OStringTransferable> pTransferable = new OStringTransferable( _rContent );
66
0
        pTransferable->CopyToClipboard( _pWindow );
67
0
    }
68
69
    bool OStringTransfer::PasteString( OUString& _rContent, vcl::Window* _pWindow )
70
0
    {
71
0
        TransferableDataHelper aClipboardData = TransferableDataHelper::CreateFromSystemClipboard( _pWindow );
72
73
        // check for a string format
74
0
        const DataFlavorExVector& rFormats = aClipboardData.GetDataFlavorExVector();
75
0
        for (auto const& format : rFormats)
76
0
        {
77
0
            if (SotClipboardFormatId::STRING == format.mnSotId)
78
0
            {
79
0
                OUString sContent;
80
0
                bool bSuccess = aClipboardData.GetString( SotClipboardFormatId::STRING, sContent );
81
0
                _rContent = sContent;
82
0
                return bSuccess;
83
0
            }
84
0
        }
85
86
0
        return false;
87
0
    }
88
89
    void OStringTransfer::StartStringDrag( const OUString& _rContent, vcl::Window* _pWindow, sal_Int8 _nDragSourceActions )
90
0
    {
91
0
        rtl::Reference<OStringTransferable> pTransferable = new OStringTransferable( _rContent );
92
0
        pTransferable->StartDrag(_pWindow, _nDragSourceActions);
93
0
    }
94
95
}   // namespace svt
96
97
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */