1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_basctl.hxx" 30 #include "dlgedclip.hxx" 31 #include <vos/mutex.hxx> 32 #include <vcl/svapp.hxx> 33 #include <comphelper/processfactory.hxx> 34 #include <com/sun/star/datatransfer/XMimeContentType.hpp> 35 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp> 36 37 38 using namespace comphelper; 39 using namespace ::com::sun::star; 40 using namespace ::com::sun::star::uno; 41 using namespace ::com::sun::star::io; 42 using namespace ::com::sun::star::datatransfer; 43 using namespace ::com::sun::star::datatransfer::clipboard; 44 45 46 //---------------------------------------------------------------------------- 47 48 DlgEdTransferableImpl::DlgEdTransferableImpl( const Sequence< DataFlavor >& aSeqFlavors, const Sequence< Any >& aSeqData ) 49 { 50 m_SeqFlavors = aSeqFlavors; 51 m_SeqData = aSeqData; 52 } 53 54 //---------------------------------------------------------------------------- 55 56 DlgEdTransferableImpl::~DlgEdTransferableImpl() 57 { 58 } 59 60 //---------------------------------------------------------------------------- 61 62 sal_Bool DlgEdTransferableImpl::compareDataFlavors( const DataFlavor& lFlavor, const DataFlavor& rFlavor ) 63 { 64 sal_Bool bRet = sal_False; 65 66 // compare mime content types 67 Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory(); 68 Reference< datatransfer::XMimeContentTypeFactory > 69 xMCntTypeFactory( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.MimeContentTypeFactory" ) ) ), UNO_QUERY ); 70 71 if ( xMCntTypeFactory.is( ) ) 72 { 73 // compare full media types 74 Reference< datatransfer::XMimeContentType > xLType = xMCntTypeFactory->createMimeContentType( lFlavor.MimeType ); 75 Reference< datatransfer::XMimeContentType > xRType = xMCntTypeFactory->createMimeContentType( rFlavor.MimeType ); 76 77 ::rtl::OUString aLFullMediaType = xLType->getFullMediaType(); 78 ::rtl::OUString aRFullMediaType = xRType->getFullMediaType(); 79 80 bRet = aLFullMediaType.equalsIgnoreAsciiCase( aRFullMediaType ); 81 } 82 83 return bRet; 84 } 85 86 // XTransferable 87 //---------------------------------------------------------------------------- 88 89 Any SAL_CALL DlgEdTransferableImpl::getTransferData( const DataFlavor& rFlavor ) throw(UnsupportedFlavorException, IOException, RuntimeException) 90 { 91 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 92 93 if ( !isDataFlavorSupported( rFlavor ) ) 94 throw UnsupportedFlavorException(); 95 96 Any aData; 97 98 for ( sal_Int32 i = 0; i < m_SeqFlavors.getLength(); i++ ) 99 { 100 if ( compareDataFlavors( m_SeqFlavors[i] , rFlavor ) ) 101 { 102 aData = m_SeqData[i]; 103 break; 104 } 105 } 106 107 return aData; 108 } 109 110 //---------------------------------------------------------------------------- 111 112 Sequence< DataFlavor > SAL_CALL DlgEdTransferableImpl::getTransferDataFlavors( ) throw(RuntimeException) 113 { 114 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 115 116 return m_SeqFlavors; 117 } 118 119 //---------------------------------------------------------------------------- 120 121 sal_Bool SAL_CALL DlgEdTransferableImpl::isDataFlavorSupported( const DataFlavor& rFlavor ) throw(RuntimeException) 122 { 123 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 124 125 sal_Bool bRet = sal_False; 126 127 for ( sal_Int32 i = 0; i < m_SeqFlavors.getLength(); i++ ) 128 { 129 if ( compareDataFlavors( m_SeqFlavors[i] , rFlavor ) ) 130 { 131 bRet = sal_True; 132 break; 133 } 134 } 135 136 return bRet; 137 } 138 139 // XClipboardOwner 140 //---------------------------------------------------------------------------- 141 142 void SAL_CALL DlgEdTransferableImpl::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& ) throw(RuntimeException) 143 { 144 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 145 146 m_SeqFlavors = Sequence< DataFlavor >(); 147 m_SeqData = Sequence< Any >(); 148 } 149 150