xref: /AOO42X/main/svtools/source/misc/transfer.cxx (revision ad6faf9749cad74c167c20bfc434a305f8fb5e15)
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             }
441*ad6faf97SDamjan Jovanovic             else if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_SVG, aSubstFlavor ) &&
442*ad6faf97SDamjan Jovanovic                      TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) &&
443*ad6faf97SDamjan Jovanovic                      SotExchange::GetFormatDataFlavor( FORMAT_GDIMETAFILE, aSubstFlavor ) )
444*ad6faf97SDamjan Jovanovic             {
445*ad6faf97SDamjan Jovanovic                 GetData( aSubstFlavor );
446*ad6faf97SDamjan Jovanovic 
447*ad6faf97SDamjan Jovanovic                 if( maAny.hasValue() )
448*ad6faf97SDamjan Jovanovic                 {
449*ad6faf97SDamjan Jovanovic                     Sequence< sal_Int8 > aSeq;
450*ad6faf97SDamjan Jovanovic 
451*ad6faf97SDamjan Jovanovic                     if( maAny >>= aSeq )
452*ad6faf97SDamjan Jovanovic                     {
453*ad6faf97SDamjan Jovanovic                         SvMemoryStream* pSrcStm = new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC );
454*ad6faf97SDamjan Jovanovic                         GDIMetaFile     aMtf;
455*ad6faf97SDamjan Jovanovic 
456*ad6faf97SDamjan Jovanovic                         *pSrcStm >> aMtf;
457*ad6faf97SDamjan Jovanovic                         delete pSrcStm;
458*ad6faf97SDamjan Jovanovic 
459*ad6faf97SDamjan Jovanovic                         Graphic         aGraphic( aMtf );
460*ad6faf97SDamjan Jovanovic                         SvMemoryStream  aDstStm( 65535, 65535 );
461*ad6faf97SDamjan Jovanovic 
462*ad6faf97SDamjan Jovanovic                         if( GraphicConverter::Export( aDstStm, aGraphic, CVT_SVG ) == ERRCODE_NONE )
463*ad6faf97SDamjan Jovanovic                         {
464*ad6faf97SDamjan Jovanovic                             maAny <<= ( aSeq = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aDstStm.GetData() ),
465*ad6faf97SDamjan Jovanovic                                                                      aDstStm.Seek( STREAM_SEEK_TO_END ) ) );
466*ad6faf97SDamjan Jovanovic                             bDone = sal_True;
467*ad6faf97SDamjan Jovanovic                         }
468*ad6faf97SDamjan Jovanovic                     }
469*ad6faf97SDamjan Jovanovic                 }
470*ad6faf97SDamjan Jovanovic             }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir             // reset Any if substitute doesn't work
473cdf0e10cSrcweir             if( !bDone && maAny.hasValue() )
474cdf0e10cSrcweir                 maAny = Any();
475cdf0e10cSrcweir 
476cdf0e10cSrcweir             // if any is not yet filled, use standard format
477cdf0e10cSrcweir             if( !maAny.hasValue() )
478cdf0e10cSrcweir                 GetData( rFlavor );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir #ifdef DEBUG
481cdf0e10cSrcweir             if( maAny.hasValue() && ::com::sun::star::uno::TypeClass_STRING != maAny.getValueType().getTypeClass() )
482cdf0e10cSrcweir                 fprintf( stderr, "TransferableHelper delivers sequence of data [ %s ]\n", ByteString( String( rFlavor.MimeType), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
483cdf0e10cSrcweir #endif
484cdf0e10cSrcweir         }
485cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
486cdf0e10cSrcweir         {
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir         if( !maAny.hasValue() )
490cdf0e10cSrcweir             throw UnsupportedFlavorException();
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     return maAny;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir // -----------------------------------------------------------------------------
497cdf0e10cSrcweir 
498cdf0e10cSrcweir Sequence< DataFlavor > SAL_CALL TransferableHelper::getTransferDataFlavors() throw( RuntimeException )
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     const ::vos::OGuard aGuard( Application::GetSolarMutex() );
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     try
503cdf0e10cSrcweir     {
504cdf0e10cSrcweir         if( !mpFormats->size() )
505cdf0e10cSrcweir             AddSupportedFormats();
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
508cdf0e10cSrcweir     {
509cdf0e10cSrcweir     }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir     Sequence< DataFlavor >          aRet( mpFormats->size() );
512cdf0e10cSrcweir     DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
513cdf0e10cSrcweir     sal_uInt32                      nCurPos = 0;
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     while( aIter != aEnd )
516cdf0e10cSrcweir     {
517cdf0e10cSrcweir         aRet[ nCurPos++ ] = *aIter++;
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     return aRet;
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir // -----------------------------------------------------------------------------
524cdf0e10cSrcweir 
525cdf0e10cSrcweir sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& rFlavor ) throw( RuntimeException )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir     const ::vos::OGuard aGuard( Application::GetSolarMutex() );
528cdf0e10cSrcweir     sal_Bool            bRet = sal_False;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir     try
531cdf0e10cSrcweir     {
532cdf0e10cSrcweir         if( !mpFormats->size() )
533cdf0e10cSrcweir             AddSupportedFormats();
534cdf0e10cSrcweir     }
535cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
536cdf0e10cSrcweir     {
537cdf0e10cSrcweir     }
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
540cdf0e10cSrcweir 
541cdf0e10cSrcweir     while( aIter != aEnd )
542cdf0e10cSrcweir     {
543cdf0e10cSrcweir         if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) )
544cdf0e10cSrcweir         {
545cdf0e10cSrcweir             aIter = aEnd;
546cdf0e10cSrcweir             bRet = sal_True;
547cdf0e10cSrcweir         }
548cdf0e10cSrcweir         else
549cdf0e10cSrcweir             aIter++;
550cdf0e10cSrcweir     }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir     return bRet;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir 
555cdf0e10cSrcweir // -----------------------------------------------------------------------------
556cdf0e10cSrcweir 
557cdf0e10cSrcweir void SAL_CALL TransferableHelper::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& ) throw( RuntimeException )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir     const ::vos::OGuard aGuard( Application::GetSolarMutex() );
560cdf0e10cSrcweir 
561cdf0e10cSrcweir     try
562cdf0e10cSrcweir     {
563cdf0e10cSrcweir         if( mxTerminateListener.is() )
564cdf0e10cSrcweir         {
565cdf0e10cSrcweir             Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir             if( xFact.is() )
568cdf0e10cSrcweir             {
569cdf0e10cSrcweir                 Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
570cdf0e10cSrcweir 
571cdf0e10cSrcweir                 if( xDesktop.is() )
572cdf0e10cSrcweir                     xDesktop->removeTerminateListener( mxTerminateListener );
573cdf0e10cSrcweir             }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir             mxTerminateListener = Reference< XTerminateListener >();
576cdf0e10cSrcweir         }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir         ObjectReleased();
579cdf0e10cSrcweir     }
580cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
581cdf0e10cSrcweir     {
582cdf0e10cSrcweir     }
583cdf0e10cSrcweir }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir // -----------------------------------------------------------------------------
586cdf0e10cSrcweir 
587cdf0e10cSrcweir void SAL_CALL TransferableHelper::disposing( const EventObject& ) throw( RuntimeException )
588cdf0e10cSrcweir {
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir // -----------------------------------------------------------------------------
592cdf0e10cSrcweir 
593cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragDropEnd( const DragSourceDropEvent& rDSDE ) throw( RuntimeException )
594cdf0e10cSrcweir {
595cdf0e10cSrcweir     const ::vos::OGuard aGuard( Application::GetSolarMutex() );
596cdf0e10cSrcweir 
597cdf0e10cSrcweir     try
598cdf0e10cSrcweir     {
599cdf0e10cSrcweir         DragFinished( rDSDE.DropSuccess ? ( rDSDE.DropAction & ~DNDConstants::ACTION_DEFAULT ) : DNDConstants::ACTION_NONE );
600cdf0e10cSrcweir         ObjectReleased();
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
603cdf0e10cSrcweir     {
604cdf0e10cSrcweir     }
605cdf0e10cSrcweir }
606cdf0e10cSrcweir 
607cdf0e10cSrcweir // -----------------------------------------------------------------------------
608cdf0e10cSrcweir 
609cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragEnter( const DragSourceDragEvent& ) throw( RuntimeException )
610cdf0e10cSrcweir {
611cdf0e10cSrcweir }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir // -----------------------------------------------------------------------------
614cdf0e10cSrcweir 
615cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragExit( const DragSourceEvent& ) throw( RuntimeException )
616cdf0e10cSrcweir {
617cdf0e10cSrcweir }
618cdf0e10cSrcweir 
619cdf0e10cSrcweir // -----------------------------------------------------------------------------
620cdf0e10cSrcweir 
621cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragOver( const DragSourceDragEvent& ) throw( RuntimeException )
622cdf0e10cSrcweir {
623cdf0e10cSrcweir }
624cdf0e10cSrcweir 
625cdf0e10cSrcweir // -----------------------------------------------------------------------------
626cdf0e10cSrcweir 
627cdf0e10cSrcweir void SAL_CALL TransferableHelper::dropActionChanged( const DragSourceDragEvent& ) throw( RuntimeException )
628cdf0e10cSrcweir {
629cdf0e10cSrcweir }
630cdf0e10cSrcweir 
631cdf0e10cSrcweir // -----------------------------------------------------------------------------
632cdf0e10cSrcweir 
633cdf0e10cSrcweir sal_Int64 SAL_CALL TransferableHelper::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException )
634cdf0e10cSrcweir {
635cdf0e10cSrcweir     sal_Int64 nRet;
636cdf0e10cSrcweir 
637cdf0e10cSrcweir     if( ( rId.getLength() == 16 ) &&
638cdf0e10cSrcweir         ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
639cdf0e10cSrcweir     {
640cdf0e10cSrcweir         nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
641cdf0e10cSrcweir     }
642cdf0e10cSrcweir     else
643cdf0e10cSrcweir         nRet = 0;
644cdf0e10cSrcweir 
645cdf0e10cSrcweir     return nRet;
646cdf0e10cSrcweir }
647cdf0e10cSrcweir 
648cdf0e10cSrcweir // -----------------------------------------------------------------------------
649cdf0e10cSrcweir 
650cdf0e10cSrcweir void TransferableHelper::ImplFlush()
651cdf0e10cSrcweir {
652cdf0e10cSrcweir     if( mxClipboard.is() )
653cdf0e10cSrcweir     {
654cdf0e10cSrcweir         Reference< XFlushableClipboard >    xFlushableClipboard( mxClipboard, UNO_QUERY );
655cdf0e10cSrcweir         const sal_uInt32                    nRef = Application::ReleaseSolarMutex();
656cdf0e10cSrcweir 
657cdf0e10cSrcweir         try
658cdf0e10cSrcweir         {
659cdf0e10cSrcweir             if( xFlushableClipboard.is() )
660cdf0e10cSrcweir                 xFlushableClipboard->flushClipboard();
661cdf0e10cSrcweir         }
662cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
663cdf0e10cSrcweir         {
664cdf0e10cSrcweir             DBG_ERROR( "Could not flush clipboard" );
665cdf0e10cSrcweir         }
666cdf0e10cSrcweir 
667cdf0e10cSrcweir         Application::AcquireSolarMutex( nRef );
668cdf0e10cSrcweir     }
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir // -----------------------------------------------------------------------------
672cdf0e10cSrcweir 
673cdf0e10cSrcweir void TransferableHelper::AddFormat( SotFormatStringId nFormat )
674cdf0e10cSrcweir {
675cdf0e10cSrcweir     DataFlavor aFlavor;
676cdf0e10cSrcweir 
677cdf0e10cSrcweir     if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
678cdf0e10cSrcweir         AddFormat( aFlavor );
679cdf0e10cSrcweir }
680cdf0e10cSrcweir 
681cdf0e10cSrcweir // -----------------------------------------------------------------------------
682cdf0e10cSrcweir 
683cdf0e10cSrcweir void TransferableHelper::AddFormat( const DataFlavor& rFlavor )
684cdf0e10cSrcweir {
685cdf0e10cSrcweir     DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
686cdf0e10cSrcweir     sal_Bool                        bAdd = sal_True;
687cdf0e10cSrcweir 
688cdf0e10cSrcweir     while( aIter != aEnd )
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir         if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) )
691cdf0e10cSrcweir         {
692cdf0e10cSrcweir             // update MimeType for SOT_FORMATSTR_ID_OBJECTDESCRIPTOR in every case
693cdf0e10cSrcweir             if( ( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aIter->mnSotId ) && mpObjDesc )
694cdf0e10cSrcweir             {
695cdf0e10cSrcweir                 DataFlavor aObjDescFlavor;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir                 SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDescFlavor );
698cdf0e10cSrcweir                 aIter->MimeType = aObjDescFlavor.MimeType;
699cdf0e10cSrcweir                 aIter->MimeType += ::ImplGetParameterString( *mpObjDesc );
700cdf0e10cSrcweir 
701cdf0e10cSrcweir #ifdef DEBUG
702cdf0e10cSrcweir                 fprintf( stderr, "TransferableHelper exchanged objectdescriptor [ %s ]\n",
703cdf0e10cSrcweir                          ByteString( String( aIter->MimeType), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
704cdf0e10cSrcweir #endif
705cdf0e10cSrcweir             }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir             aIter = aEnd;
708cdf0e10cSrcweir             bAdd = sal_False;
709cdf0e10cSrcweir         }
710cdf0e10cSrcweir         else
711cdf0e10cSrcweir             aIter++;
712cdf0e10cSrcweir     }
713cdf0e10cSrcweir 
714cdf0e10cSrcweir     if( bAdd )
715cdf0e10cSrcweir     {
716cdf0e10cSrcweir         DataFlavorEx   aFlavorEx;
717cdf0e10cSrcweir         DataFlavor     aObjDescFlavor;
718cdf0e10cSrcweir 
719cdf0e10cSrcweir         aFlavorEx.MimeType = rFlavor.MimeType;
720cdf0e10cSrcweir         aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName;
721cdf0e10cSrcweir         aFlavorEx.DataType = rFlavor.DataType;
722cdf0e10cSrcweir         aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir         if( ( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aFlavorEx.mnSotId ) && mpObjDesc )
725cdf0e10cSrcweir             aFlavorEx.MimeType += ::ImplGetParameterString( *mpObjDesc );
726cdf0e10cSrcweir 
727cdf0e10cSrcweir         mpFormats->push_back( aFlavorEx );
728cdf0e10cSrcweir 
729cdf0e10cSrcweir         if( FORMAT_BITMAP == aFlavorEx.mnSotId )
730cdf0e10cSrcweir         {
73145fd3b9aSArmin Le Grand             AddFormat( SOT_FORMATSTR_ID_PNG );
732a206ee71SArmin Le Grand             AddFormat( SOT_FORMATSTR_ID_BMP );
733cdf0e10cSrcweir         }
734cdf0e10cSrcweir         else if( FORMAT_GDIMETAFILE == aFlavorEx.mnSotId )
735cdf0e10cSrcweir         {
736cdf0e10cSrcweir             AddFormat( SOT_FORMATSTR_ID_EMF );
737cdf0e10cSrcweir             AddFormat( SOT_FORMATSTR_ID_WMF );
738*ad6faf97SDamjan Jovanovic             AddFormat( SOT_FORMATSTR_ID_SVG );
739cdf0e10cSrcweir         }
740cdf0e10cSrcweir     }
741cdf0e10cSrcweir }
742cdf0e10cSrcweir 
743cdf0e10cSrcweir // -----------------------------------------------------------------------------
744cdf0e10cSrcweir 
745cdf0e10cSrcweir void TransferableHelper::RemoveFormat( SotFormatStringId nFormat )
746cdf0e10cSrcweir {
747cdf0e10cSrcweir     DataFlavor aFlavor;
748cdf0e10cSrcweir 
749cdf0e10cSrcweir     if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
750cdf0e10cSrcweir         RemoveFormat( aFlavor );
751cdf0e10cSrcweir }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir // -----------------------------------------------------------------------------
754cdf0e10cSrcweir 
755cdf0e10cSrcweir void TransferableHelper::RemoveFormat( const DataFlavor& rFlavor )
756cdf0e10cSrcweir {
757cdf0e10cSrcweir     DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
758cdf0e10cSrcweir 
759cdf0e10cSrcweir     while( aIter != aEnd )
760cdf0e10cSrcweir     {
761cdf0e10cSrcweir         if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) )
762cdf0e10cSrcweir         {
763cdf0e10cSrcweir             aIter = mpFormats->erase( aIter );
764cdf0e10cSrcweir             aEnd = mpFormats->end();
765cdf0e10cSrcweir         }
766cdf0e10cSrcweir         else
767cdf0e10cSrcweir             ++aIter;
768cdf0e10cSrcweir     }
769cdf0e10cSrcweir }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir // -----------------------------------------------------------------------------
772cdf0e10cSrcweir 
773cdf0e10cSrcweir sal_Bool TransferableHelper::HasFormat( SotFormatStringId nFormat )
774cdf0e10cSrcweir {
775cdf0e10cSrcweir     DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
776cdf0e10cSrcweir     sal_Bool                        bRet = sal_False;
777cdf0e10cSrcweir 
778cdf0e10cSrcweir     while( aIter != aEnd )
779cdf0e10cSrcweir     {
780cdf0e10cSrcweir         if( nFormat == (*aIter).mnSotId )
781cdf0e10cSrcweir         {
782cdf0e10cSrcweir             aIter = aEnd;
783cdf0e10cSrcweir             bRet = sal_True;
784cdf0e10cSrcweir         }
785cdf0e10cSrcweir         else
786cdf0e10cSrcweir             ++aIter;
787cdf0e10cSrcweir     }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir     return bRet;
790cdf0e10cSrcweir }
791cdf0e10cSrcweir 
792cdf0e10cSrcweir // -----------------------------------------------------------------------------
793cdf0e10cSrcweir 
794cdf0e10cSrcweir void TransferableHelper::ClearFormats()
795cdf0e10cSrcweir {
796cdf0e10cSrcweir     mpFormats->clear();
797cdf0e10cSrcweir     maAny.clear();
798cdf0e10cSrcweir }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir // -----------------------------------------------------------------------------
801cdf0e10cSrcweir 
802cdf0e10cSrcweir sal_Bool TransferableHelper::SetAny( const Any& rAny, const DataFlavor& )
803cdf0e10cSrcweir {
804cdf0e10cSrcweir     maAny = rAny;
805cdf0e10cSrcweir     return( maAny.hasValue() );
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir // -----------------------------------------------------------------------------
809cdf0e10cSrcweir 
810cdf0e10cSrcweir sal_Bool TransferableHelper::SetString( const ::rtl::OUString& rString, const DataFlavor& rFlavor )
811cdf0e10cSrcweir {
812cdf0e10cSrcweir     DataFlavor aFileFlavor;
813cdf0e10cSrcweir 
814cdf0e10cSrcweir     if( rString.getLength() &&
815cdf0e10cSrcweir         SotExchange::GetFormatDataFlavor( FORMAT_FILE, aFileFlavor ) &&
816cdf0e10cSrcweir         TransferableDataHelper::IsEqual( aFileFlavor, rFlavor ) )
817cdf0e10cSrcweir     {
818cdf0e10cSrcweir         const String            aString( rString );
819cdf0e10cSrcweir         const ByteString        aByteStr( aString, gsl_getSystemTextEncoding() );
820cdf0e10cSrcweir         Sequence< sal_Int8 >    aSeq( aByteStr.Len() + 1 );
821cdf0e10cSrcweir 
822cdf0e10cSrcweir         rtl_copyMemory( aSeq.getArray(), aByteStr.GetBuffer(), aByteStr.Len() );
823cdf0e10cSrcweir         aSeq[ aByteStr.Len() ] = 0;
824cdf0e10cSrcweir         maAny <<= aSeq;
825cdf0e10cSrcweir     }
826cdf0e10cSrcweir     else
827cdf0e10cSrcweir         maAny <<= rString;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir     return( maAny.hasValue() );
830cdf0e10cSrcweir }
831cdf0e10cSrcweir 
832cdf0e10cSrcweir // -----------------------------------------------------------------------------
833cdf0e10cSrcweir 
83445fd3b9aSArmin Le Grand sal_Bool TransferableHelper::SetBitmapEx( const BitmapEx& rBitmapEx, const DataFlavor& rFlavor )
835cdf0e10cSrcweir {
83645fd3b9aSArmin Le Grand     if( !rBitmapEx.IsEmpty() )
837cdf0e10cSrcweir     {
838cdf0e10cSrcweir         SvMemoryStream aMemStm( 65535, 65535 );
839cdf0e10cSrcweir 
84045fd3b9aSArmin Le Grand         if(rFlavor.MimeType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("image/png")))
84145fd3b9aSArmin Le Grand         {
84245fd3b9aSArmin Le Grand             // write a PNG
84345fd3b9aSArmin Le Grand             ::vcl::PNGWriter aPNGWriter(rBitmapEx);
84445fd3b9aSArmin Le Grand 
84545fd3b9aSArmin Le Grand             aPNGWriter.Write(aMemStm);
84645fd3b9aSArmin Le Grand         }
84745fd3b9aSArmin Le Grand         else
84845fd3b9aSArmin Le Grand         {
84945fd3b9aSArmin Le Grand             const Bitmap aBitmap(rBitmapEx.GetBitmap());
85045fd3b9aSArmin Le Grand 
851a206ee71SArmin Le Grand             // #124085# take out DIBV5 for writing to the clipboard
852a206ee71SArmin Le Grand             //if(rBitmapEx.IsTransparent())
853a206ee71SArmin Le Grand             //{
854a206ee71SArmin Le Grand             //    const Bitmap aMask(rBitmapEx.GetAlpha().GetBitmap());
855a206ee71SArmin Le Grand             //
8566d53c851Smseidel             //    // explicitly use Bitmap::Write with bCompressed = sal_False and bFileHeader = sal_True
857a206ee71SArmin Le Grand             //    WriteDIBV5(aBitmap, aMask, aMemStm);
858a206ee71SArmin Le Grand             //}
859a206ee71SArmin Le Grand             //else
860a206ee71SArmin Le Grand             //{
8616d53c851Smseidel                 // explicitly use Bitmap::Write with bCompressed = sal_False and bFileHeader = sal_True
86245fd3b9aSArmin Le Grand                 WriteDIB(aBitmap, aMemStm, false, true);
863a206ee71SArmin Le Grand             //}
86445fd3b9aSArmin Le Grand         }
86545fd3b9aSArmin Le Grand 
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::SetGDIMetaFile( const GDIMetaFile& rMtf, const DataFlavor& )
875cdf0e10cSrcweir {
876cdf0e10cSrcweir     if( rMtf.GetActionCount() )
877cdf0e10cSrcweir     {
878cdf0e10cSrcweir         SvMemoryStream aMemStm( 65535, 65535 );
879cdf0e10cSrcweir 
880cdf0e10cSrcweir         ( (GDIMetaFile&) rMtf ).Write( aMemStm );
881cdf0e10cSrcweir         maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
882cdf0e10cSrcweir     }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir     return( maAny.hasValue() );
885cdf0e10cSrcweir }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir // -----------------------------------------------------------------------------
888cdf0e10cSrcweir 
889cdf0e10cSrcweir sal_Bool TransferableHelper::SetGraphic( const Graphic& rGraphic, const DataFlavor& )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir     if( rGraphic.GetType() != GRAPHIC_NONE )
892cdf0e10cSrcweir     {
893cdf0e10cSrcweir         SvMemoryStream aMemStm( 65535, 65535 );
894cdf0e10cSrcweir 
895cdf0e10cSrcweir         aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
896cdf0e10cSrcweir         aMemStm.SetCompressMode( COMPRESSMODE_NATIVE );
897cdf0e10cSrcweir         aMemStm << rGraphic;
898cdf0e10cSrcweir         maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
899cdf0e10cSrcweir     }
900cdf0e10cSrcweir 
901cdf0e10cSrcweir     return( maAny.hasValue() );
902cdf0e10cSrcweir }
903cdf0e10cSrcweir 
904cdf0e10cSrcweir // -----------------------------------------------------------------------------
905cdf0e10cSrcweir 
906cdf0e10cSrcweir sal_Bool TransferableHelper::SetImageMap( const ImageMap& rIMap, const ::com::sun::star::datatransfer::DataFlavor& )
907cdf0e10cSrcweir {
908cdf0e10cSrcweir     SvMemoryStream aMemStm( 8192, 8192 );
909cdf0e10cSrcweir 
910cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
911cdf0e10cSrcweir     rIMap.Write( aMemStm, String() );
912cdf0e10cSrcweir     maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
913cdf0e10cSrcweir 
914cdf0e10cSrcweir     return( maAny.hasValue() );
915cdf0e10cSrcweir }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir // -----------------------------------------------------------------------------
918cdf0e10cSrcweir 
919cdf0e10cSrcweir sal_Bool TransferableHelper::SetTransferableObjectDescriptor( const TransferableObjectDescriptor& rDesc,
920cdf0e10cSrcweir                                                               const ::com::sun::star::datatransfer::DataFlavor& )
921cdf0e10cSrcweir {
922cdf0e10cSrcweir     PrepareOLE( rDesc );
923cdf0e10cSrcweir 
924cdf0e10cSrcweir     SvMemoryStream aMemStm( 1024, 1024 );
925cdf0e10cSrcweir 
926cdf0e10cSrcweir     aMemStm << rDesc;
927cdf0e10cSrcweir     maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
928cdf0e10cSrcweir 
929cdf0e10cSrcweir     return( maAny.hasValue() );
930cdf0e10cSrcweir  }
931cdf0e10cSrcweir 
932cdf0e10cSrcweir // -----------------------------------------------------------------------------
933cdf0e10cSrcweir 
934cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetBookmark( const INetBookmark& rBmk,
935cdf0e10cSrcweir                                               const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
936cdf0e10cSrcweir {
937cdf0e10cSrcweir     rtl_TextEncoding eSysCSet = gsl_getSystemTextEncoding();
938cdf0e10cSrcweir 
939cdf0e10cSrcweir     switch( SotExchange::GetFormat( rFlavor ) )
940cdf0e10cSrcweir     {
941cdf0e10cSrcweir         case( SOT_FORMATSTR_ID_SOLK ):
942cdf0e10cSrcweir         {
943cdf0e10cSrcweir             ByteString sURL( rBmk.GetURL(), eSysCSet ),
944cdf0e10cSrcweir                        sDesc( rBmk.GetDescription(), eSysCSet );
945cdf0e10cSrcweir             ByteString sOut( ByteString::CreateFromInt32( sURL.Len() ));
946cdf0e10cSrcweir             ( sOut += '@' ) += sURL;
947cdf0e10cSrcweir             sOut += ByteString::CreateFromInt32( sDesc.Len() );
948cdf0e10cSrcweir             ( sOut += '@' ) += sDesc;
949cdf0e10cSrcweir 
950cdf0e10cSrcweir             Sequence< sal_Int8 > aSeq( sOut.Len() );
951cdf0e10cSrcweir             memcpy( aSeq.getArray(), sOut.GetBuffer(), sOut.Len() );
952cdf0e10cSrcweir             maAny <<= aSeq;
953cdf0e10cSrcweir         }
954cdf0e10cSrcweir         break;
955cdf0e10cSrcweir 
956cdf0e10cSrcweir         case( FORMAT_STRING ):
957cdf0e10cSrcweir             maAny <<= ::rtl::OUString( rBmk.GetURL() );
958cdf0e10cSrcweir             break;
959cdf0e10cSrcweir 
960cdf0e10cSrcweir         case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ):
961cdf0e10cSrcweir         {
962cdf0e10cSrcweir             ByteString sURL( rBmk.GetURL(), eSysCSet );
963cdf0e10cSrcweir             Sequence< sal_Int8 > aSeq( sURL.Len() );
964cdf0e10cSrcweir             memcpy( aSeq.getArray(), sURL.GetBuffer(), sURL.Len() );
965cdf0e10cSrcweir             maAny <<= aSeq;
966cdf0e10cSrcweir         }
967cdf0e10cSrcweir         break;
968cdf0e10cSrcweir 
969cdf0e10cSrcweir         case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ):
970cdf0e10cSrcweir         {
971cdf0e10cSrcweir             Sequence< sal_Int8 > aSeq( 2048 );
972cdf0e10cSrcweir 
973cdf0e10cSrcweir             memset( aSeq.getArray(), 0, 2048 );
974cdf0e10cSrcweir             strcpy( reinterpret_cast< char* >( aSeq.getArray() ), ByteString( rBmk.GetURL(), eSysCSet).GetBuffer() );
975cdf0e10cSrcweir             strcpy( reinterpret_cast< char* >( aSeq.getArray() ) + 1024, ByteString( rBmk.GetDescription(), eSysCSet ).GetBuffer() );
976cdf0e10cSrcweir 
977cdf0e10cSrcweir             maAny <<= aSeq;
978cdf0e10cSrcweir         }
979cdf0e10cSrcweir         break;
980cdf0e10cSrcweir 
981cdf0e10cSrcweir #ifdef WNT
982cdf0e10cSrcweir         case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
983cdf0e10cSrcweir         {
984cdf0e10cSrcweir             Sequence< sal_Int8 >    aSeq( sizeof( FILEGROUPDESCRIPTOR ) );
985cdf0e10cSrcweir             FILEGROUPDESCRIPTOR*    pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getArray();
986cdf0e10cSrcweir             FILEDESCRIPTOR&         rFDesc1 = pFDesc->fgd[ 0 ];
987cdf0e10cSrcweir 
988cdf0e10cSrcweir             pFDesc->cItems = 1;
989cdf0e10cSrcweir             memset( &rFDesc1, 0, sizeof( FILEDESCRIPTOR ) );
990cdf0e10cSrcweir             rFDesc1.dwFlags = FD_LINKUI;
991cdf0e10cSrcweir 
992cdf0e10cSrcweir             ByteString aStr( rBmk.GetDescription(), eSysCSet );
993cdf0e10cSrcweir             for( sal_uInt16 nChar = 0; nChar < aStr.Len(); ++nChar )
994cdf0e10cSrcweir                 if( strchr( "\\/:*?\"<>|", aStr.GetChar( nChar ) ) )
995cdf0e10cSrcweir                     aStr.Erase( nChar--, 1 );
996cdf0e10cSrcweir 
997cdf0e10cSrcweir             aStr.Insert( "Shortcut to ", 0 );
998cdf0e10cSrcweir             aStr += ".URL";
999cdf0e10cSrcweir             strcpy( rFDesc1.cFileName, aStr.GetBuffer() );
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir             maAny <<= aSeq;
1002cdf0e10cSrcweir         }
1003cdf0e10cSrcweir         break;
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir         case SOT_FORMATSTR_ID_FILECONTENT:
1006cdf0e10cSrcweir         {
1007cdf0e10cSrcweir             String aStr( RTL_CONSTASCII_STRINGPARAM( "[InternetShortcut]\x0aURL=" ) );
1008cdf0e10cSrcweir             maAny <<= ::rtl::OUString( aStr += rBmk.GetURL() );
1009cdf0e10cSrcweir         }
1010cdf0e10cSrcweir         break;
1011cdf0e10cSrcweir #endif
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir         default:
1014cdf0e10cSrcweir         break;
1015cdf0e10cSrcweir     }
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir     return( maAny.hasValue() );
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir // -----------------------------------------------------------------------------
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetImage( const INetImage& rINtImg,
1023cdf0e10cSrcweir                                            const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir     SvMemoryStream aMemStm( 1024, 1024 );
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
1028cdf0e10cSrcweir     rINtImg.Write( aMemStm, SotExchange::GetFormat( rFlavor ) );
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir     maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) );
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir     return( maAny.hasValue() );
1033cdf0e10cSrcweir }
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir // -----------------------------------------------------------------------------
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir sal_Bool TransferableHelper::SetFileList( const FileList& rFileList,
1038cdf0e10cSrcweir                                           const ::com::sun::star::datatransfer::DataFlavor& )
1039cdf0e10cSrcweir {
1040cdf0e10cSrcweir     SvMemoryStream aMemStm( 4096, 4096 );
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir     aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
1043cdf0e10cSrcweir     aMemStm << rFileList;
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir     maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ),
1046cdf0e10cSrcweir                                        aMemStm.Seek( STREAM_SEEK_TO_END ) );
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir     return( maAny.hasValue() );
1049cdf0e10cSrcweir }
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir // -----------------------------------------------------------------------------
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir sal_Bool TransferableHelper::SetObject( void* pUserObject, sal_uInt32 nUserObjectId, const DataFlavor& rFlavor )
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir     SotStorageStreamRef xStm( new SotStorageStream( String() ) );
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir     xStm->SetVersion( SOFFICE_FILEFORMAT_50 );
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir     if( pUserObject && WriteObject( xStm, pUserObject, nUserObjectId, rFlavor ) )
1060cdf0e10cSrcweir     {
1061cdf0e10cSrcweir         const sal_uInt32        nLen = xStm->Seek( STREAM_SEEK_TO_END );
1062cdf0e10cSrcweir         Sequence< sal_Int8 >    aSeq( nLen );
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir         xStm->Seek( STREAM_SEEK_TO_BEGIN );
1065cdf0e10cSrcweir         xStm->Read( aSeq.getArray(),  nLen );
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir         if( nLen && ( SotExchange::GetFormat( rFlavor ) == SOT_FORMAT_STRING ) )
1068cdf0e10cSrcweir         {
1069cdf0e10cSrcweir             //JP 24.7.2001: as I know was this only for the writer application and this
1070cdf0e10cSrcweir             //              writes now UTF16 format into the stream
1071cdf0e10cSrcweir             //JP 6.8.2001:  and now it writes UTF8 because then exist no problem with
1072cdf0e10cSrcweir             //              little / big endians! - Bug 88121
1073cdf0e10cSrcweir             maAny <<= ::rtl::OUString( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), nLen - 1, RTL_TEXTENCODING_UTF8 );
1074cdf0e10cSrcweir         }
1075cdf0e10cSrcweir         else
1076cdf0e10cSrcweir             maAny <<= aSeq;
1077cdf0e10cSrcweir     }
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir     return( maAny.hasValue() );
1080cdf0e10cSrcweir }
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir // -----------------------------------------------------------------------------
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir sal_Bool TransferableHelper::SetInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rIf,
1085cdf0e10cSrcweir                                            const ::com::sun::star::datatransfer::DataFlavor& )
1086cdf0e10cSrcweir {
1087cdf0e10cSrcweir     maAny <<= rIf;
1088cdf0e10cSrcweir     return( maAny.hasValue() );
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir // -----------------------------------------------------------------------------
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir sal_Bool TransferableHelper::WriteObject( SotStorageStreamRef&, void*, sal_uInt32, const DataFlavor& )
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir     DBG_ERROR( "TransferableHelper::WriteObject( ... ) not implemented" );
1096cdf0e10cSrcweir     return sal_False;
1097cdf0e10cSrcweir }
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir // -----------------------------------------------------------------------------
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir void TransferableHelper::DragFinished( sal_Int8 )
1102cdf0e10cSrcweir {
1103cdf0e10cSrcweir }
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir // -----------------------------------------------------------------------------
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir void TransferableHelper::ObjectReleased()
1108cdf0e10cSrcweir {
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir // -----------------------------------------------------------------------------
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir void TransferableHelper::PrepareOLE( const TransferableObjectDescriptor& rObjDesc )
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir     delete mpObjDesc;
1116cdf0e10cSrcweir     mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir     if( HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
1119cdf0e10cSrcweir         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
1120cdf0e10cSrcweir }
1121cdf0e10cSrcweir 
1122cdf0e10cSrcweir // -----------------------------------------------------------------------------
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir void TransferableHelper::CopyToClipboard( Window *pWindow ) const
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir     DBG_ASSERT( pWindow, "Window pointer is NULL" );
1127cdf0e10cSrcweir     Reference< XClipboard > xClipboard;
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir     if( pWindow )
1130cdf0e10cSrcweir         xClipboard = pWindow->GetClipboard();
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir     if( xClipboard.is() )
1133cdf0e10cSrcweir         mxClipboard = xClipboard;
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir     if( mxClipboard.is() && !mxTerminateListener.is() )
1136cdf0e10cSrcweir     {
1137cdf0e10cSrcweir         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir         try
1140cdf0e10cSrcweir         {
1141cdf0e10cSrcweir             TransferableHelper*                 pThis = const_cast< TransferableHelper* >( this );
1142cdf0e10cSrcweir             Reference< XMultiServiceFactory >   xFact( ::comphelper::getProcessServiceFactory() );
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir             if( xFact.is() )
1145cdf0e10cSrcweir             {
1146cdf0e10cSrcweir                 Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir                 if( xDesktop.is() )
1149cdf0e10cSrcweir                     xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) );
1150cdf0e10cSrcweir             }
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir             mxClipboard->setContents( pThis, pThis );
1153cdf0e10cSrcweir         }
1154cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
1155cdf0e10cSrcweir         {
1156cdf0e10cSrcweir         }
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir         Application::AcquireSolarMutex( nRef );
1159cdf0e10cSrcweir     }
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir // -----------------------------------------------------------------------------
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir void TransferableHelper::CopyToSelection( Window *pWindow ) const
1165cdf0e10cSrcweir {
1166cdf0e10cSrcweir     DBG_ASSERT( pWindow, "Window pointer is NULL" );
1167cdf0e10cSrcweir     Reference< XClipboard > xSelection;
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir     if( pWindow )
1170cdf0e10cSrcweir         xSelection = pWindow->GetPrimarySelection();
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir     if( xSelection.is() && !mxTerminateListener.is() )
1173cdf0e10cSrcweir     {
1174cdf0e10cSrcweir         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir         try
1177cdf0e10cSrcweir         {
1178cdf0e10cSrcweir             TransferableHelper*                 pThis = const_cast< TransferableHelper* >( this );
1179cdf0e10cSrcweir             Reference< XMultiServiceFactory >   xFact( ::comphelper::getProcessServiceFactory() );
1180cdf0e10cSrcweir 
1181cdf0e10cSrcweir             if( xFact.is() )
1182cdf0e10cSrcweir             {
1183cdf0e10cSrcweir                 Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir                 if( xDesktop.is() )
1186cdf0e10cSrcweir                     xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) );
1187cdf0e10cSrcweir             }
1188cdf0e10cSrcweir 
1189cdf0e10cSrcweir             xSelection->setContents( pThis, pThis );
1190cdf0e10cSrcweir         }
1191cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
1192cdf0e10cSrcweir         {
1193cdf0e10cSrcweir         }
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir         Application::AcquireSolarMutex( nRef );
1196cdf0e10cSrcweir     }
1197cdf0e10cSrcweir }
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir // -----------------------------------------------------------------------------
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir void TransferableHelper::StartDrag( Window* pWindow, sal_Int8 nDnDSourceActions,
1202cdf0e10cSrcweir                                     sal_Int32 nDnDPointer, sal_Int32 nDnDImage )
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir {
1205cdf0e10cSrcweir     DBG_ASSERT( pWindow, "Window pointer is NULL" );
1206cdf0e10cSrcweir     Reference< XDragSource > xDragSource( pWindow->GetDragSource() );
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir     if( xDragSource.is() )
1209cdf0e10cSrcweir     {
1210cdf0e10cSrcweir         /*
1211cdf0e10cSrcweir          *    #96792# release mouse before actually starting DnD.
1212cdf0e10cSrcweir          *    This is necessary for the X11 DnD implementation to work.
1213cdf0e10cSrcweir          */
1214cdf0e10cSrcweir         if( pWindow->IsMouseCaptured() )
1215cdf0e10cSrcweir             pWindow->ReleaseMouse();
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir         const Point aPt( pWindow->GetPointerPosPixel() );
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir         // On Mac OS X we are forced to execute 'startDrag' synchronously
1220cdf0e10cSrcweir         // contrary to the XDragSource interface specification because
1221cdf0e10cSrcweir         // we can receive drag events from the system only in the main
1222cdf0e10cSrcweir         // thread
1223cdf0e10cSrcweir #if !defined(QUARTZ)
1224cdf0e10cSrcweir         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1225cdf0e10cSrcweir #endif
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir         try
1228cdf0e10cSrcweir         {
1229cdf0e10cSrcweir             DragGestureEvent    aEvt;
1230cdf0e10cSrcweir             aEvt.DragAction = DNDConstants::ACTION_COPY;
1231cdf0e10cSrcweir             aEvt.DragOriginX = aPt.X();
1232cdf0e10cSrcweir             aEvt.DragOriginY = aPt.Y();
1233cdf0e10cSrcweir             aEvt.DragSource = xDragSource;
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir             xDragSource->startDrag( aEvt, nDnDSourceActions, nDnDPointer, nDnDImage, this, this );
1236cdf0e10cSrcweir         }
1237cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
1238cdf0e10cSrcweir         {
1239cdf0e10cSrcweir         }
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir         // See above for the reason of this define
1242cdf0e10cSrcweir #if !defined(QUARTZ)
1243cdf0e10cSrcweir         Application::AcquireSolarMutex( nRef );
1244cdf0e10cSrcweir #endif
1245cdf0e10cSrcweir     }
1246cdf0e10cSrcweir }
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir // -----------------------------------------------------------------------------
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir void TransferableHelper::ClearSelection( Window *pWindow )
1251cdf0e10cSrcweir {
1252cdf0e10cSrcweir     DBG_ASSERT( pWindow, "Window pointer is NULL" );
1253cdf0e10cSrcweir     Reference< XClipboard > xSelection( pWindow->GetPrimarySelection() );
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir     if( xSelection.is() )
1256cdf0e10cSrcweir         xSelection->setContents( NULL, NULL );
1257cdf0e10cSrcweir }
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir // -----------------------------------------------------------------------------
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir Reference< XClipboard> TransferableHelper::GetSystemClipboard()
1262cdf0e10cSrcweir {
1263cdf0e10cSrcweir     Window *pFocusWindow = Application::GetFocusWindow();
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir     if( pFocusWindow )
1266cdf0e10cSrcweir         return pFocusWindow->GetClipboard();
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir     return  Reference< XClipboard > ();
1269cdf0e10cSrcweir }
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir // -----------------------------------------------------------------------------
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir const Sequence< sal_Int8 >& TransferableHelper::getUnoTunnelId()
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir     static Sequence< sal_Int8 > aSeq;
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir     if( !aSeq.getLength() )
1278cdf0e10cSrcweir     {
1279cdf0e10cSrcweir         static osl::Mutex           aCreateMutex;
1280cdf0e10cSrcweir         osl::Guard< osl::Mutex >    aGuard( aCreateMutex );
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir         aSeq.realloc( 16 );
1283cdf0e10cSrcweir         rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
1284cdf0e10cSrcweir     }
1285cdf0e10cSrcweir 
1286cdf0e10cSrcweir 
1287cdf0e10cSrcweir     return aSeq;
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir // ---------------------------------
1291cdf0e10cSrcweir // - TransferableClipboardNotifier -
1292cdf0e10cSrcweir // ---------------------------------
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir class TransferableClipboardNotifier : public ::cppu::WeakImplHelper1< XClipboardListener >
1295cdf0e10cSrcweir {
1296cdf0e10cSrcweir private:
1297cdf0e10cSrcweir     ::osl::Mutex&                   mrMutex;
1298cdf0e10cSrcweir     Reference< XClipboardNotifier > mxNotifier;
1299cdf0e10cSrcweir     TransferableDataHelper*         mpListener;
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir protected:
1302cdf0e10cSrcweir     // XClipboardListener
1303cdf0e10cSrcweir     virtual void SAL_CALL changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException);
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir     // XEventListener
1306cdf0e10cSrcweir     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir public:
1309cdf0e10cSrcweir     TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex );
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir     /// determines whether we're currently listening
1312cdf0e10cSrcweir     inline bool isListening() const { return !isDisposed(); }
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir     /// determines whether the instance is disposed
1315cdf0e10cSrcweir     inline bool isDisposed() const { return mpListener == NULL; }
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir     /// makes the instance non-functional
1318cdf0e10cSrcweir     void    dispose();
1319cdf0e10cSrcweir };
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir // -----------------------------------------------------------------------------
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir TransferableClipboardNotifier::TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex )
1324cdf0e10cSrcweir     :mrMutex( _rMutex )
1325cdf0e10cSrcweir     ,mxNotifier( _rxClipboard, UNO_QUERY )
1326cdf0e10cSrcweir     ,mpListener( &_rListener )
1327cdf0e10cSrcweir {
1328cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
1329cdf0e10cSrcweir     {
1330cdf0e10cSrcweir         if ( mxNotifier.is() )
1331cdf0e10cSrcweir             mxNotifier->addClipboardListener( this );
1332cdf0e10cSrcweir         else
1333cdf0e10cSrcweir             // born dead
1334cdf0e10cSrcweir             mpListener = NULL;
1335cdf0e10cSrcweir     }
1336cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
1337cdf0e10cSrcweir }
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir // -----------------------------------------------------------------------------
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException)
1342cdf0e10cSrcweir {
1343cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1344cdf0e10cSrcweir         // the SolarMutex here is necessary, since
1345cdf0e10cSrcweir         // - we cannot call mpListener without our own mutex locked
1346cdf0e10cSrcweir         // - Rebind respectively InitFormats (called by Rebind) will
1347cdf0e10cSrcweir         // try to lock the SolarMutex, too
1348cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mrMutex );
1349cdf0e10cSrcweir     if( mpListener )
1350cdf0e10cSrcweir         mpListener->Rebind( event.Contents );
1351cdf0e10cSrcweir }
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir // -----------------------------------------------------------------------------
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::disposing( const EventObject& ) throw (RuntimeException)
1356cdf0e10cSrcweir {
1357cdf0e10cSrcweir     // clipboard is being disposed. Hmm. Okay, become disfunctional myself.
1358cdf0e10cSrcweir     dispose();
1359cdf0e10cSrcweir }
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir // -----------------------------------------------------------------------------
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir void TransferableClipboardNotifier::dispose()
1364cdf0e10cSrcweir {
1365cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mrMutex );
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir     Reference< XClipboardListener > xKeepMeAlive( this );
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir     if ( mxNotifier.is() )
1370cdf0e10cSrcweir         mxNotifier->removeClipboardListener( this );
1371cdf0e10cSrcweir     mxNotifier.clear();
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir     mpListener = NULL;
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir // -------------------------------
1377cdf0e10cSrcweir // - TransferableDataHelper_Impl -
1378cdf0e10cSrcweir // -------------------------------
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir struct TransferableDataHelper_Impl
1381cdf0e10cSrcweir {
1382cdf0e10cSrcweir     ::osl::Mutex                    maMutex;
1383cdf0e10cSrcweir     TransferableClipboardNotifier*  mpClipboardListener;
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir     TransferableDataHelper_Impl()
1386cdf0e10cSrcweir         :mpClipboardListener( NULL )
1387cdf0e10cSrcweir     {
1388cdf0e10cSrcweir     }
1389cdf0e10cSrcweir };
1390cdf0e10cSrcweir 
1391cdf0e10cSrcweir // --------------------------
1392cdf0e10cSrcweir // - TransferableDataHelper -
1393cdf0e10cSrcweir // --------------------------
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper() :
1396cdf0e10cSrcweir     mpFormats( new DataFlavorExVector ),
1397cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor ),
1398cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1399cdf0e10cSrcweir {
1400cdf0e10cSrcweir }
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir // -----------------------------------------------------------------------------
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const Reference< ::com::sun::star::datatransfer::XTransferable >& rxTransferable ) :
1405cdf0e10cSrcweir     mxTransfer( rxTransferable ),
1406cdf0e10cSrcweir     mpFormats( new DataFlavorExVector ),
1407cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor ),
1408cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir     InitFormats();
1411cdf0e10cSrcweir }
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir // -----------------------------------------------------------------------------
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const TransferableDataHelper& rDataHelper ) :
1416cdf0e10cSrcweir     mxTransfer( rDataHelper.mxTransfer ),
1417cdf0e10cSrcweir     mxClipboard( rDataHelper.mxClipboard ),
1418cdf0e10cSrcweir     mpFormats( new DataFlavorExVector( *rDataHelper.mpFormats ) ),
1419cdf0e10cSrcweir     mpObjDesc( new TransferableObjectDescriptor( *rDataHelper.mpObjDesc ) ),
1420cdf0e10cSrcweir     mpImpl( new TransferableDataHelper_Impl )
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir }
1423cdf0e10cSrcweir 
1424cdf0e10cSrcweir // -----------------------------------------------------------------------------
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir TransferableDataHelper& TransferableDataHelper::operator=( const TransferableDataHelper& rDataHelper )
1427cdf0e10cSrcweir {
1428cdf0e10cSrcweir     if ( this != &rDataHelper )
1429cdf0e10cSrcweir     {
1430cdf0e10cSrcweir         ::osl::MutexGuard aGuard( mpImpl->maMutex );
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir         bool bWasClipboardListening = ( NULL != mpImpl->mpClipboardListener );
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir         if ( bWasClipboardListening )
1435cdf0e10cSrcweir             StopClipboardListening();
1436cdf0e10cSrcweir 
1437cdf0e10cSrcweir         mxTransfer = rDataHelper.mxTransfer;
1438cdf0e10cSrcweir         delete mpFormats, mpFormats = new DataFlavorExVector( *rDataHelper.mpFormats );
1439cdf0e10cSrcweir         delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor( *rDataHelper.mpObjDesc );
1440cdf0e10cSrcweir         mxClipboard = rDataHelper.mxClipboard;
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir         if ( bWasClipboardListening )
1443cdf0e10cSrcweir             StartClipboardListening();
1444cdf0e10cSrcweir     }
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir     return *this;
1447cdf0e10cSrcweir }
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir // -----------------------------------------------------------------------------
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir TransferableDataHelper::~TransferableDataHelper()
1452cdf0e10cSrcweir {
1453cdf0e10cSrcweir     StopClipboardListening( );
1454cdf0e10cSrcweir     {
1455cdf0e10cSrcweir         ::osl::MutexGuard aGuard( mpImpl->maMutex );
1456cdf0e10cSrcweir         delete mpFormats, mpFormats = NULL;
1457cdf0e10cSrcweir         delete mpObjDesc, mpObjDesc = NULL;
1458cdf0e10cSrcweir     }
1459cdf0e10cSrcweir     delete mpImpl;
1460cdf0e10cSrcweir }
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir // -----------------------------------------------------------------------------
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor >& rDataFlavorSeq,
1465cdf0e10cSrcweir                                                      DataFlavorExVector& rDataFlavorExVector )
1466cdf0e10cSrcweir {
1467cdf0e10cSrcweir     try
1468cdf0e10cSrcweir     {
1469cdf0e10cSrcweir         Reference< XMultiServiceFactory >       xFact( ::comphelper::getProcessServiceFactory() );
1470cdf0e10cSrcweir         Reference< XMimeContentTypeFactory >    xMimeFact;
1471cdf0e10cSrcweir         DataFlavorEx                            aFlavorEx;
1472cdf0e10cSrcweir         const ::rtl::OUString                   aCharsetStr( ::rtl::OUString::createFromAscii( "charset" ) );
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir         if( xFact.is() )
1475cdf0e10cSrcweir             xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii(
1476cdf0e10cSrcweir                                                               "com.sun.star.datatransfer.MimeContentTypeFactory" ) ),
1477cdf0e10cSrcweir                                                               UNO_QUERY );
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir         for( sal_Int32 i = 0; i < rDataFlavorSeq.getLength(); i++ )
1480cdf0e10cSrcweir         {
1481cdf0e10cSrcweir             const DataFlavor&               rFlavor = rDataFlavorSeq[ i ];
1482cdf0e10cSrcweir             Reference< XMimeContentType >   xMimeType;
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir             try
1485cdf0e10cSrcweir             {
1486cdf0e10cSrcweir                 if( xMimeFact.is() && rFlavor.MimeType.getLength() )
1487cdf0e10cSrcweir                     xMimeType = xMimeFact->createMimeContentType( rFlavor.MimeType );
1488cdf0e10cSrcweir             }
1489cdf0e10cSrcweir             catch( const ::com::sun::star::uno::Exception& )
1490cdf0e10cSrcweir             {
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir             }
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir             aFlavorEx.MimeType = rFlavor.MimeType;
1495cdf0e10cSrcweir             aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName;
1496cdf0e10cSrcweir             aFlavorEx.DataType = rFlavor.DataType;
1497cdf0e10cSrcweir             aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor );
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir             rDataFlavorExVector.push_back( aFlavorEx );
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir             // add additional formats for special mime types
150245fd3b9aSArmin Le Grand             if(SOT_FORMATSTR_ID_BMP == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_PNG == aFlavorEx.mnSotId)
1503cdf0e10cSrcweir             {
1504cdf0e10cSrcweir                 if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavorEx ) )
1505cdf0e10cSrcweir                 {
1506cdf0e10cSrcweir                     aFlavorEx.mnSotId = SOT_FORMAT_BITMAP;
1507cdf0e10cSrcweir                     rDataFlavorExVector.push_back( aFlavorEx );
1508cdf0e10cSrcweir                 }
1509cdf0e10cSrcweir             }
1510*ad6faf97SDamjan Jovanovic             else if( SOT_FORMATSTR_ID_WMF == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_EMF == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_SVG == aFlavorEx.mnSotId )
1511cdf0e10cSrcweir             {
1512cdf0e10cSrcweir                 if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavorEx ) )
1513cdf0e10cSrcweir                 {
1514cdf0e10cSrcweir                     aFlavorEx.mnSotId = SOT_FORMAT_GDIMETAFILE;
1515cdf0e10cSrcweir                     rDataFlavorExVector.push_back( aFlavorEx );
1516cdf0e10cSrcweir                 }
1517cdf0e10cSrcweir             }
1518cdf0e10cSrcweir             else if ( SOT_FORMATSTR_ID_HTML_SIMPLE == aFlavorEx.mnSotId  )
1519cdf0e10cSrcweir             {
1520cdf0e10cSrcweir                 // #104735# HTML_SIMPLE may also be inserted without comments
1521cdf0e10cSrcweir                 aFlavorEx.mnSotId = SOT_FORMATSTR_ID_HTML_NO_COMMENT;
1522cdf0e10cSrcweir                 rDataFlavorExVector.push_back( aFlavorEx );
1523cdf0e10cSrcweir             }
1524cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) )
1525cdf0e10cSrcweir             {
1526cdf0e10cSrcweir                 // add, if it is a UTF-8 byte buffer
1527cdf0e10cSrcweir                 if( xMimeType->hasParameter( aCharsetStr ) )
1528cdf0e10cSrcweir                 {
1529cdf0e10cSrcweir                     const ::rtl::OUString aCharset( xMimeType->getParameterValue( aCharsetStr ) );
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir                     if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) ||
1532cdf0e10cSrcweir                         xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) )
1533cdf0e10cSrcweir                     {
1534cdf0e10cSrcweir                         rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_STRING;
1535cdf0e10cSrcweir 
1536cdf0e10cSrcweir                     }
1537cdf0e10cSrcweir                 }
1538cdf0e10cSrcweir             }
1539cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/rtf" ) ) )
1540cdf0e10cSrcweir             {
1541cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_RTF;
1542cdf0e10cSrcweir             }
1543cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/html" ) ) )
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir             {
1546cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_HTML;
1547cdf0e10cSrcweir             }
1548cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) )
1549cdf0e10cSrcweir             {
1550cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMAT_FILE_LIST;
1551cdf0e10cSrcweir             }
1552cdf0e10cSrcweir             else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice-objectdescriptor-xml" ) ) )
1553cdf0e10cSrcweir             {
1554cdf0e10cSrcweir                 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR;
1555cdf0e10cSrcweir             }
1556cdf0e10cSrcweir         }
1557cdf0e10cSrcweir     }
1558cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
1559cdf0e10cSrcweir     {
1560cdf0e10cSrcweir     }
1561cdf0e10cSrcweir }
1562cdf0e10cSrcweir 
1563cdf0e10cSrcweir // -----------------------------------------------------------------------------
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir void TransferableDataHelper::InitFormats()
1566cdf0e10cSrcweir {
1567cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1568cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir     mpFormats->clear();
1571cdf0e10cSrcweir     delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor;
1572cdf0e10cSrcweir 
1573cdf0e10cSrcweir     if( mxTransfer.is() )
1574cdf0e10cSrcweir     {
1575cdf0e10cSrcweir         TransferableDataHelper::FillDataFlavorExVector( mxTransfer->getTransferDataFlavors(), *mpFormats );
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir         DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir         while( aIter != aEnd )
1580cdf0e10cSrcweir         {
1581cdf0e10cSrcweir             if( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aIter->mnSotId )
1582cdf0e10cSrcweir             {
1583cdf0e10cSrcweir                 ImplSetParameterString( *mpObjDesc, *aIter );
1584cdf0e10cSrcweir                 aIter = aEnd;
1585cdf0e10cSrcweir             }
1586cdf0e10cSrcweir             else
1587cdf0e10cSrcweir                 ++aIter;
1588cdf0e10cSrcweir         }
1589cdf0e10cSrcweir     }
1590cdf0e10cSrcweir }
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir // -----------------------------------------------------------------------------
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( SotFormatStringId nFormat ) const
1595cdf0e10cSrcweir {
1596cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir     DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1599cdf0e10cSrcweir     sal_Bool                        bRet = sal_False;
1600cdf0e10cSrcweir 
1601cdf0e10cSrcweir     while( aIter != aEnd )
1602cdf0e10cSrcweir     {
1603cdf0e10cSrcweir         if( nFormat == (*aIter++).mnSotId )
1604cdf0e10cSrcweir         {
1605cdf0e10cSrcweir             aIter = aEnd;
1606cdf0e10cSrcweir             bRet = sal_True;
1607cdf0e10cSrcweir         }
1608cdf0e10cSrcweir     }
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir     return bRet;
1611cdf0e10cSrcweir }
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir // -----------------------------------------------------------------------------
1614cdf0e10cSrcweir 
1615cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( const DataFlavor& rFlavor ) const
1616cdf0e10cSrcweir {
1617cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir     DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1620cdf0e10cSrcweir     sal_Bool                        bRet = sal_False;
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir     while( aIter != aEnd )
1623cdf0e10cSrcweir     {
1624cdf0e10cSrcweir         if( TransferableDataHelper::IsEqual( rFlavor, *aIter++ ) )
1625cdf0e10cSrcweir         {
1626cdf0e10cSrcweir             aIter = aEnd;
1627cdf0e10cSrcweir             bRet = sal_True;
1628cdf0e10cSrcweir         }
1629cdf0e10cSrcweir     }
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir     return bRet;
1632cdf0e10cSrcweir }
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir // -----------------------------------------------------------------------------
1635cdf0e10cSrcweir 
1636cdf0e10cSrcweir sal_uInt32 TransferableDataHelper::GetFormatCount() const
1637cdf0e10cSrcweir {
1638cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1639cdf0e10cSrcweir     return mpFormats->size();
1640cdf0e10cSrcweir }
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir // -----------------------------------------------------------------------------
1643cdf0e10cSrcweir 
1644cdf0e10cSrcweir 
1645cdf0e10cSrcweir SotFormatStringId TransferableDataHelper::GetFormat( sal_uInt32 nFormat ) const
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1648cdf0e10cSrcweir     DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" );
1649cdf0e10cSrcweir     return( ( nFormat < mpFormats->size() ) ? (*mpFormats)[ nFormat ].mnSotId : 0 );
1650cdf0e10cSrcweir }
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir // -----------------------------------------------------------------------------
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir DataFlavor TransferableDataHelper::GetFormatDataFlavor( sal_uInt32 nFormat ) const
1655cdf0e10cSrcweir {
1656cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1657cdf0e10cSrcweir     DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" );
1658cdf0e10cSrcweir 
1659cdf0e10cSrcweir     DataFlavor aRet;
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir     if( nFormat < mpFormats->size() )
1662cdf0e10cSrcweir         aRet = (*mpFormats)[ nFormat ];
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir     return aRet;
1665cdf0e10cSrcweir }
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir // -----------------------------------------------------------------------------
1668cdf0e10cSrcweir 
1669cdf0e10cSrcweir Reference< XTransferable > TransferableDataHelper::GetXTransferable() const
1670cdf0e10cSrcweir {
1671cdf0e10cSrcweir     Reference< XTransferable > xRet;
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir     if( mxTransfer.is() )
1674cdf0e10cSrcweir     {
1675cdf0e10cSrcweir         try
1676cdf0e10cSrcweir         {
1677cdf0e10cSrcweir             xRet = mxTransfer;
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir             // do a dummy call to check, if this interface is valid (nasty)
1680cdf0e10cSrcweir             Sequence< DataFlavor > aTestSeq( xRet->getTransferDataFlavors() );
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir         }
1683cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
1684cdf0e10cSrcweir         {
1685cdf0e10cSrcweir             xRet = Reference< XTransferable >();
1686cdf0e10cSrcweir         }
1687cdf0e10cSrcweir     }
1688cdf0e10cSrcweir 
1689cdf0e10cSrcweir     return xRet;
1690cdf0e10cSrcweir }
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir // -----------------------------------------------------------------------------
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir Any TransferableDataHelper::GetAny( SotFormatStringId nFormat ) const
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir     Any aReturn;
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir     DataFlavor aFlavor;
1699cdf0e10cSrcweir     if ( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) )
1700cdf0e10cSrcweir         aReturn = GetAny( aFlavor );
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir     return aReturn;
1703cdf0e10cSrcweir }
1704cdf0e10cSrcweir 
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir // -----------------------------------------------------------------------------
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir Any TransferableDataHelper::GetAny( const DataFlavor& rFlavor ) const
1709cdf0e10cSrcweir {
1710cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
1711cdf0e10cSrcweir     Any aRet;
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir     try
1714cdf0e10cSrcweir     {
1715cdf0e10cSrcweir         if( mxTransfer.is() )
1716cdf0e10cSrcweir         {
1717cdf0e10cSrcweir             DataFlavorExVector::iterator    aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
1718cdf0e10cSrcweir             const SotFormatStringId         nRequestFormat = SotExchange::GetFormat( rFlavor );
1719cdf0e10cSrcweir 
1720cdf0e10cSrcweir             if( nRequestFormat )
1721cdf0e10cSrcweir             {
1722cdf0e10cSrcweir                 // try to get alien format first
1723cdf0e10cSrcweir                 while( aIter != aEnd )
1724cdf0e10cSrcweir                 {
1725cdf0e10cSrcweir                     if( ( nRequestFormat == (*aIter).mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( (*aIter).MimeType ) )
1726cdf0e10cSrcweir                         aRet = mxTransfer->getTransferData( *aIter );
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir                     if( aRet.hasValue() )
1729cdf0e10cSrcweir                         aIter = aEnd;
1730cdf0e10cSrcweir                     else
1731cdf0e10cSrcweir                         aIter++;
1732cdf0e10cSrcweir                 }
1733cdf0e10cSrcweir             }
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir             if( !aRet.hasValue() )
1736cdf0e10cSrcweir                 aRet = mxTransfer->getTransferData( rFlavor );
1737cdf0e10cSrcweir         }
1738cdf0e10cSrcweir     }
1739cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
1740cdf0e10cSrcweir     {
1741cdf0e10cSrcweir     }
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir     return aRet;
1744cdf0e10cSrcweir }
1745cdf0e10cSrcweir 
1746cdf0e10cSrcweir // -----------------------------------------------------------------------------
1747cdf0e10cSrcweir 
1748cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, String& rStr )
1749cdf0e10cSrcweir {
1750cdf0e10cSrcweir     ::rtl::OUString aOUString;
1751cdf0e10cSrcweir     sal_Bool        bRet = GetString( nFormat, aOUString );
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir     rStr = aOUString;
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir     return bRet;
1756cdf0e10cSrcweir }
1757cdf0e10cSrcweir 
1758cdf0e10cSrcweir // -----------------------------------------------------------------------------
1759cdf0e10cSrcweir 
1760cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, String& rStr )
1761cdf0e10cSrcweir {
1762cdf0e10cSrcweir     ::rtl::OUString aOUString;
1763cdf0e10cSrcweir     sal_Bool        bRet = GetString( rFlavor, aOUString );
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir     rStr = aOUString;
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir     return bRet;
1768cdf0e10cSrcweir }
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir // -----------------------------------------------------------------------------
1771cdf0e10cSrcweir 
1772cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, ::rtl::OUString& rStr )
1773cdf0e10cSrcweir {
1774cdf0e10cSrcweir     DataFlavor aFlavor;
1775cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetString( aFlavor, rStr ) );
1776cdf0e10cSrcweir }
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir // -----------------------------------------------------------------------------
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, ::rtl::OUString& rStr )
1781cdf0e10cSrcweir {
1782cdf0e10cSrcweir     Any         aAny( GetAny( rFlavor ) );
1783cdf0e10cSrcweir     sal_Bool    bRet = sal_False;
1784cdf0e10cSrcweir 
1785cdf0e10cSrcweir     if( aAny.hasValue() )
1786cdf0e10cSrcweir     {
1787cdf0e10cSrcweir         ::rtl::OUString         aOUString;
1788cdf0e10cSrcweir         Sequence< sal_Int8 >    aSeq;
1789cdf0e10cSrcweir 
1790cdf0e10cSrcweir         if( aAny >>= aOUString )
1791cdf0e10cSrcweir         {
1792cdf0e10cSrcweir             rStr = aOUString;
1793cdf0e10cSrcweir             bRet = sal_True;
1794cdf0e10cSrcweir         }
1795cdf0e10cSrcweir         else if( aAny >>= aSeq )
1796cdf0e10cSrcweir         {
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir             const sal_Char* pChars = reinterpret_cast< const sal_Char* >( aSeq.getConstArray() );
1799cdf0e10cSrcweir             sal_Int32       nLen = aSeq.getLength();
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir             //JP 10.10.2001: 92930 - don't copy the last zero characterinto the string.
1802cdf0e10cSrcweir             //DVO 2002-05-27: strip _all_ trailing zeros
1803cdf0e10cSrcweir             while( nLen && ( 0 == *( pChars + nLen - 1 ) ) )
1804cdf0e10cSrcweir                 --nLen;
1805cdf0e10cSrcweir 
1806cdf0e10cSrcweir             rStr = ::rtl::OUString( pChars, nLen, gsl_getSystemTextEncoding() );
1807cdf0e10cSrcweir             bRet = sal_True;
1808cdf0e10cSrcweir         }
1809cdf0e10cSrcweir     }
1810cdf0e10cSrcweir 
1811cdf0e10cSrcweir     return bRet;
1812cdf0e10cSrcweir }
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir // -----------------------------------------------------------------------------
1815cdf0e10cSrcweir 
181645fd3b9aSArmin Le Grand sal_Bool TransferableDataHelper::GetBitmapEx( SotFormatStringId nFormat, BitmapEx& rBmpEx )
1817cdf0e10cSrcweir {
181845fd3b9aSArmin Le Grand     if(FORMAT_BITMAP == nFormat)
181945fd3b9aSArmin Le Grand     {
182045fd3b9aSArmin Le Grand         // try to get PNG first
1821cdf0e10cSrcweir         DataFlavor aFlavor;
182245fd3b9aSArmin Le Grand 
182345fd3b9aSArmin Le Grand         if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor))
182445fd3b9aSArmin Le Grand         {
182545fd3b9aSArmin Le Grand             if(GetBitmapEx(aFlavor, rBmpEx))
182645fd3b9aSArmin Le Grand             {
182745fd3b9aSArmin Le Grand                 return true;
182845fd3b9aSArmin Le Grand             }
182945fd3b9aSArmin Le Grand         }
183045fd3b9aSArmin Le Grand     }
183145fd3b9aSArmin Le Grand 
183245fd3b9aSArmin Le Grand     DataFlavor aFlavor;
183345fd3b9aSArmin Le Grand     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetBitmapEx( aFlavor, rBmpEx ) );
1834cdf0e10cSrcweir }
1835cdf0e10cSrcweir 
1836cdf0e10cSrcweir // -----------------------------------------------------------------------------
1837cdf0e10cSrcweir 
183845fd3b9aSArmin Le Grand sal_Bool TransferableDataHelper::GetBitmapEx( const DataFlavor& rFlavor, BitmapEx& rBmpEx )
1839cdf0e10cSrcweir {
1840cdf0e10cSrcweir     SotStorageStreamRef xStm;
1841cdf0e10cSrcweir     DataFlavor aSubstFlavor;
184245fd3b9aSArmin Le Grand     bool bRet(GetSotStorageStream(rFlavor, xStm));
1843208f27daSArmin Le Grand     bool bSuppressPNG(false); // #122982# If PNG stream not accessed, but BMP one, suppress trying to load PNG
184445fd3b9aSArmin Le Grand 
184545fd3b9aSArmin Le Grand     if(!bRet && HasFormat(SOT_FORMATSTR_ID_PNG) && SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aSubstFlavor))
184645fd3b9aSArmin Le Grand     {
184745fd3b9aSArmin Le Grand         // when no direct success, try if PNG is available
184845fd3b9aSArmin Le Grand         bRet = GetSotStorageStream(aSubstFlavor, xStm);
184945fd3b9aSArmin Le Grand     }
185045fd3b9aSArmin Le Grand 
185145fd3b9aSArmin Le Grand     if(!bRet && HasFormat(SOT_FORMATSTR_ID_BMP) && SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_BMP, aSubstFlavor))
185245fd3b9aSArmin Le Grand     {
185345fd3b9aSArmin Le Grand         // when no direct success, try if BMP is available
185445fd3b9aSArmin Le Grand         bRet = GetSotStorageStream(aSubstFlavor, xStm);
1855208f27daSArmin Le Grand         bSuppressPNG = bRet;
185645fd3b9aSArmin Le Grand     }
1857cdf0e10cSrcweir 
1858cdf0e10cSrcweir     if(bRet)
1859cdf0e10cSrcweir     {
1860208f27daSArmin Le Grand         if(!bSuppressPNG && rFlavor.MimeType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("image/png")))
186145fd3b9aSArmin Le Grand         {
186245fd3b9aSArmin Le Grand             // it's a PNG, import to BitmapEx
186345fd3b9aSArmin Le Grand             ::vcl::PNGReader aPNGReader(*xStm);
186445fd3b9aSArmin Le Grand 
186545fd3b9aSArmin Le Grand             rBmpEx = aPNGReader.Read();
186645fd3b9aSArmin Le Grand         }
1867208f27daSArmin Le Grand 
1868208f27daSArmin Le Grand         if(rBmpEx.IsEmpty())
186945fd3b9aSArmin Le Grand         {
187045fd3b9aSArmin Le Grand             Bitmap aBitmap;
187145fd3b9aSArmin Le Grand             Bitmap aMask;
187245fd3b9aSArmin Le Grand 
18736d53c851Smseidel             // explicitly use Bitmap::Read with bFileHeader = sal_True
1874a206ee71SArmin Le Grand             // #124085# keep DIBV5 for read from clipboard, but should not happen
187545fd3b9aSArmin Le Grand             ReadDIBV5(aBitmap, aMask, *xStm);
187645fd3b9aSArmin Le Grand 
187745fd3b9aSArmin Le Grand             if(aMask.IsEmpty())
187845fd3b9aSArmin Le Grand             {
187945fd3b9aSArmin Le Grand                 rBmpEx = aBitmap;
188045fd3b9aSArmin Le Grand             }
188145fd3b9aSArmin Le Grand             else
188245fd3b9aSArmin Le Grand             {
188345fd3b9aSArmin Le Grand                 rBmpEx = BitmapEx(aBitmap, aMask);
188445fd3b9aSArmin Le Grand             }
188545fd3b9aSArmin Le Grand         }
188645fd3b9aSArmin Le Grand 
1887208f27daSArmin Le Grand         bRet = (ERRCODE_NONE == xStm->GetError() && !rBmpEx.IsEmpty());
1888cdf0e10cSrcweir 
1889cdf0e10cSrcweir         /* SJ: #110748# At the moment we are having problems with DDB inserted as DIB. The
1890cdf0e10cSrcweir            problem is, that some graphics are inserted much too big because the nXPelsPerMeter
1891cdf0e10cSrcweir            and nYPelsPerMeter of the bitmap fileheader isn't including the correct value.
1892cdf0e10cSrcweir            Due to this reason the following code assumes that bitmaps with a logical size
1893cdf0e10cSrcweir            greater than 50 cm aren't having the correct mapmode set.
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir            The following code should be removed if DDBs and DIBs are supported via clipboard
1896cdf0e10cSrcweir            properly.
1897cdf0e10cSrcweir         */
1898cdf0e10cSrcweir         if(bRet)
1899cdf0e10cSrcweir         {
190045fd3b9aSArmin Le Grand             const MapMode aMapMode(rBmpEx.GetPrefMapMode());
1901cdf0e10cSrcweir 
190245fd3b9aSArmin Le Grand             if(MAP_PIXEL != aMapMode.GetMapUnit())
1903cdf0e10cSrcweir             {
190445fd3b9aSArmin Le Grand                 const Size aSize(OutputDevice::LogicToLogic(rBmpEx.GetPrefSize(), aMapMode, MAP_100TH_MM));
190545fd3b9aSArmin Le Grand 
1906519071a5SArmin Le Grand                 // #122388# This wrongly corrects in the given case; changing from 5000 100th mm to
1907519071a5SArmin Le Grand                 // the described 50 cm (which is 50000 100th mm)
1908519071a5SArmin Le Grand                 if((aSize.Width() > 50000) || (aSize.Height() > 50000))
190945fd3b9aSArmin Le Grand                 {
191045fd3b9aSArmin Le Grand                     rBmpEx.SetPrefMapMode(MAP_PIXEL);
1911519071a5SArmin Le Grand 
1912519071a5SArmin Le Grand                     // #122388# also adapt size by applying the mew MapMode
1913519071a5SArmin Le Grand                     const Size aNewSize(OutputDevice::LogicToLogic(aSize, MAP_100TH_MM, MAP_PIXEL));
1914519071a5SArmin Le Grand                     rBmpEx.SetPrefSize(aNewSize);
191545fd3b9aSArmin Le Grand                 }
191645fd3b9aSArmin Le Grand             }
191745fd3b9aSArmin Le Grand         }
1918cdf0e10cSrcweir     }
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir     return bRet;
1921cdf0e10cSrcweir }
1922cdf0e10cSrcweir 
1923cdf0e10cSrcweir // -----------------------------------------------------------------------------
1924cdf0e10cSrcweir 
1925cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( SotFormatStringId nFormat, GDIMetaFile& rMtf )
1926cdf0e10cSrcweir {
1927cdf0e10cSrcweir     DataFlavor aFlavor;
1928cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGDIMetaFile( aFlavor, rMtf ) );
1929cdf0e10cSrcweir }
1930cdf0e10cSrcweir 
1931cdf0e10cSrcweir // -----------------------------------------------------------------------------
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaFile& rMtf )
1934cdf0e10cSrcweir {
1935cdf0e10cSrcweir     SotStorageStreamRef xStm;
1936cdf0e10cSrcweir     DataFlavor          aSubstFlavor;
1937cdf0e10cSrcweir     sal_Bool            bRet = sal_False;
1938cdf0e10cSrcweir 
1939cdf0e10cSrcweir     if( GetSotStorageStream( rFlavor, xStm ) )
1940cdf0e10cSrcweir     {
1941cdf0e10cSrcweir         *xStm >> rMtf;
1942cdf0e10cSrcweir         bRet = ( xStm->GetError() == ERRCODE_NONE );
1943cdf0e10cSrcweir     }
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir     if( !bRet &&
1946cdf0e10cSrcweir         HasFormat( SOT_FORMATSTR_ID_EMF ) &&
1947cdf0e10cSrcweir         SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_EMF, aSubstFlavor ) &&
1948cdf0e10cSrcweir         GetSotStorageStream( aSubstFlavor, xStm ) )
1949cdf0e10cSrcweir     {
1950cdf0e10cSrcweir         Graphic aGraphic;
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir         if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE )
1953cdf0e10cSrcweir         {
1954cdf0e10cSrcweir             rMtf = aGraphic.GetGDIMetaFile();
1955cdf0e10cSrcweir             bRet = sal_True;
1956cdf0e10cSrcweir         }
1957cdf0e10cSrcweir     }
1958cdf0e10cSrcweir 
1959cdf0e10cSrcweir     if( !bRet &&
1960cdf0e10cSrcweir         HasFormat( SOT_FORMATSTR_ID_WMF ) &&
1961cdf0e10cSrcweir         SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_WMF, aSubstFlavor ) &&
1962cdf0e10cSrcweir         GetSotStorageStream( aSubstFlavor, xStm ) )
1963cdf0e10cSrcweir     {
1964cdf0e10cSrcweir         Graphic aGraphic;
1965cdf0e10cSrcweir 
1966cdf0e10cSrcweir         if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE )
1967cdf0e10cSrcweir         {
1968cdf0e10cSrcweir             rMtf = aGraphic.GetGDIMetaFile();
1969cdf0e10cSrcweir             bRet = sal_True;
1970cdf0e10cSrcweir         }
1971cdf0e10cSrcweir     }
1972cdf0e10cSrcweir 
1973cdf0e10cSrcweir     return bRet;
1974cdf0e10cSrcweir }
1975cdf0e10cSrcweir 
1976cdf0e10cSrcweir // -----------------------------------------------------------------------------
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( SotFormatStringId nFormat, Graphic& rGraphic )
1979cdf0e10cSrcweir {
198045fd3b9aSArmin Le Grand     if(FORMAT_BITMAP == nFormat)
198145fd3b9aSArmin Le Grand     {
198245fd3b9aSArmin Le Grand         // try to get PNG first
198345fd3b9aSArmin Le Grand         DataFlavor aFlavor;
198445fd3b9aSArmin Le Grand 
198545fd3b9aSArmin Le Grand         if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor))
198645fd3b9aSArmin Le Grand         {
198745fd3b9aSArmin Le Grand             if(GetGraphic(aFlavor, rGraphic))
198845fd3b9aSArmin Le Grand             {
198945fd3b9aSArmin Le Grand                 return true;
199045fd3b9aSArmin Le Grand             }
199145fd3b9aSArmin Le Grand         }
199245fd3b9aSArmin Le Grand     }
199345fd3b9aSArmin Le Grand 
1994cdf0e10cSrcweir     DataFlavor aFlavor;
1995cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGraphic( aFlavor, rGraphic ) );
1996cdf0e10cSrcweir }
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir // -----------------------------------------------------------------------------
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, Graphic& rGraphic )
2001cdf0e10cSrcweir {
2002cdf0e10cSrcweir     DataFlavor  aFlavor;
2003cdf0e10cSrcweir     sal_Bool    bRet = sal_False;
2004cdf0e10cSrcweir 
200545fd3b9aSArmin Le Grand     if(SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_PNG, aFlavor) &&
2006cdf0e10cSrcweir         TransferableDataHelper::IsEqual(aFlavor, rFlavor))
2007cdf0e10cSrcweir     {
200845fd3b9aSArmin Le Grand         // try to get PNG first
200945fd3b9aSArmin Le Grand         BitmapEx aBmpEx;
2010cdf0e10cSrcweir 
201145fd3b9aSArmin Le Grand         if( ( bRet = GetBitmapEx( aFlavor, aBmpEx ) ) == sal_True )
201245fd3b9aSArmin Le Grand             rGraphic = aBmpEx;
201345fd3b9aSArmin Le Grand     }
201445fd3b9aSArmin Le Grand     else if(SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavor ) &&
201545fd3b9aSArmin Le Grand         TransferableDataHelper::IsEqual( aFlavor, rFlavor ) )
201645fd3b9aSArmin Le Grand     {
201745fd3b9aSArmin Le Grand         BitmapEx aBmpEx;
201845fd3b9aSArmin Le Grand 
201945fd3b9aSArmin Le Grand         if( ( bRet = GetBitmapEx( aFlavor, aBmpEx ) ) == sal_True )
202045fd3b9aSArmin Le Grand             rGraphic = aBmpEx;
2021cdf0e10cSrcweir     }
2022cdf0e10cSrcweir     else if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavor ) &&
2023cdf0e10cSrcweir              TransferableDataHelper::IsEqual( aFlavor, rFlavor ) )
2024cdf0e10cSrcweir     {
2025cdf0e10cSrcweir         GDIMetaFile aMtf;
2026cdf0e10cSrcweir 
2027cdf0e10cSrcweir         if( ( bRet = GetGDIMetaFile( aFlavor, aMtf ) ) == sal_True )
2028cdf0e10cSrcweir             rGraphic = aMtf;
2029cdf0e10cSrcweir     }
2030cdf0e10cSrcweir     else
2031cdf0e10cSrcweir     {
2032cdf0e10cSrcweir         SotStorageStreamRef xStm;
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir         if( GetSotStorageStream( rFlavor, xStm ) )
2035cdf0e10cSrcweir         {
2036cdf0e10cSrcweir             *xStm >> rGraphic;
2037cdf0e10cSrcweir             bRet = ( xStm->GetError() == ERRCODE_NONE );
2038cdf0e10cSrcweir         }
2039cdf0e10cSrcweir     }
2040cdf0e10cSrcweir 
2041cdf0e10cSrcweir     return bRet;
2042cdf0e10cSrcweir }
2043cdf0e10cSrcweir 
2044cdf0e10cSrcweir // -----------------------------------------------------------------------------
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( SotFormatStringId nFormat, ImageMap& rIMap )
2047cdf0e10cSrcweir {
2048cdf0e10cSrcweir     DataFlavor aFlavor;
2049cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetImageMap( aFlavor, rIMap ) );
2050cdf0e10cSrcweir }
2051cdf0e10cSrcweir 
2052cdf0e10cSrcweir // -----------------------------------------------------------------------------
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, ImageMap& rIMap )
2055cdf0e10cSrcweir {
2056cdf0e10cSrcweir     SotStorageStreamRef xStm;
2057cdf0e10cSrcweir     sal_Bool            bRet = GetSotStorageStream( rFlavor, xStm );
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir     if( bRet )
2060cdf0e10cSrcweir     {
2061cdf0e10cSrcweir         rIMap.Read( *xStm, String() );
2062cdf0e10cSrcweir         bRet = ( xStm->GetError() == ERRCODE_NONE );
2063cdf0e10cSrcweir     }
2064cdf0e10cSrcweir 
2065cdf0e10cSrcweir     return bRet;
2066cdf0e10cSrcweir }
2067cdf0e10cSrcweir 
2068cdf0e10cSrcweir // -----------------------------------------------------------------------------
2069cdf0e10cSrcweir 
2070cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( SotFormatStringId nFormat, TransferableObjectDescriptor& rDesc )
2071cdf0e10cSrcweir {
2072cdf0e10cSrcweir     DataFlavor aFlavor;
2073cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetTransferableObjectDescriptor( aFlavor, rDesc ) );
2074cdf0e10cSrcweir }
2075cdf0e10cSrcweir 
2076cdf0e10cSrcweir // -----------------------------------------------------------------------------
2077cdf0e10cSrcweir 
2078cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( const ::com::sun::star::datatransfer::DataFlavor&, TransferableObjectDescriptor& rDesc )
2079cdf0e10cSrcweir {
2080cdf0e10cSrcweir     rDesc = *mpObjDesc;
2081cdf0e10cSrcweir     return true;
2082cdf0e10cSrcweir }
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir // -----------------------------------------------------------------------------
2085cdf0e10cSrcweir 
2086cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( SotFormatStringId nFormat, INetBookmark& rBmk )
2087cdf0e10cSrcweir {
2088cdf0e10cSrcweir     DataFlavor aFlavor;
2089cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetBookmark( aFlavor, rBmk ) );
2090cdf0e10cSrcweir }
2091cdf0e10cSrcweir 
2092cdf0e10cSrcweir // -----------------------------------------------------------------------------
2093cdf0e10cSrcweir 
2094cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, INetBookmark& rBmk )
2095cdf0e10cSrcweir {
2096cdf0e10cSrcweir     sal_Bool bRet = sal_False;
2097cdf0e10cSrcweir     if( HasFormat( rFlavor ))
2098cdf0e10cSrcweir     {
2099cdf0e10cSrcweir     const SotFormatStringId nFormat = SotExchange::GetFormat( rFlavor );
2100cdf0e10cSrcweir     switch( nFormat )
2101cdf0e10cSrcweir     {
2102cdf0e10cSrcweir         case( SOT_FORMATSTR_ID_SOLK ):
2103cdf0e10cSrcweir         case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ):
2104cdf0e10cSrcweir         {
2105cdf0e10cSrcweir             String aString;
2106cdf0e10cSrcweir             if( GetString( rFlavor, aString ) )
2107cdf0e10cSrcweir             {
2108cdf0e10cSrcweir                 if( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR == nFormat )
2109cdf0e10cSrcweir                 {
2110cdf0e10cSrcweir                     rBmk = INetBookmark( aString, aString );
2111cdf0e10cSrcweir                     bRet = sal_True;
2112cdf0e10cSrcweir                 }
2113cdf0e10cSrcweir                 else
2114cdf0e10cSrcweir                 {
2115cdf0e10cSrcweir                     String      aURL, aDesc;
2116cdf0e10cSrcweir                     sal_uInt16  nStart = aString.Search( '@' ), nLen = (sal_uInt16) aString.ToInt32();
2117cdf0e10cSrcweir 
2118cdf0e10cSrcweir                     if( !nLen && aString.GetChar( 0 ) != '0' )
2119cdf0e10cSrcweir                     {
2120cdf0e10cSrcweir                         DBG_WARNING( "SOLK: 1. len=0" );
2121cdf0e10cSrcweir                     }
2122cdf0e10cSrcweir                     if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 3 )
2123cdf0e10cSrcweir                     {
2124cdf0e10cSrcweir                         DBG_WARNING( "SOLK: 1. illegal start or wrong len" );
2125cdf0e10cSrcweir                     }
2126cdf0e10cSrcweir                     aURL = aString.Copy( nStart + 1, nLen );
2127cdf0e10cSrcweir 
2128cdf0e10cSrcweir                     aString.Erase( 0, nStart + 1 + nLen );
2129cdf0e10cSrcweir                     nStart = aString.Search( '@' );
2130cdf0e10cSrcweir                     nLen = (sal_uInt16) aString.ToInt32();
2131cdf0e10cSrcweir 
2132cdf0e10cSrcweir                     if( !nLen && aString.GetChar( 0 ) != '0' )
2133cdf0e10cSrcweir                     {
2134cdf0e10cSrcweir                         DBG_WARNING( "SOLK: 2. len=0" );
2135cdf0e10cSrcweir                     }
2136cdf0e10cSrcweir                     if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 1 )
2137cdf0e10cSrcweir                     {
2138cdf0e10cSrcweir                         DBG_WARNING( "SOLK: 2. illegal start or wrong len" );
2139cdf0e10cSrcweir                     }
2140cdf0e10cSrcweir                     aDesc = aString.Copy( nStart+1, nLen );
2141cdf0e10cSrcweir 
2142cdf0e10cSrcweir                     rBmk = INetBookmark( aURL, aDesc );
2143cdf0e10cSrcweir                     bRet = sal_True;
2144cdf0e10cSrcweir                 }
2145cdf0e10cSrcweir             }
2146cdf0e10cSrcweir         }
2147cdf0e10cSrcweir         break;
2148cdf0e10cSrcweir 
2149cdf0e10cSrcweir         case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ):
2150cdf0e10cSrcweir         {
2151cdf0e10cSrcweir             Sequence< sal_Int8 > aSeq;
2152cdf0e10cSrcweir 
2153cdf0e10cSrcweir             if( GetSequence( rFlavor, aSeq ) && ( 2048 == aSeq.getLength() ) )
2154cdf0e10cSrcweir             {
2155cdf0e10cSrcweir                 rBmk = INetBookmark( String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), gsl_getSystemTextEncoding() ),
2156cdf0e10cSrcweir                                      String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ) + 1024, gsl_getSystemTextEncoding() ) );
2157cdf0e10cSrcweir                 bRet = sal_True;
2158cdf0e10cSrcweir             }
2159cdf0e10cSrcweir         }
2160cdf0e10cSrcweir         break;
2161cdf0e10cSrcweir 
2162cdf0e10cSrcweir #ifdef WNT
2163cdf0e10cSrcweir         case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
2164cdf0e10cSrcweir         {
2165cdf0e10cSrcweir             Sequence< sal_Int8 > aSeq;
2166cdf0e10cSrcweir 
2167cdf0e10cSrcweir             if( GetSequence( rFlavor, aSeq ) && aSeq.getLength() )
2168cdf0e10cSrcweir             {
2169cdf0e10cSrcweir                 FILEGROUPDESCRIPTOR* pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getConstArray();
2170cdf0e10cSrcweir 
2171cdf0e10cSrcweir                 if( pFDesc->cItems )
2172cdf0e10cSrcweir                 {
2173cdf0e10cSrcweir                     ByteString          aDesc( pFDesc->fgd[ 0 ].cFileName );
2174cdf0e10cSrcweir                     rtl_TextEncoding    eTextEncoding = gsl_getSystemTextEncoding();
2175cdf0e10cSrcweir 
2176cdf0e10cSrcweir                     if( ( aDesc.Len() > 4 ) && aDesc.Copy( aDesc.Len() - 4 ).EqualsIgnoreCaseAscii( ".URL" ) )
2177cdf0e10cSrcweir                     {
2178cdf0e10cSrcweir                         SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( INetURLObject( String( aDesc, eTextEncoding ) ).GetMainURL( INetURLObject::NO_DECODE ),
2179cdf0e10cSrcweir                                                                                   STREAM_STD_READ );
2180cdf0e10cSrcweir 
2181cdf0e10cSrcweir                         if( !pStream || pStream->GetError() )
2182cdf0e10cSrcweir                         {
2183cdf0e10cSrcweir                             DataFlavor aFileContentFlavor;
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir                             aSeq.realloc( 0 );
2186cdf0e10cSrcweir                             delete pStream;
2187cdf0e10cSrcweir 
2188cdf0e10cSrcweir                             if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_FILECONTENT, aFileContentFlavor ) &&
2189cdf0e10cSrcweir                                 GetSequence( aFileContentFlavor, aSeq ) && aSeq.getLength() )
2190cdf0e10cSrcweir                             {
2191cdf0e10cSrcweir                                 pStream = new SvMemoryStream( (sal_Char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_STD_READ );
2192cdf0e10cSrcweir                             }
2193cdf0e10cSrcweir                             else
2194cdf0e10cSrcweir                                 pStream = NULL;
2195cdf0e10cSrcweir                         }
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir                         if( pStream )
2198cdf0e10cSrcweir                         {
2199cdf0e10cSrcweir                             ByteString  aLine;
2200cdf0e10cSrcweir                             sal_Bool    bSttFnd = sal_False;
2201cdf0e10cSrcweir 
2202cdf0e10cSrcweir                             while( pStream->ReadLine( aLine ) )
2203cdf0e10cSrcweir                             {
2204cdf0e10cSrcweir                                 if( aLine.EqualsIgnoreCaseAscii( "[InternetShortcut]" ) )
2205cdf0e10cSrcweir                                     bSttFnd = sal_True;
2206cdf0e10cSrcweir                                 else if( bSttFnd && aLine.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "URL=" ) )
2207cdf0e10cSrcweir                                 {
2208cdf0e10cSrcweir                                     rBmk = INetBookmark( String( aLine.Erase( 0, 4 ), eTextEncoding ),
2209cdf0e10cSrcweir                                                          String( aDesc.Erase( aDesc.Len() - 4 ), eTextEncoding ) );
2210cdf0e10cSrcweir                                     bRet = sal_True;
2211cdf0e10cSrcweir                                     break;
2212cdf0e10cSrcweir                                 }
2213cdf0e10cSrcweir                             }
2214cdf0e10cSrcweir 
2215cdf0e10cSrcweir                             delete pStream;
2216cdf0e10cSrcweir                         }
2217cdf0e10cSrcweir                     }
2218cdf0e10cSrcweir                 }
2219cdf0e10cSrcweir             }
2220cdf0e10cSrcweir         }
2221cdf0e10cSrcweir         break;
2222cdf0e10cSrcweir #endif
2223cdf0e10cSrcweir 
2224cdf0e10cSrcweir     }
2225cdf0e10cSrcweir     }
2226cdf0e10cSrcweir     return bRet;
2227cdf0e10cSrcweir }
2228cdf0e10cSrcweir 
2229cdf0e10cSrcweir // -----------------------------------------------------------------------------
2230cdf0e10cSrcweir 
2231cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage( SotFormatStringId nFormat,
2232cdf0e10cSrcweir                                                 INetImage& rINtImg )
2233cdf0e10cSrcweir {
2234cdf0e10cSrcweir     DataFlavor aFlavor;
2235cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetImage( aFlavor, rINtImg ) );
2236cdf0e10cSrcweir }
2237cdf0e10cSrcweir 
2238cdf0e10cSrcweir // -----------------------------------------------------------------------------
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage(
2241cdf0e10cSrcweir         const ::com::sun::star::datatransfer::DataFlavor& rFlavor,
2242cdf0e10cSrcweir         INetImage& rINtImg )
2243cdf0e10cSrcweir {
2244cdf0e10cSrcweir     SotStorageStreamRef xStm;
2245cdf0e10cSrcweir     sal_Bool bRet = GetSotStorageStream( rFlavor, xStm );
2246cdf0e10cSrcweir 
2247cdf0e10cSrcweir     if( bRet )
2248cdf0e10cSrcweir         bRet = rINtImg.Read( *xStm, SotExchange::GetFormat( rFlavor ) );
2249cdf0e10cSrcweir     return bRet;
2250cdf0e10cSrcweir }
2251cdf0e10cSrcweir 
2252cdf0e10cSrcweir // -----------------------------------------------------------------------------
2253cdf0e10cSrcweir 
2254cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList( SotFormatStringId nFormat,
2255cdf0e10cSrcweir                                                 FileList& rFileList )
2256cdf0e10cSrcweir {
2257cdf0e10cSrcweir     DataFlavor aFlavor;
2258cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetFileList( aFlavor, rFileList ) );
2259cdf0e10cSrcweir }
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir // -----------------------------------------------------------------------------
2262cdf0e10cSrcweir 
2263cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList(
2264cdf0e10cSrcweir             const ::com::sun::star::datatransfer::DataFlavor&,
2265cdf0e10cSrcweir             FileList& rFileList )
2266cdf0e10cSrcweir {
2267cdf0e10cSrcweir     SotStorageStreamRef xStm;
2268cdf0e10cSrcweir     sal_Bool            bRet = sal_False;
2269cdf0e10cSrcweir 
2270cdf0e10cSrcweir     for( sal_uInt32 i = 0, nFormatCount = GetFormatCount(); ( i < nFormatCount ) && !bRet; ++i )
2271cdf0e10cSrcweir     {
2272cdf0e10cSrcweir         if( SOT_FORMAT_FILE_LIST == GetFormat( i ) )
2273cdf0e10cSrcweir         {
2274cdf0e10cSrcweir             const DataFlavor aFlavor( GetFormatDataFlavor( i ) );
2275cdf0e10cSrcweir 
2276cdf0e10cSrcweir             if( GetSotStorageStream( aFlavor, xStm ) )
2277cdf0e10cSrcweir             {
2278cdf0e10cSrcweir                 if( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) > -1 )
2279cdf0e10cSrcweir                 {
2280cdf0e10cSrcweir                     ByteString aByteString;
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir                     while( xStm->ReadLine( aByteString ) )
2283cdf0e10cSrcweir                         if( aByteString.Len() && aByteString.GetChar( 0 ) != '#' )
2284cdf0e10cSrcweir                             rFileList.AppendFile( String( aByteString, RTL_TEXTENCODING_UTF8 ) );
2285cdf0e10cSrcweir 
2286cdf0e10cSrcweir                     bRet = sal_True;
2287cdf0e10cSrcweir                  }
2288cdf0e10cSrcweir                  else
2289cdf0e10cSrcweir                     bRet = ( ( *xStm >> rFileList ).GetError() == ERRCODE_NONE );
2290cdf0e10cSrcweir             }
2291cdf0e10cSrcweir         }
2292cdf0e10cSrcweir     }
2293cdf0e10cSrcweir 
2294cdf0e10cSrcweir     return bRet;
2295cdf0e10cSrcweir }
2296cdf0e10cSrcweir 
2297cdf0e10cSrcweir // -----------------------------------------------------------------------------
2298cdf0e10cSrcweir 
2299cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( SotFormatStringId nFormat, Sequence< sal_Int8 >& rSeq )
2300cdf0e10cSrcweir {
2301cdf0e10cSrcweir     DataFlavor aFlavor;
2302cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSequence( aFlavor, rSeq ) );
2303cdf0e10cSrcweir }
2304cdf0e10cSrcweir 
2305cdf0e10cSrcweir // -----------------------------------------------------------------------------
2306cdf0e10cSrcweir 
2307cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( const DataFlavor& rFlavor, Sequence< sal_Int8 >& rSeq )
2308cdf0e10cSrcweir {
2309cdf0e10cSrcweir #ifdef DEBUG
2310cdf0e10cSrcweir     fprintf( stderr, "TransferableDataHelper requests sequence of data\n" );
2311cdf0e10cSrcweir #endif
2312cdf0e10cSrcweir 
2313cdf0e10cSrcweir     const Any aAny( GetAny( rFlavor ) );
2314cdf0e10cSrcweir     return( aAny.hasValue() && ( aAny >>= rSeq ) );
2315cdf0e10cSrcweir }
2316cdf0e10cSrcweir 
2317cdf0e10cSrcweir // -----------------------------------------------------------------------------
2318cdf0e10cSrcweir 
2319cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( SotFormatStringId nFormat, SotStorageStreamRef& rxStream )
2320cdf0e10cSrcweir {
2321cdf0e10cSrcweir     DataFlavor aFlavor;
2322cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSotStorageStream( aFlavor, rxStream ) );
2323cdf0e10cSrcweir }
2324cdf0e10cSrcweir 
2325cdf0e10cSrcweir // -----------------------------------------------------------------------------
2326cdf0e10cSrcweir 
2327cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( const DataFlavor& rFlavor, SotStorageStreamRef& rxStream )
2328cdf0e10cSrcweir {
2329cdf0e10cSrcweir     Sequence< sal_Int8 >    aSeq;
2330cdf0e10cSrcweir     sal_Bool                bRet = GetSequence( rFlavor, aSeq );
2331cdf0e10cSrcweir 
2332cdf0e10cSrcweir     if( bRet )
2333cdf0e10cSrcweir     {
2334cdf0e10cSrcweir         rxStream = new SotStorageStream( String() );
2335cdf0e10cSrcweir         rxStream->Write( aSeq.getConstArray(), aSeq.getLength() );
2336cdf0e10cSrcweir         rxStream->Seek( 0 );
2337cdf0e10cSrcweir     }
2338cdf0e10cSrcweir 
2339cdf0e10cSrcweir     return bRet;
2340cdf0e10cSrcweir }
2341cdf0e10cSrcweir 
2342cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( SotFormatStringId nFormat, Reference < XInputStream >& rxStream )
2343cdf0e10cSrcweir {
2344cdf0e10cSrcweir     DataFlavor aFlavor;
2345cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInputStream( aFlavor, rxStream ) );
2346cdf0e10cSrcweir }
2347cdf0e10cSrcweir 
2348cdf0e10cSrcweir // -----------------------------------------------------------------------------
2349cdf0e10cSrcweir 
2350cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( const DataFlavor& rFlavor, Reference < XInputStream >& rxStream )
2351cdf0e10cSrcweir {
2352cdf0e10cSrcweir     Sequence< sal_Int8 >    aSeq;
2353cdf0e10cSrcweir     sal_Bool                bRet = GetSequence( rFlavor, aSeq );
2354cdf0e10cSrcweir 
2355cdf0e10cSrcweir     if( bRet )
2356cdf0e10cSrcweir           rxStream = new ::comphelper::SequenceInputStream( aSeq );
2357cdf0e10cSrcweir 
2358cdf0e10cSrcweir     return bRet;
2359cdf0e10cSrcweir }
2360cdf0e10cSrcweir 
2361cdf0e10cSrcweir // -----------------------------------------------------------------------------
2362cdf0e10cSrcweir 
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( SotFormatStringId nFormat, Reference< XInterface >& rIf )
2365cdf0e10cSrcweir {
2366cdf0e10cSrcweir     DataFlavor aFlavor;
2367cdf0e10cSrcweir     return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInterface( aFlavor, rIf ) );
2368cdf0e10cSrcweir }
2369cdf0e10cSrcweir 
2370cdf0e10cSrcweir // -----------------------------------------------------------------------------
2371cdf0e10cSrcweir 
2372cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( const DataFlavor& rFlavor, Reference< XInterface >& rIf )
2373cdf0e10cSrcweir {
2374cdf0e10cSrcweir     const Any aAny( GetAny( rFlavor ) );
2375cdf0e10cSrcweir     return( aAny.hasValue() && ( aAny >>= rIf ) );
2376cdf0e10cSrcweir }
2377cdf0e10cSrcweir 
2378cdf0e10cSrcweir // -----------------------------------------------------------------------------
2379cdf0e10cSrcweir void TransferableDataHelper::Rebind( const Reference< XTransferable >& _rxNewContent )
2380cdf0e10cSrcweir {
2381cdf0e10cSrcweir     mxTransfer = _rxNewContent;
2382cdf0e10cSrcweir     InitFormats();
2383cdf0e10cSrcweir }
2384cdf0e10cSrcweir 
2385cdf0e10cSrcweir // -----------------------------------------------------------------------------
2386cdf0e10cSrcweir 
2387cdf0e10cSrcweir sal_Bool TransferableDataHelper::StartClipboardListening( )
2388cdf0e10cSrcweir {
2389cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
2390cdf0e10cSrcweir 
2391cdf0e10cSrcweir     StopClipboardListening( );
2392cdf0e10cSrcweir 
2393cdf0e10cSrcweir     mpImpl->mpClipboardListener = new TransferableClipboardNotifier( mxClipboard, *this, mpImpl->maMutex );
2394cdf0e10cSrcweir     mpImpl->mpClipboardListener->acquire();
2395cdf0e10cSrcweir 
2396cdf0e10cSrcweir     return mpImpl->mpClipboardListener->isListening();
2397cdf0e10cSrcweir }
2398cdf0e10cSrcweir 
2399cdf0e10cSrcweir // -----------------------------------------------------------------------------
2400cdf0e10cSrcweir 
2401cdf0e10cSrcweir void TransferableDataHelper::StopClipboardListening( )
2402cdf0e10cSrcweir {
2403cdf0e10cSrcweir     ::osl::MutexGuard aGuard( mpImpl->maMutex );
2404cdf0e10cSrcweir 
2405cdf0e10cSrcweir     if ( mpImpl->mpClipboardListener )
2406cdf0e10cSrcweir     {
2407cdf0e10cSrcweir         mpImpl->mpClipboardListener->dispose();
2408cdf0e10cSrcweir         mpImpl->mpClipboardListener->release();
2409cdf0e10cSrcweir         mpImpl->mpClipboardListener = NULL;
2410cdf0e10cSrcweir     }
2411cdf0e10cSrcweir }
2412cdf0e10cSrcweir 
2413cdf0e10cSrcweir // -----------------------------------------------------------------------------
2414cdf0e10cSrcweir 
2415cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSystemClipboard( Window * pWindow )
2416cdf0e10cSrcweir {
2417cdf0e10cSrcweir     DBG_ASSERT( pWindow, "Window pointer is NULL" );
2418cdf0e10cSrcweir 
2419cdf0e10cSrcweir     Reference< XClipboard > xClipboard;
2420cdf0e10cSrcweir     TransferableDataHelper  aRet;
2421cdf0e10cSrcweir 
2422cdf0e10cSrcweir     if( pWindow )
2423cdf0e10cSrcweir         xClipboard = pWindow->GetClipboard();
2424cdf0e10cSrcweir 
2425cdf0e10cSrcweir     if( xClipboard.is() )
2426cdf0e10cSrcweir     {
2427cdf0e10cSrcweir         try
2428cdf0e10cSrcweir 
2429cdf0e10cSrcweir         {
2430cdf0e10cSrcweir             Reference< XTransferable > xTransferable( xClipboard->getContents() );
2431cdf0e10cSrcweir 
2432cdf0e10cSrcweir             if( xTransferable.is() )
2433cdf0e10cSrcweir             {
2434cdf0e10cSrcweir                 aRet = TransferableDataHelper( xTransferable );
2435cdf0e10cSrcweir                 aRet.mxClipboard = xClipboard;
2436cdf0e10cSrcweir                     // also copy the clipboard - 99030 - 23.05.2002 - fs@openoffice.org
2437cdf0e10cSrcweir             }
2438cdf0e10cSrcweir         }
2439cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
2440cdf0e10cSrcweir         {
2441cdf0e10cSrcweir         }
2442cdf0e10cSrcweir     }
2443cdf0e10cSrcweir 
2444cdf0e10cSrcweir     return aRet;
2445cdf0e10cSrcweir }
2446cdf0e10cSrcweir 
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir // -----------------------------------------------------------------------------
2449cdf0e10cSrcweir 
2450cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSelection( Window* pWindow )
2451cdf0e10cSrcweir {
2452cdf0e10cSrcweir     DBG_ASSERT( pWindow, "Window pointer is NULL" );
2453cdf0e10cSrcweir 
2454cdf0e10cSrcweir     Reference< XClipboard > xSelection;
2455cdf0e10cSrcweir     TransferableDataHelper  aRet;
2456cdf0e10cSrcweir 
2457cdf0e10cSrcweir     if( pWindow )
2458cdf0e10cSrcweir         xSelection = pWindow->GetPrimarySelection();
2459cdf0e10cSrcweir 
2460cdf0e10cSrcweir     if( xSelection.is() )
2461cdf0e10cSrcweir     {
2462cdf0e10cSrcweir         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
2463cdf0e10cSrcweir 
2464cdf0e10cSrcweir         try
2465cdf0e10cSrcweir         {
2466cdf0e10cSrcweir             Reference< XTransferable > xTransferable( xSelection->getContents() );
2467cdf0e10cSrcweir 
2468cdf0e10cSrcweir             if( xTransferable.is() )
2469cdf0e10cSrcweir             {
2470cdf0e10cSrcweir                 aRet = TransferableDataHelper( xTransferable );
2471cdf0e10cSrcweir                 aRet.mxClipboard = xSelection;
2472cdf0e10cSrcweir             }
2473cdf0e10cSrcweir         }
2474cdf0e10cSrcweir         catch( const ::com::sun::star::uno::Exception& )
2475cdf0e10cSrcweir         {
2476cdf0e10cSrcweir         }
2477cdf0e10cSrcweir 
2478cdf0e10cSrcweir         Application::AcquireSolarMutex( nRef );
2479cdf0e10cSrcweir     }
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir     return aRet;
2482cdf0e10cSrcweir }
2483cdf0e10cSrcweir 
2484cdf0e10cSrcweir // -----------------------------------------------------------------------------
2485cdf0e10cSrcweir sal_Bool TransferableDataHelper::IsEqual( const ::com::sun::star::datatransfer::DataFlavor& rInternalFlavor,
2486cdf0e10cSrcweir                                           const ::com::sun::star::datatransfer::DataFlavor& rRequestFlavor,
2487cdf0e10cSrcweir                                           sal_Bool )
2488cdf0e10cSrcweir {
2489cdf0e10cSrcweir     Reference< XMultiServiceFactory >       xFact( ::comphelper::getProcessServiceFactory() );
2490cdf0e10cSrcweir     Reference< XMimeContentTypeFactory >    xMimeFact;
2491cdf0e10cSrcweir     sal_Bool                                bRet = sal_False;
2492cdf0e10cSrcweir 
2493cdf0e10cSrcweir     try
2494cdf0e10cSrcweir     {
2495cdf0e10cSrcweir         if( xFact.is() )
2496cdf0e10cSrcweir             xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii(
2497cdf0e10cSrcweir                                                               "com.sun.star.datatransfer.MimeContentTypeFactory" ) ),
2498cdf0e10cSrcweir                                                               UNO_QUERY );
2499cdf0e10cSrcweir 
2500cdf0e10cSrcweir         if( xMimeFact.is() )
2501cdf0e10cSrcweir         {
2502cdf0e10cSrcweir             Reference< XMimeContentType > xRequestType1( xMimeFact->createMimeContentType( rInternalFlavor.MimeType ) );
2503cdf0e10cSrcweir             Reference< XMimeContentType > xRequestType2( xMimeFact->createMimeContentType( rRequestFlavor.MimeType ) );
2504cdf0e10cSrcweir 
2505cdf0e10cSrcweir             if( xRequestType1.is() && xRequestType2.is() )
2506cdf0e10cSrcweir             {
2507cdf0e10cSrcweir                 if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( xRequestType2->getFullMediaType() ) )
2508cdf0e10cSrcweir                 {
2509cdf0e10cSrcweir                     if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) )
2510cdf0e10cSrcweir                     {
2511cdf0e10cSrcweir                         // special handling for text/plain media types
2512cdf0e10cSrcweir                         const ::rtl::OUString aCharsetString( ::rtl::OUString::createFromAscii( "charset" ) );
2513cdf0e10cSrcweir 
2514cdf0e10cSrcweir                         if( !xRequestType2->hasParameter( aCharsetString ) ||
2515cdf0e10cSrcweir                             xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) ||
2516cdf0e10cSrcweir                             xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) )
2517cdf0e10cSrcweir                         {
2518cdf0e10cSrcweir                             bRet = sal_True;
2519cdf0e10cSrcweir                         }
2520cdf0e10cSrcweir                     }
2521cdf0e10cSrcweir                     else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice" ) ) )
2522cdf0e10cSrcweir                     {
2523cdf0e10cSrcweir                         // special handling for application/x-openoffice media types
2524cdf0e10cSrcweir                         const ::rtl::OUString aFormatString( ::rtl::OUString::createFromAscii( "windows_formatname" ) );
2525cdf0e10cSrcweir 
2526cdf0e10cSrcweir                         if( xRequestType1->hasParameter( aFormatString ) &&
2527cdf0e10cSrcweir                             xRequestType2->hasParameter( aFormatString ) &&
2528cdf0e10cSrcweir                             xRequestType1->getParameterValue( aFormatString ).equalsIgnoreAsciiCase( xRequestType2->getParameterValue( aFormatString ) ) )
2529cdf0e10cSrcweir                         {
2530cdf0e10cSrcweir                             bRet = sal_True;
2531cdf0e10cSrcweir                         }
2532cdf0e10cSrcweir                     }
2533cdf0e10cSrcweir                     else
2534cdf0e10cSrcweir                         bRet = sal_True;
2535cdf0e10cSrcweir                 }
2536cdf0e10cSrcweir             }
2537cdf0e10cSrcweir         }
2538cdf0e10cSrcweir     }
2539cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
2540cdf0e10cSrcweir     {
2541cdf0e10cSrcweir         bRet = rInternalFlavor.MimeType.equalsIgnoreAsciiCase( rRequestFlavor.MimeType );
2542cdf0e10cSrcweir     }
2543cdf0e10cSrcweir 
2544cdf0e10cSrcweir     return bRet;
2545cdf0e10cSrcweir }
2546