riched20: Remove superfluous pointer casts.
[wine] / dlls / riched20 / txthost.c
1 /*
2  * RichEdit - ITextHost implementation for windowed richedit controls
3  *
4  * Copyright 2009 by Dylan Smith
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 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
37
38 typedef struct ITextHostImpl {
39     const ITextHostVtbl *lpVtbl;
40     LONG ref;
41     HWND hWnd;
42     BOOL bEmulateVersion10;
43 } ITextHostImpl;
44
45 static ITextHostVtbl textHostVtbl;
46
47 ITextHost *ME_CreateTextHost(HWND hwnd, BOOL bEmulateVersion10)
48 {
49     ITextHostImpl *texthost;
50     texthost = CoTaskMemAlloc(sizeof(*texthost));
51     if (texthost)
52     {
53         ME_TextEditor *editor;
54
55         texthost->lpVtbl = &textHostVtbl;
56         texthost->ref = 1;
57         texthost->hWnd = hwnd;
58         texthost->bEmulateVersion10 = bEmulateVersion10;
59
60         editor = ME_MakeEditor((ITextHost*)texthost, bEmulateVersion10);
61         editor->exStyleFlags = GetWindowLongW(hwnd, GWL_EXSTYLE);
62         editor->hWnd = hwnd; /* FIXME: Remove editor's dependance on hWnd */
63         SetWindowLongPtrW(hwnd, 0, (LONG_PTR)editor);
64     }
65
66     return (ITextHost*)texthost;
67 }
68
69 static HRESULT WINAPI ITextHostImpl_QueryInterface(ITextHost *iface,
70                                                    REFIID riid,
71                                                    LPVOID *ppvObject)
72 {
73     ITextHostImpl *This = (ITextHostImpl *)iface;
74
75     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextHost)) {
76         *ppvObject = This;
77         ITextHost_AddRef((ITextHost *)*ppvObject);
78         return S_OK;
79     }
80
81     FIXME("Unknown interface: %s\n", debugstr_guid(riid));
82     return E_NOINTERFACE;
83 }
84
85 static ULONG WINAPI ITextHostImpl_AddRef(ITextHost *iface)
86 {
87     ITextHostImpl *This = (ITextHostImpl *)iface;
88     ULONG ref = InterlockedIncrement(&This->ref);
89     return ref;
90 }
91
92 static ULONG WINAPI ITextHostImpl_Release(ITextHost *iface)
93 {
94     ITextHostImpl *This = (ITextHostImpl *)iface;
95     ULONG ref = InterlockedDecrement(&This->ref);
96
97     if (!ref)
98     {
99         SetWindowLongPtrW(This->hWnd, 0, 0);
100         CoTaskMemFree(This);
101     }
102     return ref;
103 }
104
105 HDC WINAPI ITextHostImpl_TxGetDC(ITextHost *iface)
106 {
107     ITextHostImpl *This = (ITextHostImpl *)iface;
108     return GetDC(This->hWnd);
109 }
110
111 INT WINAPI ITextHostImpl_TxReleaseDC(ITextHost *iface,
112                                      HDC hdc)
113 {
114     ITextHostImpl *This = (ITextHostImpl *)iface;
115     return ReleaseDC(This->hWnd, hdc);
116 }
117
118 BOOL WINAPI ITextHostImpl_TxShowScrollBar(ITextHost *iface,
119                                           INT fnBar,
120                                           BOOL fShow)
121 {
122     ITextHostImpl *This = (ITextHostImpl *)iface;
123     return ShowScrollBar(This->hWnd, fnBar, fShow);
124 }
125
126 BOOL WINAPI ITextHostImpl_TxEnableScrollBar(ITextHost *iface,
127                                             INT fuSBFlags,
128                                             INT fuArrowflags)
129 {
130     ITextHostImpl *This = (ITextHostImpl *)iface;
131     return EnableScrollBar(This->hWnd, fuSBFlags, fuArrowflags);
132 }
133
134 BOOL WINAPI ITextHostImpl_TxSetScrollRange(ITextHost *iface,
135                                            INT fnBar,
136                                            LONG nMinPos,
137                                            INT nMaxPos,
138                                            BOOL fRedraw)
139 {
140     ITextHostImpl *This = (ITextHostImpl *)iface;
141     return SetScrollRange(This->hWnd, fnBar, nMinPos, nMaxPos, fRedraw);
142 }
143
144 BOOL WINAPI ITextHostImpl_TxSetScrollPos(ITextHost *iface,
145                                          INT fnBar,
146                                          INT nPos,
147                                          BOOL fRedraw)
148 {
149     ITextHostImpl *This = (ITextHostImpl *)iface;
150     int pos = SetScrollPos(This->hWnd, fnBar, nPos, fRedraw);
151     return (pos ? TRUE : FALSE);
152 }
153
154 void WINAPI ITextHostImpl_TxInvalidateRect(ITextHost *iface,
155                                            LPCRECT prc,
156                                            BOOL fMode)
157 {
158     ITextHostImpl *This = (ITextHostImpl *)iface;
159     InvalidateRect(This->hWnd, prc, fMode);
160 }
161
162 void WINAPI ITextHostImpl_TxViewChange(ITextHost *iface,
163                                        BOOL fUpdate)
164 {
165     ITextHostImpl *This = (ITextHostImpl *)iface;
166     if (fUpdate)
167         UpdateWindow(This->hWnd);
168 }
169
170 BOOL WINAPI ITextHostImpl_TxCreateCaret(ITextHost *iface,
171                                         HBITMAP hbmp,
172                                         INT xWidth, INT yHeight)
173 {
174     ITextHostImpl *This = (ITextHostImpl *)iface;
175     return CreateCaret(This->hWnd, hbmp, xWidth, yHeight);
176 }
177
178 BOOL WINAPI ITextHostImpl_TxShowCaret(ITextHost *iface, BOOL fShow)
179 {
180     ITextHostImpl *This = (ITextHostImpl *)iface;
181     if (fShow)
182         return ShowCaret(This->hWnd);
183     else
184         return HideCaret(This->hWnd);
185 }
186
187 BOOL WINAPI ITextHostImpl_TxSetCaretPos(ITextHost *iface,
188                                         INT x, INT y)
189 {
190     return SetCaretPos(x, y);
191 }
192
193 BOOL WINAPI ITextHostImpl_TxSetTimer(ITextHost *iface,
194                                      UINT idTimer, UINT uTimeout)
195 {
196     ITextHostImpl *This = (ITextHostImpl *)iface;
197     return SetTimer(This->hWnd, idTimer, uTimeout, NULL) != 0;
198 }
199
200 void WINAPI ITextHostImpl_TxKillTimer(ITextHost *iface,
201                                       UINT idTimer)
202 {
203     ITextHostImpl *This = (ITextHostImpl *)iface;
204     KillTimer(This->hWnd, idTimer);
205 }
206
207 void WINAPI ITextHostImpl_TxScrollWindowEx(ITextHost *iface,
208                                            INT dx, INT dy,
209                                            LPCRECT lprcScroll,
210                                            LPCRECT lprcClip,
211                                            HRGN hRgnUpdate,
212                                            LPRECT lprcUpdate,
213                                            UINT fuScroll)
214 {
215     ITextHostImpl *This = (ITextHostImpl *)iface;
216     ScrollWindowEx(This->hWnd, dx, dy, lprcScroll, lprcClip,
217                    hRgnUpdate, lprcUpdate, fuScroll);
218 }
219
220 void WINAPI ITextHostImpl_TxSetCapture(ITextHost *iface,
221                                        BOOL fCapture)
222 {
223     ITextHostImpl *This = (ITextHostImpl *)iface;
224     if (fCapture)
225         SetCapture(This->hWnd);
226     else
227         ReleaseCapture();
228 }
229
230 void WINAPI ITextHostImpl_TxSetFocus(ITextHost *iface)
231 {
232     ITextHostImpl *This = (ITextHostImpl *)iface;
233     SetFocus(This->hWnd);
234 }
235
236 void WINAPI ITextHostImpl_TxSetCursor(ITextHost *iface,
237                                       HCURSOR hcur,
238                                       BOOL fText)
239 {
240     SetCursor(hcur);
241 }
242
243 BOOL WINAPI ITextHostImpl_TxScreenToClient(ITextHost *iface,
244                                            LPPOINT lppt)
245 {
246     ITextHostImpl *This = (ITextHostImpl *)iface;
247     return ScreenToClient(This->hWnd, lppt);
248 }
249
250 BOOL WINAPI ITextHostImpl_TxClientToScreen(ITextHost *iface,
251                                            LPPOINT lppt)
252 {
253     ITextHostImpl *This = (ITextHostImpl *)iface;
254     return ClientToScreen(This->hWnd, lppt);
255 }
256
257 HRESULT WINAPI ITextHostImpl_TxActivate(ITextHost *iface,
258                                         LONG *plOldState)
259 {
260     ITextHostImpl *This = (ITextHostImpl *)iface;
261     *plOldState = (LONG)SetActiveWindow(This->hWnd);
262     return (*plOldState ? S_OK : E_FAIL);
263 }
264
265 HRESULT WINAPI ITextHostImpl_TxDeactivate(ITextHost *iface,
266                                           LONG lNewState)
267 {
268     HWND ret = SetActiveWindow((HWND)lNewState);
269     return (ret ? S_OK : E_FAIL);
270 }
271
272 HRESULT WINAPI ITextHostImpl_TxGetClientRect(ITextHost *iface,
273                                              LPRECT prc)
274 {
275     ITextHostImpl *This = (ITextHostImpl *)iface;
276     int ret = GetClientRect(This->hWnd, prc);
277     return (ret ? S_OK : E_FAIL);
278 }
279
280 HRESULT WINAPI ITextHostImpl_TxGetViewInset(ITextHost *iface,
281                                             LPRECT prc)
282 {
283     prc->top = 0;
284     prc->left = 0;
285     prc->bottom = 0;
286     prc->right = 0;
287     return S_OK;
288 }
289
290 HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface,
291                                              const CHARFORMATW **ppCF)
292 {
293     return E_NOTIMPL;
294 }
295
296 HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface,
297                                              const PARAFORMAT **ppPF)
298 {
299     return E_NOTIMPL;
300 }
301
302 COLORREF WINAPI ITextHostImpl_TxGetSysColor(ITextHost *iface,
303                                             int nIndex)
304 {
305     return GetSysColor(nIndex);
306 }
307
308 HRESULT WINAPI ITextHostImpl_TxGetBackStyle(ITextHost *iface,
309                                             TXTBACKSTYLE *pStyle)
310 {
311     *pStyle = TXTBACK_OPAQUE;
312     return S_OK;
313 }
314
315 HRESULT WINAPI ITextHostImpl_TxGetMaxLength(ITextHost *iface,
316                                             DWORD *pLength)
317 {
318     *pLength = INFINITE;
319     return S_OK;
320 }
321
322 HRESULT WINAPI ITextHostImpl_TxGetScrollBars(ITextHost *iface,
323                                              DWORD *pdwScrollBar)
324 {
325     ITextHostImpl *This = (ITextHostImpl *)iface;
326     ME_TextEditor *editor = (ME_TextEditor*)GetWindowLongW(This->hWnd, 0);
327     const DWORD mask = WS_VSCROLL|
328                        WS_HSCROLL|
329                        ES_AUTOVSCROLL|
330                        ES_AUTOHSCROLL|
331                        ES_DISABLENOSCROLL;
332     if (editor)
333     {
334         *pdwScrollBar = editor->styleFlags & mask;
335     } else {
336         DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
337         if (style & WS_VSCROLL)
338             style |= ES_AUTOVSCROLL;
339         if (!This->bEmulateVersion10 && (style & WS_HSCROLL))
340             style |= ES_AUTOHSCROLL;
341         *pdwScrollBar = style & mask;
342     }
343     return S_OK;
344 }
345
346 HRESULT WINAPI ITextHostImpl_TxGetPasswordChar(ITextHost *iface,
347                                                WCHAR *pch)
348 {
349     *pch = '*';
350     return S_OK;
351 }
352
353 HRESULT WINAPI ITextHostImpl_TxGetAcceleratorPos(ITextHost *iface,
354                                                  LONG *pch)
355 {
356     *pch = -1;
357     return S_OK;
358 }
359
360 HRESULT WINAPI ITextHostImpl_TxGetExtent(ITextHost *iface,
361                                          LPSIZEL lpExtent)
362 {
363     return E_NOTIMPL;
364 }
365
366 HRESULT WINAPI ITextHostImpl_OnTxCharFormatChange(ITextHost *iface,
367                                                   const CHARFORMATW *pcf)
368 {
369     return S_OK;
370 }
371
372 HRESULT WINAPI ITextHostImpl_OnTxParaFormatChange(ITextHost *iface,
373                                                   const PARAFORMAT *ppf)
374 {
375     return S_OK;
376 }
377
378 HRESULT WINAPI ITextHostImpl_TxGetPropertyBits(ITextHost *iface,
379                                                DWORD dwMask,
380                                                DWORD *pdwBits)
381 {
382     ITextHostImpl *This = (ITextHostImpl *)iface;
383     ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(This->hWnd, 0);
384     DWORD style;
385     DWORD dwBits = 0;
386
387     if (editor)
388     {
389         style = editor->styleFlags;
390         if (editor->mode & TM_RICHTEXT)
391             dwBits |= TXTBIT_RICHTEXT;
392         if (editor->bWordWrap)
393             dwBits |= TXTBIT_WORDWRAP;
394         if (style & ECO_AUTOWORDSELECTION)
395             dwBits |= TXTBIT_AUTOWORDSEL;
396     } else {
397         DWORD dwScrollBar;
398
399         style = GetWindowLongW(This->hWnd, GWL_STYLE);
400         ITextHostImpl_TxGetScrollBars(iface, &dwScrollBar);
401
402         dwBits |= TXTBIT_RICHTEXT|TXTBIT_AUTOWORDSEL;
403         if (!(dwScrollBar & ES_AUTOHSCROLL))
404             dwBits |= TXTBIT_WORDWRAP;
405     }
406
407     /* Bits that correspond to window styles. */
408     if (style & ES_MULTILINE)
409         dwBits |= TXTBIT_MULTILINE;
410     if (style & ES_READONLY)
411         dwBits |= TXTBIT_READONLY;
412     if (style & ES_PASSWORD)
413         dwBits |= TXTBIT_USEPASSWORD;
414     if (!(style & ES_NOHIDESEL))
415         dwBits |= TXTBIT_HIDESELECTION;
416     if (style & ES_SAVESEL)
417         dwBits |= TXTBIT_SAVESELECTION;
418     if (style & ES_VERTICAL)
419         dwBits |= TXTBIT_VERTICAL;
420     if (style & ES_NOOLEDRAGDROP)
421         dwBits |= TXTBIT_DISABLEDRAG;
422
423     dwBits |= TXTBIT_ALLOWBEEP;
424
425     /* The following bits are always FALSE because they are probably only
426      * needed for ITextServices_OnTxPropertyBitsChange:
427      *   TXTBIT_VIEWINSETCHANGE
428      *   TXTBIT_BACKSTYLECHANGE
429      *   TXTBIT_MAXLENGTHCHANGE
430      *   TXTBIT_CHARFORMATCHANGE
431      *   TXTBIT_PARAFORMATCHANGE
432      *   TXTBIT_SHOWACCELERATOR
433      *   TXTBIT_EXTENTCHANGE
434      *   TXTBIT_SELBARCHANGE
435      *   TXTBIT_SCROLLBARCHANGE
436      *   TXTBIT_CLIENTRECTCHANGE
437      *
438      * Documented by MSDN as not supported:
439      *   TXTBIT_USECURRENTBKG
440      */
441
442     *pdwBits = dwBits & dwMask;
443     return S_OK;
444 }
445
446 HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface,
447                                       DWORD iNotify,
448                                       void *pv)
449 {
450     ITextHostImpl *This = (ITextHostImpl *)iface;
451     HWND hwnd = This->hWnd;
452     HWND parent = GetParent(hwnd);
453     UINT id = GetWindowLongW(hwnd, GWLP_ID);
454
455     /* Note: EN_MSGFILTER is documented as not being sent to TxNotify */
456
457     switch (iNotify)
458     {
459         case EN_DROPFILES:
460         case EN_LINK:
461         case EN_OLEOPFAILED:
462         case EN_PROTECTED:
463         case EN_REQUESTRESIZE:
464         case EN_SAVECLIPBOARD:
465         case EN_SELCHANGE:
466         case EN_STOPNOUNDO:
467         {
468             /* FIXME: Verify this assumption that pv starts with NMHDR. */
469             NMHDR *info = pv;
470             if (!info)
471                 return E_FAIL;
472
473             info->hwndFrom = hwnd;
474             info->idFrom = id;
475             info->code = iNotify;
476             SendMessageW(parent, WM_NOTIFY, id, (LPARAM)info);
477             break;
478         }
479
480         case EN_UPDATE:
481             /* Only sent when the window is visible. */
482             if (!IsWindowVisible(This->hWnd))
483                 break;
484             /* Fall through */
485         case EN_CHANGE:
486         case EN_ERRSPACE:
487         case EN_HSCROLL:
488         case EN_KILLFOCUS:
489         case EN_MAXTEXT:
490         case EN_SETFOCUS:
491         case EN_VSCROLL:
492             SendMessageW(parent, WM_COMMAND, MAKEWPARAM(id, iNotify), (LPARAM)hwnd);
493             break;
494
495         default:
496             return E_FAIL;
497     }
498     return S_OK;
499 }
500
501 HIMC WINAPI ITextHostImpl_TxImmGetContext(ITextHost *iface)
502 {
503     ITextHostImpl *This = (ITextHostImpl *)iface;
504     return ImmGetContext(This->hWnd);
505 }
506
507 void WINAPI ITextHostImpl_TxImmReleaseContext(ITextHost *iface,
508                                               HIMC himc)
509 {
510     ITextHostImpl *This = (ITextHostImpl *)iface;
511     ImmReleaseContext(This->hWnd, himc);
512 }
513
514 HRESULT WINAPI ITextHostImpl_TxGetSelectionBarWidth(ITextHost *iface,
515                                                     LONG *lSelBarWidth)
516 {
517     ITextHostImpl *This = (ITextHostImpl *)iface;
518     ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(This->hWnd, 0);
519
520     DWORD style = editor ? editor->styleFlags
521                          : GetWindowLongW(This->hWnd, GWL_STYLE);
522     *lSelBarWidth = (style & ES_SELECTIONBAR) ? 225 : 0; /* in HIMETRIC */
523     return S_OK;
524 }
525
526
527 #ifdef __i386__  /* thiscall functions are i386-specific */
528
529 #define THISCALL(func) __thiscall_ ## func
530 #define DEFINE_THISCALL_WRAPPER(func) \
531    extern typeof(func) THISCALL(func); \
532    __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
533                    "popl %eax\n\t" \
534                    "pushl %ecx\n\t" \
535                    "pushl %eax\n\t" \
536                    "jmp " __ASM_NAME(#func) )
537
538 #else /* __i386__ */
539
540 #define THISCALL(func) func
541 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
542
543 #endif /* __i386__ */
544
545 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetDC);
546 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxReleaseDC);
547 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxShowScrollBar);
548 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxEnableScrollBar);
549 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxSetScrollRange);
550 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxSetScrollPos);
551 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxInvalidateRect);
552 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxViewChange);
553 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxCreateCaret);
554 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxShowCaret);
555 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxSetCaretPos);
556 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxSetTimer);
557 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxKillTimer);
558 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxScrollWindowEx);
559 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxSetCapture);
560 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxSetFocus);
561 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxSetCursor);
562 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxScreenToClient);
563 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxClientToScreen);
564 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxActivate);
565 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxDeactivate);
566 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetClientRect);
567 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetViewInset);
568 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetCharFormat);
569 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetParaFormat);
570 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetSysColor);
571 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetBackStyle);
572 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetMaxLength);
573 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetScrollBars);
574 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetPasswordChar);
575 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetAcceleratorPos);
576 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetExtent);
577 DEFINE_THISCALL_WRAPPER(ITextHostImpl_OnTxCharFormatChange);
578 DEFINE_THISCALL_WRAPPER(ITextHostImpl_OnTxParaFormatChange);
579 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetPropertyBits);
580 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxNotify);
581 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxImmGetContext);
582 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxImmReleaseContext);
583 DEFINE_THISCALL_WRAPPER(ITextHostImpl_TxGetSelectionBarWidth);
584
585 static ITextHostVtbl textHostVtbl = {
586     ITextHostImpl_QueryInterface,
587     ITextHostImpl_AddRef,
588     ITextHostImpl_Release,
589     THISCALL(ITextHostImpl_TxGetDC),
590     THISCALL(ITextHostImpl_TxReleaseDC),
591     THISCALL(ITextHostImpl_TxShowScrollBar),
592     THISCALL(ITextHostImpl_TxEnableScrollBar),
593     THISCALL(ITextHostImpl_TxSetScrollRange),
594     THISCALL(ITextHostImpl_TxSetScrollPos),
595     THISCALL(ITextHostImpl_TxInvalidateRect),
596     THISCALL(ITextHostImpl_TxViewChange),
597     THISCALL(ITextHostImpl_TxCreateCaret),
598     THISCALL(ITextHostImpl_TxShowCaret),
599     THISCALL(ITextHostImpl_TxSetCaretPos),
600     THISCALL(ITextHostImpl_TxSetTimer),
601     THISCALL(ITextHostImpl_TxKillTimer),
602     THISCALL(ITextHostImpl_TxScrollWindowEx),
603     THISCALL(ITextHostImpl_TxSetCapture),
604     THISCALL(ITextHostImpl_TxSetFocus),
605     THISCALL(ITextHostImpl_TxSetCursor),
606     THISCALL(ITextHostImpl_TxScreenToClient),
607     THISCALL(ITextHostImpl_TxClientToScreen),
608     THISCALL(ITextHostImpl_TxActivate),
609     THISCALL(ITextHostImpl_TxDeactivate),
610     THISCALL(ITextHostImpl_TxGetClientRect),
611     THISCALL(ITextHostImpl_TxGetViewInset),
612     THISCALL(ITextHostImpl_TxGetCharFormat),
613     THISCALL(ITextHostImpl_TxGetParaFormat),
614     THISCALL(ITextHostImpl_TxGetSysColor),
615     THISCALL(ITextHostImpl_TxGetBackStyle),
616     THISCALL(ITextHostImpl_TxGetMaxLength),
617     THISCALL(ITextHostImpl_TxGetScrollBars),
618     THISCALL(ITextHostImpl_TxGetPasswordChar),
619     THISCALL(ITextHostImpl_TxGetAcceleratorPos),
620     THISCALL(ITextHostImpl_TxGetExtent),
621     THISCALL(ITextHostImpl_OnTxCharFormatChange),
622     THISCALL(ITextHostImpl_OnTxParaFormatChange),
623     THISCALL(ITextHostImpl_TxGetPropertyBits),
624     THISCALL(ITextHostImpl_TxNotify),
625     THISCALL(ITextHostImpl_TxImmGetContext),
626     THISCALL(ITextHostImpl_TxImmReleaseContext),
627     THISCALL(ITextHostImpl_TxGetSelectionBarWidth),
628 };
629
630 #ifdef __i386__  /* thiscall functions are i386-specific */
631
632 #define STDCALL(func) __stdcall_ ## func
633 #define DEFINE_STDCALL_WRAPPER(num,func) \
634    extern typeof(func) __stdcall_ ## func; \
635    __ASM_GLOBAL_FUNC(__stdcall_ ## func, \
636                    "popl %eax\n\t" \
637                    "popl %ecx\n\t" \
638                    "pushl %eax\n\t" \
639                    "movl (%ecx), %eax\n\t" \
640                    "jmp *(4*(" #num "))(%eax)" )
641
642 DEFINE_STDCALL_WRAPPER(3,ITextHostImpl_TxGetDC);
643 DEFINE_STDCALL_WRAPPER(4,ITextHostImpl_TxReleaseDC);
644 DEFINE_STDCALL_WRAPPER(5,ITextHostImpl_TxShowScrollBar);
645 DEFINE_STDCALL_WRAPPER(6,ITextHostImpl_TxEnableScrollBar);
646 DEFINE_STDCALL_WRAPPER(7,ITextHostImpl_TxSetScrollRange);
647 DEFINE_STDCALL_WRAPPER(8,ITextHostImpl_TxSetScrollPos);
648 DEFINE_STDCALL_WRAPPER(9,ITextHostImpl_TxInvalidateRect);
649 DEFINE_STDCALL_WRAPPER(10,ITextHostImpl_TxViewChange);
650 DEFINE_STDCALL_WRAPPER(11,ITextHostImpl_TxCreateCaret);
651 DEFINE_STDCALL_WRAPPER(12,ITextHostImpl_TxShowCaret);
652 DEFINE_STDCALL_WRAPPER(13,ITextHostImpl_TxSetCaretPos);
653 DEFINE_STDCALL_WRAPPER(14,ITextHostImpl_TxSetTimer);
654 DEFINE_STDCALL_WRAPPER(15,ITextHostImpl_TxKillTimer);
655 DEFINE_STDCALL_WRAPPER(16,ITextHostImpl_TxScrollWindowEx);
656 DEFINE_STDCALL_WRAPPER(17,ITextHostImpl_TxSetCapture);
657 DEFINE_STDCALL_WRAPPER(18,ITextHostImpl_TxSetFocus);
658 DEFINE_STDCALL_WRAPPER(19,ITextHostImpl_TxSetCursor);
659 DEFINE_STDCALL_WRAPPER(20,ITextHostImpl_TxScreenToClient);
660 DEFINE_STDCALL_WRAPPER(21,ITextHostImpl_TxClientToScreen);
661 DEFINE_STDCALL_WRAPPER(22,ITextHostImpl_TxActivate);
662 DEFINE_STDCALL_WRAPPER(23,ITextHostImpl_TxDeactivate);
663 DEFINE_STDCALL_WRAPPER(24,ITextHostImpl_TxGetClientRect);
664 DEFINE_STDCALL_WRAPPER(25,ITextHostImpl_TxGetViewInset);
665 DEFINE_STDCALL_WRAPPER(26,ITextHostImpl_TxGetCharFormat);
666 DEFINE_STDCALL_WRAPPER(27,ITextHostImpl_TxGetParaFormat);
667 DEFINE_STDCALL_WRAPPER(28,ITextHostImpl_TxGetSysColor);
668 DEFINE_STDCALL_WRAPPER(29,ITextHostImpl_TxGetBackStyle);
669 DEFINE_STDCALL_WRAPPER(30,ITextHostImpl_TxGetMaxLength);
670 DEFINE_STDCALL_WRAPPER(31,ITextHostImpl_TxGetScrollBars);
671 DEFINE_STDCALL_WRAPPER(32,ITextHostImpl_TxGetPasswordChar);
672 DEFINE_STDCALL_WRAPPER(33,ITextHostImpl_TxGetAcceleratorPos);
673 DEFINE_STDCALL_WRAPPER(34,ITextHostImpl_TxGetExtent);
674 DEFINE_STDCALL_WRAPPER(35,ITextHostImpl_OnTxCharFormatChange);
675 DEFINE_STDCALL_WRAPPER(36,ITextHostImpl_OnTxParaFormatChange);
676 DEFINE_STDCALL_WRAPPER(37,ITextHostImpl_TxGetPropertyBits);
677 DEFINE_STDCALL_WRAPPER(38,ITextHostImpl_TxNotify);
678 DEFINE_STDCALL_WRAPPER(39,ITextHostImpl_TxImmGetContext);
679 DEFINE_STDCALL_WRAPPER(40,ITextHostImpl_TxImmReleaseContext);
680 DEFINE_STDCALL_WRAPPER(41,ITextHostImpl_TxGetSelectionBarWidth);
681
682 ITextHostVtbl itextHostStdcallVtbl = {
683     NULL,
684     NULL,
685     NULL,
686     __stdcall_ITextHostImpl_TxGetDC,
687     __stdcall_ITextHostImpl_TxReleaseDC,
688     __stdcall_ITextHostImpl_TxShowScrollBar,
689     __stdcall_ITextHostImpl_TxEnableScrollBar,
690     __stdcall_ITextHostImpl_TxSetScrollRange,
691     __stdcall_ITextHostImpl_TxSetScrollPos,
692     __stdcall_ITextHostImpl_TxInvalidateRect,
693     __stdcall_ITextHostImpl_TxViewChange,
694     __stdcall_ITextHostImpl_TxCreateCaret,
695     __stdcall_ITextHostImpl_TxShowCaret,
696     __stdcall_ITextHostImpl_TxSetCaretPos,
697     __stdcall_ITextHostImpl_TxSetTimer,
698     __stdcall_ITextHostImpl_TxKillTimer,
699     __stdcall_ITextHostImpl_TxScrollWindowEx,
700     __stdcall_ITextHostImpl_TxSetCapture,
701     __stdcall_ITextHostImpl_TxSetFocus,
702     __stdcall_ITextHostImpl_TxSetCursor,
703     __stdcall_ITextHostImpl_TxScreenToClient,
704     __stdcall_ITextHostImpl_TxClientToScreen,
705     __stdcall_ITextHostImpl_TxActivate,
706     __stdcall_ITextHostImpl_TxDeactivate,
707     __stdcall_ITextHostImpl_TxGetClientRect,
708     __stdcall_ITextHostImpl_TxGetViewInset,
709     __stdcall_ITextHostImpl_TxGetCharFormat,
710     __stdcall_ITextHostImpl_TxGetParaFormat,
711     __stdcall_ITextHostImpl_TxGetSysColor,
712     __stdcall_ITextHostImpl_TxGetBackStyle,
713     __stdcall_ITextHostImpl_TxGetMaxLength,
714     __stdcall_ITextHostImpl_TxGetScrollBars,
715     __stdcall_ITextHostImpl_TxGetPasswordChar,
716     __stdcall_ITextHostImpl_TxGetAcceleratorPos,
717     __stdcall_ITextHostImpl_TxGetExtent,
718     __stdcall_ITextHostImpl_OnTxCharFormatChange,
719     __stdcall_ITextHostImpl_OnTxParaFormatChange,
720     __stdcall_ITextHostImpl_TxGetPropertyBits,
721     __stdcall_ITextHostImpl_TxNotify,
722     __stdcall_ITextHostImpl_TxImmGetContext,
723     __stdcall_ITextHostImpl_TxImmReleaseContext,
724     __stdcall_ITextHostImpl_TxGetSelectionBarWidth,
725 };
726
727 #endif /* __i386__ */