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