kernel32/tests: Use win_skip() to skip over unimplemented functionality.
[wine] / dlls / riched20 / txtsrv.c
1 /*
2  * RichEdit - functions and interfaces around CreateTextServices
3  *
4  * Copyright 2005, 2006, Maarten Lankhorst
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
26 #define COBJMACROS
27
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"
36
37 #ifdef __i386__  /* thiscall functions are i386-specific */
38
39 #define THISCALL(func) __thiscall_ ## func
40 #define DEFINE_THISCALL_WRAPPER(func) \
41    extern typeof(func) THISCALL(func); \
42    __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
43                    "popl %eax\n\t" \
44                    "pushl %ecx\n\t" \
45                    "pushl %eax\n\t" \
46                    "jmp " __ASM_NAME(#func) )
47 #else /* __i386__ */
48
49 #define THISCALL(func) func
50 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
51
52 #endif /* __i386__ */
53
54 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
55
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;
64
65 static const ITextServicesVtbl textservices_Vtbl;
66
67 /******************************************************************
68  *        CreateTextServices (RICHED20.4)
69  */
70 HRESULT WINAPI CreateTextServices(IUnknown  * pUnkOuter,
71                                   ITextHost * pITextHost,
72                                   IUnknown  **ppUnk)
73 {
74    ITextServicesImpl *ITextImpl;
75    HRESULT hres;
76    TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
77    if (pITextHost == NULL)
78       return E_POINTER;
79
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    ME_HandleMessage(ITextImpl->editor, WM_CREATE, 0, 0, TRUE, &hres);
91
92    if (pUnkOuter)
93    {
94       FIXME("Support aggregation\n");
95       return CLASS_E_NOAGGREGATION;
96    }
97
98    *ppUnk = (IUnknown *)ITextImpl;
99    return S_OK;
100 }
101
102 #define ICOM_THIS_MULTI(impl,field,iface) \
103                     impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
104
105 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices * iface,
106                                                REFIID riid,
107                                                LPVOID * ppv)
108 {
109    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
110    TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
111    *ppv = NULL;
112    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
113       *ppv = This;
114
115    if (*ppv)
116    {
117       IUnknown_AddRef((IUnknown *)(*ppv));
118       TRACE ("-- Interface = %p\n", *ppv);
119       return S_OK;
120    }
121    FIXME("Unknown interface: %s\n", debugstr_guid(riid));
122    return E_NOINTERFACE;
123 }
124
125 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
126 {
127    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
128    DWORD ref = InterlockedIncrement(&This->ref);
129
130    TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
131    return ref;
132 }
133
134 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
135 {
136    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
137    DWORD ref = InterlockedDecrement(&This->ref);
138
139    TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
140
141    if (!ref)
142    {
143       ITextHost_Release(This->pMyHost);
144       This->csTxtSrv.DebugInfo->Spare[0] = 0;
145       DeleteCriticalSection(&This->csTxtSrv);
146       CoTaskMemFree(This);
147    }
148    return ref;
149 }
150
151 HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface,
152                                        UINT msg,
153                                        WPARAM wparam,
154                                        LPARAM lparam,
155                                        LRESULT* plresult)
156 {
157    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
158    HRESULT hresult;
159
160    *plresult = ME_HandleMessage(This->editor, msg, wparam, lparam, TRUE, &hresult);
161    return hresult;
162 }
163
164 HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface,
165                                 DWORD dwDrawAspect,
166                                 LONG lindex,
167                                 void* pvAspect,
168                                 DVTARGETDEVICE* ptd,
169                                 HDC hdcDraw,
170                                 HDC hdcTargetDev,
171                                 LPCRECTL lprcBounds,
172                                 LPCRECTL lprcWBounds,
173                                 LPRECT lprcUpdate,
174                                 BOOL (CALLBACK * pfnContinue)(DWORD),
175                                 DWORD dwContinue,
176                                 LONG lViewId)
177 {
178    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
179
180    FIXME("%p: STUB\n", This);
181    return E_NOTIMPL;
182 }
183
184 HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface,
185                                       LONG* plMin,
186                                       LONG* plMax,
187                                       LONG* plPos,
188                                       LONG* plPage,
189                                       BOOL* pfEnabled)
190 {
191    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
192
193    *plMin = This->editor->horz_si.nMin;
194    *plMax = This->editor->horz_si.nMax;
195    *plPos = This->editor->horz_si.nPos;
196    *plPage = This->editor->horz_si.nPage;
197    *pfEnabled = (This->editor->styleFlags & WS_HSCROLL) != 0;
198    return S_OK;
199 }
200
201 HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface,
202                                       LONG* plMin,
203                                       LONG* plMax,
204                                       LONG* plPos,
205                                       LONG* plPage,
206                                       BOOL* pfEnabled)
207 {
208    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
209
210    *plMin = This->editor->vert_si.nMin;
211    *plMax = This->editor->vert_si.nMax;
212    *plPos = This->editor->vert_si.nPos;
213    *plPage = This->editor->vert_si.nPage;
214    *pfEnabled = (This->editor->styleFlags & WS_VSCROLL) != 0;
215    return S_OK;
216 }
217
218 HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface,
219                                        DWORD dwDrawAspect,
220                                        LONG lindex,
221                                        void* pvAspect,
222                                        DVTARGETDEVICE* ptd,
223                                        HDC hdcDraw,
224                                        HDC hicTargetDev,
225                                        LPCRECT lprcClient,
226                                        INT x, INT y)
227 {
228    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
229
230    FIXME("%p: STUB\n", This);
231    return E_NOTIMPL;
232 }
233
234 HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface,
235                                          DWORD dwDrawAspect,
236                                          LONG lindex,
237                                          void* pvAspect,
238                                          DVTARGETDEVICE* ptd,
239                                          HDC hdcDraw,
240                                          HDC hicTargetDev,
241                                          LPCRECT lprcClient,
242                                          INT x, INT y,
243                                          DWORD* pHitResult)
244 {
245    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
246
247    FIXME("%p: STUB\n", This);
248    return E_NOTIMPL;
249 }
250
251 HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface,
252                                              LPCRECT prcClient)
253 {
254    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
255
256    FIXME("%p: STUB\n", This);
257    return E_NOTIMPL;
258 }
259
260 HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
261 {
262    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
263
264    FIXME("%p: STUB\n", This);
265    return E_NOTIMPL;
266 }
267
268 HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
269 {
270    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
271
272    FIXME("%p: STUB\n", This);
273    return E_NOTIMPL;
274 }
275
276 HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
277 {
278    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
279
280    FIXME("%p: STUB\n", This);
281    return E_NOTIMPL;
282 }
283
284 HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface,
285                                    BSTR* pbstrText)
286 {
287    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
288    int length;
289
290    length = ME_GetTextLength(This->editor);
291    if (length)
292    {
293       BSTR bstr;
294       bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
295       if (bstr == NULL)
296          return E_OUTOFMEMORY;
297
298       ME_GetTextW(This->editor, bstr , 0, length, FALSE);
299       *pbstrText = bstr;
300    } else {
301       *pbstrText = NULL;
302    }
303
304    return S_OK;
305 }
306
307 HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface,
308                                    LPCWSTR pszText)
309 {
310    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
311
312    ME_InternalDeleteText(This->editor, 0, ME_GetTextLength(This->editor),
313                          FALSE);
314    ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
315                            This->editor->pBuffer->pDefaultStyle);
316    ME_SetSelection(This->editor, 0, 0);
317    This->editor->nModifyStep = 0;
318    OleFlushClipboard();
319    ME_EmptyUndoStack(This->editor);
320    ME_UpdateRepaint(This->editor);
321
322    return S_OK;
323 }
324
325 HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface,
326                                              LONG* x)
327 {
328    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
329
330    FIXME("%p: STUB\n", This);
331    return E_NOTIMPL;
332 }
333
334 HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface,
335                                           LONG* x)
336 {
337    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
338
339    FIXME("%p: STUB\n", This);
340    return E_NOTIMPL;
341 }
342
343 HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
344                                           DWORD dwAspect,
345                                           HDC hdcDraw,
346                                           HDC hicTargetDev,
347                                           DVTARGETDEVICE* ptd,
348                                           DWORD dwMode,
349                                           const SIZEL* psizelExtent,
350                                           LONG* pwidth,
351                                           LONG* pheight)
352 {
353    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
354
355    FIXME("%p: STUB\n", This);
356    return E_NOTIMPL;
357 }
358
359 HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface,
360                                          IDropTarget** ppDropTarget)
361 {
362    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
363
364    FIXME("%p: STUB\n", This);
365    return E_NOTIMPL;
366 }
367
368 HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface,
369                                                 DWORD dwMask,
370                                                 DWORD dwBits)
371 {
372    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
373
374    FIXME("%p: STUB\n", This);
375    return E_NOTIMPL;
376 }
377
378 HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface,
379                                          DWORD* pdwWidth,
380                                          DWORD* pdwHeight)
381 {
382    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
383
384    FIXME("%p: STUB\n", This);
385    return E_NOTIMPL;
386 }
387
388 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage)
389 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw)
390 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll)
391 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll)
392 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor)
393 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint)
394 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate)
395 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate)
396 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate)
397 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate)
398 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText)
399 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText)
400 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX)
401 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos)
402 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize)
403 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget)
404 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange)
405 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize)
406
407 static const ITextServicesVtbl textservices_Vtbl =
408 {
409    fnTextSrv_QueryInterface,
410    fnTextSrv_AddRef,
411    fnTextSrv_Release,
412    THISCALL(fnTextSrv_TxSendMessage),
413    THISCALL(fnTextSrv_TxDraw),
414    THISCALL(fnTextSrv_TxGetHScroll),
415    THISCALL(fnTextSrv_TxGetVScroll),
416    THISCALL(fnTextSrv_OnTxSetCursor),
417    THISCALL(fnTextSrv_TxQueryHitPoint),
418    THISCALL(fnTextSrv_OnTxInplaceActivate),
419    THISCALL(fnTextSrv_OnTxInplaceDeactivate),
420    THISCALL(fnTextSrv_OnTxUIActivate),
421    THISCALL(fnTextSrv_OnTxUIDeactivate),
422    THISCALL(fnTextSrv_TxGetText),
423    THISCALL(fnTextSrv_TxSetText),
424    THISCALL(fnTextSrv_TxGetCurrentTargetX),
425    THISCALL(fnTextSrv_TxGetBaseLinePos),
426    THISCALL(fnTextSrv_TxGetNaturalSize),
427    THISCALL(fnTextSrv_TxGetDropTarget),
428    THISCALL(fnTextSrv_OnTxPropertyBitsChange),
429    THISCALL(fnTextSrv_TxGetCachedSize)
430 };