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