gdi: Add test case for creating pens, make it pass under Wine for
[wine/wine64.git] / dlls / gdi / pen.c
blobf165c8267d9c52bfceb7245125ba51c65c17b776
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "wine/wingdi16.h"
31 #include "gdi.h"
32 #include "gdi_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
37 /* GDI logical pen object */
38 typedef struct
40 GDIOBJHDR header;
41 LOGPEN logpen;
42 } PENOBJ;
45 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
46 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
47 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
49 static const struct gdi_obj_funcs pen_funcs =
51 PEN_SelectObject, /* pSelectObject */
52 PEN_GetObject16, /* pGetObject16 */
53 PEN_GetObject, /* pGetObjectA */
54 PEN_GetObject, /* pGetObjectW */
55 NULL, /* pUnrealizeObject */
56 GDI_FreeObject /* pDeleteObject */
60 /***********************************************************************
61 * CreatePen (GDI32.@)
63 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
65 LOGPEN logpen;
67 TRACE("%d %d %06lx\n", style, width, color );
69 logpen.lopnStyle = style;
70 logpen.lopnWidth.x = width;
71 logpen.lopnWidth.y = 0;
72 logpen.lopnColor = color;
74 return CreatePenIndirect( &logpen );
78 /***********************************************************************
79 * CreatePenIndirect (GDI32.@)
81 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
83 PENOBJ * penPtr;
84 HPEN hpen;
86 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, (HGDIOBJ *)&hpen,
87 &pen_funcs ))) return 0;
88 if (pen->lopnStyle == PS_USERSTYLE || pen->lopnStyle == PS_ALTERNATE)
89 penPtr->logpen.lopnStyle = PS_SOLID;
90 else
91 penPtr->logpen.lopnStyle = pen->lopnStyle;
92 penPtr->logpen.lopnWidth.y = 0;
93 if (pen->lopnStyle == PS_NULL)
95 penPtr->logpen.lopnWidth.x = 1;
96 penPtr->logpen.lopnColor = RGB(0, 0, 0);
98 else
100 penPtr->logpen.lopnWidth.x = abs(pen->lopnWidth.x);
101 penPtr->logpen.lopnColor = pen->lopnColor;
103 GDI_ReleaseObj( hpen );
104 return hpen;
107 /***********************************************************************
108 * ExtCreatePen (GDI32.@)
110 * FIXME: PS_USERSTYLE not handled
113 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
114 const LOGBRUSH * brush, DWORD style_count,
115 const DWORD *style_bits )
117 PENOBJ * penPtr;
118 HPEN hpen;
120 if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
121 FIXME("PS_USERSTYLE not handled\n");
122 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
123 if (brush->lbHatch && ((brush->lbStyle == BS_SOLID) || (brush->lbStyle == BS_HOLLOW)))
124 FIXME("Hatches not implemented\n");
126 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, (HGDIOBJ *)&hpen,
127 &pen_funcs ))) return 0;
128 penPtr->logpen.lopnStyle = style & ~PS_TYPE_MASK;
130 /* PS_USERSTYLE workaround */
131 if((penPtr->logpen.lopnStyle & PS_STYLE_MASK) == PS_USERSTYLE)
132 penPtr->logpen.lopnStyle =
133 (penPtr->logpen.lopnStyle & ~PS_STYLE_MASK) | PS_SOLID;
135 penPtr->logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
136 penPtr->logpen.lopnWidth.y = 0;
137 penPtr->logpen.lopnColor = brush->lbColor;
138 GDI_ReleaseObj( hpen );
140 return hpen;
144 /***********************************************************************
145 * PEN_SelectObject
147 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
149 HGDIOBJ ret;
150 DC *dc = DC_GetDCPtr( hdc );
152 if (!dc) return 0;
153 ret = dc->hPen;
154 if (dc->funcs->pSelectPen) handle = dc->funcs->pSelectPen( dc->physDev, handle );
155 if (handle) dc->hPen = handle;
156 else ret = 0;
157 GDI_ReleaseObj( hdc );
158 return ret;
162 /***********************************************************************
163 * PEN_GetObject16
165 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
167 PENOBJ *pen = obj;
168 LOGPEN16 logpen;
170 logpen.lopnStyle = pen->logpen.lopnStyle;
171 logpen.lopnColor = pen->logpen.lopnColor;
172 logpen.lopnWidth.x = pen->logpen.lopnWidth.x;
173 logpen.lopnWidth.y = pen->logpen.lopnWidth.y;
174 if (count > sizeof(logpen)) count = sizeof(logpen);
175 memcpy( buffer, &logpen, count );
176 return count;
180 /***********************************************************************
181 * PEN_GetObject
183 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
185 PENOBJ *pen = obj;
187 if( !buffer )
188 return sizeof(pen->logpen);
190 switch (count)
192 case sizeof(EXTLOGPEN):
193 FIXME("extended pens not supported\n");
194 return 0;
196 case sizeof(LOGPEN):
197 memcpy( buffer, &pen->logpen, sizeof(LOGPEN) );
198 return sizeof(LOGPEN);
200 default:
201 break;
203 return 0;