2003-05-18 17:16:18 +00:00
|
|
|
/*
|
|
|
|
* ReactOS W32 Subsystem
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 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.
|
|
|
|
*
|
|
|
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2004-07-03 17:40:27 +00:00
|
|
|
/* $Id: misc.c,v 1.9 2004/07/03 17:40:25 navaraf Exp $ */
|
2004-05-10 17:07:20 +00:00
|
|
|
#include <w32k.h>
|
2003-02-25 23:08:54 +00:00
|
|
|
|
|
|
|
BOOL STDCALL
|
|
|
|
IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave,
|
|
|
|
SURFOBJ *DestObj,
|
|
|
|
RECTL *DestRect,
|
|
|
|
BOOL ReadOnly,
|
|
|
|
POINTL *Translate,
|
|
|
|
SURFOBJ **OutputObj)
|
|
|
|
{
|
|
|
|
LONG Exchange;
|
|
|
|
SIZEL BitmapSize;
|
|
|
|
POINTL SrcPoint;
|
|
|
|
LONG Width;
|
2004-02-10 23:40:55 +00:00
|
|
|
RECTL ClippedDestRect;
|
2003-02-25 23:08:54 +00:00
|
|
|
|
|
|
|
/* Normalize */
|
|
|
|
if (DestRect->right < DestRect->left)
|
|
|
|
{
|
|
|
|
Exchange = DestRect->left;
|
|
|
|
DestRect->left = DestRect->right;
|
|
|
|
DestRect->right = Exchange;
|
|
|
|
}
|
|
|
|
if (DestRect->bottom < DestRect->top)
|
|
|
|
{
|
|
|
|
Exchange = DestRect->top;
|
|
|
|
DestRect->top = DestRect->bottom;
|
|
|
|
DestRect->bottom = Exchange;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != DestObj && STYPE_BITMAP != DestObj->iType &&
|
|
|
|
(NULL == DestObj->pvScan0 || 0 == DestObj->lDelta))
|
|
|
|
{
|
|
|
|
/* Driver needs to support DrvCopyBits, else we can't do anything */
|
2004-07-03 13:55:37 +00:00
|
|
|
/* FIXME: Remove typecast! */
|
|
|
|
if (!(((BITMAPOBJ*)DestObj)->flHooks & HOOK_COPYBITS))
|
2003-02-25 23:08:54 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a temporary bitmap */
|
|
|
|
BitmapSize.cx = DestRect->right - DestRect->left;
|
|
|
|
BitmapSize.cy = DestRect->bottom - DestRect->top;
|
|
|
|
Width = DIB_GetDIBWidthBytes(BitmapSize.cx, BitsPerFormat(DestObj->iBitmapFormat));
|
|
|
|
EnterLeave->OutputBitmap = EngCreateBitmap(BitmapSize, Width,
|
|
|
|
DestObj->iBitmapFormat,
|
2004-06-24 19:43:49 +00:00
|
|
|
BMF_TOPDOWN | BMF_NOZEROINIT, NULL);
|
2004-07-03 13:55:37 +00:00
|
|
|
*OutputObj = EngLockSurface((HSURF)EnterLeave->OutputBitmap);
|
2003-02-25 23:08:54 +00:00
|
|
|
|
|
|
|
EnterLeave->DestRect.left = 0;
|
|
|
|
EnterLeave->DestRect.top = 0;
|
|
|
|
EnterLeave->DestRect.right = BitmapSize.cx;
|
|
|
|
EnterLeave->DestRect.bottom = BitmapSize.cy;
|
|
|
|
SrcPoint.x = DestRect->left;
|
|
|
|
SrcPoint.y = DestRect->top;
|
2004-02-10 23:40:55 +00:00
|
|
|
ClippedDestRect = EnterLeave->DestRect;
|
|
|
|
if (SrcPoint.x < 0)
|
|
|
|
{
|
|
|
|
ClippedDestRect.left -= SrcPoint.x;
|
|
|
|
SrcPoint.x = 0;
|
|
|
|
}
|
|
|
|
if (DestObj->sizlBitmap.cx < SrcPoint.x + ClippedDestRect.right - ClippedDestRect.left)
|
|
|
|
{
|
|
|
|
ClippedDestRect.right = ClippedDestRect.left + DestObj->sizlBitmap.cx - SrcPoint.x;
|
|
|
|
}
|
|
|
|
if (SrcPoint.y < 0)
|
|
|
|
{
|
|
|
|
ClippedDestRect.top -= SrcPoint.y;
|
|
|
|
SrcPoint.y = 0;
|
|
|
|
}
|
|
|
|
if (DestObj->sizlBitmap.cy < SrcPoint.y + ClippedDestRect.bottom - ClippedDestRect.top)
|
|
|
|
{
|
|
|
|
ClippedDestRect.bottom = ClippedDestRect.top + DestObj->sizlBitmap.cy - SrcPoint.y;
|
|
|
|
}
|
2003-02-25 23:08:54 +00:00
|
|
|
EnterLeave->TrivialClipObj = EngCreateClip();
|
|
|
|
EnterLeave->TrivialClipObj->iDComplexity = DC_TRIVIAL;
|
2004-02-10 23:40:55 +00:00
|
|
|
if (ClippedDestRect.left < (*OutputObj)->sizlBitmap.cx &&
|
|
|
|
0 <= ClippedDestRect.right &&
|
|
|
|
SrcPoint.x < DestObj->sizlBitmap.cx &&
|
|
|
|
ClippedDestRect.top <= (*OutputObj)->sizlBitmap.cy &&
|
|
|
|
0 <= ClippedDestRect.bottom &&
|
|
|
|
SrcPoint.y < DestObj->sizlBitmap.cy &&
|
2004-07-03 13:55:37 +00:00
|
|
|
! GDIDEVFUNCS(DestObj).CopyBits(
|
|
|
|
*OutputObj, DestObj,
|
2003-02-25 23:08:54 +00:00
|
|
|
EnterLeave->TrivialClipObj, NULL,
|
2004-02-10 23:40:55 +00:00
|
|
|
&ClippedDestRect, &SrcPoint))
|
2003-02-25 23:08:54 +00:00
|
|
|
{
|
|
|
|
EngDeleteClip(EnterLeave->TrivialClipObj);
|
|
|
|
EngFreeMem((*OutputObj)->pvBits);
|
2004-04-09 20:03:21 +00:00
|
|
|
EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
|
2003-02-25 23:08:54 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
EnterLeave->DestRect.left = DestRect->left;
|
|
|
|
EnterLeave->DestRect.top = DestRect->top;
|
|
|
|
EnterLeave->DestRect.right = DestRect->right;
|
|
|
|
EnterLeave->DestRect.bottom = DestRect->bottom;
|
|
|
|
Translate->x = - DestRect->left;
|
|
|
|
Translate->y = - DestRect->top;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Translate->x = 0;
|
|
|
|
Translate->y = 0;
|
|
|
|
*OutputObj = DestObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnterLeave->DestObj = DestObj;
|
|
|
|
EnterLeave->OutputObj = *OutputObj;
|
|
|
|
EnterLeave->ReadOnly = ReadOnly;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL STDCALL
|
|
|
|
IntEngLeave(PINTENG_ENTER_LEAVE EnterLeave)
|
|
|
|
{
|
|
|
|
POINTL SrcPoint;
|
2004-07-03 17:40:27 +00:00
|
|
|
BOOL Result = TRUE;
|
2003-02-25 23:08:54 +00:00
|
|
|
|
|
|
|
if (EnterLeave->OutputObj != EnterLeave->DestObj && NULL != EnterLeave->OutputObj)
|
|
|
|
{
|
|
|
|
if (! EnterLeave->ReadOnly)
|
|
|
|
{
|
|
|
|
SrcPoint.x = 0;
|
|
|
|
SrcPoint.y = 0;
|
2004-02-10 23:40:55 +00:00
|
|
|
if (EnterLeave->DestRect.left < 0)
|
|
|
|
{
|
|
|
|
SrcPoint.x = - EnterLeave->DestRect.left;
|
|
|
|
EnterLeave->DestRect.left = 0;
|
|
|
|
}
|
|
|
|
if (EnterLeave->DestObj->sizlBitmap.cx < EnterLeave->DestRect.right)
|
|
|
|
{
|
|
|
|
EnterLeave->DestRect.right = EnterLeave->DestObj->sizlBitmap.cx;
|
|
|
|
}
|
|
|
|
if (EnterLeave->DestRect.top < 0)
|
|
|
|
{
|
|
|
|
SrcPoint.y = - EnterLeave->DestRect.top;
|
|
|
|
EnterLeave->DestRect.top = 0;
|
|
|
|
}
|
|
|
|
if (EnterLeave->DestObj->sizlBitmap.cy < EnterLeave->DestRect.bottom)
|
|
|
|
{
|
|
|
|
EnterLeave->DestRect.bottom = EnterLeave->DestObj->sizlBitmap.cy;
|
|
|
|
}
|
|
|
|
if (SrcPoint.x < EnterLeave->OutputObj->sizlBitmap.cx &&
|
|
|
|
EnterLeave->DestRect.left <= EnterLeave->DestRect.right &&
|
|
|
|
EnterLeave->DestRect.left < EnterLeave->DestObj->sizlBitmap.cx &&
|
|
|
|
SrcPoint.y < EnterLeave->OutputObj->sizlBitmap.cy &&
|
|
|
|
EnterLeave->DestRect.top <= EnterLeave->DestRect.bottom &&
|
|
|
|
EnterLeave->DestRect.top < EnterLeave->DestObj->sizlBitmap.cy)
|
|
|
|
{
|
2004-07-03 13:55:37 +00:00
|
|
|
Result = GDIDEVFUNCS(EnterLeave->DestObj).CopyBits(
|
|
|
|
EnterLeave->DestObj,
|
2004-02-10 23:40:55 +00:00
|
|
|
EnterLeave->OutputObj,
|
|
|
|
EnterLeave->TrivialClipObj, NULL,
|
|
|
|
&EnterLeave->DestRect, &SrcPoint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
2003-02-25 23:08:54 +00:00
|
|
|
}
|
|
|
|
EngFreeMem(EnterLeave->OutputObj->pvBits);
|
2004-07-03 13:55:37 +00:00
|
|
|
EngUnlockSurface(EnterLeave->OutputObj);
|
2004-04-09 20:03:21 +00:00
|
|
|
EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
|
2003-02-25 23:08:54 +00:00
|
|
|
EngDeleteClip(EnterLeave->TrivialClipObj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
2003-05-18 17:16:18 +00:00
|
|
|
}
|
2004-02-11 19:26:51 +00:00
|
|
|
|
|
|
|
HANDLE STDCALL
|
|
|
|
EngGetCurrentProcessId(VOID)
|
|
|
|
{
|
|
|
|
/* http://www.osr.com/ddk/graphics/gdifncs_5ovb.htm */
|
|
|
|
return PsGetCurrentProcessId();
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE STDCALL
|
|
|
|
EngGetCurrentThreadId(VOID)
|
|
|
|
{
|
|
|
|
/* http://www.osr.com/ddk/graphics/gdifncs_25rb.htm */
|
|
|
|
return PsGetCurrentThreadId();
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE STDCALL
|
|
|
|
EngGetProcessHandle(VOID)
|
|
|
|
{
|
|
|
|
/* http://www.osr.com/ddk/graphics/gdifncs_3tif.htm
|
|
|
|
In Windows 2000 and later, the EngGetProcessHandle function always returns NULL.
|
|
|
|
FIXME - what does NT4 return? */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-18 17:16:18 +00:00
|
|
|
/* EOF */
|