Skip to content

Commit

Permalink
Improve IImageViewBackend.SetImage API
Browse files Browse the repository at this point in the history
 - Added docs
 - Added argument exceptions
 - Renamed 'imageBackend' to 'nativeImage' to better reflect the actual
   object being passed in.
  • Loading branch information
ermau committed Feb 28, 2012
1 parent 0ab88ed commit 1587e57
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
11 changes: 9 additions & 2 deletions Xwt.Gtk/Xwt.GtkBackend/ImageViewBackend.cs
Expand Up @@ -41,9 +41,16 @@ public override void Initialize ()
set { base.Widget = value; }
}

public void SetImage (object imageBackend)
public void SetImage (object nativeImage)
{
Widget.Pixbuf = (Gdk.Pixbuf)imageBackend;
if (nativeImage == null)
throw new ArgumentNullException ("nativeImage");

Gdk.Pixbuf pbuf = nativeImage as Gdk.Pixbuf;
if (pbuf == null)
throw new ArgumentException ("nativeImage is not of the expected type", "nativeImage");

Widget.Pixbuf = pbuf;
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions Xwt.Mac/Xwt.Mac/ImageViewBackend.cs
Expand Up @@ -42,9 +42,16 @@ public override void Initialize ()
Widget.SizeToFit ();
}

public void SetImage (object imageBackend)
public void SetImage (object nativeImage)
{
Widget.Image = (NSImage) imageBackend;
if (nativeImage == null)
throw new ArgumentNullException ("nativeImage");

NSImage image = nativeImage as NSImage;
if (image == null)
throw new ArgumentException ("nativeImage is not of the expected type", "nativeImage");

Widget.Image = image;
Widget.SetFrameSize (Widget.Image.Size);
}
}
Expand Down
8 changes: 7 additions & 1 deletion Xwt/Xwt.Backends/IImageViewBackend.cs
Expand Up @@ -29,7 +29,13 @@ namespace Xwt.Backends
{
public interface IImageViewBackend: IWidgetBackend
{
void SetImage (object imageBackend);
/// <summary>
/// Sets the image view to use the supplied image backend.
/// </summary>
/// <param name="nativeImage">A native image widget.</param>
/// <exception cref="ArgumentNullException"><paramref name="nativeImage"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="nativeImage"/> is not of the expected type.</exception>
void SetImage (object nativeImage);
}
}

0 comments on commit 1587e57

Please sign in to comment.