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