Testing combobox popup win

This commit is contained in:
niksedk 2023-08-27 17:18:00 +02:00
parent d886042458
commit acf13dc57d
6 changed files with 82 additions and 36 deletions

View File

@ -571,18 +571,38 @@ namespace Nikse.SubtitleEdit.Controls
}
var coordinates = form.PointToClient(Cursor.Position);
var listViewBounds = new Rectangle(
_listView.Bounds.X,
_listView.Bounds.Y - 25,
_listView.Bounds.Width + 25 + 25,
_listView.Bounds.Height + 50 + 25);
if (_hasItemsMouseOver &&
!(listViewBounds.Contains(coordinates) || Bounds.Contains(coordinates)) ||
!_listViewShown)
if (_popUp != null)
{
HideDropDown();
return;
var listViewBounds = new Rectangle(
_listView.Bounds.X,
_listView.Bounds.Y - 25,
_listView.Bounds.Width + 25 + 25,
_listView.Bounds.Height + 50 + 25);
if (_hasItemsMouseOver &&
!(_popUp.BoundsContainsCursorPosition() || Bounds.Contains(coordinates)) ||
!_listViewShown)
{
HideDropDown();
return;
}
}
else
{
var listViewBounds = new Rectangle(
_listView.Bounds.X,
_listView.Bounds.Y - 25,
_listView.Bounds.Width + 25 + 25,
_listView.Bounds.Height + 50 + 25);
if (_hasItemsMouseOver &&
!(listViewBounds.Contains(coordinates) || Bounds.Contains(coordinates)) ||
!_listViewShown)
{
HideDropDown();
return;
}
}
_hasItemsMouseOver = true;
};
@ -735,9 +755,9 @@ namespace Nikse.SubtitleEdit.Controls
var lvHeight = 18;
var isOverflow = Parent.GetType() == typeof(ToolStripOverflow);
var form = FindForm();
if (isOverflow || form == null)
if (isOverflow || form == null || UsePopupWindow)
{
HandleOverflow(listViewItems, lvHeight);
HandleOverflow(listViewItems, lvHeight, form);
return;
}
@ -811,7 +831,12 @@ namespace Nikse.SubtitleEdit.Controls
}
}
private void HandleOverflow(List<ListViewItem> listViewItems, int lvHeight)
/// <summary>
/// Show picker in a window.
/// </summary>
public bool UsePopupWindow { get; set; }
private void HandleOverflow(List<ListViewItem> listViewItems, int lvHeight, Form form)
{
BackColor = UiUtil.BackColor;
ForeColor = UiUtil.ForeColor;
@ -852,10 +877,31 @@ namespace Nikse.SubtitleEdit.Controls
}
_popUp?.Dispose();
_popUp = new NikseComboBoxPopUp(_listView, SelectedIndex, Cursor.Position.X - (DropDownWidth / 2), Cursor.Position.Y);
_popUp.ShowDialog(this.Parent);
var x = Cursor.Position.X - (DropDownWidth / 2);
var y = Cursor.Position.Y;
if (UsePopupWindow && form != null)
{
var ctl = (Control)this;
var totalX = ctl.Left;
var totalY = ctl.Top;
while (ctl.Parent != form)
{
ctl = ctl.Parent;
totalX += ctl.Left;
totalY += ctl.Top;
}
var p = PointToScreen(new Point(Left - totalX, Bottom - totalY));
x = p.X;
y = p.Y;
}
_popUp = new NikseComboBoxPopUp(_listView, SelectedIndex, x, y);
_popUp.ShowDialog(Parent);
_listView?.Dispose();
_listView = null;
_listViewShown = false;
Invalidate();
}
private void EnsureListViewInitialized()

View File

@ -1,32 +1,23 @@
using System;
using Nikse.SubtitleEdit.Logic;
using System.Drawing;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Controls
{
public partial class NikseComboBoxPopUp : Form
public sealed partial class NikseComboBoxPopUp : Form
{
private readonly ListView _listView;
private bool _hasMouseOver = false;
private long _startTicks;
private bool _doClose;
private bool _hasMouseOver;
public bool DoClose
{
get => _doClose;
set
{
_doClose = value;
}
}
public bool DoClose { get; set; }
public NikseComboBoxPopUp(ListView listView, int selectedIndex, int x, int y)
{
InitializeComponent();
_listView = listView;
var selectedIndex1 = selectedIndex;
Controls.Add(listView);
BackColor = UiUtil.BackColor;
StartPosition = FormStartPosition.Manual;
FormBorderStyle = FormBorderStyle.None;
@ -37,15 +28,14 @@ namespace Nikse.SubtitleEdit.Controls
_listView.BringToFront();
if (selectedIndex1 >= 0)
if (selectedIndex >= 0)
{
_listView.Focus();
_listView.Items[selectedIndex1].Selected = true;
_listView.EnsureVisible(selectedIndex1);
_listView.Items[selectedIndex1].Focused = true;
_listView.Items[selectedIndex].Selected = true;
_listView.EnsureVisible(selectedIndex);
_listView.Items[selectedIndex].Focused = true;
}
_startTicks = DateTime.UtcNow.Ticks;
KeyPreview = true;
KeyDown += NikseComboBoxPopUp_KeyDown;
@ -76,7 +66,7 @@ namespace Nikse.SubtitleEdit.Controls
DialogResult = DialogResult.Cancel;
}
if (MouseButtons == MouseButtons.Left || Control.MouseButtons == MouseButtons.Right)
if (MouseButtons == MouseButtons.Left || MouseButtons == MouseButtons.Right)
{
if (_hasMouseOver)
{
@ -96,6 +86,12 @@ namespace Nikse.SubtitleEdit.Controls
timer.Start();
}
public bool BoundsContainsCursorPosition()
{
var coordinates = Cursor.Position;
return new Rectangle(Bounds.Left - 25, Bounds.Top - 25, Bounds.Width + 50, Bounds.Height + 50).Contains(coordinates);
}
private void NikseComboBoxPopUp_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Controls
{
partial class NikseComboBoxPopUp
sealed partial class NikseComboBoxPopUp
{
/// <summary>
/// Required designer variable.

View File

@ -42,6 +42,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
}
comboBoxModels.UsePopupWindow = true;
comboBoxModels.SelectedIndex = selectedIndex;
labelPleaseWait.Text = string.Empty;
labelFileName.Text = string.Empty;

View File

@ -9,6 +9,7 @@ using System.IO.Compression;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using static Nikse.SubtitleEdit.Forms.Options.Settings;
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
namespace Nikse.SubtitleEdit.Forms
@ -48,6 +49,7 @@ namespace Nikse.SubtitleEdit.Forms
buttonOK.Text = LanguageSettings.Current.General.Ok;
labelPleaseWait.Text = string.Empty;
comboBoxDictionaries.UsePopupWindow = true;
LoadDictionaryList("Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz");
FixLargeFonts();
_cancellationTokenSource = new CancellationTokenSource();

View File

@ -116,6 +116,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
}
}
comboBoxLanguages.SelectedIndex = index;
comboBoxLanguages.UsePopupWindow = true;
Text = LanguageSettings.Current.ChooseLanguage.Title;
labelLanguage.Text = LanguageSettings.Current.ChooseLanguage.Language;