xref: /aoo41x/main/svtools/source/misc/transfer.cxx (revision a206ee71)
15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
105900e8ecSAndrew Rist  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
195900e8ecSAndrew Rist  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svtools.hxx"
24cdf0e10cSrcweir #ifdef WNT
25cdf0e10cSrcweir #include <tools/prewin.h>
26cdf0e10cSrcweir #if defined _MSC_VER
27cdf0e10cSrcweir #pragma warning(push, 1)
28cdf0e10cSrcweir #pragma warning(disable: 4917)
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <shlobj.h>
31cdf0e10cSrcweir #if defined _MSC_VER
32cdf0e10cSrcweir #pragma warning(pop)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <tools/postwin.h>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <vos/mutex.hxx>
37cdf0e10cSrcweir #include <rtl/memory.h>
38cdf0e10cSrcweir #include <rtl/uuid.h>
39cdf0e10cSrcweir #include <rtl/uri.hxx>
40cdf0e10cSrcweir #include <tools/debug.hxx>
41cdf0e10cSrcweir #include <tools/urlobj.hxx>
42cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
43cdf0e10cSrcweir #include <sot/exchange.hxx>
44cdf0e10cSrcweir #include <sot/storage.hxx>
45cdf0e10cSrcweir #include <vcl/bitmap.hxx>
46cdf0e10cSrcweir #include <vcl/gdimtf.hxx>
47cdf0e10cSrcweir #include <vcl/graph.hxx>
48cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
49cdf0e10cSrcweir #include <vcl/svapp.hxx>
50cdf0e10cSrcweir #include <vcl/window.hxx>
51cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
52cdf0e10cSrcweir #include <sot/filelist.hxx>
53cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
56cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
57cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
58cdf0e10cSrcweir #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
59cdf0e10cSrcweir #include <com/sun/star/datatransfer/XMimeContentType.hpp>
60cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
61cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include "svl/urlbmk.hxx"
64cdf0e10cSrcweir #include "inetimg.hxx"
65cdf0e10cSrcweir #include <svtools/wmf.hxx>
66cdf0e10cSrcweir #include <svtools/imap.hxx>
67cdf0e10cSrcweir #include <svtools/transfer.hxx>
68cdf0e10cSrcweir #include <cstdio>
6945fd3b9aSArmin Le Grand #include <vcl/dibtools.hxx>
7045fd3b9aSArmin Le Grand #include <vcl/pngread.hxx>
7145fd3b9aSArmin Le Grand #include <vcl/pngwrite.hxx>
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // --------------
74cdf0e10cSrcweir // - Namespaces -
75cdf0e10cSrcweir // --------------
76cdf0e10cSrcweir 
77cdf0e10cSrcweir using namespace ::com::sun::star::uno;
78cdf0e10cSrcweir using namespace ::com::sun::star::lang;
79cdf0e10cSrcweir using namespace ::com::sun::star::frame;
80cdf0e10cSrcweir using namespace ::com::sun::star::io;
81cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
82cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::clipboard;
83cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::dnd;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // --------------------------------
86cdf0e10cSrcweir // - TransferableObjectDescriptor -
87cdf0e10cSrcweir // --------------------------------
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #define TOD_SIG1 0x01234567
90cdf0e10cSrcweir #define TOD_SIG2 0x89abcdef
91cdf0e10cSrcweir 
operator >>(SvStream & rIStm,TransferableObjectDescriptor & rObjDesc)92cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, TransferableObjectDescriptor& rObjDesc )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	sal_uInt32  nSize, nViewAspect, nSig1, nSig2;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	rIStm >> nSize;
97cdf0e10cSrcweir 	rIStm >> rObjDesc.maClassName;
98cdf0e10cSrcweir 	rIStm >> nViewAspect;
99cdf0e10cSrcweir 	rIStm >> rObjDesc.maSize.Width();
100cdf0e10cSrcweir     rIStm >> rObjDesc.maSize.Height();
101cdf0e10cSrcweir 	rIStm >> rObjDesc.maDragStartPos.X();
102cdf0e10cSrcweir 	rIStm >> rObjDesc.maDragStartPos.Y();
103cdf0e10cSrcweir 	rIStm.ReadByteString( rObjDesc.maTypeName, gsl_getSystemTextEncoding() );
104cdf0e10cSrcweir 	rIStm.ReadByteString( rObjDesc.maDisplayName, gsl_getSystemTextEncoding() );
105cdf0e10cSrcweir     rIStm >> nSig1 >> nSig2;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     rObjDesc.mnViewAspect = static_cast< sal_uInt16 >( nViewAspect );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     // don't use width/height info from external objects
110cdf0e10cSrcweir     if( ( TOD_SIG1 != nSig1 ) || ( TOD_SIG2 != nSig2 ) )
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         rObjDesc.maSize.Width() = 0;
113cdf0e10cSrcweir         rObjDesc.maSize.Height() = 0;
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	return rIStm;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir // -----------------------------------------------------------------------------
120cdf0e10cSrcweir 
operator <<(SvStream & rOStm,const TransferableObjectDescriptor & rObjDesc)121cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const TransferableObjectDescriptor& rObjDesc )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	const sal_uInt32    nFirstPos = rOStm.Tell(), nViewAspect = rObjDesc.mnViewAspect;
124cdf0e10cSrcweir 	const sal_uInt32    nSig1 = TOD_SIG1, nSig2 = TOD_SIG2;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	rOStm.SeekRel( 4 );
127cdf0e10cSrcweir 	rOStm << rObjDesc.maClassName;
128cdf0e10cSrcweir 	rOStm << nViewAspect;
129cdf0e10cSrcweir 	rOStm << rObjDesc.maSize.Width();
130cdf0e10cSrcweir 	rOStm << rObjDesc.maSize.Height();
131cdf0e10cSrcweir 	rOStm << rObjDesc.maDragStartPos.X();
132cdf0e10cSrcweir 	rOStm << rObjDesc.maDragStartPos.Y();
133cdf0e10cSrcweir 	rOStm.WriteByteString( rObjDesc.maTypeName, gsl_getSystemTextEncoding() );
134cdf0e10cSrcweir 	rOStm.WriteByteString( rObjDesc.maDisplayName, gsl_getSystemTextEncoding() );
135cdf0e10cSrcweir 	rOStm << nSig1 << nSig2;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	const sal_uInt32 nLastPos = rOStm.Tell();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	rOStm.Seek( nFirstPos );
140cdf0e10cSrcweir 	rOStm << ( nLastPos - nFirstPos );
141cdf0e10cSrcweir 	rOStm.Seek( nLastPos );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	return rOStm;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir // -----------------------------------------------------------------------------
147cdf0e10cSrcweir // the reading of the parameter is done using the special service ::com::sun::star::datatransfer::MimeContentType,
148cdf0e10cSrcweir // a similar approach should be implemented for creation of the mimetype string;
149cdf0e10cSrcweir // for now the set of acceptable characters has to be hardcoded, in future it should be part of the service that creates the mimetype
1508178a74eSMathias Bauer const ::rtl::OUString aQuotedParamChars = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "()<>@,;:/[]?=!#$&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~. " ) );
151cdf0e10cSrcweir 
ImplGetParameterString(const TransferableObjectDescriptor & rObjDesc)152cdf0e10cSrcweir static ::rtl::OUString ImplGetParameterString( const TransferableObjectDescriptor& rObjDesc )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     const ::rtl::OUString   aChar( ::rtl::OUString::createFromAscii( "\"" ) );
155cdf0e10cSrcweir     const ::rtl::OUString   aClassName( rObjDesc.maClassName.GetHexName() );
156cdf0e10cSrcweir     ::rtl::OUString         aParams;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     if( aClassName.getLength() )
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         aParams += ::rtl::OUString::createFromAscii( ";classname=\"" );
161cdf0e10cSrcweir         aParams += aClassName;
162cdf0e10cSrcweir         aParams += aChar;
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     if( rObjDesc.maTypeName.Len() )
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir         aParams += ::rtl::OUString::createFromAscii( ";typename=\"" );
168cdf0e10cSrcweir         aParams += rObjDesc.maTypeName;
169cdf0e10cSrcweir         aParams += aChar;
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     if( rObjDesc.maDisplayName.Len() )
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         // the display name might contain unacceptable characters, encode all of them
175cdf0e10cSrcweir         // this seems to be the only parameter currently that might contain such characters
176cdf0e10cSrcweir         sal_Bool pToAccept[128];
177cdf0e10cSrcweir         for ( sal_Int32 nBInd = 0; nBInd < 128; nBInd++ )
178cdf0e10cSrcweir             pToAccept[nBInd] = sal_False;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         for ( sal_Int32 nInd = 0; nInd < aQuotedParamChars.getLength(); nInd++ )
181cdf0e10cSrcweir         {
182cdf0e10cSrcweir             sal_Unicode nChar = aQuotedParamChars.getStr()[nInd];
183cdf0e10cSrcweir             if ( nChar < 128 )
184cdf0e10cSrcweir                 pToAccept[nChar] = sal_True;
185cdf0e10cSrcweir         }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         aParams += ::rtl::OUString::createFromAscii( ";displayname=\"" );
188cdf0e10cSrcweir         aParams += ::rtl::Uri::encode( rObjDesc.maDisplayName, pToAccept, rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8 );
189cdf0e10cSrcweir         aParams += aChar;
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     aParams += ::rtl::OUString::createFromAscii( ";viewaspect=\"" );
193cdf0e10cSrcweir     aParams += ::rtl::OUString::valueOf( static_cast< sal_Int32 >( rObjDesc.mnViewAspect ) );
194cdf0e10cSrcweir     aParams += aChar;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     aParams += ::rtl::OUString::createFromAscii( ";width=\"" );
197cdf0e10cSrcweir     aParams += ::rtl::OUString::valueOf( rObjDesc.maSize.Width() );
198cdf0e10cSrcweir     aParams += aChar;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     aParams += ::rtl::OUString::createFromAscii( ";height=\"" );
201cdf0e10cSrcweir     aParams += ::rtl::OUString::valueOf( rObjDesc.maSize.Height() );
202cdf0e10cSrcweir     aParams += aChar;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     aParams += ::rtl::OUString::createFromAscii( ";posx=\"" );
205cdf0e10cSrcweir     aParams += ::rtl::OUString::valueOf( rObjDesc.maDragStartPos.X() );
206cdf0e10cSrcweir     aParams += aChar;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     aParams += ::rtl::OUString::createFromAscii( ";posy=\"" );
209cdf0e10cSrcweir     aParams += ::rtl::OUString::valueOf( rObjDesc.maDragStartPos.X() );
210cdf0e10cSrcweir     aParams += aChar;
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     return aParams;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // -----------------------------------------------------------------------------
216cdf0e10cSrcweir 
ImplSetParameterString(TransferableObjectDescriptor & rObjDesc,const DataFlavorEx & rFlavorEx)217cdf0e10cSrcweir static void ImplSetParameterString( TransferableObjectDescriptor& rObjDesc, const DataFlavorEx& rFlavorEx )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     Reference< XMultiServiceFactory >       xFact( ::comphelper::getProcessServiceFactory() );
220cdf0e10cSrcweir     Reference< XMimeContentTypeFactory >    xMimeFact;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     try
223cdf0e10cSrcweir     {
224cdf0e10cSrcweir         if( xFact.is() )
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii(
227cdf0e10cSrcweir                                                               "com.sun.star.datatransfer.MimeContentTypeFactory" ) ),
228cdf0e10cSrcweir                                                               UNO_QUERY );
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         if( xMimeFact.is() )
232cdf0e10cSrcweir         {
233cdf0e10cSrcweir             Reference< XMimeContentType > xMimeType( xMimeFact->createMimeContentType( rFlavorEx.MimeType ) );
234cdf0e10cSrcweir 
235cdf0e10cSrcweir             if( xMimeType.is() )
236cdf0e10cSrcweir             {
237cdf0e10cSrcweir                 const ::rtl::OUString aClassNameString( ::rtl::OUString::createFromAscii( "classname" ) );
238cdf0e10cSrcweir                 const ::rtl::OUString aTypeNameString( ::rtl::OUString::createFromAscii( "typename" ) );
239cdf0e10cSrcweir                 const ::rtl::OUString aDisplayNameString( ::rtl::OUString::createFromAscii( "displayname" ) );
240cdf0e10cSrcweir                 const ::rtl::OUString aViewAspectString( ::rtl::OUString::createFromAscii( "viewaspect" ) );
241cdf0e10cSrcweir                 const ::rtl::OUString aWidthString( ::rtl::OUString::createFromAscii( "width" ) );
242cdf0e10cSrcweir                 const ::rtl::OUString aHeightString( ::rtl::OUString::createFromAscii( "height" ) );
243cdf0e10cSrcweir                 const ::rtl::OUString aPosXString( ::rtl::OUString::createFromAscii( "posx" ) );
244cdf0e10cSrcweir                 const ::rtl::OUString aPosYString( ::rtl::OUString::createFromAscii( "posy" ) );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir                 if( xMimeType->hasParameter( aClassNameString ) )
247cdf0e10cSrcweir                 {
248cdf0e10cSrcweir                     rObjDesc.maClassName.MakeId( xMimeType->getParameterValue( aClassNameString ) );
249cdf0e10cSrcweir                 }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir                 if( xMimeType->hasParameter( aTypeNameString ) )
252cdf0e10cSrcweir                 {
253cdf0e10cSrcweir                     rObjDesc.maTypeName = xMimeType->getParameterValue( aTypeNameString );
254cdf0e10cSrcweir                 }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir                 if( xMimeType->hasParameter( aDisplayNameString ) )
257cdf0e10cSrcweir                 {
258cdf0e10cSrcweir                     // the display name might contain unacceptable characters, in this case they should be encoded
259cdf0e10cSrcweir                     // this seems to be the only parameter currently that might contain such characters
260cdf0e10cSrcweir                     rObjDesc.maDisplayName = ::rtl::Uri::decode( xMimeType->getParameterValue( aDisplayNameString ), rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
261cdf0e10cSrcweir                 }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir                 if( xMimeType->hasParameter( aViewAspectString ) )
264cdf0e10cSrcweir                 {
265cdf0e10cSrcweir                     rObjDesc.mnViewAspect = static_cast< sal_uInt16 >( xMimeType->getParameterValue( aViewAspectString ).toInt32() );
266cdf0e10cSrcweir                 }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir                 if( xMimeType->hasParameter( aWidthString ) )
269cdf0e10cSrcweir                 {
270cdf0e10cSrcweir                     rObjDesc.maSize.Width() = xMimeType->getParameterValue( aWidthString ).toInt32();
271cdf0e10cSrcweir                 }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir                 if( xMimeType->hasParameter( aHeightString ) )
274cdf0e10cSrcweir                 {
275cdf0e10cSrcweir                     rObjDesc.maSize.Height() = xMimeType->getParameterValue( aHeightString ).toInt32();
276cdf0e10cSrcweir                 }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir                 if( xMimeType->hasParameter( aPosXString ) )
279cdf0e10cSrcweir                 {
280cdf0e10cSrcweir                     rObjDesc.maDragStartPos.X() = xMimeType->getParameterValue( aPosXString ).toInt32();
281cdf0e10cSrcweir                 }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir                 if( xMimeType->hasParameter( aPosYString ) )
284cdf0e10cSrcweir                 {
285cdf0e10cSrcweir                     rObjDesc.maDragStartPos.Y() = xMimeType->getParameterValue( aPosYString ).toInt32();
286cdf0e10cSrcweir                 }
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
291cdf0e10cSrcweir     {
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir // -----------------------------------------
296cdf0e10cSrcweir // - TransferableHelper::TerminateListener -
297cdf0e10cSrcweir // -----------------------------------------
298cdf0e10cSrcweir 
TerminateListener(TransferableHelper & rTransferableHelper)299cdf0e10cSrcweir TransferableHelper::TerminateListener::TerminateListener( TransferableHelper& rTransferableHelper ) :
300cdf0e10cSrcweir 	mrParent( rTransferableHelper )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // -----------------------------------------------------------------------------
305cdf0e10cSrcweir 
~TerminateListener()306cdf0e10cSrcweir TransferableHelper::TerminateListener::~TerminateListener()
307cdf0e10cSrcweir {
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir // -----------------------------------------------------------------------------
311cdf0e10cSrcweir 
disposing(const EventObject &)312cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::disposing( const EventObject& ) throw( RuntimeException )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir // -----------------------------------------------------------------------------
317cdf0e10cSrcweir 
queryTermination(const EventObject &)318cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::queryTermination( const EventObject& ) throw( TerminationVetoException, RuntimeException )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir // -----------------------------------------------------------------------------
323cdf0e10cSrcweir 
notifyTermination(const EventObject &)324cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::notifyTermination( const EventObject& ) throw( RuntimeException )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir 	mrParent.ImplFlush();
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir // ----------------------
330cdf0e10cSrcweir // - TransferableHelper -
331cdf0e10cSrcweir // ----------------------
332cdf0e10cSrcweir 
TransferableHelper()333cdf0e10cSrcweir TransferableHelper::TransferableHelper() :
334cdf0e10cSrcweir 	mpFormats( new DataFlavorExVector ),
335cdf0e10cSrcweir     mpObjDesc( NULL )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir // -----------------------------------------------------------------------------
340cdf0e10cSrcweir 
~TransferableHelper()341cdf0e10cSrcweir TransferableHelper::~TransferableHelper()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     delete mpObjDesc;
344cdf0e10cSrcweir 	delete mpFormats;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir // -----------------------------------------------------------------------------
348cdf0e10cSrcweir 
getTransferData(const DataFlavor & rFlavor)349cdf0e10cSrcweir Any SAL_CALL TransferableHelper::getTransferData( const DataFlavor& rFlavor ) throw( UnsupportedFlavorException, IOException, RuntimeException )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	if( !maAny.hasValue() || !mpFormats->size() || ( maLastFormat != rFlavor.MimeType ) )
352cdf0e10cSrcweir 	{
353cdf0e10cSrcweir 		const ::vos::OGuard aGuard( Application::GetSolarMutex() );
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 		maLastFormat = rFlavor.MimeType;
356cdf0e10cSrcweir 		maAny = Any();
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 		try
359cdf0e10cSrcweir 		{
360cdf0e10cSrcweir     	    DataFlavor  aSubstFlavor;
361cdf0e10cSrcweir             sal_Bool    bDone = sal_False;
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 			// add formats if not already done
364cdf0e10cSrcweir             if( !mpFormats->size() )
365cdf0e10cSrcweir 				AddSupportedFormats();
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 	        // check alien formats first and try to get a substitution format
368cdf0e10cSrcweir             if( SotExchange::GetFormatDataFlavor( FORMAT_STRING, aSubstFlavor ) &&
369cdf0e10cSrcweir                 TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) )
370cdf0e10cSrcweir             {
371cdf0e10cSrcweir 			    GetData( aSubstFlavor );
372cdf0e10cSrcweir                 bDone = maAny.hasValue();
373cdf0e10cSrcweir             }
37445fd3b9aSArmin Le Grand             else if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_BMP, aSubstFlavor )
37545fd3b9aSArmin Le Grand                 && TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor )
37645fd3b9aSArmin Le Grand                 && SotExchange::GetFormatDataFlavor(FORMAT_BITMAP, aSubstFlavor))
377cdf0e10cSrcweir             {
378cdf0e10cSrcweir 			    GetData( aSubstFlavor );
379cdf0e10cSrcweir                 bDone = sal_True;
380cdf0e10cSrcweir             }
381cdf0e10cSrcweir             else if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_EMF, aSubstFlavor ) &&
382cdf0e10cSrcweir                      TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) &&
383cdf0e10cSrcweir                      SotExchange::GetFormatDataFlavor( FORMAT_GDIMETAFILE, aSubstFlavor ) )
384cdf0e10cSrcweir             {
385cdf0e10cSrcweir 			    GetData( aSubstFlavor );
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 			    if( maAny.hasValue() )
388cdf0e10cSrcweir 			    {
389cdf0e10cSrcweir 				    Sequence< sal_Int8 > aSeq;
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 				    if( maAny >>= aSeq )
392cdf0e10cSrcweir 				    {
393cdf0e10cSrcweir 					    SvMemoryStream*	pSrcStm = new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC );
394cdf0e10cSrcweir 					    GDIMetaFile		aMtf;
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 					    *pSrcStm >> aMtf;
397cdf0e10cSrcweir 					    delete pSrcStm;
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 					    Graphic			aGraphic( aMtf );
400cdf0e10cSrcweir 					    SvMemoryStream	aDstStm( 65535, 65535 );
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 					    if( GraphicConverter::Export( aDstStm, aGraphic, CVT_EMF ) == ERRCODE_NONE )
403cdf0e10cSrcweir                         {
404cdf0e10cSrcweir 						    maAny <<= ( aSeq = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aDstStm.GetData() ),
405cdf0e10cSrcweir                                                                      aDstStm.Seek( STREAM_SEEK_TO_END ) ) );
406cdf0e10cSrcweir                             bDone = sal_True;
407cdf0e10cSrcweir                         }
408cdf0e10cSrcweir 				    }
409cdf0e10cSrcweir 			    }
410cdf0e10cSrcweir             }
411cdf0e10cSrcweir             else if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_WMF, aSubstFlavor ) &&
412cdf0e10cSrcweir                      TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) &&
413cdf0e10cSrcweir                      SotExchange::GetFormatDataFlavor( FORMAT_GDIMETAFILE, aSubstFlavor ) )
414cdf0e10cSrcweir             {
415cdf0e10cSrcweir 			    GetData( aSubstFlavor );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 			    if( maAny.hasValue() )
418cdf0e10cSrcweir 			    {
419cdf0e10cSrcweir 				    Sequence< sal_Int8 > aSeq;
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 				    if( maAny >>= aSeq )
422cdf0e10cSrcweir 				    {
423cdf0e10cSrcweir 					    SvMemoryStream*	pSrcStm = new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC );
424cdf0e10cSrcweir 					    GDIMetaFile		aMtf;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 					    *pSrcStm >> aMtf;
427cdf0e10cSrcweir 					    delete pSrcStm;
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 					    SvMemoryStream	aDstStm( 65535, 65535 );
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 						// taking wmf without file header
432cdf0e10cSrcweir 						if ( ConvertGDIMetaFileToWMF( aMtf, aDstStm, NULL, sal_False ) )
433cdf0e10cSrcweir                         {
434cdf0e10cSrcweir 						    maAny <<= ( aSeq = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aDstStm.GetData() ),
435cdf0e10cSrcweir                                                                      aDstStm.Seek( STREAM_SEEK_TO_END ) ) );
436cdf0e10cSrcweir                             bDone = sal_True;
437cdf0e10cSrcweir                         }
438cdf0e10cSrcweir 				    }
439cdf0e10cSrcweir 			    }
440cdf0e10cSrcweir             }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir             // reset Any if substitute doesn't work
443cdf0e10cSrcweir             if( !bDone && maAny.hasValue() )
444cdf0e10cSrcweir                 maAny = Any();
445cdf0e10cSrcweir 
446cdf0e10cSrcweir             // if any is not yet filled, use standard format
447cdf0e10cSrcweir             if( !maAny.hasValue() )
448cdf0e10cSrcweir                 GetData( rFlavor );
449cdf0e10cSrcweir 
450cdf0e10cSrcweir #ifdef DEBUG
451cdf0e10cSrcweir             if( maAny.hasValue() && ::com::sun::star::uno::TypeClass_STRING != maAny.getValueType().getTypeClass() )
452cdf0e10cSrcweir                 fprintf( stderr, "TransferableHelper delivers sequence of data [ %s ]\n", ByteString( String( rFlavor.MimeType), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
453cdf0e10cSrcweir #endif
454cdf0e10cSrcweir         }
455cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
456cdf0e10cSrcweir 		{
457cdf0e10cSrcweir 		}
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 		if( !maAny.hasValue() )
460cdf0e10cSrcweir 			throw UnsupportedFlavorException();
461cdf0e10cSrcweir 	}
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	return maAny;
464cdf0e10cSrcweir }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir // -----------------------------------------------------------------------------
467cdf0e10cSrcweir 
getTransferDataFlavors()468cdf0e10cSrcweir Sequence< DataFlavor > SAL_CALL TransferableHelper::getTransferDataFlavors() throw( RuntimeException )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 	try
473cdf0e10cSrcweir 	{
474cdf0e10cSrcweir 		if( !mpFormats->size() )
475cdf0e10cSrcweir 			AddSupportedFormats();
476cdf0e10cSrcweir 	}
477cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
478cdf0e10cSrcweir 	{
479cdf0e10cSrcweir 	}
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 	Sequence< DataFlavor >			aRet( mpFormats->size() );
482cdf0e10cSrcweir 	DataFlavorExVector::iterator	aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
483cdf0e10cSrcweir 	sal_uInt32						nCurPos = 0;
484cdf0e10cSrcweir 
485cdf0e10cSrcweir     while( aIter != aEnd )
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir     	aRet[ nCurPos++ ] = *aIter++;
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	return aRet;
491cdf0e10cSrcweir }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir // -----------------------------------------------------------------------------
494cdf0e10cSrcweir 
isDataFlavorSupported(const DataFlavor & rFlavor)495cdf0e10cSrcweir sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& rFlavor ) throw( RuntimeException )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
498cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 	try
501cdf0e10cSrcweir 	{
502cdf0e10cSrcweir 		if( !mpFormats->size() )
503cdf0e10cSrcweir 			AddSupportedFormats();
504cdf0e10cSrcweir 	}
505cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
506cdf0e10cSrcweir 	{
507cdf0e10cSrcweir 	}
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 	DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 	while( aIter != aEnd )
512cdf0e10cSrcweir 	{
513cdf0e10cSrcweir         if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) )
514cdf0e10cSrcweir         {
515cdf0e10cSrcweir             aIter = aEnd;
516cdf0e10cSrcweir             bRet = sal_True;
517cdf0e10cSrcweir         }
518cdf0e10cSrcweir         else
519cdf0e10cSrcweir             aIter++;
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 	return bRet;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir // -----------------------------------------------------------------------------
526cdf0e10cSrcweir 
lostOwnership(const Reference<XClipboard> &,const Reference<XTransferable> &)527cdf0e10cSrcweir void SAL_CALL TransferableHelper::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& ) throw( RuntimeException )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 	try
532cdf0e10cSrcweir 	{
533cdf0e10cSrcweir 		if( mxTerminateListener.is() )
534cdf0e10cSrcweir 		{
535cdf0e10cSrcweir 			Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() );
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 			if( xFact.is() )
538cdf0e10cSrcweir 			{
539cdf0e10cSrcweir 				Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
540cdf0e10cSrcweir 
541cdf0e10cSrcweir 				if( xDesktop.is() )
542cdf0e10cSrcweir 					xDesktop->removeTerminateListener( mxTerminateListener );
543cdf0e10cSrcweir 			}
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 			mxTerminateListener = Reference< XTerminateListener >();
546cdf0e10cSrcweir 		}
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 		ObjectReleased();
549cdf0e10cSrcweir 	}
550cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
551cdf0e10cSrcweir 	{
552cdf0e10cSrcweir 	}
553cdf0e10cSrcweir }
554cdf0e10cSrcweir 
555cdf0e10cSrcweir // -----------------------------------------------------------------------------
556cdf0e10cSrcweir 
disposing(const EventObject &)557cdf0e10cSrcweir void SAL_CALL TransferableHelper::disposing( const EventObject& ) throw( RuntimeException )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // -----------------------------------------------------------------------------
562cdf0e10cSrcweir 
dragDropEnd(const DragSourceDropEvent & rDSDE)563cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragDropEnd( const DragSourceDropEvent& rDSDE ) throw( RuntimeException )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	try
568cdf0e10cSrcweir 	{
569cdf0e10cSrcweir 		DragFinished( rDSDE.DropSuccess ? ( rDSDE.DropAction & ~DNDConstants::ACTION_DEFAULT ) : DNDConstants::ACTION_NONE );
570cdf0e10cSrcweir 		ObjectReleased();
571cdf0e10cSrcweir 	}
572cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
573cdf0e10cSrcweir 	{
574cdf0e10cSrcweir 	}
575cdf0e10cSrcweir }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir // -----------------------------------------------------------------------------
578cdf0e10cSrcweir 
dragEnter(const DragSourceDragEvent &)579cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragEnter( const DragSourceDragEvent& ) throw( RuntimeException )
580cdf0e10cSrcweir {
581cdf0e10cSrcweir }
582cdf0e10cSrcweir 
583cdf0e10cSrcweir // -----------------------------------------------------------------------------
584cdf0e10cSrcweir 
dragExit(const DragSourceEvent &)585cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragExit( const DragSourceEvent& ) throw( RuntimeException )
586cdf0e10cSrcweir {
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir // -----------------------------------------------------------------------------
590cdf0e10cSrcweir 
dragOver(const DragSourceDragEvent &)591cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragOver( const DragSourceDragEvent& ) throw( RuntimeException )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir // -----------------------------------------------------------------------------
596cdf0e10cSrcweir 
dropActionChanged(const DragSourceDragEvent &)597cdf0e10cSrcweir void SAL_CALL TransferableHelper::dropActionChanged( const DragSourceDragEvent& ) throw( RuntimeException )
598cdf0e10cSrcweir {
599cdf0e10cSrcweir }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir // -----------------------------------------------------------------------------
602cdf0e10cSrcweir 
getSomething(const Sequence<sal_Int8> & rId)603cdf0e10cSrcweir sal_Int64 SAL_CALL TransferableHelper::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir     sal_Int64 nRet;
606cdf0e10cSrcweir 
607cdf0e10cSrcweir     if( ( rId.getLength() == 16 ) &&
608cdf0e10cSrcweir         ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
609cdf0e10cSrcweir     {
610cdf0e10cSrcweir         nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
611cdf0e10cSrcweir     }
612cdf0e10cSrcweir     else
613cdf0e10cSrcweir         nRet = 0;
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 	return nRet;
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir // -----------------------------------------------------------------------------
619cdf0e10cSrcweir 
ImplFlush()620cdf0e10cSrcweir void TransferableHelper::ImplFlush()
621cdf0e10cSrcweir {
622cdf0e10cSrcweir 	if( mxClipboard.is() )
623cdf0e10cSrcweir 	{
624cdf0e10cSrcweir 		Reference< XFlushableClipboard >	xFlushableClipboard( mxClipboard, UNO_QUERY );
625cdf0e10cSrcweir 		const sal_uInt32					nRef = Application::ReleaseSolarMutex();
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 		try
628cdf0e10cSrcweir 		{
629cdf0e10cSrcweir 			if( xFlushableClipboard.is() )
630cdf0e10cSrcweir 			 	xFlushableClipboard->flushClipboard();
631cdf0e10cSrcweir 		}
632cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
633cdf0e10cSrcweir 		{
634cdf0e10cSrcweir 			DBG_ERROR( "Could not flush clipboard" );
635cdf0e10cSrcweir 		}
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 		Application::AcquireSolarMutex( nRef );
638cdf0e10cSrcweir 	}
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir // -----------------------------------------------------------------------------
642cdf0e10cSrcweir 
AddFormat(SotFormatStringId nFormat)643cdf0e10cSrcweir void TransferableHelper::AddFormat( SotFormatStringId nFormat )
644cdf0e10cSrcweir {
645cdf0e10cSrcweir     DataFlavor aFlavor;
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
648cdf0e10cSrcweir         AddFormat( aFlavor );
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir // -----------------------------------------------------------------------------
652cdf0e10cSrcweir 
AddFormat(const DataFlavor & rFlavor)653cdf0e10cSrcweir void TransferableHelper::AddFormat( const DataFlavor& rFlavor )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir 	DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
656cdf0e10cSrcweir     sal_Bool                        bAdd = sal_True;
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 	while( aIter != aEnd )
659cdf0e10cSrcweir 	{
660cdf0e10cSrcweir         if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) )
661cdf0e10cSrcweir         {
662cdf0e10cSrcweir             // update MimeType for SOT_FORMATSTR_ID_OBJECTDESCRIPTOR in every case
663cdf0e10cSrcweir             if( ( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aIter->mnSotId ) && mpObjDesc )
664cdf0e10cSrcweir             {
665cdf0e10cSrcweir                 DataFlavor aObjDescFlavor;
666cdf0e10cSrcweir 
667cdf0e10cSrcweir                 SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDescFlavor );
668cdf0e10cSrcweir                 aIter->MimeType = aObjDescFlavor.MimeType;
669cdf0e10cSrcweir                 aIter->MimeType += ::ImplGetParameterString( *mpObjDesc );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir #ifdef DEBUG
672cdf0e10cSrcweir                 fprintf( stderr, "TransferableHelper exchanged objectdescriptor [ %s ]\n",
673cdf0e10cSrcweir                          ByteString( String( aIter->MimeType), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
674cdf0e10cSrcweir #endif
675cdf0e10cSrcweir             }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir             aIter = aEnd;
678cdf0e10cSrcweir             bAdd = sal_False;
679cdf0e10cSrcweir         }
680cdf0e10cSrcweir         else
681cdf0e10cSrcweir             aIter++;
682cdf0e10cSrcweir     }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir     if( bAdd )
685cdf0e10cSrcweir     {
686cdf0e10cSrcweir     	DataFlavorEx   aFlavorEx;
687cdf0e10cSrcweir         DataFlavor     aObjDescFlavor;
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 		aFlavorEx.MimeType = rFlavor.MimeType;
690cdf0e10cSrcweir 		aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName;
691cdf0e10cSrcweir 		aFlavorEx.DataType = rFlavor.DataType;
692cdf0e10cSrcweir 		aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor );
693cdf0e10cSrcweir 
694cdf0e10cSrcweir         if( ( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aFlavorEx.mnSotId ) && mpObjDesc )
695cdf0e10cSrcweir             aFlavorEx.MimeType += ::ImplGetParameterString( *mpObjDesc );
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 		mpFormats->push_back( aFlavorEx );
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 		if( FORMAT_BITMAP == aFlavorEx.mnSotId )
700cdf0e10cSrcweir 		{
70145fd3b9aSArmin Le Grand 			AddFormat( SOT_FORMATSTR_ID_PNG );
702*a206ee71SArmin Le Grand 			AddFormat( SOT_FORMATSTR_ID_BMP );
703cdf0e10cSrcweir 		}
704cdf0e10cSrcweir 		else if( FORMAT_GDIMETAFILE == aFlavorEx.mnSotId )
705cdf0e10cSrcweir 		{
706cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_EMF );
707cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_WMF );
708cdf0e10cSrcweir 		}
709cdf0e10cSrcweir     }
710cdf0e10cSrcweir }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir // -----------------------------------------------------------------------------
713cdf0e10cSrcweir 
RemoveFormat(SotFormatStringId nFormat)714cdf0e10cSrcweir void TransferableHelper::RemoveFormat( SotFormatStringId nFormat )
715cdf0e10cSrcweir {
716cdf0e10cSrcweir     DataFlavor aFlavor;
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
719cdf0e10cSrcweir         RemoveFormat( aFlavor );
720cdf0e10cSrcweir }
721cdf0e10cSrcweir 
722cdf0e10cSrcweir // -----------------------------------------------------------------------------
723cdf0e10cSrcweir 
RemoveFormat(const DataFlavor & rFlavor)724cdf0e10cSrcweir void TransferableHelper::RemoveFormat( const DataFlavor& rFlavor )
725cdf0e10cSrcweir {
726cdf0e10cSrcweir 	DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
727cdf0e10cSrcweir 
728cdf0e10cSrcweir 	while( aIter != aEnd )
729cdf0e10cSrcweir 	{
730cdf0e10cSrcweir 		if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) )
731cdf0e10cSrcweir 		{
732cdf0e10cSrcweir 			aIter = mpFormats->erase( aIter );
733cdf0e10cSrcweir 			aEnd = mpFormats->end();
734cdf0e10cSrcweir 		}
735cdf0e10cSrcweir 		else
736cdf0e10cSrcweir 			++aIter;
737cdf0e10cSrcweir 	}
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
740cdf0e10cSrcweir // -----------------------------------------------------------------------------
741cdf0e10cSrcweir 
HasFormat(SotFormatStringId nFormat)742cdf0e10cSrcweir sal_Bool TransferableHelper::HasFormat( SotFormatStringId nFormat )
743cdf0e10cSrcweir {
744cdf0e10cSrcweir 	DataFlavorExVector::iterator	aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
745cdf0e10cSrcweir 	sal_Bool						bRet = sal_False;
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 	while( aIter != aEnd )
748cdf0e10cSrcweir 	{
749cdf0e10cSrcweir 		if( nFormat == (*aIter).mnSotId )
750cdf0e10cSrcweir 		{
751cdf0e10cSrcweir 			aIter = aEnd;
752cdf0e10cSrcweir 			bRet = sal_True;
753cdf0e10cSrcweir 		}
754cdf0e10cSrcweir 		else
755cdf0e10cSrcweir 			++aIter;
756cdf0e10cSrcweir 	}
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 	return bRet;
759cdf0e10cSrcweir }
760cdf0e10cSrcweir 
761cdf0e10cSrcweir // -----------------------------------------------------------------------------
762cdf0e10cSrcweir 
ClearFormats()763cdf0e10cSrcweir void TransferableHelper::ClearFormats()
764cdf0e10cSrcweir {
765cdf0e10cSrcweir 	mpFormats->clear();
766cdf0e10cSrcweir     maAny.clear();
767cdf0e10cSrcweir }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir // -----------------------------------------------------------------------------
770cdf0e10cSrcweir 
SetAny(const Any & rAny,const DataFlavor &)771cdf0e10cSrcweir sal_Bool TransferableHelper::SetAny( const Any& rAny, const DataFlavor& )
772cdf0e10cSrcweir {
773cdf0e10cSrcweir 	maAny = rAny;
774cdf0e10cSrcweir 	return( maAny.hasValue() );
775cdf0e10cSrcweir }
776cdf0e10cSrcweir 
777cdf0e10cSrcweir // -----------------------------------------------------------------------------
778cdf0e10cSrcweir 
SetString(const::rtl::OUString & rString,const DataFlavor & rFlavor)779cdf0e10cSrcweir sal_Bool TransferableHelper::SetString( const ::rtl::OUString& rString, const DataFlavor& rFlavor )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir 	DataFlavor aFileFlavor;
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 	if( rString.getLength() &&
784cdf0e10cSrcweir 		SotExchange::GetFormatDataFlavor( FORMAT_FILE, aFileFlavor ) &&
785cdf0e10cSrcweir 		TransferableDataHelper::IsEqual( aFileFlavor, rFlavor ) )
786cdf0e10cSrcweir 	{
787cdf0e10cSrcweir 		const String			aString( rString );
788cdf0e10cSrcweir 		const ByteString		aByteStr( aString, gsl_getSystemTextEncoding() );
789cdf0e10cSrcweir 		Sequence< sal_Int8 >	aSeq( aByteStr.Len() + 1 );
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 		rtl_copyMemory( aSeq.getArray(), aByteStr.GetBuffer(), aByteStr.Len() );
792cdf0e10cSrcweir 		aSeq[ aByteStr.Len() ] = 0;
793cdf0e10cSrcweir 		maAny <<= aSeq;
794cdf0e10cSrcweir 	}
795cdf0e10cSrcweir 	else
796cdf0e10cSrcweir 		maAny <<= rString;
797cdf0e10cSrcweir 
798cdf0e10cSrcweir 	return( maAny.hasValue() );
799cdf0e10cSrcweir }
800cdf0e10cSrcweir 
801cdf0e10cSrcweir // -----------------------------------------------------------------------------
802cdf0e10cSrcweir 
SetBitmapEx(const BitmapEx & rBitmapEx,const DataFlavor & rFlavor)80345fd3b9aSArmin Le Grand sal_Bool TransferableHelper::SetBitmapEx( const BitmapEx& rBitmapEx, const DataFlavor& rFlavor )
804cdf0e10cSrcweir {
80545fd3b9aSArmin Le Grand 	if( !rBitmapEx.IsEmpty() )
806cdf0e10cSrcweir 	{
80745fd3b9aSArmin Le Grand         SvMemoryStream aMemStm( 65535, 65535 );
808cdf0e10cSrcweir 
80945fd3b9aSArmin Le Grand         if(rFlavor.MimeType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("image/png")))
81045fd3b9aSArmin Le Grand         {
81145fd3b9aSArmin Le Grand             // write a PNG
81245fd3b9aSArmin Le Grand             ::vcl::PNGWriter aPNGWriter(rBitmapEx);
81345fd3b9aSArmin Le Grand 
81445fd3b9aSArmin Le Grand             aPNGWriter.Write(aMemStm);
81545fd3b9aSArmin Le Grand         }
81645fd3b9aSArmin Le Grand         else
81745fd3b9aSArmin Le Grand         {
81845fd3b9aSArmin Le Grand             const Bitmap aBitmap(rBitmapEx.GetBitmap());
81945fd3b9aSArmin Le Grand 
820*a206ee71SArmin Le Grand             // #124085# take out DIBV5 for writing to the clipboard
821*a206ee71SArmin Le Grand             //if(rBitmapEx.IsTransparent())
822*a206ee71SArmin Le Grand             //{
823*a206ee71SArmin Le Grand             //    const Bitmap aMask(rBitmapEx.GetAlpha().GetBitmap());
824*a206ee71SArmin Le Grand             //
825*a206ee71SArmin Le Grand             //    // explicitely use Bitmap::Write with bCompressed = sal_False and bFileHeader = sal_True
826*a206ee71SArmin Le Grand             //    WriteDIBV5(aBitmap, aMask, aMemStm);
827*a206ee71SArmin Le Grand             //}
828*a206ee71SArmin Le Grand             //else
829*a206ee71SArmin Le Grand             //{
83045fd3b9aSArmin Le Grand                 // explicitely use Bitmap::Write with bCompressed = sal_False and bFileHeader = sal_True
83145fd3b9aSArmin Le Grand                 WriteDIB(aBitmap, aMemStm, false, true);
832*a206ee71SArmin Le Grand             //}
83345fd3b9aSArmin Le Grand         }
83445fd3b9aSArmin Le Grand 
83545fd3b9aSArmin Le Grand         maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
836cdf0e10cSrcweir 	}
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 	return( maAny.hasValue() );
839cdf0e10cSrcweir }
840cdf0e10cSrcweir 
841cdf0e10cSrcweir // -----------------------------------------------------------------------------
842cdf0e10cSrcweir 
SetGDIMetaFile(const GDIMetaFile & rMtf,const DataFlavor &)843cdf0e10cSrcweir sal_Bool TransferableHelper::SetGDIMetaFile( const GDIMetaFile& rMtf, const DataFlavor& )
844cdf0e10cSrcweir {
845cdf0e10cSrcweir 	if( rMtf.GetActionCount() )
846cdf0e10cSrcweir 	{
847cdf0e10cSrcweir 		SvMemoryStream aMemStm( 65535, 65535 );
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 		( (GDIMetaFile&) rMtf ).Write( aMemStm );
850cdf0e10cSrcweir 		maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
851cdf0e10cSrcweir 	}
852cdf0e10cSrcweir 
853cdf0e10cSrcweir 	return( maAny.hasValue() );
854cdf0e10cSrcweir }
855cdf0e10cSrcweir 
856cdf0e10cSrcweir // -----------------------------------------------------------------------------
857cdf0e10cSrcweir 
SetGraphic(const Graphic & rGraphic,const DataFlavor &)858cdf0e10cSrcweir sal_Bool TransferableHelper::SetGraphic( const Graphic& rGraphic, const DataFlavor& )
859cdf0e10cSrcweir {
860cdf0e10cSrcweir 	if( rGraphic.GetType() != GRAPHIC_NONE )
861cdf0e10cSrcweir 	{
862cdf0e10cSrcweir 		SvMemoryStream aMemStm( 65535, 65535 );
863cdf0e10cSrcweir 
864cdf0e10cSrcweir         aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
865cdf0e10cSrcweir         aMemStm.SetCompressMode( COMPRESSMODE_NATIVE );
866cdf0e10cSrcweir 		aMemStm << rGraphic;
867cdf0e10cSrcweir 		maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
868cdf0e10cSrcweir 	}
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 	return( maAny.hasValue() );
871cdf0e10cSrcweir }
872cdf0e10cSrcweir 
873cdf0e10cSrcweir // -----------------------------------------------------------------------------
874cdf0e10cSrcweir 
SetImageMap(const ImageMap & rIMap,const::com::sun::star::datatransfer::DataFlavor &)875cdf0e10cSrcweir sal_Bool TransferableHelper::SetImageMap( const ImageMap& rIMap, const ::com::sun::star::datatransfer::DataFlavor& )
876cdf0e10cSrcweir {
877cdf0e10cSrcweir 	SvMemoryStream aMemStm( 8192, 8192 );
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
880cdf0e10cSrcweir     rIMap.Write( aMemStm, String() );
881cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 	return( maAny.hasValue() );
884cdf0e10cSrcweir }
885cdf0e10cSrcweir 
886cdf0e10cSrcweir // -----------------------------------------------------------------------------
887cdf0e10cSrcweir 
SetTransferableObjectDescriptor(const TransferableObjectDescriptor & rDesc,const::com::sun::star::datatransfer::DataFlavor &)888cdf0e10cSrcweir sal_Bool TransferableHelper::SetTransferableObjectDescriptor( const TransferableObjectDescriptor& rDesc,
889cdf0e10cSrcweir 															  const ::com::sun::star::datatransfer::DataFlavor& )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir     PrepareOLE( rDesc );
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 	SvMemoryStream aMemStm( 1024, 1024 );
894cdf0e10cSrcweir 
895cdf0e10cSrcweir 	aMemStm << rDesc;
896cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
897cdf0e10cSrcweir 
898cdf0e10cSrcweir 	return( maAny.hasValue() );
899cdf0e10cSrcweir  }
900cdf0e10cSrcweir 
901cdf0e10cSrcweir // -----------------------------------------------------------------------------
902cdf0e10cSrcweir 
SetINetBookmark(const INetBookmark & rBmk,const::com::sun::star::datatransfer::DataFlavor & rFlavor)903cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetBookmark( const INetBookmark& rBmk,
904cdf0e10cSrcweir 											  const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
905cdf0e10cSrcweir {
906cdf0e10cSrcweir 	rtl_TextEncoding eSysCSet = gsl_getSystemTextEncoding();
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 	switch( SotExchange::GetFormat( rFlavor ) )
909cdf0e10cSrcweir 	{
910cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_SOLK ):
911cdf0e10cSrcweir 		{
912cdf0e10cSrcweir 			ByteString sURL( rBmk.GetURL(), eSysCSet ),
913cdf0e10cSrcweir 					   sDesc( rBmk.GetDescription(), eSysCSet );
914cdf0e10cSrcweir 			ByteString sOut( ByteString::CreateFromInt32( sURL.Len() ));
915cdf0e10cSrcweir 			( sOut += '@' ) += sURL;
916cdf0e10cSrcweir 			sOut += ByteString::CreateFromInt32( sDesc.Len() );
917cdf0e10cSrcweir 			( sOut += '@' ) += sDesc;
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq( sOut.Len() );
920cdf0e10cSrcweir 			memcpy( aSeq.getArray(), sOut.GetBuffer(), sOut.Len() );
921cdf0e10cSrcweir 			maAny <<= aSeq;
922cdf0e10cSrcweir 		}
923cdf0e10cSrcweir 		break;
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 		case( FORMAT_STRING ):
926cdf0e10cSrcweir 			maAny <<= ::rtl::OUString( rBmk.GetURL() );
927cdf0e10cSrcweir 			break;
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ):
930cdf0e10cSrcweir 		{
931cdf0e10cSrcweir 			ByteString sURL( rBmk.GetURL(), eSysCSet );
932cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq( sURL.Len() );
933cdf0e10cSrcweir 			memcpy( aSeq.getArray(), sURL.GetBuffer(), sURL.Len() );
934cdf0e10cSrcweir 			maAny <<= aSeq;
935cdf0e10cSrcweir 		}
936cdf0e10cSrcweir 		break;
937cdf0e10cSrcweir 
938cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ):
939cdf0e10cSrcweir 		{
940cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq( 2048 );
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 			memset( aSeq.getArray(), 0, 2048 );
943cdf0e10cSrcweir 			strcpy( reinterpret_cast< char* >( aSeq.getArray() ), ByteString( rBmk.GetURL(), eSysCSet).GetBuffer() );
944cdf0e10cSrcweir 			strcpy( reinterpret_cast< char* >( aSeq.getArray() ) + 1024, ByteString( rBmk.GetDescription(), eSysCSet ).GetBuffer() );
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 			maAny <<= aSeq;
947cdf0e10cSrcweir 		}
948cdf0e10cSrcweir 		break;
949cdf0e10cSrcweir 
950cdf0e10cSrcweir #ifdef WNT
951cdf0e10cSrcweir 		case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
952cdf0e10cSrcweir 		{
953cdf0e10cSrcweir 			Sequence< sal_Int8 >	aSeq( sizeof( FILEGROUPDESCRIPTOR ) );
954cdf0e10cSrcweir 			FILEGROUPDESCRIPTOR*	pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getArray();
955cdf0e10cSrcweir 			FILEDESCRIPTOR&			rFDesc1 = pFDesc->fgd[ 0 ];
956cdf0e10cSrcweir 
957cdf0e10cSrcweir 			pFDesc->cItems = 1;
958cdf0e10cSrcweir 			memset( &rFDesc1, 0, sizeof( FILEDESCRIPTOR ) );
959cdf0e10cSrcweir 			rFDesc1.dwFlags = FD_LINKUI;
960cdf0e10cSrcweir 
961cdf0e10cSrcweir 			ByteString aStr( rBmk.GetDescription(), eSysCSet );
962cdf0e10cSrcweir 			for( sal_uInt16 nChar = 0; nChar < aStr.Len(); ++nChar )
963cdf0e10cSrcweir 				if( strchr( "\\/:*?\"<>|", aStr.GetChar( nChar ) ) )
964cdf0e10cSrcweir 					aStr.Erase( nChar--, 1 );
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 			aStr.Insert( "Shortcut to ", 0 );
967cdf0e10cSrcweir 			aStr += ".URL";
968cdf0e10cSrcweir 			strcpy( rFDesc1.cFileName, aStr.GetBuffer() );
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 			maAny <<= aSeq;
971cdf0e10cSrcweir 		}
972cdf0e10cSrcweir 		break;
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 		case SOT_FORMATSTR_ID_FILECONTENT:
975cdf0e10cSrcweir 		{
976cdf0e10cSrcweir 			String aStr( RTL_CONSTASCII_STRINGPARAM( "[InternetShortcut]\x0aURL=" ) );
977cdf0e10cSrcweir 			maAny <<= ::rtl::OUString( aStr += rBmk.GetURL() );
978cdf0e10cSrcweir 		}
979cdf0e10cSrcweir 		break;
980cdf0e10cSrcweir #endif
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 		default:
983cdf0e10cSrcweir 		break;
984cdf0e10cSrcweir 	}
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 	return( maAny.hasValue() );
987cdf0e10cSrcweir }
988cdf0e10cSrcweir 
989cdf0e10cSrcweir // -----------------------------------------------------------------------------
990cdf0e10cSrcweir 
SetINetImage(const INetImage & rINtImg,const::com::sun::star::datatransfer::DataFlavor & rFlavor)991cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetImage( const INetImage& rINtImg,
992cdf0e10cSrcweir 										   const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
993cdf0e10cSrcweir {
994cdf0e10cSrcweir 	SvMemoryStream aMemStm( 1024, 1024 );
995cdf0e10cSrcweir 
996cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
997cdf0e10cSrcweir 	rINtImg.Write( aMemStm, SotExchange::GetFormat( rFlavor ) );
998cdf0e10cSrcweir 
999cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir 	return( maAny.hasValue() );
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir // -----------------------------------------------------------------------------
1005cdf0e10cSrcweir 
SetFileList(const FileList & rFileList,const::com::sun::star::datatransfer::DataFlavor &)1006cdf0e10cSrcweir sal_Bool TransferableHelper::SetFileList( const FileList& rFileList,
1007cdf0e10cSrcweir 										  const ::com::sun::star::datatransfer::DataFlavor& )
1008cdf0e10cSrcweir {
1009cdf0e10cSrcweir 	SvMemoryStream aMemStm( 4096, 4096 );
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
1012cdf0e10cSrcweir 	aMemStm << rFileList;
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ),
1015cdf0e10cSrcweir                                        aMemStm.Seek( STREAM_SEEK_TO_END ) );
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 	return( maAny.hasValue() );
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir // -----------------------------------------------------------------------------
1021cdf0e10cSrcweir 
SetObject(void * pUserObject,sal_uInt32 nUserObjectId,const DataFlavor & rFlavor)1022cdf0e10cSrcweir sal_Bool TransferableHelper::SetObject( void* pUserObject, sal_uInt32 nUserObjectId, const DataFlavor& rFlavor )
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir 	SotStorageStreamRef xStm( new SotStorageStream( String() ) );
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir     xStm->SetVersion( SOFFICE_FILEFORMAT_50 );
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir 	if( pUserObject && WriteObject( xStm, pUserObject, nUserObjectId, rFlavor ) )
1029cdf0e10cSrcweir 	{
1030cdf0e10cSrcweir 		const sal_uInt32		nLen = xStm->Seek( STREAM_SEEK_TO_END );
1031cdf0e10cSrcweir 		Sequence< sal_Int8 >	aSeq( nLen );
1032cdf0e10cSrcweir 
1033cdf0e10cSrcweir 		xStm->Seek( STREAM_SEEK_TO_BEGIN );
1034cdf0e10cSrcweir 		xStm->Read( aSeq.getArray(),  nLen );
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir 		if( nLen && ( SotExchange::GetFormat( rFlavor ) == SOT_FORMAT_STRING ) )
1037cdf0e10cSrcweir         {
1038cdf0e10cSrcweir             //JP 24.7.2001: as I know was this only for the writer application and this
1039cdf0e10cSrcweir             //		        writes now UTF16 format into the stream
1040cdf0e10cSrcweir             //JP 6.8.2001:  and now it writes UTF8 because then exist no problem with
1041cdf0e10cSrcweir             //		        little / big endians! - Bug 88121
1042cdf0e10cSrcweir 			maAny <<= ::rtl::OUString( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), nLen - 1, RTL_TEXTENCODING_UTF8 );
1043cdf0e10cSrcweir         }
1044cdf0e10cSrcweir 		else
1045cdf0e10cSrcweir 			maAny <<= aSeq;
1046cdf0e10cSrcweir 	}
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 	return( maAny.hasValue() );
1049cdf0e10cSrcweir }
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir // -----------------------------------------------------------------------------
1052cdf0e10cSrcweir 
SetInterface(const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & rIf,const::com::sun::star::datatransfer::DataFlavor &)1053cdf0e10cSrcweir sal_Bool TransferableHelper::SetInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rIf,
1054cdf0e10cSrcweir 										   const ::com::sun::star::datatransfer::DataFlavor& )
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir 	maAny <<= rIf;
1057cdf0e10cSrcweir 	return( maAny.hasValue() );
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir // -----------------------------------------------------------------------------
1061cdf0e10cSrcweir 
WriteObject(SotStorageStreamRef &,void *,sal_uInt32,const DataFlavor &)1062cdf0e10cSrcweir sal_Bool TransferableHelper::WriteObject( SotStorageStreamRef&, void*, sal_uInt32, const DataFlavor& )
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir 	DBG_ERROR( "TransferableHelper::WriteObject( ... ) not implemented" );
1065cdf0e10cSrcweir 	return sal_False;
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir // -----------------------------------------------------------------------------
1069cdf0e10cSrcweir 
DragFinished(sal_Int8)1070cdf0e10cSrcweir void TransferableHelper::DragFinished( sal_Int8 )
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir // -----------------------------------------------------------------------------
1075cdf0e10cSrcweir 
ObjectReleased()1076cdf0e10cSrcweir void TransferableHelper::ObjectReleased()
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir // -----------------------------------------------------------------------------
1081cdf0e10cSrcweir 
PrepareOLE(const TransferableObjectDescriptor & rObjDesc)1082cdf0e10cSrcweir void TransferableHelper::PrepareOLE( const TransferableObjectDescriptor& rObjDesc )
1083cdf0e10cSrcweir {
1084cdf0e10cSrcweir     delete mpObjDesc;
1085cdf0e10cSrcweir     mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir     if( HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
1088cdf0e10cSrcweir         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir // -----------------------------------------------------------------------------
1092cdf0e10cSrcweir 
CopyToClipboard(Window * pWindow) const1093cdf0e10cSrcweir void TransferableHelper::CopyToClipboard( Window *pWindow ) const
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1096cdf0e10cSrcweir     Reference< XClipboard > xClipboard;
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir     if( pWindow )
1099cdf0e10cSrcweir         xClipboard = pWindow->GetClipboard();
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir     if( xClipboard.is() )
1102cdf0e10cSrcweir         mxClipboard = xClipboard;
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 	if( mxClipboard.is() && !mxTerminateListener.is() )
1105cdf0e10cSrcweir 	{
1106cdf0e10cSrcweir 		const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir 		try
1109cdf0e10cSrcweir 		{
1110cdf0e10cSrcweir             TransferableHelper*                 pThis = const_cast< TransferableHelper* >( this );
1111cdf0e10cSrcweir 			Reference< XMultiServiceFactory >   xFact( ::comphelper::getProcessServiceFactory() );
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir 			if( xFact.is() )
1114cdf0e10cSrcweir 			{
1115cdf0e10cSrcweir 				Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 				if( xDesktop.is() )
1118cdf0e10cSrcweir 					xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) );
1119cdf0e10cSrcweir 			}
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir 			mxClipboard->setContents( pThis, pThis );
1122cdf0e10cSrcweir 		}
1123cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1124cdf0e10cSrcweir 		{
1125cdf0e10cSrcweir 		}
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 		Application::AcquireSolarMutex( nRef );
1128cdf0e10cSrcweir 	}
1129cdf0e10cSrcweir }
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir // -----------------------------------------------------------------------------
1132cdf0e10cSrcweir 
CopyToSelection(Window * pWindow) const1133cdf0e10cSrcweir void TransferableHelper::CopyToSelection( Window *pWindow ) const
1134cdf0e10cSrcweir {
1135cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1136cdf0e10cSrcweir     Reference< XClipboard > xSelection;
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir     if( pWindow )
1139cdf0e10cSrcweir         xSelection = pWindow->GetPrimarySelection();
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir 	if( xSelection.is() && !mxTerminateListener.is() )
1142cdf0e10cSrcweir 	{
1143cdf0e10cSrcweir 		const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir 		try
1146cdf0e10cSrcweir 		{
1147cdf0e10cSrcweir             TransferableHelper*                 pThis = const_cast< TransferableHelper* >( this );
1148cdf0e10cSrcweir 			Reference< XMultiServiceFactory >   xFact( ::comphelper::getProcessServiceFactory() );
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 			if( xFact.is() )
1151cdf0e10cSrcweir 			{
1152cdf0e10cSrcweir 				Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir 				if( xDesktop.is() )
1155cdf0e10cSrcweir 					xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) );
1156cdf0e10cSrcweir 			}
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir 			xSelection->setContents( pThis, pThis );
1159cdf0e10cSrcweir 		}
1160cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1161cdf0e10cSrcweir 		{
1162cdf0e10cSrcweir 		}
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir 		Application::AcquireSolarMutex( nRef );
1165cdf0e10cSrcweir 	}
1166cdf0e10cSrcweir }
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir // -----------------------------------------------------------------------------
1169cdf0e10cSrcweir 
StartDrag(Window * pWindow,sal_Int8 nDnDSourceActions,sal_Int32 nDnDPointer,sal_Int32 nDnDImage)1170cdf0e10cSrcweir void TransferableHelper::StartDrag( Window* pWindow, sal_Int8 nDnDSourceActions,
1171cdf0e10cSrcweir 									sal_Int32 nDnDPointer, sal_Int32 nDnDImage )
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1175cdf0e10cSrcweir     Reference< XDragSource > xDragSource( pWindow->GetDragSource() );
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir 	if( xDragSource.is() )
1178cdf0e10cSrcweir 	{
1179cdf0e10cSrcweir         /*
1180cdf0e10cSrcweir          *    #96792# release mouse before actually starting DnD.
1181cdf0e10cSrcweir          *    This is necessary for the X11 DnD implementation to work.
1182cdf0e10cSrcweir          */
1183cdf0e10cSrcweir         if( pWindow->IsMouseCaptured() )
1184cdf0e10cSrcweir             pWindow->ReleaseMouse();
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir         const Point	aPt( pWindow->GetPointerPosPixel() );
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir 		// On Mac OS X we are forced to execute 'startDrag' synchronously
1189cdf0e10cSrcweir 		// contrary to the XDragSource interface specification because
1190cdf0e10cSrcweir 		// we can receive drag events from the system only in the main
1191cdf0e10cSrcweir 		// thread
1192cdf0e10cSrcweir #if !defined(QUARTZ)
1193cdf0e10cSrcweir 		const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1194cdf0e10cSrcweir #endif
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir 		try
1197cdf0e10cSrcweir 		{
1198cdf0e10cSrcweir 			DragGestureEvent	aEvt;
1199cdf0e10cSrcweir 			aEvt.DragAction = DNDConstants::ACTION_COPY;
1200cdf0e10cSrcweir 			aEvt.DragOriginX = aPt.X();
1201cdf0e10cSrcweir 			aEvt.DragOriginY = aPt.Y();
1202cdf0e10cSrcweir 			aEvt.DragSource = xDragSource;
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir 			xDragSource->startDrag( aEvt, nDnDSourceActions, nDnDPointer, nDnDImage, this, this );
1205cdf0e10cSrcweir 		}
1206cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1207cdf0e10cSrcweir 		{
1208cdf0e10cSrcweir 		}
1209cdf0e10cSrcweir 
1210cdf0e10cSrcweir 		// See above for the reason of this define
1211cdf0e10cSrcweir #if !defined(QUARTZ)
1212cdf0e10cSrcweir 		Application::AcquireSolarMutex( nRef );
1213cdf0e10cSrcweir #endif
1214cdf0e10cSrcweir 	}
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir // -----------------------------------------------------------------------------
1218cdf0e10cSrcweir 
ClearSelection(Window * pWindow)1219cdf0e10cSrcweir void TransferableHelper::ClearSelection( Window *pWindow )
1220cdf0e10cSrcweir {
1221cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1222cdf0e10cSrcweir     Reference< XClipboard > xSelection( pWindow->GetPrimarySelection() );
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir 	if( xSelection.is() )
1225cdf0e10cSrcweir         xSelection->setContents( NULL, NULL );
1226cdf0e10cSrcweir }
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir // -----------------------------------------------------------------------------
1229cdf0e10cSrcweir 
GetSystemClipboard()1230cdf0e10cSrcweir Reference< XClipboard> TransferableHelper::GetSystemClipboard()
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir     Window *pFocusWindow = Application::GetFocusWindow();
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir     if( pFocusWindow )
1235cdf0e10cSrcweir         return pFocusWindow->GetClipboard();
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir 	return 	Reference< XClipboard > ();
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir // -----------------------------------------------------------------------------
1241cdf0e10cSrcweir 
getUnoTunnelId()1242cdf0e10cSrcweir const Sequence< sal_Int8 >& TransferableHelper::getUnoTunnelId()
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir     static Sequence< sal_Int8 > aSeq;
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir 	if( !aSeq.getLength() )
1247cdf0e10cSrcweir 	{
1248cdf0e10cSrcweir 		static osl::Mutex           aCreateMutex;
1249cdf0e10cSrcweir     	osl::Guard< osl::Mutex >    aGuard( aCreateMutex );
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir 		aSeq.realloc( 16 );
1252cdf0e10cSrcweir     	rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
1253cdf0e10cSrcweir 	}
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir     return aSeq;
1257cdf0e10cSrcweir }
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir // ---------------------------------
1260cdf0e10cSrcweir // - TransferableClipboardNotifier -
1261cdf0e10cSrcweir // ---------------------------------
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir class TransferableClipboardNotifier : public ::cppu::WeakImplHelper1< XClipboardListener >
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir private:
1266cdf0e10cSrcweir     ::osl::Mutex&                   mrMutex;
1267cdf0e10cSrcweir     Reference< XClipboardNotifier > mxNotifier;
1268cdf0e10cSrcweir 	TransferableDataHelper*		    mpListener;
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir protected:
1271cdf0e10cSrcweir 	// XClipboardListener
1272cdf0e10cSrcweir     virtual void SAL_CALL changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException);
1273cdf0e10cSrcweir 
1274cdf0e10cSrcweir     // XEventListener
1275cdf0e10cSrcweir     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir public:
1278cdf0e10cSrcweir     TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex );
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir     /// determines whether we're currently listening
isListening() const1281cdf0e10cSrcweir     inline bool isListening() const { return !isDisposed(); }
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir     /// determines whether the instance is disposed
isDisposed() const1284cdf0e10cSrcweir     inline bool isDisposed() const { return mpListener == NULL; }
1285cdf0e10cSrcweir 
1286cdf0e10cSrcweir     /// makes the instance non-functional
1287cdf0e10cSrcweir     void    dispose();
1288cdf0e10cSrcweir };
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir // -----------------------------------------------------------------------------
1291cdf0e10cSrcweir 
TransferableClipboardNotifier(const Reference<XClipboard> & _rxClipboard,TransferableDataHelper & _rListener,::osl::Mutex & _rMutex)1292cdf0e10cSrcweir TransferableClipboardNotifier::TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex )
1293cdf0e10cSrcweir     :mrMutex( _rMutex )
1294cdf0e10cSrcweir     ,mxNotifier( _rxClipboard, UNO_QUERY )
1295cdf0e10cSrcweir     ,mpListener( &_rListener )
1296cdf0e10cSrcweir {
1297cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
1298cdf0e10cSrcweir     {
1299cdf0e10cSrcweir         if ( mxNotifier.is() )
1300cdf0e10cSrcweir 		    mxNotifier->addClipboardListener( this );
1301cdf0e10cSrcweir         else
1302cdf0e10cSrcweir             // born dead
1303cdf0e10cSrcweir             mpListener = NULL;
1304cdf0e10cSrcweir     }
1305cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir // -----------------------------------------------------------------------------
1309cdf0e10cSrcweir 
changedContents(const clipboard::ClipboardEvent & event)1310cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException)
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1313cdf0e10cSrcweir         // the SolarMutex here is necessary, since
1314cdf0e10cSrcweir         // - we cannot call mpListener without our own mutex locked
1315cdf0e10cSrcweir         // - Rebind respectively InitFormats (called by Rebind) will
1316cdf0e10cSrcweir         // try to lock the SolarMutex, too
1317cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mrMutex );
1318cdf0e10cSrcweir 	if( mpListener )
1319cdf0e10cSrcweir 		mpListener->Rebind( event.Contents );
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir // -----------------------------------------------------------------------------
1323cdf0e10cSrcweir 
disposing(const EventObject &)1324cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::disposing( const EventObject& ) throw (RuntimeException)
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir     // clipboard is being disposed. Hmm. Okay, become disfunctional myself.
1327cdf0e10cSrcweir 	dispose();
1328cdf0e10cSrcweir }
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir // -----------------------------------------------------------------------------
1331cdf0e10cSrcweir 
dispose()1332cdf0e10cSrcweir void TransferableClipboardNotifier::dispose()
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mrMutex );
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir     Reference< XClipboardListener > xKeepMeAlive( this );
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir     if ( mxNotifier.is() )
1339cdf0e10cSrcweir 		mxNotifier->removeClipboardListener( this );
1340cdf0e10cSrcweir     mxNotifier.clear();
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir     mpListener = NULL;
1343cdf0e10cSrcweir }
1344cdf0e10cSrcweir 
1345cdf0e10cSrcweir // -------------------------------
1346cdf0e10cSrcweir // - TransferableDataHelper_Impl -
1347cdf0e10cSrcweir // -------------------------------
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir struct TransferableDataHelper_Impl
1350cdf0e10cSrcweir {
1351cdf0e10cSrcweir     ::osl::Mutex                    maMutex;
1352cdf0e10cSrcweir     TransferableClipboardNotifier*  mpClipboardListener;
1353cdf0e10cSrcweir 
TransferableDataHelper_ImplTransferableDataHelper_Impl1354cdf0e10cSrcweir     TransferableDataHelper_Impl()
1355cdf0e10cSrcweir         :mpClipboardListener( NULL )
1356cdf0e10cSrcweir     {
1357cdf0e10cSrcweir     }
1358cdf0e10cSrcweir };
1359cdf0e10cSrcweir 
1360cdf0e10cSrcweir // --------------------------
1361cdf0e10cSrcweir // - TransferableDataHelper -
1362cdf0e10cSrcweir // --------------------------
1363cdf0e10cSrcweir 
TransferableDataHelper()1364cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper() :
1365cdf0e10cSrcweir     mpFormats( new DataFlavorExVector ),
1366cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor ),
1367cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1368cdf0e10cSrcweir {
1369cdf0e10cSrcweir }
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir // -----------------------------------------------------------------------------
1372cdf0e10cSrcweir 
TransferableDataHelper(const Reference<::com::sun::star::datatransfer::XTransferable> & rxTransferable)1373cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const Reference< ::com::sun::star::datatransfer::XTransferable >& rxTransferable ) :
1374cdf0e10cSrcweir     mxTransfer( rxTransferable ),
1375cdf0e10cSrcweir     mpFormats( new DataFlavorExVector ),
1376cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor ),
1377cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1378cdf0e10cSrcweir {
1379cdf0e10cSrcweir 	InitFormats();
1380cdf0e10cSrcweir }
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir // -----------------------------------------------------------------------------
1383cdf0e10cSrcweir 
TransferableDataHelper(const TransferableDataHelper & rDataHelper)1384cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const TransferableDataHelper& rDataHelper ) :
1385cdf0e10cSrcweir     mxTransfer( rDataHelper.mxTransfer ),
1386cdf0e10cSrcweir     mxClipboard( rDataHelper.mxClipboard ),
1387cdf0e10cSrcweir 	mpFormats( new DataFlavorExVector( *rDataHelper.mpFormats ) ),
1388cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor( *rDataHelper.mpObjDesc ) ),
1389cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1390cdf0e10cSrcweir {
1391cdf0e10cSrcweir }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir // -----------------------------------------------------------------------------
1394cdf0e10cSrcweir 
operator =(const TransferableDataHelper & rDataHelper)1395cdf0e10cSrcweir TransferableDataHelper& TransferableDataHelper::operator=( const TransferableDataHelper& rDataHelper )
1396cdf0e10cSrcweir {
1397cdf0e10cSrcweir 	if ( this != &rDataHelper )
1398cdf0e10cSrcweir 	{
1399cdf0e10cSrcweir         ::osl::MutexGuard aGuard( mpImpl->maMutex );
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir         bool bWasClipboardListening = ( NULL != mpImpl->mpClipboardListener );
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir         if ( bWasClipboardListening )
1404cdf0e10cSrcweir             StopClipboardListening();
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir         mxTransfer = rDataHelper.mxTransfer;
1407cdf0e10cSrcweir 		delete mpFormats, mpFormats = new DataFlavorExVector( *rDataHelper.mpFormats );
1408cdf0e10cSrcweir         delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor( *rDataHelper.mpObjDesc );
1409cdf0e10cSrcweir 		mxClipboard = rDataHelper.mxClipboard;
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir         if ( bWasClipboardListening )
1412cdf0e10cSrcweir             StartClipboardListening();
1413cdf0e10cSrcweir 	}
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir 	return *this;
1416cdf0e10cSrcweir }
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir // -----------------------------------------------------------------------------
1419cdf0e10cSrcweir 
~TransferableDataHelper()1420cdf0e10cSrcweir TransferableDataHelper::~TransferableDataHelper()
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir 	StopClipboardListening( );
1423cdf0e10cSrcweir     {
1424cdf0e10cSrcweir         ::osl::MutexGuard aGuard( mpImpl->maMutex );
1425cdf0e10cSrcweir 	    delete mpFormats, mpFormats = NULL;
1426cdf0e10cSrcweir         delete mpObjDesc, mpObjDesc = NULL;
1427cdf0e10cSrcweir     }
1428cdf0e10cSrcweir     delete mpImpl;
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir // -----------------------------------------------------------------------------
1432cdf0e10cSrcweir 
FillDataFlavorExVector(const Sequence<DataFlavor> & rDataFlavorSeq,DataFlavorExVector & rDataFlavorExVector)1433cdf0e10cSrcweir void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor >& rDataFlavorSeq,
1434cdf0e10cSrcweir                                                      DataFlavorExVector& rDataFlavorExVector )
1435cdf0e10cSrcweir {
1436cdf0e10cSrcweir     try
1437cdf0e10cSrcweir     {
1438cdf0e10cSrcweir 	    Reference< XMultiServiceFactory >       xFact( ::comphelper::getProcessServiceFactory() );
1439cdf0e10cSrcweir         Reference< XMimeContentTypeFactory >    xMimeFact;
1440cdf0e10cSrcweir 	    DataFlavorEx		                    aFlavorEx;
1441cdf0e10cSrcweir         const ::rtl::OUString                   aCharsetStr( ::rtl::OUString::createFromAscii( "charset" ) );
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir 	    if( xFact.is() )
1444cdf0e10cSrcweir 		    xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii(
1445cdf0e10cSrcweir                                                               "com.sun.star.datatransfer.MimeContentTypeFactory" ) ),
1446cdf0e10cSrcweir                                                               UNO_QUERY );
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir 	    for( sal_Int32 i = 0; i < rDataFlavorSeq.getLength(); i++ )
1449cdf0e10cSrcweir 	    {
1450cdf0e10cSrcweir 		    const DataFlavor&	            rFlavor = rDataFlavorSeq[ i ];
1451cdf0e10cSrcweir             Reference< XMimeContentType >   xMimeType;
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir             try
1454cdf0e10cSrcweir             {
1455cdf0e10cSrcweir                 if( xMimeFact.is() && rFlavor.MimeType.getLength() )
1456cdf0e10cSrcweir                     xMimeType = xMimeFact->createMimeContentType( rFlavor.MimeType );
1457cdf0e10cSrcweir             }
1458cdf0e10cSrcweir             catch( const ::com::sun::star::uno::Exception& )
1459cdf0e10cSrcweir 	        {
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir 	        }
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir 		    aFlavorEx.MimeType = rFlavor.MimeType;
1464cdf0e10cSrcweir 		    aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName;
1465cdf0e10cSrcweir 		    aFlavorEx.DataType = rFlavor.DataType;
1466cdf0e10cSrcweir 		    aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor );
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir 		    rDataFlavorExVector.push_back( aFlavorEx );
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir             // add additional formats for special mime types
147145fd3b9aSArmin Le Grand             if(SOT_FORMATSTR_ID_BMP == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_PNG == aFlavorEx.mnSotId)
1472cdf0e10cSrcweir 		    {
1473cdf0e10cSrcweir 			    if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavorEx ) )
1474cdf0e10cSrcweir 			    {
1475cdf0e10cSrcweir 				    aFlavorEx.mnSotId = SOT_FORMAT_BITMAP;
1476cdf0e10cSrcweir 				    rDataFlavorExVector.push_back( aFlavorEx );
1477cdf0e10cSrcweir 			    }
1478cdf0e10cSrcweir 		    }
1479cdf0e10cSrcweir             else if( SOT_FORMATSTR_ID_WMF == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_EMF == aFlavorEx.mnSotId )
1480cdf0e10cSrcweir 		    {
1481cdf0e10cSrcweir 			    if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavorEx ) )
1482cdf0e10cSrcweir 			    {
1483cdf0e10cSrcweir 				    aFlavorEx.mnSotId = SOT_FORMAT_GDIMETAFILE;
1484cdf0e10cSrcweir 				    rDataFlavorExVector.push_back( aFlavorEx );
1485cdf0e10cSrcweir 			    }
1486cdf0e10cSrcweir 		    }
1487cdf0e10cSrcweir             else if ( SOT_FORMATSTR_ID_HTML_SIMPLE == aFlavorEx.mnSotId  )
1488cdf0e10cSrcweir             {
1489cdf0e10cSrcweir                 // #104735# HTML_SIMPLE may also be inserted without comments
1490cdf0e10cSrcweir                 aFlavorEx.mnSotId = SOT_FORMATSTR_ID_HTML_NO_COMMENT;
1491cdf0e10cSrcweir                 rDataFlavorExVector.push_back( aFlavorEx );
1492cdf0e10cSrcweir             }
1493cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) )
1494cdf0e10cSrcweir             {
1495cdf0e10cSrcweir                 // add, if it is a UTF-8 byte buffer
1496cdf0e10cSrcweir                 if( xMimeType->hasParameter( aCharsetStr ) )
1497cdf0e10cSrcweir                 {
1498cdf0e10cSrcweir                     const ::rtl::OUString aCharset( xMimeType->getParameterValue( aCharsetStr ) );
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir                     if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) ||
1501cdf0e10cSrcweir 					    xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) )
1502cdf0e10cSrcweir                     {
1503cdf0e10cSrcweir                         rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_STRING;
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir                     }
1506cdf0e10cSrcweir                 }
1507cdf0e10cSrcweir             }
1508cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/rtf" ) ) )
1509cdf0e10cSrcweir             {
1510cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_RTF;
1511cdf0e10cSrcweir             }
1512cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/html" ) ) )
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir             {
1515cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_HTML;
1516cdf0e10cSrcweir             }
1517cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) )
1518cdf0e10cSrcweir             {
1519cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMAT_FILE_LIST;
1520cdf0e10cSrcweir             }
1521cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice-objectdescriptor-xml" ) ) )
1522cdf0e10cSrcweir             {
1523cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR;
1524cdf0e10cSrcweir             }
1525cdf0e10cSrcweir 	    }
1526cdf0e10cSrcweir     }
1527cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
1528cdf0e10cSrcweir 	{
1529cdf0e10cSrcweir 	}
1530cdf0e10cSrcweir }
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir // -----------------------------------------------------------------------------
1533cdf0e10cSrcweir 
InitFormats()1534cdf0e10cSrcweir void TransferableDataHelper::InitFormats()
1535cdf0e10cSrcweir {
1536cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1537cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir     mpFormats->clear();
1540cdf0e10cSrcweir     delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor;
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir     if( mxTransfer.is() )
1543cdf0e10cSrcweir     {
1544cdf0e10cSrcweir         TransferableDataHelper::FillDataFlavorExVector( mxTransfer->getTransferDataFlavors(), *mpFormats );
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir         DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1547cdf0e10cSrcweir 
1548cdf0e10cSrcweir         while( aIter != aEnd )
1549cdf0e10cSrcweir         {
1550cdf0e10cSrcweir             if( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aIter->mnSotId )
1551cdf0e10cSrcweir             {
1552cdf0e10cSrcweir                 ImplSetParameterString( *mpObjDesc, *aIter );
1553cdf0e10cSrcweir                 aIter = aEnd;
1554cdf0e10cSrcweir             }
1555cdf0e10cSrcweir             else
1556cdf0e10cSrcweir                 ++aIter;
1557cdf0e10cSrcweir         }
1558cdf0e10cSrcweir     }
1559cdf0e10cSrcweir }
1560cdf0e10cSrcweir 
1561cdf0e10cSrcweir // -----------------------------------------------------------------------------
1562cdf0e10cSrcweir 
HasFormat(SotFormatStringId nFormat) const1563cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( SotFormatStringId nFormat ) const
1564cdf0e10cSrcweir {
1565cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir 	DataFlavorExVector::iterator	aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1568cdf0e10cSrcweir 	sal_Bool						bRet = sal_False;
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir 	while( aIter != aEnd )
1571cdf0e10cSrcweir 	{
1572cdf0e10cSrcweir 		if( nFormat == (*aIter++).mnSotId )
1573cdf0e10cSrcweir 		{
1574cdf0e10cSrcweir 			aIter = aEnd;
1575cdf0e10cSrcweir 			bRet = sal_True;
1576cdf0e10cSrcweir 		}
1577cdf0e10cSrcweir 	}
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir 	return bRet;
1580cdf0e10cSrcweir }
1581cdf0e10cSrcweir 
1582cdf0e10cSrcweir // -----------------------------------------------------------------------------
1583cdf0e10cSrcweir 
HasFormat(const DataFlavor & rFlavor) const1584cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( const DataFlavor& rFlavor ) const
1585cdf0e10cSrcweir {
1586cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir     DataFlavorExVector::iterator	aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1589cdf0e10cSrcweir 	sal_Bool						bRet = sal_False;
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir 	while( aIter != aEnd )
1592cdf0e10cSrcweir 	{
1593cdf0e10cSrcweir 		if( TransferableDataHelper::IsEqual( rFlavor, *aIter++ ) )
1594cdf0e10cSrcweir 		{
1595cdf0e10cSrcweir 			aIter = aEnd;
1596cdf0e10cSrcweir 			bRet = sal_True;
1597cdf0e10cSrcweir 		}
1598cdf0e10cSrcweir 	}
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir 	return bRet;
1601cdf0e10cSrcweir }
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir // -----------------------------------------------------------------------------
1604cdf0e10cSrcweir 
GetFormatCount() const1605cdf0e10cSrcweir sal_uInt32 TransferableDataHelper::GetFormatCount() const
1606cdf0e10cSrcweir {
1607cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1608cdf0e10cSrcweir 	return mpFormats->size();
1609cdf0e10cSrcweir }
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir // -----------------------------------------------------------------------------
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir 
GetFormat(sal_uInt32 nFormat) const1614cdf0e10cSrcweir SotFormatStringId TransferableDataHelper::GetFormat( sal_uInt32 nFormat ) const
1615cdf0e10cSrcweir {
1616cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1617cdf0e10cSrcweir 	DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" );
1618cdf0e10cSrcweir 	return( ( nFormat < mpFormats->size() ) ? (*mpFormats)[ nFormat ].mnSotId : 0 );
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir 
1621cdf0e10cSrcweir // -----------------------------------------------------------------------------
1622cdf0e10cSrcweir 
GetFormatDataFlavor(sal_uInt32 nFormat) const1623cdf0e10cSrcweir DataFlavor TransferableDataHelper::GetFormatDataFlavor( sal_uInt32 nFormat ) const
1624cdf0e10cSrcweir {
1625cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1626cdf0e10cSrcweir 	DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" );
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir     DataFlavor aRet;
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 	if( nFormat < mpFormats->size() )
1631cdf0e10cSrcweir 		aRet = (*mpFormats)[ nFormat ];
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir 	return aRet;
1634cdf0e10cSrcweir }
1635cdf0e10cSrcweir 
1636cdf0e10cSrcweir // -----------------------------------------------------------------------------
1637cdf0e10cSrcweir 
GetXTransferable() const1638cdf0e10cSrcweir Reference< XTransferable > TransferableDataHelper::GetXTransferable() const
1639cdf0e10cSrcweir {
1640cdf0e10cSrcweir 	Reference< XTransferable > xRet;
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 	if( mxTransfer.is() )
1643cdf0e10cSrcweir 	{
1644cdf0e10cSrcweir 		try
1645cdf0e10cSrcweir 		{
1646cdf0e10cSrcweir 			xRet = mxTransfer;
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir 			// do a dummy call to check, if this interface is valid (nasty)
1649cdf0e10cSrcweir 			Sequence< DataFlavor > aTestSeq( xRet->getTransferDataFlavors() );
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir 		}
1652cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1653cdf0e10cSrcweir 		{
1654cdf0e10cSrcweir 			xRet = Reference< XTransferable >();
1655cdf0e10cSrcweir 		}
1656cdf0e10cSrcweir 	}
1657cdf0e10cSrcweir 
1658cdf0e10cSrcweir 	return xRet;
1659cdf0e10cSrcweir }
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir // -----------------------------------------------------------------------------
1662cdf0e10cSrcweir 
GetAny(SotFormatStringId nFormat) const1663cdf0e10cSrcweir Any	TransferableDataHelper::GetAny( SotFormatStringId nFormat ) const
1664cdf0e10cSrcweir {
1665cdf0e10cSrcweir 	Any aReturn;
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir 	DataFlavor aFlavor;
1668cdf0e10cSrcweir 	if ( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
1669cdf0e10cSrcweir 		aReturn = GetAny( aFlavor );
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir 	return aReturn;
1672cdf0e10cSrcweir }
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir 
1675cdf0e10cSrcweir // -----------------------------------------------------------------------------
1676cdf0e10cSrcweir 
GetAny(const DataFlavor & rFlavor) const1677cdf0e10cSrcweir Any TransferableDataHelper::GetAny( const DataFlavor& rFlavor ) const
1678cdf0e10cSrcweir {
1679cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1680cdf0e10cSrcweir 	Any aRet;
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir 	try
1683cdf0e10cSrcweir 	{
1684cdf0e10cSrcweir 		if( mxTransfer.is() )
1685cdf0e10cSrcweir         {
1686cdf0e10cSrcweir             DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1687cdf0e10cSrcweir             const SotFormatStringId         nRequestFormat = SotExchange::GetFormat( rFlavor );
1688cdf0e10cSrcweir 
1689cdf0e10cSrcweir             if( nRequestFormat )
1690cdf0e10cSrcweir             {
1691cdf0e10cSrcweir     	        // try to get alien format first
1692cdf0e10cSrcweir 	            while( aIter != aEnd )
1693cdf0e10cSrcweir 	            {
1694cdf0e10cSrcweir                     if( ( nRequestFormat == (*aIter).mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( (*aIter).MimeType ) )
1695cdf0e10cSrcweir             			aRet = mxTransfer->getTransferData( *aIter );
1696cdf0e10cSrcweir 
1697cdf0e10cSrcweir                     if( aRet.hasValue() )
1698cdf0e10cSrcweir                         aIter = aEnd;
1699cdf0e10cSrcweir                     else
1700cdf0e10cSrcweir                         aIter++;
1701cdf0e10cSrcweir 	            }
1702cdf0e10cSrcweir             }
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir             if( !aRet.hasValue() )
1705cdf0e10cSrcweir     			aRet = mxTransfer->getTransferData( rFlavor );
1706cdf0e10cSrcweir         }
1707cdf0e10cSrcweir 	}
1708cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
1709cdf0e10cSrcweir 	{
1710cdf0e10cSrcweir 	}
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir 	return aRet;
1713cdf0e10cSrcweir }
1714cdf0e10cSrcweir 
1715cdf0e10cSrcweir // -----------------------------------------------------------------------------
1716cdf0e10cSrcweir 
GetString(SotFormatStringId nFormat,String & rStr)1717cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, String& rStr )
1718cdf0e10cSrcweir {
1719cdf0e10cSrcweir     ::rtl::OUString aOUString;
1720cdf0e10cSrcweir     sal_Bool        bRet = GetString( nFormat, aOUString );
1721cdf0e10cSrcweir 
1722cdf0e10cSrcweir     rStr = aOUString;
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir     return bRet;
1725cdf0e10cSrcweir }
1726cdf0e10cSrcweir 
1727cdf0e10cSrcweir // -----------------------------------------------------------------------------
1728cdf0e10cSrcweir 
GetString(const DataFlavor & rFlavor,String & rStr)1729cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, String& rStr )
1730cdf0e10cSrcweir {
1731cdf0e10cSrcweir     ::rtl::OUString aOUString;
1732cdf0e10cSrcweir     sal_Bool        bRet = GetString( rFlavor, aOUString );
1733cdf0e10cSrcweir 
1734cdf0e10cSrcweir     rStr = aOUString;
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir     return bRet;
1737cdf0e10cSrcweir }
1738cdf0e10cSrcweir 
1739cdf0e10cSrcweir // -----------------------------------------------------------------------------
1740cdf0e10cSrcweir 
GetString(SotFormatStringId nFormat,::rtl::OUString & rStr)1741cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, ::rtl::OUString& rStr )
1742cdf0e10cSrcweir {
1743cdf0e10cSrcweir 	DataFlavor aFlavor;
1744cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetString( aFlavor, rStr ) );
1745cdf0e10cSrcweir }
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir // -----------------------------------------------------------------------------
1748cdf0e10cSrcweir 
GetString(const DataFlavor & rFlavor,::rtl::OUString & rStr)1749cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, ::rtl::OUString& rStr )
1750cdf0e10cSrcweir {
1751cdf0e10cSrcweir 	Any         aAny( GetAny( rFlavor ) );
1752cdf0e10cSrcweir     sal_Bool    bRet = sal_False;
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir     if( aAny.hasValue() )
1755cdf0e10cSrcweir 	{
1756cdf0e10cSrcweir 		::rtl::OUString         aOUString;
1757cdf0e10cSrcweir 		Sequence< sal_Int8 >    aSeq;
1758cdf0e10cSrcweir 
1759cdf0e10cSrcweir         if( aAny >>= aOUString )
1760cdf0e10cSrcweir         {
1761cdf0e10cSrcweir 			rStr = aOUString;
1762cdf0e10cSrcweir             bRet = sal_True;
1763cdf0e10cSrcweir         }
1764cdf0e10cSrcweir 		else if( aAny >>= aSeq )
1765cdf0e10cSrcweir 		{
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir 			const sal_Char* pChars = reinterpret_cast< const sal_Char* >( aSeq.getConstArray() );
1768cdf0e10cSrcweir 			sal_Int32       nLen = aSeq.getLength();
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir             //JP 10.10.2001: 92930 - don't copy the last zero characterinto the string.
1771cdf0e10cSrcweir             //DVO 2002-05-27: strip _all_ trailing zeros
1772cdf0e10cSrcweir 			while( nLen && ( 0 == *( pChars + nLen - 1 ) ) )
1773cdf0e10cSrcweir 				--nLen;
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir 			rStr = ::rtl::OUString( pChars, nLen, gsl_getSystemTextEncoding() );
1776cdf0e10cSrcweir             bRet = sal_True;
1777cdf0e10cSrcweir 		}
1778cdf0e10cSrcweir 	}
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir     return bRet;
1781cdf0e10cSrcweir }
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir // -----------------------------------------------------------------------------
1784cdf0e10cSrcweir 
GetBitmapEx(SotFormatStringId nFormat,BitmapEx & rBmpEx)178545fd3b9aSArmin Le Grand sal_Bool TransferableDataHelper::GetBitmapEx( SotFormatStringId nFormat, BitmapEx& rBmpEx )
1786cdf0e10cSrcweir {
178745fd3b9aSArmin Le Grand     if(FORMAT_BITMAP == nFormat)
178845fd3b9aSArmin Le Grand     {
178945fd3b9aSArmin Le Grand         // try to get PNG first
179045fd3b9aSArmin Le Grand         DataFlavor aFlavor;
179145fd3b9aSArmin Le Grand 
179245fd3b9aSArmin Le Grand         if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor))
179345fd3b9aSArmin Le Grand         {
179445fd3b9aSArmin Le Grand             if(GetBitmapEx(aFlavor, rBmpEx))
179545fd3b9aSArmin Le Grand             {
179645fd3b9aSArmin Le Grand                 return true;
179745fd3b9aSArmin Le Grand             }
179845fd3b9aSArmin Le Grand         }
179945fd3b9aSArmin Le Grand     }
180045fd3b9aSArmin Le Grand 
180145fd3b9aSArmin Le Grand     DataFlavor aFlavor;
180245fd3b9aSArmin Le Grand     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetBitmapEx( aFlavor, rBmpEx ) );
1803cdf0e10cSrcweir }
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir // -----------------------------------------------------------------------------
1806cdf0e10cSrcweir 
GetBitmapEx(const DataFlavor & rFlavor,BitmapEx & rBmpEx)180745fd3b9aSArmin Le Grand sal_Bool TransferableDataHelper::GetBitmapEx( const DataFlavor& rFlavor, BitmapEx& rBmpEx )
1808cdf0e10cSrcweir {
180945fd3b9aSArmin Le Grand     SotStorageStreamRef xStm;
181045fd3b9aSArmin Le Grand     DataFlavor aSubstFlavor;
181145fd3b9aSArmin Le Grand     bool bRet(GetSotStorageStream(rFlavor, xStm));
1812208f27daSArmin Le Grand     bool bSuppressPNG(false); // #122982# If PNG stream not accessed, but BMP one, suppress trying to load PNG
1813cdf0e10cSrcweir 
181445fd3b9aSArmin Le Grand     if(!bRet && HasFormat(SOT_FORMATSTR_ID_PNG) && SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aSubstFlavor))
181545fd3b9aSArmin Le Grand     {
181645fd3b9aSArmin Le Grand         // when no direct success, try if PNG is available
181745fd3b9aSArmin Le Grand         bRet = GetSotStorageStream(aSubstFlavor, xStm);
181845fd3b9aSArmin Le Grand     }
1819cdf0e10cSrcweir 
182045fd3b9aSArmin Le Grand     if(!bRet && HasFormat(SOT_FORMATSTR_ID_BMP) && SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_BMP, aSubstFlavor))
182145fd3b9aSArmin Le Grand     {
182245fd3b9aSArmin Le Grand         // when no direct success, try if BMP is available
182345fd3b9aSArmin Le Grand         bRet = GetSotStorageStream(aSubstFlavor, xStm);
1824208f27daSArmin Le Grand         bSuppressPNG = bRet;
182545fd3b9aSArmin Le Grand     }
1826cdf0e10cSrcweir 
182745fd3b9aSArmin Le Grand     if(bRet)
182845fd3b9aSArmin Le Grand     {
1829208f27daSArmin Le Grand         if(!bSuppressPNG && rFlavor.MimeType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("image/png")))
183045fd3b9aSArmin Le Grand         {
183145fd3b9aSArmin Le Grand             // it's a PNG, import to BitmapEx
183245fd3b9aSArmin Le Grand             ::vcl::PNGReader aPNGReader(*xStm);
1833cdf0e10cSrcweir 
183445fd3b9aSArmin Le Grand             rBmpEx = aPNGReader.Read();
183545fd3b9aSArmin Le Grand         }
1836208f27daSArmin Le Grand 
1837208f27daSArmin Le Grand         if(rBmpEx.IsEmpty())
183845fd3b9aSArmin Le Grand         {
183945fd3b9aSArmin Le Grand             Bitmap aBitmap;
184045fd3b9aSArmin Le Grand             Bitmap aMask;
1841cdf0e10cSrcweir 
184245fd3b9aSArmin Le Grand             // explicitely use Bitmap::Read with bFileHeader = sal_True
1843*a206ee71SArmin Le Grand             // #124085# keep DIBV5 for read from clipboard, but should not happen
184445fd3b9aSArmin Le Grand             ReadDIBV5(aBitmap, aMask, *xStm);
184545fd3b9aSArmin Le Grand 
184645fd3b9aSArmin Le Grand             if(aMask.IsEmpty())
184745fd3b9aSArmin Le Grand             {
184845fd3b9aSArmin Le Grand                 rBmpEx = aBitmap;
184945fd3b9aSArmin Le Grand             }
185045fd3b9aSArmin Le Grand             else
185145fd3b9aSArmin Le Grand             {
185245fd3b9aSArmin Le Grand                 rBmpEx = BitmapEx(aBitmap, aMask);
185345fd3b9aSArmin Le Grand             }
185445fd3b9aSArmin Le Grand         }
185545fd3b9aSArmin Le Grand 
1856208f27daSArmin Le Grand         bRet = (ERRCODE_NONE == xStm->GetError() && !rBmpEx.IsEmpty());
185745fd3b9aSArmin Le Grand 
185845fd3b9aSArmin Le Grand         /* SJ: #110748# At the moment we are having problems with DDB inserted as DIB. The
185945fd3b9aSArmin Le Grand            problem is, that some graphics are inserted much too big because the nXPelsPerMeter
186045fd3b9aSArmin Le Grand            and nYPelsPerMeter of the bitmap fileheader isn't including the correct value.
186145fd3b9aSArmin Le Grand            Due to this reason the following code assumes that bitmaps with a logical size
186245fd3b9aSArmin Le Grand            greater than 50 cm aren't having the correct mapmode set.
186345fd3b9aSArmin Le Grand 
186445fd3b9aSArmin Le Grand            The following code should be removed if DDBs and DIBs are supported via clipboard
186545fd3b9aSArmin Le Grand            properly.
186645fd3b9aSArmin Le Grand         */
186745fd3b9aSArmin Le Grand         if(bRet)
186845fd3b9aSArmin Le Grand         {
186945fd3b9aSArmin Le Grand             const MapMode aMapMode(rBmpEx.GetPrefMapMode());
187045fd3b9aSArmin Le Grand 
187145fd3b9aSArmin Le Grand             if(MAP_PIXEL != aMapMode.GetMapUnit())
187245fd3b9aSArmin Le Grand             {
187345fd3b9aSArmin Le Grand                 const Size aSize(OutputDevice::LogicToLogic(rBmpEx.GetPrefSize(), aMapMode, MAP_100TH_MM));
187445fd3b9aSArmin Le Grand 
1875519071a5SArmin Le Grand                 // #122388# This wrongly corrects in the given case; changing from 5000 100th mm to
1876519071a5SArmin Le Grand                 // the described 50 cm (which is 50000 100th mm)
1877519071a5SArmin Le Grand                 if((aSize.Width() > 50000) || (aSize.Height() > 50000))
187845fd3b9aSArmin Le Grand                 {
187945fd3b9aSArmin Le Grand                     rBmpEx.SetPrefMapMode(MAP_PIXEL);
1880519071a5SArmin Le Grand 
1881519071a5SArmin Le Grand                     // #122388# also adapt size by applying the mew MapMode
1882519071a5SArmin Le Grand                     const Size aNewSize(OutputDevice::LogicToLogic(aSize, MAP_100TH_MM, MAP_PIXEL));
1883519071a5SArmin Le Grand                     rBmpEx.SetPrefSize(aNewSize);
188445fd3b9aSArmin Le Grand                 }
188545fd3b9aSArmin Le Grand             }
188645fd3b9aSArmin Le Grand         }
188745fd3b9aSArmin Le Grand     }
188845fd3b9aSArmin Le Grand 
188945fd3b9aSArmin Le Grand     return bRet;
1890cdf0e10cSrcweir }
1891cdf0e10cSrcweir 
1892cdf0e10cSrcweir // -----------------------------------------------------------------------------
1893cdf0e10cSrcweir 
GetGDIMetaFile(SotFormatStringId nFormat,GDIMetaFile & rMtf)1894cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( SotFormatStringId nFormat, GDIMetaFile& rMtf )
1895cdf0e10cSrcweir {
1896cdf0e10cSrcweir 	DataFlavor aFlavor;
1897cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGDIMetaFile( aFlavor, rMtf ) );
1898cdf0e10cSrcweir }
1899cdf0e10cSrcweir 
1900cdf0e10cSrcweir // -----------------------------------------------------------------------------
1901cdf0e10cSrcweir 
GetGDIMetaFile(const DataFlavor & rFlavor,GDIMetaFile & rMtf)1902cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaFile& rMtf )
1903cdf0e10cSrcweir {
1904cdf0e10cSrcweir 	SotStorageStreamRef xStm;
1905cdf0e10cSrcweir 	DataFlavor			aSubstFlavor;
1906cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
1907cdf0e10cSrcweir 
1908cdf0e10cSrcweir 	if( GetSotStorageStream( rFlavor, xStm ) )
1909cdf0e10cSrcweir 	{
1910cdf0e10cSrcweir 		*xStm >> rMtf;
1911cdf0e10cSrcweir 		bRet = ( xStm->GetError() == ERRCODE_NONE );
1912cdf0e10cSrcweir 	}
1913cdf0e10cSrcweir 
1914cdf0e10cSrcweir 	if( !bRet &&
1915cdf0e10cSrcweir 		HasFormat( SOT_FORMATSTR_ID_EMF ) &&
1916cdf0e10cSrcweir 		SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_EMF, aSubstFlavor ) &&
1917cdf0e10cSrcweir 		GetSotStorageStream( aSubstFlavor, xStm ) )
1918cdf0e10cSrcweir 	{
1919cdf0e10cSrcweir 		Graphic aGraphic;
1920cdf0e10cSrcweir 
1921cdf0e10cSrcweir 		if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE )
1922cdf0e10cSrcweir 		{
1923cdf0e10cSrcweir 			rMtf = aGraphic.GetGDIMetaFile();
1924cdf0e10cSrcweir 			bRet = sal_True;
1925cdf0e10cSrcweir 		}
1926cdf0e10cSrcweir 	}
1927cdf0e10cSrcweir 
1928cdf0e10cSrcweir 	if( !bRet &&
1929cdf0e10cSrcweir 		HasFormat( SOT_FORMATSTR_ID_WMF ) &&
1930cdf0e10cSrcweir 		SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_WMF, aSubstFlavor ) &&
1931cdf0e10cSrcweir 		GetSotStorageStream( aSubstFlavor, xStm ) )
1932cdf0e10cSrcweir 	{
1933cdf0e10cSrcweir 		Graphic aGraphic;
1934cdf0e10cSrcweir 
1935cdf0e10cSrcweir 		if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE )
1936cdf0e10cSrcweir 		{
1937cdf0e10cSrcweir 			rMtf = aGraphic.GetGDIMetaFile();
1938cdf0e10cSrcweir 			bRet = sal_True;
1939cdf0e10cSrcweir 		}
1940cdf0e10cSrcweir 	}
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir 	return bRet;
1943cdf0e10cSrcweir }
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir // -----------------------------------------------------------------------------
1946cdf0e10cSrcweir 
GetGraphic(SotFormatStringId nFormat,Graphic & rGraphic)1947cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( SotFormatStringId nFormat, Graphic& rGraphic )
1948cdf0e10cSrcweir {
194945fd3b9aSArmin Le Grand     if(FORMAT_BITMAP == nFormat)
195045fd3b9aSArmin Le Grand     {
195145fd3b9aSArmin Le Grand         // try to get PNG first
195245fd3b9aSArmin Le Grand         DataFlavor aFlavor;
195345fd3b9aSArmin Le Grand 
195445fd3b9aSArmin Le Grand         if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor))
195545fd3b9aSArmin Le Grand         {
195645fd3b9aSArmin Le Grand             if(GetGraphic(aFlavor, rGraphic))
195745fd3b9aSArmin Le Grand             {
195845fd3b9aSArmin Le Grand                 return true;
195945fd3b9aSArmin Le Grand             }
196045fd3b9aSArmin Le Grand         }
196145fd3b9aSArmin Le Grand     }
196245fd3b9aSArmin Le Grand 
196345fd3b9aSArmin Le Grand     DataFlavor aFlavor;
196445fd3b9aSArmin Le Grand     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGraphic( aFlavor, rGraphic ) );
1965cdf0e10cSrcweir }
1966cdf0e10cSrcweir 
1967cdf0e10cSrcweir // -----------------------------------------------------------------------------
1968cdf0e10cSrcweir 
GetGraphic(const::com::sun::star::datatransfer::DataFlavor & rFlavor,Graphic & rGraphic)1969cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, Graphic& rGraphic )
1970cdf0e10cSrcweir {
1971cdf0e10cSrcweir 	DataFlavor	aFlavor;
1972cdf0e10cSrcweir 	sal_Bool	bRet = sal_False;
1973cdf0e10cSrcweir 
197445fd3b9aSArmin Le Grand     if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor) &&
197545fd3b9aSArmin Le Grand         TransferableDataHelper::IsEqual(aFlavor, rFlavor))
197645fd3b9aSArmin Le Grand 	{
197745fd3b9aSArmin Le Grand         // try to get PNG first
197845fd3b9aSArmin Le Grand 		BitmapEx aBmpEx;
197945fd3b9aSArmin Le Grand 
198045fd3b9aSArmin Le Grand 		if( ( bRet = GetBitmapEx( aFlavor, aBmpEx ) ) == sal_True )
198145fd3b9aSArmin Le Grand 			rGraphic = aBmpEx;
198245fd3b9aSArmin Le Grand 	}
198345fd3b9aSArmin Le Grand 	else if(SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavor ) &&
1984cdf0e10cSrcweir 		TransferableDataHelper::IsEqual( aFlavor, rFlavor ) )
1985cdf0e10cSrcweir 	{
198645fd3b9aSArmin Le Grand 		BitmapEx aBmpEx;
1987cdf0e10cSrcweir 
198845fd3b9aSArmin Le Grand 		if( ( bRet = GetBitmapEx( aFlavor, aBmpEx ) ) == sal_True )
198945fd3b9aSArmin Le Grand 			rGraphic = aBmpEx;
1990cdf0e10cSrcweir 	}
1991cdf0e10cSrcweir 	else if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavor ) &&
1992cdf0e10cSrcweir 			 TransferableDataHelper::IsEqual( aFlavor, rFlavor ) )
1993cdf0e10cSrcweir 	{
1994cdf0e10cSrcweir 		GDIMetaFile aMtf;
1995cdf0e10cSrcweir 
1996cdf0e10cSrcweir 		if( ( bRet = GetGDIMetaFile( aFlavor, aMtf ) ) == sal_True )
1997cdf0e10cSrcweir 			rGraphic = aMtf;
1998cdf0e10cSrcweir 	}
1999cdf0e10cSrcweir 	else
2000cdf0e10cSrcweir 	{
2001cdf0e10cSrcweir 		SotStorageStreamRef xStm;
2002cdf0e10cSrcweir 
2003cdf0e10cSrcweir 		if( GetSotStorageStream( rFlavor, xStm ) )
2004cdf0e10cSrcweir 		{
2005cdf0e10cSrcweir 			*xStm >> rGraphic;
2006cdf0e10cSrcweir 			bRet = ( xStm->GetError() == ERRCODE_NONE );
2007cdf0e10cSrcweir 		}
2008cdf0e10cSrcweir 	}
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir 	return bRet;
2011cdf0e10cSrcweir }
2012cdf0e10cSrcweir 
2013cdf0e10cSrcweir // -----------------------------------------------------------------------------
2014cdf0e10cSrcweir 
GetImageMap(SotFormatStringId nFormat,ImageMap & rIMap)2015cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( SotFormatStringId nFormat, ImageMap& rIMap )
2016cdf0e10cSrcweir {
2017cdf0e10cSrcweir 	DataFlavor aFlavor;
2018cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetImageMap( aFlavor, rIMap ) );
2019cdf0e10cSrcweir }
2020cdf0e10cSrcweir 
2021cdf0e10cSrcweir // -----------------------------------------------------------------------------
2022cdf0e10cSrcweir 
GetImageMap(const::com::sun::star::datatransfer::DataFlavor & rFlavor,ImageMap & rIMap)2023cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, ImageMap& rIMap )
2024cdf0e10cSrcweir {
2025cdf0e10cSrcweir 	SotStorageStreamRef xStm;
2026cdf0e10cSrcweir 	sal_Bool			bRet = GetSotStorageStream( rFlavor, xStm );
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir 	if( bRet )
2029cdf0e10cSrcweir 	{
2030cdf0e10cSrcweir         rIMap.Read( *xStm, String() );
2031cdf0e10cSrcweir 		bRet = ( xStm->GetError() == ERRCODE_NONE );
2032cdf0e10cSrcweir 	}
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir 	return bRet;
2035cdf0e10cSrcweir }
2036cdf0e10cSrcweir 
2037cdf0e10cSrcweir // -----------------------------------------------------------------------------
2038cdf0e10cSrcweir 
GetTransferableObjectDescriptor(SotFormatStringId nFormat,TransferableObjectDescriptor & rDesc)2039cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( SotFormatStringId nFormat, TransferableObjectDescriptor& rDesc )
2040cdf0e10cSrcweir {
2041cdf0e10cSrcweir 	DataFlavor aFlavor;
2042cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetTransferableObjectDescriptor( aFlavor, rDesc ) );
2043cdf0e10cSrcweir }
2044cdf0e10cSrcweir 
2045cdf0e10cSrcweir // -----------------------------------------------------------------------------
2046cdf0e10cSrcweir 
GetTransferableObjectDescriptor(const::com::sun::star::datatransfer::DataFlavor &,TransferableObjectDescriptor & rDesc)2047cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( const ::com::sun::star::datatransfer::DataFlavor&, TransferableObjectDescriptor& rDesc )
2048cdf0e10cSrcweir {
2049cdf0e10cSrcweir     rDesc = *mpObjDesc;
2050cdf0e10cSrcweir     return true;
2051cdf0e10cSrcweir }
2052cdf0e10cSrcweir 
2053cdf0e10cSrcweir // -----------------------------------------------------------------------------
2054cdf0e10cSrcweir 
GetINetBookmark(SotFormatStringId nFormat,INetBookmark & rBmk)2055cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( SotFormatStringId nFormat, INetBookmark& rBmk )
2056cdf0e10cSrcweir {
2057cdf0e10cSrcweir 	DataFlavor aFlavor;
2058cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetBookmark( aFlavor, rBmk ) );
2059cdf0e10cSrcweir }
2060cdf0e10cSrcweir 
2061cdf0e10cSrcweir // -----------------------------------------------------------------------------
2062cdf0e10cSrcweir 
GetINetBookmark(const::com::sun::star::datatransfer::DataFlavor & rFlavor,INetBookmark & rBmk)2063cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, INetBookmark& rBmk )
2064cdf0e10cSrcweir {
2065cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2066cdf0e10cSrcweir 	if( HasFormat( rFlavor ))
2067cdf0e10cSrcweir 	{
2068cdf0e10cSrcweir 	const SotFormatStringId nFormat = SotExchange::GetFormat( rFlavor );
2069cdf0e10cSrcweir 	switch( nFormat )
2070cdf0e10cSrcweir 	{
2071cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_SOLK ):
2072cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ):
2073cdf0e10cSrcweir 		{
2074cdf0e10cSrcweir 			String aString;
2075cdf0e10cSrcweir 			if( GetString( rFlavor, aString ) )
2076cdf0e10cSrcweir 			{
2077cdf0e10cSrcweir 				if( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR == nFormat )
2078cdf0e10cSrcweir 				{
2079cdf0e10cSrcweir 					rBmk = INetBookmark( aString, aString );
2080cdf0e10cSrcweir 					bRet = sal_True;
2081cdf0e10cSrcweir 				}
2082cdf0e10cSrcweir 				else
2083cdf0e10cSrcweir 				{
2084cdf0e10cSrcweir 					String		aURL, aDesc;
2085cdf0e10cSrcweir 					sal_uInt16	nStart = aString.Search( '@' ), nLen = (sal_uInt16) aString.ToInt32();
2086cdf0e10cSrcweir 
2087cdf0e10cSrcweir 					if( !nLen && aString.GetChar( 0 ) != '0' )
2088cdf0e10cSrcweir 					{
2089cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 1. len=0" );
2090cdf0e10cSrcweir 					}
2091cdf0e10cSrcweir 					if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 3 )
2092cdf0e10cSrcweir 					{
2093cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 1. illegal start or wrong len" );
2094cdf0e10cSrcweir 					}
2095cdf0e10cSrcweir 					aURL = aString.Copy( nStart + 1, nLen );
2096cdf0e10cSrcweir 
2097cdf0e10cSrcweir 					aString.Erase( 0, nStart + 1 + nLen );
2098cdf0e10cSrcweir 					nStart = aString.Search( '@' );
2099cdf0e10cSrcweir 					nLen = (sal_uInt16) aString.ToInt32();
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir 					if( !nLen && aString.GetChar( 0 ) != '0' )
2102cdf0e10cSrcweir 					{
2103cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 2. len=0" );
2104cdf0e10cSrcweir 					}
2105cdf0e10cSrcweir 					if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 1 )
2106cdf0e10cSrcweir 					{
2107cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 2. illegal start or wrong len" );
2108cdf0e10cSrcweir 					}
2109cdf0e10cSrcweir 					aDesc = aString.Copy( nStart+1, nLen );
2110cdf0e10cSrcweir 
2111cdf0e10cSrcweir 					rBmk = INetBookmark( aURL, aDesc );
2112cdf0e10cSrcweir 					bRet = sal_True;
2113cdf0e10cSrcweir 				}
2114cdf0e10cSrcweir 			}
2115cdf0e10cSrcweir 		}
2116cdf0e10cSrcweir 		break;
2117cdf0e10cSrcweir 
2118cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ):
2119cdf0e10cSrcweir 		{
2120cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq;
2121cdf0e10cSrcweir 
2122cdf0e10cSrcweir 			if( GetSequence( rFlavor, aSeq ) && ( 2048 == aSeq.getLength() ) )
2123cdf0e10cSrcweir 			{
2124cdf0e10cSrcweir 				rBmk = INetBookmark( String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), gsl_getSystemTextEncoding() ),
2125cdf0e10cSrcweir 									 String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ) + 1024, gsl_getSystemTextEncoding() ) );
2126cdf0e10cSrcweir 				bRet = sal_True;
2127cdf0e10cSrcweir 			}
2128cdf0e10cSrcweir 		}
2129cdf0e10cSrcweir 		break;
2130cdf0e10cSrcweir 
2131cdf0e10cSrcweir #ifdef WNT
2132cdf0e10cSrcweir 		case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
2133cdf0e10cSrcweir 		{
2134cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq;
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir 			if( GetSequence( rFlavor, aSeq ) && aSeq.getLength() )
2137cdf0e10cSrcweir 			{
2138cdf0e10cSrcweir 				FILEGROUPDESCRIPTOR* pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getConstArray();
2139cdf0e10cSrcweir 
2140cdf0e10cSrcweir 				if( pFDesc->cItems )
2141cdf0e10cSrcweir 				{
2142cdf0e10cSrcweir 					ByteString			aDesc( pFDesc->fgd[ 0 ].cFileName );
2143cdf0e10cSrcweir 					rtl_TextEncoding	eTextEncoding = gsl_getSystemTextEncoding();
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir 					if( ( aDesc.Len() > 4 ) && aDesc.Copy( aDesc.Len() - 4 ).EqualsIgnoreCaseAscii( ".URL" ) )
2146cdf0e10cSrcweir 					{
2147cdf0e10cSrcweir 						SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( INetURLObject( String( aDesc, eTextEncoding ) ).GetMainURL( INetURLObject::NO_DECODE ),
2148cdf0e10cSrcweir                                                                                   STREAM_STD_READ );
2149cdf0e10cSrcweir 
2150cdf0e10cSrcweir 						if( !pStream || pStream->GetError() )
2151cdf0e10cSrcweir 						{
2152cdf0e10cSrcweir 							DataFlavor aFileContentFlavor;
2153cdf0e10cSrcweir 
2154cdf0e10cSrcweir 							aSeq.realloc( 0 );
2155cdf0e10cSrcweir 							delete pStream;
2156cdf0e10cSrcweir 
2157cdf0e10cSrcweir 							if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_FILECONTENT, aFileContentFlavor ) &&
2158cdf0e10cSrcweir 								GetSequence( aFileContentFlavor, aSeq ) && aSeq.getLength() )
2159cdf0e10cSrcweir 							{
2160cdf0e10cSrcweir 								pStream = new SvMemoryStream( (sal_Char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_STD_READ );
2161cdf0e10cSrcweir 							}
2162cdf0e10cSrcweir 							else
2163cdf0e10cSrcweir 								pStream = NULL;
2164cdf0e10cSrcweir 						}
2165cdf0e10cSrcweir 
2166cdf0e10cSrcweir 						if( pStream )
2167cdf0e10cSrcweir 						{
2168cdf0e10cSrcweir 							ByteString	aLine;
2169cdf0e10cSrcweir 							sal_Bool	bSttFnd = sal_False;
2170cdf0e10cSrcweir 
2171cdf0e10cSrcweir 							while( pStream->ReadLine( aLine ) )
2172cdf0e10cSrcweir 							{
2173cdf0e10cSrcweir 								if( aLine.EqualsIgnoreCaseAscii( "[InternetShortcut]" ) )
2174cdf0e10cSrcweir 									bSttFnd = sal_True;
2175cdf0e10cSrcweir 								else if( bSttFnd && aLine.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "URL=" ) )
2176cdf0e10cSrcweir 								{
2177cdf0e10cSrcweir 									rBmk = INetBookmark( String( aLine.Erase( 0, 4 ), eTextEncoding ),
2178cdf0e10cSrcweir 														 String( aDesc.Erase( aDesc.Len() - 4 ), eTextEncoding ) );
2179cdf0e10cSrcweir 									bRet = sal_True;
2180cdf0e10cSrcweir 									break;
2181cdf0e10cSrcweir 								}
2182cdf0e10cSrcweir 							}
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir 							delete pStream;
2185cdf0e10cSrcweir 						}
2186cdf0e10cSrcweir 					}
2187cdf0e10cSrcweir 				}
2188cdf0e10cSrcweir 			}
2189cdf0e10cSrcweir 		}
2190cdf0e10cSrcweir 		break;
2191cdf0e10cSrcweir #endif
2192cdf0e10cSrcweir 
2193cdf0e10cSrcweir 	}
2194cdf0e10cSrcweir 	}
2195cdf0e10cSrcweir 	return bRet;
2196cdf0e10cSrcweir }
2197cdf0e10cSrcweir 
2198cdf0e10cSrcweir // -----------------------------------------------------------------------------
2199cdf0e10cSrcweir 
GetINetImage(SotFormatStringId nFormat,INetImage & rINtImg)2200cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage( SotFormatStringId nFormat,
2201cdf0e10cSrcweir 												INetImage& rINtImg )
2202cdf0e10cSrcweir {
2203cdf0e10cSrcweir 	DataFlavor aFlavor;
2204cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetImage( aFlavor, rINtImg ) );
2205cdf0e10cSrcweir }
2206cdf0e10cSrcweir 
2207cdf0e10cSrcweir // -----------------------------------------------------------------------------
2208cdf0e10cSrcweir 
GetINetImage(const::com::sun::star::datatransfer::DataFlavor & rFlavor,INetImage & rINtImg)2209cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage(
2210cdf0e10cSrcweir 		const ::com::sun::star::datatransfer::DataFlavor& rFlavor,
2211cdf0e10cSrcweir 		INetImage& rINtImg )
2212cdf0e10cSrcweir {
2213cdf0e10cSrcweir 	SotStorageStreamRef xStm;
2214cdf0e10cSrcweir 	sal_Bool bRet = GetSotStorageStream( rFlavor, xStm );
2215cdf0e10cSrcweir 
2216cdf0e10cSrcweir 	if( bRet )
2217cdf0e10cSrcweir 		bRet = rINtImg.Read( *xStm, SotExchange::GetFormat( rFlavor ) );
2218cdf0e10cSrcweir 	return bRet;
2219cdf0e10cSrcweir }
2220cdf0e10cSrcweir 
2221cdf0e10cSrcweir // -----------------------------------------------------------------------------
2222cdf0e10cSrcweir 
GetFileList(SotFormatStringId nFormat,FileList & rFileList)2223cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList( SotFormatStringId nFormat,
2224cdf0e10cSrcweir 												FileList& rFileList )
2225cdf0e10cSrcweir {
2226cdf0e10cSrcweir 	DataFlavor aFlavor;
2227cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetFileList( aFlavor, rFileList ) );
2228cdf0e10cSrcweir }
2229cdf0e10cSrcweir 
2230cdf0e10cSrcweir // -----------------------------------------------------------------------------
2231cdf0e10cSrcweir 
GetFileList(const::com::sun::star::datatransfer::DataFlavor &,FileList & rFileList)2232cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList(
2233cdf0e10cSrcweir 			const ::com::sun::star::datatransfer::DataFlavor&,
2234cdf0e10cSrcweir 			FileList& rFileList )
2235cdf0e10cSrcweir {
2236cdf0e10cSrcweir 	SotStorageStreamRef xStm;
2237cdf0e10cSrcweir     sal_Bool            bRet = sal_False;
2238cdf0e10cSrcweir 
2239cdf0e10cSrcweir     for( sal_uInt32 i = 0, nFormatCount = GetFormatCount(); ( i < nFormatCount ) && !bRet; ++i )
2240cdf0e10cSrcweir     {
2241cdf0e10cSrcweir         if( SOT_FORMAT_FILE_LIST == GetFormat( i ) )
2242cdf0e10cSrcweir         {
2243cdf0e10cSrcweir             const DataFlavor aFlavor( GetFormatDataFlavor( i ) );
2244cdf0e10cSrcweir 
2245cdf0e10cSrcweir             if( GetSotStorageStream( aFlavor, xStm ) )
2246cdf0e10cSrcweir             {
2247cdf0e10cSrcweir                 if( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) > -1 )
2248cdf0e10cSrcweir                 {
2249cdf0e10cSrcweir                     ByteString aByteString;
2250cdf0e10cSrcweir 
2251cdf0e10cSrcweir                     while( xStm->ReadLine( aByteString ) )
2252cdf0e10cSrcweir                         if( aByteString.Len() && aByteString.GetChar( 0 ) != '#' )
2253cdf0e10cSrcweir                             rFileList.AppendFile( String( aByteString, RTL_TEXTENCODING_UTF8 ) );
2254cdf0e10cSrcweir 
2255cdf0e10cSrcweir                     bRet = sal_True;
2256cdf0e10cSrcweir                  }
2257cdf0e10cSrcweir                  else
2258cdf0e10cSrcweir                     bRet = ( ( *xStm >> rFileList ).GetError() == ERRCODE_NONE );
2259cdf0e10cSrcweir             }
2260cdf0e10cSrcweir         }
2261cdf0e10cSrcweir     }
2262cdf0e10cSrcweir 
2263cdf0e10cSrcweir     return bRet;
2264cdf0e10cSrcweir }
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir // -----------------------------------------------------------------------------
2267cdf0e10cSrcweir 
GetSequence(SotFormatStringId nFormat,Sequence<sal_Int8> & rSeq)2268cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( SotFormatStringId nFormat, Sequence< sal_Int8 >& rSeq )
2269cdf0e10cSrcweir {
2270cdf0e10cSrcweir 	DataFlavor aFlavor;
2271cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSequence( aFlavor, rSeq ) );
2272cdf0e10cSrcweir }
2273cdf0e10cSrcweir 
2274cdf0e10cSrcweir // -----------------------------------------------------------------------------
2275cdf0e10cSrcweir 
GetSequence(const DataFlavor & rFlavor,Sequence<sal_Int8> & rSeq)2276cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( const DataFlavor& rFlavor, Sequence< sal_Int8 >& rSeq )
2277cdf0e10cSrcweir {
2278cdf0e10cSrcweir #ifdef DEBUG
2279cdf0e10cSrcweir     fprintf( stderr, "TransferableDataHelper requests sequence of data\n" );
2280cdf0e10cSrcweir #endif
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir     const Any aAny( GetAny( rFlavor ) );
2283cdf0e10cSrcweir 	return( aAny.hasValue() && ( aAny >>= rSeq ) );
2284cdf0e10cSrcweir }
2285cdf0e10cSrcweir 
2286cdf0e10cSrcweir // -----------------------------------------------------------------------------
2287cdf0e10cSrcweir 
GetSotStorageStream(SotFormatStringId nFormat,SotStorageStreamRef & rxStream)2288cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( SotFormatStringId nFormat, SotStorageStreamRef& rxStream )
2289cdf0e10cSrcweir {
2290cdf0e10cSrcweir     DataFlavor aFlavor;
2291cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSotStorageStream( aFlavor, rxStream ) );
2292cdf0e10cSrcweir }
2293cdf0e10cSrcweir 
2294cdf0e10cSrcweir // -----------------------------------------------------------------------------
2295cdf0e10cSrcweir 
GetSotStorageStream(const DataFlavor & rFlavor,SotStorageStreamRef & rxStream)2296cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( const DataFlavor& rFlavor, SotStorageStreamRef& rxStream )
2297cdf0e10cSrcweir {
2298cdf0e10cSrcweir 	Sequence< sal_Int8 >	aSeq;
2299cdf0e10cSrcweir 	sal_Bool				bRet = GetSequence( rFlavor, aSeq );
2300cdf0e10cSrcweir 
2301cdf0e10cSrcweir 	if( bRet )
2302cdf0e10cSrcweir 	{
2303cdf0e10cSrcweir 		rxStream = new SotStorageStream( String() );
2304cdf0e10cSrcweir 		rxStream->Write( aSeq.getConstArray(), aSeq.getLength() );
2305cdf0e10cSrcweir 		rxStream->Seek( 0 );
2306cdf0e10cSrcweir 	}
2307cdf0e10cSrcweir 
2308cdf0e10cSrcweir 	return bRet;
2309cdf0e10cSrcweir }
2310cdf0e10cSrcweir 
GetInputStream(SotFormatStringId nFormat,Reference<XInputStream> & rxStream)2311cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( SotFormatStringId nFormat, Reference < XInputStream >& rxStream )
2312cdf0e10cSrcweir {
2313cdf0e10cSrcweir 	DataFlavor aFlavor;
2314cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInputStream( aFlavor, rxStream ) );
2315cdf0e10cSrcweir }
2316cdf0e10cSrcweir 
2317cdf0e10cSrcweir // -----------------------------------------------------------------------------
2318cdf0e10cSrcweir 
GetInputStream(const DataFlavor & rFlavor,Reference<XInputStream> & rxStream)2319cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( const DataFlavor& rFlavor, Reference < XInputStream >& rxStream )
2320cdf0e10cSrcweir {
2321cdf0e10cSrcweir 	Sequence< sal_Int8 >	aSeq;
2322cdf0e10cSrcweir 	sal_Bool				bRet = GetSequence( rFlavor, aSeq );
2323cdf0e10cSrcweir 
2324cdf0e10cSrcweir 	if( bRet )
2325cdf0e10cSrcweir           rxStream = new ::comphelper::SequenceInputStream( aSeq );
2326cdf0e10cSrcweir 
2327cdf0e10cSrcweir 	return bRet;
2328cdf0e10cSrcweir }
2329cdf0e10cSrcweir 
2330cdf0e10cSrcweir // -----------------------------------------------------------------------------
2331cdf0e10cSrcweir 
2332cdf0e10cSrcweir 
GetInterface(SotFormatStringId nFormat,Reference<XInterface> & rIf)2333cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( SotFormatStringId nFormat, Reference< XInterface >& rIf )
2334cdf0e10cSrcweir {
2335cdf0e10cSrcweir 	DataFlavor aFlavor;
2336cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInterface( aFlavor, rIf ) );
2337cdf0e10cSrcweir }
2338cdf0e10cSrcweir 
2339cdf0e10cSrcweir // -----------------------------------------------------------------------------
2340cdf0e10cSrcweir 
GetInterface(const DataFlavor & rFlavor,Reference<XInterface> & rIf)2341cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( const DataFlavor& rFlavor, Reference< XInterface >& rIf )
2342cdf0e10cSrcweir {
2343cdf0e10cSrcweir 	const Any aAny( GetAny( rFlavor ) );
2344cdf0e10cSrcweir 	return( aAny.hasValue() && ( aAny >>= rIf ) );
2345cdf0e10cSrcweir }
2346cdf0e10cSrcweir 
2347cdf0e10cSrcweir // -----------------------------------------------------------------------------
Rebind(const Reference<XTransferable> & _rxNewContent)2348cdf0e10cSrcweir void TransferableDataHelper::Rebind( const Reference< XTransferable >& _rxNewContent )
2349cdf0e10cSrcweir {
2350cdf0e10cSrcweir 	mxTransfer = _rxNewContent;
2351cdf0e10cSrcweir 	InitFormats();
2352cdf0e10cSrcweir }
2353cdf0e10cSrcweir 
2354cdf0e10cSrcweir // -----------------------------------------------------------------------------
2355cdf0e10cSrcweir 
StartClipboardListening()2356cdf0e10cSrcweir sal_Bool TransferableDataHelper::StartClipboardListening( )
2357cdf0e10cSrcweir {
2358cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
2359cdf0e10cSrcweir 
2360cdf0e10cSrcweir     StopClipboardListening( );
2361cdf0e10cSrcweir 
2362cdf0e10cSrcweir 	mpImpl->mpClipboardListener = new TransferableClipboardNotifier( mxClipboard, *this, mpImpl->maMutex );
2363cdf0e10cSrcweir     mpImpl->mpClipboardListener->acquire();
2364cdf0e10cSrcweir 
2365cdf0e10cSrcweir 	return mpImpl->mpClipboardListener->isListening();
2366cdf0e10cSrcweir }
2367cdf0e10cSrcweir 
2368cdf0e10cSrcweir // -----------------------------------------------------------------------------
2369cdf0e10cSrcweir 
StopClipboardListening()2370cdf0e10cSrcweir void TransferableDataHelper::StopClipboardListening( )
2371cdf0e10cSrcweir {
2372cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
2373cdf0e10cSrcweir 
2374cdf0e10cSrcweir 	if ( mpImpl->mpClipboardListener )
2375cdf0e10cSrcweir     {
2376cdf0e10cSrcweir         mpImpl->mpClipboardListener->dispose();
2377cdf0e10cSrcweir         mpImpl->mpClipboardListener->release();
2378cdf0e10cSrcweir         mpImpl->mpClipboardListener = NULL;
2379cdf0e10cSrcweir     }
2380cdf0e10cSrcweir }
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir // -----------------------------------------------------------------------------
2383cdf0e10cSrcweir 
CreateFromSystemClipboard(Window * pWindow)2384cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSystemClipboard( Window * pWindow )
2385cdf0e10cSrcweir {
2386cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
2387cdf0e10cSrcweir 
2388cdf0e10cSrcweir     Reference< XClipboard >	xClipboard;
2389cdf0e10cSrcweir    	TransferableDataHelper	aRet;
2390cdf0e10cSrcweir 
2391cdf0e10cSrcweir     if( pWindow )
2392cdf0e10cSrcweir         xClipboard = pWindow->GetClipboard();
2393cdf0e10cSrcweir 
2394cdf0e10cSrcweir     if( xClipboard.is() )
2395cdf0e10cSrcweir    	{
2396cdf0e10cSrcweir    		try
2397cdf0e10cSrcweir 
2398cdf0e10cSrcweir     	{
2399cdf0e10cSrcweir 	    	Reference< XTransferable > xTransferable( xClipboard->getContents() );
2400cdf0e10cSrcweir 
2401cdf0e10cSrcweir 		    if( xTransferable.is() )
2402cdf0e10cSrcweir 			{
2403cdf0e10cSrcweir     			aRet = TransferableDataHelper( xTransferable );
2404cdf0e10cSrcweir    				aRet.mxClipboard = xClipboard;
2405cdf0e10cSrcweir 					// also copy the clipboard - 99030 - 23.05.2002 - fs@openoffice.org
2406cdf0e10cSrcweir 			}
2407cdf0e10cSrcweir    		}
2408cdf0e10cSrcweir     	catch( const ::com::sun::star::uno::Exception& )
2409cdf0e10cSrcweir 	    {
2410cdf0e10cSrcweir    		}
2411cdf0e10cSrcweir     }
2412cdf0e10cSrcweir 
2413cdf0e10cSrcweir 	return aRet;
2414cdf0e10cSrcweir }
2415cdf0e10cSrcweir 
2416cdf0e10cSrcweir 
2417cdf0e10cSrcweir // -----------------------------------------------------------------------------
2418cdf0e10cSrcweir 
CreateFromSelection(Window * pWindow)2419cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSelection( Window* pWindow )
2420cdf0e10cSrcweir {
2421cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
2422cdf0e10cSrcweir 
2423cdf0e10cSrcweir     Reference< XClipboard >	xSelection;
2424cdf0e10cSrcweir    	TransferableDataHelper	aRet;
2425cdf0e10cSrcweir 
2426cdf0e10cSrcweir     if( pWindow )
2427cdf0e10cSrcweir         xSelection = pWindow->GetPrimarySelection();
2428cdf0e10cSrcweir 
2429cdf0e10cSrcweir     if( xSelection.is() )
2430cdf0e10cSrcweir    	{
2431cdf0e10cSrcweir         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
2432cdf0e10cSrcweir 
2433cdf0e10cSrcweir   		try
2434cdf0e10cSrcweir     	{
2435cdf0e10cSrcweir 	    	Reference< XTransferable > xTransferable( xSelection->getContents() );
2436cdf0e10cSrcweir 
2437cdf0e10cSrcweir 		    if( xTransferable.is() )
2438cdf0e10cSrcweir    			{
2439cdf0e10cSrcweir     			aRet = TransferableDataHelper( xTransferable );
2440cdf0e10cSrcweir    				aRet.mxClipboard = xSelection;
2441cdf0e10cSrcweir 		    }
2442cdf0e10cSrcweir    		}
2443cdf0e10cSrcweir     	catch( const ::com::sun::star::uno::Exception& )
2444cdf0e10cSrcweir 	    {
2445cdf0e10cSrcweir    		}
2446cdf0e10cSrcweir 
2447cdf0e10cSrcweir         Application::AcquireSolarMutex( nRef );
2448cdf0e10cSrcweir     }
2449cdf0e10cSrcweir 
2450cdf0e10cSrcweir 	return aRet;
2451cdf0e10cSrcweir }
2452cdf0e10cSrcweir 
2453cdf0e10cSrcweir // -----------------------------------------------------------------------------
IsEqual(const::com::sun::star::datatransfer::DataFlavor & rInternalFlavor,const::com::sun::star::datatransfer::DataFlavor & rRequestFlavor,sal_Bool)2454cdf0e10cSrcweir sal_Bool TransferableDataHelper::IsEqual( const ::com::sun::star::datatransfer::DataFlavor& rInternalFlavor,
2455cdf0e10cSrcweir 										  const ::com::sun::star::datatransfer::DataFlavor& rRequestFlavor,
2456cdf0e10cSrcweir                                           sal_Bool )
2457cdf0e10cSrcweir {
2458cdf0e10cSrcweir     Reference< XMultiServiceFactory >       xFact( ::comphelper::getProcessServiceFactory() );
2459cdf0e10cSrcweir     Reference< XMimeContentTypeFactory >    xMimeFact;
2460cdf0e10cSrcweir 	sal_Bool								bRet = sal_False;
2461cdf0e10cSrcweir 
2462cdf0e10cSrcweir     try
2463cdf0e10cSrcweir     {
2464cdf0e10cSrcweir 		if( xFact.is() )
2465cdf0e10cSrcweir     	    xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii(
2466cdf0e10cSrcweir                                                               "com.sun.star.datatransfer.MimeContentTypeFactory" ) ),
2467cdf0e10cSrcweir                                                               UNO_QUERY );
2468cdf0e10cSrcweir 
2469cdf0e10cSrcweir         if( xMimeFact.is() )
2470cdf0e10cSrcweir 		{
2471cdf0e10cSrcweir             Reference< XMimeContentType > xRequestType1( xMimeFact->createMimeContentType( rInternalFlavor.MimeType ) );
2472cdf0e10cSrcweir             Reference< XMimeContentType > xRequestType2( xMimeFact->createMimeContentType( rRequestFlavor.MimeType ) );
2473cdf0e10cSrcweir 
2474cdf0e10cSrcweir 			if( xRequestType1.is() && xRequestType2.is() )
2475cdf0e10cSrcweir             {
2476cdf0e10cSrcweir                 if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( xRequestType2->getFullMediaType() ) )
2477cdf0e10cSrcweir 			    {
2478cdf0e10cSrcweir                     if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) )
2479cdf0e10cSrcweir                     {
2480cdf0e10cSrcweir                         // special handling for text/plain media types
2481cdf0e10cSrcweir                         const ::rtl::OUString aCharsetString( ::rtl::OUString::createFromAscii( "charset" ) );
2482cdf0e10cSrcweir 
2483cdf0e10cSrcweir                         if( !xRequestType2->hasParameter( aCharsetString ) ||
2484cdf0e10cSrcweir 						    xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) ||
2485cdf0e10cSrcweir 						    xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) )
2486cdf0e10cSrcweir                         {
2487cdf0e10cSrcweir                             bRet = sal_True;
2488cdf0e10cSrcweir                         }
2489cdf0e10cSrcweir                     }
2490cdf0e10cSrcweir                     else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice" ) ) )
2491cdf0e10cSrcweir                     {
2492cdf0e10cSrcweir                         // special handling for application/x-openoffice media types
2493cdf0e10cSrcweir                         const ::rtl::OUString aFormatString( ::rtl::OUString::createFromAscii( "windows_formatname" ) );
2494cdf0e10cSrcweir 
2495cdf0e10cSrcweir                         if( xRequestType1->hasParameter( aFormatString ) &&
2496cdf0e10cSrcweir                             xRequestType2->hasParameter( aFormatString ) &&
2497cdf0e10cSrcweir                             xRequestType1->getParameterValue( aFormatString ).equalsIgnoreAsciiCase( xRequestType2->getParameterValue( aFormatString ) ) )
2498cdf0e10cSrcweir                         {
2499cdf0e10cSrcweir                             bRet = sal_True;
2500cdf0e10cSrcweir                         }
2501cdf0e10cSrcweir                     }
2502cdf0e10cSrcweir                     else
2503cdf0e10cSrcweir                         bRet = sal_True;
2504cdf0e10cSrcweir 			    }
2505cdf0e10cSrcweir             }
2506cdf0e10cSrcweir 		}
2507cdf0e10cSrcweir     }
2508cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
2509cdf0e10cSrcweir 	{
2510cdf0e10cSrcweir         bRet = rInternalFlavor.MimeType.equalsIgnoreAsciiCase( rRequestFlavor.MimeType );
2511cdf0e10cSrcweir 	}
2512cdf0e10cSrcweir 
2513cdf0e10cSrcweir     return bRet;
2514cdf0e10cSrcweir }
2515