3 * Copyright (C) 2003 ReactOS Team
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.
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.
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.
21 * PROJECT: ReactOS gdi32.dll
22 * FILE: lib/gdi32/misc/misc.c
23 * PURPOSE: Miscellaneous functions
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
31 PGDI_TABLE_ENTRY GdiHandleTable
= NULL
;
32 PGDI_SHARED_HANDLE_TABLE GdiSharedHandleTable
= NULL
;
33 HANDLE CurrentProcessId
= NULL
;
34 DWORD GDI_BatchLimit
= 1;
50 BLENDFUNCTION BlendFunction
53 if ( hDCSrc
== NULL
) return FALSE
;
55 if (GDI_HANDLE_GET_TYPE(hDCSrc
) == GDI_OBJECT_TYPE_METADC
) return FALSE
;
57 return NtGdiAlphaBlend(
77 GdiFixUpHandle(HGDIOBJ hGdiObj
)
79 PGDI_TABLE_ENTRY Entry
;
81 if (((ULONG_PTR
)(hGdiObj
)) & GDI_HANDLE_UPPER_MASK
)
86 /* FIXME is this right ?? */
88 Entry
= GdiHandleTable
+ GDI_HANDLE_GET_INDEX(hGdiObj
);
90 /* Rebuild handle for Object */
91 return hGdiObj
= (HGDIOBJ
)(((LONG_PTR
)(hGdiObj
)) | (Entry
->Type
<< GDI_ENTRY_UPPER_SHIFT
));
101 return (PVOID
)GdiHandleTable
;
104 BOOL
GdiIsHandleValid(HGDIOBJ hGdiObj
)
106 PGDI_TABLE_ENTRY Entry
= GdiHandleTable
+ GDI_HANDLE_GET_INDEX(hGdiObj
);
107 // We are only looking for TYPE not the rest here, and why is FullUnique filled up with CRAP!?
108 // DPRINT1("FullUnique -> %x\n", Entry->FullUnique);
109 if((Entry
->Type
& GDI_ENTRY_BASETYPE_MASK
) != 0 &&
110 ( (Entry
->Type
<< GDI_ENTRY_UPPER_SHIFT
) & GDI_HANDLE_TYPE_MASK
) ==
111 GDI_HANDLE_GET_TYPE(hGdiObj
))
113 HANDLE pid
= (HANDLE
)((ULONG_PTR
)Entry
->ProcessId
& ~0x1);
114 if(pid
== NULL
|| pid
== CurrentProcessId
)
122 BOOL
GdiGetHandleUserData(HGDIOBJ hGdiObj
, DWORD ObjectType
, PVOID
*UserData
)
124 PGDI_TABLE_ENTRY Entry
= GdiHandleTable
+ GDI_HANDLE_GET_INDEX(hGdiObj
);
125 if((Entry
->Type
& GDI_ENTRY_BASETYPE_MASK
) == ObjectType
&&
126 ( (Entry
->Type
<< GDI_ENTRY_UPPER_SHIFT
) & GDI_HANDLE_TYPE_MASK
) ==
127 GDI_HANDLE_GET_TYPE(hGdiObj
))
129 HANDLE pid
= (HANDLE
)((ULONG_PTR
)Entry
->ProcessId
& ~0x1);
130 if(pid
== NULL
|| pid
== CurrentProcessId
)
133 // Need to test if we have Read & Write access to the VM address space.
138 volatile CHAR
*Current
= (volatile CHAR
*)Entry
->UserData
;
143 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
150 Result
= FALSE
; // Can not be zero.
151 if (Result
) *UserData
= Entry
->UserData
;
155 SetLastError(ERROR_INVALID_PARAMETER
);
159 PLDC
GdiGetLDC(HDC hDC
)
162 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
))
164 return Dc_Attr
->pvLDC
;
167 VOID
GdiSAPCallback(PLDC pldc
)
169 DWORD Time
, NewTime
= GetTickCount();
171 Time
= NewTime
- pldc
->CallBackTick
;
173 if ( Time
< SAPCALLBACKDELAY
) return;
175 pldc
->CallBackTick
= NewTime
;
177 if ( !pldc
->pAbortProc(pldc
->hDC
, 0) )
189 GdiSetBatchLimit(DWORD Limit
)
191 DWORD OldLimit
= GDI_BatchLimit
;
194 (Limit
>= GDI_BATCH_LIMIT
))
200 GDI_BatchLimit
= Limit
;
212 return GDI_BatchLimit
;
220 GdiReleaseDC(HDC hdc
)
234 return NtGdiExtEscape(hDC
, NULL
, 0, nEscape
, cbInput
, (LPSTR
)lpszInData
, cbOutput
, lpszOutData
);
242 GdiSetLastError(DWORD dwErrCode
)
244 NtCurrentTeb()->LastErrorValue
= (ULONG
) dwErrCode
;
249 GdiAddGlsBounds(HDC hdc
,LPRECT prc
)
251 //FIXME: Lookup what 0x8000 means
252 return NtGdiSetBoundsRect(hdc
, prc
, 0x8000 | DCB_ACCUMULATE
) ? TRUE
: FALSE
;