Branch libreoffice-5-0-4
[LibreOffice.git] / basctl / source / dlged / dlgedclip.cxx
blob9d042c64049de0a57644d60405f4d44ae2b45039
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 namespace basctl
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;
39 m_SeqData = aSeqData;
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 );
60 return bRet;
63 // XTransferable
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();
71 Any aData;
73 for ( sal_Int32 i = 0; i < m_SeqFlavors.getLength(); i++ )
75 if ( compareDataFlavors( m_SeqFlavors[i] , rFlavor ) )
77 aData = m_SeqData[i];
78 break;
82 return aData;
84 Sequence< DataFlavor > SAL_CALL DlgEdTransferableImpl::getTransferDataFlavors( ) throw(RuntimeException, std::exception)
86 const SolarMutexGuard aGuard;
88 return m_SeqFlavors;
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 ) )
96 return true;
97 return false;
100 // XClipboardOwner
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: */