99709e1946b3414e8ed837076f7a0d89bf585298
[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 if (((ULONG_PTR)(hGdiObj)) & GDI_HANDLE_UPPER_MASK ) return hGdiObj;
79 PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
80 return hGdiObj = (HGDIOBJ)(((LONG_PTR)(hGdiObj)) |
81 (Entry->Type << GDI_ENTRY_UPPER_SHIFT)); // Rebuild handle for Object
82 }
83
84 /*
85 * @implemented
86 */
87 PVOID
88 STDCALL
89 GdiQueryTable(VOID)
90 {
91 return (PVOID)GdiHandleTable;
92 }
93
94 BOOL GdiIsHandleValid(HGDIOBJ hGdiObj)
95 {
96 PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
97 if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) != 0 &&
98 (Entry->Type << GDI_ENTRY_UPPER_SHIFT) == GDI_HANDLE_GET_UPPER(hGdiObj))
99 {
100 HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
101 if(pid == NULL || pid == CurrentProcessId)
102 {
103 return TRUE;
104 }
105 }
106 return FALSE;
107 }
108
109 BOOL GdiGetHandleUserData(HGDIOBJ hGdiObj, PVOID *UserData)
110 {
111 PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
112 if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) != 0 &&
113 (Entry->Type << GDI_ENTRY_UPPER_SHIFT) == GDI_HANDLE_GET_UPPER(hGdiObj))
114 {
115 HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
116 if(pid == NULL || pid == CurrentProcessId)
117 {
118 *UserData = Entry->UserData;
119 return TRUE;
120 }
121 }
122 SetLastError(ERROR_INVALID_PARAMETER);
123 return FALSE;
124 }
125
126 PLDC GdiGetLDC(HDC hDC)
127 {
128 PDC_ATTR Dc_Attr;
129 if (!GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr))
130 return NULL;
131 return Dc_Attr->pvLDC;
132 }
133
134 /*
135 * @implemented
136 */
137 DWORD
138 STDCALL
139 GdiSetBatchLimit(DWORD Limit)
140 {
141 DWORD OldLimit = GDI_BatchLimit;
142 if ((!Limit) || (Limit > GDI_BATCH_LIMIT)) return Limit;
143 GdiFlush();
144 GDI_BatchLimit = Limit;
145 return OldLimit;
146 }
147
148
149 /*
150 * @implemented
151 */
152 DWORD
153 STDCALL
154 GdiGetBatchLimit()
155 {
156 return GDI_BatchLimit;
157 }
158
159 /*
160 * @unimplemented
161 */
162 BOOL
163 STDCALL
164 GdiReleaseDC(HDC hdc)
165 {
166 return 0;
167 }
168
169 INT STDCALL
170 ExtEscape(
171 HDC hDC,
172 int nEscape,
173 int cbInput,
174 LPCSTR lpszInData,
175 int cbOutput,
176 LPSTR lpszOutData
177 )
178 {
179 return NtGdiExtEscape(hDC, NULL, 0, nEscape, cbInput, (LPSTR)lpszInData, cbOutput, lpszOutData);
180 }
181
182 /*
183 * @implemented
184 */
185 VOID
186 STDCALL
187 GdiSetLastError(DWORD dwErrCode)
188 {
189 SetLastError(dwErrCode);
190 }