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
30 #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 %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
)
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
;
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);
100 penPtr
->logpen
.lopnWidth
.x
= abs(pen
->lopnWidth
.x
);
101 penPtr
->logpen
.lopnColor
= pen
->lopnColor
;
103 GDI_ReleaseObj( 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
)
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
);
144 /***********************************************************************
147 static HGDIOBJ
PEN_SelectObject( HGDIOBJ handle
, void *obj
, HDC hdc
)
150 DC
*dc
= DC_GetDCPtr( hdc
);
154 if (dc
->funcs
->pSelectPen
) handle
= dc
->funcs
->pSelectPen( dc
->physDev
, handle
);
155 if (handle
) dc
->hPen
= handle
;
157 GDI_ReleaseObj( hdc
);
162 /***********************************************************************
165 static INT
PEN_GetObject16( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
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
);
180 /***********************************************************************
183 static INT
PEN_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
188 return sizeof(pen
->logpen
);
192 case sizeof(EXTLOGPEN
):
193 FIXME("extended pens not supported\n");
197 memcpy( buffer
, &pen
->logpen
, sizeof(LOGPEN
) );
198 return sizeof(LOGPEN
);