Store monitor size and depth in the generic structure.
[wine] / windows / multimon.c
1 /*
2  * Multimonitor APIs
3  *
4  * Copyright 1998 Turchanov Sergey
5  */
6
7 #include "monitor.h"
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "winbase.h"
11 #include "winuser.h"
12
13 /**********************************************************************/
14
15 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
16
17 MONITOR MONITOR_PrimaryMonitor;
18
19 /**********************************************************************/
20
21 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
22 {
23     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
24         ((ptScreenCoords.x >= 0) &&
25         (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
26         (ptScreenCoords.y >= 0) &&
27         (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
28     {
29         return xPRIMARY_MONITOR;
30     }
31         return NULL;
32 }
33
34 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
35 {
36     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
37         ((lprcScreenCoords->right > 0) &&
38         (lprcScreenCoords->bottom > 0) &&
39         (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
40         (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
41     {
42         return xPRIMARY_MONITOR;
43     }
44     return NULL;
45 }
46
47 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
48 {
49     WINDOWPLACEMENT wp;
50
51     if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
52         return xPRIMARY_MONITOR;
53
54     if (IsIconic(hWnd) ? 
55             GetWindowPlacement(hWnd, &wp) : 
56             GetWindowRect(hWnd, &wp.rcNormalPosition)) {
57
58         return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
59     }
60
61     return NULL;
62 }
63
64 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
65 {
66     RECT rcWork;
67
68     if ((hMonitor == xPRIMARY_MONITOR) &&
69         lpMonitorInfo &&
70         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
71         SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
72     {
73         lpMonitorInfo->rcMonitor = MONITOR_PrimaryMonitor.rect;
74         lpMonitorInfo->rcWork = rcWork;
75         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
76         
77         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
78             lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
79
80         return TRUE;
81     }
82
83     return FALSE;
84 }
85
86 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
87 {
88     RECT rcWork;
89
90     if ((hMonitor == xPRIMARY_MONITOR) &&
91         lpMonitorInfo &&
92         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
93         SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
94     {
95         lpMonitorInfo->rcMonitor = MONITOR_PrimaryMonitor.rect;
96         lpMonitorInfo->rcWork = rcWork;
97         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
98
99         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
100             lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
101
102         return TRUE;
103     }
104
105     return FALSE;
106 }
107
108 BOOL WINAPI EnumDisplayMonitors(
109         HDC             hdcOptionalForPainting,
110         LPRECT         lprcEnumMonitorsThatIntersect,
111         MONITORENUMPROC lpfnEnumProc,
112         LPARAM          dwData)
113 {
114     RECT rcLimit = MONITOR_PrimaryMonitor.rect;
115
116     if (!lpfnEnumProc)
117         return FALSE;
118
119     if (hdcOptionalForPainting)
120     {
121         RECT    rcClip;
122         POINT   ptOrg;
123
124         switch (GetClipBox(hdcOptionalForPainting, &rcClip))
125         {
126         default:
127             if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
128                 return FALSE;
129
130             OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
131             if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
132                 (!lprcEnumMonitorsThatIntersect ||
133                      IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
134
135                 break;
136             }
137             /*fall thru */
138         case NULLREGION:
139              return TRUE;
140         case ERROR:
141              return FALSE;
142         }
143     } else {
144         if (    lprcEnumMonitorsThatIntersect &&
145                 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
146
147             return TRUE;
148         }
149     }
150
151     return lpfnEnumProc(
152             xPRIMARY_MONITOR,
153             hdcOptionalForPainting,
154             &rcLimit,
155             dwData);
156 }