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 const ITextServicesVtbl
*lpVtbl
;
60 CRITICAL_SECTION csTxtSrv
;
61 ME_TextEditor
*editor
;
65 static const ITextServicesVtbl textservices_Vtbl
;
67 /******************************************************************
68 * CreateTextServices (RICHED20.4)
70 HRESULT WINAPI
CreateTextServices(IUnknown
* pUnkOuter
,
71 ITextHost
* pITextHost
,
74 ITextServicesImpl
*ITextImpl
;
76 TRACE("%p %p --> %p\n", pUnkOuter
, pITextHost
, ppUnk
);
77 if (pITextHost
== NULL
)
80 ITextImpl
= CoTaskMemAlloc(sizeof(*ITextImpl
));
81 if (ITextImpl
== NULL
)
83 InitializeCriticalSection(&ITextImpl
->csTxtSrv
);
84 ITextImpl
->csTxtSrv
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ITextServicesImpl.csTxtSrv");
86 ITextHost_AddRef(pITextHost
);
87 ITextImpl
->pMyHost
= pITextHost
;
88 ITextImpl
->lpVtbl
= &textservices_Vtbl
;
89 ITextImpl
->editor
= ME_MakeEditor(pITextHost
, FALSE
);
90 ITextImpl
->editor
->exStyleFlags
= 0;
91 ITextImpl
->editor
->rcFormat
.left
= 0;
92 ITextImpl
->editor
->rcFormat
.top
= 0;
93 ITextImpl
->editor
->rcFormat
.right
= 0;
94 ITextImpl
->editor
->rcFormat
.bottom
= 0;
96 ME_HandleMessage(ITextImpl
->editor
, WM_CREATE
, 0, 0, TRUE
, &hres
);
100 FIXME("Support aggregation\n");
101 return CLASS_E_NOAGGREGATION
;
104 *ppUnk
= (IUnknown
*)ITextImpl
;
108 #define ICOM_THIS_MULTI(impl,field,iface) \
109 impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
111 static HRESULT WINAPI
fnTextSrv_QueryInterface(ITextServices
* iface
,
115 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
116 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, debugstr_guid(riid
), ppv
);
118 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_ITextServices
))
123 IUnknown_AddRef((IUnknown
*)(*ppv
));
124 TRACE ("-- Interface = %p\n", *ppv
);
127 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
128 return E_NOINTERFACE
;
131 static ULONG WINAPI
fnTextSrv_AddRef(ITextServices
*iface
)
133 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
134 DWORD ref
= InterlockedIncrement(&This
->ref
);
136 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, ref
- 1);
140 static ULONG WINAPI
fnTextSrv_Release(ITextServices
*iface
)
142 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
143 DWORD ref
= InterlockedDecrement(&This
->ref
);
145 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, ref
+ 1);
149 ITextHost_Release(This
->pMyHost
);
150 This
->csTxtSrv
.DebugInfo
->Spare
[0] = 0;
151 DeleteCriticalSection(&This
->csTxtSrv
);
157 HRESULT WINAPI
fnTextSrv_TxSendMessage(ITextServices
*iface
,
163 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
167 lresult
= ME_HandleMessage(This
->editor
, msg
, wparam
, lparam
, TRUE
, &hresult
);
168 if (plresult
) *plresult
= lresult
;
172 HRESULT WINAPI
fnTextSrv_TxDraw(ITextServices
*iface
,
180 LPCRECTL lprcWBounds
,
182 BOOL (CALLBACK
* pfnContinue
)(DWORD
),
186 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
188 FIXME("%p: STUB\n", This
);
192 HRESULT WINAPI
fnTextSrv_TxGetHScroll(ITextServices
*iface
,
199 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
201 *plMin
= This
->editor
->horz_si
.nMin
;
202 *plMax
= This
->editor
->horz_si
.nMax
;
203 *plPos
= This
->editor
->horz_si
.nPos
;
204 *plPage
= This
->editor
->horz_si
.nPage
;
205 *pfEnabled
= (This
->editor
->styleFlags
& WS_HSCROLL
) != 0;
209 HRESULT WINAPI
fnTextSrv_TxGetVScroll(ITextServices
*iface
,
216 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
218 *plMin
= This
->editor
->vert_si
.nMin
;
219 *plMax
= This
->editor
->vert_si
.nMax
;
220 *plPos
= This
->editor
->vert_si
.nPos
;
221 *plPage
= This
->editor
->vert_si
.nPage
;
222 *pfEnabled
= (This
->editor
->styleFlags
& WS_VSCROLL
) != 0;
226 HRESULT WINAPI
fnTextSrv_OnTxSetCursor(ITextServices
*iface
,
236 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
238 FIXME("%p: STUB\n", This
);
242 HRESULT WINAPI
fnTextSrv_TxQueryHitPoint(ITextServices
*iface
,
253 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
255 FIXME("%p: STUB\n", This
);
259 HRESULT WINAPI
fnTextSrv_OnTxInplaceActivate(ITextServices
*iface
,
262 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
264 FIXME("%p: STUB\n", This
);
268 HRESULT WINAPI
fnTextSrv_OnTxInplaceDeactivate(ITextServices
*iface
)
270 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
272 FIXME("%p: STUB\n", This
);
276 HRESULT WINAPI
fnTextSrv_OnTxUIActivate(ITextServices
*iface
)
278 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
280 FIXME("%p: STUB\n", This
);
284 HRESULT WINAPI
fnTextSrv_OnTxUIDeactivate(ITextServices
*iface
)
286 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
288 FIXME("%p: STUB\n", This
);
292 HRESULT WINAPI
fnTextSrv_TxGetText(ITextServices
*iface
,
295 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
298 length
= ME_GetTextLength(This
->editor
);
303 bstr
= SysAllocStringByteLen(NULL
, length
* sizeof(WCHAR
));
305 return E_OUTOFMEMORY
;
307 ME_CursorFromCharOfs(This
->editor
, 0, &start
);
308 ME_GetTextW(This
->editor
, bstr
, length
, &start
, INT_MAX
, FALSE
);
317 HRESULT WINAPI
fnTextSrv_TxSetText(ITextServices
*iface
,
320 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
323 ME_SetCursorToStart(This
->editor
, &cursor
);
324 ME_InternalDeleteText(This
->editor
, &cursor
,
325 ME_GetTextLength(This
->editor
), FALSE
);
326 ME_InsertTextFromCursor(This
->editor
, 0, pszText
, -1,
327 This
->editor
->pBuffer
->pDefaultStyle
);
328 ME_SetSelection(This
->editor
, 0, 0);
329 This
->editor
->nModifyStep
= 0;
331 ME_EmptyUndoStack(This
->editor
);
332 ME_UpdateRepaint(This
->editor
, FALSE
);
337 HRESULT WINAPI
fnTextSrv_TxGetCurrentTargetX(ITextServices
*iface
,
340 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
342 FIXME("%p: STUB\n", This
);
346 HRESULT WINAPI
fnTextSrv_TxGetBaseLinePos(ITextServices
*iface
,
349 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
351 FIXME("%p: STUB\n", This
);
355 HRESULT WINAPI
fnTextSrv_TxGetNaturalSize(ITextServices
*iface
,
361 const SIZEL
* psizelExtent
,
365 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
367 FIXME("%p: STUB\n", This
);
371 HRESULT WINAPI
fnTextSrv_TxGetDropTarget(ITextServices
*iface
,
372 IDropTarget
** ppDropTarget
)
374 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
376 FIXME("%p: STUB\n", This
);
380 HRESULT WINAPI
fnTextSrv_OnTxPropertyBitsChange(ITextServices
*iface
,
384 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
386 FIXME("%p: STUB\n", This
);
390 HRESULT WINAPI
fnTextSrv_TxGetCachedSize(ITextServices
*iface
,
394 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
396 FIXME("%p: STUB\n", This
);
400 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage
,20)
401 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw
,52)
402 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll
,24)
403 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll
,24)
404 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor
,40)
405 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint
,44)
406 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate
,8)
407 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate
,4)
408 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate
,4)
409 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate
,4)
410 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText
,8)
411 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText
,8)
412 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX
,8)
413 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos
,8)
414 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize
,36)
415 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget
,8)
416 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange
,12)
417 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize
,12)
419 static const ITextServicesVtbl textservices_Vtbl
=
421 fnTextSrv_QueryInterface
,
424 THISCALL(fnTextSrv_TxSendMessage
),
425 THISCALL(fnTextSrv_TxDraw
),
426 THISCALL(fnTextSrv_TxGetHScroll
),
427 THISCALL(fnTextSrv_TxGetVScroll
),
428 THISCALL(fnTextSrv_OnTxSetCursor
),
429 THISCALL(fnTextSrv_TxQueryHitPoint
),
430 THISCALL(fnTextSrv_OnTxInplaceActivate
),
431 THISCALL(fnTextSrv_OnTxInplaceDeactivate
),
432 THISCALL(fnTextSrv_OnTxUIActivate
),
433 THISCALL(fnTextSrv_OnTxUIDeactivate
),
434 THISCALL(fnTextSrv_TxGetText
),
435 THISCALL(fnTextSrv_TxSetText
),
436 THISCALL(fnTextSrv_TxGetCurrentTargetX
),
437 THISCALL(fnTextSrv_TxGetBaseLinePos
),
438 THISCALL(fnTextSrv_TxGetNaturalSize
),
439 THISCALL(fnTextSrv_TxGetDropTarget
),
440 THISCALL(fnTextSrv_OnTxPropertyBitsChange
),
441 THISCALL(fnTextSrv_TxGetCachedSize
)