Initial commit
This commit is contained in:
Коммит
e0add32f9a
|
@ -0,0 +1,27 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("Xwt.Gtk")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("Xamarin, Inc (http://www.xamarin.com)")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C3887A93-B2BD-4097-8E2F-3A063EFF32FD}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Xwt.GtkBackend</RootNamespace>
|
||||
<AssemblyName>Xwt.Gtk</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
|
||||
<Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
|
||||
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
|
||||
<Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Mono.Cairo" />
|
||||
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\LabelBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\WidgetBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\WindowBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\GtkEngine.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\BoxBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\ButtonBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\NotebookBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\TreeStoreBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\TreeViewBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend.CellViews\CellUtil.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\ImageHandler.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\ContextBackendHandler.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\CanvasBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\GradientBackendHandler.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\Util.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\TextLayoutBackendHandler.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\FontBackendHandler.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\ListViewBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\TableViewBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\ListStoreBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\TableStoreBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\MenuBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\MenuItemBackend.cs" />
|
||||
<Compile Include="Xwt.GtkBackend\Platform.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Xwt\Xwt.csproj">
|
||||
<Project>{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}</Project>
|
||||
<Name>Xwt</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Xwt.GtkBackend\" />
|
||||
<Folder Include="Xwt.GtkBackend.CellViews\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// CellUtil.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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;
|
||||
using System.Linq;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public static class CellUtil
|
||||
{
|
||||
public static Gtk.CellRenderer CreateCellRenderer (Gtk.TreeViewColumn col, CellView view)
|
||||
{
|
||||
if (view is TextCellView) {
|
||||
Gtk.CellRendererText cr = new Gtk.CellRendererText ();
|
||||
col.PackStart (cr, false);
|
||||
col.AddAttribute (cr, "text", ((TextCellView)view).TextField.Index);
|
||||
return cr;
|
||||
}
|
||||
else if (view is CheckBoxCellView) {
|
||||
Gtk.CellRendererToggle cr = new Gtk.CellRendererToggle ();
|
||||
col.PackStart (cr, false);
|
||||
col.AddAttribute (cr, "active", ((CheckBoxCellView)view).ActiveField.Index);
|
||||
return cr;
|
||||
}
|
||||
else if (view is ImageCellView) {
|
||||
Gtk.CellRendererPixbuf cr = new Gtk.CellRendererPixbuf ();
|
||||
col.PackStart (cr, false);
|
||||
col.AddAttribute (cr, "pixbuf", ((ImageCellView)view).ImageField.Index);
|
||||
return cr;
|
||||
}
|
||||
throw new NotSupportedException ("Unknown cell view type: " + view.GetType ());
|
||||
}
|
||||
|
||||
public static Gtk.Widget CreateCellRenderer (ICollection<CellView> views)
|
||||
{
|
||||
if (views.Count == 1) {
|
||||
Gtk.HBox box = new Gtk.HBox ();
|
||||
foreach (var v in views)
|
||||
box.PackStart (CreateCellRenderer (v), false, false, 0);
|
||||
box.ShowAll ();
|
||||
return box;
|
||||
}
|
||||
else
|
||||
return CreateCellRenderer (views.First ());
|
||||
}
|
||||
|
||||
public static Gtk.Widget CreateCellRenderer (CellView view)
|
||||
{
|
||||
if (view is TextCellView) {
|
||||
Gtk.Label lab = new Gtk.Label ();
|
||||
lab.Xalign = 0;
|
||||
// lab.Text = ((TextCellView)view).TextField;
|
||||
return lab;
|
||||
}
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
//
|
||||
// BoxBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Backends;
|
||||
using Xwt;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
class BoxBackend<T, S>: WidgetBackend<T, S>, IBoxBackend where T:CustomContainer where S:IWidgetEventSink
|
||||
{
|
||||
public BoxBackend ()
|
||||
{
|
||||
Widget = (T) new CustomContainer ();
|
||||
Widget.Show ();
|
||||
}
|
||||
|
||||
public override void Initialize ()
|
||||
{
|
||||
Widget.Frontend = Frontend;
|
||||
}
|
||||
|
||||
public void Add (IWidgetBackend widget)
|
||||
{
|
||||
Widget.Add (GetWidget (widget));
|
||||
}
|
||||
|
||||
public void Remove (IWidgetBackend widget)
|
||||
{
|
||||
Widget.Remove (GetWidget (widget));
|
||||
}
|
||||
|
||||
public void SetAllocation (IWidgetBackend widget, Rectangle rect)
|
||||
{
|
||||
var w = GetWidget (widget);
|
||||
Widget.SetAllocation (w, rect);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomContainer: Gtk.Container
|
||||
{
|
||||
public Widget Frontend;
|
||||
Dictionary<Gtk.Widget, Rectangle> children = new Dictionary<Gtk.Widget, Rectangle> ();
|
||||
|
||||
public CustomContainer (IntPtr p): base (p)
|
||||
{
|
||||
}
|
||||
|
||||
public CustomContainer ()
|
||||
{
|
||||
WidgetFlags |= Gtk.WidgetFlags.NoWindow;
|
||||
}
|
||||
|
||||
public void SetAllocation (Gtk.Widget w, Rectangle rect)
|
||||
{
|
||||
children [w] = rect;
|
||||
}
|
||||
|
||||
protected override void OnAdded (Gtk.Widget widget)
|
||||
{
|
||||
children.Add (widget, new Rectangle (0,0,0,0));
|
||||
widget.Parent = this;
|
||||
widget.QueueResize ();
|
||||
}
|
||||
|
||||
protected override void OnRemoved (Gtk.Widget widget)
|
||||
{
|
||||
children.Remove (widget);
|
||||
widget.Unparent ();
|
||||
}
|
||||
|
||||
protected override void OnSizeRequested (ref Gtk.Requisition requisition)
|
||||
{
|
||||
requisition.Height = requisition.Width = 0;
|
||||
foreach (var cr in children) {
|
||||
cr.Key.SizeRequest ();
|
||||
if (cr.Value.Right + 1 > requisition.Width)
|
||||
requisition.Width = (int) cr.Value.Right + 1;
|
||||
if (cr.Value.Bottom + 1 > requisition.Height)
|
||||
requisition.Height = (int) cr.Value.Bottom + 1;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
|
||||
{
|
||||
base.OnSizeAllocated (allocation);
|
||||
((IWidgetSurface)Frontend).Reallocate ();
|
||||
foreach (var cr in children) {
|
||||
var r = cr.Value;
|
||||
cr.Key.SizeAllocate (new Gdk.Rectangle (allocation.X + (int)r.X, allocation.Y + (int)r.Y, (int)r.Width, (int)r.Height));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ForAll (bool include_internals, Gtk.Callback callback)
|
||||
{
|
||||
base.ForAll (include_internals, callback);
|
||||
foreach (var c in children.Keys.ToArray ())
|
||||
callback (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// ButtonBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
class ButtonBackend<T,S>: WidgetBackend<T,S>, IButtonBackend where T:Gtk.Button where S:IButtonEventSink
|
||||
{
|
||||
public ButtonBackend ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Initialize ()
|
||||
{
|
||||
Widget = (T) new Gtk.Button ();
|
||||
Widget.Show ();
|
||||
}
|
||||
|
||||
public string Label {
|
||||
get {
|
||||
return Widget.Label;
|
||||
}
|
||||
set {
|
||||
Widget.Label = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void EnableEvent (object eventId)
|
||||
{
|
||||
base.EnableEvent (eventId);
|
||||
if (eventId is ButtonEvent) {
|
||||
switch ((ButtonEvent)eventId) {
|
||||
case ButtonEvent.Clicked: Widget.Clicked += HandleWidgetClicked; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void DisableEvent (object eventId)
|
||||
{
|
||||
base.DisableEvent (eventId);
|
||||
if (eventId is ButtonEvent) {
|
||||
switch ((ButtonEvent)eventId) {
|
||||
case ButtonEvent.Clicked: Widget.Clicked -= HandleWidgetClicked; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetClicked (object sender, EventArgs e)
|
||||
{
|
||||
EventSink.OnClicked ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
//
|
||||
// CanvasBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class CanvasBackend<T,S>: WidgetBackend<T, S>, ICanvasBackend where T:Gtk.DrawingArea where S:ICanvasEventSink
|
||||
{
|
||||
public override void Initialize ()
|
||||
{
|
||||
Widget = (T) new Gtk.DrawingArea ();
|
||||
Widget.Events |= Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask;
|
||||
Widget.ExposeEvent += HandleWidgetExposeEvent;
|
||||
Widget.ButtonPressEvent += HandleWidgetButtonPressEvent;
|
||||
Widget.ButtonReleaseEvent += HandleWidgetButtonReleaseEvent;
|
||||
Widget.MotionNotifyEvent += HandleWidgetMotionNotifyEvent;
|
||||
Widget.SizeAllocated += HandleWidgetSizeAllocated;
|
||||
Widget.Show ();
|
||||
}
|
||||
|
||||
public void QueueDraw ()
|
||||
{
|
||||
Widget.QueueDraw ();
|
||||
}
|
||||
|
||||
void HandleWidgetMotionNotifyEvent (object o, Gtk.MotionNotifyEventArgs args)
|
||||
{
|
||||
var a = new MouseMovedEventArgs ();
|
||||
a.X = args.Event.X;
|
||||
a.Y = args.Event.Y;
|
||||
EventSink.OnMouseMoved (a);
|
||||
}
|
||||
|
||||
void HandleWidgetButtonReleaseEvent (object o, Gtk.ButtonReleaseEventArgs args)
|
||||
{
|
||||
var a = new ButtonEventArgs ();
|
||||
a.X = args.Event.X;
|
||||
a.Y = args.Event.Y;
|
||||
a.Button = (int) args.Event.Button;
|
||||
EventSink.OnButtonReleased (a);
|
||||
}
|
||||
|
||||
void HandleWidgetButtonPressEvent (object o, Gtk.ButtonPressEventArgs args)
|
||||
{
|
||||
var a = new ButtonEventArgs ();
|
||||
a.X = args.Event.X;
|
||||
a.Y = args.Event.Y;
|
||||
a.Button = (int) args.Event.Button;
|
||||
EventSink.OnButtonPressed (a);
|
||||
}
|
||||
|
||||
void HandleWidgetExposeEvent (object o, Gtk.ExposeEventArgs args)
|
||||
{
|
||||
EventSink.OnDraw (null);
|
||||
}
|
||||
|
||||
public Rectangle Bounds {
|
||||
get {
|
||||
return new Rectangle (0, 0, Widget.Allocation.Width, Widget.Allocation.Height);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
|
||||
{
|
||||
EventSink.OnBoundsChanged ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
//
|
||||
// ContextBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Engine;
|
||||
using Xwt.Drawing;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
class GtkContext
|
||||
{
|
||||
public Cairo.Context Context;
|
||||
public Cairo.Surface TempSurface;
|
||||
public Gtk.Widget Widget;
|
||||
public Point Origin;
|
||||
}
|
||||
|
||||
public class ContextBackendHandler: IContextBackendHandler
|
||||
{
|
||||
public ContextBackendHandler ()
|
||||
{
|
||||
}
|
||||
|
||||
#region IContextBackendHandler implementation
|
||||
public object CreateContext (Widget w)
|
||||
{
|
||||
GtkContext ctx = new GtkContext ();
|
||||
var b = (IGtkWidgetBackend)WidgetRegistry.GetBackend (w);
|
||||
if (!b.Widget.IsRealized) {
|
||||
Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
|
||||
Cairo.Context c = new Cairo.Context (sf);
|
||||
ctx.Context = c;
|
||||
ctx.TempSurface = sf;
|
||||
} else {
|
||||
ctx.Context = Gdk.CairoHelper.Create (b.Widget.GdkWindow);
|
||||
}
|
||||
ctx.Widget = b.Widget;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public void Arc (object backend, double xc, double yc, double radius, double angle1, double angle2)
|
||||
{
|
||||
GtkContext gc = (GtkContext) backend;
|
||||
gc.Context.Arc (gc.Origin.X + xc, gc.Origin.Y + yc, radius, (angle1 * System.Math.PI) / 180, (angle2 * System.Math.PI) / 180);
|
||||
}
|
||||
|
||||
public void Clip (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.Clip ();
|
||||
}
|
||||
|
||||
public void ClipPreserve (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.ClipPreserve ();
|
||||
}
|
||||
|
||||
public void ResetClip (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.ResetClip ();
|
||||
}
|
||||
|
||||
public void ClosePath (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.ClosePath ();
|
||||
}
|
||||
|
||||
public void CurveTo (object backend, double x1, double y1, double x2, double y2, double x3, double y3)
|
||||
{
|
||||
GtkContext gc = (GtkContext) backend;
|
||||
gc.Context.CurveTo (gc.Origin.X + x1, gc.Origin.Y + y1, gc.Origin.X + x2, gc.Origin.Y + y2, gc.Origin.X + x3, gc.Origin.Y + y3);
|
||||
}
|
||||
|
||||
public void Fill (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.Fill ();
|
||||
}
|
||||
|
||||
public void FillPreserve (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.FillPreserve ();
|
||||
}
|
||||
|
||||
public void LineTo (object backend, double x, double y)
|
||||
{
|
||||
GtkContext gc = (GtkContext) backend;
|
||||
gc.Context.LineTo (gc.Origin.X + x, gc.Origin.Y + y);
|
||||
}
|
||||
|
||||
public void MoveTo (object backend, double x, double y)
|
||||
{
|
||||
GtkContext gc = (GtkContext) backend;
|
||||
gc.Context.MoveTo (gc.Origin.X + x, gc.Origin.Y + y);
|
||||
}
|
||||
|
||||
public void NewPath (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.NewPath ();
|
||||
}
|
||||
|
||||
public void Rectangle (object backend, double x, double y, double width, double height)
|
||||
{
|
||||
GtkContext gc = (GtkContext) backend;
|
||||
gc.Context.Rectangle (gc.Origin.X + x, gc.Origin.Y + y, width, height);
|
||||
}
|
||||
|
||||
public void RelCurveTo (object backend, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.RelCurveTo (dx1, dy1, dx2, dy2, dx3, dy3);
|
||||
}
|
||||
|
||||
public void RelLineTo (object backend, double dx, double dy)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.RelLineTo (dx, dy);
|
||||
}
|
||||
|
||||
public void RelMoveTo (object backend, double dx, double dy)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.RelMoveTo (dx, dy);
|
||||
}
|
||||
|
||||
public void Stroke (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.Stroke ();
|
||||
}
|
||||
|
||||
public void StrokePreserve (object backend)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.StrokePreserve ();
|
||||
}
|
||||
|
||||
public void SetColor (object backend, Xwt.Drawing.Color color)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.Color = new Cairo.Color (color.Red, color.Green, color.Blue, color.Alpha);
|
||||
}
|
||||
|
||||
public void SetLineWidth (object backend, double width)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.LineWidth = width;
|
||||
}
|
||||
|
||||
public void SetPattern (object backend, Pattern p)
|
||||
{
|
||||
Cairo.Context ctx = ((GtkContext) backend).Context;
|
||||
ctx.Pattern = (Cairo.Pattern) WidgetRegistry.GetBackend (p);
|
||||
}
|
||||
|
||||
public void SetFont (object backend, Font font)
|
||||
{
|
||||
}
|
||||
|
||||
public void DrawTextLayout (object backend, TextLayout layout, double x, double y)
|
||||
{
|
||||
Pango.Layout pl = (Pango.Layout) WidgetRegistry.GetBackend (layout);
|
||||
GtkContext ctx = (GtkContext) backend;
|
||||
|
||||
Gdk.GC gc = ctx.Widget.Style.BlackGC;
|
||||
ctx.Widget.GdkWindow.DrawLayout (gc, (int)(ctx.Origin.X + x), (int)(ctx.Origin.Y + y), pl);
|
||||
}
|
||||
|
||||
public void DrawImage (object backend, Image img, double x, double y)
|
||||
{
|
||||
Gdk.Pixbuf pb = (Gdk.Pixbuf) WidgetRegistry.GetBackend (img);
|
||||
GtkContext ctx = (GtkContext) backend;
|
||||
Gdk.CairoHelper.SetSourcePixbuf (ctx.Context, pb, x, y);
|
||||
ctx.Context.Paint ();
|
||||
}
|
||||
|
||||
public void Dispose (object backend)
|
||||
{
|
||||
var ctx = (GtkContext) backend;
|
||||
IDisposable d = (IDisposable) ctx.Context;
|
||||
d.Dispose ();
|
||||
if (ctx.TempSurface != null)
|
||||
ctx.TempSurface.Dispose ();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// FontBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Pango;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public class FontBackendHandler: IFontBackendHandler
|
||||
{
|
||||
public object CreateFromName (string fontName, double size)
|
||||
{
|
||||
return FontDescription.FromString (fontName + " " + size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// GradientBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class GradientBackendHandler: IGradientBackendHandler
|
||||
{
|
||||
public object CreateLinear (double x0, double y0, double x1, double y1)
|
||||
{
|
||||
return new Cairo.LinearGradient (x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
public void AddColorStop (object backend, double position, Xwt.Drawing.Color color)
|
||||
{
|
||||
Cairo.Gradient g = (Cairo.Gradient) backend;
|
||||
g.AddColorStop (position, color.ToCairoColor ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
//
|
||||
// GtkEngine.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Engine;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
class GtkEngine: Xwt.Backends.EngineBackend
|
||||
{
|
||||
public override void InitializeApplication ()
|
||||
{
|
||||
Gtk.Application.Init ();
|
||||
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Window), typeof(WindowBackend<Gtk.Window, IWindowEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Label), typeof(LabelBackend<Gtk.Label,IWidgetEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.HBox), typeof(BoxBackend<CustomContainer,IWidgetEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.VBox), typeof(BoxBackend<CustomContainer,IWidgetEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Button), typeof(ButtonBackend<Gtk.Button,IButtonEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Notebook), typeof(NotebookBackend<Gtk.Notebook,IWidgetEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.TreeView), typeof(TreeViewBackend<Gtk.TreeView,ITreeViewEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.TreeStore), typeof(TreeStoreBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.ListView), typeof(ListViewBackend<Gtk.TreeView,IListViewEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.ListStore), typeof(ListStoreBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Canvas), typeof(CanvasBackend<Gtk.DrawingArea,ICanvasEventSink>));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Image), typeof(ImageHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Context), typeof(ContextBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Gradient), typeof(GradientBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.TextLayout), typeof(TextLayoutBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Font), typeof(FontBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Menu), typeof(MenuBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.MenuItem), typeof(MenuItemBackend));
|
||||
}
|
||||
|
||||
public override void RunApplication ()
|
||||
{
|
||||
Gtk.Application.Run ();
|
||||
}
|
||||
|
||||
public static void ReplaceChild (Gtk.Container cont, Gtk.Widget oldWidget, Gtk.Widget newWidget)
|
||||
{
|
||||
if (cont is IGtkContainer) {
|
||||
((IGtkContainer)cont).ReplaceChild (oldWidget, newWidget);
|
||||
}
|
||||
else if (cont is Gtk.Bin) {
|
||||
((Gtk.Bin)cont).Remove (oldWidget);
|
||||
((Gtk.Bin)cont).Child = newWidget;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Invoke (Action action)
|
||||
{
|
||||
Gtk.Application.Invoke (delegate {
|
||||
action ();
|
||||
});
|
||||
}
|
||||
|
||||
public override object TimeoutInvoke (Func<bool> action, TimeSpan timeSpan)
|
||||
{
|
||||
return GLib.Timeout.Add ((uint) timeSpan.TotalMilliseconds, delegate {
|
||||
return action ();
|
||||
});
|
||||
}
|
||||
|
||||
public override void CancelTimeoutInvoke (object id)
|
||||
{
|
||||
GLib.Source.Remove ((uint)id);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IGtkContainer
|
||||
{
|
||||
void ReplaceChild (Gtk.Widget oldWidget, Gtk.Widget newWidget);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// ImageHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class ImageHandler: ImageBackendHandler
|
||||
{
|
||||
public override object LoadFromStream (System.IO.Stream stream)
|
||||
{
|
||||
using (Gdk.PixbufLoader loader = new Gdk.PixbufLoader (stream))
|
||||
return loader.Pixbuf;
|
||||
}
|
||||
|
||||
public override void Dispose (object backend)
|
||||
{
|
||||
((Gdk.Pixbuf)backend).Dispose ();
|
||||
}
|
||||
|
||||
public override Size GetSize (object handle)
|
||||
{
|
||||
var pix = (Gdk.Pixbuf)handle;
|
||||
return new Size (pix.Width, pix.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// LabelBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
class LabelBackend<T,S>: WidgetBackend<T,S>, ILabelBackend where T:Gtk.Label where S:IWidgetEventSink
|
||||
{
|
||||
public LabelBackend ()
|
||||
{
|
||||
Widget = (T) new Gtk.Label ();
|
||||
Widget.Show ();
|
||||
Widget.Xalign = 0;
|
||||
Widget.Yalign = 0;
|
||||
}
|
||||
|
||||
public string Text {
|
||||
get { return Widget.Text; }
|
||||
set { Widget.Text = value; }
|
||||
}
|
||||
|
||||
public Alignment HorizontalAlignment {
|
||||
get {
|
||||
if (Widget.Xalign == 0)
|
||||
return Alignment.Start;
|
||||
else if (Widget.Xalign == 1)
|
||||
return Alignment.End;
|
||||
else
|
||||
return Alignment.Center;
|
||||
}
|
||||
set {
|
||||
switch (value) {
|
||||
case Alignment.Start: Widget.Xalign = 0; break;
|
||||
case Alignment.End: Widget.Xalign = 1; break;
|
||||
case Alignment.Center: Widget.Xalign = 0.5f; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
//
|
||||
// ListStoreBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Drawing;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public class ListStoreBackend: TableStoreBackend, IListStoreBackend
|
||||
{
|
||||
public override Gtk.TreeModel InitializeModel (Type[] columnTypes)
|
||||
{
|
||||
return new Gtk.ListStore (columnTypes);
|
||||
}
|
||||
|
||||
public Gtk.ListStore List {
|
||||
get { return (Gtk.ListStore) Store; }
|
||||
}
|
||||
|
||||
public object GetValue (int row, int column)
|
||||
{
|
||||
Gtk.TreeIter it;
|
||||
if (!List.IterNthChild (out it, row))
|
||||
return null;
|
||||
return GetValue (it, column);
|
||||
}
|
||||
|
||||
public void SetValue (int row, int column, object value)
|
||||
{
|
||||
Gtk.TreeIter it;
|
||||
if (!List.IterNthChild (out it, row))
|
||||
return;
|
||||
SetValue (it, column, value);
|
||||
}
|
||||
|
||||
public int RowCount {
|
||||
get {
|
||||
return List.IterNChildren ();
|
||||
}
|
||||
}
|
||||
|
||||
public int AddRow ()
|
||||
{
|
||||
List.Append ();
|
||||
return RowCount - 1;
|
||||
}
|
||||
|
||||
public int InsertRowAfter (int row)
|
||||
{
|
||||
List.Insert (row + 1);
|
||||
return row + 1;
|
||||
}
|
||||
|
||||
public int InsertRowBefore (int row)
|
||||
{
|
||||
List.Insert (row);
|
||||
return row;
|
||||
}
|
||||
|
||||
public void RemoveRow (int row)
|
||||
{
|
||||
Gtk.TreeIter it;
|
||||
if (!List.IterNthChild (out it, row))
|
||||
return;
|
||||
List.Remove (ref it);
|
||||
}
|
||||
|
||||
public void EnableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
|
||||
public void DisableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// ListViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class ListViewBackend<T, S>: TableViewBackend<T,S>, IListViewBackend where T:Gtk.TreeView where S:IListViewEventSink
|
||||
{
|
||||
public void SetSource (IListViewSource source, IBackend sourceBackend)
|
||||
{
|
||||
ListStoreBackend b = sourceBackend as ListStoreBackend;
|
||||
if (b == null)
|
||||
throw new NotSupportedException ("Custom list stores are not supported");
|
||||
Widget.Model = b.Store;
|
||||
}
|
||||
|
||||
public void SelectRow (int row)
|
||||
{
|
||||
Gtk.TreeIter it;
|
||||
if (!Widget.Model.IterNthChild (out it, row))
|
||||
return;
|
||||
Widget.Selection.SelectIter (it);
|
||||
}
|
||||
|
||||
public void UnselectRow (int row)
|
||||
{
|
||||
Gtk.TreeIter it;
|
||||
if (!Widget.Model.IterNthChild (out it, row))
|
||||
return;
|
||||
Widget.Selection.UnselectIter (it);
|
||||
}
|
||||
|
||||
public int[] SelectedRows {
|
||||
get {
|
||||
var sel = Widget.Selection.GetSelectedRows ();
|
||||
int[] res = new int [sel.Length];
|
||||
for (int n=0; n<sel.Length; n++)
|
||||
res [n] = sel [n].Indices[0];
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
//
|
||||
// MenuBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MenuBackend: IMenuBackend
|
||||
{
|
||||
Gtk.MenuShell menu;
|
||||
|
||||
public void Initialize (object frontend)
|
||||
{
|
||||
menu = new Gtk.Menu ();
|
||||
menu.Visible = true;
|
||||
}
|
||||
|
||||
public Gtk.Menu Menu {
|
||||
get {
|
||||
if (menu is Gtk.Menu)
|
||||
return (Gtk.Menu) menu;
|
||||
Gtk.Menu newMenu = new Gtk.Menu ();
|
||||
TransferProps (menu, newMenu);
|
||||
foreach (var it in menu.Children) {
|
||||
menu.Remove (it);
|
||||
newMenu.Add (it);
|
||||
}
|
||||
menu = newMenu;
|
||||
return newMenu;
|
||||
}
|
||||
}
|
||||
|
||||
public Gtk.MenuBar MenuBar {
|
||||
get {
|
||||
if (menu is Gtk.MenuBar)
|
||||
return (Gtk.MenuBar) menu;
|
||||
Gtk.MenuBar bar = new Gtk.MenuBar ();
|
||||
TransferProps (menu, bar);
|
||||
foreach (var it in menu.Children) {
|
||||
menu.Remove (it);
|
||||
bar.Insert (it, -1);
|
||||
}
|
||||
menu = bar;
|
||||
return bar;
|
||||
}
|
||||
}
|
||||
|
||||
void TransferProps (Gtk.MenuShell oldMenu, Gtk.MenuShell newMenu)
|
||||
{
|
||||
if (oldMenu.Visible)
|
||||
newMenu.Show ();
|
||||
if (!oldMenu.Sensitive)
|
||||
newMenu.Sensitive = false;
|
||||
}
|
||||
|
||||
public void InsertItem (int index, IMenuItemBackend menuItem)
|
||||
{
|
||||
Gtk.MenuItem item = ((MenuItemBackend)menuItem).MenuItem;
|
||||
menu.Insert (item, index);
|
||||
}
|
||||
|
||||
public void RemoveItem (IMenuItemBackend menuItem)
|
||||
{
|
||||
Gtk.MenuItem item = ((MenuItemBackend)menuItem).MenuItem;
|
||||
menu.Remove (item);
|
||||
}
|
||||
|
||||
public void EnableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
|
||||
public void DisableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
//
|
||||
// MenuItemBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class MenuItemBackend: IMenuItemBackend
|
||||
{
|
||||
IMenuItemEventSink eventSink;
|
||||
Gtk.MenuItem item;
|
||||
Gtk.Label label;
|
||||
|
||||
public MenuItemBackend ()
|
||||
{
|
||||
item = new Gtk.ImageMenuItem ("");
|
||||
label = (Gtk.Label) item.Child;
|
||||
item.ShowAll ();
|
||||
}
|
||||
|
||||
public Gtk.MenuItem MenuItem {
|
||||
get { return item; }
|
||||
}
|
||||
|
||||
public void Initialize (IMenuItemEventSink eventSink)
|
||||
{
|
||||
this.eventSink = eventSink;
|
||||
}
|
||||
|
||||
public void SetSubmenu (IMenuBackend menu)
|
||||
{
|
||||
if (menu == null)
|
||||
item.Submenu = null;
|
||||
else {
|
||||
Gtk.Menu m = ((MenuBackend)menu).Menu;
|
||||
item.Submenu = m;
|
||||
}
|
||||
}
|
||||
|
||||
public string Label {
|
||||
get {
|
||||
return label.Text;
|
||||
}
|
||||
set {
|
||||
label.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize (object frontend)
|
||||
{
|
||||
}
|
||||
|
||||
public void EnableEvent (object eventId)
|
||||
{
|
||||
if (eventId is MenuItemEvent) {
|
||||
if ((MenuItemEvent)eventId == MenuItemEvent.Clicked)
|
||||
item.Activated += HandleItemActivated;
|
||||
}
|
||||
}
|
||||
|
||||
public void DisableEvent (object eventId)
|
||||
{
|
||||
if (eventId is MenuItemEvent) {
|
||||
if ((MenuItemEvent)eventId == MenuItemEvent.Clicked)
|
||||
item.Activated -= HandleItemActivated;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleItemActivated (object sender, EventArgs e)
|
||||
{
|
||||
eventSink.OnClicked ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// NotebookBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class NotebookBackend<T,S>: WidgetBackend<T,S>, INotebookBackend where T:Gtk.Notebook where S:IWidgetEventSink
|
||||
{
|
||||
public NotebookBackend ()
|
||||
{
|
||||
Widget = (T) new Gtk.Notebook ();
|
||||
Widget.Show ();
|
||||
}
|
||||
|
||||
public void Add (IWidgetBackend widget, NotebookTab tab)
|
||||
{
|
||||
Gtk.Label label = new Gtk.Label (tab.Label);
|
||||
label.Show ();
|
||||
Widget.AppendPage (GetWidget (widget), label);
|
||||
}
|
||||
|
||||
public void Remove (IWidgetBackend widget)
|
||||
{
|
||||
Widget.Remove (GetWidget (widget));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// Platform.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Hutchinson <mhutch@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 Xamarin Inc. (http://xamarin.com)
|
||||
//
|
||||
// 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.Runtime.InteropServices;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public static class Platform
|
||||
{
|
||||
public readonly static bool IsWindows;
|
||||
public readonly static bool IsMac;
|
||||
|
||||
static Platform ()
|
||||
{
|
||||
IsWindows = Path.DirectorySeparatorChar == '\\';
|
||||
IsMac = !IsWindows && IsRunningOnMac ();
|
||||
}
|
||||
|
||||
//From Managed.Windows.Forms/XplatUI
|
||||
static bool IsRunningOnMac ()
|
||||
{
|
||||
IntPtr buf = IntPtr.Zero;
|
||||
try {
|
||||
buf = Marshal.AllocHGlobal (8192);
|
||||
// This is a hacktastic way of getting sysname from uname ()
|
||||
if (uname (buf) == 0) {
|
||||
string os = System.Runtime.InteropServices.Marshal.PtrToStringAnsi (buf);
|
||||
if (os == "Darwin")
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
} finally {
|
||||
if (buf != IntPtr.Zero)
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal (buf);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[DllImport ("libc")]
|
||||
static extern int uname (IntPtr buf);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// TableStoreBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing;
|
||||
using Xwt.Engine;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public abstract class TableStoreBackend
|
||||
{
|
||||
Gtk.TreeModel store;
|
||||
|
||||
public Gtk.TreeModel Store {
|
||||
get {
|
||||
return store;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize (Type[] columnTypes)
|
||||
{
|
||||
Type[] types = new Type[columnTypes.Length];
|
||||
for (int n=0; n<types.Length; n++) {
|
||||
if (columnTypes [n] == typeof(Image))
|
||||
types [n] = typeof(Gdk.Pixbuf);
|
||||
else
|
||||
types [n] = columnTypes [n];
|
||||
}
|
||||
store = InitializeModel (types);
|
||||
}
|
||||
|
||||
public abstract Gtk.TreeModel InitializeModel (Type[] columnTypes);
|
||||
|
||||
public void Initialize (object frontend)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter it, int column, object value)
|
||||
{
|
||||
if (value is string)
|
||||
store.SetValue (it, column, (string)value);
|
||||
else if (value is Image)
|
||||
store.SetValue (it, column, (Gdk.Pixbuf)WidgetRegistry.GetBackend (value));
|
||||
else
|
||||
store.SetValue (it, column, value ?? DBNull.Value);
|
||||
}
|
||||
|
||||
public object GetValue (Gtk.TreeIter it, int column)
|
||||
{
|
||||
object val = store.GetValue (it, column);
|
||||
if (val is Gdk.Pixbuf)
|
||||
return WidgetRegistry.CreateFrontend<Image> (val);
|
||||
else if (val is DBNull)
|
||||
return null;
|
||||
else
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
//
|
||||
// TableViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class TableViewBackend<T,S>: WidgetBackend<T,S> where T:Gtk.TreeView where S:ITableViewEventSink
|
||||
{
|
||||
public TableViewBackend ()
|
||||
{
|
||||
Widget = (T) new Gtk.TreeView ();
|
||||
Widget.Show ();
|
||||
}
|
||||
|
||||
public override void EnableEvent (object eventId)
|
||||
{
|
||||
base.EnableEvent (eventId);
|
||||
if (eventId is TableViewEvent) {
|
||||
if (((TableViewEvent)eventId) == TableViewEvent.SelectionChanged)
|
||||
Widget.Selection.Changed += HandleWidgetSelectionChanged;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DisableEvent (object eventId)
|
||||
{
|
||||
base.DisableEvent (eventId);
|
||||
if (eventId is TableViewEvent) {
|
||||
if (((TableViewEvent)eventId) == TableViewEvent.SelectionChanged)
|
||||
Widget.Selection.Changed -= HandleWidgetSelectionChanged;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetSelectionChanged (object sender, EventArgs e)
|
||||
{
|
||||
EventSink.OnSelectionChanged ();
|
||||
}
|
||||
|
||||
public object AddColumn (ListViewColumn col)
|
||||
{
|
||||
Gtk.TreeViewColumn tc = new Gtk.TreeViewColumn ();
|
||||
tc.Title = col.Title;
|
||||
Widget.AppendColumn (tc);
|
||||
MapTitle (col, tc);
|
||||
MapColumn (col, tc);
|
||||
return tc;
|
||||
}
|
||||
|
||||
void MapTitle (ListViewColumn col, Gtk.TreeViewColumn tc)
|
||||
{
|
||||
if (col.HeaderView == null)
|
||||
tc.Title = col.Title;
|
||||
else
|
||||
tc.Widget = CellUtil.CreateCellRenderer (col.HeaderView);
|
||||
}
|
||||
|
||||
void MapColumn (ListViewColumn col, Gtk.TreeViewColumn tc)
|
||||
{
|
||||
foreach (var v in col.Views) {
|
||||
CellUtil.CreateCellRenderer (tc, v);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveColumn (ListViewColumn col, object handle)
|
||||
{
|
||||
Widget.RemoveColumn ((Gtk.TreeViewColumn)handle);
|
||||
}
|
||||
|
||||
public void UpdateColumn (ListViewColumn col, object handle, ListViewColumnChange change)
|
||||
{
|
||||
Gtk.TreeViewColumn tc = (Gtk.TreeViewColumn) handle;
|
||||
if (change == ListViewColumnChange.Cells) {
|
||||
tc.Clear ();
|
||||
MapColumn (col, tc);
|
||||
}
|
||||
else if (change == ListViewColumnChange.Title)
|
||||
MapTitle (col, tc);
|
||||
}
|
||||
|
||||
public void SelectAll ()
|
||||
{
|
||||
Widget.Selection.SelectAll ();
|
||||
}
|
||||
|
||||
public void UnselectAll ()
|
||||
{
|
||||
Widget.Selection.UnselectAll ();
|
||||
}
|
||||
|
||||
public void SetSelectionMode (SelectionMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case SelectionMode.Single: Widget.Selection.Mode = Gtk.SelectionMode.Single; break;
|
||||
case SelectionMode.Multiple: Widget.Selection.Mode = Gtk.SelectionMode.Multiple; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// TextLayoutBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Drawing;
|
||||
using Xwt.Engine;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public class TextLayoutBackendHandler: ITextLayoutBackendHandler
|
||||
{
|
||||
public object Create (Context context)
|
||||
{
|
||||
GtkContext c = (GtkContext) WidgetRegistry.GetBackend (context);
|
||||
return new Pango.Layout (c.Widget.PangoContext);
|
||||
}
|
||||
|
||||
public void SetText (object backend, string text)
|
||||
{
|
||||
Pango.Layout tl = (Pango.Layout) backend;
|
||||
tl.SetText (text);
|
||||
}
|
||||
|
||||
public void SetFont (object backend, Xwt.Drawing.Font font)
|
||||
{
|
||||
Pango.Layout tl = (Pango.Layout) backend;
|
||||
tl.FontDescription = (Pango.FontDescription) WidgetRegistry.GetBackend (font);
|
||||
}
|
||||
|
||||
public Size GetSize (object backend)
|
||||
{
|
||||
Pango.Layout tl = (Pango.Layout) backend;
|
||||
int w, h;
|
||||
tl.GetSize (out w, out h);
|
||||
return new Size ((double)w / (double)Pango.Scale.PangoScale, (double)h / (double)Pango.Scale.PangoScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
//
|
||||
// TreeStoreBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Drawing;
|
||||
using Xwt.Engine;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
class IterPos: TreePosition
|
||||
{
|
||||
public IterPos ()
|
||||
{
|
||||
}
|
||||
|
||||
public IterPos (Gtk.TreeIter iter)
|
||||
{
|
||||
this.Iter = iter;
|
||||
}
|
||||
|
||||
public Gtk.TreeIter Iter;
|
||||
public Gtk.TreeIter LastChildIter;
|
||||
public int LastChildIndex = -1;
|
||||
public int ChildrenCount = -1;
|
||||
}
|
||||
|
||||
public class TreeStoreBackend: TableStoreBackend, ITreeStoreBackend
|
||||
{
|
||||
public Gtk.TreeStore Tree {
|
||||
get { return (Gtk.TreeStore) Store; }
|
||||
}
|
||||
|
||||
public override Gtk.TreeModel InitializeModel (Type[] columnTypes)
|
||||
{
|
||||
return new Gtk.TreeStore (columnTypes);
|
||||
}
|
||||
|
||||
public TreePosition GetChild (TreePosition pos, int index)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
if (tpos.LastChildIndex == index)
|
||||
return new IterPos (tpos.LastChildIter);
|
||||
if (index == 0) {
|
||||
Gtk.TreeIter it;
|
||||
if (Tree.GetIterFirst (out it)) {
|
||||
tpos.LastChildIter = it;
|
||||
tpos.LastChildIndex = 0;
|
||||
return new IterPos (it);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
if (tpos.LastChildIndex == -1 || tpos.LastChildIndex > index) {
|
||||
Gtk.TreeIter it;
|
||||
if (Tree.IterNthChild (out it, index)) {
|
||||
tpos.LastChildIter = it;
|
||||
tpos.LastChildIndex = index;
|
||||
return new IterPos (it);
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
// tpos.LastChildIndex < index
|
||||
|
||||
Gtk.TreeIter iter = tpos.LastChildIter;
|
||||
for (int n = tpos.LastChildIndex; n < index; n++) {
|
||||
if (!Tree.IterNext (ref iter))
|
||||
return null;
|
||||
}
|
||||
tpos.LastChildIter = iter;
|
||||
tpos.LastChildIndex = index;
|
||||
return new IterPos (iter);
|
||||
}
|
||||
|
||||
public int GetChildrenCount (TreePosition pos)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
if (tpos.ChildrenCount != -1)
|
||||
return tpos.ChildrenCount;
|
||||
if (pos == null)
|
||||
tpos.ChildrenCount = Tree.IterNChildren ();
|
||||
else
|
||||
tpos.ChildrenCount = Tree.IterNChildren (tpos.Iter);
|
||||
return tpos.ChildrenCount;
|
||||
}
|
||||
|
||||
public void SetValue (TreePosition pos, int column, object value)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
SetValue (tpos.Iter, column, value);
|
||||
}
|
||||
|
||||
public object GetValue (TreePosition pos, int column)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
return GetValue (tpos.Iter, column);
|
||||
}
|
||||
|
||||
public TreePosition InsertBefore (TreePosition pos)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
var p = Tree.InsertNodeBefore (tpos.Iter);
|
||||
return new IterPos (p);
|
||||
}
|
||||
|
||||
public TreePosition InsertAfter (TreePosition pos)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
var p = Tree.InsertNodeAfter (tpos.Iter);
|
||||
return new IterPos (p);
|
||||
}
|
||||
|
||||
public TreePosition AddChild (TreePosition pos)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
Gtk.TreeIter it;
|
||||
if (pos == null)
|
||||
it = Tree.AppendNode ();
|
||||
else
|
||||
it = Tree.AppendNode (tpos.Iter);
|
||||
return new IterPos (it);
|
||||
}
|
||||
|
||||
public TreePosition GetNext (TreePosition pos)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
Gtk.TreeIter it = tpos.Iter;
|
||||
if (!Tree.IterNext (ref it))
|
||||
return null;
|
||||
return new IterPos (it);
|
||||
}
|
||||
|
||||
public TreePosition GetPrevious (TreePosition pos)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public TreePosition GetParent (TreePosition pos)
|
||||
{
|
||||
IterPos tpos = (IterPos) pos;
|
||||
Gtk.TreeIter it;
|
||||
if (!Tree.IterParent (out it, tpos.Iter))
|
||||
return null;
|
||||
return new IterPos (it);
|
||||
}
|
||||
|
||||
public void EnableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
|
||||
public void DisableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// TreeViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class TreeViewBackend<T, S>: TableViewBackend<T, S>, ITreeViewBackend where T:Gtk.TreeView where S:ITreeViewEventSink
|
||||
{
|
||||
public void SetSource (ITreeViewSource source, IBackend sourceBackend)
|
||||
{
|
||||
TreeStoreBackend b = sourceBackend as TreeStoreBackend;
|
||||
if (b == null)
|
||||
throw new NotSupportedException ("Custom tree stores are not supported");
|
||||
Widget.Model = b.Store;
|
||||
}
|
||||
|
||||
public TreePosition[] SelectedItems {
|
||||
get {
|
||||
var rows = Widget.Selection.GetSelectedRows ();
|
||||
IterPos[] sel = new IterPos [rows.Length];
|
||||
for (int i = 0; i < rows.Length; i++) {
|
||||
Gtk.TreeIter it;
|
||||
Widget.Model.GetIter (out it, rows[i]);
|
||||
sel[i] = new IterPos (it);
|
||||
}
|
||||
return sel;
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectItem (TreePosition pos)
|
||||
{
|
||||
Widget.Selection.SelectIter (((IterPos)pos).Iter);
|
||||
}
|
||||
|
||||
public void UnselectItem (TreePosition pos)
|
||||
{
|
||||
Widget.Selection.UnselectIter (((IterPos)pos).Iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// Util.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public static class Util
|
||||
{
|
||||
public static Cairo.Color ToCairoColor (this Color col)
|
||||
{
|
||||
return new Cairo.Color (col.Red, col.Green, col.Blue, col.Alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,515 @@
|
|||
//
|
||||
// WidgetBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xwt.Engine;
|
||||
|
||||
namespace Xwt.GtkBackend
|
||||
{
|
||||
public class WidgetBackend<T,S>: IWidgetBackend, IGtkWidgetBackend where T:Gtk.Widget where S:IWidgetEventSink
|
||||
{
|
||||
Widget frontend;
|
||||
Gtk.Alignment alignment;
|
||||
S eventSink;
|
||||
|
||||
static Dictionary<string, Gtk.TargetEntry[]> dragTargets = new Dictionary<string, Gtk.TargetEntry[]> ();
|
||||
static Dictionary<string, string> atomToType = new Dictionary<string, string> ();
|
||||
static uint targetIdCounter = 0;
|
||||
|
||||
bool dragEventsSet;
|
||||
TransferDataSource currentDragData;
|
||||
Gdk.DragAction destDragAction;
|
||||
Gdk.DragAction sourceDragAction;
|
||||
bool dropCheckEventEnabled;
|
||||
bool dropEventEnabled;
|
||||
bool dragMotionCheckEventEnabled;
|
||||
bool dragMotionEventEnabled;
|
||||
int dragDataRequests;
|
||||
TransferDataStore dragData;
|
||||
bool dragDataForMotion;
|
||||
Gtk.TargetEntry[] validDropTypes;
|
||||
|
||||
void IBackend.Initialize (object frontend)
|
||||
{
|
||||
this.frontend = (Widget) frontend;
|
||||
}
|
||||
|
||||
void IWidgetBackend.Initialize (IWidgetEventSink sink)
|
||||
{
|
||||
eventSink = (S) sink;
|
||||
Initialize ();
|
||||
}
|
||||
|
||||
public virtual void Initialize ()
|
||||
{
|
||||
}
|
||||
|
||||
public S EventSink {
|
||||
get { return eventSink; }
|
||||
}
|
||||
|
||||
public Widget Frontend {
|
||||
get { return frontend; }
|
||||
}
|
||||
|
||||
public object NativeWidget {
|
||||
get {
|
||||
return Widget;
|
||||
}
|
||||
}
|
||||
|
||||
public T Widget { get; set; }
|
||||
|
||||
public Gtk.Widget RootWidget {
|
||||
get {
|
||||
return alignment != null ? alignment : (Gtk.Widget) Widget;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Visible {
|
||||
get { return Widget.Visible; }
|
||||
set { Widget.Visible = value; }
|
||||
}
|
||||
|
||||
public virtual bool Sensitive {
|
||||
get { return Widget.Sensitive; }
|
||||
set { Widget.Sensitive = value; }
|
||||
}
|
||||
|
||||
public virtual void Dispose ()
|
||||
{
|
||||
if (Widget != null)
|
||||
Widget.Destroy ();
|
||||
}
|
||||
|
||||
public Size Size {
|
||||
get {
|
||||
return new Size (Widget.Allocation.Width, Widget.Allocation.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual WidgetSize GetPreferredWidth ()
|
||||
{
|
||||
return new WidgetSize (Widget.SizeRequest ().Width) + frontend.Margin.HorizontalSpacing;
|
||||
}
|
||||
|
||||
public virtual WidgetSize GetPreferredHeight ()
|
||||
{
|
||||
return new WidgetSize (Widget.SizeRequest ().Height) + frontend.Margin.VerticalSpacing;
|
||||
}
|
||||
|
||||
public virtual WidgetSize GetPreferredHeightForWidth (double width)
|
||||
{
|
||||
return new WidgetSize (Widget.SizeRequest ().Height) + frontend.Margin.VerticalSpacing;
|
||||
}
|
||||
|
||||
public virtual WidgetSize GetPreferredWidthForHeight (double height)
|
||||
{
|
||||
return new WidgetSize (Widget.SizeRequest ().Width) + frontend.Margin.HorizontalSpacing;
|
||||
}
|
||||
|
||||
Gtk.Widget IGtkWidgetBackend.Widget {
|
||||
get { return RootWidget; }
|
||||
}
|
||||
|
||||
public static Gtk.Widget GetWidget (IWidgetBackend w)
|
||||
{
|
||||
return ((IGtkWidgetBackend)w).Widget;
|
||||
}
|
||||
|
||||
public virtual void UpdateLayout ()
|
||||
{
|
||||
if (frontend.Margin.HorizontalSpacing == 0 && frontend.Margin.VerticalSpacing == 0) {
|
||||
if (alignment != null) {
|
||||
alignment.Remove (Widget);
|
||||
Gtk.Container cont = alignment.Parent as Gtk.Container;
|
||||
if (cont != null)
|
||||
GtkEngine.ReplaceChild (cont, alignment, Widget);
|
||||
alignment.Destroy ();
|
||||
alignment = null;
|
||||
}
|
||||
} else {
|
||||
if (alignment == null) {
|
||||
alignment = new Gtk.Alignment (0, 0, 1, 1);
|
||||
Gtk.Container cont = Widget.Parent as Gtk.Container;
|
||||
if (cont != null)
|
||||
GtkEngine.ReplaceChild (cont, Widget, alignment);
|
||||
alignment.Add (Widget);
|
||||
}
|
||||
alignment.LeftPadding = (uint) frontend.Margin.Left;
|
||||
alignment.RightPadding = (uint) frontend.Margin.Right;
|
||||
alignment.TopPadding = (uint) frontend.Margin.Top;
|
||||
alignment.BottomPadding = (uint) frontend.Margin.Bottom;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void EnableEvent (object eventId)
|
||||
{
|
||||
if (eventId is WidgetEvent) {
|
||||
WidgetEvent ev = (WidgetEvent) eventId;
|
||||
switch (ev) {
|
||||
case WidgetEvent.DragDropCheck:
|
||||
dropCheckEventEnabled = true;
|
||||
break;
|
||||
case WidgetEvent.DragDrop:
|
||||
dropEventEnabled = true;
|
||||
break;
|
||||
case WidgetEvent.DragOverCheck:
|
||||
dragMotionCheckEventEnabled = true;
|
||||
break;
|
||||
case WidgetEvent.DragOver:
|
||||
dragMotionEventEnabled = true;
|
||||
break;
|
||||
case WidgetEvent.DragLeave:
|
||||
Widget.DragLeave += HandleWidgetDragLeave;;
|
||||
break;
|
||||
}
|
||||
if (dropEventEnabled || dropCheckEventEnabled || dragMotionCheckEventEnabled || dragMotionEventEnabled) {
|
||||
if (!dragEventsSet) {
|
||||
dragEventsSet = true;
|
||||
Widget.DragDrop += HandleWidgetDragDrop;
|
||||
Widget.DragMotion += HandleWidgetDragMotion;
|
||||
Widget.DragDataReceived += HandleWidgetDragDataReceived;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DisableEvent (object eventId)
|
||||
{
|
||||
if (eventId is WidgetEvent) {
|
||||
WidgetEvent ev = (WidgetEvent) eventId;
|
||||
switch (ev) {
|
||||
case WidgetEvent.DragDropCheck:
|
||||
dropCheckEventEnabled = false;
|
||||
break;
|
||||
case WidgetEvent.DragDrop:
|
||||
dropEventEnabled = false;
|
||||
break;
|
||||
case WidgetEvent.DragOverCheck:
|
||||
dragMotionCheckEventEnabled = false;
|
||||
break;
|
||||
case WidgetEvent.DragOver:
|
||||
dragMotionEventEnabled = false;
|
||||
break;
|
||||
case WidgetEvent.DragLeave:
|
||||
Widget.DragLeave -= HandleWidgetDragLeave;
|
||||
break;
|
||||
}
|
||||
if (!dropEventEnabled && !dropCheckEventEnabled && !dragMotionCheckEventEnabled && !dragMotionEventEnabled) {
|
||||
if (dragEventsSet) {
|
||||
dragEventsSet = false;
|
||||
Widget.DragDrop -= HandleWidgetDragDrop;
|
||||
Widget.DragMotion -= HandleWidgetDragMotion;
|
||||
Widget.DragDataReceived -= HandleWidgetDragDataReceived;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Point lastDragPosition;
|
||||
|
||||
void HandleWidgetDragMotion (object o, Gtk.DragMotionArgs args)
|
||||
{
|
||||
Console.WriteLine ("DragMotion");
|
||||
lastDragPosition = new Point (args.X, args.Y);
|
||||
|
||||
DragDropAction ac;
|
||||
if (!dragMotionCheckEventEnabled) {
|
||||
if (dragMotionEventEnabled)
|
||||
ac = DragDropAction.Default;
|
||||
else
|
||||
ac = ConvertDragAction (destDragAction);
|
||||
}
|
||||
else {
|
||||
DragOverCheckEventArgs da = new DragOverCheckEventArgs (new Point (args.X, args.Y), GetDragTypes (args.Context.Targets), ConvertDragAction (args.Context.Actions));
|
||||
EventSink.OnDragOverCheck (da);
|
||||
ac = da.AllowedAction;
|
||||
if (!dragMotionEventEnabled && ac == DragDropAction.Default)
|
||||
ac = DragDropAction.None;
|
||||
}
|
||||
|
||||
if (ac == DragDropAction.None) {
|
||||
args.RetVal = false;
|
||||
}
|
||||
else if (ac == DragDropAction.Default) {
|
||||
// Undefined, we need more data
|
||||
args.RetVal = true;
|
||||
QueryDragData (args.Context, args.Time, true);
|
||||
}
|
||||
else {
|
||||
// Gtk.Drag.Highlight (Widget);
|
||||
args.RetVal = true;
|
||||
Console.WriteLine ("-> Status");
|
||||
Gdk.Drag.Status (args.Context, ConvertDragAction (ac), args.Time);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetDragDrop (object o, Gtk.DragDropArgs args)
|
||||
{
|
||||
Console.WriteLine ("DragDrop");
|
||||
lastDragPosition = new Point (args.X, args.Y);
|
||||
|
||||
DragDropResult res;
|
||||
if (!dropCheckEventEnabled) {
|
||||
if (dropEventEnabled)
|
||||
res = DragDropResult.None;
|
||||
else
|
||||
res = DragDropResult.Canceled;
|
||||
}
|
||||
else {
|
||||
DragCheckEventArgs da = new DragCheckEventArgs (new Point (args.X, args.Y), GetDragTypes (args.Context.Targets), ConvertDragAction (args.Context.Actions));
|
||||
EventSink.OnDragDropCheck (da);
|
||||
res = da.Result;
|
||||
if (!dropEventEnabled && res == DragDropResult.None)
|
||||
res = DragDropResult.Canceled;
|
||||
}
|
||||
if (res == DragDropResult.Canceled) {
|
||||
args.RetVal = false;
|
||||
}
|
||||
else if (res == DragDropResult.Success) {
|
||||
args.RetVal = true;
|
||||
Gtk.Drag.Finish (args.Context, true, false, args.Time);
|
||||
}
|
||||
else {
|
||||
// Undefined, we need more data
|
||||
args.RetVal = true;
|
||||
QueryDragData (args.Context, args.Time, false);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetDragLeave (object o, Gtk.DragLeaveArgs args)
|
||||
{
|
||||
// Gtk.Drag.Unhighlight (Widget);
|
||||
eventSink.OnDragLeave (EventArgs.Empty);
|
||||
}
|
||||
|
||||
void QueryDragData (Gdk.DragContext ctx, uint time, bool isMotionEvent)
|
||||
{
|
||||
dragDataForMotion = isMotionEvent;
|
||||
dragData = new TransferDataStore ();
|
||||
dragDataRequests = validDropTypes.Length;
|
||||
foreach (var t in validDropTypes) {
|
||||
Console.WriteLine ("-> GetData");
|
||||
var at = Gdk.Atom.Intern (t.Target, true);
|
||||
data.Add (at);
|
||||
Gtk.Drag.GetData (Widget, ctx, at, time);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetDragDataReceived (object o, Gtk.DragDataReceivedArgs args)
|
||||
{
|
||||
Console.WriteLine ("DataReceived");
|
||||
dragDataRequests--;
|
||||
|
||||
string type;
|
||||
if (!atomToType.TryGetValue (args.SelectionData.Target.Name, out type)) {
|
||||
args.RetVal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.SelectionData.Length > 0) {
|
||||
if (type == TransferDataType.Text)
|
||||
dragData.AddText (args.SelectionData.Text);
|
||||
else if (args.SelectionData.TargetsIncludeImage (false))
|
||||
dragData.AddImage (WidgetRegistry.CreateFrontend<Xwt.Drawing.Image> (args.SelectionData.Pixbuf));
|
||||
else if (type == TransferDataType.Uri) {
|
||||
var uris = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data).Split ('\n').Where (u => !string.IsNullOrEmpty(u)).Select (u => new Uri (u)).ToArray ();
|
||||
dragData.AddUris (uris);
|
||||
}
|
||||
else
|
||||
dragData.AddValue (type, args.SelectionData.Data);
|
||||
}
|
||||
if (dragDataRequests == 0) {
|
||||
if (dragDataForMotion) {
|
||||
DragOverEventArgs da = new DragOverEventArgs (lastDragPosition, dragData, ConvertDragAction (args.Context.Actions));
|
||||
EventSink.OnDragOver (da);
|
||||
// if (da.AllowedAction != DragDropAction.None)
|
||||
// Gtk.Drag.Highlight (Widget);
|
||||
Gdk.Drag.Status (args.Context, ConvertDragAction (da.AllowedAction), args.Time);
|
||||
Console.WriteLine ("-> Status");
|
||||
}
|
||||
else {
|
||||
DragEventArgs da = new DragEventArgs (lastDragPosition, dragData, ConvertDragAction (args.Context.Actions));
|
||||
EventSink.OnDragDrop (da);
|
||||
Gtk.Drag.Finish (args.Context, da.Success, false, args.Time);
|
||||
Console.WriteLine ("-> Finish");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DragStart (TransferDataSource data, DragDropAction dragAction)
|
||||
{
|
||||
Gdk.DragAction action = ConvertDragAction (dragAction);
|
||||
currentDragData = data;
|
||||
Widget.DragEnd += HandleWidgetDragEnd;
|
||||
Widget.DragDataGet += HandleWidgetDragDataGet;
|
||||
Gtk.Drag.Begin (Widget, BuildTargetTable (data.DataTypes), action, 0, Gtk.Global.CurrentEvent);
|
||||
}
|
||||
|
||||
void HandleWidgetDragDataGet (object o, Gtk.DragDataGetArgs args)
|
||||
{
|
||||
foreach (var t in currentDragData.DataTypes) {
|
||||
object val = currentDragData.GetValue (t);
|
||||
if (val == null)
|
||||
continue;
|
||||
if (val is string)
|
||||
args.SelectionData.Text = (string)currentDragData.GetValue (t);
|
||||
else if (val is Xwt.Drawing.Image)
|
||||
args.SelectionData.SetPixbuf ((Gdk.Pixbuf) WidgetRegistry.GetBackend (val));
|
||||
else {
|
||||
var at = Gdk.Atom.Intern (t, false);
|
||||
data.Add (at);
|
||||
args.SelectionData.Set (at, 0, TransferDataSource.SerializeValue (val));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<object> data = new List<object> ();
|
||||
|
||||
void HandleWidgetDragEnd (object o, Gtk.DragEndArgs args)
|
||||
{
|
||||
Widget.DragEnd -= HandleWidgetDragEnd;
|
||||
Widget.DragDataGet -= HandleWidgetDragDataGet;
|
||||
}
|
||||
|
||||
public void SetDragTarget (string[] types, DragDropAction dragAction)
|
||||
{
|
||||
destDragAction = ConvertDragAction (dragAction);
|
||||
var table = BuildTargetTable (types);
|
||||
validDropTypes = (Gtk.TargetEntry[]) table;
|
||||
Gtk.Drag.DestSet (Widget, Gtk.DestDefaults.Highlight, validDropTypes, destDragAction);
|
||||
}
|
||||
|
||||
public void SetDragSource (string[] types, DragDropAction dragAction)
|
||||
{
|
||||
sourceDragAction = ConvertDragAction (dragAction);
|
||||
var table = BuildTargetTable (types);
|
||||
Gtk.Drag.SourceSet (Widget, (Gdk.ModifierType)0, (Gtk.TargetEntry[]) table, sourceDragAction);
|
||||
}
|
||||
|
||||
Gdk.DragAction ConvertDragAction (DragDropAction dragAction)
|
||||
{
|
||||
Gdk.DragAction action = (Gdk.DragAction)0;
|
||||
if ((dragAction & DragDropAction.Copy) != 0)
|
||||
action |= Gdk.DragAction.Copy;
|
||||
if ((dragAction & DragDropAction.Move) != 0)
|
||||
action |= Gdk.DragAction.Move;
|
||||
if ((dragAction & DragDropAction.Link) != 0)
|
||||
action |= Gdk.DragAction.Link;
|
||||
return action;
|
||||
}
|
||||
|
||||
DragDropAction ConvertDragAction (Gdk.DragAction dragAction)
|
||||
{
|
||||
DragDropAction action = (DragDropAction)0;
|
||||
if ((dragAction & Gdk.DragAction.Copy) != 0)
|
||||
action |= DragDropAction.Copy;
|
||||
if ((dragAction & Gdk.DragAction.Move) != 0)
|
||||
action |= DragDropAction.Move;
|
||||
if ((dragAction & Gdk.DragAction.Link) != 0)
|
||||
action |= DragDropAction.Link;
|
||||
return action;
|
||||
}
|
||||
|
||||
string[] GetDragTypes (Gdk.Atom[] dropTypes)
|
||||
{
|
||||
List<string> types = new List<string> ();
|
||||
foreach (var dt in dropTypes) {
|
||||
string type;
|
||||
if (atomToType.TryGetValue (dt.ToString (), out type))
|
||||
types.Add (type);
|
||||
}
|
||||
return types.ToArray ();
|
||||
}
|
||||
|
||||
Gtk.TargetList BuildTargetTable (string[] types)
|
||||
{
|
||||
var tl = new Gtk.TargetList ();
|
||||
foreach (var tt in types)
|
||||
tl.AddTable (CreateTargetEntries (tt));
|
||||
data.Add (tl);
|
||||
return tl;
|
||||
}
|
||||
|
||||
Gtk.TargetEntry[] CreateTargetEntries (string type)
|
||||
{
|
||||
lock (dragTargets) {
|
||||
Gtk.TargetEntry[] entries;
|
||||
if (dragTargets.TryGetValue (type, out entries))
|
||||
return entries;
|
||||
|
||||
uint id = targetIdCounter++;
|
||||
|
||||
switch (type) {
|
||||
case TransferDataType.Uri: {
|
||||
Gtk.TargetList list = new Gtk.TargetList ();
|
||||
list.AddUriTargets (id);
|
||||
entries = (Gtk.TargetEntry[]) list;
|
||||
break;
|
||||
}
|
||||
case TransferDataType.Text: {
|
||||
Gtk.TargetList list = new Gtk.TargetList ();
|
||||
list.AddTextTargets (id);
|
||||
//HACK: work around gtk_selection_data_set_text causing crashes on Mac w/ QuickSilver, Clipbard History etc.
|
||||
if (Platform.IsMac) {
|
||||
list.Remove ("COMPOUND_TEXT");
|
||||
list.Remove ("TEXT");
|
||||
list.Remove ("STRING");
|
||||
}
|
||||
entries = (Gtk.TargetEntry[]) list;
|
||||
break;
|
||||
}
|
||||
case TransferDataType.Rtf: {
|
||||
Gdk.Atom atom;
|
||||
if (Platform.IsMac)
|
||||
atom = Gdk.Atom.Intern ("NSRTFPboardType", false); //TODO: use public.rtf when dep on MacOS 10.6
|
||||
else
|
||||
atom = Gdk.Atom.Intern ("text/rtf", false);
|
||||
entries = new Gtk.TargetEntry[] { new Gtk.TargetEntry (atom, 0, id) };
|
||||
break;
|
||||
}
|
||||
default:
|
||||
entries = new Gtk.TargetEntry[] { new Gtk.TargetEntry (Gdk.Atom.Intern ("application/" + type, false), 0, id) };
|
||||
break;
|
||||
}
|
||||
foreach (var a in entries.Select (e => e.Target))
|
||||
atomToType [a] = type;
|
||||
return dragTargets [type] = entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IGtkWidgetBackend
|
||||
{
|
||||
Gtk.Widget Widget { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
//
|
||||
// WindowBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.GtkBackend
|
||||
{
|
||||
public class WindowBackend<T,S>: WidgetBackend<T,S>, IWindowBackend where T:Gtk.Window where S:IWindowEventSink
|
||||
{
|
||||
Gtk.Alignment alignment;
|
||||
Gtk.MenuBar mainMenu;
|
||||
Gtk.VBox mainBox;
|
||||
|
||||
public WindowBackend ()
|
||||
{
|
||||
Widget = (T) new Gtk.Window ("");
|
||||
mainBox = new Gtk.VBox ();
|
||||
Widget.Add (mainBox);
|
||||
mainBox.Show ();
|
||||
alignment = new Gtk.Alignment (0, 0, 1, 1);
|
||||
mainBox.PackStart (alignment, true, true, 0);
|
||||
alignment.Show ();
|
||||
}
|
||||
|
||||
public string Title {
|
||||
get { return Widget.Title; }
|
||||
set { Widget.Title = value; }
|
||||
}
|
||||
|
||||
public Gtk.VBox MainBox {
|
||||
get { return mainBox; }
|
||||
}
|
||||
|
||||
public void SetChild (IWidgetBackend child)
|
||||
{
|
||||
var w = (IGtkWidgetBackend) child;
|
||||
alignment.Child = w.Widget;
|
||||
}
|
||||
|
||||
public void SetMainMenu (IMenuBackend menu)
|
||||
{
|
||||
if (mainMenu != null)
|
||||
mainBox.Remove (mainMenu);
|
||||
|
||||
MenuBackend m = (MenuBackend) menu;
|
||||
mainMenu = m.MenuBar;
|
||||
mainBox.PackStart (mainMenu, false, false, 0);
|
||||
((Gtk.Box.BoxChild)mainBox[mainMenu]).Position = 0;
|
||||
}
|
||||
|
||||
#region IWindowBackend implementation
|
||||
|
||||
public void EnableEvent (WindowEvent ev)
|
||||
{
|
||||
switch (ev) {
|
||||
case WindowEvent.BoundsChanged:
|
||||
Widget.SizeAllocated += HandleWidgetSizeAllocated; break;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWidgetSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
|
||||
{
|
||||
EventSink.OnBoundsChanged (new Rectangle (args.Allocation.X, args.Allocation.Y, args.Allocation.Width, args.Allocation.Height));
|
||||
}
|
||||
|
||||
public void DisableEvent (WindowEvent ev)
|
||||
{
|
||||
switch (ev) {
|
||||
case WindowEvent.BoundsChanged:
|
||||
Widget.SizeAllocated -= HandleWidgetSizeAllocated; break;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle Bounds {
|
||||
get {
|
||||
int w, h, x, y;
|
||||
Widget.GetPosition (out x, out y);
|
||||
Widget.GetSize (out w, out h);
|
||||
return new Rectangle (x, y, w, h);
|
||||
}
|
||||
set {
|
||||
Widget.Move ((int)value.X, (int)value.Y);
|
||||
Widget.Resize ((int)value.Width, (int)value.Height);
|
||||
Widget.SetDefaultSize ((int)value.Width, (int)value.Height);
|
||||
EventSink.OnBoundsChanged (Bounds);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateLayout ()
|
||||
{
|
||||
alignment.LeftPadding = (uint) Frontend.Margin.Left;
|
||||
alignment.RightPadding = (uint) Frontend.Margin.Right;
|
||||
alignment.TopPadding = (uint) Frontend.Margin.Top;
|
||||
alignment.BottomPadding = (uint) Frontend.Margin.Bottom;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("Xwt.Mac")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("Xamarin, Inc (http://www.xamarin.com)")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// CellUtil.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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;
|
||||
using System.Linq;
|
||||
using MonoMac.AppKit;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
static class CellUtil
|
||||
{
|
||||
public static NSCell CreateCell (ICellSource source, ICollection<CellView> cells)
|
||||
{
|
||||
// if (cells.Count > 1) {
|
||||
CompositeCell c = new CompositeCell (Orientation.Horizontal, source);
|
||||
foreach (var cell in cells)
|
||||
c.AddCell ((ICellRenderer) CreateCell (source, cell));
|
||||
return c;
|
||||
// } else
|
||||
// return CreateCell (source, cells.First ());
|
||||
}
|
||||
|
||||
public static NSCell CreateCell (ICellSource source, CellView cell)
|
||||
{
|
||||
if (cell is TextCellView)
|
||||
return new TextTableCell ((TextCellView) cell);
|
||||
if (cell is ImageCellView)
|
||||
return new ImageTableCell ((ImageCellView) cell);
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,221 @@
|
|||
//
|
||||
// CompositeCell.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
class CompositeCell: NSCell
|
||||
{
|
||||
ICellSource source;
|
||||
NSObject val;
|
||||
List<ICellRenderer> cells = new List<ICellRenderer> ();
|
||||
Orientation direction;
|
||||
|
||||
public CompositeCell (Orientation dir, ICellSource source)
|
||||
{
|
||||
direction = dir;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public CompositeCell (IntPtr p): base (p)
|
||||
{
|
||||
}
|
||||
|
||||
public override NSObject ObjectValue {
|
||||
get {
|
||||
return val;
|
||||
}
|
||||
set {
|
||||
val = value;
|
||||
if (val is ITablePosition)
|
||||
Fill (((ITablePosition)val).Position);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCell (ICellRenderer cell)
|
||||
{
|
||||
cells.Add (cell);
|
||||
}
|
||||
|
||||
public void Fill (object pos)
|
||||
{
|
||||
if (source == null || pos == null)
|
||||
return;
|
||||
var s = CellSize;
|
||||
if (s.Height > source.RowHeight)
|
||||
source.RowHeight = s.Height;
|
||||
foreach (var c in cells)
|
||||
c.Fill (source, pos);
|
||||
}
|
||||
|
||||
public override void CalcDrawInfo (RectangleF aRect)
|
||||
{
|
||||
base.CalcDrawInfo (aRect);
|
||||
}
|
||||
|
||||
public override SizeF CellSizeForBounds (RectangleF bounds)
|
||||
{
|
||||
return base.CellSizeForBounds (bounds);
|
||||
}
|
||||
|
||||
public override SizeF CellSize {
|
||||
get {
|
||||
float w = 0;
|
||||
float h = 0;
|
||||
foreach (NSCell c in cells) {
|
||||
var s = c.CellSize;
|
||||
if (direction == Orientation.Horizontal) {
|
||||
w += s.Width;
|
||||
if (s.Height > h)
|
||||
h = s.Height;
|
||||
} else {
|
||||
h += s.Height;
|
||||
if (s.Width > w)
|
||||
w = s.Width;
|
||||
}
|
||||
}
|
||||
return new SizeF (w, h);
|
||||
}
|
||||
}
|
||||
|
||||
public override RectangleF DrawingRectForBounds (RectangleF theRect)
|
||||
{
|
||||
return base.DrawingRectForBounds (theRect);
|
||||
}
|
||||
|
||||
public override NSCellStateValue State {
|
||||
get {
|
||||
return base.State;
|
||||
}
|
||||
set {
|
||||
base.State = value;
|
||||
foreach (NSCell c in cells)
|
||||
c.State = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Highlighted {
|
||||
get {
|
||||
return base.Highlighted;
|
||||
}
|
||||
set {
|
||||
base.Highlighted = value;
|
||||
foreach (NSCell c in cells)
|
||||
c.Highlighted = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawWithFrame (RectangleF cellFrame, NSView inView)
|
||||
{
|
||||
foreach (CellPos cp in GetCells(cellFrame)) {
|
||||
cp.Cell.DrawWithFrame (cp.Frame, inView);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Highlight (bool flag, RectangleF withFrame, NSView inView)
|
||||
{
|
||||
foreach (CellPos cp in GetCells(withFrame)) {
|
||||
cp.Cell.Highlight (flag, cp.Frame, inView);
|
||||
}
|
||||
}
|
||||
|
||||
public override NSCellHit HitTest (NSEvent forEvent, RectangleF inRect, NSView ofView)
|
||||
{
|
||||
foreach (CellPos cp in GetCells(inRect)) {
|
||||
var h = cp.Cell.HitTest (forEvent, cp.Frame, ofView);
|
||||
if (h != NSCellHit.None)
|
||||
return h;
|
||||
}
|
||||
return NSCellHit.None;
|
||||
}
|
||||
|
||||
NSCell trackingCell;
|
||||
|
||||
public override bool StartTracking (PointF startPoint, NSView inView)
|
||||
{
|
||||
foreach (NSCell c in cells) {
|
||||
if (c.StartTracking (startPoint, inView)) {
|
||||
trackingCell = c;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void StopTracking (PointF lastPoint, PointF stopPoint, NSView inView, bool mouseIsUp)
|
||||
{
|
||||
if (trackingCell != null) {
|
||||
try {
|
||||
trackingCell.StopTracking (lastPoint, stopPoint, inView, mouseIsUp);
|
||||
} finally {
|
||||
trackingCell = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ContinueTracking (PointF lastPoint, PointF currentPoint, NSView inView)
|
||||
{
|
||||
if (trackingCell != null)
|
||||
return trackingCell.ContinueTracking (lastPoint, currentPoint, inView);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IEnumerable<CellPos> GetCells (RectangleF cellFrame)
|
||||
{
|
||||
if (direction == Orientation.Horizontal) {
|
||||
float x = cellFrame.X;
|
||||
foreach (NSCell c in cells) {
|
||||
var s = c.CellSize;
|
||||
RectangleF f = new RectangleF (x, cellFrame.Y, s.Width, s.Height);
|
||||
x += s.Width;
|
||||
yield return new CellPos () { Cell = c, Frame = f };
|
||||
}
|
||||
} else {
|
||||
float y = cellFrame.Y;
|
||||
foreach (NSCell c in cells) {
|
||||
var s = c.CellSize;
|
||||
RectangleF f = new RectangleF (cellFrame.X, y, s.Width, s.Height);
|
||||
y += s.Height;
|
||||
yield return new CellPos () { Cell = c, Frame = f };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CellPos
|
||||
{
|
||||
public NSCell Cell;
|
||||
public RectangleF Frame;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// ICellRenderer.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
interface ICellRenderer
|
||||
{
|
||||
void Fill (ICellSource source, object pos);
|
||||
}
|
||||
|
||||
interface ITablePosition
|
||||
{
|
||||
object Position { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// ICellSource.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
interface ICellSource
|
||||
{
|
||||
object GetValue (object pos, int nField);
|
||||
float RowHeight { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// ImageTableCell.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Engine;
|
||||
using Xwt.Drawing;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
class ImageTableCell: NSImageCell, ICellRenderer
|
||||
{
|
||||
ImageCellView cellView;
|
||||
|
||||
public ImageTableCell (IntPtr p): base (p)
|
||||
{
|
||||
}
|
||||
|
||||
public ImageTableCell (ImageCellView cellView)
|
||||
{
|
||||
this.cellView = cellView;
|
||||
}
|
||||
|
||||
public void Fill (ICellSource source, object pos)
|
||||
{
|
||||
Image img = (Image) source.GetValue (pos, cellView.ImageField.Index);
|
||||
if (img != null)
|
||||
ObjectValue = (NSImage) WidgetRegistry.GetBackend (img);
|
||||
}
|
||||
|
||||
public override System.Drawing.SizeF CellSize {
|
||||
get {
|
||||
NSImage img = ObjectValue as NSImage;
|
||||
if (img != null)
|
||||
return img.Size;
|
||||
else
|
||||
return base.CellSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// TextTableCell.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
class TextTableCell: NSTextFieldCell, ICellRenderer
|
||||
{
|
||||
TextCellView cellView;
|
||||
|
||||
public TextTableCell (IntPtr p): base (p)
|
||||
{
|
||||
}
|
||||
|
||||
public TextTableCell (TextCellView cellView)
|
||||
{
|
||||
this.cellView = cellView;
|
||||
}
|
||||
|
||||
public void Fill (ICellSource source, object pos)
|
||||
{
|
||||
StringValue = (string) source.GetValue (pos, cellView.TextField.Index) ?? "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{B7C1673E-5124-4BE5-8D21-EC8B12F85B6B}</ProjectGuid>
|
||||
<ProjectTypeGuids>{948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Xwt.Mac</RootNamespace>
|
||||
<AssemblyName>Xwt.Mac</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="MonoMac">
|
||||
</Reference>
|
||||
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Xwt.Mac\BoxBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\ButtonBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\LabelBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\MacEngine.cs" />
|
||||
<Compile Include="Xwt.Mac\NotebookBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\TreeViewBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\Util.cs" />
|
||||
<Compile Include="Xwt.Mac\ViewBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\WindowBackend.cs" />
|
||||
<Compile Include="Xwt.Mac.CellViews\CompositeCell.cs" />
|
||||
<Compile Include="Xwt.Mac.CellViews\ICellRenderer.cs" />
|
||||
<Compile Include="Xwt.Mac.CellViews\ICellSource.cs" />
|
||||
<Compile Include="Xwt.Mac.CellViews\TextTableCell.cs" />
|
||||
<Compile Include="Xwt.Mac.CellViews\CellUtil.cs" />
|
||||
<Compile Include="Xwt.Mac\ImageHandler.cs" />
|
||||
<Compile Include="Xwt.Mac.CellViews\ImageTableCell.cs" />
|
||||
<Compile Include="Xwt.Mac\ContextBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Mac\CanvasBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\GradientBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Mac\TextLayoutBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Mac\FontBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Mac\ListViewBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\TableViewBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\MenuBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\MenuItemBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\ObjcHelper.cs" />
|
||||
<Compile Include="Xwt.Mac\IViewObject.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Xwt\Xwt.csproj">
|
||||
<Project>{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}</Project>
|
||||
<Name>Xwt</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Xwt.Mac\" />
|
||||
<Folder Include="Xwt.Mac.CellViews\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// BoxBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class BoxBackend: ViewBackend<NSView,IWidgetEventSink>, IBoxBackend
|
||||
{
|
||||
public BoxBackend ()
|
||||
{
|
||||
ViewObject = new BoxView ();
|
||||
}
|
||||
|
||||
public void Add (IWidgetBackend widget)
|
||||
{
|
||||
IMacViewBackend b = (IMacViewBackend) widget;
|
||||
Widget.AddSubview (b.View);
|
||||
}
|
||||
|
||||
public void Remove (IWidgetBackend widget)
|
||||
{
|
||||
var w = GetWidget (widget);
|
||||
if (w.Superview != Widget)
|
||||
throw new InvalidOperationException ("Widget is not a child of this container");
|
||||
w.RemoveFromSuperview ();
|
||||
}
|
||||
|
||||
public void SetAllocation (IWidgetBackend widget, Rectangle rect)
|
||||
{
|
||||
var w = GetWidget (widget);
|
||||
w.SetWidgetBounds (rect);
|
||||
w.NeedsDisplay = true;
|
||||
}
|
||||
}
|
||||
|
||||
class BoxView: NSView, IViewObject<NSView>
|
||||
{
|
||||
public Widget Frontend { get; set; }
|
||||
public NSView View {
|
||||
get { return this; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
//
|
||||
// ButtonBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class ButtonBackend: ViewBackend<NSButton,IButtonEventSink>, IButtonBackend
|
||||
{
|
||||
public ButtonBackend ()
|
||||
{
|
||||
}
|
||||
|
||||
#region IButtonBackend implementation
|
||||
public override void Initialize ()
|
||||
{
|
||||
ViewObject = new Button (EventSink);
|
||||
Widget.SizeToFit ();
|
||||
}
|
||||
|
||||
public void EnableEvent (Xwt.Backends.ButtonEvent ev)
|
||||
{
|
||||
((Button)Widget).EnableEvent (ev);
|
||||
}
|
||||
|
||||
public void DisableEvent (Xwt.Backends.ButtonEvent ev)
|
||||
{
|
||||
((Button)Widget).DisableEvent (ev);
|
||||
}
|
||||
|
||||
public string Label {
|
||||
get {
|
||||
return Widget.StringValue;
|
||||
}
|
||||
set {
|
||||
Widget.StringValue = value;
|
||||
Widget.SizeToFit ();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
class Button: NSButton, IViewObject<NSButton>
|
||||
{
|
||||
public Button (IntPtr p): base (p)
|
||||
{
|
||||
Console.WriteLine ("NSBUTTON CREATED");
|
||||
}
|
||||
|
||||
public Button (IButtonEventSink eventSink)
|
||||
{
|
||||
BezelStyle = NSBezelStyle.Rounded;
|
||||
Activated += delegate {
|
||||
eventSink.OnClicked ();
|
||||
};
|
||||
}
|
||||
|
||||
public Widget Frontend { get; set; }
|
||||
|
||||
public NSButton View {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public void EnableEvent (Xwt.Backends.ButtonEvent ev)
|
||||
{
|
||||
}
|
||||
|
||||
public void DisableEvent (Xwt.Backends.ButtonEvent ev)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
//
|
||||
// CanvasBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class CanvasBackend: ViewBackend<NSView,ICanvasEventSink>, ICanvasBackend
|
||||
{
|
||||
CanvasView view;
|
||||
|
||||
public CanvasBackend ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Initialize ()
|
||||
{
|
||||
view = new CanvasView (EventSink);
|
||||
ViewObject = view;
|
||||
}
|
||||
|
||||
public Rectangle Bounds {
|
||||
get {
|
||||
return new Rectangle (0, 0, view.Frame.Width, view.Frame.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public void QueueDraw ()
|
||||
{
|
||||
view.NeedsDisplay = true;
|
||||
}
|
||||
}
|
||||
|
||||
class CanvasView: NSView, IViewObject<NSView>
|
||||
{
|
||||
ICanvasEventSink eventSink;
|
||||
|
||||
public CanvasView (ICanvasEventSink eventSink)
|
||||
{
|
||||
this.eventSink = eventSink;
|
||||
}
|
||||
|
||||
public Widget Frontend { get; set; }
|
||||
|
||||
public NSView View {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public override bool IsFlipped {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawRect (System.Drawing.RectangleF dirtyRect)
|
||||
{
|
||||
eventSink.OnDraw (null);
|
||||
}
|
||||
|
||||
public override void MouseDown (NSEvent theEvent)
|
||||
{
|
||||
var p = ConvertPointFromView (theEvent.LocationInWindow, null);
|
||||
ButtonEventArgs args = new ButtonEventArgs ();
|
||||
args.X = p.X;
|
||||
args.Y = p.Y;
|
||||
args.Button = theEvent.ButtonNumber + 1;
|
||||
eventSink.OnButtonPressed (args);
|
||||
}
|
||||
|
||||
public override void MouseUp (NSEvent theEvent)
|
||||
{
|
||||
var p = ConvertPointFromView (theEvent.LocationInWindow, null);
|
||||
ButtonEventArgs args = new ButtonEventArgs ();
|
||||
args.X = p.X;
|
||||
args.Y = p.Y;
|
||||
args.Button = theEvent.ButtonNumber + 1;
|
||||
eventSink.OnButtonReleased (args);
|
||||
}
|
||||
|
||||
public override void MouseMoved (NSEvent theEvent)
|
||||
{
|
||||
var p = ConvertPointFromView (theEvent.LocationInWindow, null);
|
||||
MouseMovedEventArgs args = new MouseMovedEventArgs ();
|
||||
args.X = p.X;
|
||||
args.Y = p.Y;
|
||||
eventSink.OnMouseMoved (args);
|
||||
}
|
||||
|
||||
public override void MouseDragged (NSEvent theEvent)
|
||||
{
|
||||
var p = ConvertPointFromView (theEvent.LocationInWindow, null);
|
||||
MouseMovedEventArgs args = new MouseMovedEventArgs ();
|
||||
args.X = p.X;
|
||||
args.Y = p.Y;
|
||||
eventSink.OnMouseMoved (args);
|
||||
}
|
||||
|
||||
public override void SetFrameSize (System.Drawing.SizeF newSize)
|
||||
{
|
||||
base.SetFrameSize (newSize);
|
||||
eventSink.OnBoundsChanged ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
//
|
||||
// ContextBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Engine;
|
||||
using MonoMac.AppKit;
|
||||
using Xwt.Drawing;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class ContextBackendHandler: IContextBackendHandler
|
||||
{
|
||||
public ContextBackendHandler ()
|
||||
{
|
||||
}
|
||||
|
||||
public class ContextInfo
|
||||
{
|
||||
public NSBezierPath Path;
|
||||
public Pattern Pattern;
|
||||
}
|
||||
|
||||
public object CreateContext (Widget w)
|
||||
{
|
||||
ContextInfo c = new ContextInfo ();
|
||||
c.Path = new NSBezierPath ();
|
||||
return c;
|
||||
}
|
||||
|
||||
public void Arc (object backend, double xc, double yc, double radius, double angle1, double angle2)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.AppendPathWithArc (new System.Drawing.PointF ((float)xc, (float)yc), (float)radius, (float)angle1, (float)angle2);
|
||||
}
|
||||
|
||||
public void Clip (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.AddClip ();
|
||||
ctx.Path.Dispose ();
|
||||
ctx.Path = new NSBezierPath ();
|
||||
}
|
||||
|
||||
public void ClipPreserve (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.AddClip ();
|
||||
}
|
||||
|
||||
public void ResetClip (object backend)
|
||||
{
|
||||
var path = new NSBezierPath ();
|
||||
path.AppendPathWithRect (new System.Drawing.RectangleF (0, 0, float.MaxValue, float.MaxValue));
|
||||
path.SetClip ();
|
||||
}
|
||||
|
||||
public void ClosePath (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.ClosePath ();
|
||||
}
|
||||
|
||||
public void CurveTo (object backend, double x1, double y1, double x2, double y2, double x3, double y3)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.CurveTo (new System.Drawing.PointF ((float)x1, (float)y1),
|
||||
new System.Drawing.PointF ((float)x2, (float)y2),
|
||||
new System.Drawing.PointF ((float)x3, (float)y3));
|
||||
}
|
||||
|
||||
public void Fill (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
if (ctx.Pattern is Gradient) {
|
||||
GradientInfo gr = (GradientInfo) WidgetRegistry.GetBackend (ctx.Pattern);
|
||||
NSGradient g = new NSGradient (gr.Colors.ToArray (), gr.Stops.ToArray ());
|
||||
g.DrawInBezierPath (ctx.Path, 0f);
|
||||
}
|
||||
else {
|
||||
ctx.Path.Fill ();
|
||||
}
|
||||
ctx.Pattern = null;
|
||||
ctx.Path.Dispose ();
|
||||
ctx.Path = new NSBezierPath ();
|
||||
}
|
||||
|
||||
public void FillPreserve (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
NSGraphicsContext.CurrentContext.SaveGraphicsState ();
|
||||
ctx.Path.Fill ();
|
||||
NSGraphicsContext.CurrentContext.RestoreGraphicsState ();
|
||||
}
|
||||
|
||||
public void LineTo (object backend, double x, double y)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.LineTo (new System.Drawing.PointF ((float)x, (float)y));
|
||||
}
|
||||
|
||||
public void MoveTo (object backend, double x, double y)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.MoveTo (new System.Drawing.PointF ((float)x, (float)y));
|
||||
}
|
||||
|
||||
public void NewPath (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path = new NSBezierPath ();
|
||||
}
|
||||
|
||||
public void Rectangle (object backend, double x, double y, double width, double height)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.AppendPathWithRect (new System.Drawing.RectangleF ((float)x, (float)y, (float)width, (float)height));
|
||||
}
|
||||
|
||||
public void RelCurveTo (object backend, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.RelativeCurveTo (new System.Drawing.PointF ((float)dx1, (float)dy1),
|
||||
new System.Drawing.PointF ((float)dx2, (float)dy2),
|
||||
new System.Drawing.PointF ((float)dx3, (float)dy3));
|
||||
}
|
||||
|
||||
public void RelLineTo (object backend, double dx, double dy)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.RelativeLineTo (new System.Drawing.PointF ((float)dx, (float)dy));
|
||||
}
|
||||
|
||||
public void RelMoveTo (object backend, double dx, double dy)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.RelativeMoveTo (new System.Drawing.PointF ((float)dx, (float)dy));
|
||||
}
|
||||
|
||||
public void Stroke (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.Stroke ();
|
||||
ctx.Path.Dispose ();
|
||||
ctx.Path = new NSBezierPath ();
|
||||
}
|
||||
|
||||
public void StrokePreserve (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.Stroke ();
|
||||
}
|
||||
|
||||
public void SetColor (object backend, Xwt.Drawing.Color color)
|
||||
{
|
||||
NSColor col = NSColor.FromDeviceRgba ((float)color.Red, (float)color.Green, (float)color.Blue, (float)color.Alpha);
|
||||
col.Set ();
|
||||
col.SetFill ();
|
||||
}
|
||||
|
||||
public void SetLineWidth (object backend, double width)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.LineWidth = (float) width;
|
||||
}
|
||||
|
||||
public void SetPattern (object backend, Pattern p)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Pattern = p;
|
||||
}
|
||||
|
||||
public void SetFont (object backend, Font font)
|
||||
{
|
||||
}
|
||||
|
||||
public void DrawTextLayout (object backend, TextLayout layout, double x, double y)
|
||||
{
|
||||
TextLayoutBackendHandler.Draw (null, WidgetRegistry.GetBackend (layout), x, y);
|
||||
}
|
||||
|
||||
public void DrawImage (object backend, Xwt.Drawing.Image img, double x, double y)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public void Dispose (object backend)
|
||||
{
|
||||
ContextInfo ctx = (ContextInfo) backend;
|
||||
ctx.Path.Dispose ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// FontBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class FontBackendHandler: IFontBackendHandler
|
||||
{
|
||||
public object CreateFromName (string fontName, double size)
|
||||
{
|
||||
object o = NSFont.FromFontName (fontName, (float)size);
|
||||
if (o == null)
|
||||
Console.WriteLine ("kk");
|
||||
return o;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// GradientBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Drawing;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class GradientBackendHandler: IGradientBackendHandler
|
||||
{
|
||||
public object CreateLinear (double x0, double y0, double x1, double y1)
|
||||
{
|
||||
return new GradientInfo () { Linear = true, Start = new Point (x0, y0), End = new Point (x1, y1) };
|
||||
}
|
||||
|
||||
public void AddColorStop (object backend, double position, Xwt.Drawing.Color color)
|
||||
{
|
||||
GradientInfo gr = (GradientInfo) backend;
|
||||
gr.Colors.Add (color.ToNSColor ());
|
||||
gr.Stops.Add ((float) position);
|
||||
}
|
||||
}
|
||||
|
||||
class GradientInfo
|
||||
{
|
||||
public bool Linear;
|
||||
public Point Start;
|
||||
public Point End;
|
||||
public List<NSColor> Colors = new List<NSColor> ();
|
||||
public List<float> Stops = new List<float> ();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// IViewObject.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Mac
|
||||
{
|
||||
public interface IViewObject<T>
|
||||
{
|
||||
T View { get; }
|
||||
Widget Frontend { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// ImageHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class ImageHandler: ImageBackendHandler
|
||||
{
|
||||
public override object LoadFromStream (System.IO.Stream stream)
|
||||
{
|
||||
using (NSData data = NSData.FromStream (stream)) {
|
||||
return new NSImage (data);
|
||||
}
|
||||
}
|
||||
|
||||
public override object LoadFromFile (string file)
|
||||
{
|
||||
return new NSImage (file);
|
||||
}
|
||||
|
||||
public override Size GetSize (object handle)
|
||||
{
|
||||
NSImage img = (NSImage) handle;
|
||||
return new Size ((int)img.Size.Width, (int)img.Size.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
//
|
||||
// LabelBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class LabelBackend: ViewBackend<NSTextField,IWidgetEventSink>, ILabelBackend
|
||||
{
|
||||
public LabelBackend ()
|
||||
{
|
||||
ViewObject = new TextFieldView ();
|
||||
Widget.Editable = false;
|
||||
Widget.Bezeled = false;
|
||||
Widget.DrawsBackground = false;
|
||||
Widget.SizeToFit ();
|
||||
}
|
||||
|
||||
public string Text {
|
||||
get {
|
||||
return Widget.StringValue;
|
||||
}
|
||||
set {
|
||||
Widget.StringValue = value;
|
||||
Widget.SizeToFit ();
|
||||
}
|
||||
}
|
||||
|
||||
public Alignment HorizontalAlignment {
|
||||
get {
|
||||
switch (Widget.Alignment) {
|
||||
case NSTextAlignment.Left: return Alignment.Start;
|
||||
case NSTextAlignment.Center: return Alignment.Center;
|
||||
case NSTextAlignment.Right: return Alignment.End;
|
||||
}
|
||||
return Alignment.Start;
|
||||
}
|
||||
set {
|
||||
switch (value) {
|
||||
case Alignment.Start: Widget.Alignment = NSTextAlignment.Left; break;
|
||||
case Alignment.Center: Widget.Alignment = NSTextAlignment.Center; break;
|
||||
case Alignment.End: Widget.Alignment = NSTextAlignment.Right; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TextFieldView: NSTextField, IViewObject<NSTextField>
|
||||
{
|
||||
public Widget Frontend { get; set; }
|
||||
public NSTextField View {
|
||||
get { return this; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
//
|
||||
// ListViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
using MonoMac.Foundation;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class ListViewBackend: TableViewBackend<NSTableView,IListViewEventSink>, IListViewBackend
|
||||
{
|
||||
IListViewSource source;
|
||||
ListSource tsource;
|
||||
|
||||
protected override NSTableView CreateView ()
|
||||
{
|
||||
return new NSTableView ();
|
||||
}
|
||||
|
||||
protected override string SelectionChangeEventName {
|
||||
get { return "NSTableViewSelectionDidChangeNotification"; }
|
||||
}
|
||||
|
||||
public void SetSource (IListViewSource source, IBackend sourceBackend)
|
||||
{
|
||||
this.source = source;
|
||||
tsource = new ListSource (source);
|
||||
Table.DataSource = tsource;
|
||||
}
|
||||
|
||||
public int[] SelectedRows {
|
||||
get {
|
||||
int[] sel = new int [Table.SelectedRowCount];
|
||||
int i = 0;
|
||||
foreach (int r in Table.SelectedRows)
|
||||
sel [i++] = r;
|
||||
return sel;
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectRow (int pos)
|
||||
{
|
||||
Table.SelectRow (pos, false);
|
||||
}
|
||||
|
||||
public void UnselectRow (int pos)
|
||||
{
|
||||
Table.DeselectRow (pos);
|
||||
}
|
||||
|
||||
public override object GetValue (object pos, int nField)
|
||||
{
|
||||
return source.GetValue ((int)pos, nField);
|
||||
}
|
||||
}
|
||||
|
||||
class TableRow: NSObject, ITablePosition
|
||||
{
|
||||
public int Row;
|
||||
|
||||
public object Position {
|
||||
get { return Row; }
|
||||
}
|
||||
}
|
||||
|
||||
class ListSource: NSTableViewDataSource
|
||||
{
|
||||
IListViewSource source;
|
||||
|
||||
public ListSource (IListViewSource source)
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public override bool AcceptDrop (NSTableView tableView, NSDraggingInfo info, int row, NSTableViewDropOperation dropOperation)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string[] FilesDropped (NSTableView tableView, MonoMac.Foundation.NSUrl dropDestination, MonoMac.Foundation.NSIndexSet indexSet)
|
||||
{
|
||||
return new string [0];
|
||||
}
|
||||
|
||||
public override MonoMac.Foundation.NSObject GetObjectValue (NSTableView tableView, NSTableColumn tableColumn, int row)
|
||||
{
|
||||
return new TableRow () { Row = row };
|
||||
}
|
||||
|
||||
public override int GetRowCount (NSTableView tableView)
|
||||
{
|
||||
return source.RowCount;
|
||||
}
|
||||
|
||||
public override void SetObjectValue (NSTableView tableView, MonoMac.Foundation.NSObject theObject, NSTableColumn tableColumn, int row)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SortDescriptorsChanged (NSTableView tableView, MonoMac.Foundation.NSSortDescriptor[] oldDescriptors)
|
||||
{
|
||||
}
|
||||
|
||||
public override NSDragOperation ValidateDrop (NSTableView tableView, NSDraggingInfo info, int row, NSTableViewDropOperation dropOperation)
|
||||
{
|
||||
return NSDragOperation.None;
|
||||
}
|
||||
|
||||
public override bool WriteRows (NSTableView tableView, MonoMac.Foundation.NSIndexSet rowIndexes, NSPasteboard pboard)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
//
|
||||
// MacEngine.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Engine;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
using MonoMac.ObjCRuntime;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
class MacEngine: Xwt.Backends.EngineBackend
|
||||
{
|
||||
static AppDelegate appDelegate = new AppDelegate ();
|
||||
static NSAutoreleasePool pool;
|
||||
|
||||
public static AppDelegate App {
|
||||
get { return appDelegate; }
|
||||
}
|
||||
|
||||
public override void InitializeApplication ()
|
||||
{
|
||||
NSApplication.Init ();
|
||||
Hijack ();
|
||||
pool = new NSAutoreleasePool ();
|
||||
NSApplication.SharedApplication.Delegate = appDelegate;
|
||||
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Window), typeof(WindowBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Label), typeof(LabelBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.HBox), typeof(BoxBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.VBox), typeof(BoxBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Button), typeof(ButtonBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Notebook), typeof(NotebookBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.TreeView), typeof(TreeViewBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.ListView), typeof(ListViewBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Canvas), typeof(CanvasBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Image), typeof(ImageHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Context), typeof(ContextBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Gradient), typeof(GradientBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.TextLayout), typeof(TextLayoutBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Font), typeof(FontBackendHandler));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.Menu), typeof(MenuBackend));
|
||||
WidgetRegistry.RegisterBackend (typeof(Xwt.MenuItem), typeof(MenuItemBackend));
|
||||
}
|
||||
|
||||
public override void RunApplication ()
|
||||
{
|
||||
pool.Dispose ();
|
||||
NSApplication.Main (new string [0]);
|
||||
pool = new NSAutoreleasePool ();
|
||||
}
|
||||
|
||||
public static void ReplaceChild (NSView cont, NSView oldView, NSView newView)
|
||||
{
|
||||
if (cont is IViewContainer) {
|
||||
((IViewContainer)cont).ReplaceChild (oldView, newView);
|
||||
}
|
||||
else if (cont is NSView) {
|
||||
newView.Frame = oldView.Frame;
|
||||
oldView.RemoveFromSuperview ();
|
||||
newView.AddSubview (newView);
|
||||
}
|
||||
}
|
||||
|
||||
static Selector hijackedSel = new Selector ("hijacked_loadNibNamed:owner:");
|
||||
static Selector originalSel = new Selector ("loadNibNamed:owner:");
|
||||
|
||||
static void Hijack ()
|
||||
{
|
||||
Class c = ObjcHelper.GetMetaClass ("NSBundle");
|
||||
if (!c.AddMethod (hijackedSel.Handle, new Func<IntPtr, IntPtr, IntPtr, IntPtr,bool>(HijackedLoadNibNamed), "B@:@@"))
|
||||
throw new Exception ("Failed to add method");
|
||||
c.MethodExchange (originalSel.Handle, hijackedSel.Handle);
|
||||
}
|
||||
|
||||
static bool HijackedLoadNibNamed (IntPtr self, IntPtr sel, IntPtr filePath, IntPtr owner)
|
||||
{
|
||||
var str = new NSString (filePath);
|
||||
if (str.Length == 0)
|
||||
return true;
|
||||
return Messaging.bool_objc_msgSend_IntPtr_IntPtr (self, hijackedSel.Handle, filePath, owner);
|
||||
}
|
||||
|
||||
public override void Invoke (Action action)
|
||||
{
|
||||
NSApplication.SharedApplication.BeginInvokeOnMainThread (delegate {
|
||||
action ();
|
||||
});
|
||||
}
|
||||
|
||||
public override object TimeoutInvoke (Func<bool> action, TimeSpan timeSpan)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public override void CancelTimeoutInvoke (object id)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IViewContainer
|
||||
{
|
||||
void ReplaceChild (NSView oldView, NSView newView);
|
||||
}
|
||||
|
||||
public class AppDelegate : NSApplicationDelegate
|
||||
{
|
||||
bool launched;
|
||||
List<WindowBackend> pendingWindows = new List<WindowBackend> ();
|
||||
|
||||
public AppDelegate ()
|
||||
{
|
||||
}
|
||||
|
||||
internal void ShowWindow (WindowBackend w)
|
||||
{
|
||||
if (!launched)
|
||||
pendingWindows.Add (w);
|
||||
else
|
||||
w.InternalShow ();
|
||||
}
|
||||
|
||||
public override void FinishedLaunching (NSObject notification)
|
||||
{
|
||||
launched = true;
|
||||
foreach (var w in pendingWindows)
|
||||
w.InternalShow ();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// MenuBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class MenuBackend: NSMenu, IMenuBackend
|
||||
{
|
||||
public void InsertItem (int index, IMenuItemBackend menuItem)
|
||||
{
|
||||
InsertItematIndex ((NSMenuItem)menuItem, index);
|
||||
}
|
||||
|
||||
public void RemoveItem (IMenuItemBackend menuItem)
|
||||
{
|
||||
RemoveItem ((NSMenuItem)menuItem);
|
||||
}
|
||||
|
||||
public void Initialize (object frontend)
|
||||
{
|
||||
}
|
||||
|
||||
public void EnableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
|
||||
public void DisableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// MenuItemBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class MenuItemBackend: NSMenuItem, IMenuItemBackend
|
||||
{
|
||||
public void Initialize (IMenuItemEventSink eventSink)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetSubmenu (IMenuBackend menu)
|
||||
{
|
||||
if (menu == null)
|
||||
Submenu = null;
|
||||
else
|
||||
Submenu = ((MenuBackend)menu);
|
||||
}
|
||||
|
||||
public string Label {
|
||||
get {
|
||||
return Title;
|
||||
}
|
||||
set {
|
||||
Title = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region IBackend implementation
|
||||
public void Initialize (object frontend)
|
||||
{
|
||||
}
|
||||
|
||||
public void EnableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
|
||||
public void DisableEvent (object eventId)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
//
|
||||
// NotebookBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class NotebookBackend: ViewBackend<NSTabView,IWidgetEventSink>, INotebookBackend
|
||||
{
|
||||
public NotebookBackend ()
|
||||
{
|
||||
ViewObject = new TabView ();
|
||||
Widget.AutoresizesSubviews = true;
|
||||
}
|
||||
|
||||
#region INotebookBackend implementation
|
||||
public void Add (IWidgetBackend widget, NotebookTab tab)
|
||||
{
|
||||
NSTabViewItem item = new NSTabViewItem ();
|
||||
item.Label = tab.Label;
|
||||
item.View = GetWidget (widget);
|
||||
Widget.Add (item);
|
||||
}
|
||||
|
||||
public void Remove (IWidgetBackend widget)
|
||||
{
|
||||
var v = GetWidget (widget);
|
||||
foreach (var t in Widget.Items) {
|
||||
if (t.View == v) {
|
||||
Widget.Remove (t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
class TabView: NSTabView, IViewObject<NSTabView>
|
||||
{
|
||||
public Widget Frontend { get; set; }
|
||||
public NSTabView View {
|
||||
get { return this; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
//
|
||||
// ObjcHelper.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.ObjCRuntime;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public static class ObjcHelper
|
||||
{
|
||||
[DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern bool class_addMethod (IntPtr cls, IntPtr sel, Delegate method, string argTypes);
|
||||
|
||||
[DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern IntPtr objc_getMetaClass (string name);
|
||||
|
||||
[DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern IntPtr class_getInstanceMethod (IntPtr cls, IntPtr sel);
|
||||
|
||||
[DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern IntPtr class_getClassMethod (IntPtr cls, IntPtr sel);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern bool method_exchangeImplementations (IntPtr m1, IntPtr m2);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern IntPtr method_setImplementations (IntPtr m1, Delegate impl);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern IntPtr object_getClass (IntPtr obj);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern IntPtr objc_getProtocol (string name);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern bool class_conformsToProtocol(IntPtr cls, IntPtr protocol);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport ("/usr/lib/libobjc.dylib")]
|
||||
static extern bool class_addProtocol(IntPtr cls, IntPtr protocol);
|
||||
|
||||
public static Class GetObjectClass (IntPtr obj)
|
||||
{
|
||||
return new Class (object_getClass (obj));
|
||||
}
|
||||
|
||||
public static Class GetMetaClass (string name)
|
||||
{
|
||||
return new Class (objc_getMetaClass (name));
|
||||
}
|
||||
|
||||
public static void InstanceMethodExchange (this Class cls, IntPtr sel1, IntPtr sel2)
|
||||
{
|
||||
IntPtr m1 = class_getInstanceMethod (cls.Handle, sel1);
|
||||
if (m1 == IntPtr.Zero)
|
||||
throw new Exception ("Class did not have a method for the first selector");
|
||||
IntPtr m2 = class_getInstanceMethod (cls.Handle, sel2);
|
||||
if (m2 == IntPtr.Zero)
|
||||
throw new Exception ("Class did not have a method for the second selector");
|
||||
if (!method_exchangeImplementations (m1, m2))
|
||||
throw new Exception ("Failed to exchange implementations");
|
||||
}
|
||||
|
||||
public static void MethodExchange (this Class cls, IntPtr sel1, IntPtr sel2)
|
||||
{
|
||||
IntPtr m1 = class_getClassMethod (cls.Handle, sel1);
|
||||
if (m1 == IntPtr.Zero)
|
||||
throw new Exception ("Class did not have a method for the first selector");
|
||||
IntPtr m2 = cls.GetMethod (sel2);
|
||||
if (m2 == IntPtr.Zero)
|
||||
throw new Exception ("Class did not have a method for the second selector");
|
||||
if (!method_exchangeImplementations (m1, m2))
|
||||
throw new Exception ("Failed to exchange implementations");
|
||||
}
|
||||
|
||||
public static IntPtr SetMethodImplementation (this Class cls, IntPtr method, Delegate impl)
|
||||
{
|
||||
IntPtr m1 = class_getClassMethod (cls.Handle, method);
|
||||
if (m1 == IntPtr.Zero)
|
||||
throw new Exception ("Class did not have a method for the first selector");
|
||||
return method_setImplementations (m1, impl);
|
||||
}
|
||||
|
||||
public static IntPtr GetMethod (this Class cls, IntPtr sel)
|
||||
{
|
||||
return class_getClassMethod (cls.Handle, sel);
|
||||
}
|
||||
|
||||
public static bool AddMethod (this Class cls, IntPtr sel, Delegate method, string argTypes)
|
||||
{
|
||||
return class_addMethod (cls.Handle, sel, method, argTypes);
|
||||
}
|
||||
|
||||
public static IntPtr GetProtocol (string name)
|
||||
{
|
||||
return objc_getProtocol (name);
|
||||
}
|
||||
|
||||
public static bool ConformsToProtocol(this Class cls, IntPtr protocol)
|
||||
{
|
||||
return class_conformsToProtocol (cls.Handle, protocol);
|
||||
}
|
||||
|
||||
public static bool AddProtocol(this Class cls, IntPtr protocol)
|
||||
{
|
||||
return class_addProtocol (cls.Handle, protocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
//
|
||||
// TableViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
using MonoMac.Foundation;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public abstract class TableViewBackend<T,S>: ViewBackend<NSScrollView,S>, ICellSource where T:NSTableView where S:ITableViewEventSink
|
||||
{
|
||||
List<NSTableColumn> cols = new List<NSTableColumn> ();
|
||||
protected NSTableView Table;
|
||||
ScrollView scroll;
|
||||
NSObject selChangeObserver;
|
||||
|
||||
public TableViewBackend ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Initialize ()
|
||||
{
|
||||
Table = CreateView ();
|
||||
scroll = new ScrollView ();
|
||||
scroll.DocumentView = Table;
|
||||
ViewObject = scroll;
|
||||
Table.SizeToFit ();
|
||||
Widget.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
|
||||
Widget.AutoresizesSubviews = true;
|
||||
}
|
||||
|
||||
protected abstract NSTableView CreateView ();
|
||||
protected abstract string SelectionChangeEventName { get; }
|
||||
|
||||
public override void EnableEvent (object eventId)
|
||||
{
|
||||
base.EnableEvent (eventId);
|
||||
if (eventId is TableViewEvent) {
|
||||
switch ((TableViewEvent)eventId) {
|
||||
case TableViewEvent.SelectionChanged:
|
||||
selChangeObserver = NSNotificationCenter.DefaultCenter.AddObserver (new NSString (SelectionChangeEventName), HandleTreeSelectionDidChange, Table);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void DisableEvent (object eventId)
|
||||
{
|
||||
base.DisableEvent (eventId);
|
||||
if (eventId is TableViewEvent) {
|
||||
switch ((TableViewEvent)eventId) {
|
||||
case TableViewEvent.SelectionChanged:
|
||||
if (selChangeObserver != null)
|
||||
NSNotificationCenter.DefaultCenter.RemoveObserver (selChangeObserver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleTreeSelectionDidChange (NSNotification notif)
|
||||
{
|
||||
EventSink.OnSelectionChanged ();
|
||||
}
|
||||
|
||||
public void SetSelectionMode (SelectionMode mode)
|
||||
{
|
||||
Table.AllowsMultipleSelection = mode == SelectionMode.Multiple;
|
||||
}
|
||||
|
||||
public virtual object AddColumn (ListViewColumn col)
|
||||
{
|
||||
var tcol = new NSTableColumn ();
|
||||
cols.Add (tcol);
|
||||
var c = CellUtil.CreateCell (this, col.Views);
|
||||
tcol.DataCell = c;
|
||||
Table.AddColumn (tcol);
|
||||
var hc = new NSTableHeaderCell ();
|
||||
hc.Title = col.Title;
|
||||
tcol.HeaderCell = hc;
|
||||
return tcol;
|
||||
}
|
||||
|
||||
public void RemoveColumn (ListViewColumn col, object handle)
|
||||
{
|
||||
Table.RemoveColumn ((NSTableColumn)handle);
|
||||
}
|
||||
|
||||
public void UpdateColumn (ListViewColumn col, object handle, ListViewColumnChange change)
|
||||
{
|
||||
NSTableColumn tcol = (NSTableColumn) handle;
|
||||
tcol.DataCell = CellUtil.CreateCell (this, col.Views);
|
||||
}
|
||||
|
||||
public void SelectAll ()
|
||||
{
|
||||
Table.SelectAll (null);
|
||||
}
|
||||
|
||||
public void UnselectAll ()
|
||||
{
|
||||
Table.DeselectAll (null);
|
||||
}
|
||||
|
||||
public abstract object GetValue (object pos, int nField);
|
||||
|
||||
float ICellSource.RowHeight {
|
||||
get { return Table.RowHeight; }
|
||||
set { Table.RowHeight = value; }
|
||||
}
|
||||
}
|
||||
|
||||
class ScrollView: NSScrollView, IViewObject<NSScrollView>
|
||||
{
|
||||
public Widget Frontend { get; set; }
|
||||
public NSScrollView View {
|
||||
get { return this; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// TextLayoutBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using Xwt.Engine;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class TextLayoutBackendHandler: ITextLayoutBackendHandler
|
||||
{
|
||||
class LayoutInfo
|
||||
{
|
||||
public NSAttributedString Text;
|
||||
public NSFont Font;
|
||||
public string PlainText;
|
||||
}
|
||||
|
||||
public object Create (Xwt.Drawing.Context context)
|
||||
{
|
||||
return new LayoutInfo ();
|
||||
}
|
||||
|
||||
public void SetText (object backend, string text)
|
||||
{
|
||||
LayoutInfo li = (LayoutInfo)backend;
|
||||
li.PlainText = text;
|
||||
UpdateInfo (li);
|
||||
}
|
||||
|
||||
public void SetFont (object backend, Xwt.Drawing.Font font)
|
||||
{
|
||||
LayoutInfo li = (LayoutInfo)backend;
|
||||
li.Font = (NSFont) WidgetRegistry.GetBackend (font);
|
||||
UpdateInfo (li);
|
||||
}
|
||||
|
||||
void UpdateInfo (LayoutInfo li)
|
||||
{
|
||||
if (li.PlainText == null)
|
||||
return;
|
||||
if (li.Font != null) {
|
||||
NSDictionary dict = NSDictionary.FromObjectsAndKeys (
|
||||
new object[] { li.Font },
|
||||
new object[] { NSAttributedString.FontAttributeName }
|
||||
);
|
||||
li.Text = new NSAttributedString (li.PlainText, dict);
|
||||
} else {
|
||||
li.Text = new NSAttributedString (li.PlainText);
|
||||
}
|
||||
}
|
||||
|
||||
public Size GetSize (object backend)
|
||||
{
|
||||
LayoutInfo li = (LayoutInfo)backend;
|
||||
var s = li.Text.Size;
|
||||
return new Xwt.Size (s.Width, s.Height);
|
||||
}
|
||||
|
||||
public static void Draw (object ctx, object layout, double x, double y)
|
||||
{
|
||||
LayoutInfo li = (LayoutInfo) layout;
|
||||
li.Text.DrawString (new System.Drawing.PointF ((float)x, (float)y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
//
|
||||
// TreeViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using Xwt.Backends;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class TreeViewBackend: TableViewBackend<NSOutlineView,ITreeViewEventSink>, ITreeViewBackend
|
||||
{
|
||||
ITreeViewSource source;
|
||||
TreeSource tsource;
|
||||
|
||||
NSOutlineView Tree {
|
||||
get { return (NSOutlineView) Table; }
|
||||
}
|
||||
|
||||
protected override NSTableView CreateView ()
|
||||
{
|
||||
return new NSOutlineView ();
|
||||
}
|
||||
|
||||
protected override string SelectionChangeEventName {
|
||||
get { return "NSOutlineViewSelectionDidChangeNotification"; }
|
||||
}
|
||||
|
||||
public override object AddColumn (ListViewColumn col)
|
||||
{
|
||||
NSTableColumn tcol = (NSTableColumn) base.AddColumn (col);
|
||||
if (Tree.OutlineTableColumn == null)
|
||||
Tree.OutlineTableColumn = tcol;
|
||||
return tcol;
|
||||
}
|
||||
|
||||
public void SetSource (ITreeViewSource source, IBackend sourceBackend)
|
||||
{
|
||||
this.source = source;
|
||||
tsource = new TreeSource (source);
|
||||
Tree.DataSource = tsource;
|
||||
}
|
||||
|
||||
public override object GetValue (object pos, int nField)
|
||||
{
|
||||
return source.GetValue ((TreePosition)pos, nField);
|
||||
}
|
||||
|
||||
public TreePosition[] SelectedItems {
|
||||
get {
|
||||
TreePosition[] res = new TreePosition [Table.SelectedRowCount];
|
||||
int n = 0;
|
||||
foreach (var i in Table.SelectedRows) {
|
||||
res [n] = ((TreeItem)Tree.ItemAtRow ((int)i)).Position;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectItem (TreePosition pos)
|
||||
{
|
||||
var it = tsource.GetItem (pos);
|
||||
if (it != null)
|
||||
Table.SelectRow (Tree.RowForItem (it), false);
|
||||
}
|
||||
|
||||
public void UnselectItem (TreePosition pos)
|
||||
{
|
||||
var it = tsource.GetItem (pos);
|
||||
if (it != null)
|
||||
Table.DeselectRow (Tree.RowForItem (it));
|
||||
}
|
||||
}
|
||||
|
||||
class TreeItem: NSObject, ITablePosition
|
||||
{
|
||||
public TreePosition Position;
|
||||
|
||||
public TreeItem ()
|
||||
{
|
||||
}
|
||||
|
||||
public TreeItem (IntPtr p): base (p)
|
||||
{
|
||||
}
|
||||
|
||||
object ITablePosition.Position {
|
||||
get { return Position; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TreeSource: NSOutlineViewDataSource
|
||||
{
|
||||
ITreeViewSource source;
|
||||
|
||||
// TODO: remove unused positions
|
||||
Dictionary<TreePosition,TreeItem> items = new Dictionary<TreePosition, TreeItem> ();
|
||||
|
||||
public TreeSource (ITreeViewSource source)
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public TreeItem GetItem (TreePosition pos)
|
||||
{
|
||||
TreeItem it;
|
||||
items.TryGetValue (pos, out it);
|
||||
return it;
|
||||
}
|
||||
|
||||
public override bool AcceptDrop (NSOutlineView outlineView, NSDraggingInfo info, NSObject item, int index)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string[] FilesDropped (NSOutlineView outlineView, NSUrl dropDestination, NSArray items)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public override NSObject GetChild (NSOutlineView outlineView, int childIndex, NSObject ofItem)
|
||||
{
|
||||
var item = (TreeItem) ofItem;
|
||||
var pos = source.GetChild (item != null ? item.Position : null, childIndex);
|
||||
if (pos != null) {
|
||||
TreeItem res;
|
||||
if (!items.TryGetValue (pos, out res))
|
||||
items [pos] = res = new TreeItem () { Position = pos };
|
||||
return res;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public override int GetChildrenCount (NSOutlineView outlineView, NSObject item)
|
||||
{
|
||||
var it = (TreeItem) item;
|
||||
return source.GetChildrenCount (it != null ? it.Position : null);
|
||||
}
|
||||
|
||||
public override NSObject GetObjectValue (NSOutlineView outlineView, NSTableColumn forTableColumn, NSObject byItem)
|
||||
{
|
||||
return byItem;
|
||||
}
|
||||
|
||||
public override void SetObjectValue (NSOutlineView outlineView, NSObject theObject, NSTableColumn tableColumn, NSObject item)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool ItemExpandable (NSOutlineView outlineView, NSObject item)
|
||||
{
|
||||
return GetChildrenCount (outlineView, item) > 0;
|
||||
}
|
||||
|
||||
public override NSObject ItemForPersistentObject (NSOutlineView outlineView, NSObject theObject)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool OutlineViewwriteItemstoPasteboard (NSOutlineView outlineView, NSArray items, NSPasteboard pboard)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override NSObject PersistentObjectForItem (NSOutlineView outlineView, NSObject item)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void SortDescriptorsChanged (NSOutlineView outlineView, NSSortDescriptor[] oldDescriptors)
|
||||
{
|
||||
}
|
||||
|
||||
public override NSDragOperation ValidateDrop (NSOutlineView outlineView, NSDraggingInfo info, NSObject item, int index)
|
||||
{
|
||||
return NSDragOperation.None;
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
base.Dispose (disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
//
|
||||
// Util.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
using Xwt.Drawing;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public static class Util
|
||||
{
|
||||
public static double WidgetX (this NSView v)
|
||||
{
|
||||
return (double) v.Frame.X;
|
||||
}
|
||||
|
||||
public static double WidgetY (this NSView v)
|
||||
{
|
||||
return (double) v.Frame.Y;
|
||||
}
|
||||
|
||||
public static double WidgetWidth (this NSView v)
|
||||
{
|
||||
return (double) (v.Frame.Width);
|
||||
}
|
||||
|
||||
public static double WidgetHeight (this NSView v)
|
||||
{
|
||||
return (double) (v.Frame.Height);
|
||||
}
|
||||
|
||||
public static Rectangle WidgetBounds (this NSView v)
|
||||
{
|
||||
return new Rectangle (v.WidgetX(), v.WidgetY(), v.WidgetWidth(), v.WidgetHeight());
|
||||
}
|
||||
|
||||
public static void SetWidgetBounds (this NSView v, Rectangle rect)
|
||||
{
|
||||
float y = (float)rect.Y;
|
||||
if (v.Superview != null)
|
||||
y = v.Superview.Frame.Height - y - (float)rect.Height;
|
||||
v.Frame = new System.Drawing.RectangleF ((float)rect.X, y, (float)rect.Width, (float)rect.Height);
|
||||
}
|
||||
|
||||
public static NSColor ToNSColor (this Color col)
|
||||
{
|
||||
return NSColor.FromDeviceRgba ((float)col.Red, (float)col.Green, (float)col.Blue, (float)col.Alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,423 @@
|
|||
//
|
||||
// ViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.ObjCRuntime;
|
||||
using Xwt;
|
||||
using Xwt.Backends;
|
||||
using Xwt.Engine;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public abstract class ViewBackend<T,S>: IWidgetBackend,IMacViewBackend where T:NSView where S:IWidgetEventSink
|
||||
{
|
||||
Widget frontend;
|
||||
NSView alignment;
|
||||
S eventSink;
|
||||
IViewObject<T> viewObject;
|
||||
WidgetEvent currentEvents;
|
||||
|
||||
void IBackend.Initialize (object frontend)
|
||||
{
|
||||
this.frontend = (Widget) frontend;
|
||||
if (viewObject != null)
|
||||
viewObject.Frontend = (Widget) frontend;
|
||||
}
|
||||
|
||||
void IWidgetBackend.Initialize (IWidgetEventSink sink)
|
||||
{
|
||||
eventSink = (S) sink;
|
||||
Initialize ();
|
||||
}
|
||||
|
||||
public virtual void Initialize ()
|
||||
{
|
||||
}
|
||||
|
||||
public S EventSink {
|
||||
get { return eventSink; }
|
||||
}
|
||||
|
||||
public Widget Frontend {
|
||||
get {
|
||||
return this.frontend;
|
||||
}
|
||||
}
|
||||
|
||||
public object NativeWidget {
|
||||
get {
|
||||
return Widget;
|
||||
}
|
||||
}
|
||||
|
||||
public T Widget {
|
||||
get { return ViewObject.View; }
|
||||
}
|
||||
|
||||
public IViewObject<T> ViewObject {
|
||||
get { return viewObject; }
|
||||
set {
|
||||
viewObject = value;
|
||||
viewObject.Frontend = frontend;
|
||||
}
|
||||
}
|
||||
|
||||
public NSView RootWidget {
|
||||
get { return alignment ?? (NSView) Widget; }
|
||||
}
|
||||
|
||||
public bool Visible {
|
||||
get { return !RootWidget.Hidden; }
|
||||
set { RootWidget.Hidden = !value; }
|
||||
}
|
||||
|
||||
public virtual bool Sensitive {
|
||||
get { return true; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public virtual void Dispose ()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual SizeRequestMode SizeRequestMode {
|
||||
get { return SizeRequestMode.HeightForWidth; }
|
||||
}
|
||||
|
||||
Size IWidgetBackend.Size {
|
||||
get { return new Size (RootWidget.WidgetWidth (), RootWidget.WidgetHeight ()); }
|
||||
}
|
||||
|
||||
NSView IMacViewBackend.View {
|
||||
get { return RootWidget; }
|
||||
}
|
||||
|
||||
public static NSView GetWidget (IWidgetBackend w)
|
||||
{
|
||||
return ((IMacViewBackend)w).View;
|
||||
}
|
||||
|
||||
public static NSView GetWidget (Widget w)
|
||||
{
|
||||
return GetWidget ((IWidgetBackend)WidgetRegistry.GetBackend (w));
|
||||
}
|
||||
|
||||
#region IWidgetBackend implementation
|
||||
public WidgetSize GetPreferredWidth ()
|
||||
{
|
||||
double w = Widget.WidgetWidth () + frontend.Margin.HorizontalSpacing;
|
||||
return new Xwt.WidgetSize (w, w);
|
||||
}
|
||||
|
||||
public WidgetSize GetPreferredHeightForWidth (double width)
|
||||
{
|
||||
double w = Widget.WidgetHeight () + frontend.Margin.VerticalSpacing;
|
||||
return new Xwt.WidgetSize (w, w);
|
||||
}
|
||||
|
||||
public WidgetSize GetPreferredHeight ()
|
||||
{
|
||||
double w = Widget.WidgetHeight () + frontend.Margin.VerticalSpacing;
|
||||
return new Xwt.WidgetSize (w, w);
|
||||
}
|
||||
|
||||
public WidgetSize GetPreferredWidthForHeight (double height)
|
||||
{
|
||||
double w = Widget.WidgetWidth () + frontend.Margin.HorizontalSpacing;
|
||||
return new Xwt.WidgetSize (w, w);
|
||||
}
|
||||
|
||||
public virtual void UpdateLayout ()
|
||||
{
|
||||
if (frontend.Margin.HorizontalSpacing == 0 && frontend.Margin.VerticalSpacing == 0) {
|
||||
if (alignment != null) {
|
||||
Widget.RemoveFromSuperview ();
|
||||
NSView cont = alignment.Superview;
|
||||
if (cont != null)
|
||||
MacEngine.ReplaceChild (cont, alignment, Widget);
|
||||
alignment.Dispose ();
|
||||
alignment = null;
|
||||
}
|
||||
} else {
|
||||
if (alignment == null) {
|
||||
alignment = new NSView ();
|
||||
alignment.Frame = Widget.Frame;
|
||||
NSView cont = Widget.Superview;
|
||||
if (cont != null)
|
||||
MacEngine.ReplaceChild (cont, Widget, alignment);
|
||||
alignment.AddSubview (Widget);
|
||||
}
|
||||
Rectangle frame = new Rectangle ((int)frontend.Margin.Left, (int)frontend.Margin.Top, (int)alignment.Frame.Width - frontend.Margin.HorizontalSpacing, (int)alignment.Frame.Height - frontend.Margin.VerticalSpacing);
|
||||
Widget.SetWidgetBounds (frame);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void EnableEvent (object eventId)
|
||||
{
|
||||
if (eventId is WidgetEvent) {
|
||||
WidgetEvent ev = (WidgetEvent) eventId;
|
||||
currentEvents |= ev;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DisableEvent (object eventId)
|
||||
{
|
||||
if (eventId is WidgetEvent) {
|
||||
WidgetEvent ev = (WidgetEvent) eventId;
|
||||
currentEvents &= ~ev;
|
||||
}
|
||||
}
|
||||
|
||||
static Selector draggingEnteredSel = new Selector ("draggingEntered:");
|
||||
static Selector draggingUpdatedSel = new Selector ("draggingUpdated:");
|
||||
static Selector draggingExitedSel = new Selector ("draggingExited:");
|
||||
static Selector prepareForDragOperationSel = new Selector ("prepareForDragOperation:");
|
||||
static Selector performDragOperationSel = new Selector ("performDragOperation:");
|
||||
static Selector concludeDragOperationSel = new Selector ("concludeDragOperation:");
|
||||
static HashSet<Type> typesConfiguredForDragDrop = new HashSet<Type> ();
|
||||
|
||||
static void SetupForDragDrop (Type type)
|
||||
{
|
||||
lock (typesConfiguredForDragDrop) {
|
||||
if (typesConfiguredForDragDrop.Add (type)) {
|
||||
Class c = new Class (type);
|
||||
c.AddMethod (draggingEnteredSel.Handle, new Func<IntPtr,IntPtr,IntPtr,NSDragOperation> (DraggingEntered), "i@:@");
|
||||
c.AddMethod (draggingUpdatedSel.Handle, new Func<IntPtr,IntPtr,IntPtr,NSDragOperation> (DraggingUpdated), "i@:@");
|
||||
c.AddMethod (draggingExitedSel.Handle, new Action<IntPtr,IntPtr,IntPtr> (DraggingExited), "v@:@");
|
||||
c.AddMethod (prepareForDragOperationSel.Handle, new Func<IntPtr,IntPtr,IntPtr,bool> (PrepareForDragOperation), "B@:@");
|
||||
c.AddMethod (performDragOperationSel.Handle, new Func<IntPtr,IntPtr,IntPtr,bool> (PerformDragOperation), "B@:@");
|
||||
c.AddMethod (concludeDragOperationSel.Handle, new Action<IntPtr,IntPtr,IntPtr> (ConcludeDragOperation), "v@:@");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DragStart (TransferDataSource data, DragDropAction dragAction)
|
||||
{
|
||||
var pb = NSPasteboard.FromName (NSPasteboard.NSDragPasteboardName);
|
||||
InitPasteboard (pb, data);
|
||||
var pos = new PointF (Widget.Bounds.X + Widget.Bounds.Width/2, Widget.Bounds.Y + Widget.Bounds.Height / 2);
|
||||
var img = new NSImage ("/Users/lluis/prog/work/Xwt/MacTest/class.png");
|
||||
Widget.DragImage (img, pos, new SizeF (0,0), NSApplication.SharedApplication.CurrentEvent, pb, Widget, true);
|
||||
}
|
||||
|
||||
public void SetDragSource (string[] types, DragDropAction dragAction)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetDragTarget (string[] types, DragDropAction dragAction)
|
||||
{
|
||||
SetupForDragDrop (Widget.GetType ());
|
||||
var dtypes = types.Select (t => ToNSDragType (t)).ToArray ();
|
||||
Widget.RegisterForDraggedTypes (dtypes);
|
||||
}
|
||||
|
||||
static NSDragOperation DraggingEntered (IntPtr sender, IntPtr sel, IntPtr dragInfo)
|
||||
{
|
||||
return DraggingUpdated (sender, sel, dragInfo);
|
||||
}
|
||||
|
||||
static NSDragOperation DraggingUpdated (IntPtr sender, IntPtr sel, IntPtr dragInfo)
|
||||
{
|
||||
IViewObject<T> ob = Runtime.GetNSObject (sender) as IViewObject<T>;
|
||||
if (ob == null)
|
||||
return NSDragOperation.None;
|
||||
var backend = (ViewBackend<T,S>) WidgetRegistry.GetBackend (ob.Frontend);
|
||||
|
||||
NSDraggingInfo di = new NSDraggingInfo (dragInfo);
|
||||
var types = di.DraggingPasteboard.Types.Select (t => ToXwtDragType (t)).ToArray ();
|
||||
var pos = new Point (di.DraggingLocation.X, di.DraggingLocation.Y);
|
||||
|
||||
if ((backend.currentEvents & WidgetEvent.DragOverCheck) != 0) {
|
||||
var args = new DragOverCheckEventArgs (pos, types, ConvertAction (di.DraggingSourceOperationMask));
|
||||
backend.eventSink.OnDragOverCheck (args);
|
||||
if (args.AllowedAction == DragDropAction.None)
|
||||
return NSDragOperation.None;
|
||||
if (args.AllowedAction != DragDropAction.Default)
|
||||
return ConvertAction (args.AllowedAction);
|
||||
}
|
||||
|
||||
if ((backend.currentEvents & WidgetEvent.DragOver) != 0) {
|
||||
TransferDataStore store = new TransferDataStore ();
|
||||
FillDataStore (store, di.DraggingPasteboard, ob.View.RegisteredDragTypes ());
|
||||
var args = new DragOverEventArgs (pos, store, ConvertAction (di.DraggingSourceOperationMask));
|
||||
backend.eventSink.OnDragOver (args);
|
||||
if (args.AllowedAction == DragDropAction.None)
|
||||
return NSDragOperation.None;
|
||||
if (args.AllowedAction != DragDropAction.Default)
|
||||
return ConvertAction (args.AllowedAction);
|
||||
}
|
||||
|
||||
return di.DraggingSourceOperationMask;
|
||||
}
|
||||
|
||||
static void DraggingExited (IntPtr sender, IntPtr sel, IntPtr dragInfo)
|
||||
{
|
||||
IViewObject<T> ob = Runtime.GetNSObject (sender) as IViewObject<T>;
|
||||
if (ob != null) {
|
||||
var backend = (ViewBackend<T,S>) WidgetRegistry.GetBackend (ob.Frontend);
|
||||
backend.eventSink.OnDragLeave (EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
static bool PrepareForDragOperation (IntPtr sender, IntPtr sel, IntPtr dragInfo)
|
||||
{
|
||||
IViewObject<T> ob = Runtime.GetNSObject (sender) as IViewObject<T>;
|
||||
if (ob == null)
|
||||
return false;
|
||||
|
||||
var backend = (ViewBackend<T,S>) WidgetRegistry.GetBackend (ob.Frontend);
|
||||
|
||||
NSDraggingInfo di = new NSDraggingInfo (dragInfo);
|
||||
var types = di.DraggingPasteboard.Types.Select (t => ToXwtDragType (t)).ToArray ();
|
||||
var pos = new Point (di.DraggingLocation.X, di.DraggingLocation.Y);
|
||||
|
||||
if ((backend.currentEvents & WidgetEvent.DragDropCheck) != 0) {
|
||||
var args = new DragCheckEventArgs (pos, types, ConvertAction (di.DraggingSourceOperationMask));
|
||||
backend.eventSink.OnDragDropCheck (args);
|
||||
if (args.Result == DragDropResult.Canceled)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool PerformDragOperation (IntPtr sender, IntPtr sel, IntPtr dragInfo)
|
||||
{
|
||||
IViewObject<T> ob = Runtime.GetNSObject (sender) as IViewObject<T>;
|
||||
if (ob == null)
|
||||
return false;
|
||||
|
||||
var backend = (ViewBackend<T,S>) WidgetRegistry.GetBackend (ob.Frontend);
|
||||
|
||||
NSDraggingInfo di = new NSDraggingInfo (dragInfo);
|
||||
var pos = new Point (di.DraggingLocation.X, di.DraggingLocation.Y);
|
||||
|
||||
if ((backend.currentEvents & WidgetEvent.DragDrop) != 0) {
|
||||
TransferDataStore store = new TransferDataStore ();
|
||||
FillDataStore (store, di.DraggingPasteboard, ob.View.RegisteredDragTypes ());
|
||||
var args = new DragEventArgs (pos, store, ConvertAction (di.DraggingSourceOperationMask));
|
||||
backend.eventSink.OnDragDrop (args);
|
||||
return args.Success;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ConcludeDragOperation (IntPtr sender, IntPtr sel, IntPtr dragInfo)
|
||||
{
|
||||
Console.WriteLine ("ConcludeDragOperation");
|
||||
}
|
||||
|
||||
void InitPasteboard (NSPasteboard pb, TransferDataSource data)
|
||||
{
|
||||
pb.ClearContents ();
|
||||
foreach (var t in data.DataTypes) {
|
||||
if (t == TransferDataType.Text) {
|
||||
pb.AddTypes (new string[] { NSPasteboard.NSStringType }, null);
|
||||
pb.SetStringForType ((string)data.GetValue (t), NSPasteboard.NSStringType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void FillDataStore (TransferDataStore store, NSPasteboard pb, string[] types)
|
||||
{
|
||||
foreach (var t in types) {
|
||||
if (!pb.Types.Contains (t))
|
||||
continue;
|
||||
if (t == NSPasteboard.NSStringType)
|
||||
store.AddText (pb.GetStringForType (t));
|
||||
else if (t == NSPasteboard.NSFilenamesType) {
|
||||
string data = pb.GetStringForType (t);
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.XmlResolver = null; // Avoid DTD validation
|
||||
doc.LoadXml (data);
|
||||
store.AddUris (doc.SelectNodes ("/plist/array/string").Cast<XmlElement> ().Select (e => new Uri (e.InnerText)).ToArray ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NSDragOperation ConvertAction (DragDropAction action)
|
||||
{
|
||||
NSDragOperation res = (NSDragOperation)0;
|
||||
if ((action & DragDropAction.Copy) != 0)
|
||||
res |= NSDragOperation.Copy;
|
||||
if ((action & DragDropAction.Move) != 0)
|
||||
res |= NSDragOperation.Move;
|
||||
if ((action & DragDropAction.Link) != 0)
|
||||
res |= NSDragOperation.Link;
|
||||
return res;
|
||||
}
|
||||
|
||||
static DragDropAction ConvertAction (NSDragOperation action)
|
||||
{
|
||||
DragDropAction res = (DragDropAction)0;
|
||||
if ((action & NSDragOperation.Copy) != 0)
|
||||
res |= DragDropAction.Copy;
|
||||
if ((action & NSDragOperation.Move) != 0)
|
||||
res |= DragDropAction.Move;
|
||||
if ((action & NSDragOperation.Link) != 0)
|
||||
res |= DragDropAction.Link;
|
||||
return res;
|
||||
}
|
||||
|
||||
static string ToNSDragType (string type)
|
||||
{
|
||||
switch (type) {
|
||||
case TransferDataType.Text: return NSPasteboard.NSStringType;
|
||||
case TransferDataType.Uri: return NSPasteboard.NSFilenamesType;
|
||||
case TransferDataType.Image: return NSPasteboard.NSPictType;
|
||||
case TransferDataType.Rtf: return NSPasteboard.NSRtfType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static string ToXwtDragType (string type)
|
||||
{
|
||||
if (type == NSPasteboard.NSStringType)
|
||||
return TransferDataType.Text;
|
||||
if (type == NSPasteboard.NSFilenamesType)
|
||||
return TransferDataType.Uri;
|
||||
if (type == NSPasteboard.NSPictType)
|
||||
return TransferDataType.Image;
|
||||
if (type == NSPasteboard.NSRtfType)
|
||||
return TransferDataType.Rtf;
|
||||
return type;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public interface IMacViewBackend
|
||||
{
|
||||
NSView View { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
//
|
||||
// WindowBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 MonoMac.AppKit;
|
||||
|
||||
namespace Xwt.Mac
|
||||
{
|
||||
public class WindowBackend: NSWindow, IWindowBackend
|
||||
{
|
||||
WindowBackendController controller;
|
||||
IWindowEventSink eventSink;
|
||||
Window frontend;
|
||||
IMacViewBackend child;
|
||||
|
||||
public WindowBackend ()
|
||||
{
|
||||
this.controller = new WindowBackendController ();
|
||||
controller.Window = this;
|
||||
StyleMask |= NSWindowStyle.Resizable;
|
||||
ContentView.AutoresizesSubviews = true;
|
||||
Center ();
|
||||
}
|
||||
|
||||
public virtual void Initialize (object frontend)
|
||||
{
|
||||
this.frontend = (Window) frontend;
|
||||
}
|
||||
|
||||
public object NativeWidget {
|
||||
get {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowAll ()
|
||||
{
|
||||
MacEngine.App.ShowWindow (this);
|
||||
}
|
||||
|
||||
internal void InternalShow ()
|
||||
{
|
||||
MakeKeyAndOrderFront (MacEngine.App);
|
||||
}
|
||||
|
||||
public bool Visible {
|
||||
get {
|
||||
return !ContentView.Hidden;
|
||||
}
|
||||
set {
|
||||
ContentView.Hidden = !value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Sensitive {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
set {
|
||||
}
|
||||
}
|
||||
|
||||
#region IWindowBackend implementation
|
||||
void IWidgetBackend.Initialize (IWidgetEventSink eventSink)
|
||||
{
|
||||
this.eventSink = (IWindowEventSink) eventSink;
|
||||
}
|
||||
|
||||
void IBackend.EnableEvent (object ev)
|
||||
{
|
||||
if ((ev is WindowEvent) && ((WindowEvent)ev) == WindowEvent.BoundsChanged)
|
||||
DidResize += HandleDidResize;
|
||||
}
|
||||
|
||||
void IBackend.DisableEvent (object ev)
|
||||
{
|
||||
if ((ev is WindowEvent) && ((WindowEvent)ev) == WindowEvent.BoundsChanged)
|
||||
DidResize -= HandleDidResize;
|
||||
}
|
||||
|
||||
void HandleDidResize (object sender, EventArgs e)
|
||||
{
|
||||
eventSink.OnBoundsChanged (((IWindowBackend)this).Bounds);
|
||||
}
|
||||
|
||||
void IWindowBackend.SetChild (IWidgetBackend child)
|
||||
{
|
||||
if (this.child != null) {
|
||||
this.child.View.RemoveFromSuperview ();
|
||||
}
|
||||
this.child = (IMacViewBackend) child;
|
||||
if (child != null) {
|
||||
ContentView.AddSubview (this.child.View);
|
||||
UpdateLayout ();
|
||||
this.child.View.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void UpdateLayout ()
|
||||
{
|
||||
if (child != null) {
|
||||
var frame = ContentView.Frame;
|
||||
frame.X += frontend.Margin.Left;
|
||||
frame.Width -= frontend.Margin.HorizontalSpacing;
|
||||
frame.Y += frontend.Margin.Top;
|
||||
frame.Height -= frontend.Margin.VerticalSpacing;
|
||||
child.View.Frame = frame;
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle IWindowBackend.Bounds {
|
||||
get {
|
||||
var r = ContentRectFor (Frame);
|
||||
return new Rectangle ((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
|
||||
}
|
||||
set {
|
||||
var r = FrameRectFor (new System.Drawing.RectangleF ((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height));
|
||||
SetFrame (r, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMainMenu (IMenuBackend menu)
|
||||
{
|
||||
NSMenu m = (NSMenu) menu;
|
||||
NSApplication.SharedApplication.Menu = m;
|
||||
// base.Menu = m;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IWidgetBackend implementation
|
||||
|
||||
Size IWidgetBackend.Size {
|
||||
get { return ((IWindowBackend)this).Bounds.Size; }
|
||||
}
|
||||
|
||||
WidgetSize IWidgetBackend.GetPreferredWidth ()
|
||||
{
|
||||
int w = (int)Frame.Width + frontend.Margin.HorizontalSpacing;
|
||||
return new WidgetSize (w, w);
|
||||
}
|
||||
|
||||
WidgetSize IWidgetBackend.GetPreferredHeightForWidth (double width)
|
||||
{
|
||||
int h = (int) Frame.Height + frontend.Margin.VerticalSpacing;
|
||||
return new WidgetSize (h, h);
|
||||
}
|
||||
|
||||
WidgetSize IWidgetBackend.GetPreferredHeight ()
|
||||
{
|
||||
int h = (int) Frame.Height + frontend.Margin.VerticalSpacing;
|
||||
return new WidgetSize (h, h);
|
||||
}
|
||||
|
||||
WidgetSize IWidgetBackend.GetPreferredWidthForHeight (double height)
|
||||
{
|
||||
int w = (int)Frame.Width + frontend.Margin.HorizontalSpacing;
|
||||
return new WidgetSize (w, w);
|
||||
}
|
||||
|
||||
bool IWidgetBackend.Visible {
|
||||
get {
|
||||
return IsVisible;
|
||||
}
|
||||
set {
|
||||
if (value)
|
||||
MakeKeyAndOrderFront (controller);
|
||||
else
|
||||
OrderOut (controller);
|
||||
}
|
||||
}
|
||||
|
||||
bool IWidgetBackend.Sensitive {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
set {
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
void IDisposable.Dispose ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void DragStart (TransferDataSource data, DragDropAction dragAction)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public void SetDragSource (string[] types, DragDropAction dragAction)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetDragTarget (string[] types, DragDropAction dragAction)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class WindowBackendController : MonoMac.AppKit.NSWindowController
|
||||
{
|
||||
public WindowBackendController ()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xwt", "Xwt\Xwt.csproj", "{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xwt.Gtk", "Xwt.Gtk\Xwt.Gtk.csproj", "{C3887A93-B2BD-4097-8E2F-3A063EFF32FD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xwt.Mac", "Xwt.Mac\Xwt.Mac.csproj", "{B7C1673E-5124-4BE5-8D21-EC8B12F85B6B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B7C1673E-5124-4BE5-8D21-EC8B12F85B6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B7C1673E-5124-4BE5-8D21-EC8B12F85B6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B7C1673E-5124-4BE5-8D21-EC8B12F85B6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B7C1673E-5124-4BE5-8D21-EC8B12F85B6B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C3887A93-B2BD-4097-8E2F-3A063EFF32FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3887A93-B2BD-4097-8E2F-3A063EFF32FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3887A93-B2BD-4097-8E2F-3A063EFF32FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3887A93-B2BD-4097-8E2F-3A063EFF32FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Xwt\Xwt.csproj
|
||||
Policies = $0
|
||||
$0.DotNetNamingPolicy = $1
|
||||
$1.DirectoryNamespaceAssociation = None
|
||||
$1.ResourceNamePolicy = FileFormatDefault
|
||||
$0.VersionControlPolicy = $2
|
||||
$2.inheritsSet = Mono
|
||||
$0.StandardHeader = $3
|
||||
$3.Text = @\n${FileName}\n \nAuthor:\n ${AuthorName} <${AuthorEmail}>\n\nCopyright (c) ${Year} ${CopyrightHolder}\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.
|
||||
$3.IncludeInNewFiles = True
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,27 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("Xwt")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("Xamarin, Inc (http://www.xamarin.com)")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
Двоичный файл не отображается.
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// EngineBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Reflection;
|
||||
using System.IO;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public abstract class EngineBackend
|
||||
{
|
||||
public virtual void InitializeApplication ()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void RunApplication ();
|
||||
|
||||
public abstract void Invoke (Action action);
|
||||
|
||||
public abstract object TimeoutInvoke (Func<bool> action, TimeSpan timeSpan);
|
||||
|
||||
public abstract void CancelTimeoutInvoke (object id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// IBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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
|
||||
{
|
||||
public interface IBackend
|
||||
{
|
||||
void Initialize (object frontend);
|
||||
void EnableEvent (object eventId);
|
||||
void DisableEvent (object eventId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// IBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IBackendHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// IBoxBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IBoxBackend: IWidgetBackend
|
||||
{
|
||||
void Add (IWidgetBackend widget);
|
||||
void Remove (IWidgetBackend widget);
|
||||
void SetAllocation (IWidgetBackend widget, Rectangle rect);
|
||||
}
|
||||
|
||||
public enum Orientation
|
||||
{
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// IButtonBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IButtonBackend: IWidgetBackend
|
||||
{
|
||||
string Label { get; set; }
|
||||
}
|
||||
|
||||
public interface IButtonEventSink: IWidgetEventSink
|
||||
{
|
||||
void OnClicked ();
|
||||
}
|
||||
|
||||
public enum ButtonEvent
|
||||
{
|
||||
Clicked = 1
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// ICanvasBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface ICanvasBackend
|
||||
{
|
||||
void QueueDraw ();
|
||||
Rectangle Bounds { get; }
|
||||
}
|
||||
|
||||
public interface ICanvasEventSink: IWidgetEventSink
|
||||
{
|
||||
void OnDraw (object context);
|
||||
void OnBoundsChanged ();
|
||||
void OnButtonPressed (ButtonEventArgs args);
|
||||
void OnButtonReleased (ButtonEventArgs args);
|
||||
void OnMouseMoved (MouseMovedEventArgs args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// IColumnContainerBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IColumnContainerBackend
|
||||
{
|
||||
object AddColumn (ListViewColumn col);
|
||||
void RemoveColumn (ListViewColumn col, object handle);
|
||||
void UpdateColumn (ListViewColumn col, object handle, ListViewColumnChange change);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// IContainerBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IContainerBackend
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
//
|
||||
// IContextBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public interface IContextBackendHandler: IBackendHandler
|
||||
{
|
||||
object CreateContext (Widget w);
|
||||
|
||||
void Arc (object backend, double xc, double yc, double radius, double angle1, double angle2);
|
||||
|
||||
void Clip (object backend);
|
||||
|
||||
void ClipPreserve(object backend);
|
||||
|
||||
void ResetClip (object backend);
|
||||
|
||||
void ClosePath(object backend);
|
||||
|
||||
void CurveTo (object backend, double x1, double y1, double x2, double y2, double x3, double y3);
|
||||
|
||||
void Fill (object backend);
|
||||
|
||||
void FillPreserve (object backend);
|
||||
|
||||
void LineTo (object backend, double x, double y);
|
||||
|
||||
void MoveTo (object backend, double x, double y);
|
||||
|
||||
void NewPath (object backend);
|
||||
|
||||
void Rectangle (object backend, double x, double y, double width, double height);
|
||||
|
||||
void RelCurveTo (object backend, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
|
||||
|
||||
void RelLineTo (object backend, double dx, double dy);
|
||||
|
||||
void RelMoveTo (object backend, double dx, double dy);
|
||||
|
||||
void Stroke (object backend);
|
||||
|
||||
void StrokePreserve (object backend);
|
||||
|
||||
void SetColor (object backend, Xwt.Drawing.Color color);
|
||||
|
||||
void SetLineWidth (object backend, double width);
|
||||
|
||||
void SetPattern (object backend, Pattern p);
|
||||
|
||||
void SetFont (object backend, Font font);
|
||||
|
||||
void DrawTextLayout (object backend, TextLayout layout, double x, double y);
|
||||
|
||||
void DrawImage (object backend, Image img, double x, double y);
|
||||
|
||||
void Dispose (object backend);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// IDesignerSurfaceBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IDesignerSurfaceBackend: IWidgetBackend
|
||||
{
|
||||
void Load (Widget w);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// IFontBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IFontBackendHandler: IBackendHandler
|
||||
{
|
||||
object CreateFromName (string fontName, double size);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// IGradientBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public interface IGradientBackendHandler: IBackendHandler
|
||||
{
|
||||
object CreateLinear (double x0, double y0, double x1, double y1);
|
||||
void AddColorStop (object backend, double position, Color color);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// ILabelBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface ILabelBackend: IWidgetBackend
|
||||
{
|
||||
string Text { get; set; }
|
||||
Alignment HorizontalAlignment { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// IListStoreBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IListStoreBackend: IListViewSource, IBackend
|
||||
{
|
||||
void Initialize (Type[] columnTypes);
|
||||
|
||||
int AddRow ();
|
||||
|
||||
int InsertRowAfter (int row);
|
||||
|
||||
int InsertRowBefore (int row);
|
||||
|
||||
void RemoveRow (int row);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// IListViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IListViewBackend: ITableViewBackend
|
||||
{
|
||||
void SetSource (IListViewSource source, IBackend sourceBackend);
|
||||
int[] SelectedRows { get; }
|
||||
void SelectRow (int pos);
|
||||
void UnselectRow (int pos);
|
||||
}
|
||||
|
||||
public interface IListViewEventSink: ITableViewEventSink
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// IMenuBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IMenuBackend: IBackend
|
||||
{
|
||||
void InsertItem (int index, IMenuItemBackend menuItem);
|
||||
void RemoveItem (IMenuItemBackend menuItem);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// IMenuItemBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IMenuItemBackend: IBackend
|
||||
{
|
||||
void Initialize (IMenuItemEventSink eventSink);
|
||||
void SetSubmenu (IMenuBackend menu);
|
||||
string Label { get; set; }
|
||||
}
|
||||
|
||||
public interface IMenuItemEventSink
|
||||
{
|
||||
void OnClicked ();
|
||||
}
|
||||
|
||||
public enum MenuItemEvent
|
||||
{
|
||||
Clicked = 1
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// INotebookBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface INotebookBackend: IWidgetBackend
|
||||
{
|
||||
void Add (IWidgetBackend widget, NotebookTab tab);
|
||||
void Remove (IWidgetBackend widget);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// IPanedBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IPanedBackend
|
||||
{
|
||||
void Initialize (Orientation dir);
|
||||
void SetPanel (int panel, IWidgetBackend widget, Panel placement);
|
||||
void Update (int panel, Panel placement);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// ITableViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface ITableViewBackend: IWidgetBackend, IColumnContainerBackend
|
||||
{
|
||||
void SetSelectionMode (SelectionMode mode);
|
||||
void SelectAll ();
|
||||
void UnselectAll ();
|
||||
}
|
||||
|
||||
public interface ITableViewEventSink: IWidgetEventSink
|
||||
{
|
||||
void OnSelectionChanged ();
|
||||
}
|
||||
|
||||
public enum TableViewEvent
|
||||
{
|
||||
SelectionChanged
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// ITextLayoutBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public interface ITextLayoutBackendHandler: IBackendHandler
|
||||
{
|
||||
object Create (Context context);
|
||||
void SetText (object backend, string text);
|
||||
void SetFont (object backend, Font font);
|
||||
Size GetSize (object backend);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// ITreeStoreBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface ITreeStoreBackend: ITreeViewSource, IBackend
|
||||
{
|
||||
void Initialize (Type[] columnTypes);
|
||||
TreePosition InsertBefore (TreePosition pos);
|
||||
TreePosition InsertAfter (TreePosition pos);
|
||||
TreePosition AddChild (TreePosition pos);
|
||||
TreePosition GetNext (TreePosition pos);
|
||||
TreePosition GetPrevious (TreePosition pos);
|
||||
TreePosition GetParent (TreePosition pos);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// ITreeViewBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public interface ITreeViewBackend: ITableViewBackend
|
||||
{
|
||||
void SetSource (ITreeViewSource source, IBackend sourceBackend);
|
||||
TreePosition[] SelectedItems { get; }
|
||||
void SelectItem (TreePosition pos);
|
||||
void UnselectItem (TreePosition pos);
|
||||
}
|
||||
|
||||
public enum ListViewColumnChange
|
||||
{
|
||||
Title,
|
||||
Cells
|
||||
}
|
||||
|
||||
public interface ITreeViewEventSink: ITableViewEventSink
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
//
|
||||
// IWidgetBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Backends
|
||||
{
|
||||
public interface IWidgetBackend: IBackend, IDisposable
|
||||
{
|
||||
void Initialize (IWidgetEventSink eventSink);
|
||||
|
||||
bool Visible { get; set; }
|
||||
bool Sensitive { get; set; }
|
||||
Size Size { get; }
|
||||
|
||||
void UpdateLayout ();
|
||||
WidgetSize GetPreferredWidth ();
|
||||
WidgetSize GetPreferredHeightForWidth (double width);
|
||||
WidgetSize GetPreferredHeight ();
|
||||
WidgetSize GetPreferredWidthForHeight (double height);
|
||||
|
||||
object NativeWidget { get; }
|
||||
|
||||
void DragStart (TransferDataSource data, DragDropAction dragAction);
|
||||
void SetDragSource (string[] types, DragDropAction dragAction);
|
||||
void SetDragTarget (string[] types, DragDropAction dragAction);
|
||||
}
|
||||
|
||||
public interface IWidgetEventSink
|
||||
{
|
||||
void OnDragOverCheck (DragOverCheckEventArgs args);
|
||||
void OnDragOver (DragOverEventArgs args);
|
||||
void OnDragDropCheck (DragCheckEventArgs args);
|
||||
void OnDragDrop (DragEventArgs args);
|
||||
void OnDragLeave (EventArgs args);
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum WidgetEvent
|
||||
{
|
||||
DragOverCheck = 1,
|
||||
DragOver = 2,
|
||||
DragDropCheck = 4,
|
||||
DragDrop = 8,
|
||||
DragLeave = 16
|
||||
}
|
||||
|
||||
public interface DragOperationEventSink
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ITransferDataSource
|
||||
{
|
||||
string[] Types { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// IWindowBackend.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public interface IWindowBackend: IWidgetBackend
|
||||
{
|
||||
Rectangle Bounds { get; set; }
|
||||
|
||||
string Title { get; set; }
|
||||
void SetChild (IWidgetBackend child);
|
||||
void SetMainMenu (IMenuBackend menu);
|
||||
}
|
||||
|
||||
public interface IWindowEventSink: IWidgetEventSink
|
||||
{
|
||||
void OnBoundsChanged (Rectangle bounds);
|
||||
}
|
||||
|
||||
public enum WindowEvent
|
||||
{
|
||||
BoundsChanged = 1
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
//
|
||||
// ImageBackendHandler.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Xwt.Backends
|
||||
{
|
||||
public abstract class ImageBackendHandler: IBackendHandler
|
||||
{
|
||||
public virtual object CreateBackend ()
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public virtual void Dispose (object backend)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual object LoadFromResource (Assembly asm, string name)
|
||||
{
|
||||
using (var s = asm.GetManifestResourceStream (name)) {
|
||||
if (s == null)
|
||||
throw new InvalidOperationException ("Resource not found: " + name);
|
||||
return LoadFromStream (s);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual object LoadFromFile (string file)
|
||||
{
|
||||
using (var s = File.OpenRead (file))
|
||||
return LoadFromStream (s);
|
||||
}
|
||||
|
||||
public abstract object LoadFromStream (Stream stream);
|
||||
|
||||
public abstract Size GetSize (object handle);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// DesignerSurface.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Xml;
|
||||
using System.Xaml;
|
||||
|
||||
namespace Xwt.Design
|
||||
{
|
||||
public class DesignerSurface: Widget
|
||||
{
|
||||
Widget widget;
|
||||
|
||||
public DesignerSurface ()
|
||||
{
|
||||
}
|
||||
|
||||
new IDesignerSurfaceBackend Backend {
|
||||
get { return (IDesignerSurfaceBackend) base.Backend; }
|
||||
}
|
||||
|
||||
public void Load (XmlReader r)
|
||||
{
|
||||
object o = XamlServices.Load (r);
|
||||
if (!(o is Widget))
|
||||
throw new InvalidOperationException ("Invalid object type. Expected Xwt.Widget, found: " + o.GetType ());
|
||||
widget = (Widget)o;
|
||||
Backend.Load (widget);
|
||||
}
|
||||
|
||||
public void Save (XmlWriter w)
|
||||
{
|
||||
XamlServices.Save (w, widget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
//
|
||||
// Color.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing
|
||||
{
|
||||
public struct Color
|
||||
{
|
||||
double r, g, b, a;
|
||||
HslColor hsl;
|
||||
|
||||
public static Color Black = new Color (0, 0, 0);
|
||||
public static Color White = new Color (1, 1, 1);
|
||||
|
||||
public double Red {
|
||||
get { return r; }
|
||||
set { r = value; hsl = null; }
|
||||
}
|
||||
|
||||
public double Green {
|
||||
get { return g; }
|
||||
set { g = value; hsl = null; }
|
||||
}
|
||||
|
||||
public double Blue {
|
||||
get { return b; }
|
||||
set { b = value; hsl = null; }
|
||||
}
|
||||
|
||||
public double Alpha {
|
||||
get { return a; }
|
||||
set { a = value; }
|
||||
}
|
||||
|
||||
public double Hue {
|
||||
get {
|
||||
return Hsl.H;
|
||||
}
|
||||
set {
|
||||
Hsl = new HslColor (value, Hsl.S, Hsl.L);
|
||||
}
|
||||
}
|
||||
|
||||
public double Saturation {
|
||||
get {
|
||||
return Hsl.S;
|
||||
}
|
||||
set {
|
||||
Hsl = new HslColor (Hsl.H, value, Hsl.L);
|
||||
}
|
||||
}
|
||||
|
||||
public double Light {
|
||||
get {
|
||||
return Hsl.L;
|
||||
}
|
||||
set {
|
||||
Hsl = new HslColor (Hsl.H, Hsl.S, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double Brightness {
|
||||
get {
|
||||
return System.Math.Sqrt (Red * .241 + Green * .691 + Blue * .068);
|
||||
}
|
||||
}
|
||||
|
||||
HslColor Hsl {
|
||||
get {
|
||||
if (hsl == null)
|
||||
hsl = (HslColor)this;
|
||||
return hsl;
|
||||
}
|
||||
set {
|
||||
hsl = value;
|
||||
Color c = (Color)value;
|
||||
r = c.r;
|
||||
b = c.b;
|
||||
g = c.g;
|
||||
}
|
||||
}
|
||||
|
||||
public Color (double red, double green, double blue): this ()
|
||||
{
|
||||
Red = red;
|
||||
Green = green;
|
||||
Blue = blue;
|
||||
Alpha = 1f;
|
||||
}
|
||||
|
||||
public Color (double red, double green, double blue, double alpha): this ()
|
||||
{
|
||||
Red = red;
|
||||
Green = green;
|
||||
Blue = blue;
|
||||
Alpha = alpha;
|
||||
}
|
||||
|
||||
public static Color FromHsl (double h, double s, double l)
|
||||
{
|
||||
return FromHsl (h, s, l, 1);
|
||||
}
|
||||
|
||||
public static Color FromHsl (double h, double s, double l, double alpha)
|
||||
{
|
||||
HslColor hsl = new HslColor (h, s, l);
|
||||
Color c = (Color)hsl;
|
||||
c.Alpha = alpha;
|
||||
c.hsl = hsl;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,220 @@
|
|||
//
|
||||
// Context.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Engine;
|
||||
|
||||
namespace Xwt.Drawing
|
||||
{
|
||||
public sealed class Context: XwtObject, IDisposable
|
||||
{
|
||||
static IContextBackendHandler handler;
|
||||
|
||||
Pattern pattern;
|
||||
Font font;
|
||||
|
||||
static Context ()
|
||||
{
|
||||
handler = WidgetRegistry.CreateSharedBackend<IContextBackendHandler> (typeof(Context));
|
||||
}
|
||||
|
||||
protected override IBackendHandler BackendHandler {
|
||||
get {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
internal Context (Widget w): base (handler.CreateContext (w))
|
||||
{
|
||||
}
|
||||
|
||||
internal Context (object backend): base (backend)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetColor (Color color)
|
||||
{
|
||||
handler.SetColor (Backend, color);
|
||||
}
|
||||
|
||||
public void Arc (double xc, double yc, double radius, double angle1, double angle2)
|
||||
{
|
||||
handler.Arc (Backend, xc, yc, radius, angle1, angle2);
|
||||
}
|
||||
|
||||
public void Clip()
|
||||
{
|
||||
handler.Clip (Backend);
|
||||
}
|
||||
|
||||
public void ClipPreserve()
|
||||
{
|
||||
handler.ClipPreserve (Backend);
|
||||
}
|
||||
|
||||
public void ResetClip()
|
||||
{
|
||||
handler.ResetClip (Backend);
|
||||
}
|
||||
|
||||
public void ClosePath()
|
||||
{
|
||||
handler.ClosePath (Backend);
|
||||
}
|
||||
|
||||
public void CurveTo (Point p1, Point p2, Point p3)
|
||||
{
|
||||
CurveTo (p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y);
|
||||
}
|
||||
|
||||
public void CurveTo (double x1, double y1, double x2, double y2, double x3, double y3)
|
||||
{
|
||||
handler.CurveTo (Backend, x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
|
||||
public void Fill ()
|
||||
{
|
||||
handler.Fill (Backend);
|
||||
}
|
||||
|
||||
public void FillPreserve ()
|
||||
{
|
||||
handler.FillPreserve (Backend);
|
||||
}
|
||||
|
||||
public void LineTo (Point p)
|
||||
{
|
||||
LineTo (p.X, p.Y);
|
||||
}
|
||||
|
||||
public void LineTo (double x, double y)
|
||||
{
|
||||
handler.LineTo (Backend, x, y);
|
||||
}
|
||||
|
||||
public void MoveTo (Point p)
|
||||
{
|
||||
MoveTo (p.X, p.Y);
|
||||
}
|
||||
|
||||
public void MoveTo (double x, double y)
|
||||
{
|
||||
handler.MoveTo (Backend, x, y);
|
||||
}
|
||||
|
||||
public void NewPath ()
|
||||
{
|
||||
handler.NewPath (Backend);
|
||||
}
|
||||
|
||||
public void Rectangle (Rectangle rectangle)
|
||||
{
|
||||
Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
|
||||
}
|
||||
|
||||
public void Rectangle (Point p, double width, double height)
|
||||
{
|
||||
Rectangle (p.X, p.Y, width, height);
|
||||
}
|
||||
|
||||
public void Rectangle (double x, double y, double width, double height)
|
||||
{
|
||||
handler.Rectangle (Backend, x, y, width, height);
|
||||
}
|
||||
|
||||
public void RelCurveTo (Distance d1, Distance d2, Distance d3)
|
||||
{
|
||||
RelCurveTo (d1.Dx, d1.Dy, d2.Dx, d2.Dy, d3.Dx, d3.Dy);
|
||||
}
|
||||
|
||||
public void RelCurveTo (double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
|
||||
{
|
||||
handler.RelCurveTo (Backend, dx1, dy1, dx2, dy2, dx3, dy3);
|
||||
}
|
||||
|
||||
public void RelLineTo (Distance d)
|
||||
{
|
||||
RelLineTo (d.Dx, d.Dy);
|
||||
}
|
||||
|
||||
public void RelLineTo (double dx, double dy)
|
||||
{
|
||||
handler.RelLineTo (Backend, dx, dy);
|
||||
}
|
||||
|
||||
public void RelMoveTo (Distance d)
|
||||
{
|
||||
RelMoveTo (d.Dx, d.Dy);
|
||||
}
|
||||
|
||||
public void RelMoveTo (double dx, double dy)
|
||||
{
|
||||
handler.RelMoveTo (Backend, dx, dy);
|
||||
}
|
||||
|
||||
public void Stroke ()
|
||||
{
|
||||
handler.Stroke (Backend);
|
||||
}
|
||||
|
||||
public void StrokePreserve ()
|
||||
{
|
||||
handler.StrokePreserve (Backend);
|
||||
}
|
||||
|
||||
public void SetLineWidth (double width)
|
||||
{
|
||||
handler.SetLineWidth (Backend, width);
|
||||
}
|
||||
|
||||
public void DrawTextLayout (TextLayout layout, double x, double y)
|
||||
{
|
||||
handler.DrawTextLayout (Backend, layout, x, y);
|
||||
}
|
||||
|
||||
public void DrawImage (Image img, double x, double y)
|
||||
{
|
||||
handler.DrawImage (Backend, img, x, y);
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
handler.Dispose (Backend);
|
||||
}
|
||||
|
||||
public Pattern Pattern {
|
||||
get { return pattern; }
|
||||
set { pattern = value; handler.SetPattern (Backend, value); }
|
||||
}
|
||||
|
||||
public Font Font {
|
||||
get { return font; }
|
||||
set { font = value; handler.SetFont (Backend, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// Font.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Engine;
|
||||
|
||||
namespace Xwt.Drawing
|
||||
{
|
||||
public class Font: XwtObject
|
||||
{
|
||||
static IFontBackendHandler handler;
|
||||
|
||||
static Font ()
|
||||
{
|
||||
handler = WidgetRegistry.CreateSharedBackend<IFontBackendHandler> (typeof(Font));
|
||||
}
|
||||
|
||||
public static Font FromName (string name, double size)
|
||||
{
|
||||
Font f = new Font ();
|
||||
f.Backend = handler.CreateFromName (name, size);
|
||||
return f;
|
||||
}
|
||||
|
||||
protected override Xwt.Backends.IBackendHandler BackendHandler {
|
||||
get {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// Gradient.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Engine;
|
||||
|
||||
namespace Xwt.Drawing
|
||||
{
|
||||
public abstract class Gradient: Pattern
|
||||
{
|
||||
static IGradientBackendHandler handler;
|
||||
|
||||
static Gradient ()
|
||||
{
|
||||
handler = WidgetRegistry.CreateSharedBackend<IGradientBackendHandler> (typeof(Gradient));
|
||||
}
|
||||
|
||||
protected override Xwt.Backends.IBackendHandler BackendHandler {
|
||||
get {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddColorStop (double pos, Color color)
|
||||
{
|
||||
handler.AddColorStop (Backend, pos, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
//
|
||||
// HslColor.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Xamarin, Inc (http://www.xamarin.com)
|
||||
//
|
||||
// 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.Drawing
|
||||
{
|
||||
class HslColor
|
||||
{
|
||||
public double H {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public double S {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public double L {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public HslColor ()
|
||||
{
|
||||
}
|
||||
|
||||
public HslColor (double h, double s, double l)
|
||||
{
|
||||
H = h;
|
||||
S = s;
|
||||
L = l;
|
||||
}
|
||||
|
||||
public static implicit operator Color (HslColor hsl)
|
||||
{
|
||||
if (hsl.L > 1) hsl.L = 1;
|
||||
if (hsl.L < 0) hsl.L = 0;
|
||||
if (hsl.H > 1) hsl.H = 1;
|
||||
if (hsl.H < 0) hsl.H = 0;
|
||||
if (hsl.S > 1) hsl.S = 1;
|
||||
if (hsl.S < 0) hsl.S = 0;
|
||||
|
||||
double r = 0, g = 0, b = 0;
|
||||
|
||||
if (hsl.L == 0)
|
||||
return new Color (0f, 0f, 0f);
|
||||
|
||||
if (hsl.S == 0) {
|
||||
r = g = b = hsl.L;
|
||||
} else {
|
||||
double temp2 = hsl.L <= 0.5 ? hsl.L * (1.0 + hsl.S) : hsl.L + hsl.S -(hsl.L * hsl.S);
|
||||
double temp1 = 2.0 * hsl.L - temp2;
|
||||
|
||||
double[] t3 = new double[] { hsl.H + 1.0 / 3.0, hsl.H, hsl.H - 1.0 / 3.0};
|
||||
double[] clr= new double[] { 0, 0, 0};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (t3[i] < 0)
|
||||
t3[i] += 1.0;
|
||||
if (t3[i] > 1)
|
||||
t3[i]-=1.0;
|
||||
if (6.0 * t3[i] < 1.0)
|
||||
clr[i] = temp1 + (temp2 - temp1) * t3[i] * 6.0;
|
||||
else if (2.0 * t3[i] < 1.0)
|
||||
clr[i] = temp2;
|
||||
else if (3.0 * t3[i] < 2.0)
|
||||
clr[i] = (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - t3[i]) * 6.0);
|
||||
else
|
||||
clr[i] = temp1;
|
||||
}
|
||||
|
||||
r = clr[0];
|
||||
g = clr[1];
|
||||
b = clr[2];
|
||||
}
|
||||
return new Color ((byte)(255 * r),
|
||||
(byte)(255 * g),
|
||||
(byte)(255 * b));
|
||||
}
|
||||
|
||||
public static implicit operator HslColor (Color color)
|
||||
{
|
||||
return new HslColor (color);
|
||||
}
|
||||
|
||||
public HslColor (Color color)
|
||||
{
|
||||
double r = color.Red / (double)ushort.MaxValue;
|
||||
double g = color.Green / (double)ushort.MaxValue;
|
||||
double b = color.Blue / (double)ushort.MaxValue;
|
||||
|
||||
double v = System.Math.Max (r, g);
|
||||
v = System.Math.Max (v, b);
|
||||
|
||||
double m = System.Math.Min (r, g);
|
||||
m = System.Math.Min (m, b);
|
||||
|
||||
this.L = (m + v) / 2.0;
|
||||
if (this.L <= 0.0)
|
||||
return;
|
||||
double vm = v - m;
|
||||
this.S = vm;
|
||||
|
||||
if (this.S > 0.0) {
|
||||
this.S /= (this.L <= 0.5) ? (v + m) : (2.0 - v - m);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
double r2 = (v - r) / vm;
|
||||
double g2 = (v - g) / vm;
|
||||
double b2 = (v - b) / vm;
|
||||
|
||||
if (r == v) {
|
||||
this.H = (g == m ? 5.0 + b2 : 1.0 - g2);
|
||||
} else if (g == v) {
|
||||
this.H = (b == m ? 1.0 + r2 : 3.0 - b2);
|
||||
} else {
|
||||
this.H = (r == m ? 3.0 + g2 : 5.0 - r2);
|
||||
}
|
||||
this.H /= 6.0;
|
||||
}
|
||||
|
||||
public static double Brightness (Color c)
|
||||
{
|
||||
double r = c.Red / (double)ushort.MaxValue;
|
||||
double g = c.Green / (double)ushort.MaxValue;
|
||||
double b = c.Blue / (double)ushort.MaxValue;
|
||||
return System.Math.Sqrt (r * .241 + g * .691 + b * .068);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return string.Format ("[HslColor: H={0}, S={1}, L={2}]", H, S, L);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
//
|
||||
// Image.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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 Xwt.Engine;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
|
||||
namespace Xwt.Drawing
|
||||
{
|
||||
public sealed class Image: XwtObject
|
||||
{
|
||||
static ImageBackendHandler handler;
|
||||
|
||||
static Image ()
|
||||
{
|
||||
handler = WidgetRegistry.CreateSharedBackend<ImageBackendHandler> (typeof(Image));
|
||||
}
|
||||
|
||||
protected override IBackendHandler BackendHandler {
|
||||
get {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
internal Image (object backend): base (backend)
|
||||
{
|
||||
}
|
||||
|
||||
public static Image FromResource (Type type, string resource)
|
||||
{
|
||||
return new Image (handler.LoadFromResource (type.Assembly, resource));
|
||||
}
|
||||
|
||||
public static Image FromResource (Assembly asm, string resource)
|
||||
{
|
||||
return new Image (handler.LoadFromResource (asm, resource));
|
||||
}
|
||||
|
||||
public static Image FromFile (string file)
|
||||
{
|
||||
return new Image (handler.LoadFromFile (file));
|
||||
}
|
||||
|
||||
public static Image FromStream (Stream stream)
|
||||
{
|
||||
return new Image (handler.LoadFromStream (stream));
|
||||
}
|
||||
|
||||
public Size Size {
|
||||
get { return handler.GetSize (Backend); }
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
handler.Dispose (Backend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// LinearGradient.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing
|
||||
{
|
||||
public class LinearGradient: Gradient
|
||||
{
|
||||
public LinearGradient (double d1, double d2, double d3, double d4)
|
||||
{
|
||||
Backend = ((IGradientBackendHandler)BackendHandler).CreateLinear (d1,d2,d3,d4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// Pattern.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Drawing
|
||||
{
|
||||
public abstract class Pattern: XwtObject
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
//
|
||||
// TextLayout.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Engine;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.Drawing
|
||||
{
|
||||
public class TextLayout: XwtObject
|
||||
{
|
||||
static ITextLayoutBackendHandler handler;
|
||||
|
||||
Font font;
|
||||
string text;
|
||||
|
||||
static TextLayout ()
|
||||
{
|
||||
handler = WidgetRegistry.CreateSharedBackend<ITextLayoutBackendHandler> (typeof(TextLayout));
|
||||
}
|
||||
|
||||
protected override IBackendHandler BackendHandler {
|
||||
get {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
public TextLayout (Context ctx)
|
||||
{
|
||||
Backend = handler.Create (ctx);
|
||||
}
|
||||
|
||||
public Font Font {
|
||||
get { return font; }
|
||||
set { font = value; handler.SetFont (Backend, value); }
|
||||
}
|
||||
|
||||
public string Text {
|
||||
get { return text; }
|
||||
set { text = value; handler.SetText (Backend, text); }
|
||||
}
|
||||
|
||||
public Size GetSize ()
|
||||
{
|
||||
return handler.GetSize (Backend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// WidgetRegistry.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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;
|
||||
using Xwt.Backends;
|
||||
|
||||
namespace Xwt.Engine
|
||||
{
|
||||
public static class WidgetRegistry
|
||||
{
|
||||
static Dictionary<Type,Type> backendTypes = new Dictionary<Type, Type> ();
|
||||
static Dictionary<Type,object> sharedBackends = new Dictionary<Type, object> ();
|
||||
|
||||
internal static T CreateBackend<T> (Type widgetType)
|
||||
{
|
||||
Type bt;
|
||||
if (!backendTypes.TryGetValue (widgetType, out bt))
|
||||
return default(T);
|
||||
object res = Activator.CreateInstance (bt);
|
||||
if (!typeof(T).IsInstanceOfType (res))
|
||||
throw new InvalidOperationException ("Invalid backend type.");
|
||||
return (T) res;
|
||||
}
|
||||
|
||||
internal static T CreateSharedBackend<T> (Type widgetType)
|
||||
{
|
||||
object res;
|
||||
if (!sharedBackends.TryGetValue (widgetType, out res))
|
||||
res = sharedBackends [widgetType] = CreateBackend<T> (widgetType);
|
||||
return (T)res;
|
||||
}
|
||||
|
||||
public static void RegisterBackend (Type widgetType, Type backendType)
|
||||
{
|
||||
backendTypes [widgetType] = backendType;
|
||||
}
|
||||
|
||||
public static object GetBackend (object obj)
|
||||
{
|
||||
if (obj is XwtComponent)
|
||||
return XwtComponent.GetBackend ((XwtComponent)obj);
|
||||
else if (obj is XwtObject)
|
||||
return XwtObject.GetBackend ((XwtObject)obj);
|
||||
else
|
||||
throw new InvalidOperationException ("Object doesn't have a backend");
|
||||
}
|
||||
|
||||
public static T CreateFrontend<T> (object backend)
|
||||
{
|
||||
return (T) Activator.CreateInstance (typeof(T), backend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Xwt</RootNamespace>
|
||||
<AssemblyName>Xwt</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xaml">
|
||||
<HintPath>System.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Xwt\Widget.cs" />
|
||||
<Compile Include="Xwt\Window.cs" />
|
||||
<Compile Include="Xwt\Button.cs" />
|
||||
<Compile Include="Xwt\Label.cs" />
|
||||
<Compile Include="Xwt.Engine\WidgetRegistry.cs" />
|
||||
<Compile Include="Xwt.Backends\IWidgetBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\ILabelBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\IWindowBackend.cs" />
|
||||
<Compile Include="Xwt\Application.cs" />
|
||||
<Compile Include="Xwt.Backends\EngineBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\IBackend.cs" />
|
||||
<Compile Include="Xwt\XwtComponent.cs" />
|
||||
<Compile Include="Xwt\Box.cs" />
|
||||
<Compile Include="Xwt\WidgetCollection.cs" />
|
||||
<Compile Include="Xwt.Backends\IContainerBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\IBoxBackend.cs" />
|
||||
<Compile Include="Xwt\HBox.cs" />
|
||||
<Compile Include="Xwt\VBox.cs" />
|
||||
<Compile Include="Xwt\Table.cs" />
|
||||
<Compile Include="Xwt.Backends\IButtonBackend.cs" />
|
||||
<Compile Include="Xwt\Notebook.cs" />
|
||||
<Compile Include="Xwt.Backends\INotebookBackend.cs" />
|
||||
<Compile Include="Xwt\Paned.cs" />
|
||||
<Compile Include="Xwt\VPaned.cs" />
|
||||
<Compile Include="Xwt\HPaned.cs" />
|
||||
<Compile Include="Xwt.Backends\IPanedBackend.cs" />
|
||||
<Compile Include="Xwt\HScale.cs" />
|
||||
<Compile Include="Xwt\TextView.cs" />
|
||||
<Compile Include="Xwt\TreeView.cs" />
|
||||
<Compile Include="Xwt\DataStore.cs" />
|
||||
<Compile Include="Xwt\SizeRequestMode.cs" />
|
||||
<Compile Include="Xwt\Rectangle.cs" />
|
||||
<Compile Include="Xwt\Point.cs" />
|
||||
<Compile Include="Xwt\Size.cs" />
|
||||
<Compile Include="Xwt\WidgetSize.cs" />
|
||||
<Compile Include="Xwt\Alignment.cs" />
|
||||
<Compile Include="Xwt.Drawing\Image.cs" />
|
||||
<Compile Include="Xwt\ITreeViewSource.cs" />
|
||||
<Compile Include="Xwt\TreeStore.cs" />
|
||||
<Compile Include="Xwt\DataField.cs" />
|
||||
<Compile Include="Xwt\TreeNavigator.cs" />
|
||||
<Compile Include="Xwt\TreePosition.cs" />
|
||||
<Compile Include="Xwt\CellViewCollection.cs" />
|
||||
<Compile Include="Xwt\CellView.cs" />
|
||||
<Compile Include="Xwt\TextCellView.cs" />
|
||||
<Compile Include="Xwt\IconTextCellView.cs" />
|
||||
<Compile Include="Xwt\ComboBoxCellView.cs" />
|
||||
<Compile Include="Xwt.Backends\ITreeViewBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\ITreeStoreBackend.cs" />
|
||||
<Compile Include="Xwt\XwtObject.cs" />
|
||||
<Compile Include="Xwt.Backends\IBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Backends\ImageBackendHandler.cs" />
|
||||
<Compile Include="Xwt\ImageCellView.cs" />
|
||||
<Compile Include="Xwt.Drawing\Context.cs" />
|
||||
<Compile Include="Xwt\Distance.cs" />
|
||||
<Compile Include="Xwt.Backends\IContextBackendHandler.cs" />
|
||||
<Compile Include="Xwt\Canvas.cs" />
|
||||
<Compile Include="Xwt.Backends\ICanvasBackend.cs" />
|
||||
<Compile Include="Xwt.Drawing\Color.cs" />
|
||||
<Compile Include="Xwt.Drawing\HslColor.cs" />
|
||||
<Compile Include="Xwt.Drawing\LinearGradient.cs" />
|
||||
<Compile Include="Xwt.Drawing\Pattern.cs" />
|
||||
<Compile Include="Xwt.Drawing\Gradient.cs" />
|
||||
<Compile Include="Xwt.Drawing\TextLayout.cs" />
|
||||
<Compile Include="Xwt.Drawing\Font.cs" />
|
||||
<Compile Include="Xwt.Backends\IGradientBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Backends\IFontBackendHandler.cs" />
|
||||
<Compile Include="Xwt.Backends\ITextLayoutBackendHandler.cs" />
|
||||
<Compile Include="Xwt\ButtonEventArgs.cs" />
|
||||
<Compile Include="Xwt\MouseMovedEventArgs.cs" />
|
||||
<Compile Include="Xwt\SelectionMode.cs" />
|
||||
<Compile Include="Xwt\ListViewColumn.cs" />
|
||||
<Compile Include="Xwt\ListViewColumnCollection.cs" />
|
||||
<Compile Include="Xwt\ListView.cs" />
|
||||
<Compile Include="Xwt.Backends\IListViewBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\IColumnContainerBackend.cs" />
|
||||
<Compile Include="Xwt\IListViewSource.cs" />
|
||||
<Compile Include="Xwt\ListStore.cs" />
|
||||
<Compile Include="Xwt.Backends\IListStoreBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\ITableViewBackend.cs" />
|
||||
<Compile Include="Xwt\CheckBoxCellView.cs" />
|
||||
<Compile Include="Xwt.Design\DesignerSurface.cs" />
|
||||
<Compile Include="Xwt.Backends\IDesignerSurfaceBackend.cs" />
|
||||
<Compile Include="Xwt\Menu.cs" />
|
||||
<Compile Include="Xwt\MenuItem.cs" />
|
||||
<Compile Include="Xwt\MenuItemCollection.cs" />
|
||||
<Compile Include="Xwt.Backends\IMenuBackend.cs" />
|
||||
<Compile Include="Xwt.Backends\IMenuItemBackend.cs" />
|
||||
<Compile Include="Xwt\IWidgetSurface.cs" />
|
||||
<Compile Include="Xwt\ChildrenCollection.cs" />
|
||||
<Compile Include="Xwt\IContainerEventSink.cs" />
|
||||
<Compile Include="Xwt\DragDropAction.cs" />
|
||||
<Compile Include="Xwt\DragOperation.cs" />
|
||||
<Compile Include="Xwt\DragEventArgs.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Xwt\" />
|
||||
<Folder Include="Xwt.Engine\" />
|
||||
<Folder Include="Xwt.Backends\" />
|
||||
<Folder Include="Xwt.Drawing\" />
|
||||
<Folder Include="Xwt.Design\" />
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<MonoDevelop>
|
||||
<Properties>
|
||||
<Policies>
|
||||
<DotNetNamingPolicy DirectoryNamespaceAssociation="Flat" ResourceNamePolicy="FileFormatDefault" />
|
||||
</Policies>
|
||||
</Properties>
|
||||
</MonoDevelop>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// Alignment.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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
|
||||
{
|
||||
public enum Alignment
|
||||
{
|
||||
Start,
|
||||
Center,
|
||||
End
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
//
|
||||
// Application.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Reflection;
|
||||
using Xwt.Backends;
|
||||
using Xwt.Engine;
|
||||
|
||||
namespace Xwt
|
||||
{
|
||||
public static class Application
|
||||
{
|
||||
static EngineBackend engine;
|
||||
|
||||
public static void Initialize ()
|
||||
{
|
||||
if (engine != null)
|
||||
return;
|
||||
InitBackend (null);
|
||||
engine.InitializeApplication ();
|
||||
}
|
||||
|
||||
public static void Initialize (string backendType)
|
||||
{
|
||||
InitBackend (backendType);
|
||||
engine.InitializeApplication ();
|
||||
}
|
||||
|
||||
public static void Run ()
|
||||
{
|
||||
engine.RunApplication ();
|
||||
}
|
||||
|
||||
public static void Invoke (Action action)
|
||||
{
|
||||
engine.Invoke (action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method after the provided time span
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A timer object
|
||||
/// </returns>
|
||||
/// <param name='action'>
|
||||
/// The action to execute.
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// This method schedules the execution of the provided function. The function
|
||||
/// must return 'true' if it has to be executed again after the time span, or 'false'
|
||||
/// if the timer can be discarded.
|
||||
/// The execution of the funciton can be canceled by disposing the returned object.
|
||||
/// </remarks>
|
||||
public static IDisposable TimeoutInvoke (Func<bool> action, TimeSpan timeSpan)
|
||||
{
|
||||
Timer t = new Timer ();
|
||||
t.Id = engine.TimeoutInvoke (action, timeSpan);
|
||||
return t;
|
||||
}
|
||||
|
||||
class Timer: IDisposable
|
||||
{
|
||||
public object Id;
|
||||
public void Dispose ()
|
||||
{
|
||||
Application.engine.CancelTimeoutInvoke (Id);
|
||||
}
|
||||
}
|
||||
|
||||
static bool LoadBackend (string type)
|
||||
{
|
||||
int i = type.IndexOf (',');
|
||||
string assembly = type.Substring (i+1).Trim ();
|
||||
type = type.Substring (0, i).Trim ();
|
||||
try {
|
||||
Assembly asm = Assembly.Load (assembly);
|
||||
if (asm != null) {
|
||||
Type t = asm.GetType (type);
|
||||
if (t != null) {
|
||||
engine = (EngineBackend) Activator.CreateInstance (t);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void InitBackend (string type)
|
||||
{
|
||||
if (type != null && LoadBackend (type))
|
||||
return;
|
||||
|
||||
if (LoadBackend ("Xwt.GtkBackend.GtkEngine, Xwt.Gtk, Version=1.0.0.0"))
|
||||
return;
|
||||
|
||||
if (LoadBackend ("Xwt.Mac.MacEngine, Xwt.Mac, Version=1.0.0.0"))
|
||||
return;
|
||||
|
||||
throw new InvalidOperationException ("Xwt engine not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,430 @@
|
|||
//
|
||||
// Box.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using Xwt.Backends;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Xwt
|
||||
{
|
||||
public class Box: Widget
|
||||
{
|
||||
ChildrenCollection<BoxPlacement> children;
|
||||
Orientation direction;
|
||||
double spacing = 6;
|
||||
|
||||
protected new class EventSink: Widget.EventSink, ICollectionEventSink<BoxPlacement>, IContainerEventSink<BoxPlacement>
|
||||
{
|
||||
public void AddedItem (BoxPlacement item, int index)
|
||||
{
|
||||
((Box)Parent).OnAdd (item.Child, item);
|
||||
}
|
||||
|
||||
public void RemovedItem (BoxPlacement item, int index)
|
||||
{
|
||||
((Box)Parent).OnRemove (item.Child);
|
||||
}
|
||||
|
||||
public void ChildChanged (BoxPlacement child, string hint)
|
||||
{
|
||||
((Box)Parent).OnChildChanged (child, hint);
|
||||
}
|
||||
|
||||
public void ChildReplaced (BoxPlacement child, Widget oldWidget, Widget newWidget)
|
||||
{
|
||||
((Box)Parent).OnReplaceChild (child, oldWidget, newWidget);
|
||||
}
|
||||
}
|
||||
|
||||
protected override Widget.EventSink CreateEventSink ()
|
||||
{
|
||||
return new EventSink ();
|
||||
}
|
||||
|
||||
new IBoxBackend Backend {
|
||||
get { return (IBoxBackend) base.Backend; }
|
||||
}
|
||||
|
||||
internal Box (Orientation dir)
|
||||
{
|
||||
children = new ChildrenCollection<BoxPlacement> ((EventSink)WidgetEventSink);
|
||||
direction = dir;
|
||||
}
|
||||
|
||||
public ChildrenCollection<BoxPlacement> Placements {
|
||||
get { return children; }
|
||||
}
|
||||
|
||||
public IEnumerable<Widget> Children {
|
||||
get { return children.Select (c => c.Child); }
|
||||
}
|
||||
|
||||
public void PackStart (Widget widget)
|
||||
{
|
||||
PackStart (widget, BoxMode.None, 0);
|
||||
}
|
||||
|
||||
public void PackStart (Widget widget, BoxMode mode)
|
||||
{
|
||||
PackStart (widget, mode, 0);
|
||||
}
|
||||
|
||||
public void PackStart (Widget widget, BoxMode mode, int padding)
|
||||
{
|
||||
Pack (widget, mode, padding, PackType.Start);
|
||||
}
|
||||
|
||||
public void PackEnd (Widget widget)
|
||||
{
|
||||
PackEnd (widget, BoxMode.None, 0);
|
||||
}
|
||||
|
||||
public void PackEnd (Widget widget, BoxMode mode)
|
||||
{
|
||||
PackEnd (widget, mode, 0);
|
||||
}
|
||||
|
||||
public void PackEnd (Widget widget, BoxMode mode, int padding)
|
||||
{
|
||||
Pack (widget, mode, padding, PackType.End);
|
||||
}
|
||||
|
||||
void Pack (Widget widget, BoxMode mode, int padding, PackType ptype)
|
||||
{
|
||||
var p = new BoxPlacement ((EventSink)WidgetEventSink, widget);
|
||||
p.BoxMode = mode;
|
||||
p.Padding = padding;
|
||||
p.PackType = ptype;
|
||||
children.Add (p);
|
||||
}
|
||||
|
||||
public bool Remove (Widget widget)
|
||||
{
|
||||
for (int n=0; n<children.Count; n++) {
|
||||
if (children[n].Child == widget) {
|
||||
children.RemoveAt (n);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnAdd (Widget child, BoxPlacement placement)
|
||||
{
|
||||
RegisterChild (child);
|
||||
Backend.Add ((IWidgetBackend)GetBackend (child));
|
||||
OnPreferredSizeChanged ();
|
||||
}
|
||||
|
||||
void OnRemove (Widget child)
|
||||
{
|
||||
UnregisterChild (child);
|
||||
Backend.Remove ((IWidgetBackend)GetBackend (child));
|
||||
OnPreferredSizeChanged ();
|
||||
}
|
||||
|
||||
void OnChildChanged (BoxPlacement placement, object hint)
|
||||
{
|
||||
OnPreferredSizeChanged ();
|
||||
}
|
||||
|
||||
internal protected virtual void OnReplaceChild (BoxPlacement placement, Widget oldWidget, Widget newWidget)
|
||||
{
|
||||
if (oldWidget != null)
|
||||
OnRemove (oldWidget);
|
||||
OnAdd (newWidget, placement);
|
||||
}
|
||||
|
||||
protected override void OnReallocate ()
|
||||
{
|
||||
var size = Backend.Size;
|
||||
if (direction == Orientation.Horizontal) {
|
||||
CalcDefaultSizes (((IWidgetSurface)this).SizeRequestMode, size.Width, size.Height);
|
||||
double x = 0;
|
||||
foreach (var bp in children) {
|
||||
Backend.SetAllocation ((IWidgetBackend)GetBackend (bp.Child), new Rectangle (x, 0, bp.NextSize, size.Height));
|
||||
((IWidgetSurface)bp.Child).Reallocate ();
|
||||
x += bp.NextSize + spacing;
|
||||
}
|
||||
} else {
|
||||
CalcDefaultSizes (((IWidgetSurface)this).SizeRequestMode, size.Height, size.Width);
|
||||
double y = 0;
|
||||
foreach (var bp in children) {
|
||||
Backend.SetAllocation ((IWidgetBackend)GetBackend (bp.Child), new Rectangle (0, y, size.Width, bp.NextSize));
|
||||
((IWidgetSurface)bp.Child).Reallocate ();
|
||||
y += bp.NextSize + spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CalcDefaultSizes (SizeRequestMode mode, double totalSize, double lengthConstraint)
|
||||
{
|
||||
bool calcHeights = direction == Orientation.Vertical;
|
||||
bool useLengthConstraint = mode == SizeRequestMode.HeightForWidth && calcHeights || mode == SizeRequestMode.WidthForHeight && !calcHeights;
|
||||
int nexpands = 0;
|
||||
double naturalSize = 0;
|
||||
|
||||
// Get the natural size of each child
|
||||
foreach (var bp in children) {
|
||||
WidgetSize s;
|
||||
if (useLengthConstraint)
|
||||
s = GetPreferredLengthForSize (mode, bp.Child, lengthConstraint);
|
||||
else
|
||||
s = GetPreferredSize (calcHeights, bp.Child);
|
||||
naturalSize += s.NaturalSize;
|
||||
bp.NextSize = s.NaturalSize;
|
||||
if ((bp.BoxMode & BoxMode.Expand) != 0)
|
||||
nexpands++;
|
||||
}
|
||||
|
||||
if (nexpands == 0) {
|
||||
Console.WriteLine ();
|
||||
}
|
||||
|
||||
double remaining = totalSize - naturalSize - (spacing * (double)(children.Count - 1));
|
||||
if (remaining < 0) {
|
||||
// The box is not big enough to fit the widgets using its natural size.
|
||||
// We have to shrink the widgets.
|
||||
var sizePart = new SizeSplitter (-remaining, children.Count);
|
||||
var toAdjust = new List<BoxPlacement> ();
|
||||
double adjustSize = 0;
|
||||
foreach (var bp in children) {
|
||||
WidgetSize s;
|
||||
if (useLengthConstraint)
|
||||
s = GetPreferredLengthForSize (mode, bp.Child, lengthConstraint);
|
||||
else
|
||||
s = GetPreferredSize (calcHeights, bp.Child);
|
||||
bp.NextSize = s.NaturalSize - sizePart.NextSizePart ();
|
||||
if (bp.NextSize < s.MinSize) {
|
||||
adjustSize += (s.MinSize - bp.NextSize);
|
||||
bp.NextSize = s.MinSize;
|
||||
} else
|
||||
toAdjust.Add (bp);
|
||||
}
|
||||
sizePart = new SizeSplitter (adjustSize, toAdjust.Count);
|
||||
foreach (var bp in toAdjust)
|
||||
bp.NextSize += sizePart.NextSizePart ();
|
||||
}
|
||||
else {
|
||||
var expandRemaining = new SizeSplitter (remaining, nexpands);
|
||||
foreach (var bp in children) {
|
||||
if ((bp.BoxMode & BoxMode.Expand) != 0)
|
||||
bp.NextSize += expandRemaining.NextSizePart ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override WidgetSize OnGetPreferredWidth ()
|
||||
{
|
||||
WidgetSize s = new WidgetSize ();
|
||||
|
||||
if (direction == Orientation.Horizontal) {
|
||||
foreach (IWidgetSurface cw in Children)
|
||||
s += cw.GetPreferredWidth ();
|
||||
s += spacing * (double)(children.Count - 1);
|
||||
} else {
|
||||
foreach (IWidgetSurface cw in Children)
|
||||
s.UnionWith (cw.GetPreferredWidth ());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
protected override WidgetSize OnGetPreferredHeight ()
|
||||
{
|
||||
WidgetSize s = new WidgetSize ();
|
||||
|
||||
if (direction == Orientation.Vertical) {
|
||||
foreach (IWidgetSurface cw in Children)
|
||||
s += cw.GetPreferredHeight ();
|
||||
s += spacing * (double)(children.Count - 1);
|
||||
} else {
|
||||
foreach (IWidgetSurface cw in Children)
|
||||
s.UnionWith (cw.GetPreferredHeight ());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
protected override WidgetSize OnGetPreferredHeightForWidth (double width)
|
||||
{
|
||||
return GetPreferredLengthForSize (SizeRequestMode.HeightForWidth, width);
|
||||
}
|
||||
|
||||
protected override WidgetSize OnGetPreferredWidthForHeight (double height)
|
||||
{
|
||||
return GetPreferredLengthForSize (SizeRequestMode.WidthForHeight, height);
|
||||
}
|
||||
|
||||
WidgetSize GetPreferredLengthForSize (SizeRequestMode mode, double width)
|
||||
{
|
||||
WidgetSize s = new WidgetSize ();
|
||||
|
||||
if ((direction == Orientation.Horizontal && mode == SizeRequestMode.HeightForWidth) || (direction == Orientation.Vertical && mode == SizeRequestMode.WidthForHeight)) {
|
||||
CalcDefaultSizes (mode, width, -1);
|
||||
foreach (var bp in children) {
|
||||
s.UnionWith (GetPreferredLengthForSize (mode, bp.Child, bp.NextSize));
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach (var bp in children)
|
||||
s += GetPreferredLengthForSize (mode, bp.Child, width);
|
||||
s += spacing * (double)(children.Count - 1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
WidgetSize GetPreferredSize (bool calcHeight, Widget w)
|
||||
{
|
||||
if (calcHeight)
|
||||
return ((IWidgetSurface)w).GetPreferredHeight ();
|
||||
else
|
||||
return ((IWidgetSurface)w).GetPreferredWidth ();
|
||||
}
|
||||
|
||||
WidgetSize GetPreferredLengthForSize (SizeRequestMode mode, Widget w, double width)
|
||||
{
|
||||
IWidgetSurface surface = w;
|
||||
if (mode == SizeRequestMode.WidthForHeight)
|
||||
return surface.GetPreferredWidthForHeight (width);
|
||||
else
|
||||
return surface.GetPreferredHeightForWidth (width);
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum BoxMode
|
||||
{
|
||||
None = 0,
|
||||
Fill = 1,
|
||||
Expand = 2,
|
||||
FillAndExpand = 3
|
||||
}
|
||||
|
||||
[ContentProperty("Child")]
|
||||
public class BoxPlacement
|
||||
{
|
||||
IContainerEventSink<BoxPlacement> parent;
|
||||
int position;
|
||||
BoxMode boxMode = BoxMode.None;
|
||||
int padding;
|
||||
PackType packType = PackType.Start;
|
||||
Widget child;
|
||||
|
||||
internal BoxPlacement (IContainerEventSink<BoxPlacement> parent, Widget child)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
internal double NextSize;
|
||||
|
||||
public int Position {
|
||||
get {
|
||||
return this.position;
|
||||
}
|
||||
set {
|
||||
position = value;
|
||||
parent.ChildChanged (this, "Position");
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue (BoxMode.None)]
|
||||
public BoxMode BoxMode {
|
||||
get {
|
||||
return this.boxMode;
|
||||
}
|
||||
set {
|
||||
boxMode = value;
|
||||
parent.ChildChanged (this, "BoxMode");
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue (0)]
|
||||
public int Padding {
|
||||
get {
|
||||
return this.padding;
|
||||
}
|
||||
set {
|
||||
padding = value;
|
||||
parent.ChildChanged (this, "Padding");
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue (PackType.Start)]
|
||||
public PackType PackType {
|
||||
get {
|
||||
return this.packType;
|
||||
}
|
||||
set {
|
||||
packType = value;
|
||||
parent.ChildChanged (this, "PackType");
|
||||
}
|
||||
}
|
||||
|
||||
public Widget Child {
|
||||
get { return child; }
|
||||
set {
|
||||
var old = child;
|
||||
child = value;
|
||||
parent.ChildReplaced (this, old, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum PackType
|
||||
{
|
||||
Start,
|
||||
End
|
||||
}
|
||||
|
||||
class SizeSplitter
|
||||
{
|
||||
int rem;
|
||||
int part;
|
||||
|
||||
public SizeSplitter (double total, int numParts)
|
||||
{
|
||||
if (numParts > 0) {
|
||||
part = ((int)total) / numParts;
|
||||
rem = ((int)total) % numParts;
|
||||
}
|
||||
}
|
||||
|
||||
public double NextSizePart ()
|
||||
{
|
||||
if (rem > 0) {
|
||||
rem--;
|
||||
return part + 1;
|
||||
}
|
||||
else
|
||||
return part;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
//
|
||||
// Button.cs
|
||||
//
|
||||
// Author:
|
||||
// Lluis Sanchez <lluis@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 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
|
||||
{
|
||||
public class Button: Widget
|
||||
{
|
||||
EventHandler clicked;
|
||||
|
||||
protected new class EventSink: Widget.EventSink, IButtonEventSink
|
||||
{
|
||||
public void OnClicked ()
|
||||
{
|
||||
((Button)Parent).OnClicked (EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
static Button ()
|
||||
{
|
||||
MapEvent (ButtonEvent.Clicked, typeof(Button), "OnClicked");
|
||||
}
|
||||
|
||||
public Button ()
|
||||
{
|
||||
}
|
||||
|
||||
public Button (string label): this ()
|
||||
{
|
||||
Label = label;
|
||||
}
|
||||
|
||||
protected override Widget.EventSink CreateEventSink ()
|
||||
{
|
||||
return new EventSink ();
|
||||
}
|
||||
|
||||
new IButtonBackend Backend {
|
||||
get { return (IButtonBackend) base.Backend; }
|
||||
}
|
||||
|
||||
public string Label {
|
||||
get { return Backend.Label; }
|
||||
set { Backend.Label = value; }
|
||||
}
|
||||
|
||||
protected override void OnBackendCreated ()
|
||||
{
|
||||
base.OnBackendCreated ();
|
||||
Backend.Initialize ((EventSink)WidgetEventSink);
|
||||
}
|
||||
|
||||
protected virtual void OnClicked (EventArgs e)
|
||||
{
|
||||
if (clicked != null)
|
||||
clicked (this, e);
|
||||
}
|
||||
|
||||
public event EventHandler Clicked {
|
||||
add {
|
||||
OnBeforeEventAdd (ButtonEvent.Clicked, clicked);
|
||||
clicked += value;
|
||||
}
|
||||
remove {
|
||||
clicked -= value;
|
||||
OnAfterEventRemove (ButtonEvent.Clicked, clicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче