quartz: Free two assert calls from having side effects.
[wine/testsucceed.git] / dlls / riched20 / txtsrv.c
bloba2fe8dc3a70388555a9428d9f688a1d77a511cd5
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,args) \
41 extern typeof(func) THISCALL(func); \
42 __ASM_STDCALL_FUNC(__thiscall_ ## func, args, \
43 "popl %eax\n\t" \
44 "pushl %ecx\n\t" \
45 "pushl %eax\n\t" \
46 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
47 #else /* __i386__ */
49 #define THISCALL(func) func
50 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
52 #endif /* __i386__ */
54 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
56 typedef struct ITextServicesImpl {
57 ITextServices ITextServices_iface;
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->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);
98 if (pUnkOuter)
100 FIXME("Support aggregation\n");
101 return CLASS_E_NOAGGREGATION;
104 *ppUnk = (IUnknown *)&ITextImpl->ITextServices_iface;
105 return S_OK;
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);
118 *ppv = NULL;
119 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
120 *ppv = This;
122 if (*ppv)
124 IUnknown_AddRef((IUnknown *)(*ppv));
125 TRACE ("-- Interface = %p\n", *ppv);
126 return S_OK;
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);
138 return ref;
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);
148 if (!ref)
150 ITextHost_Release(This->pMyHost);
151 This->csTxtSrv.DebugInfo->Spare[0] = 0;
152 DeleteCriticalSection(&This->csTxtSrv);
153 CoTaskMemFree(This);
155 return ref;
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);
162 HRESULT hresult;
163 LRESULT lresult;
165 lresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
166 if (plresult) *plresult = lresult;
167 return hresult;
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,
174 LONG lViewId)
176 ITextServicesImpl *This = impl_from_ITextServices(iface);
178 FIXME("%p: STUB\n", This);
179 return E_NOTIMPL;
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;
192 return S_OK;
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;
205 return S_OK;
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);
215 return E_NOTIMPL;
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,
221 DWORD *pHitResult)
223 ITextServicesImpl *This = impl_from_ITextServices(iface);
225 FIXME("%p: STUB\n", This);
226 return E_NOTIMPL;
229 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface, LPCRECT prcClient)
231 ITextServicesImpl *This = impl_from_ITextServices(iface);
233 FIXME("%p: STUB\n", This);
234 return E_NOTIMPL;
237 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
239 ITextServicesImpl *This = impl_from_ITextServices(iface);
241 FIXME("%p: STUB\n", This);
242 return E_NOTIMPL;
245 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
247 ITextServicesImpl *This = impl_from_ITextServices(iface);
249 FIXME("%p: STUB\n", This);
250 return E_NOTIMPL;
253 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
255 ITextServicesImpl *This = impl_from_ITextServices(iface);
257 FIXME("%p: STUB\n", This);
258 return E_NOTIMPL;
261 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface, BSTR *pbstrText)
263 ITextServicesImpl *This = impl_from_ITextServices(iface);
264 int length;
266 length = ME_GetTextLength(This->editor);
267 if (length)
269 ME_Cursor start;
270 BSTR bstr;
271 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
272 if (bstr == NULL)
273 return E_OUTOFMEMORY;
275 ME_CursorFromCharOfs(This->editor, 0, &start);
276 ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE);
277 *pbstrText = bstr;
278 } else {
279 *pbstrText = NULL;
282 return S_OK;
285 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface, LPCWSTR pszText)
287 ITextServicesImpl *This = impl_from_ITextServices(iface);
288 ME_Cursor cursor;
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;
297 OleFlushClipboard();
298 ME_EmptyUndoStack(This->editor);
299 ME_UpdateRepaint(This->editor, FALSE);
301 return S_OK;
304 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface, LONG *x)
306 ITextServicesImpl *This = impl_from_ITextServices(iface);
308 FIXME("%p: STUB\n", This);
309 return E_NOTIMPL;
312 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface, LONG *x)
314 ITextServicesImpl *This = impl_from_ITextServices(iface);
316 FIXME("%p: STUB\n", This);
317 return E_NOTIMPL;
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);
327 return E_NOTIMPL;
330 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface, IDropTarget **ppDropTarget)
332 ITextServicesImpl *This = impl_from_ITextServices(iface);
334 FIXME("%p: STUB\n", This);
335 return E_NOTIMPL;
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);
343 return E_NOTIMPL;
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);
351 return E_NOTIMPL;
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,
376 fnTextSrv_AddRef,
377 fnTextSrv_Release,
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)