[Gtk-sharp-list] Re: Pixbuf-from-assembly problem solved

Mike Kestner mkestner@ximian.com
Mon, 17 Nov 2003 00:17:06 -0600


On Sun, 2003-11-16 at 23:54, Ettore Perazzoli wrote:

> > Please post a message to the list describing the API
> > change since there's probably a lot of code out there using those ctors.
> 
> OK, I am not on the list.  Can you do it instead?  

Sure.  Copying the list on this reply.

Folks this is a heads-up that the "load a pixbuf from a resource" API is
changing.  Instead of exposing ctors, Ettore's attached patch (which was
committed tonight) exposes the functionality as static methods on
Pixbuf.

So any code that used the old ctors will need to change to something
like:

Pixbuf foo = Pixbuf.LoadResource (myassembly, myresourcename);

or the (string resource) overload that default to the calling assembly.

Thanks again for the patch, Ettore.

Mike

> 
> ______________________________________________________________________
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/public/gtk-sharp/ChangeLog,v
> retrieving revision 1.539
> diff -u -p -r1.539 ChangeLog
> --- ChangeLog	30 Oct 2003 18:19:58 -0000	1.539
> +++ ChangeLog	17 Nov 2003 05:32:11 -0000
> @@ -1,3 +1,9 @@
> +2003-11-17  Ettore Perazzoli  <ettore@ximian.com>
> +
> +	* gdk/Pixbuf.custom: Removed the Assembly constructors.
> +	(Pixbuf.LoadResource (string)): New.
> +	(Pixbuf.LoadResource (Assembly, string)): New.
> +
>  2003-10-30  Ken Foster  <kenfoster@tampabay.rr.com>    
>  
>  	* glue/button.c: initial creating of glue file for GdkButton    
> Index: gdk/Pixbuf.custom
> ===================================================================
> RCS file: /cvs/public/gtk-sharp/gdk/Pixbuf.custom,v
> retrieving revision 1.8
> diff -u -p -r1.8 Pixbuf.custom
> --- gdk/Pixbuf.custom	30 Aug 2003 00:26:37 -0000	1.8
> +++ gdk/Pixbuf.custom	17 Nov 2003 05:32:36 -0000
> @@ -15,34 +15,31 @@
>  //
>  // This code is inserted after the automatically generated code.
>  
> -		IntPtr LoadFromStream (System.IO.Stream input)
> +		static private Pixbuf LoadFromStream (System.IO.Stream input)
>  		{
>  			PixbufLoader loader = new PixbufLoader ();
>  			byte [] buffer = new byte [8192];
> -		
>  			int n;
> -		
> +
>  			while ((n = input.Read (buffer, 0, 8192)) != 0)
>  				loader.Write (buffer, (uint) n);
> -			loader.Close ();
>  		
> -			return loader.Pixbuf.Handle;
> +			loader.Close ();
> +			return loader.Pixbuf;
>  		}
>  		
> -		public Pixbuf (System.IO.Stream input)
> +		static public Pixbuf LoadResource (System.Reflection.Assembly assembly, string resource)
>  		{
> -			Raw = LoadFromStream (input);
> +			System.IO.Stream s = assembly.GetManifestResourceStream (resource);
> +			if (s == null)
> +				return null;
> +			else
> +				return LoadFromStream (s);
>  		}
> -		
> -		public Pixbuf (System.Reflection.Assembly assembly, string resource)
> +
> +		static public Pixbuf LoadResource (string resource)
>  		{
> -			if (assembly == null)
> -				assembly = System.Reflection.Assembly.GetCallingAssembly ();
> -		
> -			System.IO.Stream s;
> -			Pixbuf p = null;
> -			using (s = assembly.GetManifestResourceStream (resource))
> -				Raw = LoadFromStream (s);
> +			return LoadResource (System.Reflection.Assembly.GetCallingAssembly (), resource);
>  		}
>  
>  		
-- 
Mike Kestner <mkestner@ximian.com>