forget commit Implement of GdiGetLocalBrush, GdiGetLocalDC, GdiGetLocalFont
[reactos.git] / reactos / dll / win32 / gdi32 / misc / misc.c
1 /*
2 * ReactOS GDI lib
3 * Copyright (C) 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS gdi32.dll
22 * FILE: lib/gdi32/misc/misc.c
23 * PURPOSE: Miscellaneous functions
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
25 * UPDATE HISTORY:
26 * 2004/09/04 Created
27 */
28
29 #include "precomp.h"
30
31 PGDI_TABLE_ENTRY GdiHandleTable = NULL;
32 HANDLE CurrentProcessId = NULL;
33 DWORD GDI_BatchLimit = 1;
34
35
36 BOOL
37 STDCALL
38 GdiAlphaBlend(
39 HDC hDCDst,
40 int DstX,
41 int DstY,
42 int DstCx,
43 int DstCy,
44 HDC hDCSrc,
45 int SrcX,
46 int SrcY,
47 int SrcCx,
48 int SrcCy,
49 BLENDFUNCTION BlendFunction
50 )
51 {
52 if ( hDCSrc == NULL ) return FALSE;
53
54 if (GDI_HANDLE_GET_TYPE(hDCSrc) == GDI_OBJECT_TYPE_METADC) return FALSE;
55
56 return NtGdiAlphaBlend(
57 hDCDst,
58 DstX,
59 DstY,
60 DstCx,
61 DstCy,
62 hDCSrc,
63 SrcX,
64 SrcY,
65 SrcCx,
66 SrcCy,
67 BlendFunction,
68 0 );
69 }
70
71 /*
72 * @implemented
73 */
74 HGDIOBJ
75 STDCALL
76 GdiFixUpHandle(HGDIOBJ hGdiObj)
77 {
78 PGDI_TABLE_ENTRY Entry;
79
80 if (((ULONG_PTR)(hGdiObj)) & GDI_HANDLE_UPPER_MASK )
81 {
82 return hGdiObj;
83 }
84
85 /* FIXME is this right ?? */
86
87 Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
88
89 /* Rebuild handle for Object */
90 return hGdiObj = (HGDIOBJ)(((LONG_PTR)(hGdiObj)) | (Entry->Type << GDI_ENTRY_UPPER_SHIFT));
91 }
92
93 /*
94 * @implemented
95 */
96 PVOID
97 STDCALL
98 GdiQueryTable(VOID)
99 {
100 return (PVOID)GdiHandleTable;
101 }
102
103 BOOL GdiIsHandleValid(HGDIOBJ hGdiObj)
104 {
105 PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
106 if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) != 0 &&
107 (Entry->Type << GDI_ENTRY_UPPER_SHIFT) == GDI_HANDLE_GET_UPPER(hGdiObj))
108 {
109 HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
110 if(pid == NULL || pid == CurrentProcessId)
111 {
112 return TRUE;
113 }
114 }
115 return FALSE;
116 }
117
118 BOOL GdiGetHandleUserData(HGDIOBJ hGdiObj, PVOID *UserData)
119 {
120 PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
121 if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) != 0 &&
122 (Entry->Type << GDI_ENTRY_UPPER_SHIFT) == GDI_HANDLE_GET_UPPER(hGdiObj))
123 {
124 HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
125 if(pid == NULL || pid == CurrentProcessId)
126 {
127 *UserData = Entry->UserData;
128 return TRUE;
129 }
130 }
131 SetLastError(ERROR_INVALID_PARAMETER);
132 return FALSE;
133 }
134
135 PLDC GdiGetLDC(HDC hDC)
136 {
137 PDC_ATTR Dc_Attr;
138 if (!GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr))
139 return NULL;
140 return Dc_Attr->pvLDC;
141 }
142
143 /*
144 * @implemented
145 */
146 DWORD
147 STDCALL
148 GdiSetBatchLimit(DWORD Limit)
149 {
150 DWORD OldLimit = GDI_BatchLimit;
151
152 if ( (!Limit) ||
153 (Limit >= GDI_BATCH_LIMIT))
154 {
155 return Limit;
156 }
157
158 GdiFlush();
159 GDI_BatchLimit = Limit;
160 return OldLimit;
161 }
162
163
164 /*
165 * @implemented
166 */
167 DWORD
168 STDCALL
169 GdiGetBatchLimit()
170 {
171 return GDI_BatchLimit;
172 }
173
174 /*
175 * @unimplemented
176 */
177 BOOL
178 STDCALL
179 GdiReleaseDC(HDC hdc)
180 {
181 return 0;
182 }
183
184 INT
185 STDCALL
186 ExtEscape(HDC hDC,
187 int nEscape,
188 int cbInput,
189 LPCSTR lpszInData,
190 int cbOutput,
191 LPSTR lpszOutData)
192 {
193 return NtGdiExtEscape(hDC, NULL, 0, nEscape, cbInput, (LPSTR)lpszInData, cbOutput, lpszOutData);
194 }
195
196 /*
197 * @implemented
198 */
199 VOID
200 STDCALL
201 GdiSetLastError(DWORD dwErrCode)
202 {
203 NtCurrentTeb ()->LastErrorValue = (ULONG) dwErrCode;
204 }