ReactOS 0.4.15-dev-8127-g6338913
gdiobj.c File Reference
#include <precomp.h>
#include <debug.h>
Include dependency graph for gdiobj.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

HGDIOBJ WINAPI GetStockObject (INT fnObject)
 
DWORD WINAPI GetObjectType (HGDIOBJ h)
 
ULONG WINAPI GetFontObjectA (_In_ HGDIOBJ hfont, _In_ ULONG cbSize, _Out_ LPVOID lpBuffer)
 
int WINAPI GetObjectA (_In_ HGDIOBJ hGdiObj, _In_ int cbSize, _Out_ LPVOID lpBuffer)
 
int WINAPI GetObjectW (_In_ HGDIOBJ hGdiObj, _In_ int cbSize, _Out_ LPVOID lpBuffer)
 
static BOOL GdiDeleteBrushOrPen (HGDIOBJ hobj)
 
BOOL WINAPI DeleteObject (HGDIOBJ hObject)
 

Variables

HGDIOBJ stock_objects [NB_STOCK_OBJECTS]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file gdiobj.c.

Function Documentation

◆ DeleteObject()

BOOL WINAPI DeleteObject ( HGDIOBJ  hObject)

Definition at line 315 of file gdiobj.c.

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}
#define DPRINT1
Definition: precomp.h:8
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI GdiValidateHandle(HGDIOBJ)
Definition: misc.c:712
ULONG gcClientObj
Definition: clientobj.c:11
VOID WINAPI METADC_RosGlueDeleteObject(HGDIOBJ hobj)
Definition: rosglue.c:352
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
@ 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
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteColorSpace(_In_ HANDLE hColorSpace)
#define DPRINT
Definition: sndvol32.h:73
static void DeleteRegion(GLUtesselator *tess, ActiveRegion *reg)
Definition: sweep.c:151
static BOOL GdiDeleteBrushOrPen(HGDIOBJ hobj)
Definition: gdiobj.c:281
BOOL WINAPI DeleteDC(_In_ HDC)

◆ GdiDeleteBrushOrPen()

static BOOL GdiDeleteBrushOrPen ( HGDIOBJ  hobj)
static

FIXME: we need to mark the object as deleted!

Definition at line 281 of file gdiobj.c.

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}
#define NULL
Definition: types.h:112
FORCEINLINE PVOID GdiAllocBatchCommand(HDC hdc, USHORT Cmd)
Definition: gdi32p.h:381
enum GDILoObjType GDILOOBJTYPE
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
#define NtCurrentTeb
@ GdiBCDelObj
Definition: ntgdityp.h:93
HGDIOBJ hgdiobj
Definition: ntgdityp.h:560
Definition: compat.h:836
PVOID Win32ThreadInfo
Definition: compat.h:846

Referenced by DeleteObject().

◆ GetFontObjectA()

ULONG WINAPI GetFontObjectA ( _In_ HGDIOBJ  hfont,
_In_ ULONG  cbSize,
_Out_ LPVOID  lpBuffer 
)

Definition at line 113 of file gdiobj.c.

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}
static HFONT hfont
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
VOID WINAPI EnumLogFontExW2A(LPENUMLOGFONTEXA fontA, CONST ENUMLOGFONTEXW *fontW)
Definition: utils.c:402
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
DESIGNVECTOR elfDesignVector
Definition: wingdi.h:2775
ENUMLOGFONTEXA elfEnumLogfontEx
Definition: wingdi.h:2774
DESIGNVECTOR elfDesignVector
Definition: wingdi.h:2780
ENUMLOGFONTEXW elfEnumLogfontEx
Definition: wingdi.h:2779
uint32_t ULONG
Definition: typedefs.h:59
W32KAPI INT APIENTRY NtGdiExtGetObjectW(IN HANDLE hobj, IN INT cjBufferSize, OUT LPVOID lpBuffer)
Definition: gdiobj.c:1326
struct tagENUMLOGFONTEXDVA ENUMLOGFONTEXDVA

Referenced by GetObjectA().

◆ GetObjectA()

int WINAPI GetObjectA ( _In_ HGDIOBJ  hGdiObj,
_In_ int  cbSize,
_Out_ LPVOID  lpBuffer 
)

Definition at line 162 of file gdiobj.c.

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}
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GDI_OBJECT_TYPE_FONT
Definition: gdi.h:50
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

◆ GetObjectType()

DWORD WINAPI GetObjectType ( HGDIOBJ  h)

Definition at line 43 of file gdiobj.c.

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}
Type
Definition: Type.h:7
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
DWORD WINAPI GetDCDWord(_In_ HDC hdc, _In_ UINT u, _In_ DWORD dwError)
Definition: dc.c:787
#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_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_METADC
Definition: gdi.h:57
#define GDI_OBJECT_TYPE_PEN
Definition: gdi.h:54
#define GDI_OBJECT_TYPE_METAFILE
Definition: gdi.h:58
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
@ GdiGetIsMemDc
Definition: ntgdityp.h:55
#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 OBJ_COLORSPACE
Definition: wingdi.h:704

◆ GetObjectW()

int WINAPI GetObjectW ( _In_ HGDIOBJ  hGdiObj,
_In_ int  cbSize,
_Out_ LPVOID  lpBuffer 
)

Definition at line 187 of file gdiobj.c.

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}
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
unsigned short WORD
Definition: ntddk_ex.h:93
HGDIOBJ WINAPI GdiFixUpHandle(HGDIOBJ hGO)
Definition: misc.c:734
#define GDI_OBJECT_TYPE_EMF
Definition: gdi.h:53
#define BITMAP
Definition: pedump.c:503
Definition: bl.h:1331
int32_t INT
Definition: typedefs.h:58
#define ERROR_NOACCESS
Definition: winerror.h:578
struct tagLOGPEN LOGPEN
struct tagLOGBRUSH LOGBRUSH

Referenced by GetObjectA().

◆ GetStockObject()

HGDIOBJ WINAPI GetStockObject ( INT  fnObject)

Definition at line 13 of file gdiobj.c.

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}
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
#define NB_STOCK_OBJECTS
Definition: ntgdityp.h:192
HGDIOBJ stock_objects[NB_STOCK_OBJECTS]
Definition: gdiobj.c:6

Variable Documentation

◆ stock_objects

HGDIOBJ stock_objects[NB_STOCK_OBJECTS]

Definition at line 6 of file gdiobj.c.

Referenced by GdiDllInitialize(), and GetStockObject().