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
= (RECT
){0,0,0,0};
92 ME_HandleMessage(ITextImpl
->editor
, WM_CREATE
, 0, 0, TRUE
, &hres
);
96 FIXME("Support aggregation\n");
97 return CLASS_E_NOAGGREGATION
;
100 *ppUnk
= (IUnknown
*)ITextImpl
;
104 #define ICOM_THIS_MULTI(impl,field,iface) \
105 impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
107 static HRESULT WINAPI
fnTextSrv_QueryInterface(ITextServices
* iface
,
111 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
112 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, debugstr_guid(riid
), ppv
);
114 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_ITextServices
))
119 IUnknown_AddRef((IUnknown
*)(*ppv
));
120 TRACE ("-- Interface = %p\n", *ppv
);
123 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
124 return E_NOINTERFACE
;
127 static ULONG WINAPI
fnTextSrv_AddRef(ITextServices
*iface
)
129 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
130 DWORD ref
= InterlockedIncrement(&This
->ref
);
132 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, ref
- 1);
136 static ULONG WINAPI
fnTextSrv_Release(ITextServices
*iface
)
138 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
139 DWORD ref
= InterlockedDecrement(&This
->ref
);
141 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, ref
+ 1);
145 ITextHost_Release(This
->pMyHost
);
146 This
->csTxtSrv
.DebugInfo
->Spare
[0] = 0;
147 DeleteCriticalSection(&This
->csTxtSrv
);
153 HRESULT WINAPI
fnTextSrv_TxSendMessage(ITextServices
*iface
,
159 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
163 lresult
= ME_HandleMessage(This
->editor
, msg
, wparam
, lparam
, TRUE
, &hresult
);
164 if (plresult
) *plresult
= lresult
;
168 HRESULT WINAPI
fnTextSrv_TxDraw(ITextServices
*iface
,
176 LPCRECTL lprcWBounds
,
178 BOOL (CALLBACK
* pfnContinue
)(DWORD
),
182 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
184 FIXME("%p: STUB\n", This
);
188 HRESULT WINAPI
fnTextSrv_TxGetHScroll(ITextServices
*iface
,
195 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
197 *plMin
= This
->editor
->horz_si
.nMin
;
198 *plMax
= This
->editor
->horz_si
.nMax
;
199 *plPos
= This
->editor
->horz_si
.nPos
;
200 *plPage
= This
->editor
->horz_si
.nPage
;
201 *pfEnabled
= (This
->editor
->styleFlags
& WS_HSCROLL
) != 0;
205 HRESULT WINAPI
fnTextSrv_TxGetVScroll(ITextServices
*iface
,
212 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
214 *plMin
= This
->editor
->vert_si
.nMin
;
215 *plMax
= This
->editor
->vert_si
.nMax
;
216 *plPos
= This
->editor
->vert_si
.nPos
;
217 *plPage
= This
->editor
->vert_si
.nPage
;
218 *pfEnabled
= (This
->editor
->styleFlags
& WS_VSCROLL
) != 0;
222 HRESULT WINAPI
fnTextSrv_OnTxSetCursor(ITextServices
*iface
,
232 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
234 FIXME("%p: STUB\n", This
);
238 HRESULT WINAPI
fnTextSrv_TxQueryHitPoint(ITextServices
*iface
,
249 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
251 FIXME("%p: STUB\n", This
);
255 HRESULT WINAPI
fnTextSrv_OnTxInplaceActivate(ITextServices
*iface
,
258 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
260 FIXME("%p: STUB\n", This
);
264 HRESULT WINAPI
fnTextSrv_OnTxInplaceDeactivate(ITextServices
*iface
)
266 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
268 FIXME("%p: STUB\n", This
);
272 HRESULT WINAPI
fnTextSrv_OnTxUIActivate(ITextServices
*iface
)
274 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
276 FIXME("%p: STUB\n", This
);
280 HRESULT WINAPI
fnTextSrv_OnTxUIDeactivate(ITextServices
*iface
)
282 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
284 FIXME("%p: STUB\n", This
);
288 HRESULT WINAPI
fnTextSrv_TxGetText(ITextServices
*iface
,
291 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
294 length
= ME_GetTextLength(This
->editor
);
299 bstr
= SysAllocStringByteLen(NULL
, length
* sizeof(WCHAR
));
301 return E_OUTOFMEMORY
;
303 ME_CursorFromCharOfs(This
->editor
, 0, &start
);
304 ME_GetTextW(This
->editor
, bstr
, length
, &start
, INT_MAX
, FALSE
);
313 HRESULT WINAPI
fnTextSrv_TxSetText(ITextServices
*iface
,
316 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
319 ME_SetCursorToStart(This
->editor
, &cursor
);
320 ME_InternalDeleteText(This
->editor
, &cursor
,
321 ME_GetTextLength(This
->editor
), FALSE
);
322 ME_InsertTextFromCursor(This
->editor
, 0, pszText
, -1,
323 This
->editor
->pBuffer
->pDefaultStyle
);
324 ME_SetSelection(This
->editor
, 0, 0);
325 This
->editor
->nModifyStep
= 0;
327 ME_EmptyUndoStack(This
->editor
);
328 ME_UpdateRepaint(This
->editor
);
333 HRESULT WINAPI
fnTextSrv_TxGetCurrentTargetX(ITextServices
*iface
,
336 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
338 FIXME("%p: STUB\n", This
);
342 HRESULT WINAPI
fnTextSrv_TxGetBaseLinePos(ITextServices
*iface
,
345 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
347 FIXME("%p: STUB\n", This
);
351 HRESULT WINAPI
fnTextSrv_TxGetNaturalSize(ITextServices
*iface
,
357 const SIZEL
* psizelExtent
,
361 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
363 FIXME("%p: STUB\n", This
);
367 HRESULT WINAPI
fnTextSrv_TxGetDropTarget(ITextServices
*iface
,
368 IDropTarget
** ppDropTarget
)
370 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
372 FIXME("%p: STUB\n", This
);
376 HRESULT WINAPI
fnTextSrv_OnTxPropertyBitsChange(ITextServices
*iface
,
380 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
382 FIXME("%p: STUB\n", This
);
386 HRESULT WINAPI
fnTextSrv_TxGetCachedSize(ITextServices
*iface
,
390 ICOM_THIS_MULTI(ITextServicesImpl
, lpVtbl
, iface
);
392 FIXME("%p: STUB\n", This
);
396 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage
,20)
397 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw
,52)
398 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll
,24)
399 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll
,24)
400 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor
,40)
401 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint
,44)
402 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate
,8)
403 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate
,4)
404 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate
,4)
405 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate
,4)
406 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText
,8)
407 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText
,8)
408 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX
,8)
409 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos
,8)
410 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize
,36)
411 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget
,8)
412 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange
,12)
413 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize
,12)
415 static const ITextServicesVtbl textservices_Vtbl
=
417 fnTextSrv_QueryInterface
,
420 THISCALL(fnTextSrv_TxSendMessage
),
421 THISCALL(fnTextSrv_TxDraw
),
422 THISCALL(fnTextSrv_TxGetHScroll
),
423 THISCALL(fnTextSrv_TxGetVScroll
),
424 THISCALL(fnTextSrv_OnTxSetCursor
),
425 THISCALL(fnTextSrv_TxQueryHitPoint
),
426 THISCALL(fnTextSrv_OnTxInplaceActivate
),
427 THISCALL(fnTextSrv_OnTxInplaceDeactivate
),
428 THISCALL(fnTextSrv_OnTxUIActivate
),
429 THISCALL(fnTextSrv_OnTxUIDeactivate
),
430 THISCALL(fnTextSrv_TxGetText
),
431 THISCALL(fnTextSrv_TxSetText
),
432 THISCALL(fnTextSrv_TxGetCurrentTargetX
),
433 THISCALL(fnTextSrv_TxGetBaseLinePos
),
434 THISCALL(fnTextSrv_TxGetNaturalSize
),
435 THISCALL(fnTextSrv_TxGetDropTarget
),
436 THISCALL(fnTextSrv_OnTxPropertyBitsChange
),
437 THISCALL(fnTextSrv_TxGetCachedSize
)