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