//
//
-// COMPLETE
-
-// NOTE: We made a concious decision to have only a single 'screen'
-// due to the differences in platforms. On Win32 we could gather
-// all information, but not for X11 (and possibly Mac). So for now
-// we'll stick with a single screen, but the functions are still
-// written to support multiple screens, simply beef up the all_screens
-// assignment to get multiples
-// To support multiples, we need to use GetMonitorInfo API on Win32
-
using System;
using System.Drawing;
namespace System.Windows.Forms {
public class Screen {
#region Local Variables
- private static Screen[] all_screens = { new Screen(true, "Mono MWF Primary Display", SystemInformation.VirtualScreen, SystemInformation.WorkingArea) };
+ private static Screen[] all_screens;
private bool primary;
private Rectangle bounds;
private Rectangle workarea;
private string name;
-
+ private int bits_per_pixel;
#endregion // Local Variables
#region Constructors
- private Screen() {
+ static Screen ()
+ {
+ try {
+ all_screens = XplatUI.AllScreens;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("{0} trying to get all screens: {1}", e.GetType (), e.Message);
+ }
+
+ if (all_screens == null || all_screens.Length == 0) {
+ // just use a default one
+ all_screens = new[] { new Screen(true, "Mono MWF Primary Display",
+ XplatUI.VirtualScreen, XplatUI.WorkingArea) };
+ }
+ }
+
+ internal Screen() {
this.primary = true;
- this.bounds = SystemInformation.WorkingArea;
+ this.bounds = XplatUI.WorkingArea;
}
- private Screen(bool primary, string name, Rectangle bounds, Rectangle workarea) {
+ internal Screen(bool primary, string name, Rectangle bounds, Rectangle workarea) {
this.primary = primary;
this.name = name;
this.bounds = bounds;
this.workarea = workarea;
+ this.bits_per_pixel = 32;
}
#endregion // Constructors
#endregion // Public Static Properties
#region Public Instance Properties
+ [MonoTODO ("Stub, always returns 32")]
+ public int BitsPerPixel {
+ get { return bits_per_pixel; }
+ }
+
public Rectangle Bounds {
get {
return this.bounds;
#region Public Static Methods
public static Screen FromControl(Control control) {
- return Screen.FromPoint(control.Location);
+ var point = control.Parent != null ? control.Parent.PointToScreen(control.Location) : control.Location;
+ return Screen.FromPoint(point);
}
public static Screen FromHandle(IntPtr hwnd) {
control = Control.FromHandle(hwnd);
if (control != null) {
- return Screen.FromPoint(control.Location);
+ var point = control.Parent != null ? control.Parent.PointToScreen(control.Location) : control.Location;
+ return Screen.FromPoint(point);
}
return Screen.PrimaryScreen;
}