wbemprox: Add stub implementations of IEnumWbemClassObject and IWbemClassObject.
[wine] / dlls / d3dx9_36 / font.c
1 /*
2  * Copyright (C) 2008 Tony Wasserka
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "wine/debug.h"
24 #include "wine/unicode.h"
25 #include "d3dx9_36_private.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
28
29 typedef struct ID3DXFontImpl
30 {
31     ID3DXFont ID3DXFont_iface;
32     LONG ref;
33
34     IDirect3DDevice9 *device;
35     D3DXFONT_DESCW desc;
36
37     HDC hdc;
38     HFONT hfont;
39 } ID3DXFontImpl;
40
41 static inline ID3DXFontImpl *impl_from_ID3DXFont(ID3DXFont *iface)
42 {
43     return CONTAINING_RECORD(iface, ID3DXFontImpl, ID3DXFont_iface);
44 }
45
46 static HRESULT WINAPI ID3DXFontImpl_QueryInterface(ID3DXFont *iface, REFIID riid, void **out)
47 {
48     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
49
50     if (IsEqualGUID(riid, &IID_ID3DXFont)
51             || IsEqualGUID(riid, &IID_IUnknown))
52     {
53         IUnknown_AddRef(iface);
54         *out = iface;
55         return S_OK;
56     }
57
58     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
59
60     *out = NULL;
61     return E_NOINTERFACE;
62 }
63
64 static ULONG WINAPI ID3DXFontImpl_AddRef(ID3DXFont *iface)
65 {
66     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
67     ULONG ref=InterlockedIncrement(&This->ref);
68     TRACE("(%p)->(): AddRef from %d\n", This, ref-1);
69     return ref;
70 }
71
72 static ULONG WINAPI ID3DXFontImpl_Release(ID3DXFont *iface)
73 {
74     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
75     ULONG ref=InterlockedDecrement(&This->ref);
76
77     TRACE("(%p)->(): ReleaseRef to %d\n", This, ref);
78
79     if(ref==0) {
80         DeleteObject(This->hfont);
81         DeleteDC(This->hdc);
82         IDirect3DDevice9_Release(This->device);
83         HeapFree(GetProcessHeap(), 0, This);
84     }
85     return ref;
86 }
87
88 static HRESULT WINAPI ID3DXFontImpl_GetDevice(ID3DXFont *iface, LPDIRECT3DDEVICE9 *device)
89 {
90     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
91
92     TRACE("(%p)->(%p)\n", This, device);
93
94     if( !device ) return D3DERR_INVALIDCALL;
95     *device = This->device;
96     IDirect3DDevice9_AddRef(This->device);
97
98     return D3D_OK;
99 }
100
101 static HRESULT WINAPI ID3DXFontImpl_GetDescA(ID3DXFont *iface, D3DXFONT_DESCA *desc)
102 {
103     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
104
105     TRACE("(%p)->(%p)\n", This, desc);
106
107     if( !desc ) return D3DERR_INVALIDCALL;
108     memcpy(desc, &This->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
109     WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, sizeof(desc->FaceName) / sizeof(CHAR), NULL, NULL);
110
111     return D3D_OK;
112 }
113
114 static HRESULT WINAPI ID3DXFontImpl_GetDescW(ID3DXFont *iface, D3DXFONT_DESCW *desc)
115 {
116     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
117
118     TRACE("(%p)->(%p)\n", This, desc);
119
120     if( !desc ) return D3DERR_INVALIDCALL;
121     *desc = This->desc;
122
123     return D3D_OK;
124 }
125
126 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(ID3DXFont *iface, TEXTMETRICA *metrics)
127 {
128     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
129     TRACE("(%p)->(%p)\n", This, metrics);
130     return GetTextMetricsA(This->hdc, metrics);
131 }
132
133 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(ID3DXFont *iface, TEXTMETRICW *metrics)
134 {
135     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
136     TRACE("(%p)->(%p)\n", This, metrics);
137     return GetTextMetricsW(This->hdc, metrics);
138 }
139
140 static HDC WINAPI ID3DXFontImpl_GetDC(ID3DXFont *iface)
141 {
142     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
143     TRACE("(%p)->()\n", This);
144     return This->hdc;
145 }
146
147 static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(ID3DXFont *iface, UINT glyph,
148         IDirect3DTexture9 **texture, RECT *blackbox, POINT *cellinc)
149 {
150     FIXME("iface %p, glyph %#x, texture %p, baclbox %s, cellinc %s stub!\n",
151             iface, glyph, texture, wine_dbgstr_rect(blackbox), wine_dbgstr_point(cellinc));
152
153     return D3D_OK;
154 }
155
156 static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(ID3DXFont *iface, UINT first, UINT last)
157 {
158     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
159     FIXME("(%p)->(%u, %u): stub\n", This, first, last);
160     return D3D_OK;
161 }
162
163 static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(ID3DXFont *iface, UINT first, UINT last)
164 {
165     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
166     FIXME("(%p)->(%u, %u): stub\n", This, first, last);
167     return D3D_OK;
168 }
169
170 static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(ID3DXFont *iface, LPCSTR string, INT count)
171 {
172     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
173     FIXME("(%p)->(%s, %d): stub\n", This, string, count);
174     return D3D_OK;
175 }
176
177 static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(ID3DXFont *iface, LPCWSTR string, INT count)
178 {
179     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
180     FIXME("(%p)->(%s, %d): stub\n", This, debugstr_w(string), count);
181     return D3D_OK;
182 }
183
184 static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite,
185         const char *string, INT count, RECT *rect, DWORD format, D3DCOLOR color)
186 {
187     FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n",
188             iface,  sprite, debugstr_a(string), count, wine_dbgstr_rect(rect), format, color);
189     return 1;
190 }
191
192 static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
193         const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color)
194 {
195     FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n",
196             iface,  sprite, debugstr_w(string), count, wine_dbgstr_rect(rect), format, color);
197     return 1;
198 }
199
200 static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(ID3DXFont *iface)
201 {
202     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
203     FIXME("(%p)->(): stub\n", This);
204     return D3D_OK;
205 }
206
207 static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(ID3DXFont *iface)
208 {
209     ID3DXFontImpl *This=impl_from_ID3DXFont(iface);
210     FIXME("(%p)->(): stub\n", This);
211     return D3D_OK;
212 }
213
214 static const ID3DXFontVtbl D3DXFont_Vtbl =
215 {
216     /*** IUnknown methods ***/
217     ID3DXFontImpl_QueryInterface,
218     ID3DXFontImpl_AddRef,
219     ID3DXFontImpl_Release,
220     /*** ID3DXFont methods ***/
221     ID3DXFontImpl_GetDevice,
222     ID3DXFontImpl_GetDescA,
223     ID3DXFontImpl_GetDescW,
224     ID3DXFontImpl_GetTextMetricsA,
225     ID3DXFontImpl_GetTextMetricsW,
226     ID3DXFontImpl_GetDC,
227     ID3DXFontImpl_GetGlyphData,
228     ID3DXFontImpl_PreloadCharacters,
229     ID3DXFontImpl_PreloadGlyphs,
230     ID3DXFontImpl_PreloadTextA,
231     ID3DXFontImpl_PreloadTextW,
232     ID3DXFontImpl_DrawTextA,
233     ID3DXFontImpl_DrawTextW,
234     ID3DXFontImpl_OnLostDevice,
235     ID3DXFontImpl_OnResetDevice
236 };
237
238 HRESULT WINAPI D3DXCreateFontA(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
239                                DWORD precision, DWORD quality, DWORD pitchandfamily, LPCSTR facename, LPD3DXFONT *font)
240 {
241     D3DXFONT_DESCA desc;
242
243     if( !device || !font ) return D3DERR_INVALIDCALL;
244
245     desc.Height=height;
246     desc.Width=width;
247     desc.Weight=weight;
248     desc.MipLevels=miplevels;
249     desc.Italic=italic;
250     desc.CharSet=charset;
251     desc.OutputPrecision=precision;
252     desc.Quality=quality;
253     desc.PitchAndFamily=pitchandfamily;
254     if(facename != NULL) lstrcpyA(desc.FaceName, facename);
255     else desc.FaceName[0] = '\0';
256
257     return D3DXCreateFontIndirectA(device, &desc, font);
258 }
259
260 HRESULT WINAPI D3DXCreateFontW(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
261                                DWORD precision, DWORD quality, DWORD pitchandfamily, LPCWSTR facename, LPD3DXFONT *font)
262 {
263     D3DXFONT_DESCW desc;
264
265     if( !device || !font ) return D3DERR_INVALIDCALL;
266
267     desc.Height=height;
268     desc.Width=width;
269     desc.Weight=weight;
270     desc.MipLevels=miplevels;
271     desc.Italic=italic;
272     desc.CharSet=charset;
273     desc.OutputPrecision=precision;
274     desc.Quality=quality;
275     desc.PitchAndFamily=pitchandfamily;
276     if(facename != NULL) strcpyW(desc.FaceName, facename);
277     else desc.FaceName[0] = '\0';
278
279     return D3DXCreateFontIndirectW(device, &desc, font);
280 }
281
282 /***********************************************************************
283  *           D3DXCreateFontIndirectA    (D3DX9_36.@)
284  */
285 HRESULT WINAPI D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCA *desc, LPD3DXFONT *font)
286 {
287     D3DXFONT_DESCW widedesc;
288
289     if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
290
291     /* Copy everything but the last structure member. This requires the
292        two D3DXFONT_DESC structures to be equal until the FaceName member */
293     memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
294     MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1,
295                         widedesc.FaceName, sizeof(widedesc.FaceName)/sizeof(WCHAR));
296     return D3DXCreateFontIndirectW(device, &widedesc, font);
297 }
298
299 /***********************************************************************
300  *           D3DXCreateFontIndirectW    (D3DX9_36.@)
301  */
302 HRESULT WINAPI D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCW *desc, LPD3DXFONT *font)
303 {
304     D3DDEVICE_CREATION_PARAMETERS cpars;
305     D3DDISPLAYMODE mode;
306     ID3DXFontImpl *object;
307     IDirect3D9 *d3d;
308     HRESULT hr;
309
310     FIXME("(%p, %p, %p): stub\n", device, desc, font);
311
312     if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
313
314     /* the device MUST support D3DFMT_A8R8G8B8 */
315     IDirect3DDevice9_GetDirect3D(device, &d3d);
316     IDirect3DDevice9_GetCreationParameters(device, &cpars);
317     IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
318     hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
319     if(FAILED(hr)) {
320         IDirect3D9_Release(d3d);
321         return D3DXERR_INVALIDDATA;
322     }
323     IDirect3D9_Release(d3d);
324
325     object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXFontImpl));
326     if(object==NULL) {
327         *font=NULL;
328         return E_OUTOFMEMORY;
329     }
330     object->ID3DXFont_iface.lpVtbl = &D3DXFont_Vtbl;
331     object->ref=1;
332     object->device=device;
333     object->desc=*desc;
334
335     object->hdc = CreateCompatibleDC(NULL);
336     if( !object->hdc ) {
337         HeapFree(GetProcessHeap(), 0, object);
338         return D3DXERR_INVALIDDATA;
339     }
340
341     object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet,
342                                 desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName);
343     if( !object->hfont ) {
344         DeleteDC(object->hdc);
345         HeapFree(GetProcessHeap(), 0, object);
346         return D3DXERR_INVALIDDATA;
347     }
348     SelectObject(object->hdc, object->hfont);
349
350     IDirect3DDevice9_AddRef(device);
351     *font=&object->ID3DXFont_iface;
352
353     return D3D_OK;
354 }