//  
//   Rebex Sample Code License
// 
//   Copyright 2026, REBEX CR s.r.o.
//   All rights reserved.
//   https://www.rebex.net/
// 
//   Permission to use, copy, modify, and/or distribute this software for any
//   purpose with or without fee is hereby granted.
// 
//   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.
// 

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Rebex.TerminalEmulation;

namespace Rebex.Samples
{
    /// <summary>
    /// The Options class provides user interface for setting the terminal options.
    /// </summary>
    public class Options : Form
    {
        /// <summary>
        /// Helper class for working with Encoding combo box.
        /// </summary>
        private class EncodingElement
        {
            public int CodePage
            {
                get { return _encoding.CodePage; }
            }

            public Encoding Encoding
            {
                get { return _encoding; }
            }
            private Encoding _encoding;

            public EncodingElement(string encodingName)
            {
                _encoding = EncodingTools.GetEncoding(encodingName);
            }

            public override string ToString()
            {
                return string.Format("{0} {1}", _encoding.HeaderName, _encoding.EncodingName);
            }
        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        private System.Windows.Forms.ComboBox cbEncoding;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Button btnOk;
        private System.Windows.Forms.CheckBox cbForceNonDestructiveBackspace;
        private System.Windows.Forms.CheckBox cbIgnoreSubstituteCharacter;
        private System.Windows.Forms.CheckBox cbImplicitCarriageReturnInLinefeed;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.ComboBox cbAutoWrapMode;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.ComboBox cbBackspaceWrapMode;
        private System.Windows.Forms.TabControl tabOptions;
        private System.Windows.Forms.TabPage tabTerminal;
        private System.Windows.Forms.TabPage tabKeyboard;
        private System.Windows.Forms.RadioButton rbBackspaceBck;
        private System.Windows.Forms.RadioButton rbHomeEndStandard;
        private System.Windows.Forms.RadioButton rbBackspaceDel;
        private System.Windows.Forms.RadioButton rbFunctionKeysXTermR6;
        private System.Windows.Forms.RadioButton rbFunctionKeysVT52;
        private System.Windows.Forms.RadioButton rbFunctionKeysSCO;
        private System.Windows.Forms.RadioButton rbFunctionKeysCommonAlternative;
        private System.Windows.Forms.RadioButton rbFunctionKeysCommon;
        private System.Windows.Forms.RadioButton rbFunctionKeysCommonExtended;
        private System.Windows.Forms.RadioButton rbHomeEndRxvt;
        private System.Windows.Forms.RadioButton radioButton1;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.RadioButton radioButton2;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.RadioButton radioButton3;
        private System.Windows.Forms.Label label10;
        private System.Windows.Forms.RadioButton radioButton4;
        private System.Windows.Forms.RadioButton rbFunctionKeysLinuxAlternative;
        private System.Windows.Forms.RadioButton rbFunctionKeysVT400;
        private System.Windows.Forms.RadioButton rbFunctionKeysLinux;
        private System.Windows.Forms.RadioButton rbFunctionKeysVT100Plus;
        private System.Windows.Forms.RadioButton rbCursorKeyApplication;
        private System.Windows.Forms.RadioButton rbCursorKeyNormal;
        private System.Windows.Forms.RadioButton rbNewLineCRLF;
        private System.Windows.Forms.RadioButton rbNewLineCR;
        private System.Windows.Forms.Label label13;
        private System.Windows.Forms.Label label14;
        private System.Windows.Forms.TextBox txtTerminalName;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.CheckBox cbIgnoreRemoteCursoKeyChange;
        private System.Windows.Forms.TabPage tabRecorder;
        private System.Windows.Forms.Label label15;
        private System.Windows.Forms.TextBox txtRecorderFile;
        private System.Windows.Forms.Button btnRecorderFile;
        private System.Windows.Forms.Label label16;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.GroupBox groupBox5;
        private System.Windows.Forms.GroupBox groupBox4;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.SaveFileDialog saveDialog;
        private System.Windows.Forms.Button btnCancel;
        private System.Windows.Forms.CheckBox cbLocalEcho;

        /// <summary>
        /// Encoding names shown in combo box.
        /// </summary>
        string[] _encodingNames = EncodingTools.GetEncodingNames();

        /// <summary>
        /// Gets the terminal options set using this form.
        /// </summary>
        public TerminalOptions TerminalOptions
        {
            get { return _options; }
        }
        private TerminalOptions _options;

        /// <summary>
        /// Initializes this class.
        /// </summary>
        public Options()
        {
            InitializeComponent();

            _options = Settings.Default.TerminalOptions;

            FillComboBoxes();

            SetFormValues();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.cbEncoding = new System.Windows.Forms.ComboBox();
            this.label2 = new System.Windows.Forms.Label();
            this.btnOk = new System.Windows.Forms.Button();
            this.cbForceNonDestructiveBackspace = new System.Windows.Forms.CheckBox();
            this.cbIgnoreSubstituteCharacter = new System.Windows.Forms.CheckBox();
            this.cbImplicitCarriageReturnInLinefeed = new System.Windows.Forms.CheckBox();
            this.label3 = new System.Windows.Forms.Label();
            this.cbAutoWrapMode = new System.Windows.Forms.ComboBox();
            this.label4 = new System.Windows.Forms.Label();
            this.cbBackspaceWrapMode = new System.Windows.Forms.ComboBox();
            this.tabOptions = new System.Windows.Forms.TabControl();
            this.tabTerminal = new System.Windows.Forms.TabPage();
            this.label1 = new System.Windows.Forms.Label();
            this.tabKeyboard = new System.Windows.Forms.TabPage();
            this.txtTerminalName = new System.Windows.Forms.TextBox();
            this.groupBox5 = new System.Windows.Forms.GroupBox();
            this.rbFunctionKeysLinuxAlternative = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysLinux = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysCommonAlternative = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysCommonExtended = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysCommon = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysSCO = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysVT52 = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysXTermR6 = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysVT100Plus = new System.Windows.Forms.RadioButton();
            this.rbFunctionKeysVT400 = new System.Windows.Forms.RadioButton();
            this.groupBox4 = new System.Windows.Forms.GroupBox();
            this.rbHomeEndStandard = new System.Windows.Forms.RadioButton();
            this.rbHomeEndRxvt = new System.Windows.Forms.RadioButton();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.rbBackspaceBck = new System.Windows.Forms.RadioButton();
            this.rbBackspaceDel = new System.Windows.Forms.RadioButton();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.rbCursorKeyNormal = new System.Windows.Forms.RadioButton();
            this.rbCursorKeyApplication = new System.Windows.Forms.RadioButton();
            this.cbIgnoreRemoteCursoKeyChange = new System.Windows.Forms.CheckBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.rbNewLineCR = new System.Windows.Forms.RadioButton();
            this.rbNewLineCRLF = new System.Windows.Forms.RadioButton();
            this.label14 = new System.Windows.Forms.Label();
            this.label13 = new System.Windows.Forms.Label();
            this.tabRecorder = new System.Windows.Forms.TabPage();
            this.label16 = new System.Windows.Forms.Label();
            this.btnRecorderFile = new System.Windows.Forms.Button();
            this.txtRecorderFile = new System.Windows.Forms.TextBox();
            this.label15 = new System.Windows.Forms.Label();
            this.radioButton1 = new System.Windows.Forms.RadioButton();
            this.label8 = new System.Windows.Forms.Label();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.label9 = new System.Windows.Forms.Label();
            this.radioButton3 = new System.Windows.Forms.RadioButton();
            this.label10 = new System.Windows.Forms.Label();
            this.radioButton4 = new System.Windows.Forms.RadioButton();
            this.saveDialog = new System.Windows.Forms.SaveFileDialog();
            this.btnCancel = new System.Windows.Forms.Button();
            this.cbLocalEcho = new System.Windows.Forms.CheckBox();
            this.tabOptions.SuspendLayout();
            this.tabTerminal.SuspendLayout();
            this.tabKeyboard.SuspendLayout();
            this.groupBox5.SuspendLayout();
            this.groupBox4.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.tabRecorder.SuspendLayout();
            this.SuspendLayout();
            // 
            // cbEncoding
            // 
            this.cbEncoding.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbEncoding.Location = new System.Drawing.Point(104, 33);
            this.cbEncoding.Name = "cbEncoding";
            this.cbEncoding.Size = new System.Drawing.Size(272, 21);
            this.cbEncoding.TabIndex = 1;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(7, 36);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(55, 16);
            this.label2.TabIndex = 23;
            this.label2.Text = "Encoding:";
            // 
            // btnOk
            // 
            this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.btnOk.Location = new System.Drawing.Point(336, 393);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(62, 23);
            this.btnOk.TabIndex = 7;
            this.btnOk.Text = "OK";
            this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
            // 
            // cbForceNonDestructiveBackspace
            // 
            this.cbForceNonDestructiveBackspace.Location = new System.Drawing.Point(9, 114);
            this.cbForceNonDestructiveBackspace.Name = "cbForceNonDestructiveBackspace";
            this.cbForceNonDestructiveBackspace.Size = new System.Drawing.Size(215, 17);
            this.cbForceNonDestructiveBackspace.TabIndex = 4;
            this.cbForceNonDestructiveBackspace.Text = "Force Non-destructive backspace";
            // 
            // cbIgnoreSubstituteCharacter
            // 
            this.cbIgnoreSubstituteCharacter.Location = new System.Drawing.Point(9, 137);
            this.cbIgnoreSubstituteCharacter.Name = "cbIgnoreSubstituteCharacter";
            this.cbIgnoreSubstituteCharacter.Size = new System.Drawing.Size(215, 17);
            this.cbIgnoreSubstituteCharacter.TabIndex = 5;
            this.cbIgnoreSubstituteCharacter.Text = "Ignore Substitute character";
            // 
            // cbImplicitCarriageReturnInLinefeed
            // 
            this.cbImplicitCarriageReturnInLinefeed.Location = new System.Drawing.Point(9, 160);
            this.cbImplicitCarriageReturnInLinefeed.Name = "cbImplicitCarriageReturnInLinefeed";
            this.cbImplicitCarriageReturnInLinefeed.Size = new System.Drawing.Size(215, 17);
            this.cbImplicitCarriageReturnInLinefeed.TabIndex = 6;
            this.cbImplicitCarriageReturnInLinefeed.Text = "Implicit Carriage return in Linefeed";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(7, 63);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(58, 16);
            this.label3.TabIndex = 33;
            this.label3.Text = "Auto wrap:";
            // 
            // cbAutoWrapMode
            // 
            this.cbAutoWrapMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbAutoWrapMode.Location = new System.Drawing.Point(104, 60);
            this.cbAutoWrapMode.Name = "cbAutoWrapMode";
            this.cbAutoWrapMode.Size = new System.Drawing.Size(109, 21);
            this.cbAutoWrapMode.TabIndex = 2;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(7, 90);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(90, 16);
            this.label4.TabIndex = 35;
            this.label4.Text = "Backspace wrap:";
            // 
            // cbBackspaceWrapMode
            // 
            this.cbBackspaceWrapMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbBackspaceWrapMode.Location = new System.Drawing.Point(104, 87);
            this.cbBackspaceWrapMode.Name = "cbBackspaceWrapMode";
            this.cbBackspaceWrapMode.Size = new System.Drawing.Size(109, 21);
            this.cbBackspaceWrapMode.TabIndex = 3;
            // 
            // tabOptions
            // 
            this.tabOptions.Controls.Add(this.tabTerminal);
            this.tabOptions.Controls.Add(this.tabKeyboard);
            this.tabOptions.Controls.Add(this.tabRecorder);
            this.tabOptions.Location = new System.Drawing.Point(0, 0);
            this.tabOptions.Name = "tabOptions";
            this.tabOptions.SelectedIndex = 0;
            this.tabOptions.Size = new System.Drawing.Size(472, 391);
            this.tabOptions.TabIndex = 36;
            // 
            // tabTerminal
            // 
            this.tabTerminal.Controls.Add(this.cbLocalEcho);
            this.tabTerminal.Controls.Add(this.label1);
            this.tabTerminal.Controls.Add(this.label2);
            this.tabTerminal.Controls.Add(this.label4);
            this.tabTerminal.Controls.Add(this.cbEncoding);
            this.tabTerminal.Controls.Add(this.cbBackspaceWrapMode);
            this.tabTerminal.Controls.Add(this.cbForceNonDestructiveBackspace);
            this.tabTerminal.Controls.Add(this.label3);
            this.tabTerminal.Controls.Add(this.cbIgnoreSubstituteCharacter);
            this.tabTerminal.Controls.Add(this.cbAutoWrapMode);
            this.tabTerminal.Controls.Add(this.cbImplicitCarriageReturnInLinefeed);
            this.tabTerminal.Location = new System.Drawing.Point(4, 22);
            this.tabTerminal.Name = "tabTerminal";
            this.tabTerminal.Size = new System.Drawing.Size(464, 365);
            this.tabTerminal.TabIndex = 0;
            this.tabTerminal.Text = "Terminal";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(238)));
            this.label1.Location = new System.Drawing.Point(7, 10);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(381, 16);
            this.label1.TabIndex = 36;
            this.label1.Text = "These options defines how to interpret sequences received from the server.";
            // 
            // tabKeyboard
            // 
            this.tabKeyboard.Controls.Add(this.txtTerminalName);
            this.tabKeyboard.Controls.Add(this.groupBox5);
            this.tabKeyboard.Controls.Add(this.groupBox4);
            this.tabKeyboard.Controls.Add(this.groupBox3);
            this.tabKeyboard.Controls.Add(this.groupBox2);
            this.tabKeyboard.Controls.Add(this.groupBox1);
            this.tabKeyboard.Controls.Add(this.label14);
            this.tabKeyboard.Controls.Add(this.label13);
            this.tabKeyboard.Location = new System.Drawing.Point(4, 22);
            this.tabKeyboard.Name = "tabKeyboard";
            this.tabKeyboard.Size = new System.Drawing.Size(464, 365);
            this.tabKeyboard.TabIndex = 1;
            this.tabKeyboard.Text = "Keyboard";
            // 
            // txtTerminalName
            // 
            this.txtTerminalName.Location = new System.Drawing.Point(104, 30);
            this.txtTerminalName.Name = "txtTerminalName";
            this.txtTerminalName.Size = new System.Drawing.Size(352, 20);
            this.txtTerminalName.TabIndex = 27;
            this.txtTerminalName.Text = "";
            // 
            // groupBox5
            // 
            this.groupBox5.Controls.Add(this.rbFunctionKeysLinuxAlternative);
            this.groupBox5.Controls.Add(this.rbFunctionKeysLinux);
            this.groupBox5.Controls.Add(this.rbFunctionKeysCommonAlternative);
            this.groupBox5.Controls.Add(this.rbFunctionKeysCommonExtended);
            this.groupBox5.Controls.Add(this.rbFunctionKeysCommon);
            this.groupBox5.Controls.Add(this.rbFunctionKeysSCO);
            this.groupBox5.Controls.Add(this.rbFunctionKeysVT52);
            this.groupBox5.Controls.Add(this.rbFunctionKeysXTermR6);
            this.groupBox5.Controls.Add(this.rbFunctionKeysVT100Plus);
            this.groupBox5.Controls.Add(this.rbFunctionKeysVT400);
            this.groupBox5.Location = new System.Drawing.Point(9, 286);
            this.groupBox5.Name = "groupBox5";
            this.groupBox5.Size = new System.Drawing.Size(447, 71);
            this.groupBox5.TabIndex = 34;
            this.groupBox5.TabStop = false;
            this.groupBox5.Text = "Function keys";
            // 
            // rbFunctionKeysLinuxAlternative
            // 
            this.rbFunctionKeysLinuxAlternative.Location = new System.Drawing.Point(328, 19);
            this.rbFunctionKeysLinuxAlternative.Name = "rbFunctionKeysLinuxAlternative";
            this.rbFunctionKeysLinuxAlternative.Size = new System.Drawing.Size(112, 17);
            this.rbFunctionKeysLinuxAlternative.TabIndex = 16;
            this.rbFunctionKeysLinuxAlternative.TabStop = true;
            this.rbFunctionKeysLinuxAlternative.Text = "Linux alternative";
            // 
            // rbFunctionKeysLinux
            // 
            this.rbFunctionKeysLinux.Location = new System.Drawing.Point(256, 19);
            this.rbFunctionKeysLinux.Name = "rbFunctionKeysLinux";
            this.rbFunctionKeysLinux.Size = new System.Drawing.Size(72, 17);
            this.rbFunctionKeysLinux.TabIndex = 14;
            this.rbFunctionKeysLinux.TabStop = true;
            this.rbFunctionKeysLinux.Text = "Linux";
            // 
            // rbFunctionKeysCommonAlternative
            // 
            this.rbFunctionKeysCommonAlternative.Location = new System.Drawing.Point(168, 19);
            this.rbFunctionKeysCommonAlternative.Name = "rbFunctionKeysCommonAlternative";
            this.rbFunctionKeysCommonAlternative.Size = new System.Drawing.Size(78, 17);
            this.rbFunctionKeysCommonAlternative.TabIndex = 9;
            this.rbFunctionKeysCommonAlternative.TabStop = true;
            this.rbFunctionKeysCommonAlternative.Text = "Alternative";
            // 
            // rbFunctionKeysCommonExtended
            // 
            this.rbFunctionKeysCommonExtended.Location = new System.Drawing.Point(88, 19);
            this.rbFunctionKeysCommonExtended.Name = "rbFunctionKeysCommonExtended";
            this.rbFunctionKeysCommonExtended.Size = new System.Drawing.Size(77, 17);
            this.rbFunctionKeysCommonExtended.TabIndex = 7;
            this.rbFunctionKeysCommonExtended.TabStop = true;
            this.rbFunctionKeysCommonExtended.Text = "Extended";
            // 
            // rbFunctionKeysCommon
            // 
            this.rbFunctionKeysCommon.Location = new System.Drawing.Point(5, 19);
            this.rbFunctionKeysCommon.Name = "rbFunctionKeysCommon";
            this.rbFunctionKeysCommon.Size = new System.Drawing.Size(75, 17);
            this.rbFunctionKeysCommon.TabIndex = 8;
            this.rbFunctionKeysCommon.TabStop = true;
            this.rbFunctionKeysCommon.Text = "Common";
            // 
            // rbFunctionKeysSCO
            // 
            this.rbFunctionKeysSCO.Location = new System.Drawing.Point(88, 42);
            this.rbFunctionKeysSCO.Name = "rbFunctionKeysSCO";
            this.rbFunctionKeysSCO.Size = new System.Drawing.Size(80, 17);
            this.rbFunctionKeysSCO.TabIndex = 10;
            this.rbFunctionKeysSCO.TabStop = true;
            this.rbFunctionKeysSCO.Text = "SCO";
            // 
            // rbFunctionKeysVT52
            // 
            this.rbFunctionKeysVT52.Location = new System.Drawing.Point(168, 42);
            this.rbFunctionKeysVT52.Name = "rbFunctionKeysVT52";
            this.rbFunctionKeysVT52.Size = new System.Drawing.Size(80, 17);
            this.rbFunctionKeysVT52.TabIndex = 11;
            this.rbFunctionKeysVT52.TabStop = true;
            this.rbFunctionKeysVT52.Text = "VT 52";
            // 
            // rbFunctionKeysXTermR6
            // 
            this.rbFunctionKeysXTermR6.Location = new System.Drawing.Point(4, 42);
            this.rbFunctionKeysXTermR6.Name = "rbFunctionKeysXTermR6";
            this.rbFunctionKeysXTermR6.Size = new System.Drawing.Size(76, 17);
            this.rbFunctionKeysXTermR6.TabIndex = 12;
            this.rbFunctionKeysXTermR6.TabStop = true;
            this.rbFunctionKeysXTermR6.Text = "Xterm R6";
            // 
            // rbFunctionKeysVT100Plus
            // 
            this.rbFunctionKeysVT100Plus.Location = new System.Drawing.Point(256, 42);
            this.rbFunctionKeysVT100Plus.Name = "rbFunctionKeysVT100Plus";
            this.rbFunctionKeysVT100Plus.Size = new System.Drawing.Size(67, 17);
            this.rbFunctionKeysVT100Plus.TabIndex = 13;
            this.rbFunctionKeysVT100Plus.TabStop = true;
            this.rbFunctionKeysVT100Plus.Text = "VT 100+";
            // 
            // rbFunctionKeysVT400
            // 
            this.rbFunctionKeysVT400.Location = new System.Drawing.Point(328, 42);
            this.rbFunctionKeysVT400.Name = "rbFunctionKeysVT400";
            this.rbFunctionKeysVT400.Size = new System.Drawing.Size(104, 17);
            this.rbFunctionKeysVT400.TabIndex = 15;
            this.rbFunctionKeysVT400.TabStop = true;
            this.rbFunctionKeysVT400.Text = "VT 400";
            // 
            // groupBox4
            // 
            this.groupBox4.Controls.Add(this.rbHomeEndStandard);
            this.groupBox4.Controls.Add(this.rbHomeEndRxvt);
            this.groupBox4.Location = new System.Drawing.Point(9, 236);
            this.groupBox4.Name = "groupBox4";
            this.groupBox4.Size = new System.Drawing.Size(447, 44);
            this.groupBox4.TabIndex = 33;
            this.groupBox4.TabStop = false;
            this.groupBox4.Text = "Home and End keys";
            // 
            // rbHomeEndStandard
            // 
            this.rbHomeEndStandard.Location = new System.Drawing.Point(5, 19);
            this.rbHomeEndStandard.Name = "rbHomeEndStandard";
            this.rbHomeEndStandard.Size = new System.Drawing.Size(99, 17);
            this.rbHomeEndStandard.TabIndex = 3;
            this.rbHomeEndStandard.TabStop = true;
            this.rbHomeEndStandard.Text = "Standard";
            // 
            // rbHomeEndRxvt
            // 
            this.rbHomeEndRxvt.Location = new System.Drawing.Point(176, 19);
            this.rbHomeEndRxvt.Name = "rbHomeEndRxvt";
            this.rbHomeEndRxvt.Size = new System.Drawing.Size(128, 17);
            this.rbHomeEndRxvt.TabIndex = 5;
            this.rbHomeEndRxvt.TabStop = true;
            this.rbHomeEndRxvt.Text = "Rxvt";
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.rbBackspaceBck);
            this.groupBox3.Controls.Add(this.rbBackspaceDel);
            this.groupBox3.Location = new System.Drawing.Point(9, 181);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(447, 48);
            this.groupBox3.TabIndex = 32;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Backspace key";
            // 
            // rbBackspaceBck
            // 
            this.rbBackspaceBck.Location = new System.Drawing.Point(5, 19);
            this.rbBackspaceBck.Name = "rbBackspaceBck";
            this.rbBackspaceBck.Size = new System.Drawing.Size(163, 17);
            this.rbBackspaceBck.TabIndex = 0;
            this.rbBackspaceBck.TabStop = true;
            this.rbBackspaceBck.Text = "Backspace key = ^H = 0x08 ";
            // 
            // rbBackspaceDel
            // 
            this.rbBackspaceDel.Location = new System.Drawing.Point(176, 19);
            this.rbBackspaceDel.Name = "rbBackspaceDel";
            this.rbBackspaceDel.Size = new System.Drawing.Size(158, 17);
            this.rbBackspaceDel.TabIndex = 2;
            this.rbBackspaceDel.TabStop = true;
            this.rbBackspaceDel.Text = "Delete key = ^? = 0x7F";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.rbCursorKeyNormal);
            this.groupBox2.Controls.Add(this.rbCursorKeyApplication);
            this.groupBox2.Controls.Add(this.cbIgnoreRemoteCursoKeyChange);
            this.groupBox2.Location = new System.Drawing.Point(9, 108);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(447, 67);
            this.groupBox2.TabIndex = 31;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Cursor key mode";
            // 
            // rbCursorKeyNormal
            // 
            this.rbCursorKeyNormal.Location = new System.Drawing.Point(8, 16);
            this.rbCursorKeyNormal.Name = "rbCursorKeyNormal";
            this.rbCursorKeyNormal.Size = new System.Drawing.Size(107, 19);
            this.rbCursorKeyNormal.TabIndex = 30;
            this.rbCursorKeyNormal.TabStop = true;
            this.rbCursorKeyNormal.Text = "Normal";
            // 
            // rbCursorKeyApplication
            // 
            this.rbCursorKeyApplication.Location = new System.Drawing.Point(176, 19);
            this.rbCursorKeyApplication.Name = "rbCursorKeyApplication";
            this.rbCursorKeyApplication.Size = new System.Drawing.Size(120, 17);
            this.rbCursorKeyApplication.TabIndex = 22;
            this.rbCursorKeyApplication.TabStop = true;
            this.rbCursorKeyApplication.Text = "Application";
            // 
            // cbIgnoreRemoteCursoKeyChange
            // 
            this.cbIgnoreRemoteCursoKeyChange.Location = new System.Drawing.Point(5, 42);
            this.cbIgnoreRemoteCursoKeyChange.Name = "cbIgnoreRemoteCursoKeyChange";
            this.cbIgnoreRemoteCursoKeyChange.Size = new System.Drawing.Size(181, 17);
            this.cbIgnoreRemoteCursoKeyChange.TabIndex = 29;
            this.cbIgnoreRemoteCursoKeyChange.Text = "Ignore remote Cursor key mode changes";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.rbNewLineCR);
            this.groupBox1.Controls.Add(this.rbNewLineCRLF);
            this.groupBox1.Location = new System.Drawing.Point(9, 56);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(447, 46);
            this.groupBox1.TabIndex = 30;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "New line sequence";
            // 
            // rbNewLineCR
            // 
            this.rbNewLineCR.Location = new System.Drawing.Point(5, 19);
            this.rbNewLineCR.Name = "rbNewLineCR";
            this.rbNewLineCR.Size = new System.Drawing.Size(107, 17);
            this.rbNewLineCR.TabIndex = 17;
            this.rbNewLineCR.TabStop = true;
            this.rbNewLineCR.Text = "<CR>";
            // 
            // rbNewLineCRLF
            // 
            this.rbNewLineCRLF.Location = new System.Drawing.Point(176, 19);
            this.rbNewLineCRLF.Name = "rbNewLineCRLF";
            this.rbNewLineCRLF.Size = new System.Drawing.Size(112, 17);
            this.rbNewLineCRLF.TabIndex = 19;
            this.rbNewLineCRLF.TabStop = true;
            this.rbNewLineCRLF.Text = "<CR><LF>";
            // 
            // label14
            // 
            this.label14.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(238)));
            this.label14.Location = new System.Drawing.Point(7, 33);
            this.label14.Name = "label14";
            this.label14.Size = new System.Drawing.Size(97, 13);
            this.label14.TabIndex = 28;
            this.label14.Text = "Terminal name:";
            // 
            // label13
            // 
            this.label13.AutoSize = true;
            this.label13.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(238)));
            this.label13.Location = new System.Drawing.Point(7, 10);
            this.label13.Name = "label13";
            this.label13.Size = new System.Drawing.Size(317, 16);
            this.label13.TabIndex = 23;
            this.label13.Text = "These options defines which sequences are sent to the server.";
            // 
            // tabRecorder
            // 
            this.tabRecorder.Controls.Add(this.label16);
            this.tabRecorder.Controls.Add(this.btnRecorderFile);
            this.tabRecorder.Controls.Add(this.txtRecorderFile);
            this.tabRecorder.Controls.Add(this.label15);
            this.tabRecorder.Location = new System.Drawing.Point(4, 22);
            this.tabRecorder.Name = "tabRecorder";
            this.tabRecorder.Size = new System.Drawing.Size(464, 365);
            this.tabRecorder.TabIndex = 2;
            this.tabRecorder.Text = "Recorder";
            // 
            // label16
            // 
            this.label16.AutoSize = true;
            this.label16.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(238)));
            this.label16.Location = new System.Drawing.Point(7, 10);
            this.label16.Name = "label16";
            this.label16.Size = new System.Drawing.Size(409, 16);
            this.label16.TabIndex = 24;
            this.label16.Text = "If recorder output is not specified, <running directory>/hostname.rec will be use" +
                "d.";
            // 
            // btnRecorderFile
            // 
            this.btnRecorderFile.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.btnRecorderFile.Location = new System.Drawing.Point(432, 51);
            this.btnRecorderFile.Name = "btnRecorderFile";
            this.btnRecorderFile.Size = new System.Drawing.Size(24, 20);
            this.btnRecorderFile.TabIndex = 21;
            this.btnRecorderFile.Text = "...";
            this.btnRecorderFile.Click += new System.EventHandler(this.btnRecorderFile_Click);
            // 
            // txtRecorderFile
            // 
            this.txtRecorderFile.Location = new System.Drawing.Point(9, 52);
            this.txtRecorderFile.Name = "txtRecorderFile";
            this.txtRecorderFile.Size = new System.Drawing.Size(415, 20);
            this.txtRecorderFile.TabIndex = 1;
            this.txtRecorderFile.Text = "";
            // 
            // label15
            // 
            this.label15.AutoSize = true;
            this.label15.Location = new System.Drawing.Point(7, 36);
            this.label15.Name = "label15";
            this.label15.Size = new System.Drawing.Size(106, 16);
            this.label15.TabIndex = 0;
            this.label15.Text = "Recorder output file:";
            // 
            // radioButton1
            // 
            this.radioButton1.Location = new System.Drawing.Point(12, 63);
            this.radioButton1.Name = "radioButton1";
            this.radioButton1.Size = new System.Drawing.Size(68, 17);
            this.radioButton1.TabIndex = 3;
            this.radioButton1.TabStop = true;
            this.radioButton1.Text = "Standard";
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(9, 83);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(77, 16);
            this.label8.TabIndex = 6;
            this.label8.Text = "Function keys:";
            // 
            // radioButton2
            // 
            this.radioButton2.Location = new System.Drawing.Point(125, 63);
            this.radioButton2.Name = "radioButton2";
            this.radioButton2.Size = new System.Drawing.Size(47, 17);
            this.radioButton2.TabIndex = 5;
            this.radioButton2.TabStop = true;
            this.radioButton2.Text = "Rxvt";
            // 
            // label9
            // 
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(9, 47);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(109, 16);
            this.label9.TabIndex = 4;
            this.label9.Text = "Home and End keys:";
            // 
            // radioButton3
            // 
            this.radioButton3.Location = new System.Drawing.Point(125, 23);
            this.radioButton3.Name = "radioButton3";
            this.radioButton3.Size = new System.Drawing.Size(66, 17);
            this.radioButton3.TabIndex = 2;
            this.radioButton3.TabStop = true;
            this.radioButton3.Text = "DEL key";
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(9, 7);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(83, 16);
            this.label10.TabIndex = 1;
            this.label10.Text = "Backspace key:";
            // 
            // radioButton4
            // 
            this.radioButton4.Location = new System.Drawing.Point(12, 23);
            this.radioButton4.Name = "radioButton4";
            this.radioButton4.Size = new System.Drawing.Size(99, 17);
            this.radioButton4.TabIndex = 0;
            this.radioButton4.TabStop = true;
            this.radioButton4.Text = "Backspace key";
            // 
            // saveDialog
            // 
            this.saveDialog.Filter = "Ansi files (*.ans)|*.ans|All files (*.*)|*.*";
            this.saveDialog.OverwritePrompt = false;
            // 
            // btnCancel
            // 
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.btnCancel.Location = new System.Drawing.Point(408, 393);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(62, 23);
            this.btnCancel.TabIndex = 37;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // cbLocalEcho
            // 
            this.cbLocalEcho.Location = new System.Drawing.Point(8, 184);
            this.cbLocalEcho.Name = "cbLocalEcho";
            this.cbLocalEcho.Size = new System.Drawing.Size(215, 17);
            this.cbLocalEcho.TabIndex = 37;
            this.cbLocalEcho.Text = "Local echo";
            // 
            // Options
            // 
            this.AcceptButton = this.btnOk;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(474, 420);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.tabOptions);
            this.Controls.Add(this.btnOk);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MinimizeBox = true;
            this.MaximizeBox = false;
            this.ShowInTaskbar = false;
            this.KeyPreview = true;
            this.Name = "Options";
            this.Text = "Properties";
            this.tabOptions.ResumeLayout(false);
            this.tabTerminal.ResumeLayout(false);
            this.tabKeyboard.ResumeLayout(false);
            this.groupBox5.ResumeLayout(false);
            this.groupBox4.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            this.tabRecorder.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        /// <summary>
        /// Fills the form's combo boxes.
        /// </summary>
        private void FillComboBoxes()
        {
            // fill the cbEncoding.Items collection
            for (int i = 0; i < _encodingNames.Length; i++)
            {
                EncodingElement encoding = new EncodingElement(_encodingNames[i]);
                cbEncoding.Items.Add(encoding);
            }


            cbAutoWrapMode.DataSource = Enum.GetValues(typeof(AutoWrapMode));
            cbBackspaceWrapMode.DataSource = Enum.GetValues(typeof(AutoWrapMode));
        }

        /// <summary>
        /// Sets the form values according to the values taken from the config.
        /// </summary>
        private void SetFormValues()
        {
            txtRecorderFile.Text = Settings.Default.GetString("RecorderFile");
            this.Encoding = _options.Encoding;
            cbAutoWrapMode.SelectedItem = _options.AutoWrapMode;
            cbBackspaceWrapMode.SelectedItem = _options.BackspaceWrapMode;
            cbForceNonDestructiveBackspace.Checked = _options.ForceNondestructiveBackspace;
            cbIgnoreSubstituteCharacter.Checked = _options.IgnoreSubstituteCharacter;
            cbImplicitCarriageReturnInLinefeed.Checked = _options.ImplicitCarriageReturnInLinefeed;
            cbLocalEcho.Checked = _options.LocalEcho;

            txtTerminalName.Text = _options.TerminalName;

            rbNewLineCR.Checked = (_options.NewLineSequence == NewLineSequence.CR);
            rbNewLineCRLF.Checked = (_options.NewLineSequence == NewLineSequence.CRLF);

            rbCursorKeyNormal.Checked = (_options.CursorKeyMode == CursorKeyMode.Normal);
            rbCursorKeyApplication.Checked = (_options.CursorKeyMode == CursorKeyMode.Application);
            cbIgnoreRemoteCursoKeyChange.Checked = _options.IgnoreCursorKeyModeChange;

            rbBackspaceBck.Checked = (_options.BackspaceSequence == BackspaceSequence.Backspace);
            rbBackspaceDel.Checked = (_options.BackspaceSequence == BackspaceSequence.Del);

            rbHomeEndStandard.Checked = (_options.HomeEndKeysMode == HomeEndKeysMode.Standard);
            rbHomeEndRxvt.Checked = (_options.HomeEndKeysMode == HomeEndKeysMode.Rxvt);

            rbFunctionKeysCommonExtended.Checked = (_options.FunctionKeysMode == FunctionKeysMode.CommonExtended);
            rbFunctionKeysCommon.Checked = (_options.FunctionKeysMode == FunctionKeysMode.Common);
            rbFunctionKeysXTermR6.Checked = (_options.FunctionKeysMode == FunctionKeysMode.XtermR6);
            rbFunctionKeysLinux.Checked = (_options.FunctionKeysMode == FunctionKeysMode.Linux);
            rbFunctionKeysLinuxAlternative.Checked = (_options.FunctionKeysMode == FunctionKeysMode.LinuxAlternative);
            rbFunctionKeysCommonAlternative.Checked = (_options.FunctionKeysMode == FunctionKeysMode.CommonAlternative);
            rbFunctionKeysSCO.Checked = (_options.FunctionKeysMode == FunctionKeysMode.Sco);
            rbFunctionKeysVT52.Checked = (_options.FunctionKeysMode == FunctionKeysMode.VT52);
            rbFunctionKeysVT100Plus.Checked = (_options.FunctionKeysMode == FunctionKeysMode.VT100Plus);
            rbFunctionKeysVT400.Checked = (_options.FunctionKeysMode == FunctionKeysMode.VT400);
        }

        /// <summary>
        /// Gets or sets the selected Encoding in the combo box.
        /// </summary>
        private Encoding Encoding
        {
            get
            {
                return ((EncodingElement)cbEncoding.SelectedItem).Encoding;
            }
            set
            {
                cbEncoding.SelectedIndex = -1;

                if (value == null)
                    return;

                foreach (EncodingElement encoding in cbEncoding.Items)
                {
                    if (encoding.CodePage == value.CodePage)
                    {
                        cbEncoding.SelectedItem = encoding;
                        return;
                    }
                }
            }
        }

        /// <summary>
        /// Saves the form values to the config.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            _options.Encoding = this.Encoding;
            _options.AutoWrapMode = (AutoWrapMode)cbAutoWrapMode.SelectedValue;
            _options.BackspaceWrapMode = (AutoWrapMode)cbBackspaceWrapMode.SelectedValue;
            _options.ForceNondestructiveBackspace = cbForceNonDestructiveBackspace.Checked;
            _options.IgnoreSubstituteCharacter = cbIgnoreSubstituteCharacter.Checked;
            _options.ImplicitCarriageReturnInLinefeed = cbImplicitCarriageReturnInLinefeed.Checked;
            _options.LocalEcho = cbLocalEcho.Checked;

            _options.TerminalName = txtTerminalName.Text;
            
            _options.IgnoreCursorKeyModeChange = cbIgnoreRemoteCursoKeyChange.Checked;

            if (rbNewLineCR.Checked)
                _options.NewLineSequence = NewLineSequence.CR;
            else
                _options.NewLineSequence = NewLineSequence.CRLF;
            if (rbCursorKeyNormal.Checked)
                _options.CursorKeyMode = CursorKeyMode.Normal;
            else
                _options.CursorKeyMode = CursorKeyMode.Application;
            if (rbBackspaceBck.Checked)
                _options.BackspaceSequence = BackspaceSequence.Backspace;
            else
                _options.BackspaceSequence = BackspaceSequence.Del;
            if (rbHomeEndStandard.Checked)
                _options.HomeEndKeysMode = HomeEndKeysMode.Standard;
            else
                _options.HomeEndKeysMode = HomeEndKeysMode.Rxvt;

            if (rbFunctionKeysCommonExtended.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.CommonExtended;
            else if (rbFunctionKeysCommon.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.Common;
            else if (rbFunctionKeysXTermR6.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.XtermR6;
            else if (rbFunctionKeysLinux.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.Linux;
            else if (rbFunctionKeysLinuxAlternative.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.LinuxAlternative;
            else if (rbFunctionKeysCommonAlternative.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.CommonAlternative;
            else if (rbFunctionKeysSCO.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.Sco;
            else if (rbFunctionKeysVT52.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.VT52;
            else if (rbFunctionKeysVT100Plus.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.VT100Plus;
            else if (rbFunctionKeysVT400.Checked)
                _options.FunctionKeysMode = FunctionKeysMode.VT400;

            Settings.Default.SetValue("options", _options);
            Settings.Default.SetValue("RecorderFile", txtRecorderFile.Text);

            Settings.Default.Save();

            Close();
        }

        /// <summary>
        /// Closes the form without saving the form values to the config.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// Promt the user to choose the file for recorder.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRecorderFile_Click(object sender, EventArgs e)
        {
            if (saveDialog.ShowDialog() != DialogResult.OK)
                return;

            txtRecorderFile.Text = saveDialog.FileName;
        }
    }
}