winhttp: The last parameter of WinHttpQueryDataAvailable and WinHttpReadData is optional.
[wine] / dlls / riched20 / txtsrv.c
1 /*
2  * RichEdit - functions and interfaces around CreateTextServices
3  *
4  * Copyright 2005, 2006, Maarten Lankhorst
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
26 #define COBJMACROS
27
28 #include "editor.h"
29 #include "ole2.h"
30 #include "richole.h"
31 #include "imm.h"
32 #include "textserv.h"
33 #include "wine/debug.h"
34 #include "editstr.h"
35
36 #ifdef __i386__  /* thiscall functions are i386-specific */
37
38 #define THISCALL(func) __thiscall_ ## func
39 #define DEFINE_THISCALL_WRAPPER(func) \
40    extern typeof(func) THISCALL(func); \
41    __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
42                    "popl %eax\n\t" \
43                    "pushl %ecx\n\t" \
44                    "pushl %eax\n\t" \
45                    "jmp " __ASM_NAME(#func) )
46 #else /* __i386__ */
47
48 #define THISCALL(func) func
49 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
50
51 #endif /* __i386__ */
52
53 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
54
55 typedef struct ITextServicesImpl {
56    const ITextServicesVtbl *lpVtbl;
57    ITextHost *pMyHost;
58    LONG ref;
59    CRITICAL_SECTION csTxtSrv;
60 } ITextServicesImpl;
61
62 static const ITextServicesVtbl textservices_Vtbl;
63
64 /******************************************************************
65  *        CreateTextServices (RICHED20.4)
66  */
67 HRESULT WINAPI CreateTextServices(IUnknown  * pUnkOuter,
68                                   ITextHost * pITextHost,
69                                   IUnknown  **ppUnk)
70 {
71    ITextServicesImpl *ITextImpl;
72    TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
73    if (pITextHost == NULL)
74       return E_POINTER;
75
76    ITextImpl = CoTaskMemAlloc(sizeof(*ITextImpl));
77    if (ITextImpl == NULL)
78       return E_OUTOFMEMORY;
79    InitializeCriticalSection(&ITextImpl->csTxtSrv);
80    ITextImpl->csTxtSrv.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ITextServicesImpl.csTxtSrv");
81    ITextImpl->ref = 1;
82    ITextHost_AddRef(pITextHost);
83    ITextImpl->pMyHost = pITextHost;
84    ITextImpl->lpVtbl = &textservices_Vtbl;
85
86    if (pUnkOuter)
87    {
88       FIXME("Support aggregation\n");
89       return CLASS_E_NOAGGREGATION;
90    }
91
92    *ppUnk = (IUnknown *)ITextImpl;
93    return S_OK;
94 }
95
96 #define ICOM_THIS_MULTI(impl,field,iface) \
97                     impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
98
99 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices * iface,
100                                                REFIID riid,
101                                                LPVOID * ppv)
102 {
103    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
104    TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
105    *ppv = NULL;
106    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
107       *ppv = (LPVOID)This;
108
109    if (*ppv)
110    {
111       IUnknown_AddRef((IUnknown *)(*ppv));
112       TRACE ("-- Interface = %p\n", *ppv);
113       return S_OK;
114    }
115    FIXME("Unknown interface: %s\n", debugstr_guid(riid));
116    return E_NOINTERFACE;
117 }
118
119 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
120 {
121    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
122    DWORD ref = InterlockedIncrement(&This->ref);
123
124    TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
125    return ref;
126 }
127
128 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
129 {
130    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
131    DWORD ref = InterlockedDecrement(&This->ref);
132
133    TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
134
135    if (!ref)
136    {
137       ITextHost_Release(This->pMyHost);
138       This->csTxtSrv.DebugInfo->Spare[0] = 0;
139       DeleteCriticalSection(&This->csTxtSrv);
140       CoTaskMemFree(This);
141    }
142    return ref;
143 }
144
145 HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface,
146                                        UINT msg,
147                                        WPARAM wparam,
148                                        LPARAM lparam,
149                                        LRESULT* plresult)
150 {
151    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
152
153    FIXME("%p: STUB\n", This);
154    return E_NOTIMPL;
155 }
156
157 HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface,
158                                 DWORD dwDrawAspect,
159                                 LONG lindex,
160                                 void* pvAspect,
161                                 DVTARGETDEVICE* ptd,
162                                 HDC hdcDraw,
163                                 HDC hdcTargetDev,
164                                 LPCRECTL lprcBounds,
165                                 LPCRECTL lprcWBounds,
166                                 LPRECT lprcUpdate,
167                                 BOOL (CALLBACK * pfnContinue)(DWORD),
168                                 DWORD dwContinue,
169                                 LONG lViewId)
170 {
171    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
172
173    FIXME("%p: STUB\n", This);
174    return E_NOTIMPL;
175 }
176
177 HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface,
178                                       LONG* plMin,
179                                       LONG* plMax,
180                                       LONG* plPos,
181                                       LONG* plPage,
182                                       BOOL* pfEnabled)
183 {
184    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
185
186    FIXME("%p: STUB\n", This);
187    return E_NOTIMPL;
188 }
189
190 HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface,
191                                       LONG* plMin,
192                                       LONG* plMax,
193                                       LONG* plPos,
194                                       LONG* plPage,
195                                       BOOL* pfEnabled)
196 {
197    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
198
199    FIXME("%p: STUB\n", This);
200    return E_NOTIMPL;
201 }
202
203 HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface,
204                                        DWORD dwDrawAspect,
205                                        LONG lindex,
206                                        void* pvAspect,
207                                        DVTARGETDEVICE* ptd,
208                                        HDC hdcDraw,
209                                        HDC hicTargetDev,
210                                        LPCRECT lprcClient,
211                                        INT x, INT y)
212 {
213    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
214
215    FIXME("%p: STUB\n", This);
216    return E_NOTIMPL;
217 }
218
219 HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface,
220                                          DWORD dwDrawAspect,
221                                          LONG lindex,
222                                          void* pvAspect,
223                                          DVTARGETDEVICE* ptd,
224                                          HDC hdcDraw,
225                                          HDC hicTargetDev,
226                                          LPCRECT lprcClient,
227                                          INT x, INT y,
228                                          DWORD* pHitResult)
229 {
230    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
231
232    FIXME("%p: STUB\n", This);
233    return E_NOTIMPL;
234 }
235
236 HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface,
237                                              LPCRECT prcClient)
238 {
239    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
240
241    FIXME("%p: STUB\n", This);
242    return E_NOTIMPL;
243 }
244
245 HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
246 {
247    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
248
249    FIXME("%p: STUB\n", This);
250    return E_NOTIMPL;
251 }
252
253 HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
254 {
255    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
256
257    FIXME("%p: STUB\n", This);
258    return E_NOTIMPL;
259 }
260
261 HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
262 {
263    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
264
265    FIXME("%p: STUB\n", This);
266    return E_NOTIMPL;
267 }
268
269 HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface,
270                                    BSTR* pbstrText)
271 {
272    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
273
274    FIXME("%p: STUB\n", This);
275    return E_NOTIMPL;
276 }
277
278 HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface,
279                                    LPCWSTR pszText)
280 {
281    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
282
283    FIXME("%p: STUB\n", This);
284    return E_NOTIMPL;
285 }
286
287 HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface,
288                                              LONG* x)
289 {
290    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
291
292    FIXME("%p: STUB\n", This);
293    return E_NOTIMPL;
294 }
295
296 HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface,
297                                           LONG* x)
298 {
299    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
300
301    FIXME("%p: STUB\n", This);
302    return E_NOTIMPL;
303 }
304
305 HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
306                                           DWORD dwAspect,
307                                           HDC hdcDraw,
308                                           HDC hicTargetDev,
309                                           DVTARGETDEVICE* ptd,
310                                           DWORD dwMode,
311                                           const SIZEL* psizelExtent,
312                                           LONG* pwidth,
313                                           LONG* pheight)
314 {
315    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
316
317    FIXME("%p: STUB\n", This);
318    return E_NOTIMPL;
319 }
320
321 HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface,
322                                          IDropTarget** ppDropTarget)
323 {
324    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
325
326    FIXME("%p: STUB\n", This);
327    return E_NOTIMPL;
328 }
329
330 HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface,
331                                                 DWORD dwMask,
332                                                 DWORD dwBits)
333 {
334    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
335
336    FIXME("%p: STUB\n", This);
337    return E_NOTIMPL;
338 }
339
340 HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface,
341                                          DWORD* pdwWidth,
342                                          DWORD* pdwHeight)
343 {
344    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
345
346    FIXME("%p: STUB\n", This);
347    return E_NOTIMPL;
348 }
349
350 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage)
351 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw)
352 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll)
353 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll)
354 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor)
355 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint)
356 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate)
357 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate)
358 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate)
359 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate)
360 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText)
361 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText)
362 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX)
363 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos)
364 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize)
365 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget)
366 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange)
367 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize)
368
369 static const ITextServicesVtbl textservices_Vtbl =
370 {
371    fnTextSrv_QueryInterface,
372    fnTextSrv_AddRef,
373    fnTextSrv_Release,
374    THISCALL(fnTextSrv_TxSendMessage),
375    THISCALL(fnTextSrv_TxDraw),
376    THISCALL(fnTextSrv_TxGetHScroll),
377    THISCALL(fnTextSrv_TxGetVScroll),
378    THISCALL(fnTextSrv_OnTxSetCursor),
379    THISCALL(fnTextSrv_TxQueryHitPoint),
380    THISCALL(fnTextSrv_OnTxInplaceActivate),
381    THISCALL(fnTextSrv_OnTxInplaceDeactivate),
382    THISCALL(fnTextSrv_OnTxUIActivate),
383    THISCALL(fnTextSrv_OnTxUIDeactivate),
384    THISCALL(fnTextSrv_TxGetText),
385    THISCALL(fnTextSrv_TxSetText),
386    THISCALL(fnTextSrv_TxGetCurrentTargetX),
387    THISCALL(fnTextSrv_TxGetBaseLinePos),
388    THISCALL(fnTextSrv_TxGetNaturalSize),
389    THISCALL(fnTextSrv_TxGetDropTarget),
390    THISCALL(fnTextSrv_OnTxPropertyBitsChange),
391    THISCALL(fnTextSrv_TxGetCachedSize)
392 };