- Implement CCM_{GET|SET}COLORSCHEME.
[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 <string.h>
24
25 #include "windef.h"
26 #include "wingdi.h"
27
28 #include "wine/wingdi16.h"
29 #include "pen.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
34
35
36
37 /***********************************************************************
38  *           CreatePen    (GDI.61)
39  */
40 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
41 {
42     LOGPEN logpen;
43
44     TRACE("%d %d %06lx\n", style, width, color );
45
46     logpen.lopnStyle = style; 
47     logpen.lopnWidth.x = width;
48     logpen.lopnWidth.y = 0;
49     logpen.lopnColor = color;
50
51     return CreatePenIndirect( &logpen );
52 }
53
54
55 /***********************************************************************
56  *           CreatePen    (GDI32.@)
57  */
58 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
59 {
60     LOGPEN logpen;
61
62     TRACE("%d %d %06lx\n", style, width, color );
63
64     logpen.lopnStyle = style; 
65     logpen.lopnWidth.x = width;
66     logpen.lopnWidth.y = 0;
67     logpen.lopnColor = color;
68
69     return CreatePenIndirect( &logpen );
70 }
71
72
73 /***********************************************************************
74  *           CreatePenIndirect    (GDI.62)
75  */
76 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
77 {
78     PENOBJ * penPtr;
79     HPEN hpen;
80
81     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
82     if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen ))) return 0;
83     penPtr->logpen.lopnStyle = pen->lopnStyle;
84     penPtr->logpen.lopnColor = pen->lopnColor;
85     CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
86     GDI_ReleaseObj( hpen );
87     return hpen;
88 }
89
90
91 /***********************************************************************
92  *           CreatePenIndirect    (GDI32.@)
93  */
94 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
95 {
96     PENOBJ * penPtr;
97     HPEN hpen;
98
99     if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen ))) return 0;
100     penPtr->logpen.lopnStyle = pen->lopnStyle;
101     penPtr->logpen.lopnWidth = pen->lopnWidth;
102     penPtr->logpen.lopnColor = pen->lopnColor;
103     GDI_ReleaseObj( hpen );
104     return hpen;
105 }
106
107 /***********************************************************************
108  *           ExtCreatePen    (GDI32.@)
109  *
110  * FIXME: PS_USERSTYLE not handled
111  */
112
113 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
114                               const LOGBRUSH * brush, DWORD style_count,
115                               const DWORD *style_bits )
116 {
117     PENOBJ * penPtr;
118     HPEN hpen;
119
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)
124             FIXME("Hatches not implemented\n");
125
126     if (!(penPtr = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC, &hpen ))) return 0;
127     penPtr->logpen.lopnStyle = style & ~PS_TYPE_MASK; 
128     
129     /* PS_USERSTYLE workaround */   
130     if((penPtr->logpen.lopnStyle & PS_STYLE_MASK) == PS_USERSTYLE)
131        penPtr->logpen.lopnStyle = 
132          (penPtr->logpen.lopnStyle & ~PS_STYLE_MASK) | PS_SOLID;
133
134     penPtr->logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1; 
135     penPtr->logpen.lopnWidth.y = 0;
136     penPtr->logpen.lopnColor = brush->lbColor;
137     GDI_ReleaseObj( hpen );
138
139     return hpen;
140 }
141
142 /***********************************************************************
143  *           PEN_GetObject16
144  */
145 INT16 PEN_GetObject16( PENOBJ * pen, INT16 count, LPSTR buffer )
146 {
147     LOGPEN16 logpen;
148     logpen.lopnStyle = pen->logpen.lopnStyle;
149     logpen.lopnColor = pen->logpen.lopnColor;
150     CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
151     if (count > sizeof(logpen)) count = sizeof(logpen);
152     memcpy( buffer, &logpen, count );
153     return count;
154 }
155
156
157 /***********************************************************************
158  *           PEN_GetObject
159  */
160 INT PEN_GetObject( PENOBJ * pen, INT count, LPSTR buffer )
161 {
162     if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
163     memcpy( buffer, &pen->logpen, count );
164     return count;
165 }
166