msxml3: Properly free namespace structure pointer.
[wine/testsucceed.git] / dlls / riched20 / txtsrv.c
blob7ab2af45162b484ea393f766e2ec5bbcf24bb093
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 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 ITextImpl->editor->exStyleFlags = 0;
91 ITextImpl->editor->rcFormat = (RECT){0,0,0,0};
92 ME_HandleMessage(ITextImpl->editor, WM_CREATE, 0, 0, TRUE, &hres);
94 if (pUnkOuter)
96 FIXME("Support aggregation\n");
97 return CLASS_E_NOAGGREGATION;
100 *ppUnk = (IUnknown *)ITextImpl;
101 return S_OK;
104 #define ICOM_THIS_MULTI(impl,field,iface) \
105 impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
107 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices * iface,
108 REFIID riid,
109 LPVOID * ppv)
111 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
112 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
113 *ppv = NULL;
114 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
115 *ppv = This;
117 if (*ppv)
119 IUnknown_AddRef((IUnknown *)(*ppv));
120 TRACE ("-- Interface = %p\n", *ppv);
121 return S_OK;
123 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
124 return E_NOINTERFACE;
127 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
129 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
130 DWORD ref = InterlockedIncrement(&This->ref);
132 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
133 return ref;
136 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
138 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
139 DWORD ref = InterlockedDecrement(&This->ref);
141 TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
143 if (!ref)
145 ITextHost_Release(This->pMyHost);
146 This->csTxtSrv.DebugInfo->Spare[0] = 0;
147 DeleteCriticalSection(&This->csTxtSrv);
148 CoTaskMemFree(This);
150 return ref;
153 HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface,
154 UINT msg,
155 WPARAM wparam,
156 LPARAM lparam,
157 LRESULT* plresult)
159 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
160 HRESULT hresult;
161 LRESULT lresult;
163 lresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
164 if (plresult) *plresult = lresult;
165 return hresult;
168 HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface,
169 DWORD dwDrawAspect,
170 LONG lindex,
171 void* pvAspect,
172 DVTARGETDEVICE* ptd,
173 HDC hdcDraw,
174 HDC hdcTargetDev,
175 LPCRECTL lprcBounds,
176 LPCRECTL lprcWBounds,
177 LPRECT lprcUpdate,
178 BOOL (CALLBACK * pfnContinue)(DWORD),
179 DWORD dwContinue,
180 LONG lViewId)
182 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
184 FIXME("%p: STUB\n", This);
185 return E_NOTIMPL;
188 HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface,
189 LONG* plMin,
190 LONG* plMax,
191 LONG* plPos,
192 LONG* plPage,
193 BOOL* pfEnabled)
195 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
197 *plMin = This->editor->horz_si.nMin;
198 *plMax = This->editor->horz_si.nMax;
199 *plPos = This->editor->horz_si.nPos;
200 *plPage = This->editor->horz_si.nPage;
201 *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
202 return S_OK;
205 HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface,
206 LONG* plMin,
207 LONG* plMax,
208 LONG* plPos,
209 LONG* plPage,
210 BOOL* pfEnabled)
212 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
214 *plMin = This->editor->vert_si.nMin;
215 *plMax = This->editor->vert_si.nMax;
216 *plPos = This->editor->vert_si.nPos;
217 *plPage = This->editor->vert_si.nPage;
218 *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
219 return S_OK;
222 HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface,
223 DWORD dwDrawAspect,
224 LONG lindex,
225 void* pvAspect,
226 DVTARGETDEVICE* ptd,
227 HDC hdcDraw,
228 HDC hicTargetDev,
229 LPCRECT lprcClient,
230 INT x, INT y)
232 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
234 FIXME("%p: STUB\n", This);
235 return E_NOTIMPL;
238 HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface,
239 DWORD dwDrawAspect,
240 LONG lindex,
241 void* pvAspect,
242 DVTARGETDEVICE* ptd,
243 HDC hdcDraw,
244 HDC hicTargetDev,
245 LPCRECT lprcClient,
246 INT x, INT y,
247 DWORD* pHitResult)
249 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
251 FIXME("%p: STUB\n", This);
252 return E_NOTIMPL;
255 HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface,
256 LPCRECT prcClient)
258 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
260 FIXME("%p: STUB\n", This);
261 return E_NOTIMPL;
264 HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
266 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
268 FIXME("%p: STUB\n", This);
269 return E_NOTIMPL;
272 HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
274 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
276 FIXME("%p: STUB\n", This);
277 return E_NOTIMPL;
280 HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
282 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
284 FIXME("%p: STUB\n", This);
285 return E_NOTIMPL;
288 HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface,
289 BSTR* pbstrText)
291 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
292 int length;
294 length = ME_GetTextLength(This->editor);
295 if (length)
297 ME_Cursor start;
298 BSTR bstr;
299 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
300 if (bstr == NULL)
301 return E_OUTOFMEMORY;
303 ME_CursorFromCharOfs(This->editor, 0, &start);
304 ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE);
305 *pbstrText = bstr;
306 } else {
307 *pbstrText = NULL;
310 return S_OK;
313 HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface,
314 LPCWSTR pszText)
316 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
317 ME_Cursor cursor;
319 ME_SetCursorToStart(This->editor, &cursor);
320 ME_InternalDeleteText(This->editor, &cursor,
321 ME_GetTextLength(This->editor), FALSE);
322 ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
323 This->editor->pBuffer->pDefaultStyle);
324 ME_SetSelection(This->editor, 0, 0);
325 This->editor->nModifyStep = 0;
326 OleFlushClipboard();
327 ME_EmptyUndoStack(This->editor);
328 ME_UpdateRepaint(This->editor);
330 return S_OK;
333 HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface,
334 LONG* x)
336 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
338 FIXME("%p: STUB\n", This);
339 return E_NOTIMPL;
342 HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface,
343 LONG* x)
345 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
347 FIXME("%p: STUB\n", This);
348 return E_NOTIMPL;
351 HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
352 DWORD dwAspect,
353 HDC hdcDraw,
354 HDC hicTargetDev,
355 DVTARGETDEVICE* ptd,
356 DWORD dwMode,
357 const SIZEL* psizelExtent,
358 LONG* pwidth,
359 LONG* pheight)
361 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
363 FIXME("%p: STUB\n", This);
364 return E_NOTIMPL;
367 HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface,
368 IDropTarget** ppDropTarget)
370 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
372 FIXME("%p: STUB\n", This);
373 return E_NOTIMPL;
376 HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface,
377 DWORD dwMask,
378 DWORD dwBits)
380 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
382 FIXME("%p: STUB\n", This);
383 return E_NOTIMPL;
386 HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface,
387 DWORD* pdwWidth,
388 DWORD* pdwHeight)
390 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
392 FIXME("%p: STUB\n", This);
393 return E_NOTIMPL;
396 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage,20)
397 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw,52)
398 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll,24)
399 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll,24)
400 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor,40)
401 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint,44)
402 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate,8)
403 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate,4)
404 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate,4)
405 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate,4)
406 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText,8)
407 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText,8)
408 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX,8)
409 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos,8)
410 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize,36)
411 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget,8)
412 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange,12)
413 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize,12)
415 static const ITextServicesVtbl textservices_Vtbl =
417 fnTextSrv_QueryInterface,
418 fnTextSrv_AddRef,
419 fnTextSrv_Release,
420 THISCALL(fnTextSrv_TxSendMessage),
421 THISCALL(fnTextSrv_TxDraw),
422 THISCALL(fnTextSrv_TxGetHScroll),
423 THISCALL(fnTextSrv_TxGetVScroll),
424 THISCALL(fnTextSrv_OnTxSetCursor),
425 THISCALL(fnTextSrv_TxQueryHitPoint),
426 THISCALL(fnTextSrv_OnTxInplaceActivate),
427 THISCALL(fnTextSrv_OnTxInplaceDeactivate),
428 THISCALL(fnTextSrv_OnTxUIActivate),
429 THISCALL(fnTextSrv_OnTxUIDeactivate),
430 THISCALL(fnTextSrv_TxGetText),
431 THISCALL(fnTextSrv_TxSetText),
432 THISCALL(fnTextSrv_TxGetCurrentTargetX),
433 THISCALL(fnTextSrv_TxGetBaseLinePos),
434 THISCALL(fnTextSrv_TxGetNaturalSize),
435 THISCALL(fnTextSrv_TxGetDropTarget),
436 THISCALL(fnTextSrv_OnTxPropertyBitsChange),
437 THISCALL(fnTextSrv_TxGetCachedSize)