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
30 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
35 typedef struct ITextServicesImpl
{
36 IUnknown IUnknown_inner
;
37 ITextServices ITextServices_iface
;
41 CRITICAL_SECTION csTxtSrv
;
42 ME_TextEditor
*editor
;
46 static inline ITextServicesImpl
*impl_from_IUnknown(IUnknown
*iface
)
48 return CONTAINING_RECORD(iface
, ITextServicesImpl
, IUnknown_inner
);
51 static HRESULT WINAPI
ITextServicesImpl_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
53 ITextServicesImpl
*This
= impl_from_IUnknown(iface
);
55 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
57 if (IsEqualIID(riid
, &IID_IUnknown
))
58 *ppv
= &This
->IUnknown_inner
;
59 else if (IsEqualIID(riid
, &IID_ITextServices
))
60 *ppv
= &This
->ITextServices_iface
;
61 else if (IsEqualIID(riid
, &IID_IRichEditOle
) || IsEqualIID(riid
, &IID_ITextDocument
) ||
62 IsEqualIID(riid
, &IID_ITextDocument2Old
)) {
63 if (!This
->editor
->reOle
)
64 if (!CreateIRichEditOle(This
->outer_unk
, This
->editor
, (void **)(&This
->editor
->reOle
)))
66 return IUnknown_QueryInterface(This
->editor
->reOle
, riid
, ppv
);
69 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
73 IUnknown_AddRef((IUnknown
*)*ppv
);
77 static ULONG WINAPI
ITextServicesImpl_AddRef(IUnknown
*iface
)
79 ITextServicesImpl
*This
= impl_from_IUnknown(iface
);
80 LONG ref
= InterlockedIncrement(&This
->ref
);
82 TRACE("(%p) ref=%d\n", This
, ref
);
87 static ULONG WINAPI
ITextServicesImpl_Release(IUnknown
*iface
)
89 ITextServicesImpl
*This
= impl_from_IUnknown(iface
);
90 LONG ref
= InterlockedDecrement(&This
->ref
);
92 TRACE("(%p) ref=%d\n", This
, ref
);
96 ME_DestroyEditor(This
->editor
);
97 This
->csTxtSrv
.DebugInfo
->Spare
[0] = 0;
98 DeleteCriticalSection(&This
->csTxtSrv
);
104 static const IUnknownVtbl textservices_inner_vtbl
=
106 ITextServicesImpl_QueryInterface
,
107 ITextServicesImpl_AddRef
,
108 ITextServicesImpl_Release
111 static inline ITextServicesImpl
*impl_from_ITextServices(ITextServices
*iface
)
113 return CONTAINING_RECORD(iface
, ITextServicesImpl
, ITextServices_iface
);
116 static HRESULT WINAPI
fnTextSrv_QueryInterface(ITextServices
*iface
, REFIID riid
, void **ppv
)
118 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
119 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
122 static ULONG WINAPI
fnTextSrv_AddRef(ITextServices
*iface
)
124 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
125 return IUnknown_AddRef(This
->outer_unk
);
128 static ULONG WINAPI
fnTextSrv_Release(ITextServices
*iface
)
130 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
131 return IUnknown_Release(This
->outer_unk
);
134 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage
,20)
135 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxSendMessage(ITextServices
*iface
, UINT msg
, WPARAM wparam
,
136 LPARAM lparam
, LRESULT
*plresult
)
138 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
142 lresult
= ME_HandleMessage(This
->editor
, msg
, wparam
, lparam
, TRUE
, &hresult
);
143 if (plresult
) *plresult
= lresult
;
147 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw
,52)
148 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxDraw(ITextServices
*iface
, DWORD dwDrawAspect
, LONG lindex
,
149 void *pvAspect
, DVTARGETDEVICE
*ptd
, HDC hdcDraw
, HDC hdcTargetDev
,
150 LPCRECTL lprcBounds
, LPCRECTL lprcWBounds
, LPRECT lprcUpdate
,
151 BOOL (CALLBACK
* pfnContinue
)(DWORD
), DWORD dwContinue
,
154 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
156 FIXME("%p: STUB\n", This
);
160 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll
,24)
161 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetHScroll(ITextServices
*iface
, LONG
*plMin
, LONG
*plMax
, LONG
*plPos
,
162 LONG
*plPage
, BOOL
*pfEnabled
)
164 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
167 *plMin
= This
->editor
->horz_si
.nMin
;
169 *plMax
= This
->editor
->horz_si
.nMax
;
171 *plPos
= This
->editor
->horz_si
.nPos
;
173 *plPage
= This
->editor
->horz_si
.nPage
;
175 *pfEnabled
= (This
->editor
->styleFlags
& WS_HSCROLL
) != 0;
179 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll
,24)
180 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetVScroll(ITextServices
*iface
, LONG
*plMin
, LONG
*plMax
, LONG
*plPos
,
181 LONG
*plPage
, BOOL
*pfEnabled
)
183 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
186 *plMin
= This
->editor
->vert_si
.nMin
;
188 *plMax
= This
->editor
->vert_si
.nMax
;
190 *plPos
= This
->editor
->vert_si
.nPos
;
192 *plPage
= This
->editor
->vert_si
.nPage
;
194 *pfEnabled
= (This
->editor
->styleFlags
& WS_VSCROLL
) != 0;
198 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor
,40)
199 DECLSPEC_HIDDEN HRESULT __thiscall
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 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint
,44)
210 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxQueryHitPoint(ITextServices
*iface
, DWORD dwDrawAspect
, LONG lindex
,
211 void *pvAspect
, DVTARGETDEVICE
*ptd
, HDC hdcDraw
,
212 HDC hicTargetDev
, LPCRECT lprcClient
, INT x
, INT y
,
215 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
217 FIXME("%p: STUB\n", This
);
221 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate
,8)
222 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_OnTxInplaceActivate(ITextServices
*iface
, LPCRECT prcClient
)
224 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
226 FIXME("%p: STUB\n", This
);
230 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate
,4)
231 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_OnTxInplaceDeactivate(ITextServices
*iface
)
233 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
235 FIXME("%p: STUB\n", This
);
239 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate
,4)
240 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_OnTxUIActivate(ITextServices
*iface
)
242 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
244 FIXME("%p: STUB\n", This
);
248 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate
,4)
249 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_OnTxUIDeactivate(ITextServices
*iface
)
251 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
253 FIXME("%p: STUB\n", This
);
257 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText
,8)
258 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetText(ITextServices
*iface
, BSTR
*pbstrText
)
260 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
263 length
= ME_GetTextLength(This
->editor
);
268 bstr
= SysAllocStringByteLen(NULL
, length
* sizeof(WCHAR
));
270 return E_OUTOFMEMORY
;
272 cursor_from_char_ofs( This
->editor
, 0, &start
);
273 ME_GetTextW(This
->editor
, bstr
, length
, &start
, INT_MAX
, FALSE
, FALSE
);
282 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText
,8)
283 DECLSPEC_HIDDEN HRESULT __thiscall
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 set_selection_cursors(This
->editor
, 0, 0);
293 This
->editor
->nModifyStep
= 0;
295 ME_EmptyUndoStack(This
->editor
);
296 ME_UpdateRepaint(This
->editor
, FALSE
);
301 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurTargetX
,8)
302 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetCurTargetX(ITextServices
*iface
, LONG
*x
)
304 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
306 FIXME("%p: STUB\n", This
);
310 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos
,8)
311 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetBaseLinePos(ITextServices
*iface
, LONG
*x
)
313 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
315 FIXME("%p: STUB\n", This
);
319 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize
,36)
320 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetNaturalSize(ITextServices
*iface
, DWORD dwAspect
, HDC hdcDraw
,
321 HDC hicTargetDev
, DVTARGETDEVICE
*ptd
, DWORD dwMode
,
322 const SIZEL
*psizelExtent
, LONG
*pwidth
, LONG
*pheight
)
324 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
326 FIXME("%p: STUB\n", This
);
330 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget
,8)
331 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetDropTarget(ITextServices
*iface
, IDropTarget
**ppDropTarget
)
333 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
335 FIXME("%p: STUB\n", This
);
339 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange
,12)
340 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_OnTxPropertyBitsChange(ITextServices
*iface
, DWORD dwMask
, DWORD dwBits
)
342 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
344 FIXME("%p: STUB\n", This
);
348 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize
,12)
349 DECLSPEC_HIDDEN HRESULT __thiscall
fnTextSrv_TxGetCachedSize(ITextServices
*iface
, DWORD
*pdwWidth
, DWORD
*pdwHeight
)
351 ITextServicesImpl
*This
= impl_from_ITextServices(iface
);
353 FIXME("%p: STUB\n", This
);
358 static const ITextServicesVtbl textservices_vtbl
=
360 fnTextSrv_QueryInterface
,
363 THISCALL(fnTextSrv_TxSendMessage
),
364 THISCALL(fnTextSrv_TxDraw
),
365 THISCALL(fnTextSrv_TxGetHScroll
),
366 THISCALL(fnTextSrv_TxGetVScroll
),
367 THISCALL(fnTextSrv_OnTxSetCursor
),
368 THISCALL(fnTextSrv_TxQueryHitPoint
),
369 THISCALL(fnTextSrv_OnTxInplaceActivate
),
370 THISCALL(fnTextSrv_OnTxInplaceDeactivate
),
371 THISCALL(fnTextSrv_OnTxUIActivate
),
372 THISCALL(fnTextSrv_OnTxUIDeactivate
),
373 THISCALL(fnTextSrv_TxGetText
),
374 THISCALL(fnTextSrv_TxSetText
),
375 THISCALL(fnTextSrv_TxGetCurTargetX
),
376 THISCALL(fnTextSrv_TxGetBaseLinePos
),
377 THISCALL(fnTextSrv_TxGetNaturalSize
),
378 THISCALL(fnTextSrv_TxGetDropTarget
),
379 THISCALL(fnTextSrv_OnTxPropertyBitsChange
),
380 THISCALL(fnTextSrv_TxGetCachedSize
)
383 /******************************************************************
384 * CreateTextServices (RICHED20.4)
386 HRESULT WINAPI
CreateTextServices(IUnknown
*pUnkOuter
, ITextHost
*pITextHost
, IUnknown
**ppUnk
)
388 ITextServicesImpl
*ITextImpl
;
390 TRACE("%p %p --> %p\n", pUnkOuter
, pITextHost
, ppUnk
);
391 if (pITextHost
== NULL
)
394 ITextImpl
= CoTaskMemAlloc(sizeof(*ITextImpl
));
395 if (ITextImpl
== NULL
)
396 return E_OUTOFMEMORY
;
397 InitializeCriticalSection(&ITextImpl
->csTxtSrv
);
398 ITextImpl
->csTxtSrv
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ITextServicesImpl.csTxtSrv");
400 ITextHost_AddRef(pITextHost
);
401 ITextImpl
->pMyHost
= pITextHost
;
402 ITextImpl
->IUnknown_inner
.lpVtbl
= &textservices_inner_vtbl
;
403 ITextImpl
->ITextServices_iface
.lpVtbl
= &textservices_vtbl
;
404 ITextImpl
->editor
= ME_MakeEditor(pITextHost
, FALSE
);
407 ITextImpl
->outer_unk
= pUnkOuter
;
409 ITextImpl
->outer_unk
= &ITextImpl
->IUnknown_inner
;
411 *ppUnk
= &ITextImpl
->IUnknown_inner
;