msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / riched20 / txtsrv.c
blobd7b915cc1c9f2926bda3f26a2ead6b24a25e51e5
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
26 #define COBJMACROS
28 #include "editor.h"
29 #include "ole2.h"
30 #include "oleauto.h"
31 #include "richole.h"
32 #include "imm.h"
33 #include "textserv.h"
34 #include "wine/debug.h"
35 #include "editstr.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, \
43 "popl %eax\n\t" \
44 "pushl %ecx\n\t" \
45 "pushl %eax\n\t" \
46 "jmp " __ASM_NAME(#func) )
47 #else /* __i386__ */
49 #define THISCALL(func) func
50 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
52 #endif /* __i386__ */
54 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
56 typedef struct ITextServicesImpl {
57 const ITextServicesVtbl *lpVtbl;
58 ITextHost *pMyHost;
59 LONG ref;
60 CRITICAL_SECTION csTxtSrv;
61 ME_TextEditor *editor;
62 char spare[256];
63 } ITextServicesImpl;
65 static const ITextServicesVtbl textservices_Vtbl;
67 /******************************************************************
68 * CreateTextServices (RICHED20.4)
70 HRESULT WINAPI CreateTextServices(IUnknown * pUnkOuter,
71 ITextHost * pITextHost,
72 IUnknown **ppUnk)
74 ITextServicesImpl *ITextImpl;
75 HRESULT hres;
76 TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
77 if (pITextHost == NULL)
78 return E_POINTER;
80 ITextImpl = CoTaskMemAlloc(sizeof(*ITextImpl));
81 if (ITextImpl == NULL)
82 return E_OUTOFMEMORY;
83 InitializeCriticalSection(&ITextImpl->csTxtSrv);
84 ITextImpl->csTxtSrv.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ITextServicesImpl.csTxtSrv");
85 ITextImpl->ref = 1;
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);
92 if (pUnkOuter)
94 FIXME("Support aggregation\n");
95 return CLASS_E_NOAGGREGATION;
98 *ppUnk = (IUnknown *)ITextImpl;
99 return S_OK;
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,
106 REFIID riid,
107 LPVOID * ppv)
109 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
110 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
111 *ppv = NULL;
112 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
113 *ppv = This;
115 if (*ppv)
117 IUnknown_AddRef((IUnknown *)(*ppv));
118 TRACE ("-- Interface = %p\n", *ppv);
119 return S_OK;
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);
131 return ref;
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);
141 if (!ref)
143 ITextHost_Release(This->pMyHost);
144 This->csTxtSrv.DebugInfo->Spare[0] = 0;
145 DeleteCriticalSection(&This->csTxtSrv);
146 CoTaskMemFree(This);
148 return ref;
151 HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface,
152 UINT msg,
153 WPARAM wparam,
154 LPARAM lparam,
155 LRESULT* plresult)
157 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
158 HRESULT hresult;
160 *plresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
161 return hresult;
164 HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface,
165 DWORD dwDrawAspect,
166 LONG lindex,
167 void* pvAspect,
168 DVTARGETDEVICE* ptd,
169 HDC hdcDraw,
170 HDC hdcTargetDev,
171 LPCRECTL lprcBounds,
172 LPCRECTL lprcWBounds,
173 LPRECT lprcUpdate,
174 BOOL (CALLBACK * pfnContinue)(DWORD),
175 DWORD dwContinue,
176 LONG lViewId)
178 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
180 FIXME("%p: STUB\n", This);
181 return E_NOTIMPL;
184 HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface,
185 LONG* plMin,
186 LONG* plMax,
187 LONG* plPos,
188 LONG* plPage,
189 BOOL* pfEnabled)
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;
198 return S_OK;
201 HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface,
202 LONG* plMin,
203 LONG* plMax,
204 LONG* plPos,
205 LONG* plPage,
206 BOOL* pfEnabled)
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;
215 return S_OK;
218 HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface,
219 DWORD dwDrawAspect,
220 LONG lindex,
221 void* pvAspect,
222 DVTARGETDEVICE* ptd,
223 HDC hdcDraw,
224 HDC hicTargetDev,
225 LPCRECT lprcClient,
226 INT x, INT y)
228 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
230 FIXME("%p: STUB\n", This);
231 return E_NOTIMPL;
234 HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface,
235 DWORD dwDrawAspect,
236 LONG lindex,
237 void* pvAspect,
238 DVTARGETDEVICE* ptd,
239 HDC hdcDraw,
240 HDC hicTargetDev,
241 LPCRECT lprcClient,
242 INT x, INT y,
243 DWORD* pHitResult)
245 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
247 FIXME("%p: STUB\n", This);
248 return E_NOTIMPL;
251 HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface,
252 LPCRECT prcClient)
254 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
256 FIXME("%p: STUB\n", This);
257 return E_NOTIMPL;
260 HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
262 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
264 FIXME("%p: STUB\n", This);
265 return E_NOTIMPL;
268 HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
270 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
272 FIXME("%p: STUB\n", This);
273 return E_NOTIMPL;
276 HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
278 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
280 FIXME("%p: STUB\n", This);
281 return E_NOTIMPL;
284 HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface,
285 BSTR* pbstrText)
287 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
288 int length;
290 length = ME_GetTextLength(This->editor);
291 if (length)
293 BSTR bstr;
294 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
295 if (bstr == NULL)
296 return E_OUTOFMEMORY;
298 ME_GetTextW(This->editor, bstr , 0, length, FALSE);
299 *pbstrText = bstr;
300 } else {
301 *pbstrText = NULL;
304 return S_OK;
307 HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface,
308 LPCWSTR pszText)
310 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
312 ME_InternalDeleteText(This->editor, 0, ME_GetTextLength(This->editor),
313 FALSE);
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;
318 OleFlushClipboard();
319 ME_EmptyUndoStack(This->editor);
320 ME_UpdateRepaint(This->editor);
322 return S_OK;
325 HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface,
326 LONG* x)
328 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
330 FIXME("%p: STUB\n", This);
331 return E_NOTIMPL;
334 HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface,
335 LONG* x)
337 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
339 FIXME("%p: STUB\n", This);
340 return E_NOTIMPL;
343 HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
344 DWORD dwAspect,
345 HDC hdcDraw,
346 HDC hicTargetDev,
347 DVTARGETDEVICE* ptd,
348 DWORD dwMode,
349 const SIZEL* psizelExtent,
350 LONG* pwidth,
351 LONG* pheight)
353 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
355 FIXME("%p: STUB\n", This);
356 return E_NOTIMPL;
359 HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface,
360 IDropTarget** ppDropTarget)
362 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
364 FIXME("%p: STUB\n", This);
365 return E_NOTIMPL;
368 HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface,
369 DWORD dwMask,
370 DWORD dwBits)
372 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
374 FIXME("%p: STUB\n", This);
375 return E_NOTIMPL;
378 HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface,
379 DWORD* pdwWidth,
380 DWORD* pdwHeight)
382 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
384 FIXME("%p: STUB\n", This);
385 return E_NOTIMPL;
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,
410 fnTextSrv_AddRef,
411 fnTextSrv_Release,
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)