2 * Unit test suite for windowless rich edit controls
4 * Copyright 2008 Maarten Lankhorst
5 * Copyright 2008 Austin Lund
6 * Copyright 2008 Dylan Smith
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37 #include <wine/test.h>
41 #define DEFINE_EXPECT(func) \
42 static UINT called_count_ ## func = 0
44 #define INCREASE_CALL_COUNTER(func) \
46 called_count_ ## func++; \
49 #define CHECK_CALLED(func) \
51 ok(called_count_ ## func, "expected " #func "\n"); \
54 #define CHECK_NOT_CALLED(func) \
56 ok(!called_count_ ## func, "unexpected " #func "\n"); \
59 #define CLEAR_COUNTER(func) \
60 called_count_ ## func = 0
62 static HMODULE hmoduleRichEdit
;
63 static IID
*pIID_ITextServices
;
64 static IID
*pIID_ITextHost
;
65 static IID
*pIID_ITextHost2
;
66 static PCreateTextServices pCreateTextServices
;
68 /* Define C Macros for ITextServices calls. */
70 /* Use a special table for x86 machines to convert the thiscall
71 * calling convention. This isn't needed on other platforms. */
72 #if defined(__i386__) && !defined(__MINGW32__) && (!defined(_MSC_VER) || !defined(__clang__))
73 static ITextServicesVtbl itextServicesStdcallVtbl
;
74 #define TXTSERV_VTABLE(This) (&itextServicesStdcallVtbl)
76 #define TXTSERV_VTABLE(This) (This)->lpVtbl
79 #define ITextServices_TxSendMessage(This,a,b,c,d) TXTSERV_VTABLE(This)->TxSendMessage(This,a,b,c,d)
80 #define ITextServices_TxDraw(This,a,b,c,d,e,f,g,h,i,j,k,l) TXTSERV_VTABLE(This)->TxDraw(This,a,b,c,d,e,f,g,h,i,j,k,l)
81 #define ITextServices_TxGetHScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetHScroll(This,a,b,c,d,e)
82 #define ITextServices_TxGetVScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetVScroll(This,a,b,c,d,e)
83 #define ITextServices_OnTxSetCursor(This,a,b,c,d,e,f,g,h,i) TXTSERV_VTABLE(This)->OnTxSetCursor(This,a,b,c,d,e,f,g,h,i)
84 #define ITextServices_TxQueryHitPoint(This,a,b,c,d,e,f,g,h,i,j) TXTSERV_VTABLE(This)->TxQueryHitPoint(This,a,b,c,d,e,f,g,h,i,j)
85 #define ITextServices_OnTxInPlaceActivate(This,a) TXTSERV_VTABLE(This)->OnTxInPlaceActivate(This,a)
86 #define ITextServices_OnTxInPlaceDeactivate(This) TXTSERV_VTABLE(This)->OnTxInPlaceDeactivate(This)
87 #define ITextServices_OnTxUIActivate(This) TXTSERV_VTABLE(This)->OnTxUIActivate(This)
88 #define ITextServices_OnTxUIDeactivate(This) TXTSERV_VTABLE(This)->OnTxUIDeactivate(This)
89 #define ITextServices_TxGetText(This,a) TXTSERV_VTABLE(This)->TxGetText(This,a)
90 #define ITextServices_TxSetText(This,a) TXTSERV_VTABLE(This)->TxSetText(This,a)
91 #define ITextServices_TxGetCurTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurTargetX(This,a)
92 #define ITextServices_TxGetBaseLinePos(This,a) TXTSERV_VTABLE(This)->TxGetBaseLinePos(This,a)
93 #define ITextServices_TxGetNaturalSize(This,a,b,c,d,e,f,g,h) TXTSERV_VTABLE(This)->TxGetNaturalSize(This,a,b,c,d,e,f,g,h)
94 #define ITextServices_TxGetDropTarget(This,a) TXTSERV_VTABLE(This)->TxGetDropTarget(This,a)
95 #define ITextServices_OnTxPropertyBitsChange(This,a,b) TXTSERV_VTABLE(This)->OnTxPropertyBitsChange(This,a,b)
96 #define ITextServices_TxGetCachedSize(This,a,b) TXTSERV_VTABLE(This)->TxGetCachedSize(This,a,b)
98 /* Set the WINETEST_DEBUG environment variable to be greater than 1 for verbose
99 * function call traces of ITextHost. */
100 #define TRACECALL if(winetest_debug > 1) trace
102 /************************************************************************/
103 /* ITextHost implementation for conformance testing. */
105 DEFINE_EXPECT(ITextHostImpl_TxViewChange
);
107 typedef struct ITextHostTestImpl
109 ITextHost ITextHost_iface
;
113 CHARFORMAT2W char_format
;
114 DWORD scrollbars
, props
;
117 static inline ITextHostTestImpl
*impl_from_ITextHost(ITextHost
*iface
)
119 return CONTAINING_RECORD(iface
, ITextHostTestImpl
, ITextHost_iface
);
122 static const WCHAR lorem
[] = L
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
123 "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
124 "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "
125 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
127 static HRESULT WINAPI
ITextHostImpl_QueryInterface(ITextHost
*iface
,
131 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
133 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, pIID_ITextHost
)) {
134 *ppvObject
= &This
->ITextHost_iface
;
135 ITextHost_AddRef((ITextHost
*)*ppvObject
);
139 return E_NOINTERFACE
;
142 static ULONG WINAPI
ITextHostImpl_AddRef(ITextHost
*iface
)
144 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
145 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
149 static ULONG WINAPI
ITextHostImpl_Release(ITextHost
*iface
)
151 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
152 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
163 static HDC __thiscall
ITextHostImpl_TxGetDC(ITextHost
*iface
)
165 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
166 TRACECALL("Call to TxGetDC(%p)\n", This
);
167 if (This
->window
) return GetDC( This
->window
);
171 static INT __thiscall
ITextHostImpl_TxReleaseDC(ITextHost
*iface
, HDC hdc
)
173 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
174 TRACECALL("Call to TxReleaseDC(%p)\n", This
);
175 if (This
->window
) return ReleaseDC( This
->window
, hdc
);
179 static BOOL __thiscall
ITextHostImpl_TxShowScrollBar(ITextHost
*iface
, INT fnBar
, BOOL fShow
)
181 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
182 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
187 static BOOL __thiscall
ITextHostImpl_TxEnableScrollBar(ITextHost
*iface
, INT fuSBFlags
, INT fuArrowflags
)
189 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
190 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
191 This
, fuSBFlags
, fuArrowflags
);
195 static BOOL __thiscall
ITextHostImpl_TxSetScrollRange(ITextHost
*iface
, INT fnBar
, LONG nMinPos
,
196 INT nMaxPos
, BOOL fRedraw
)
198 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
199 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%ld, nMaxPos=%d, fRedraw=%d)\n",
200 This
, fnBar
, nMinPos
, nMaxPos
, fRedraw
);
204 static BOOL __thiscall
ITextHostImpl_TxSetScrollPos(ITextHost
*iface
, INT fnBar
, INT nPos
, BOOL fRedraw
)
206 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
207 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
208 This
, fnBar
, nPos
, fRedraw
);
212 static void __thiscall
ITextHostImpl_TxInvalidateRect(ITextHost
*iface
, LPCRECT prc
, BOOL fMode
)
214 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
215 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
219 static void __thiscall
ITextHostImpl_TxViewChange(ITextHost
*iface
, BOOL fUpdate
)
221 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
222 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
224 INCREASE_CALL_COUNTER(ITextHostImpl_TxViewChange
);
227 static BOOL __thiscall
ITextHostImpl_TxCreateCaret(ITextHost
*iface
, HBITMAP hbmp
, INT xWidth
, INT yHeight
)
229 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
230 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
231 This
, hbmp
, xWidth
, yHeight
);
235 static BOOL __thiscall
ITextHostImpl_TxShowCaret(ITextHost
*iface
, BOOL fShow
)
237 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
238 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
243 static BOOL __thiscall
ITextHostImpl_TxSetCaretPos(ITextHost
*iface
, INT x
, INT y
)
245 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
246 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This
, x
, y
);
250 static BOOL __thiscall
ITextHostImpl_TxSetTimer(ITextHost
*iface
, UINT idTimer
, UINT uTimeout
)
252 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
253 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
254 This
, idTimer
, uTimeout
);
258 static void __thiscall
ITextHostImpl_TxKillTimer(ITextHost
*iface
, UINT idTimer
)
260 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
261 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This
, idTimer
);
264 static void __thiscall
ITextHostImpl_TxScrollWindowEx(ITextHost
*iface
, INT dx
, INT dy
, LPCRECT lprcScroll
,
265 LPCRECT lprcClip
, HRGN hRgnUpdate
, LPRECT lprcUpdate
,
268 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
269 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
270 This
, dx
, dy
, lprcScroll
, lprcClip
, hRgnUpdate
, lprcUpdate
, fuScroll
);
273 static void __thiscall
ITextHostImpl_TxSetCapture(ITextHost
*iface
, BOOL fCapture
)
275 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
276 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This
, fCapture
);
279 static void __thiscall
ITextHostImpl_TxSetFocus(ITextHost
*iface
)
281 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
282 TRACECALL("Call to TxSetFocus(%p)\n", This
);
285 static void __thiscall
ITextHostImpl_TxSetCursor(ITextHost
*iface
, HCURSOR hcur
, BOOL fText
)
287 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
288 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
292 static BOOL __thiscall
ITextHostImpl_TxScreenToClient(ITextHost
*iface
, LPPOINT lppt
)
294 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
295 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This
, lppt
);
299 static BOOL __thiscall
ITextHostImpl_TxClientToScreen(ITextHost
*iface
, LPPOINT lppt
)
301 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
302 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This
, lppt
);
306 static HRESULT __thiscall
ITextHostImpl_TxActivate(ITextHost
*iface
, LONG
*plOldState
)
308 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
309 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This
, plOldState
);
313 static HRESULT __thiscall
ITextHostImpl_TxDeactivate(ITextHost
*iface
, LONG lNewState
)
315 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
316 TRACECALL("Call to TxDeactivate(%p, lNewState=%ld)\n", This
, lNewState
);
320 static HRESULT __thiscall
ITextHostImpl_TxGetClientRect(ITextHost
*iface
, LPRECT prc
)
322 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
323 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This
, prc
);
324 *prc
= This
->client_rect
;
328 static HRESULT __thiscall
ITextHostImpl_TxGetViewInset(ITextHost
*iface
, LPRECT prc
)
330 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
331 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This
, prc
);
335 static HRESULT __thiscall
ITextHostImpl_TxGetCharFormat(ITextHost
*iface
, const CHARFORMATW
**ppCF
)
337 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
338 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This
, ppCF
);
339 *ppCF
= (CHARFORMATW
*)&This
->char_format
;
343 static HRESULT __thiscall
ITextHostImpl_TxGetParaFormat(ITextHost
*iface
, const PARAFORMAT
**ppPF
)
345 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
346 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This
, ppPF
);
350 static COLORREF __thiscall
ITextHostImpl_TxGetSysColor(ITextHost
*iface
, int nIndex
)
352 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
353 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This
, nIndex
);
357 static HRESULT __thiscall
ITextHostImpl_TxGetBackStyle(ITextHost
*iface
, TXTBACKSTYLE
*pStyle
)
359 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
360 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This
, pStyle
);
364 static HRESULT __thiscall
ITextHostImpl_TxGetMaxLength(ITextHost
*iface
, DWORD
*pLength
)
366 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
367 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This
, pLength
);
371 static HRESULT __thiscall
ITextHostImpl_TxGetScrollBars(ITextHost
*iface
, DWORD
*scrollbars
)
373 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
374 TRACECALL("Call to TxGetScrollBars(%p, scrollbars=%p)\n", This
, scrollbars
);
375 *scrollbars
= This
->scrollbars
;
379 static HRESULT __thiscall
ITextHostImpl_TxGetPasswordChar(ITextHost
*iface
, WCHAR
*pch
)
381 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
382 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This
, pch
);
386 static HRESULT __thiscall
ITextHostImpl_TxGetAcceleratorPos(ITextHost
*iface
, LONG
*pch
)
388 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
389 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This
, pch
);
393 static HRESULT __thiscall
ITextHostImpl_TxGetExtent(ITextHost
*iface
, LPSIZEL lpExtent
)
395 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
396 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This
, lpExtent
);
400 static HRESULT __thiscall
ITextHostImpl_OnTxCharFormatChange(ITextHost
*iface
, const CHARFORMATW
*pcf
)
402 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
403 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This
, pcf
);
407 static HRESULT __thiscall
ITextHostImpl_OnTxParaFormatChange(ITextHost
*iface
, const PARAFORMAT
*ppf
)
409 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
410 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This
, ppf
);
414 /* This must return S_OK for the native ITextServices object to
416 static HRESULT __thiscall
ITextHostImpl_TxGetPropertyBits(ITextHost
*iface
, DWORD dwMask
, DWORD
*pdwBits
)
418 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
419 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08lx, pdwBits=%p)\n",
420 This
, dwMask
, pdwBits
);
421 *pdwBits
= This
->props
& dwMask
;
425 static int en_vscroll_sent
;
426 static int en_update_sent
;
427 static int en_change_sent
;
428 static int en_selchange_sent
;
429 static HRESULT __thiscall
ITextHostImpl_TxNotify( ITextHost
*iface
, DWORD code
, void *data
)
431 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
432 TRACECALL( "Call to TxNotify(%p, code = %#lx, data = %p)\n", This
, code
, data
);
437 ok( !data
, "got %p\n", data
);
441 ok( !data
, "got %p\n", data
);
446 ok( data
!= NULL
, "got %p\n", data
);
450 ok( data
!= NULL
, "got %p\n", data
);
456 static HIMC __thiscall
ITextHostImpl_TxImmGetContext(ITextHost
*iface
)
458 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
459 TRACECALL("Call to TxImmGetContext(%p)\n", This
);
463 static void __thiscall
ITextHostImpl_TxImmReleaseContext(ITextHost
*iface
, HIMC himc
)
465 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
466 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This
, himc
);
469 /* This function must set the variable pointed to by *lSelBarWidth.
470 Otherwise an uninitialized value will be used to calculate
471 positions and sizes even if E_NOTIMPL is returned. */
472 static HRESULT __thiscall
ITextHostImpl_TxGetSelectionBarWidth(ITextHost
*iface
, LONG
*lSelBarWidth
)
474 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
475 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
481 static ITextHostVtbl itextHostVtbl
= {
482 ITextHostImpl_QueryInterface
,
483 ITextHostImpl_AddRef
,
484 ITextHostImpl_Release
,
485 ITextHostImpl_TxGetDC
,
486 ITextHostImpl_TxReleaseDC
,
487 ITextHostImpl_TxShowScrollBar
,
488 ITextHostImpl_TxEnableScrollBar
,
489 ITextHostImpl_TxSetScrollRange
,
490 ITextHostImpl_TxSetScrollPos
,
491 ITextHostImpl_TxInvalidateRect
,
492 ITextHostImpl_TxViewChange
,
493 ITextHostImpl_TxCreateCaret
,
494 ITextHostImpl_TxShowCaret
,
495 ITextHostImpl_TxSetCaretPos
,
496 ITextHostImpl_TxSetTimer
,
497 ITextHostImpl_TxKillTimer
,
498 ITextHostImpl_TxScrollWindowEx
,
499 ITextHostImpl_TxSetCapture
,
500 ITextHostImpl_TxSetFocus
,
501 ITextHostImpl_TxSetCursor
,
502 ITextHostImpl_TxScreenToClient
,
503 ITextHostImpl_TxClientToScreen
,
504 ITextHostImpl_TxActivate
,
505 ITextHostImpl_TxDeactivate
,
506 ITextHostImpl_TxGetClientRect
,
507 ITextHostImpl_TxGetViewInset
,
508 ITextHostImpl_TxGetCharFormat
,
509 ITextHostImpl_TxGetParaFormat
,
510 ITextHostImpl_TxGetSysColor
,
511 ITextHostImpl_TxGetBackStyle
,
512 ITextHostImpl_TxGetMaxLength
,
513 ITextHostImpl_TxGetScrollBars
,
514 ITextHostImpl_TxGetPasswordChar
,
515 ITextHostImpl_TxGetAcceleratorPos
,
516 ITextHostImpl_TxGetExtent
,
517 ITextHostImpl_OnTxCharFormatChange
,
518 ITextHostImpl_OnTxParaFormatChange
,
519 ITextHostImpl_TxGetPropertyBits
,
520 ITextHostImpl_TxNotify
,
521 ITextHostImpl_TxImmGetContext
,
522 ITextHostImpl_TxImmReleaseContext
,
523 ITextHostImpl_TxGetSelectionBarWidth
526 static void *wrapperCodeMem
= NULL
;
528 #include "pshpack1.h"
530 /* Code structure for x86 byte code */
533 BYTE pop_eax
; /* popl %eax */
534 BYTE push_ecx
; /* pushl %ecx */
535 BYTE push_eax
; /* pushl %eax */
536 BYTE jmp_func
; /* jmp $func */
538 } THISCALL_TO_STDCALL_THUNK
;
542 BYTE pop_eax
; /* popl %eax */
543 BYTE pop_ecx
; /* popl %ecx */
544 BYTE push_eax
; /* pushl %eax */
545 BYTE mov_vtable_eax
[2]; /* movl (%ecx), %eax */
546 BYTE jmp_eax
[2]; /* jmp *$vtablefunc_offset(%eax) */
547 int vtablefunc_offset
;
548 } STDCALL_TO_THISCALL_THUNK
;
552 static void setup_thiscall_wrappers(void)
554 #if defined(__i386__) && !defined(__MINGW32__) && (!defined(_MSC_VER) || !defined(__clang__))
557 THISCALL_TO_STDCALL_THUNK
*thunk
;
558 STDCALL_TO_THISCALL_THUNK
*thunk2
;
560 wrapperCodeMem
= VirtualAlloc(NULL
,
561 (sizeof(ITextHostVtbl
)/sizeof(void*) - 3)
562 * sizeof(THISCALL_TO_STDCALL_THUNK
)
563 +(sizeof(ITextServicesVtbl
)/sizeof(void*) - 3)
564 * sizeof(STDCALL_TO_THISCALL_THUNK
),
565 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
566 thunk
= wrapperCodeMem
;
568 /* Wrap all ITextHostImpl methods with code to perform a thiscall to
569 * stdcall conversion. The thiscall calling convention places the This
570 * pointer in ecx on the x86 platform, and the stdcall calling convention
571 * pushes the This pointer on the stack as the first argument.
573 * The byte code does the conversion then jumps to the real function.
575 * Each wrapper needs to be modified so that the function to jump to is
576 * modified in the byte code. */
578 /* Skip QueryInterface, AddRef, and Release native actually
579 * defined them with the stdcall calling convention. */
580 pVtable
= (void**)&itextHostVtbl
+ 3;
581 pVtableEnd
= (void**)(&itextHostVtbl
+ 1);
582 while (pVtable
!= pVtableEnd
) {
583 /* write byte code to executable memory */
584 thunk
->pop_eax
= 0x58; /* popl %eax */
585 thunk
->push_ecx
= 0x51; /* pushl %ecx */
586 thunk
->push_eax
= 0x50; /* pushl %eax */
587 thunk
->jmp_func
= 0xe9; /* jmp $func */
588 /* The address needs to be relative to the end of the jump instructions. */
589 thunk
->func
= (char*)*pVtable
- (char*)(&thunk
->func
+ 1);
595 /* Setup an ITextServices standard call vtable that will call the
596 * native thiscall vtable when the methods are called. */
598 /* QueryInterface, AddRef, and Release should be called directly on the
599 * real vtable since they use the stdcall calling convention. */
600 thunk2
= (STDCALL_TO_THISCALL_THUNK
*)thunk
;
601 pVtable
= (void**)&itextServicesStdcallVtbl
+ 3;
602 pVtableEnd
= (void**)(&itextServicesStdcallVtbl
+ 1);
603 while (pVtable
!= pVtableEnd
) {
604 /* write byte code to executable memory */
605 thunk2
->pop_eax
= 0x58; /* popl %eax */
606 thunk2
->pop_ecx
= 0x59; /* popl %ecx */
607 thunk2
->push_eax
= 0x50; /* pushl %eax */
608 thunk2
->mov_vtable_eax
[0] = 0x8b; /* movl (%ecx), %eax */
609 thunk2
->mov_vtable_eax
[1] = 0x01;
610 thunk2
->jmp_eax
[0] = 0xff; /* jmp *$vtablefunc_offset(%eax) */
611 thunk2
->jmp_eax
[1] = 0xa0;
612 thunk2
->vtablefunc_offset
= (char*)pVtable
- (char*)&itextServicesStdcallVtbl
;
617 #endif /* __i386__ */
620 static void hf_to_cf(HFONT hf
, CHARFORMAT2W
*cf
)
624 GetObjectW(hf
, sizeof(lf
), &lf
);
625 lstrcpyW(cf
->szFaceName
, lf
.lfFaceName
);
626 cf
->yHeight
= MulDiv(abs(lf
.lfHeight
), 1440, GetDeviceCaps(GetDC(NULL
), LOGPIXELSY
));
627 if (lf
.lfWeight
> FW_NORMAL
) cf
->dwEffects
|= CFE_BOLD
;
628 if (lf
.lfItalic
) cf
->dwEffects
|= CFE_ITALIC
;
629 if (lf
.lfUnderline
) cf
->dwEffects
|= CFE_UNDERLINE
;
630 if (lf
.lfStrikeOut
) cf
->dwEffects
|= CFE_SUBSCRIPT
;
631 cf
->bPitchAndFamily
= lf
.lfPitchAndFamily
;
632 cf
->bCharSet
= lf
.lfCharSet
;
635 /*************************************************************************/
636 /* Conformance test functions. */
638 /* Initialize the test texthost structure */
639 static BOOL
init_texthost(ITextServices
**txtserv
, ITextHost
**ret
)
641 ITextHostTestImpl
*dummyTextHost
;
646 dummyTextHost
= CoTaskMemAlloc(sizeof(*dummyTextHost
));
647 if (dummyTextHost
== NULL
) {
648 win_skip("Insufficient memory to create ITextHost interface\n");
651 dummyTextHost
->ITextHost_iface
.lpVtbl
= &itextHostVtbl
;
652 dummyTextHost
->refCount
= 1;
653 dummyTextHost
->window
= NULL
;
654 SetRectEmpty( &dummyTextHost
->client_rect
);
655 memset(&dummyTextHost
->char_format
, 0, sizeof(dummyTextHost
->char_format
));
656 dummyTextHost
->char_format
.cbSize
= sizeof(dummyTextHost
->char_format
);
657 dummyTextHost
->char_format
.dwMask
= CFM_ALL2
;
658 dummyTextHost
->scrollbars
= ES_AUTOVSCROLL
;
659 dummyTextHost
->props
= 0;
660 hf
= GetStockObject(DEFAULT_GUI_FONT
);
661 hf_to_cf(hf
, &dummyTextHost
->char_format
);
663 /* MSDN states that an IUnknown object is returned by
664 CreateTextServices which is then queried to obtain a
665 ITextServices object. */
666 result
= pCreateTextServices(NULL
, &dummyTextHost
->ITextHost_iface
, &init
);
667 ok(result
== S_OK
, "Did not return S_OK when created (result = %lx)\n", result
);
668 ok(dummyTextHost
->refCount
== 1, "host ref %ld\n", dummyTextHost
->refCount
);
669 if (result
!= S_OK
) {
670 CoTaskMemFree(dummyTextHost
);
671 win_skip("CreateTextServices failed.\n");
675 result
= IUnknown_QueryInterface(init
, pIID_ITextServices
, (void**)txtserv
);
676 ok((result
== S_OK
) && (*txtserv
!= NULL
), "Querying interface failed (result = %lx, txtserv = %p)\n", result
, *txtserv
);
677 IUnknown_Release(init
);
678 if (!((result
== S_OK
) && (*txtserv
!= NULL
))) {
679 CoTaskMemFree(dummyTextHost
);
680 win_skip("Could not retrieve ITextServices interface\n");
684 *ret
= &dummyTextHost
->ITextHost_iface
;
688 static void fill_reobject_struct(REOBJECT
*reobj
, LONG cp
, LPOLEOBJECT poleobj
,
689 LPSTORAGE pstg
, LPOLECLIENTSITE polesite
, LONG sizel_cx
,
690 LONG sizel_cy
, DWORD aspect
, DWORD flags
, DWORD user
)
692 reobj
->cbStruct
= sizeof(*reobj
);
693 reobj
->clsid
= CLSID_NULL
;
695 reobj
->poleobj
= poleobj
;
697 reobj
->polesite
= polesite
;
698 reobj
->sizel
.cx
= sizel_cx
;
699 reobj
->sizel
.cy
= sizel_cy
;
700 reobj
->dvaspect
= aspect
;
701 reobj
->dwFlags
= flags
;
702 reobj
->dwUser
= user
;
705 static void test_TxGetText(void)
707 const WCHAR
*expected_string
;
708 IOleClientSite
*clientsite
;
709 ITextServices
*txtserv
;
716 if (!init_texthost(&txtserv
, &host
))
719 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
720 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %lx)\n", hres
);
721 SysFreeString(rettext
);
723 hres
= ITextServices_TxSetText(txtserv
, L
"abcdefg");
724 ok(hres
== S_OK
, "Got hres: %#lx.\n", hres
);
725 hres
= ITextServices_QueryInterface(txtserv
, &IID_IRichEditOle
, (void **)&reole
);
726 ok(hres
== S_OK
, "Got hres: %#lx.\n", hres
);
727 hres
= IRichEditOle_GetClientSite(reole
, &clientsite
);
728 ok(hres
== S_OK
, "Got hres: %#lx.\n", hres
);
729 expected_string
= L
"abc\xfffc""defg";
730 fill_reobject_struct(&reobject
, 3, NULL
, NULL
, clientsite
, 10, 10, DVASPECT_CONTENT
, 0, 1);
731 hres
= IRichEditOle_InsertObject(reole
, &reobject
);
732 ok(hres
== S_OK
, "Got hres: %#lx.\n", hres
);
733 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
734 ok(hres
== S_OK
, "Got hres: %#lx.\n", hres
);
735 ok(lstrlenW(rettext
) == lstrlenW(expected_string
), "Got wrong length: %d.\n", lstrlenW(rettext
));
736 todo_wine
ok(!lstrcmpW(rettext
, expected_string
), "Got wrong content: %s.\n", debugstr_w(rettext
));
737 SysFreeString(rettext
);
738 IOleClientSite_Release(clientsite
);
739 IRichEditOle_Release(reole
);
741 ITextServices_Release(txtserv
);
742 ITextHost_Release(host
);
745 static void test_TxSetText(void)
747 ITextServices
*txtserv
;
751 WCHAR settext
[] = {'T','e','s','t',0};
753 if (!init_texthost(&txtserv
, &host
))
756 hres
= ITextServices_TxSetText(txtserv
, settext
);
757 ok(hres
== S_OK
, "ITextServices_TxSetText failed (result = %lx)\n", hres
);
759 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
760 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %lx)\n", hres
);
762 ok(SysStringLen(rettext
) == 4,
763 "String returned of wrong length (expected 4, got %d)\n", SysStringLen(rettext
));
764 ok(memcmp(rettext
,settext
,SysStringByteLen(rettext
)) == 0,
765 "String returned differs\n");
767 SysFreeString(rettext
);
769 /* Null-pointer should behave the same as empty-string */
771 hres
= ITextServices_TxSetText(txtserv
, 0);
772 ok(hres
== S_OK
, "ITextServices_TxSetText failed (result = %lx)\n", hres
);
774 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
775 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %lx)\n", hres
);
776 ok(SysStringLen(rettext
) == 0,
777 "String returned of wrong length (expected 0, got %d)\n", SysStringLen(rettext
));
779 SysFreeString(rettext
);
780 ITextServices_Release(txtserv
);
781 ITextHost_Release(host
);
784 #define CHECK_TXGETNATURALSIZE(res,width,height,hdc,rect,string) \
785 _check_txgetnaturalsize(res, width, height, hdc, rect, string, __LINE__)
786 static void _check_txgetnaturalsize(HRESULT res
, LONG width
, LONG height
, HDC hdc
, RECT rect
, LPCWSTR string
, int line
)
788 RECT expected_rect
= rect
;
789 LONG expected_width
, expected_height
;
791 DrawTextW(hdc
, string
, -1, &expected_rect
, DT_LEFT
| DT_CALCRECT
| DT_NOCLIP
| DT_EDITCONTROL
);
792 expected_width
= expected_rect
.right
- expected_rect
.left
;
793 expected_height
= expected_rect
.bottom
- expected_rect
.top
;
794 ok_(__FILE__
,line
)(res
== S_OK
, "ITextServices_TxGetNaturalSize failed: 0x%08lx.\n", res
);
795 todo_wine
ok_(__FILE__
,line
)(width
>= expected_width
&& width
<= expected_width
+ 1,
796 "got wrong width: %ld, expected: %ld {+1}.\n", width
, expected_width
);
797 ok_(__FILE__
,line
)(height
== expected_height
, "got wrong height: %ld, expected: %ld.\n",
798 height
, expected_height
);
801 static void test_TxGetNaturalSize(void)
803 ITextServices
*txtserv
;
807 static const WCHAR test_text
[] = L
"TestSomeText";
816 if (!init_texthost(&txtserv
, &host
))
819 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
| WS_VISIBLE
,
820 0, 0, 100, 100, 0, 0, 0, NULL
);
821 hdcDraw
= GetDC(hwnd
);
822 SetMapMode(hdcDraw
,MM_TEXT
);
823 GetClientRect(hwnd
, &rect
);
825 memset(&cf
, 0, sizeof(cf
));
826 cf
.cbSize
= sizeof(cf
);
827 cf
.dwMask
= CFM_ALL2
;
828 hf
= GetStockObject(DEFAULT_GUI_FONT
);
830 result
= ITextServices_TxSendMessage(txtserv
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&cf
, &lresult
);
831 ok(result
== S_OK
, "ITextServices_TxSendMessage failed: 0x%08lx.\n", result
);
832 SelectObject(hdcDraw
, hf
);
834 result
= ITextServices_TxSetText(txtserv
, test_text
);
835 ok(result
== S_OK
, "ITextServices_TxSetText failed: 0x%08lx.\n", result
);
837 extent
.cx
= -1; extent
.cy
= -1;
838 width
= rect
.right
- rect
.left
;
840 result
= ITextServices_TxGetNaturalSize(txtserv
, DVASPECT_CONTENT
, hdcDraw
, NULL
, NULL
,
841 TXTNS_FITTOCONTENT
, &extent
, &width
, &height
);
842 CHECK_TXGETNATURALSIZE(result
, width
, height
, hdcDraw
, rect
, test_text
);
844 ReleaseDC(hwnd
, hdcDraw
);
846 ITextServices_Release(txtserv
);
847 ITextHost_Release(host
);
850 static void test_TxDraw(void)
852 ITextServices
*txtserv
;
853 ITextDocument
*txtdoc
;
856 RECT client
= {0, 0, 100, 100};
857 ITextHostTestImpl
*host_impl
;
861 if (!init_texthost(&txtserv
, &host
))
864 hr
= ITextServices_QueryInterface( txtserv
, &IID_ITextDocument
, (void **)&txtdoc
);
865 ok( hr
== S_OK
, "ITextServices_QueryInterface (ITextDocument) returned %#lx\n", hr
);
867 host_impl
= impl_from_ITextHost( host
);
868 host_impl
->window
= CreateWindowExA( 0, "static", NULL
, WS_POPUP
| WS_VISIBLE
,
869 0, 0, 400, 400, 0, 0, 0, NULL
);
870 host_impl
->client_rect
= client
;
871 host_impl
->props
= TXTBIT_MULTILINE
| TXTBIT_RICHTEXT
| TXTBIT_WORDWRAP
;
872 ITextServices_OnTxPropertyBitsChange( txtserv
, TXTBIT_CLIENTRECTCHANGE
| TXTBIT_MULTILINE
| TXTBIT_RICHTEXT
| TXTBIT_WORDWRAP
,
874 hdc
= GetDC( host_impl
->window
);
876 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
877 NULL
, NULL
, 0, TXTVIEW_INACTIVE
);
878 ok( hr
== E_INVALIDARG
, "got %08lx\n", hr
);
879 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, hdc
, NULL
, NULL
, NULL
,
880 NULL
, NULL
, 0, TXTVIEW_INACTIVE
);
881 ok( hr
== E_INVALIDARG
, "got %08lx\n", hr
);
882 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, NULL
, NULL
, (RECTL
*)&client
, NULL
,
883 NULL
, NULL
, 0, TXTVIEW_INACTIVE
);
884 ok( hr
== E_FAIL
, "got %08lx\n", hr
);
885 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, hdc
, NULL
, (RECTL
*)&client
, NULL
,
886 NULL
, NULL
, 0, TXTVIEW_INACTIVE
);
887 ok( hr
== S_OK
, "got %08lx\n", hr
);
888 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, hdc
, NULL
, (RECTL
*)&client
, NULL
,
889 NULL
, NULL
, 0, TXTVIEW_ACTIVE
);
890 ok( hr
== S_OK
, "got %08lx\n", hr
);
892 hr
= ITextServices_OnTxInPlaceActivate( txtserv
, &client
);
893 ok( hr
== S_OK
, "got %08lx\n", hr
);
895 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
896 NULL
, NULL
, 0, TXTVIEW_INACTIVE
);
897 ok( hr
== S_OK
, "got %08lx\n", hr
);
899 freeze_count
= 0xdeadbeef;
900 hr
= ITextDocument_Freeze( txtdoc
, &freeze_count
);
901 ok( hr
== S_OK
, "ITextDocument_Freeze returned %#lx\n", hr
);
902 ok( freeze_count
== 1, "expected count to be %d, got %ld\n", 1, freeze_count
);
904 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, hdc
, NULL
, (RECTL
*)&client
, NULL
,
905 NULL
, NULL
, 0, TXTVIEW_INACTIVE
);
906 ok( hr
== S_OK
, "got %08lx\n", hr
);
907 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, hdc
, NULL
, (RECTL
*)&client
, NULL
,
908 NULL
, NULL
, 0, TXTVIEW_ACTIVE
);
909 ok( hr
== E_UNEXPECTED
, "got %08lx\n", hr
);
911 freeze_count
= 0xdeadbeef;
912 hr
= ITextDocument_Unfreeze( txtdoc
, &freeze_count
);
913 ok( hr
== S_OK
, "ITextDocument_Unfreeze returned %#lx\n", hr
);
914 ok( freeze_count
== 0, "expected count to be %d, got %ld\n", 0, freeze_count
);
916 hr
= ITextServices_OnTxInPlaceDeactivate( txtserv
);
918 ReleaseDC( host_impl
->window
, hdc
);
919 ITextDocument_Release(txtdoc
);
920 ITextServices_Release(txtserv
);
921 DestroyWindow( host_impl
->window
);
922 ITextHost_Release(host
);
925 DEFINE_GUID(expected_iid_itextservices
, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
926 DEFINE_GUID(expected_iid_itexthost
, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
927 DEFINE_GUID(expected_iid_itexthost2
, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
929 static void test_IIDs(void)
931 ok(IsEqualIID(pIID_ITextServices
, &expected_iid_itextservices
),
932 "unexpected value for IID_ITextServices: %s\n", wine_dbgstr_guid(pIID_ITextServices
));
933 ok(IsEqualIID(pIID_ITextHost
, &expected_iid_itexthost
),
934 "unexpected value for IID_ITextHost: %s\n", wine_dbgstr_guid(pIID_ITextHost
));
935 ok(IsEqualIID(pIID_ITextHost2
, &expected_iid_itexthost2
),
936 "unexpected value for IID_ITextHost2: %s\n", wine_dbgstr_guid(pIID_ITextHost2
));
939 /* Outer IUnknown for COM aggregation tests */
941 IUnknown IUnknown_iface
;
946 static inline struct unk_impl
*impl_from_IUnknown(IUnknown
*iface
)
948 return CONTAINING_RECORD(iface
, struct unk_impl
, IUnknown_iface
);
951 static HRESULT WINAPI
unk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
953 struct unk_impl
*This
= impl_from_IUnknown(iface
);
955 return IUnknown_QueryInterface(This
->inner_unk
, riid
, ppv
);
958 static ULONG WINAPI
unk_AddRef(IUnknown
*iface
)
960 struct unk_impl
*This
= impl_from_IUnknown(iface
);
962 return InterlockedIncrement(&This
->ref
);
965 static ULONG WINAPI
unk_Release(IUnknown
*iface
)
967 struct unk_impl
*This
= impl_from_IUnknown(iface
);
969 return InterlockedDecrement(&This
->ref
);
972 static const IUnknownVtbl unk_vtbl
=
979 static void test_COM(void)
981 struct unk_impl unk_obj
= {{&unk_vtbl
}, 19, NULL
};
982 struct ITextHostTestImpl texthost
= {{&itextHostVtbl
}, 1};
983 ITextServices
*textsrv
;
987 /* COM aggregation */
988 hr
= pCreateTextServices(&unk_obj
.IUnknown_iface
, &texthost
.ITextHost_iface
,
990 ok(hr
== S_OK
, "CreateTextServices failed: %08lx\n", hr
);
991 hr
= IUnknown_QueryInterface(unk_obj
.inner_unk
, pIID_ITextServices
, (void**)&textsrv
);
992 ok(hr
== S_OK
, "QueryInterface for IID_ITextServices failed: %08lx\n", hr
);
993 refcount
= ITextServices_AddRef(textsrv
);
994 ok(refcount
== unk_obj
.ref
, "CreateTextServices just pretends to support COM aggregation\n");
995 refcount
= ITextServices_Release(textsrv
);
996 ok(refcount
== unk_obj
.ref
, "CreateTextServices just pretends to support COM aggregation\n");
997 refcount
= ITextServices_Release(textsrv
);
998 ok(refcount
== 19, "Refcount should be back at 19 but is %lu\n", refcount
);
1000 IUnknown_Release(unk_obj
.inner_unk
);
1003 static ULONG
get_refcount(IUnknown
*iface
)
1005 IUnknown_AddRef(iface
);
1006 return IUnknown_Release(iface
);
1009 static void test_QueryInterface(void)
1011 ITextServices
*txtserv
;
1014 IRichEditOle
*reole
, *txtsrv_reole
;
1015 ITextDocument
*txtdoc
, *txtsrv_txtdoc
;
1016 ITextDocument2Old
*txtdoc2old
, *txtsrv_txtdoc2old
;
1017 IUnknown
*unk
, *unk2
;
1020 if(!init_texthost(&txtserv
, &host
))
1023 refcount
= get_refcount((IUnknown
*)txtserv
);
1024 ok(refcount
== 1, "got wrong ref count: %ld\n", refcount
);
1026 /* IID_IRichEditOle */
1027 hres
= ITextServices_QueryInterface(txtserv
, &IID_IRichEditOle
, (void **)&txtsrv_reole
);
1028 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08lx\n", hres
);
1029 refcount
= get_refcount((IUnknown
*)txtserv
);
1030 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1031 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
1032 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1034 hres
= ITextServices_QueryInterface( txtserv
, &IID_IUnknown
, (void **)&unk
);
1035 ok( hres
== S_OK
, "got 0x%08lx\n", hres
);
1036 hres
= IRichEditOle_QueryInterface( txtsrv_reole
, &IID_IUnknown
, (void **)&unk2
);
1037 ok( hres
== S_OK
, "got 0x%08lx\n", hres
);
1038 ok( unk
== unk2
, "unknowns differ\n" );
1039 IUnknown_Release( unk2
);
1040 IUnknown_Release( unk
);
1042 hres
= IRichEditOle_QueryInterface(txtsrv_reole
, &IID_ITextDocument
, (void **)&txtdoc
);
1043 ok(hres
== S_OK
, "IRichEditOle_QueryInterface: 0x%08lx\n", hres
);
1044 refcount
= get_refcount((IUnknown
*)txtserv
);
1045 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1046 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
1047 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1049 ITextDocument_Release(txtdoc
);
1050 refcount
= get_refcount((IUnknown
*)txtserv
);
1051 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1053 hres
= IRichEditOle_QueryInterface(txtsrv_reole
, &IID_ITextDocument2Old
, (void **)&txtdoc2old
);
1054 ok(hres
== S_OK
, "IRichEditOle_QueryInterface: 0x%08lx\n", hres
);
1055 refcount
= get_refcount((IUnknown
*)txtserv
);
1056 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1057 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
1058 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1060 ITextDocument2Old_Release(txtdoc2old
);
1061 refcount
= get_refcount((IUnknown
*)txtserv
);
1062 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1063 IRichEditOle_Release(txtsrv_reole
);
1064 refcount
= get_refcount((IUnknown
*)txtserv
);
1065 ok(refcount
== 1, "got wrong ref count: %ld\n", refcount
);
1067 /* IID_ITextDocument */
1068 hres
= ITextServices_QueryInterface(txtserv
, &IID_ITextDocument
, (void **)&txtsrv_txtdoc
);
1069 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08lx\n", hres
);
1070 refcount
= get_refcount((IUnknown
*)txtserv
);
1071 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1072 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc
);
1073 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1075 hres
= ITextDocument_QueryInterface(txtsrv_txtdoc
, &IID_IRichEditOle
, (void **)&reole
);
1076 ok(hres
== S_OK
, "ITextDocument_QueryInterface: 0x%08lx\n", hres
);
1077 refcount
= get_refcount((IUnknown
*)txtserv
);
1078 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1079 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc
);
1080 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1082 IRichEditOle_Release(reole
);
1083 refcount
= get_refcount((IUnknown
*)txtserv
);
1084 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1085 ITextDocument_Release(txtsrv_txtdoc
);
1086 refcount
= get_refcount((IUnknown
*)txtserv
);
1087 ok(refcount
== 1, "got wrong ref count: %ld\n", refcount
);
1089 /* ITextDocument2Old */
1090 hres
= ITextServices_QueryInterface(txtserv
, &IID_ITextDocument2Old
, (void **)&txtsrv_txtdoc2old
);
1091 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08lx\n", hres
);
1092 refcount
= get_refcount((IUnknown
*)txtserv
);
1093 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1094 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc2old
);
1095 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1097 hres
= ITextDocument2Old_QueryInterface(txtsrv_txtdoc2old
, &IID_IRichEditOle
, (void **)&reole
);
1098 ok(hres
== S_OK
, "ITextDocument2Old_QueryInterface: 0x%08lx\n", hres
);
1099 refcount
= get_refcount((IUnknown
*)txtserv
);
1100 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1101 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc2old
);
1102 ok(refcount
== 3, "got wrong ref count: %ld\n", refcount
);
1104 IRichEditOle_Release(reole
);
1105 refcount
= get_refcount((IUnknown
*)txtserv
);
1106 ok(refcount
== 2, "got wrong ref count: %ld\n", refcount
);
1107 ITextDocument2Old_Release(txtsrv_txtdoc2old
);
1108 refcount
= get_refcount((IUnknown
*)txtserv
);
1109 ok(refcount
== 1, "got wrong ref count: %ld\n", refcount
);
1111 ITextServices_Release(txtserv
);
1112 ITextHost_Release(host
);
1115 static void test_default_format(void)
1117 ITextServices
*txtserv
;
1122 const CHARFORMATW
*host_cf
;
1123 DWORD expected_effects
;
1125 if (!init_texthost(&txtserv
, &host
))
1128 cf2
.cbSize
= sizeof(CHARFORMAT2W
);
1129 result
= ITextServices_TxSendMessage(txtserv
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&cf2
, &lresult
);
1130 ok(result
== S_OK
, "ITextServices_TxSendMessage failed: 0x%08lx.\n", result
);
1132 ITextHostImpl_TxGetCharFormat(host
, &host_cf
);
1133 ok(!lstrcmpW(host_cf
->szFaceName
, cf2
.szFaceName
), "got wrong font name: %s.\n", wine_dbgstr_w(cf2
.szFaceName
));
1134 ok(cf2
.yHeight
== host_cf
->yHeight
, "got wrong yHeight: %ld, expected %ld.\n", cf2
.yHeight
, host_cf
->yHeight
);
1135 expected_effects
= (cf2
.dwEffects
& ~(CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
));
1136 ok(host_cf
->dwEffects
== expected_effects
, "got wrong dwEffects: %lx, expected %lx.\n", cf2
.dwEffects
, expected_effects
);
1137 ok(cf2
.bPitchAndFamily
== host_cf
->bPitchAndFamily
, "got wrong bPitchAndFamily: %x, expected %x.\n",
1138 cf2
.bPitchAndFamily
, host_cf
->bPitchAndFamily
);
1139 ok(cf2
.bCharSet
== host_cf
->bCharSet
, "got wrong bCharSet: %x, expected %x.\n", cf2
.bCharSet
, host_cf
->bCharSet
);
1141 ITextServices_Release(txtserv
);
1142 ITextHost_Release(host
);
1145 static void test_TxGetScroll(void)
1147 ITextServices
*txtserv
;
1150 LONG min_pos
, max_pos
, pos
, page
;
1152 ITextHostTestImpl
*host_impl
;
1153 RECT client
= {0, 0, 100, 100};
1155 if (!init_texthost(&txtserv
, &host
))
1158 host_impl
= impl_from_ITextHost( host
);
1160 ret
= ITextServices_TxGetHScroll(txtserv
, NULL
, NULL
, NULL
, NULL
, NULL
);
1161 ok(ret
== S_OK
, "ITextServices_TxGetHScroll failed: 0x%08lx.\n", ret
);
1163 ret
= ITextServices_TxGetVScroll(txtserv
, NULL
, NULL
, NULL
, NULL
, NULL
);
1164 ok(ret
== S_OK
, "ITextServices_TxGetVScroll failed: 0x%08lx.\n", ret
);
1166 ret
= ITextServices_TxGetVScroll( txtserv
, &min_pos
, &max_pos
, &pos
, &page
, &enabled
);
1167 ok( ret
== S_OK
, "ITextServices_TxGetHScroll failed: 0x%08lx.\n", ret
);
1168 ok( min_pos
== 0, "got %ld\n", min_pos
);
1169 ok( max_pos
== 0, "got %ld\n", max_pos
);
1170 ok( pos
== 0, "got %ld\n", pos
);
1171 ok( page
== 0, "got %ld\n", page
);
1172 ok( !enabled
, "got %d\n", enabled
);
1174 host_impl
->scrollbars
= WS_VSCROLL
;
1175 host_impl
->props
= TXTBIT_MULTILINE
| TXTBIT_RICHTEXT
| TXTBIT_WORDWRAP
;
1176 ITextServices_OnTxPropertyBitsChange( txtserv
, TXTBIT_SCROLLBARCHANGE
| TXTBIT_MULTILINE
| TXTBIT_RICHTEXT
| TXTBIT_WORDWRAP
, host_impl
->props
);
1178 host_impl
->window
= CreateWindowExA( 0, "static", NULL
, WS_POPUP
| WS_VISIBLE
,
1179 0, 0, 400, 400, 0, 0, 0, NULL
);
1180 host_impl
->client_rect
= client
;
1181 ret
= ITextServices_OnTxInPlaceActivate( txtserv
, &client
);
1182 ok( ret
== S_OK
, "got 0x%08lx.\n", ret
);
1184 ret
= ITextServices_TxGetVScroll( txtserv
, &min_pos
, &max_pos
, &pos
, &page
, &enabled
);
1185 ok( ret
== S_OK
, "ITextServices_TxGetHScroll failed: 0x%08lx.\n", ret
);
1186 ok( min_pos
== 0, "got %ld\n", min_pos
);
1188 ok( max_pos
== 0, "got %ld\n", max_pos
);
1189 ok( pos
== 0, "got %ld\n", pos
);
1190 ok( page
== client
.bottom
, "got %ld\n", page
);
1191 ok( !enabled
, "got %d\n", enabled
);
1193 ret
= ITextServices_TxSetText( txtserv
, lorem
);
1194 ok( ret
== S_OK
, "got 0x%08lx.\n", ret
);
1196 ret
= ITextServices_TxGetVScroll( txtserv
, &min_pos
, &max_pos
, &pos
, &page
, &enabled
);
1197 ok( ret
== S_OK
, "ITextServices_TxGetHScroll failed: 0x%08lx.\n", ret
);
1198 ok( min_pos
== 0, "got %ld\n", min_pos
);
1199 ok( max_pos
> client
.bottom
, "got %ld\n", max_pos
);
1200 ok( pos
== 0, "got %ld\n", pos
);
1201 ok( page
== client
.bottom
, "got %ld\n", page
);
1202 ok( enabled
, "got %d\n", enabled
);
1204 host_impl
->scrollbars
= WS_VSCROLL
| ES_DISABLENOSCROLL
;
1205 ITextServices_OnTxPropertyBitsChange( txtserv
, TXTBIT_SCROLLBARCHANGE
, host_impl
->props
);
1206 ITextServices_TxSetText( txtserv
, L
"short" );
1208 ret
= ITextServices_TxGetVScroll( txtserv
, &min_pos
, &max_pos
, &pos
, &page
, &enabled
);
1209 ok( ret
== S_OK
, "ITextServices_TxGetHScroll failed: 0x%08lx.\n", ret
);
1210 ok( min_pos
== 0, "got %ld\n", min_pos
);
1212 ok( max_pos
== 0, "got %ld\n", max_pos
);
1213 ok( pos
== 0, "got %ld\n", pos
);
1214 ok( page
== client
.bottom
, "got %ld\n", page
);
1215 ok( !enabled
, "got %d\n", enabled
);
1217 DestroyWindow( host_impl
->window
);
1218 ITextServices_Release(txtserv
);
1219 ITextHost_Release(host
);
1222 static void test_notifications( void )
1224 ITextServices
*txtserv
;
1228 RECT client
= { 0, 0, 100, 100 };
1229 ITextHostTestImpl
*host_impl
;
1231 init_texthost( &txtserv
, &host
);
1232 host_impl
= impl_from_ITextHost( host
);
1234 host_impl
->scrollbars
= WS_VSCROLL
;
1235 host_impl
->props
= TXTBIT_MULTILINE
| TXTBIT_RICHTEXT
| TXTBIT_WORDWRAP
;
1236 ITextServices_OnTxPropertyBitsChange( txtserv
, TXTBIT_SCROLLBARCHANGE
| TXTBIT_MULTILINE
| TXTBIT_RICHTEXT
| TXTBIT_WORDWRAP
, host_impl
->props
);
1238 ITextServices_TxSetText( txtserv
, lorem
);
1240 host_impl
->window
= CreateWindowExA( 0, "static", NULL
, WS_POPUP
| WS_VISIBLE
,
1241 0, 0, 400, 400, 0, 0, 0, NULL
);
1242 host_impl
->client_rect
= client
;
1243 hr
= ITextServices_OnTxInPlaceActivate( txtserv
, &client
);
1244 ok( hr
== S_OK
, "got 0x%08lx.\n", hr
);
1246 hr
= ITextServices_TxSendMessage( txtserv
, EM_SETEVENTMASK
, 0, ENM_SCROLL
, &res
);
1247 ok( hr
== S_OK
, "got %08lx\n", hr
);
1249 /* check EN_VSCROLL notification is sent */
1250 en_vscroll_sent
= 0;
1251 hr
= ITextServices_TxSendMessage( txtserv
, WM_VSCROLL
, SB_LINEDOWN
, 0, &res
);
1252 ok( hr
== S_OK
, "got %08lx\n", hr
);
1253 ok( en_vscroll_sent
== 1, "got %d\n", en_vscroll_sent
);
1255 hr
= ITextServices_TxSendMessage( txtserv
, WM_VSCROLL
, SB_BOTTOM
, 0, &res
);
1256 ok( hr
== S_OK
, "got %08lx\n", hr
);
1257 ok( en_vscroll_sent
== 2, "got %d\n", en_vscroll_sent
);
1259 /* but not when the thumb is moved */
1260 hr
= ITextServices_TxSendMessage( txtserv
, WM_VSCROLL
, MAKEWPARAM( SB_THUMBTRACK
, 0 ), 0, &res
);
1261 ok( hr
== S_OK
, "got %08lx\n", hr
);
1262 hr
= ITextServices_TxSendMessage( txtserv
, WM_VSCROLL
, MAKEWPARAM( SB_THUMBPOSITION
, 0 ), 0, &res
);
1263 ok( hr
== S_OK
, "got %08lx\n", hr
);
1264 ok( en_vscroll_sent
== 2, "got %d\n", en_vscroll_sent
);
1266 /* EN_UPDATE is sent by TxDraw() */
1268 hr
= ITextServices_TxDraw( txtserv
, DVASPECT_CONTENT
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
1269 NULL
, NULL
, 0, TXTVIEW_ACTIVE
);
1270 ok( hr
== S_OK
, "got %08lx\n", hr
);
1271 ok( en_update_sent
== 1, "got %d\n", en_update_sent
);
1273 DestroyWindow( host_impl
->window
);
1274 ITextServices_Release( txtserv
);
1275 ITextHost_Release( host
);
1278 static void test_set_selection_message( void )
1280 ITextServices
*txtserv
;
1286 if (!init_texthost(&txtserv
, &host
))
1289 ITextServices_TxSetText(txtserv
, L
"");
1291 if (winetest_debug
> 1) trace("TxSendMessage EM_SETEVENTMASK");
1293 hr
= ITextServices_TxSendMessage( txtserv
, EM_SETEVENTMASK
, 0, ENM_CHANGE
| ENM_SELCHANGE
, &result
);
1294 ok( hr
== S_OK
, "got %08lx\n", hr
);
1296 if (winetest_debug
> 1) trace("TxSendMessage EM_SETSEL 0 20");
1298 CLEAR_COUNTER(ITextHostImpl_TxViewChange
);
1300 en_selchange_sent
= 0;
1302 hr
= ITextServices_TxSendMessage(txtserv
, EM_SETSEL
, 0, 20, &result
);
1303 ok( hr
== S_OK
, "got %08lx\n", hr
);
1305 CHECK_CALLED(ITextHostImpl_TxViewChange
);
1306 ok(en_change_sent
== 0, "got %d\n", en_change_sent
);
1308 ok(en_selchange_sent
== 0, "got %d\n", en_selchange_sent
);
1310 hr
= ITextServices_TxSendMessage(txtserv
, EM_EXGETSEL
, 0, (LPARAM
)&range
, &result
); ok( hr
== S_OK
, "got %08lx\n", hr
); trace("getsel: %lu, %lu\n", range
.cpMin
, range
.cpMax
);
1312 if (winetest_debug
> 1) trace("TxSendMessage EM_SETSELEX 0 20");
1314 CLEAR_COUNTER(ITextHostImpl_TxViewChange
);
1316 en_selchange_sent
= 0;
1320 hr
= ITextServices_TxSendMessage(txtserv
, EM_EXSETSEL
, 0, (LPARAM
)&range
, &result
);
1321 ok( hr
== S_OK
, "got %08lx\n", hr
);
1323 CHECK_CALLED(ITextHostImpl_TxViewChange
);
1324 ok(en_change_sent
== 0, "got %d\n", en_change_sent
);
1325 ok(en_selchange_sent
== 0, "got %d\n", en_selchange_sent
);
1327 if (winetest_debug
> 1) trace("TxSetText");
1329 CLEAR_COUNTER(ITextHostImpl_TxViewChange
);
1331 en_selchange_sent
= 0;
1333 hr
= ITextServices_TxSendMessage(txtserv
, EM_EXGETSEL
, 0, (LPARAM
)&range
, &result
); ok( hr
== S_OK
, "got %08lx\n", hr
); trace("getsel: %lu, %lu\n", range
.cpMin
, range
.cpMax
);
1335 ITextServices_TxSetText(txtserv
, lorem
);
1337 hr
= ITextServices_TxSendMessage(txtserv
, EM_EXGETSEL
, 0, (LPARAM
)&range
, &result
); ok( hr
== S_OK
, "got %08lx\n", hr
); trace("getsel: %lu, %lu\n", range
.cpMin
, range
.cpMax
);
1339 CHECK_CALLED(ITextHostImpl_TxViewChange
);
1340 ok(en_change_sent
== 1, "got %d\n", en_change_sent
);
1342 ok(en_selchange_sent
== 0, "got %d\n", en_selchange_sent
);
1344 if (winetest_debug
> 1) trace("TxSendMessage EM_SETSEL 0 20");
1346 CLEAR_COUNTER(ITextHostImpl_TxViewChange
);
1348 en_selchange_sent
= 0;
1350 hr
= ITextServices_TxSendMessage(txtserv
, EM_SETSEL
, 0, 20, &result
);
1351 ok( hr
== S_OK
, "got %08lx\n", hr
);
1353 CHECK_CALLED(ITextHostImpl_TxViewChange
);
1354 ok(en_change_sent
== 0, "got %d\n", en_change_sent
);
1355 ok(en_selchange_sent
== 1, "got %d\n", en_selchange_sent
);
1357 hr
= ITextServices_TxSendMessage(txtserv
, EM_EXGETSEL
, 0, (LPARAM
)&range
, &result
); ok( hr
== S_OK
, "got %08lx\n", hr
); trace("getsel: %lu, %lu\n", range
.cpMin
, range
.cpMax
);
1359 if (winetest_debug
> 1) trace("TxSendMessage EM_SETSELEX 0 20");
1361 CLEAR_COUNTER(ITextHostImpl_TxViewChange
);
1363 en_selchange_sent
= 0;
1367 hr
= ITextServices_TxSendMessage(txtserv
, EM_EXSETSEL
, 0, (LPARAM
)&range
, &result
);
1368 ok( hr
== S_OK
, "got %08lx\n", hr
);
1370 CHECK_CALLED(ITextHostImpl_TxViewChange
);
1371 ok(en_change_sent
== 0, "got %d\n", en_change_sent
);
1372 ok(en_selchange_sent
== 0, "got %d\n", en_selchange_sent
);
1374 hr
= ITextServices_TxSendMessage(txtserv
, EM_EXGETSEL
, 0, (LPARAM
)&range
, &result
); ok( hr
== S_OK
, "got %08lx\n", hr
); trace("getsel: %lu, %lu\n", range
.cpMin
, range
.cpMax
);
1376 if (winetest_debug
> 1) trace("release interfaces");
1378 ITextServices_Release( txtserv
);
1379 ITextHost_Release( host
);
1382 static void test_scrollcaret( void )
1384 ITextServices
*txtserv
;
1389 if (!init_texthost(&txtserv
, &host
))
1392 hr
= ITextServices_TxSendMessage(txtserv
, EM_SCROLLCARET
, 0, 0, &result
);
1393 ok( hr
== S_OK
, "got %08lx\n", hr
);
1395 ITextServices_Release( txtserv
);
1396 ITextHost_Release( host
);
1399 START_TEST( txtsrv
)
1401 ITextServices
*txtserv
;
1404 setup_thiscall_wrappers();
1406 /* Must explicitly LoadLibrary(). The test has no references to functions in
1407 * RICHED20.DLL, so the linker doesn't actually link to it. */
1408 hmoduleRichEdit
= LoadLibraryA("riched20.dll");
1409 ok(hmoduleRichEdit
!= NULL
, "error: %d\n", (int) GetLastError());
1411 pIID_ITextServices
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextServices");
1412 pIID_ITextHost
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost");
1413 pIID_ITextHost2
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost2");
1414 pCreateTextServices
= (void*)GetProcAddress(hmoduleRichEdit
, "CreateTextServices");
1419 if (init_texthost(&txtserv
, &host
))
1421 ITextServices_Release(txtserv
);
1422 ITextHost_Release(host
);
1426 test_TxGetNaturalSize();
1428 test_QueryInterface();
1429 test_default_format();
1431 test_notifications();
1432 test_set_selection_message();
1435 if (wrapperCodeMem
) VirtualFree(wrapperCodeMem
, 0, MEM_RELEASE
);