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