Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / riched20 / txtsrv.c
blobe9cc5e1c5b762fc8fbd5da9a7ea36e59a046776e
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 IUnknown IUnknown_inner;
58 ITextServices ITextServices_iface;
59 IUnknown *outer_unk;
60 LONG ref;
61 ITextHost *pMyHost;
62 CRITICAL_SECTION csTxtSrv;
63 ME_TextEditor *editor;
64 char spare[256];
65 } ITextServicesImpl;
67 static inline ITextServicesImpl *impl_from_IUnknown(IUnknown *iface)
69 return CONTAINING_RECORD(iface, ITextServicesImpl, IUnknown_inner);
72 static HRESULT WINAPI ITextServicesImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
74 ITextServicesImpl *This = impl_from_IUnknown(iface);
76 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
78 if (IsEqualIID(riid, &IID_IUnknown))
79 *ppv = &This->IUnknown_inner;
80 else if IsEqualIID(riid, &IID_ITextServices)
81 *ppv = &This->ITextServices_iface;
82 else {
83 *ppv = NULL;
84 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
85 return E_NOINTERFACE;
88 IUnknown_AddRef((IUnknown*)*ppv);
89 return S_OK;
92 static ULONG WINAPI ITextServicesImpl_AddRef(IUnknown *iface)
94 ITextServicesImpl *This = impl_from_IUnknown(iface);
95 LONG ref = InterlockedIncrement(&This->ref);
97 TRACE("(%p) ref=%d\n", This, ref);
99 return ref;
102 static ULONG WINAPI ITextServicesImpl_Release(IUnknown *iface)
104 ITextServicesImpl *This = impl_from_IUnknown(iface);
105 LONG ref = InterlockedDecrement(&This->ref);
107 TRACE("(%p) ref=%d\n", This, ref);
109 if (!ref)
111 ITextHost_Release(This->pMyHost);
112 This->csTxtSrv.DebugInfo->Spare[0] = 0;
113 DeleteCriticalSection(&This->csTxtSrv);
114 CoTaskMemFree(This);
116 return ref;
119 static const IUnknownVtbl textservices_inner_vtbl =
121 ITextServicesImpl_QueryInterface,
122 ITextServicesImpl_AddRef,
123 ITextServicesImpl_Release
126 static inline ITextServicesImpl *impl_from_ITextServices(ITextServices *iface)
128 return CONTAINING_RECORD(iface, ITextServicesImpl, ITextServices_iface);
131 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices *iface, REFIID riid, void **ppv)
133 ITextServicesImpl *This = impl_from_ITextServices(iface);
134 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
137 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
139 ITextServicesImpl *This = impl_from_ITextServices(iface);
140 return IUnknown_AddRef(This->outer_unk);
143 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
145 ITextServicesImpl *This = impl_from_ITextServices(iface);
146 return IUnknown_Release(This->outer_unk);
149 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface, UINT msg, WPARAM wparam,
150 LPARAM lparam, LRESULT *plresult)
152 ITextServicesImpl *This = impl_from_ITextServices(iface);
153 HRESULT hresult;
154 LRESULT lresult;
156 lresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
157 if (plresult) *plresult = lresult;
158 return hresult;
161 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
162 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw, HDC hdcTargetDev,
163 LPCRECTL lprcBounds, LPCRECTL lprcWBounds, LPRECT lprcUpdate,
164 BOOL (CALLBACK * pfnContinue)(DWORD), DWORD dwContinue,
165 LONG lViewId)
167 ITextServicesImpl *This = impl_from_ITextServices(iface);
169 FIXME("%p: STUB\n", This);
170 return E_NOTIMPL;
173 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
174 LONG *plPage, BOOL *pfEnabled)
176 ITextServicesImpl *This = impl_from_ITextServices(iface);
178 *plMin = This->editor->horz_si.nMin;
179 *plMax = This->editor->horz_si.nMax;
180 *plPos = This->editor->horz_si.nPos;
181 *plPage = This->editor->horz_si.nPage;
182 *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
183 return S_OK;
186 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface, LONG *plMin, LONG *plMax, LONG *plPos,
187 LONG *plPage, BOOL *pfEnabled)
189 ITextServicesImpl *This = impl_from_ITextServices(iface);
191 *plMin = This->editor->vert_si.nMin;
192 *plMax = This->editor->vert_si.nMax;
193 *plPos = This->editor->vert_si.nPos;
194 *plPage = This->editor->vert_si.nPage;
195 *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
196 return S_OK;
199 DECLSPEC_HIDDEN HRESULT WINAPI 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 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
210 void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
211 HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y,
212 DWORD *pHitResult)
214 ITextServicesImpl *This = impl_from_ITextServices(iface);
216 FIXME("%p: STUB\n", This);
217 return E_NOTIMPL;
220 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface, LPCRECT prcClient)
222 ITextServicesImpl *This = impl_from_ITextServices(iface);
224 FIXME("%p: STUB\n", This);
225 return E_NOTIMPL;
228 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
230 ITextServicesImpl *This = impl_from_ITextServices(iface);
232 FIXME("%p: STUB\n", This);
233 return E_NOTIMPL;
236 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
238 ITextServicesImpl *This = impl_from_ITextServices(iface);
240 FIXME("%p: STUB\n", This);
241 return E_NOTIMPL;
244 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
246 ITextServicesImpl *This = impl_from_ITextServices(iface);
248 FIXME("%p: STUB\n", This);
249 return E_NOTIMPL;
252 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface, BSTR *pbstrText)
254 ITextServicesImpl *This = impl_from_ITextServices(iface);
255 int length;
257 length = ME_GetTextLength(This->editor);
258 if (length)
260 ME_Cursor start;
261 BSTR bstr;
262 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
263 if (bstr == NULL)
264 return E_OUTOFMEMORY;
266 ME_CursorFromCharOfs(This->editor, 0, &start);
267 ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE);
268 *pbstrText = bstr;
269 } else {
270 *pbstrText = NULL;
273 return S_OK;
276 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface, LPCWSTR pszText)
278 ITextServicesImpl *This = impl_from_ITextServices(iface);
279 ME_Cursor cursor;
281 ME_SetCursorToStart(This->editor, &cursor);
282 ME_InternalDeleteText(This->editor, &cursor,
283 ME_GetTextLength(This->editor), FALSE);
284 ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
285 This->editor->pBuffer->pDefaultStyle);
286 ME_SetSelection(This->editor, 0, 0);
287 This->editor->nModifyStep = 0;
288 OleFlushClipboard();
289 ME_EmptyUndoStack(This->editor);
290 ME_UpdateRepaint(This->editor, FALSE);
292 return S_OK;
295 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface, LONG *x)
297 ITextServicesImpl *This = impl_from_ITextServices(iface);
299 FIXME("%p: STUB\n", This);
300 return E_NOTIMPL;
303 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface, LONG *x)
305 ITextServicesImpl *This = impl_from_ITextServices(iface);
307 FIXME("%p: STUB\n", This);
308 return E_NOTIMPL;
311 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface, DWORD dwAspect, HDC hdcDraw,
312 HDC hicTargetDev, DVTARGETDEVICE *ptd, DWORD dwMode,
313 const SIZEL *psizelExtent, LONG *pwidth, LONG *pheight)
315 ITextServicesImpl *This = impl_from_ITextServices(iface);
317 FIXME("%p: STUB\n", This);
318 return E_NOTIMPL;
321 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface, IDropTarget **ppDropTarget)
323 ITextServicesImpl *This = impl_from_ITextServices(iface);
325 FIXME("%p: STUB\n", This);
326 return E_NOTIMPL;
329 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface, DWORD dwMask, DWORD dwBits)
331 ITextServicesImpl *This = impl_from_ITextServices(iface);
333 FIXME("%p: STUB\n", This);
334 return E_NOTIMPL;
337 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface, DWORD *pdwWidth, DWORD *pdwHeight)
339 ITextServicesImpl *This = impl_from_ITextServices(iface);
341 FIXME("%p: STUB\n", This);
342 return E_NOTIMPL;
345 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage,20)
346 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw,52)
347 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll,24)
348 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll,24)
349 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor,40)
350 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint,44)
351 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate,8)
352 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate,4)
353 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate,4)
354 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate,4)
355 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText,8)
356 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText,8)
357 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX,8)
358 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos,8)
359 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize,36)
360 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget,8)
361 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange,12)
362 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize,12)
364 static const ITextServicesVtbl textservices_vtbl =
366 fnTextSrv_QueryInterface,
367 fnTextSrv_AddRef,
368 fnTextSrv_Release,
369 THISCALL(fnTextSrv_TxSendMessage),
370 THISCALL(fnTextSrv_TxDraw),
371 THISCALL(fnTextSrv_TxGetHScroll),
372 THISCALL(fnTextSrv_TxGetVScroll),
373 THISCALL(fnTextSrv_OnTxSetCursor),
374 THISCALL(fnTextSrv_TxQueryHitPoint),
375 THISCALL(fnTextSrv_OnTxInplaceActivate),
376 THISCALL(fnTextSrv_OnTxInplaceDeactivate),
377 THISCALL(fnTextSrv_OnTxUIActivate),
378 THISCALL(fnTextSrv_OnTxUIDeactivate),
379 THISCALL(fnTextSrv_TxGetText),
380 THISCALL(fnTextSrv_TxSetText),
381 THISCALL(fnTextSrv_TxGetCurrentTargetX),
382 THISCALL(fnTextSrv_TxGetBaseLinePos),
383 THISCALL(fnTextSrv_TxGetNaturalSize),
384 THISCALL(fnTextSrv_TxGetDropTarget),
385 THISCALL(fnTextSrv_OnTxPropertyBitsChange),
386 THISCALL(fnTextSrv_TxGetCachedSize)
389 /******************************************************************
390 * CreateTextServices (RICHED20.4)
392 HRESULT WINAPI CreateTextServices(IUnknown *pUnkOuter, ITextHost *pITextHost, IUnknown **ppUnk)
394 ITextServicesImpl *ITextImpl;
395 HRESULT hres;
396 TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
397 if (pITextHost == NULL)
398 return E_POINTER;
400 ITextImpl = CoTaskMemAlloc(sizeof(*ITextImpl));
401 if (ITextImpl == NULL)
402 return E_OUTOFMEMORY;
403 InitializeCriticalSection(&ITextImpl->csTxtSrv);
404 ITextImpl->csTxtSrv.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ITextServicesImpl.csTxtSrv");
405 ITextImpl->ref = 1;
406 ITextHost_AddRef(pITextHost);
407 ITextImpl->pMyHost = pITextHost;
408 ITextImpl->IUnknown_inner.lpVtbl = &textservices_inner_vtbl;
409 ITextImpl->ITextServices_iface.lpVtbl = &textservices_vtbl;
410 ITextImpl->editor = ME_MakeEditor(pITextHost, FALSE);
411 ITextImpl->editor->exStyleFlags = 0;
412 ITextImpl->editor->rcFormat.left = 0;
413 ITextImpl->editor->rcFormat.top = 0;
414 ITextImpl->editor->rcFormat.right = 0;
415 ITextImpl->editor->rcFormat.bottom = 0;
417 ME_HandleMessage(ITextImpl->editor, WM_CREATE, 0, 0, TRUE, &hres);
419 if (pUnkOuter)
420 ITextImpl->outer_unk = pUnkOuter;
421 else
422 ITextImpl->outer_unk = &ITextImpl->IUnknown_inner;
424 *ppUnk = &ITextImpl->IUnknown_inner;
425 return S_OK;