msvcrt: Added fopen_s test with ccs option.
[wine] / dlls / winemac.drv / display.c
1 /*
2  * MACDRV display settings
3  *
4  * Copyright 2003 Alexander James Pasadyn
5  * Copyright 2011, 2012 Ken Thomases for CodeWeavers Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include "macdrv.h"
25 #include "winuser.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(display);
28
29
30 static inline HMONITOR display_id_to_monitor(CGDirectDisplayID display_id)
31 {
32     return (HMONITOR)(UINT_PTR)display_id;
33 }
34
35 static inline CGDirectDisplayID monitor_to_display_id(HMONITOR handle)
36 {
37     return (CGDirectDisplayID)(UINT_PTR)handle;
38 }
39
40
41 /***********************************************************************
42  *              EnumDisplayMonitors  (MACDRV.@)
43  */
44 BOOL CDECL macdrv_EnumDisplayMonitors(HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPARAM lparam)
45 {
46     struct macdrv_display *displays;
47     int num_displays;
48     int i;
49     BOOL ret = TRUE;
50
51     TRACE("%p, %s, %p, %#lx\n", hdc, wine_dbgstr_rect(rect), proc, lparam);
52
53     if (hdc)
54     {
55         POINT origin;
56         RECT limit;
57
58         if (!GetDCOrgEx(hdc, &origin)) return FALSE;
59         if (GetClipBox(hdc, &limit) == ERROR) return FALSE;
60
61         if (rect && !IntersectRect(&limit, &limit, rect)) return TRUE;
62
63         if (macdrv_get_displays(&displays, &num_displays))
64             return FALSE;
65
66         for (i = 0; i < num_displays; i++)
67         {
68             RECT monrect = rect_from_cgrect(displays[i].frame);
69             OffsetRect(&monrect, -origin.x, -origin.y);
70             if (IntersectRect(&monrect, &monrect, &limit))
71             {
72                 HMONITOR monitor = display_id_to_monitor(displays[i].displayID);
73                 TRACE("monitor %d handle %p @ %s\n", i, monitor, wine_dbgstr_rect(&monrect));
74                 if (!proc(monitor, hdc, &monrect, lparam))
75                 {
76                     ret = FALSE;
77                     break;
78                 }
79             }
80         }
81     }
82     else
83     {
84         if (macdrv_get_displays(&displays, &num_displays))
85             return FALSE;
86
87         for (i = 0; i < num_displays; i++)
88         {
89             RECT monrect = rect_from_cgrect(displays[i].frame);
90             RECT unused;
91             if (!rect || IntersectRect(&unused, &monrect, rect))
92             {
93                 HMONITOR monitor = display_id_to_monitor(displays[i].displayID);
94                 TRACE("monitor %d handle %p @ %s\n", i, monitor, wine_dbgstr_rect(&monrect));
95                 if (!proc(monitor, 0, &monrect, lparam))
96                 {
97                     ret = FALSE;
98                     break;
99                 }
100             }
101         }
102     }
103
104     macdrv_free_displays(displays);
105
106     return ret;
107 }
108
109
110 /***********************************************************************
111  *              GetMonitorInfo  (MACDRV.@)
112  */
113 BOOL CDECL macdrv_GetMonitorInfo(HMONITOR monitor, LPMONITORINFO info)
114 {
115     static const WCHAR adapter_name[] = { '\\','\\','.','\\','D','I','S','P','L','A','Y','1',0 };
116     struct macdrv_display *displays;
117     int num_displays;
118     CGDirectDisplayID display_id;
119     int i;
120
121     TRACE("%p, %p\n", monitor, info);
122
123     if (macdrv_get_displays(&displays, &num_displays))
124     {
125         ERR("couldn't get display list\n");
126         SetLastError(ERROR_GEN_FAILURE);
127         return FALSE;
128     }
129
130     display_id = monitor_to_display_id(monitor);
131     for (i = 0; i < num_displays; i++)
132     {
133         if (displays[i].displayID == display_id)
134             break;
135     }
136
137     if (i < num_displays)
138     {
139         info->rcMonitor = rect_from_cgrect(displays[i].frame);
140         info->rcWork    = rect_from_cgrect(displays[i].work_frame);
141
142         info->dwFlags = (i == 0) ? MONITORINFOF_PRIMARY : 0;
143
144         if (info->cbSize >= sizeof(MONITORINFOEXW))
145             lstrcpyW(((MONITORINFOEXW*)info)->szDevice, adapter_name);
146
147         TRACE(" -> rcMonitor %s rcWork %s dwFlags %08x\n", wine_dbgstr_rect(&info->rcMonitor),
148               wine_dbgstr_rect(&info->rcWork), info->dwFlags);
149     }
150     else
151     {
152         ERR("invalid monitor handle\n");
153         SetLastError(ERROR_INVALID_HANDLE);
154     }
155
156     macdrv_free_displays(displays);
157     return (i < num_displays);
158 }