Fairly simple. Also a trivial fix to CreateComponentsCore to maintain compatibility with .NET.
I've tested it works with some icons I whipped up for the Web Controls in System.Web.dll, but I'd like to make them a bit prettier before offering them too. Any objections to me committing this? Michael
Index: class/System.Drawing/System.Drawing.Design/ToolboxItem.cs =================================================================== --- class/System.Drawing/System.Drawing.Design/ToolboxItem.cs (revision 48547) +++ class/System.Drawing/System.Drawing.Design/ToolboxItem.cs (working copy) @@ -46,7 +46,7 @@ { private AssemblyName assembly; - private Bitmap bitmap; + private Bitmap bitmap = null; private ICollection filter = new ToolboxItemFilterAttribute[0]; private string displayname = string.Empty; private bool locked = false; @@ -203,17 +203,35 @@ Assembly assembly = typeRes.GetAssembly(assemblyName, true); if (reference) typeRes.ReferenceAssembly(assemblyName); - return assembly.GetType(typeName, true); + return typeRes.GetType(typeName, true); } - [MonoTODO] + [MonoTODO ("Should we be returning empty bitmap, or null?")] public virtual void Initialize (Type type) { assembly = type.Assembly.GetName(); displayname = type.Name; name = type.FullName; + // seems to be a right place to create the bitmap - bitmap = new Bitmap (16, 16); // FIXME: load bitmap from resources if present, else set some default bitmap + System.Drawing.Image image = null; + foreach (object attribute in type.GetCustomAttributes(true)) { + ToolboxBitmapAttribute tba = attribute as ToolboxBitmapAttribute; + if (tba != null) { + image = tba.GetImage (type); + break; + } + } + //fallback: check for image even if not attribute + if (image == null) + image = ToolboxBitmapAttribute.GetImageFromResource (type, null, false); + + if (image != null) { + if (image is Bitmap) + bitmap = (Bitmap) image; + else + bitmap = new Bitmap (image); + } filter = type.GetCustomAttributes (typeof (ToolboxItemFilterAttribute), true); } Index: class/System.Drawing/System.Drawing/ToolboxBitmapAttribute.cs =================================================================== --- class/System.Drawing/System.Drawing/ToolboxBitmapAttribute.cs (revision 48547) +++ class/System.Drawing/System.Drawing/ToolboxBitmapAttribute.cs (working copy) @@ -39,36 +39,27 @@ [AttributeUsage (AttributeTargets.Class)] public class ToolboxBitmapAttribute : Attribute { - private Image smallImage; - private Image bigImage; + private Image smallImage = null; + private Image bigImage = null; public static readonly ToolboxBitmapAttribute Default = new ToolboxBitmapAttribute(); private ToolboxBitmapAttribute () { } - [MonoTODO ("implement")] public ToolboxBitmapAttribute (string imageFile) { - // - // TODO: Add constructor logic here - // + smallImage = new Bitmap (imageFile); } - [MonoTODO ("implement")] public ToolboxBitmapAttribute (Type t) { - // - // TODO: Add constructor logic here - // + smallImage = GetImageFromResource (t, null, false); } - [MonoTODO ("implement")] public ToolboxBitmapAttribute (Type t, string name) { - // - // TODO: Add constructor logic here - // + smallImage = GetImageFromResource (t, name, false); } public override bool Equals (object value) @@ -105,16 +96,41 @@ return GetImage (type, null, large); } - [MonoTODO ("implement")] public Image GetImage (Type type, string imgName, bool large) { - return null; + if (smallImage == null) + smallImage = GetImageFromResource (type, imgName, false); + + if (large) { + if (bigImage == null) + bigImage = new Bitmap (smallImage, 32, 32); + return bigImage; + } + else + return smallImage; } - [MonoTODO ("implement")] public static Image GetImageFromResource (Type t, string imageName, bool large) { - return null; + Bitmap bitmap; + if (imageName == null) + imageName = t.Name + ".bmp"; + + using (System.IO.Stream s = t.Assembly.GetManifestResourceStream (t.Namespace + "." + imageName)){ + if (s == null) { + return null; + } + else { + bitmap = new Bitmap (s, false); + } + } + + //FIXME: thrown too easily + //if (bitmap.Width != 16 || bitmap.Height != 16) + // throw new Exception ("ToolboxBitmap must be 16x16 pixels"); + + if (large) return new Bitmap (bitmap, 32, 32); + return bitmap; } } }
_______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list