using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents;
using DevComponents.DotNetBar.Rendering;
using DevComponents.DotNetBar;
using VEPROMS.Properties;
using Volian.Base.Library;
using DescriptiveEnum;

namespace VEPROMS
{
	public partial class frmSysOptions : DevComponents.DotNetBar.Office2007Form
	{
		bool _initializing;
		public frmSysOptions()
		{
			_initializing = true;
			InitializeComponent();
			CurrentSettings();
			SaveStartingSettings();
			cbPropGrid.Visible = VlnSettings.DebugMode;
			btnGeneral.PerformClick();
			groupPanel9.Visible = false;// Don't allow Separate Windows
			_initializing = false;
		}

		/// <summary>
		/// Check the proper buttons with respect to the current settings
		/// </summary>
		private void CurrentSettings()
		{
			switch (Settings.Default.PropPageStyle)
			{
				case 1: cbButtonIntrFace.Checked = true;
					break;
				case 2: cbTabbedIntrFace.Checked = true;
					break;
				case 3: cbPropGrid.Checked = true;
					break;
			}
			switch (Settings.Default.SystemColor)
			{
				case (int)eOffice2007ColorScheme.Black:
					cbRibonBlack.Checked = true;
					break;
				case (int)eOffice2007ColorScheme.Blue:
					cbRibonBlue.Checked = true;
					break;
				case (int)eOffice2007ColorScheme.Silver:
					cbRibonSilver.Checked = true;
					break;
			}
			colorPickerButton1.SelectedColor = Settings.Default.TransitionRangeColor;
			cbAnnotationPopup.Checked = Settings.Default.AutoPopUpAnnotations;
			cbStepTypeToolTip.Checked = Settings.Default.StepTypeToolTip;
			cbTVExpand.Checked = Settings.Default.SaveTreeviewExpanded;
			cbPasteNoReturns.Checked = Settings.Default.PasteNoReturns;
			cbPastePlainText.Checked = Settings.Default.PastePlainText;
			cbEnhancedDocumentSync.Checked = Settings.Default.SyncEnhancedDocuments;
			cbSeparateWindows.Checked = Settings.Default.SeparateWindows;
			txbxVisioPath.Text = Settings.Default.VisioPath;
		}
		private void cbEnhancedDocumentSync_CheckedChanged(object sender, System.EventArgs e)
		{
			if (!_initializing)
			{
				Settings.Default.SyncEnhancedDocuments = cbEnhancedDocumentSync.Checked;
			}
		}
		private void cbPastePlainText_CheckedChanged(object sender, EventArgs e)
		{
			if (!_initializing)
			{
				Settings.Default.PastePlainText = cbPastePlainText.Checked;
			}
		}
		private void cbPasteNoReturns_CheckedChanged(object sender, EventArgs e)
		{
			if (!_initializing)
			{
				Settings.Default.PasteNoReturns = cbPasteNoReturns.Checked;
			}
		}
		private void cbRibonBlue_CheckedChanged(object sender, EventArgs e)
		{
			if (!_initializing)
			{
				RibbonPredefinedColorSchemes.ChangeOffice2007ColorTable(eOffice2007ColorScheme.Blue);
				Settings.Default.SystemColor = (int)eOffice2007ColorScheme.Blue;
			}
		}

		private void cbRibonSilver_CheckedChanged(object sender, EventArgs e)
		{
			if (!_initializing)
			{
				RibbonPredefinedColorSchemes.ChangeOffice2007ColorTable(eOffice2007ColorScheme.Silver);
				Settings.Default.SystemColor = (int)eOffice2007ColorScheme.Silver;
			}
		}

		private void cbRibonBlack_CheckedChanged(object sender, EventArgs e)
		{
			if (!_initializing)
			{
				RibbonPredefinedColorSchemes.ChangeOffice2007ColorTable(eOffice2007ColorScheme.Black);
				Settings.Default.SystemColor = (int)eOffice2007ColorScheme.Black;
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			// Save Default settings for User
			
			// Property Page style
			if (cbButtonIntrFace.Checked)
				Settings.Default.PropPageStyle = 1;
			else if (cbTabbedIntrFace.Checked)
				Settings.Default.PropPageStyle = 2;
			else if (cbPropGrid.Checked)
				Settings.Default.PropPageStyle = 3;

			Settings.Default.Save();
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private int ss_propPageStyle;
		private	int ss_SystemColor;
		private	Color ss_TransRangeColor;
		private	bool ss_PopUPAnnotations;
		private	bool ss_StepTypeToolTip;
		private	bool ss_SaveTreeviewExpanded;
		private	bool ss_PasteNoReturns;
		private	bool ss_PastePlainText;
		private	bool ss_SyncEnhancedDocuments;
		private	bool ss_SeparateWindows;
		private	string ss_VisioPath;

		private void SaveStartingSettings()
		{
			ss_propPageStyle = Settings.Default.PropPageStyle;
			ss_SystemColor = Settings.Default.SystemColor;
			ss_TransRangeColor = Settings.Default.TransitionRangeColor;
			ss_PopUPAnnotations = Settings.Default.AutoPopUpAnnotations;
			ss_StepTypeToolTip = Settings.Default.StepTypeToolTip;
			ss_SaveTreeviewExpanded = Settings.Default.SaveTreeviewExpanded;
			ss_PasteNoReturns = Settings.Default.PasteNoReturns;
			ss_PastePlainText = Settings.Default.PastePlainText;
			ss_SyncEnhancedDocuments = Settings.Default.SyncEnhancedDocuments;
			ss_SeparateWindows = Settings.Default.SeparateWindows;
			ss_VisioPath = Settings.Default.VisioPath;
		}

		private void RestoreStartingSettings() // used with the cancel button
		{
			Settings.Default.PropPageStyle = ss_propPageStyle;
			 Settings.Default.SystemColor = ss_SystemColor;
			Settings.Default.TransitionRangeColor = ss_TransRangeColor;
			Settings.Default.AutoPopUpAnnotations = ss_PopUPAnnotations;
			Settings.Default.StepTypeToolTip = ss_StepTypeToolTip;
			Settings.Default.SaveTreeviewExpanded = ss_SaveTreeviewExpanded;
			Settings.Default.PasteNoReturns = ss_PasteNoReturns;
			Settings.Default.PastePlainText = ss_PastePlainText;
			Settings.Default.SyncEnhancedDocuments = ss_SyncEnhancedDocuments;
			Settings.Default.SeparateWindows = ss_SeparateWindows;
			Settings.Default.VisioPath = ss_VisioPath;
		}


		private void btnIntrFaceStngs_Click(object sender, EventArgs e)
		{
			ClearAllCheckedButtons();
			tcSysOpts.SelectedTab = tiIntrFaceStngs;
			btnIntrFaceStngs.Checked = true;
		}

		private void btnStartMsg_Click(object sender, EventArgs e)
		{
			ClearAllCheckedButtons();
			tcSysOpts.SelectedTab = tiStUpMsg;
			btnStartMsg.Checked = true;
		}

		private void btnGeneral_Click(object sender, EventArgs e)
		{
			ClearAllCheckedButtons();
			tcSysOpts.SelectedTab = tiGeneral;
			btnGeneral.Checked = true;
		}

		private void ClearAllCheckedButtons()
		{
			btnGeneral.Checked = false;
			btnStartMsg.Checked = false;
			btnIntrFaceStngs.Checked = false;
		}

		private void btnReset_Click(object sender, EventArgs e)
		{
			Settings.Default.Reset();// .Reload();
			CurrentSettings();
			// show the resetted color scheme
			RibbonPredefinedColorSchemes.ChangeOffice2007ColorTable((eOffice2007ColorScheme)Settings.Default.SystemColor);
		}

		private void colorPickerButton1_SelectedColorChanged(object sender, EventArgs e)
		{
			if (!_initializing)
			{
				Settings.Default.TransitionRangeColor = colorPickerButton1.SelectedColor;
			}
		}

		private void cbAnnotationPopup_CheckedChanged(object sender, EventArgs e)
		{
			Settings.Default.AutoPopUpAnnotations = cbAnnotationPopup.Checked;
		}

		private void frmSysOptions_Load(object sender, EventArgs e)
		{
			ClearAllCheckedButtons();
			tcSysOpts.SelectedTab = tiIntrFaceStngs;
			btnIntrFaceStngs.Checked = true;
		}
		private void cbStepTypeToolTip_CheckedChanged(object sender, EventArgs e)
		{
			Settings.Default.StepTypeToolTip = cbStepTypeToolTip.Checked;
			VlnSettings.StepTypeToolType = cbStepTypeToolTip.Checked;
		}
		private void cbTVExpand_CheckedChanged(object sender, EventArgs e)
		{
			Settings.Default.SaveTreeviewExpanded = cbTVExpand.Checked;
		}
		private void cbSeparateWindows_CheckedChanged(object sender, EventArgs e)
		{
			Settings.Default.SeparateWindows = cbSeparateWindows.Checked;
		}
		private void txbxVisioPath_Leave(object sender, EventArgs e)
		{
			Settings.Default.VisioPath = txbxVisioPath.Text;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			RestoreStartingSettings();
		}

		private void txbxVisioPath_Leave_1(object sender, EventArgs e)
		{
			Settings.Default.VisioPath = txbxVisioPath.Text;
		}
	}
}