1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 29*cdf0e10cSrcweir #include <stdio.h> 30*cdf0e10cSrcweir #endif 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #define INCL_WIN 33*cdf0e10cSrcweir #include <svpm.h> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <string.h> 36*cdf0e10cSrcweir #include <com/sun/star/io/IOException.hpp> 37*cdf0e10cSrcweir #include "Os2Transferable.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace com::sun::star::datatransfer; 40*cdf0e10cSrcweir using namespace com::sun::star::lang; 41*cdf0e10cSrcweir using namespace com::sun::star::io; 42*cdf0e10cSrcweir using namespace com::sun::star::uno; 43*cdf0e10cSrcweir using namespace cppu; 44*cdf0e10cSrcweir using namespace osl; 45*cdf0e10cSrcweir using namespace rtl; 46*cdf0e10cSrcweir using namespace os2; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir // ======================================================================= 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir Os2Transferable::Os2Transferable( 51*cdf0e10cSrcweir const Reference< XInterface >& xCreator ) : 52*cdf0e10cSrcweir m_xCreator( xCreator ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir debug_printf("Os2Transferable::Os2Transferable %08x\n", this); 55*cdf0e10cSrcweir hAB = WinQueryAnchorBlock( HWND_DESKTOP ); 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // query clipboard data to get mimetype 58*cdf0e10cSrcweir if( UWinOpenClipbrd( hAB ) ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir ULONG handle = UWinQueryClipbrdData( hAB, UCLIP_CF_UNICODETEXT); 61*cdf0e10cSrcweir if (handle) { 62*cdf0e10cSrcweir aFlavor.MimeType = OUString::createFromAscii( "text/plain;charset=utf-16" ); 63*cdf0e10cSrcweir aFlavor.DataType = getCppuType( (OUString*)0 ); 64*cdf0e10cSrcweir //debug_printf("Os2Transferable::Os2Transferable pszText %s\n", pszText); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir handle = UWinQueryClipbrdData( hAB, UCLIP_CF_BITMAP); 67*cdf0e10cSrcweir if (handle) { 68*cdf0e10cSrcweir aFlavor.MimeType = OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ); 69*cdf0e10cSrcweir aFlavor.DataType = getCppuType( (OUString*)0 ); 70*cdf0e10cSrcweir //debug_printf("Os2Transferable::Os2Transferable pszText %s\n", pszText); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir UWinCloseClipbrd( hAB); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir else 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir debug_printf("Os2Transferable::Os2Transferable failed to open clipboard\n"); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir //================================================================================================== 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir Os2Transferable::~Os2Transferable() 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir debug_printf("Os2Transferable::~Os2Transferable %08x\n", this); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //================================================================================================== 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir Any SAL_CALL Os2Transferable::getTransferData( const DataFlavor& rFlavor ) 91*cdf0e10cSrcweir throw(UnsupportedFlavorException, IOException, RuntimeException) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferData %08x\n", this); 94*cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferData mimetype: %s\n", CHAR_POINTER(rFlavor.MimeType)); 95*cdf0e10cSrcweir Any aRet; 96*cdf0e10cSrcweir Sequence< sal_Int8 > aData; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // retrieve unicode text 99*cdf0e10cSrcweir if( rFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if( UWinOpenClipbrd( hAB ) ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir // check if clipboard has text format 104*cdf0e10cSrcweir sal_Unicode* pszText = (sal_Unicode*) UWinQueryClipbrdData( hAB, UCLIP_CF_UNICODETEXT); 105*cdf0e10cSrcweir if (pszText) { 106*cdf0e10cSrcweir // convert to oustring and return it 107*cdf0e10cSrcweir OUString aString( pszText); 108*cdf0e10cSrcweir aRet <<= aString; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir UWinCloseClipbrd( hAB ); 111*cdf0e10cSrcweir if (pszText) 112*cdf0e10cSrcweir return aRet; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // retrieve bitmap 117*cdf0e10cSrcweir if( rFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) ) ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir if( UWinOpenClipbrd( hAB ) ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir // check if clipboard has text format 122*cdf0e10cSrcweir ULONG handle = UWinQueryClipbrdData( hAB, UCLIP_CF_BITMAP); 123*cdf0e10cSrcweir if (handle) { 124*cdf0e10cSrcweir Sequence< sal_Int8 > winDIBStream; 125*cdf0e10cSrcweir // convert to oustring and return it 126*cdf0e10cSrcweir if (OS2HandleToOOoBmp( handle, &winDIBStream)) 127*cdf0e10cSrcweir aRet <<= winDIBStream; 128*cdf0e10cSrcweir else 129*cdf0e10cSrcweir handle = 0; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir UWinCloseClipbrd( hAB ); 132*cdf0e10cSrcweir if (handle) 133*cdf0e10cSrcweir return aRet; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // clipboard format unsupported, throw exception 138*cdf0e10cSrcweir throw UnsupportedFlavorException( rFlavor.MimeType, static_cast < XTransferable * > ( this ) ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //================================================================================================== 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir Sequence< DataFlavor > SAL_CALL Os2Transferable::getTransferDataFlavors() 144*cdf0e10cSrcweir throw(RuntimeException) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferDataFlavors %08x\n", this); 147*cdf0e10cSrcweir Sequence< DataFlavor > aFlavorList(1); 148*cdf0e10cSrcweir aFlavorList[0] = aFlavor; 149*cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferDataFlavors mimetype: %s\n", CHAR_POINTER(aFlavor.MimeType)); 150*cdf0e10cSrcweir return aFlavorList; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir //================================================================================================== 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir sal_Bool SAL_CALL Os2Transferable::isDataFlavorSupported( const DataFlavor& aFlavor ) 156*cdf0e10cSrcweir throw(RuntimeException) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir debug_printf("Os2Transferable::isDataFlavorSupported %08x\n", this); 159*cdf0e10cSrcweir debug_printf("Os2Transferable::isDataFlavorSupported %s\n", CHAR_POINTER(aFlavor.MimeType)); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir if( aFlavor.DataType != getCppuType( (Sequence< sal_Int8 >*)0 ) ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir if( ! aFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) && 164*cdf0e10cSrcweir aFlavor.DataType == getCppuType( (OUString*)0 ) ) 165*cdf0e10cSrcweir return false; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir Sequence< DataFlavor > aFlavors( getTransferDataFlavors() ); 169*cdf0e10cSrcweir for( int i = 0; i < aFlavors.getLength(); i++ ) 170*cdf0e10cSrcweir if( aFlavor.MimeType.equalsIgnoreAsciiCase( aFlavors.getConstArray()[i].MimeType ) && 171*cdf0e10cSrcweir aFlavor.DataType == aFlavors.getConstArray()[i].DataType ) 172*cdf0e10cSrcweir return sal_True; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir return sal_False; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177