Move __stdcall/__cdecl to the right place.
[wine/gsoc_dplay.git] / graphics / enhmetafiledrv / objects.c
blob0cd11e6e6abae568cd9573f2612998c59290bc0a
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;
104 int i;
106 /* If the object is a stock brush object, do not need to create it.
107 * See definitions in wingdi.h for range of stock brushes.
108 * We do however have to handle setting the higher order bit to
109 * designate that this is a stock object.
111 for (i = WHITE_BRUSH; i <= NULL_BRUSH; i++)
113 if (hBrush == GetStockObject(i))
115 index = i | 0x80000000;
116 goto found;
119 if (!(index = EMFDRV_CreateBrushIndirect(dc, hBrush ))) return 0;
121 found:
122 emr.emr.iType = EMR_SELECTOBJECT;
123 emr.emr.nSize = sizeof(emr);
124 emr.ihObject = index;
125 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
126 return FALSE;
128 hOldBrush = dc->hBrush;
129 dc->hBrush = hBrush;
130 return hOldBrush;
134 /******************************************************************
135 * EMFDRV_CreateFontIndirect
137 static BOOL EMFDRV_CreateFontIndirect(DC *dc, HFONT hFont )
139 DWORD index = 0;
140 EMREXTCREATEFONTINDIRECTW emr;
141 int i;
143 if (!GetObjectW( hFont, sizeof(emr.elfw.elfLogFont), &emr.elfw.elfLogFont )) return 0;
145 emr.emr.iType = EMR_EXTCREATEFONTINDIRECTW;
146 emr.emr.nSize = (sizeof(emr) + 3) / 4 * 4;
147 emr.ihFont = index = EMFDRV_AddHandleDC( dc );
148 emr.elfw.elfFullName[0] = '\0';
149 emr.elfw.elfStyle[0] = '\0';
150 emr.elfw.elfVersion = 0;
151 emr.elfw.elfStyleSize = 0;
152 emr.elfw.elfMatch = 0;
153 emr.elfw.elfReserved = 0;
154 for(i = 0; i < ELF_VENDOR_SIZE; i++)
155 emr.elfw.elfVendorId[i] = 0;
156 emr.elfw.elfCulture = PAN_CULTURE_LATIN;
157 emr.elfw.elfPanose.bFamilyType = PAN_NO_FIT;
158 emr.elfw.elfPanose.bSerifStyle = PAN_NO_FIT;
159 emr.elfw.elfPanose.bWeight = PAN_NO_FIT;
160 emr.elfw.elfPanose.bProportion = PAN_NO_FIT;
161 emr.elfw.elfPanose.bContrast = PAN_NO_FIT;
162 emr.elfw.elfPanose.bStrokeVariation = PAN_NO_FIT;
163 emr.elfw.elfPanose.bArmStyle = PAN_NO_FIT;
164 emr.elfw.elfPanose.bLetterform = PAN_NO_FIT;
165 emr.elfw.elfPanose.bMidline = PAN_NO_FIT;
166 emr.elfw.elfPanose.bXHeight = PAN_NO_FIT;
168 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
169 index = 0;
170 return index;
174 /***********************************************************************
175 * EMFDRV_FONT_SelectObject
177 static HFONT EMFDRV_FONT_SelectObject( DC * dc, HFONT hFont )
179 EMRSELECTOBJECT emr;
180 DWORD index;
181 int i;
183 /* If the object is a stock font object, do not need to create it.
184 * See definitions in wingdi.h for range of stock fonts.
185 * We do however have to handle setting the higher order bit to
186 * designate that this is a stock object.
189 for (i = OEM_FIXED_FONT; i <= DEFAULT_GUI_FONT; i++)
191 if (i != DEFAULT_PALETTE && hFont == GetStockObject(i))
193 index = i | 0x80000000;
194 goto found;
197 if (!(index = EMFDRV_CreateFontIndirect(dc, hFont ))) return GDI_ERROR;
198 found:
199 emr.emr.iType = EMR_SELECTOBJECT;
200 emr.emr.nSize = sizeof(emr);
201 emr.ihObject = index;
202 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
203 return GDI_ERROR;
205 return FALSE;
210 /******************************************************************
211 * EMFDRV_CreatePenIndirect
213 static HPEN EMFDRV_CreatePenIndirect(DC *dc, HPEN hPen )
215 EMRCREATEPEN emr;
216 DWORD index = 0;
218 if (!GetObjectA( hPen, sizeof(emr.lopn), &emr.lopn )) return 0;
220 emr.emr.iType = EMR_CREATEPEN;
221 emr.emr.nSize = sizeof(emr);
222 emr.ihPen = index = EMFDRV_AddHandleDC( dc );
224 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
225 index = 0;
226 return index;
229 /******************************************************************
230 * EMFDRV_PEN_SelectObject
232 static HPEN EMFDRV_PEN_SelectObject(DC *dc, HPEN hPen )
234 EMRSELECTOBJECT emr;
235 DWORD index;
236 HPEN hOldPen;
237 int i;
239 /* If the object is a stock pen object, do not need to create it.
240 * See definitions in wingdi.h for range of stock pens.
241 * We do however have to handle setting the higher order bit to
242 * designate that this is a stock object.
245 for (i = WHITE_PEN; i <= NULL_PEN; i++)
247 if (hPen == GetStockObject(i))
249 index = i | 0x80000000;
250 goto found;
253 if (!(index = EMFDRV_CreatePenIndirect(dc, hPen ))) return 0;
254 found:
255 emr.emr.iType = EMR_SELECTOBJECT;
256 emr.emr.nSize = sizeof(emr);
257 emr.ihObject = index;
258 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
259 return FALSE;
261 hOldPen = dc->hPen;
262 dc->hPen = hPen;
263 return hOldPen;
267 /***********************************************************************
268 * EMFDRV_SelectObject
270 HGDIOBJ EMFDRV_SelectObject( DC *dc, HGDIOBJ handle )
272 GDIOBJHDR * ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
273 HGDIOBJ ret = 0;
275 if (!ptr) return 0;
276 TRACE("hdc=%04x %04x\n", dc->hSelf, handle );
278 switch(GDIMAGIC(ptr->wMagic))
280 case PEN_MAGIC:
281 ret = EMFDRV_PEN_SelectObject( dc, handle );
282 break;
283 case BRUSH_MAGIC:
284 ret = EMFDRV_BRUSH_SelectObject( dc, handle );
285 break;
286 case FONT_MAGIC:
287 ret = EMFDRV_FONT_SelectObject( dc, handle );
288 break;
289 case BITMAP_MAGIC:
290 ret = EMFDRV_BITMAP_SelectObject( dc, handle );
291 break;
293 GDI_ReleaseObj( handle );
294 return ret;