Add a help function for gdi32.
[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 * @implemented
37 */
38 PVOID
39 STDCALL
40 GdiQueryTable(VOID)
41 {
42 return (PVOID)GdiHandleTable;
43 }
44
45 BOOL GdiIsHandleValid(HGDIOBJ hGdiObj)
46 {
47 PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
48 if(Entry->KernelData != NULL && (Entry->Type & GDI_HANDLE_TYPE_MASK) == (LONG)GDI_HANDLE_GET_TYPE(hGdiObj))
49 {
50 HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
51 if(pid == NULL || pid == CurrentProcessId)
52 {
53 return TRUE;
54 }
55 }
56 return FALSE;
57 }
58
59 BOOL GdiGetHandleUserData(HGDIOBJ hGdiObj, PVOID *UserData)
60 {
61 PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
62 if(Entry->KernelData != NULL && (Entry->Type & GDI_HANDLE_TYPE_MASK) == (LONG)GDI_HANDLE_GET_TYPE(hGdiObj))
63 {
64 HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
65 if(pid == NULL || pid == CurrentProcessId)
66 {
67 *UserData = Entry->UserData;
68 return TRUE;
69 }
70 }
71 return FALSE;
72 }
73
74 PLDC GdiGetLDC(HDC hDC)
75 {
76 PDC_ATTR Dc_Attr;
77 if (!GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr))
78 return NULL;
79 return Dc_Attr->pvLDC;
80 }
81
82 /*
83 * @implemented
84 */
85 DWORD
86 STDCALL
87 GdiSetBatchLimit(DWORD Limit)
88 {
89 DWORD OldLimit = GDI_BatchLimit;
90 if ((!Limit) || (Limit > GDI_BATCH_LIMIT)) return Limit;
91 GdiFlush();
92 GDI_BatchLimit = Limit;
93 return OldLimit;
94 }
95
96
97 /*
98 * @implemented
99 */
100 DWORD
101 STDCALL
102 GdiGetBatchLimit()
103 {
104 return GDI_BatchLimit;
105 }