wined3d: Use the texture sampling function in a few more instructions (GLSL).
[wine] / dlls / riched20 / txtsrv.c
1 /*
2  * RichEdit - functions and interfaces around CreateTextServices
3  *
4  * Copyright 2005, 2006, Maarten Lankhorst
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
26 #define COBJMACROS
27
28 #include "editor.h"
29 #include "ole2.h"
30 #include "richole.h"
31 #include "winreg.h"
32 #include "imm.h"
33 #include "textserv.h"
34 #include "wine/debug.h"
35 #include "editstr.h"
36
37 #ifdef __i386__  /* thiscall functions are i386-specific */
38
39 #define THISCALL(func) __thiscall_ ## func
40 #define DEFINE_THISCALL_WRAPPER(func) \
41    extern typeof(func) THISCALL(func); \
42    __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
43                    "popl %eax\n\t" \
44                    "pushl %ecx\n\t" \
45                    "pushl %eax\n\t" \
46                    "jmp " __ASM_NAME(#func) )
47 #else /* __i386__ */
48
49 #define THISCALL(func) func
50 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
51
52 #endif /* __i386__ */
53
54 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
55
56 typedef struct ITextServicesImpl {
57    const ITextServicesVtbl *lpVtbl;
58    ITextHost *pMyHost;
59    LONG ref;
60    CRITICAL_SECTION csTxtSrv;
61 } ITextServicesImpl;
62
63 static const ITextServicesVtbl textservices_Vtbl;
64
65 /******************************************************************
66  *        CreateTextServices (RICHED20.4)
67  */
68 HRESULT WINAPI CreateTextServices(IUnknown  * pUnkOuter,
69                                   ITextHost * pITextHost,
70                                   IUnknown  **ppUnk)
71 {
72    ITextServicesImpl *ITextImpl;
73    TRACE("%p %p --> %p\n", pUnkOuter, pITextHost, ppUnk);
74    if (pITextHost == NULL)
75       return E_POINTER;
76
77    ITextImpl = CoTaskMemAlloc(sizeof(*ITextImpl));
78    if (ITextImpl == NULL)
79       return E_OUTOFMEMORY;
80    InitializeCriticalSection(&ITextImpl->csTxtSrv);
81    ITextImpl->ref = 1;
82    ITextHost_AddRef(pITextHost);
83    ITextImpl->pMyHost = pITextHost;
84    ITextImpl->lpVtbl = &textservices_Vtbl;
85
86    if (pUnkOuter)
87    {
88       FIXME("Support aggregation\n");
89       return CLASS_E_NOAGGREGATION;
90    }
91
92    *ppUnk = (IUnknown *)ITextImpl;
93    return S_OK;
94 }
95
96 #define ICOM_THIS_MULTI(impl,field,iface) \
97                     impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
98
99 static HRESULT WINAPI fnTextSrv_QueryInterface(ITextServices * iface,
100                                                REFIID riid,
101                                                LPVOID * ppv)
102 {
103    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
104    TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
105    *ppv = NULL;
106    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextServices))
107       *ppv = (LPVOID)This;
108
109    if (*ppv)
110    {
111       IUnknown_AddRef((IUnknown *)(*ppv));
112       TRACE ("-- Interface = %p\n", *ppv);
113       return S_OK;
114    }
115    FIXME("Unknown interface: %s\n", debugstr_guid(riid));
116    return E_NOINTERFACE;
117 }
118
119 static ULONG WINAPI fnTextSrv_AddRef(ITextServices *iface)
120 {
121    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
122    DWORD ref = InterlockedIncrement(&This->ref);
123
124    TRACE("(%p/%p)->() AddRef from %d\n", This, iface, ref - 1);
125    return ref;
126 }
127
128 static ULONG WINAPI fnTextSrv_Release(ITextServices *iface)
129 {
130    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
131    DWORD ref = InterlockedDecrement(&This->ref);
132
133    TRACE("(%p/%p)->() Release from %d\n", This, iface, ref + 1);
134
135    if (!ref)
136    {
137       ITextHost_Release(This->pMyHost);
138       DeleteCriticalSection(&This->csTxtSrv);
139       CoTaskMemFree(This);
140    }
141    return ref;
142 }
143
144 HRESULT WINAPI fnTextSrv_TxSendMessage(ITextServices *iface,
145                                        UINT msg,
146                                        WPARAM wparam,
147                                        LPARAM lparam,
148                                        LRESULT* plresult)
149 {
150    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
151
152    FIXME("%p: STUB\n", This);
153    return E_NOTIMPL;
154 }
155
156 HRESULT WINAPI fnTextSrv_TxDraw(ITextServices *iface,
157                                 DWORD dwDrawAspect,
158                                 LONG lindex,
159                                 void* pvAspect,
160                                 DVTARGETDEVICE* ptd,
161                                 HDC hdcDraw,
162                                 HDC hdcTargetDev,
163                                 LPCRECTL lprcBounds,
164                                 LPCRECTL lprcWBounds,
165                                 LPRECT lprcUpdate,
166                                 BOOL (CALLBACK * pfnContinue)(DWORD),
167                                 DWORD dwContinue,
168                                 LONG lViewId)
169 {
170    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
171
172    FIXME("%p: STUB\n", This);
173    return E_NOTIMPL;
174 }
175
176 HRESULT WINAPI fnTextSrv_TxGetHScroll(ITextServices *iface,
177                                       LONG* plMin,
178                                       LONG* plMax,
179                                       LONG* plPos,
180                                       LONG* plPage,
181                                       BOOL* pfEnabled)
182 {
183    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
184
185    FIXME("%p: STUB\n", This);
186    return E_NOTIMPL;
187 }
188
189 HRESULT WINAPI fnTextSrv_TxGetVScroll(ITextServices *iface,
190                                       LONG* plMin,
191                                       LONG* plMax,
192                                       LONG* plPos,
193                                       LONG* plPage,
194                                       BOOL* pfEnabled)
195 {
196    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
197
198    FIXME("%p: STUB\n", This);
199    return E_NOTIMPL;
200 }
201
202 HRESULT WINAPI fnTextSrv_OnTxSetCursor(ITextServices *iface,
203                                        DWORD dwDrawAspect,
204                                        LONG lindex,
205                                        void* pvAspect,
206                                        DVTARGETDEVICE* ptd,
207                                        HDC hdcDraw,
208                                        HDC hicTargetDev,
209                                        LPCRECT lprcClient,
210                                        INT x, INT y)
211 {
212    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
213
214    FIXME("%p: STUB\n", This);
215    return E_NOTIMPL;
216 }
217
218 HRESULT WINAPI fnTextSrv_TxQueryHitPoint(ITextServices *iface,
219                                          DWORD dwDrawAspect,
220                                          LONG lindex,
221                                          void* pvAspect,
222                                          DVTARGETDEVICE* ptd,
223                                          HDC hdcDraw,
224                                          HDC hicTargetDev,
225                                          LPCRECT lprcClient,
226                                          INT x, INT y,
227                                          DWORD* pHitResult)
228 {
229    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
230
231    FIXME("%p: STUB\n", This);
232    return E_NOTIMPL;
233 }
234
235 HRESULT WINAPI fnTextSrv_OnTxInplaceActivate(ITextServices *iface,
236                                              LPCRECT prcClient)
237 {
238    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
239
240    FIXME("%p: STUB\n", This);
241    return E_NOTIMPL;
242 }
243
244 HRESULT WINAPI fnTextSrv_OnTxInplaceDeactivate(ITextServices *iface)
245 {
246    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
247
248    FIXME("%p: STUB\n", This);
249    return E_NOTIMPL;
250 }
251
252 HRESULT WINAPI fnTextSrv_OnTxUIActivate(ITextServices *iface)
253 {
254    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
255
256    FIXME("%p: STUB\n", This);
257    return E_NOTIMPL;
258 }
259
260 HRESULT WINAPI fnTextSrv_OnTxUIDeactivate(ITextServices *iface)
261 {
262    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
263
264    FIXME("%p: STUB\n", This);
265    return E_NOTIMPL;
266 }
267
268 HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface,
269                                    BSTR* pbstrText)
270 {
271    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
272
273    FIXME("%p: STUB\n", This);
274    return E_NOTIMPL;
275 }
276
277 HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface,
278                                    LPCWSTR pszText)
279 {
280    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
281
282    FIXME("%p: STUB\n", This);
283    return E_NOTIMPL;
284 }
285
286 HRESULT WINAPI fnTextSrv_TxGetCurrentTargetX(ITextServices *iface,
287                                              LONG* x)
288 {
289    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
290
291    FIXME("%p: STUB\n", This);
292    return E_NOTIMPL;
293 }
294
295 HRESULT WINAPI fnTextSrv_TxGetBaseLinePos(ITextServices *iface,
296                                           LONG* x)
297 {
298    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
299
300    FIXME("%p: STUB\n", This);
301    return E_NOTIMPL;
302 }
303
304 HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
305                                           DWORD dwAspect,
306                                           HDC hdcDraw,
307                                           HDC hicTargetDev,
308                                           DVTARGETDEVICE* ptd,
309                                           DWORD dwMode,
310                                           const SIZEL* psizelExtent,
311                                           LONG* pwidth,
312                                           LONG* pheight)
313 {
314    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
315
316    FIXME("%p: STUB\n", This);
317    return E_NOTIMPL;
318 }
319
320 HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface,
321                                          IDropTarget** ppDropTarget)
322 {
323    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
324
325    FIXME("%p: STUB\n", This);
326    return E_NOTIMPL;
327 }
328
329 HRESULT WINAPI fnTextSrv_OnTxPropertyBitsChange(ITextServices *iface,
330                                                 DWORD dwMask,
331                                                 DWORD dwBits)
332 {
333    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
334
335    FIXME("%p: STUB\n", This);
336    return E_NOTIMPL;
337 }
338
339 HRESULT WINAPI fnTextSrv_TxGetCachedSize(ITextServices *iface,
340                                          DWORD* pdwWidth,
341                                          DWORD* pdwHeight)
342 {
343    ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface);
344
345    FIXME("%p: STUB\n", This);
346    return E_NOTIMPL;
347 }
348
349 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSendMessage);
350 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxDraw);
351 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetHScroll);
352 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetVScroll);
353 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor);
354 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint);
355 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceActivate);
356 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxInplaceDeactivate);
357 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIActivate);
358 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxUIDeactivate);
359 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetText);
360 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxSetText);
361 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCurrentTargetX);
362 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetBaseLinePos);
363 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetNaturalSize);
364 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetDropTarget);
365 DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxPropertyBitsChange);
366 DEFINE_THISCALL_WRAPPER(fnTextSrv_TxGetCachedSize);
367
368 static const ITextServicesVtbl textservices_Vtbl =
369 {
370    fnTextSrv_QueryInterface,
371    fnTextSrv_AddRef,
372    fnTextSrv_Release,
373    THISCALL(fnTextSrv_TxSendMessage),
374    THISCALL(fnTextSrv_TxDraw),
375    THISCALL(fnTextSrv_TxGetHScroll),
376    THISCALL(fnTextSrv_TxGetVScroll),
377    THISCALL(fnTextSrv_OnTxSetCursor),
378    THISCALL(fnTextSrv_TxQueryHitPoint),
379    THISCALL(fnTextSrv_OnTxInplaceActivate),
380    THISCALL(fnTextSrv_OnTxInplaceDeactivate),
381    THISCALL(fnTextSrv_OnTxUIActivate),
382    THISCALL(fnTextSrv_OnTxUIDeactivate),
383    THISCALL(fnTextSrv_TxGetText),
384    THISCALL(fnTextSrv_TxSetText),
385    THISCALL(fnTextSrv_TxGetCurrentTargetX),
386    THISCALL(fnTextSrv_TxGetBaseLinePos),
387    THISCALL(fnTextSrv_TxGetNaturalSize),
388    THISCALL(fnTextSrv_TxGetDropTarget),
389    THISCALL(fnTextSrv_OnTxPropertyBitsChange),
390    THISCALL(fnTextSrv_TxGetCachedSize)
391 };