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
31 #include "wine/wingdi16.h"
32 #include "gdi_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
37 /* GDI logical pen object */
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 /***********************************************************************
63 HPEN WINAPI
CreatePen( INT style
, INT width
, COLORREF color
)
67 TRACE("%d %d %06x\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
)
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
.elpPenStyle
= PS_SOLID
;
91 penPtr
->logpen
.elpPenStyle
= pen
->lopnStyle
;
92 if (pen
->lopnStyle
== PS_NULL
)
94 penPtr
->logpen
.elpWidth
= 1;
95 penPtr
->logpen
.elpColor
= RGB(0, 0, 0);
99 penPtr
->logpen
.elpWidth
= abs(pen
->lopnWidth
.x
);
100 penPtr
->logpen
.elpColor
= pen
->lopnColor
;
102 penPtr
->logpen
.elpBrushStyle
= BS_SOLID
;
103 penPtr
->logpen
.elpHatch
= 0;
104 penPtr
->logpen
.elpNumEntries
= 0;
105 penPtr
->logpen
.elpStyleEntry
[0] = 0;
107 GDI_ReleaseObj( hpen
);
111 /***********************************************************************
112 * ExtCreatePen (GDI32.@)
114 * FIXME: PS_USERSTYLE not handled
117 HPEN WINAPI
ExtCreatePen( DWORD style
, DWORD width
,
118 const LOGBRUSH
* brush
, DWORD style_count
,
119 const DWORD
*style_bits
)
124 if ((style
& PS_STYLE_MASK
) == PS_USERSTYLE
)
126 if (!style_count
|| !style_bits
)
128 SetLastError(ERROR_INVALID_PARAMETER
);
131 /* FIXME: PS_USERSTYLE workaround */
132 FIXME("PS_USERSTYLE not handled\n");
133 style
= (style
& ~PS_STYLE_MASK
) | PS_SOLID
;
137 if (style_count
|| style_bits
)
139 SetLastError(ERROR_INVALID_PARAMETER
);
144 if ((style
& PS_STYLE_MASK
) == PS_NULL
)
145 return CreatePen( PS_NULL
, 0, brush
->lbColor
);
147 if ((style
& PS_TYPE_MASK
) == PS_GEOMETRIC
)
149 /* PS_ALTERNATE is applicable only for cosmetic pens */
150 if ((style
& PS_STYLE_MASK
) == PS_ALTERNATE
)
152 SetLastError(ERROR_INVALID_PARAMETER
);
156 if (brush
->lbHatch
&& ((brush
->lbStyle
== BS_SOLID
) || (brush
->lbStyle
== BS_HOLLOW
)))
158 static int fixme_hatches_shown
;
159 if (!fixme_hatches_shown
++) FIXME("Hatches not implemented\n");
164 /* PS_INSIDEFRAME is applicable only for gemetric pens */
165 if ((style
& PS_STYLE_MASK
) == PS_INSIDEFRAME
|| width
!= 1)
167 SetLastError(ERROR_INVALID_PARAMETER
);
172 if (!(penPtr
= GDI_AllocObject( sizeof(PENOBJ
) +
173 style_count
* sizeof(DWORD
) - sizeof(penPtr
->logpen
.elpStyleEntry
),
174 EXT_PEN_MAGIC
, (HGDIOBJ
*)&hpen
,
175 &pen_funcs
))) return 0;
177 penPtr
->logpen
.elpPenStyle
= style
;
178 penPtr
->logpen
.elpWidth
= abs(width
);
179 penPtr
->logpen
.elpBrushStyle
= brush
->lbStyle
;
180 penPtr
->logpen
.elpColor
= brush
->lbColor
;
181 penPtr
->logpen
.elpHatch
= brush
->lbHatch
;
182 penPtr
->logpen
.elpNumEntries
= style_count
;
183 memcpy(penPtr
->logpen
.elpStyleEntry
, style_bits
, style_count
* sizeof(DWORD
));
185 GDI_ReleaseObj( hpen
);
191 /***********************************************************************
194 static HGDIOBJ
PEN_SelectObject( HGDIOBJ handle
, void *obj
, HDC hdc
)
197 DC
*dc
= DC_GetDCPtr( hdc
);
201 if (dc
->funcs
->pSelectPen
) handle
= dc
->funcs
->pSelectPen( dc
->physDev
, handle
);
202 if (handle
) dc
->hPen
= handle
;
204 GDI_ReleaseObj( hdc
);
209 /***********************************************************************
212 static INT
PEN_GetObject16( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
217 if (!buffer
) return sizeof(LOGPEN16
);
219 if (count
< sizeof(LOGPEN16
)) return 0;
222 logpen
->lopnStyle
= pen
->logpen
.elpPenStyle
;
223 logpen
->lopnColor
= pen
->logpen
.elpColor
;
224 logpen
->lopnWidth
.x
= pen
->logpen
.elpWidth
;
225 logpen
->lopnWidth
.y
= 0;
227 return sizeof(LOGPEN16
);
231 /***********************************************************************
234 static INT
PEN_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
238 switch (GDIMAGIC(pen
->header
.wMagic
))
244 if (!buffer
) return sizeof(LOGPEN
);
246 if (count
< sizeof(LOGPEN
)) return 0;
248 if ((pen
->logpen
.elpPenStyle
& PS_STYLE_MASK
) == PS_NULL
&&
249 count
== sizeof(EXTLOGPEN
))
251 EXTLOGPEN
*elp
= buffer
;
252 memcpy(elp
, &pen
->logpen
, sizeof(EXTLOGPEN
));
254 return sizeof(EXTLOGPEN
);
258 lp
->lopnStyle
= pen
->logpen
.elpPenStyle
;
259 lp
->lopnColor
= pen
->logpen
.elpColor
;
260 lp
->lopnWidth
.x
= pen
->logpen
.elpWidth
;
262 return sizeof(LOGPEN
);
267 INT size
= sizeof(EXTLOGPEN
) + pen
->logpen
.elpNumEntries
* sizeof(DWORD
) - sizeof(pen
->logpen
.elpStyleEntry
);
269 if (!buffer
) return size
;
271 if (count
< size
) return 0;
272 memcpy(buffer
, &pen
->logpen
, size
);