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"
33 #include "wine/debug.h"
36 #ifdef __i386__ /* thiscall functions are i386-specific */
38 #define THISCALL(func) __thiscall_ ## func
39 #define DEFINE_THISCALL_WRAPPER(func,args) \
40 extern typeof(func) THISCALL(func); \
41 __ASM_STDCALL_FUNC(__thiscall_ ## func, args, \
45 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
48 #define THISCALL(func) func
49 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
53 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
55 typedef struct ITextServicesImpl
{
56 IUnknown IUnknown_inner
;
57 ITextServices ITextServices_iface
;
61 CRITICAL_SECTION csTxtSrv
;
62 ME_TextEditor
*editor
;
66 static inline ITextServicesImpl
*impl_from_IUnknown(IUnknown
*iface
)
68 return CONTAINING_RECORD(iface
, ITextServicesImpl
, IUnknown_inner
);
71 static HRESULT WINAPI
ITextServicesImpl_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
73 ITextServicesImpl
*This
= impl_from_IUnknown(iface
);
75 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
77 if (IsEqualIID(riid
, &IID_IUnknown
))
78 *ppv
= &This
->IUnknown_inner
;
79 else if (IsEqualIID(riid
, &IID_ITextServices
))
80 *ppv
= &This
->ITextServices_iface
;
81 else if (IsEqualIID(riid
, &IID_IRichEditOle
) || IsEqualIID(riid
, &IID_ITextDocument
)) {
82 if (!This
->editor
->reOle
)
83 if (!CreateIRichEditOle(This
->outer_unk
, This
->editor
, (void **)(&This
->editor
->reOle
)))
85 if (IsEqualIID(riid
, &IID_ITextDocument
))
86 ME_GetITextDocumentInterface(This
->editor
->reOle
, ppv
);
88 *ppv
= This
->editor
->reOle
;
91 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
95 IUnknown_AddRef((IUnknown
*)*ppv
);
99 static ULONG WINAPI
ITextServicesImpl_AddRef(IUnknown
*iface
)
101 ITextServicesImpl
*This
= impl_from_IUnknown(iface
);
102 LONG ref
= InterlockedIncrement(&This
->ref
);
104 TRACE("(%p) ref=%d\n", This
, ref
);
109 static ULONG WINAPI
ITextServicesImpl_Release(IUnknown
*iface
)
111 ITextServicesImpl
*This
= impl_from_IUnknown(iface
);
112 LONG ref
= InterlockedDecrement(&This
->ref
);
114 TRACE("(%p) ref=%d\n", This
, ref
);
118 ME_DestroyEditor(This
->editor
);
119 This
->csTxtSrv
.DebugInfo
->Spare
[0] = 0;
120 DeleteCriticalSection(&This
->csTxtSrv
);
126 static const IUnknownVtbl textservices_inner_vtbl
=
128 ITextServicesImpl_QueryInterface
,
129 ITextServicesImpl_AddRef
,
130 ITextServicesImpl_Release
133 static inline ITextServicesImpl
*impl_from_ITextServices(ITextServices
*iface
)
135 return CONTAINING_RECORD(iface
, ITextServicesImpl
, ITextServices_iface
);
138 static HRESULT WINAPI
fnTextSrv_QueryInterface(ITextServices
*iface
, REFIID riid
, void **ppv
)
140 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
141 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
144 static ULONG WINAPI
fnTextSrv_AddRef(ITextServices
*iface
)
146 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
147 return IUnknown_AddRef(This
->outer_unk
);
150 static ULONG WINAPI
fnTextSrv_Release(ITextServices
*iface
)
152 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
153 return IUnknown_Release(This
->outer_unk
);
156 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxSendMessage(ITextServices
*iface
, UINT msg
, WPARAM wparam
,
157 LPARAM lparam
, LRESULT
*plresult
)
159 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
163 lresult
= ME_HandleMessage(This
->editor
, msg
, wparam
, lparam
, TRUE
, &hresult
);
164 if (plresult
) *plresult
= lresult
;
168 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxDraw(ITextServices
*iface
, DWORD dwDrawAspect
, LONG lindex
,
169 void *pvAspect
, DVTARGETDEVICE
*ptd
, HDC hdcDraw
, HDC hdcTargetDev
,
170 LPCRECTL lprcBounds
, LPCRECTL lprcWBounds
, LPRECT lprcUpdate
,
171 BOOL (CALLBACK
* pfnContinue
)(DWORD
), DWORD dwContinue
,
174 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
176 FIXME("%p: STUB\n", This
);
180 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetHScroll(ITextServices
*iface
, LONG
*plMin
, LONG
*plMax
, LONG
*plPos
,
181 LONG
*plPage
, BOOL
*pfEnabled
)
183 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
185 *plMin
= This
->editor
->horz_si
.nMin
;
186 *plMax
= This
->editor
->horz_si
.nMax
;
187 *plPos
= This
->editor
->horz_si
.nPos
;
188 *plPage
= This
->editor
->horz_si
.nPage
;
189 *pfEnabled
= (This
->editor
->styleFlags
& WS_HSCROLL
) != 0;
193 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetVScroll(ITextServices
*iface
, LONG
*plMin
, LONG
*plMax
, LONG
*plPos
,
194 LONG
*plPage
, BOOL
*pfEnabled
)
196 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
198 *plMin
= This
->editor
->vert_si
.nMin
;
199 *plMax
= This
->editor
->vert_si
.nMax
;
200 *plPos
= This
->editor
->vert_si
.nPos
;
201 *plPage
= This
->editor
->vert_si
.nPage
;
202 *pfEnabled
= (This
->editor
->styleFlags
& WS_VSCROLL
) != 0;
206 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxSetCursor(ITextServices
*iface
, DWORD dwDrawAspect
, LONG lindex
,
207 void *pvAspect
, DVTARGETDEVICE
*ptd
, HDC hdcDraw
,
208 HDC hicTargetDev
, LPCRECT lprcClient
, INT x
, INT y
)
210 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
212 FIXME("%p: STUB\n", This
);
216 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxQueryHitPoint(ITextServices
*iface
, DWORD dwDrawAspect
, LONG lindex
,
217 void *pvAspect
, DVTARGETDEVICE
*ptd
, HDC hdcDraw
,
218 HDC hicTargetDev
, LPCRECT lprcClient
, INT x
, INT y
,
221 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
223 FIXME("%p: STUB\n", This
);
227 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxInplaceActivate(ITextServices
*iface
, LPCRECT prcClient
)
229 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
231 FIXME("%p: STUB\n", This
);
235 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxInplaceDeactivate(ITextServices
*iface
)
237 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
239 FIXME("%p: STUB\n", This
);
243 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxUIActivate(ITextServices
*iface
)
245 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
247 FIXME("%p: STUB\n", This
);
251 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxUIDeactivate(ITextServices
*iface
)
253 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
255 FIXME("%p: STUB\n", This
);
259 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetText(ITextServices
*iface
, BSTR
*pbstrText
)
261 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
264 length
= ME_GetTextLength(This
->editor
);
269 bstr
= SysAllocStringByteLen(NULL
, length
* sizeof(WCHAR
));
271 return E_OUTOFMEMORY
;
273 ME_CursorFromCharOfs(This
->editor
, 0, &start
);
274 ME_GetTextW(This
->editor
, bstr
, length
, &start
, INT_MAX
, FALSE
, FALSE
);
283 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxSetText(ITextServices
*iface
, LPCWSTR pszText
)
285 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
288 ME_SetCursorToStart(This
->editor
, &cursor
);
289 ME_InternalDeleteText(This
->editor
, &cursor
, ME_GetTextLength(This
->editor
), FALSE
);
291 ME_InsertTextFromCursor(This
->editor
, 0, pszText
, -1, This
->editor
->pBuffer
->pDefaultStyle
);
292 ME_SetSelection(This
->editor
, 0, 0);
293 This
->editor
->nModifyStep
= 0;
295 ME_EmptyUndoStack(This
->editor
);
296 ME_UpdateRepaint(This
->editor
, FALSE
);
301 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetCurTargetX(ITextServices
*iface
, LONG
*x
)
303 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
305 FIXME("%p: STUB\n", This
);
309 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetBaseLinePos(ITextServices
*iface
, LONG
*x
)
311 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
313 FIXME("%p: STUB\n", This
);
317 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetNaturalSize(ITextServices
*iface
, DWORD dwAspect
, HDC hdcDraw
,
318 HDC hicTargetDev
, DVTARGETDEVICE
*ptd
, DWORD dwMode
,
319 const SIZEL
*psizelExtent
, LONG
*pwidth
, LONG
*pheight
)
321 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
323 FIXME("%p: STUB\n", This
);
327 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetDropTarget(ITextServices
*iface
, IDropTarget
**ppDropTarget
)
329 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
331 FIXME("%p: STUB\n", This
);
335 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_OnTxPropertyBitsChange(ITextServices
*iface
, DWORD dwMask
, DWORD dwBits
)
337 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
339 FIXME("%p: STUB\n", This
);
343 DECLSPEC_HIDDEN HRESULT WINAPI
fnTextSrv_TxGetCachedSize(ITextServices
*iface
, DWORD
*pdwWidth
, DWORD
*pdwHeight
)
345 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
347 FIXME("%p: STUB\n", This
);
351 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage
,20)
352 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw
,52)
353 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll
,24)
354 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll
,24)
355 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor
,40)
356 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint
,44)
357 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate
,8)
358 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate
,4)
359 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate
,4)
360 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate
,4)
361 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText
,8)
362 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText
,8)
363 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurTargetX
,8)
364 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos
,8)
365 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize
,36)
366 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget
,8)
367 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange
,12)
368 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize
,12)
370 static const ITextServicesVtbl textservices_vtbl
=
372 fnTextSrv_QueryInterface
,
375 THISCALL(fnTextSrv_TxSendMessage
),
376 THISCALL(fnTextSrv_TxDraw
),
377 THISCALL(fnTextSrv_TxGetHScroll
),
378 THISCALL(fnTextSrv_TxGetVScroll
),
379 THISCALL(fnTextSrv_OnTxSetCursor
),
380 THISCALL(fnTextSrv_TxQueryHitPoint
),
381 THISCALL(fnTextSrv_OnTxInplaceActivate
),
382 THISCALL(fnTextSrv_OnTxInplaceDeactivate
),
383 THISCALL(fnTextSrv_OnTxUIActivate
),
384 THISCALL(fnTextSrv_OnTxUIDeactivate
),
385 THISCALL(fnTextSrv_TxGetText
),
386 THISCALL(fnTextSrv_TxSetText
),
387 THISCALL(fnTextSrv_TxGetCurTargetX
),
388 THISCALL(fnTextSrv_TxGetBaseLinePos
),
389 THISCALL(fnTextSrv_TxGetNaturalSize
),
390 THISCALL(fnTextSrv_TxGetDropTarget
),
391 THISCALL(fnTextSrv_OnTxPropertyBitsChange
),
392 THISCALL(fnTextSrv_TxGetCachedSize
)
395 /******************************************************************
396 * CreateTextServices (RICHED20.4)
398 HRESULT WINAPI
CreateTextServices(IUnknown
*pUnkOuter
, ITextHost
*pITextHost
, IUnknown
**ppUnk
)
400 ITextServicesImpl
*ITextImpl
;
402 TRACE("%p %p --> %p\n", pUnkOuter
, pITextHost
, ppUnk
);
403 if (pITextHost
== NULL
)
406 ITextImpl
= CoTaskMemAlloc(sizeof(*ITextImpl
));
407 if (ITextImpl
== NULL
)
408 return E_OUTOFMEMORY
;
409 InitializeCriticalSection(&ITextImpl
->csTxtSrv
);
410 ITextImpl
->csTxtSrv
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ITextServicesImpl.csTxtSrv");
412 ITextHost_AddRef(pITextHost
);
413 ITextImpl
->pMyHost
= pITextHost
;
414 ITextImpl
->IUnknown_inner
.lpVtbl
= &textservices_inner_vtbl
;
415 ITextImpl
->ITextServices_iface
.lpVtbl
= &textservices_vtbl
;
416 ITextImpl
->editor
= ME_MakeEditor(pITextHost
, FALSE
);
419 ITextImpl
->outer_unk
= pUnkOuter
;
421 ITextImpl
->outer_unk
= &ITextImpl
->IUnknown_inner
;
423 *ppUnk
= &ITextImpl
->IUnknown_inner
;