wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / riched20 / txtsrv.c
blob674bf3814e16f0e049ead8561a4a4ce2da137d55
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.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;
105 return S_OK;
108 #define ICOM_THIS_MULTI(impl,field,iface) \
109 impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
111 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices * iface,
112 REFIID riid,
113 LPVOID * ppv)
115 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
116 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
117 *ppv = NULL;
118 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
119 *ppv = This;
121 if (*ppv)
123 IUnknown_AddRef((IUnknown *)(*ppv));
124 TRACE ("-- Interface = %p\n", *ppv);
125 return S_OK;
127 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
128 return E_NOINTERFACE;
131 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
133 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
134 DWORD ref = InterlockedIncrement(&This->ref);
136 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
137 return ref;
140 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
142 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
143 DWORD ref = InterlockedDecrement(&This->ref);
145 TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
147 if (!ref)
149 ITextHost_Release(This->pMyHost);
150 This->csTxtSrv.DebugInfo->Spare[0] = 0;
151 DeleteCriticalSection(&This->csTxtSrv);
152 CoTaskMemFree(This);
154 return ref;
157 HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface,
158 UINT msg,
159 WPARAM wparam,
160 LPARAM lparam,
161 LRESULT* plresult)
163 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
164 HRESULT hresult;
165 LRESULT lresult;
167 lresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
168 if (plresult) *plresult = lresult;
169 return hresult;
172 HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface,
173 DWORD dwDrawAspect,
174 LONG lindex,
175 void* pvAspect,
176 DVTARGETDEVICE* ptd,
177 HDC hdcDraw,
178 HDC hdcTargetDev,
179 LPCRECTL lprcBounds,
180 LPCRECTL lprcWBounds,
181 LPRECT lprcUpdate,
182 BOOL (CALLBACK * pfnContinue)(DWORD),
183 DWORD dwContinue,
184 LONG lViewId)
186 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
188 FIXME("%p: STUB\n", This);
189 return E_NOTIMPL;
192 HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface,
193 LONG* plMin,
194 LONG* plMax,
195 LONG* plPos,
196 LONG* plPage,
197 BOOL* pfEnabled)
199 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
201 *plMin = This->editor->horz_si.nMin;
202 *plMax = This->editor->horz_si.nMax;
203 *plPos = This->editor->horz_si.nPos;
204 *plPage = This->editor->horz_si.nPage;
205 *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
206 return S_OK;
209 HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface,
210 LONG* plMin,
211 LONG* plMax,
212 LONG* plPos,
213 LONG* plPage,
214 BOOL* pfEnabled)
216 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
218 *plMin = This->editor->vert_si.nMin;
219 *plMax = This->editor->vert_si.nMax;
220 *plPos = This->editor->vert_si.nPos;
221 *plPage = This->editor->vert_si.nPage;
222 *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
223 return S_OK;
226 HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface,
227 DWORD dwDrawAspect,
228 LONG lindex,
229 void* pvAspect,
230 DVTARGETDEVICE* ptd,
231 HDC hdcDraw,
232 HDC hicTargetDev,
233 LPCRECT lprcClient,
234 INT x, INT y)
236 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
238 FIXME("%p: STUB\n", This);
239 return E_NOTIMPL;
242 HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface,
243 DWORD dwDrawAspect,
244 LONG lindex,
245 void* pvAspect,
246 DVTARGETDEVICE* ptd,
247 HDC hdcDraw,
248 HDC hicTargetDev,
249 LPCRECT lprcClient,
250 INT x, INT y,
251 DWORD* pHitResult)
253 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
255 FIXME("%p: STUB\n", This);
256 return E_NOTIMPL;
259 HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface,
260 LPCRECT prcClient)
262 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
264 FIXME("%p: STUB\n", This);
265 return E_NOTIMPL;
268 HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
270 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
272 FIXME("%p: STUB\n", This);
273 return E_NOTIMPL;
276 HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
278 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
280 FIXME("%p: STUB\n", This);
281 return E_NOTIMPL;
284 HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
286 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
288 FIXME("%p: STUB\n", This);
289 return E_NOTIMPL;
292 HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface,
293 BSTR* pbstrText)
295 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
296 int length;
298 length = ME_GetTextLength(This->editor);
299 if (length)
301 ME_Cursor start;
302 BSTR bstr;
303 bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
304 if (bstr == NULL)
305 return E_OUTOFMEMORY;
307 ME_CursorFromCharOfs(This->editor, 0, &start);
308 ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE);
309 *pbstrText = bstr;
310 } else {
311 *pbstrText = NULL;
314 return S_OK;
317 HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface,
318 LPCWSTR pszText)
320 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
321 ME_Cursor cursor;
323 ME_SetCursorToStart(This->editor, &cursor);
324 ME_InternalDeleteText(This->editor, &cursor,
325 ME_GetTextLength(This->editor), FALSE);
326 ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
327 This->editor->pBuffer->pDefaultStyle);
328 ME_SetSelection(This->editor, 0, 0);
329 This->editor->nModifyStep = 0;
330 OleFlushClipboard();
331 ME_EmptyUndoStack(This->editor);
332 ME_UpdateRepaint(This->editor, FALSE);
334 return S_OK;
337 HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface,
338 LONG* x)
340 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
342 FIXME("%p: STUB\n", This);
343 return E_NOTIMPL;
346 HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface,
347 LONG* x)
349 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
351 FIXME("%p: STUB\n", This);
352 return E_NOTIMPL;
355 HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
356 DWORD dwAspect,
357 HDC hdcDraw,
358 HDC hicTargetDev,
359 DVTARGETDEVICE* ptd,
360 DWORD dwMode,
361 const SIZEL* psizelExtent,
362 LONG* pwidth,
363 LONG* pheight)
365 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
367 FIXME("%p: STUB\n", This);
368 return E_NOTIMPL;
371 HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface,
372 IDropTarget** ppDropTarget)
374 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
376 FIXME("%p: STUB\n", This);
377 return E_NOTIMPL;
380 HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface,
381 DWORD dwMask,
382 DWORD dwBits)
384 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
386 FIXME("%p: STUB\n", This);
387 return E_NOTIMPL;
390 HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface,
391 DWORD* pdwWidth,
392 DWORD* pdwHeight)
394 ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
396 FIXME("%p: STUB\n", This);
397 return E_NOTIMPL;
400 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage,20)
401 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw,52)
402 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll,24)
403 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll,24)
404 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor,40)
405 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint,44)
406 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate,8)
407 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate,4)
408 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate,4)
409 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate,4)
410 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText,8)
411 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText,8)
412 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX,8)
413 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos,8)
414 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize,36)
415 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget,8)
416 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange,12)
417 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize,12)
419 static const ITextServicesVtbl textservices_Vtbl =
421 fnTextSrv_QueryInterface,
422 fnTextSrv_AddRef,
423 fnTextSrv_Release,
424 THISCALL(fnTextSrv_TxSendMessage),
425 THISCALL(fnTextSrv_TxDraw),
426 THISCALL(fnTextSrv_TxGetHScroll),
427 THISCALL(fnTextSrv_TxGetVScroll),
428 THISCALL(fnTextSrv_OnTxSetCursor),
429 THISCALL(fnTextSrv_TxQueryHitPoint),
430 THISCALL(fnTextSrv_OnTxInplaceActivate),
431 THISCALL(fnTextSrv_OnTxInplaceDeactivate),
432 THISCALL(fnTextSrv_OnTxUIActivate),
433 THISCALL(fnTextSrv_OnTxUIDeactivate),
434 THISCALL(fnTextSrv_TxGetText),
435 THISCALL(fnTextSrv_TxSetText),
436 THISCALL(fnTextSrv_TxGetCurrentTargetX),
437 THISCALL(fnTextSrv_TxGetBaseLinePos),
438 THISCALL(fnTextSrv_TxGetNaturalSize),
439 THISCALL(fnTextSrv_TxGetDropTarget),
440 THISCALL(fnTextSrv_OnTxPropertyBitsChange),
441 THISCALL(fnTextSrv_TxGetCachedSize)