xref: /AOO41X/main/svtools/source/misc/transfer.cxx (revision 519071a51b7301bb966cf1c788901a9f24ea0379)
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
10cdf0e10cSrcweir  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 
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 
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 
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 
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 
299cdf0e10cSrcweir TransferableHelper::TerminateListener::TerminateListener( TransferableHelper& rTransferableHelper ) :
300cdf0e10cSrcweir 	mrParent( rTransferableHelper )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // -----------------------------------------------------------------------------
305cdf0e10cSrcweir 
306cdf0e10cSrcweir TransferableHelper::TerminateListener::~TerminateListener()
307cdf0e10cSrcweir {
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir // -----------------------------------------------------------------------------
311cdf0e10cSrcweir 
312cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::disposing( const EventObject& ) throw( RuntimeException )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir // -----------------------------------------------------------------------------
317cdf0e10cSrcweir 
318cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::queryTermination( const EventObject& ) throw( TerminationVetoException, RuntimeException )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir // -----------------------------------------------------------------------------
323cdf0e10cSrcweir 
324cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::notifyTermination( const EventObject& ) throw( RuntimeException )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir 	mrParent.ImplFlush();
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir // ----------------------
330cdf0e10cSrcweir // - TransferableHelper -
331cdf0e10cSrcweir // ----------------------
332cdf0e10cSrcweir 
333cdf0e10cSrcweir TransferableHelper::TransferableHelper() :
334cdf0e10cSrcweir 	mpFormats( new DataFlavorExVector ),
335cdf0e10cSrcweir     mpObjDesc( NULL )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir // -----------------------------------------------------------------------------
340cdf0e10cSrcweir 
341cdf0e10cSrcweir TransferableHelper::~TransferableHelper()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     delete mpObjDesc;
344cdf0e10cSrcweir 	delete mpFormats;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir // -----------------------------------------------------------------------------
348cdf0e10cSrcweir 
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 
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 
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 
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 
557cdf0e10cSrcweir void SAL_CALL TransferableHelper::disposing( const EventObject& ) throw( RuntimeException )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // -----------------------------------------------------------------------------
562cdf0e10cSrcweir 
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 
579cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragEnter( const DragSourceDragEvent& ) throw( RuntimeException )
580cdf0e10cSrcweir {
581cdf0e10cSrcweir }
582cdf0e10cSrcweir 
583cdf0e10cSrcweir // -----------------------------------------------------------------------------
584cdf0e10cSrcweir 
585cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragExit( const DragSourceEvent& ) throw( RuntimeException )
586cdf0e10cSrcweir {
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir // -----------------------------------------------------------------------------
590cdf0e10cSrcweir 
591cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragOver( const DragSourceDragEvent& ) throw( RuntimeException )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir // -----------------------------------------------------------------------------
596cdf0e10cSrcweir 
597cdf0e10cSrcweir void SAL_CALL TransferableHelper::dropActionChanged( const DragSourceDragEvent& ) throw( RuntimeException )
598cdf0e10cSrcweir {
599cdf0e10cSrcweir }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir // -----------------------------------------------------------------------------
602cdf0e10cSrcweir 
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 
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 
643cdf0e10cSrcweir void TransferableHelper::AddFormat( SotFormatStringId nFormat )
644cdf0e10cSrcweir {
645cdf0e10cSrcweir     DataFlavor aFlavor;
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
648cdf0e10cSrcweir         AddFormat( aFlavor );
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir // -----------------------------------------------------------------------------
652cdf0e10cSrcweir 
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 		{
701cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_BMP );
70245fd3b9aSArmin Le Grand 			AddFormat( SOT_FORMATSTR_ID_PNG );
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 
714cdf0e10cSrcweir void TransferableHelper::RemoveFormat( SotFormatStringId nFormat )
715cdf0e10cSrcweir {
716cdf0e10cSrcweir     DataFlavor aFlavor;
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
719cdf0e10cSrcweir         RemoveFormat( aFlavor );
720cdf0e10cSrcweir }
721cdf0e10cSrcweir 
722cdf0e10cSrcweir // -----------------------------------------------------------------------------
723cdf0e10cSrcweir 
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 
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 
763cdf0e10cSrcweir void TransferableHelper::ClearFormats()
764cdf0e10cSrcweir {
765cdf0e10cSrcweir 	mpFormats->clear();
766cdf0e10cSrcweir     maAny.clear();
767cdf0e10cSrcweir }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir // -----------------------------------------------------------------------------
770cdf0e10cSrcweir 
771cdf0e10cSrcweir sal_Bool TransferableHelper::SetAny( const Any& rAny, const DataFlavor& )
772cdf0e10cSrcweir {
773cdf0e10cSrcweir 	maAny = rAny;
774cdf0e10cSrcweir 	return( maAny.hasValue() );
775cdf0e10cSrcweir }
776cdf0e10cSrcweir 
777cdf0e10cSrcweir // -----------------------------------------------------------------------------
778cdf0e10cSrcweir 
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 
80345fd3b9aSArmin Le Grand sal_Bool TransferableHelper::SetBitmapEx( const BitmapEx& rBitmapEx, const DataFlavor& rFlavor )
804cdf0e10cSrcweir {
80545fd3b9aSArmin Le Grand 	if( !rBitmapEx.IsEmpty() )
806cdf0e10cSrcweir 	{
807cdf0e10cSrcweir         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 
82045fd3b9aSArmin Le Grand             if(rBitmapEx.IsTransparent())
82145fd3b9aSArmin Le Grand             {
82245fd3b9aSArmin Le Grand                 const Bitmap aMask(rBitmapEx.GetAlpha().GetBitmap());
82345fd3b9aSArmin Le Grand 
82445fd3b9aSArmin Le Grand                 // explicitely use Bitmap::Write with bCompressed = sal_False and bFileHeader = sal_True
82545fd3b9aSArmin Le Grand                 WriteDIBV5(aBitmap, aMask, aMemStm);
82645fd3b9aSArmin Le Grand             }
82745fd3b9aSArmin Le Grand             else
82845fd3b9aSArmin Le Grand             {
82945fd3b9aSArmin Le Grand                 // explicitely use Bitmap::Write with bCompressed = sal_False and bFileHeader = sal_True
83045fd3b9aSArmin Le Grand                 WriteDIB(aBitmap, aMemStm, false, true);
83145fd3b9aSArmin Le Grand             }
83245fd3b9aSArmin Le Grand         }
83345fd3b9aSArmin Le Grand 
834cdf0e10cSrcweir         maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
835cdf0e10cSrcweir 	}
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 	return( maAny.hasValue() );
838cdf0e10cSrcweir }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir // -----------------------------------------------------------------------------
841cdf0e10cSrcweir 
842cdf0e10cSrcweir sal_Bool TransferableHelper::SetGDIMetaFile( const GDIMetaFile& rMtf, const DataFlavor& )
843cdf0e10cSrcweir {
844cdf0e10cSrcweir 	if( rMtf.GetActionCount() )
845cdf0e10cSrcweir 	{
846cdf0e10cSrcweir 		SvMemoryStream aMemStm( 65535, 65535 );
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 		( (GDIMetaFile&) rMtf ).Write( aMemStm );
849cdf0e10cSrcweir 		maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
850cdf0e10cSrcweir 	}
851cdf0e10cSrcweir 
852cdf0e10cSrcweir 	return( maAny.hasValue() );
853cdf0e10cSrcweir }
854cdf0e10cSrcweir 
855cdf0e10cSrcweir // -----------------------------------------------------------------------------
856cdf0e10cSrcweir 
857cdf0e10cSrcweir sal_Bool TransferableHelper::SetGraphic( const Graphic& rGraphic, const DataFlavor& )
858cdf0e10cSrcweir {
859cdf0e10cSrcweir 	if( rGraphic.GetType() != GRAPHIC_NONE )
860cdf0e10cSrcweir 	{
861cdf0e10cSrcweir 		SvMemoryStream aMemStm( 65535, 65535 );
862cdf0e10cSrcweir 
863cdf0e10cSrcweir         aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
864cdf0e10cSrcweir         aMemStm.SetCompressMode( COMPRESSMODE_NATIVE );
865cdf0e10cSrcweir 		aMemStm << rGraphic;
866cdf0e10cSrcweir 		maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
867cdf0e10cSrcweir 	}
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 	return( maAny.hasValue() );
870cdf0e10cSrcweir }
871cdf0e10cSrcweir 
872cdf0e10cSrcweir // -----------------------------------------------------------------------------
873cdf0e10cSrcweir 
874cdf0e10cSrcweir sal_Bool TransferableHelper::SetImageMap( const ImageMap& rIMap, const ::com::sun::star::datatransfer::DataFlavor& )
875cdf0e10cSrcweir {
876cdf0e10cSrcweir 	SvMemoryStream aMemStm( 8192, 8192 );
877cdf0e10cSrcweir 
878cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
879cdf0e10cSrcweir     rIMap.Write( aMemStm, String() );
880cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 	return( maAny.hasValue() );
883cdf0e10cSrcweir }
884cdf0e10cSrcweir 
885cdf0e10cSrcweir // -----------------------------------------------------------------------------
886cdf0e10cSrcweir 
887cdf0e10cSrcweir sal_Bool TransferableHelper::SetTransferableObjectDescriptor( const TransferableObjectDescriptor& rDesc,
888cdf0e10cSrcweir 															  const ::com::sun::star::datatransfer::DataFlavor& )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir     PrepareOLE( rDesc );
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 	SvMemoryStream aMemStm( 1024, 1024 );
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 	aMemStm << rDesc;
895cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 	return( maAny.hasValue() );
898cdf0e10cSrcweir  }
899cdf0e10cSrcweir 
900cdf0e10cSrcweir // -----------------------------------------------------------------------------
901cdf0e10cSrcweir 
902cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetBookmark( const INetBookmark& rBmk,
903cdf0e10cSrcweir 											  const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
904cdf0e10cSrcweir {
905cdf0e10cSrcweir 	rtl_TextEncoding eSysCSet = gsl_getSystemTextEncoding();
906cdf0e10cSrcweir 
907cdf0e10cSrcweir 	switch( SotExchange::GetFormat( rFlavor ) )
908cdf0e10cSrcweir 	{
909cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_SOLK ):
910cdf0e10cSrcweir 		{
911cdf0e10cSrcweir 			ByteString sURL( rBmk.GetURL(), eSysCSet ),
912cdf0e10cSrcweir 					   sDesc( rBmk.GetDescription(), eSysCSet );
913cdf0e10cSrcweir 			ByteString sOut( ByteString::CreateFromInt32( sURL.Len() ));
914cdf0e10cSrcweir 			( sOut += '@' ) += sURL;
915cdf0e10cSrcweir 			sOut += ByteString::CreateFromInt32( sDesc.Len() );
916cdf0e10cSrcweir 			( sOut += '@' ) += sDesc;
917cdf0e10cSrcweir 
918cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq( sOut.Len() );
919cdf0e10cSrcweir 			memcpy( aSeq.getArray(), sOut.GetBuffer(), sOut.Len() );
920cdf0e10cSrcweir 			maAny <<= aSeq;
921cdf0e10cSrcweir 		}
922cdf0e10cSrcweir 		break;
923cdf0e10cSrcweir 
924cdf0e10cSrcweir 		case( FORMAT_STRING ):
925cdf0e10cSrcweir 			maAny <<= ::rtl::OUString( rBmk.GetURL() );
926cdf0e10cSrcweir 			break;
927cdf0e10cSrcweir 
928cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ):
929cdf0e10cSrcweir 		{
930cdf0e10cSrcweir 			ByteString sURL( rBmk.GetURL(), eSysCSet );
931cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq( sURL.Len() );
932cdf0e10cSrcweir 			memcpy( aSeq.getArray(), sURL.GetBuffer(), sURL.Len() );
933cdf0e10cSrcweir 			maAny <<= aSeq;
934cdf0e10cSrcweir 		}
935cdf0e10cSrcweir 		break;
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ):
938cdf0e10cSrcweir 		{
939cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq( 2048 );
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 			memset( aSeq.getArray(), 0, 2048 );
942cdf0e10cSrcweir 			strcpy( reinterpret_cast< char* >( aSeq.getArray() ), ByteString( rBmk.GetURL(), eSysCSet).GetBuffer() );
943cdf0e10cSrcweir 			strcpy( reinterpret_cast< char* >( aSeq.getArray() ) + 1024, ByteString( rBmk.GetDescription(), eSysCSet ).GetBuffer() );
944cdf0e10cSrcweir 
945cdf0e10cSrcweir 			maAny <<= aSeq;
946cdf0e10cSrcweir 		}
947cdf0e10cSrcweir 		break;
948cdf0e10cSrcweir 
949cdf0e10cSrcweir #ifdef WNT
950cdf0e10cSrcweir 		case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
951cdf0e10cSrcweir 		{
952cdf0e10cSrcweir 			Sequence< sal_Int8 >	aSeq( sizeof( FILEGROUPDESCRIPTOR ) );
953cdf0e10cSrcweir 			FILEGROUPDESCRIPTOR*	pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getArray();
954cdf0e10cSrcweir 			FILEDESCRIPTOR&			rFDesc1 = pFDesc->fgd[ 0 ];
955cdf0e10cSrcweir 
956cdf0e10cSrcweir 			pFDesc->cItems = 1;
957cdf0e10cSrcweir 			memset( &rFDesc1, 0, sizeof( FILEDESCRIPTOR ) );
958cdf0e10cSrcweir 			rFDesc1.dwFlags = FD_LINKUI;
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 			ByteString aStr( rBmk.GetDescription(), eSysCSet );
961cdf0e10cSrcweir 			for( sal_uInt16 nChar = 0; nChar < aStr.Len(); ++nChar )
962cdf0e10cSrcweir 				if( strchr( "\\/:*?\"<>|", aStr.GetChar( nChar ) ) )
963cdf0e10cSrcweir 					aStr.Erase( nChar--, 1 );
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 			aStr.Insert( "Shortcut to ", 0 );
966cdf0e10cSrcweir 			aStr += ".URL";
967cdf0e10cSrcweir 			strcpy( rFDesc1.cFileName, aStr.GetBuffer() );
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 			maAny <<= aSeq;
970cdf0e10cSrcweir 		}
971cdf0e10cSrcweir 		break;
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 		case SOT_FORMATSTR_ID_FILECONTENT:
974cdf0e10cSrcweir 		{
975cdf0e10cSrcweir 			String aStr( RTL_CONSTASCII_STRINGPARAM( "[InternetShortcut]\x0aURL=" ) );
976cdf0e10cSrcweir 			maAny <<= ::rtl::OUString( aStr += rBmk.GetURL() );
977cdf0e10cSrcweir 		}
978cdf0e10cSrcweir 		break;
979cdf0e10cSrcweir #endif
980cdf0e10cSrcweir 
981cdf0e10cSrcweir 		default:
982cdf0e10cSrcweir 		break;
983cdf0e10cSrcweir 	}
984cdf0e10cSrcweir 
985cdf0e10cSrcweir 	return( maAny.hasValue() );
986cdf0e10cSrcweir }
987cdf0e10cSrcweir 
988cdf0e10cSrcweir // -----------------------------------------------------------------------------
989cdf0e10cSrcweir 
990cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetImage( const INetImage& rINtImg,
991cdf0e10cSrcweir 										   const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
992cdf0e10cSrcweir {
993cdf0e10cSrcweir 	SvMemoryStream aMemStm( 1024, 1024 );
994cdf0e10cSrcweir 
995cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
996cdf0e10cSrcweir 	rINtImg.Write( aMemStm, SotExchange::GetFormat( rFlavor ) );
997cdf0e10cSrcweir 
998cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 	return( maAny.hasValue() );
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir // -----------------------------------------------------------------------------
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir sal_Bool TransferableHelper::SetFileList( const FileList& rFileList,
1006cdf0e10cSrcweir 										  const ::com::sun::star::datatransfer::DataFlavor& )
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir 	SvMemoryStream aMemStm( 4096, 4096 );
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
1011cdf0e10cSrcweir 	aMemStm << rFileList;
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 	maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ),
1014cdf0e10cSrcweir                                        aMemStm.Seek( STREAM_SEEK_TO_END ) );
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir 	return( maAny.hasValue() );
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir // -----------------------------------------------------------------------------
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir sal_Bool TransferableHelper::SetObject( void* pUserObject, sal_uInt32 nUserObjectId, const DataFlavor& rFlavor )
1022cdf0e10cSrcweir {
1023cdf0e10cSrcweir 	SotStorageStreamRef xStm( new SotStorageStream( String() ) );
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir     xStm->SetVersion( SOFFICE_FILEFORMAT_50 );
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 	if( pUserObject && WriteObject( xStm, pUserObject, nUserObjectId, rFlavor ) )
1028cdf0e10cSrcweir 	{
1029cdf0e10cSrcweir 		const sal_uInt32		nLen = xStm->Seek( STREAM_SEEK_TO_END );
1030cdf0e10cSrcweir 		Sequence< sal_Int8 >	aSeq( nLen );
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir 		xStm->Seek( STREAM_SEEK_TO_BEGIN );
1033cdf0e10cSrcweir 		xStm->Read( aSeq.getArray(),  nLen );
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 		if( nLen && ( SotExchange::GetFormat( rFlavor ) == SOT_FORMAT_STRING ) )
1036cdf0e10cSrcweir         {
1037cdf0e10cSrcweir             //JP 24.7.2001: as I know was this only for the writer application and this
1038cdf0e10cSrcweir             //		        writes now UTF16 format into the stream
1039cdf0e10cSrcweir             //JP 6.8.2001:  and now it writes UTF8 because then exist no problem with
1040cdf0e10cSrcweir             //		        little / big endians! - Bug 88121
1041cdf0e10cSrcweir 			maAny <<= ::rtl::OUString( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), nLen - 1, RTL_TEXTENCODING_UTF8 );
1042cdf0e10cSrcweir         }
1043cdf0e10cSrcweir 		else
1044cdf0e10cSrcweir 			maAny <<= aSeq;
1045cdf0e10cSrcweir 	}
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir 	return( maAny.hasValue() );
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir // -----------------------------------------------------------------------------
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir sal_Bool TransferableHelper::SetInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rIf,
1053cdf0e10cSrcweir 										   const ::com::sun::star::datatransfer::DataFlavor& )
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir 	maAny <<= rIf;
1056cdf0e10cSrcweir 	return( maAny.hasValue() );
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir // -----------------------------------------------------------------------------
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir sal_Bool TransferableHelper::WriteObject( SotStorageStreamRef&, void*, sal_uInt32, const DataFlavor& )
1062cdf0e10cSrcweir {
1063cdf0e10cSrcweir 	DBG_ERROR( "TransferableHelper::WriteObject( ... ) not implemented" );
1064cdf0e10cSrcweir 	return sal_False;
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir // -----------------------------------------------------------------------------
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir void TransferableHelper::DragFinished( sal_Int8 )
1070cdf0e10cSrcweir {
1071cdf0e10cSrcweir }
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir // -----------------------------------------------------------------------------
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir void TransferableHelper::ObjectReleased()
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir }
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir // -----------------------------------------------------------------------------
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir void TransferableHelper::PrepareOLE( const TransferableObjectDescriptor& rObjDesc )
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir     delete mpObjDesc;
1084cdf0e10cSrcweir     mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir     if( HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
1087cdf0e10cSrcweir         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
1088cdf0e10cSrcweir }
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir // -----------------------------------------------------------------------------
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir void TransferableHelper::CopyToClipboard( Window *pWindow ) const
1093cdf0e10cSrcweir {
1094cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1095cdf0e10cSrcweir     Reference< XClipboard > xClipboard;
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir     if( pWindow )
1098cdf0e10cSrcweir         xClipboard = pWindow->GetClipboard();
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir     if( xClipboard.is() )
1101cdf0e10cSrcweir         mxClipboard = xClipboard;
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir 	if( mxClipboard.is() && !mxTerminateListener.is() )
1104cdf0e10cSrcweir 	{
1105cdf0e10cSrcweir 		const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir 		try
1108cdf0e10cSrcweir 		{
1109cdf0e10cSrcweir             TransferableHelper*                 pThis = const_cast< TransferableHelper* >( this );
1110cdf0e10cSrcweir 			Reference< XMultiServiceFactory >   xFact( ::comphelper::getProcessServiceFactory() );
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir 			if( xFact.is() )
1113cdf0e10cSrcweir 			{
1114cdf0e10cSrcweir 				Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir 				if( xDesktop.is() )
1117cdf0e10cSrcweir 					xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) );
1118cdf0e10cSrcweir 			}
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir 			mxClipboard->setContents( pThis, pThis );
1121cdf0e10cSrcweir 		}
1122cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1123cdf0e10cSrcweir 		{
1124cdf0e10cSrcweir 		}
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir 		Application::AcquireSolarMutex( nRef );
1127cdf0e10cSrcweir 	}
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir // -----------------------------------------------------------------------------
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir void TransferableHelper::CopyToSelection( Window *pWindow ) const
1133cdf0e10cSrcweir {
1134cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1135cdf0e10cSrcweir     Reference< XClipboard > xSelection;
1136cdf0e10cSrcweir 
1137cdf0e10cSrcweir     if( pWindow )
1138cdf0e10cSrcweir         xSelection = pWindow->GetPrimarySelection();
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir 	if( xSelection.is() && !mxTerminateListener.is() )
1141cdf0e10cSrcweir 	{
1142cdf0e10cSrcweir 		const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir 		try
1145cdf0e10cSrcweir 		{
1146cdf0e10cSrcweir             TransferableHelper*                 pThis = const_cast< TransferableHelper* >( this );
1147cdf0e10cSrcweir 			Reference< XMultiServiceFactory >   xFact( ::comphelper::getProcessServiceFactory() );
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir 			if( xFact.is() )
1150cdf0e10cSrcweir 			{
1151cdf0e10cSrcweir 				Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir 				if( xDesktop.is() )
1154cdf0e10cSrcweir 					xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) );
1155cdf0e10cSrcweir 			}
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir 			xSelection->setContents( pThis, pThis );
1158cdf0e10cSrcweir 		}
1159cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1160cdf0e10cSrcweir 		{
1161cdf0e10cSrcweir 		}
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir 		Application::AcquireSolarMutex( nRef );
1164cdf0e10cSrcweir 	}
1165cdf0e10cSrcweir }
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir // -----------------------------------------------------------------------------
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir void TransferableHelper::StartDrag( Window* pWindow, sal_Int8 nDnDSourceActions,
1170cdf0e10cSrcweir 									sal_Int32 nDnDPointer, sal_Int32 nDnDImage )
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir {
1173cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1174cdf0e10cSrcweir     Reference< XDragSource > xDragSource( pWindow->GetDragSource() );
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir 	if( xDragSource.is() )
1177cdf0e10cSrcweir 	{
1178cdf0e10cSrcweir         /*
1179cdf0e10cSrcweir          *    #96792# release mouse before actually starting DnD.
1180cdf0e10cSrcweir          *    This is necessary for the X11 DnD implementation to work.
1181cdf0e10cSrcweir          */
1182cdf0e10cSrcweir         if( pWindow->IsMouseCaptured() )
1183cdf0e10cSrcweir             pWindow->ReleaseMouse();
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir         const Point	aPt( pWindow->GetPointerPosPixel() );
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir 		// On Mac OS X we are forced to execute 'startDrag' synchronously
1188cdf0e10cSrcweir 		// contrary to the XDragSource interface specification because
1189cdf0e10cSrcweir 		// we can receive drag events from the system only in the main
1190cdf0e10cSrcweir 		// thread
1191cdf0e10cSrcweir #if !defined(QUARTZ)
1192cdf0e10cSrcweir 		const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1193cdf0e10cSrcweir #endif
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 		try
1196cdf0e10cSrcweir 		{
1197cdf0e10cSrcweir 			DragGestureEvent	aEvt;
1198cdf0e10cSrcweir 			aEvt.DragAction = DNDConstants::ACTION_COPY;
1199cdf0e10cSrcweir 			aEvt.DragOriginX = aPt.X();
1200cdf0e10cSrcweir 			aEvt.DragOriginY = aPt.Y();
1201cdf0e10cSrcweir 			aEvt.DragSource = xDragSource;
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir 			xDragSource->startDrag( aEvt, nDnDSourceActions, nDnDPointer, nDnDImage, this, this );
1204cdf0e10cSrcweir 		}
1205cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1206cdf0e10cSrcweir 		{
1207cdf0e10cSrcweir 		}
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 		// See above for the reason of this define
1210cdf0e10cSrcweir #if !defined(QUARTZ)
1211cdf0e10cSrcweir 		Application::AcquireSolarMutex( nRef );
1212cdf0e10cSrcweir #endif
1213cdf0e10cSrcweir 	}
1214cdf0e10cSrcweir }
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir // -----------------------------------------------------------------------------
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir void TransferableHelper::ClearSelection( Window *pWindow )
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
1221cdf0e10cSrcweir     Reference< XClipboard > xSelection( pWindow->GetPrimarySelection() );
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir 	if( xSelection.is() )
1224cdf0e10cSrcweir         xSelection->setContents( NULL, NULL );
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir // -----------------------------------------------------------------------------
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir Reference< XClipboard> TransferableHelper::GetSystemClipboard()
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir     Window *pFocusWindow = Application::GetFocusWindow();
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir     if( pFocusWindow )
1234cdf0e10cSrcweir         return pFocusWindow->GetClipboard();
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir 	return 	Reference< XClipboard > ();
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir // -----------------------------------------------------------------------------
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir const Sequence< sal_Int8 >& TransferableHelper::getUnoTunnelId()
1242cdf0e10cSrcweir {
1243cdf0e10cSrcweir     static Sequence< sal_Int8 > aSeq;
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir 	if( !aSeq.getLength() )
1246cdf0e10cSrcweir 	{
1247cdf0e10cSrcweir 		static osl::Mutex           aCreateMutex;
1248cdf0e10cSrcweir     	osl::Guard< osl::Mutex >    aGuard( aCreateMutex );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 		aSeq.realloc( 16 );
1251cdf0e10cSrcweir     	rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
1252cdf0e10cSrcweir 	}
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir     return aSeq;
1256cdf0e10cSrcweir }
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir // ---------------------------------
1259cdf0e10cSrcweir // - TransferableClipboardNotifier -
1260cdf0e10cSrcweir // ---------------------------------
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir class TransferableClipboardNotifier : public ::cppu::WeakImplHelper1< XClipboardListener >
1263cdf0e10cSrcweir {
1264cdf0e10cSrcweir private:
1265cdf0e10cSrcweir     ::osl::Mutex&                   mrMutex;
1266cdf0e10cSrcweir     Reference< XClipboardNotifier > mxNotifier;
1267cdf0e10cSrcweir 	TransferableDataHelper*		    mpListener;
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir protected:
1270cdf0e10cSrcweir 	// XClipboardListener
1271cdf0e10cSrcweir     virtual void SAL_CALL changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException);
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir     // XEventListener
1274cdf0e10cSrcweir     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir public:
1277cdf0e10cSrcweir     TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex );
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir     /// determines whether we're currently listening
1280cdf0e10cSrcweir     inline bool isListening() const { return !isDisposed(); }
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir     /// determines whether the instance is disposed
1283cdf0e10cSrcweir     inline bool isDisposed() const { return mpListener == NULL; }
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir     /// makes the instance non-functional
1286cdf0e10cSrcweir     void    dispose();
1287cdf0e10cSrcweir };
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir // -----------------------------------------------------------------------------
1290cdf0e10cSrcweir 
1291cdf0e10cSrcweir TransferableClipboardNotifier::TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex )
1292cdf0e10cSrcweir     :mrMutex( _rMutex )
1293cdf0e10cSrcweir     ,mxNotifier( _rxClipboard, UNO_QUERY )
1294cdf0e10cSrcweir     ,mpListener( &_rListener )
1295cdf0e10cSrcweir {
1296cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
1297cdf0e10cSrcweir     {
1298cdf0e10cSrcweir         if ( mxNotifier.is() )
1299cdf0e10cSrcweir 		    mxNotifier->addClipboardListener( this );
1300cdf0e10cSrcweir         else
1301cdf0e10cSrcweir             // born dead
1302cdf0e10cSrcweir             mpListener = NULL;
1303cdf0e10cSrcweir     }
1304cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
1305cdf0e10cSrcweir }
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir // -----------------------------------------------------------------------------
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException)
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1312cdf0e10cSrcweir         // the SolarMutex here is necessary, since
1313cdf0e10cSrcweir         // - we cannot call mpListener without our own mutex locked
1314cdf0e10cSrcweir         // - Rebind respectively InitFormats (called by Rebind) will
1315cdf0e10cSrcweir         // try to lock the SolarMutex, too
1316cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mrMutex );
1317cdf0e10cSrcweir 	if( mpListener )
1318cdf0e10cSrcweir 		mpListener->Rebind( event.Contents );
1319cdf0e10cSrcweir }
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir // -----------------------------------------------------------------------------
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::disposing( const EventObject& ) throw (RuntimeException)
1324cdf0e10cSrcweir {
1325cdf0e10cSrcweir     // clipboard is being disposed. Hmm. Okay, become disfunctional myself.
1326cdf0e10cSrcweir 	dispose();
1327cdf0e10cSrcweir }
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir // -----------------------------------------------------------------------------
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir void TransferableClipboardNotifier::dispose()
1332cdf0e10cSrcweir {
1333cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mrMutex );
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir     Reference< XClipboardListener > xKeepMeAlive( this );
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir     if ( mxNotifier.is() )
1338cdf0e10cSrcweir 		mxNotifier->removeClipboardListener( this );
1339cdf0e10cSrcweir     mxNotifier.clear();
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir     mpListener = NULL;
1342cdf0e10cSrcweir }
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir // -------------------------------
1345cdf0e10cSrcweir // - TransferableDataHelper_Impl -
1346cdf0e10cSrcweir // -------------------------------
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir struct TransferableDataHelper_Impl
1349cdf0e10cSrcweir {
1350cdf0e10cSrcweir     ::osl::Mutex                    maMutex;
1351cdf0e10cSrcweir     TransferableClipboardNotifier*  mpClipboardListener;
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir     TransferableDataHelper_Impl()
1354cdf0e10cSrcweir         :mpClipboardListener( NULL )
1355cdf0e10cSrcweir     {
1356cdf0e10cSrcweir     }
1357cdf0e10cSrcweir };
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir // --------------------------
1360cdf0e10cSrcweir // - TransferableDataHelper -
1361cdf0e10cSrcweir // --------------------------
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper() :
1364cdf0e10cSrcweir     mpFormats( new DataFlavorExVector ),
1365cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor ),
1366cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1367cdf0e10cSrcweir {
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir // -----------------------------------------------------------------------------
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const Reference< ::com::sun::star::datatransfer::XTransferable >& rxTransferable ) :
1373cdf0e10cSrcweir     mxTransfer( rxTransferable ),
1374cdf0e10cSrcweir     mpFormats( new DataFlavorExVector ),
1375cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor ),
1376cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1377cdf0e10cSrcweir {
1378cdf0e10cSrcweir 	InitFormats();
1379cdf0e10cSrcweir }
1380cdf0e10cSrcweir 
1381cdf0e10cSrcweir // -----------------------------------------------------------------------------
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const TransferableDataHelper& rDataHelper ) :
1384cdf0e10cSrcweir     mxTransfer( rDataHelper.mxTransfer ),
1385cdf0e10cSrcweir     mxClipboard( rDataHelper.mxClipboard ),
1386cdf0e10cSrcweir 	mpFormats( new DataFlavorExVector( *rDataHelper.mpFormats ) ),
1387cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor( *rDataHelper.mpObjDesc ) ),
1388cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1389cdf0e10cSrcweir {
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir // -----------------------------------------------------------------------------
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir TransferableDataHelper& TransferableDataHelper::operator=( const TransferableDataHelper& rDataHelper )
1395cdf0e10cSrcweir {
1396cdf0e10cSrcweir 	if ( this != &rDataHelper )
1397cdf0e10cSrcweir 	{
1398cdf0e10cSrcweir         ::osl::MutexGuard aGuard( mpImpl->maMutex );
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir         bool bWasClipboardListening = ( NULL != mpImpl->mpClipboardListener );
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir         if ( bWasClipboardListening )
1403cdf0e10cSrcweir             StopClipboardListening();
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir         mxTransfer = rDataHelper.mxTransfer;
1406cdf0e10cSrcweir 		delete mpFormats, mpFormats = new DataFlavorExVector( *rDataHelper.mpFormats );
1407cdf0e10cSrcweir         delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor( *rDataHelper.mpObjDesc );
1408cdf0e10cSrcweir 		mxClipboard = rDataHelper.mxClipboard;
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir         if ( bWasClipboardListening )
1411cdf0e10cSrcweir             StartClipboardListening();
1412cdf0e10cSrcweir 	}
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir 	return *this;
1415cdf0e10cSrcweir }
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir // -----------------------------------------------------------------------------
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir TransferableDataHelper::~TransferableDataHelper()
1420cdf0e10cSrcweir {
1421cdf0e10cSrcweir 	StopClipboardListening( );
1422cdf0e10cSrcweir     {
1423cdf0e10cSrcweir         ::osl::MutexGuard aGuard( mpImpl->maMutex );
1424cdf0e10cSrcweir 	    delete mpFormats, mpFormats = NULL;
1425cdf0e10cSrcweir         delete mpObjDesc, mpObjDesc = NULL;
1426cdf0e10cSrcweir     }
1427cdf0e10cSrcweir     delete mpImpl;
1428cdf0e10cSrcweir }
1429cdf0e10cSrcweir 
1430cdf0e10cSrcweir // -----------------------------------------------------------------------------
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor >& rDataFlavorSeq,
1433cdf0e10cSrcweir                                                      DataFlavorExVector& rDataFlavorExVector )
1434cdf0e10cSrcweir {
1435cdf0e10cSrcweir     try
1436cdf0e10cSrcweir     {
1437cdf0e10cSrcweir 	    Reference< XMultiServiceFactory >       xFact( ::comphelper::getProcessServiceFactory() );
1438cdf0e10cSrcweir         Reference< XMimeContentTypeFactory >    xMimeFact;
1439cdf0e10cSrcweir 	    DataFlavorEx		                    aFlavorEx;
1440cdf0e10cSrcweir         const ::rtl::OUString                   aCharsetStr( ::rtl::OUString::createFromAscii( "charset" ) );
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir 	    if( xFact.is() )
1443cdf0e10cSrcweir 		    xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii(
1444cdf0e10cSrcweir                                                               "com.sun.star.datatransfer.MimeContentTypeFactory" ) ),
1445cdf0e10cSrcweir                                                               UNO_QUERY );
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir 	    for( sal_Int32 i = 0; i < rDataFlavorSeq.getLength(); i++ )
1448cdf0e10cSrcweir 	    {
1449cdf0e10cSrcweir 		    const DataFlavor&	            rFlavor = rDataFlavorSeq[ i ];
1450cdf0e10cSrcweir             Reference< XMimeContentType >   xMimeType;
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir             try
1453cdf0e10cSrcweir             {
1454cdf0e10cSrcweir                 if( xMimeFact.is() && rFlavor.MimeType.getLength() )
1455cdf0e10cSrcweir                     xMimeType = xMimeFact->createMimeContentType( rFlavor.MimeType );
1456cdf0e10cSrcweir             }
1457cdf0e10cSrcweir             catch( const ::com::sun::star::uno::Exception& )
1458cdf0e10cSrcweir 	        {
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir 	        }
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir 		    aFlavorEx.MimeType = rFlavor.MimeType;
1463cdf0e10cSrcweir 		    aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName;
1464cdf0e10cSrcweir 		    aFlavorEx.DataType = rFlavor.DataType;
1465cdf0e10cSrcweir 		    aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor );
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir 		    rDataFlavorExVector.push_back( aFlavorEx );
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir             // add additional formats for special mime types
147045fd3b9aSArmin Le Grand             if(SOT_FORMATSTR_ID_BMP == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_PNG == aFlavorEx.mnSotId)
1471cdf0e10cSrcweir 		    {
1472cdf0e10cSrcweir 			    if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavorEx ) )
1473cdf0e10cSrcweir 			    {
1474cdf0e10cSrcweir 				    aFlavorEx.mnSotId = SOT_FORMAT_BITMAP;
1475cdf0e10cSrcweir 				    rDataFlavorExVector.push_back( aFlavorEx );
1476cdf0e10cSrcweir 			    }
1477cdf0e10cSrcweir 		    }
1478cdf0e10cSrcweir             else if( SOT_FORMATSTR_ID_WMF == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_EMF == aFlavorEx.mnSotId )
1479cdf0e10cSrcweir 		    {
1480cdf0e10cSrcweir 			    if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavorEx ) )
1481cdf0e10cSrcweir 			    {
1482cdf0e10cSrcweir 				    aFlavorEx.mnSotId = SOT_FORMAT_GDIMETAFILE;
1483cdf0e10cSrcweir 				    rDataFlavorExVector.push_back( aFlavorEx );
1484cdf0e10cSrcweir 			    }
1485cdf0e10cSrcweir 		    }
1486cdf0e10cSrcweir             else if ( SOT_FORMATSTR_ID_HTML_SIMPLE == aFlavorEx.mnSotId  )
1487cdf0e10cSrcweir             {
1488cdf0e10cSrcweir                 // #104735# HTML_SIMPLE may also be inserted without comments
1489cdf0e10cSrcweir                 aFlavorEx.mnSotId = SOT_FORMATSTR_ID_HTML_NO_COMMENT;
1490cdf0e10cSrcweir                 rDataFlavorExVector.push_back( aFlavorEx );
1491cdf0e10cSrcweir             }
1492cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) )
1493cdf0e10cSrcweir             {
1494cdf0e10cSrcweir                 // add, if it is a UTF-8 byte buffer
1495cdf0e10cSrcweir                 if( xMimeType->hasParameter( aCharsetStr ) )
1496cdf0e10cSrcweir                 {
1497cdf0e10cSrcweir                     const ::rtl::OUString aCharset( xMimeType->getParameterValue( aCharsetStr ) );
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir                     if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) ||
1500cdf0e10cSrcweir 					    xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) )
1501cdf0e10cSrcweir                     {
1502cdf0e10cSrcweir                         rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_STRING;
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir                     }
1505cdf0e10cSrcweir                 }
1506cdf0e10cSrcweir             }
1507cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/rtf" ) ) )
1508cdf0e10cSrcweir             {
1509cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_RTF;
1510cdf0e10cSrcweir             }
1511cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/html" ) ) )
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir             {
1514cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_HTML;
1515cdf0e10cSrcweir             }
1516cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) )
1517cdf0e10cSrcweir             {
1518cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMAT_FILE_LIST;
1519cdf0e10cSrcweir             }
1520cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice-objectdescriptor-xml" ) ) )
1521cdf0e10cSrcweir             {
1522cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR;
1523cdf0e10cSrcweir             }
1524cdf0e10cSrcweir 	    }
1525cdf0e10cSrcweir     }
1526cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
1527cdf0e10cSrcweir 	{
1528cdf0e10cSrcweir 	}
1529cdf0e10cSrcweir }
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir // -----------------------------------------------------------------------------
1532cdf0e10cSrcweir 
1533cdf0e10cSrcweir void TransferableDataHelper::InitFormats()
1534cdf0e10cSrcweir {
1535cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1536cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir     mpFormats->clear();
1539cdf0e10cSrcweir     delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor;
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir     if( mxTransfer.is() )
1542cdf0e10cSrcweir     {
1543cdf0e10cSrcweir         TransferableDataHelper::FillDataFlavorExVector( mxTransfer->getTransferDataFlavors(), *mpFormats );
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir         DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1546cdf0e10cSrcweir 
1547cdf0e10cSrcweir         while( aIter != aEnd )
1548cdf0e10cSrcweir         {
1549cdf0e10cSrcweir             if( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aIter->mnSotId )
1550cdf0e10cSrcweir             {
1551cdf0e10cSrcweir                 ImplSetParameterString( *mpObjDesc, *aIter );
1552cdf0e10cSrcweir                 aIter = aEnd;
1553cdf0e10cSrcweir             }
1554cdf0e10cSrcweir             else
1555cdf0e10cSrcweir                 ++aIter;
1556cdf0e10cSrcweir         }
1557cdf0e10cSrcweir     }
1558cdf0e10cSrcweir }
1559cdf0e10cSrcweir 
1560cdf0e10cSrcweir // -----------------------------------------------------------------------------
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( SotFormatStringId nFormat ) const
1563cdf0e10cSrcweir {
1564cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir 	DataFlavorExVector::iterator	aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1567cdf0e10cSrcweir 	sal_Bool						bRet = sal_False;
1568cdf0e10cSrcweir 
1569cdf0e10cSrcweir 	while( aIter != aEnd )
1570cdf0e10cSrcweir 	{
1571cdf0e10cSrcweir 		if( nFormat == (*aIter++).mnSotId )
1572cdf0e10cSrcweir 		{
1573cdf0e10cSrcweir 			aIter = aEnd;
1574cdf0e10cSrcweir 			bRet = sal_True;
1575cdf0e10cSrcweir 		}
1576cdf0e10cSrcweir 	}
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir 	return bRet;
1579cdf0e10cSrcweir }
1580cdf0e10cSrcweir 
1581cdf0e10cSrcweir // -----------------------------------------------------------------------------
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( const DataFlavor& rFlavor ) const
1584cdf0e10cSrcweir {
1585cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir     DataFlavorExVector::iterator	aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1588cdf0e10cSrcweir 	sal_Bool						bRet = sal_False;
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir 	while( aIter != aEnd )
1591cdf0e10cSrcweir 	{
1592cdf0e10cSrcweir 		if( TransferableDataHelper::IsEqual( rFlavor, *aIter++ ) )
1593cdf0e10cSrcweir 		{
1594cdf0e10cSrcweir 			aIter = aEnd;
1595cdf0e10cSrcweir 			bRet = sal_True;
1596cdf0e10cSrcweir 		}
1597cdf0e10cSrcweir 	}
1598cdf0e10cSrcweir 
1599cdf0e10cSrcweir 	return bRet;
1600cdf0e10cSrcweir }
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir // -----------------------------------------------------------------------------
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir sal_uInt32 TransferableDataHelper::GetFormatCount() const
1605cdf0e10cSrcweir {
1606cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1607cdf0e10cSrcweir 	return mpFormats->size();
1608cdf0e10cSrcweir }
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir // -----------------------------------------------------------------------------
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir SotFormatStringId TransferableDataHelper::GetFormat( sal_uInt32 nFormat ) const
1614cdf0e10cSrcweir {
1615cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1616cdf0e10cSrcweir 	DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" );
1617cdf0e10cSrcweir 	return( ( nFormat < mpFormats->size() ) ? (*mpFormats)[ nFormat ].mnSotId : 0 );
1618cdf0e10cSrcweir }
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir // -----------------------------------------------------------------------------
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir DataFlavor TransferableDataHelper::GetFormatDataFlavor( sal_uInt32 nFormat ) const
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1625cdf0e10cSrcweir 	DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" );
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir     DataFlavor aRet;
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir 	if( nFormat < mpFormats->size() )
1630cdf0e10cSrcweir 		aRet = (*mpFormats)[ nFormat ];
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir 	return aRet;
1633cdf0e10cSrcweir }
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir // -----------------------------------------------------------------------------
1636cdf0e10cSrcweir 
1637cdf0e10cSrcweir Reference< XTransferable > TransferableDataHelper::GetXTransferable() const
1638cdf0e10cSrcweir {
1639cdf0e10cSrcweir 	Reference< XTransferable > xRet;
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir 	if( mxTransfer.is() )
1642cdf0e10cSrcweir 	{
1643cdf0e10cSrcweir 		try
1644cdf0e10cSrcweir 		{
1645cdf0e10cSrcweir 			xRet = mxTransfer;
1646cdf0e10cSrcweir 
1647cdf0e10cSrcweir 			// do a dummy call to check, if this interface is valid (nasty)
1648cdf0e10cSrcweir 			Sequence< DataFlavor > aTestSeq( xRet->getTransferDataFlavors() );
1649cdf0e10cSrcweir 
1650cdf0e10cSrcweir 		}
1651cdf0e10cSrcweir 		catch( const ::com::sun::star::uno::Exception& )
1652cdf0e10cSrcweir 		{
1653cdf0e10cSrcweir 			xRet = Reference< XTransferable >();
1654cdf0e10cSrcweir 		}
1655cdf0e10cSrcweir 	}
1656cdf0e10cSrcweir 
1657cdf0e10cSrcweir 	return xRet;
1658cdf0e10cSrcweir }
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir // -----------------------------------------------------------------------------
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir Any	TransferableDataHelper::GetAny( SotFormatStringId nFormat ) const
1663cdf0e10cSrcweir {
1664cdf0e10cSrcweir 	Any aReturn;
1665cdf0e10cSrcweir 
1666cdf0e10cSrcweir 	DataFlavor aFlavor;
1667cdf0e10cSrcweir 	if ( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
1668cdf0e10cSrcweir 		aReturn = GetAny( aFlavor );
1669cdf0e10cSrcweir 
1670cdf0e10cSrcweir 	return aReturn;
1671cdf0e10cSrcweir }
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir // -----------------------------------------------------------------------------
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir Any TransferableDataHelper::GetAny( const DataFlavor& rFlavor ) const
1677cdf0e10cSrcweir {
1678cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1679cdf0e10cSrcweir 	Any aRet;
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir 	try
1682cdf0e10cSrcweir 	{
1683cdf0e10cSrcweir 		if( mxTransfer.is() )
1684cdf0e10cSrcweir         {
1685cdf0e10cSrcweir             DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1686cdf0e10cSrcweir             const SotFormatStringId         nRequestFormat = SotExchange::GetFormat( rFlavor );
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir             if( nRequestFormat )
1689cdf0e10cSrcweir             {
1690cdf0e10cSrcweir     	        // try to get alien format first
1691cdf0e10cSrcweir 	            while( aIter != aEnd )
1692cdf0e10cSrcweir 	            {
1693cdf0e10cSrcweir                     if( ( nRequestFormat == (*aIter).mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( (*aIter).MimeType ) )
1694cdf0e10cSrcweir             			aRet = mxTransfer->getTransferData( *aIter );
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir                     if( aRet.hasValue() )
1697cdf0e10cSrcweir                         aIter = aEnd;
1698cdf0e10cSrcweir                     else
1699cdf0e10cSrcweir                         aIter++;
1700cdf0e10cSrcweir 	            }
1701cdf0e10cSrcweir             }
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir             if( !aRet.hasValue() )
1704cdf0e10cSrcweir     			aRet = mxTransfer->getTransferData( rFlavor );
1705cdf0e10cSrcweir         }
1706cdf0e10cSrcweir 	}
1707cdf0e10cSrcweir 	catch( const ::com::sun::star::uno::Exception& )
1708cdf0e10cSrcweir 	{
1709cdf0e10cSrcweir 	}
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir 	return aRet;
1712cdf0e10cSrcweir }
1713cdf0e10cSrcweir 
1714cdf0e10cSrcweir // -----------------------------------------------------------------------------
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, String& rStr )
1717cdf0e10cSrcweir {
1718cdf0e10cSrcweir     ::rtl::OUString aOUString;
1719cdf0e10cSrcweir     sal_Bool        bRet = GetString( nFormat, aOUString );
1720cdf0e10cSrcweir 
1721cdf0e10cSrcweir     rStr = aOUString;
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir     return bRet;
1724cdf0e10cSrcweir }
1725cdf0e10cSrcweir 
1726cdf0e10cSrcweir // -----------------------------------------------------------------------------
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, String& rStr )
1729cdf0e10cSrcweir {
1730cdf0e10cSrcweir     ::rtl::OUString aOUString;
1731cdf0e10cSrcweir     sal_Bool        bRet = GetString( rFlavor, aOUString );
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir     rStr = aOUString;
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir     return bRet;
1736cdf0e10cSrcweir }
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir // -----------------------------------------------------------------------------
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, ::rtl::OUString& rStr )
1741cdf0e10cSrcweir {
1742cdf0e10cSrcweir 	DataFlavor aFlavor;
1743cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetString( aFlavor, rStr ) );
1744cdf0e10cSrcweir }
1745cdf0e10cSrcweir 
1746cdf0e10cSrcweir // -----------------------------------------------------------------------------
1747cdf0e10cSrcweir 
1748cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, ::rtl::OUString& rStr )
1749cdf0e10cSrcweir {
1750cdf0e10cSrcweir 	Any         aAny( GetAny( rFlavor ) );
1751cdf0e10cSrcweir     sal_Bool    bRet = sal_False;
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir     if( aAny.hasValue() )
1754cdf0e10cSrcweir 	{
1755cdf0e10cSrcweir 		::rtl::OUString         aOUString;
1756cdf0e10cSrcweir 		Sequence< sal_Int8 >    aSeq;
1757cdf0e10cSrcweir 
1758cdf0e10cSrcweir         if( aAny >>= aOUString )
1759cdf0e10cSrcweir         {
1760cdf0e10cSrcweir 			rStr = aOUString;
1761cdf0e10cSrcweir             bRet = sal_True;
1762cdf0e10cSrcweir         }
1763cdf0e10cSrcweir 		else if( aAny >>= aSeq )
1764cdf0e10cSrcweir 		{
1765cdf0e10cSrcweir 
1766cdf0e10cSrcweir 			const sal_Char* pChars = reinterpret_cast< const sal_Char* >( aSeq.getConstArray() );
1767cdf0e10cSrcweir 			sal_Int32       nLen = aSeq.getLength();
1768cdf0e10cSrcweir 
1769cdf0e10cSrcweir             //JP 10.10.2001: 92930 - don't copy the last zero characterinto the string.
1770cdf0e10cSrcweir             //DVO 2002-05-27: strip _all_ trailing zeros
1771cdf0e10cSrcweir 			while( nLen && ( 0 == *( pChars + nLen - 1 ) ) )
1772cdf0e10cSrcweir 				--nLen;
1773cdf0e10cSrcweir 
1774cdf0e10cSrcweir 			rStr = ::rtl::OUString( pChars, nLen, gsl_getSystemTextEncoding() );
1775cdf0e10cSrcweir             bRet = sal_True;
1776cdf0e10cSrcweir 		}
1777cdf0e10cSrcweir 	}
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir     return bRet;
1780cdf0e10cSrcweir }
1781cdf0e10cSrcweir 
1782cdf0e10cSrcweir // -----------------------------------------------------------------------------
1783cdf0e10cSrcweir 
178445fd3b9aSArmin Le Grand sal_Bool TransferableDataHelper::GetBitmapEx( SotFormatStringId nFormat, BitmapEx& rBmpEx )
1785cdf0e10cSrcweir {
178645fd3b9aSArmin Le Grand     if(FORMAT_BITMAP == nFormat)
178745fd3b9aSArmin Le Grand     {
178845fd3b9aSArmin Le Grand         // try to get PNG first
1789cdf0e10cSrcweir         DataFlavor aFlavor;
179045fd3b9aSArmin Le Grand 
179145fd3b9aSArmin Le Grand         if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor))
179245fd3b9aSArmin Le Grand         {
179345fd3b9aSArmin Le Grand             if(GetBitmapEx(aFlavor, rBmpEx))
179445fd3b9aSArmin Le Grand             {
179545fd3b9aSArmin Le Grand                 return true;
179645fd3b9aSArmin Le Grand             }
179745fd3b9aSArmin Le Grand         }
179845fd3b9aSArmin Le Grand     }
179945fd3b9aSArmin Le Grand 
180045fd3b9aSArmin Le Grand     DataFlavor aFlavor;
180145fd3b9aSArmin Le Grand     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetBitmapEx( aFlavor, rBmpEx ) );
1802cdf0e10cSrcweir }
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir // -----------------------------------------------------------------------------
1805cdf0e10cSrcweir 
180645fd3b9aSArmin Le Grand sal_Bool TransferableDataHelper::GetBitmapEx( const DataFlavor& rFlavor, BitmapEx& rBmpEx )
1807cdf0e10cSrcweir {
1808cdf0e10cSrcweir     SotStorageStreamRef xStm;
1809cdf0e10cSrcweir     DataFlavor aSubstFlavor;
181045fd3b9aSArmin Le Grand     bool bRet(GetSotStorageStream(rFlavor, xStm));
181145fd3b9aSArmin Le Grand 
181245fd3b9aSArmin Le Grand     if(!bRet && HasFormat(SOT_FORMATSTR_ID_PNG) && SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aSubstFlavor))
181345fd3b9aSArmin Le Grand     {
181445fd3b9aSArmin Le Grand         // when no direct success, try if PNG is available
181545fd3b9aSArmin Le Grand         bRet = GetSotStorageStream(aSubstFlavor, xStm);
181645fd3b9aSArmin Le Grand     }
181745fd3b9aSArmin Le Grand 
181845fd3b9aSArmin Le Grand     if(!bRet && HasFormat(SOT_FORMATSTR_ID_BMP) && SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_BMP, aSubstFlavor))
181945fd3b9aSArmin Le Grand     {
182045fd3b9aSArmin Le Grand         // when no direct success, try if BMP is available
182145fd3b9aSArmin Le Grand         bRet = GetSotStorageStream(aSubstFlavor, xStm);
182245fd3b9aSArmin Le Grand     }
1823cdf0e10cSrcweir 
1824cdf0e10cSrcweir     if(bRet)
1825cdf0e10cSrcweir     {
182645fd3b9aSArmin Le Grand         if(rFlavor.MimeType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("image/png")))
182745fd3b9aSArmin Le Grand         {
182845fd3b9aSArmin Le Grand             // it's a PNG, import to BitmapEx
182945fd3b9aSArmin Le Grand             ::vcl::PNGReader aPNGReader(*xStm);
183045fd3b9aSArmin Le Grand 
183145fd3b9aSArmin Le Grand             rBmpEx = aPNGReader.Read();
183245fd3b9aSArmin Le Grand         }
183345fd3b9aSArmin Le Grand         else
183445fd3b9aSArmin Le Grand         {
183545fd3b9aSArmin Le Grand             Bitmap aBitmap;
183645fd3b9aSArmin Le Grand             Bitmap aMask;
183745fd3b9aSArmin Le Grand 
183845fd3b9aSArmin Le Grand             // explicitely use Bitmap::Read with bFileHeader = sal_True
183945fd3b9aSArmin Le Grand             ReadDIBV5(aBitmap, aMask, *xStm);
184045fd3b9aSArmin Le Grand 
184145fd3b9aSArmin Le Grand             if(aMask.IsEmpty())
184245fd3b9aSArmin Le Grand             {
184345fd3b9aSArmin Le Grand                 rBmpEx = aBitmap;
184445fd3b9aSArmin Le Grand             }
184545fd3b9aSArmin Le Grand             else
184645fd3b9aSArmin Le Grand             {
184745fd3b9aSArmin Le Grand                 rBmpEx = BitmapEx(aBitmap, aMask);
184845fd3b9aSArmin Le Grand             }
184945fd3b9aSArmin Le Grand         }
185045fd3b9aSArmin Le Grand 
185145fd3b9aSArmin Le Grand         bRet = (ERRCODE_NONE == xStm->GetError());
1852cdf0e10cSrcweir 
1853cdf0e10cSrcweir         /* SJ: #110748# At the moment we are having problems with DDB inserted as DIB. The
1854cdf0e10cSrcweir            problem is, that some graphics are inserted much too big because the nXPelsPerMeter
1855cdf0e10cSrcweir            and nYPelsPerMeter of the bitmap fileheader isn't including the correct value.
1856cdf0e10cSrcweir            Due to this reason the following code assumes that bitmaps with a logical size
1857cdf0e10cSrcweir            greater than 50 cm aren't having the correct mapmode set.
1858cdf0e10cSrcweir 
1859cdf0e10cSrcweir            The following code should be removed if DDBs and DIBs are supported via clipboard
1860cdf0e10cSrcweir            properly.
1861cdf0e10cSrcweir         */
1862cdf0e10cSrcweir         if(bRet)
1863cdf0e10cSrcweir         {
186445fd3b9aSArmin Le Grand             const MapMode aMapMode(rBmpEx.GetPrefMapMode());
1865cdf0e10cSrcweir 
186645fd3b9aSArmin Le Grand             if(MAP_PIXEL != aMapMode.GetMapUnit())
1867cdf0e10cSrcweir             {
186845fd3b9aSArmin Le Grand                 const Size aSize(OutputDevice::LogicToLogic(rBmpEx.GetPrefSize(), aMapMode, MAP_100TH_MM));
186945fd3b9aSArmin Le Grand 
1870*519071a5SArmin Le Grand                 // #122388# This wrongly corrects in the given case; changing from 5000 100th mm to
1871*519071a5SArmin Le Grand                 // the described 50 cm (which is 50000 100th mm)
1872*519071a5SArmin Le Grand                 if((aSize.Width() > 50000) || (aSize.Height() > 50000))
187345fd3b9aSArmin Le Grand                 {
187445fd3b9aSArmin Le Grand                     rBmpEx.SetPrefMapMode(MAP_PIXEL);
1875*519071a5SArmin Le Grand 
1876*519071a5SArmin Le Grand                     // #122388# also adapt size by applying the mew MapMode
1877*519071a5SArmin Le Grand                     const Size aNewSize(OutputDevice::LogicToLogic(aSize, MAP_100TH_MM, MAP_PIXEL));
1878*519071a5SArmin Le Grand                     rBmpEx.SetPrefSize(aNewSize);
187945fd3b9aSArmin Le Grand                 }
188045fd3b9aSArmin Le Grand             }
188145fd3b9aSArmin Le Grand         }
1882cdf0e10cSrcweir     }
1883cdf0e10cSrcweir 
1884cdf0e10cSrcweir     return bRet;
1885cdf0e10cSrcweir }
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir // -----------------------------------------------------------------------------
1888cdf0e10cSrcweir 
1889cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( SotFormatStringId nFormat, GDIMetaFile& rMtf )
1890cdf0e10cSrcweir {
1891cdf0e10cSrcweir 	DataFlavor aFlavor;
1892cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGDIMetaFile( aFlavor, rMtf ) );
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir // -----------------------------------------------------------------------------
1896cdf0e10cSrcweir 
1897cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaFile& rMtf )
1898cdf0e10cSrcweir {
1899cdf0e10cSrcweir 	SotStorageStreamRef xStm;
1900cdf0e10cSrcweir 	DataFlavor			aSubstFlavor;
1901cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir 	if( GetSotStorageStream( rFlavor, xStm ) )
1904cdf0e10cSrcweir 	{
1905cdf0e10cSrcweir 		*xStm >> rMtf;
1906cdf0e10cSrcweir 		bRet = ( xStm->GetError() == ERRCODE_NONE );
1907cdf0e10cSrcweir 	}
1908cdf0e10cSrcweir 
1909cdf0e10cSrcweir 	if( !bRet &&
1910cdf0e10cSrcweir 		HasFormat( SOT_FORMATSTR_ID_EMF ) &&
1911cdf0e10cSrcweir 		SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_EMF, aSubstFlavor ) &&
1912cdf0e10cSrcweir 		GetSotStorageStream( aSubstFlavor, xStm ) )
1913cdf0e10cSrcweir 	{
1914cdf0e10cSrcweir 		Graphic aGraphic;
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 		if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE )
1917cdf0e10cSrcweir 		{
1918cdf0e10cSrcweir 			rMtf = aGraphic.GetGDIMetaFile();
1919cdf0e10cSrcweir 			bRet = sal_True;
1920cdf0e10cSrcweir 		}
1921cdf0e10cSrcweir 	}
1922cdf0e10cSrcweir 
1923cdf0e10cSrcweir 	if( !bRet &&
1924cdf0e10cSrcweir 		HasFormat( SOT_FORMATSTR_ID_WMF ) &&
1925cdf0e10cSrcweir 		SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_WMF, aSubstFlavor ) &&
1926cdf0e10cSrcweir 		GetSotStorageStream( aSubstFlavor, xStm ) )
1927cdf0e10cSrcweir 	{
1928cdf0e10cSrcweir 		Graphic aGraphic;
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir 		if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE )
1931cdf0e10cSrcweir 		{
1932cdf0e10cSrcweir 			rMtf = aGraphic.GetGDIMetaFile();
1933cdf0e10cSrcweir 			bRet = sal_True;
1934cdf0e10cSrcweir 		}
1935cdf0e10cSrcweir 	}
1936cdf0e10cSrcweir 
1937cdf0e10cSrcweir 	return bRet;
1938cdf0e10cSrcweir }
1939cdf0e10cSrcweir 
1940cdf0e10cSrcweir // -----------------------------------------------------------------------------
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( SotFormatStringId nFormat, Graphic& rGraphic )
1943cdf0e10cSrcweir {
194445fd3b9aSArmin Le Grand     if(FORMAT_BITMAP == nFormat)
194545fd3b9aSArmin Le Grand     {
194645fd3b9aSArmin Le Grand         // try to get PNG first
194745fd3b9aSArmin Le Grand         DataFlavor aFlavor;
194845fd3b9aSArmin Le Grand 
194945fd3b9aSArmin Le Grand         if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor))
195045fd3b9aSArmin Le Grand         {
195145fd3b9aSArmin Le Grand             if(GetGraphic(aFlavor, rGraphic))
195245fd3b9aSArmin Le Grand             {
195345fd3b9aSArmin Le Grand                 return true;
195445fd3b9aSArmin Le Grand             }
195545fd3b9aSArmin Le Grand         }
195645fd3b9aSArmin Le Grand     }
195745fd3b9aSArmin Le Grand 
1958cdf0e10cSrcweir     DataFlavor aFlavor;
1959cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGraphic( aFlavor, rGraphic ) );
1960cdf0e10cSrcweir }
1961cdf0e10cSrcweir 
1962cdf0e10cSrcweir // -----------------------------------------------------------------------------
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, Graphic& rGraphic )
1965cdf0e10cSrcweir {
1966cdf0e10cSrcweir 	DataFlavor	aFlavor;
1967cdf0e10cSrcweir 	sal_Bool	bRet = sal_False;
1968cdf0e10cSrcweir 
196945fd3b9aSArmin Le Grand     if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor) &&
1970cdf0e10cSrcweir         TransferableDataHelper::IsEqual(aFlavor, rFlavor))
1971cdf0e10cSrcweir 	{
197245fd3b9aSArmin Le Grand         // try to get PNG first
197345fd3b9aSArmin Le Grand 		BitmapEx aBmpEx;
1974cdf0e10cSrcweir 
197545fd3b9aSArmin Le Grand 		if( ( bRet = GetBitmapEx( aFlavor, aBmpEx ) ) == sal_True )
197645fd3b9aSArmin Le Grand 			rGraphic = aBmpEx;
197745fd3b9aSArmin Le Grand 	}
197845fd3b9aSArmin Le Grand 	else if(SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavor ) &&
197945fd3b9aSArmin Le Grand 		TransferableDataHelper::IsEqual( aFlavor, rFlavor ) )
198045fd3b9aSArmin Le Grand 	{
198145fd3b9aSArmin Le Grand 		BitmapEx aBmpEx;
198245fd3b9aSArmin Le Grand 
198345fd3b9aSArmin Le Grand 		if( ( bRet = GetBitmapEx( aFlavor, aBmpEx ) ) == sal_True )
198445fd3b9aSArmin Le Grand 			rGraphic = aBmpEx;
1985cdf0e10cSrcweir 	}
1986cdf0e10cSrcweir 	else if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavor ) &&
1987cdf0e10cSrcweir 			 TransferableDataHelper::IsEqual( aFlavor, rFlavor ) )
1988cdf0e10cSrcweir 	{
1989cdf0e10cSrcweir 		GDIMetaFile aMtf;
1990cdf0e10cSrcweir 
1991cdf0e10cSrcweir 		if( ( bRet = GetGDIMetaFile( aFlavor, aMtf ) ) == sal_True )
1992cdf0e10cSrcweir 			rGraphic = aMtf;
1993cdf0e10cSrcweir 	}
1994cdf0e10cSrcweir 	else
1995cdf0e10cSrcweir 	{
1996cdf0e10cSrcweir 		SotStorageStreamRef xStm;
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir 		if( GetSotStorageStream( rFlavor, xStm ) )
1999cdf0e10cSrcweir 		{
2000cdf0e10cSrcweir 			*xStm >> rGraphic;
2001cdf0e10cSrcweir 			bRet = ( xStm->GetError() == ERRCODE_NONE );
2002cdf0e10cSrcweir 		}
2003cdf0e10cSrcweir 	}
2004cdf0e10cSrcweir 
2005cdf0e10cSrcweir 	return bRet;
2006cdf0e10cSrcweir }
2007cdf0e10cSrcweir 
2008cdf0e10cSrcweir // -----------------------------------------------------------------------------
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( SotFormatStringId nFormat, ImageMap& rIMap )
2011cdf0e10cSrcweir {
2012cdf0e10cSrcweir 	DataFlavor aFlavor;
2013cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetImageMap( aFlavor, rIMap ) );
2014cdf0e10cSrcweir }
2015cdf0e10cSrcweir 
2016cdf0e10cSrcweir // -----------------------------------------------------------------------------
2017cdf0e10cSrcweir 
2018cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, ImageMap& rIMap )
2019cdf0e10cSrcweir {
2020cdf0e10cSrcweir 	SotStorageStreamRef xStm;
2021cdf0e10cSrcweir 	sal_Bool			bRet = GetSotStorageStream( rFlavor, xStm );
2022cdf0e10cSrcweir 
2023cdf0e10cSrcweir 	if( bRet )
2024cdf0e10cSrcweir 	{
2025cdf0e10cSrcweir         rIMap.Read( *xStm, String() );
2026cdf0e10cSrcweir 		bRet = ( xStm->GetError() == ERRCODE_NONE );
2027cdf0e10cSrcweir 	}
2028cdf0e10cSrcweir 
2029cdf0e10cSrcweir 	return bRet;
2030cdf0e10cSrcweir }
2031cdf0e10cSrcweir 
2032cdf0e10cSrcweir // -----------------------------------------------------------------------------
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( SotFormatStringId nFormat, TransferableObjectDescriptor& rDesc )
2035cdf0e10cSrcweir {
2036cdf0e10cSrcweir 	DataFlavor aFlavor;
2037cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetTransferableObjectDescriptor( aFlavor, rDesc ) );
2038cdf0e10cSrcweir }
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir // -----------------------------------------------------------------------------
2041cdf0e10cSrcweir 
2042cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( const ::com::sun::star::datatransfer::DataFlavor&, TransferableObjectDescriptor& rDesc )
2043cdf0e10cSrcweir {
2044cdf0e10cSrcweir     rDesc = *mpObjDesc;
2045cdf0e10cSrcweir     return true;
2046cdf0e10cSrcweir }
2047cdf0e10cSrcweir 
2048cdf0e10cSrcweir // -----------------------------------------------------------------------------
2049cdf0e10cSrcweir 
2050cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( SotFormatStringId nFormat, INetBookmark& rBmk )
2051cdf0e10cSrcweir {
2052cdf0e10cSrcweir 	DataFlavor aFlavor;
2053cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetBookmark( aFlavor, rBmk ) );
2054cdf0e10cSrcweir }
2055cdf0e10cSrcweir 
2056cdf0e10cSrcweir // -----------------------------------------------------------------------------
2057cdf0e10cSrcweir 
2058cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, INetBookmark& rBmk )
2059cdf0e10cSrcweir {
2060cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2061cdf0e10cSrcweir 	if( HasFormat( rFlavor ))
2062cdf0e10cSrcweir 	{
2063cdf0e10cSrcweir 	const SotFormatStringId nFormat = SotExchange::GetFormat( rFlavor );
2064cdf0e10cSrcweir 	switch( nFormat )
2065cdf0e10cSrcweir 	{
2066cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_SOLK ):
2067cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ):
2068cdf0e10cSrcweir 		{
2069cdf0e10cSrcweir 			String aString;
2070cdf0e10cSrcweir 			if( GetString( rFlavor, aString ) )
2071cdf0e10cSrcweir 			{
2072cdf0e10cSrcweir 				if( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR == nFormat )
2073cdf0e10cSrcweir 				{
2074cdf0e10cSrcweir 					rBmk = INetBookmark( aString, aString );
2075cdf0e10cSrcweir 					bRet = sal_True;
2076cdf0e10cSrcweir 				}
2077cdf0e10cSrcweir 				else
2078cdf0e10cSrcweir 				{
2079cdf0e10cSrcweir 					String		aURL, aDesc;
2080cdf0e10cSrcweir 					sal_uInt16	nStart = aString.Search( '@' ), nLen = (sal_uInt16) aString.ToInt32();
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir 					if( !nLen && aString.GetChar( 0 ) != '0' )
2083cdf0e10cSrcweir 					{
2084cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 1. len=0" );
2085cdf0e10cSrcweir 					}
2086cdf0e10cSrcweir 					if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 3 )
2087cdf0e10cSrcweir 					{
2088cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 1. illegal start or wrong len" );
2089cdf0e10cSrcweir 					}
2090cdf0e10cSrcweir 					aURL = aString.Copy( nStart + 1, nLen );
2091cdf0e10cSrcweir 
2092cdf0e10cSrcweir 					aString.Erase( 0, nStart + 1 + nLen );
2093cdf0e10cSrcweir 					nStart = aString.Search( '@' );
2094cdf0e10cSrcweir 					nLen = (sal_uInt16) aString.ToInt32();
2095cdf0e10cSrcweir 
2096cdf0e10cSrcweir 					if( !nLen && aString.GetChar( 0 ) != '0' )
2097cdf0e10cSrcweir 					{
2098cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 2. len=0" );
2099cdf0e10cSrcweir 					}
2100cdf0e10cSrcweir 					if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 1 )
2101cdf0e10cSrcweir 					{
2102cdf0e10cSrcweir 						DBG_WARNING( "SOLK: 2. illegal start or wrong len" );
2103cdf0e10cSrcweir 					}
2104cdf0e10cSrcweir 					aDesc = aString.Copy( nStart+1, nLen );
2105cdf0e10cSrcweir 
2106cdf0e10cSrcweir 					rBmk = INetBookmark( aURL, aDesc );
2107cdf0e10cSrcweir 					bRet = sal_True;
2108cdf0e10cSrcweir 				}
2109cdf0e10cSrcweir 			}
2110cdf0e10cSrcweir 		}
2111cdf0e10cSrcweir 		break;
2112cdf0e10cSrcweir 
2113cdf0e10cSrcweir 		case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ):
2114cdf0e10cSrcweir 		{
2115cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq;
2116cdf0e10cSrcweir 
2117cdf0e10cSrcweir 			if( GetSequence( rFlavor, aSeq ) && ( 2048 == aSeq.getLength() ) )
2118cdf0e10cSrcweir 			{
2119cdf0e10cSrcweir 				rBmk = INetBookmark( String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), gsl_getSystemTextEncoding() ),
2120cdf0e10cSrcweir 									 String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ) + 1024, gsl_getSystemTextEncoding() ) );
2121cdf0e10cSrcweir 				bRet = sal_True;
2122cdf0e10cSrcweir 			}
2123cdf0e10cSrcweir 		}
2124cdf0e10cSrcweir 		break;
2125cdf0e10cSrcweir 
2126cdf0e10cSrcweir #ifdef WNT
2127cdf0e10cSrcweir 		case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
2128cdf0e10cSrcweir 		{
2129cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq;
2130cdf0e10cSrcweir 
2131cdf0e10cSrcweir 			if( GetSequence( rFlavor, aSeq ) && aSeq.getLength() )
2132cdf0e10cSrcweir 			{
2133cdf0e10cSrcweir 				FILEGROUPDESCRIPTOR* pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getConstArray();
2134cdf0e10cSrcweir 
2135cdf0e10cSrcweir 				if( pFDesc->cItems )
2136cdf0e10cSrcweir 				{
2137cdf0e10cSrcweir 					ByteString			aDesc( pFDesc->fgd[ 0 ].cFileName );
2138cdf0e10cSrcweir 					rtl_TextEncoding	eTextEncoding = gsl_getSystemTextEncoding();
2139cdf0e10cSrcweir 
2140cdf0e10cSrcweir 					if( ( aDesc.Len() > 4 ) && aDesc.Copy( aDesc.Len() - 4 ).EqualsIgnoreCaseAscii( ".URL" ) )
2141cdf0e10cSrcweir 					{
2142cdf0e10cSrcweir 						SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( INetURLObject( String( aDesc, eTextEncoding ) ).GetMainURL( INetURLObject::NO_DECODE ),
2143cdf0e10cSrcweir                                                                                   STREAM_STD_READ );
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir 						if( !pStream || pStream->GetError() )
2146cdf0e10cSrcweir 						{
2147cdf0e10cSrcweir 							DataFlavor aFileContentFlavor;
2148cdf0e10cSrcweir 
2149cdf0e10cSrcweir 							aSeq.realloc( 0 );
2150cdf0e10cSrcweir 							delete pStream;
2151cdf0e10cSrcweir 
2152cdf0e10cSrcweir 							if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_FILECONTENT, aFileContentFlavor ) &&
2153cdf0e10cSrcweir 								GetSequence( aFileContentFlavor, aSeq ) && aSeq.getLength() )
2154cdf0e10cSrcweir 							{
2155cdf0e10cSrcweir 								pStream = new SvMemoryStream( (sal_Char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_STD_READ );
2156cdf0e10cSrcweir 							}
2157cdf0e10cSrcweir 							else
2158cdf0e10cSrcweir 								pStream = NULL;
2159cdf0e10cSrcweir 						}
2160cdf0e10cSrcweir 
2161cdf0e10cSrcweir 						if( pStream )
2162cdf0e10cSrcweir 						{
2163cdf0e10cSrcweir 							ByteString	aLine;
2164cdf0e10cSrcweir 							sal_Bool	bSttFnd = sal_False;
2165cdf0e10cSrcweir 
2166cdf0e10cSrcweir 							while( pStream->ReadLine( aLine ) )
2167cdf0e10cSrcweir 							{
2168cdf0e10cSrcweir 								if( aLine.EqualsIgnoreCaseAscii( "[InternetShortcut]" ) )
2169cdf0e10cSrcweir 									bSttFnd = sal_True;
2170cdf0e10cSrcweir 								else if( bSttFnd && aLine.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "URL=" ) )
2171cdf0e10cSrcweir 								{
2172cdf0e10cSrcweir 									rBmk = INetBookmark( String( aLine.Erase( 0, 4 ), eTextEncoding ),
2173cdf0e10cSrcweir 														 String( aDesc.Erase( aDesc.Len() - 4 ), eTextEncoding ) );
2174cdf0e10cSrcweir 									bRet = sal_True;
2175cdf0e10cSrcweir 									break;
2176cdf0e10cSrcweir 								}
2177cdf0e10cSrcweir 							}
2178cdf0e10cSrcweir 
2179cdf0e10cSrcweir 							delete pStream;
2180cdf0e10cSrcweir 						}
2181cdf0e10cSrcweir 					}
2182cdf0e10cSrcweir 				}
2183cdf0e10cSrcweir 			}
2184cdf0e10cSrcweir 		}
2185cdf0e10cSrcweir 		break;
2186cdf0e10cSrcweir #endif
2187cdf0e10cSrcweir 
2188cdf0e10cSrcweir 	}
2189cdf0e10cSrcweir 	}
2190cdf0e10cSrcweir 	return bRet;
2191cdf0e10cSrcweir }
2192cdf0e10cSrcweir 
2193cdf0e10cSrcweir // -----------------------------------------------------------------------------
2194cdf0e10cSrcweir 
2195cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage( SotFormatStringId nFormat,
2196cdf0e10cSrcweir 												INetImage& rINtImg )
2197cdf0e10cSrcweir {
2198cdf0e10cSrcweir 	DataFlavor aFlavor;
2199cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetImage( aFlavor, rINtImg ) );
2200cdf0e10cSrcweir }
2201cdf0e10cSrcweir 
2202cdf0e10cSrcweir // -----------------------------------------------------------------------------
2203cdf0e10cSrcweir 
2204cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage(
2205cdf0e10cSrcweir 		const ::com::sun::star::datatransfer::DataFlavor& rFlavor,
2206cdf0e10cSrcweir 		INetImage& rINtImg )
2207cdf0e10cSrcweir {
2208cdf0e10cSrcweir 	SotStorageStreamRef xStm;
2209cdf0e10cSrcweir 	sal_Bool bRet = GetSotStorageStream( rFlavor, xStm );
2210cdf0e10cSrcweir 
2211cdf0e10cSrcweir 	if( bRet )
2212cdf0e10cSrcweir 		bRet = rINtImg.Read( *xStm, SotExchange::GetFormat( rFlavor ) );
2213cdf0e10cSrcweir 	return bRet;
2214cdf0e10cSrcweir }
2215cdf0e10cSrcweir 
2216cdf0e10cSrcweir // -----------------------------------------------------------------------------
2217cdf0e10cSrcweir 
2218cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList( SotFormatStringId nFormat,
2219cdf0e10cSrcweir 												FileList& rFileList )
2220cdf0e10cSrcweir {
2221cdf0e10cSrcweir 	DataFlavor aFlavor;
2222cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetFileList( aFlavor, rFileList ) );
2223cdf0e10cSrcweir }
2224cdf0e10cSrcweir 
2225cdf0e10cSrcweir // -----------------------------------------------------------------------------
2226cdf0e10cSrcweir 
2227cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList(
2228cdf0e10cSrcweir 			const ::com::sun::star::datatransfer::DataFlavor&,
2229cdf0e10cSrcweir 			FileList& rFileList )
2230cdf0e10cSrcweir {
2231cdf0e10cSrcweir 	SotStorageStreamRef xStm;
2232cdf0e10cSrcweir     sal_Bool            bRet = sal_False;
2233cdf0e10cSrcweir 
2234cdf0e10cSrcweir     for( sal_uInt32 i = 0, nFormatCount = GetFormatCount(); ( i < nFormatCount ) && !bRet; ++i )
2235cdf0e10cSrcweir     {
2236cdf0e10cSrcweir         if( SOT_FORMAT_FILE_LIST == GetFormat( i ) )
2237cdf0e10cSrcweir         {
2238cdf0e10cSrcweir             const DataFlavor aFlavor( GetFormatDataFlavor( i ) );
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir             if( GetSotStorageStream( aFlavor, xStm ) )
2241cdf0e10cSrcweir             {
2242cdf0e10cSrcweir                 if( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) > -1 )
2243cdf0e10cSrcweir                 {
2244cdf0e10cSrcweir                     ByteString aByteString;
2245cdf0e10cSrcweir 
2246cdf0e10cSrcweir                     while( xStm->ReadLine( aByteString ) )
2247cdf0e10cSrcweir                         if( aByteString.Len() && aByteString.GetChar( 0 ) != '#' )
2248cdf0e10cSrcweir                             rFileList.AppendFile( String( aByteString, RTL_TEXTENCODING_UTF8 ) );
2249cdf0e10cSrcweir 
2250cdf0e10cSrcweir                     bRet = sal_True;
2251cdf0e10cSrcweir                  }
2252cdf0e10cSrcweir                  else
2253cdf0e10cSrcweir                     bRet = ( ( *xStm >> rFileList ).GetError() == ERRCODE_NONE );
2254cdf0e10cSrcweir             }
2255cdf0e10cSrcweir         }
2256cdf0e10cSrcweir     }
2257cdf0e10cSrcweir 
2258cdf0e10cSrcweir     return bRet;
2259cdf0e10cSrcweir }
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir // -----------------------------------------------------------------------------
2262cdf0e10cSrcweir 
2263cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( SotFormatStringId nFormat, Sequence< sal_Int8 >& rSeq )
2264cdf0e10cSrcweir {
2265cdf0e10cSrcweir 	DataFlavor aFlavor;
2266cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSequence( aFlavor, rSeq ) );
2267cdf0e10cSrcweir }
2268cdf0e10cSrcweir 
2269cdf0e10cSrcweir // -----------------------------------------------------------------------------
2270cdf0e10cSrcweir 
2271cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( const DataFlavor& rFlavor, Sequence< sal_Int8 >& rSeq )
2272cdf0e10cSrcweir {
2273cdf0e10cSrcweir #ifdef DEBUG
2274cdf0e10cSrcweir     fprintf( stderr, "TransferableDataHelper requests sequence of data\n" );
2275cdf0e10cSrcweir #endif
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir     const Any aAny( GetAny( rFlavor ) );
2278cdf0e10cSrcweir 	return( aAny.hasValue() && ( aAny >>= rSeq ) );
2279cdf0e10cSrcweir }
2280cdf0e10cSrcweir 
2281cdf0e10cSrcweir // -----------------------------------------------------------------------------
2282cdf0e10cSrcweir 
2283cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( SotFormatStringId nFormat, SotStorageStreamRef& rxStream )
2284cdf0e10cSrcweir {
2285cdf0e10cSrcweir     DataFlavor aFlavor;
2286cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSotStorageStream( aFlavor, rxStream ) );
2287cdf0e10cSrcweir }
2288cdf0e10cSrcweir 
2289cdf0e10cSrcweir // -----------------------------------------------------------------------------
2290cdf0e10cSrcweir 
2291cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( const DataFlavor& rFlavor, SotStorageStreamRef& rxStream )
2292cdf0e10cSrcweir {
2293cdf0e10cSrcweir 	Sequence< sal_Int8 >	aSeq;
2294cdf0e10cSrcweir 	sal_Bool				bRet = GetSequence( rFlavor, aSeq );
2295cdf0e10cSrcweir 
2296cdf0e10cSrcweir 	if( bRet )
2297cdf0e10cSrcweir 	{
2298cdf0e10cSrcweir 		rxStream = new SotStorageStream( String() );
2299cdf0e10cSrcweir 		rxStream->Write( aSeq.getConstArray(), aSeq.getLength() );
2300cdf0e10cSrcweir 		rxStream->Seek( 0 );
2301cdf0e10cSrcweir 	}
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir 	return bRet;
2304cdf0e10cSrcweir }
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( SotFormatStringId nFormat, Reference < XInputStream >& rxStream )
2307cdf0e10cSrcweir {
2308cdf0e10cSrcweir 	DataFlavor aFlavor;
2309cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInputStream( aFlavor, rxStream ) );
2310cdf0e10cSrcweir }
2311cdf0e10cSrcweir 
2312cdf0e10cSrcweir // -----------------------------------------------------------------------------
2313cdf0e10cSrcweir 
2314cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( const DataFlavor& rFlavor, Reference < XInputStream >& rxStream )
2315cdf0e10cSrcweir {
2316cdf0e10cSrcweir 	Sequence< sal_Int8 >	aSeq;
2317cdf0e10cSrcweir 	sal_Bool				bRet = GetSequence( rFlavor, aSeq );
2318cdf0e10cSrcweir 
2319cdf0e10cSrcweir 	if( bRet )
2320cdf0e10cSrcweir           rxStream = new ::comphelper::SequenceInputStream( aSeq );
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir 	return bRet;
2323cdf0e10cSrcweir }
2324cdf0e10cSrcweir 
2325cdf0e10cSrcweir // -----------------------------------------------------------------------------
2326cdf0e10cSrcweir 
2327cdf0e10cSrcweir 
2328cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( SotFormatStringId nFormat, Reference< XInterface >& rIf )
2329cdf0e10cSrcweir {
2330cdf0e10cSrcweir 	DataFlavor aFlavor;
2331cdf0e10cSrcweir 	return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInterface( aFlavor, rIf ) );
2332cdf0e10cSrcweir }
2333cdf0e10cSrcweir 
2334cdf0e10cSrcweir // -----------------------------------------------------------------------------
2335cdf0e10cSrcweir 
2336cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( const DataFlavor& rFlavor, Reference< XInterface >& rIf )
2337cdf0e10cSrcweir {
2338cdf0e10cSrcweir 	const Any aAny( GetAny( rFlavor ) );
2339cdf0e10cSrcweir 	return( aAny.hasValue() && ( aAny >>= rIf ) );
2340cdf0e10cSrcweir }
2341cdf0e10cSrcweir 
2342cdf0e10cSrcweir // -----------------------------------------------------------------------------
2343cdf0e10cSrcweir void TransferableDataHelper::Rebind( const Reference< XTransferable >& _rxNewContent )
2344cdf0e10cSrcweir {
2345cdf0e10cSrcweir 	mxTransfer = _rxNewContent;
2346cdf0e10cSrcweir 	InitFormats();
2347cdf0e10cSrcweir }
2348cdf0e10cSrcweir 
2349cdf0e10cSrcweir // -----------------------------------------------------------------------------
2350cdf0e10cSrcweir 
2351cdf0e10cSrcweir sal_Bool TransferableDataHelper::StartClipboardListening( )
2352cdf0e10cSrcweir {
2353cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
2354cdf0e10cSrcweir 
2355cdf0e10cSrcweir     StopClipboardListening( );
2356cdf0e10cSrcweir 
2357cdf0e10cSrcweir 	mpImpl->mpClipboardListener = new TransferableClipboardNotifier( mxClipboard, *this, mpImpl->maMutex );
2358cdf0e10cSrcweir     mpImpl->mpClipboardListener->acquire();
2359cdf0e10cSrcweir 
2360cdf0e10cSrcweir 	return mpImpl->mpClipboardListener->isListening();
2361cdf0e10cSrcweir }
2362cdf0e10cSrcweir 
2363cdf0e10cSrcweir // -----------------------------------------------------------------------------
2364cdf0e10cSrcweir 
2365cdf0e10cSrcweir void TransferableDataHelper::StopClipboardListening( )
2366cdf0e10cSrcweir {
2367cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
2368cdf0e10cSrcweir 
2369cdf0e10cSrcweir 	if ( mpImpl->mpClipboardListener )
2370cdf0e10cSrcweir     {
2371cdf0e10cSrcweir         mpImpl->mpClipboardListener->dispose();
2372cdf0e10cSrcweir         mpImpl->mpClipboardListener->release();
2373cdf0e10cSrcweir         mpImpl->mpClipboardListener = NULL;
2374cdf0e10cSrcweir     }
2375cdf0e10cSrcweir }
2376cdf0e10cSrcweir 
2377cdf0e10cSrcweir // -----------------------------------------------------------------------------
2378cdf0e10cSrcweir 
2379cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSystemClipboard( Window * pWindow )
2380cdf0e10cSrcweir {
2381cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
2382cdf0e10cSrcweir 
2383cdf0e10cSrcweir     Reference< XClipboard >	xClipboard;
2384cdf0e10cSrcweir    	TransferableDataHelper	aRet;
2385cdf0e10cSrcweir 
2386cdf0e10cSrcweir     if( pWindow )
2387cdf0e10cSrcweir         xClipboard = pWindow->GetClipboard();
2388cdf0e10cSrcweir 
2389cdf0e10cSrcweir     if( xClipboard.is() )
2390cdf0e10cSrcweir    	{
2391cdf0e10cSrcweir    		try
2392cdf0e10cSrcweir 
2393cdf0e10cSrcweir     	{
2394cdf0e10cSrcweir 	    	Reference< XTransferable > xTransferable( xClipboard->getContents() );
2395cdf0e10cSrcweir 
2396cdf0e10cSrcweir 		    if( xTransferable.is() )
2397cdf0e10cSrcweir 			{
2398cdf0e10cSrcweir     			aRet = TransferableDataHelper( xTransferable );
2399cdf0e10cSrcweir    				aRet.mxClipboard = xClipboard;
2400cdf0e10cSrcweir 					// also copy the clipboard - 99030 - 23.05.2002 - fs@openoffice.org
2401cdf0e10cSrcweir 			}
2402cdf0e10cSrcweir    		}
2403cdf0e10cSrcweir     	catch( const ::com::sun::star::uno::Exception& )
2404cdf0e10cSrcweir 	    {
2405cdf0e10cSrcweir    		}
2406cdf0e10cSrcweir     }
2407cdf0e10cSrcweir 
2408cdf0e10cSrcweir 	return aRet;
2409cdf0e10cSrcweir }
2410cdf0e10cSrcweir 
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir // -----------------------------------------------------------------------------
2413cdf0e10cSrcweir 
2414cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSelection( Window* pWindow )
2415cdf0e10cSrcweir {
2416cdf0e10cSrcweir 	DBG_ASSERT( pWindow, "Window pointer is NULL" );
2417cdf0e10cSrcweir 
2418cdf0e10cSrcweir     Reference< XClipboard >	xSelection;
2419cdf0e10cSrcweir    	TransferableDataHelper	aRet;
2420cdf0e10cSrcweir 
2421cdf0e10cSrcweir     if( pWindow )
2422cdf0e10cSrcweir         xSelection = pWindow->GetPrimarySelection();
2423cdf0e10cSrcweir 
2424cdf0e10cSrcweir     if( xSelection.is() )
2425cdf0e10cSrcweir    	{
2426cdf0e10cSrcweir         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
2427cdf0e10cSrcweir 
2428cdf0e10cSrcweir   		try
2429cdf0e10cSrcweir     	{
2430cdf0e10cSrcweir 	    	Reference< XTransferable > xTransferable( xSelection->getContents() );
2431cdf0e10cSrcweir 
2432cdf0e10cSrcweir 		    if( xTransferable.is() )
2433cdf0e10cSrcweir    			{
2434cdf0e10cSrcweir     			aRet = TransferableDataHelper( xTransferable );
2435cdf0e10cSrcweir    				aRet.mxClipboard = xSelection;
2436cdf0e10cSrcweir 		    }
2437cdf0e10cSrcweir    		}
2438cdf0e10cSrcweir     	catch( const ::com::sun::star::uno::Exception& )
2439cdf0e10cSrcweir 	    {
2440cdf0e10cSrcweir    		}
2441cdf0e10cSrcweir 
2442cdf0e10cSrcweir         Application::AcquireSolarMutex( nRef );
2443cdf0e10cSrcweir     }
2444cdf0e10cSrcweir 
2445cdf0e10cSrcweir 	return aRet;
2446cdf0e10cSrcweir }
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir // -----------------------------------------------------------------------------
2449cdf0e10cSrcweir sal_Bool TransferableDataHelper::IsEqual( const ::com::sun::star::datatransfer::DataFlavor& rInternalFlavor,
2450cdf0e10cSrcweir 										  const ::com::sun::star::datatransfer::DataFlavor& rRequestFlavor,
2451cdf0e10cSrcweir                                           sal_Bool )
2452cdf0e10cSrcweir {
2453cdf0e10cSrcweir     Reference< XMultiServiceFactory >       xFact( ::comphelper::getProcessServiceFactory() );
2454cdf0e10cSrcweir     Reference< XMimeContentTypeFactory >    xMimeFact;
2455cdf0e10cSrcweir 	sal_Bool								bRet = sal_False;
2456cdf0e10cSrcweir 
2457cdf0e10cSrcweir     try
2458cdf0e10cSrcweir     {
2459cdf0e10cSrcweir 		if( xFact.is() )
2460cdf0e10cSrcweir     	    xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii(
2461cdf0e10cSrcweir                                                               "com.sun.star.datatransfer.MimeContentTypeFactory" ) ),
2462cdf0e10cSrcweir                                                               UNO_QUERY );
2463cdf0e10cSrcweir 
2464cdf0e10cSrcweir         if( xMimeFact.is() )
2465cdf0e10cSrcweir 		{
2466cdf0e10cSrcweir             Reference< XMimeContentType > xRequestType1( xMimeFact->createMimeContentType( rInternalFlavor.MimeType ) );
2467cdf0e10cSrcweir             Reference< XMimeContentType > xRequestType2( xMimeFact->createMimeContentType( rRequestFlavor.MimeType ) );
2468cdf0e10cSrcweir 
2469cdf0e10cSrcweir 			if( xRequestType1.is() && xRequestType2.is() )
2470cdf0e10cSrcweir             {
2471cdf0e10cSrcweir                 if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( xRequestType2->getFullMediaType() ) )
2472cdf0e10cSrcweir 			    {
2473cdf0e10cSrcweir                     if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) )
2474cdf0e10cSrcweir                     {
2475cdf0e10cSrcweir                         // special handling for text/plain media types
2476cdf0e10cSrcweir                         const ::rtl::OUString aCharsetString( ::rtl::OUString::createFromAscii( "charset" ) );
2477cdf0e10cSrcweir 
2478cdf0e10cSrcweir                         if( !xRequestType2->hasParameter( aCharsetString ) ||
2479cdf0e10cSrcweir 						    xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) ||
2480cdf0e10cSrcweir 						    xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) )
2481cdf0e10cSrcweir                         {
2482cdf0e10cSrcweir                             bRet = sal_True;
2483cdf0e10cSrcweir                         }
2484cdf0e10cSrcweir                     }
2485cdf0e10cSrcweir                     else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice" ) ) )
2486cdf0e10cSrcweir                     {
2487cdf0e10cSrcweir                         // special handling for application/x-openoffice media types
2488cdf0e10cSrcweir                         const ::rtl::OUString aFormatString( ::rtl::OUString::createFromAscii( "windows_formatname" ) );
2489cdf0e10cSrcweir 
2490cdf0e10cSrcweir                         if( xRequestType1->hasParameter( aFormatString ) &&
2491cdf0e10cSrcweir                             xRequestType2->hasParameter( aFormatString ) &&
2492cdf0e10cSrcweir                             xRequestType1->getParameterValue( aFormatString ).equalsIgnoreAsciiCase( xRequestType2->getParameterValue( aFormatString ) ) )
2493cdf0e10cSrcweir                         {
2494cdf0e10cSrcweir                             bRet = sal_True;
2495cdf0e10cSrcweir                         }
2496cdf0e10cSrcweir                     }
2497cdf0e10cSrcweir                     else
2498cdf0e10cSrcweir                         bRet = sal_True;
2499cdf0e10cSrcweir 			    }
2500cdf0e10cSrcweir             }
2501cdf0e10cSrcweir 		}
2502cdf0e10cSrcweir     }
2503cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
2504cdf0e10cSrcweir 	{
2505cdf0e10cSrcweir         bRet = rInternalFlavor.MimeType.equalsIgnoreAsciiCase( rRequestFlavor.MimeType );
2506cdf0e10cSrcweir 	}
2507cdf0e10cSrcweir 
2508cdf0e10cSrcweir     return bRet;
2509cdf0e10cSrcweir }
2510