- stubs for SHLWAPI.295 (create a URL shortcut ?) and SHLWAPI.394
[wine/multimedia.git] / objects / pen.c
blobfdb758040bf64e08ddd3d96e247eec425ce36128
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 <string.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "wine/wingdi16.h"
28 #include "gdi.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
33 /* GDI logical pen object */
34 typedef struct
36 GDIOBJHDR header;
37 LOGPEN logpen;
38 } PENOBJ;
41 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
42 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
43 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
45 static const struct gdi_obj_funcs pen_funcs =
47 PEN_SelectObject, /* pSelectObject */
48 PEN_GetObject16, /* pGetObject16 */
49 PEN_GetObject, /* pGetObjectA */
50 PEN_GetObject, /* pGetObjectW */
51 NULL, /* pUnrealizeObject */
52 GDI_FreeObject /* pDeleteObject */
55 /***********************************************************************
56 * CreatePen (GDI.61)
58 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
60 LOGPEN logpen;
62 TRACE("%d %d %06lx\n", style, width, color );
64 logpen.lopnStyle = style;
65 logpen.lopnWidth.x = width;
66 logpen.lopnWidth.y = 0;
67 logpen.lopnColor = color;
69 return CreatePenIndirect( &logpen );
73 /***********************************************************************
74 * CreatePen (GDI32.@)
76 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
78 LOGPEN logpen;
80 TRACE("%d %d %06lx\n", style, width, color );
82 logpen.lopnStyle = style;
83 logpen.lopnWidth.x = width;
84 logpen.lopnWidth.y = 0;
85 logpen.lopnColor = color;
87 return CreatePenIndirect( &logpen );
91 /***********************************************************************
92 * CreatePenIndirect (GDI.62)
94 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
96 PENOBJ * penPtr;
97 HPEN hpen;
99 if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
100 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen, &pen_funcs ))) return 0;
101 penPtr->logpen.lopnStyle = pen->lopnStyle;
102 penPtr->logpen.lopnColor = pen->lopnColor;
103 CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
104 GDI_ReleaseObj( hpen );
105 return hpen;
109 /***********************************************************************
110 * CreatePenIndirect (GDI32.@)
112 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
114 PENOBJ * penPtr;
115 HPEN hpen;
117 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen, &pen_funcs ))) return 0;
118 penPtr->logpen.lopnStyle = pen->lopnStyle;
119 penPtr->logpen.lopnWidth = pen->lopnWidth;
120 penPtr->logpen.lopnColor = pen->lopnColor;
121 GDI_ReleaseObj( hpen );
122 return hpen;
125 /***********************************************************************
126 * ExtCreatePen (GDI32.@)
128 * FIXME: PS_USERSTYLE not handled
131 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
132 const LOGBRUSH * brush, DWORD style_count,
133 const DWORD *style_bits )
135 PENOBJ * penPtr;
136 HPEN hpen;
138 if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
139 FIXME("PS_USERSTYLE not handled\n");
140 if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
141 if (brush->lbHatch)
142 FIXME("Hatches not implemented\n");
144 if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen, &pen_funcs ))) return 0;
145 penPtr->logpen.lopnStyle = style & ~PS_TYPE_MASK;
147 /* PS_USERSTYLE workaround */
148 if((penPtr->logpen.lopnStyle & PS_STYLE_MASK) == PS_USERSTYLE)
149 penPtr->logpen.lopnStyle =
150 (penPtr->logpen.lopnStyle & ~PS_STYLE_MASK) | PS_SOLID;
152 penPtr->logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
153 penPtr->logpen.lopnWidth.y = 0;
154 penPtr->logpen.lopnColor = brush->lbColor;
155 GDI_ReleaseObj( hpen );
157 return hpen;
161 /***********************************************************************
162 * PEN_SelectObject
164 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
166 HGDIOBJ ret;
167 DC *dc = DC_GetDCPtr( hdc );
169 if (!dc) return 0;
170 ret = dc->hPen;
171 if (dc->funcs->pSelectPen) handle = dc->funcs->pSelectPen( dc->physDev, handle );
172 if (handle) dc->hPen = handle;
173 else ret = 0;
174 GDI_ReleaseObj( hdc );
175 return ret;
179 /***********************************************************************
180 * PEN_GetObject16
182 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
184 PENOBJ *pen = obj;
185 LOGPEN16 logpen;
187 logpen.lopnStyle = pen->logpen.lopnStyle;
188 logpen.lopnColor = pen->logpen.lopnColor;
189 CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
190 if (count > sizeof(logpen)) count = sizeof(logpen);
191 memcpy( buffer, &logpen, count );
192 return count;
196 /***********************************************************************
197 * PEN_GetObject
199 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
201 PENOBJ *pen = obj;
203 if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
204 memcpy( buffer, &pen->logpen, count );
205 return count;