'  
'   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.
' 

Imports System
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Imports Rebex.TerminalEmulation

''' <summary>
''' The Options class provides user interface for setting the terminal options.
''' </summary>
Public Class Options
    Inherits Form
    ''' <summary>
    ''' Helper class for working with Encoding combo box.
    ''' </summary>
    Private Class EncodingElement
        Public ReadOnly Property CodePage() As Integer
            Get
                Return _encoding.CodePage
            End Get
        End Property

        Public ReadOnly Property Encoding() As Encoding
            Get
                Return _encoding
            End Get
        End Property
        Private _encoding As Encoding

        Public Sub New(ByVal encodingName As String)
            _encoding = EncodingTools.GetEncoding(encodingName)
        End Sub

        Public Overloads Overrides Function ToString() As String
            Return String.Format("{0} {1}", _encoding.HeaderName, _encoding.EncodingName)
        End Function
    End Class

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

    ''' <summary>
    ''' Encoding names shown in combo box.
    ''' </summary>
    Private _encodingNames As String() = Rebex.EncodingTools.GetEncodingNames()

    ''' <summary>
    ''' Gets the terminal options set using this form.
    ''' </summary>
    Public ReadOnly Property TerminalOptions() As TerminalOptions
        Get
            Return _options
        End Get
    End Property
    Private _options As TerminalOptions

    ''' <summary>
    ''' Initializes this class.
    ''' </summary>
    Public Sub New()
        InitializeComponent()

        _options = Settings.Default.TerminalOptions

        FillComboBoxes()

        SetFormValues()
    End Sub

    ''' <summary>
    ''' Clean up any resources being used.
    ''' </summary>
    ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso Not (components Is Nothing) Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

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

    End Sub

#End Region

    ''' <summary>
    ''' Fills the form's combo boxes.
    ''' </summary>
    Private Sub FillComboBoxes()
        Dim i As Integer
        For i = 0 To _encodingNames.Length - 1
            ' fill the cbEncoding.Items collection
            Dim encoding As New EncodingElement(_encodingNames(i))
            cbEncoding.Items.Add(encoding)
        Next

        cbAutoWrapMode.DataSource = [Enum].GetValues(GetType(AutoWrapMode))
        cbBackspaceWrapMode.DataSource = [Enum].GetValues(GetType(AutoWrapMode))
    End Sub

    ''' <summary>
    ''' Sets the form values according to the values taken from the config.
    ''' </summary>
    Private Sub SetFormValues()
        txtRecorderFile.Text = Settings.Default.GetString("RecorderFile")

        Me.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)
    End Sub

    ''' <summary>
    ''' Gets or sets the selected Encoding in the combo box.
    ''' </summary>
    Private Property Encoding() As Encoding
        Get
            Return CType(cbEncoding.SelectedItem, EncodingElement).Encoding
        End Get
        Set(ByVal Value As Encoding)
            cbEncoding.SelectedIndex = -1

            If Value Is Nothing Then
                Return
            End If

            Dim encoding As EncodingElement
            For Each encoding In cbEncoding.Items
                If encoding.CodePage = Value.CodePage Then
                    cbEncoding.SelectedItem = encoding
                    Return
                End If
            Next
        End Set
    End Property

    ''' <summary>
    ''' Saves the form values to the config.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        _options.Encoding = Me.Encoding
        _options.AutoWrapMode = CType(cbAutoWrapMode.SelectedValue, AutoWrapMode)
        _options.BackspaceWrapMode = CType(cbBackspaceWrapMode.SelectedValue, AutoWrapMode)
        _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 Then
            _options.NewLineSequence = NewLineSequence.CR
        Else
            _options.NewLineSequence = NewLineSequence.CRLF
        End If
        If rbCursorKeyNormal.Checked Then
            _options.CursorKeyMode = CursorKeyMode.Normal
        Else
            _options.CursorKeyMode = CursorKeyMode.Application
        End If
        If rbBackspaceBck.Checked Then
            _options.BackspaceSequence = BackspaceSequence.Backspace
        Else
            _options.BackspaceSequence = BackspaceSequence.Del
        End If
        If rbHomeEndStandard.Checked Then
            _options.HomeEndKeysMode = HomeEndKeysMode.Standard
        Else
            _options.HomeEndKeysMode = HomeEndKeysMode.Rxvt
        End If

        If rbFunctionKeysCommonExtended.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.CommonExtended
        ElseIf rbFunctionKeysCommon.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.Common
        ElseIf rbFunctionKeysXTermR6.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.XtermR6
        ElseIf rbFunctionKeysLinux.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.Linux
        ElseIf rbFunctionKeysLinuxAlternative.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.LinuxAlternative
        ElseIf rbFunctionKeysCommonAlternative.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.CommonAlternative
        ElseIf rbFunctionKeysSCO.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.Sco
        ElseIf rbFunctionKeysVT52.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.VT52
        ElseIf rbFunctionKeysVT100Plus.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.VT100Plus
        ElseIf rbFunctionKeysVT400.Checked Then
            _options.FunctionKeysMode = FunctionKeysMode.VT400
        End If

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

        Settings.Default.Save()

        Close()
    End Sub

    ''' <summary>
    ''' Closes the form without saving the form values to the config.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Close()
    End Sub

    ''' <summary>
    ''' Promt the user to choose the file for recorder.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btnRecorderFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecorderFile.Click
        If saveDialog.ShowDialog() <> DialogResult.OK Then
            Return
        End If

        txtRecorderFile.Text = saveDialog.FileName
    End Sub
End Class
