Bugfix: Always release the Win16Lock in TASK_Reschedule.
[wine] / objects / pen.c
1 /*
2  * GDI pen objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include <string.h>
8 #include "pen.h"
9 #include "debug.h"
10
11
12
13 /***********************************************************************
14  *           CreatePen16    (GDI.61)
15  */
16 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
17 {
18     LOGPEN logpen = { style, { width, 0 }, color };
19     TRACE(gdi, "%d %d %06lx\n", style, width, color );
20     return CreatePenIndirect( &logpen );
21 }
22
23
24 /***********************************************************************
25  *           CreatePen32    (GDI32.55)
26  */
27 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
28 {
29     LOGPEN logpen = { style, { width, 0 }, color };
30     TRACE(gdi, "%d %d %06lx\n", style, width, color );
31     return CreatePenIndirect( &logpen );
32 }
33
34
35 /***********************************************************************
36  *           CreatePenIndirect16    (GDI.62)
37  */
38 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
39 {
40     PENOBJ * penPtr;
41     HPEN16 hpen;
42
43     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
44     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
45     if (!hpen) return 0;
46     penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
47     penPtr->logpen.lopnStyle = pen->lopnStyle;
48     penPtr->logpen.lopnColor = pen->lopnColor;
49     CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
50     GDI_HEAP_UNLOCK( hpen );
51     return hpen;
52 }
53
54
55 /***********************************************************************
56  *           CreatePenIndirect32    (GDI32.56)
57  */
58 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
59 {
60     PENOBJ * penPtr;
61     HPEN hpen;
62
63     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
64     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
65     if (!hpen) return 0;
66     penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
67     penPtr->logpen.lopnStyle = pen->lopnStyle;
68     penPtr->logpen.lopnWidth = pen->lopnWidth;
69     penPtr->logpen.lopnColor = pen->lopnColor;
70     GDI_HEAP_UNLOCK( hpen );
71     return hpen;
72 }
73
74 /***********************************************************************
75  *           ExtCreatePen32    (GDI32.93)
76  *
77  * FIXME: PS_USERSTYLE not handled
78  */
79
80 HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
81                               const LOGBRUSH * brush, DWORD style_count,
82                               const DWORD *style_bits )
83 {
84     LOGPEN logpen;
85
86     if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
87         FIXME(gdi, "PS_USERSTYLE not handled\n");
88     if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
89         if (brush->lbHatch)
90             FIXME(gdi, "Hatches not implemented\n");
91
92     logpen.lopnStyle = style & ~PS_TYPE_MASK;
93     logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
94     logpen.lopnWidth.y = 0;
95     logpen.lopnColor = brush->lbColor;
96     return CreatePenIndirect( &logpen );
97 }
98
99 /***********************************************************************
100  *           PEN_GetObject16
101  */
102 INT16 PEN_GetObject16( PENOBJ * pen, INT16 count, LPSTR buffer )
103 {
104     LOGPEN16 logpen;
105     logpen.lopnStyle = pen->logpen.lopnStyle;
106     logpen.lopnColor = pen->logpen.lopnColor;
107     CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
108     if (count > sizeof(logpen)) count = sizeof(logpen);
109     memcpy( buffer, &logpen, count );
110     return count;
111 }
112
113
114 /***********************************************************************
115  *           PEN_GetObject32
116  */
117 INT PEN_GetObject( PENOBJ * pen, INT count, LPSTR buffer )
118 {
119     if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
120     memcpy( buffer, &pen->logpen, count );
121     return count;
122 }
123