Removed unnecessary inclusion of heap.h.
[wine/gsoc_dplay.git] / graphics / enhmetafiledrv / objects.c
blob166816c4d4ec7e51bbdd482a17d944e0627b061b
1 /*
2 * Enhanced MetaFile objects
4 * Copyright 1999 Huw D M Davies
5 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
11 #include "bitmap.h"
12 #include "enhmetafiledrv.h"
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(enhmetafile);
17 /***********************************************************************
18 * EMFDRV_BITMAP_SelectObject
20 static HBITMAP EMFDRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap )
22 return 0;
26 /***********************************************************************
27 * EMFDRV_CreateBrushIndirect
29 DWORD EMFDRV_CreateBrushIndirect( DC *dc, HBRUSH hBrush )
31 DWORD index = 0;
32 LOGBRUSH logbrush;
34 if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return 0;
36 switch (logbrush.lbStyle) {
37 case BS_SOLID:
38 case BS_HATCHED:
39 case BS_NULL:
41 EMRCREATEBRUSHINDIRECT emr;
42 emr.emr.iType = EMR_CREATEBRUSHINDIRECT;
43 emr.emr.nSize = sizeof(emr);
44 emr.ihBrush = index = EMFDRV_AddHandleDC( dc );
45 emr.lb = logbrush;
47 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
48 index = 0;
50 break;
51 case BS_DIBPATTERN:
53 EMRCREATEDIBPATTERNBRUSHPT *emr;
54 DWORD bmSize, biSize, size;
55 BITMAPINFO *info = GlobalLock16(logbrush.lbHatch);
57 if (info->bmiHeader.biCompression)
58 bmSize = info->bmiHeader.biSizeImage;
59 else
60 bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
61 info->bmiHeader.biHeight,
62 info->bmiHeader.biBitCount);
63 biSize = DIB_BitmapInfoSize(info, LOWORD(logbrush.lbColor));
64 size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize;
65 emr = HeapAlloc( GetProcessHeap(), 0, size );
66 if(!emr) break;
67 emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
68 emr->emr.nSize = size;
69 emr->ihBrush = index = EMFDRV_AddHandleDC( dc );
70 emr->iUsage = LOWORD(logbrush.lbColor);
71 emr->offBmi = sizeof(EMRCREATEDIBPATTERNBRUSHPT);
72 emr->cbBmi = biSize;
73 emr->offBits = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize;
74 memcpy((char *)emr + sizeof(EMRCREATEDIBPATTERNBRUSHPT), info,
75 biSize + bmSize );
77 if(!EMFDRV_WriteRecord( dc, &emr->emr ))
78 index = 0;
79 HeapFree( GetProcessHeap(), 0, emr );
80 GlobalUnlock16(logbrush.lbHatch);
82 break;
84 case BS_PATTERN:
85 FIXME("Unsupported style %x\n",
86 logbrush.lbStyle);
87 break;
88 default:
89 FIXME("Unknown style %x\n", logbrush.lbStyle);
90 break;
92 return index;
96 /***********************************************************************
97 * EMFDRV_BRUSH_SelectObject
99 static HBRUSH EMFDRV_BRUSH_SelectObject(DC *dc, HBRUSH hBrush )
101 EMRSELECTOBJECT emr;
102 DWORD index;
103 HBRUSH hOldBrush;
105 /* If the object is a stock brush object, do not need to create it.
106 * See definitions in wingdi.h for range of stock brushes.
107 * We do however have to handle setting the higher order bit to
108 * designate that this is a stock object.
110 if (hBrush >= FIRST_STOCK_HANDLE &&
111 hBrush <= FIRST_STOCK_HANDLE+HOLLOW_BRUSH )
113 DWORD brush_index = hBrush - FIRST_STOCK_HANDLE;
114 index = brush_index | 0x80000000;
116 else
118 index = EMFDRV_CreateBrushIndirect(dc, hBrush );
121 if(!index) return FALSE;
123 emr.emr.iType = EMR_SELECTOBJECT;
124 emr.emr.nSize = sizeof(emr);
125 emr.ihObject = index;
126 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
127 return FALSE;
129 hOldBrush = dc->hBrush;
130 dc->hBrush = hBrush;
131 return hOldBrush;
135 /******************************************************************
136 * EMFDRV_CreateFontIndirect
138 static BOOL EMFDRV_CreateFontIndirect(DC *dc, HFONT hFont )
140 DWORD index = 0;
141 EMREXTCREATEFONTINDIRECTW emr;
142 int i;
144 if (!GetObjectW( hFont, sizeof(emr.elfw.elfLogFont), &emr.elfw.elfLogFont )) return 0;
146 emr.emr.iType = EMR_EXTCREATEFONTINDIRECTW;
147 emr.emr.nSize = (sizeof(emr) + 3) / 4 * 4;
148 emr.ihFont = index = EMFDRV_AddHandleDC( dc );
149 emr.elfw.elfFullName[0] = '\0';
150 emr.elfw.elfStyle[0] = '\0';
151 emr.elfw.elfVersion = 0;
152 emr.elfw.elfStyleSize = 0;
153 emr.elfw.elfMatch = 0;
154 emr.elfw.elfReserved = 0;
155 for(i = 0; i < ELF_VENDOR_SIZE; i++)
156 emr.elfw.elfVendorId[i] = 0;
157 emr.elfw.elfCulture = PAN_CULTURE_LATIN;
158 emr.elfw.elfPanose.bFamilyType = PAN_NO_FIT;
159 emr.elfw.elfPanose.bSerifStyle = PAN_NO_FIT;
160 emr.elfw.elfPanose.bWeight = PAN_NO_FIT;
161 emr.elfw.elfPanose.bProportion = PAN_NO_FIT;
162 emr.elfw.elfPanose.bContrast = PAN_NO_FIT;
163 emr.elfw.elfPanose.bStrokeVariation = PAN_NO_FIT;
164 emr.elfw.elfPanose.bArmStyle = PAN_NO_FIT;
165 emr.elfw.elfPanose.bLetterform = PAN_NO_FIT;
166 emr.elfw.elfPanose.bMidline = PAN_NO_FIT;
167 emr.elfw.elfPanose.bXHeight = PAN_NO_FIT;
169 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
170 index = 0;
171 return index;
175 /***********************************************************************
176 * EMFDRV_FONT_SelectObject
178 static HFONT EMFDRV_FONT_SelectObject( DC * dc, HFONT hFont )
180 EMRSELECTOBJECT emr;
181 DWORD index;
182 HFONT hOldFont;
184 /* If the object is a stock font object, do not need to create it.
185 * See definitions in wingdi.h for range of stock fonts.
186 * We do however have to handle setting the higher order bit to
187 * designate that this is a stock object.
190 if (hFont >= STOCK_OEM_FIXED_FONT &&
191 hFont <= STOCK_DEFAULT_GUI_FONT &&
192 hFont != STOCK_DEFAULT_PALETTE)
194 DWORD font_index = hFont - FIRST_STOCK_HANDLE;
195 index = font_index | 0x80000000;
197 else
199 index = EMFDRV_CreateFontIndirect(dc, hFont );
202 if(!index) return FALSE;
204 emr.emr.iType = EMR_SELECTOBJECT;
205 emr.emr.nSize = sizeof(emr);
206 emr.ihObject = index;
207 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
208 return FALSE;
210 hOldFont = dc->hFont;
211 dc->hFont = hFont;
212 return hOldFont;
217 /******************************************************************
218 * EMFDRV_CreatePenIndirect
220 static HPEN EMFDRV_CreatePenIndirect(DC *dc, HPEN hPen )
222 EMRCREATEPEN emr;
223 DWORD index = 0;
225 if (!GetObjectA( hPen, sizeof(emr.lopn), &emr.lopn )) return 0;
227 emr.emr.iType = EMR_CREATEPEN;
228 emr.emr.nSize = sizeof(emr);
229 emr.ihPen = index = EMFDRV_AddHandleDC( dc );
231 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
232 index = 0;
233 return index;
236 /******************************************************************
237 * EMFDRV_PEN_SelectObject
239 static HPEN EMFDRV_PEN_SelectObject(DC *dc, HPEN hPen )
241 EMRSELECTOBJECT emr;
242 DWORD index;
243 HPEN hOldPen;
245 /* If the object is a stock pen object, do not need to create it.
246 * See definitions in wingdi.h for range of stock pens.
247 * We do however have to handle setting the higher order bit to
248 * designate that this is a stock object.
251 if (hPen >= STOCK_WHITE_PEN &&
252 hPen <= STOCK_NULL_PEN )
254 DWORD pen_index = hPen - FIRST_STOCK_HANDLE;
255 index = pen_index | 0x80000000;
257 else
259 index = EMFDRV_CreatePenIndirect(dc, hPen );
262 if(!index) return FALSE;
264 emr.emr.iType = EMR_SELECTOBJECT;
265 emr.emr.nSize = sizeof(emr);
266 emr.ihObject = index;
267 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
268 return FALSE;
270 hOldPen = dc->hPen;
271 dc->hPen = hPen;
272 return hOldPen;
276 /***********************************************************************
277 * EMFDRV_SelectObject
279 HGDIOBJ EMFDRV_SelectObject( DC *dc, HGDIOBJ handle )
281 GDIOBJHDR * ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
282 HGDIOBJ ret = 0;
284 if (!ptr) return 0;
285 TRACE("hdc=%04x %04x\n", dc->hSelf, handle );
287 switch(GDIMAGIC(ptr->wMagic))
289 case PEN_MAGIC:
290 ret = EMFDRV_PEN_SelectObject( dc, handle );
291 break;
292 case BRUSH_MAGIC:
293 ret = EMFDRV_BRUSH_SelectObject( dc, handle );
294 break;
295 case FONT_MAGIC:
296 ret = EMFDRV_FONT_SelectObject( dc, handle );
297 break;
298 case BITMAP_MAGIC:
299 ret = EMFDRV_BITMAP_SelectObject( dc, handle );
300 break;
302 GDI_ReleaseObj( handle );
303 return ret;