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