Ongoing work in the mac backend

This commit is contained in:
Lluis Sanchez 2012-02-02 09:32:16 +01:00
Родитель 38d3ad497b
Коммит 16323e309c
25 изменённых файлов: 835 добавлений и 94 удалений

Просмотреть файл

@ -191,11 +191,11 @@ namespace Xwt.GtkBackend
ctx.SetDash (pattern, offset);
}
public void SetPattern (object backend, Pattern p)
public void SetPattern (object backend, object p)
{
Cairo.Context ctx = ((GtkContext)backend).Context;
if (p != null)
ctx.Pattern = (Cairo.Pattern)WidgetRegistry.GetBackend (p);
ctx.Pattern = (Cairo.Pattern) p;
else
ctx.Pattern = null;
}
@ -212,9 +212,9 @@ namespace Xwt.GtkBackend
Pango.CairoHelper.ShowLayout (ctx.Context, pl);
}
public void DrawImage (object backend, Image img, double x, double y, double alpha)
public void DrawImage (object backend, object img, double x, double y, double alpha)
{
Gdk.Pixbuf pb = (Gdk.Pixbuf)WidgetRegistry.GetBackend (img);
Gdk.Pixbuf pb = (Gdk.Pixbuf)img;
GtkContext ctx = (GtkContext)backend;
Gdk.CairoHelper.SetSourcePixbuf (ctx.Context, pb, x, y);
if (alpha == 1)
@ -223,13 +223,13 @@ namespace Xwt.GtkBackend
ctx.Context.PaintWithAlpha (alpha);
}
public void DrawImage (object backend, Image img, double x, double y, double width, double height, double alpha)
public void DrawImage (object backend, object img, double x, double y, double width, double height, double alpha)
{
Gdk.Pixbuf pb = (Gdk.Pixbuf)WidgetRegistry.GetBackend (img);
Gdk.Pixbuf pb = (Gdk.Pixbuf)img;
GtkContext ctx = (GtkContext)backend;
ctx.Context.Save ();
double sx = ((double) width) / img.Size.Width;
double sy = ((double) height) / img.Size.Height;
double sx = ((double) width) / pb.Width;
double sy = ((double) height) / pb.Height;
ctx.Context.Translate (x, y);
ctx.Context.Scale (sx, sy);
Gdk.CairoHelper.SetSourcePixbuf (ctx.Context, pb, 0, 0);

Просмотреть файл

@ -71,6 +71,14 @@
<Compile Include="Xwt.Mac\ComboBoxBackend.cs" />
<Compile Include="Xwt.Mac\TextEntryBackend.cs" />
<Compile Include="Xwt.Mac\ImageViewBackend.cs" />
<Compile Include="Xwt.Mac\CheckBoxMenuItemBackend.cs" />
<Compile Include="Xwt.Mac\RadioButtonMenuItemBackend.cs" />
<Compile Include="Xwt.Mac\SeparatorMenuItemBackend.cs" />
<Compile Include="Xwt.Mac\CheckBoxBackend.cs" />
<Compile Include="Xwt.Mac\ComboBoxEntryBackend.cs" />
<Compile Include="Xwt.Mac\ImageBuilderBackendHandler.cs" />
<Compile Include="Xwt.Mac\ImagePatternBackendHandler.cs" />
<Compile Include="Xwt.Mac\FrameBackend.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
@ -83,5 +91,23 @@
<ItemGroup>
<Folder Include="Xwt.Mac\" />
<Folder Include="Xwt.Mac.CellViews\" />
<Folder Include="icons\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="icons\magnifier-zoom-in.png">
<LogicalName>magnifier-zoom-in.png</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="icons\magnifier-zoom-out.png">
<LogicalName>magnifier-zoom-out.png</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<DotNetNamingPolicy DirectoryNamespaceAssociation="None" ResourceNamePolicy="FileName" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project>

Просмотреть файл

@ -41,23 +41,23 @@ namespace Xwt.Mac
#region IButtonBackend implementation
public override void Initialize ()
{
ViewObject = new Button (EventSink);
ViewObject = new MacButton (EventSink);
Widget.SizeToFit ();
}
public void EnableEvent (Xwt.Backends.ButtonEvent ev)
{
((Button)Widget).EnableEvent (ev);
((MacButton)Widget).EnableEvent (ev);
}
public void DisableEvent (Xwt.Backends.ButtonEvent ev)
{
((Button)Widget).DisableEvent (ev);
((MacButton)Widget).DisableEvent (ev);
}
public void SetContent (string label, object imageBackend, ContentPosition imagePosition)
{
Widget.Title = label;
Widget.Title = label ?? "";
if (imageBackend != null) {
Widget.Image = (NSImage)imageBackend;
switch (imagePosition) {
@ -92,13 +92,13 @@ namespace Xwt.Mac
#endregion
}
class Button: NSButton, IViewObject<NSButton>
class MacButton: NSButton, IViewObject<NSButton>
{
public Button (IntPtr p): base (p)
public MacButton (IntPtr p): base (p)
{
}
public Button (IButtonEventSink eventSink)
public MacButton (IButtonEventSink eventSink)
{
BezelStyle = NSBezelStyle.Rounded;
Activated += delegate {
@ -108,6 +108,15 @@ namespace Xwt.Mac
};
}
public MacButton (ICheckBoxEventSink eventSink)
{
Activated += delegate {
Toolkit.Invoke (delegate {
eventSink.OnClicked ();
});
};
}
public Widget Frontend { get; set; }
public NSButton View {

Просмотреть файл

@ -0,0 +1,84 @@
//
// CheckBoxBackend.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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 CheckBoxBackend: ViewBackend<NSButton,ICheckBoxEventSink>, ICheckBoxBackend
{
public CheckBoxBackend ()
{
}
public override void Initialize ()
{
ViewObject = new MacButton (EventSink);
ViewObject.View.SetButtonType (NSButtonType.Switch);
Widget.SizeToFit ();
}
#region ICheckBoxBackend implementation
public void SetContent (IWidgetBackend widget)
{
}
public void SetContent (string label)
{
Widget.Title = label;
}
public bool Active {
get {
return Widget.State == NSCellStateValue.On;
}
set {
Widget.State = value ? NSCellStateValue.On : NSCellStateValue.Off;
}
}
public bool Mixed {
get {
return Widget.State == NSCellStateValue.Mixed;
}
set {
Widget.State = value ? NSCellStateValue.Mixed : NSCellStateValue.Off;
}
}
public bool AllowMixed {
get {
return Widget.AllowsMixedState;
}
set {
Widget.AllowsMixedState = value;
}
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,38 @@
//
// CheckBoxMenuItemBackend.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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.Mac
{
public class CheckBoxMenuItemBackend: MenuItemBackend, ICheckBoxMenuItemBackend
{
public CheckBoxMenuItemBackend ()
{
}
}
}

Просмотреть файл

@ -161,7 +161,7 @@ namespace Xwt.Mac
void UpdateItem (NSMenuItem mi, int index)
{
mi.Title = (string) source.GetValue (index, 0);
mi.Title = (string) source.GetValue (index, 0) ?? "";
}
public int SelectedRow {

Просмотреть файл

@ -0,0 +1,150 @@
//
// ComboBoxEntryBackend.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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 ComboBoxEntryBackend: ViewBackend<NSComboBox,IComboBoxEventSink>, IComboBoxEntryBackend
{
IListDataSource source;
ComboDataSource tsource;
TextEntryBackend entryBackend;
public ComboBoxEntryBackend ()
{
}
public override void Initialize ()
{
base.Initialize ();
ViewObject = new MacComboBox (EventSink);
Widget.SizeToFit ();
}
#region IComboBoxEntryBackend implementation
public ITextEntryBackend TextEntryBackend {
get {
if (entryBackend == null)
entryBackend = new Xwt.Mac.TextEntryBackend ((MacComboBox)ViewObject);
return entryBackend;
}
}
#endregion
#region IComboBoxBackend implementation
public void SetViews (CellViewCollection views)
{
}
public void SetSource (IListDataSource source, IBackend sourceBackend)
{
this.source = source;
tsource = new ComboDataSource (source);
Widget.UsesDataSource = true;
Widget.DataSource = tsource;
}
public int SelectedRow {
get {
return Widget.SelectedIndex;
}
set {
Widget.SelectItem (value);
}
}
#endregion
}
class MacComboBox: NSComboBox, IViewObject<NSComboBox>, IViewObject<NSTextField>
{
IComboBoxEventSink eventSink;
ITextEntryEventSink entryEventSink;
public MacComboBox (IComboBoxEventSink eventSink)
{
this.eventSink = eventSink;
}
public void SetEntryEventSink (ITextEntryEventSink entryEventSink)
{
this.entryEventSink = entryEventSink;
}
#region IViewObject implementation
NSComboBox IViewObject<NSComboBox>.View {
get {
return this;
}
}
public Widget Frontend { get; set; }
#endregion
#region IViewObject implementation
NSTextField IViewObject<NSTextField>.View {
get {
return this;
}
}
#endregion
public override void DidChange (MonoMac.Foundation.NSNotification notification)
{
base.DidChange (notification);
if (entryEventSink != null) {
Toolkit.Invoke (delegate {
entryEventSink.OnChanged ();
});
}
}
}
class ComboDataSource: NSComboBoxDataSource
{
IListDataSource source;
public ComboDataSource (IListDataSource source)
{
this.source = source;
}
public override NSObject ObjectValueForItem (NSComboBox comboBox, int index)
{
return NSObject.FromObject (source.GetValue (index, 0));
}
public override int ItemCount (NSComboBox comboBox)
{
return source.RowCount;
}
}
}

Просмотреть файл

@ -30,6 +30,7 @@ using Xwt.Engine;
using MonoMac.AppKit;
using Xwt.Drawing;
using MonoMac.Foundation;
using System.Drawing;
namespace Xwt.Mac
{
@ -39,38 +40,39 @@ namespace Xwt.Mac
{
}
public class ContextInfo
{
public NSBezierPath Path;
public Pattern Pattern;
}
public object CreateContext (Widget w)
{
ContextInfo c = new ContextInfo ();
c.Path = new NSBezierPath ();
return c;
return new ContextInfo ();
}
ContextInfo GetContext (object backend)
{
var ctx = (ContextInfo) backend;
ctx.SetFocus ();
return ctx;
}
public void Save (object backend)
{
GetContext (backend);
NSGraphicsContext.CurrentContext.SaveGraphicsState ();
}
public void Restore (object backend)
{
GetContext (backend);
NSGraphicsContext.CurrentContext.RestoreGraphicsState ();
}
public void Arc (object backend, double xc, double yc, double radius, double angle1, double angle2)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (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;
var ctx = GetContext (backend);
ctx.Path.AddClip ();
ctx.Path.Dispose ();
ctx.Path = new NSBezierPath ();
@ -78,12 +80,13 @@ namespace Xwt.Mac
public void ClipPreserve (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
ctx.Path.AddClip ();
}
public void ResetClip (object backend)
{
GetContext (backend);
var path = new NSBezierPath ();
path.AppendPathWithRect (new System.Drawing.RectangleF (0, 0, float.MaxValue, float.MaxValue));
path.SetClip ();
@ -91,13 +94,13 @@ namespace Xwt.Mac
public void ClosePath (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (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;
var ctx = GetContext (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));
@ -105,12 +108,17 @@ namespace Xwt.Mac
public void Fill (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
if (ctx.Pattern is Gradient) {
GradientInfo gr = (GradientInfo) WidgetRegistry.GetBackend (ctx.Pattern);
var ctx = GetContext (backend);
if (ctx.Pattern is GradientInfo) {
GradientInfo gr = (GradientInfo) ctx.Pattern;
NSGradient g = new NSGradient (gr.Colors.ToArray (), gr.Stops.ToArray ());
g.DrawInBezierPath (ctx.Path, 0f);
}
else if (ctx.Pattern is NSColor) {
NSColor col = (NSColor) ctx.Pattern;
col.Set ();
col.SetFill ();
}
else {
ctx.Path.Fill ();
}
@ -121,7 +129,7 @@ namespace Xwt.Mac
public void FillPreserve (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
NSGraphicsContext.CurrentContext.SaveGraphicsState ();
ctx.Path.Fill ();
NSGraphicsContext.CurrentContext.RestoreGraphicsState ();
@ -129,31 +137,31 @@ namespace Xwt.Mac
public void LineTo (object backend, double x, double y)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (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;
var ctx = GetContext (backend);
ctx.Path.MoveTo (new System.Drawing.PointF ((float)x, (float)y));
}
public void NewPath (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
ctx.Path = new NSBezierPath ();
}
public void Rectangle (object backend, double x, double y, double width, double height)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (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;
var ctx = GetContext (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));
@ -161,19 +169,19 @@ namespace Xwt.Mac
public void RelLineTo (object backend, double dx, double dy)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (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;
var ctx = GetContext (backend);
ctx.Path.RelativeMoveTo (new System.Drawing.PointF ((float)dx, (float)dy));
}
public void Stroke (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
ctx.Path.Stroke ();
ctx.Path.Dispose ();
ctx.Path = new NSBezierPath ();
@ -181,12 +189,13 @@ namespace Xwt.Mac
public void StrokePreserve (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
ctx.Path.Stroke ();
}
public void SetColor (object backend, Xwt.Drawing.Color color)
{
GetContext (backend);
NSColor col = NSColor.FromDeviceRgba ((float)color.Red, (float)color.Green, (float)color.Blue, (float)color.Alpha);
col.Set ();
col.SetFill ();
@ -194,46 +203,52 @@ namespace Xwt.Mac
public void SetLineWidth (object backend, double width)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
ctx.Path.LineWidth = (float) width;
}
public void SetLineDash (object backend, double offset, params double[] pattern)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
float[] array = new float[pattern.Length];
for (int n=0; n<pattern.Length; n++)
array [n] = (float) pattern[n];
if (array.Length == 0)
array = new float [] { 0 };
ctx.Path.SetLineDash (array, (float)offset);
}
public void SetPattern (object backend, Pattern p)
public void SetPattern (object backend, object p)
{
ContextInfo ctx = (ContextInfo) backend;
var ctx = GetContext (backend);
ctx.Pattern = p;
}
public void SetFont (object backend, Font font)
public void SetFont (object backend, Xwt.Drawing.Font font)
{
}
public void DrawTextLayout (object backend, TextLayout layout, double x, double y)
{
GetContext (backend);
TextLayoutBackendHandler.Draw (null, WidgetRegistry.GetBackend (layout), x, y);
}
public void DrawImage (object backend, Xwt.Drawing.Image img, double x, double y, double alpha)
public void DrawImage (object backend, object img, double x, double y, double alpha)
{
throw new NotImplementedException ();
var image = (NSImage) img;
image.Draw (new PointF ((float)x, (float)y), RectangleF.Empty, NSCompositingOperation.Copy, (float)alpha);
}
public void DrawImage (object backend, Xwt.Drawing.Image img, double x, double y, double width, double height, double alpha)
public void DrawImage (object backend, object img, double x, double y, double width, double height, double alpha)
{
throw new NotImplementedException ();
var image = (NSImage) img;
image.DrawInRect (new RectangleF ((float)x, (float)y, (float)width, (float)height), RectangleF.Empty, NSCompositingOperation.Copy, (float)alpha);
}
public void Rotate (object backend, double angle)
{
GetContext (backend);
NSAffineTransform t = new NSAffineTransform ();
t.RotateByDegrees ((float)angle);
t.Concat ();
@ -241,6 +256,7 @@ namespace Xwt.Mac
public void Translate (object backend, double tx, double ty)
{
GetContext (backend);
NSAffineTransform t = new NSAffineTransform ();
t.Translate ((float)tx, (float)ty);
t.Concat ();
@ -249,8 +265,56 @@ namespace Xwt.Mac
public void Dispose (object backend)
{
ContextInfo ctx = (ContextInfo) backend;
ctx.Path.Dispose ();
ctx.Dispose ();
}
}
public class ContextInfo
{
static ContextInfo CurrentFocus;
public NSBezierPath Path = new NSBezierPath ();
public object Pattern;
public NSImage TargetImage;
public ContextInfo ()
{
}
public ContextInfo (NSImage targetImage)
{
this.TargetImage = targetImage;
}
public void SetFocus ()
{
if (CurrentFocus != this) {
if (CurrentFocus != null)
CurrentFocus.UnlockFocus ();
CurrentFocus = this;
LockFocus ();
}
}
public void Dispose ()
{
Path.Dispose ();
if (CurrentFocus == this)
UnlockFocus ();
}
public virtual void LockFocus ()
{
if (TargetImage != null)
TargetImage.LockFocus ();
}
public virtual void UnlockFocus ()
{
if (TargetImage != null)
TargetImage.UnlockFocus ();
}
}
}

Просмотреть файл

@ -0,0 +1,111 @@
//
// FrameBackend.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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 Xwt.Drawing;
namespace Xwt.Mac
{
public class FrameBackend: ViewBackend<NSBox,IFrameEventSink>, IFrameBackend
{
Color borderColor;
public override void Initialize ()
{
ViewObject = new MacFrame ();
Widget.SizeToFit ();
}
#region IFrameBackend implementation
public void SetFrameType (FrameType type)
{
switch (type) {
case FrameType.WidgetBox: Widget.BoxType = NSBoxType.NSBoxPrimary; break;
case FrameType.Custom: Widget.BoxType = NSBoxType.NSBoxCustom; break;
}
}
public void SetContent (IWidgetBackend child)
{
Widget.ContentView = GetWidget (child);
Widget.SizeToFit ();
}
public void SetBorderSize (double left, double right, double top, double bottom)
{
}
public void SetPadding (double left, double right, double top, double bottom)
{
}
public string Label {
get {
return Widget.Title;
}
set {
Widget.Title = value;
}
}
public Xwt.Drawing.Color BorderColor {
get {
return borderColor;
}
set {
borderColor = value;
Widget.BorderColor = value.ToNSColor ();
}
}
public override Color BackgroundColor {
get {
return Widget.FillColor.ToXwtColor ();
}
set {
Widget.FillColor = value.ToNSColor ();
}
}
#endregion
}
class MacFrame: NSBox, IViewObject<NSBox>
{
#region IViewObject implementation
public NSBox View {
get {
return this;
}
}
public Widget Frontend { get; set; }
#endregion
}
}

Просмотреть файл

@ -0,0 +1,67 @@
//
// ImageBuilderBackendHandler.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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 MonoMac.AppKit;
using System.Drawing;
namespace Xwt.Mac
{
public class ImageBuilderBackendHandler: IImageBuilderBackendHandler
{
public ImageBuilderBackendHandler ()
{
}
#region IImageBuilderBackendHandler implementation
public object CreateImageBuilder (int width, int height, ImageFormat format)
{
return new NSImage (new SizeF (width, height));
}
public object CreateContext (object backend)
{
NSImage img = (NSImage) backend;
return new ContextInfo (img);
}
public object CreateImage (object backend)
{
return (NSImage) backend;
}
public void Dispose (object backend)
{
NSImage img = (NSImage) backend;
img.Dispose ();
}
#endregion
}
}

Просмотреть файл

@ -29,11 +29,14 @@ using Xwt.Backends;
using MonoMac.AppKit;
using MonoMac.Foundation;
using System.Drawing;
using System.Collections.Generic;
namespace Xwt.Mac
{
public class ImageHandler: ImageBackendHandler
{
static Dictionary<string, NSImage> stockIcons = new Dictionary<string, NSImage> ();
public override object LoadFromStream (System.IO.Stream stream)
{
using (NSData data = NSData.FromStream (stream)) {
@ -48,7 +51,12 @@ namespace Xwt.Mac
public override object LoadFromIcon (string id, IconSize size)
{
throw new NotImplementedException ();
NSImage img;
if (!stockIcons.TryGetValue (id + size, out img)) {
img = LoadStockIcon (id, size);
stockIcons [id + size] = img;
}
return img;
}
public override Size GetSize (object handle)
@ -81,6 +89,24 @@ namespace Xwt.Mac
{
throw new NotImplementedException ();
}
static NSImage FromResource (string res)
{
var stream = typeof(ImageHandler).Assembly.GetManifestResourceStream (res);
using (stream)
using (NSData data = NSData.FromStream (stream)) {
return new NSImage (data);
}
}
static NSImage LoadStockIcon (String id, IconSize size)
{
switch (id) {
case StockIcons.ZoomIn: return FromResource ("magnifier-zoom-in.png");
case StockIcons.ZoomOut: return FromResource ("magnifier-zoom-out.png");
}
throw new NotSupportedException ();
}
}
}

Просмотреть файл

@ -0,0 +1,41 @@
//
// ImagePatternBackendHandler.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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 ImagePatternBackendHandler: IImagePatternBackendHandler
{
public object Create (object img)
{
NSImage nimg = (NSImage) img;
return NSColor.FromPatternImage (nimg);
}
}
}

Просмотреть файл

@ -61,15 +61,23 @@ namespace Xwt.Mac
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.ImageBuilder), typeof(ImageBuilderBackendHandler));
WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.ImagePattern), typeof(ImagePatternBackendHandler));
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));
WidgetRegistry.RegisterBackend (typeof(Xwt.CheckBoxMenuItem), typeof(CheckBoxMenuItemBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.RadioButtonMenuItem), typeof(RadioButtonMenuItemBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.SeparatorMenuItem), typeof(SeparatorMenuItemBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.ComboBox), typeof(ComboBoxBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.ComboBoxEntry), typeof(ComboBoxEntryBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.TextEntry), typeof(TextEntryBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.ImageView), typeof(ImageViewBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.Table), typeof(BoxBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.CheckBox), typeof(CheckBoxBackend));
WidgetRegistry.RegisterBackend (typeof(Xwt.Frame), typeof(FrameBackend));
}
public override void RunApplication ()

Просмотреть файл

@ -34,7 +34,7 @@ namespace Xwt.Mac
{
public void InsertItem (int index, IMenuItemBackend menuItem)
{
InsertItematIndex ((NSMenuItem)menuItem, index);
InsertItematIndex (((MenuItemBackend)menuItem).Item, index);
}
public void RemoveItem (IMenuItemBackend menuItem)

Просмотреть файл

@ -30,8 +30,23 @@ using MonoMac.AppKit;
namespace Xwt.Mac
{
public class MenuItemBackend: NSMenuItem, IMenuItemBackend
public class MenuItemBackend: IMenuItemBackend
{
NSMenuItem item;
public MenuItemBackend (): this (new NSMenuItem ())
{
}
public MenuItemBackend (NSMenuItem item)
{
this.item = item;
}
public NSMenuItem Item {
get { return item; }
}
public void Initialize (IMenuItemEventSink eventSink)
{
}
@ -39,62 +54,56 @@ namespace Xwt.Mac
public void SetSubmenu (IMenuBackend menu)
{
if (menu == null)
Submenu = null;
item.Submenu = null;
else
Submenu = ((MenuBackend)menu);
item.Submenu = ((MenuBackend)menu);
}
public string Label {
get {
return Title;
return item.Title;
}
set {
Title = value;
item.Title = value;
}
}
public void SetType (MenuItemType type)
{
throw new NotImplementedException ();
}
public void SetImage (object imageBackend)
{
throw new NotImplementedException ();
var img = (NSImage) imageBackend;
item.Image = img;
}
public bool Visible {
get {
throw new NotImplementedException ();
return !item.Hidden;
}
set {
throw new NotImplementedException ();
item.Hidden = !value;
}
}
public bool Sensitive {
get {
throw new NotImplementedException ();
return item.Enabled;
}
set {
throw new NotImplementedException ();
item.Enabled = value;
}
}
public bool Checked {
get {
throw new NotImplementedException ();
return item.State == NSCellStateValue.On;
}
set {
throw new NotImplementedException ();
if (value)
item.State = NSCellStateValue.On;
else
item.State = NSCellStateValue.Off;
}
}
public void SetSeparator ()
{
throw new NotImplementedException ();
}
#region IBackend implementation
public void Initialize (object frontend)
{

Просмотреть файл

@ -0,0 +1,38 @@
//
// RadioButtonMenuItemBackend.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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.Mac
{
public class RadioButtonMenuItemBackend: MenuItemBackend, IRadioButtonMenuItemBackend
{
public RadioButtonMenuItemBackend ()
{
}
}
}

Просмотреть файл

@ -0,0 +1,38 @@
//
// SeparatorMenuItemBackend.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 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;
namespace Xwt.Mac
{
public class SeparatorMenuItemBackend: MenuItemBackend
{
public SeparatorMenuItemBackend (): base (NSMenuItem.SeparatorItem)
{
}
}
}

Просмотреть файл

@ -36,11 +36,20 @@ namespace Xwt.Mac
{
}
internal TextEntryBackend (MacComboBox field)
{
ViewObject = field;
}
public override void Initialize ()
{
base.Initialize ();
ViewObject = new CustomTextField (EventSink);
Widget.SizeToFit ();
if (ViewObject is MacComboBox) {
((MacComboBox)ViewObject).SetEntryEventSink (EventSink);
} else {
ViewObject = new CustomTextField (EventSink);
Widget.SizeToFit ();
}
}
#region ITextEntryBackend implementation

Просмотреть файл

@ -27,6 +27,7 @@
using System;
using MonoMac.AppKit;
using Xwt.Drawing;
using MonoMac.CoreGraphics;
namespace Xwt.Mac
{
@ -69,6 +70,22 @@ namespace Xwt.Mac
{
return NSColor.FromDeviceRgba ((float)col.Red, (float)col.Green, (float)col.Blue, (float)col.Alpha);
}
public static CGColor ToCGColor (this Color col)
{
return new CGColor ((float)col.Red, (float)col.Green, (float)col.Blue, (float)col.Alpha);
}
public static Color ToXwtColor (this NSColor col)
{
return new Color (col.RedComponent, col.GreenComponent, col.BlueComponent, col.AlphaComponent);
}
public static Color ToXwtColor (this CGColor col)
{
var cs = col.Components;
return new Color (cs[0], cs[1], cs[2], col.Alpha);
}
}
}

Просмотреть файл

@ -166,12 +166,16 @@ namespace Xwt.Mac
}
}
public Xwt.Drawing.Color BackgroundColor {
public virtual Xwt.Drawing.Color BackgroundColor {
get {
throw new NotImplementedException ();
if (Widget.Layer != null)
return Widget.Layer.BackgroundColor.ToXwtColor ();
else
return Xwt.Drawing.Color.Black;
}
set {
throw new NotImplementedException ();
if (Widget.Layer != null)
Widget.Layer.BackgroundColor = value.ToCGColor ();
}
}
@ -186,6 +190,7 @@ namespace Xwt.Mac
public WidgetSize GetPreferredWidth ()
{
double w1 = Widget.FittingSize.Width + frontend.Margin.HorizontalSpacing;
double w = Widget.WidgetWidth() + frontend.Margin.HorizontalSpacing;
var s = new Xwt.WidgetSize (w, w);
if (minWidth != -1 && s.MinSize > minWidth)
@ -195,6 +200,7 @@ namespace Xwt.Mac
public WidgetSize GetPreferredHeight ()
{
double h1 = Widget.FittingSize.Height + frontend.Margin.VerticalSpacing;
double h = Widget.WidgetHeight() + frontend.Margin.VerticalSpacing;
var s = new Xwt.WidgetSize (h, h);
if (minHeight != -1 && s.MinSize > minHeight)

Двоичные данные
Xwt.Mac/icons/magnifier-zoom-in.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 758 B

Двоичные данные
Xwt.Mac/icons/magnifier-zoom-out.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 736 B

Просмотреть файл

@ -63,7 +63,7 @@ Global
{C93D746E-1586-4D4F-B411-BF5A966E6A08}.Win-Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = GtkTest\GtkTest.csproj
StartupItem = MacTest\MacTest.csproj
Policies = $0
$0.DotNetNamingPolicy = $1
$1.DirectoryNamespaceAssociation = None

Просмотреть файл

@ -77,15 +77,15 @@ namespace Xwt.Backends
void SetLineDash (object backend, double offset, params double[] pattern);
void SetPattern (object backend, Pattern p);
void SetPattern (object backend, object 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, double alpha);
void DrawImage (object backend, object img, double x, double y, double alpha);
void DrawImage (object backend, Image img, double x, double y, double width, double height, double alpha);
void DrawImage (object backend, object img, double x, double y, double width, double height, double alpha);
void Rotate (object backend, double angle);

Просмотреть файл

@ -213,37 +213,37 @@ namespace Xwt.Drawing
public void DrawImage (Image img, Point location)
{
handler.DrawImage (Backend, img, location.X, location.Y, 1);
handler.DrawImage (Backend, GetBackend (img), location.X, location.Y, 1);
}
public void DrawImage (Image img, double x, double y)
{
handler.DrawImage (Backend, img, x, y, 1);
handler.DrawImage (Backend, GetBackend (img), x, y, 1);
}
public void DrawImage (Image img, Point location, double alpha)
{
handler.DrawImage (Backend, img, location.X, location.Y, alpha);
handler.DrawImage (Backend, GetBackend (img), location.X, location.Y, alpha);
}
public void DrawImage (Image img, double x, double y, double alpha)
{
handler.DrawImage (Backend, img, x, y, alpha);
handler.DrawImage (Backend, GetBackend (img), x, y, alpha);
}
public void DrawImage (Image img, Rectangle rect)
{
handler.DrawImage (Backend, img, rect.X, rect.Y, rect.Width, rect.Height, 1);
handler.DrawImage (Backend, GetBackend (img), rect.X, rect.Y, rect.Width, rect.Height, 1);
}
public void DrawImage (Image img, double x, double y, double width, double height)
{
handler.DrawImage (Backend, img, x, y, width, height, 1);
handler.DrawImage (Backend, GetBackend (img), x, y, width, height, 1);
}
public void DrawImage (Image img, Rectangle rect, double alpha)
{
handler.DrawImage (Backend, img, rect.X, rect.Y, rect.Width, rect.Height, alpha);
handler.DrawImage (Backend, GetBackend (img), rect.X, rect.Y, rect.Width, rect.Height, alpha);
}
/// <summary>
@ -279,7 +279,7 @@ namespace Xwt.Drawing
public Pattern Pattern {
get { return pattern; }
set { pattern = value; handler.SetPattern (Backend, value); }
set { pattern = value; handler.SetPattern (Backend, GetBackend (value)); }
}
public Font Font {