crypt32: Add and use HCRYPTPROV_LEGACY and HCRYPTPROV_OR_NCRYPT_KEY_HANDLE.
[wine] / dlls / gdiplus / brush.c
1 /*
2  * Copyright (C) 2007 Google (Evan Stade)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "windef.h"
20 #include "wingdi.h"
21
22 #include "objbase.h"
23
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
29
30 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
31 {
32     if(!brush || !clone)
33         return InvalidParameter;
34
35     switch(brush->bt){
36         case BrushTypeSolidColor:
37             *clone = GdipAlloc(sizeof(GpSolidFill));
38             if (!*clone) return OutOfMemory;
39
40             memcpy(*clone, brush, sizeof(GpSolidFill));
41
42             (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
43             break;
44         default:
45             return NotImplemented;
46     }
47
48     return Ok;
49 }
50
51 /* FIXME: path gradient brushes not truly supported (drawn as solid brushes) */
52 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
53     GpPathGradient **grad)
54 {
55     COLORREF col = ARGB2COLORREF(0xffffffff);
56
57     if(!path || !grad)
58         return InvalidParameter;
59
60     *grad = GdipAlloc(sizeof(GpPathGradient));
61     if (!*grad) return OutOfMemory;
62
63     (*grad)->brush.lb.lbStyle = BS_SOLID;
64     (*grad)->brush.lb.lbColor = col;
65     (*grad)->brush.lb.lbHatch = 0;
66
67     (*grad)->brush.gdibrush = CreateSolidBrush(col);
68     (*grad)->brush.bt = BrushTypeSolidColor;
69     (*grad)->centercolor = 0xffffffff;
70     (*grad)->wrap = WrapModeClamp;
71
72     return Ok;
73 }
74
75 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
76 {
77     COLORREF col = ARGB2COLORREF(color);
78
79     if(!sf)  return InvalidParameter;
80
81     *sf = GdipAlloc(sizeof(GpSolidFill));
82     if (!*sf) return OutOfMemory;
83
84     (*sf)->brush.lb.lbStyle = BS_SOLID;
85     (*sf)->brush.lb.lbColor = col;
86     (*sf)->brush.lb.lbHatch = 0;
87
88     (*sf)->brush.gdibrush = CreateSolidBrush(col);
89     (*sf)->brush.bt = BrushTypeSolidColor;
90     (*sf)->color = color;
91
92     return Ok;
93 }
94
95 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
96 {
97     if(!brush || !type)  return InvalidParameter;
98
99     *type = brush->bt;
100
101     return Ok;
102 }
103
104 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
105 {
106     if(!brush)  return InvalidParameter;
107
108     DeleteObject(brush->gdibrush);
109     GdipFree(brush);
110
111     return Ok;
112 }
113
114 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
115 {
116     if(!sf || !argb)
117         return InvalidParameter;
118
119     *argb = sf->color;
120
121     return Ok;
122 }
123
124 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
125     ARGB argb)
126 {
127     if(!grad)
128         return InvalidParameter;
129
130     grad->centercolor = argb;
131     grad->brush.lb.lbColor = ARGB2COLORREF(argb);
132
133     DeleteObject(grad->brush.gdibrush);
134     grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
135
136     return Ok;
137 }
138
139 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
140     GpWrapMode wrap)
141 {
142     if(!grad)
143         return InvalidParameter;
144
145     grad->wrap = wrap;
146
147     return Ok;
148 }
149
150 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
151 {
152     if(!sf)
153         return InvalidParameter;
154
155     sf->color = argb;
156     sf->brush.lb.lbColor = ARGB2COLORREF(argb);
157
158     DeleteObject(sf->brush.gdibrush);
159     sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
160
161     return Ok;
162 }