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