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 <sot/exchange.hxx>
23 #include <svtools/stringtransfer.hxx>
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::datatransfer
;
34 //= OStringTransferable
37 OStringTransferable::OStringTransferable(const OUString
& _rContent
)
39 ,m_sContent( _rContent
)
44 void OStringTransferable::AddSupportedFormats()
46 AddFormat(SotClipboardFormatId::STRING
);
50 bool OStringTransferable::GetData( const DataFlavor
& _rFlavor
, const OUString
& /*rDestDoc*/ )
52 SotClipboardFormatId nFormat
= SotExchange::GetFormat( _rFlavor
);
53 if (SotClipboardFormatId::STRING
== nFormat
)
54 return SetString( m_sContent
, _rFlavor
);
63 void OStringTransfer::CopyString( const OUString
& _rContent
, vcl::Window
* _pWindow
)
65 OStringTransferable
* pTransferable
= new OStringTransferable( _rContent
);
66 Reference
< XTransferable
> xTransfer
= pTransferable
;
67 pTransferable
->CopyToClipboard( _pWindow
);
71 bool OStringTransfer::PasteString( OUString
& _rContent
, vcl::Window
* _pWindow
)
73 TransferableDataHelper aClipboardData
= TransferableDataHelper::CreateFromSystemClipboard( _pWindow
);
75 // check for a string format
76 const DataFlavorExVector
& rFormats
= aClipboardData
.GetDataFlavorExVector();
77 for ( DataFlavorExVector::const_iterator aSearch
= rFormats
.begin();
78 aSearch
!= rFormats
.end();
82 if (SotClipboardFormatId::STRING
== aSearch
->mnSotId
)
85 bool bSuccess
= aClipboardData
.GetString( SotClipboardFormatId::STRING
, sContent
);
95 void OStringTransfer::StartStringDrag( const OUString
& _rContent
, vcl::Window
* _pWindow
, sal_Int8 _nDragSourceActions
)
97 OStringTransferable
* pTransferable
= new OStringTransferable( _rContent
);
98 Reference
< XTransferable
> xTransfer
= pTransferable
;
99 pTransferable
->StartDrag(_pWindow
, _nDragSourceActions
);
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */