2004-11-16 17:25:47 +00:00
|
|
|
/*
|
|
|
|
* ReactOS W32 Subsystem
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 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-11-16 17:25:47 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* PURPOSE: Monitor support
|
|
|
|
* FILE: subsys/win32k/ntuser/monitor.c
|
|
|
|
* PROGRAMER: Anich Gregor (blight@blight.eu.org)
|
|
|
|
* REVISION HISTORY:
|
|
|
|
* 26-02-2004 Created
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <w32k.h>
|
|
|
|
|
|
|
|
/* FIXME: find include file for these */
|
|
|
|
#define MONITORINFOF_PRIMARY 1
|
|
|
|
#define MONITOR_DEFAULTTONULL 0
|
|
|
|
#define MONITOR_DEFAULTTOPRIMARY 1
|
|
|
|
#define MONITOR_DEFAULTTONEAREST 2
|
|
|
|
|
2005-06-29 07:09:25 +00:00
|
|
|
#define NDEBUG
|
2004-11-16 17:25:47 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
/* list of monitors */
|
2010-01-11 07:36:48 +00:00
|
|
|
static PMONITOR gMonitorList = NULL;
|
2004-11-16 17:25:47 +00:00
|
|
|
|
|
|
|
/* INITALIZATION FUNCTIONS ****************************************************/
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
InitMonitorImpl()
|
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
DPRINT("Initializing monitor implementation...\n");
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CleanupMonitorImpl()
|
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
DPRINT("Cleaning up monitor implementation...\n");
|
|
|
|
/* FIXME: Destroy monitor objects? */
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
#ifndef ABS
|
|
|
|
# define ABS(a) ((a) < (0) ? (-(a)) : (a))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* IntCreateMonitorObject
|
|
|
|
*
|
2010-01-11 07:36:48 +00:00
|
|
|
* Creates a MONITOR
|
2004-11-16 17:25:47 +00:00
|
|
|
*
|
|
|
|
* Return value
|
2010-01-11 07:36:48 +00:00
|
|
|
* If the function succeeds a pointer to a MONITOR is returned. On failure
|
2004-11-16 17:25:47 +00:00
|
|
|
* NULL is returned.
|
|
|
|
*/
|
|
|
|
static
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR
|
2004-11-16 17:25:47 +00:00
|
|
|
IntCreateMonitorObject()
|
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
HANDLE Handle;
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR Monitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2010-01-15 13:47:25 +00:00
|
|
|
Monitor = UserCreateObject(gHandleTable, NULL, &Handle, otMonitor, sizeof (MONITOR));
|
2005-09-07 21:25:42 +00:00
|
|
|
if (Monitor == NULL)
|
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
return NULL;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
ExInitializeFastMutex(&Monitor->Lock);
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return Monitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IntDestroyMonitorObject
|
|
|
|
*
|
2010-01-11 07:36:48 +00:00
|
|
|
* Destroys a MONITOR
|
2004-11-16 17:25:47 +00:00
|
|
|
* You have to be the owner of the monitors lock to safely destroy it.
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
|
|
|
* pMonitor
|
2010-01-11 07:36:48 +00:00
|
|
|
* Pointer to the MONITOR which shall be deleted
|
2004-11-16 17:25:47 +00:00
|
|
|
*/
|
|
|
|
static
|
|
|
|
void
|
2010-01-11 07:36:48 +00:00
|
|
|
IntDestroyMonitorObject(IN PMONITOR pMonitor)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
RtlFreeUnicodeString(&pMonitor->DeviceName);
|
2008-02-13 00:46:23 +00:00
|
|
|
UserDereferenceObject(pMonitor);
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR FASTCALL
|
2005-09-08 16:18:51 +00:00
|
|
|
UserGetMonitorObject(IN HMONITOR hMonitor)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR Monitor;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-19 00:02:39 +00:00
|
|
|
if (!hMonitor)
|
|
|
|
{
|
|
|
|
SetLastWin32Error(ERROR_INVALID_MONITOR_HANDLE);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
|
|
|
|
2010-01-11 07:36:48 +00:00
|
|
|
Monitor = (PMONITOR)UserGetObject(gHandleTable, hMonitor, otMonitor);
|
2005-09-07 20:59:26 +00:00
|
|
|
if (!Monitor)
|
|
|
|
{
|
|
|
|
SetLastWin32Error(ERROR_INVALID_MONITOR_HANDLE);
|
2004-11-16 17:25:47 +00:00
|
|
|
return NULL;
|
2005-09-07 20:59:26 +00:00
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2010-01-15 13:47:25 +00:00
|
|
|
ASSERT(Monitor->head.cLockObj >= 0);
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
return Monitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* IntAttachMonitor
|
|
|
|
*
|
2010-01-11 07:36:48 +00:00
|
|
|
* Creates a new MONITOR and appends it to the list of monitors.
|
2004-11-16 17:25:47 +00:00
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
2009-03-20 18:02:55 +00:00
|
|
|
* pGdiDevice Pointer to the PDEVOBJ onto which the monitor was attached
|
2004-11-16 17:25:47 +00:00
|
|
|
* DisplayNumber Display Number (starting with 0)
|
|
|
|
*
|
|
|
|
* Return value
|
|
|
|
* Returns a NTSTATUS
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2009-03-20 18:02:55 +00:00
|
|
|
IntAttachMonitor(IN PDEVOBJ *pGdiDevice,
|
2004-11-16 17:25:47 +00:00
|
|
|
IN ULONG DisplayNumber)
|
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR Monitor;
|
2005-09-07 21:25:42 +00:00
|
|
|
WCHAR Buffer[CCHDEVICENAME];
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
DPRINT("Attaching monitor...\n");
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
/* create new monitor object */
|
|
|
|
Monitor = IntCreateMonitorObject();
|
|
|
|
if (Monitor == NULL)
|
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
DPRINT("Couldnt create monitor object\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2008-05-20 15:20:28 +00:00
|
|
|
_snwprintf(Buffer, CCHDEVICENAME, L"\\\\.\\DISPLAY%d", DisplayNumber + 1);
|
2005-09-07 21:25:42 +00:00
|
|
|
if (!RtlCreateUnicodeString(&Monitor->DeviceName, Buffer))
|
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
DPRINT("Couldn't duplicate monitor name!\n");
|
2008-02-13 00:46:23 +00:00
|
|
|
UserDereferenceObject(Monitor);
|
2010-01-15 13:47:25 +00:00
|
|
|
UserDeleteObject(UserHMGetHandle(Monitor), otMonitor);
|
2004-11-16 17:25:47 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
Monitor->GdiDevice = pGdiDevice;
|
2010-01-11 07:36:48 +00:00
|
|
|
Monitor->rcMonitor.left = 0;
|
|
|
|
Monitor->rcMonitor.top = 0;
|
|
|
|
Monitor->rcMonitor.right = Monitor->rcMonitor.left + pGdiDevice->gdiinfo.ulHorzRes;
|
|
|
|
Monitor->rcMonitor.bottom = Monitor->rcMonitor.top + pGdiDevice->gdiinfo.ulVertRes;
|
|
|
|
Monitor->rcWork = Monitor->rcMonitor;
|
|
|
|
Monitor->cWndStack = 0;
|
|
|
|
|
2010-01-21 13:18:33 +00:00
|
|
|
Monitor->hrgnMonitor= IntSysCreateRectRgnIndirect( &Monitor->rcMonitor );
|
2010-01-12 05:25:22 +00:00
|
|
|
|
2010-01-21 13:18:33 +00:00
|
|
|
IntGdiSetRegionOwner(Monitor->hrgnMonitor, GDI_OBJ_HMGR_PUBLIC);
|
2010-01-12 05:25:22 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
if (gMonitorList == NULL)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
DPRINT("Primary monitor is beeing attached\n");
|
|
|
|
Monitor->IsPrimary = TRUE;
|
2005-09-08 16:18:51 +00:00
|
|
|
gMonitorList = Monitor;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR p;
|
2004-11-16 17:25:47 +00:00
|
|
|
DPRINT("Additional monitor is beeing attached\n");
|
2005-09-08 16:18:51 +00:00
|
|
|
for (p = gMonitorList; p->Next != NULL; p = p->Next)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
|
|
|
p->Next = Monitor;
|
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
Monitor->Prev = p;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IntDetachMonitor
|
|
|
|
*
|
2010-01-11 07:36:48 +00:00
|
|
|
* Deletes a MONITOR and removes it from the list of monitors.
|
2004-11-16 17:25:47 +00:00
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
2009-03-20 18:02:55 +00:00
|
|
|
* pGdiDevice Pointer to the PDEVOBJ from which the monitor was detached
|
2004-11-16 17:25:47 +00:00
|
|
|
*
|
|
|
|
* Return value
|
|
|
|
* Returns a NTSTATUS
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2009-03-20 18:02:55 +00:00
|
|
|
IntDetachMonitor(IN PDEVOBJ *pGdiDevice)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR Monitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
for (Monitor = gMonitorList; Monitor != NULL; Monitor = Monitor->Next)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
if (Monitor->GdiDevice == pGdiDevice)
|
2005-09-07 21:25:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (Monitor == NULL)
|
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
/* no monitor for given device found */
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (Monitor->IsPrimary && (Monitor->Next != NULL || Monitor->Prev != NULL))
|
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR NewPrimaryMonitor = (Monitor->Prev != NULL) ? (Monitor->Prev) : (Monitor->Next);
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-11-19 22:13:35 +00:00
|
|
|
ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&NewPrimaryMonitor->Lock);
|
2004-11-16 17:25:47 +00:00
|
|
|
NewPrimaryMonitor->IsPrimary = TRUE;
|
2005-11-19 22:13:35 +00:00
|
|
|
ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&NewPrimaryMonitor->Lock);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
if (gMonitorList == Monitor)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2005-09-08 16:18:51 +00:00
|
|
|
gMonitorList = Monitor->Next;
|
2004-11-16 17:25:47 +00:00
|
|
|
if (Monitor->Next != NULL)
|
2005-09-07 21:25:42 +00:00
|
|
|
Monitor->Next->Prev = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
Monitor->Prev->Next = Monitor->Next;
|
|
|
|
if (Monitor->Next != NULL)
|
2005-09-07 21:25:42 +00:00
|
|
|
Monitor->Next->Prev = Monitor->Prev;
|
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
IntDestroyMonitorObject(Monitor);
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IntGetPrimaryMonitor
|
|
|
|
*
|
2010-01-11 07:36:48 +00:00
|
|
|
* Returns a PMONITOR for the primary monitor
|
2004-11-16 17:25:47 +00:00
|
|
|
*
|
|
|
|
* Return value
|
2010-01-11 07:36:48 +00:00
|
|
|
* PMONITOR
|
2004-11-16 17:25:47 +00:00
|
|
|
*/
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR
|
|
|
|
FASTCALL
|
2004-11-16 17:25:47 +00:00
|
|
|
IntGetPrimaryMonitor()
|
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR Monitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
for (Monitor = gMonitorList; Monitor != NULL; Monitor = Monitor->Next)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
/* FIXME: I guess locking the monitor is not neccessary to read 1 int */
|
|
|
|
if (Monitor->IsPrimary)
|
2005-09-07 21:25:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return Monitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IntGetMonitorsFromRect
|
|
|
|
*
|
|
|
|
* Returns a list of monitor handles/rectangles. The rectangles in the list are
|
|
|
|
* the areas of intersection with the monitors.
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
|
|
|
* pRect
|
|
|
|
* Rectangle in desktop coordinates. If this is NULL all monitors are
|
|
|
|
* returned and the rect list is filled with the sizes of the monitors.
|
|
|
|
*
|
|
|
|
* hMonitorList
|
|
|
|
* Pointer to an array of HMONITOR which is filled with monitor handles.
|
|
|
|
* Can be NULL
|
|
|
|
*
|
|
|
|
* monitorRectList
|
|
|
|
* Pointer to an array of RECT which is filled with intersection rects in
|
|
|
|
* desktop coordinates.
|
|
|
|
* Can be NULL, will be ignored if no intersecting monitor is found and
|
|
|
|
* flags is MONITOR_DEFAULTTONEAREST
|
|
|
|
*
|
|
|
|
* listSize
|
|
|
|
* Size of the hMonitorList and monitorRectList arguments. If this is zero
|
|
|
|
* hMonitorList and monitorRectList are ignored.
|
|
|
|
*
|
|
|
|
* flags
|
|
|
|
* Either 0 or MONITOR_DEFAULTTONEAREST (ignored if rect is NULL)
|
|
|
|
*
|
|
|
|
* Returns
|
|
|
|
* The number of monitors which intersect the specified region.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
UINT
|
2009-03-19 01:42:34 +00:00
|
|
|
IntGetMonitorsFromRect(OPTIONAL IN LPCRECTL pRect,
|
2004-11-16 17:25:47 +00:00
|
|
|
OPTIONAL OUT HMONITOR *hMonitorList,
|
2009-03-19 01:42:34 +00:00
|
|
|
OPTIONAL OUT PRECTL monitorRectList,
|
2004-11-16 17:25:47 +00:00
|
|
|
OPTIONAL IN DWORD listSize,
|
|
|
|
OPTIONAL IN DWORD flags)
|
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR Monitor, NearestMonitor = NULL, PrimaryMonitor = NULL;
|
2005-09-07 21:25:42 +00:00
|
|
|
UINT iCount = 0;
|
|
|
|
LONG iNearestDistanceX = 0x7fffffff, iNearestDistanceY = 0x7fffffff;
|
|
|
|
|
|
|
|
/* find monitors which intersect the rectangle */
|
2005-09-08 16:18:51 +00:00
|
|
|
for (Monitor = gMonitorList; Monitor != NULL; Monitor = Monitor->Next)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL MonitorRect, IntersectionRect;
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-11-19 22:13:35 +00:00
|
|
|
ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&Monitor->Lock);
|
2004-11-16 17:25:47 +00:00
|
|
|
MonitorRect.left = 0; /* FIXME: get origin */
|
|
|
|
MonitorRect.top = 0; /* FIXME: get origin */
|
2009-08-16 12:57:41 +00:00
|
|
|
MonitorRect.right = MonitorRect.left + Monitor->GdiDevice->gdiinfo.ulHorzRes;
|
|
|
|
MonitorRect.bottom = MonitorRect.top + Monitor->GdiDevice->gdiinfo.ulVertRes;
|
2005-11-19 22:13:35 +00:00
|
|
|
ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&Monitor->Lock);
|
2004-11-16 17:25:47 +00:00
|
|
|
|
|
|
|
DPRINT("MonitorRect: left = %d, top = %d, right = %d, bottom = %d\n",
|
|
|
|
MonitorRect.left, MonitorRect.top, MonitorRect.right, MonitorRect.bottom);
|
|
|
|
|
2008-05-26 13:50:36 +00:00
|
|
|
if (flags == MONITOR_DEFAULTTOPRIMARY && Monitor->IsPrimary)
|
|
|
|
{
|
|
|
|
PrimaryMonitor = Monitor;
|
|
|
|
}
|
|
|
|
|
2004-11-16 17:25:47 +00:00
|
|
|
if (pRect != NULL)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
|
|
|
BOOL intersects = TRUE;
|
|
|
|
|
|
|
|
/* check if the rect intersects the monitor */
|
|
|
|
if ((pRect->right < MonitorRect.left) || (pRect->left > MonitorRect.right) ||
|
|
|
|
(pRect->bottom < MonitorRect.top) || (pRect->top > MonitorRect.bottom))
|
|
|
|
{
|
|
|
|
intersects = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags == MONITOR_DEFAULTTONEAREST && !intersects)
|
|
|
|
{
|
|
|
|
INT distanceX, distanceY;
|
|
|
|
|
|
|
|
distanceX = MIN(ABS(MonitorRect.left - pRect->right),
|
|
|
|
ABS(pRect->left - MonitorRect.right));
|
|
|
|
distanceY = MIN(ABS(MonitorRect.top - pRect->bottom),
|
|
|
|
ABS(pRect->top - MonitorRect.bottom));
|
|
|
|
|
|
|
|
if (((distanceX < iNearestDistanceX) && (distanceY <= iNearestDistanceY)) ||
|
2004-11-16 17:25:47 +00:00
|
|
|
((distanceX <= iNearestDistanceX) && (distanceY < iNearestDistanceY)))
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
|
|
|
iNearestDistanceX = distanceX;
|
|
|
|
iNearestDistanceY = distanceY;
|
|
|
|
NearestMonitor = Monitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (!intersects)
|
2004-11-16 17:25:47 +00:00
|
|
|
continue;
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
/* calculate intersection */
|
|
|
|
IntersectionRect.left = MAX(MonitorRect.left, pRect->left);
|
|
|
|
IntersectionRect.top = MAX(MonitorRect.top, pRect->top);
|
|
|
|
IntersectionRect.right = MIN(MonitorRect.right, pRect->right);
|
|
|
|
IntersectionRect.bottom = MIN(MonitorRect.bottom, pRect->bottom);
|
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
else
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
|
|
|
IntersectionRect = MonitorRect;
|
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
|
|
|
if (iCount < listSize)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
|
|
|
if (hMonitorList != NULL)
|
2010-01-15 13:47:25 +00:00
|
|
|
hMonitorList[iCount] = UserHMGetHandle(Monitor);
|
2005-09-07 21:25:42 +00:00
|
|
|
if (monitorRectList != NULL)
|
2004-11-16 17:25:47 +00:00
|
|
|
monitorRectList[iCount] = IntersectionRect;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
iCount++;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (iCount == 0 && flags == MONITOR_DEFAULTTONEAREST)
|
|
|
|
{
|
2004-11-16 17:25:47 +00:00
|
|
|
if (iCount < listSize)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
|
|
|
if (hMonitorList != NULL)
|
2010-01-15 13:47:25 +00:00
|
|
|
hMonitorList[iCount] = UserHMGetHandle(NearestMonitor);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-11-16 17:25:47 +00:00
|
|
|
iCount++;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2008-05-20 15:20:28 +00:00
|
|
|
else if (iCount == 0 && flags == MONITOR_DEFAULTTOPRIMARY)
|
|
|
|
{
|
|
|
|
if (iCount < listSize)
|
|
|
|
{
|
|
|
|
if (hMonitorList != NULL)
|
2010-01-15 13:47:25 +00:00
|
|
|
hMonitorList[iCount] = UserHMGetHandle(PrimaryMonitor);
|
2008-05-20 15:20:28 +00:00
|
|
|
}
|
|
|
|
iCount++;
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
return iCount;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
|
|
|
/* NtUserEnumDisplayMonitors
|
|
|
|
*
|
|
|
|
* Enumerates display monitors which intersect the given HDC/cliprect
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
|
|
|
* hDC
|
|
|
|
* Handle to a DC for which to enum intersecting monitors. If this is NULL
|
|
|
|
* it returns all monitors which are part of the current virtual screen.
|
|
|
|
*
|
|
|
|
* pRect
|
|
|
|
* Clipping rectangle with coordinate system origin at the DCs origin if the
|
|
|
|
* given HDC is not NULL or in virtual screen coordinated if it is NULL.
|
|
|
|
* Can be NULL
|
|
|
|
*
|
|
|
|
* hMonitorList
|
|
|
|
* Pointer to an array of HMONITOR which is filled with monitor handles.
|
|
|
|
* Can be NULL
|
|
|
|
*
|
|
|
|
* monitorRectList
|
|
|
|
* Pointer to an array of RECT which is filled with intersection rectangles.
|
|
|
|
* Can be NULL
|
|
|
|
*
|
|
|
|
* listSize
|
|
|
|
* Size of the hMonitorList and monitorRectList arguments. If this is zero
|
|
|
|
* hMonitorList and monitorRectList are ignored.
|
|
|
|
*
|
|
|
|
* Returns
|
|
|
|
* The number of monitors which intersect the specified region or -1 on failure.
|
|
|
|
*/
|
|
|
|
INT
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2004-11-16 17:25:47 +00:00
|
|
|
NtUserEnumDisplayMonitors(
|
2005-09-07 21:25:42 +00:00
|
|
|
OPTIONAL IN HDC hDC,
|
2009-03-19 01:42:34 +00:00
|
|
|
OPTIONAL IN LPCRECTL pRect,
|
2005-09-07 21:25:42 +00:00
|
|
|
OPTIONAL OUT HMONITOR *hMonitorList,
|
2009-03-19 01:42:34 +00:00
|
|
|
OPTIONAL OUT PRECTL monitorRectList,
|
2005-09-07 21:25:42 +00:00
|
|
|
OPTIONAL IN DWORD listSize)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
INT numMonitors, i;
|
|
|
|
HMONITOR *safeHMonitorList = NULL;
|
2009-03-19 01:42:34 +00:00
|
|
|
PRECTL safeRectList = NULL;
|
|
|
|
RECTL rect, *myRect;
|
|
|
|
RECTL dcRect;
|
2005-09-07 21:25:42 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
/* get rect */
|
|
|
|
if (pRect != NULL)
|
|
|
|
{
|
|
|
|
status = MmCopyFromCaller(&rect, pRect, sizeof (RECT));
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
{
|
|
|
|
DPRINT("MmCopyFromCaller() failed!\n");
|
|
|
|
SetLastNtError(status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hDC != NULL)
|
|
|
|
{
|
|
|
|
PDC dc;
|
|
|
|
HRGN dcVisRgn;
|
|
|
|
INT regionType;
|
|
|
|
|
|
|
|
/* get visible region bounding rect */
|
|
|
|
dc = DC_LockDc(hDC);
|
|
|
|
if (dc == NULL)
|
|
|
|
{
|
|
|
|
DPRINT("DC_LockDc() failed!\n");
|
|
|
|
/* FIXME: setlasterror? */
|
|
|
|
return -1;
|
|
|
|
}
|
2009-03-20 01:35:49 +00:00
|
|
|
dcVisRgn = dc->rosdc.hVisRgn;
|
2005-09-07 21:25:42 +00:00
|
|
|
DC_UnlockDc(dc);
|
|
|
|
|
|
|
|
regionType = NtGdiGetRgnBox(dcVisRgn, &dcRect);
|
|
|
|
if (regionType == 0)
|
|
|
|
{
|
|
|
|
DPRINT("NtGdiGetRgnBox() failed!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (regionType == NULLREGION)
|
|
|
|
return 0;
|
|
|
|
if (regionType == COMPLEXREGION)
|
|
|
|
{ /* TODO: warning */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if hDC and pRect are given the area of interest is pRect with
|
|
|
|
coordinate origin at the DC position */
|
|
|
|
if (pRect != NULL)
|
|
|
|
{
|
|
|
|
rect.left += dcRect.left;
|
|
|
|
rect.right += dcRect.left;
|
|
|
|
rect.top += dcRect.top;
|
|
|
|
rect.bottom += dcRect.top;
|
|
|
|
}
|
|
|
|
/* if hDC is given and pRect is not the area of interest is the
|
|
|
|
bounding rect of hDC */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect = dcRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hDC == NULL && pRect == NULL)
|
|
|
|
myRect = NULL;
|
|
|
|
else
|
|
|
|
myRect = ▭
|
|
|
|
|
|
|
|
/* find intersecting monitors */
|
|
|
|
numMonitors = IntGetMonitorsFromRect(myRect, NULL, NULL, 0, 0);
|
|
|
|
if (numMonitors == 0 || listSize == 0 ||
|
|
|
|
(hMonitorList == NULL && monitorRectList == NULL))
|
|
|
|
{
|
|
|
|
DPRINT("numMonitors = %d\n", numMonitors);
|
|
|
|
return numMonitors;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hMonitorList != NULL && listSize != 0)
|
|
|
|
{
|
|
|
|
safeHMonitorList = ExAllocatePool(PagedPool, sizeof (HMONITOR) * listSize);
|
|
|
|
if (safeHMonitorList == NULL)
|
|
|
|
{
|
|
|
|
/* FIXME: SetLastWin32Error? */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (monitorRectList != NULL && listSize != 0)
|
|
|
|
{
|
|
|
|
safeRectList = ExAllocatePool(PagedPool, sizeof (RECT) * listSize);
|
|
|
|
if (safeRectList == NULL)
|
|
|
|
{
|
|
|
|
ExFreePool(safeHMonitorList);
|
|
|
|
/* FIXME: SetLastWin32Error? */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get intersecting monitors */
|
|
|
|
numMonitors = IntGetMonitorsFromRect(myRect, safeHMonitorList, safeRectList,
|
|
|
|
listSize, 0 );
|
|
|
|
|
|
|
|
if (hDC != NULL && pRect != NULL && safeRectList != NULL)
|
|
|
|
for (i = 0; i < numMonitors; i++)
|
|
|
|
{
|
|
|
|
safeRectList[i].left -= dcRect.left;
|
|
|
|
safeRectList[i].right -= dcRect.left;
|
|
|
|
safeRectList[i].top -= dcRect.top;
|
|
|
|
safeRectList[i].bottom -= dcRect.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output result */
|
|
|
|
if (hMonitorList != NULL && listSize != 0)
|
|
|
|
{
|
|
|
|
status = MmCopyToCaller(hMonitorList, safeHMonitorList, sizeof (HMONITOR) * listSize);
|
|
|
|
ExFreePool(safeHMonitorList);
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
{
|
|
|
|
ExFreePool(safeRectList);
|
|
|
|
SetLastNtError(status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (monitorRectList != NULL && listSize != 0)
|
|
|
|
{
|
|
|
|
status = MmCopyToCaller(monitorRectList, safeRectList, sizeof (RECT) * listSize);
|
|
|
|
ExFreePool(safeRectList);
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
{
|
|
|
|
SetLastNtError(status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numMonitors;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NtUserGetMonitorInfo
|
|
|
|
*
|
|
|
|
* Retrieves information about a given monitor
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
|
|
|
* hMonitor
|
|
|
|
* Handle to a monitor for which to get information
|
|
|
|
*
|
|
|
|
* pMonitorInfo
|
|
|
|
* Pointer to a MONITORINFO struct which is filled with the information.
|
|
|
|
* The cbSize member must be set to sizeof(MONITORINFO) or
|
|
|
|
* sizeof(MONITORINFOEX). Even if set to sizeof(MONITORINFOEX) only parts
|
|
|
|
* from MONITORINFO will be filled.
|
|
|
|
*
|
|
|
|
* pDevice
|
|
|
|
* Pointer to a UNICODE_STRING which will recieve the device's name. The
|
|
|
|
* length should be CCHDEVICENAME
|
|
|
|
* Can be NULL
|
|
|
|
*
|
|
|
|
* Return value
|
|
|
|
* TRUE on success; FALSE on failure (calls SetLastNtError())
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2004-11-16 17:25:47 +00:00
|
|
|
NtUserGetMonitorInfo(
|
2005-09-07 21:25:42 +00:00
|
|
|
IN HMONITOR hMonitor,
|
|
|
|
OUT LPMONITORINFO pMonitorInfo)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR Monitor;
|
2005-09-07 21:25:42 +00:00
|
|
|
MONITORINFOEXW MonitorInfo;
|
|
|
|
NTSTATUS Status;
|
2005-09-08 16:18:51 +00:00
|
|
|
DECLARE_RETURN(BOOL);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
DPRINT("Enter NtUserGetMonitorInfo\n");
|
|
|
|
UserEnterShared();
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
/* get monitor object */
|
2005-09-08 16:18:51 +00:00
|
|
|
if (!(Monitor = UserGetMonitorObject(hMonitor)))
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
|
|
|
DPRINT("Couldnt find monitor 0x%lx\n", hMonitor);
|
2005-09-08 16:18:51 +00:00
|
|
|
RETURN(FALSE);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2005-12-28 16:27:20 +00:00
|
|
|
if(pMonitorInfo == NULL)
|
|
|
|
{
|
|
|
|
SetLastNtError(STATUS_INVALID_PARAMETER);
|
|
|
|
RETURN(FALSE);
|
|
|
|
}
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
/* get size of pMonitorInfo */
|
|
|
|
Status = MmCopyFromCaller(&MonitorInfo.cbSize, &pMonitorInfo->cbSize, sizeof (MonitorInfo.cbSize));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastNtError(Status);
|
2005-09-08 16:18:51 +00:00
|
|
|
RETURN(FALSE);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
if ((MonitorInfo.cbSize != sizeof (MONITORINFO)) &&
|
|
|
|
(MonitorInfo.cbSize != sizeof (MONITORINFOEXW)))
|
|
|
|
{
|
|
|
|
SetLastNtError(STATUS_INVALID_PARAMETER);
|
2005-09-08 16:18:51 +00:00
|
|
|
RETURN(FALSE);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill monitor info */
|
|
|
|
MonitorInfo.rcMonitor.left = 0; /* FIXME: get origin */
|
|
|
|
MonitorInfo.rcMonitor.top = 0; /* FIXME: get origin */
|
2009-08-16 12:57:41 +00:00
|
|
|
MonitorInfo.rcMonitor.right = MonitorInfo.rcMonitor.left + Monitor->GdiDevice->gdiinfo.ulHorzRes;
|
|
|
|
MonitorInfo.rcMonitor.bottom = MonitorInfo.rcMonitor.top + Monitor->GdiDevice->gdiinfo.ulVertRes;
|
2005-09-07 21:25:42 +00:00
|
|
|
MonitorInfo.rcWork = MonitorInfo.rcMonitor; /* FIXME: use DEVMODE panning to calculate work area? */
|
|
|
|
MonitorInfo.dwFlags = 0;
|
2005-09-08 16:18:51 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (Monitor->IsPrimary)
|
|
|
|
MonitorInfo.dwFlags |= MONITORINFOF_PRIMARY;
|
|
|
|
|
|
|
|
/* fill device name */
|
|
|
|
if (MonitorInfo.cbSize == sizeof (MONITORINFOEXW))
|
|
|
|
{
|
|
|
|
WCHAR nul = L'\0';
|
|
|
|
INT len = Monitor->DeviceName.Length;
|
|
|
|
if (len >= CCHDEVICENAME * sizeof (WCHAR))
|
|
|
|
len = (CCHDEVICENAME - 1) * sizeof (WCHAR);
|
|
|
|
|
|
|
|
memcpy(MonitorInfo.szDevice, Monitor->DeviceName.Buffer, len);
|
|
|
|
memcpy(MonitorInfo.szDevice + (len / sizeof (WCHAR)), &nul, sizeof (WCHAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output data */
|
|
|
|
Status = MmCopyToCaller(pMonitorInfo, &MonitorInfo, MonitorInfo.cbSize);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("GetMonitorInfo: MmCopyToCaller failed\n");
|
|
|
|
SetLastNtError(Status);
|
2005-09-08 16:18:51 +00:00
|
|
|
RETURN(FALSE);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("GetMonitorInfo: success\n");
|
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
RETURN(TRUE);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
CLEANUP:
|
|
|
|
DPRINT("Leave NtUserGetMonitorInfo, ret=%i\n",_ret_);
|
|
|
|
UserLeave();
|
|
|
|
END_CLEANUP;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NtUserMonitorFromPoint
|
|
|
|
*
|
|
|
|
* Returns a handle to the monitor containing the given point.
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
|
|
|
* point
|
|
|
|
* Point for which to find monitor
|
|
|
|
*
|
|
|
|
* dwFlags
|
|
|
|
* Specifies the behaviour if the point isn't on any of the monitors.
|
|
|
|
*
|
|
|
|
* Return value
|
|
|
|
* If the point is found a handle to the monitor is returned; if not the
|
|
|
|
* return value depends on dwFlags
|
|
|
|
*/
|
|
|
|
HMONITOR
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2004-11-16 17:25:47 +00:00
|
|
|
NtUserMonitorFromPoint(
|
2005-09-07 21:25:42 +00:00
|
|
|
IN POINT point,
|
|
|
|
IN DWORD dwFlags)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
INT NumMonitors;
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL InRect;
|
2005-09-07 21:25:42 +00:00
|
|
|
HMONITOR hMonitor = NULL;
|
|
|
|
|
|
|
|
/* fill inRect */
|
|
|
|
InRect.left = InRect.right = point.x;
|
|
|
|
InRect.top = InRect.bottom = point.y;
|
|
|
|
|
|
|
|
/* find intersecting monitor */
|
|
|
|
NumMonitors = IntGetMonitorsFromRect(&InRect, &hMonitor, NULL, 1, 0);
|
|
|
|
if (NumMonitors < 0)
|
|
|
|
{
|
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hMonitor == NULL)
|
|
|
|
{
|
|
|
|
if (dwFlags == MONITOR_DEFAULTTOPRIMARY)
|
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR MonitorObj = IntGetPrimaryMonitor();
|
2005-09-07 21:25:42 +00:00
|
|
|
if (MonitorObj)
|
2010-01-15 13:47:25 +00:00
|
|
|
hMonitor = UserHMGetHandle(MonitorObj);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
else if (dwFlags == MONITOR_DEFAULTTONEAREST)
|
|
|
|
{
|
|
|
|
NumMonitors = IntGetMonitorsFromRect(&InRect, &hMonitor, NULL,
|
|
|
|
1, MONITOR_DEFAULTTONEAREST);
|
|
|
|
/*ASSERT( (numMonitors > 0) && (hMonitor != NULL) );*/
|
|
|
|
}
|
|
|
|
/* else flag is DEFAULTTONULL */
|
|
|
|
}
|
|
|
|
|
|
|
|
return hMonitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NtUserMonitorFromRect
|
|
|
|
*
|
|
|
|
* Returns a handle to the monitor having the largest intersection with a
|
|
|
|
* given rectangle
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
*
|
|
|
|
* pRect
|
|
|
|
* Pointer to a RECT for which to find monitor
|
|
|
|
*
|
|
|
|
* dwFlags
|
|
|
|
* Specifies the behaviour if no monitor intersects the given rect
|
|
|
|
*
|
|
|
|
* Return value
|
|
|
|
* If a monitor intersects the rect a handle to it is returned; if not the
|
|
|
|
* return value depends on dwFlags
|
|
|
|
*/
|
|
|
|
HMONITOR
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2004-11-16 17:25:47 +00:00
|
|
|
NtUserMonitorFromRect(
|
2009-03-19 01:42:34 +00:00
|
|
|
IN LPCRECTL pRect,
|
2005-09-07 21:25:42 +00:00
|
|
|
IN DWORD dwFlags)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
INT numMonitors, iLargestArea = -1, i;
|
2009-03-19 01:42:34 +00:00
|
|
|
PRECTL rectList;
|
2005-09-07 21:25:42 +00:00
|
|
|
HMONITOR *hMonitorList;
|
|
|
|
HMONITOR hMonitor = NULL;
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL rect;
|
2005-09-07 21:25:42 +00:00
|
|
|
NTSTATUS status;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
/* get rect */
|
|
|
|
status = MmCopyFromCaller(&rect, pRect, sizeof (RECT));
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
{
|
|
|
|
SetLastNtError(status);
|
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find intersecting monitors */
|
|
|
|
numMonitors = IntGetMonitorsFromRect(&rect, NULL, NULL, 0, 0);
|
|
|
|
if (numMonitors < 0)
|
|
|
|
{
|
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numMonitors == 0)
|
|
|
|
{
|
|
|
|
if (dwFlags == MONITOR_DEFAULTTOPRIMARY)
|
|
|
|
{
|
2010-01-11 07:36:48 +00:00
|
|
|
PMONITOR monitorObj = IntGetPrimaryMonitor();
|
2005-09-07 21:25:42 +00:00
|
|
|
if (monitorObj)
|
2010-01-15 13:47:25 +00:00
|
|
|
return UserHMGetHandle(monitorObj);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
else if (dwFlags == MONITOR_DEFAULTTONEAREST)
|
|
|
|
{
|
|
|
|
numMonitors = IntGetMonitorsFromRect(&rect, &hMonitor, NULL,
|
|
|
|
1, MONITOR_DEFAULTTONEAREST);
|
|
|
|
if (numMonitors <= 0)
|
|
|
|
{
|
|
|
|
/* error? */
|
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numMonitors > 0)
|
|
|
|
return hMonitor;
|
|
|
|
}
|
|
|
|
/* else flag is DEFAULTTONULL */
|
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hMonitorList = ExAllocatePool(PagedPool, sizeof (HMONITOR) * numMonitors);
|
|
|
|
if (hMonitorList == NULL)
|
|
|
|
{
|
|
|
|
/* FIXME: SetLastWin32Error? */
|
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
rectList = ExAllocatePool(PagedPool, sizeof (RECT) * numMonitors);
|
|
|
|
if (rectList == NULL)
|
|
|
|
{
|
|
|
|
ExFreePool(hMonitorList);
|
|
|
|
/* FIXME: SetLastWin32Error? */
|
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get intersecting monitors */
|
|
|
|
numMonitors = IntGetMonitorsFromRect(&rect, hMonitorList, rectList,
|
|
|
|
numMonitors, 0);
|
|
|
|
if (numMonitors <= 0)
|
|
|
|
{
|
2005-12-29 13:13:14 +00:00
|
|
|
ExFreePool(hMonitorList);
|
|
|
|
ExFreePool(rectList);
|
2005-09-07 21:25:42 +00:00
|
|
|
return (HMONITOR)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find largest intersection */
|
|
|
|
for (i = 0; i < numMonitors; i++)
|
|
|
|
{
|
|
|
|
INT area = (rectList[i].right - rectList[i].left) *
|
|
|
|
(rectList[i].bottom - rectList[i].top);
|
|
|
|
if (area > iLargestArea)
|
|
|
|
{
|
|
|
|
hMonitor = hMonitorList[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExFreePool(hMonitorList);
|
|
|
|
ExFreePool(rectList);
|
|
|
|
|
|
|
|
return hMonitor;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HMONITOR
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2004-11-16 17:25:47 +00:00
|
|
|
NtUserMonitorFromWindow(
|
2005-09-07 21:25:42 +00:00
|
|
|
IN HWND hWnd,
|
|
|
|
IN DWORD dwFlags)
|
2004-11-16 17:25:47 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
PWINDOW_OBJECT Window;
|
|
|
|
HMONITOR hMonitor = NULL;
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL Rect;
|
2005-09-08 16:18:51 +00:00
|
|
|
DECLARE_RETURN(HMONITOR);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
DPRINT("Enter NtUserMonitorFromWindow\n");
|
|
|
|
UserEnterShared();
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
if (!(Window = UserGetWindowObject(hWnd)))
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2008-05-20 15:20:28 +00:00
|
|
|
if (dwFlags == MONITOR_DEFAULTTONULL)
|
|
|
|
{
|
|
|
|
RETURN(hMonitor);
|
|
|
|
}
|
|
|
|
IntGetMonitorsFromRect(NULL, &hMonitor, NULL, 1, dwFlags);
|
|
|
|
RETURN(hMonitor);
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2004-12-14 23:38:14 +00:00
|
|
|
|
2008-07-05 09:19:56 +00:00
|
|
|
if (!Window->Wnd)
|
|
|
|
RETURN(hMonitor);
|
|
|
|
|
2009-07-20 23:18:16 +00:00
|
|
|
Rect.left = Rect.right = Window->Wnd->rcWindow.left;
|
|
|
|
Rect.top = Rect.bottom = Window->Wnd->rcWindow.bottom;
|
2004-12-14 23:38:14 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
IntGetMonitorsFromRect(&Rect, &hMonitor, NULL, 1, dwFlags);
|
2004-12-14 23:38:14 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
RETURN(hMonitor);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
CLEANUP:
|
|
|
|
DPRINT("Leave NtUserMonitorFromWindow, ret=%i\n",_ret_);
|
|
|
|
UserLeave();
|
2007-10-19 23:21:45 +00:00
|
|
|
END_CLEANUP;
|
2004-11-16 17:25:47 +00:00
|
|
|
}
|