Check brush style before printing FIXME.
[wine] / objects / pen.c
1 /*
2  * GDI pen objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24 #include <string.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "wine/wingdi16.h"
30 #include "gdi.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
34
35   /* GDI logical pen object */
36 typedef struct
37 {
38     GDIOBJHDR   header;
39     LOGPEN    logpen;
40 } PENOBJ;
41
42
43 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
44 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
45 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
46
47 static const struct gdi_obj_funcs pen_funcs =
48 {
49     PEN_SelectObject,  /* pSelectObject */
50     PEN_GetObject16,   /* pGetObject16 */
51     PEN_GetObject,     /* pGetObjectA */
52     PEN_GetObject,     /* pGetObjectW */
53     NULL,              /* pUnrealizeObject */
54     GDI_FreeObject     /* pDeleteObject */
55 };
56
57
58 /***********************************************************************
59  *           CreatePen    (GDI32.@)
60  */
61 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
62 {
63     LOGPEN logpen;
64
65     TRACE("%d %d %06lx\n", style, width, color );
66
67     logpen.lopnStyle = style;
68     logpen.lopnWidth.x = width;
69     logpen.lopnWidth.y = 0;
70     logpen.lopnColor = color;
71
72     return CreatePenIndirect( &logpen );
73 }
74
75
76 /***********************************************************************
77  *           CreatePenIndirect    (GDI32.@)
78  */
79 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
80 {
81     PENOBJ * penPtr;
82     HPEN hpen;
83
84     if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, (HGDIOBJ *)&hpen,
85                                     &pen_funcs ))) return 0;
86     penPtr->logpen.lopnStyle = pen->lopnStyle;
87     penPtr->logpen.lopnWidth = pen->lopnWidth;
88     penPtr->logpen.lopnColor = pen->lopnColor;
89     GDI_ReleaseObj( hpen );
90     return hpen;
91 }
92
93 /***********************************************************************
94  *           ExtCreatePen    (GDI32.@)
95  *
96  * FIXME: PS_USERSTYLE not handled
97  */
98
99 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
100                               const LOGBRUSH * brush, DWORD style_count,
101                               const DWORD *style_bits )
102 {
103     PENOBJ * penPtr;
104     HPEN hpen;
105
106     if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
107         FIXME("PS_USERSTYLE not handled\n");
108     if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
109         if (brush->lbHatch && ((brush->lbStyle == BS_SOLID) || (brush->lbStyle == BS_HOLLOW)))
110             FIXME("Hatches not implemented\n"); 
111
112     if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, (HGDIOBJ *)&hpen,
113                                     &pen_funcs ))) return 0;
114     penPtr->logpen.lopnStyle = style & ~PS_TYPE_MASK;
115
116     /* PS_USERSTYLE workaround */
117     if((penPtr->logpen.lopnStyle & PS_STYLE_MASK) == PS_USERSTYLE)
118        penPtr->logpen.lopnStyle =
119          (penPtr->logpen.lopnStyle & ~PS_STYLE_MASK) | PS_SOLID;
120
121     penPtr->logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
122     penPtr->logpen.lopnWidth.y = 0;
123     penPtr->logpen.lopnColor = brush->lbColor;
124     GDI_ReleaseObj( hpen );
125
126     return hpen;
127 }
128
129
130 /***********************************************************************
131  *           PEN_SelectObject
132  */
133 static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
134 {
135     HGDIOBJ ret;
136     DC *dc = DC_GetDCPtr( hdc );
137
138     if (!dc) return 0;
139     ret = dc->hPen;
140     if (dc->funcs->pSelectPen) handle = dc->funcs->pSelectPen( dc->physDev, handle );
141     if (handle) dc->hPen = handle;
142     else ret = 0;
143     GDI_ReleaseObj( hdc );
144     return ret;
145 }
146
147
148 /***********************************************************************
149  *           PEN_GetObject16
150  */
151 static INT PEN_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
152 {
153     PENOBJ *pen = obj;
154     LOGPEN16 logpen;
155
156     logpen.lopnStyle = pen->logpen.lopnStyle;
157     logpen.lopnColor = pen->logpen.lopnColor;
158     CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
159     if (count > sizeof(logpen)) count = sizeof(logpen);
160     memcpy( buffer, &logpen, count );
161     return count;
162 }
163
164
165 /***********************************************************************
166  *           PEN_GetObject
167  */
168 static INT PEN_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
169 {
170     PENOBJ *pen = obj;
171
172     if( !buffer )
173         return sizeof(pen->logpen);
174
175     if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
176     memcpy( buffer, &pen->logpen, count );
177     return count;
178 }