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 "dlgedclip.hxx"
21 #include <osl/mutex.hxx>
22 #include <vcl/svapp.hxx>
23 #include <comphelper/processfactory.hxx>
24 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
25 #include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
30 using namespace comphelper
;
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::io
;
34 using namespace ::com::sun::star::datatransfer
;
35 using namespace ::com::sun::star::datatransfer::clipboard
;
36 DlgEdTransferableImpl::DlgEdTransferableImpl( const Sequence
< DataFlavor
>& aSeqFlavors
, const Sequence
< Any
>& aSeqData
)
38 m_SeqFlavors
= aSeqFlavors
;
41 DlgEdTransferableImpl::~DlgEdTransferableImpl()
44 bool DlgEdTransferableImpl::compareDataFlavors( const DataFlavor
& lFlavor
, const DataFlavor
& rFlavor
)
46 // compare mime content types
47 Reference
< uno::XComponentContext
> xContext
= getProcessComponentContext();
48 Reference
< datatransfer::XMimeContentTypeFactory
>
49 xMCntTypeFactory
= MimeContentTypeFactory::create(xContext
);;
51 // compare full media types
52 Reference
< datatransfer::XMimeContentType
> xLType
= xMCntTypeFactory
->createMimeContentType( lFlavor
.MimeType
);
53 Reference
< datatransfer::XMimeContentType
> xRType
= xMCntTypeFactory
->createMimeContentType( rFlavor
.MimeType
);
55 OUString aLFullMediaType
= xLType
->getFullMediaType();
56 OUString aRFullMediaType
= xRType
->getFullMediaType();
58 bool bRet
= aLFullMediaType
.equalsIgnoreAsciiCase( aRFullMediaType
);
64 Any SAL_CALL
DlgEdTransferableImpl::getTransferData( const DataFlavor
& rFlavor
) throw(UnsupportedFlavorException
, IOException
, RuntimeException
, std::exception
)
66 const SolarMutexGuard aGuard
;
68 if ( !isDataFlavorSupported( rFlavor
) )
69 throw UnsupportedFlavorException();
73 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
75 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
84 Sequence
< DataFlavor
> SAL_CALL
DlgEdTransferableImpl::getTransferDataFlavors( ) throw(RuntimeException
, std::exception
)
86 const SolarMutexGuard aGuard
;
90 sal_Bool SAL_CALL
DlgEdTransferableImpl::isDataFlavorSupported( const DataFlavor
& rFlavor
) throw(RuntimeException
, std::exception
)
92 const SolarMutexGuard aGuard
;
94 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
95 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
101 void SAL_CALL
DlgEdTransferableImpl::lostOwnership( const Reference
< XClipboard
>&, const Reference
< XTransferable
>& ) throw(RuntimeException
, std::exception
)
103 const SolarMutexGuard aGuard
;
105 m_SeqFlavors
= Sequence
< DataFlavor
>();
106 m_SeqData
= Sequence
< Any
>();
108 } // namespace basctl
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */