298271fff309e86a9648db9317a1a2fede51ff6a
[reactos.git] / reactos / subsys / win32k / objects / pen.c
1 /*
2 * ReactOS Win32 Subsystem
3 *
4 * Copyright (C) 1998 - 2004 ReactOS Team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * $Id$
21 */
22
23 #include <w32k.h>
24
25 #define NDEBUG
26 #include <debug.h>
27
28 /* PRIVATE FUNCTIONS **********************************************************/
29
30 HPEN FASTCALL
31 IntGdiCreatePenIndirect(PLOGPEN LogPen)
32 {
33 HPEN hPen;
34 PGDIBRUSHOBJ PenObject;
35 static const WORD wPatternAlternate[] = {0x5555};
36
37 if (LogPen->lopnStyle > PS_INSIDEFRAME)
38 return 0;
39
40 hPen = PENOBJ_AllocPen();
41 if (!hPen)
42 {
43 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
44 DPRINT("Can't allocate pen\n");
45 return 0;
46 }
47
48 PenObject = PENOBJ_LockPen(hPen);
49 /* FIXME - Handle PenObject == NULL!!! */
50 PenObject->ptPenWidth = LogPen->lopnWidth;
51 PenObject->ulPenStyle = LogPen->lopnStyle;
52 PenObject->BrushAttr.lbColor = LogPen->lopnColor;
53 PenObject->flAttrs = GDIBRUSH_IS_OLDSTYLEPEN;
54 switch (LogPen->lopnStyle)
55 {
56 case PS_NULL:
57 PenObject->flAttrs |= GDIBRUSH_IS_NULL;
58 break;
59
60 case PS_SOLID:
61 PenObject->flAttrs |= GDIBRUSH_IS_SOLID;
62 break;
63
64 case PS_ALTERNATE:
65 PenObject->flAttrs |= GDIBRUSH_IS_BITMAP;
66 PenObject->hbmPattern = NtGdiCreateBitmap(8, 1, 1, 1, (LPBYTE)wPatternAlternate);
67 break;
68
69 default:
70 DPRINT1("FIXME: IntGdiCreatePenIndirect is UNIMPLEMENTED\n");
71 }
72
73 PENOBJ_UnlockPen(PenObject);
74
75 return hPen;
76 }
77
78 /* PUBLIC FUNCTIONS ***********************************************************/
79
80 HPEN STDCALL
81 NtGdiCreatePen(
82 INT PenStyle,
83 INT Width,
84 COLORREF Color,
85 IN HBRUSH hbr)
86 {
87 LOGPEN LogPen;
88
89 LogPen.lopnStyle = PenStyle;
90 LogPen.lopnWidth.x = Width;
91 LogPen.lopnWidth.y = 0;
92 LogPen.lopnColor = Color;
93
94 return IntGdiCreatePenIndirect(&LogPen);
95 }
96
97 HPEN STDCALL
98 NtGdiCreatePenIndirect(CONST PLOGPEN LogPen)
99 {
100 LOGPEN SafeLogPen;
101 NTSTATUS Status = STATUS_SUCCESS;
102
103 _SEH_TRY
104 {
105 ProbeForRead(LogPen,
106 sizeof(LOGPEN),
107 1);
108 SafeLogPen = *LogPen;
109 }
110 _SEH_HANDLE
111 {
112 Status = _SEH_GetExceptionCode();
113 }
114 _SEH_END;
115
116 if (!NT_SUCCESS(Status))
117 {
118 SetLastNtError(Status);
119 return 0;
120 }
121
122 return IntGdiCreatePenIndirect(&SafeLogPen);
123 }
124
125 HPEN STDCALL
126 NtGdiExtCreatePen(
127 DWORD PenStyle,
128 DWORD Width,
129 IN ULONG iBrushStyle,
130 IN ULONG ulColor,
131 IN ULONG_PTR lClientHatch,
132 IN ULONG_PTR lHatch,
133 DWORD StyleCount,
134 PULONG Style,
135 IN ULONG cjDIB,
136 IN BOOL bOldStylePen,
137 IN OPTIONAL HBRUSH hbrush)
138 {
139 /* NOTE: This is HACK! */
140 DPRINT1("FIXME: FIX CALLERS FIRST!\n");
141 KEBUGCHECK(0);
142 LOGPEN LogPen;
143
144 if (PenStyle & PS_USERSTYLE)
145 PenStyle = (PenStyle & ~PS_STYLE_MASK) | PS_SOLID;
146
147 LogPen.lopnStyle = PenStyle & PS_STYLE_MASK;
148 LogPen.lopnWidth.x = Width;
149 LogPen.lopnColor = ulColor;
150
151 return IntGdiCreatePenIndirect(&LogPen);
152 }
153
154 /* EOF */