1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
);
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
)
81 bool bSuccess
= aClipboardData
.GetString( SotClipboardFormatId::STRING
, sContent
);
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
);
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */