Browse Source

Initial implementation of gtk WindowImpl.

pull/10/head
Steven Kirk 12 years ago
parent
commit
9350bef7b4
  1. 5
      Gtk/Perspex.Gtk/GtkPlatform.cs
  2. 4
      Gtk/Perspex.Gtk/Perspex.Gtk.csproj
  3. 132
      Gtk/Perspex.Gtk/Window.cs
  4. 73
      Gtk/Perspex.Gtk/WindowImpl.cs
  5. 1
      Perspex.Base/Perspex.Base.csproj
  6. 23
      Perspex.Base/Platform/PlatformHandle.cs
  7. 14
      Windows/Perspex.Win32/WindowImpl.cs

5
Gtk/Perspex.Gtk/GtkPlatform.cs

@ -24,8 +24,9 @@ namespace Perspex.Gtk
public static void Initialize() public static void Initialize()
{ {
var locator = Locator.CurrentMutable; var locator = Locator.CurrentMutable;
//locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); locator.Register(() => new WindowImpl(), typeof(IWindowImpl));
locator.Register(() => instance, typeof(IPlatformThreadingInterface)); //locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice));
locator.Register(() => instance, typeof(IPlatformThreadingInterface));
} }
public void ProcessMessage () public void ProcessMessage ()

4
Gtk/Perspex.Gtk/Perspex.Gtk.csproj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -57,7 +57,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GtkPlatform.cs" /> <Compile Include="GtkPlatform.cs" />
<Compile Include="Window.cs" /> <Compile Include="WindowImpl.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

132
Gtk/Perspex.Gtk/Window.cs

@ -1,132 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="Window.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Gtk
{
using System;
using System.Reactive.Linq;
using Perspex.Controls;
using Perspex.Controls.Presenters;
using Perspex.Input;
using Perspex.Layout;
using Perspex.Rendering;
using Perspex.Platform;
using Perspex.Threading;
using Splat;
using Gtk = global::Gtk;
public class Window : ContentControl, ILayoutRoot, IRenderRoot, ICloseable
{
public static readonly PerspexProperty<string> TitleProperty =
PerspexProperty.Register<Window, string>("Title");
private Gtk.Window inner;
private Dispatcher dispatcher;
private IRenderer renderer;
public Window ()
{
IPlatformRenderInterface factory = Locator.Current.GetService<IPlatformRenderInterface>();
this.inner = new Gtk.Window(Gtk.WindowType.Toplevel);
inner.SetDefaultSize(1400, 800);
inner.SetPosition(Gtk.WindowPosition.Center);
inner.DeleteEvent += (o, a) =>
{
if (this.Closed != null)
{
this.Closed(this, EventArgs.Empty);
}
};
var clientSize = this.ClientSize;
this.renderer = factory.CreateRenderer(this.inner.Handle, (int)clientSize.Width, (int)clientSize.Height);
this.LayoutManager = new LayoutManager(this);
this.RenderManager = new RenderManager();
this.Template = ControlTemplate.Create<Window>(this.DefaultTemplate);
this.LayoutManager.LayoutNeeded.Subscribe(x =>
{
this.dispatcher.InvokeAsync(
() =>
{
this.LayoutManager.ExecuteLayoutPass();
this.renderer.Render(this);
this.RenderManager.RenderFinished();
},
DispatcherPriority.Render);
});
this.RenderManager.RenderNeeded
.Where(_ => !this.LayoutManager.LayoutQueued)
.Subscribe(x =>
{
this.dispatcher.InvokeAsync(
() =>
{
if (!this.LayoutManager.LayoutQueued)
{
this.renderer.Render(this);
this.RenderManager.RenderFinished();
}
},
DispatcherPriority.Render);
});
}
public event System.EventHandler Closed;
public Size ClientSize
{
get
{
int width;
int height;
this.inner.GetSize(out width, out height);
return new Size(width, height);
}
}
public ILayoutManager LayoutManager
{
get;
private set;
}
public IRenderManager RenderManager
{
get;
private set;
}
public string Title
{
get { return this.GetValue(TitleProperty); }
set { this.SetValue(TitleProperty, value); }
}
public void Show()
{
this.inner.Show();
}
private Control DefaultTemplate(Window c)
{
Border border = new Border();
border.Background = new Perspex.Media.SolidColorBrush(0xffffffff);
ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.Bind(
ContentPresenter.ContentProperty,
this.GetObservable(Window.ContentProperty),
BindingPriority.Style);
border.Content = contentPresenter;
return border;
}
}
}

73
Gtk/Perspex.Gtk/WindowImpl.cs

@ -0,0 +1,73 @@
// -----------------------------------------------------------------------
// <copyright file="Window.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Gtk
{
using System;
using Perspex.Controls;
using Perspex.Input.Raw;
using Perspex.Platform;
using Gtk = global::Gtk;
public class WindowImpl : IWindowImpl
{
private Gtk.Window inner;
private Window owner;
public WindowImpl ()
{
this.inner = new Gtk.Window(Gtk.WindowType.Toplevel);
// TODO: Use ?. operator on these when it's available.
this.inner.FocusActivated += (s, a) => this.Activated.Invoke(this, EventArgs.Empty);
this.inner.Destroyed += (s, a) => this.Closed.Invoke(this, EventArgs.Empty);
this.inner.ConfigureEvent += (s, a) => this.Resized.Invoke(this, new RawSizeEventArgs(a.Event.Width, a.Event.Height));
this.Handle = new PlatformHandle(this.inner.Handle, "GtkWindow");
}
public Size ClientSize
{
get
{
int width;
int height;
this.inner.GetSize(out width, out height);
return new Size(width, height);
}
}
public IPlatformHandle Handle
{
get;
private set;
}
public event EventHandler Activated;
public event EventHandler Closed;
public event EventHandler<RawInputEventArgs> Input;
public event EventHandler<RawSizeEventArgs> Resized;
public void SetOwner(Window window)
{
this.owner = window;
}
public void SetTitle(string title)
{
this.inner.Title = title;
}
public void Show()
{
this.inner.Show();
}
}
}

1
Perspex.Base/Perspex.Base.csproj

@ -47,6 +47,7 @@
<Compile Include="PerspexPropertyChangedEventArgs.cs" /> <Compile Include="PerspexPropertyChangedEventArgs.cs" />
<Compile Include="Platform\IPlatformHandle.cs" /> <Compile Include="Platform\IPlatformHandle.cs" />
<Compile Include="Platform\IPlatformThreadingInterface.cs" /> <Compile Include="Platform\IPlatformThreadingInterface.cs" />
<Compile Include="Platform\PlatformHandle.cs" />
<Compile Include="PriorityValue.cs" /> <Compile Include="PriorityValue.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Threading\Dispatcher.cs" /> <Compile Include="Threading\Dispatcher.cs" />

23
Perspex.Base/Platform/PlatformHandle.cs

@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// <copyright file="PlatformHandle.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Platform
{
using System;
public class PlatformHandle : IPlatformHandle
{
public PlatformHandle(IntPtr handle, string descriptor)
{
this.Handle = handle;
this.HandleDescriptor = descriptor;
}
public IntPtr Handle { get; private set; }
public string HandleDescriptor { get; private set; }
}
}

14
Windows/Perspex.Win32/WindowImpl.cs

@ -124,7 +124,7 @@ namespace Perspex.Win32
throw new Win32Exception(); throw new Win32Exception();
} }
this.Handle = new PlatformHandle(this.hwnd); this.Handle = new PlatformHandle(this.hwnd, "HWND");
} }
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")] [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")]
@ -198,17 +198,5 @@ namespace Perspex.Win32
return UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam); return UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam);
} }
private class PlatformHandle : IPlatformHandle
{
public PlatformHandle(IntPtr hwnd)
{
this.Handle = hwnd;
}
public IntPtr Handle { get; private set; }
public string HandleDescriptor { get { return "HWND"; } }
}
} }
} }

Loading…
Cancel
Save