Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svtools / source / misc / stringtransfer.cxx
blob37470128e5c2f47efc104ec2a3f21fa01fe8635d
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 <sal/config.h>
22 #include <rtl/ref.hxx>
23 #include <sot/exchange.hxx>
24 #include <svtools/stringtransfer.hxx>
25 #include <utility>
28 namespace svt
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::datatransfer;
36 //= OStringTransferable
37 OStringTransferable::OStringTransferable(OUString aContent)
38 : TransferDataContainer()
39 , m_sContent(std::move(aContent))
43 void OStringTransferable::AddSupportedFormats()
45 AddFormat(SotClipboardFormatId::STRING);
48 void OStringTransferable::SetData(const OUString& rContent)
50 m_sContent = rContent;
51 ClearFormats(); // invalidate m_aAny so new data will take effect
54 bool OStringTransferable::GetData( const DataFlavor& _rFlavor, const OUString& /*rDestDoc*/ )
56 SotClipboardFormatId nFormat = SotExchange::GetFormat( _rFlavor );
57 if (SotClipboardFormatId::STRING == nFormat)
58 return SetString( m_sContent );
60 return false;
63 //= OStringTransfer
64 void OStringTransfer::CopyString( const OUString& _rContent, vcl::Window* _pWindow )
66 rtl::Reference<OStringTransferable> pTransferable = new OStringTransferable( _rContent );
67 pTransferable->CopyToClipboard( _pWindow );
70 bool OStringTransfer::PasteString( OUString& _rContent, vcl::Window* _pWindow )
72 TransferableDataHelper aClipboardData = TransferableDataHelper::CreateFromSystemClipboard( _pWindow );
74 // check for a string format
75 const DataFlavorExVector& rFormats = aClipboardData.GetDataFlavorExVector();
76 for (auto const& format : rFormats)
78 if (SotClipboardFormatId::STRING == format.mnSotId)
80 OUString sContent;
81 bool bSuccess = aClipboardData.GetString( SotClipboardFormatId::STRING, sContent );
82 _rContent = sContent;
83 return bSuccess;
87 return false;
90 void OStringTransfer::StartStringDrag( const OUString& _rContent, vcl::Window* _pWindow, sal_Int8 _nDragSourceActions )
92 rtl::Reference<OStringTransferable> pTransferable = new OStringTransferable( _rContent );
93 pTransferable->StartDrag(_pWindow, _nDragSourceActions);
96 } // namespace svt
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */