winemac.drv: Implement EnumDisplayMonitors.

This commit is contained in:
Ken Thomases 2012-12-20 19:02:28 -06:00 committed by Alexandre Julliard
parent 49dc686ae9
commit 21c4fc3326
6 changed files with 352 additions and 58 deletions

View File

@ -1,9 +1,13 @@
MODULE = winemac.drv
IMPORTS = user32 gdi32 advapi32
EXTRALIBS = @APPLICATIONSERVICESLIB@
EXTRALIBS = -framework AppKit
C_SRCS = \
display.c \
gdi.c \
macdrv_main.c
OBJC_SRCS = \
cocoa_display.m
@MAKE_DLL_RULES@

View File

@ -0,0 +1,103 @@
/*
* MACDRV Cocoa display settings
*
* Copyright 2011, 2012 Ken Thomases for CodeWeavers Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#import <AppKit/AppKit.h>
#include "macdrv_cocoa.h"
/***********************************************************************
* convert_display_rect
*
* Converts an NSRect in Cocoa's y-goes-up-from-bottom coordinate system
* to a CGRect in y-goes-down-from-top coordinates.
*/
static inline void convert_display_rect(CGRect* out_rect, NSRect in_rect,
NSRect primary_frame)
{
*out_rect = NSRectToCGRect(in_rect);
out_rect->origin.y = NSMaxY(primary_frame) - NSMaxY(in_rect);
}
/***********************************************************************
* macdrv_get_displays
*
* Returns information about the displays.
*
* Returns 0 on success and *displays contains a newly-allocated array
* of macdrv_display structures and *count contains the number of
* elements in that array. The first element of the array is the
* primary display. When the caller is done with the array, it should
* use macdrv_free_displays() to deallocate it.
*
* Returns non-zero on failure and *displays and *count are unchanged.
*/
int macdrv_get_displays(struct macdrv_display** displays, int* count)
{
int ret = -1;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSArray* screens = [NSScreen screens];
if (screens)
{
NSUInteger num_screens = [screens count];
struct macdrv_display* disps = malloc(num_screens * sizeof(disps[0]));
if (disps)
{
NSRect primary_frame;
NSUInteger i;
for (i = 0; i < num_screens; i++)
{
NSScreen* screen = [screens objectAtIndex:i];
NSRect frame = [screen frame];
NSRect visible_frame = [screen visibleFrame];
if (i == 0)
primary_frame = frame;
disps[i].displayID = [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
convert_display_rect(&disps[i].frame, frame, primary_frame);
convert_display_rect(&disps[i].work_frame, visible_frame,
primary_frame);
}
*displays = disps;
*count = num_screens;
ret = 0;
}
}
[pool release];
return ret;
}
/***********************************************************************
* macdrv_free_displays
*
* Deallocates an array of macdrv_display structures previously returned
* from macdrv_get_displays().
*/
void macdrv_free_displays(struct macdrv_display* displays)
{
free(displays);
}

107
dlls/winemac.drv/display.c Normal file
View File

@ -0,0 +1,107 @@
/*
* MACDRV display settings
*
* Copyright 2003 Alexander James Pasadyn
* Copyright 2011, 2012 Ken Thomases for CodeWeavers Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "macdrv.h"
#include "winuser.h"
WINE_DEFAULT_DEBUG_CHANNEL(display);
static inline HMONITOR display_id_to_monitor(CGDirectDisplayID display_id)
{
return (HMONITOR)(UINT_PTR)display_id;
}
static inline CGDirectDisplayID monitor_to_display_id(HMONITOR handle)
{
return (CGDirectDisplayID)(UINT_PTR)handle;
}
/***********************************************************************
* EnumDisplayMonitors (MACDRV.@)
*/
BOOL CDECL macdrv_EnumDisplayMonitors(HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPARAM lparam)
{
struct macdrv_display *displays;
int num_displays;
int i;
BOOL ret = TRUE;
TRACE("%p, %s, %p, %#lx\n", hdc, wine_dbgstr_rect(rect), proc, lparam);
if (hdc)
{
POINT origin;
RECT limit;
if (!GetDCOrgEx(hdc, &origin)) return FALSE;
if (GetClipBox(hdc, &limit) == ERROR) return FALSE;
if (rect && !IntersectRect(&limit, &limit, rect)) return TRUE;
if (macdrv_get_displays(&displays, &num_displays))
return FALSE;
for (i = 0; i < num_displays; i++)
{
RECT monrect = rect_from_cgrect(displays[i].frame);
OffsetRect(&monrect, -origin.x, -origin.y);
if (IntersectRect(&monrect, &monrect, &limit))
{
HMONITOR monitor = display_id_to_monitor(displays[i].displayID);
TRACE("monitor %d handle %p @ %s\n", i, monitor, wine_dbgstr_rect(&monrect));
if (!proc(monitor, hdc, &monrect, lparam))
{
ret = FALSE;
break;
}
}
}
}
else
{
if (macdrv_get_displays(&displays, &num_displays))
return FALSE;
for (i = 0; i < num_displays; i++)
{
RECT monrect = rect_from_cgrect(displays[i].frame);
RECT unused;
if (!rect || IntersectRect(&unused, &monrect, rect))
{
HMONITOR monitor = display_id_to_monitor(displays[i].displayID);
TRACE("monitor %d handle %p @ %s\n", i, monitor, wine_dbgstr_rect(&monrect));
if (!proc(monitor, 0, &monrect, lparam))
{
ret = FALSE;
break;
}
}
}
}
macdrv_free_displays(displays);
return ret;
}

View File

@ -27,63 +27,7 @@
# error You must include config.h to use this header
#endif
#define GetCurrentProcess MacGetCurrentProcess
#define GetCurrentThread MacGetCurrentThread
#define LoadResource MacLoadResource
#define AnimatePalette MacAnimatePalette
#define EqualRgn MacEqualRgn
#define FillRgn MacFillRgn
#define FrameRgn MacFrameRgn
#define GetPixel MacGetPixel
#define InvertRgn MacInvertRgn
#define LineTo MacLineTo
#define OffsetRgn MacOffsetRgn
#define PaintRgn MacPaintRgn
#define Polygon MacPolygon
#define ResizePalette MacResizePalette
#define SetRectRgn MacSetRectRgn
#define EqualRect MacEqualRect
#define FillRect MacFillRect
#define FrameRect MacFrameRect
#define GetCursor MacGetCursor
#define InvertRect MacInvertRect
#define OffsetRect MacOffsetRect
#define PtInRect MacPtInRect
#define SetCursor MacSetCursor
#define SetRect MacSetRect
#define ShowCursor MacShowCursor
#define UnionRect MacUnionRect
#include <ApplicationServices/ApplicationServices.h>
#undef GetCurrentProcess
#undef GetCurrentThread
#undef LoadResource
#undef AnimatePalette
#undef EqualRgn
#undef FillRgn
#undef FrameRgn
#undef GetPixel
#undef InvertRgn
#undef LineTo
#undef OffsetRgn
#undef PaintRgn
#undef Polygon
#undef ResizePalette
#undef SetRectRgn
#undef EqualRect
#undef FillRect
#undef FrameRect
#undef GetCursor
#undef InvertRect
#undef OffsetRect
#undef PtInRect
#undef SetCursor
#undef SetRect
#undef ShowCursor
#undef UnionRect
#undef DPRINTF
#include "macdrv_cocoa.h"
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
@ -91,6 +35,27 @@
#include "wine/gdi_driver.h"
static inline CGRect cgrect_from_rect(RECT rect)
{
if (rect.left >= rect.right || rect.top >= rect.bottom)
return CGRectNull;
return CGRectMake(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
}
static inline RECT rect_from_cgrect(CGRect cgrect)
{
static const RECT empty;
if (!CGRectIsNull(cgrect))
{
RECT rect = { CGRectGetMinX(cgrect), CGRectGetMinY(cgrect),
CGRectGetMaxX(cgrect), CGRectGetMaxY(cgrect) };
return rect;
}
return empty;
}
static inline const char *wine_dbgstr_cgrect(CGRect cgrect)
{
return wine_dbg_sprintf("(%g,%g)-(%g,%g)", CGRectGetMinX(cgrect), CGRectGetMinY(cgrect),

View File

@ -0,0 +1,111 @@
/*
* MACDRV Cocoa interface declarations
*
* Copyright 2011, 2012 Ken Thomases for CodeWeavers Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* This header serves as a C interface between the Wine parts of MACDRV
* and the Objective-C parts. It should restrict itself to C and the C-based
* Mac APIs, avoiding both Wine and Objective-C/Cocoa features, so that it can
* be included by both sides without contaminating either.
*/
#ifndef __WINE_MACDRV_COCOA_H
#define __WINE_MACDRV_COCOA_H
#define GetCurrentProcess MacGetCurrentProcess
#define GetCurrentThread MacGetCurrentThread
#define LoadResource MacLoadResource
#define AnimatePalette MacAnimatePalette
#define EqualRgn MacEqualRgn
#define FillRgn MacFillRgn
#define FrameRgn MacFrameRgn
#define GetPixel MacGetPixel
#define InvertRgn MacInvertRgn
#define LineTo MacLineTo
#define OffsetRgn MacOffsetRgn
#define PaintRgn MacPaintRgn
#define Polygon MacPolygon
#define ResizePalette MacResizePalette
#define SetRectRgn MacSetRectRgn
#define EqualRect MacEqualRect
#define FillRect MacFillRect
#define FrameRect MacFrameRect
#define GetCursor MacGetCursor
#define InvertRect MacInvertRect
#define OffsetRect MacOffsetRect
#define PtInRect MacPtInRect
#define SetCursor MacSetCursor
#define SetRect MacSetRect
#define ShowCursor MacShowCursor
#define UnionRect MacUnionRect
#include <ApplicationServices/ApplicationServices.h>
#undef GetCurrentProcess
#undef GetCurrentThread
#undef LoadResource
#undef AnimatePalette
#undef EqualRgn
#undef FillRgn
#undef FrameRgn
#undef GetPixel
#undef InvertRgn
#undef LineTo
#undef OffsetRgn
#undef PaintRgn
#undef Polygon
#undef ResizePalette
#undef SetRectRgn
#undef EqualRect
#undef FillRect
#undef FrameRect
#undef GetCursor
#undef InvertRect
#undef OffsetRect
#undef PtInRect
#undef SetCursor
#undef SetRect
#undef ShowCursor
#undef UnionRect
#undef DPRINTF
#ifndef DECLSPEC_HIDDEN
# if defined(__MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
# define DECLSPEC_HIDDEN
# elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
# define DECLSPEC_HIDDEN __attribute__((visibility ("hidden")))
# else
# define DECLSPEC_HIDDEN
# endif
#endif
struct macdrv_display {
CGDirectDisplayID displayID;
CGRect frame;
CGRect work_frame;
};
/* display */
extern int macdrv_get_displays(struct macdrv_display** displays, int* count) DECLSPEC_HIDDEN;
extern void macdrv_free_displays(struct macdrv_display* displays) DECLSPEC_HIDDEN;
#endif /* __WINE_MACDRV_COCOA_H */

View File

@ -1,3 +1,7 @@
# GDI driver
@ cdecl wine_get_gdi_driver(long) macdrv_get_gdi_driver
# USER driver
@ cdecl EnumDisplayMonitors(long ptr ptr long) macdrv_EnumDisplayMonitors