context: //
  // VisualStylesGtkPlus.cs: IVisualStyles that uses GtkPlus.
  //
  // Permission is hereby granted, free of charge, to any person obtaining
  // a copy of this software and associated documentation files (the
  // "Software"), to deal in the Software without restriction, including
  // without limitation the rights to use, copy, modify, merge, publish,
  // distribute, sublicense, and/or sell copies of the Software, and to
  // permit persons to whom the Software is furnished to do so, subject to
  // the following conditions:
  // 
  // The above copyright notice and this permission notice shall be
  // included in all copies or substantial portions of the Software.
  // 
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  //
  // Copyright (c) 2008 George Giolfan
  //
  // Authors:
  //	George Giolfan (georgegiolfan@yahoo.com)
  //
  
  using System.Drawing;
  using System.Collections.Generic;
  namespace System.Windows.Forms.VisualStyles
  {
  	class VisualStylesGtkPlus : IVisualStyles
  	{
  		public static bool Initialize ()
  		{
  			return GtkPlus.Initialize ();
  		}
  		static GtkPlus GtkPlus {
  			get {
  				return GtkPlus.Instance;
  			}
  		}
  
  		enum S {
  			S_OK,
  			S_FALSE
  		}
  		enum ThemeHandle {
  			BUTTON = 1,
  			COMBOBOX,
  			EDIT,
  			HEADER,
  			PROGRESS,
  			REBAR,
  			SCROLLBAR,
  			SPIN,
  			STATUS,
  			TAB,
  			TOOLBAR,
  			TRACKBAR,
  			TREEVIEW
  		}
  
  		#region UxTheme
  		public int UxThemeCloseThemeData (IntPtr hTheme)
  		{
  #if DEBUG
  			return (int)((Enum.IsDefined (typeof (ThemeHandle), (int)hTheme)) ? S.S_OK : S.S_FALSE);
  #else
  			return (int)S.S_OK;
  #endif
  		}
  		public int UxThemeDrawThemeParentBackground (IDeviceContext dc, Rectangle bounds, Control childControl)
  		{
  			return (int)S.S_FALSE;
  		}
  		public int UxThemeDrawThemeBackground (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, Rectangle clipRectangle)
  		{
  			return (int)(DrawBackground ((ThemeHandle)(int)hTheme, dc, iPartId, iStateId, bounds, clipRectangle, Rectangle.Empty) ? S.S_OK : S.S_FALSE);
  		}
  		public int UxThemeDrawThemeBackground (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds)
  		{
  			return UxThemeDrawThemeBackground (hTheme, dc, iPartId, iStateId, bounds, bounds);
  		}
  		bool DrawBackground (ThemeHandle themeHandle, IDeviceContext dc, int part, int state, Rectangle bounds, Rectangle clipRectangle, Rectangle excludedArea) {
  			GtkPlusState gtk_plus_state;
  			GtkPlusToggleButtonValue gtk_plus_toggle_button_value;
  			switch (themeHandle) {
  			#region BUTTON
  			case ThemeHandle.BUTTON:
  				switch ((BUTTONPARTS)part) {
  				#region BP_PUSHBUTTON
  				case BUTTONPARTS.BP_PUSHBUTTON:
  					switch ((PUSHBUTTONSTATES)state) {
  					case PUSHBUTTONSTATES.PBS_NORMAL:
  						gtk_plus_state = GtkPlusState.Normal;
  						break;
  					case PUSHBUTTONSTATES.PBS_HOT:
  						gtk_plus_state = GtkPlusState.Hot;
  						break;
  					case PUSHBUTTONSTATES.PBS_PRESSED:
  						gtk_plus_state = GtkPlusState.Pressed;
  						break;
  					case PUSHBUTTONSTATES.PBS_DISABLED:
  						gtk_plus_state = GtkPlusState.Disabled;
  						break;
  					case PUSHBUTTONSTATES.PBS_DEFAULTED:
  						gtk_plus_state = GtkPlusState.Normal;
  						break;
  					default:
  						return false;
  					}
  					GtkPlus.ButtonPaint (dc, bounds, clipRectangle, (PUSHBUTTONSTATES)state == PUSHBUTTONSTATES.PBS_DEFAULTED, gtk_plus_state);
  					return true;
  				#endregion
  				#region BP_RADIOBUTTON
  				case BUTTONPARTS.BP_RADIOBUTTON:
  					switch ((RADIOBUTTONSTATES)state) {
  					case RADIOBUTTONSTATES.RBS_UNCHECKEDNORMAL:
  						gtk_plus_state = GtkPlusState.Normal;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case RADIOBUTTONSTATES.RBS_UNCHECKEDPRESSED:
  						gtk_plus_state = GtkPlusState.Pressed;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case RADIOBUTTONSTATES.RBS_UNCHECKEDHOT:
  						gtk_plus_state = GtkPlusState.Hot;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case RADIOBUTTONSTATES.RBS_UNCHECKEDDISABLED:
  						gtk_plus_state = GtkPlusState.Disabled;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case RADIOBUTTONSTATES.RBS_CHECKEDNORMAL:
  						gtk_plus_state = GtkPlusState.Normal;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					case RADIOBUTTONSTATES.RBS_CHECKEDPRESSED:
  						gtk_plus_state = GtkPlusState.Pressed;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					case RADIOBUTTONSTATES.RBS_CHECKEDHOT:
  						gtk_plus_state = GtkPlusState.Hot;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					case RADIOBUTTONSTATES.RBS_CHECKEDDISABLED:
  						gtk_plus_state = GtkPlusState.Disabled;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					default:
  						return false;
  					}
  					GtkPlus.RadioButtonPaint (dc, bounds, clipRectangle, gtk_plus_state, gtk_plus_toggle_button_value);
  					return true;
  				#endregion
  				#region BP_CHECKBOX
  				case BUTTONPARTS.BP_CHECKBOX:
  					switch ((CHECKBOXSTATES)state) {
  					case CHECKBOXSTATES.CBS_UNCHECKEDNORMAL:
  						gtk_plus_state = GtkPlusState.Normal;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case CHECKBOXSTATES.CBS_UNCHECKEDPRESSED:
  						gtk_plus_state = GtkPlusState.Pressed;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case CHECKBOXSTATES.CBS_UNCHECKEDHOT:
  						gtk_plus_state = GtkPlusState.Hot;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case CHECKBOXSTATES.CBS_UNCHECKEDDISABLED:
  						gtk_plus_state = GtkPlusState.Disabled;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Unchecked;
  						break;
  					case CHECKBOXSTATES.CBS_CHECKEDNORMAL:
  						gtk_plus_state = GtkPlusState.Normal;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					case CHECKBOXSTATES.CBS_CHECKEDPRESSED:
  						gtk_plus_state = GtkPlusState.Pressed;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					case CHECKBOXSTATES.CBS_CHECKEDHOT:
  						gtk_plus_state = GtkPlusState.Hot;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					case CHECKBOXSTATES.CBS_CHECKEDDISABLED:
  						gtk_plus_state = GtkPlusState.Disabled;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Checked;
  						break;
  					case CHECKBOXSTATES.CBS_MIXEDNORMAL:
  						gtk_plus_state = GtkPlusState.Normal;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Mixed;
  						break;
  					case CHECKBOXSTATES.CBS_MIXEDPRESSED:
  						gtk_plus_state = GtkPlusState.Pressed;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Mixed;
  						break;
  					case CHECKBOXSTATES.CBS_MIXEDHOT:
  						gtk_plus_state = GtkPlusState.Hot;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Mixed;
  						break;
  					case CHECKBOXSTATES.CBS_MIXEDDISABLED:
  						gtk_plus_state = GtkPlusState.Disabled;
  						gtk_plus_toggle_button_value = GtkPlusToggleButtonValue.Mixed;
  						break;
  					default:
  						return false;
  					}
  					GtkPlus.CheckBoxPaint (dc, bounds, clipRectangle, gtk_plus_state, gtk_plus_toggle_button_value);
  					return true;
  				#endregion
  				#region BP_GROUPBOX
  				case BUTTONPARTS.BP_GROUPBOX:
  					switch ((GROUPBOXSTATES)state) {
  					case GROUPBOXSTATES.GBS_NORMAL:
  						gtk_plus_state = GtkPlusState.Normal;
  						break;
  					case GROUPBOXSTATES.GBS_DISABLED:
  						gtk_plus_state = GtkPlusState.Disabled;
  						break;
  					default:
  						return false;
  					}
  					GtkPlus.GroupBoxPaint (dc, bounds, excludedArea, gtk_plus_state);
  					return true;
  				#endregion
  				default: return false;
  				}
  			#endregion
  			#region COMBOBOX
  			case ThemeHandle.COMBOBOX:
  				switch ((COMBOBOXPARTS)part) {
  				#region CP_DROPDOWNBUTTON
  				case COMBOBOXPARTS.CP_DROPDOWNBUTTON:
  					switch ((COMBOBOXSTYLESTATES)state) {
  					case COMBOBOXSTYLESTATES.CBXS_NORMAL: gtk_plus_state = GtkPlusState.Normal; break;
  					case COMBOBOXSTYLESTATES.CBXS_HOT: gtk_plus_state = GtkPlusState.Hot; break;
  					case COMBOBOXSTYLESTATES.CBXS_PRESSED: gtk_plus_state = GtkPlusState.Pressed; break;
  					case COMBOBOXSTYLESTATES.CBXS_DISABLED: gtk_plus_state = GtkPlusState.Disabled; break;
  					default: return false;
  					}
  					GtkPlus.ComboBoxPaintDropDownButton (dc, bounds, clipRectangle, gtk_plus_state);
  					return true;
  				#endregion
  				#region CP_BORDER
  				case COMBOBOXPARTS.CP_BORDER:
  					switch ((BORDERSTATES)state) {
  					case BORDERSTATES.CBB_NORMAL:
  					case BORDERSTATES.CBB_HOT:
  					case BORDERSTATES.CBB_FOCUSED:
  					case BORDERSTATES.CBB_DISABLED:
  						GtkPlus.ComboBoxPaintBorder (dc, bounds, clipRectangle);
  						return true;
  					default: return false;
  					}
  				#endregion
  				default: return false;
  				}
  			#endregion
  			#region EDIT
  			case ThemeHandle.EDIT:
  
gt: 				switch ((EDITPARTS)part) {