Imports System.ComponentModel

Imports Stax
Imports Stax.UI
Imports Stax.AppFramework

<ToolboxItem(False)> _
Public Class OptionsAutomationControl
    Inherits DialogControl

#Region " Designer "

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents TipProvider As Stax.UI.TipProvider
    Friend WithEvents cbAutoCropBorders As System.Windows.Forms.CheckBox
    Friend WithEvents SmartTagProvider As Stax.UI.Design.SmartTagProvider
    Friend WithEvents gbSubtitlePreselection As System.Windows.Forms.GroupBox
    Friend WithEvents lbSubtitles As System.Windows.Forms.ListBox
    Friend WithEvents bRemove As System.Windows.Forms.Button
    Friend WithEvents bAdd As System.Windows.Forms.Button
    Friend WithEvents cbAutoCompressibilityCheck As System.Windows.Forms.CheckBox
    Friend WithEvents cbAutoResizeImageSize As System.Windows.Forms.CheckBox
    Friend WithEvents lAfterthecompressibilitycheckadjust As System.Windows.Forms.Label
    Friend WithEvents cbCompCheckAction As System.Windows.Forms.ComboBox
    Friend WithEvents nudAutoResize As System.Windows.Forms.NumericUpDown
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(OptionsAutomationControl))
        Me.TipProvider = New Stax.UI.TipProvider(Me.components)
        Me.cbAutoResizeImageSize = New System.Windows.Forms.CheckBox
        Me.cbAutoCropBorders = New System.Windows.Forms.CheckBox
        Me.cbCompCheckAction = New System.Windows.Forms.ComboBox
        Me.nudAutoResize = New System.Windows.Forms.NumericUpDown
        Me.SmartTagProvider = New Stax.UI.Design.SmartTagProvider
        Me.gbSubtitlePreselection = New System.Windows.Forms.GroupBox
        Me.lbSubtitles = New System.Windows.Forms.ListBox
        Me.bRemove = New System.Windows.Forms.Button
        Me.bAdd = New System.Windows.Forms.Button
        Me.cbAutoCompressibilityCheck = New System.Windows.Forms.CheckBox
        Me.lAfterthecompressibilitycheckadjust = New System.Windows.Forms.Label
        CType(Me.TipProvider, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.nudAutoResize, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.gbSubtitlePreselection.SuspendLayout()
        Me.SuspendLayout()
        '
        'cbAutoResizeImageSize
        '
        Me.cbAutoResizeImageSize.AutoSize = True
        Me.cbAutoResizeImageSize.Location = New System.Drawing.Point(11, 54)
        Me.cbAutoResizeImageSize.Name = "cbAutoResizeImageSize"
        Me.cbAutoResizeImageSize.Size = New System.Drawing.Size(141, 17)
        Me.cbAutoResizeImageSize.TabIndex = 107
        Me.cbAutoResizeImageSize.Text = "Auto Resize Image Size:"
        Me.TipProvider.SetTipText(Me.cbAutoResizeImageSize, "Automatic adjustment of the image size in pixel.")
        Me.cbAutoResizeImageSize.UseVisualStyleBackColor = True
        '
        'cbAutoCropBorders
        '
        Me.cbAutoCropBorders.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cbAutoCropBorders.AutoSize = True
        Me.cbAutoCropBorders.Location = New System.Drawing.Point(11, 31)
        Me.cbAutoCropBorders.Name = "cbAutoCropBorders"
        Me.cbAutoCropBorders.Size = New System.Drawing.Size(112, 17)
        Me.cbAutoCropBorders.TabIndex = 101
        Me.cbAutoCropBorders.Text = "Auto Crop Borders"
        Me.TipProvider.SetTipText(Me.cbAutoCropBorders, "Automatic cropping of unnecessary borders.")
        '
        'cbCompCheckAction
        '
        Me.cbCompCheckAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cbCompCheckAction.FormattingEnabled = True
        Me.cbCompCheckAction.Location = New System.Drawing.Point(201, 94)
        Me.cbCompCheckAction.Name = "cbCompCheckAction"
        Me.cbCompCheckAction.Size = New System.Drawing.Size(82, 21)
        Me.cbCompCheckAction.TabIndex = 111
        Me.TipProvider.SetTipName(Me.cbCompCheckAction, "After the compressibility check adjust")
        Me.TipProvider.SetTipText(Me.cbCompCheckAction, "Adjusts the file size or image size according to the percent value defined in the" & _
                " encoder options.")
        '
        'nudAutoResize
        '
        Me.nudAutoResize.Enabled = False
        Me.nudAutoResize.Increment = New Decimal(New Integer() {10000, 0, 0, 0})
        Me.nudAutoResize.Location = New System.Drawing.Point(158, 53)
        Me.nudAutoResize.Maximum = New Decimal(New Integer() {1000000, 0, 0, 0})
        Me.nudAutoResize.Name = "nudAutoResize"
        Me.nudAutoResize.Size = New System.Drawing.Size(72, 20)
        Me.nudAutoResize.TabIndex = 103
        '
        'gbSubtitlePreselection
        '
        Me.gbSubtitlePreselection.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.gbSubtitlePreselection.Controls.Add(Me.lbSubtitles)
        Me.gbSubtitlePreselection.Controls.Add(Me.bRemove)
        Me.gbSubtitlePreselection.Controls.Add(Me.bAdd)
        Me.gbSubtitlePreselection.Location = New System.Drawing.Point(11, 193)
        Me.gbSubtitlePreselection.Name = "gbSubtitlePreselection"
        Me.gbSubtitlePreselection.Size = New System.Drawing.Size(357, 88)
        Me.gbSubtitlePreselection.TabIndex = 104
        Me.gbSubtitlePreselection.TabStop = False
        Me.gbSubtitlePreselection.Text = "Auto Subtitle Selection"
        '
        'lbSubtitles
        '
        Me.lbSubtitles.FormattingEnabled = True
        Me.lbSubtitles.IntegralHeight = False
        Me.lbSubtitles.Location = New System.Drawing.Point(10, 19)
        Me.lbSubtitles.Name = "lbSubtitles"
        Me.lbSubtitles.Size = New System.Drawing.Size(128, 54)
        Me.lbSubtitles.Sorted = True
        Me.lbSubtitles.TabIndex = 2
        '
        'bRemove
        '
        Me.bRemove.Image = Global.StaxRip.My.Resources.Resources.Minus16
        Me.bRemove.Location = New System.Drawing.Point(144, 49)
        Me.bRemove.Name = "bRemove"
        Me.bRemove.Size = New System.Drawing.Size(75, 24)
        Me.bRemove.TabIndex = 1
        Me.bRemove.Text = "Remove"
        Me.bRemove.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
        Me.bRemove.UseVisualStyleBackColor = True
        '
        'bAdd
        '
        Me.bAdd.Image = Global.StaxRip.My.Resources.Resources.Plus16
        Me.bAdd.Location = New System.Drawing.Point(144, 19)
        Me.bAdd.Name = "bAdd"
        Me.bAdd.Size = New System.Drawing.Size(75, 24)
        Me.bAdd.TabIndex = 0
        Me.bAdd.Text = "Add"
        Me.bAdd.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
        Me.bAdd.UseVisualStyleBackColor = True
        '
        'cbAutoCompressibilityCheck
        '
        Me.cbAutoCompressibilityCheck.AutoSize = True
        Me.cbAutoCompressibilityCheck.Location = New System.Drawing.Point(11, 77)
        Me.cbAutoCompressibilityCheck.Name = "cbAutoCompressibilityCheck"
        Me.cbAutoCompressibilityCheck.Size = New System.Drawing.Size(153, 17)
        Me.cbAutoCompressibilityCheck.TabIndex = 105
        Me.cbAutoCompressibilityCheck.Text = "Auto Compressibility Check"
        Me.TipProvider.SetTipText(Me.cbAutoCompressibilityCheck, resources.GetString("cbAutoCompressibilityCheck.TipText"))
        Me.cbAutoCompressibilityCheck.UseVisualStyleBackColor = True
        '
        'lAfterthecompressibilitycheckadjust
        '
        Me.lAfterthecompressibilitycheckadjust.AutoSize = True
        Me.lAfterthecompressibilitycheckadjust.Location = New System.Drawing.Point(11, 97)
        Me.lAfterthecompressibilitycheckadjust.Name = "lAfterthecompressibilitycheckadjust"
        Me.lAfterthecompressibilitycheckadjust.Size = New System.Drawing.Size(184, 13)
        Me.lAfterthecompressibilitycheckadjust.TabIndex = 110
        Me.lAfterthecompressibilitycheckadjust.Text = "After the compressibility check adjust:"
        '
        'OptionsAutomationControl
        '
        Me.Controls.Add(Me.cbCompCheckAction)
        Me.Controls.Add(Me.lAfterthecompressibilitycheckadjust)
        Me.Controls.Add(Me.cbAutoResizeImageSize)
        Me.Controls.Add(Me.cbAutoCompressibilityCheck)
        Me.Controls.Add(Me.gbSubtitlePreselection)
        Me.Controls.Add(Me.nudAutoResize)
        Me.Controls.Add(Me.cbAutoCropBorders)
        Me.Name = "OptionsAutomationControl"
        Me.Padding = New System.Windows.Forms.Padding(8, 28, 8, 8)
        Me.Size = New System.Drawing.Size(379, 294)
        Me.Text = "Text"
        Me.UseVisualStyle = True
        CType(Me.TipProvider, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.nudAutoResize, System.ComponentModel.ISupportInitialize).EndInit()
        Me.gbSubtitlePreselection.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Public Sub New()
        MyBase.New()
        InitializeComponent()

        ListBag(Of CompCheckAction).PopulateList(cbCompCheckAction)
        ListBag(Of CompCheckAction).SelectItem(cbCompCheckAction, p.CompCheckAction)

        cbAutoCropBorders.Checked = p.AutoCrop
        nudAutoResize.Value = p.AutoResizeImage
        cbAutoResizeImageSize.Checked = p.AutoResizeImage <> 0
        cbAutoCompressibilityCheck.Checked = p.AutoCompCheck

        lbSubtitles.Items.AddRange(p.PreselectionSubtitleLanguages.ToArray)
        UpdateControls()
    End Sub

    Private Sub OptionsGeneralControl_FormClosingOK() Handles MyBase.FormClosingOK
        p.AutoCrop = cbAutoCropBorders.Checked
        p.AutoResizeImage = CInt(nudAutoResize.Value)
        p.AutoCompCheck = cbAutoCompressibilityCheck.Checked
        p.PreselectionSubtitleLanguages.Clear()

        p.CompCheckAction = ListBag(Of CompCheckAction).GetValue(cbCompCheckAction)

        For Each i As Language In lbSubtitles.Items
            p.PreselectionSubtitleLanguages.Add(i)
        Next
    End Sub

    Private Sub bAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bAdd.Click
        Dim f As New SelectionBox(Of Language)
        f.Text = "Please select a language."
        f.Title = "Language Selection"

        For Each i As Language In Language.Languages
            f.AddItem(i)
        Next

        If f.Show = DialogResult.OK Then
            lbSubtitles.Items.Add(f.SelecteItem)
        End If
    End Sub

    Private Sub bRemove_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bRemove.Click
        ListBoxHelp.RemoveSelection(lbSubtitles)
    End Sub

    Private Sub UpdateControls()
        bRemove.Enabled = Not lbSubtitles.SelectedItem Is Nothing
    End Sub

    Private Sub lbSubtitles_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lbSubtitles.SelectedIndexChanged
        UpdateControls()
    End Sub

    Private Sub cbAutoResize_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbAutoResizeImageSize.CheckedChanged
        nudAutoResize.Enabled = cbAutoResizeImageSize.Checked

        If Not cbAutoResizeImageSize.Checked Then
            nudAutoResize.Value = 0
        Else
            If nudAutoResize.Value = 0 Then
                nudAutoResize.Value = 195000
            End If
        End If
    End Sub
End Class