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
22 #include "wine/port.h"
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
34 #include "wine/debug.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, \
46 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
49 #define THISCALL(func) func
50 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
54 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
56 typedef struct ITextServicesImpl
{
57 IUnknown IUnknown_inner
;
58 ITextServices ITextServices_iface
;
62 CRITICAL_SECTION csTxtSrv
;
63 ME_TextEditor
*editor
;
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
;
84 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
88 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
111 ITextHost_Release(This
->pMyHost
);
112 This
->csTxtSrv
.DebugInfo
->Spare
[0] = 0;
113 DeleteCriticalSection(&This
->csTxtSrv
);
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
);
156 lresult
= ME_HandleMessage(This
->editor
, msg
, wparam
, lparam
, TRUE
, &hresult
);
157 if (plresult
) *plresult
= lresult
;
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
,
167 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
169 FIXME("%p: STUB\n", This
);
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;
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;
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
);
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
,
214 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
216 FIXME("%p: STUB\n", This
);
220 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxInplaceActivate(ITextServices
*iface
, LPCRECT prcClient
)
222 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
224 FIXME("%p: STUB\n", This
);
228 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxInplaceDeactivate(ITextServices
*iface
)
230 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
232 FIXME("%p: STUB\n", This
);
236 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxUIActivate(ITextServices
*iface
)
238 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
240 FIXME("%p: STUB\n", This
);
244 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxUIDeactivate(ITextServices
*iface
)
246 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
248 FIXME("%p: STUB\n", This
);
252 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetText(ITextServices
*iface
, BSTR
*pbstrText
)
254 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
257 length
= ME_GetTextLength(This
->editor
);
262 bstr
= SysAllocStringByteLen(NULL
, length
* sizeof(WCHAR
));
264 return E_OUTOFMEMORY
;
266 ME_CursorFromCharOfs(This
->editor
, 0, &start
);
267 ME_GetTextW(This
->editor
, bstr
, length
, &start
, INT_MAX
, FALSE
);
276 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxSetText(ITextServices
*iface
, LPCWSTR pszText
)
278 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
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;
289 ME_EmptyUndoStack(This
->editor
);
290 ME_UpdateRepaint(This
->editor
, FALSE
);
295 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetCurTargetX(ITextServices
*iface
, LONG
*x
)
297 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
299 FIXME("%p: STUB\n", This
);
303 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetBaseLinePos(ITextServices
*iface
, LONG
*x
)
305 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
307 FIXME("%p: STUB\n", This
);
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
);
321 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetDropTarget(ITextServices
*iface
, IDropTarget
**ppDropTarget
)
323 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
325 FIXME("%p: STUB\n", This
);
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
);
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
);
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_TxGetCurTargetX
,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
,
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_TxGetCurTargetX
),
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
;
396 TRACE("%p %p --> %p\n", pUnkOuter
, pITextHost
, ppUnk
);
397 if (pITextHost
== NULL
)
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");
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
);
420 ITextImpl
->outer_unk
= pUnkOuter
;
422 ITextImpl
->outer_unk
= &ITextImpl
->IUnknown_inner
;
424 *ppUnk
= &ITextImpl
->IUnknown_inner
;