1*48123e16SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*48123e16SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*48123e16SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*48123e16SAndrew Rist * distributed with this work for additional information
6*48123e16SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*48123e16SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*48123e16SAndrew Rist * "License"); you may not use this file except in compliance
9*48123e16SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*48123e16SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*48123e16SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*48123e16SAndrew Rist * software distributed under the License is distributed on an
15*48123e16SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*48123e16SAndrew Rist * KIND, either express or implied. See the License for the
17*48123e16SAndrew Rist * specific language governing permissions and limitations
18*48123e16SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*48123e16SAndrew Rist *************************************************************/
21*48123e16SAndrew Rist
22*48123e16SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
25cdf0e10cSrcweir #include <stdio.h>
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir
28cdf0e10cSrcweir #define INCL_WIN
29cdf0e10cSrcweir #include <svpm.h>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <string.h>
32cdf0e10cSrcweir #include <com/sun/star/io/IOException.hpp>
33cdf0e10cSrcweir #include "Os2Transferable.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir using namespace com::sun::star::datatransfer;
36cdf0e10cSrcweir using namespace com::sun::star::lang;
37cdf0e10cSrcweir using namespace com::sun::star::io;
38cdf0e10cSrcweir using namespace com::sun::star::uno;
39cdf0e10cSrcweir using namespace cppu;
40cdf0e10cSrcweir using namespace osl;
41cdf0e10cSrcweir using namespace rtl;
42cdf0e10cSrcweir using namespace os2;
43cdf0e10cSrcweir
44cdf0e10cSrcweir // =======================================================================
45cdf0e10cSrcweir
Os2Transferable(const Reference<XInterface> & xCreator)46cdf0e10cSrcweir Os2Transferable::Os2Transferable(
47cdf0e10cSrcweir const Reference< XInterface >& xCreator ) :
48cdf0e10cSrcweir m_xCreator( xCreator )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir debug_printf("Os2Transferable::Os2Transferable %08x\n", this);
51cdf0e10cSrcweir hAB = WinQueryAnchorBlock( HWND_DESKTOP );
52cdf0e10cSrcweir
53cdf0e10cSrcweir // query clipboard data to get mimetype
54cdf0e10cSrcweir if( UWinOpenClipbrd( hAB ) )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir ULONG handle = UWinQueryClipbrdData( hAB, UCLIP_CF_UNICODETEXT);
57cdf0e10cSrcweir if (handle) {
58cdf0e10cSrcweir aFlavor.MimeType = OUString::createFromAscii( "text/plain;charset=utf-16" );
59cdf0e10cSrcweir aFlavor.DataType = getCppuType( (OUString*)0 );
60cdf0e10cSrcweir //debug_printf("Os2Transferable::Os2Transferable pszText %s\n", pszText);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir handle = UWinQueryClipbrdData( hAB, UCLIP_CF_BITMAP);
63cdf0e10cSrcweir if (handle) {
64cdf0e10cSrcweir aFlavor.MimeType = OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" );
65cdf0e10cSrcweir aFlavor.DataType = getCppuType( (OUString*)0 );
66cdf0e10cSrcweir //debug_printf("Os2Transferable::Os2Transferable pszText %s\n", pszText);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir UWinCloseClipbrd( hAB);
69cdf0e10cSrcweir }
70cdf0e10cSrcweir else
71cdf0e10cSrcweir {
72cdf0e10cSrcweir debug_printf("Os2Transferable::Os2Transferable failed to open clipboard\n");
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir //==================================================================================================
78cdf0e10cSrcweir
~Os2Transferable()79cdf0e10cSrcweir Os2Transferable::~Os2Transferable()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir debug_printf("Os2Transferable::~Os2Transferable %08x\n", this);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir //==================================================================================================
85cdf0e10cSrcweir
getTransferData(const DataFlavor & rFlavor)86cdf0e10cSrcweir Any SAL_CALL Os2Transferable::getTransferData( const DataFlavor& rFlavor )
87cdf0e10cSrcweir throw(UnsupportedFlavorException, IOException, RuntimeException)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferData %08x\n", this);
90cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferData mimetype: %s\n", CHAR_POINTER(rFlavor.MimeType));
91cdf0e10cSrcweir Any aRet;
92cdf0e10cSrcweir Sequence< sal_Int8 > aData;
93cdf0e10cSrcweir
94cdf0e10cSrcweir // retrieve unicode text
95cdf0e10cSrcweir if( rFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir if( UWinOpenClipbrd( hAB ) )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir // check if clipboard has text format
100cdf0e10cSrcweir sal_Unicode* pszText = (sal_Unicode*) UWinQueryClipbrdData( hAB, UCLIP_CF_UNICODETEXT);
101cdf0e10cSrcweir if (pszText) {
102cdf0e10cSrcweir // convert to oustring and return it
103cdf0e10cSrcweir OUString aString( pszText);
104cdf0e10cSrcweir aRet <<= aString;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir UWinCloseClipbrd( hAB );
107cdf0e10cSrcweir if (pszText)
108cdf0e10cSrcweir return aRet;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
112a7e9c4d8SPedro Giffuni // retrieve bitmap
113a7e9c4d8SPedro Giffuni if( rFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) ) )
114a7e9c4d8SPedro Giffuni {
115a7e9c4d8SPedro Giffuni if( UWinOpenClipbrd( hAB ) )
116a7e9c4d8SPedro Giffuni {
117a7e9c4d8SPedro Giffuni // check if clipboard has text format
118a7e9c4d8SPedro Giffuni ULONG handle = UWinQueryClipbrdData( hAB, UCLIP_CF_BITMAP);
119a7e9c4d8SPedro Giffuni if (handle) {
120a7e9c4d8SPedro Giffuni Sequence< sal_Int8 > winDIBStream;
121a7e9c4d8SPedro Giffuni // convert to oustring and return it
122a7e9c4d8SPedro Giffuni if (OS2HandleToOOoBmp( handle, &winDIBStream))
123a7e9c4d8SPedro Giffuni aRet <<= winDIBStream;
124a7e9c4d8SPedro Giffuni else
125a7e9c4d8SPedro Giffuni handle = 0;
126a7e9c4d8SPedro Giffuni }
127a7e9c4d8SPedro Giffuni UWinCloseClipbrd( hAB );
128a7e9c4d8SPedro Giffuni if (handle)
129a7e9c4d8SPedro Giffuni return aRet;
130a7e9c4d8SPedro Giffuni }
131a7e9c4d8SPedro Giffuni }
132a7e9c4d8SPedro Giffuni
133cdf0e10cSrcweir // clipboard format unsupported, throw exception
134cdf0e10cSrcweir throw UnsupportedFlavorException( rFlavor.MimeType, static_cast < XTransferable * > ( this ) );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir //==================================================================================================
138cdf0e10cSrcweir
getTransferDataFlavors()139cdf0e10cSrcweir Sequence< DataFlavor > SAL_CALL Os2Transferable::getTransferDataFlavors()
140cdf0e10cSrcweir throw(RuntimeException)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferDataFlavors %08x\n", this);
143cdf0e10cSrcweir Sequence< DataFlavor > aFlavorList(1);
144cdf0e10cSrcweir aFlavorList[0] = aFlavor;
145cdf0e10cSrcweir debug_printf("Os2Transferable::getTransferDataFlavors mimetype: %s\n", CHAR_POINTER(aFlavor.MimeType));
146cdf0e10cSrcweir return aFlavorList;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir //==================================================================================================
150cdf0e10cSrcweir
isDataFlavorSupported(const DataFlavor & aFlavor)151cdf0e10cSrcweir sal_Bool SAL_CALL Os2Transferable::isDataFlavorSupported( const DataFlavor& aFlavor )
152cdf0e10cSrcweir throw(RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir debug_printf("Os2Transferable::isDataFlavorSupported %08x\n", this);
155cdf0e10cSrcweir debug_printf("Os2Transferable::isDataFlavorSupported %s\n", CHAR_POINTER(aFlavor.MimeType));
156cdf0e10cSrcweir
157cdf0e10cSrcweir if( aFlavor.DataType != getCppuType( (Sequence< sal_Int8 >*)0 ) )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir if( ! aFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) &&
160cdf0e10cSrcweir aFlavor.DataType == getCppuType( (OUString*)0 ) )
161cdf0e10cSrcweir return false;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir Sequence< DataFlavor > aFlavors( getTransferDataFlavors() );
165cdf0e10cSrcweir for( int i = 0; i < aFlavors.getLength(); i++ )
166cdf0e10cSrcweir if( aFlavor.MimeType.equalsIgnoreAsciiCase( aFlavors.getConstArray()[i].MimeType ) &&
167cdf0e10cSrcweir aFlavor.DataType == aFlavors.getConstArray()[i].DataType )
168cdf0e10cSrcweir return sal_True;
169cdf0e10cSrcweir
170cdf0e10cSrcweir return sal_False;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173