mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 03:33:18 +01:00
Testing combobox popup win
This commit is contained in:
parent
d886042458
commit
acf13dc57d
@ -571,18 +571,38 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
var coordinates = form.PointToClient(Cursor.Position);
|
var coordinates = form.PointToClient(Cursor.Position);
|
||||||
var listViewBounds = new Rectangle(
|
if (_popUp != null)
|
||||||
_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();
|
var listViewBounds = new Rectangle(
|
||||||
return;
|
_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;
|
_hasItemsMouseOver = true;
|
||||||
};
|
};
|
||||||
@ -735,9 +755,9 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
var lvHeight = 18;
|
var lvHeight = 18;
|
||||||
var isOverflow = Parent.GetType() == typeof(ToolStripOverflow);
|
var isOverflow = Parent.GetType() == typeof(ToolStripOverflow);
|
||||||
var form = FindForm();
|
var form = FindForm();
|
||||||
if (isOverflow || form == null)
|
if (isOverflow || form == null || UsePopupWindow)
|
||||||
{
|
{
|
||||||
HandleOverflow(listViewItems, lvHeight);
|
HandleOverflow(listViewItems, lvHeight, form);
|
||||||
return;
|
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;
|
BackColor = UiUtil.BackColor;
|
||||||
ForeColor = UiUtil.ForeColor;
|
ForeColor = UiUtil.ForeColor;
|
||||||
@ -852,10 +877,31 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
_popUp?.Dispose();
|
_popUp?.Dispose();
|
||||||
_popUp = new NikseComboBoxPopUp(_listView, SelectedIndex, Cursor.Position.X - (DropDownWidth / 2), Cursor.Position.Y);
|
var x = Cursor.Position.X - (DropDownWidth / 2);
|
||||||
_popUp.ShowDialog(this.Parent);
|
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?.Dispose();
|
||||||
_listView = null;
|
_listView = null;
|
||||||
|
_listViewShown = false;
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureListViewInitialized()
|
private void EnsureListViewInitialized()
|
||||||
|
@ -1,32 +1,23 @@
|
|||||||
using System;
|
using Nikse.SubtitleEdit.Logic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Nikse.SubtitleEdit.Controls
|
namespace Nikse.SubtitleEdit.Controls
|
||||||
{
|
{
|
||||||
public partial class NikseComboBoxPopUp : Form
|
public sealed partial class NikseComboBoxPopUp : Form
|
||||||
{
|
{
|
||||||
private readonly ListView _listView;
|
private readonly ListView _listView;
|
||||||
private bool _hasMouseOver = false;
|
private bool _hasMouseOver;
|
||||||
private long _startTicks;
|
|
||||||
private bool _doClose;
|
|
||||||
|
|
||||||
public bool DoClose
|
public bool DoClose { get; set; }
|
||||||
{
|
|
||||||
get => _doClose;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_doClose = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public NikseComboBoxPopUp(ListView listView, int selectedIndex, int x, int y)
|
public NikseComboBoxPopUp(ListView listView, int selectedIndex, int x, int y)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
_listView = listView;
|
_listView = listView;
|
||||||
var selectedIndex1 = selectedIndex;
|
|
||||||
Controls.Add(listView);
|
Controls.Add(listView);
|
||||||
|
BackColor = UiUtil.BackColor;
|
||||||
|
|
||||||
StartPosition = FormStartPosition.Manual;
|
StartPosition = FormStartPosition.Manual;
|
||||||
FormBorderStyle = FormBorderStyle.None;
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
@ -37,15 +28,14 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
|
|
||||||
_listView.BringToFront();
|
_listView.BringToFront();
|
||||||
|
|
||||||
if (selectedIndex1 >= 0)
|
if (selectedIndex >= 0)
|
||||||
{
|
{
|
||||||
_listView.Focus();
|
_listView.Focus();
|
||||||
_listView.Items[selectedIndex1].Selected = true;
|
_listView.Items[selectedIndex].Selected = true;
|
||||||
_listView.EnsureVisible(selectedIndex1);
|
_listView.EnsureVisible(selectedIndex);
|
||||||
_listView.Items[selectedIndex1].Focused = true;
|
_listView.Items[selectedIndex].Focused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_startTicks = DateTime.UtcNow.Ticks;
|
|
||||||
KeyPreview = true;
|
KeyPreview = true;
|
||||||
KeyDown += NikseComboBoxPopUp_KeyDown;
|
KeyDown += NikseComboBoxPopUp_KeyDown;
|
||||||
|
|
||||||
@ -76,7 +66,7 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MouseButtons == MouseButtons.Left || Control.MouseButtons == MouseButtons.Right)
|
if (MouseButtons == MouseButtons.Left || MouseButtons == MouseButtons.Right)
|
||||||
{
|
{
|
||||||
if (_hasMouseOver)
|
if (_hasMouseOver)
|
||||||
{
|
{
|
||||||
@ -96,6 +86,12 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
timer.Start();
|
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)
|
private void NikseComboBoxPopUp_KeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.KeyCode == Keys.Escape)
|
if (e.KeyCode == Keys.Escape)
|
||||||
|
2
src/ui/Controls/NikseComboBoxPopUp.designer.cs
generated
2
src/ui/Controls/NikseComboBoxPopUp.designer.cs
generated
@ -1,6 +1,6 @@
|
|||||||
namespace Nikse.SubtitleEdit.Controls
|
namespace Nikse.SubtitleEdit.Controls
|
||||||
{
|
{
|
||||||
partial class NikseComboBoxPopUp
|
sealed partial class NikseComboBoxPopUp
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
|
@ -42,6 +42,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comboBoxModels.UsePopupWindow = true;
|
||||||
comboBoxModels.SelectedIndex = selectedIndex;
|
comboBoxModels.SelectedIndex = selectedIndex;
|
||||||
labelPleaseWait.Text = string.Empty;
|
labelPleaseWait.Text = string.Empty;
|
||||||
labelFileName.Text = string.Empty;
|
labelFileName.Text = string.Empty;
|
||||||
|
@ -9,6 +9,7 @@ using System.IO.Compression;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using static Nikse.SubtitleEdit.Forms.Options.Settings;
|
||||||
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
|
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
|
||||||
|
|
||||||
namespace Nikse.SubtitleEdit.Forms
|
namespace Nikse.SubtitleEdit.Forms
|
||||||
@ -48,6 +49,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
buttonOK.Text = LanguageSettings.Current.General.Ok;
|
buttonOK.Text = LanguageSettings.Current.General.Ok;
|
||||||
labelPleaseWait.Text = string.Empty;
|
labelPleaseWait.Text = string.Empty;
|
||||||
|
|
||||||
|
comboBoxDictionaries.UsePopupWindow = true;
|
||||||
LoadDictionaryList("Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz");
|
LoadDictionaryList("Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz");
|
||||||
FixLargeFonts();
|
FixLargeFonts();
|
||||||
_cancellationTokenSource = new CancellationTokenSource();
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
@ -116,6 +116,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
comboBoxLanguages.SelectedIndex = index;
|
comboBoxLanguages.SelectedIndex = index;
|
||||||
|
comboBoxLanguages.UsePopupWindow = true;
|
||||||
|
|
||||||
Text = LanguageSettings.Current.ChooseLanguage.Title;
|
Text = LanguageSettings.Current.ChooseLanguage.Title;
|
||||||
labelLanguage.Text = LanguageSettings.Current.ChooseLanguage.Language;
|
labelLanguage.Text = LanguageSettings.Current.ChooseLanguage.Language;
|
||||||
|
Loading…
Reference in New Issue
Block a user