Add support for getting screen geometry information
This commit is contained in:
Родитель
204e665768
Коммит
ffae4a9cbd
|
@ -98,9 +98,10 @@ namespace Samples
|
|||
AddSample (null, "Notebook", typeof(NotebookSample));
|
||||
AddSample (null, "Paneds", typeof(PanedViews));
|
||||
AddSample (null, "Popover", typeof(PopoverSample));
|
||||
AddSample (null, "ReliefFrame", typeof (ReliefFrameSample));
|
||||
AddSample (null, "Screens", typeof (ScreensSample));
|
||||
AddSample (null, "Scroll View", typeof(ScrollWindowSample));
|
||||
AddSample (null, "Spinners", typeof (Spinners));
|
||||
AddSample (null, "ReliefFrame", typeof (ReliefFrameSample));
|
||||
AddSample (null, "Tables", typeof (Tables));
|
||||
AddSample (null, "Text Entry", typeof (TextEntries));
|
||||
AddSample (null, "Tooltips", typeof(Tooltips));
|
||||
|
|
|
@ -170,6 +170,7 @@
|
|||
<Compile Include="Samples\PopoverSample.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Samples\ScreensSample.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
//
|
||||
// ScreensSample.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using Xwt;
|
||||
using Xwt.Drawing;
|
||||
|
||||
namespace Samples
|
||||
{
|
||||
public class ScreensSample: VBox
|
||||
{
|
||||
public ScreensSample ()
|
||||
{
|
||||
Label la = new Label (Desktop.Screens.Count + " screens found");
|
||||
PackStart (la);
|
||||
|
||||
var c = new ScreensCanvas ();
|
||||
c.Margin = 30;
|
||||
PackStart (c, BoxMode.FillAndExpand);
|
||||
}
|
||||
}
|
||||
|
||||
class ScreensCanvas: Canvas
|
||||
{
|
||||
bool pset;
|
||||
|
||||
public ScreensCanvas ()
|
||||
{
|
||||
Desktop.ScreensChanged += HandleScreensChanged;
|
||||
}
|
||||
|
||||
void HandleScreensChanged (object sender, EventArgs e)
|
||||
{
|
||||
QueueDraw ();
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
base.Dispose (disposing);
|
||||
if (disposing)
|
||||
Desktop.ScreensChanged -= HandleScreensChanged;
|
||||
}
|
||||
|
||||
protected override void OnDraw (Context ctx, Rectangle dirtyRect)
|
||||
{
|
||||
base.OnDraw (ctx, dirtyRect);
|
||||
|
||||
if (!pset) {
|
||||
ParentWindow.BoundsChanged += delegate {
|
||||
QueueDraw ();
|
||||
};
|
||||
pset = true;
|
||||
}
|
||||
|
||||
var size = Size;
|
||||
size.Width--;
|
||||
size.Height--;
|
||||
var fx = size.Width / Desktop.Bounds.Width;
|
||||
|
||||
if (Desktop.Bounds.Height * fx > size.Height)
|
||||
fx = size.Height / Desktop.Bounds.Height;
|
||||
|
||||
ctx.SetLineWidth (1);
|
||||
foreach (var s in Desktop.Screens) {
|
||||
if (s.Bounds != s.VisibleBounds) {
|
||||
var vr = new Rectangle ((int)(s.Bounds.X * fx), (int)(s.Bounds.Y * fx), (int)(s.Bounds.Width * fx), (int)(s.Bounds.Height * fx));
|
||||
vr = vr.Offset (0.5, 0.5);
|
||||
ctx.Rectangle (vr);
|
||||
ctx.SetColor (Colors.White);
|
||||
ctx.FillPreserve ();
|
||||
ctx.SetColor (Colors.Black);
|
||||
ctx.Stroke ();
|
||||
}
|
||||
var r = new Rectangle ((int)(s.VisibleBounds.X * fx), (int)(s.VisibleBounds.Y * fx), (int)(s.VisibleBounds.Width * fx), (int)(s.VisibleBounds.Height * fx));
|
||||
r = r.Offset (0.5, 0.5);
|
||||
ctx.Rectangle (r);
|
||||
ctx.SetColor (new Color (0.4, 0.62, 0.83));
|
||||
ctx.FillPreserve ();
|
||||
ctx.SetColor (Colors.Black);
|
||||
ctx.Stroke ();
|
||||
|
||||
TextLayout tl = new TextLayout (ctx);
|
||||
tl.Text = s.DeviceName;
|
||||
tl.Font = Font;
|
||||
ctx.DrawTextLayout (tl, r.Center.X - tl.Width / 2, r.Center.Y - tl.Height / 2);
|
||||
}
|
||||
|
||||
var wr = ParentWindow.ScreenBounds;
|
||||
wr = new Rectangle ((int)(wr.X * fx), (int)(wr.Y * fx), (int)(wr.Width * fx), (int)(wr.Height * fx));
|
||||
ctx.Rectangle (wr);
|
||||
ctx.SetColor (Colors.Azure.WithAlpha (0.5));
|
||||
ctx.FillPreserve ();
|
||||
ctx.SetColor (Colors.Azure);
|
||||
ctx.Stroke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -116,6 +116,7 @@
|
|||
<Compile Include="Xwt.GtkBackend\LinkLabelBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\SpinnerBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\RichTextViewBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\GtkDesktopBackend.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
//
|
||||
// GtkDesktopBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public class GtkDesktopBackend: DesktopBackend
|
||||
{
|
||||
#region implemented abstract members of DesktopBackend
|
||||
|
||||
public GtkDesktopBackend ()
|
||||
{
|
||||
Gdk.Screen.Default.SizeChanged += delegate {
|
||||
OnScreensChanged ();
|
||||
};
|
||||
Gdk.Screen.Default.CompositedChanged += delegate {
|
||||
OnScreensChanged ();
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<object> GetScreens ()
|
||||
{
|
||||
for (int n=0; n<Gdk.Screen.Default.NMonitors; n++)
|
||||
yield return n;
|
||||
}
|
||||
|
||||
public override bool IsPrimaryScreen (object backend)
|
||||
{
|
||||
return (int)backend == Gdk.Screen.Default.GetMonitorAtPoint (0, 0);
|
||||
}
|
||||
|
||||
public override Rectangle GetScreenBounds (object backend)
|
||||
{
|
||||
var r = Gdk.Screen.Default.GetMonitorGeometry ((int)backend);
|
||||
return new Rectangle (r.X, r.Y, r.Width, r.Height);
|
||||
}
|
||||
|
||||
public override Rectangle GetScreenVisibleBounds (object backend)
|
||||
{
|
||||
var r = Gdk.Screen.Default.GetUsableMonitorGeometry ((int)backend);
|
||||
return new Rectangle (r.X, r.Y, r.Width, r.Height);
|
||||
}
|
||||
|
||||
public override string GetScreenDeviceName (object backend)
|
||||
{
|
||||
return backend.ToString ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -105,6 +105,7 @@ namespace Xwt.GtkBackend
|
|||
RegisterBackend (typeof(Xwt.Spinner), typeof (SpinnerBackend));
|
||||
RegisterBackend (typeof(Xwt.RichTextView), typeof (RichTextViewBackend));
|
||||
RegisterBackend (typeof(Xwt.Expander), typeof (ExpanderBackend));
|
||||
RegisterBackend (typeof(Xwt.Desktop), typeof(GtkDesktopBackend));
|
||||
}
|
||||
|
||||
public override void RunApplication ()
|
||||
|
|
|
@ -186,7 +186,8 @@ namespace Xwt.GtkBackend
|
|||
if (ev is WindowFrameEvent) {
|
||||
switch ((WindowFrameEvent)ev) {
|
||||
case WindowFrameEvent.BoundsChanged:
|
||||
Window.SizeAllocated += HandleWidgetSizeAllocated; break;
|
||||
Window.AddEvents ((int)Gdk.EventMask.StructureMask);
|
||||
Window.ConfigureEvent += HandleConfigureEvent; break;
|
||||
case WindowFrameEvent.CloseRequested:
|
||||
Window.DeleteEvent += HandleCloseRequested; break;
|
||||
}
|
||||
|
@ -198,14 +199,15 @@ namespace Xwt.GtkBackend
|
|||
if (ev is WindowFrameEvent) {
|
||||
switch ((WindowFrameEvent)ev) {
|
||||
case WindowFrameEvent.BoundsChanged:
|
||||
Window.SizeAllocated -= HandleWidgetSizeAllocated; break;
|
||||
Window.ConfigureEvent -= HandleConfigureEvent; break;
|
||||
case WindowFrameEvent.CloseRequested:
|
||||
Window.DeleteEvent -= HandleCloseRequested; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
|
||||
[GLib.ConnectBefore]
|
||||
void HandleConfigureEvent (object o, Gtk.ConfigureEventArgs args)
|
||||
{
|
||||
ApplicationContext.InvokeUserCode (delegate {
|
||||
EventSink.OnBoundsChanged (Bounds);
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
<Compile Include="Xwt.Mac\MacClipboardBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\PathBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Mac\CustomWidgetBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\MacDesktopBackend.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
//
|
||||
// MacDesktopBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
using MonoMac.AppKit;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class MacDesktopBackend: DesktopBackend
|
||||
{
|
||||
#region implemented abstract members of DesktopBackend
|
||||
|
||||
internal static MacDesktopBackend Instance;
|
||||
internal static Rectangle desktopBounds;
|
||||
|
||||
public MacDesktopBackend ()
|
||||
{
|
||||
Instance = this;
|
||||
CalcDesktopBounds ();
|
||||
}
|
||||
|
||||
internal void NotifyScreensChanged ()
|
||||
{
|
||||
CalcDesktopBounds ();
|
||||
OnScreensChanged ();
|
||||
}
|
||||
|
||||
static void CalcDesktopBounds ()
|
||||
{
|
||||
desktopBounds = new Rectangle ();
|
||||
foreach (var s in NSScreen.Screens) {
|
||||
var r = s.Frame;
|
||||
desktopBounds = desktopBounds.Union (new Rectangle (r.X, r.Y, r.Width, r.Height));
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<object> GetScreens ()
|
||||
{
|
||||
return NSScreen.Screens;
|
||||
}
|
||||
|
||||
public override bool IsPrimaryScreen (object backend)
|
||||
{
|
||||
return NSScreen.Screens[0] == (NSScreen) backend;
|
||||
}
|
||||
|
||||
public static Rectangle ToDesktopRect (System.Drawing.RectangleF r)
|
||||
{
|
||||
r.Y = (float)desktopBounds.Height - r.Y - r.Height;
|
||||
if (desktopBounds.Y < 0)
|
||||
r.Y += (float)desktopBounds.Y;
|
||||
return new Rectangle (r.X, r.Y, r.Width, r.Height);
|
||||
}
|
||||
|
||||
public override Rectangle GetScreenBounds (object backend)
|
||||
{
|
||||
var r = ((NSScreen)backend).Frame;
|
||||
return ToDesktopRect (r);
|
||||
}
|
||||
|
||||
public override Rectangle GetScreenVisibleBounds (object backend)
|
||||
{
|
||||
var r = ((NSScreen)backend).VisibleFrame;
|
||||
return ToDesktopRect (r);
|
||||
}
|
||||
|
||||
public override string GetScreenDeviceName (object backend)
|
||||
{
|
||||
return ((NSScreen)backend).DeviceDescription ["NSScreenNumber"].ToString ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -105,6 +105,7 @@ namespace Xwt.Mac
|
|||
RegisterBackend (typeof(Xwt.SelectFolderDialog), typeof(SelectFolderDialogBackend));
|
||||
RegisterBackend (typeof(Xwt.OpenFileDialog), typeof(OpenFileDialogBackend));
|
||||
RegisterBackend (typeof(Xwt.Clipboard), typeof(MacClipboardBackend));
|
||||
RegisterBackend (typeof(Xwt.Desktop), typeof(MacDesktopBackend));
|
||||
}
|
||||
|
||||
public override void RunApplication ()
|
||||
|
@ -206,5 +207,11 @@ namespace Xwt.Mac
|
|||
foreach (var w in pendingWindows)
|
||||
w.InternalShow ();
|
||||
}
|
||||
|
||||
public override void ScreenParametersChanged (NSNotification notification)
|
||||
{
|
||||
if (MacDesktopBackend.Instance != null)
|
||||
MacDesktopBackend.Instance.NotifyScreensChanged ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ namespace Xwt.Mac
|
|||
switch (@event) {
|
||||
case WindowFrameEvent.BoundsChanged:
|
||||
DidResize += HandleDidResize;
|
||||
DidMoved += HandleDidResize;
|
||||
break;
|
||||
case WindowFrameEvent.Hidden:
|
||||
EnableVisibilityEvent (@event);
|
||||
|
@ -211,6 +212,7 @@ namespace Xwt.Mac
|
|||
switch (@event) {
|
||||
case WindowFrameEvent.BoundsChanged:
|
||||
DidResize -= HandleDidResize;
|
||||
DidMoved -= HandleDidResize;
|
||||
break;
|
||||
case WindowFrameEvent.Hidden:
|
||||
this.WillClose -= OnWillClose;
|
||||
|
@ -308,7 +310,8 @@ namespace Xwt.Mac
|
|||
|
||||
Rectangle IWindowFrameBackend.Bounds {
|
||||
get {
|
||||
var r = ContentRectFor (Frame);
|
||||
var b = ContentRectFor (Frame);
|
||||
var r = MacDesktopBackend.ToDesktopRect (b);
|
||||
return new Rectangle ((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
|
||||
}
|
||||
set {
|
||||
|
|
|
@ -133,6 +133,7 @@
|
|||
<Compile Include="Xwt.WPFBackend\ScrollAdjustmentBackend.cs" />
|
||||
<Compile Include="Xwt.WPFBackend\CustomScrollViewPort.cs" />
|
||||
<Compile Include="Xwt.WPFBackend\RichTextViewBackend.cs" />
|
||||
<Compile Include="Xwt.WPFBackend\WpfDesktopBackend.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -98,6 +98,7 @@ namespace Xwt.WPFBackend
|
|||
RegisterBackend (typeof (RichTextView), typeof (RichTextViewBackend));
|
||||
RegisterBackend (typeof (LinkLabel), typeof (LinkLabelBackend));
|
||||
RegisterBackend (typeof (Spinner), typeof (SpinnerBackend));
|
||||
RegisterBackend (typeof (Desktop), typeof(WpfDesktopBackend));
|
||||
}
|
||||
|
||||
public override void DispatchPendingEvents()
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// WpfDesktopBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.WPFBackend
|
||||
{
|
||||
public class WpfDesktopBackend: DesktopBackend
|
||||
{
|
||||
public WpfDesktopBackend ()
|
||||
{
|
||||
}
|
||||
|
||||
#region implemented abstract members of DesktopBackend
|
||||
|
||||
public override System.Collections.Generic.IEnumerable<object> GetScreens ()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
public override bool IsPrimaryScreen (object backend)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public override Rectangle GetScreenBounds (object backend)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public override Rectangle GetScreenVisibleBounds (object backend)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public override string GetScreenDeviceName (object backend)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// DesktopBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public abstract class DesktopBackend: BackendHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// List of screens that compose the desktop
|
||||
/// </summary>
|
||||
public abstract IEnumerable<object> GetScreens ();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the provided screen is the primary screen
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the screen is the primary screen; otherwise, <c>false</c>.</returns>
|
||||
/// <param name="backend">Screen backend</param>
|
||||
/// <remarks>The primary screen is considered the screen where the 'main desktop' lives.</remarks>
|
||||
public abstract bool IsPrimaryScreen (object backend);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bounds of a screen, in desktop coordinates
|
||||
/// </summary>
|
||||
/// <returns>The screen bounds.</returns>
|
||||
/// <param name="backend">A screen backend</param>
|
||||
public abstract Rectangle GetScreenBounds (object backend);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the visible bounds of a screen (excluding dock area and other decorations), in desktop coordinates
|
||||
/// </summary>
|
||||
/// <returns>The screen bounds.</returns>
|
||||
/// <param name="backend">A screen backend</param>
|
||||
public abstract Rectangle GetScreenVisibleBounds (object backend);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the screen device.
|
||||
/// </summary>
|
||||
/// <returns>The screen device name.</returns>
|
||||
/// <param name="backend">Backend.</param>
|
||||
public abstract string GetScreenDeviceName (object backend);
|
||||
|
||||
/// <summary>
|
||||
/// Raises the ScreensChanged event.
|
||||
/// </summary>
|
||||
/// <remarks>To be called by the subclass when there is a change in the configuration of screens</remarks>
|
||||
public void OnScreensChanged ()
|
||||
{
|
||||
ApplicationContext.InvokeUserCode (delegate {
|
||||
Desktop.NotifyScreensChanged ();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -365,6 +365,9 @@
|
|||
<Compile Include="Xwt\Toolkit.cs" />
|
||||
<Compile Include="Xwt.Drawing\DrawingPath.cs" />
|
||||
<Compile Include="Xwt.Backends\DrawingPathBackendHandler.cs" />
|
||||
<Compile Include="Xwt\Desktop.cs" />
|
||||
<Compile Include="Xwt\Screen.cs" />
|
||||
<Compile Include="Xwt.Backends\DesktopBackend.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup />
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
//
|
||||
// Desktop.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Xwt
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides information about the screens that compose the desktop
|
||||
/// </summary>
|
||||
public static class Desktop
|
||||
{
|
||||
static Screen[] screens;
|
||||
static Screen primary;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when there is some change in the geometry of the screens
|
||||
/// </summary>
|
||||
public static event EventHandler ScreensChanged;
|
||||
|
||||
internal static void NotifyScreensChanged ()
|
||||
{
|
||||
screens = null;
|
||||
if (ScreensChanged != null)
|
||||
ScreensChanged (null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of screens that compose the desktop
|
||||
/// </summary>
|
||||
/// <value>The screens.</value>
|
||||
public static ReadOnlyCollection<Screen> Screens {
|
||||
get {
|
||||
if (screens == null) {
|
||||
screens = Toolkit.CurrentEngine.DesktopBackend.GetScreens ().Select (s => new Screen (s)).ToArray ();
|
||||
primary = screens.FirstOrDefault (s => s.IsPrimary);
|
||||
}
|
||||
return new ReadOnlyCollection<Screen> (screens);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the primary screen.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The primary screen is considered the screen where the 'main desktop' lives.
|
||||
/// </remarks>
|
||||
public static Screen PrimaryScreen {
|
||||
get {
|
||||
return primary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bounds of the desktop
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The bounds of the desktop is the union of the areas of all screens
|
||||
/// </remarks>
|
||||
public static Rectangle Bounds {
|
||||
get {
|
||||
Rectangle r = new Rectangle (0,0,0,0);
|
||||
foreach (var s in Screens)
|
||||
r = r.Union (s.Bounds);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the screen at location.
|
||||
/// </summary>
|
||||
/// <returns>The screen at location.</returns>
|
||||
/// <param name="p">A point</param>
|
||||
public static Screen GetScreenAtLocation (Point p)
|
||||
{
|
||||
return GetScreenAtLocation (p.X, p.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the screen at location.
|
||||
/// </summary>
|
||||
/// <returns>The screen at location.</returns>
|
||||
/// <param name="x">The x coordinate.</param>
|
||||
/// <param name="y">The y coordinate.</param>
|
||||
public static Screen GetScreenAtLocation (double x, double y)
|
||||
{
|
||||
return screens.FirstOrDefault (s => s.Bounds.Contains (x, y));
|
||||
}
|
||||
|
||||
static Screen GetScreen (object sb)
|
||||
{
|
||||
foreach (var s in Screens) {
|
||||
var backend = Toolkit.GetBackend (s);
|
||||
if (backend == sb || backend.Equals (sb))
|
||||
return s;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
//
|
||||
// Screen.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Xwt
|
||||
{
|
||||
/// <summary>
|
||||
/// Object representing a physical screen
|
||||
/// </summary>
|
||||
public class Screen: XwtObject
|
||||
{
|
||||
internal Screen (object backend): this (backend, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal Screen (object backend, Toolkit toolkit): base (backend, toolkit)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bounds of the screen, including the dock area (and menu bar on Mac)
|
||||
/// </summary>
|
||||
/// <value>The bounds.</value>
|
||||
public Rectangle Bounds {
|
||||
get {
|
||||
return ToolkitEngine.DesktopBackend.GetScreenBounds (Backend);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bounds of the screen, not including the dock area (or menu bar on Mac)
|
||||
/// </summary>
|
||||
public Rectangle VisibleBounds {
|
||||
get {
|
||||
return ToolkitEngine.DesktopBackend.GetScreenVisibleBounds (Backend);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the device.
|
||||
/// </summary>
|
||||
/// <value>The name of the device.</value>
|
||||
public string DeviceName {
|
||||
get {
|
||||
return ToolkitEngine.DesktopBackend.GetScreenDeviceName (Backend);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this screen is the primary screen
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is the primary screen; otherwise, <c>false</c>.</value>
|
||||
/// <remarks>The primary screen is considered the screen where the 'main desktop' lives.</remarks>
|
||||
public bool IsPrimary {
|
||||
get {
|
||||
return ToolkitEngine.DesktopBackend.IsPrimaryScreen (Backend);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,6 +143,7 @@ namespace Xwt
|
|||
ImagePatternBackendHandler = Backend.CreateSharedBackend<ImagePatternBackendHandler> (typeof(ImagePattern));
|
||||
ImageBackendHandler = Backend.CreateSharedBackend<ImageBackendHandler> (typeof(Image));
|
||||
DrawingPathBackendHandler = Backend.CreateSharedBackend<DrawingPathBackendHandler> (typeof(DrawingPath));
|
||||
DesktopBackend = Backend.CreateSharedBackend<DesktopBackend> (typeof(Desktop));
|
||||
}
|
||||
|
||||
internal void SetActive ()
|
||||
|
@ -299,6 +300,7 @@ namespace Xwt
|
|||
internal ImagePatternBackendHandler ImagePatternBackendHandler;
|
||||
internal ImageBackendHandler ImageBackendHandler;
|
||||
internal DrawingPathBackendHandler DrawingPathBackendHandler;
|
||||
internal DesktopBackend DesktopBackend;
|
||||
}
|
||||
|
||||
class NativeWindowFrame: WindowFrame
|
||||
|
|
Загрузка…
Ссылка в новой задаче