1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10*9f62ea84SAndrew Rist * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9f62ea84SAndrew Rist * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19*9f62ea84SAndrew Rist * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir #include <vcl/unohelp2.hxx> 27cdf0e10cSrcweir #include <sot/exchange.hxx> 28cdf0e10cSrcweir #include <sot/formats.hxx> 29cdf0e10cSrcweir #include <tools/debug.hxx> 30cdf0e10cSrcweir #include <vcl/svapp.hxx> 31cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 32cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir using namespace ::com::sun::star; 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace vcl { namespace unohelper { 38cdf0e10cSrcweir TextDataObject(const String & rText)39cdf0e10cSrcweir TextDataObject::TextDataObject( const String& rText ) : maText( rText ) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir } 42cdf0e10cSrcweir ~TextDataObject()43cdf0e10cSrcweir TextDataObject::~TextDataObject() 44cdf0e10cSrcweir { 45cdf0e10cSrcweir } 46cdf0e10cSrcweir CopyStringTo(const String & rContent,const uno::Reference<datatransfer::clipboard::XClipboard> & rxClipboard)47cdf0e10cSrcweir void TextDataObject::CopyStringTo( const String& rContent, 48cdf0e10cSrcweir const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir DBG_ASSERT( rxClipboard.is(), "TextDataObject::CopyStringTo: invalid clipboard!" ); 51cdf0e10cSrcweir if ( !rxClipboard.is() ) 52cdf0e10cSrcweir return; 53cdf0e10cSrcweir 54cdf0e10cSrcweir TextDataObject* pDataObj = new TextDataObject( rContent ); 55cdf0e10cSrcweir 56cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 57cdf0e10cSrcweir try 58cdf0e10cSrcweir { 59cdf0e10cSrcweir rxClipboard->setContents( pDataObj, NULL ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY ); 62cdf0e10cSrcweir if( xFlushableClipboard.is() ) 63cdf0e10cSrcweir xFlushableClipboard->flushClipboard(); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir catch( const uno::Exception& ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir } 68cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir // ::com::sun::star::uno::XInterface queryInterface(const uno::Type & rType)72cdf0e10cSrcweir uno::Any TextDataObject::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir uno::Any aRet = ::cppu::queryInterface( rType, SAL_STATIC_CAST( datatransfer::XTransferable*, this ) ); 75cdf0e10cSrcweir return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir // ::com::sun::star::datatransfer::XTransferable getTransferData(const datatransfer::DataFlavor & rFlavor)79cdf0e10cSrcweir uno::Any TextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor ) throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir uno::Any aAny; 82cdf0e10cSrcweir 83cdf0e10cSrcweir sal_uLong nT = SotExchange::GetFormat( rFlavor ); 84cdf0e10cSrcweir if ( nT == SOT_FORMAT_STRING ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir aAny <<= (::rtl::OUString)GetString(); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir else 89cdf0e10cSrcweir { 90cdf0e10cSrcweir throw datatransfer::UnsupportedFlavorException(); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir return aAny; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir getTransferDataFlavors()95cdf0e10cSrcweir uno::Sequence< datatransfer::DataFlavor > TextDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir uno::Sequence< datatransfer::DataFlavor > aDataFlavors(1); 98cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aDataFlavors.getArray()[0] ); 99cdf0e10cSrcweir return aDataFlavors; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir isDataFlavorSupported(const datatransfer::DataFlavor & rFlavor)102cdf0e10cSrcweir sal_Bool TextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor ) throw(uno::RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir sal_uLong nT = SotExchange::GetFormat( rFlavor ); 105cdf0e10cSrcweir return ( nT == SOT_FORMAT_STRING ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir }} // namespace vcl::unohelper 109