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_editeng.hxx" 30 31 32 #include <eeng_pch.hxx> 33 34 #include <eeobj.hxx> 35 #include <sot/exchange.hxx> 36 #include <sot/formats.hxx> 37 #include <editeng/editeng.hxx> 38 #include <svl/itempool.hxx> 39 #include <vos/mutex.hxx> 40 #include <vcl/svapp.hxx> 41 using namespace ::com::sun::star; 42 43 44 EditDataObject::EditDataObject() 45 { 46 } 47 48 EditDataObject::~EditDataObject() 49 { 50 } 51 52 // uno::XInterface 53 uno::Any EditDataObject::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException) 54 { 55 uno::Any aRet = ::cppu::queryInterface( rType, SAL_STATIC_CAST( datatransfer::XTransferable*, this ) ); 56 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); 57 } 58 59 // datatransfer::XTransferable 60 uno::Any EditDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor ) throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException) 61 { 62 uno::Any aAny; 63 64 sal_uLong nT = SotExchange::GetFormat( rFlavor ); 65 if ( nT == SOT_FORMAT_STRING ) 66 { 67 aAny <<= (::rtl::OUString)GetString(); 68 } 69 else if ( ( nT == SOT_FORMATSTR_ID_EDITENGINE ) || ( nT == SOT_FORMAT_RTF ) ) 70 { 71 // MT 01/2002: No RTF on demand any more: 72 // 1) Was not working, because I had to flush() the clipboard immediately anyway 73 // 2) Don't have the old pool defaults and the StyleSheetPool here. 74 75 SvMemoryStream* pStream = ( nT == SOT_FORMATSTR_ID_EDITENGINE ) ? &GetStream() : &GetRTFStream(); 76 pStream->Seek( STREAM_SEEK_TO_END ); 77 sal_uLong nLen = pStream->Tell(); 78 pStream->Seek(0); 79 80 uno::Sequence< sal_Int8 > aSeq( nLen ); 81 memcpy( aSeq.getArray(), pStream->GetData(), nLen ); 82 aAny <<= aSeq; 83 } 84 else 85 { 86 datatransfer::UnsupportedFlavorException aException; 87 throw( aException ); 88 } 89 90 return aAny; 91 } 92 93 uno::Sequence< datatransfer::DataFlavor > EditDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException) 94 { 95 uno::Sequence< datatransfer::DataFlavor > aDataFlavors(3); 96 SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_EDITENGINE, aDataFlavors.getArray()[0] ); 97 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aDataFlavors.getArray()[1] ); 98 SotExchange::GetFormatDataFlavor( SOT_FORMAT_RTF, aDataFlavors.getArray()[2] ); 99 100 return aDataFlavors; 101 } 102 103 sal_Bool EditDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor ) throw(uno::RuntimeException) 104 { 105 sal_Bool bSupported = sal_False; 106 107 sal_uLong nT = SotExchange::GetFormat( rFlavor ); 108 if ( ( nT == SOT_FORMAT_STRING ) || ( nT == SOT_FORMAT_RTF ) /* || ( nT == SOT_FORMAT_XML ) */ || ( nT == SOT_FORMATSTR_ID_EDITENGINE ) ) 109 bSupported = sal_True; 110 111 return bSupported; 112 } 113