dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing.Win32 .cvsignore,NONE


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing.Win32 .cvsignore,NONE,1.1 DrawingBrush.cs,NONE,1.1 DrawingControlWindow.cs,NONE,1.1 DrawingFont.cs,NONE,1.1 DrawingGraphics.cs,NONE,1.1 DrawingHatchBrush.cs,NONE,1.1 DrawingPen.cs,NONE,1.1 DrawingRootTopLevelWindow.cs,NONE,1.1 DrawingSolidBrush.cs,NONE,1.1 DrawingTextureBrush.cs,NONE,1.1 DrawingToolkit.cs,NONE,1.1 DrawingTopLevelWindow.cs,NONE,1.1 DrawingWindow.cs,NONE,1.1 Makefile.am,NONE,1.1 System.Drawing.Win32.build,NONE,1.1Win32.cs,NONE,1.1
Date: Fri, 20 Jun 2003 21:23:55 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Win32
In directory subversions:/tmp/cvs-serv3689/System.Drawing.Win32

Added Files:
        .cvsignore DrawingBrush.cs DrawingControlWindow.cs 
        DrawingFont.cs DrawingGraphics.cs DrawingHatchBrush.cs 
        DrawingPen.cs DrawingRootTopLevelWindow.cs 
        DrawingSolidBrush.cs DrawingTextureBrush.cs DrawingToolkit.cs 
        DrawingTopLevelWindow.cs DrawingWindow.cs Makefile.am 
        System.Drawing.Win32.build Win32.cs 
Log Message:


Add the "System.Drawing.Win32" assembly, which provides drawing
functionality using the raw Win32 API.


--- NEW FILE ---
Makefile
Makefile.in
.deps
*.dll

--- NEW FILE ---
/*
 * DrawingBrush.cs - Implementation of abstract brush for System.Drawing.Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

        using System;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.Drawing.Toolkit;

        abstract class DrawingBrush : IToolkitBrush, IDisposable
        {
                // Internal state.
                protected IntPtr hBrush;
                private static IntPtr hPrevBrush;
                protected DrawingGraphics drawingGraphics;
                protected internal Color color;
                protected IToolkit toolkit;

                public DrawingBrush(IToolkit toolkit, Color color) 
                {
                        this.toolkit = toolkit;
                        this.color = color;
                }

                // Select this brush into a graphics object.
                public virtual void Select(IToolkitGraphics graphics)
                {
                        drawingGraphics = (graphics as DrawingGraphics);
                        drawingGraphics.selectedBrush = this;
                        IntPtr hOldBrush = 
Win32.Api.SelectObject(drawingGraphics.hdc, hBrush);
                        if (hPrevBrush == IntPtr.Zero)
                                hPrevBrush = hOldBrush;
                }

                // Dispose of this object.
                public void Dispose()
                {
                        Win32.Api.SelectObject(drawingGraphics.hdc, hPrevBrush);
                        Win32.Api.DeleteObject(hBrush);
                        hBrush = IntPtr.Zero;
                }
        }
}; // namespace System.Drawing.Toolkit;

--- NEW FILE ---
/*
 * DrawingControlWindow.cs - Implementation of the control, inherits from 
drawing window.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;
using d = System.Diagnostics.Debug;

internal class DrawingControlWindow : DrawingWindow, IToolkitWindow
{
        //for a unique class name
        protected static uint createCount;

        public DrawingControlWindow(IToolkit toolkit, string name, 
DrawingWindow parent, int x,
                int y, int width, int height) : base (toolkit, parent)
        {
                d.WriteLine("DrawingControlWindow");

                //At the moment we create a unique class name for EVERY window. 
SWF does it for each window type
                className = "DrawingControlWindow" + createCount;
                //Register the windows class
                windowsClass = new Win32.Api.WNDCLASS();
                windowsClass.style = Win32.Api.WindowClassStyle.CS_DBLCLKS;
                windowsClass.lpfnWndProc = new Win32.Api.WNDPROC(WindowsLoop);
                windowsClass.hbrBackground = IntPtr.Zero; 
//(IntPtr)(Win32.Api.COLOR_WINDOW + 1);
                windowsClass.lpszClassName = className ;
                if (Win32.Api.RegisterClassA( ref windowsClass)==0) 
                {
                        throw new Exception("Failed to register Windows class " 
+ className);
                }
                createCount++;
                //Set default windows settings
                style = Win32.Api.WindowStyle.WS_CHILD;
                extendedStyle = 0;
                if (parent != null)
                {
                        CreateWindow( new Rectangle( x, y, width, height ) );
                }
        }

        // Reparent this window to underneath a new parent.
        // If there is no parent then we destroy the window.
        // If the parent changes, we destroy and recreate
        void IToolkitWindow.Reparent(IToolkitWindow parent, int x, int y)
        {
                if (parent != this.parent)
                {
                        if(this.parent != null || parent == null )
                        {
                                (this as IToolkitWindow).Destroy();
                        }
                        if (parent != null)
                        {
                                Rectangle dimension = (this as 
IToolkitWindow).Dimensions;
                                CreateWindow( new Rectangle( x, y, 
dimension.Width, dimension.Height )) ;
                        }
                }
                d.WriteLine("DrawingWindow.Reparent, hwnd="+hwnd);
        }

        
        protected void CreateWindow(Rectangle bounds)
        {
                hwnd = Win32.Api.CreateWindowExA( extendedStyle, className, 
string.Empty, style, bounds.X, bounds.Y, bounds.Width, bounds.Height, 
parent.hwnd, IntPtr.Zero,Win32.Api.GetModuleHandleA(null),IntPtr.Zero );
                d.WriteLine("DrawingControlWindow.CreateWindow hwnd="+hwnd + 
",parent hwnd="+parent.hwnd+",["+bounds.ToString()+"]");
                if (hwnd==IntPtr.Zero) 
                {
                        throw new Exception("Failed to create new Window");
                }
        }


}; // class DrawingControlWindow

}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingFont.cs - Implementation of fonts for System.Drawing.Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;

internal class DrawingFont : IToolkitFont
{
        // Internal state.
        private System.Drawing.Font properties;
        private IToolkit toolkit;
        
        public DrawingFont(IToolkit toolkit, System.Drawing.Font properties)
                        {
                                this.toolkit = toolkit;
                                this.properties = properties;
                        }

        // Select this font into a graphics object.
        public void Select(IToolkitGraphics _graphics)
                        {
                                DrawingGraphics graphics = (_graphics as 
DrawingGraphics);
                                if(graphics != null)
                                {
                                        lock(this)
                                        {
                                                /*if(xfont == null)
                                                {
                                                        xfont = new Xsharp.Font
                                                                
(MapFamilyName(properties.Name),
                                                                 
(int)(properties.SizeInPoints * 10.0f),
                                                                 
(Xsharp.FontStyle)(properties.Style));
                                                }
                                                graphics.font = xfont;*/
                                        }
                                }
                        }

        // Dispose of this font.
        public void Dispose()
                        {
                                
                        }

        // Get the raw HFONT for this toolkit font.  IntPtr.Zero if none.
        public IntPtr GetHfont()
                        {
                                // Nothing to do here in this implementation.
                                return IntPtr.Zero;
                        }

        // Get the LOGFONT information for this toolkit font.
        public void ToLogFont(Object lf, IToolkitGraphics graphics)
                        {
                                // Nothing to do here in this implementation.
                        }

        // Map a Windows-style family name to an Xsharp-style family name.
        private static String MapFamilyName(String name)
                        {
                                if(String.Compare(name, "Times", true) == 0 ||
                                   String.Compare(name, "Times New Roman", 
true) == 0)
                                {
                                        return null;//Xsharp.Font.Serif;
                                }
                                else if(String.Compare(name, "Helvetica", true) 
== 0 ||
                                        String.Compare(name, "Helv", true) == 0 
||
                                        String.Compare
                                                        (name, "Microsoft Sans 
Serif", true) == 0 ||
                                        String.Compare(name, "Arial", true) == 
0 ||
                                        String.Compare(name, 0, "Arial ", 0, 6, 
true) == 0)
                                {
                                        return null; //Xsharp.Font.SansSerif;
                                }
                                else if(String.Compare(name, "Courier", true) 
== 0 ||
                                        String.Compare(name, "Courier New", 
true) == 0)
                                {
                                        return null; //Xsharp.Font.Fixed;
                                }
                                else
                                {
                                        return null; //Xsharp.Font.Serif;
                                }
                        }

}; // class DrawingFont

}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingGraphics.cs - Implementation of graphics drawing for 
System.Drawing.Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;

internal class DrawingGraphics : ToolkitGraphicsBase, IDisposable
{
        // Internal state.
        //internal Xsharp.Font font;
        internal IntPtr hdc;
        internal DrawingPen selectedPen;
        internal DrawingBrush selectedBrush;

        public DrawingGraphics(IToolkit toolkit, IntPtr hdc)
                        : base(toolkit)
                        {
                                this.hdc = hdc;
                                //this.font = null;
                        }


        // Dispose of this object.
        public override void Dispose()
                        {
                                Win32.Api.DeleteObject(hdc);
                                hdc = IntPtr.Zero;
                        }

        // Clear the entire drawing surface.
        public override void Clear()
                        {
                                //graphics.Clear();
                        }

        // Draw a line between two points using the current pen.
        public override void DrawLine( int x1, int y1, int x2, int y2 )
                        {
                                Win32.Api.MoveToEx( hdc, x1, y1,IntPtr.Zero );
                                Win32.Api.LineTo( hdc, x2, y2 );
                                //set last point
                                Win32.Api.SetPixel( hdc, x2, y2, ColorToWin32( 
selectedPen.properties.Color ) );
                        }

        // Draw a set of connected line seguments using the current pen.
        public override void DrawLines( System.Drawing.Point[] points )
                        {
                                for ( int i = 1;i < points.Length; i++ )
                                {
                                        DrawLine( 
points[i-1].X,points[i-1].Y,points[i].X,points[i].Y );
                                }

                        }

        private Win32.Api.POINT[] ConvertPoints( System.Drawing.Point[] points 
) 
                        {
                                Win32.Api.POINT[] wPoints = new 
Win32.Api.POINT[points.Length];
                                for( int i = 0; i < points.Length; i++ )
                                {
                                        wPoints[i].x = points[i].X;
                                        wPoints[i].y = points[i].Y;
                                }
                                return wPoints;
                        }

        // Draw a polygon using the current pen.
        public override void DrawPolygon( System.Drawing.Point[] points )
                        {
                                IntPtr prevBrush = Win32.Api.SelectObject(hdc, 
Win32.Api.GetStockObject(Win32.Api.StockObjectType.HOLLOW_BRUSH));
                                Win32.Api.POINT[] wPoints = 
ConvertPoints(points);
                                Win32.Api.Polygon(hdc, wPoints, wPoints.Length);
                                Win32.Api.SelectObject(hdc, prevBrush);
                        }

        // Fill a polygon using the current brush.
        public override void FillPolygon
                                ( System.Drawing.Point[] points, FillMode 
fillMode )
                        {
                                
                                Win32.Api.SetPolyFillMode(hdc, (int)fillMode);
                                Win32.Api.POINT[] wPoints = 
ConvertPoints(points);
                                Win32.Api.Polygon(hdc, wPoints, wPoints.Length);

                        }

        // Draw an arc within a rectangle defined by four points.
        public override void DrawArc
                                ( System.Drawing.Point[] rect,
                                 float startAngle, float sweepAngle )
                        {

                                int p1X, p1Y, p2X, p2Y;
                                RectangleAngleToPoints( rect, startAngle, 
sweepAngle, out p1X, out p1Y, out p2X, out p2Y );
                                Win32.Api.Arc( hdc, rect[0].X, rect[0].Y, 
rect[2].X, rect[2].Y, p1X, p1Y, p2X, p2Y );

                        }

        // Draw a pie slice within a rectangle defined by four points.
        public override void DrawPie ( System.Drawing.Point[] rect, float 
startAngle, float sweepAngle )
                        {

                                IntPtr prevBrush = Win32.Api.SelectObject(hdc, 
Win32.Api.GetStockObject(Win32.Api.StockObjectType.HOLLOW_BRUSH));
                                int p1X, p1Y, p2X, p2Y;
                                RectangleAngleToPoints( rect, startAngle, 
sweepAngle, out p1X, out p1Y, out p2X, out p2Y );
                                Win32.Api.Pie( hdc, rect[0].X, rect[0].Y, 
rect[2].X, rect[2].Y, p1X, p1Y, p2X, p2Y);
                                Win32.Api.SelectObject( hdc, prevBrush );

                        }

        // Fill a pie slice within a rectangle defined by four points.
        public override void FillPie (System.Drawing.Point[] rect, float 
startAngle, float sweepAngle)
                        {

                                IntPtr prevPen = Win32.Api.SelectObject( hdc, 
Win32.Api.GetStockObject( Win32.Api.StockObjectType.NULL_PEN ) );
                                int p1X, p1Y, p2X, p2Y;
                                RectangleAngleToPoints( rect, startAngle, 
sweepAngle, out p1X, out p1Y, out p2X, out p2Y );
                                Win32.Api.Pie( hdc, rect[0].X, rect[0].Y, 
rect[2].X, rect[2].Y, p1X, p1Y, p2X, p2Y );
                                Win32.Api.SelectObject( hdc, prevPen );

                        }

        //Woops this is works only for a square - id better get some trig going
        private void RectangleAngleToPoints(System.Drawing.Point[] rect, float 
startAngle, float sweepAngle,
                out int p1X, out int p1Y, out int p2X, out int p2Y)
                        {

                                double centerX = (rect[0].X+rect[2].X)/2;
                                double centerY = (rect[0].Y+rect[2].Y)/2;
                                double r = 
Math.Sqrt((Math.Pow(rect[0].X-rect[2].X,2))+Math.Pow(rect[0].Y-rect[2].Y,2))/2;
                                double a = startAngle*Math.PI/180;
                                double b = (startAngle+sweepAngle)*Math.PI/180;
                                p1X = (int)(Math.Cos(b)*r+centerX+.5);
                                p1Y = (int)(Math.Sin(b)*r+centerY+.5);
                                p2X = (int)(Math.Cos(a)*r+centerX+.5);
                                p2Y = (int)(Math.Sin(a)*r+centerY+.5);

                        }

        // Draw a string using the current font and brush.
        public override void DrawString
                                (String s, int x, int y, StringFormat format)
                        {
                                //FontExtents extents = 
graphics.GetFontExtents(font);
                                //graphics.DrawString(x, y + extents.Ascent - 
1, s, font);

                                //GDI does support writing text with a brush so 
we get the brush color - if available
                                /*Could do but is it slow?:
                                 * 1) Select hatch brush
                                2) BeginPath
                                3) TextOut
                                4) EndPath
                                5) StrokeAndFillPath*/

                                Win32.Api.SetTextColor(hdc, 
ColorToWin32(selectedBrush.color));
                                
Win32.Api.SetBkMode(hdc,Win32.Api.BackGroundModeType.TRANSPARENT);
                                Win32.Api.TextOutA(hdc, x, y , s, s.Length);

                        }

        // Measure a string using the current font and a given layout rectangle.
        public override Size MeasureString( String s, System.Drawing.Point[] 
layoutRectangle, StringFormat format, out int charactersFitted, out int 
linesFilled, bool ascentOnly )
                        {
                                // TODO: line wrapping, etc
                                Win32.Api.SIZE size;
                                size.cx = 0;
                                size.cy = 0;
                                Win32.Api.GetTextExtentPoint32A(hdc, s, 
s.Length, ref size);

                                Win32.Api.TEXTMETRIC tm;
                                Win32.Api.GetTextMetrics(hdc, out tm);
                                
                                charactersFitted = 0;
                                linesFilled = 0;
                                if(!ascentOnly)
                                {
                                        return new Size(size.cx, size.cy); 
/*ascent + descent*/
                                }
                                else
                                {
                                        return new Size(size.cx,tm.tmAscent);
                                }
                                
                        }

        // Not implementing Flush
        public override void Flush(FlushIntention intention)
                        {
                        }

        // Get the HDC associated with this graphics object.
        public override IntPtr GetHdc()
                        {
                                return hdc;
                        }

        // Release a HDC that was obtained using "GetHdc()".
        public override void ReleaseHdc(IntPtr hdc)
                        {
                                Win32.Api.DeleteObject(hdc);
                        }

        // Set the clipping region to empty.
        public override void SetClipEmpty()
                        {
                                //Hope this is right!
                                SetClipRect( 0, 0, 0, 0 );
                        }

        // Set the clipping region to infinite (i.e. disable clipping).
        public override void SetClipInfinite()
                        {
                                Win32.Api.SelectClipRgn( hdc, IntPtr.Zero );
                        }

        // Set the clipping region to a single rectangle.
        public override void SetClipRect( int x, int y, int width, int height )
                        {
                                IntPtr region = Win32.Api.CreateRectRgn( x, y, 
x + width, y + height );
                                Win32.Api.SelectClipRgn( hdc, region );
                                Win32.Api.DeleteObject( region );
                        }

        // Set the clipping region to a list of rectangles.
        public override void SetClipRects(System.Drawing.Rectangle[] rects)
                        {
                                // TODO
                        }

        // Set the clipping region to a complex mask.
        public override void SetClipMask(Object mask, int topx, int topy)
                        {
                                // TODO
                        }

        // Get the line spacing for the font selected into this graphics object.
        public override int GetLineSpacing()
                        {
                                /*FontExtents extents = 
graphics.GetFontExtents(font);
                                return extents.Ascent + extents.Descent;*/
                return 0;
        
                        }

        public static int ColorToWin32( Color color) 
                        {
                                return color.R | color.G<<8 | color.B<<16;
                        }

}; // class DrawingGraphics


}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingHatchBrush.cs - Implementation of hatch brushes for 
System.Drawing.Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;

internal class DrawingHatchBrush : DrawingBrush, IToolkitBrush
{
        // Internal state.
        private int foreColor;
        private int backColor;
        private static IntPtr[] hatchBitmaps;

        public DrawingHatchBrush(IToolkit toolkit, HatchStyle style,
                                                         System.Drawing.Color 
foreColor,
                                                         System.Drawing.Color 
backColor) : base (toolkit, backColor)
                        {
                                this.foreColor = 
DrawingGraphics.ColorToWin32(foreColor);
                                this.backColor = 
DrawingGraphics.ColorToWin32(backColor);
                                IntPtr hBi;
                                lock(typeof(DrawingHatchBrush))
                                {
                                        hBi = GetBitmap(style);
                                }
                                if (hBi != IntPtr.Zero)
                                {
                                        hBrush = 
Win32.Api.CreatePatternBrush(hBi);
                                }
                                else
                                        //not one of the types we recognize, so 
make it a solid brush
                                        hBrush = 
DrawingSolidBrush.CreateSolidBrush(foreColor);
                                
                        }

        // Select this brush into a graphics object.
        public override void Select(IToolkitGraphics graphics)
                        {
                                Win32.Api.SetTextColor( (graphics as 
DrawingGraphics).hdc, backColor);
                                Win32.Api.SetBkColor( (graphics as 
DrawingGraphics).hdc,foreColor);
                        
                                base.Select(graphics);
                        }

        // Get the bitmap corresponding to a particular hatch style.
        private static IntPtr GetBitmap(HatchStyle style)
        {
                IntPtr bitmap;

                // See if we have a cached bitmap for this style.
                if(((int)style) >= 0 && ((int)style) <= 52)
                {
                        if (hatchBitmaps == null)
                        {
                                hatchBitmaps = new IntPtr[53];
                        }
                        bitmap = hatchBitmaps[(int)style];
                        if (bitmap != IntPtr.Zero)
                        {
                                return bitmap;
                        }
                }
                else
                {
                        return IntPtr.Zero;
                }

                // Get the raw bits for the hatch bitmap.
                byte[] bits;
                switch(style)
                {
                        case HatchStyle.BackwardDiagonal:
                                bits = BackwardDiagonal_bits; break;
                        case HatchStyle.DarkDownwardDiagonal:
                                bits = DarkDownwardDiagonal_bits; break;
                        case HatchStyle.DarkHorizontal:
                                bits = DarkHorizontal_bits; break;
                        case HatchStyle.DarkUpwardDiagonal:
                                bits = DarkUpwardDiagonal_bits; break;
                        case HatchStyle.DarkVertical:
                                bits = DarkVertical_bits; break;
                        case HatchStyle.DashedDownwardDiagonal:
                                bits = DashedDownwardDiagonal_bits; break;
                        case HatchStyle.DashedHorizontal:
                                bits = DashedHorizontal_bits; break;
                        case HatchStyle.DashedUpwardDiagonal:
                                bits = DashedUpwardDiagonal_bits; break;
                        case HatchStyle.DashedVertical:
                                bits = DashedVertical_bits; break;
                        case HatchStyle.DiagonalBrick:
                                bits = DiagonalBrick_bits; break;
                        case HatchStyle.DiagonalCross:
                                bits = DiagonalCross_bits; break;
                        case HatchStyle.Divot:
                                bits = Divot_bits; break;
                        case HatchStyle.DottedDiamond:
                                bits = DottedDiamond_bits; break;
                        case HatchStyle.DottedGrid:
                                bits = DottedGrid_bits; break;
                        case HatchStyle.ForwardDiagonal:
                                bits = ForwardDiagonal_bits; break;
                        case HatchStyle.Horizontal:
                                bits = Horizontal_bits; break;
                        case HatchStyle.HorizontalBrick:
                                bits = HorizontalBrick_bits; break;
                        case HatchStyle.LargeCheckerBoard:
                                bits = LargeCheckerBoard_bits; break;
                        case HatchStyle.LargeConfetti:
                                bits = LargeConfetti_bits; break;
                        case HatchStyle.LargeGrid:
                                bits = LargeGrid_bits; break;
                        case HatchStyle.LightDownwardDiagonal:
                                bits = LightDownwardDiagonal_bits; break;
                        case HatchStyle.LightHorizontal:
                                bits = LightHorizontal_bits; break;
                        case HatchStyle.LightUpwardDiagonal:
                                bits = LightUpwardDiagonal_bits; break;
                        case HatchStyle.LightVertical:
                                bits = LightVertical_bits; break;
                        case HatchStyle.NarrowHorizontal:
                                bits = NarrowHorizontal_bits; break;
                        case HatchStyle.NarrowVertical:
                                bits = NarrowVertical_bits; break;
                        case HatchStyle.OutlinedDiamond:
                                bits = OutlinedDiamond_bits; break;
                        case HatchStyle.Percent05:
                                bits = Percent05_bits; break;
                        case HatchStyle.Percent10:
                                bits = Percent10_bits; break;
                        case HatchStyle.Percent20:
                                bits = Percent20_bits; break;
                        case HatchStyle.Percent25:
                                bits = Percent25_bits; break;
                        case HatchStyle.Percent30:
                                bits = Percent30_bits; break;
                        case HatchStyle.Percent40:
                                bits = Percent40_bits; break;
                        case HatchStyle.Percent50:
                                bits = Percent50_bits; break;
                        case HatchStyle.Percent60:
                                bits = Percent60_bits; break;
                        case HatchStyle.Percent70:
                                bits = Percent70_bits; break;
                        case HatchStyle.Percent75:
                                bits = Percent75_bits; break;
                        case HatchStyle.Percent80:
                                bits = Percent80_bits; break;
                        case HatchStyle.Percent90:
                                bits = Percent90_bits; break;
                        case HatchStyle.Plaid:
                                bits = Plaid_bits; break;
                        case HatchStyle.Shingle:
                                bits = Shingle_bits; break;
                        case HatchStyle.SmallCheckerBoard:
                                bits = SmallCheckerBoard_bits; break;
                        case HatchStyle.SmallConfetti:
                                bits = SmallConfetti_bits; break;
                        case HatchStyle.SmallGrid:
                                bits = SmallGrid_bits; break;
                        case HatchStyle.SolidDiamond:
                                bits = SolidDiamond_bits; break;
                        case HatchStyle.Sphere:
                                bits = Sphere_bits; break;
                        case HatchStyle.Trellis:
                                bits = Trellis_bits; break;
                        case HatchStyle.Vertical:
                                bits = Vertical_bits; break;
                        case HatchStyle.Wave:
                                bits = Wave_bits; break;
                        case HatchStyle.Weave:
                                bits = Weave_bits; break;
                        case HatchStyle.WideDownwardDiagonal:
                                bits = WideDownwardDiagonal_bits; break;
                        case HatchStyle.WideUpwardDiagonal:
                                bits = WideUpwardDiagonal_bits; break;
                        case HatchStyle.ZigZag:
                                bits = ZigZag_bits; break;
                        default: return IntPtr.Zero;
                }

                // Create the bitmap, cache it for later, and then return it.
                //This is temporary
                //should have all the bits in an inherited class (same for 
XSharp)
                byte[] flipped = new byte[bits.Length];
                Array.Copy(bits, flipped, bits.Length);
                Array.Reverse(flipped);
                bitmap = Win32.Api.CreateBitmap(16, 16, 1, 1, flipped);
                hatchBitmaps[(int)style] = bitmap;
                return bitmap;
                                
        }

        // Bitmap data for all of the hatch styles.
        private static readonly byte[] BackwardDiagonal_bits = {
                0x80,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,
                0x02,0x02,0x01,0x01,0x80,0x80,0x40,0x40,0x20,0x20,0x10,0x10,
                0x08,0x08,0x04,0x04,0x02,0x02,0x01,0x01};
        private static readonly byte[] DarkDownwardDiagonal_bits = {
                0x33,0x33,0x66,0x66,0xcc,0xcc,0x99,0x99,0x33,0x33,0x66,0x66,
                0xcc,0xcc,0x99,0x99,0x33,0x33,0x66,0x66,0xcc,0xcc,0x99,0x99,
                0x33,0x33,0x66,0x66,0xcc,0xcc,0x99,0x99};
        private static readonly byte[] DarkHorizontal_bits = {
                0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
                0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
                0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00};
        private static readonly byte[] DarkUpwardDiagonal_bits = {
                0xcc,0xcc,0x66,0x66,0x33,0x33,0x99,0x99,0xcc,0xcc,0x66,0x66,
                0x33,0x33,0x99,0x99,0xcc,0xcc,0x66,0x66,0x33,0x33,0x99,0x99,
                0xcc,0xcc,0x66,0x66,0x33,0x33,0x99,0x99};
        private static readonly byte[] DarkVertical_bits = {
                0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
                0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
                0x33,0x33,0x33,0x33,0x33,0x33, 0x33,0x33};
        private static readonly byte[] DashedDownwardDiagonal_bits = {
                0x00,0x00,0x00,0x00,0x11,0x11,0x22,0x22,0x44,0x44,0x88,0x88,
                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x11,0x22,0x22,
                0x44,0x44,0x88,0x88,0x00,0x00,0x00,0x00};
        private static readonly byte[] DashedHorizontal_bits = {
                0x0f,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0xf0,0x00,0x00,
                0x00,0x00,0x00,0x00,0x0f,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,
                0xf0,0xf0,0x00,0x00,0x00,0x00,0x00,0x00};
        private static readonly byte[] DashedUpwardDiagonal_bits = {
                0x00,0x00,0x00,0x00,0x88,0x88,0x44,0x44,0x22,0x22,0x11,0x11,
                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x44,0x44,
                0x22,0x22,0x11,0x11,0x00,0x00,0x00,0x00};
        private static readonly byte[] DashedVertical_bits = {
                0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,
                0x10,0x10,0x10,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
                0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
        private static readonly byte[] DiagonalBrick_bits = {
                0x80,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x18,0x18,0x24,0x24,
                0x42,0x42,0x81,0x81,0x80,0x80,0x40,0x40,0x20,0x20,0x10,0x10,
                0x18,0x18,0x24,0x24,0x42,0x42,0x81,0x81};
        private static readonly byte[] DiagonalCross_bits = {
                0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18,0x18,0x18,0x24,0x24,
                0x42,0x42,0x81,0x81,0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18,
                0x18,0x18,0x24,0x24,0x42,0x42,0x81,0x81};
        private static readonly byte[] Divot_bits = {
                0x00,0x00,0x08,0x08,0x10,0x10,0x08,0x08,0x00,0x00,0x01,0x01,
                0x80,0x80,0x01,0x01,0x00,0x00,0x08,0x08,0x10,0x10,0x08,0x08,
                0x00,0x00,0x01,0x01,0x80,0x80,0x01,0x01};
        private static readonly byte[] DottedDiamond_bits = {
                0x01,0x01,0x00,0x00,0x44,0x44,0x00,0x00,0x10,0x10,0x00,0x00,
                0x44,0x44,0x00,0x00,0x01,0x01,0x00,0x00,0x44,0x44,0x00,0x00,
                0x10,0x10,0x00,0x00,0x44,0x44,0x00,0x00};
        private static readonly byte[] DottedGrid_bits = {
                0x55,0x55,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,
                0x01,0x01,0x00,0x00,0x55,0x55,0x00,0x00,0x01,0x01,0x00,0x00,
                0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00};
        private static readonly byte[] ForwardDiagonal_bits = {
                0x01,0x01,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,
                0x40,0x40,0x80,0x80,0x01,0x01,0x02,0x02,0x04,0x04,0x08,0x08,
                0x10,0x10,0x20,0x20,0x40,0x40,0x80,0x80};
        private static readonly byte[] Horizontal_bits = {
                0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,
                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
        private static readonly byte[] HorizontalBrick_bits = {
                0xff,0xff,0x01,0x01,0x01,0x01,0x01,0x01,0xff,0xff,0x10,0x10,
                0x10,0x10,0x10,0x10,0xff,0xff,0x01,0x01,0x01,0x01,0x01,0x01,
                0xff,0xff,0x10,0x10,0x10,0x10,0x10,0x10};
        private static readonly byte[] LargeCheckerBoard_bits = {
                0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0xf0,0xf0,0xf0,0xf0,
                0xf0,0xf0,0xf0,0xf0,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
                0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0};
        private static readonly byte[] LargeConfetti_bits = {
                0x8d,0x8d,0x0c,0x0c,0xc0,0xc0,0xd8,0xd8,0x1b,0x1b,0x03,0x03,
                0x30,0x30,0xb1,0xb1,0x8d,0x8d,0x0c,0x0c,0xc0,0xc0,0xd8,0xd8,
                0x1b,0x1b,0x03,0x03,0x30,0x30,0xb1,0xb1};
        private static readonly byte[] LargeGrid_bits = {
                0xff,0xff,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
                0x01,0x01,0x01,0x01,0xff,0xff,0x01,0x01,0x01,0x01,0x01,0x01,
                0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
        private static readonly byte[] LightDownwardDiagonal_bits = {
                0x11,0x11,0x22,0x22,0x44,0x44,0x88,0x88,0x11,0x11,0x22,0x22,
                0x44,0x44,0x88,0x88,0x11,0x11,0x22,0x22,0x44,0x44,0x88,0x88,
                0x11,0x11,0x22,0x22,0x44,0x44,0x88,0x88};
        private static readonly byte[] LightHorizontal_bits = {
                0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,
                0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,
                0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00};
        private static readonly byte[] LightUpwardDiagonal_bits = {
                0x88,0x88,0x44,0x44,0x22,0x22,0x11,0x11,0x88,0x88,0x44,0x44,
                0x22,0x22,0x11,0x11,0x88,0x88,0x44,0x44,0x22,0x22,0x11,0x11,
                0x88,0x88,0x44,0x44,0x22,0x22,0x11,0x11};
        private static readonly byte[] LightVertical_bits = {
                0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
                0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
                0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11};
        private static readonly byte[] NarrowHorizontal_bits = {
                0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
                0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
                0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00};
        private static readonly byte[] NarrowVertical_bits = {
                0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
                0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
                0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa};
        private static readonly byte[] OutlinedDiamond_bits = {
                0x41,0x41,0x22,0x22,0x14,0x14,0x08,0x08,0x14,0x14,0x22,0x22,
                0x41,0x41,0x80,0x80,0x41,0x41,0x22,0x22,0x14,0x14,0x08,0x08,
                0x14,0x14,0x22,0x22,0x41,0x41,0x80,0x80};
        private static readonly byte[] Percent05_bits = {
                0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x00,
                0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
                0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00};
        private static readonly byte[] Percent10_bits = {
                0x01,0x01,0x00,0x00,0x10,0x10,0x00,0x00,0x01,0x01,0x00,0x00,
                0x10,0x10,0x00,0x00,0x01,0x01,0x00,0x00,0x10,0x10,0x00,0x00,
                0x01,0x01,0x00,0x00,0x10,0x10,0x00,0x00};
        private static readonly byte[] Percent20_bits = {
                0x11,0x11,0x00,0x00,0x44,0x44,0x00,0x00,0x11,0x11,0x00,0x00,
                0x44,0x44,0x00,0x00,0x11,0x11,0x00,0x00,0x44,0x44,0x00,0x00,
                0x11,0x11,0x00,0x00,0x44,0x44,0x00,0x00};
        private static readonly byte[] Percent25_bits = {
                0x11,0x11,0x44,0x44,0x11,0x11,0x44,0x44,0x11,0x11,0x44,0x44,
                0x11,0x11,0x44,0x44,0x11,0x11,0x44,0x44,0x11,0x11,0x44,0x44,
                0x11,0x11,0x44,0x44,0x11,0x11,0x44,0x44};
        private static readonly byte[] Percent30_bits = {
                0x55,0x55,0x22,0x22,0x55,0x55,0x88,0x88,0x55,0x55,0x22,0x22,
                0x55,0x55,0x88,0x88,0x55,0x55,0x22,0x22,0x55,0x55,0x88,0x88,
                0x55,0x55,0x22,0x22,0x55,0x55,0x88,0x88};
        private static readonly byte[] Percent40_bits = {
                0x55,0x55,0xaa,0xaa,0x55,0x55,0x8a,0x8a,0x55,0x55,0xaa,0xaa,
                0x55,0x55,0xa8,0xa8,0x55,0x55,0xaa,0xaa,0x55,0x55,0x8a,0x8a,
                0x55,0x55,0xaa,0xaa,0x55,0x55,0xa8,0xa8};
        private static readonly byte[] Percent50_bits = {
                0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,
                0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,
                0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa};
        private static readonly byte[] Percent60_bits = {
                0x77,0x77,0xaa,0xaa,0xdd,0xdd,0xaa,0xaa,0x77,0x77,0xaa,0xaa,
                0xdd,0xdd,0xaa,0xaa,0x77,0x77,0xaa,0xaa,0xdd,0xdd,0xaa,0xaa,
                0x77,0x77,0xaa,0xaa,0xdd,0xdd,0xaa,0xaa};
        private static readonly byte[] Percent70_bits = {
                0xee,0xee,0xbb,0xbb,0xee,0xee,0xbb,0xbb,0xee,0xee,0xbb,0xbb,
                0xee,0xee,0xbb,0xbb,0xee,0xee,0xbb,0xbb,0xee,0xee,0xbb,0xbb,
                0xee,0xee,0xbb,0xbb,0xee,0xee,0xbb,0xbb};
        private static readonly byte[] Percent75_bits = {
                0xee,0xee,0xff,0xff,0xbb,0xbb,0xff,0xff,0xee,0xee,0xff,0xff,
                0xbb,0xbb,0xff,0xff,0xee,0xee,0xff,0xff,0xbb,0xbb,0xff,0xff,
                0xee,0xee,0xff,0xff,0xbb,0xbb,0xff,0xff};
        private static readonly byte[] Percent80_bits = {
                0xf7,0xf7,0xff,0xff,0x7f,0x7f,0xff,0xff,0xf7,0xf7,0xff,0xff,
                0x7f,0x7f,0xff,0xff,0xf7,0xf7,0xff,0xff,0x7f,0x7f,0xff,0xff,
                0xf7,0xf7,0xff,0xff,0x7f,0x7f,0xff,0xff};
        private static readonly byte[] Percent90_bits = {
                0xff,0xff,0xff,0xff,0xff,0xff,0xef,0xef,0xff,0xff,0xff,0xff,
                0xff,0xff,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0xef,
                0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe};
        private static readonly byte[] Plaid_bits = {
                0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,0x0f,0x0f,0x0f,0x0f,
                0x0f,0x0f,0x0f,0x0f,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,
                0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f};
        private static readonly byte[] Shingle_bits = {
                0xc0,0xc0,0x21,0x21,0x12,0x12,0x0c,0x0c,0x30,0x30,0x40,0x40,
                0x80,0x80,0x80,0x80,0xc0,0xc0,0x21,0x21,0x12,0x12,0x0c,0x0c,
                0x30,0x30,0x40,0x40,0x80,0x80,0x80,0x80};
        private static readonly byte[] SmallCheckerBoard_bits = {
                0x99,0x99,0x66,0x66,0x66,0x66,0x99,0x99,0x99,0x99,0x66,0x66,
                0x66,0x66,0x99,0x99,0x99,0x99,0x66,0x66,0x66,0x66,0x99,0x99,
                0x99,0x99,0x66,0x66,0x66,0x66,0x99,0x99};
        private static readonly byte[] SmallConfetti_bits = {
                0x01,0x01,0x10,0x10,0x02,0x02,0x40,0x40,0x08,0x08,0x80,0x80,
                0x04,0x04,0x20,0x20,0x01,0x01,0x10,0x10,0x02,0x02,0x40,0x40,
                0x08,0x08,0x80,0x80,0x04,0x04,0x20,0x20};
        private static readonly byte[] SmallGrid_bits = {
                0xff,0xff,0x11,0x11,0x11,0x11,0x11,0x11,0xff,0xff,0x11,0x11,
                0x11,0x11,0x11,0x11,0xff,0xff,0x11,0x11,0x11,0x11,0x11,0x11,
                0xff,0xff,0x11,0x11,0x11,0x11,0x11,0x11};
        private static readonly byte[] SolidDiamond_bits = {
                0x08,0x08,0x1c,0x1c,0x3e,0x3e,0x7f,0x7f,0x3e,0x3e,0x1c,0x1c,
                0x08,0x08,0x00,0x00,0x08,0x08,0x1c,0x1c,0x3e,0x3e,0x7f,0x7f,
                0x3e,0x3e,0x1c,0x1c,0x08,0x08,0x00,0x00};
        private static readonly byte[] Sphere_bits = {
                0xee,0xee,0x91,0x91,0xf1,0xf1,0xf1,0xf1,0xee,0xee,0x19,0x19,
                0x1f,0x1f,0x1f,0x1f,0xee,0xee,0x91,0x91,0xf1,0xf1,0xf1,0xf1,
                0xee,0xee,0x19,0x19,0x1f,0x1f,0x1f,0x1f};
        private static readonly byte[] Trellis_bits = {
                0xff,0xff,0x66,0x66,0xff,0xff,0x99,0x99,0xff,0xff,0x66,0x66,
                0xff,0xff,0x99,0x99,0xff,0xff,0x66,0x66,0xff,0xff,0x99,0x99,
                0xff,0xff,0x66,0x66,0xff,0xff,0x99,0x99};
        private static readonly byte[] Vertical_bits = {
                0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
                0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
                0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
        private static readonly byte[] Wave_bits = {
                0x00,0x00,0x18,0x18,0xa4,0xa4,0x03,0x03,0x00,0x00,0x18,0x18,
                0xa4,0xa4,0x03,0x03,0x00,0x00,0x18,0x18,0xa4,0xa4,0x03,0x03,
                0x00,0x00,0x18,0x18,0xa4,0xa4,0x03,0x03};
        private static readonly byte[] Weave_bits = {
                0x11,0x11,0x2a,0x2a,0x44,0x44,0xa2,0xa2,0x11,0x11,0x28,0x28,
                0x44,0x44,0x8a,0x8a,0x11,0x11,0x2a,0x2a,0x44,0x44,0xa2,0xa2,
                0x11,0x11,0x28,0x28,0x44,0x44,0x8a,0x8a};
        private static readonly byte[] WideDownwardDiagonal_bits = {
                0x83,0x83,0x07,0x07,0x0e,0x0e,0x1c,0x1c,0x38,0x38,0x70,0x70,
                0xe0,0xe0,0xc1,0xc1,0x83,0x83,0x07,0x07,0x0e,0x0e,0x1c,0x1c,
                0x38,0x38,0x70,0x70,0xe0,0xe0,0xc1,0xc1};
        private static readonly byte[] WideUpwardDiagonal_bits = {
                0xc1,0xc1,0xe0,0xe0,0x70,0x70,0x38,0x38,0x1c,0x1c,0x0e,0x0e,
                0x07,0x07,0x83,0x83,0xc1,0xc1,0xe0,0xe0,0x70,0x70,0x38,0x38,
                0x1c,0x1c,0x0e,0x0e,0x07,0x07,0x83,0x83};
        private static readonly byte[] ZigZag_bits = {
                0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18,0x81,0x81,0x42,0x42,
                0x24,0x24,0x18,0x18,0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18,
                0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18};

}; // class DrawingHatchBrush

}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingPen.cs - Implementation of pens for System.Drawing.Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;

internal class DrawingPen : IToolkitPen, IDisposable
{
        // Internal state.
        internal Pen properties;
        private IntPtr hPen;
        private static IntPtr hPrevPen;
        private DrawingGraphics drawingGraphics;
        private IToolkit toolkit;

        // Constructor.
        public DrawingPen(IToolkit toolkit, Pen properties)
                        {
                                this.toolkit = toolkit;
                                this.properties = properties;
                                //TODO: Rest of the properties
                                int c = 
DrawingGraphics.ColorToWin32(properties.Color);
                                hPen = 
Win32.Api.CreatePen((int)properties.DashStyle, (int)properties.Width, c);
                        }

        // Select this pen into a graphics object.
        public void Select(IToolkitGraphics graphics)
                        {
                                drawingGraphics = graphics as DrawingGraphics;
                                if(drawingGraphics != null)
                                {
                                        drawingGraphics.selectedPen = this;
                                        IntPtr hOldPen = 
Win32.Api.SelectObject(drawingGraphics.hdc, hPen);
                                        if (hPrevPen == IntPtr.Zero)
                                                hPrevPen = hOldPen;
                                }
                        }

        // Dispose of this object.
        public void Dispose()
        {
                Win32.Api.SelectObject(drawingGraphics.hdc, hPrevPen);
                Win32.Api.DeleteObject(hPen);
        }

}; // class DrawingPen

}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingRootTopLevelWindow.cs - This is the main windows form for the 
application
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

        using System;
        using d=System.Diagnostics.Debug;

        internal class DrawingRootTopLevelWindow : DrawingTopLevelWindow
        {
                public DrawingRootTopLevelWindow(IToolkit toolkit, String name,
                        int width, int height) : base (toolkit, name, width, 
height) {}

                protected override void Destroyed()
                {
                        base.Destroyed ();
                        //Exit the message loop when the last window is 
destroyed
                        (toolkit as DrawingToolkit).Quit();
                }


                //TODO
                /*wParam 
        When the system sends this message as a result of a 
SystemParametersInfo call, wParam is a flag that indicates the system parameter 
that was changed. For a list of values, see SystemParametersInfo. 
        When the system sends this message as a result of a change in policy 
settings, this parameter indicates the type of policy that was applied. This 
value is 1 if computer policy was applied or zero if user policy was applied.

        When the system sends this message as a result of a change in locale 
settings, this parameter is zero.

        When an application sends this message, this parameter must be NULL.
        */
                //TODO
                protected override void SettingsChange(int wParam)
                {
                        
                }
        }
}

--- NEW FILE ---
/*
 * DrawingSolidBrush.cs - Implementation of solid brushes for 
System.Drawing.Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;

internal class DrawingSolidBrush : DrawingBrush, IToolkitBrush
{
        public DrawingSolidBrush(IToolkit toolkit, System.Drawing.Color color) 
: base(toolkit, color)
                        {
                                hBrush = CreateSolidBrush(color);
                        }

        public static IntPtr CreateSolidBrush(Color color)
        {
                Win32.Api.LOGBRUSH lb; 
                lb.lbStyle = 
(Win32.Api.LogBrushStyles)Win32.Api.LogBrushStyles.BS_SOLID;
                lb.lbColor = DrawingGraphics.ColorToWin32(color); 
                lb.lbHatch = 0;
                return Win32.Api.CreateBrushIndirect(ref lb);
        }

}; // class DrawingSolidBrush

}; // namespace System.Drawing.Toolkit;

--- NEW FILE ---
/*
 * DrawingTextureBrush.cs - Implementation of texture brushes for 
System.Drawing.Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;
using System.Drawing.Imaging;

internal class DrawingTextureBrush : DrawingBrush, IToolkitBrush
{
        // Internal state.
        private TextureBrush properties;
        private RectangleF dstRect;
        private ImageAttributes imageAttr;

        // Constructor.
        public DrawingTextureBrush(IToolkit toolkit, TextureBrush properties,
                                                           RectangleF dstRect,
                                                           ImageAttributes 
imageAttr) : base(toolkit, Color.Black)
                        {
                                this.properties = properties;
                                this.dstRect = dstRect;
                                this.imageAttr = imageAttr;
                                //TODO
                        }

}; // class DrawingTextureBrush

}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingToolkit.cs - Implementation of IToolkit for Win32.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;
using System.Drawing.Text;
using System.Drawing.Imaging;
using System.Collections;
using d = System.Diagnostics.Debug;

public class DrawingToolkit : IToolkit
{
        DrawingRootTopLevelWindow drawingRootTopLevelWindow;

        // TODO: Deprecated
        public void Run()
                        {
                        }

        // Process events in the event queue.  If "waitForEvent" is true,
        // then wait for the next event and return "false" if "Quit" was
        // seen.  If "waitForEvent" is false, then process events in the
        // queue and return "true".  If "waitForEvent" is false and there
        // are no events in the queue, then return "false".
        public bool ProcessEvents(bool waitForEvent)
                        {
                                Win32.Api.MSG message;
                                if (!waitForEvent)
                                {
                                        //return false if there is no message 
or the quit message
                                        if (!Win32.Api.PeekMessageA(out 
message, IntPtr.Zero, 0, 0, Win32.Api.PeekMessageType.PM_NOREMOVE)
                                                || 
message.message==Win32.Api.WindowsMessages.WM_QUIT)
                                                return false;
                                }
                                //process the message
                                if (Win32.Api.GetMessageA(out message, 
IntPtr.Zero,0,0)==0)
                                        return false; //occurs on WM_QUIT
                                Win32.Api.TranslateMessage(ref message);
                                Win32.Api.DispatchMessageA(ref message);        
                                return true;
                        }

        // Send a quit message to the toolkit, which should cause
        // it to exit from the "Run" method.
        public void Quit()
                        {
                                Win32.Api.PostQuitMessage(0);
                        }

        // Resolve a system color to an RGB value.  Returns -1 if the
        // system does not support the color and a default should be used.
        // TODO
        public int ResolveSystemColor(KnownColor color)
                        {
                                return -1;
                        /*ActiveBorder                  = 1,
        ActiveCaption                   = 2,
        ActiveCaptionText               = 3,
        AppWorkspace                    = 4,
        Control                                 = 5,
        ControlDark                             = 6,
        ControlDarkDark                 = 7,
        ControlLight                    = 8,
        ControlLightLight               = 9,
        ControlText                             = 10,
        Desktop                                 = 11,
        GrayText                                = 12,
        Highlight                               = 13,
        HighlightText                   = 14,
        HotTrack                                = 15,
        InactiveBorder                  = 16,
        InactiveCaption                 = 17,
        InactiveCaptionText             = 18,
        Info                                    = 19,
        InfoText                                = 20,
        Menu                                    = 21,
        MenuText                                = 22,
        ScrollBar                               = 23,
        Window                                  = 24,
        WindowFrame                             = 25,
        WindowText                              = 26,*/
                        }

        // Create an IToolkitGraphics object from a HDC.
        public IToolkitGraphics CreateFromHdc(IntPtr hdc, IntPtr hdevice)
                        {
                                // This is tricky - maybe we have to keep track 
of which hdc's we create?
                                return null;
                        }

        // Create an IToolkitGraphics object from a HWND.
        public IToolkitGraphics CreateFromHwnd(IntPtr hwnd)
                        {
                                return null;
                        }

        // Create a solid toolkit brush.
        public IToolkitBrush CreateSolidBrush(System.Drawing.Color color)
                        {
                                return new DrawingSolidBrush(this, color);
                        }

        // Create a hatched toolkit brush.
        public IToolkitBrush CreateHatchBrush
                                        (HatchStyle style, System.Drawing.Color 
foreColor,
                                         System.Drawing.Color backColor)
                        {
                                return new DrawingHatchBrush(this, style, 
foreColor, backColor);
                        }

        // Create a linear gradient brush.
        public IToolkitBrush CreateLinearGradientBrush
                                (RectangleF rect, System.Drawing.Color color1,
                                 System.Drawing.Color color2,
                                 LinearGradientMode mode)
                        {
                                //TODO
                                return null;
                        }

        public IToolkitBrush CreateLinearGradientBrush
                                (RectangleF rect, System.Drawing.Color color1,
                                 System.Drawing.Color color2, float angle,
                                 bool isAngleScaleable)
                        {
                                //TODO
                                return null;
                        }

        // Create a texture brush.
        public IToolkitBrush CreateTextureBrush
                                (TextureBrush properties, RectangleF dstRect,
                                 ImageAttributes imageAttr)
                        {
                                return new DrawingTextureBrush(this, 
properties, dstRect, imageAttr);
                        }

        // Create a toolkit pen from pen properties.
        // If the toolkit does not support the precise combination of pen
        // properties, it will return the closest matching pen.
        public IToolkitPen CreatePen(Pen pen)
                        {
                                return new DrawingPen(this, pen);
                        }

        // Create a toolkit font from the properties in the specified object.
        public IToolkitFont CreateFont(System.Drawing.Font font)
                        {
                                return new DrawingFont(this, font);
                        }

        // Get the handle for the halftone palette.  IntPtr.Zero if not 
supported.
        //TODO
        public IntPtr GetHalftonePalette()
                        {
                                return IntPtr.Zero;
                        }

        // Create a form.
        public IToolkitWindow CreateTopLevelWindow(int width, int height)
                        {
                                //for now..
                                if ( drawingRootTopLevelWindow == null)
                                {
                                        return drawingRootTopLevelWindow = new 
DrawingRootTopLevelWindow(this, string.Empty, width, height);
                                }
                                        
                                return new DrawingTopLevelWindow(this, 
string.Empty, width, height);
                        }

        // Create a top-level dialog shell.
        //TODO
        public IToolkitWindow CreateTopLevelDialog
                                (int width, int height, bool modal, bool 
resizable,
                                 IToolkitWindow dialogParent)
                        {
                                DrawingTopLevelWindow window;
                                window = new DrawingTopLevelWindow
                                        (this, String.Empty, width, height);
                                /*if(dialogParent is TopLevelWindow)
                                {
                                        window.TransientFor = 
(TopLevelWindow)dialogParent;
                                }
                                if(modal)
                                {
                                        window.InputType = 
MotifInputType.ApplicationModal;
                                }
                                else
                                {
                                        window.InputType = 
MotifInputType.Modeless;
                                }
                                if(!resizable)
                                {
                                        window.Decorations = 
MotifDecorations.Border |
                                                                                
 MotifDecorations.Title |
                                                                                
 MotifDecorations.Menu;
                                        window.Functions = MotifFunctions.Move |
                                                                           
MotifFunctions.Close;
                                }*/
                                return window;
                        }

        // Create a top-level menu shell.
        public IToolkitWindow CreateTopLevelMenu
                                (int x, int y, int width, int height)
                        {
                                // TODO
                                return null;
                        }

        // Create a child window.  If "parent" is null, then the child
        // does not yet have a "real" parent - it will be reparented later.
        public IToolkitWindow CreateChildWindow
                                (IToolkitWindow parent, int x, int y, int 
width, int height)
                        {
                                DrawingWindow dparent;
                                if(parent is DrawingWindow)
                                {
                                        dparent = ((DrawingWindow)parent);
                                }
                                else
                                {
                                        dparent = null;
                                }
                                return new DrawingControlWindow(this, "", 
dparent, x, y, width, height);
                        }

        // Get a list of all font families on this system, or all font
        // families that are compatible with a particular IToolkitGraphics.
        //TODO
        public FontFamily[] GetFontFamilies(IToolkitGraphics graphics)
                        {
                                // We only support three font families.  Extend 
later.
                                return new FontFamily [] {
                                        new FontFamily("Arial"),
                                        new FontFamily("Times New Roman"),
                                        new FontFamily("Courier New"),
                                };
                        }

        // Get font family metric information.
        public void GetFontFamilyMetrics(GenericFontFamilies genericFamily,
                                                                         String 
name,
                                                                         
System.Drawing.FontStyle style,
                                                                         out 
int ascent, out int descent,
                                                                         out 
int emHeight, out int lineSpacing)
                        {
                                //TODO
                                switch(genericFamily)
                                {
                                        case GenericFontFamilies.SansSerif:
                                        default:
                                        {
                                                // Metrics for "Arial".
                                                ascent = 1854;
                                                descent = 434;
                                                emHeight = 2048;
                                                lineSpacing = 2355;
                                        }
                                        break;

                                        case GenericFontFamilies.Serif:
                                        {
                                                // Metrics for "Times New 
Roman".
                                                ascent = 1825;
                                                descent = 443;
                                                emHeight = 2048;
                                                lineSpacing = 2355;
                                        }
                                        break;

                                        case GenericFontFamilies.Monospace:
                                        {
                                                // Metrics for "Courier New".
                                                ascent = 1705;
                                                descent = 615;
                                                emHeight = 2048;
                                                lineSpacing = 2320;
                                        }
                                        break;
                                }
                        }

        // Get the IToolkitFont that corresponds to a hdc's current font.
        // Returns null if there is no way to obtain the information.
        //TODO
        public IToolkitFont GetFontFromHdc(IntPtr hdc)
                        {
                                return null;
                        }

        // Get the IToolkitFont that corresponds to a native font object.
        // Returns null if there is no way to obtain the information.
        //TODO
        public IToolkitFont GetFontFromHfont(IntPtr hfont)
                        {
                                return null;
                        }

        // Get the IToolkitFont that corresponds to LOGFONT information.
        // Returns null if there is no way to obtain the information.
        //TODO
        public IToolkitFont GetFontFromLogFont(Object lf, IntPtr hdc)
                        {
                                return null;
                        }

        // Get the default IToolkitGraphics object to measure screen sizes.
        public IToolkitGraphics GetDefaultGraphics()
                        {
                                
d.WriteLine("DrawingToolkit.GetDefaultGraphics");
                                return new DrawingGraphics(this, 
Win32.Api.GetDC(Win32.Api.GetDesktopWindow()));
                        }

        // Get the screen size, in pixels.
        public Size GetScreenSize()
        {
                int x = 
Win32.Api.GetSystemMetrics(Win32.Api.SystemMetricsType.SM_CXSCREEN);
                int y = 
Win32.Api.GetSystemMetrics(Win32.Api.SystemMetricsType.SM_CYSCREEN);
                return new Size(x,y);
        }

        // Get the working area of the screen, excluding task bars, etc.
        public System.Drawing.Rectangle GetWorkingArea()
        {
                Win32.Api.RECT r;
                
Win32.Api.SystemParametersInfoA(Win32.Api.SystemParametersAction.SPI_GETWORKAREA,
 0, out r, 0);
                return new 
Rectangle(r.left,r.right,r.right-r.left,r.bottom-r.top);
        }

}; // class DrawingToolkit

}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingTopLevelWindow.cs - This is a windows form
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;
using d=System.Diagnostics.Debug;

internal class DrawingTopLevelWindow : DrawingWindow, IToolkitWindow
{

        protected static uint createCount;
        public DrawingTopLevelWindow(IToolkit toolkit, String name,
                                                                 int width, int 
height) : base ( toolkit, null )
                        {
                                
System.Diagnostics.Debug.WriteLine("DrawingTopLevelWindow");

                                //At the moment we create a unique class name 
for EVERY window. SWF does it for each unique window class
                                className = "DrawingTopLevelWindow" + 
createCount;

                                //Register the windows class
                                windowsClass = new Win32.Api.WNDCLASS();
                                windowsClass.style = 
Win32.Api.WindowClassStyle.CS_DBLCLKS;
                                windowsClass.lpfnWndProc = new 
Win32.Api.WNDPROC(WindowsLoop);
                                 //We will draw
                                windowsClass.hbrBackground = IntPtr.Zero;
                                windowsClass.lpszClassName = className ;
                                if (Win32.Api.RegisterClassA( ref 
windowsClass)==0) 
                                {
                                        throw new Exception("Failed to register 
Windows class " + className);
                                }
                                createCount++;
                                
                                //Set default window characteristics
                                style = Win32.Api.WindowStyle.WS_THICKFRAME |
                        Win32.Api.WindowStyle.WS_SYSMENU | 
Win32.Api.WindowStyle.WS_MAXIMIZEBOX | Win32.Api.WindowStyle.WS_MINIMIZEBOX | 
Win32.Api.WindowStyle.WS_CAPTION | Win32.Api.WindowStyle.WS_CLIPCHILDREN;
                                menu = false;
                                extendedStyle = 0;
                                CreateWindow(new Size( width, height ));
                        }

        // Change the set of supported window decorations and functions.
        void IToolkitWindow.SetWindowFlags(ToolkitWindowFlags flags)
                        {
                                style = Win32.Api.WindowStyle.WS_POPUP | 
Win32.Api.WindowStyle.WS_VISIBLE;
                
                                //to remove the popup style
                                Win32.Api.WindowStyle overlapped = 
~Win32.Api.WindowStyle.WS_POPUP;
                                
                                if((flags & ToolkitWindowFlags.Close) > 0)
                                        style |= 
Win32.Api.WindowStyle.WS_SYSMENU;

                                if((flags & ToolkitWindowFlags.Minimize) > 0)
                                        style = style & overlapped | 
Win32.Api.WindowStyle.WS_MINIMIZEBOX;

                                if((flags & ToolkitWindowFlags.Maximize) > 0)
                                        style = style & overlapped | 
Win32.Api.WindowStyle.WS_MAXIMIZEBOX;

                                if((flags & ToolkitWindowFlags.Caption) > 0)
                                        style |= 
Win32.Api.WindowStyle.WS_CAPTION;

                                if((flags & ToolkitWindowFlags.Border) > 0)
                                        style |= 
Win32.Api.WindowStyle.WS_BORDER;

                                if((flags & ToolkitWindowFlags.ResizeHandles) > 
0)
                                        style |= 
Win32.Api.WindowStyle.WS_THICKFRAME;

                                if((flags & ToolkitWindowFlags.Menu) > 0)
                                        style = style | 
Win32.Api.WindowStyle.WS_SYSMENU;

                                if((flags & ToolkitWindowFlags.Resize) > 0)
                                        style |= 
Win32.Api.WindowStyle.WS_THICKFRAME;

                                //We dont handle the Move flag in Win32

                                //TODO: NOT SURE HERE
                                if((flags & ToolkitWindowFlags.Modal) > 0)
                                        style |= Win32.Api.WindowStyle.WS_POPUP 
| Win32.Api.WindowStyle.WS_DLGFRAME;

                                //TODO: Need a hidden window
                                if((flags & ToolkitWindowFlags.ShowInTaskBar)>0)
                                        ;
                                else
                                        ;                       

                                if((flags & ToolkitWindowFlags.TopMost)>0)
                                        extendedStyle |= 
Win32.Api.WindowsExtendedStyle.WS_EX_TOPMOST;

                                if((flags & ToolkitWindowFlags.ToolWindow) > 0)
                                        extendedStyle |= 
Win32.Api.WindowsExtendedStyle.WS_EX_TOOLWINDOW;               

                                //Now set the style
                                if (Win32.Api.SetWindowLong(hwnd, 
Win32.Api.SetWindowLongType.GWL_STYLE,style) == 0)
                                        throw new 
InvalidOperationException("Unable to change the window style.");
                                if (Win32.Api.SetWindowLong(hwnd, 
Win32.Api.SetWindowLongType.GWL_EXSTYLE,extendedStyle) == 0)
                                        throw new 
InvalidOperationException("Unable to change the extended window style.");

                                //Redraw the entire window including the non 
client portion
                                Win32.Api.RedrawWindow( hwnd, IntPtr.Zero, 
IntPtr.Zero, Win32.Api.RedrawWindowFlags.RDW_INVALIDATE | 
Win32.Api.RedrawWindowFlags.RDW_FRAME );
                                d.WriteLine( 
"DrawingTopLevelWindow.SetWindowFlags, hwnd="+hwnd );

                        }

        //Use the style and extended style and menu thats currenly in use to 
get the actual size of the window with all the extra trimmings added
        protected override Rectangle OutsideFromClientSize(Rectangle client)
        {
                Win32.Api.RECT rect;
                rect.left = client.Left;
                rect.top = client.Top;
                rect.right = client.Right;
                rect.bottom = client.Bottom;
                Win32.Api.AdjustWindowRectEx( ref rect, style, menu, 
extendedStyle );
                return new Rectangle( rect.left, rect.top, 
rect.right-rect.left, rect.bottom-rect.top );
        }

        //Create the invisible control
        protected void CreateWindow(Size size) 
        {
                Size outside = OutsideFromClientSize( size );

                hwnd = Win32.Api.CreateWindowExA( extendedStyle, className, "", 
style, Win32.Api.CW_USEDEFAULT, 0, outside.Width, outside.Height, IntPtr.Zero, 
IntPtr.Zero, Win32.Api.GetModuleHandleA(null), IntPtr.Zero );
                if (hwnd==IntPtr.Zero) 
                {
                        throw new Exception( "Failed to create new Window" );
                }
                Win32.Api.InvalidateRect( hwnd, IntPtr.Zero,true );
                d.WriteLine( "DrawingTopLevelWindow.CreateWindow, 
hwnd="+hwnd+", [" + size.ToString() + "]" );
        }
}; // class DrawingTopLevelWindow

}; // namespace System.Drawing.Toolkit

--- NEW FILE ---
/*
 * DrawingWindow.cs - Abstract DrawingWindow class. This is each win32 window, 
controls and forms.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;
using System.Runtime.InteropServices;
using d = System.Diagnostics.Debug;

internal abstract class DrawingWindow : IToolkitWindow
{
        protected IToolkit toolkit;
        protected IToolkitEventSink sink;
        protected internal IntPtr hwnd;
        protected IntPtr hdc;
        protected DrawingWindow parent;
        private Color background;
        //cached when we create the window
        private IntPtr backgroundBrush = IntPtr.Zero;
        //have we told windows that we want to be notified when the mouse 
leaves?
        private bool trackingMouse;

        //Windows Class name
        protected string className;
        //This structure needs to be kept in memory
        protected Win32.Api.WNDCLASS windowsClass;
        //Used so we can tell the size of the non client window
        protected Win32.Api.WindowStyle style;
        //Used so we can tell the size of the non client window
        protected Win32.Api.WindowsExtendedStyle extendedStyle;
        //Used so we can tell the size of the non client window
        //Does the window have a menu
        protected bool menu = false;

        protected DrawingWindow(IToolkit toolkit, DrawingWindow parent )
        {
                this.toolkit = toolkit;
                this.parent = parent;
        }

        // Set the window title (top-level windows only).
        void IToolkitWindow.SetTitle(String title)
        {
                if(title == null)
                {
                        title = String.Empty;
                }
                Win32.Api.SetWindowTextA(hwnd, title);
                d.WriteLine("DrawingWindow.SetTitle, hwnd="+hwnd);
        }

        void IToolkitWindow.Lower()
        {
                Win32.Api.SetWindowPos(hwnd, 
Win32.Api.SetWindowsPosPosition.HWND_BOTTOM, 0, 0, 0, 0, 
Win32.Api.SetWindowsPosFlags.SWP_NOMOVE | 
Win32.Api.SetWindowsPosFlags.SWP_NOSIZE);
                d.WriteLine("DrawingWindow.Lower, hwnd="+hwnd);
        }

        void IToolkitWindow.Raise()
        {
                Win32.Api.SetWindowPos(hwnd, 
Win32.Api.SetWindowsPosPosition.HWND_TOP, 0, 0, 0, 0, 
Win32.Api.SetWindowsPosFlags.SWP_NOMOVE | 
Win32.Api.SetWindowsPosFlags.SWP_NOSIZE);
                d.WriteLine("DrawingWindow.Raise, hwnd="+hwnd);
        }

        // Get the adjustment values for the client area.
        // On entry, all values are zero.
        void IToolkitWindow.GetClientAreaAdjust(ref int leftAdjust, ref int 
topAdjust, ref int rightAdjust, ref int bottomAdjust)
        {
                //Nothing to do
        }

        // Move this window to below one of its siblings.
        // Is this really useful?
        void IToolkitWindow.MoveToBelow(IToolkitWindow sibling)
        {
                throw new NotImplementedException();
        }

        // Move this window to above one of its siblings.
        void IToolkitWindow.MoveToAbove(IToolkitWindow sibling)
        {
                Win32.Api.SetWindowPos(hwnd, (sibling as DrawingWindow).hwnd, 
0, 0, 0, 0, Win32.Api.SetWindowsPosFlags.SWP_NOMOVE | 
Win32.Api.SetWindowsPosFlags.SWP_NOSIZE);
                d.WriteLine("DrawingWindow.MoveToAbove, hwnd="+hwnd);
        }


        void IToolkitWindow.Reparent(IToolkitWindow parent, int x, int y)
        {
        }

        public IToolkit Toolkit
        {
                get
                {
                        return toolkit;
                }
        }

        //Client dimensions
        Rectangle IToolkitWindow.Dimensions
        {
                get
                {
                        Win32.Api.RECT rect;
                        Win32.Api.GetClientRect(hwnd, out rect);
                        return new System.Drawing.Rectangle(rect.top, 
rect.left, rect.right-rect.left, rect.bottom - rect.top);
                }
        }

        //Does the window have focus
        bool IToolkitWindow.Focused
        {
                get
                {
                        return Win32.Api.GetForegroundWindow() == hwnd;
                }
        }

        //Destroy window
        public virtual void Destroy()
        {
                Win32.Api.DestroyWindow(hwnd);
                d.WriteLine("DrawingWindow.Destroy, hwnd="+hwnd);
        }

        //After the WM_DESTORY message
        protected virtual void Destroyed()
        {
                d.WriteLine("DrawingWindow.Destroyed, hwnd="+hwnd);
        }

        void 
IToolkitWindow.SetWindowFlags(System.Drawing.Toolkit.ToolkitWindowFlags flags)
        {
        }

        // Set the background of the window to a solid color.
        void IToolkitWindow.SetBackground(System.Drawing.Color color)
        {
                if (color != background)
                {
                        background = color;
                        //If there was already a background brush then delete it
                        if (backgroundBrush!=IntPtr.Zero)
                                Win32.Api.DeleteObject(backgroundBrush);
                        //Create the new cached brush
                        backgroundBrush = 
DrawingSolidBrush.CreateSolidBrush(background);
                        d.WriteLine("DrawingControlWindow.SetBackground, 
hwnd="+hwnd);
                }
        }

        void IToolkitWindow.MoveResize(int x, int y, int width, int height)
        {
                Rectangle rect = (this as IToolkitWindow).Dimensions;
        
                if (x != rect.Left || y != rect.Right || width != rect.Width
                        || height != rect.Height)
                {
                        Rectangle outside = OutsideFromClientSize(new 
Rectangle( x, y, width, height));
                        Win32.Api.SetWindowPos(hwnd, 
Win32.Api.SetWindowsPosPosition.HWND_TOP, outside.Left, outside.Top, 
outside.Width, outside.Height, Win32.Api.SetWindowsPosFlags.SWP_NOSENDCHANGING);
                }
                d.WriteLine("DrawingWindow.MoveResize, 
hwnd="+hwnd+",["+x+","+y+","+width+","+height+"]");
        }

        // Set the event sink to use for this window.
        void IToolkitWindow.SetEventSink(IToolkitEventSink sink)
        {
                this.sink = sink;
        }

        //This is the windows visibility
        bool IToolkitWindow.IsMapped
        {
                get
                {
                        return Win32.Api.IsWindowVisible(hwnd);
                }
                set
                {
                        if (value)
                                
Win32.Api.ShowWindow(hwnd,Win32.Api.ShowWindowCommand.SW_SHOWNA);
                        else
                                
Win32.Api.ShowWindow(hwnd,Win32.Api.ShowWindowCommand.SW_HIDE);
                        d.WriteLine("DrawingWindow.setIsMapped 
hwnd="+hwnd+",visible="+value);
                }
        }

        // Force an update of all invalidated regions.
        void IToolkitWindow.Update()
        {
                Win32.Api.UpdateWindow(hwnd);
                d.WriteLine("DrawingWindow.Update, hwnd="+hwnd);
        }

        void IToolkitWindow.SetForeground(Color color)
        {
        }

        void IToolkitWindow.Iconify()
        {
                Win32.Api.CloseWindow(hwnd);
                d.WriteLine("DrawingWindow.Iconify, hwnd="+hwnd);
        }


        // Get a toolkit graphics object for this window.
        IToolkitGraphics IToolkitWindow.GetGraphics()
        {
                d.WriteLine("DrawingWindow.GetGraphics, hwnd="+hwnd);
                return new DrawingGraphics (toolkit, Win32.Api.GetDC(hwnd));
        }


        // Get the toolkit parent window.
        IToolkitWindow IToolkitWindow.Parent
        {
                get
                {
                        return (IToolkitWindow)parent;
                }
        }

        System.IntPtr IToolkitWindow.GetHwnd()
        {
                return hwnd;
        }

        // Invalidate a rectangle within this window.
        public void Invalidate(int x, int y, int width, int height)
        {
                Win32.Api.RECT r;
                r.left = x;
                r.top = y;
                //TODO: Check if its +1
                r.right = x + width + 1;
                r.bottom = y + height + 1;
                Win32.Api.InvalidateRect(hwnd, ref r, false);
                d.WriteLine("DrawingWindow.Invalidate, hwnd="+hwnd + " 
["+x+","+y+","+width+","+height+"]");
        }

        // Invalidate this window.
        public void Invalidate()
        {
                Win32.Api.InvalidateRect(hwnd, IntPtr.Zero, false);
        }

        //Called when Windows wants to erase the form background. Use the 
provided hdc
        protected void EraseBackground(IntPtr hdc) 
        {
                if (backgroundBrush!=IntPtr.Zero) 
                {
                        Win32.Api.RECT clientRectangle;
                        Win32.Api.GetClientRect(hwnd, out clientRectangle);
                        Win32.Api.FillRect(hdc, ref 
clientRectangle,backgroundBrush);
                }
        }

        //Called when windows receives WM_MOUSEMOVE
        protected void MouseMove(int wParam, int lParam) 
        {
                if (!trackingMouse) 
                {
                        //so we get notified when the mouse leaves this window
                        Win32.Api.TRACKMOUSEEVENT tm = new 
Win32.Api.TRACKMOUSEEVENT();
                        tm.hwndTrack = hwnd;
                        tm.dwFlags = Win32.Api.TrackMouseEventFlags.TME_LEAVE;
                        tm.cbSize = Marshal.SizeOf(tm);
                        Win32.Api.TrackMouseEvent(ref tm);
                        trackingMouse = true;
                        sink.ToolkitMouseEnter();
                }

                sink.ToolkitMouseMove(ToolkitMouseButtons.None, 
MapMouseToToolkitKeys(wParam),0 ,MouseX(lParam) , MouseY(lParam), 0);
                d.WriteLine("DrawingWindow.MouseMove [" + (MouseX(lParam)) + 
"," + (MouseY(lParam)) + "], key:" + MapMouseToToolkitKeys(wParam));
        }

        //Called when windows receives WM_MOUSEWHEEL
        protected void MouseWheel( int wParam, int lParam)
        {
                int wheelDelta = (wParam >> 16)/120;
                sink.ToolkitMouseWheel(ToolkitMouseButtons.None, 
MapMouseToToolkitKeys(wParam), 0, MouseX(lParam) , MouseY(lParam), wheelDelta);
                d.WriteLine("DrawingWindow.MouseWheel [" + (MouseX(lParam)) + 
"," + (MouseY(lParam)) + "], key:" + MapMouseToToolkitKeys(wParam) + ", wheel:" 
+ wheelDelta);
        }

        protected void MouseLeave() 
        {
                trackingMouse = false;
                sink.ToolkitMouseLeave();
                d.WriteLine("DrawingWindow.MouseLeave, hwnd="+hwnd);
        }

        protected void ButtonDown(int wParam, int lParam)
        {
                sink.ToolkitMouseDown(MapToToolkitMouseButtons(wParam), 
MapMouseToToolkitKeys(wParam), 0 ,MouseX(lParam), MouseY(lParam) ,0);
                d.WriteLine("DrawingWindow.ButtonDown [" + (MouseX(lParam)) + 
"," + (MouseY(lParam)) + "], key:" + MapMouseToToolkitKeys(wParam) + ", 
button:" + MapToToolkitMouseButtons(wParam));
        }

        protected void ButtonUp(int wParam, int lParam)
        {
                sink.ToolkitMouseUp(MapToToolkitMouseButtons(wParam), 
MapMouseToToolkitKeys(wParam), 0 ,MouseX(lParam), MouseY(lParam),0);
                d.WriteLine("DrawingWindow.ButtonUp [" + (MouseX(lParam)) + "," 
+ (MouseY(lParam)) + "], key:" + MapMouseToToolkitKeys(wParam) + ", button:" + 
MapToToolkitMouseButtons(wParam));
        }

        protected void DoubleClick( int wParam, int lParam)
        {
                sink.ToolkitMouseDown(MapToToolkitMouseButtons(wParam), 
MapMouseToToolkitKeys(wParam), 2 ,MouseX(lParam), MouseY(lParam),0);
                d.WriteLine("DrawingWindow.DoubleClick [" + (MouseX(lParam)) + 
"," + (MouseY(lParam)) + "], key:" + MapMouseToToolkitKeys(wParam) + ", 
button:" + MapToToolkitMouseButtons(wParam));
        }

        protected void KeyDown( int wParam, int lParam)
        {
                sink.ToolkitKeyDown((ToolkitKeys)(wParam & 0xFFFF));
                d.WriteLine("DrawingWindow.KeyDown " + ((ToolkitKeys)(wParam & 
0xFFFF)).ToString());
        }

        protected void Char( int wParam, int lParam)
        {
                sink.ToolkitKeyChar((char)wParam);
                d.WriteLine("DrawingWindow.Char " + ((char)wParam).ToString());
        }
        
        protected void KeyUp( int wParam, int lParam )
        {
                sink.ToolkitKeyUp((ToolkitKeys)(wParam & 0xFFFF));
                d.WriteLine("DrawingWindow.KeyUp " + ((ToolkitKeys)(wParam & 
0xFFFF)).ToString());
        }

        //TODO:
        protected void SetCursor( int cursor )
        {
                Win32.Api.SetCursor(Win32.Api.LoadCursorA(IntPtr.Zero, 
Win32.Api.CursorName.IDC_ARROW));
        }

        //WM_PAINT
        protected void Paint()
        {
                Win32.Api.PAINTSTRUCT myPS;
                hdc = Win32.Api.BeginPaint( hwnd, out myPS );
                if( sink != null )
                {
                        DrawingGraphics g = new DrawingGraphics( toolkit, hdc );
                        System.Drawing.Graphics gr = 
ToolkitManager.CreateGraphics( g );
                        g.SetClipRect( myPS.rcPaint.left, myPS.rcPaint.top, 
myPS.rcPaint.right - myPS.rcPaint.left, myPS.rcPaint.bottom - myPS.rcPaint.top 
);
                        sink.ToolkitExpose( gr );
                        gr.Dispose();
                }
                d.WriteLine( "DrawingWindow.Paint hwnd="+hwnd );

                Win32.Api.EndPaint( hwnd, ref myPS );
        }

        //WM_SETFOCUS occurs when either mouse or keyboard sets focus
        protected void SetFocus()
        {
                if (sink != null)
                        sink.ToolkitFocusEnter();
                d.WriteLine( "DrawingWindow.GotFocus hwnd="+hwnd );
        }

        //WM_KILLFOCUS occurs when either mouse or keyboard causes focus to be 
lost (or windows does)
        protected void KillFocus()
        {
                if (sink != null)
                        sink.ToolkitFocusEnter();
                d.WriteLine( "DrawingWindow.LostFocus hwnd="+hwnd ) ;
        }

        //WM_WINDOWPOSCHANGING
        protected void WindowPosChanging(int lParam)
        {
                //When window is created - CreateWindow(), WindowPosChanging is 
called when the initial size is set
                //because sink==null, its size and position will be set
                if (sink != null)
                {
                #if false       // cscc has probs with pointers - to be fixed 
soon -- Rhys
                        unsafe
                        {
                                Win32.Api.WINDOWPOS *pos = 
(Win32.Api.WINDOWPOS*)lParam;
                                Rectangle rect = (this as 
IToolkitWindow).Dimensions;
                                        
                                //If moving
                                if (((*pos).flags & 2) == 0)
                                {
                                        Rectangle offset = 
OutsideFromClientSize( new Rectangle(0,0,0,0) );
                                        sink.ToolkitExternalMove( (*pos).x - 
offset.X, (*pos).y - offset.Y );
                                }

                                //If sizing
                                if (((*pos).flags & 1) ==0)
                                {
                                        Rectangle offset = 
OutsideFromClientSize( new Rectangle(0,0,0,0) );
                                        sink.ToolkitExternalResize( (*pos).cx - 
offset.Width, (*pos).cy - offset.Height );
                                }       
                                //Now prevent windows from changing the 
position or size, System.Windows.Control will do that
                                (*pos).flags |= (uint)0x3;
                        }
                #endif
                }
        }

        //WM_SETTINGSCHANGE occurs when some windows setting changes. This is 
used to notify the app that system settings have changed eg. button colors or 
form colors
        //We only want the RootTopLevelWindow to receive this
        protected virtual void SettingsChange(int wParam)
        {
        }

        //The main windows loop. Messages are handed off
        protected int WindowsLoop(IntPtr hwnd, int msg, int wParam, int lParam) 
 
        {
                int retval = 0;
                switch((Win32.Api.WindowsMessages)msg) 
                {

                        case Win32.Api.WindowsMessages.WM_SETFOCUS:
                                SetFocus();
                                break;
                        case Win32.Api.WindowsMessages.WM_KILLFOCUS:
                                KillFocus();
                                break;

                        case Win32.Api.WindowsMessages.WM_WINDOWPOSCHANGING:
                                WindowPosChanging(lParam);
                                break;

                        case Win32.Api.WindowsMessages.WM_SYSCOMMAND:
                                switch((Win32.Api.SystemCommand)wParam) 
                                {
                                        
case(Win32.Api.SystemCommand.SC_RESTORE):
                                                //TODO
                                                retval = 
Win32.Api.DefWindowProcA(hwnd, msg, wParam, lParam);
                                                break;
                                        
case(Win32.Api.SystemCommand.SC_MAXIMIZE):
                                                //TODO
                                                retval = 
Win32.Api.DefWindowProcA(hwnd, msg, wParam, lParam);
                                                break;
                                        
case(Win32.Api.SystemCommand.SC_MINIMIZE):
                                                //TODO
                                                retval = 
Win32.Api.DefWindowProcA(hwnd, msg, wParam, lParam);
                                                break;
                                        case(Win32.Api.SystemCommand.SC_CLOSE):
                                                //TODO
                                                retval = 
Win32.Api.DefWindowProcA(hwnd, msg, wParam, lParam);
                                                break;
                                        default:
                                                retval = 
Win32.Api.DefWindowProcA(hwnd, msg, wParam, lParam);
                                                break;
                                }
                                        break;  

                        case Win32.Api.WindowsMessages.WM_DESTROY:
                                Destroyed();
                                break;

                        case Win32.Api.WindowsMessages.WM_PAINT:
                                Paint();
                                break;
                        case Win32.Api.WindowsMessages.WM_ERASEBKGND:
                                EraseBackground( (IntPtr)wParam );
                                retval=1;
                                break;

                        case Win32.Api.WindowsMessages.WM_MOUSEMOVE:
                                MouseMove( wParam, lParam );
                                break;
                        case Win32.Api.WindowsMessages.WM_MOUSEWHEEL:
                                MouseMove( wParam, lParam );
                                break;
                        case Win32.Api.WindowsMessages.WM_LBUTTONDOWN:
                        case Win32.Api.WindowsMessages.WM_RBUTTONDOWN:
                        case Win32.Api.WindowsMessages.WM_MBUTTONDOWN:
                        case Win32.Api.WindowsMessages.WM_XBUTTONDOWN:
                                ButtonDown( wParam, lParam );
                                break;
                        case Win32.Api.WindowsMessages.WM_LBUTTONUP:
                        case Win32.Api.WindowsMessages.WM_RBUTTONUP:
                        case Win32.Api.WindowsMessages.WM_MBUTTONUP:
                        case Win32.Api.WindowsMessages.WM_XBUTTONUP:
                                ButtonUp( wParam, lParam );
                                break;
                        case Win32.Api.WindowsMessages.WM_LBUTTONDBLCLK:
                        case Win32.Api.WindowsMessages.WM_RBUTTONDBLCLK:
                        case Win32.Api.WindowsMessages.WM_MBUTTONDBLCLK:
                        case Win32.Api.WindowsMessages.WM_XBUTTONDBLCLK:
                                DoubleClick( wParam, lParam );
                                break;
                        case Win32.Api.WindowsMessages.WM_MOUSELEAVE:
                                MouseLeave();
                                break;

                        case Win32.Api.WindowsMessages.WM_KEYDOWN:
                                KeyDown( wParam, lParam );
                                break;
                        case Win32.Api.WindowsMessages.WM_CHAR:
                                Char( wParam, lParam );
                                break;
                        case Win32.Api.WindowsMessages.WM_KEYUP:
                                KeyUp( wParam, lParam );
                                break;

                        case Win32.Api.WindowsMessages.WM_SETTINGCHANGE:
                                SettingsChange( wParam );
                                break;

                        default:
                                retval = Win32.Api.DefWindowProcA(hwnd, msg, 
wParam, lParam);
                                break;
                }
                return retval;
        }

        //Gives the overall window size, given a client size, including all 
windows trimmings eg. borders, title. DrawingControlWindow doesnt override
        protected virtual Size OutsideFromClientSize(Size client)
        {
                return OutsideFromClientSize(new Rectangle(0, 0, client.Width, 
client.Height)).Size;
        }

        //Gives the overall window bounds, given a client client bounds, 
including all windows trimmings eg. borders, title. DrawingControlWindow doesnt 
override
        protected virtual Rectangle OutsideFromClientSize(Rectangle client)
        {
                return client;
        }

        //Extract the mouse positions
        protected int MouseX( int value )
        {
                return 0xFFFF & value;
        }

        protected int MouseY( int value )
        {
                return value >> 16;
        }

        //Map the win32 MouseKeyState to ToolkitMouseButtons
        private ToolkitMouseButtons MapToToolkitMouseButtons( int wParam )
        {
                ToolkitMouseButtons buttons = ToolkitMouseButtons.None; 
                Win32.Api.MouseKeyState fwKeys = (Win32.Api.MouseKeyState) 
(wParam & 0xFFFF);

                if ((fwKeys & Win32.Api.MouseKeyState.MK_LBUTTON)>0)
                        buttons |= ToolkitMouseButtons.Left;

                if ((fwKeys & Win32.Api.MouseKeyState.MK_MBUTTON)>0)
                        buttons |= ToolkitMouseButtons.Middle;

                if ((fwKeys & Win32.Api.MouseKeyState.MK_RBUTTON)>0)
                        buttons |= ToolkitMouseButtons.Right;

                if ((fwKeys & Win32.Api.MouseKeyState.MK_XBUTTON1)>0)
                        buttons |= ToolkitMouseButtons.XButton1;

                if ((fwKeys & Win32.Api.MouseKeyState.MK_XBUTTON2)>0)
                        buttons |= ToolkitMouseButtons.XButton2;

                return buttons;
        }

        //Map the win32 MouseKeyState to ToolkitKeys. Alt is handled differently
        private ToolkitKeys MapMouseToToolkitKeys( int wParam )
        {
                ToolkitKeys keys = ToolkitKeys.None;
                Win32.Api.MouseKeyState fwKeys = (Win32.Api.MouseKeyState) 
(wParam & 0xFFFF);
                if ((fwKeys & Win32.Api.MouseKeyState.MK_CONTROL)>0)
                        keys |= ToolkitKeys.Control;

                if ((fwKeys & Win32.Api.MouseKeyState.MK_SHIFT)>0)
                        keys |= ToolkitKeys.Shift;

                if ((Win32.Api.GetKeyState(Win32.Api.VirtualKeyType.VK_MENU) & 
0x800) > 0)
                        keys |= ToolkitKeys.Alt;
                
                return keys;

        }

}
}

--- NEW FILE ---

.PHONY: System.Drawing.Win32.dll

all-local: System.Drawing.Win32.dll

System.Drawing.Win32.dll:
        "$(CSANT)" $(CSANT_FLAGS) -f System.Drawing.Win32.build all

CLEANFILES = System.Drawing.Win32.dll

pnetassembliesdir = $(libdir)/cscc/lib
pnetassemblies_DATA = System.Drawing.Win32.dll

--- NEW FILE ---
<?xml version="1.0"?>
<project name="pnetlib System.Drawing.Win32" default="all">
        <target name="all">

                <!-- Build the primary System.Drawing.Win32.dll library -->
                <compile output="System.Drawing.Win32.dll"
                                 target="library"
                                 unsafe="true"
                                 nostdlib="true"
                                 debug="${CONFIG_DEBUG_LINES}"
                                 optimize="true">

                        <sources>
                                <includes name="**/*.cs"/>
                        </sources>

                        <references>
                                <file 
name="../System.Drawing/System.Drawing.dll"/>
                                <file name="../Xsharp/Xsharp.dll"/>
                                <file name="../System/first/System.dll"/>
                                <file name="../DotGNU.SSL/DotGNU.SSL.dll"/>
                                <file name="../runtime/mscorlib.dll"/>
                        </references>

                        <arg compiler="cscc" value="-Wno-empty-input"/>
                        <arg compiler="cscc" value="-fminimize-parameters"/>
                        <arg compiler="csc" value="/nowarn:626"/>
                        <arg compiler="csc" value="/nowarn:649"/>
                        <arg compiler="csc" value="/nowarn:168"/>
                        <arg compiler="csc" value="/nowarn:67"/>
                        <arg compiler="csc" value="/nowarn:169"/>
                        <arg compiler="csc" value="/nowarn:679"/>
                </compile>

        </target>
</project>

--- NEW FILE ---
/*
 * Win32.cs - Api class for all native constants, structures and calls.
 * Copyright (C) 2003  Neil Cawse.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Win32
{

using System;
using System.Runtime.InteropServices;

internal class Api
{
        public delegate int WNDPROC( IntPtr hwnd, int msg, int wParam, int 
lParam);

        public enum WindowClassStyle :uint
        {
                CS_VREDRAW = 0x0001,
                CS_HREDRAW = 0x0002,
                CS_DBLCLKS = 0x0008,
                CS_OWNDC = 0x0020,
                CS_CLASSDC = 0x0040,
                CS_PARENTDC = 0x0080,
                CS_NOCLOSE = 0x0200,
                CS_SAVEBITS = 0x0800,
                CS_BYTEALIGNCLIENT = 0x1000,
                CS_BYTEALIGNWINDOW = 0x2000,
                CS_GLOBALCLASS = 0x4000,
                CS_IME = 0x00010000,
                CS_DROPSHADOW = 0x00020000
        }

        public enum WindowsMessages : int 
                {
                        WM_CREATE = 0x1,
                        WM_DESTROY = 0x2,
                        WM_ACTIVATE = 0x6,
                        WM_SETFOCUS = 0x7,
                        WM_KILLFOCUS = 0x8,
                        WM_PAINT = 0xF,
                        WM_CLOSE = 0x10,
                        WM_QUIT = 0x12,
                        WM_ERASEBKGND = 0x14,
                        WM_SETTINGCHANGE = 0x1A,
                        WM_SETCURSOR = 0x20,
                        WM_WINDOWPOSCHANGING = 0x46,
                        WM_NCCALCSIZE = 0x83,
                        WM_NCHITTEST = 0x84,
                        WM_NCPAINT = 0x0085,
                        WM_NCACTIVATE = 0x86,
                        WM_KEYDOWN = 0x0100,
                        WM_KEYUP = 0x0101,
                        WM_CHAR = 0x0102,
                        WM_SYSCOMMAND = 0x112,
                        WM_TIMER = 0x0113,
                        WM_MOUSEMOVE = 0x0200,
                        WM_LBUTTONDOWN = 0x0201,
                        WM_LBUTTONUP = 0x0202,
                        WM_LBUTTONDBLCLK = 0x0203,
                        WM_RBUTTONDOWN = 0x0204,
                        WM_RBUTTONUP = 0x0205,
                        WM_RBUTTONDBLCLK = 0x0206,
                        WM_MBUTTONDOWN = 0x0207,
                        WM_MBUTTONUP = 0x0208,
                        WM_MBUTTONDBLCLK = 0x0209,
                        WM_MOUSEWHEEL = 0x020A,
                        WM_XBUTTONDOWN = 0x020B,
                        WM_XBUTTONUP = 0x020C,
                        WM_XBUTTONDBLCLK = 0x020D,
                        WM_SIZING = 0x0214,
                        WM_MOVING = 0x0216,
                        WM_MOUSELEAVE = 0x02A3

                }

        public enum MouseKeyState : ushort
        {
                MK_LBUTTON = 0x1,
                MK_RBUTTON = 0x2,
                MK_SHIFT = 0x4,
                MK_CONTROL = 0x8,
                MK_MBUTTON = 0x10,
                MK_XBUTTON1 = 0x20,
                MK_XBUTTON2 = 0x40
        }

        //Window Styles used when creating a window
        public enum WindowStyle : uint 
        {
                WS_OVERLAPPED = 0x00000000,
                WS_POPUP = 0x80000000,
                WS_CHILD = 0x40000000,
                WS_MINIMIZE = 0x20000000,
                WS_VISIBLE = 0x10000000,
                WS_DISABLED = 0x08000000,
                WS_CLIPSIBLINGS = 0x04000000,
                WS_CLIPCHILDREN = 0x02000000,
                WS_MAXIMIZE = 0x01000000,
                WS_CAPTION = 0x00C00000,    /* WS_BORDER | WS_DLGFRAME  */
                WS_BORDER = 0x00800000,
                WS_DLGFRAME = 0x00400000,
                WS_VSCROLL = 0x00200000,
                WS_HSCROLL = 0x00100000,
                WS_SYSMENU = 0x00080000,
                WS_THICKFRAME = 0x00040000,
                WS_GROUP = 0x00020000,
                WS_TABSTOP = 0x00010000,
                WS_MINIMIZEBOX = 0x00020000,
                WS_MAXIMIZEBOX = 0x00010000,
                WS_TILED = WS_OVERLAPPED,
                WS_ICONIC = WS_MINIMIZE,
                WS_SIZEBOX = WS_THICKFRAME,
                WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,
                WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | 
WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
                WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
                WS_CHILDWINDOW = WS_CHILD
        }

        public enum WindowsExtendedStyle : uint
        {
                WS_EX_DLGMODALFRAME = 0x00000001,
                WS_EX_NOPARENTNOTIFY = 0x00000004,
                WS_EX_TOPMOST = 0x00000008,
                WS_EX_ACCEPTFILES = 0x00000010,
                WS_EX_TRANSPARENT = 0x00000020,
                WS_EX_MDICHILD = 0x00000040,
                WS_EX_TOOLWINDOW = 0x00000080,
                WS_EX_WINDOWEDGE = 0x00000100,
                WS_EX_CLIENTEDGE = 0x00000200,
                WS_EX_CONTEXTHELP = 0x00000400,
                WS_EX_RIGHT = 0x00001000,
                WS_EX_LEFT = 0x00000000,
                WS_EX_RTLREADING = 0x00002000,
                WS_EX_LTRREADING = 0x00000000,
                WS_EX_LEFTSCROLLBAR = 0x00004000,
                WS_EX_RIGHTSCROLLBAR = 0x00000000,
                WS_EX_CONTROLPARENT = 0x00010000,
                WS_EX_STATICEDGE = 0x00020000,
                WS_EX_APPWINDOW = 0x00040000,
                WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE),
                WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | 
WS_EX_TOPMOST)
        }

        //For ShowWindow API
        public enum SetWindowsPosFlags : uint 
        {
                SWP_NOSIZE = 0x1,
                SWP_NOMOVE = 0x2,
                SWP_NOZORDER = 0x4,
                SWP_NOREDRAW = 0x8,
                SWP_NOACTIVATE = 0x10,
                SWP_SHOWWINDOW = 0x40,
                SWP_HIDEWINDOW = 0x80,
                SWP_NOSENDCHANGING = 0x400
        }

        public enum SetWindowsPosPosition : int
        {
                HWND_TOP =0,
                HWND_BOTTOM = 1,
                HWND_TOPMOST = -1,
                HWND_NOTOPMOST = -2
        }

        public enum SystemMetricsType 
        {
                SM_CXSCREEN = 0,
                SM_CYSCREEN = 1,
                SM_CYCAPTION = 4,
                SM_CXBORDER = 5,
                SM_CYBORDER = 6,
                SM_CXFIXEDFRAME = 7,
                SM_CYFIXEDFRAME = 8,
                SM_CXSIZE = 30,
                SM_CYSIZE = 31,
                SM_CXFRAME = 32,
                SM_CYFRAME = 33,
                SM_CXEDGE = 45,
                SM_CYEDGE = 46,
                SM_CXSMICON = 49,
                SM_CYSMICON = 50,
                SM_CXSMSIZE = 52,
                SM_CYSMSIZE = 53
        }
        
        public enum SystemParametersAction : uint 
        {
                SPI_GETBORDER = 0x5,
                SPI_GETNONCLIENTMETRICS=0x29,
                SPI_GETWORKAREA=0x30,
                SPI_GETGRADIENTCAPTIONS=0x1008
        }

        public const int CW_USEDEFAULT = unchecked((int)0x80000000);

        public enum ShowWindowCommand 
        {
                SW_HIDE = 0,
                SW_SHOWNORMAL = 1,
                SW_MAXIMIZE = 3,
                SW_SHOW = 5,
                SW_MINIMIZE = 6,
                SW_SHOWNA = 8 //Visible but no activate
        }

        public enum SystemCommand
        {
                SC_MINIMIZE = 0xF020,
                SC_MAXIMIZE = 0xF030,
                SC_CLOSE = 0xF060,
                SC_RESTORE = 0xF120
        }

        public enum StockObjectType
        {
                WHITE_BRUSH = 0,
                LTGRAY_BRUSH = 1,
                GRAY_BRUSH = 2,
                DKGRAY_BRUSH = 3,
                BLACK_BRUSH = 4,
                HOLLOW_BRUSH = 5, //also NULL_BRUSH
                WHITE_PEN = 6,
                BLACK_PEN = 7,
                NULL_PEN = 8,
                OEM_FIXED_FONT = 10,
                ANSI_FIXED_FONT = 11,
                ANSI_VAR_FONT = 12,
                SYSTEM_FONT = 13,
                DEVICE_DEFAULT_FONT = 14,
                DEFAULT_PALETTE = 15,
                SYSTEM_FIXED_FONT = 16
        }

        public enum LogBrushStyles
        {
                BS_SOLID = 0,
                BS_HOLLOW = 1,
                BS_HATCHED = 2,
                BS_PATTERN = 3,
                BS_INDEXED = 4,
                BS_DIBPATTERN = 5,
                BS_DIBPATTERNPT = 6,
                BS_PATTERN8X8 = 7,
                BS_DIBPATTERN8X8 = 8,
                BS_MONOPATTERN = 9
        }

        public enum FontQuality : byte 
        {
                NONANTIALIASED_QUALITY = 3,
                ANTIALIASED_QUALITY = 4,
                CLEARTYPE_QUALITY =5,
                CLEARTYPE_NATURAL_QUALITY = 6
        }

        public enum BackGroundModeType
        {
                TRANSPARENT = 1
        }

        public enum TrackMouseEventFlags : uint
        {
                TME_LEAVE = 2
        }

        public enum CursorName
        {
                IDC_ARROW = 32512,
                IDC_IBEAM = 32513,
                IDC_WAIT = 32514,
                IDC_CROSS = 32515,
                IDC_UPARROW = 32516,
                IDC_SIZENWSE = 32642,
                IDC_SIZENESW = 32643,
                IDC_SIZEWE = 32644,
                IDC_SIZENS = 32645,
                IDC_SIZEALL = 32646
        }

        public enum PeekMessageType : uint
        {
                PM_NOREMOVE = 0x0000,
                PM_REMOVE = 0x0001,
                PM_NOYIELD = 0x0002
        }

        public enum SetWindowLongType
        {
                GWL_STYLE = -16,
                GWL_EXSTYLE = -20
        }

        public enum RedrawWindowFlags
        {
                RDW_INVALIDATE = 0x1,
                RDW_FRAME = 0x400
        }

        public enum VirtualKeyType
        {
                VK_SHIFT = 0x10,
                VK_CONTROL = 0x11,
                VK_MENU = 0x12, //ALT KEY
                VK_LSHIFT = 0xA0,
                VK_RSHIFT = 0xA1,
                VK_LCONTROL = 0xA2,
                VK_RCONTROL = 0xA3,
                VK_LMENU = 0xA4,
                VK_RMENU = 0xA5

        }

        [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
        public struct WNDCLASS 
        {
                public WindowClassStyle style;
                public WNDPROC lpfnWndProc;
                public int cbClsExtra;
                public int cbWndExtra;
                public IntPtr hInstance;
                public IntPtr hIcon;
                public IntPtr hCursor;
                public IntPtr hbrBackground;
                public string lpszMenuName;
                public string lpszClassName;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct MSG 
        {
                public IntPtr hwnd;
                public WindowsMessages message;
                public int wParam;
                public int lParam;
                public int itime;
                public int pt_x;
                public int pt_y;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct PAINTSTRUCT 
        {
                public IntPtr hdc;
                public bool fErase;
                public RECT rcPaint;
                public bool fRestore;
                public bool fIncUpdate;
                public int reserved1;
                public int reserved2;
                public int reserved3;
                public int reserved4;
                public int reserved5;
                public int reserved6;
                public int reserved7;
                public int reserved8;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct RECT 
        {
                public int left; 
                public int top; 
                public int right; 
                public int bottom; 
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct POINT 
        {
                public int x;
                public int y;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SIZE
        {
                public int cx;
                public int cy;
        }

        // Logical Brush (or Pattern)
        [StructLayout(LayoutKind.Sequential)]
        public struct LOGBRUSH 
        {
                public LogBrushStyles lbStyle;
                public int lbColor;
                public long lbHatch;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct NONCLIENTMETRICS 
        {
                public uint cbSize;
                public int iBorderWidth;
                public int iScrollWidth;
                public int iScrollHeight;
                public int iCaptionWidth;
                public int iCaptionHeight;
                public LOGFONT lfCaptionFont;
                public int iSmCaptionWidth;
                public int iSmCaptionHeight;
                public LOGFONT lfSmCaptionFont;
                public int iMenuWidth;
                public int iMenuHeight;
                public LOGFONT lfMenuFont;
                public LOGFONT lfStatusFont;
                public LOGFONT lfMessageFont;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct LOGFONT
        {
                public int lfHeight;
                public int lfWidth;
                public int lfEscapement;
                public int lfOrientation;
                public int lfWeight;
                public byte lfItalic;
                public byte lfUnderline;
                public byte lfStrikeout;
                public byte lfCharSet;
                public byte lfOutPrecision;
                public byte lfClipPrecision;
                public FontQuality lfQuality;
                public byte lfPitchAndFamily;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
                public string lfFaceName;
        }

        [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
        public struct TEXTMETRIC 
        { 
                public int tmHeight; 
                public int tmAscent; 
                public int tmDescent; 
                public int tmInternalLeading; 
                public int tmExternalLeading; 
                public int tmAveCharWidth; 
                public int tmMaxCharWidth; 
                public int tmWeight; 
                public int tmOverhang; 
                public int tmDigitizedAspectX; 
                public int tmDigitizedAspectY; 
                public char tmFirstChar; 
                public char tmLastChar; 
                public char tmDefaultChar; 
                public char tmBreakChar; 
                public byte tmItalic; 
                public byte tmUnderlined; 
                public byte tmStruckOut; 
                public byte tmPitchAndFamily; 
                public byte tmCharSet; 
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct TRACKMOUSEEVENT
        {
                public int cbSize;
                public TrackMouseEventFlags dwFlags;
                public IntPtr hwndTrack;
                public uint dwHoverTime;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct WINDOWPOS
        {
                public IntPtr hwnd;
                public IntPtr hwndInsertAfter;
                public int x;
                public int y;
                public int cx;
                public int cy;
                public uint flags;
        }

        [DllImport("user32")] //ANSI
        public static extern int RegisterClassA(ref WNDCLASS wc);

        [DllImport("user32")] //ANSI
        public static extern int DefWindowProcA(IntPtr hwnd, int msg, int 
wParam, int lParam);
                
        [DllImport("user32")]
        public static extern void PostQuitMessage(int nExitCode);

        [DllImport("user32")] //ANSI
        public static extern int GetMessageA(out MSG msg, IntPtr hwnd, int 
minFilter, int maxFilter);

        [DllImport("user32")] //ANSI
        public static extern bool PeekMessageA(out MSG lpMsg, IntPtr hWnd, uint 
wMsgFilterMin, uint wMsgFilterMax, PeekMessageType wRemoveMsg );
        
        [DllImport("user32",CharSet=CharSet.Ansi)] //ANSI
        public static extern int DispatchMessageA(ref MSG msg);
        
        [DllImport("user32")]
        public static extern bool TranslateMessage(ref MSG msg);

        [DllImport("gdi32")] //ANSI
        public static extern bool TextOutA(IntPtr hdc, int x, int y, string 
textstring, int charCount);

        [DllImport("user32")]
        public static extern IntPtr BeginPaint(IntPtr hwnd, out PAINTSTRUCT ps);

        [DllImport("user32")]
        public static extern bool EndPaint (IntPtr hwnd, ref PAINTSTRUCT ps);
                
        [DllImport("user32")]
        public static extern bool GetClientRect(IntPtr hwnd, out RECT rect);

        [DllImport("gdi32")]
        public static extern int GetClipBox(IntPtr hdc, out RECT lprc);

        [DllImport("user32")] 
        public extern static System.IntPtr GetDC(System.IntPtr hwnd); 

        [DllImport("user32")]
        public static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC);

        [DllImport("user32")] //ANSI
        public static extern IntPtr CreateWindowExA(WindowsExtendedStyle 
dwExStyle, string lpszClassName, string lpszWindowName, WindowStyle style, int 
x, int y, int width, int height, IntPtr hWndParent, IntPtr hMenu, IntPtr hInst, 
IntPtr pvParam);
        
        [DllImport("kernel32")] //ANSI
        public static extern IntPtr GetModuleHandleA(string modName);

        [DllImport("user32")]
        public static extern bool SetWindowPos( IntPtr hwnd, IntPtr 
hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowsPosFlags uFlags );

        [DllImport("user32")]
        public static extern bool SetWindowPos( IntPtr hwnd, 
SetWindowsPosPosition hWndInsertAfter, int X, int Y, int cx, int cy, 
SetWindowsPosFlags uFlags );

        [DllImport("user32")]
        public static extern bool ShowWindow(IntPtr hwnd, ShowWindowCommand 
nCmdShow );

        [DllImport("user32")]
        public static extern bool UpdateWindow(IntPtr hwnd);

        [DllImport("gdi32")]
        public static extern bool LineTo(IntPtr hdc, int nXEnd, int nYEnd);
        
        [DllImport("gdi32")]
        public static extern bool MoveToEx(IntPtr hdc, int X, int Y, IntPtr 
lpPoint);

        [DllImport("gdi32")]
        public static extern int SetPixel(IntPtr hdc, int X, int Y, int crColor 
);

        [DllImport("gdi32")]
        public static extern bool Polygon( IntPtr hdc, POINT[] lpPoints, int 
nCount);

        [DllImport("gdi32")]
        public static extern int SetPolyFillMode( IntPtr hdc, int iPolyFillMode 
);

        [DllImport("gdi32")]
        public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

        [DllImport("gdi32")]
        public static extern bool DeleteObject(IntPtr hObject);

        [DllImport("gdi32")]
        public static extern IntPtr CreatePen(int fnPenStyle, int nWidth, int 
crColor);

        [DllImport("gdi32")]
        public static extern IntPtr CreateBrushIndirect(ref LOGBRUSH lplb);

        [DllImport("user32")] //ANSI
        public static extern bool PostMessageA(IntPtr hwnd, WindowsMessages 
Msg, int wParam, int lParam);

        [DllImport("user32")]
        public static extern int GetSystemMetrics (SystemMetricsType nIndex);

        [DllImport("user32")] //ANSI
        public static extern bool SystemParametersInfoA(SystemParametersAction 
uiAction, uint uiParam, out RECT pvParam, uint fWinIni );

        [DllImport("user32")] //ANSI
        public static extern bool SystemParametersInfoA(SystemParametersAction 
uiAction, uint uiParam, out int pvParam, uint fWinIni );
                
        [DllImport("user32")] //ANSI
        public static extern bool SystemParametersInfoA(SystemParametersAction 
uiAction, uint uiParam, out bool pvParam, uint fWinIni );
                
        [DllImport("user32")] //ANSI
        public static extern bool SystemParametersInfoA(uint uiAction, uint 
uiParam, ref NONCLIENTMETRICS pvParam,uint fWinIni);

        //Get font information
        [DllImport("gdi32")]
        public static extern bool GetTextMetrics( IntPtr hdc, out TEXTMETRIC 
lptm);

        //Measure size and width of text
        [DllImport("gdi32")] //ANSI
        public static extern int GetTextExtentPoint32A(IntPtr hdc, string str, 
int len, ref SIZE size);
        
        [DllImport("gdi32")]
        public static extern IntPtr GetStockObject( StockObjectType fnObject );

        [DllImport("gdi32")]
        public static extern int SetBkMode(IntPtr hdc, BackGroundModeType 
iBkMode);

        [DllImport("user32")]
        public static extern int FillRect(IntPtr hDC, ref RECT lprc, IntPtr 
hbr);

        [DllImport("user32")] //ANSI
        public static extern bool SetWindowTextA( IntPtr hWnd, string lpString);

        [DllImport("user32")]
        public static extern bool GetWindowRect( IntPtr hWnd, out RECT lpRect );

        [DllImport("user32")]
        public static extern bool InvalidateRect(IntPtr hWnd, ref RECT hRgn, 
bool bErase);

        [DllImport("user32")]
        public static extern bool InvalidateRect(IntPtr hWnd, IntPtr hRgn, bool 
bErase);
        
        [DllImport("user32")]
        public static extern bool TrackMouseEvent( ref TRACKMOUSEEVENT 
lpEventTrack);

        [DllImport("user32")]
        public static extern IntPtr SetCursor( IntPtr hCursor);
                
        [DllImport("user32")] //ANSI
        public static extern IntPtr LoadCursorA( IntPtr hInstance, CursorName 
lpCursorName);

        [DllImport("user32")]
        public static extern bool DestroyWindow( IntPtr hWnd );

        [DllImport("user32")]
        public static extern IntPtr GetDesktopWindow();

        [DllImport("user32")]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32")]
        public static extern bool CloseWindow(IntPtr hWnd);

        [DllImport("gdi32")]
        public static extern bool Arc( IntPtr hdc, int nLeftRect,int nTopRect, 
int nRightRect, int nBottomRect, int nXStartArc, int nYStartArc, int nXEndArc, 
int nYEndArc );

        [DllImport("gdi32")]
        public static extern bool Pie( IntPtr hdc, int nLeftRect,int nTopRect, 
int nRightRect, int nBottomRect, int nXRadial1, int nYRadial1, int nXRadial2, 
int nYRadial2 );

        [DllImport("gdi32")]
        public static extern IntPtr SetTextColor( IntPtr hdc, int crColor);

        [DllImport("gdi32")]
        public static extern int SetBkColor( IntPtr hdc,int crColor);

        [DllImport("user32")]
        public static extern bool IsWindowVisible( IntPtr hWnd);

        [DllImport("gdi32")]
        public static extern IntPtr CreatePatternBrush( IntPtr hbmp );

        [DllImport("gdi32")]
        public static extern IntPtr CreateBitmap( int nWidth, int nHeight, uint 
cPlanes, uint cBitsPerPel, byte[] lpvBits);

        [DllImport("user32")]
        public static extern long SetWindowLong( IntPtr hWnd, SetWindowLongType 
nIndex, WindowStyle dwNewLong);

        [DllImport("user32")]
        public static extern long SetWindowLong( IntPtr hWnd, SetWindowLongType 
nIndex, WindowsExtendedStyle dwNewLong);

        [DllImport("user32")]
        public static extern long GetWindowLong( IntPtr hWnd, SetWindowLongType 
nIndex);

        [DllImport("user32")]
        public static extern bool RedrawWindow( IntPtr hWnd, IntPtr lprcUpdate, 
IntPtr hrgnUpdate, RedrawWindowFlags flags);

        [DllImport("user32")]
        public static extern bool AdjustWindowRectEx(ref RECT lpRect, 
WindowStyle dwStyle, bool bMenu, WindowsExtendedStyle dwExStyle);

        [DllImport("user32")]
        public static extern short GetKeyState( VirtualKeyType nVirtKey );

        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateRectRgn(int nLeftRect, int nTopRect, 
int nRightRect, int nBottomRect);
                
        [DllImport("gdi32.dll")]
        public static extern int SelectClipRgn(IntPtr hdc, IntPtr hrgn);


}//Api

}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]