user32: Factor in EDIT_WM_EraseBkGnd().
[wine] / dlls / user32 / ddeml16.c
1 /*
2  * DDEML library
3  *
4  * Copyright 1997 Alexandre Julliard
5  * Copyright 1997 Len White
6  * Copyright 1999 Keith Matthews
7  * Copyright 2000 Corel
8  * Copyright 2001,2002 Eric Pouech
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24
25 #include <stdarg.h>
26 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wine/windef16.h"
30 #include "wownt32.h"
31 #include "dde.h"
32 #include "ddeml.h"
33 #include "dde_private.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
37
38
39 typedef HDDEDATA (CALLBACK *PFNCALLBACK16)(UINT16,UINT16,HCONV,HSZ,HSZ,HDDEDATA,
40                                            DWORD,DWORD);
41
42 typedef struct
43 {
44     UINT16  cb;
45     UINT16  wFlags;
46     UINT16  wCountryID;
47     INT16   iCodePage;
48     DWORD   dwLangID;
49     DWORD   dwSecurity;
50 } CONVCONTEXT16, *LPCONVCONTEXT16;
51
52 typedef struct
53 {
54     DWORD          cb;
55     DWORD          hUser;
56     HCONV          hConvPartner;
57     HSZ            hszSvcPartner;
58     HSZ            hszServiceReq;
59     HSZ            hszTopic;
60     HSZ            hszItem;
61     UINT16         wFmt;
62     UINT16         wType;
63     UINT16         wStatus;
64     UINT16         wConvst;
65     UINT16         wLastError;
66     HCONVLIST      hConvList;
67     CONVCONTEXT16  ConvCtxt;
68 } CONVINFO16, *LPCONVINFO16;
69
70 static void map1632_conv_context(CONVCONTEXT* cc32, const CONVCONTEXT16* cc16)
71 {
72     cc32->cb = sizeof(*cc32);
73     cc32->wFlags = cc16->wFlags;
74     cc32->wCountryID = cc16->wCountryID;
75     cc32->iCodePage = cc16->iCodePage;
76     cc32->dwLangID = cc16->dwLangID;
77     cc32->dwSecurity = cc16->dwSecurity;
78 }
79
80 static void map3216_conv_context(CONVCONTEXT16* cc16, const CONVCONTEXT* cc32)
81 {
82     cc16->cb = sizeof(*cc16);
83     cc16->wFlags = cc32->wFlags;
84     cc16->wCountryID = cc32->wCountryID;
85     cc16->iCodePage = cc32->iCodePage;
86     cc16->dwLangID = cc32->dwLangID;
87     cc16->dwSecurity = cc32->dwSecurity;
88 }
89
90
91 /******************************************************************
92  *              WDML_InvokeCallback16
93  *
94  *
95  */
96 HDDEDATA        WDML_InvokeCallback16(PFNCALLBACK pfn, UINT uType, UINT uFmt,
97                                       HCONV hConv, HSZ hsz1, HSZ hsz2,
98                                       HDDEDATA hdata, DWORD dwData1, DWORD dwData2)
99 {
100     DWORD               d1 = 0;
101     HDDEDATA            ret;
102     CONVCONTEXT16       cc16;
103     WORD args[16];
104
105     switch (uType)
106     {
107     case XTYP_CONNECT:
108     case XTYP_WILDCONNECT:
109         if (dwData1)
110         {
111             map3216_conv_context(&cc16, (const CONVCONTEXT*)dwData1);
112             d1 = MapLS(&cc16);
113         }
114         else
115         break;
116     default:
117         d1 = dwData1;
118         break;
119     }
120     args[15] = HIWORD(uType);
121     args[14] = LOWORD(uType);
122     args[13] = HIWORD(uFmt);
123     args[12] = LOWORD(uFmt);
124     args[11] = HIWORD(hConv);
125     args[10] = LOWORD(hConv);
126     args[9]  = HIWORD(hsz1);
127     args[8]  = LOWORD(hsz1);
128     args[7]  = HIWORD(hsz2);
129     args[6]  = LOWORD(hsz2);
130     args[5]  = HIWORD(hdata);
131     args[4]  = LOWORD(hdata);
132     args[3]  = HIWORD(d1);
133     args[2]  = LOWORD(d1);
134     args[1]  = HIWORD(dwData2);
135     args[0]  = LOWORD(dwData2);
136     WOWCallback16Ex( (DWORD)pfn, WCB16_PASCAL, sizeof(args), args, (DWORD *)&ret );
137
138     switch (uType)
139     {
140     case XTYP_CONNECT:
141     case XTYP_WILDCONNECT:
142         if (d1 != 0) UnMapLS(d1);
143         break;
144     }
145     return ret;
146 }
147
148 /******************************************************************************
149  *            DdeInitialize   (DDEML.2)
150  */
151 UINT16 WINAPI DdeInitialize16(LPDWORD pidInst, PFNCALLBACK16 pfnCallback,
152                               DWORD afCmd, DWORD ulRes)
153 {
154     return WDML_Initialize(pidInst, (PFNCALLBACK)pfnCallback, afCmd, ulRes,
155                            FALSE, TRUE);
156 }
157
158 /*****************************************************************
159  *            DdeUninitialize   (DDEML.3)
160  */
161 BOOL16 WINAPI DdeUninitialize16(DWORD idInst)
162 {
163     return (BOOL16)DdeUninitialize(idInst);
164 }
165
166 /*****************************************************************
167  * DdeConnectList [DDEML.4]
168  */
169
170 HCONVLIST WINAPI DdeConnectList16(DWORD idInst, HSZ hszService, HSZ hszTopic,
171                                   HCONVLIST hConvList, LPCONVCONTEXT16 pCC16)
172 {
173     CONVCONTEXT         cc;
174     CONVCONTEXT*        pCC = NULL;
175
176     if (pCC16)
177         map1632_conv_context(pCC = &cc, pCC16);
178     return DdeConnectList(idInst, hszService, hszTopic, hConvList, pCC);
179 }
180
181 /*****************************************************************
182  * DdeQueryNextServer [DDEML.5]
183  */
184 HCONV WINAPI DdeQueryNextServer16(HCONVLIST hConvList, HCONV hConvPrev)
185 {
186     return DdeQueryNextServer(hConvList, hConvPrev);
187 }
188
189 /*****************************************************************
190  *            DdeDisconnectList (DDEML.6)
191  */
192 BOOL16 WINAPI DdeDisconnectList16(HCONVLIST hConvList)
193 {
194     return (BOOL16)DdeDisconnectList(hConvList);
195 }
196
197
198 /*****************************************************************
199  *              DdeQueryString (DDEML.23)
200  */
201 DWORD WINAPI DdeQueryString16(DWORD idInst, HSZ hsz, LPSTR lpsz, DWORD cchMax,
202                               INT16 codepage)
203 {
204     return DdeQueryStringA(idInst, hsz, lpsz, cchMax, codepage);
205 }
206
207 /*****************************************************************
208  *            DdeConnect   (DDEML.7)
209  */
210 HCONV WINAPI DdeConnect16(DWORD idInst, HSZ hszService, HSZ hszTopic,
211                           LPCONVCONTEXT16 pCC16)
212 {
213     CONVCONTEXT         cc;
214     CONVCONTEXT*        pCC = NULL;
215
216     if (pCC16)
217         map1632_conv_context(pCC = &cc, pCC16);
218     return DdeConnect(idInst, hszService, hszTopic, pCC);
219 }
220
221 /*****************************************************************
222  *            DdeDisconnect   (DDEML.8)
223  */
224 BOOL16 WINAPI DdeDisconnect16(HCONV hConv)
225 {
226     return (BOOL16)DdeDisconnect(hConv);
227 }
228
229 /*****************************************************************
230  *            DdeSetUserHandle (DDEML.10)
231  */
232 BOOL16 WINAPI DdeSetUserHandle16(HCONV hConv, DWORD id, DWORD hUser)
233 {
234     return DdeSetUserHandle(hConv, id, hUser);
235 }
236
237 /*****************************************************************
238  *            DdeCreateDataHandle (DDEML.14)
239  */
240 HDDEDATA WINAPI DdeCreateDataHandle16(DWORD idInst, LPBYTE pSrc, DWORD cb,
241                                       DWORD cbOff, HSZ hszItem, UINT16 wFmt,
242                                       UINT16 afCmd)
243 {
244     return DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd);
245 }
246
247 /*****************************************************************
248  *            DdeCreateStringHandle   (DDEML.21)
249  */
250 HSZ WINAPI DdeCreateStringHandle16(DWORD idInst, LPCSTR str, INT16 codepage)
251 {
252     if  (codepage)
253     {
254         return DdeCreateStringHandleA(idInst, str, codepage);
255     }
256     else
257     {
258         TRACE("Default codepage supplied\n");
259         return DdeCreateStringHandleA(idInst, str, CP_WINANSI);
260     }
261 }
262
263 /*****************************************************************
264  *            DdeFreeStringHandle   (DDEML.22)
265  */
266 BOOL16 WINAPI DdeFreeStringHandle16(DWORD idInst, HSZ hsz)
267 {
268     return (BOOL16)DdeFreeStringHandle(idInst, hsz);
269 }
270
271 /*****************************************************************
272  *            DdeFreeDataHandle   (DDEML.19)
273  */
274 BOOL16 WINAPI DdeFreeDataHandle16(HDDEDATA hData)
275 {
276     return (BOOL16)DdeFreeDataHandle(hData);
277 }
278
279 /*****************************************************************
280  *            DdeKeepStringHandle   (DDEML.24)
281  */
282 BOOL16 WINAPI DdeKeepStringHandle16(DWORD idInst, HSZ hsz)
283 {
284     return (BOOL)DdeKeepStringHandle(idInst, hsz);
285 }
286
287 /*****************************************************************
288  *            DdeClientTransaction  (DDEML.11)
289  */
290 HDDEDATA WINAPI DdeClientTransaction16(LPVOID pData, DWORD cbData, HCONV hConv,
291                                        HSZ hszItem, UINT16 wFmt, UINT16 wType,
292                                        DWORD dwTimeout, LPDWORD pdwResult)
293 {
294     return DdeClientTransaction((LPBYTE)pData, cbData, hConv, hszItem,
295                                 wFmt, wType, dwTimeout, pdwResult);
296 }
297
298 /*****************************************************************
299  *
300  *            DdeAbandonTransaction (DDEML.12)
301  *
302  */
303 BOOL16 WINAPI DdeAbandonTransaction16(DWORD idInst, HCONV hConv, DWORD idTransaction)
304 {
305     return (BOOL16)DdeAbandonTransaction(idInst, hConv, idTransaction);
306 }
307
308 /*****************************************************************
309  * DdePostAdvise [DDEML.13]
310  */
311 BOOL16 WINAPI DdePostAdvise16(DWORD idInst, HSZ hszTopic, HSZ hszItem)
312 {
313     return (BOOL16)DdePostAdvise(idInst, hszTopic, hszItem);
314 }
315
316 /*****************************************************************
317  *            DdeAddData (DDEML.15)
318  */
319 HDDEDATA WINAPI DdeAddData16(HDDEDATA hData, LPBYTE pSrc, DWORD cb, DWORD cbOff)
320 {
321     return DdeAddData(hData, pSrc, cb, cbOff);
322 }
323
324 /*****************************************************************
325  * DdeGetData [DDEML.16]
326  */
327 DWORD WINAPI DdeGetData16(HDDEDATA hData, LPBYTE pDst, DWORD cbMax, DWORD cbOff)
328 {
329     return DdeGetData(hData, pDst, cbMax, cbOff);
330 }
331
332 /*****************************************************************
333  *            DdeAccessData (DDEML.17)
334  */
335 LPBYTE WINAPI DdeAccessData16(HDDEDATA hData, LPDWORD pcbDataSize)
336 {
337     FIXME("expect trouble\n");
338     /* FIXME: there's a memory leak here... */
339     return (LPBYTE)MapLS(DdeAccessData(hData, pcbDataSize));
340 }
341
342 /*****************************************************************
343  *            DdeUnaccessData (DDEML.18)
344  */
345 BOOL16 WINAPI DdeUnaccessData16(HDDEDATA hData)
346 {
347     return DdeUnaccessData(hData);
348 }
349
350 /*****************************************************************
351  *            DdeEnableCallback (DDEML.26)
352  */
353 BOOL16 WINAPI DdeEnableCallback16(DWORD idInst, HCONV hConv, UINT16 wCmd)
354 {
355     return DdeEnableCallback(idInst, hConv, wCmd);
356 }
357
358 /*****************************************************************
359  *            DdeNameService  (DDEML.27)
360  */
361 HDDEDATA WINAPI DdeNameService16(DWORD idInst, HSZ hsz1, HSZ hsz2, UINT16 afCmd)
362 {
363     return DdeNameService(idInst, hsz1, hsz2, afCmd);
364 }
365
366 /*****************************************************************
367  *            DdeGetLastError  (DDEML.20)
368  */
369 UINT16 WINAPI DdeGetLastError16(DWORD idInst)
370 {
371     return (UINT16)DdeGetLastError(idInst);
372 }
373
374 /*****************************************************************
375  *            DdeCmpStringHandles (DDEML.36)
376  */
377 INT16 WINAPI DdeCmpStringHandles16(HSZ hsz1, HSZ hsz2)
378 {
379     return DdeCmpStringHandles(hsz1, hsz2);
380 }
381
382 /******************************************************************
383  *              DdeQueryConvInfo (DDEML.9)
384  *
385  */
386 UINT16 WINAPI DdeQueryConvInfo16(HCONV hConv, DWORD idTransaction,
387                                  LPCONVINFO16 lpConvInfo)
388 {
389     CONVINFO    ci32;
390     CONVINFO16  ci16;
391     UINT        ret;
392
393     ci32.cb = sizeof(ci32);
394     ci32.ConvCtxt.cb = sizeof(ci32.ConvCtxt);
395
396     ret = DdeQueryConvInfo(hConv, idTransaction, &ci32);
397     if (ret == 0) return 0;
398
399     ci16.hUser = ci32.hUser;
400     ci16.hConvPartner = ci32.hConvPartner;
401     ci16.hszSvcPartner = ci32.hszSvcPartner;
402     ci16.hszServiceReq = ci32.hszServiceReq;
403     ci16.hszTopic = ci32.hszTopic;
404     ci16.hszItem = ci32.hszItem;
405     ci16.wFmt = ci32.wFmt;
406     ci16.wType = ci32.wType;
407     ci16.wStatus = ci32.wStatus;
408     ci16.wConvst = ci32.wConvst;
409     ci16.wLastError = ci32.wLastError;
410     ci16.hConvList = ci32.hConvList;
411
412     map3216_conv_context(&ci16.ConvCtxt, &ci32.ConvCtxt);
413
414     memcpy(lpConvInfo, &ci16, lpConvInfo->cb);
415     return lpConvInfo->cb;
416 }