# Patch created by 
# Date: Wed Jun 23 16:44:53 WAST 2004
# Repository: pnetlib-syscolors
# Comments:
# Implements system color resolution on Windows platforms.
#### End of Preamble ####

#### Patch data follows ####
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/ChangeLog,v
retrieving revision 1.1871
diff -c -r1.1871 ChangeLog
*** ChangeLog	22 Jun 2004 14:39:15 -0000	1.1871
--- ChangeLog	23 Jun 2004 08:47:16 -0000
***************
*** 1,3 ****
--- 1,10 ----
+ 2004-06-23  Maciek Plewa <milsim@mil-sim.net>
+ 
+ 	* System.Drawing.Win32/DrawingToolkit.cs: implemented system
+ 	color scheme resolution
+ 
+ 	* System.Drawing.Win32/Win32.cs: added utility color enums
+ 
  2004-06-22  Richard Baumann  <biochem333@nyc.rr.com>
  
  	* System.Xml/XmlElement.cs: fixed IsEmpty behavior for non-empty
Index: System.Drawing.Win32/DrawingToolkit.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Win32/DrawingToolkit.cs,v
retrieving revision 1.32
diff -c -r1.32 DrawingToolkit.cs
*** System.Drawing.Win32/DrawingToolkit.cs	16 Jun 2004 15:13:52 -0000	1.32
--- System.Drawing.Win32/DrawingToolkit.cs	23 Jun 2004 08:47:51 -0000
***************
*** 93,128 ****
  
  	// 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.
--- 93,114 ----
  
  	// Resolve a system color to an RGB value.  Returns -1 if the
  	// system does not support the color and a default should be used.
  	public int ResolveSystemColor(KnownColor color)
  	{
! 		// array out of bounds
! 		if ((int)color >= Win32.Api.KnownColorWindowsMap.Length)
! 			return -1;
! 
! 		// map KnownColor to Windows color type
! 		int syscolortype = Win32.Api.KnownColorWindowsMap[(int)color];
! 			
! 		// get BGR value of system color
! 		int colorbgr = Win32.Api.GetSysColor(syscolortype);
! 
! 		// convert the BGR value to RGB
! 		int colorrgb = Win32.Api.SwapRGB(colorbgr);
! 
! 		return colorrgb;
  	}
  
  	// Create an IToolkitGraphics object from a HDC.
Index: System.Drawing.Win32/Win32.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Win32/Win32.cs,v
retrieving revision 1.23
diff -c -r1.23 Win32.cs
*** System.Drawing.Win32/Win32.cs	31 May 2004 15:29:01 -0000	1.23
--- System.Drawing.Win32/Win32.cs	23 Jun 2004 08:48:22 -0000
***************
*** 25,30 ****
--- 25,49 ----
  
  internal class Api
  {
+ 	/// <summary>
+ 	/// Utility function for swapping colors - BGR to RGB and vice versa
+ 	/// </summary>
+ 	/// <param name="c">color value, e.g. 0xDEADF0</param>
+ 	/// <returns>swapped value, e.g. 0xF0ADDE</returns>
+ 	public static int SwapRGB(int color)
+ 	{
+ 		string zeropad = "000000";
+ 		string hexcolor = color.ToString("X6");
+ 
+ 		hexcolor = zeropad.Substring(0, 6 - (hexcolor.Length)) + hexcolor;
+ 
+ 		int b = Convert.ToByte(Convert.ToInt32(hexcolor.Substring(0, 2), 16));
+ 		int g = Convert.ToByte(Convert.ToInt32(hexcolor.Substring(2, 2), 16));
+ 		int r = Convert.ToByte(Convert.ToInt32(hexcolor.Substring(4, 2), 16));
+ 
+ 		return ((r * 256) + g) * 256 + b;
+ 	}
+ 
  	public delegate int WNDPROC( IntPtr hwnd, int msg, int wParam, int lParam);
  
  	public enum WindowClassStyle :uint
***************
*** 275,280 ****
--- 294,365 ----
  		BS_MONOPATTERN = 9
  	}
  
+ 	// Color types - winuser.h
+ 	private enum WinUserColor : int
+ 	{
+ 		COLOR_SCROLLBAR         = 0,
+ 		COLOR_BACKGROUND        = 1,
+ 		COLOR_ACTIVECAPTION     = 2,
+ 		COLOR_INACTIVECAPTION   = 3,
+ 		COLOR_MENU              = 4,
+ 		COLOR_WINDOW            = 5,
+ 		COLOR_WINDOWFRAME       = 6,
+ 		COLOR_MENUTEXT          = 7,
+ 		COLOR_WINDOWTEXT        = 8,
+ 		COLOR_CAPTIONTEXT       = 9,
+ 		COLOR_ACTIVEBORDER      = 10,
+ 		COLOR_INACTIVEBORDER    = 11,
+ 		COLOR_APPWORKSPACE      = 12,
+ 		COLOR_HIGHLIGHT         = 13,
+ 		COLOR_HIGHLIGHTTEXT     = 14,
+ 		COLOR_BTNFACE           = 15,
+ 		COLOR_BTNSHADOW         = 16,
+ 		COLOR_GRAYTEXT          = 17,
+ 		COLOR_BTNTEXT           = 18,
+ 		COLOR_INACTIVECAPTIONTEXT = 19,
+ 		COLOR_BTNHIGHLIGHT      = 20,
+ 		COLOR_3DDKSHADOW        = 21,
+ 		COLOR_3DLIGHT           = 22,
+ 		COLOR_INFOTEXT          = 23,
+ 		COLOR_INFOBK            = 24,
+ 		COLOR_HOTLIGHT          = 26,
+ 		COLOR_GRADIENTACTIVECAPTION = 27,
+ 		COLOR_GRADIENTINACTIVECAPTION = 28,
+ 		COLOR_MENUHILIGHT       = 29,
+ 		COLOR_MENUBAR           = 30
+ 	}
+ 
+ 	// Utility array for mapping KnownColor to WinUserColor
+ 	public static readonly int[] KnownColorWindowsMap = {
+ 		0x00000000,
+ 		(int)WinUserColor.COLOR_ACTIVEBORDER,			// ActiveBorder
+ 		(int)WinUserColor.COLOR_ACTIVECAPTION,			// ActiveCaption
+ 		(int)WinUserColor.COLOR_CAPTIONTEXT,			// ActiveCaptionText
+ 		(int)WinUserColor.COLOR_APPWORKSPACE,			// AppWorkspace
+ 		(int)WinUserColor.COLOR_BTNFACE,				// Control
+ 		(int)WinUserColor.COLOR_BTNSHADOW,				// ControlDark
+ 		(int)WinUserColor.COLOR_3DDKSHADOW,				// ControlDarkDark
+ 		(int)WinUserColor.COLOR_3DLIGHT,				// ControlLight
+ 		(int)WinUserColor.COLOR_BTNHIGHLIGHT,			// ControlLightLight
+ 		(int)WinUserColor.COLOR_BTNTEXT,				// ControlText
+ 		(int)WinUserColor.COLOR_BACKGROUND,				// Desktop
+ 		(int)WinUserColor.COLOR_GRAYTEXT,				// GrayText
+ 		(int)WinUserColor.COLOR_HIGHLIGHT,				// Highlight
+ 		(int)WinUserColor.COLOR_HIGHLIGHTTEXT,			// HighlightText
+ 		(int)WinUserColor.COLOR_HOTLIGHT,				// HotTrack
+ 		(int)WinUserColor.COLOR_INACTIVEBORDER,			// InactiveBorder
+ 		(int)WinUserColor.COLOR_INACTIVECAPTION,		// InactiveCaption
+ 		(int)WinUserColor.COLOR_INACTIVECAPTIONTEXT,	// InactiveCaptionText
+ 		(int)WinUserColor.COLOR_INFOBK,					// Info
+ 		(int)WinUserColor.COLOR_INFOTEXT,				// InfoText
+ 		(int)WinUserColor.COLOR_MENUBAR,				// Menu
+ 		(int)WinUserColor.COLOR_MENU,					// MenuText
+ 		(int)WinUserColor.COLOR_BTNFACE,				// ScrollBar
+ 		(int)WinUserColor.COLOR_WINDOW,					// Window
+ 		(int)WinUserColor.COLOR_WINDOWFRAME,			// WindowFrame
+ 		(int)WinUserColor.COLOR_WINDOWTEXT				// WindowText
+ 	};
+ 
  	public enum FontQuality : byte 
  	{
  		NONANTIALIASED_QUALITY = 3,
***************
*** 893,898 ****
--- 978,986 ----
  	[DllImport("user32")]
  	public static extern bool CloseWindow(IntPtr hWnd);
  
+ 	[DllImport("user32")]
+ 	public extern static int GetSysColor(int nIndex);
+ 
  	[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 );
  
***************
*** 1037,1042 ****
--- 1125,1140 ----
  	[DllImport("gdi32")]
  	public static extern bool DeleteDC(IntPtr hdc);
  
+ 	/// <summary>
+ 	/// Retrieves Windows version
+ 	/// </summary>
+ 	/// <returns>
+ 	/// Unsigned integer representing Windows version
+ 	/// To obtain e.g. the major version:
+ 	/// windowsMajorVer = GetVersion() & 0xFF;
+ 	/// </returns>
+ 	[DllImport("kernel32.dll")]
+ 	public extern static uint GetVersion();
  }//Api
  
  }
#### End of Patch data ####
