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
;
38 //----------------------------------------------------------------------------
40 DlgEdTransferableImpl::DlgEdTransferableImpl( const Sequence
< DataFlavor
>& aSeqFlavors
, const Sequence
< Any
>& aSeqData
)
42 m_SeqFlavors
= aSeqFlavors
;
46 //----------------------------------------------------------------------------
48 DlgEdTransferableImpl::~DlgEdTransferableImpl()
52 //----------------------------------------------------------------------------
54 sal_Bool
DlgEdTransferableImpl::compareDataFlavors( const DataFlavor
& lFlavor
, const DataFlavor
& rFlavor
)
58 // compare mime content types
59 Reference
< uno::XComponentContext
> xContext
= getProcessComponentContext();
60 Reference
< datatransfer::XMimeContentTypeFactory
>
61 xMCntTypeFactory
= MimeContentTypeFactory::create(xContext
);;
63 // compare full media types
64 Reference
< datatransfer::XMimeContentType
> xLType
= xMCntTypeFactory
->createMimeContentType( lFlavor
.MimeType
);
65 Reference
< datatransfer::XMimeContentType
> xRType
= xMCntTypeFactory
->createMimeContentType( rFlavor
.MimeType
);
67 OUString aLFullMediaType
= xLType
->getFullMediaType();
68 OUString aRFullMediaType
= xRType
->getFullMediaType();
70 bRet
= aLFullMediaType
.equalsIgnoreAsciiCase( aRFullMediaType
);
76 //----------------------------------------------------------------------------
78 Any SAL_CALL
DlgEdTransferableImpl::getTransferData( const DataFlavor
& rFlavor
) throw(UnsupportedFlavorException
, IOException
, RuntimeException
)
80 const SolarMutexGuard aGuard
;
82 if ( !isDataFlavorSupported( rFlavor
) )
83 throw UnsupportedFlavorException();
87 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
89 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
99 //----------------------------------------------------------------------------
101 Sequence
< DataFlavor
> SAL_CALL
DlgEdTransferableImpl::getTransferDataFlavors( ) throw(RuntimeException
)
103 const SolarMutexGuard aGuard
;
108 //----------------------------------------------------------------------------
110 sal_Bool SAL_CALL
DlgEdTransferableImpl::isDataFlavorSupported( const DataFlavor
& rFlavor
) throw(RuntimeException
)
112 const SolarMutexGuard aGuard
;
114 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
115 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
121 //----------------------------------------------------------------------------
123 void SAL_CALL
DlgEdTransferableImpl::lostOwnership( const Reference
< XClipboard
>&, const Reference
< XTransferable
>& ) throw(RuntimeException
)
125 const SolarMutexGuard aGuard
;
127 m_SeqFlavors
= Sequence
< DataFlavor
>();
128 m_SeqData
= Sequence
< Any
>();
132 } // namespace basctl
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */