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 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()
|
||||
|
@ -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)
|
||||
|
2
src/ui/Controls/NikseComboBoxPopUp.designer.cs
generated
2
src/ui/Controls/NikseComboBoxPopUp.designer.cs
generated
@ -1,6 +1,6 @@
|
||||
namespace Nikse.SubtitleEdit.Controls
|
||||
{
|
||||
partial class NikseComboBoxPopUp
|
||||
sealed partial class NikseComboBoxPopUp
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
@ -42,6 +42,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
}
|
||||
|
||||
comboBoxModels.UsePopupWindow = true;
|
||||
comboBoxModels.SelectedIndex = selectedIndex;
|
||||
labelPleaseWait.Text = string.Empty;
|
||||
labelFileName.Text = string.Empty;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user