merge the formfield patch from ooo-build
[ooovba.git] / vcl / source / app / unohelp2.cxx
blob9061ac259a30c7a16b421638f69c341a19d280d6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unohelp2.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <vcl/unohelp2.hxx>
34 #include <sot/exchange.hxx>
35 #include <sot/formats.hxx>
36 #include <tools/debug.hxx>
37 #include <vcl/svapp.hxx>
38 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
39 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
42 using namespace ::com::sun::star;
44 namespace vcl { namespace unohelper {
46 TextDataObject::TextDataObject( const String& rText ) : maText( rText )
50 TextDataObject::~TextDataObject()
54 void TextDataObject::CopyStringTo( const String& rContent,
55 const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard )
57 DBG_ASSERT( rxClipboard.is(), "TextDataObject::CopyStringTo: invalid clipboard!" );
58 if ( !rxClipboard.is() )
59 return;
61 TextDataObject* pDataObj = new TextDataObject( rContent );
63 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
64 try
66 rxClipboard->setContents( pDataObj, NULL );
68 uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY );
69 if( xFlushableClipboard.is() )
70 xFlushableClipboard->flushClipboard();
72 catch( const uno::Exception& )
75 Application::AcquireSolarMutex( nRef );
78 // ::com::sun::star::uno::XInterface
79 uno::Any TextDataObject::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException)
81 uno::Any aRet = ::cppu::queryInterface( rType, SAL_STATIC_CAST( datatransfer::XTransferable*, this ) );
82 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
85 // ::com::sun::star::datatransfer::XTransferable
86 uno::Any TextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor ) throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException)
88 uno::Any aAny;
90 ULONG nT = SotExchange::GetFormat( rFlavor );
91 if ( nT == SOT_FORMAT_STRING )
93 aAny <<= (::rtl::OUString)GetString();
95 else
97 throw datatransfer::UnsupportedFlavorException();
99 return aAny;
102 uno::Sequence< datatransfer::DataFlavor > TextDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException)
104 uno::Sequence< datatransfer::DataFlavor > aDataFlavors(1);
105 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aDataFlavors.getArray()[0] );
106 return aDataFlavors;
109 sal_Bool TextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor ) throw(uno::RuntimeException)
111 ULONG nT = SotExchange::GetFormat( rFlavor );
112 return ( nT == SOT_FORMAT_STRING );
115 }} // namespace vcl::unohelper