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_vcl.hxx" 30 #include <vcl/unohelp2.hxx> 31 #include <sot/exchange.hxx> 32 #include <sot/formats.hxx> 33 #include <tools/debug.hxx> 34 #include <vcl/svapp.hxx> 35 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 36 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> 37 38 39 using namespace ::com::sun::star; 40 41 namespace vcl { namespace unohelper { 42 43 TextDataObject::TextDataObject( const String& rText ) : maText( rText ) 44 { 45 } 46 47 TextDataObject::~TextDataObject() 48 { 49 } 50 51 void TextDataObject::CopyStringTo( const String& rContent, 52 const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard ) 53 { 54 DBG_ASSERT( rxClipboard.is(), "TextDataObject::CopyStringTo: invalid clipboard!" ); 55 if ( !rxClipboard.is() ) 56 return; 57 58 TextDataObject* pDataObj = new TextDataObject( rContent ); 59 60 const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 61 try 62 { 63 rxClipboard->setContents( pDataObj, NULL ); 64 65 uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY ); 66 if( xFlushableClipboard.is() ) 67 xFlushableClipboard->flushClipboard(); 68 } 69 catch( const uno::Exception& ) 70 { 71 } 72 Application::AcquireSolarMutex( nRef ); 73 } 74 75 // ::com::sun::star::uno::XInterface 76 uno::Any TextDataObject::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException) 77 { 78 uno::Any aRet = ::cppu::queryInterface( rType, SAL_STATIC_CAST( datatransfer::XTransferable*, this ) ); 79 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); 80 } 81 82 // ::com::sun::star::datatransfer::XTransferable 83 uno::Any TextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor ) throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException) 84 { 85 uno::Any aAny; 86 87 sal_uLong nT = SotExchange::GetFormat( rFlavor ); 88 if ( nT == SOT_FORMAT_STRING ) 89 { 90 aAny <<= (::rtl::OUString)GetString(); 91 } 92 else 93 { 94 throw datatransfer::UnsupportedFlavorException(); 95 } 96 return aAny; 97 } 98 99 uno::Sequence< datatransfer::DataFlavor > TextDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException) 100 { 101 uno::Sequence< datatransfer::DataFlavor > aDataFlavors(1); 102 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aDataFlavors.getArray()[0] ); 103 return aDataFlavors; 104 } 105 106 sal_Bool TextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor ) throw(uno::RuntimeException) 107 { 108 sal_uLong nT = SotExchange::GetFormat( rFlavor ); 109 return ( nT == SOT_FORMAT_STRING ); 110 } 111 112 }} // namespace vcl::unohelper 113