[Mono-winforms-list] VisualStyles implementation based on GTK+

George Giolfan georgegiolfan at yahoo.com
Thu Jun 5 21:21:08 EDT 2008

This patch contains a refactoring of the managed VisualStyles API to allow multiple implementations. The existing implementation was moved to VisualStylesNative.

The new code is split in two parts. The code in GtkPlus wraps GTK+ and exposes methods to paint controls (mostly based on ThemeGtk in the experimental mode, but faster and with less bugs). The VisualStyles implementation itself is VisualStylesGtkPlus and it translates class name/part/state combinations to calls to GtkPlus.
This new VisualStyles implementation combined with the VisualStyles theme would achieve a native GTK+ look for many of the usual controls. However, due to some differences between the VisualStyles and GTK+ APIs, a better (faster and more flexible) long term solution for having a native GTK+ look would be to write a new theme (or refactor ThemeGtk) to use the GtkPlus code directly. This would be faster especially for controls with a solid color background and would allow painting control elements not supported by the VisualStyles API (if there are any).

The code is far from finished. It is meant as proof of concept. I need to know if the approach is good.
Only background painting for the VisualStyleElement.Button.CheckBox.UncheckedNormal element is implemented.
You can use this to test it
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
class Test
	static void Main ()
		Application.Run (new TestForm ());
	class TestForm : Form
		public TestForm ()
			SetStyle (ControlStyles.ResizeRedraw, true);
			DoubleBuffered = true;
			BackgroundImage = Icon.ToBitmap ();
		protected override void OnPaint (PaintEventArgs e)
			new VisualStyleRenderer (VisualStyleElement.Button.CheckBox.UncheckedNormal).DrawBackground (e.Graphics, ClientRectangle);

On Windows, in the HKEY_CURRENT_USER\Software\Mono registry key, you need to add a string value named "VisualStyles" with the data "GTK+".
On non-Windows platforms you can either use DLL mapping for the GTK+ libraries or disable the "#define Windows" line in GtkPlus.cs.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: VisualStylesGtkPlus.patch.gz
Type: application/x-gzip
Size: 10629 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20080605/defd83c7/attachment.gz 

More information about the Mono-winforms-list mailing list