widl: Generate helper macros for WinRT implementation.
[wine/zf.git] / dlls / riched20 / txtsrv.c
blob3fd4ae540c5714afc3830b90780975dfa304a077
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 #define COBJMACROS
23 #include "editor.h"
24 #include "ole2.h"
25 #include "oleauto.h"
26 #include "richole.h"
27 #include "tom.h"
28 #include "imm.h"
29 #include "textserv.h"
30 #include "wine/debug.h"
31 #include "editstr.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
35 typedef struct ITextServicesImpl {
36 IUnknown IUnknown_inner;
37 ITextServices ITextServices_iface;
38 IUnknown *outer_unk;
39 LONG ref;
40 ITextHost *pMyHost;
41 CRITICAL_SECTION csTxtSrv;
42 ME_TextEditor *editor;
43 char spare[256];
44 } ITextServicesImpl;
46 static inline ITextServicesImpl *impl_from_IUnknown(IUnknown *iface)
48 return CONTAINING_RECORD(iface, ITextServicesImpl, IUnknown_inner);
51 static HRESULT WINAPI ITextServicesImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
53 ITextServicesImpl *This = impl_from_IUnknown(iface);
55 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
57 if (IsEqualIID(riid, &IID_IUnknown))
58 *ppv = &This->IUnknown_inner;
59 else if (IsEqualIID(riid, &IID_ITextServices))
60 *ppv = &This->ITextServices_iface;
61 else if (IsEqualIID(riid, &IID_IRichEditOle) || IsEqualIID(riid, &IID_ITextDocument) ||
62 IsEqualIID(riid, &IID_ITextDocument2Old)) {
63 if (!This->editor->reOle)
64 if (!CreateIRichEditOle(This->outer_unk, This->editor, (void **)(&This->editor->reOle)))
65 return E_OUTOFMEMORY;
66 return IUnknown_QueryInterface(This->editor->reOle, riid, ppv);
67 } else {
68 *ppv = NULL;
69 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
70 return E_NOINTERFACE;
73 IUnknown_AddRef((IUnknown*)*ppv);
74 return S_OK;
77 static ULONG WINAPI ITextServicesImpl_AddRef(IUnknown *iface)
79 ITextServicesImpl *This = impl_from_IUnknown(iface);
80 LONG ref = InterlockedIncrement(&This->ref);
82 TRACE("(%p) ref=%d\n", This, ref);
84 return ref;
87 static ULONG WINAPI ITextServicesImpl_Release(IUnknown *iface)
89 ITextServicesImpl *This = impl_from_IUnknown(iface);
90 LONG ref = InterlockedDecrement(&This->ref);
92 TRACE("(%p) ref=%d\n", This, ref);
94 if (!ref)
96 ME_DestroyEditor(This->editor);
97 This->csTxtSrv.DebugInfo->Spare[0] = 0;
98 DeleteCriticalSection(&This->csTxtSrv);
99 CoTaskMemFree(This);
101 return ref;
104 static const IUnknownVtbl textservices_inner_vtbl =
106 ITextServicesImpl_QueryInterface,
107 ITextServicesImpl_AddRef,
108 ITextServicesImpl_Release
111 static inline ITextServicesImpl *impl_from_ITextServices(ITextServices *iface)
113 return CONTAINING_RECORD(iface, ITextServicesImpl, ITextServices_iface);
116 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices *iface, REFIID riid, void **ppv)
118 ITextServicesImpl *This = impl_from_ITextServices(iface);
119 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
122 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
124 ITextServicesImpl *This = impl_from_ITextServices(iface);
125 return IUnknown_AddRef(This->outer_unk);
128 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
130 ITextServicesImpl *This = impl_from_ITextServices(iface);
131 return IUnknown_Release(This->outer_unk);
134 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage,20)
135 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxSendMessage(ITextServices *iface, UINT msg, WPARAM wparam,
136 LPARAM lparam, LRESULT *plresult)
138 ITextServicesImpl *This = impl_from_ITextServices(iface);
139 HRESULT hresult;
140 LRESULT lresult;
142 lresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
143 if (plresult) *plresult = lresult;
144 return hresult;
147 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw,52)
148 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxDraw(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
149 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw, HDC hdcTargetDev,
150 LPCRECTL lprcBounds, LPCRECTL lprcWBounds, LPRECT lprcUpdate,
151 BOOL (CALLBACK * pfnContinue)(DWORD), DWORD dwContinue,
152 LONG lViewId)
154 ITextServicesImpl *This = impl_from_ITextServices(iface);
156 FIXME("%p: STUB\n", This);
157 return E_NOTIMPL;
160 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll,24)
161 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetHScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
162 LONG *plPage, BOOL *pfEnabled)
164 ITextServicesImpl *This = impl_from_ITextServices(iface);
166 if (plMin)
167 *plMin = This->editor->horz_si.nMin;
168 if (plMax)
169 *plMax = This->editor->horz_si.nMax;
170 if (plPos)
171 *plPos = This->editor->horz_si.nPos;
172 if (plPage)
173 *plPage = This->editor->horz_si.nPage;
174 if (pfEnabled)
175 *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
176 return S_OK;
179 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll,24)
180 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetVScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
181 LONG *plPage, BOOL *pfEnabled)
183 ITextServicesImpl *This = impl_from_ITextServices(iface);
185 if (plMin)
186 *plMin = This->editor->vert_si.nMin;
187 if (plMax)
188 *plMax = This->editor->vert_si.nMax;
189 if (plPos)
190 *plPos = This->editor->vert_si.nPos;
191 if (plPage)
192 *plPage = This->editor->vert_si.nPage;
193 if (pfEnabled)
194 *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
195 return S_OK;
198 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor,40)
199 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxSetCursor(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
200 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
201 HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y)
203 ITextServicesImpl *This = impl_from_ITextServices(iface);
205 FIXME("%p: STUB\n", This);
206 return E_NOTIMPL;
209 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint,44)
210 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxQueryHitPoint(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
211 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
212 HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y,
213 DWORD *pHitResult)
215 ITextServicesImpl *This = impl_from_ITextServices(iface);
217 FIXME("%p: STUB\n", This);
218 return E_NOTIMPL;
221 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate,8)
222 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxInplaceActivate(ITextServices *iface, LPCRECT prcClient)
224 ITextServicesImpl *This = impl_from_ITextServices(iface);
226 FIXME("%p: STUB\n", This);
227 return E_NOTIMPL;
230 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate,4)
231 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
233 ITextServicesImpl *This = impl_from_ITextServices(iface);
235 FIXME("%p: STUB\n", This);
236 return E_NOTIMPL;
239 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate,4)
240 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxUIActivate(ITextServices *iface)
242 ITextServicesImpl *This = impl_from_ITextServices(iface);
244 FIXME("%p: STUB\n", This);
245 return E_NOTIMPL;
248 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate,4)
249 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
251 ITextServicesImpl *This = impl_from_ITextServices(iface);
253 FIXME("%p: STUB\n", This);
254 return E_NOTIMPL;
257 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText,8)
258 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetText(ITextServices *iface, BSTR *pbstrText)
260 ITextServicesImpl *This = impl_from_ITextServices(iface);
261 int length;
263 length = ME_GetTextLength(This->editor);
264 if (length)
266 ME_Cursor start;
267 BSTR bstr;
268 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
269 if (bstr == NULL)
270 return E_OUTOFMEMORY;
272 cursor_from_char_ofs( This->editor, 0, &start );
273 ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE, FALSE);
274 *pbstrText = bstr;
275 } else {
276 *pbstrText = NULL;
279 return S_OK;
282 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText,8)
283 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxSetText(ITextServices *iface, LPCWSTR pszText)
285 ITextServicesImpl *This = impl_from_ITextServices(iface);
286 ME_Cursor cursor;
288 ME_SetCursorToStart(This->editor, &cursor);
289 ME_InternalDeleteText(This->editor, &cursor, ME_GetTextLength(This->editor), FALSE);
290 if(pszText)
291 ME_InsertTextFromCursor(This->editor, 0, pszText, -1, This->editor->pBuffer->pDefaultStyle);
292 set_selection_cursors(This->editor, 0, 0);
293 This->editor->nModifyStep = 0;
294 OleFlushClipboard();
295 ME_EmptyUndoStack(This->editor);
296 ME_UpdateRepaint(This->editor, FALSE);
298 return S_OK;
301 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurTargetX,8)
302 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetCurTargetX(ITextServices *iface, LONG *x)
304 ITextServicesImpl *This = impl_from_ITextServices(iface);
306 FIXME("%p: STUB\n", This);
307 return E_NOTIMPL;
310 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos,8)
311 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetBaseLinePos(ITextServices *iface, LONG *x)
313 ITextServicesImpl *This = impl_from_ITextServices(iface);
315 FIXME("%p: STUB\n", This);
316 return E_NOTIMPL;
319 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize,36)
320 DECLSPEC_HIDDEN HRESULT __thiscall 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 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget,8)
331 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetDropTarget(ITextServices *iface, IDropTarget **ppDropTarget)
333 ITextServicesImpl *This = impl_from_ITextServices(iface);
335 FIXME("%p: STUB\n", This);
336 return E_NOTIMPL;
339 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange,12)
340 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface, DWORD dwMask, DWORD dwBits)
342 ITextServicesImpl *This = impl_from_ITextServices(iface);
344 FIXME("%p: STUB\n", This);
345 return E_NOTIMPL;
348 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize,12)
349 DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetCachedSize(ITextServices *iface, DWORD *pdwWidth, DWORD *pdwHeight)
351 ITextServicesImpl *This = impl_from_ITextServices(iface);
353 FIXME("%p: STUB\n", This);
354 return E_NOTIMPL;
358 static const ITextServicesVtbl textservices_vtbl =
360 fnTextSrv_QueryInterface,
361 fnTextSrv_AddRef,
362 fnTextSrv_Release,
363 THISCALL(fnTextSrv_TxSendMessage),
364 THISCALL(fnTextSrv_TxDraw),
365 THISCALL(fnTextSrv_TxGetHScroll),
366 THISCALL(fnTextSrv_TxGetVScroll),
367 THISCALL(fnTextSrv_OnTxSetCursor),
368 THISCALL(fnTextSrv_TxQueryHitPoint),
369 THISCALL(fnTextSrv_OnTxInplaceActivate),
370 THISCALL(fnTextSrv_OnTxInplaceDeactivate),
371 THISCALL(fnTextSrv_OnTxUIActivate),
372 THISCALL(fnTextSrv_OnTxUIDeactivate),
373 THISCALL(fnTextSrv_TxGetText),
374 THISCALL(fnTextSrv_TxSetText),
375 THISCALL(fnTextSrv_TxGetCurTargetX),
376 THISCALL(fnTextSrv_TxGetBaseLinePos),
377 THISCALL(fnTextSrv_TxGetNaturalSize),
378 THISCALL(fnTextSrv_TxGetDropTarget),
379 THISCALL(fnTextSrv_OnTxPropertyBitsChange),
380 THISCALL(fnTextSrv_TxGetCachedSize)
383 /******************************************************************
384 * CreateTextServices (RICHED20.4)
386 HRESULT WINAPI CreateTextServices(IUnknown *pUnkOuter, ITextHost *pITextHost, IUnknown **ppUnk)
388 ITextServicesImpl *ITextImpl;
390 TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
391 if (pITextHost == NULL)
392 return E_POINTER;
394 ITextImpl = CoTaskMemAlloc(sizeof(*ITextImpl));
395 if (ITextImpl == NULL)
396 return E_OUTOFMEMORY;
397 InitializeCriticalSection(&ITextImpl->csTxtSrv);
398 ITextImpl->csTxtSrv.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ITextServicesImpl.csTxtSrv");
399 ITextImpl->ref = 1;
400 ITextHost_AddRef(pITextHost);
401 ITextImpl->pMyHost = pITextHost;
402 ITextImpl->IUnknown_inner.lpVtbl = &textservices_inner_vtbl;
403 ITextImpl->ITextServices_iface.lpVtbl = &textservices_vtbl;
404 ITextImpl->editor = ME_MakeEditor(pITextHost, FALSE);
406 if (pUnkOuter)
407 ITextImpl->outer_unk = pUnkOuter;
408 else
409 ITextImpl->outer_unk = &ITextImpl->IUnknown_inner;
411 *ppUnk = &ITextImpl->IUnknown_inner;
412 return S_OK;