Added process_id_t and thread_it_t types to the server interface
[wine] / windows / multimon.c
1 /*
2  * Multimonitor APIs
3  *
4  * Copyright 1998 Turchanov Sergey
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <string.h>
22 #include "windef.h"
23 #include "wingdi.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wine/unicode.h"
27
28 /**********************************************************************/
29
30 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
31
32 /***********************************************************************
33  *              MonitorFromPoint (USER32.@)
34  */
35 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
36 {
37     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
38         ((ptScreenCoords.x >= 0) &&
39         (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
40         (ptScreenCoords.y >= 0) &&
41         (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
42     {
43         return xPRIMARY_MONITOR;
44     }
45     return (HMONITOR)0;
46 }
47
48 /***********************************************************************
49  *              MonitorFromRect (USER32.@)
50  */
51 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
52 {
53     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
54         ((lprcScreenCoords->right > 0) &&
55         (lprcScreenCoords->bottom > 0) &&
56         (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
57         (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
58     {
59         return xPRIMARY_MONITOR;
60     }
61     return (HMONITOR)0;
62 }
63
64 /***********************************************************************
65  *              MonitorFromWindow (USER32.@)
66  */
67 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
68 {
69     WINDOWPLACEMENT wp;
70
71     if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
72         return xPRIMARY_MONITOR;
73
74     if (IsIconic(hWnd) ?
75             GetWindowPlacement(hWnd, &wp) :
76             GetWindowRect(hWnd, &wp.rcNormalPosition)) {
77
78         return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
79     }
80
81     return (HMONITOR)0;
82 }
83
84 /***********************************************************************
85  *              GetMonitorInfoA (USER32.@)
86  */
87 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
88 {
89     RECT rcWork;
90
91     if ((hMonitor == xPRIMARY_MONITOR) &&
92         lpMonitorInfo &&
93         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
94         SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
95     {
96         SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
97                  GetSystemMetrics(SM_CXSCREEN),
98                  GetSystemMetrics(SM_CYSCREEN) );
99         lpMonitorInfo->rcWork = rcWork;
100         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
101
102         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
103             strcpy(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
104
105         return TRUE;
106     }
107
108     return FALSE;
109 }
110
111 /***********************************************************************
112  *              GetMonitorInfoW (USER32.@)
113  */
114 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
115 {
116     RECT rcWork;
117
118     if ((hMonitor == xPRIMARY_MONITOR) &&
119         lpMonitorInfo &&
120         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
121         SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
122     {
123         SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
124                  GetSystemMetrics(SM_CXSCREEN),
125                  GetSystemMetrics(SM_CYSCREEN) );
126         lpMonitorInfo->rcWork = rcWork;
127         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
128
129         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
130             strcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
131
132         return TRUE;
133     }
134
135     return FALSE;
136 }
137
138 /***********************************************************************
139  *              EnumDisplayMonitors (USER32.@)
140  */
141 BOOL WINAPI EnumDisplayMonitors(
142         HDC             hdcOptionalForPainting,
143         LPRECT         lprcEnumMonitorsThatIntersect,
144         MONITORENUMPROC lpfnEnumProc,
145         LPARAM          dwData)
146 {
147     RECT rcLimit;
148     SetRect( &rcLimit, 0, 0, GetSystemMetrics(SM_CXSCREEN),
149              GetSystemMetrics(SM_CYSCREEN) );
150
151     if (!lpfnEnumProc)
152         return FALSE;
153
154     if (hdcOptionalForPainting)
155     {
156         RECT    rcClip;
157         POINT   ptOrg;
158
159         switch (GetClipBox(hdcOptionalForPainting, &rcClip))
160         {
161         default:
162             if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
163                 return FALSE;
164
165             OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
166             if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
167                 (!lprcEnumMonitorsThatIntersect ||
168                      IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
169
170                 break;
171             }
172             /* fall through */
173         case NULLREGION:
174              return TRUE;
175         case ERROR:
176              return FALSE;
177         }
178     } else {
179         if (    lprcEnumMonitorsThatIntersect &&
180                 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
181
182             return TRUE;
183         }
184     }
185
186     return lpfnEnumProc(
187             xPRIMARY_MONITOR,
188             hdcOptionalForPainting,
189             &rcLimit,
190             dwData);
191 }