1*cc13e73eSYuri Dario /**************************************************************
2*cc13e73eSYuri Dario *
3*cc13e73eSYuri Dario * Licensed to the Apache Software Foundation (ASF) under one
4*cc13e73eSYuri Dario * or more contributor license agreements.  See the NOTICE file
5*cc13e73eSYuri Dario * distributed with this work for additional information
6*cc13e73eSYuri Dario * regarding copyright ownership.  The ASF licenses this file
7*cc13e73eSYuri Dario * to you under the Apache License, Version 2.0 (the
8*cc13e73eSYuri Dario * "License"); you may not use this file except in compliance
9*cc13e73eSYuri Dario * with the License.  You may obtain a copy of the License at
10*cc13e73eSYuri Dario *
11*cc13e73eSYuri Dario *   http://www.apache.org/licenses/LICENSE-2.0
12*cc13e73eSYuri Dario *
13*cc13e73eSYuri Dario * Unless required by applicable law or agreed to in writing,
14*cc13e73eSYuri Dario * software distributed under the License is distributed on an
15*cc13e73eSYuri Dario * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cc13e73eSYuri Dario * KIND, either express or implied.  See the License for the
17*cc13e73eSYuri Dario * specific language governing permissions and limitations
18*cc13e73eSYuri Dario * under the License.
19*cc13e73eSYuri Dario *
20*cc13e73eSYuri Dario *************************************************************/
21*cc13e73eSYuri Dario 
22*cc13e73eSYuri Dario 
23*cc13e73eSYuri Dario // MARKER(update_precomp.py): autogen include statement, do not remove
24*cc13e73eSYuri Dario #include "precompiled_dtrans.hxx"
25*cc13e73eSYuri Dario 
26*cc13e73eSYuri Dario #define INCL_DOSERRORS
27*cc13e73eSYuri Dario 
28*cc13e73eSYuri Dario #include <stdio.h>
29*cc13e73eSYuri Dario #include <string.h>
30*cc13e73eSYuri Dario #include <unistd.h>
31*cc13e73eSYuri Dario 
32*cc13e73eSYuri Dario #include <rtl/string.hxx>
33*cc13e73eSYuri Dario 
34*cc13e73eSYuri Dario #include "OTransferable.hxx"
35*cc13e73eSYuri Dario #include "globals.hxx"
36*cc13e73eSYuri Dario 
37*cc13e73eSYuri Dario 
OTransferable(HWND hwndTarget,PDRAGINFO dragInfo)38*cc13e73eSYuri Dario OTransferable::OTransferable( HWND hwndTarget, PDRAGINFO dragInfo)
39*cc13e73eSYuri Dario     : m_aFlavorList( 1),
40*cc13e73eSYuri Dario       mHwndTarget( hwndTarget),
41*cc13e73eSYuri Dario       mDragInfo( dragInfo),
42*cc13e73eSYuri Dario       removeOnExit( false),
43*cc13e73eSYuri Dario       pDTShare( NULL),
44*cc13e73eSYuri Dario       renderDRM( DRM_NULL),
45*cc13e73eSYuri Dario       mimeType( MIMETYPE_NULL)
46*cc13e73eSYuri Dario {
47*cc13e73eSYuri Dario     USHORT cItems;
48*cc13e73eSYuri Dario     PDRAGITEM dragItem;
49*cc13e73eSYuri Dario     PSZ pNativeRMF;
50*cc13e73eSYuri Dario 
51*cc13e73eSYuri Dario     strcpy( fullpath, "");
52*cc13e73eSYuri Dario 
53*cc13e73eSYuri Dario     cItems = DrgQueryDragitemCount(dragInfo);
54*cc13e73eSYuri Dario     if (cItems > 1) {
55*cc13e73eSYuri Dario         debug_printf("OTransferable::OTransferable multiple drop not supported");
56*cc13e73eSYuri Dario         return;
57*cc13e73eSYuri Dario     }
58*cc13e73eSYuri Dario 
59*cc13e73eSYuri Dario     ULONG ulLength;
60*cc13e73eSYuri Dario     PSZ pBuffer;
61*cc13e73eSYuri Dario 
62*cc13e73eSYuri Dario     // get 1st item
63*cc13e73eSYuri Dario     dragItem = DrgQueryDragitemPtr(dragInfo, 0);
64*cc13e73eSYuri Dario 
65*cc13e73eSYuri Dario     // dump true type
66*cc13e73eSYuri Dario     ulLength = DrgQueryTrueTypeLen( dragItem) + 1;
67*cc13e73eSYuri Dario     pBuffer = (PSZ) malloc( ulLength);
68*cc13e73eSYuri Dario     DrgQueryTrueType( dragItem, ulLength, pBuffer);
69*cc13e73eSYuri Dario     debug_printf("DrgQueryTrueType %s", pBuffer);
70*cc13e73eSYuri Dario     free( pBuffer);
71*cc13e73eSYuri Dario 
72*cc13e73eSYuri Dario     // get native RMF format
73*cc13e73eSYuri Dario     ulLength = DrgQueryNativeRMFLen( dragItem) + 1;
74*cc13e73eSYuri Dario     pNativeRMF = (PSZ) malloc( ulLength);
75*cc13e73eSYuri Dario     DrgQueryNativeRMF( dragItem, ulLength, pNativeRMF);
76*cc13e73eSYuri Dario     debug_printf("OTransferable::OTransferable DrgQueryNativeRMF %s", pNativeRMF);
77*cc13e73eSYuri Dario 
78*cc13e73eSYuri Dario     debug_printf("OTransferable::OTransferable DrgVerifyRMF DRM_ATOM %d", DrgVerifyRMF( dragItem, "DRM_ATOM", NULL));
79*cc13e73eSYuri Dario     debug_printf("OTransferable::OTransferable DrgVerifyRMF DRM_OS2FILE %d", DrgVerifyRMF( dragItem, "DRM_OS2FILE", NULL));
80*cc13e73eSYuri Dario     debug_printf("OTransferable::OTransferable DrgVerifyRMF DRM_PRINTOBJECT %d", DrgVerifyRMF( dragItem, "DRM_PRINTOBJECT", NULL));
81*cc13e73eSYuri Dario     debug_printf("OTransferable::OTransferable DrgVerifyRMF DRM_SHAREDMEM %d", DrgVerifyRMF( dragItem, "DRM_SHAREDMEM", NULL));
82*cc13e73eSYuri Dario     debug_printf("OTransferable::OTransferable DrgVerifyRMF DRM_DTSHARE %d", DrgVerifyRMF( dragItem, "DRM_DTSHARE", NULL));
83*cc13e73eSYuri Dario 
84*cc13e73eSYuri Dario     DataFlavor df;
85*cc13e73eSYuri Dario 
86*cc13e73eSYuri Dario     if (strstr( pNativeRMF, "<DRM_ATOM") != 0
87*cc13e73eSYuri Dario             || strstr( pNativeRMF, "<DRM_DTSHARE") != 0
88*cc13e73eSYuri Dario             || strstr( pNativeRMF, "<DRM_SHAREDMEM") != 0) {
89*cc13e73eSYuri Dario 
90*cc13e73eSYuri Dario         df.MimeType = OUString::createFromAscii( "text/plain;charset=utf-16" );
91*cc13e73eSYuri Dario         df.DataType = getCppuType( static_cast<rtl::OUString*>(0));
92*cc13e73eSYuri Dario         m_aFlavorList[0] = df;
93*cc13e73eSYuri Dario         mimeType = MIMETYPE_TEXT;
94*cc13e73eSYuri Dario 
95*cc13e73eSYuri Dario     } else if (strstr( pNativeRMF, "<DRM_OS2FILE") != 0) {
96*cc13e73eSYuri Dario 
97*cc13e73eSYuri Dario         df.MimeType = OUString::createFromAscii(
98*cc13e73eSYuri Dario                     "application/x-openoffice-file;windows_formatname=\"FileName\"");
99*cc13e73eSYuri Dario         df.DataType = getCppuType( static_cast<OUString*>(0));
100*cc13e73eSYuri Dario         m_aFlavorList[0] = df;
101*cc13e73eSYuri Dario         mimeType = MIMETYPE_FILE;
102*cc13e73eSYuri Dario 
103*cc13e73eSYuri Dario     } else {
104*cc13e73eSYuri Dario 
105*cc13e73eSYuri Dario         mimeType = MIMETYPE_NULL;
106*cc13e73eSYuri Dario         debug_printf("OTransferable::OTransferable UNKNOWN native RMF");
107*cc13e73eSYuri Dario 
108*cc13e73eSYuri Dario     }
109*cc13e73eSYuri Dario 
110*cc13e73eSYuri Dario     free( pNativeRMF);
111*cc13e73eSYuri Dario 
112*cc13e73eSYuri Dario }
113*cc13e73eSYuri Dario 
~OTransferable()114*cc13e73eSYuri Dario OTransferable::~OTransferable()
115*cc13e73eSYuri Dario {
116*cc13e73eSYuri Dario     if (removeOnExit) {
117*cc13e73eSYuri Dario         int rc;
118*cc13e73eSYuri Dario         rc = unlink( fullpath);
119*cc13e73eSYuri Dario         debug_printf( "OTransferable::~OTransferable unlink rc=%d", rc);
120*cc13e73eSYuri Dario     }
121*cc13e73eSYuri Dario }
122*cc13e73eSYuri Dario 
123*cc13e73eSYuri Dario 
124*cc13e73eSYuri Dario //
125*cc13e73eSYuri Dario // a generic request dispatcher
126*cc13e73eSYuri Dario //
RequestFileRendering(PDRAGITEM pditem,HWND hwnd,PCSZ pRMF,PCSZ pName)127*cc13e73eSYuri Dario bool OTransferable::RequestFileRendering( PDRAGITEM pditem, HWND hwnd,
128*cc13e73eSYuri Dario                                           PCSZ pRMF, PCSZ pName)
129*cc13e73eSYuri Dario {
130*cc13e73eSYuri Dario     PDRAGTRANSFER pdxfer;
131*cc13e73eSYuri Dario 
132*cc13e73eSYuri Dario     pdxfer = DrgAllocDragtransfer( 1);
133*cc13e73eSYuri Dario     if (!pdxfer)
134*cc13e73eSYuri Dario         return true;
135*cc13e73eSYuri Dario 
136*cc13e73eSYuri Dario     pdxfer->cb = sizeof(DRAGTRANSFER);
137*cc13e73eSYuri Dario     pdxfer->hwndClient = hwnd;
138*cc13e73eSYuri Dario     pdxfer->pditem = pditem;
139*cc13e73eSYuri Dario     pdxfer->hstrSelectedRMF = DrgAddStrHandle( pRMF);
140*cc13e73eSYuri Dario     pdxfer->hstrRenderToName = 0;
141*cc13e73eSYuri Dario     pdxfer->ulTargetInfo = pditem->ulItemID;
142*cc13e73eSYuri Dario     pdxfer->usOperation = (USHORT)DO_COPY;
143*cc13e73eSYuri Dario     pdxfer->fsReply = 0;
144*cc13e73eSYuri Dario 
145*cc13e73eSYuri Dario     // send the msg before setting a render-to name
146*cc13e73eSYuri Dario     if (pditem->fsControl & DC_PREPAREITEM)
147*cc13e73eSYuri Dario         DrgSendTransferMsg( pditem->hwndItem, DM_RENDERPREPARE, (MPARAM)pdxfer, 0);
148*cc13e73eSYuri Dario 
149*cc13e73eSYuri Dario     if (pName)
150*cc13e73eSYuri Dario         pdxfer->hstrRenderToName = DrgAddStrHandle( pName);
151*cc13e73eSYuri Dario     else
152*cc13e73eSYuri Dario         pdxfer->hstrRenderToName = 0;
153*cc13e73eSYuri Dario 
154*cc13e73eSYuri Dario     // send the msg after setting a render-to name
155*cc13e73eSYuri Dario     if ((pditem->fsControl & (DC_PREPARE | DC_PREPAREITEM)) == DC_PREPARE)
156*cc13e73eSYuri Dario         DrgSendTransferMsg( pditem->hwndItem, DM_RENDERPREPARE, (MPARAM)pdxfer, 0);
157*cc13e73eSYuri Dario 
158*cc13e73eSYuri Dario     // ask the source to render the selected item
159*cc13e73eSYuri Dario     if (!DrgSendTransferMsg( pditem->hwndItem, DM_RENDER, (MPARAM)pdxfer, 0))
160*cc13e73eSYuri Dario         return true;
161*cc13e73eSYuri Dario 
162*cc13e73eSYuri Dario     return false;
163*cc13e73eSYuri Dario }
164*cc13e73eSYuri Dario 
165*cc13e73eSYuri Dario // currently, the same filename is used for every render request;
166*cc13e73eSYuri Dario // it is deleted when the drag session ends
167*cc13e73eSYuri Dario //
RenderToOS2File(PDRAGITEM pditem,HWND hwnd)168*cc13e73eSYuri Dario bool OTransferable::RenderToOS2File( PDRAGITEM pditem, HWND hwnd)
169*cc13e73eSYuri Dario {
170*cc13e73eSYuri Dario     bool rv = true;
171*cc13e73eSYuri Dario 
172*cc13e73eSYuri Dario     const char * pszRMF;
173*cc13e73eSYuri Dario     if (DrgVerifyRMF(pditem, "DRM_OS2FILE", "DRF_TEXT"))
174*cc13e73eSYuri Dario         pszRMF = OS2FILE_TXTRMF;
175*cc13e73eSYuri Dario     else
176*cc13e73eSYuri Dario         pszRMF = OS2FILE_UNKRMF;
177*cc13e73eSYuri Dario 
178*cc13e73eSYuri Dario     // create temp name
179*cc13e73eSYuri Dario     strcpy( fullpath, tempnam( NULL, "AOO"));
180*cc13e73eSYuri Dario     debug_printf("OTransferable::RenderToOS2File to %s", fullpath);
181*cc13e73eSYuri Dario 
182*cc13e73eSYuri Dario     rv = RequestFileRendering( pditem, hwnd, pszRMF, fullpath);
183*cc13e73eSYuri Dario 
184*cc13e73eSYuri Dario     return rv;
185*cc13e73eSYuri Dario }
186*cc13e73eSYuri Dario 
187*cc13e73eSYuri Dario // DTShare uses 1mb of uncommitted named-shared memory
188*cc13e73eSYuri Dario // (next time I'll do it differently - rw)
189*cc13e73eSYuri Dario //
RenderToDTShare(PDRAGITEM pditem,HWND hwnd)190*cc13e73eSYuri Dario bool OTransferable::RenderToDTShare( PDRAGITEM pditem, HWND hwnd)
191*cc13e73eSYuri Dario {
192*cc13e73eSYuri Dario     bool rv;
193*cc13e73eSYuri Dario 
194*cc13e73eSYuri Dario     APIRET rc = DosAllocSharedMem( &pDTShare, DTSHARE_NAME, 0x100000,
195*cc13e73eSYuri Dario                                    PAG_WRITE | PAG_READ | OBJ_ANY);
196*cc13e73eSYuri Dario     if (rc != NO_ERROR &&
197*cc13e73eSYuri Dario             rc != ERROR_ALREADY_EXISTS) { // Did the kernel handle OBJ_ANY?
198*cc13e73eSYuri Dario         // Try again without OBJ_ANY and if the first failure was not caused
199*cc13e73eSYuri Dario         // by OBJ_ANY then we will get the same failure, else we have taken
200*cc13e73eSYuri Dario         // care of pre-FP13 systems where the kernel couldn't handle it.
201*cc13e73eSYuri Dario         rc = DosAllocSharedMem( &pDTShare, DTSHARE_NAME, 0x100000,
202*cc13e73eSYuri Dario                                 PAG_WRITE | PAG_READ);
203*cc13e73eSYuri Dario     }
204*cc13e73eSYuri Dario 
205*cc13e73eSYuri Dario     if (rc == ERROR_ALREADY_EXISTS)
206*cc13e73eSYuri Dario         rc = DosGetNamedSharedMem( &pDTShare, DTSHARE_NAME,
207*cc13e73eSYuri Dario                                    PAG_WRITE | PAG_READ);
208*cc13e73eSYuri Dario     if (rc)
209*cc13e73eSYuri Dario         rv = true; // error
210*cc13e73eSYuri Dario     else
211*cc13e73eSYuri Dario         rv = RequestFileRendering( pditem, hwnd, DTSHARE_RMF, DTSHARE_NAME);
212*cc13e73eSYuri Dario 
213*cc13e73eSYuri Dario     return rv;
214*cc13e73eSYuri Dario }
215*cc13e73eSYuri Dario 
216*cc13e73eSYuri Dario // SharedMem rendering, memory is allocated by source window
217*cc13e73eSYuri Dario //
RenderToSharedMem(PDRAGITEM pditem,HWND hwnd)218*cc13e73eSYuri Dario bool OTransferable::RenderToSharedMem( PDRAGITEM pditem, HWND hwnd)
219*cc13e73eSYuri Dario {
220*cc13e73eSYuri Dario     bool rv;
221*cc13e73eSYuri Dario 
222*cc13e73eSYuri Dario     rv = RequestFileRendering( pditem, hwnd, SHAREDMEM_RMF, NULL);
223*cc13e73eSYuri Dario 
224*cc13e73eSYuri Dario     return rv;
225*cc13e73eSYuri Dario }
226*cc13e73eSYuri Dario 
requestRendering(void)227*cc13e73eSYuri Dario bool OTransferable::requestRendering( void)
228*cc13e73eSYuri Dario {
229*cc13e73eSYuri Dario     char path[CCHMAXPATH];
230*cc13e73eSYuri Dario     char file[CCHMAXPATH];
231*cc13e73eSYuri Dario     PDRAGITEM dragItem;
232*cc13e73eSYuri Dario 
233*cc13e73eSYuri Dario     // unknown rendering
234*cc13e73eSYuri Dario     renderDRM = DRM_NULL;
235*cc13e73eSYuri Dario 
236*cc13e73eSYuri Dario     // only 1st item supported
237*cc13e73eSYuri Dario     dragItem = DrgQueryDragitemPtr( mDragInfo, 0);
238*cc13e73eSYuri Dario 
239*cc13e73eSYuri Dario     // check if we already have all necessary fields or a rendering
240*cc13e73eSYuri Dario     // request must be sent to source window
241*cc13e73eSYuri Dario 
242*cc13e73eSYuri Dario     switch( mimeType) {
243*cc13e73eSYuri Dario     case MIMETYPE_NULL:
244*cc13e73eSYuri Dario         debug_printf("OTransferable::requestRendering INTERNAL ERROR, mimetype undef");
245*cc13e73eSYuri Dario         break;
246*cc13e73eSYuri Dario 
247*cc13e73eSYuri Dario     case MIMETYPE_FILE:
248*cc13e73eSYuri Dario         if (DrgVerifyRMF( dragItem, "DRM_OS2FILE", NULL)
249*cc13e73eSYuri Dario                 && dragItem->hstrSourceName == NULLHANDLE) {
250*cc13e73eSYuri Dario 
251*cc13e73eSYuri Dario             // if hstrSourceName is NULL we need to ask source for rendering
252*cc13e73eSYuri Dario             bool rv;
253*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering request rendering");
254*cc13e73eSYuri Dario             rv = RenderToOS2File( dragItem, mHwndTarget);
255*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering requested rendering rv=%d", rv);
256*cc13e73eSYuri Dario             renderDRM = DRM_OS2FILE;
257*cc13e73eSYuri Dario 
258*cc13e73eSYuri Dario             // notify rendering request ongoing
259*cc13e73eSYuri Dario             return true;
260*cc13e73eSYuri Dario 
261*cc13e73eSYuri Dario         } else if (DrgVerifyRMF( dragItem, "DRM_OS2FILE", NULL)) {
262*cc13e73eSYuri Dario 
263*cc13e73eSYuri Dario             // we have hstrSourceName, no need for rendering,
264*cc13e73eSYuri Dario             // we already have enough data for rendering path now
265*cc13e73eSYuri Dario 
266*cc13e73eSYuri Dario             // get full path
267*cc13e73eSYuri Dario             DrgQueryStrName(dragItem->hstrContainerName, sizeof(path), path);
268*cc13e73eSYuri Dario             debug_printf("OTransferable::getTransferData hstrSourceName %x", dragItem->hstrSourceName);
269*cc13e73eSYuri Dario             debug_printf("OTransferable::getTransferData hstrTargetName %x", dragItem->hstrTargetName);
270*cc13e73eSYuri Dario             DrgQueryStrName(dragItem->hstrSourceName, sizeof(file), file);
271*cc13e73eSYuri Dario             sprintf( fullpath, "%s%s", path, file);
272*cc13e73eSYuri Dario             debug_printf("OTransferable::getTransferData fullpath %s", fullpath);
273*cc13e73eSYuri Dario             renderDRM = DRM_OS2FILE;
274*cc13e73eSYuri Dario 
275*cc13e73eSYuri Dario         } else {
276*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering UNKNOWN request for FILE mimetype");
277*cc13e73eSYuri Dario         }
278*cc13e73eSYuri Dario         break;
279*cc13e73eSYuri Dario 
280*cc13e73eSYuri Dario     case MIMETYPE_TEXT:
281*cc13e73eSYuri Dario         if (DrgVerifyRMF( dragItem, "DRM_ATOM", NULL)) {
282*cc13e73eSYuri Dario 
283*cc13e73eSYuri Dario             DrgQueryStrName(dragItem->ulItemID, sizeof(fullpath), fullpath);
284*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering DRM_ATOM '%s'", fullpath);
285*cc13e73eSYuri Dario             renderDRM = DRM_ATOM;
286*cc13e73eSYuri Dario 
287*cc13e73eSYuri Dario             // no request rendering necessary
288*cc13e73eSYuri Dario             return false;
289*cc13e73eSYuri Dario 
290*cc13e73eSYuri Dario         } else if (DrgVerifyRMF( dragItem, "DRM_DTSHARE", NULL)) {
291*cc13e73eSYuri Dario 
292*cc13e73eSYuri Dario             bool rv;
293*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering request DRM_DTSHARE rendering");
294*cc13e73eSYuri Dario             rv = RenderToDTShare( dragItem, mHwndTarget);
295*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering requested DRM_DTSHARE rendering rv=%d", rv);
296*cc13e73eSYuri Dario             renderDRM = DRM_DTSHARE;
297*cc13e73eSYuri Dario 
298*cc13e73eSYuri Dario             // notify rendering request ongoing
299*cc13e73eSYuri Dario             return true;
300*cc13e73eSYuri Dario 
301*cc13e73eSYuri Dario         } else if (DrgVerifyRMF( dragItem, "DRM_SHAREDMEM", NULL)) {
302*cc13e73eSYuri Dario 
303*cc13e73eSYuri Dario             bool rv;
304*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering request DRM_SHAREDMEM rendering");
305*cc13e73eSYuri Dario             rv = RenderToSharedMem( dragItem, mHwndTarget);
306*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering requested DRM_SHAREDMEM rendering rv=%d", rv);
307*cc13e73eSYuri Dario             renderDRM = DRM_SHAREDMEM;
308*cc13e73eSYuri Dario 
309*cc13e73eSYuri Dario             // notify rendering request ongoing
310*cc13e73eSYuri Dario             return true;
311*cc13e73eSYuri Dario 
312*cc13e73eSYuri Dario         } else {
313*cc13e73eSYuri Dario             debug_printf("OTransferable::requestRendering UNKNOWN request for TEXT mimetype");
314*cc13e73eSYuri Dario         }
315*cc13e73eSYuri Dario         break;
316*cc13e73eSYuri Dario     }
317*cc13e73eSYuri Dario 
318*cc13e73eSYuri Dario     // request rendering not necessary
319*cc13e73eSYuri Dario     return false;
320*cc13e73eSYuri Dario 
321*cc13e73eSYuri Dario }
322*cc13e73eSYuri Dario 
323*cc13e73eSYuri Dario //
324*cc13e73eSYuri Dario // AOO window received DM_RENDERCOMPLETE message
325*cc13e73eSYuri Dario //
renderComplete(PDRAGTRANSFER pdxfer)326*cc13e73eSYuri Dario bool OTransferable::renderComplete( PDRAGTRANSFER pdxfer)
327*cc13e73eSYuri Dario {
328*cc13e73eSYuri Dario     switch( renderDRM) {
329*cc13e73eSYuri Dario     case DRM_NULL:
330*cc13e73eSYuri Dario         // already handled in requestRendering()
331*cc13e73eSYuri Dario         break;
332*cc13e73eSYuri Dario     case DRM_ATOM:
333*cc13e73eSYuri Dario         // set full path from source rendered name string
334*cc13e73eSYuri Dario         DrgQueryStrName( pdxfer->hstrRenderToName, sizeof(fullpath), fullpath);
335*cc13e73eSYuri Dario         debug_printf("OTransferable::setDragTransfer fullpath %s", fullpath);
336*cc13e73eSYuri Dario         break;
337*cc13e73eSYuri Dario     case DRM_DTSHARE:
338*cc13e73eSYuri Dario         // handled in getTransferData()
339*cc13e73eSYuri Dario         break;
340*cc13e73eSYuri Dario     case DRM_SHAREDMEM:
341*cc13e73eSYuri Dario         // save pointer
342*cc13e73eSYuri Dario         pSharedMem = (char *) pdxfer->hstrRenderToName;
343*cc13e73eSYuri Dario         // extraction handled in getTransferData()
344*cc13e73eSYuri Dario         break;
345*cc13e73eSYuri Dario     case DRM_OS2FILE:
346*cc13e73eSYuri Dario         // we already know the path, no need to use hstrRenderToName
347*cc13e73eSYuri Dario         debug_printf("OTransferable::setDragTransfer fullpath %s", fullpath);
348*cc13e73eSYuri Dario         // remove tmp file on destruction
349*cc13e73eSYuri Dario         removeOnExit = true;
350*cc13e73eSYuri Dario         break;
351*cc13e73eSYuri Dario     }
352*cc13e73eSYuri Dario 
353*cc13e73eSYuri Dario     // send success to source window
354*cc13e73eSYuri Dario     DrgSendTransferMsg( pdxfer->hwndClient, DM_ENDCONVERSATION,
355*cc13e73eSYuri Dario                         (MPARAM) pdxfer->ulTargetInfo,
356*cc13e73eSYuri Dario                         (MPARAM) DMFL_TARGETSUCCESSFUL);
357*cc13e73eSYuri Dario 
358*cc13e73eSYuri Dario     // free resources
359*cc13e73eSYuri Dario     DrgDeleteStrHandle( pdxfer->hstrSelectedRMF);
360*cc13e73eSYuri Dario     DrgDeleteStrHandle( pdxfer->hstrRenderToName);
361*cc13e73eSYuri Dario     DrgFreeDragtransfer( pdxfer);
362*cc13e73eSYuri Dario 
363*cc13e73eSYuri Dario     return false;
364*cc13e73eSYuri Dario }
365*cc13e73eSYuri Dario 
getTransferData(const DataFlavor & df)366*cc13e73eSYuri Dario Any SAL_CALL OTransferable::getTransferData( const DataFlavor& df)
367*cc13e73eSYuri Dario throw(UnsupportedFlavorException, IOException, RuntimeException)
368*cc13e73eSYuri Dario {
369*cc13e73eSYuri Dario     OUString m_aData;
370*cc13e73eSYuri Dario     char * pszText = 0;
371*cc13e73eSYuri Dario     int pszLen;
372*cc13e73eSYuri Dario     ULONG size = ~0;
373*cc13e73eSYuri Dario     ULONG flags = 0;
374*cc13e73eSYuri Dario     APIRET rc;
375*cc13e73eSYuri Dario     bool renderOk = false;
376*cc13e73eSYuri Dario 
377*cc13e73eSYuri Dario     debug_printf("OTransferable::getTransferData MimeType %s",
378*cc13e73eSYuri Dario                  ::rtl::OUStringToOString( df.MimeType, RTL_TEXTENCODING_UTF8 ).getStr());
379*cc13e73eSYuri Dario 
380*cc13e73eSYuri Dario     // handle shared memory cases
381*cc13e73eSYuri Dario     switch( renderDRM) {
382*cc13e73eSYuri Dario     case DRM_DTSHARE:
383*cc13e73eSYuri Dario 
384*cc13e73eSYuri Dario         pszLen = ((ULONG*)pDTShare)[0];
385*cc13e73eSYuri Dario         pszText = (char*) malloc( pszLen + 1);
386*cc13e73eSYuri Dario         if (pszText) {
387*cc13e73eSYuri Dario             strcpy(pszText, &((char*)pDTShare)[sizeof(ULONG)] );
388*cc13e73eSYuri Dario         }
389*cc13e73eSYuri Dario         // using DosGetNamedSharedMem() on memory we allocated appears
390*cc13e73eSYuri Dario         // to increment its usage ctr, so we have to free it 2x
391*cc13e73eSYuri Dario         DosFreeMem(pDTShare);
392*cc13e73eSYuri Dario         DosFreeMem(pDTShare);
393*cc13e73eSYuri Dario         // reset pointer
394*cc13e73eSYuri Dario         pDTShare = NULL;
395*cc13e73eSYuri Dario 
396*cc13e73eSYuri Dario         // prepare data for AOO
397*cc13e73eSYuri Dario         m_aData = OUString( pszText, pszLen, RTL_TEXTENCODING_UTF8);
398*cc13e73eSYuri Dario         break;
399*cc13e73eSYuri Dario 
400*cc13e73eSYuri Dario     case DRM_SHAREDMEM:
401*cc13e73eSYuri Dario         rc = DosQueryMem((PVOID) pSharedMem, &size, &flags);
402*cc13e73eSYuri Dario         renderOk = rc == 0;
403*cc13e73eSYuri Dario         if (renderOk) {
404*cc13e73eSYuri Dario             renderOk = (flags & (PAG_COMMIT | PAG_READ | PAG_BASE)) ==
405*cc13e73eSYuri Dario                        (PAG_COMMIT | PAG_READ | PAG_BASE);
406*cc13e73eSYuri Dario         }
407*cc13e73eSYuri Dario         if (renderOk) {
408*cc13e73eSYuri Dario             ULONG realSize = *(ULONG *) pSharedMem;
409*cc13e73eSYuri Dario             renderOk = realSize <= size;
410*cc13e73eSYuri Dario             if (renderOk) {
411*cc13e73eSYuri Dario                 // prepare data for AOO
412*cc13e73eSYuri Dario                 m_aData = OUString( pSharedMem + sizeof(ULONG), realSize, RTL_TEXTENCODING_UTF8);
413*cc13e73eSYuri Dario             }
414*cc13e73eSYuri Dario         }
415*cc13e73eSYuri Dario         // free memory only if it is given by another process,
416*cc13e73eSYuri Dario         // otherwise DefaultDragWorker will free it
417*cc13e73eSYuri Dario         if (flags & PAG_SHARED)
418*cc13e73eSYuri Dario             DosFreeMem((PVOID) pSharedMem);
419*cc13e73eSYuri Dario         break;
420*cc13e73eSYuri Dario 
421*cc13e73eSYuri Dario     case DRM_ATOM:
422*cc13e73eSYuri Dario     case DRM_OS2FILE:
423*cc13e73eSYuri Dario         // data is in fullpath string
424*cc13e73eSYuri Dario         // prepare data for AOO
425*cc13e73eSYuri Dario         m_aData = OUString( fullpath, strlen(fullpath), RTL_TEXTENCODING_UTF8);
426*cc13e73eSYuri Dario         break;
427*cc13e73eSYuri Dario 
428*cc13e73eSYuri Dario     default:
429*cc13e73eSYuri Dario         debug_printf( "OTransferable::getTransferData unsupported DRM_* type %d",
430*cc13e73eSYuri Dario                       renderDRM);
431*cc13e73eSYuri Dario         break;
432*cc13e73eSYuri Dario     }
433*cc13e73eSYuri Dario 
434*cc13e73eSYuri Dario     // return data
435*cc13e73eSYuri Dario     return makeAny( m_aData );
436*cc13e73eSYuri Dario }
437*cc13e73eSYuri Dario 
438*cc13e73eSYuri Dario // -----------------------------------------------------------------------
439*cc13e73eSYuri Dario 
getTransferDataFlavors()440*cc13e73eSYuri Dario Sequence< DataFlavor > SAL_CALL OTransferable::getTransferDataFlavors(  )
441*cc13e73eSYuri Dario throw(RuntimeException)
442*cc13e73eSYuri Dario {
443*cc13e73eSYuri Dario     return m_aFlavorList;
444*cc13e73eSYuri Dario }
445*cc13e73eSYuri Dario 
446*cc13e73eSYuri Dario // -----------------------------------------------------------------------
447*cc13e73eSYuri Dario 
isDataFlavorSupported(const DataFlavor &)448*cc13e73eSYuri Dario sal_Bool SAL_CALL OTransferable::isDataFlavorSupported( const DataFlavor& )
449*cc13e73eSYuri Dario throw(RuntimeException)
450*cc13e73eSYuri Dario {
451*cc13e73eSYuri Dario     return sal_True;
452*cc13e73eSYuri Dario }
453