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 <vcl/svapp.hxx>
22 #include <comphelper/processfactory.hxx>
23 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
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::datatransfer
;
34 using namespace ::com::sun::star::datatransfer::clipboard
;
35 DlgEdTransferableImpl::DlgEdTransferableImpl( const Sequence
< DataFlavor
>& aSeqFlavors
, const Sequence
< Any
>& aSeqData
)
37 m_SeqFlavors
= aSeqFlavors
;
40 DlgEdTransferableImpl::~DlgEdTransferableImpl()
43 bool DlgEdTransferableImpl::compareDataFlavors( const DataFlavor
& lFlavor
, const DataFlavor
& rFlavor
)
45 // compare mime content types
46 Reference
< uno::XComponentContext
> xContext
= getProcessComponentContext();
47 Reference
< datatransfer::XMimeContentTypeFactory
>
48 xMCntTypeFactory
= MimeContentTypeFactory::create(xContext
);
50 // compare full media types
51 Reference
< datatransfer::XMimeContentType
> xLType
= xMCntTypeFactory
->createMimeContentType( lFlavor
.MimeType
);
52 Reference
< datatransfer::XMimeContentType
> xRType
= xMCntTypeFactory
->createMimeContentType( rFlavor
.MimeType
);
54 OUString aLFullMediaType
= xLType
->getFullMediaType();
55 OUString aRFullMediaType
= xRType
->getFullMediaType();
57 bool bRet
= aLFullMediaType
.equalsIgnoreAsciiCase( aRFullMediaType
);
63 Any SAL_CALL
DlgEdTransferableImpl::getTransferData( const DataFlavor
& rFlavor
)
65 const SolarMutexGuard aGuard
;
67 if ( !isDataFlavorSupported( rFlavor
) )
68 throw UnsupportedFlavorException();
72 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
74 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
83 Sequence
< DataFlavor
> SAL_CALL
DlgEdTransferableImpl::getTransferDataFlavors( )
85 const SolarMutexGuard aGuard
;
89 sal_Bool SAL_CALL
DlgEdTransferableImpl::isDataFlavorSupported( const DataFlavor
& rFlavor
)
91 const SolarMutexGuard aGuard
;
93 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
94 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
100 void SAL_CALL
DlgEdTransferableImpl::lostOwnership( const Reference
< XClipboard
>&, const Reference
< XTransferable
>& )
102 const SolarMutexGuard aGuard
;
104 m_SeqFlavors
= Sequence
< DataFlavor
>();
105 m_SeqData
= Sequence
< Any
>();
107 } // namespace basctl
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */