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) \
41 extern typeof(func) THISCALL(func); \
42 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
46 "jmp " __ASM_NAME(#func) )
49 #define THISCALL(func) func
50 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
54 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
56 typedef struct ITextServicesImpl {
57 const ITextServicesVtbl *lpVtbl;
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->lpVtbl = &textservices_Vtbl;
89 ITextImpl->editor = ME_MakeEditor(pITextHost, FALSE);
90 ME_HandleMessage(ITextImpl->editor, WM_CREATE, 0, 0, TRUE, &hres);
94 FIXME("Support aggregation\n");
95 return CLASS_E_NOAGGREGATION;
98 *ppUnk = (IUnknown *)ITextImpl;
102 #define ICOM_THIS_MULTI(impl,field,iface) \
103 impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
105 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices * iface,
109 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
110 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
112 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
117 IUnknown_AddRef((IUnknown *)(*ppv));
118 TRACE ("-- Interface = %p\n", *ppv);
121 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
122 return E_NOINTERFACE;
125 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
127 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
128 DWORD ref = InterlockedIncrement(&This->ref);
130 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
134 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
136 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
137 DWORD ref = InterlockedDecrement(&This->ref);
139 TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
143 ITextHost_Release(This->pMyHost);
144 This->csTxtSrv.DebugInfo->Spare[0] = 0;
145 DeleteCriticalSection(&This->csTxtSrv);
151 HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface,
157 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
160 *plresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
164 HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface,
172 LPCRECTL lprcWBounds,
174 BOOL (CALLBACK * pfnContinue)(DWORD),
178 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
180 FIXME("%p: STUB\n", This);
184 HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface,
191 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
193 *plMin = This->editor->horz_si.nMin;
194 *plMax = This->editor->horz_si.nMax;
195 *plPos = This->editor->horz_si.nPos;
196 *plPage = This->editor->horz_si.nPage;
197 *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
201 HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface,
208 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
210 *plMin = This->editor->vert_si.nMin;
211 *plMax = This->editor->vert_si.nMax;
212 *plPos = This->editor->vert_si.nPos;
213 *plPage = This->editor->vert_si.nPage;
214 *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
218 HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface,
228 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
230 FIXME("%p: STUB\n", This);
234 HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface,
245 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
247 FIXME("%p: STUB\n", This);
251 HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface,
254 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
256 FIXME("%p: STUB\n", This);
260 HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
262 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
264 FIXME("%p: STUB\n", This);
268 HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
270 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
272 FIXME("%p: STUB\n", This);
276 HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
278 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
280 FIXME("%p: STUB\n", This);
284 HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface,
287 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
290 length = ME_GetTextLength(This->editor);
294 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
296 return E_OUTOFMEMORY;
298 ME_GetTextW(This->editor, bstr , 0, length, FALSE);
307 HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface,
310 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
312 ME_InternalDeleteText(This->editor, 0, ME_GetTextLength(This->editor),
314 ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
315 This->editor->pBuffer->pDefaultStyle);
316 ME_SetSelection(This->editor, 0, 0);
317 This->editor->nModifyStep = 0;
319 ME_EmptyUndoStack(This->editor);
320 ME_UpdateRepaint(This->editor);
325 HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface,
328 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
330 FIXME("%p: STUB\n", This);
334 HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface,
337 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
339 FIXME("%p: STUB\n", This);
343 HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
349 const SIZEL* psizelExtent,
353 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
355 FIXME("%p: STUB\n", This);
359 HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface,
360 IDropTarget** ppDropTarget)
362 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
364 FIXME("%p: STUB\n", This);
368 HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface,
372 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
374 FIXME("%p: STUB\n", This);
378 HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface,
382 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
384 FIXME("%p: STUB\n", This);
388 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage)
389 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw)
390 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll)
391 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll)
392 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor)
393 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint)
394 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate)
395 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate)
396 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate)
397 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate)
398 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText)
399 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText)
400 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX)
401 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos)
402 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize)
403 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget)
404 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange)
405 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize)
407 static const ITextServicesVtbl textservices_Vtbl =
409 fnTextSrv_QueryInterface,
412 THISCALL(fnTextSrv_TxSendMessage),
413 THISCALL(fnTextSrv_TxDraw),
414 THISCALL(fnTextSrv_TxGetHScroll),
415 THISCALL(fnTextSrv_TxGetVScroll),
416 THISCALL(fnTextSrv_OnTxSetCursor),
417 THISCALL(fnTextSrv_TxQueryHitPoint),
418 THISCALL(fnTextSrv_OnTxInplaceActivate),
419 THISCALL(fnTextSrv_OnTxInplaceDeactivate),
420 THISCALL(fnTextSrv_OnTxUIActivate),
421 THISCALL(fnTextSrv_OnTxUIDeactivate),
422 THISCALL(fnTextSrv_TxGetText),
423 THISCALL(fnTextSrv_TxSetText),
424 THISCALL(fnTextSrv_TxGetCurrentTargetX),
425 THISCALL(fnTextSrv_TxGetBaseLinePos),
426 THISCALL(fnTextSrv_TxGetNaturalSize),
427 THISCALL(fnTextSrv_TxGetDropTarget),
428 THISCALL(fnTextSrv_OnTxPropertyBitsChange),
429 THISCALL(fnTextSrv_TxGetCachedSize)