2004-09-06 21:15:46 +00:00
|
|
|
/*
|
|
|
|
* ReactOS GDI lib
|
|
|
|
* Copyright (C) 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-09-06 21:15:46 +00:00
|
|
|
*/
|
2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
2004-09-06 21:15:46 +00:00
|
|
|
*
|
|
|
|
* PROJECT: ReactOS gdi32.dll
|
|
|
|
* FILE: lib/gdi32/misc/misc.c
|
|
|
|
* PURPOSE: Miscellaneous functions
|
|
|
|
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* 2004/09/04 Created
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2009-05-27 04:49:29 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2004-09-06 21:15:46 +00:00
|
|
|
PGDI_TABLE_ENTRY GdiHandleTable = NULL;
|
2007-12-15 08:08:11 +00:00
|
|
|
PGDI_SHARED_HANDLE_TABLE GdiSharedHandleTable = NULL;
|
2005-02-18 15:13:02 +00:00
|
|
|
HANDLE CurrentProcessId = NULL;
|
2006-10-17 05:30:54 +00:00
|
|
|
DWORD GDI_BatchLimit = 1;
|
2004-09-06 21:15:46 +00:00
|
|
|
|
2007-04-20 21:21:15 +00:00
|
|
|
|
2007-08-09 06:48:07 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2007-08-09 06:48:07 +00:00
|
|
|
GdiAlphaBlend(
|
|
|
|
HDC hDCDst,
|
|
|
|
int DstX,
|
|
|
|
int DstY,
|
|
|
|
int DstCx,
|
|
|
|
int DstCy,
|
|
|
|
HDC hDCSrc,
|
|
|
|
int SrcX,
|
|
|
|
int SrcY,
|
|
|
|
int SrcCx,
|
|
|
|
int SrcCy,
|
|
|
|
BLENDFUNCTION BlendFunction
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if ( hDCSrc == NULL ) return FALSE;
|
|
|
|
|
|
|
|
if (GDI_HANDLE_GET_TYPE(hDCSrc) == GDI_OBJECT_TYPE_METADC) return FALSE;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2007-08-09 06:48:07 +00:00
|
|
|
return NtGdiAlphaBlend(
|
|
|
|
hDCDst,
|
|
|
|
DstX,
|
|
|
|
DstY,
|
|
|
|
DstCx,
|
|
|
|
DstCy,
|
|
|
|
hDCSrc,
|
|
|
|
SrcX,
|
|
|
|
SrcY,
|
|
|
|
SrcCx,
|
|
|
|
SrcCy,
|
|
|
|
BlendFunction,
|
|
|
|
0 );
|
|
|
|
}
|
|
|
|
|
2007-04-20 21:21:15 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-10-19 23:21:45 +00:00
|
|
|
HGDIOBJ
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2007-04-20 21:21:15 +00:00
|
|
|
GdiFixUpHandle(HGDIOBJ hGdiObj)
|
|
|
|
{
|
2007-09-25 20:44:53 +00:00
|
|
|
PGDI_TABLE_ENTRY Entry;
|
|
|
|
|
|
|
|
if (((ULONG_PTR)(hGdiObj)) & GDI_HANDLE_UPPER_MASK )
|
|
|
|
{
|
|
|
|
return hGdiObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME is this right ?? */
|
|
|
|
|
|
|
|
Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
|
|
|
|
|
|
|
|
/* Rebuild handle for Object */
|
|
|
|
return hGdiObj = (HGDIOBJ)(((LONG_PTR)(hGdiObj)) | (Entry->Type << GDI_ENTRY_UPPER_SHIFT));
|
2007-04-20 21:21:15 +00:00
|
|
|
}
|
|
|
|
|
2004-09-06 21:15:46 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
PVOID
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2004-09-06 21:15:46 +00:00
|
|
|
GdiQueryTable(VOID)
|
|
|
|
{
|
|
|
|
return (PVOID)GdiHandleTable;
|
|
|
|
}
|
2005-02-18 15:13:02 +00:00
|
|
|
|
|
|
|
BOOL GdiIsHandleValid(HGDIOBJ hGdiObj)
|
|
|
|
{
|
2007-04-28 06:43:44 +00:00
|
|
|
PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
|
2008-04-21 18:28:35 +00:00
|
|
|
// We are only looking for TYPE not the rest here, and why is FullUnique filled up with CRAP!?
|
|
|
|
// DPRINT1("FullUnique -> %x\n", Entry->FullUnique);
|
2007-10-19 23:21:45 +00:00
|
|
|
if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) != 0 &&
|
2008-04-21 18:28:35 +00:00
|
|
|
( (Entry->Type << GDI_ENTRY_UPPER_SHIFT) & GDI_HANDLE_TYPE_MASK ) ==
|
|
|
|
GDI_HANDLE_GET_TYPE(hGdiObj))
|
2005-02-18 15:13:02 +00:00
|
|
|
{
|
|
|
|
HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
|
|
|
|
if(pid == NULL || pid == CurrentProcessId)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-11-29 05:21:19 +00:00
|
|
|
BOOL GdiGetHandleUserData(HGDIOBJ hGdiObj, DWORD ObjectType, PVOID *UserData)
|
2005-02-18 15:13:02 +00:00
|
|
|
{
|
2009-05-29 07:13:43 +00:00
|
|
|
PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
|
|
|
|
if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) == ObjectType &&
|
|
|
|
( (Entry->Type << GDI_ENTRY_UPPER_SHIFT) & GDI_HANDLE_TYPE_MASK ) ==
|
|
|
|
GDI_HANDLE_GET_TYPE(hGdiObj))
|
2009-05-27 04:49:29 +00:00
|
|
|
{
|
2009-05-29 07:13:43 +00:00
|
|
|
HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
|
|
|
|
if(pid == NULL || pid == CurrentProcessId)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Need to test if we have Read & Write access to the VM address space.
|
|
|
|
//
|
|
|
|
BOOL Result = TRUE;
|
|
|
|
if(Entry->UserData)
|
|
|
|
{
|
|
|
|
volatile CHAR *Current = (volatile CHAR*)Entry->UserData;
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
*Current = *Current;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
Result = FALSE;
|
|
|
|
}
|
|
|
|
_SEH2_END
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Result = FALSE; // Can not be zero.
|
|
|
|
if (Result) *UserData = Entry->UserData;
|
|
|
|
return Result;
|
|
|
|
}
|
2005-02-18 15:13:02 +00:00
|
|
|
}
|
2009-05-29 07:13:43 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2005-02-18 15:13:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-10-17 05:30:54 +00:00
|
|
|
|
2009-05-27 04:49:29 +00:00
|
|
|
PLDC
|
|
|
|
FASTCALL
|
|
|
|
GdiGetLDC(HDC hDC)
|
2006-11-27 21:58:46 +00:00
|
|
|
{
|
2009-05-29 07:13:43 +00:00
|
|
|
PDC_ATTR Dc_Attr;
|
|
|
|
PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX((HGDIOBJ) hDC);
|
|
|
|
HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
|
|
|
|
// Don't check the mask, just the object type.
|
|
|
|
if ( Entry->ObjectType == GDIObjType_DC_TYPE &&
|
|
|
|
(pid == NULL || pid == CurrentProcessId) )
|
|
|
|
{
|
|
|
|
BOOL Result = TRUE;
|
|
|
|
if (Entry->UserData)
|
2009-05-27 04:49:29 +00:00
|
|
|
{
|
2009-05-29 07:13:43 +00:00
|
|
|
volatile CHAR *Current = (volatile CHAR*)Entry->UserData;
|
|
|
|
_SEH2_TRY
|
2009-05-27 04:49:29 +00:00
|
|
|
{
|
2009-05-29 07:13:43 +00:00
|
|
|
*Current = *Current;
|
2009-05-27 04:49:29 +00:00
|
|
|
}
|
2009-05-29 07:13:43 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2009-05-27 04:49:29 +00:00
|
|
|
{
|
2009-05-29 07:13:43 +00:00
|
|
|
Result = FALSE;
|
2009-05-27 04:49:29 +00:00
|
|
|
}
|
2009-05-29 07:13:43 +00:00
|
|
|
_SEH2_END
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Result = FALSE;
|
|
|
|
|
|
|
|
if (Result)
|
|
|
|
{
|
|
|
|
Dc_Attr = (PDC_ATTR)Entry->UserData;
|
|
|
|
return Dc_Attr->pvLDC;
|
2009-05-27 04:49:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-11-27 21:58:46 +00:00
|
|
|
}
|
2006-10-17 05:30:54 +00:00
|
|
|
|
2009-05-24 04:07:47 +00:00
|
|
|
VOID GdiSAPCallback(PLDC pldc)
|
|
|
|
{
|
|
|
|
DWORD Time, NewTime = GetTickCount();
|
|
|
|
|
|
|
|
Time = NewTime - pldc->CallBackTick;
|
|
|
|
|
|
|
|
if ( Time < SAPCALLBACKDELAY) return;
|
|
|
|
|
|
|
|
pldc->CallBackTick = NewTime;
|
|
|
|
|
2009-05-24 04:14:48 +00:00
|
|
|
if ( !pldc->pAbortProc(pldc->hDC, 0) )
|
2009-05-24 04:07:47 +00:00
|
|
|
{
|
|
|
|
CancelDC(pldc->hDC);
|
|
|
|
AbortDoc(pldc->hDC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-17 05:30:54 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2006-10-17 05:30:54 +00:00
|
|
|
GdiSetBatchLimit(DWORD Limit)
|
|
|
|
{
|
2007-09-25 20:44:53 +00:00
|
|
|
DWORD OldLimit = GDI_BatchLimit;
|
|
|
|
|
|
|
|
if ( (!Limit) ||
|
|
|
|
(Limit >= GDI_BATCH_LIMIT))
|
|
|
|
{
|
|
|
|
return Limit;
|
|
|
|
}
|
|
|
|
|
2006-10-17 05:30:54 +00:00
|
|
|
GdiFlush();
|
|
|
|
GDI_BatchLimit = Limit;
|
|
|
|
return OldLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2006-10-17 05:30:54 +00:00
|
|
|
GdiGetBatchLimit()
|
|
|
|
{
|
|
|
|
return GDI_BatchLimit;
|
|
|
|
}
|
2007-04-20 21:21:15 +00:00
|
|
|
|
2007-04-28 23:40:51 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2007-04-28 23:42:38 +00:00
|
|
|
GdiReleaseDC(HDC hdc)
|
2007-04-28 23:40:51 +00:00
|
|
|
{
|
2007-08-31 16:17:28 +00:00
|
|
|
return 0;
|
2007-04-28 23:40:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 20:44:53 +00:00
|
|
|
INT
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2007-09-25 20:44:53 +00:00
|
|
|
ExtEscape(HDC hDC,
|
|
|
|
int nEscape,
|
|
|
|
int cbInput,
|
|
|
|
LPCSTR lpszInData,
|
|
|
|
int cbOutput,
|
|
|
|
LPSTR lpszOutData)
|
2007-08-01 02:07:15 +00:00
|
|
|
{
|
2007-09-25 20:44:53 +00:00
|
|
|
return NtGdiExtEscape(hDC, NULL, 0, nEscape, cbInput, (LPSTR)lpszInData, cbOutput, lpszOutData);
|
2007-08-01 02:07:15 +00:00
|
|
|
}
|
2007-09-25 13:27:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2007-09-25 13:27:09 +00:00
|
|
|
GdiSetLastError(DWORD dwErrCode)
|
|
|
|
{
|
2008-10-17 04:34:21 +00:00
|
|
|
NtCurrentTeb()->LastErrorValue = (ULONG) dwErrCode;
|
2007-09-25 13:27:09 +00:00
|
|
|
}
|
2008-05-24 19:02:23 +00:00
|
|
|
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2008-05-24 19:02:23 +00:00
|
|
|
GdiAddGlsBounds(HDC hdc,LPRECT prc)
|
|
|
|
{
|
|
|
|
//FIXME: Lookup what 0x8000 means
|
|
|
|
return NtGdiSetBoundsRect(hdc, prc, 0x8000 | DCB_ACCUMULATE ) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|