From 89d4a3ba2ecf35c4bde144ec6f35b348fca77fd0 Mon Sep 17 00:00:00 2001 From: sr55 Date: Tue, 18 May 2010 15:19:42 +0000 Subject: WinGui: - Switch the Audio Panel over to a DataGridView for more flexibility in possible upcoming changes. - Few UI tweaks to other panels to make look / behave similarly. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3299 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Controls/AudioPanel.Designer.cs | 187 +++++++++++++++++++-------------- win/C#/Controls/AudioPanel.cs | 186 +++++++++++++++++--------------- win/C#/Controls/AudioPanel.resx | 21 ++++ 3 files changed, 232 insertions(+), 162 deletions(-) (limited to 'win/C#/Controls') diff --git a/win/C#/Controls/AudioPanel.Designer.cs b/win/C#/Controls/AudioPanel.Designer.cs index 42d3858a9..5c6462883 100644 --- a/win/C#/Controls/AudioPanel.Designer.cs +++ b/win/C#/Controls/AudioPanel.Designer.cs @@ -35,14 +35,6 @@ namespace Handbrake.Controls private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.lv_audioList = new System.Windows.Forms.ListView(); - this.col_id = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.col_Source = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.col_codec = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.col_mixdown = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.col_samplerate = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.col_bitrate = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.col_drc = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.audioMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.audioList_moveup = new System.Windows.Forms.ToolStripMenuItem(); this.audioList_movedown = new System.Windows.Forms.ToolStripMenuItem(); @@ -66,69 +58,20 @@ namespace Handbrake.Controls this.drp_audioSample = new System.Windows.Forms.ComboBox(); this.AudioTrackGroup = new System.Windows.Forms.GroupBox(); this.AudioMenuRowHeightHack = new System.Windows.Forms.ImageList(this.components); + this.audioList = new System.Windows.Forms.DataGridView(); + this.Track = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Source = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.AudioCodec = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Mixdown = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Samplerate = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Bitrate = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DRC = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.audioMenu.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.tb_drc)).BeginInit(); this.AudioTrackGroup.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.audioList)).BeginInit(); this.SuspendLayout(); // - // lv_audioList - // - this.lv_audioList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.col_id, - this.col_Source, - this.col_codec, - this.col_mixdown, - this.col_samplerate, - this.col_bitrate, - this.col_drc}); - this.lv_audioList.ContextMenuStrip = this.audioMenu; - this.lv_audioList.FullRowSelect = true; - this.lv_audioList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; - this.lv_audioList.HideSelection = false; - this.lv_audioList.Location = new System.Drawing.Point(16, 150); - this.lv_audioList.MultiSelect = false; - this.lv_audioList.Name = "lv_audioList"; - this.lv_audioList.Size = new System.Drawing.Size(689, 140); - this.lv_audioList.TabIndex = 65; - this.lv_audioList.UseCompatibleStateImageBehavior = false; - this.lv_audioList.View = System.Windows.Forms.View.Details; - this.lv_audioList.SelectedIndexChanged += new System.EventHandler(this.lv_audioList_SelectedIndexChanged); - // - // col_id - // - this.col_id.Text = "Track"; - this.col_id.Width = 47; - // - // col_Source - // - this.col_Source.Text = "Source"; - this.col_Source.Width = 170; - // - // col_codec - // - this.col_codec.Text = "Audio Codec"; - this.col_codec.Width = 88; - // - // col_mixdown - // - this.col_mixdown.Text = "Mixdown"; - this.col_mixdown.Width = 127; - // - // col_samplerate - // - this.col_samplerate.Text = "Samplerate (kHz)"; - this.col_samplerate.Width = 101; - // - // col_bitrate - // - this.col_bitrate.Text = "Bitrate (Kbps)"; - this.col_bitrate.Width = 95; - // - // col_drc - // - this.col_drc.Text = "DRC"; - this.col_drc.Width = 57; - // // audioMenu // this.audioMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -386,7 +329,7 @@ namespace Handbrake.Controls this.AudioTrackGroup.Controls.Add(this.lbl_bitrate); this.AudioTrackGroup.Location = new System.Drawing.Point(16, 67); this.AudioTrackGroup.Name = "AudioTrackGroup"; - this.AudioTrackGroup.Size = new System.Drawing.Size(689, 77); + this.AudioTrackGroup.Size = new System.Drawing.Size(685, 77); this.AudioTrackGroup.TabIndex = 66; this.AudioTrackGroup.TabStop = false; this.AudioTrackGroup.Text = "Selected Track: New Track"; @@ -397,13 +340,104 @@ namespace Handbrake.Controls this.AudioMenuRowHeightHack.ImageSize = new System.Drawing.Size(1, 18); this.AudioMenuRowHeightHack.TransparentColor = System.Drawing.Color.Transparent; // + // audioList + // + this.audioList.AllowUserToAddRows = false; + this.audioList.AllowUserToResizeColumns = false; + this.audioList.BackgroundColor = System.Drawing.Color.White; + this.audioList.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.audioList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.audioList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Track, + this.Source, + this.AudioCodec, + this.Mixdown, + this.Samplerate, + this.Bitrate, + this.DRC}); + this.audioList.ContextMenuStrip = this.audioMenu; + this.audioList.GridColor = System.Drawing.Color.White; + this.audioList.Location = new System.Drawing.Point(16, 150); + this.audioList.Name = "audioList"; + this.audioList.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.audioList.RowHeadersVisible = false; + this.audioList.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; + this.audioList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.audioList.ShowCellErrors = false; + this.audioList.ShowCellToolTips = false; + this.audioList.ShowEditingIcon = false; + this.audioList.ShowRowErrors = false; + this.audioList.Size = new System.Drawing.Size(685, 140); + this.audioList.TabIndex = 67; + this.audioList.SelectionChanged += new System.EventHandler(this.audioList_SelectionChanged); + // + // Track + // + this.Track.FillWeight = 304.2808F; + this.Track.HeaderText = "Track"; + this.Track.Name = "Track"; + this.Track.ReadOnly = true; + this.Track.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.Track.Width = 50; + // + // Source + // + this.Source.FillWeight = 49.69727F; + this.Source.HeaderText = "Source"; + this.Source.Name = "Source"; + this.Source.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.Source.Width = 150; + // + // AudioCodec + // + this.AudioCodec.HeaderText = "Audio Codec"; + this.AudioCodec.Name = "AudioCodec"; + this.AudioCodec.ReadOnly = true; + this.AudioCodec.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + // + // Mixdown + // + this.Mixdown.FillWeight = 49.69727F; + this.Mixdown.HeaderText = "Mixdown"; + this.Mixdown.Name = "Mixdown"; + this.Mixdown.ReadOnly = true; + this.Mixdown.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.Mixdown.Width = 150; + // + // Samplerate + // + this.Samplerate.FillWeight = 49.69727F; + this.Samplerate.HeaderText = "Samplerate"; + this.Samplerate.Name = "Samplerate"; + this.Samplerate.ReadOnly = true; + this.Samplerate.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.Samplerate.Width = 75; + // + // Bitrate + // + this.Bitrate.FillWeight = 49.69727F; + this.Bitrate.HeaderText = "Bitrate"; + this.Bitrate.Name = "Bitrate"; + this.Bitrate.ReadOnly = true; + this.Bitrate.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.Bitrate.Width = 75; + // + // DRC + // + this.DRC.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.DRC.FillWeight = 96.36334F; + this.DRC.HeaderText = "DRC"; + this.DRC.Name = "DRC"; + this.DRC.ReadOnly = true; + this.DRC.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + // // AudioPanel // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.audioList); this.Controls.Add(this.label68); this.Controls.Add(this.btn_addAudioTrack); - this.Controls.Add(this.lv_audioList); this.Controls.Add(this.AudioTrackGroup); this.Controls.Add(this.btn_RemoveAudioTrack); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -413,6 +447,7 @@ namespace Handbrake.Controls ((System.ComponentModel.ISupportInitialize)(this.tb_drc)).EndInit(); this.AudioTrackGroup.ResumeLayout(false); this.AudioTrackGroup.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.audioList)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -420,13 +455,6 @@ namespace Handbrake.Controls #endregion - internal System.Windows.Forms.ListView lv_audioList; - private System.Windows.Forms.ColumnHeader col_Source; - private System.Windows.Forms.ColumnHeader col_codec; - private System.Windows.Forms.ColumnHeader col_mixdown; - private System.Windows.Forms.ColumnHeader col_samplerate; - private System.Windows.Forms.ColumnHeader col_bitrate; - private System.Windows.Forms.ColumnHeader col_drc; private System.Windows.Forms.Button btn_RemoveAudioTrack; private System.Windows.Forms.Button btn_addAudioTrack; internal System.Windows.Forms.Label lbl_drc; @@ -442,7 +470,6 @@ namespace Handbrake.Controls internal System.Windows.Forms.ComboBox drp_audioMix; internal System.Windows.Forms.ComboBox drp_audioTrack; internal System.Windows.Forms.ComboBox drp_audioSample; - private System.Windows.Forms.ColumnHeader col_id; private System.Windows.Forms.GroupBox AudioTrackGroup; private System.Windows.Forms.ImageList AudioMenuRowHeightHack; private System.Windows.Forms.ContextMenuStrip audioMenu; @@ -451,5 +478,13 @@ namespace Handbrake.Controls private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; private System.Windows.Forms.ToolStripMenuItem audioList_remove; internal System.Windows.Forms.ComboBox drp_audioBitrate; + private System.Windows.Forms.DataGridView audioList; + private System.Windows.Forms.DataGridViewTextBoxColumn Track; + private System.Windows.Forms.DataGridViewTextBoxColumn Source; + private System.Windows.Forms.DataGridViewTextBoxColumn AudioCodec; + private System.Windows.Forms.DataGridViewTextBoxColumn Mixdown; + private System.Windows.Forms.DataGridViewTextBoxColumn Samplerate; + private System.Windows.Forms.DataGridViewTextBoxColumn Bitrate; + private System.Windows.Forms.DataGridViewTextBoxColumn DRC; } } diff --git a/win/C#/Controls/AudioPanel.cs b/win/C#/Controls/AudioPanel.cs index 9a4938bb1..915910573 100644 --- a/win/C#/Controls/AudioPanel.cs +++ b/win/C#/Controls/AudioPanel.cs @@ -39,9 +39,9 @@ namespace Handbrake.Controls /// Get the audio panel /// /// A listview containing the audio tracks - public ListView GetAudioPanel() + public DataGridView GetAudioPanel() { - return lv_audioList; + return audioList; } /// @@ -79,10 +79,10 @@ namespace Handbrake.Controls } // Make sure the table is updated with new audio codecs - foreach (ListViewItem row in lv_audioList.Items) + foreach (DataGridViewRow row in audioList.Rows) { - if (!drp_audioEncoder.Items.Contains(row.SubItems[2].Text)) - row.SubItems[2].Text = drp_audioEncoder.Items[0].ToString(); + if (!drp_audioEncoder.Items.Contains(row.Cells[2].Value)) + row.Cells[2].Value = drp_audioEncoder.Items[0].ToString(); } } @@ -92,7 +92,7 @@ namespace Handbrake.Controls /// True if m4v is required public bool RequiresM4V() { - return lv_audioList.Items.Cast().Any(item => item.SubItems[2].Text.Contains("AC3")); + return this.audioList.Rows.Cast().Any(row => row.Cells[2].Value.ToString().Contains("AC3")); } /// @@ -108,14 +108,15 @@ namespace Handbrake.Controls foreach (AudioTrack track in audioTracks) { - ListViewItem newTrack = new ListViewItem(GetNewID().ToString()); - - newTrack.SubItems.Add("Automatic"); - newTrack.SubItems.Add(track.Encoder); - newTrack.SubItems.Add(track.MixDown); - newTrack.SubItems.Add(track.SampleRate); - newTrack.SubItems.Add(track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate); - newTrack.SubItems.Add(track.DRC); + DataGridViewRow newTrack = new DataGridViewRow(); + newTrack.CreateCells(audioList); + newTrack.Cells[0].Value = GetNewID().ToString(); + newTrack.Cells[1].Value = "Automatic"; + newTrack.Cells[2].Value = track.Encoder; + newTrack.Cells[3].Value = track.MixDown; + newTrack.Cells[4].Value = track.SampleRate; + newTrack.Cells[5].Value = track.Encoder.Contains("AC3") ? "Auto" : track.Bitrate; + newTrack.Cells[6].Value = track.DRC; AddTrackForPreset(newTrack); } } @@ -129,30 +130,40 @@ namespace Handbrake.Controls { if (selectedTitle.AudioTracks.Count == 0) { - lv_audioList.Items.Clear(); + audioList.Rows.Clear(); drp_audioTrack.Items.Clear(); drp_audioTrack.Items.Add("None Found"); drp_audioTrack.SelectedIndex = 0; return; } + // The Source Information for the title will have changed, so set all the tracks to Automatic. + foreach (DataGridViewRow row in this.audioList.Rows) + { + row.Cells[1].Value = "Automatic"; + } + + // Setup the Audio track source dropdown with the new audio tracks. drp_audioTrack.Items.Clear(); drp_audioTrack.Items.Add("Automatic"); drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray()); - if (lv_audioList.Items.Count == 0 && preset != null) + // Re-add any audio tracks that the preset has. + if (audioList.Rows.Count == 0 && preset != null) { QueryParser parsed = QueryParser.Parse(preset.Query); foreach (AudioTrack audioTrack in parsed.AudioInformation) { - ListViewItem newTrack = new ListViewItem(GetNewID().ToString()); - newTrack.SubItems.Add(audioTrack.Track); - newTrack.SubItems.Add(audioTrack.Encoder); - newTrack.SubItems.Add(audioTrack.MixDown); - newTrack.SubItems.Add(audioTrack.SampleRate); - newTrack.SubItems.Add(audioTrack.Bitrate); - newTrack.SubItems.Add(audioTrack.DRC); - lv_audioList.Items.Add(newTrack); + DataGridViewRow newTrack = new DataGridViewRow(); + newTrack.CreateCells(audioList); + newTrack.Cells[0].Value = GetNewID().ToString(); + newTrack.Cells[1].Value = (audioTrack.Track); + newTrack.Cells[2].Value = (audioTrack.Encoder); + newTrack.Cells[3].Value = (audioTrack.MixDown); + newTrack.Cells[4].Value = (audioTrack.SampleRate); + newTrack.Cells[5].Value = (audioTrack.Bitrate); + newTrack.Cells[6].Value = (audioTrack.DRC); + audioList.Rows.Add(newTrack); } } @@ -176,14 +187,14 @@ namespace Handbrake.Controls } if (drp_audioTrack.SelectedItem != null) - foreach (ListViewItem item in lv_audioList.Items) - item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString(); + foreach (DataGridViewRow item in audioList.Rows) + item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString(); else { drp_audioTrack.SelectedIndex = 0; if (drp_audioTrack.SelectedItem != null) - foreach (ListViewItem item in lv_audioList.Items) - item.SubItems[1].Text = drp_audioTrack.SelectedItem.ToString(); + foreach (DataGridViewRow item in audioList.Rows) + item.Cells[1].Value = drp_audioTrack.SelectedItem.ToString(); } } else @@ -210,8 +221,8 @@ namespace Handbrake.Controls switch (ctl.Name) { case "drp_audioTrack": - if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0) - lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audioTrack.Text; + if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0) + audioList.SelectedRows[0].Cells[1].Value = drp_audioTrack.Text; break; case "drp_audioEncoder": SetMixDown(); @@ -236,23 +247,23 @@ namespace Handbrake.Controls } // Update an item in the Audio list if required. - if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0) - lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audioEncoder.Text; + if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0) + audioList.SelectedRows[0].Cells[2].Value = drp_audioEncoder.Text; break; case "drp_audioMix": SetBitrate(); - if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0) - lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audioMix.Text; + if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0) + audioList.SelectedRows[0].Cells[3].Value = drp_audioMix.Text; break; case "drp_audioSample": - if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0) - lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audioSample.Text; + if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0) + audioList.SelectedRows[0].Cells[4].Value = drp_audioSample.Text; break; case "drp_audioBitrate": // Update an item in the Audio list if required. - if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0) - lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = drp_audioBitrate.Text; + if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0) + audioList.SelectedRows[0].Cells[5].Value = drp_audioBitrate.Text; break; case "tb_drc": double value; @@ -263,15 +274,15 @@ namespace Handbrake.Controls lbl_drc.Text = value.ToString(); // Update an item in the Audio list if required. - if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0) + if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0) { - lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text = value.ToString(); - lv_audioList.Select(); + audioList.SelectedRows[0].Cells[6].Value = value.ToString(); + audioList.Select(); } break; } - lv_audioList.Select(); + audioList.Select(); } /// @@ -283,27 +294,26 @@ namespace Handbrake.Controls /// /// The e. /// - private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e) + private void audioList_SelectionChanged(object sender, EventArgs e) { // Set the dropdown controls based on the selected item in the Audio List. - if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0) + if (audioList.Rows.Count != 0 && audioList.SelectedRows.Count != 0) { - drp_audioTrack.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text; - drp_audioEncoder.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text; - drp_audioMix.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text; - drp_audioSample.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text; - drp_audioBitrate.SelectedItem = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text; + drp_audioTrack.SelectedItem = audioList.SelectedRows[0].Cells[1].Value; + drp_audioEncoder.SelectedItem = audioList.SelectedRows[0].Cells[2].Value; + drp_audioMix.SelectedItem = audioList.SelectedRows[0].Cells[3].Value; + drp_audioSample.SelectedItem = audioList.SelectedRows[0].Cells[4].Value; + drp_audioBitrate.SelectedItem = audioList.SelectedRows[0].Cells[5].Value; double drcValue; int drcCalculated; - double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue); + double.TryParse(audioList.SelectedRows[0].Cells[6].Value.ToString(), out drcValue); if (drcValue != 0) drcValue = ((drcValue * 10) + 1) - 10; int.TryParse(drcValue.ToString(), out drcCalculated); tb_drc.Value = drcCalculated; - lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text; + lbl_drc.Text = audioList.SelectedRows[0].Cells[6].Value.ToString(); - AudioTrackGroup.Text = "Selected Track: " + - lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[0].Text; + AudioTrackGroup.Text = "Selected Track: " + audioList.SelectedRows[0].Cells[0].Value; } else AudioTrackGroup.Text = "Selected Track: None (Click \"Add Track\" to add)"; @@ -337,22 +347,25 @@ namespace Handbrake.Controls value = ((tb_drc.Value - 1) / 10.0) + 1; // Create a new row for the Audio list based on the currently selected items in the dropdown. - ListViewItem newTrack = new ListViewItem(GetNewID().ToString()); - newTrack.SubItems.Add(drp_audioTrack.Text); - newTrack.SubItems.Add(drp_audioEncoder.Text); - newTrack.SubItems.Add(drp_audioMix.Text); - newTrack.SubItems.Add(drp_audioSample.Text); - newTrack.SubItems.Add(drp_audioBitrate.Text); - newTrack.SubItems.Add(value.ToString()); - lv_audioList.Items.Add(newTrack); + DataGridViewRow newTrack = new DataGridViewRow(); + newTrack.CreateCells(audioList); + newTrack.Cells[0].Value = GetNewID().ToString(); + newTrack.Cells[1].Value = drp_audioTrack.Text; + newTrack.Cells[2].Value = drp_audioEncoder.Text; + newTrack.Cells[3].Value = drp_audioMix.Text; + newTrack.Cells[4].Value = drp_audioSample.Text; + newTrack.Cells[5].Value = drp_audioBitrate.Text; + newTrack.Cells[6].Value = value.ToString(); + audioList.Rows.Add(newTrack); // The Audio List has changed to raise the event. if (this.AudioListChanged != null) this.AudioListChanged(this, new EventArgs()); // Select the newly added track and select the control - lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true; - lv_audioList.Select(); + audioList.ClearSelection(); + audioList.Rows[audioList.Rows.Count - 1].Selected = true; + audioList.Select(); } /// @@ -413,7 +426,7 @@ namespace Handbrake.Controls RemoveTrack(); } - // Public Functions + // Private Functions /// /// Add track for preset @@ -421,9 +434,9 @@ namespace Handbrake.Controls /// /// The item. /// - private void AddTrackForPreset(ListViewItem item) + private void AddTrackForPreset(DataGridViewRow item) { - lv_audioList.Items.Add(item); + audioList.Rows.Add(item); if (this.AudioListChanged != null) this.AudioListChanged(this, new EventArgs()); } @@ -433,7 +446,7 @@ namespace Handbrake.Controls /// private void ClearAudioList() { - lv_audioList.Items.Clear(); + audioList.Rows.Clear(); if (this.AudioListChanged != null) this.AudioListChanged(this, new EventArgs()); } @@ -446,7 +459,7 @@ namespace Handbrake.Controls /// private int GetNewID() { - return lv_audioList.Items.Count + 1; + return audioList.Rows.Count + 1; } /// @@ -455,26 +468,27 @@ namespace Handbrake.Controls private void RemoveTrack() { // Remove the Item and reselect the control if the following conditions are met. - if (lv_audioList.SelectedItems.Count != 0) + if (audioList.SelectedRows.Count != 0) { // The Audio List is about to change so raise the event. if (this.AudioListChanged != null) this.AudioListChanged(this, new EventArgs()); // Record the current selected index. - int currentPosition = lv_audioList.SelectedIndices[0]; + int currentPosition = audioList.SelectedRows[0].Index; - lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]); + audioList.Rows.Remove(audioList.SelectedRows[0]); // Now reslect the correct item and give focus to the audio list. - if (lv_audioList.Items.Count != 0) + if (audioList.Rows.Count != 0) { - if (currentPosition <= (lv_audioList.Items.Count - 1)) - lv_audioList.Items[currentPosition].Selected = true; - else if (currentPosition > (lv_audioList.Items.Count - 1)) - lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true; + audioList.ClearSelection(); + if (currentPosition <= (audioList.Rows.Count - 1)) + audioList.Rows[currentPosition].Selected = true; + else if (currentPosition > (audioList.Rows.Count - 1)) + audioList.Rows[audioList.Rows.Count - 1].Selected = true; - lv_audioList.Select(); + audioList.Select(); } // Regenerate the ID numers ReGenerateListIDs(); @@ -489,20 +503,20 @@ namespace Handbrake.Controls /// private void MoveTrack(bool up) { - if (lv_audioList.SelectedIndices.Count == 0) return; + if (audioList.SelectedRows.Count == 0) return; - ListViewItem item = lv_audioList.SelectedItems[0]; + DataGridViewRow item = audioList.SelectedRows[0]; int index = item.Index; if (up) index--; else index++; - - if (index < lv_audioList.Items.Count || (lv_audioList.Items.Count > index && index >= 0)) + + if (index < audioList.Rows.Count || (audioList.Rows.Count > index && index >= 0)) { - lv_audioList.Items.Remove(item); - lv_audioList.Items.Insert(index, item); + audioList.Rows.Remove(item); + audioList.Rows.Insert(index, item); + audioList.ClearSelection(); item.Selected = true; - lv_audioList.Focus(); } } @@ -512,9 +526,9 @@ namespace Handbrake.Controls private void ReGenerateListIDs() { int i = 1; - foreach (ListViewItem item in lv_audioList.Items) + foreach (DataGridViewRow item in audioList.Rows) { - item.SubItems[0].Text = i.ToString(); + item.Cells[0].Value = i.ToString(); i++; } } diff --git a/win/C#/Controls/AudioPanel.resx b/win/C#/Controls/AudioPanel.resx index 07fd5e25d..1a227342d 100644 --- a/win/C#/Controls/AudioPanel.resx +++ b/win/C#/Controls/AudioPanel.resx @@ -123,4 +123,25 @@ 35, 17 + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file -- cgit v1.2.3