4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
12 #include "prototypes.h"
14 MDESC
*GDI_Heap
= NULL
;
16 extern HPALETTE
COLOR_Init(); /* color.c */
18 /***********************************************************************
22 static BRUSHOBJ WhiteBrush
=
24 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
25 { BS_SOLID
, RGB(255,255,255), 0 } /* logbrush */
28 static BRUSHOBJ LtGrayBrush
=
30 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
31 { BS_SOLID
, RGB(192,192,192), 0 } /* logbrush */
34 static BRUSHOBJ GrayBrush
=
36 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
37 { BS_SOLID
, RGB(128,128,128), 0 } /* logbrush */
40 static BRUSHOBJ DkGrayBrush
=
42 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
43 { BS_SOLID
, RGB(64,64,64), 0 } /* logbrush */
46 static BRUSHOBJ BlackBrush
=
48 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
49 { BS_SOLID
, RGB(0,0,0), 0 } /* logbrush */
52 static BRUSHOBJ NullBrush
=
54 { 0, BRUSH_MAGIC
, 1, 0 }, /* header */
55 { BS_NULL
, 0, 0 } /* logbrush */
58 static PENOBJ WhitePen
=
60 { 0, PEN_MAGIC
, 1, 0 }, /* header */
61 { PS_SOLID
, { 1, 0 }, RGB(255,255,255) } /* logpen */
64 static PENOBJ BlackPen
=
66 { 0, PEN_MAGIC
, 1, 0 }, /* header */
67 { PS_SOLID
, { 1, 0 }, RGB(0,0,0) } /* logpen */
70 static PENOBJ NullPen
=
72 { 0, PEN_MAGIC
, 1, 0 }, /* header */
73 { PS_NULL
, { 1, 0 }, 0 } /* logpen */
76 static FONTOBJ OEMFixedFont
=
78 { 0, FONT_MAGIC
, 1, 0 }, /* header */
79 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, OEM_CHARSET
,
80 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, "" }
83 static FONTOBJ AnsiFixedFont
=
85 { 0, FONT_MAGIC
, 1, 0 }, /* header */
86 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
87 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, "" }
90 static FONTOBJ AnsiVarFont
=
92 { 0, FONT_MAGIC
, 1, 0 }, /* header */
93 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
94 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, "" }
97 static FONTOBJ SystemFont
=
99 { 0, FONT_MAGIC
, 1, 0 }, /* header */
100 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
101 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, "" }
104 static FONTOBJ DeviceDefaultFont
=
106 { 0, FONT_MAGIC
, 1, 0 }, /* header */
107 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
108 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, "" }
111 static FONTOBJ SystemFixedFont
=
113 { 0, FONT_MAGIC
, 1, 0 }, /* header */
114 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
115 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, "" }
119 static GDIOBJHDR
* StockObjects
[NB_STOCK_OBJECTS
] =
121 (GDIOBJHDR
*) &WhiteBrush
,
122 (GDIOBJHDR
*) &LtGrayBrush
,
123 (GDIOBJHDR
*) &GrayBrush
,
124 (GDIOBJHDR
*) &DkGrayBrush
,
125 (GDIOBJHDR
*) &BlackBrush
,
126 (GDIOBJHDR
*) &NullBrush
,
127 (GDIOBJHDR
*) &WhitePen
,
128 (GDIOBJHDR
*) &BlackPen
,
129 (GDIOBJHDR
*) &NullPen
,
131 (GDIOBJHDR
*) &OEMFixedFont
,
132 (GDIOBJHDR
*) &AnsiFixedFont
,
133 (GDIOBJHDR
*) &AnsiVarFont
,
134 (GDIOBJHDR
*) &SystemFont
,
135 (GDIOBJHDR
*) &DeviceDefaultFont
,
136 NULL
, /* DEFAULT_PALETTE created by COLOR_Init */
137 (GDIOBJHDR
*) &SystemFixedFont
141 /***********************************************************************
144 * GDI initialisation.
149 struct segment_descriptor_s
* s
;
152 /* Create GDI heap */
154 s
= (struct segment_descriptor_s
*)GetNextSegment( 0, 0x10000 );
155 if (s
== NULL
) return FALSE
;
156 HEAP_Init( &GDI_Heap
, s
->base_addr
, GDI_HEAP_SIZE
);
159 /* Create default palette */
161 if (!(hpalette
= COLOR_Init())) return FALSE
;
162 StockObjects
[DEFAULT_PALETTE
] = (GDIOBJHDR
*) GDI_HEAP_ADDR( hpalette
);
164 /* Create default bitmap */
166 if (!BITMAP_Init()) return FALSE
;
168 /* Initialise regions */
170 if (!REGION_Init()) return FALSE
;
172 /* Initialise dithering */
174 if (!DITHER_Init()) return FALSE
;
180 /***********************************************************************
183 * Return the GDI object whose hNext field points to obj.
185 HANDLE
GDI_FindPrevObject( HANDLE first
, HANDLE obj
)
189 for (handle
= first
; handle
&& (handle
!= obj
); )
191 GDIOBJHDR
* header
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
192 handle
= header
->hNext
;
198 /***********************************************************************
201 HANDLE
GDI_AllocObject( WORD size
, WORD magic
)
203 static DWORD count
= 0;
205 HANDLE handle
= GDI_HEAP_ALLOC( GMEM_MOVEABLE
, size
);
206 if (!handle
) return 0;
207 obj
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
209 printf("GDI_AllocObject // Error trying to get GDI_HEAD_ADDR !\n");
214 obj
->dwCount
= ++count
;
219 /***********************************************************************
222 BOOL
GDI_FreeObject( HANDLE handle
)
226 /* Can't free stock objects */
227 if (handle
>= FIRST_STOCK_HANDLE
) return FALSE
;
229 object
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
230 if (!object
) return FALSE
;
234 GDI_HEAP_FREE( handle
);
238 /***********************************************************************
241 * Return a pointer to the GDI object associated to the handle.
242 * Return NULL if the object has the wrong magic number.
244 GDIOBJHDR
* GDI_GetObjPtr( HANDLE handle
, WORD magic
)
246 GDIOBJHDR
* ptr
= NULL
;
248 if (handle
>= FIRST_STOCK_HANDLE
)
250 if (handle
< FIRST_STOCK_HANDLE
+ NB_STOCK_OBJECTS
)
251 ptr
= StockObjects
[handle
- FIRST_STOCK_HANDLE
];
253 else ptr
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
254 if (!ptr
) return NULL
;
255 if (ptr
->wMagic
!= magic
) return NULL
;
260 /***********************************************************************
261 * DeleteObject (GDI.69)
263 BOOL
DeleteObject( HANDLE obj
)
265 /* Check if object is valid */
267 GDIOBJHDR
* header
= (GDIOBJHDR
*) GDI_HEAP_ADDR( obj
);
268 if (!header
) return FALSE
;
271 printf( "DeleteObject: %d\n", obj
);
276 switch(header
->wMagic
)
278 case PEN_MAGIC
: return GDI_FreeObject( obj
);
279 case BRUSH_MAGIC
: return BRUSH_DeleteObject( obj
, header
);
280 case FONT_MAGIC
: return GDI_FreeObject( obj
);
281 case PALETTE_MAGIC
: return GDI_FreeObject( obj
);
282 case BITMAP_MAGIC
: return BMP_DeleteObject( obj
, header
);
283 case REGION_MAGIC
: return REGION_DeleteObject( obj
, header
);
289 /***********************************************************************
290 * GetStockObject (GDI.87)
292 HANDLE
GetStockObject( int obj
)
294 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
295 if (!StockObjects
[obj
]) return 0;
297 printf( "GetStockObject: returning %04x\n", FIRST_STOCK_HANDLE
+ obj
);
299 return FIRST_STOCK_HANDLE
+ obj
;
303 /***********************************************************************
306 int GetObject( HANDLE handle
, int count
, LPSTR buffer
)
308 GDIOBJHDR
* ptr
= NULL
;
310 printf( "GetObject: %04x %d %08x\n", handle
, count
, buffer
);
312 if (!count
) return 0;
314 if (handle
>= FIRST_STOCK_HANDLE
)
316 if (handle
< FIRST_STOCK_HANDLE
+ NB_STOCK_OBJECTS
)
317 ptr
= StockObjects
[handle
- FIRST_STOCK_HANDLE
];
319 else ptr
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
325 return PEN_GetObject( (PENOBJ
*)ptr
, count
, buffer
);
327 return BRUSH_GetObject( (BRUSHOBJ
*)ptr
, count
, buffer
);
329 return BMP_GetObject( (BITMAPOBJ
*)ptr
, count
, buffer
);
331 return FONT_GetObject( (FONTOBJ
*)ptr
, count
, buffer
);
333 return PALETTE_GetObject( (PALETTEOBJ
*)ptr
, count
, buffer
);
339 /***********************************************************************
340 * SelectObject (GDI.45)
342 HANDLE
SelectObject( HDC hdc
, HANDLE handle
)
344 GDIOBJHDR
* ptr
= NULL
;
348 printf( "SelectObject: %d %04x\n", hdc
, handle
);
350 if (handle
>= FIRST_STOCK_HANDLE
)
352 if (handle
< FIRST_STOCK_HANDLE
+ NB_STOCK_OBJECTS
)
353 ptr
= StockObjects
[handle
- FIRST_STOCK_HANDLE
];
355 else ptr
= (GDIOBJHDR
*) GDI_HEAP_ADDR( handle
);
358 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
364 return PEN_SelectObject( dc
, handle
, (PENOBJ
*)ptr
);
366 return BRUSH_SelectObject( hdc
, dc
, handle
, (BRUSHOBJ
*)ptr
);
368 return BITMAP_SelectObject( hdc
, dc
, handle
, (BITMAPOBJ
*)ptr
);
370 return FONT_SelectObject( dc
, handle
, (FONTOBJ
*)ptr
);
372 return SelectClipRgn( hdc
, handle
);
378 /***********************************************************************
379 * UnrealizeObject (GDI.150)
381 BOOL
UnrealizeObject( HANDLE handle
)
384 printf( "UnrealizeObject: %04x\n", handle
);