[Mono-winforms-list] SWF Wine Color integration

Johannes Roith johannes@jroith.de
Wed, 27 Aug 2003 19:47:55 +0200


--=-w31voldokpnqlJRUs2Fl
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello, Windows.Formers!

I have written a small patch yesterday, that themes SWF/Wine with Gtk+
colors.

screenshot here: http://www.jroith.de/swfsample.png

Miguel pointed out, that loading Gtk# probably probably eats to much
memory, so the current approach would be

* Read the values from a configuration file
* store the values there once, using a small app
* try to set up an event to call that app everytime the theme changes

Owen suggested using XSETTINGS for the event stuff.

Old patch is attached.
Any comments?

Johannes

--=-w31voldokpnqlJRUs2Fl
Content-Disposition: attachment; filename=gtkswf.cs
Content-Type: text/plain; name=gtkswf.cs; charset=UTF-8
Content-Transfer-Encoding: 7bit

// Gtk# Integration in System.Windows.Forms.dll
// [C] 2003 by Johannes Roith

// NOTE: The colors choosen, are not always correct, or the best solution.
// This will be changed overtime to get best integration.

using System;
using System.Windows.Forms;
using Gdk;
using GdkSharp;
using Gtk;
using GtkSharp;

class GtkSharpColorProvider {

	static uint Rgb (byte red, byte green, byte blue) {
		uint rgbvalue = blue;
		rgbvalue = rgbvalue<<8;
		rgbvalue +=green;
		rgbvalue = rgbvalue <<8;
		rgbvalue+=red;
		return rgbvalue;
	}

	static uint ConvertColor(Color color) {

		uint colorint = Rgb((byte) color.red, (byte) color.green, (byte) color.blue);
		return colorint;

	}
	public static uint[] GetColors() {

		Gtk.Application.Init();

		Gtk.Invisible invisible1 = new Gtk.Invisible();
		invisible1.EnsureStyle();
		invisible1.Sink();
		Gtk.Style style1 = invisible1.Style;

		Gtk.Button button1 = new Gtk.Button();
		Gtk.Style buttonstyle = button1.Style;

		Gtk.VScrollbar scroll1 = new VScrollbar(null);
		scroll1.EnsureStyle();
		Style scrollbarstyle = scroll1.Style;

		Gtk.Menu menu1 = new Gtk.Menu();
		Gtk.MenuItem menuitem1 = new Gtk.MenuItem();
		menu1.Add(menuitem1);
		menuitem1.EnsureStyle();
		menuitem1.Sink();	
		Gtk.Style menustyle = menuitem1.Style;

		uint[] colors = {
					ConvertColor(scrollbarstyle.Background(Gtk.StateType.Normal)),	// COLOR_SCROLLBAR
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_BACKGROUN
                                        ConvertColor(menustyle.Background(Gtk.StateType.Prelight)),	// COLOR_ACTIVECAPTION
                                        ConvertColor(menustyle.Background(Gtk.StateType.Prelight)),	// COLOR_INACTIVECAPTION
                                        ConvertColor(menustyle.Background(Gtk.StateType.Normal)),	// COLOR_MENU
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_WINDOW
                                        ConvertColor(style1.Foreground(Gtk.StateType.Insensitive)),	// COLOR_WINDOWFRAME    
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_MENUTEXT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_WINDOWTEXT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_CAPTIONTEXT
                                        ConvertColor(menustyle.Background(Gtk.StateType.Prelight)),	// COLOR_ACTIVEBORDER
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_INACTIVEBORDER
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_APPWORKSPACE
                                        ConvertColor(menustyle.Background(Gtk.StateType.Prelight)),	// COLOR_HIGHLIGHT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Prelight)),	// COLOR_HIGHLIGHTTEXT
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_BTNFACE 
                                        ConvertColor(style1.Background(Gtk.StateType.Insensitive)),	// COLOR_BTNSHADOW
                                        ConvertColor(style1.Foreground(Gtk.StateType.Insensitive)),	// COLOR_GRAYTEXT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_BTNTEXT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Insensitive)),	// COLOR_INACTIVECAPTIONTEXT
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_BTNHIGHLIGHT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_3DDKSHADOW
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_3DLIGHT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_INFOTEXT
                                        ConvertColor(style1.Foreground(Gtk.StateType.Normal)),		// COLOR_INFOBK
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_ALTERNATEBTNFACE
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_HOTLIGHT
                                        ConvertColor(style1.Background(Gtk.StateType.Normal)),		// COLOR_GRADIENTACTIVECAPTION
                                        ConvertColor(style1.Background(Gtk.StateType.Normal))		// COLOR_GRADIENTINACTIVECAPTION


			};

			return colors;
	}

}

--=-w31voldokpnqlJRUs2Fl
Content-Disposition: attachment; filename=monocolors.patch
Content-Type: text/x-patch; name=monocolors.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

Index: win32functions.cs
===================================================================
RCS file: /cvs/public/mcs/class/System.Windows.Forms/System.Windows.Forms/win32functions.cs,v
retrieving revision 1.51
diff -u -r1.51 win32functions.cs
--- win32functions.cs	11 Aug 2003 14:15:10 -0000	1.51
+++ win32functions.cs	26 Aug 2003 19:54:28 -0000
@@ -34,6 +34,7 @@
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Diagnostics;
+using System.Reflection;
 
 //using UtilityLibrary.WinControls;
 
@@ -567,6 +568,8 @@
 		internal static extern IntPtr WindowFromPoint( POINT pt);
 		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
 		internal static extern int GetSysColor( GetSysColorIndex color);
+		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
+		public static extern bool SetSysColors(int cElements, int[] lpaElements, uint[] lpaRgbValues);
 
 		internal delegate void TimerProc(IntPtr hWnd, uint uMsg, uint idEvent, int dwTime);
 		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
@@ -1258,6 +1261,17 @@
 		[DllImport ("libwinnt.dll.so", EntryPoint="LoadLibraryA")]
 		extern static void NTDLL_LoadLibraryA (string s);
 
+		static uint[] GetGtkSharpColors() {
+
+			// This is needed to avoid a direct Gtk# dependency
+
+			Assembly a = Assembly.LoadFrom("gtkswf.dll");
+			Type type = a.GetType("GtkSharpColorProvider");
+			Object obj = Activator.CreateInstance(type);
+			MethodInfo mi = type.GetMethod("GetColors");
+			return (uint[]) mi.Invoke(obj, null);
+		}
+
 		internal static bool RunningOnUnix = false;		
 		// 
 		// Used to initialize the runtime
@@ -1285,11 +1299,19 @@
 				
 			string [] args = new string [1];
 			args [0] = "mono";
-			
+
 			PROCESS_InitWine (0, args);
 			NTDLL_LoadLibraryA ("kernel32.dll");
 			NTDLL_LoadLibraryA ("user32.dll");
 			NTDLL_LoadLibraryA ("comctl32.dll");
+
+			int[] elements = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};
+
+			string gtk_colors = Environment.GetEnvironmentVariable ("SWF_GTK_COLORS");
+			if (gtk_colors == "1") {
+				uint[] colors = GetGtkSharpColors();
+				SetSysColors(29, elements, colors);
+			}
 		}
 	}
 }

--=-w31voldokpnqlJRUs2Fl--