4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
13 #include "prototypes.h"
15 MDESC
*GDI_Heap
= NULL
;
17 /* Object types for EnumObjects() */
22 HANDLE
*lpPenBrushList
= NULL
;
24 extern HPALETTE
COLOR_Init(); /* color.c */
26 /***********************************************************************
30 static BRUSHOBJ WhiteBrush
=
32 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
33 { BS_SOLID
, RGB(255,255,255), 0 } /* logbrush */
36 static BRUSHOBJ LtGrayBrush
=
38 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
39 { BS_SOLID
, RGB(192,192,192), 0 } /* logbrush */
42 static BRUSHOBJ GrayBrush
=
44 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
45 { BS_SOLID
, RGB(128,128,128), 0 } /* logbrush */
48 static BRUSHOBJ DkGrayBrush
=
50 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
51 { BS_SOLID
, RGB(64,64,64), 0 } /* logbrush */
54 static BRUSHOBJ BlackBrush
=
56 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
57 { BS_SOLID
, RGB(0,0,0), 0 } /* logbrush */
60 static BRUSHOBJ NullBrush
=
62 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
63 { BS_NULL
, 0, 0 } /* logbrush */
66 static PENOBJ WhitePen
=
68 { 0, PEN_MAGIC
, 1, 0 }, /* header */
69 { PS_SOLID
, { 1, 0 }, RGB(255,255,255) } /* logpen */
72 static PENOBJ BlackPen
=
74 { 0, PEN_MAGIC
, 1, 0 }, /* header */
75 { PS_SOLID
, { 1, 0 }, RGB(0,0,0) } /* logpen */
78 static PENOBJ NullPen
=
80 { 0, PEN_MAGIC
, 1, 0 }, /* header */
81 { PS_NULL
, { 1, 0 }, 0 } /* logpen */
84 static FONTOBJ OEMFixedFont
=
86 { 0, FONT_MAGIC
, 1, 0 }, /* header */
87 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, OEM_CHARSET
,
88 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, "" }
91 static FONTOBJ AnsiFixedFont
=
93 { 0, FONT_MAGIC
, 1, 0 }, /* header */
94 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
95 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, "" }
98 static FONTOBJ AnsiVarFont
=
100 { 0, FONT_MAGIC
, 1, 0 }, /* header */
101 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
102 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, "" }
105 static FONTOBJ SystemFont
=
107 { 0, FONT_MAGIC
, 1, 0 }, /* header */
108 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
109 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, "" }
112 static FONTOBJ DeviceDefaultFont
=
114 { 0, FONT_MAGIC
, 1, 0 }, /* header */
115 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
116 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, "" }
119 static FONTOBJ SystemFixedFont
=
121 { 0, FONT_MAGIC
, 1, 0 }, /* header */
122 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
123 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, "" }
127 static GDIOBJHDR
* StockObjects
[NB_STOCK_OBJECTS
] =
129 (GDIOBJHDR
*) &WhiteBrush
,
130 (GDIOBJHDR
*) &LtGrayBrush
,
131 (GDIOBJHDR
*) &GrayBrush
,
132 (GDIOBJHDR
*) &DkGrayBrush
,
133 (GDIOBJHDR
*) &BlackBrush
,
134 (GDIOBJHDR
*) &NullBrush
,
135 (GDIOBJHDR
*) &WhitePen
,
136 (GDIOBJHDR
*) &BlackPen
,
137 (GDIOBJHDR
*) &NullPen
,
139 (GDIOBJHDR
*) &OEMFixedFont
,
140 (GDIOBJHDR
*) &AnsiFixedFont
,
141 (GDIOBJHDR
*) &AnsiVarFont
,
142 (GDIOBJHDR
*) &SystemFont
,
143 (GDIOBJHDR
*) &DeviceDefaultFont
,
144 NULL
, /* DEFAULT_PALETTE created by COLOR_Init */
145 (GDIOBJHDR
*) &SystemFixedFont
149 /***********************************************************************
152 * GDI initialisation.
157 struct segment_descriptor_s
* s
;
160 /* Create GDI heap */
162 s
= (struct segment_descriptor_s
*)GetNextSegment( 0, 0x10000 );
163 if (s
== NULL
) return FALSE
;
164 HEAP_Init( &GDI_Heap
, s
->base_addr
, GDI_HEAP_SIZE
);
167 /* Create default palette */
169 if (!(hpalette
= COLOR_Init())) return FALSE
;
170 StockObjects
[DEFAULT_PALETTE
] = (GDIOBJHDR
*) GDI_HEAP_ADDR( hpalette
);
172 /* Create default bitmap */
174 if (!BITMAP_Init()) return FALSE
;
176 /* Initialise regions */
178 if (!REGION_Init()) return FALSE
;
180 /* Initialise dithering */
182 if (!DITHER_Init()) return FALSE
;
188 /***********************************************************************
189 * GDI_AppendToPenBrushList
191 BOOL
GDI_AppendToPenBrushList(HANDLE hNewObj
)
195 if (hNewObj
== 0) return FALSE
;
196 if (lpPenBrushList
== NULL
) {
197 lpPenBrushList
= malloc(MAX_OBJ
* sizeof(HANDLE
));
198 lpPenBrushList
[0] = 0;
200 printf("GDI_AppendToPenBrushList() lpPenBrushList allocated !\n");
203 for (lphObj
= lpPenBrushList
; i
< MAX_OBJ
; i
++) {
208 printf("GDI_AppendToPenBrushList(%04X) appended (count=%d)\n", hNewObj
, i
);
218 /***********************************************************************
221 * Return the GDI object whose hNext field points to obj.
223 HANDLE
GDI_FindPrevObject( HANDLE first
, HANDLE obj
)
227 for (handle
= first
; handle
&& (handle
!= obj
); )
229 GDIOBJHDR
* header
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
230 handle
= header
->hNext
;
236 /***********************************************************************
239 HANDLE
GDI_AllocObject( WORD size
, WORD magic
)
241 static DWORD count
= 0;
243 HANDLE handle
= GDI_HEAP_ALLOC( GMEM_MOVEABLE
, size
);
244 if (!handle
) return 0;
245 obj
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
247 printf("GDI_AllocObject // Error trying to get GDI_HEAD_ADDR !\n");
252 obj
->dwCount
= ++count
;
253 if (magic
== PEN_MAGIC
|| magic
== BRUSH_MAGIC
) {
254 GDI_AppendToPenBrushList(handle
);
260 /***********************************************************************
263 BOOL
GDI_FreeObject( HANDLE handle
)
267 /* Can't free stock objects */
268 if (handle
>= FIRST_STOCK_HANDLE
) return FALSE
;
270 object
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
271 if (!object
) return FALSE
;
275 GDI_HEAP_FREE( handle
);
279 /***********************************************************************
282 * Return a pointer to the GDI object associated to the handle.
283 * Return NULL if the object has the wrong magic number.
285 GDIOBJHDR
* GDI_GetObjPtr( HANDLE handle
, WORD magic
)
287 GDIOBJHDR
* ptr
= NULL
;
289 if (handle
>= FIRST_STOCK_HANDLE
)
291 if (handle
< FIRST_STOCK_HANDLE
+ NB_STOCK_OBJECTS
)
292 ptr
= StockObjects
[handle
- FIRST_STOCK_HANDLE
];
294 else ptr
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
295 if (!ptr
) return NULL
;
296 if (ptr
->wMagic
!= magic
) return NULL
;
301 /***********************************************************************
302 * DeleteObject (GDI.69)
304 BOOL
DeleteObject( HANDLE obj
)
306 /* Check if object is valid */
308 GDIOBJHDR
* header
= (GDIOBJHDR
*) GDI_HEAP_ADDR( obj
);
309 if (!header
) return FALSE
;
312 printf( "DeleteObject: %d\n", obj
);
317 switch(header
->wMagic
)
319 case PEN_MAGIC
: return GDI_FreeObject( obj
);
320 case BRUSH_MAGIC
: return BRUSH_DeleteObject( obj
, header
);
321 case FONT_MAGIC
: return GDI_FreeObject( obj
);
322 case PALETTE_MAGIC
: return GDI_FreeObject( obj
);
323 case BITMAP_MAGIC
: return BMP_DeleteObject( obj
, header
);
324 case REGION_MAGIC
: return REGION_DeleteObject( obj
, header
);
330 /***********************************************************************
331 * GetStockObject (GDI.87)
333 HANDLE
GetStockObject( int obj
)
335 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
336 if (!StockObjects
[obj
]) return 0;
338 printf( "GetStockObject: returning %04x\n", FIRST_STOCK_HANDLE
+ obj
);
340 return FIRST_STOCK_HANDLE
+ obj
;
344 /***********************************************************************
347 int GetObject( HANDLE handle
, int count
, LPSTR buffer
)
349 GDIOBJHDR
* ptr
= NULL
;
351 printf( "GetObject: %04x %d %08x\n", handle
, count
, buffer
);
353 if (!count
) return 0;
355 if (handle
>= FIRST_STOCK_HANDLE
)
357 if (handle
< FIRST_STOCK_HANDLE
+ NB_STOCK_OBJECTS
)
358 ptr
= StockObjects
[handle
- FIRST_STOCK_HANDLE
];
360 else ptr
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
366 return PEN_GetObject( (PENOBJ
*)ptr
, count
, buffer
);
368 return BRUSH_GetObject( (BRUSHOBJ
*)ptr
, count
, buffer
);
370 return BMP_GetObject( (BITMAPOBJ
*)ptr
, count
, buffer
);
372 return FONT_GetObject( (FONTOBJ
*)ptr
, count
, buffer
);
374 return PALETTE_GetObject( (PALETTEOBJ
*)ptr
, count
, buffer
);
380 /***********************************************************************
381 * SelectObject (GDI.45)
383 HANDLE
SelectObject( HDC hdc
, HANDLE handle
)
385 GDIOBJHDR
* ptr
= NULL
;
389 printf( "SelectObject: %d %04x\n", hdc
, handle
);
391 if (handle
>= FIRST_STOCK_HANDLE
)
393 if (handle
< FIRST_STOCK_HANDLE
+ NB_STOCK_OBJECTS
)
394 ptr
= StockObjects
[handle
- FIRST_STOCK_HANDLE
];
396 else ptr
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
399 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
402 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
409 return PEN_SelectObject( dc
, handle
, (PENOBJ
*)ptr
);
411 return BRUSH_SelectObject( hdc
, dc
, handle
, (BRUSHOBJ
*)ptr
);
413 return BITMAP_SelectObject( hdc
, dc
, handle
, (BITMAPOBJ
*)ptr
);
415 return FONT_SelectObject( dc
, handle
, (FONTOBJ
*)ptr
);
417 return SelectClipRgn( hdc
, handle
);
423 /***********************************************************************
424 * UnrealizeObject (GDI.150)
426 BOOL
UnrealizeObject( HANDLE handle
)
429 printf( "UnrealizeObject: %04x\n", handle
);
435 /***********************************************************************
436 * EnumObjects (GDI.71)
438 int EnumObjects(HDC hDC
, int nObjType
, FARPROC lpEnumFunc
, LPSTR lpData
)
445 LPSTR lpLog
; /* Point to a LOGBRUSH or LOGPEN struct */
448 if (lpEnumFunc
== NULL
) {
449 printf("EnumObjects // Bad EnumProc callback address !\n");
455 printf("EnumObjects(%04X, OBJ_PEN, %08X, %08X);\n",
456 hDC
, lpEnumFunc
, lpData
);
457 hLog
= USER_HEAP_ALLOC(GMEM_MOVEABLE
, sizeof(LOGPEN
));
458 lpLog
= (LPSTR
) USER_HEAP_ADDR(hLog
);
460 printf("EnumObjects // Unable to alloc LOGPEN struct !\n");
465 wMagic
= BRUSH_MAGIC
;
466 printf("EnumObjects(%04X, OBJ_BRUSH, %08X, %08X);\n",
467 hDC
, lpEnumFunc
, lpData
);
468 hLog
= USER_HEAP_ALLOC(GMEM_MOVEABLE
, sizeof(LOGBRUSH
));
469 lpLog
= (LPSTR
) USER_HEAP_ADDR(hLog
);
471 printf("EnumObjects // Unable to alloc LOGBRUSH struct !\n");
476 printf("EnumObjects(%04X, %04X, %08X, %08X); // Unknown OBJ type !\n",
477 hDC
, nObjType
, lpEnumFunc
, lpData
);
480 printf("EnumObjects // Stock Objects first !\n");
481 for (i
= 0; i
< NB_STOCK_OBJECTS
; i
++) {
482 header
= StockObjects
[i
];
483 if (header
->wMagic
== wMagic
) {
484 PEN_GetObject( (PENOBJ
*)header
, sizeof(LOGPEN
), (LPLOGPEN
)lpLog
);
485 BRUSH_GetObject( (BRUSHOBJ
*)header
, sizeof(LOGBRUSH
), (LPLOGBRUSH
)lpLog
);
486 printf("EnumObjects // StockObj lpLog=%08X lpData=%08X\n", lpLog
, lpData
);
487 if (header
->wMagic
== BRUSH_MAGIC
) {
488 printf("EnumObjects // StockBrush lbStyle=%04X\n", ((LPLOGBRUSH
)lpLog
)->lbStyle
);
489 printf("EnumObjects // StockBrush lbColor=%08X\n", ((LPLOGBRUSH
)lpLog
)->lbColor
);
490 printf("EnumObjects // StockBrush lbHatch=%04X\n", ((LPLOGBRUSH
)lpLog
)->lbHatch
);
492 if (header
->wMagic
== PEN_MAGIC
) {
493 printf("EnumObjects // StockPen lopnStyle=%04X\n", ((LPLOGPEN
)lpLog
)->lopnStyle
);
494 printf("EnumObjects // StockPen lopnWidth=%08X\n", ((LPLOGPEN
)lpLog
)->lopnWidth
);
495 printf("EnumObjects // StockPen lopnColor=%08X\n", ((LPLOGPEN
)lpLog
)->lopnColor
);
500 nRet = (*lpEnumFunc)(lpLog, lpData);
502 nRet = CallBack16(lpEnumFunc, 4, 2, (int)lpLog, 2, (int)lpData);
505 printf("EnumObjects // after CallBack16 !\n");
507 USER_HEAP_FREE(hLog
);
508 printf("EnumObjects // EnumEnd requested by application !\n");
513 if (lpPenBrushList
== NULL
) return 0;
514 printf("EnumObjects // Now DC owned objects %08X !\n", header
);
515 for (lphObj
= lpPenBrushList
; *lphObj
!= 0; ) {
517 printf("EnumObjects // *lphObj=%04X\n", *lphObj
);
519 header
= (GDIOBJHDR
*) GDI_HEAP_ADDR(*lphObj
++);
520 if (header
->wMagic
== wMagic
) {
522 printf("EnumObjects // DC_Obj lpLog=%08X lpData=%08X\n", lpLog
, lpData
);
524 if (header
->wMagic
== BRUSH_MAGIC
) {
525 BRUSH_GetObject( (BRUSHOBJ
*)header
, sizeof(LOGBRUSH
), (LPLOGBRUSH
)lpLog
);
526 printf("EnumObjects // DC_Brush lbStyle=%04X\n", ((LPLOGBRUSH
)lpLog
)->lbStyle
);
527 printf("EnumObjects // DC_Brush lbColor=%08X\n", ((LPLOGBRUSH
)lpLog
)->lbColor
);
528 printf("EnumObjects // DC_Brush lbHatch=%04X\n", ((LPLOGBRUSH
)lpLog
)->lbHatch
);
530 if (header
->wMagic
== PEN_MAGIC
) {
531 PEN_GetObject( (PENOBJ
*)header
, sizeof(LOGPEN
), (LPLOGPEN
)lpLog
);
532 printf("EnumObjects // DC_Pen lopnStyle=%04X\n", ((LPLOGPEN
)lpLog
)->lopnStyle
);
533 printf("EnumObjects // DC_Pen lopnWidth=%08X\n", ((LPLOGPEN
)lpLog
)->lopnWidth
);
534 printf("EnumObjects // DC_Pen lopnColor=%08X\n", ((LPLOGPEN
)lpLog
)->lopnColor
);
538 nRet = (*lpEnumFunc)(lpLog, lpData);
540 nRet = CallBack16(lpEnumFunc, 4, 2, (int)lpLog, 2, (int)lpData);
544 printf("EnumObjects // after CallBack16 !\n");
546 USER_HEAP_FREE(hLog
);
547 printf("EnumObjects // EnumEnd requested by application !\n");
552 USER_HEAP_FREE(hLog
);
553 printf("EnumObjects // End of enumeration !\n");
557 /***********************************************************************
558 * IsGDIObject(GDI.462)
560 BOOL
IsGDIObject(HANDLE handle
)
564 object
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);