1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Os2Transferable.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #if OSL_DEBUG_LEVEL > 1
39 #include <com/sun/star/io/IOException.hpp>
40 #include "Os2Transferable.hxx"
42 using namespace com::sun::star::datatransfer
;
43 using namespace com::sun::star::lang
;
44 using namespace com::sun::star::io
;
45 using namespace com::sun::star::uno
;
51 // =======================================================================
53 Os2Transferable::Os2Transferable(
54 const Reference
< XInterface
>& xCreator
) :
55 m_xCreator( xCreator
)
57 debug_printf("Os2Transferable::Os2Transferable %08x\n", this);
58 hAB
= WinQueryAnchorBlock( HWND_DESKTOP
);
60 // query clipboard data to get mimetype
61 if( UWinOpenClipbrd( hAB
) )
63 ULONG handle
= UWinQueryClipbrdData( hAB
, UCLIP_CF_UNICODETEXT
);
65 aFlavor
.MimeType
= OUString::createFromAscii( "text/plain;charset=utf-16" );
66 aFlavor
.DataType
= getCppuType( (OUString
*)0 );
67 //debug_printf("Os2Transferable::Os2Transferable pszText %s\n", pszText);
69 handle
= UWinQueryClipbrdData( hAB
, UCLIP_CF_BITMAP
);
71 aFlavor
.MimeType
= OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" );
72 aFlavor
.DataType
= getCppuType( (OUString
*)0 );
73 //debug_printf("Os2Transferable::Os2Transferable pszText %s\n", pszText);
75 UWinCloseClipbrd( hAB
);
79 debug_printf("Os2Transferable::Os2Transferable failed to open clipboard\n");
84 //==================================================================================================
86 Os2Transferable::~Os2Transferable()
88 debug_printf("Os2Transferable::~Os2Transferable %08x\n", this);
91 //==================================================================================================
93 Any SAL_CALL
Os2Transferable::getTransferData( const DataFlavor
& rFlavor
)
94 throw(UnsupportedFlavorException
, IOException
, RuntimeException
)
96 debug_printf("Os2Transferable::getTransferData %08x\n", this);
97 debug_printf("Os2Transferable::getTransferData mimetype: %s\n", CHAR_POINTER(rFlavor
.MimeType
));
99 Sequence
< sal_Int8
> aData
;
101 // retrieve unicode text
102 if( rFlavor
.MimeType
.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) )
104 if( UWinOpenClipbrd( hAB
) )
106 // check if clipboard has text format
107 sal_Unicode
* pszText
= (sal_Unicode
*) UWinQueryClipbrdData( hAB
, UCLIP_CF_UNICODETEXT
);
109 // convert to oustring and return it
110 OUString
aString( pszText
);
113 UWinCloseClipbrd( hAB
);
120 if( rFlavor
.MimeType
.equalsIgnoreAsciiCase( OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) ) )
122 if( UWinOpenClipbrd( hAB
) )
124 // check if clipboard has text format
125 ULONG handle
= UWinQueryClipbrdData( hAB
, UCLIP_CF_BITMAP
);
127 Sequence
< sal_Int8
> winDIBStream
;
128 // convert to oustring and return it
129 if (OS2HandleToOOoBmp( handle
, &winDIBStream
))
130 aRet
<<= winDIBStream
;
134 UWinCloseClipbrd( hAB
);
140 // clipboard format unsupported, throw exception
141 throw UnsupportedFlavorException( rFlavor
.MimeType
, static_cast < XTransferable
* > ( this ) );
144 //==================================================================================================
146 Sequence
< DataFlavor
> SAL_CALL
Os2Transferable::getTransferDataFlavors()
147 throw(RuntimeException
)
149 debug_printf("Os2Transferable::getTransferDataFlavors %08x\n", this);
150 Sequence
< DataFlavor
> aFlavorList(1);
151 aFlavorList
[0] = aFlavor
;
152 debug_printf("Os2Transferable::getTransferDataFlavors mimetype: %s\n", CHAR_POINTER(aFlavor
.MimeType
));
156 //==================================================================================================
158 sal_Bool SAL_CALL
Os2Transferable::isDataFlavorSupported( const DataFlavor
& aFlavor
)
159 throw(RuntimeException
)
161 debug_printf("Os2Transferable::isDataFlavorSupported %08x\n", this);
162 debug_printf("Os2Transferable::isDataFlavorSupported %s\n", CHAR_POINTER(aFlavor
.MimeType
));
164 if( aFlavor
.DataType
!= getCppuType( (Sequence
< sal_Int8
>*)0 ) )
166 if( ! aFlavor
.MimeType
.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) &&
167 aFlavor
.DataType
== getCppuType( (OUString
*)0 ) )
171 Sequence
< DataFlavor
> aFlavors( getTransferDataFlavors() );
172 for( int i
= 0; i
< aFlavors
.getLength(); i
++ )
173 if( aFlavor
.MimeType
.equalsIgnoreAsciiCase( aFlavors
.getConstArray()[i
].MimeType
) &&
174 aFlavor
.DataType
== aFlavors
.getConstArray()[i
].DataType
)