LibreOffice Module svtools (master) 1
stringtransfer.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
20#include <sal/config.h>
21
22#include <rtl/ref.hxx>
23#include <sot/exchange.hxx>
25#include <utility>
26
27
28namespace svt
29{
30
31
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::datatransfer;
34
35
36 //= OStringTransferable
39 , m_sContent(std::move(aContent))
40 {
41 }
42
44 {
45 AddFormat(SotClipboardFormatId::STRING);
46 }
47
48 void OStringTransferable::SetData(const OUString& rContent)
49 {
50 m_sContent = rContent;
51 ClearFormats(); // invalidate m_aAny so new data will take effect
52 }
53
54 bool OStringTransferable::GetData( const DataFlavor& _rFlavor, const OUString& /*rDestDoc*/ )
55 {
56 SotClipboardFormatId nFormat = SotExchange::GetFormat( _rFlavor );
57 if (SotClipboardFormatId::STRING == nFormat)
58 return SetString( m_sContent );
59
60 return false;
61 }
62
63 //= OStringTransfer
64 void OStringTransfer::CopyString( const OUString& _rContent, vcl::Window* _pWindow )
65 {
66 rtl::Reference<OStringTransferable> pTransferable = new OStringTransferable( _rContent );
67 pTransferable->CopyToClipboard( _pWindow );
68 }
69
70 bool OStringTransfer::PasteString( OUString& _rContent, vcl::Window* _pWindow )
71 {
73
74 // check for a string format
75 const DataFlavorExVector& rFormats = aClipboardData.GetDataFlavorExVector();
76 for (auto const& format : rFormats)
77 {
78 if (SotClipboardFormatId::STRING == format.mnSotId)
79 {
80 OUString sContent;
81 bool bSuccess = aClipboardData.GetString( SotClipboardFormatId::STRING, sContent );
82 _rContent = sContent;
83 return bSuccess;
84 }
85 }
86
87 return false;
88 }
89
90 void OStringTransfer::StartStringDrag( const OUString& _rContent, vcl::Window* _pWindow, sal_Int8 _nDragSourceActions )
91 {
92 rtl::Reference<OStringTransferable> pTransferable = new OStringTransferable( _rContent );
93 pTransferable->StartDrag(_pWindow, _nDragSourceActions);
94 }
95
96} // namespace svt
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
const DataFlavorExVector & GetDataFlavorExVector() const
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
bool SetString(const OUString &rString)
void AddFormat(SotClipboardFormatId nFormat)
static SVT_DLLPUBLIC void StartStringDrag(const OUString &_rContent, vcl::Window *_pWindow, sal_Int8 _nDragSourceActions)
starts dragging a simple string
static SVT_DLLPUBLIC bool PasteString(OUString &_rContent, vcl::Window *_pWindow)
extracts a string from the system clipboard given
static SVT_DLLPUBLIC void CopyString(const OUString &_rContent, vcl::Window *_pWindow)
copies the string given into the system clipboard
OStringTransferable(OUString aContent)
virtual bool GetData(const css::datatransfer::DataFlavor &_rFlavor, const OUString &rDestDoc) override
virtual void AddSupportedFormats() override
void SetData(const OUString &rContent)
::std::vector< DataFlavorEx > DataFlavorExVector
SotClipboardFormatId
signed char sal_Int8