Added optional debugging code in object management.
[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 "debugtools.h"
10
11 DEFAULT_DEBUG_CHANNEL(gdi)
12
13
14
15 /***********************************************************************
16  *           CreatePen16    (GDI.61)
17  */
18 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
19 {
20     LOGPEN logpen;
21
22     TRACE("%d %d %06lx\n", style, width, color );
23
24     logpen.lopnStyle = style; 
25     logpen.lopnWidth.x = width;
26     logpen.lopnWidth.y = 0;
27     logpen.lopnColor = color;
28
29     return CreatePenIndirect( &logpen );
30 }
31
32
33 /***********************************************************************
34  *           CreatePen32    (GDI32.55)
35  */
36 HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
37 {
38     LOGPEN logpen;
39
40     TRACE("%d %d %06lx\n", style, width, color );
41
42     logpen.lopnStyle = style; 
43     logpen.lopnWidth.x = width;
44     logpen.lopnWidth.y = 0;
45     logpen.lopnColor = color;
46
47     return CreatePenIndirect( &logpen );
48 }
49
50
51 /***********************************************************************
52  *           CreatePenIndirect16    (GDI.62)
53  */
54 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
55 {
56     PENOBJ * penPtr;
57     HPEN16 hpen;
58
59     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
60     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
61     if (!hpen) return 0;
62     penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
63     penPtr->logpen.lopnStyle = pen->lopnStyle;
64     penPtr->logpen.lopnColor = pen->lopnColor;
65     CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
66     GDI_HEAP_UNLOCK( hpen );
67     return hpen;
68 }
69
70
71 /***********************************************************************
72  *           CreatePenIndirect32    (GDI32.56)
73  */
74 HPEN WINAPI CreatePenIndirect( const LOGPEN * pen )
75 {
76     PENOBJ * penPtr;
77     HPEN hpen;
78
79     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
80     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
81     if (!hpen) return 0;
82     penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
83     penPtr->logpen.lopnStyle = pen->lopnStyle;
84     penPtr->logpen.lopnWidth = pen->lopnWidth;
85     penPtr->logpen.lopnColor = pen->lopnColor;
86     GDI_HEAP_UNLOCK( hpen );
87     return hpen;
88 }
89
90 /***********************************************************************
91  *           ExtCreatePen32    (GDI32.93)
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     LOGPEN logpen;
101
102     if ((style & PS_STYLE_MASK) == PS_USERSTYLE)
103         FIXME("PS_USERSTYLE not handled\n");
104     if ((style & PS_TYPE_MASK) == PS_GEOMETRIC)
105         if (brush->lbHatch)
106             FIXME("Hatches not implemented\n");
107
108     logpen.lopnStyle = style & ~PS_TYPE_MASK;
109     logpen.lopnWidth.x = (style & PS_GEOMETRIC) ? width : 1;
110     logpen.lopnWidth.y = 0;
111     logpen.lopnColor = brush->lbColor;
112     return CreatePenIndirect( &logpen );
113 }
114
115 /***********************************************************************
116  *           PEN_GetObject16
117  */
118 INT16 PEN_GetObject16( PENOBJ * pen, INT16 count, LPSTR buffer )
119 {
120     LOGPEN16 logpen;
121     logpen.lopnStyle = pen->logpen.lopnStyle;
122     logpen.lopnColor = pen->logpen.lopnColor;
123     CONV_POINT32TO16( &pen->logpen.lopnWidth, &logpen.lopnWidth );
124     if (count > sizeof(logpen)) count = sizeof(logpen);
125     memcpy( buffer, &logpen, count );
126     return count;
127 }
128
129
130 /***********************************************************************
131  *           PEN_GetObject32
132  */
133 INT PEN_GetObject( PENOBJ * pen, INT count, LPSTR buffer )
134 {
135     if (count > sizeof(pen->logpen)) count = sizeof(pen->logpen);
136     memcpy( buffer, &pen->logpen, count );
137     return count;
138 }
139