1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Peter Bartok (pbartok@novell.com)
27 // NOTE: We made a concious decision to have only a single 'screen'
28 // due to the differences in platforms. On Win32 we could gather
29 // all information, but not for X11 (and possibly Mac). So for now
30 // we'll stick with a single screen, but the functions are still
31 // written to support multiple screens, simply beef up the all_screens
32 // assignment to get multiples
33 // To support multiples, we need to use GetMonitorInfo API on Win32
38 namespace System
.Windows
.Forms
{
40 #region Local Variables
41 private static Screen
[] all_screens
= { new Screen(true, "Mono MWF Primary Display", SystemInformation.VirtualScreen, SystemInformation.WorkingArea) }
;
43 private Rectangle bounds
;
44 private Rectangle workarea
;
47 #endregion // Local Variables
52 this.bounds
= SystemInformation
.WorkingArea
;
55 private Screen(bool primary
, string name
, Rectangle bounds
, Rectangle workarea
) {
56 this.primary
= primary
;
59 this.workarea
= workarea
;
61 #endregion // Constructors
63 #region Public Static Properties
64 public static Screen
[] AllScreens
{
70 public static Screen PrimaryScreen
{
72 return all_screens
[0];
75 #endregion // Public Static Properties
77 #region Public Instance Properties
78 public Rectangle Bounds
{
84 public string DeviceName
{
96 public Rectangle WorkingArea
{
101 #endregion // Public Instance Properties
103 #region Public Static Methods
104 public static Screen
FromControl(Control control
) {
105 return Screen
.FromPoint(control
.Location
);
108 public static Screen
FromHandle(IntPtr hwnd
) {
111 control
= Control
.FromHandle(hwnd
);
112 if (control
!= null) {
113 return Screen
.FromPoint(control
.Location
);
115 return Screen
.PrimaryScreen
;
118 public static Screen
FromPoint(Point point
) {
119 for (int i
= 0; i
< all_screens
.Length
; i
++) {
120 if (all_screens
[i
].Bounds
.Contains(point
)) {
121 return all_screens
[i
];
124 return Screen
.PrimaryScreen
;
127 public static Screen
FromRectangle(Rectangle rect
) {
128 return Screen
.FromPoint(new Point(rect
.Left
, rect
.Top
));
131 public static Rectangle
GetBounds(Control ctl
) {
132 return Screen
.FromControl(ctl
).Bounds
;
135 public static Rectangle
GetBounds(Point pt
) {
136 return Screen
.FromPoint(pt
).Bounds
;
139 public static Rectangle
GetBounds(Rectangle rect
) {
140 return Screen
.FromRectangle(rect
).Bounds
;
143 public static Rectangle
GetWorkingArea(Control ctl
) {
144 return Screen
.FromControl(ctl
).WorkingArea
;
147 public static Rectangle
GetWorkingArea(Point pt
) {
148 return Screen
.FromPoint(pt
).WorkingArea
;
151 public static Rectangle
GetWorkingArea(Rectangle rect
) {
152 return Screen
.FromRectangle(rect
).WorkingArea
;
154 #endregion // Public Static Methods
156 #region Public Instance Methods
157 public override bool Equals(object obj
) {
159 Screen s
= (Screen
)obj
;
161 if (name
.Equals(s
.name
) && (primary
== s
.primary
) && (bounds
.Equals(s
.Bounds
)) && (workarea
.Equals(s
.workarea
))) {
168 public override int GetHashCode() {
169 return base.GetHashCode ();
172 public override string ToString() {
173 return "Screen[Bounds={" + this.Bounds + "} WorkingArea={" + this.WorkingArea + "} Primary={" + this.Primary + "} DeviceName=" + this.DeviceName
;
177 #endregion // Public Instance Methods