ReactOS 0.4.15-dev-8138-g1e75ea8
gdiobj.c
Go to the documentation of this file.
1#include <precomp.h>
2
3#define NDEBUG
4#include <debug.h>
5
7
8/*
9 * @implemented
10 */
14 INT fnObject)
15{
16 HGDIOBJ hobj;
17
18 if ((fnObject < 0) || (fnObject >= NB_STOCK_OBJECTS))
19 return NULL;
20
21 hobj = stock_objects[fnObject];
22 if (hobj == NULL)
23 {
24 hobj = NtGdiGetStockObject(fnObject);
25
26 if (!GdiValidateHandle(hobj))
27 {
28 return NULL;
29 }
30
31 stock_objects[fnObject] = hobj;
32 }
33
34 return hobj;
35}
36
37
38/*
39 * @implemented
40 */
44 HGDIOBJ h)
45{
46 DWORD Ret = 0;
47
49 {
51 switch(Type)
52 {
54 Ret = OBJ_PEN;
55 break;
57 Ret = OBJ_BRUSH;
58 break;
60 Ret = OBJ_BITMAP;
61 break;
63 Ret = OBJ_FONT;
64 break;
66 Ret = OBJ_PAL;
67 break;
69 Ret = OBJ_REGION;
70 break;
72 if ( GetDCDWord( h, GdiGetIsMemDc, 0))
73 {
74 Ret = OBJ_MEMDC;
75 }
76 else
77 Ret = OBJ_DC;
78 break;
80 Ret = OBJ_COLORSPACE;
81 break;
83 Ret = OBJ_METAFILE;
84 break;
86 Ret = OBJ_ENHMETAFILE;
87 break;
89 Ret = OBJ_METADC;
90 break;
92 Ret = OBJ_EXTPEN;
93 break;
94
96 // FIXME: could be something else?
97 Ret = OBJ_ENHMETADC;
98 break;
99
100 default:
101 DPRINT1("GetObjectType: Magic 0x%08x not implemented\n", Type);
102 break;
103 }
104 }
105 else
106 /* From Wine: GetObjectType does SetLastError() on a null object */
108 return Ret;
109}
110
111ULONG
112WINAPI
115 _In_ ULONG cbSize,
117{
118 ENUMLOGFONTEXDVW elfedvW;
119 ENUMLOGFONTEXDVA elfedvA;
120 ULONG cbResult;
121
122 /* Check if size only is requested */
123 if (!lpBuffer) return sizeof(LOGFONTA);
124
125 /* Check for size 0 */
126 if (cbSize == 0)
127 {
128 /* Windows does not SetLastError() */
129 return 0;
130 }
131
132 /* Windows does this ... */
133 if (cbSize == sizeof(LOGFONTW)) cbSize = sizeof(LOGFONTA);
134
135 /* Call win32k to get the logfont (widechar) */
136 cbResult = NtGdiExtGetObjectW(hfont, sizeof(ENUMLOGFONTEXDVW), &elfedvW);
137 if (cbResult == 0)
138 {
139 return 0;
140 }
141
142 /* Convert the logfont from widechar to ansi */
144 elfedvA.elfDesignVector = elfedvW.elfDesignVector;
145
146 /* Don't copy more than maximum */
147 if (cbSize > sizeof(ENUMLOGFONTEXDVA)) cbSize = sizeof(ENUMLOGFONTEXDVA);
148
149 /* Copy the number of bytes requested */
150 memcpy(lpBuffer, &elfedvA, cbSize);
151
152 /* Return the number of bytes copied */
153 return cbSize;
154}
155
156
157/*
158 * @implemented
159 */
160int
161WINAPI
163 _In_ HGDIOBJ hGdiObj,
164 _In_ int cbSize,
166{
167 DWORD dwType = GDI_HANDLE_GET_TYPE(hGdiObj);
168
169 /* Chjeck if this is anything else but a font */
170 if (dwType == GDI_OBJECT_TYPE_FONT)
171 {
172 return GetFontObjectA(hGdiObj, cbSize, lpBuffer);
173 }
174 else
175 {
176 /* Simply pass it to the widechar version */
177 return GetObjectW(hGdiObj, cbSize, lpBuffer);
178 }
179}
180
181
182/*
183 * @implemented
184 */
185int
186WINAPI
188 _In_ HGDIOBJ hGdiObj,
189 _In_ int cbSize,
191{
192 DWORD dwType;
193 INT cbResult = 0;
194
195 /* Fixup handles with upper 16 bits masked */
196 hGdiObj = GdiFixUpHandle(hGdiObj);
197
198 /* Get the object type */
199 dwType = GDI_HANDLE_GET_TYPE(hGdiObj);
200
201 /* Check what kind of object we have */
202 switch (dwType)
203 {
205 if (!lpBuffer) return sizeof(LOGPEN);
206 break;
207
209 if (!lpBuffer) return sizeof(LOGBRUSH);
210 break;
211
213 if (!lpBuffer) return sizeof(BITMAP);
214 break;
215
217 if (!lpBuffer) return sizeof(WORD);
218 break;
219
221 if (!lpBuffer) return sizeof(LOGFONTW);
222 break;
223
225 /* we don't know the size, ask win32k */
226 break;
227
229 if ((cbSize < 328) || !lpBuffer)
230 {
232 return 0;
233 }
234 break;
235
242 default:
243 return 0;
244 }
245
246 /* Call win32k */
247 cbResult = NtGdiExtGetObjectW(hGdiObj, cbSize, lpBuffer);
248
249 /* Handle error */
250 if (cbResult == 0)
251 {
252 if (!GdiValidateHandle(hGdiObj))
253 {
254 if ((dwType == GDI_OBJECT_TYPE_PEN) ||
255 (dwType == GDI_OBJECT_TYPE_EXTPEN) ||
256 (dwType == GDI_OBJECT_TYPE_BRUSH) ||
257 (dwType == GDI_OBJECT_TYPE_COLORSPACE))
258 {
260 }
261 }
262 else
263 {
264 if ((dwType == GDI_OBJECT_TYPE_PEN) ||
265 (dwType == GDI_OBJECT_TYPE_BRUSH) ||
266 (dwType == GDI_OBJECT_TYPE_COLORSPACE) ||
267 ( (dwType == GDI_OBJECT_TYPE_EXTPEN) &&
268 ( (cbSize >= sizeof(EXTLOGPEN)) || (cbSize == 0) ) ) ||
269 ( (dwType == GDI_OBJECT_TYPE_BITMAP) && (cbSize >= sizeof(BITMAP)) ))
270 {
272 }
273 }
274 }
275
276 return cbResult;
277}
278
279static
280BOOL
282 HGDIOBJ hobj)
283{
284 GDILOOBJTYPE eObjectType;
285 PBRUSH_ATTR pbrattr;
286 PTEB pTeb;
287 PGDIBSOBJECT pgO;
288
289 eObjectType = GDI_HANDLE_GET_TYPE(hobj);
290
291 if ((GdiGetHandleUserData(hobj, eObjectType, (PVOID*)&pbrattr)) &&
292 (pbrattr != NULL))
293 {
294 pTeb = NtCurrentTeb();
295 if (pTeb->Win32ThreadInfo != NULL)
296 {
298 if (pgO)
299 {
301 pgO->hgdiobj = hobj;
302 return TRUE;
303 }
304 }
305 }
306
307 return NtGdiDeleteObjectApp(hobj);
308}
309
310/*
311 * @implemented
312 */
313BOOL
314WINAPI
316{
317 /* Check if the handle is valid (FIXME: we need some special
318 sauce for the stock object flag) */
319 if (!GdiValidateHandle(hObject))
320 return FALSE;
321
322 /* Check if this is a stock object */
323 if (GDI_HANDLE_IS_STOCKOBJ(hObject))
324 {
325 /* Ignore the attempt to delete a stock object */
326 DPRINT1("Trying to delete system object 0x%p\n", hObject);
327 return TRUE;
328 }
329
330 /* If we have any METAFILE objects, we need to check them */
331 if (gcClientObj > 0)
332 {
333 DPRINT("Going Glue\n");
335 }
336
337 /* Switch by object type */
338 switch (GDI_HANDLE_GET_TYPE(hObject))
339 {
342 return FALSE;
343
346 return DeleteDC(hObject);
347
349 return NtGdiDeleteColorSpace(hObject);
350
352 return DeleteRegion(hObject);
353
357 return GdiDeleteBrushOrPen(hObject);
358
361 default:
362 break;
363 }
364
365 return NtGdiDeleteObjectApp(hObject);
366}
367
368
static HFONT hfont
static POBJECT_TYPE GetObjectType(IN PCWSTR TypeName)
Definition: ObTypes.c:15
Type
Definition: Type.h:7
#define DPRINT1
Definition: precomp.h:8
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
VOID WINAPI EnumLogFontExW2A(LPENUMLOGFONTEXA fontA, CONST ENUMLOGFONTEXW *fontW)
Definition: utils.c:402
FORCEINLINE PVOID GdiAllocBatchCommand(HDC hdc, USHORT Cmd)
Definition: gdi32p.h:381
BOOL WINAPI GdiValidateHandle(HGDIOBJ)
Definition: misc.c:712
HGDIOBJ WINAPI GdiFixUpHandle(HGDIOBJ hGO)
Definition: misc.c:734
ULONG gcClientObj
Definition: clientobj.c:11
DWORD WINAPI GetDCDWord(_In_ HDC hdc, _In_ UINT u, _In_ DWORD dwError)
Definition: dc.c:787
VOID WINAPI METADC_RosGlueDeleteObject(HGDIOBJ hobj)
Definition: rosglue.c:352
#define GDI_OBJECT_TYPE_REGION
Definition: gdi.h:47
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
#define GDI_OBJECT_TYPE_BRUSH
Definition: gdi.h:52
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDI_OBJECT_TYPE_ENHMETAFILE
Definition: gdi.h:59
#define GDI_OBJECT_TYPE_COLORSPACE
Definition: gdi.h:56
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
#define GDI_OBJECT_TYPE_PALETTE
Definition: gdi.h:49
#define GDI_OBJECT_TYPE_EXTPEN
Definition: gdi.h:55
#define GDI_OBJECT_TYPE_FONT
Definition: gdi.h:50
#define GDI_OBJECT_TYPE_EMF
Definition: gdi.h:53
#define GDI_OBJECT_TYPE_METADC
Definition: gdi.h:57
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
#define GDI_OBJECT_TYPE_PEN
Definition: gdi.h:54
#define GDI_OBJECT_TYPE_METAFILE
Definition: gdi.h:58
@ GDILoObjType_LO_FONT_TYPE
Definition: gdi_private.h:37
@ GDILoObjType_LO_BRUSH_TYPE
Definition: gdi_private.h:33
@ GDILoObjType_LO_BITMAP_TYPE
Definition: gdi_private.h:35
@ GDILoObjType_LO_METAFILE_TYPE
Definition: gdi_private.h:48
@ GDILoObjType_LO_REGION_TYPE
Definition: gdi_private.h:38
@ GDILoObjType_LO_EXTPEN_TYPE
Definition: gdi_private.h:45
@ GDILoObjType_LO_METAFILE16_TYPE
Definition: gdi_private.h:47
@ GDILoObjType_LO_ICMLCS_TYPE
Definition: gdi_private.h:39
@ GDILoObjType_LO_DC_TYPE
Definition: gdi_private.h:34
@ GDILoObjType_LO_PEN_TYPE
Definition: gdi_private.h:44
@ GDILoObjType_LO_ALTDC_TYPE
Definition: gdi_private.h:43
enum GDILoObjType GDILOOBJTYPE
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define NtCurrentTeb
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteColorSpace(_In_ HANDLE hColorSpace)
@ GdiGetIsMemDc
Definition: ntgdityp.h:55
#define NB_STOCK_OBJECTS
Definition: ntgdityp.h:192
@ GdiBCDelObj
Definition: ntgdityp.h:93
#define OBJ_METAFILE
Definition: objidl.idl:1417
#define OBJ_EXTPEN
Definition: objidl.idl:1419
#define OBJ_REGION
Definition: objidl.idl:1416
#define OBJ_DC
Definition: objidl.idl:1411
#define OBJ_PEN
Definition: objidl.idl:1409
#define OBJ_METADC
Definition: objidl.idl:1412
#define OBJ_BRUSH
Definition: objidl.idl:1410
#define OBJ_FONT
Definition: objidl.idl:1414
#define OBJ_BITMAP
Definition: objidl.idl:1415
#define OBJ_ENHMETADC
Definition: objidl.idl:1420
#define OBJ_PAL
Definition: objidl.idl:1413
#define OBJ_MEMDC
Definition: objidl.idl:1418
#define OBJ_ENHMETAFILE
Definition: objidl.idl:1421
long LONG
Definition: pedump.c:60
#define BITMAP
Definition: pedump.c:503
#define DPRINT
Definition: sndvol32.h:73
Definition: bl.h:1331
HGDIOBJ hgdiobj
Definition: ntgdityp.h:560
Definition: compat.h:836
PVOID Win32ThreadInfo
Definition: compat.h:846
DESIGNVECTOR elfDesignVector
Definition: wingdi.h:2775
ENUMLOGFONTEXA elfEnumLogfontEx
Definition: wingdi.h:2774
DESIGNVECTOR elfDesignVector
Definition: wingdi.h:2780
ENUMLOGFONTEXW elfEnumLogfontEx
Definition: wingdi.h:2779
static void DeleteRegion(GLUtesselator *tess, ActiveRegion *reg)
Definition: sweep.c:151
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
static BOOL GdiDeleteBrushOrPen(HGDIOBJ hobj)
Definition: gdiobj.c:281
HGDIOBJ stock_objects[NB_STOCK_OBJECTS]
Definition: gdiobj.c:6
int WINAPI GetObjectW(_In_ HGDIOBJ hGdiObj, _In_ int cbSize, _Out_ LPVOID lpBuffer)
Definition: gdiobj.c:187
ULONG WINAPI GetFontObjectA(_In_ HGDIOBJ hfont, _In_ ULONG cbSize, _Out_ LPVOID lpBuffer)
Definition: gdiobj.c:113
W32KAPI INT APIENTRY NtGdiExtGetObjectW(IN HANDLE hobj, IN INT cjBufferSize, OUT LPVOID lpBuffer)
Definition: gdiobj.c:1326
#define WINAPI
Definition: msvc.h:6
#define ERROR_NOACCESS
Definition: winerror.h:578
struct tagENUMLOGFONTEXDVA ENUMLOGFONTEXDVA
HGDIOBJ WINAPI GetStockObject(_In_ int)
struct tagLOGPEN LOGPEN
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
#define OBJ_COLORSPACE
Definition: wingdi.h:704
BOOL WINAPI DeleteDC(_In_ HDC)
struct tagLOGBRUSH LOGBRUSH