2 * RichEdit - functions and interfaces around CreateTextServices
4 * Copyright 2005, 2006, Maarten Lankhorst
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.
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.
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
22 #include "wine/port.h"
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
34 #include "wine/debug.h"
37 #ifdef __i386__ /* thiscall functions are i386-specific */
39 #define THISCALL(func) __thiscall_ ## func
40 #define DEFINE_THISCALL_WRAPPER(func,args) \
41 extern typeof(func) THISCALL(func); \
42 __ASM_STDCALL_FUNC(__thiscall_ ## func, args, \
46 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
49 #define THISCALL(func) func
50 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
54 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
56 typedef struct ITextServicesImpl {
57 ITextServices ITextServices_iface;
60 CRITICAL_SECTION csTxtSrv;
61 ME_TextEditor *editor;
65 static const ITextServicesVtbl textservices_Vtbl;
67 /******************************************************************
68 * CreateTextServices (RICHED20.4)
70 HRESULT WINAPI CreateTextServices(IUnknown * pUnkOuter,
71 ITextHost * pITextHost,
74 ITextServicesImpl *ITextImpl;
76 TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
77 if (pITextHost == NULL)
80 ITextImpl = CoTaskMemAlloc(sizeof(*ITextImpl));
81 if (ITextImpl == NULL)
83 InitializeCriticalSection(&ITextImpl->csTxtSrv);
84 ITextImpl->csTxtSrv.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ITextServicesImpl.csTxtSrv");
86 ITextHost_AddRef(pITextHost);
87 ITextImpl->pMyHost = pITextHost;
88 ITextImpl->ITextServices_iface.lpVtbl = &textservices_Vtbl;
89 ITextImpl->editor = ME_MakeEditor(pITextHost, FALSE);
90 ITextImpl->editor->exStyleFlags = 0;
91 ITextImpl->editor->rcFormat.left = 0;
92 ITextImpl->editor->rcFormat.top = 0;
93 ITextImpl->editor->rcFormat.right = 0;
94 ITextImpl->editor->rcFormat.bottom = 0;
96 ME_HandleMessage(ITextImpl->editor, WM_CREATE, 0, 0, TRUE, &hres);
100 FIXME("Support aggregation\n");
101 return CLASS_E_NOAGGREGATION;
104 *ppUnk = (IUnknown *)&ITextImpl->ITextServices_iface;
108 static inline ITextServicesImpl *impl_from_ITextServices(ITextServices *iface)
110 return CONTAINING_RECORD(iface, ITextServicesImpl, ITextServices_iface);
113 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices *iface, REFIID riid, void **ppv)
115 ITextServicesImpl *This = impl_from_ITextServices(iface);
117 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
119 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
124 IUnknown_AddRef((IUnknown *)(*ppv));
125 TRACE ("-- Interface = %p\n", *ppv);
128 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
129 return E_NOINTERFACE;
132 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
134 ITextServicesImpl *This = impl_from_ITextServices(iface);
135 DWORD ref = InterlockedIncrement(&This->ref);
137 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
141 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
143 ITextServicesImpl *This = impl_from_ITextServices(iface);
144 DWORD ref = InterlockedDecrement(&This->ref);
146 TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
150 ITextHost_Release(This->pMyHost);
151 This->csTxtSrv.DebugInfo->Spare[0] = 0;
152 DeleteCriticalSection(&This->csTxtSrv);
158 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface, UINT msg, WPARAM wparam,
159 LPARAM lparam, LRESULT *plresult)
161 ITextServicesImpl *This = impl_from_ITextServices(iface);
165 lresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
166 if (plresult) *plresult = lresult;
170 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
171 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw, HDC hdcTargetDev,
172 LPCRECTL lprcBounds, LPCRECTL lprcWBounds, LPRECT lprcUpdate,
173 BOOL (CALLBACK * pfnContinue)(DWORD), DWORD dwContinue,
176 ITextServicesImpl *This = impl_from_ITextServices(iface);
178 FIXME("%p: STUB\n", This);
182 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
183 LONG *plPage, BOOL *pfEnabled)
185 ITextServicesImpl *This = impl_from_ITextServices(iface);
187 *plMin = This->editor->horz_si.nMin;
188 *plMax = This->editor->horz_si.nMax;
189 *plPos = This->editor->horz_si.nPos;
190 *plPage = This->editor->horz_si.nPage;
191 *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
195 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
196 LONG *plPage, BOOL *pfEnabled)
198 ITextServicesImpl *This = impl_from_ITextServices(iface);
200 *plMin = This->editor->vert_si.nMin;
201 *plMax = This->editor->vert_si.nMax;
202 *plPos = This->editor->vert_si.nPos;
203 *plPage = This->editor->vert_si.nPage;
204 *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
208 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
209 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
210 HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y)
212 ITextServicesImpl *This = impl_from_ITextServices(iface);
214 FIXME("%p: STUB\n", This);
218 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
219 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
220 HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y,
223 ITextServicesImpl *This = impl_from_ITextServices(iface);
225 FIXME("%p: STUB\n", This);
229 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface, LPCRECT prcClient)
231 ITextServicesImpl *This = impl_from_ITextServices(iface);
233 FIXME("%p: STUB\n", This);
237 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
239 ITextServicesImpl *This = impl_from_ITextServices(iface);
241 FIXME("%p: STUB\n", This);
245 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
247 ITextServicesImpl *This = impl_from_ITextServices(iface);
249 FIXME("%p: STUB\n", This);
253 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
255 ITextServicesImpl *This = impl_from_ITextServices(iface);
257 FIXME("%p: STUB\n", This);
261 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface, BSTR *pbstrText)
263 ITextServicesImpl *This = impl_from_ITextServices(iface);
266 length = ME_GetTextLength(This->editor);
271 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
273 return E_OUTOFMEMORY;
275 ME_CursorFromCharOfs(This->editor, 0, &start);
276 ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE);
285 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface, LPCWSTR pszText)
287 ITextServicesImpl *This = impl_from_ITextServices(iface);
290 ME_SetCursorToStart(This->editor, &cursor);
291 ME_InternalDeleteText(This->editor, &cursor,
292 ME_GetTextLength(This->editor), FALSE);
293 ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
294 This->editor->pBuffer->pDefaultStyle);
295 ME_SetSelection(This->editor, 0, 0);
296 This->editor->nModifyStep = 0;
298 ME_EmptyUndoStack(This->editor);
299 ME_UpdateRepaint(This->editor, FALSE);
304 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface, LONG *x)
306 ITextServicesImpl *This = impl_from_ITextServices(iface);
308 FIXME("%p: STUB\n", This);
312 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface, LONG *x)
314 ITextServicesImpl *This = impl_from_ITextServices(iface);
316 FIXME("%p: STUB\n", This);
320 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface, DWORD dwAspect, HDC hdcDraw,
321 HDC hicTargetDev, DVTARGETDEVICE *ptd, DWORD dwMode,
322 const SIZEL *psizelExtent, LONG *pwidth, LONG *pheight)
324 ITextServicesImpl *This = impl_from_ITextServices(iface);
326 FIXME("%p: STUB\n", This);
330 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface, IDropTarget **ppDropTarget)
332 ITextServicesImpl *This = impl_from_ITextServices(iface);
334 FIXME("%p: STUB\n", This);
338 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface, DWORD dwMask, DWORD dwBits)
340 ITextServicesImpl *This = impl_from_ITextServices(iface);
342 FIXME("%p: STUB\n", This);
346 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface, DWORD *pdwWidth, DWORD *pdwHeight)
348 ITextServicesImpl *This = impl_from_ITextServices(iface);
350 FIXME("%p: STUB\n", This);
354 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage,20)
355 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw,52)
356 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll,24)
357 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll,24)
358 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor,40)
359 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint,44)
360 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate,8)
361 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate,4)
362 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate,4)
363 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate,4)
364 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText,8)
365 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText,8)
366 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX,8)
367 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos,8)
368 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize,36)
369 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget,8)
370 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange,12)
371 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize,12)
373 static const ITextServicesVtbl textservices_Vtbl =
375 fnTextSrv_QueryInterface,
378 THISCALL(fnTextSrv_TxSendMessage),
379 THISCALL(fnTextSrv_TxDraw),
380 THISCALL(fnTextSrv_TxGetHScroll),
381 THISCALL(fnTextSrv_TxGetVScroll),
382 THISCALL(fnTextSrv_OnTxSetCursor),
383 THISCALL(fnTextSrv_TxQueryHitPoint),
384 THISCALL(fnTextSrv_OnTxInplaceActivate),
385 THISCALL(fnTextSrv_OnTxInplaceDeactivate),
386 THISCALL(fnTextSrv_OnTxUIActivate),
387 THISCALL(fnTextSrv_OnTxUIDeactivate),
388 THISCALL(fnTextSrv_TxGetText),
389 THISCALL(fnTextSrv_TxSetText),
390 THISCALL(fnTextSrv_TxGetCurrentTargetX),
391 THISCALL(fnTextSrv_TxGetBaseLinePos),
392 THISCALL(fnTextSrv_TxGetNaturalSize),
393 THISCALL(fnTextSrv_TxGetDropTarget),
394 THISCALL(fnTextSrv_OnTxPropertyBitsChange),
395 THISCALL(fnTextSrv_TxGetCachedSize)