Moved metafiles and win16 drivers to dlls/gdi.
[wine/testsucceed.git] / dlls / gdi / enhmfdrv / objects.c
blobe108cdee7cc143b49203b1b55f0be3aa199892ac
1 /*
2 * Enhanced MetaFile objects
4 * Copyright 1999 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "bitmap.h"
26 #include "enhmfdrv/enhmetafiledrv.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
31 /***********************************************************************
32 * EMFDRV_BITMAP_SelectObject
34 static HBITMAP EMFDRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap )
36 return 0;
40 /***********************************************************************
41 * EMFDRV_CreateBrushIndirect
43 DWORD EMFDRV_CreateBrushIndirect( DC *dc, HBRUSH hBrush )
45 DWORD index = 0;
46 LOGBRUSH logbrush;
48 if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return 0;
50 switch (logbrush.lbStyle) {
51 case BS_SOLID:
52 case BS_HATCHED:
53 case BS_NULL:
55 EMRCREATEBRUSHINDIRECT emr;
56 emr.emr.iType = EMR_CREATEBRUSHINDIRECT;
57 emr.emr.nSize = sizeof(emr);
58 emr.ihBrush = index = EMFDRV_AddHandleDC( dc );
59 emr.lb = logbrush;
61 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
62 index = 0;
64 break;
65 case BS_DIBPATTERN:
67 EMRCREATEDIBPATTERNBRUSHPT *emr;
68 DWORD bmSize, biSize, size;
69 BITMAPINFO *info = GlobalLock16(logbrush.lbHatch);
71 if (info->bmiHeader.biCompression)
72 bmSize = info->bmiHeader.biSizeImage;
73 else
74 bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
75 info->bmiHeader.biHeight,
76 info->bmiHeader.biBitCount);
77 biSize = DIB_BitmapInfoSize(info, LOWORD(logbrush.lbColor));
78 size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize;
79 emr = HeapAlloc( GetProcessHeap(), 0, size );
80 if(!emr) break;
81 emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
82 emr->emr.nSize = size;
83 emr->ihBrush = index = EMFDRV_AddHandleDC( dc );
84 emr->iUsage = LOWORD(logbrush.lbColor);
85 emr->offBmi = sizeof(EMRCREATEDIBPATTERNBRUSHPT);
86 emr->cbBmi = biSize;
87 emr->offBits = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize;
88 memcpy((char *)emr + sizeof(EMRCREATEDIBPATTERNBRUSHPT), info,
89 biSize + bmSize );
91 if(!EMFDRV_WriteRecord( dc, &emr->emr ))
92 index = 0;
93 HeapFree( GetProcessHeap(), 0, emr );
94 GlobalUnlock16(logbrush.lbHatch);
96 break;
98 case BS_PATTERN:
99 FIXME("Unsupported style %x\n",
100 logbrush.lbStyle);
101 break;
102 default:
103 FIXME("Unknown style %x\n", logbrush.lbStyle);
104 break;
106 return index;
110 /***********************************************************************
111 * EMFDRV_BRUSH_SelectObject
113 static HBRUSH EMFDRV_BRUSH_SelectObject(DC *dc, HBRUSH hBrush )
115 EMRSELECTOBJECT emr;
116 DWORD index;
117 HBRUSH hOldBrush;
118 int i;
120 /* If the object is a stock brush object, do not need to create it.
121 * See definitions in wingdi.h for range of stock brushes.
122 * We do however have to handle setting the higher order bit to
123 * designate that this is a stock object.
125 for (i = WHITE_BRUSH; i <= NULL_BRUSH; i++)
127 if (hBrush == GetStockObject(i))
129 index = i | 0x80000000;
130 goto found;
133 if (!(index = EMFDRV_CreateBrushIndirect(dc, hBrush ))) return 0;
135 found:
136 emr.emr.iType = EMR_SELECTOBJECT;
137 emr.emr.nSize = sizeof(emr);
138 emr.ihObject = index;
139 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
140 return FALSE;
142 hOldBrush = dc->hBrush;
143 dc->hBrush = hBrush;
144 return hOldBrush;
148 /******************************************************************
149 * EMFDRV_CreateFontIndirect
151 static BOOL EMFDRV_CreateFontIndirect(DC *dc, HFONT hFont )
153 DWORD index = 0;
154 EMREXTCREATEFONTINDIRECTW emr;
155 int i;
157 if (!GetObjectW( hFont, sizeof(emr.elfw.elfLogFont), &emr.elfw.elfLogFont )) return 0;
159 emr.emr.iType = EMR_EXTCREATEFONTINDIRECTW;
160 emr.emr.nSize = (sizeof(emr) + 3) / 4 * 4;
161 emr.ihFont = index = EMFDRV_AddHandleDC( dc );
162 emr.elfw.elfFullName[0] = '\0';
163 emr.elfw.elfStyle[0] = '\0';
164 emr.elfw.elfVersion = 0;
165 emr.elfw.elfStyleSize = 0;
166 emr.elfw.elfMatch = 0;
167 emr.elfw.elfReserved = 0;
168 for(i = 0; i < ELF_VENDOR_SIZE; i++)
169 emr.elfw.elfVendorId[i] = 0;
170 emr.elfw.elfCulture = PAN_CULTURE_LATIN;
171 emr.elfw.elfPanose.bFamilyType = PAN_NO_FIT;
172 emr.elfw.elfPanose.bSerifStyle = PAN_NO_FIT;
173 emr.elfw.elfPanose.bWeight = PAN_NO_FIT;
174 emr.elfw.elfPanose.bProportion = PAN_NO_FIT;
175 emr.elfw.elfPanose.bContrast = PAN_NO_FIT;
176 emr.elfw.elfPanose.bStrokeVariation = PAN_NO_FIT;
177 emr.elfw.elfPanose.bArmStyle = PAN_NO_FIT;
178 emr.elfw.elfPanose.bLetterform = PAN_NO_FIT;
179 emr.elfw.elfPanose.bMidline = PAN_NO_FIT;
180 emr.elfw.elfPanose.bXHeight = PAN_NO_FIT;
182 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
183 index = 0;
184 return index;
188 /***********************************************************************
189 * EMFDRV_FONT_SelectObject
191 static HFONT EMFDRV_FONT_SelectObject( DC * dc, HFONT hFont )
193 EMRSELECTOBJECT emr;
194 DWORD index;
195 int i;
197 /* If the object is a stock font object, do not need to create it.
198 * See definitions in wingdi.h for range of stock fonts.
199 * We do however have to handle setting the higher order bit to
200 * designate that this is a stock object.
203 for (i = OEM_FIXED_FONT; i <= DEFAULT_GUI_FONT; i++)
205 if (i != DEFAULT_PALETTE && hFont == GetStockObject(i))
207 index = i | 0x80000000;
208 goto found;
211 if (!(index = EMFDRV_CreateFontIndirect(dc, hFont ))) return GDI_ERROR;
212 found:
213 emr.emr.iType = EMR_SELECTOBJECT;
214 emr.emr.nSize = sizeof(emr);
215 emr.ihObject = index;
216 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
217 return GDI_ERROR;
219 return FALSE;
224 /******************************************************************
225 * EMFDRV_CreatePenIndirect
227 static HPEN EMFDRV_CreatePenIndirect(DC *dc, HPEN hPen )
229 EMRCREATEPEN emr;
230 DWORD index = 0;
232 if (!GetObjectA( hPen, sizeof(emr.lopn), &emr.lopn )) return 0;
234 emr.emr.iType = EMR_CREATEPEN;
235 emr.emr.nSize = sizeof(emr);
236 emr.ihPen = index = EMFDRV_AddHandleDC( dc );
238 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
239 index = 0;
240 return index;
243 /******************************************************************
244 * EMFDRV_PEN_SelectObject
246 static HPEN EMFDRV_PEN_SelectObject(DC *dc, HPEN hPen )
248 EMRSELECTOBJECT emr;
249 DWORD index;
250 HPEN hOldPen;
251 int i;
253 /* If the object is a stock pen object, do not need to create it.
254 * See definitions in wingdi.h for range of stock pens.
255 * We do however have to handle setting the higher order bit to
256 * designate that this is a stock object.
259 for (i = WHITE_PEN; i <= NULL_PEN; i++)
261 if (hPen == GetStockObject(i))
263 index = i | 0x80000000;
264 goto found;
267 if (!(index = EMFDRV_CreatePenIndirect(dc, hPen ))) return 0;
268 found:
269 emr.emr.iType = EMR_SELECTOBJECT;
270 emr.emr.nSize = sizeof(emr);
271 emr.ihObject = index;
272 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
273 return FALSE;
275 hOldPen = dc->hPen;
276 dc->hPen = hPen;
277 return hOldPen;
281 /***********************************************************************
282 * EMFDRV_SelectObject
284 HGDIOBJ EMFDRV_SelectObject( DC *dc, HGDIOBJ handle )
286 GDIOBJHDR * ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
287 HGDIOBJ ret = 0;
289 if (!ptr) return 0;
290 TRACE("hdc=%04x %04x\n", dc->hSelf, handle );
292 switch(GDIMAGIC(ptr->wMagic))
294 case PEN_MAGIC:
295 ret = EMFDRV_PEN_SelectObject( dc, handle );
296 break;
297 case BRUSH_MAGIC:
298 ret = EMFDRV_BRUSH_SelectObject( dc, handle );
299 break;
300 case FONT_MAGIC:
301 ret = EMFDRV_FONT_SelectObject( dc, handle );
302 break;
303 case BITMAP_MAGIC:
304 ret = EMFDRV_BITMAP_SelectObject( dc, handle );
305 break;
307 GDI_ReleaseObj( handle );
308 return ret;