shlwapi: Add tests for PathCombineA.
[wine/dcerpc.git] / dlls / gdi / pen.c
blob982f2fdec1aef22167f95c5098ff0ab3f652e645
1 /*
2 * GDI pen objects
4 * Copyright 1993 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <assert.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "wine/wingdi16.h"
32 #include "gdi.h"
33 #include "gdi_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
38 /* GDI logical pen object */
39 typedef struct
41 GDIOBJHDR header;
42 EXTLOGPEN logpen;
43 } PENOBJ;
46 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
47 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
48 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
50 static const struct gdi_obj_funcs pen_funcs =
52 PEN_SelectObject, /* pSelectObject */
53 PEN_GetObject16, /* pGetObject16 */
54 PEN_GetObject, /* pGetObjectA */
55 PEN_GetObject, /* pGetObjectW */
56 NULL, /* pUnrealizeObject */
57 GDI_FreeObject /* pDeleteObject */
61 /***********************************************************************
62 * CreatePen (GDI32.@)
64 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
66 LOGPEN logpen;
68 TRACE("%d %d %06lx\n", style, width, color );
70 logpen.lopnStyle = style;
71 logpen.lopnWidth.x = width;
72 logpen.lopnWidth.y = 0;
73 logpen.lopnColor = color;
75 return CreatePenIndirect( &logpen );
79 /***********************************************************************
80 * CreatePenIndirect (GDI32.@)
82 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
84 PENOBJ * penPtr;
85 HPEN hpen;
87 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, (HGDIOBJ *)&hpen,
88 &pen_funcs ))) return 0;
89 if (pen->lopnStyle == PS_USERSTYLE || pen->lopnStyle == PS_ALTERNATE)
90 penPtr->logpen.elpPenStyle = PS_SOLID;
91 else
92 penPtr->logpen.elpPenStyle = pen->lopnStyle;
93 if (pen->lopnStyle == PS_NULL)
95 penPtr->logpen.elpWidth = 1;
96 penPtr->logpen.elpColor = RGB(0, 0, 0);
98 else
100 penPtr->logpen.elpWidth = abs(pen->lopnWidth.x);
101 penPtr->logpen.elpColor = pen->lopnColor;
103 penPtr->logpen.elpBrushStyle = BS_SOLID;
104 penPtr->logpen.elpHatch = 0;
105 penPtr->logpen.elpNumEntries = 0;
106 penPtr->logpen.elpStyleEntry[0] = 0;
108 GDI_ReleaseObj( hpen );
109 return hpen;
112 /***********************************************************************
113 * ExtCreatePen (GDI32.@)
115 * FIXME: PS_USERSTYLE not handled
118 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
119 const LOGBRUSH * brush, DWORD style_count,
120 const DWORD *style_bits )
122 PENOBJ * penPtr;
123 HPEN hpen;
125 if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
127 if (!style_count || !style_bits)
129 SetLastError(ERROR_INVALID_PARAMETER);
130 return 0;
132 /* FIXME: PS_USERSTYLE workaround */
133 FIXME("PS_USERSTYLE not handled\n");
134 style = (style & ~PS_STYLE_MASK) | PS_SOLID;
136 else
138 if (style_count || style_bits)
140 SetLastError(ERROR_INVALID_PARAMETER);
141 return 0;
145 if ((style & PS_STYLE_MASK) == PS_NULL)
146 return CreatePen( PS_NULL, 0, brush->lbColor );
148 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
150 /* PS_ALTERNATE is applicable only for cosmetic pens */
151 if ((style & PS_STYLE_MASK) == PS_ALTERNATE)
153 SetLastError(ERROR_INVALID_PARAMETER);
154 return 0;
157 if (brush->lbHatch && ((brush->lbStyle == BS_SOLID) || (brush->lbStyle == BS_HOLLOW)))
159 static int fixme_hatches_shown;
160 if (!fixme_hatches_shown++) FIXME("Hatches not implemented\n");
163 else
165 /* PS_INSIDEFRAME is applicable only for gemetric pens */
166 if ((style & PS_STYLE_MASK) == PS_INSIDEFRAME || width != 1)
168 SetLastError(ERROR_INVALID_PARAMETER);
169 return 0;
173 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ) +
174 style_count * sizeof(DWORD) - sizeof(penPtr->logpen.elpStyleEntry),
175 EXT_PEN_MAGIC, (HGDIOBJ *)&hpen,
176 &pen_funcs ))) return 0;
178 penPtr->logpen.elpPenStyle = style;
179 penPtr->logpen.elpWidth = abs(width);
180 penPtr->logpen.elpBrushStyle = brush->lbStyle;
181 penPtr->logpen.elpColor = brush->lbColor;
182 penPtr->logpen.elpHatch = brush->lbHatch;
183 penPtr->logpen.elpNumEntries = style_count;
184 memcpy(penPtr->logpen.elpStyleEntry, style_bits, style_count * sizeof(DWORD));
186 GDI_ReleaseObj( hpen );
188 return hpen;
192 /***********************************************************************
193 * PEN_SelectObject
195 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
197 HGDIOBJ ret;
198 DC *dc = DC_GetDCPtr( hdc );
200 if (!dc) return 0;
201 ret = dc->hPen;
202 if (dc->funcs->pSelectPen) handle = dc->funcs->pSelectPen( dc->physDev, handle );
203 if (handle) dc->hPen = handle;
204 else ret = 0;
205 GDI_ReleaseObj( hdc );
206 return ret;
210 /***********************************************************************
211 * PEN_GetObject16
213 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
215 PENOBJ *pen = obj;
216 LOGPEN16 *logpen;
218 if (!buffer) return sizeof(LOGPEN16);
220 if (count < sizeof(LOGPEN16)) return 0;
222 logpen = buffer;
223 logpen->lopnStyle = pen->logpen.elpPenStyle;
224 logpen->lopnColor = pen->logpen.elpColor;
225 logpen->lopnWidth.x = pen->logpen.elpWidth;
226 logpen->lopnWidth.y = 0;
228 return sizeof(LOGPEN16);
232 /***********************************************************************
233 * PEN_GetObject
235 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
237 PENOBJ *pen = obj;
239 switch (GDIMAGIC(pen->header.wMagic))
241 case PEN_MAGIC:
243 LOGPEN *lp;
245 if (!buffer) return sizeof(LOGPEN);
247 if (count < sizeof(LOGPEN)) return 0;
249 if ((pen->logpen.elpPenStyle & PS_STYLE_MASK) == PS_NULL &&
250 count == sizeof(EXTLOGPEN))
252 EXTLOGPEN *elp = buffer;
253 memcpy(elp, &pen->logpen, sizeof(EXTLOGPEN));
254 elp->elpWidth = 0;
255 return sizeof(EXTLOGPEN);
258 lp = buffer;
259 lp->lopnStyle = pen->logpen.elpPenStyle;
260 lp->lopnColor = pen->logpen.elpColor;
261 lp->lopnWidth.x = pen->logpen.elpWidth;
262 lp->lopnWidth.y = 0;
263 return sizeof(LOGPEN);
266 case EXT_PEN_MAGIC:
268 INT size = sizeof(EXTLOGPEN) + pen->logpen.elpNumEntries * sizeof(DWORD) - sizeof(pen->logpen.elpStyleEntry);
270 if (!buffer) return size;
272 if (count < size) return 0;
273 memcpy(buffer, &pen->logpen, size);
274 return size;
277 default:
278 break;
280 assert(0);
281 return 0;