wined3d: Only set GL_DEPTH_TEXTURE_MODE_ARB if ARB_depth_texture is supported.
[wine.git] / dlls / riched20 / txtsrv.c
blob1bf9cf29bfa87a424f0752cb046e50f7a73a025f
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 COBJMACROS
26 #include "editor.h"
27 #include "ole2.h"
28 #include "oleauto.h"
29 #include "richole.h"
30 #include "tom.h"
31 #include "imm.h"
32 #include "textserv.h"
33 #include "wine/debug.h"
34 #include "editstr.h"
36 #ifdef __i386__ /* thiscall functions are i386-specific */
38 #define THISCALL(func) __thiscall_ ## func
39 #define DEFINE_THISCALL_WRAPPER(func,args) \
40 extern typeof(func) THISCALL(func); \
41 __ASM_STDCALL_FUNC(__thiscall_ ## func, args, \
42 "popl %eax\n\t" \
43 "pushl %ecx\n\t" \
44 "pushl %eax\n\t" \
45 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
46 #else /* __i386__ */
48 #define THISCALL(func) func
49 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
51 #endif /* __i386__ */
53 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
55 typedef struct ITextServicesImpl {
56 IUnknown IUnknown_inner;
57 ITextServices ITextServices_iface;
58 IUnknown *outer_unk;
59 LONG ref;
60 ITextHost *pMyHost;
61 CRITICAL_SECTION csTxtSrv;
62 ME_TextEditor *editor;
63 char spare[256];
64 } ITextServicesImpl;
66 static inline ITextServicesImpl *impl_from_IUnknown(IUnknown *iface)
68 return CONTAINING_RECORD(iface, ITextServicesImpl, IUnknown_inner);
71 static HRESULT WINAPI ITextServicesImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
73 ITextServicesImpl *This = impl_from_IUnknown(iface);
75 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
77 if (IsEqualIID(riid, &IID_IUnknown))
78 *ppv = &This->IUnknown_inner;
79 else if (IsEqualIID(riid, &IID_ITextServices))
80 *ppv = &This->ITextServices_iface;
81 else if (IsEqualIID(riid, &IID_IRichEditOle) || IsEqualIID(riid, &IID_ITextDocument)) {
82 if (!This->editor->reOle)
83 if (!CreateIRichEditOle(This->outer_unk, This->editor, (void **)(&This->editor->reOle)))
84 return E_OUTOFMEMORY;
85 if (IsEqualIID(riid, &IID_ITextDocument))
86 ME_GetITextDocumentInterface(This->editor->reOle, ppv);
87 else
88 *ppv = This->editor->reOle;
89 } else {
90 *ppv = NULL;
91 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
92 return E_NOINTERFACE;
95 IUnknown_AddRef((IUnknown*)*ppv);
96 return S_OK;
99 static ULONG WINAPI ITextServicesImpl_AddRef(IUnknown *iface)
101 ITextServicesImpl *This = impl_from_IUnknown(iface);
102 LONG ref = InterlockedIncrement(&This->ref);
104 TRACE("(%p) ref=%d\n", This, ref);
106 return ref;
109 static ULONG WINAPI ITextServicesImpl_Release(IUnknown *iface)
111 ITextServicesImpl *This = impl_from_IUnknown(iface);
112 LONG ref = InterlockedDecrement(&This->ref);
114 TRACE("(%p) ref=%d\n", This, ref);
116 if (!ref)
118 ME_DestroyEditor(This->editor);
119 This->csTxtSrv.DebugInfo->Spare[0] = 0;
120 DeleteCriticalSection(&This->csTxtSrv);
121 CoTaskMemFree(This);
123 return ref;
126 static const IUnknownVtbl textservices_inner_vtbl =
128 ITextServicesImpl_QueryInterface,
129 ITextServicesImpl_AddRef,
130 ITextServicesImpl_Release
133 static inline ITextServicesImpl *impl_from_ITextServices(ITextServices *iface)
135 return CONTAINING_RECORD(iface, ITextServicesImpl, ITextServices_iface);
138 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices *iface, REFIID riid, void **ppv)
140 ITextServicesImpl *This = impl_from_ITextServices(iface);
141 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
144 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
146 ITextServicesImpl *This = impl_from_ITextServices(iface);
147 return IUnknown_AddRef(This->outer_unk);
150 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
152 ITextServicesImpl *This = impl_from_ITextServices(iface);
153 return IUnknown_Release(This->outer_unk);
156 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface, UINT msg, WPARAM wparam,
157 LPARAM lparam, LRESULT *plresult)
159 ITextServicesImpl *This = impl_from_ITextServices(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 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
169 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw, HDC hdcTargetDev,
170 LPCRECTL lprcBounds, LPCRECTL lprcWBounds, LPRECT lprcUpdate,
171 BOOL (CALLBACK * pfnContinue)(DWORD), DWORD dwContinue,
172 LONG lViewId)
174 ITextServicesImpl *This = impl_from_ITextServices(iface);
176 FIXME("%p: STUB\n", This);
177 return E_NOTIMPL;
180 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
181 LONG *plPage, BOOL *pfEnabled)
183 ITextServicesImpl *This = impl_from_ITextServices(iface);
185 *plMin = This->editor->horz_si.nMin;
186 *plMax = This->editor->horz_si.nMax;
187 *plPos = This->editor->horz_si.nPos;
188 *plPage = This->editor->horz_si.nPage;
189 *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
190 return S_OK;
193 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
194 LONG *plPage, BOOL *pfEnabled)
196 ITextServicesImpl *This = impl_from_ITextServices(iface);
198 *plMin = This->editor->vert_si.nMin;
199 *plMax = This->editor->vert_si.nMax;
200 *plPos = This->editor->vert_si.nPos;
201 *plPage = This->editor->vert_si.nPage;
202 *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
203 return S_OK;
206 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
207 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
208 HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y)
210 ITextServicesImpl *This = impl_from_ITextServices(iface);
212 FIXME("%p: STUB\n", This);
213 return E_NOTIMPL;
216 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
217 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
218 HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y,
219 DWORD *pHitResult)
221 ITextServicesImpl *This = impl_from_ITextServices(iface);
223 FIXME("%p: STUB\n", This);
224 return E_NOTIMPL;
227 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface, LPCRECT prcClient)
229 ITextServicesImpl *This = impl_from_ITextServices(iface);
231 FIXME("%p: STUB\n", This);
232 return E_NOTIMPL;
235 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
237 ITextServicesImpl *This = impl_from_ITextServices(iface);
239 FIXME("%p: STUB\n", This);
240 return E_NOTIMPL;
243 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
245 ITextServicesImpl *This = impl_from_ITextServices(iface);
247 FIXME("%p: STUB\n", This);
248 return E_NOTIMPL;
251 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
253 ITextServicesImpl *This = impl_from_ITextServices(iface);
255 FIXME("%p: STUB\n", This);
256 return E_NOTIMPL;
259 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface, BSTR *pbstrText)
261 ITextServicesImpl *This = impl_from_ITextServices(iface);
262 int length;
264 length = ME_GetTextLength(This->editor);
265 if (length)
267 ME_Cursor start;
268 BSTR bstr;
269 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
270 if (bstr == NULL)
271 return E_OUTOFMEMORY;
273 ME_CursorFromCharOfs(This->editor, 0, &start);
274 ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE, FALSE);
275 *pbstrText = bstr;
276 } else {
277 *pbstrText = NULL;
280 return S_OK;
283 DECLSPEC_HIDDEN HRESULT WINAPI 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,
290 ME_GetTextLength(This->editor), FALSE);
291 ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
292 This->editor->pBuffer->pDefaultStyle);
293 ME_SetSelection(This->editor, 0, 0);
294 This->editor->nModifyStep = 0;
295 OleFlushClipboard();
296 ME_EmptyUndoStack(This->editor);
297 ME_UpdateRepaint(This->editor, FALSE);
299 return S_OK;
302 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetCurTargetX(ITextServices *iface, LONG *x)
304 ITextServicesImpl *This = impl_from_ITextServices(iface);
306 FIXME("%p: STUB\n", This);
307 return E_NOTIMPL;
310 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface, LONG *x)
312 ITextServicesImpl *This = impl_from_ITextServices(iface);
314 FIXME("%p: STUB\n", This);
315 return E_NOTIMPL;
318 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface, DWORD dwAspect, HDC hdcDraw,
319 HDC hicTargetDev, DVTARGETDEVICE *ptd, DWORD dwMode,
320 const SIZEL *psizelExtent, LONG *pwidth, LONG *pheight)
322 ITextServicesImpl *This = impl_from_ITextServices(iface);
324 FIXME("%p: STUB\n", This);
325 return E_NOTIMPL;
328 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface, IDropTarget **ppDropTarget)
330 ITextServicesImpl *This = impl_from_ITextServices(iface);
332 FIXME("%p: STUB\n", This);
333 return E_NOTIMPL;
336 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface, DWORD dwMask, DWORD dwBits)
338 ITextServicesImpl *This = impl_from_ITextServices(iface);
340 FIXME("%p: STUB\n", This);
341 return E_NOTIMPL;
344 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface, DWORD *pdwWidth, DWORD *pdwHeight)
346 ITextServicesImpl *This = impl_from_ITextServices(iface);
348 FIXME("%p: STUB\n", This);
349 return E_NOTIMPL;
352 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage,20)
353 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw,52)
354 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll,24)
355 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll,24)
356 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor,40)
357 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint,44)
358 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate,8)
359 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate,4)
360 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate,4)
361 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate,4)
362 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText,8)
363 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText,8)
364 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurTargetX,8)
365 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos,8)
366 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize,36)
367 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget,8)
368 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange,12)
369 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize,12)
371 static const ITextServicesVtbl textservices_vtbl =
373 fnTextSrv_QueryInterface,
374 fnTextSrv_AddRef,
375 fnTextSrv_Release,
376 THISCALL(fnTextSrv_TxSendMessage),
377 THISCALL(fnTextSrv_TxDraw),
378 THISCALL(fnTextSrv_TxGetHScroll),
379 THISCALL(fnTextSrv_TxGetVScroll),
380 THISCALL(fnTextSrv_OnTxSetCursor),
381 THISCALL(fnTextSrv_TxQueryHitPoint),
382 THISCALL(fnTextSrv_OnTxInplaceActivate),
383 THISCALL(fnTextSrv_OnTxInplaceDeactivate),
384 THISCALL(fnTextSrv_OnTxUIActivate),
385 THISCALL(fnTextSrv_OnTxUIDeactivate),
386 THISCALL(fnTextSrv_TxGetText),
387 THISCALL(fnTextSrv_TxSetText),
388 THISCALL(fnTextSrv_TxGetCurTargetX),
389 THISCALL(fnTextSrv_TxGetBaseLinePos),
390 THISCALL(fnTextSrv_TxGetNaturalSize),
391 THISCALL(fnTextSrv_TxGetDropTarget),
392 THISCALL(fnTextSrv_OnTxPropertyBitsChange),
393 THISCALL(fnTextSrv_TxGetCachedSize)
396 /******************************************************************
397 * CreateTextServices (RICHED20.4)
399 HRESULT WINAPI CreateTextServices(IUnknown *pUnkOuter, ITextHost *pITextHost, IUnknown **ppUnk)
401 ITextServicesImpl *ITextImpl;
403 TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
404 if (pITextHost == NULL)
405 return E_POINTER;
407 ITextImpl = CoTaskMemAlloc(sizeof(*ITextImpl));
408 if (ITextImpl == NULL)
409 return E_OUTOFMEMORY;
410 InitializeCriticalSection(&ITextImpl->csTxtSrv);
411 ITextImpl->csTxtSrv.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ITextServicesImpl.csTxtSrv");
412 ITextImpl->ref = 1;
413 ITextHost_AddRef(pITextHost);
414 ITextImpl->pMyHost = pITextHost;
415 ITextImpl->IUnknown_inner.lpVtbl = &textservices_inner_vtbl;
416 ITextImpl->ITextServices_iface.lpVtbl = &textservices_vtbl;
417 ITextImpl->editor = ME_MakeEditor(pITextHost, FALSE);
418 ITextImpl->editor->exStyleFlags = 0;
419 ITextImpl->editor->rcFormat.left = 0;
420 ITextImpl->editor->rcFormat.top = 0;
421 ITextImpl->editor->rcFormat.right = 0;
422 ITextImpl->editor->rcFormat.bottom = 0;
424 if (pUnkOuter)
425 ITextImpl->outer_unk = pUnkOuter;
426 else
427 ITextImpl->outer_unk = &ITextImpl->IUnknown_inner;
429 *ppUnk = &ITextImpl->IUnknown_inner;
430 return S_OK;