Author: jackson
Date: 2005-03-18 21:40:32 -0500 (Fri, 18 Mar 2005)
New Revision: 42024
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageList.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageListStreamer.cs
Log:
* ImageList.cs: When the image stream is set pull all the images
from it.
* ImageListStreamer.cs: Implement reading image list streams.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2005-03-19 00:17:24 UTC (rev 42023)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2005-03-19 02:40:32 UTC (rev 42024)
@@ -1,3 +1,9 @@
+2005-03-18 Jackson Harper <[EMAIL PROTECTED]>
+
+ * ImageList.cs: When the image stream is set pull all the images
+ from it.
+ * ImageListStreamer.cs: Implement reading image list streams.
+
2005-03-18 Peter Bartok <[EMAIL PROTECTED]>
* ThemeWin32Classic.cs (DrawPictureBox):
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageList.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageList.cs
2005-03-19 00:17:24 UTC (rev 42023)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageList.cs
2005-03-19 02:40:32 UTC (rev 42024)
@@ -425,6 +425,15 @@
set {
image_stream = value;
+
+ size = image_stream.ImageSize;
+ color_depth = image_stream.ImageColorDepth;
+ transparency_color = image_stream.BackColor;
+
+ image_collection.Clear ();
+
+ foreach (Image image in image_stream.Images)
+ image_collection.Add (image);
}
}
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageListStreamer.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageListStreamer.cs
2005-03-19 00:17:24 UTC (rev 42023)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageListStreamer.cs
2005-03-19 02:40:32 UTC (rev 42024)
@@ -5,10 +5,10 @@
// 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
@@ -17,31 +17,146 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Copyright (c) 2004 Novell, Inc.
+// Copyright (c) 2002-2005 Novell, Inc.
//
// Authors:
-// Peter Bartok ([EMAIL PROTECTED])
+// Jackson Harper ([EMAIL PROTECTED])
//
-//
+// Based on work done by:
+// Dennis Hayes ([EMAIL PROTECTED])
+// Aleksey Ryabchuk ([EMAIL PROTECTED])
+using System.IO;
+using System.Drawing;
+using System.Collections;
+using System.Drawing.Imaging;
+using System.Runtime.Serialization;
+using System.Runtime.InteropServices;
-// NOT COMPLETE
-using System.Runtime.Serialization;
+namespace System.Windows.Forms {
-namespace System.Windows.Forms {
[Serializable]
public sealed class ImageListStreamer : ISerializable {
- #region Constructor
- private ImageListStreamer() {
+
+ private static byte [] signature = new byte [] {77 , 83 , 70 ,
116};
+
+ private Image [] images;
+ private Size image_size;
+ private Color back_color;
+
+ private ImageListStreamer (SerializationInfo info,
StreamingContext context) {
+
+
+
+ byte [] data = (byte [])info.GetValue ("Data", typeof
(byte []));
+ if (data == null || data.Length <= signature.Length)
+ return;
+ // check the signature ( 'MSFt' )
+ if (data [0] != signature [0] || data [1] != signature
[1] ||
+ data [2] != signature [2] || data [3]
!= signature [3])
+ return;
+
+ // calulate size of array needed for decomressed data
+ int i = 0;
+ int real_byte_count = 0;
+ for (i = signature.Length; i < data.Length; i += 2)
+ real_byte_count += data [i];
+
+ if (real_byte_count == 0)
+ return;
+
+ int j = 0;
+ byte [] decompressed = new byte [real_byte_count];
+
+ for (i = signature.Length; i < data.Length; i += 2) {
+ for (int k = 0; k < data [i]; k++)
+ decompressed [j++] = data [i + 1];
+ }
+
+ MemoryStream stream = new MemoryStream (decompressed);
+ BinaryReader reader = new BinaryReader (stream);
+
+ IntPtr hbmMask = IntPtr.Zero;
+ IntPtr hbmColor= IntPtr.Zero;
+
+ try {
+ // read image list header
+ ushort usMagic = reader.ReadUInt16 ();
+ ushort usVersion = reader.ReadUInt16 ();
+ ushort cCurImage = reader.ReadUInt16 ();
+ ushort cMaxImage = reader.ReadUInt16 ();
+ ushort cGrow = reader.ReadUInt16 ();
+ ushort cx = reader.ReadUInt16 ();
+ ushort cy = reader.ReadUInt16 ();
+ uint bkcolor = reader.ReadUInt32 ();
+ ushort flags = reader.ReadUInt16 ();
+
+ short [] ovls = new short [4];
+ for (i = 0; i < ovls.Length; i++)
+ ovls[i] = reader.ReadInt16 ();
+
+ image_size = new Size (cx, cy);
+ back_color = Color.FromArgb ((int) bkcolor);
+
+ MemoryStream start = new MemoryStream
(decompressed,
+ (int) stream.Position,
+ (int) stream.Length - (int)
stream.Position,
+ false);
+
+ Image image = Image.FromStream (start);
+
+ // Holy calamity. This is what happens on MS
+ // if the background colour is 0xFFFFFFFF
(CLR_NONE)
+ // the mask is set to the color at pixel 0, 0
+ Bitmap bmp = image as Bitmap;
+ if (bkcolor == 0xFFFFFFFF && bmp != null)
+ back_color = bmp.GetPixel (0, 0);
+
+ int step = image.Width / cx;
+ images = new Image [cCurImage];
+
+ Rectangle dest_rect = new Rectangle (0, 0, cx,
cy);
+ for (int r = 0 ; r < cCurImage ; r++) {
+ Rectangle area = new Rectangle (
+ (r % step) / cx,
+ (r / step) * cy,
+ cx, cy);
+ Bitmap b = new Bitmap (cx, cy);
+ using (Graphics g = Graphics.FromImage
(b)) {
+ g.DrawImage (image, dest_rect,
area,
+
GraphicsUnit.Pixel);
+ }
+ b.MakeTransparent (back_color);
+ images [r] = b;
+ }
+
+ } catch (Exception e) {
+
+ }
}
- #endregion // Constructor
- #region Public Instance Methods
- [MonoTODO("Need to learn about streaming first - Peter")]
- public void GetObjectData(SerializationInfo si,
StreamingContext context) {
- throw new NotImplementedException();
+ [MonoTODO]
+ void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
+ {
+
}
- #endregion // Public Instance Methods
+
+ internal Image [] Images {
+ get { return images; }
+ }
+
+ internal Size ImageSize {
+ get { return image_size; }
+ }
+
+ internal ColorDepth ImageColorDepth {
+ get { return ColorDepth.Depth32Bit; }
+ }
+
+ internal Color BackColor {
+ get { return back_color; }
+ }
}
}
+
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches