|
@@ -202,7 +202,7 @@ namespace Terminal.Gui {
|
|
/// Gets the parent for this <see cref="MenuItem"/>.
|
|
/// Gets the parent for this <see cref="MenuItem"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <value>The parent.</value>
|
|
/// <value>The parent.</value>
|
|
- public MenuItem Parent { get; internal set; }
|
|
|
|
|
|
+ public MenuItem Parent { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets if this <see cref="MenuItem"/> is from a sub-menu.
|
|
/// Gets if this <see cref="MenuItem"/> is from a sub-menu.
|
|
@@ -443,7 +443,7 @@ namespace Terminal.Gui {
|
|
}
|
|
}
|
|
int minX = x;
|
|
int minX = x;
|
|
int minY = y;
|
|
int minY = y;
|
|
- var borderOffset = border != LineStyle.None ? 2 : 0; // This 2 is frame border?
|
|
|
|
|
|
+ var borderOffset = 2; // This 2 is for the space around
|
|
int maxW = (items.Max (z => z?.Width) ?? 0) + borderOffset;
|
|
int maxW = (items.Max (z => z?.Width) ?? 0) + borderOffset;
|
|
int maxH = items.Length + borderOffset;
|
|
int maxH = items.Length + borderOffset;
|
|
if (parent != null && x + maxW > Driver.Cols) {
|
|
if (parent != null && x + maxW > Driver.Cols) {
|
|
@@ -482,6 +482,7 @@ namespace Terminal.Gui {
|
|
|
|
|
|
if (Application.Current != null) {
|
|
if (Application.Current != null) {
|
|
Application.Current.DrawContentComplete += Current_DrawContentComplete;
|
|
Application.Current.DrawContentComplete += Current_DrawContentComplete;
|
|
|
|
+ Application.Current.TerminalResized += Current_TerminalResized;
|
|
}
|
|
}
|
|
Application.RootMouseEvent += Application_RootMouseEvent;
|
|
Application.RootMouseEvent += Application_RootMouseEvent;
|
|
|
|
|
|
@@ -510,10 +511,40 @@ namespace Terminal.Gui {
|
|
AddKeyBinding (Key.Enter, Command.Accept);
|
|
AddKeyBinding (Key.Enter, Command.Accept);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void Current_TerminalResized (object sender, SizeChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (host.IsMenuOpen) {
|
|
|
|
+ host.CloseAllMenus ();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
+ public override void OnVisibleChanged ()
|
|
|
|
+ {
|
|
|
|
+ base.OnVisibleChanged ();
|
|
|
|
+ if (Visible) {
|
|
|
|
+ Application.RootMouseEvent += Application_RootMouseEvent;
|
|
|
|
+ } else {
|
|
|
|
+ Application.RootMouseEvent -= Application_RootMouseEvent;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void Application_RootMouseEvent (MouseEvent me)
|
|
private void Application_RootMouseEvent (MouseEvent me)
|
|
{
|
|
{
|
|
- var view = View.FindDeepestView (this, me.X, me.Y, out int rx, out int ry);
|
|
|
|
|
|
+ if (me.View is MenuBar) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ var locationOffset = host.GetScreenOffsetFromCurrent ();
|
|
|
|
+ if (SuperView != null && SuperView != Application.Current) {
|
|
|
|
+ locationOffset.X += SuperView.Border.Thickness.Left;
|
|
|
|
+ locationOffset.Y += SuperView.Border.Thickness.Top;
|
|
|
|
+ }
|
|
|
|
+ var view = View.FindDeepestView (this, me.X + locationOffset.X, me.Y + locationOffset.Y, out int rx, out int ry);
|
|
if (view == this) {
|
|
if (view == this) {
|
|
|
|
+ if (!Visible) {
|
|
|
|
+ throw new InvalidOperationException ("This shouldn't running on a invisible menu!");
|
|
|
|
+ }
|
|
|
|
+
|
|
var nme = new MouseEvent () {
|
|
var nme = new MouseEvent () {
|
|
X = rx,
|
|
X = rx,
|
|
Y = ry,
|
|
Y = ry,
|
|
@@ -540,8 +571,8 @@ namespace Terminal.Gui {
|
|
if (barItems.Children == null) {
|
|
if (barItems.Children == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- var savedClip = Application.Driver.Clip;
|
|
|
|
- Application.Driver.Clip = Application.Top.Frame;
|
|
|
|
|
|
+ var savedClip = Driver.Clip;
|
|
|
|
+ Driver.Clip = new Rect (0, 0, Driver.Cols, Driver.Rows);
|
|
|
|
|
|
Driver.SetAttribute (GetNormalColor ());
|
|
Driver.SetAttribute (GetNormalColor ());
|
|
|
|
|
|
@@ -549,8 +580,12 @@ namespace Terminal.Gui {
|
|
OnRenderLineCanvas ();
|
|
OnRenderLineCanvas ();
|
|
|
|
|
|
for (int i = Bounds.Y; i < barItems.Children.Length; i++) {
|
|
for (int i = Bounds.Y; i < barItems.Children.Length; i++) {
|
|
- if (i < 0)
|
|
|
|
|
|
+ if (i < 0) {
|
|
continue;
|
|
continue;
|
|
|
|
+ }
|
|
|
|
+ if (ViewToScreen (Bounds).Y + i >= Driver.Rows) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
var item = barItems.Children [i];
|
|
var item = barItems.Children [i];
|
|
Driver.SetAttribute (item == null ? GetNormalColor ()
|
|
Driver.SetAttribute (item == null ? GetNormalColor ()
|
|
: i == current ? ColorScheme.Focus : GetNormalColor ());
|
|
: i == current ? ColorScheme.Focus : GetNormalColor ());
|
|
@@ -563,8 +598,12 @@ namespace Terminal.Gui {
|
|
|
|
|
|
Driver.SetAttribute (DetermineColorSchemeFor (item, i));
|
|
Driver.SetAttribute (DetermineColorSchemeFor (item, i));
|
|
for (int p = Bounds.X; p < Frame.Width - 2; p++) { // This - 2 is for the border
|
|
for (int p = Bounds.X; p < Frame.Width - 2; p++) { // This - 2 is for the border
|
|
- if (p < 0)
|
|
|
|
|
|
+ if (p < 0) {
|
|
continue;
|
|
continue;
|
|
|
|
+ }
|
|
|
|
+ if (ViewToScreen (Bounds).X + p >= Driver.Cols) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
if (item == null)
|
|
if (item == null)
|
|
Driver.AddRune (Driver.HLine);
|
|
Driver.AddRune (Driver.HLine);
|
|
else if (i == 0 && p == 0 && host.UseSubMenusSingleFrame && item.Parent.Parent != null)
|
|
else if (i == 0 && p == 0 && host.UseSubMenusSingleFrame && item.Parent.Parent != null)
|
|
@@ -605,9 +644,9 @@ namespace Terminal.Gui {
|
|
textToDraw = item.Title;
|
|
textToDraw = item.Title;
|
|
}
|
|
}
|
|
|
|
|
|
- ViewToScreen (0, i, out int vtsCol, out _, false);
|
|
|
|
|
|
+ ViewToScreen (0, i, out int vtsCol, out int vtsRow, false);
|
|
if (vtsCol < Driver.Cols) {
|
|
if (vtsCol < Driver.Cols) {
|
|
- Move (1, i);
|
|
|
|
|
|
+ Driver.Move (vtsCol + 1, vtsRow);
|
|
if (!item.IsEnabled ()) {
|
|
if (!item.IsEnabled ()) {
|
|
DrawHotString (textToDraw, ColorScheme.Disabled, ColorScheme.Disabled);
|
|
DrawHotString (textToDraw, ColorScheme.Disabled, ColorScheme.Disabled);
|
|
} else if (i == 0 && host.UseSubMenusSingleFrame && item.Parent.Parent != null) {
|
|
} else if (i == 0 && host.UseSubMenusSingleFrame && item.Parent.Parent != null) {
|
|
@@ -630,15 +669,14 @@ namespace Terminal.Gui {
|
|
// The help string
|
|
// The help string
|
|
var l = item.ShortcutTag.ConsoleWidth == 0 ? item.Help.ConsoleWidth : item.Help.ConsoleWidth + item.ShortcutTag.ConsoleWidth + 2;
|
|
var l = item.ShortcutTag.ConsoleWidth == 0 ? item.Help.ConsoleWidth : item.Help.ConsoleWidth + item.ShortcutTag.ConsoleWidth + 2;
|
|
var col = Frame.Width - l - 3;
|
|
var col = Frame.Width - l - 3;
|
|
- ViewToScreen (col, i, out vtsCol, out _, false);
|
|
|
|
|
|
+ ViewToScreen (col, i, out vtsCol, out vtsRow, false);
|
|
if (vtsCol < Driver.Cols) {
|
|
if (vtsCol < Driver.Cols) {
|
|
- Move (col, i);
|
|
|
|
|
|
+ Driver.Move (vtsCol, vtsRow);
|
|
Driver.AddStr (item.Help);
|
|
Driver.AddStr (item.Help);
|
|
|
|
|
|
// The shortcut tag string
|
|
// The shortcut tag string
|
|
if (!item.ShortcutTag.IsEmpty) {
|
|
if (!item.ShortcutTag.IsEmpty) {
|
|
- l = item.ShortcutTag.ConsoleWidth;
|
|
|
|
- Move (Frame.Width - l - 3, i);
|
|
|
|
|
|
+ Driver.Move (vtsCol + l - item.ShortcutTag.ConsoleWidth, vtsRow);
|
|
Driver.AddStr (item.ShortcutTag);
|
|
Driver.AddStr (item.ShortcutTag);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -651,7 +689,9 @@ namespace Terminal.Gui {
|
|
|
|
|
|
private void Current_DrawContentComplete (object sender, DrawEventArgs e)
|
|
private void Current_DrawContentComplete (object sender, DrawEventArgs e)
|
|
{
|
|
{
|
|
- OnDrawContent (Bounds);
|
|
|
|
|
|
+ if (Visible) {
|
|
|
|
+ OnDrawContent (Bounds);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public override void PositionCursor ()
|
|
public override void PositionCursor ()
|
|
@@ -858,12 +898,11 @@ namespace Terminal.Gui {
|
|
}
|
|
}
|
|
host.handled = false;
|
|
host.handled = false;
|
|
bool disabled;
|
|
bool disabled;
|
|
- var meYOffset = BorderStyle != LineStyle.None ? 1 : 0;
|
|
|
|
|
|
+ var meY = me.Y - (Border == null ? 0 : Border.Thickness.Top);
|
|
if (me.Flags == MouseFlags.Button1Clicked) {
|
|
if (me.Flags == MouseFlags.Button1Clicked) {
|
|
disabled = false;
|
|
disabled = false;
|
|
- if (me.Y < meYOffset)
|
|
|
|
|
|
+ if (meY < 0)
|
|
return true;
|
|
return true;
|
|
- var meY = me.Y - meYOffset;
|
|
|
|
if (meY >= barItems.Children.Length)
|
|
if (meY >= barItems.Children.Length)
|
|
return true;
|
|
return true;
|
|
var item = barItems.Children [meY];
|
|
var item = barItems.Children [meY];
|
|
@@ -878,14 +917,14 @@ namespace Terminal.Gui {
|
|
me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) {
|
|
me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) {
|
|
|
|
|
|
disabled = false;
|
|
disabled = false;
|
|
- if (me.Y < meYOffset || me.Y - meYOffset >= barItems.Children.Length) {
|
|
|
|
|
|
+ if (meY < 0 || meY >= barItems.Children.Length) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- var item = barItems.Children [me.Y - meYOffset];
|
|
|
|
|
|
+ var item = barItems.Children [meY];
|
|
if (item == null) return true;
|
|
if (item == null) return true;
|
|
if (item == null || !item.IsEnabled ()) disabled = true;
|
|
if (item == null || !item.IsEnabled ()) disabled = true;
|
|
if (item != null && !disabled)
|
|
if (item != null && !disabled)
|
|
- current = me.Y - meYOffset;
|
|
|
|
|
|
+ current = meY;
|
|
if (host.UseSubMenusSingleFrame || !CheckSubMenu ()) {
|
|
if (host.UseSubMenusSingleFrame || !CheckSubMenu ()) {
|
|
SetNeedsDisplay ();
|
|
SetNeedsDisplay ();
|
|
SetParentSetNeedsDisplay ();
|
|
SetParentSetNeedsDisplay ();
|
|
@@ -950,6 +989,7 @@ namespace Terminal.Gui {
|
|
{
|
|
{
|
|
if (Application.Current != null) {
|
|
if (Application.Current != null) {
|
|
Application.Current.DrawContentComplete -= Current_DrawContentComplete;
|
|
Application.Current.DrawContentComplete -= Current_DrawContentComplete;
|
|
|
|
+ Application.Current.TerminalResized -= Current_TerminalResized;
|
|
}
|
|
}
|
|
Application.RootMouseEvent -= Application_RootMouseEvent;
|
|
Application.RootMouseEvent -= Application_RootMouseEvent;
|
|
base.Dispose (disposing);
|
|
base.Dispose (disposing);
|
|
@@ -1284,7 +1324,7 @@ namespace Terminal.Gui {
|
|
set {
|
|
set {
|
|
if (ocm != value) {
|
|
if (ocm != value) {
|
|
ocm = value;
|
|
ocm = value;
|
|
- if (ocm.current > -1) {
|
|
|
|
|
|
+ if (ocm != null && ocm.current > -1) {
|
|
OnMenuOpened ();
|
|
OnMenuOpened ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1381,7 +1421,7 @@ namespace Terminal.Gui {
|
|
if (openSubMenu != null && !CloseMenu (false, true))
|
|
if (openSubMenu != null && !CloseMenu (false, true))
|
|
return;
|
|
return;
|
|
if (openMenu != null) {
|
|
if (openMenu != null) {
|
|
- Application.Top.Remove (openMenu);
|
|
|
|
|
|
+ Application.Current.Remove (openMenu);
|
|
openMenu.Dispose ();
|
|
openMenu.Dispose ();
|
|
openMenu = null;
|
|
openMenu = null;
|
|
}
|
|
}
|
|
@@ -1390,18 +1430,21 @@ namespace Terminal.Gui {
|
|
// text belonging to the menu
|
|
// text belonging to the menu
|
|
for (int i = 0; i < index; i++)
|
|
for (int i = 0; i < index; i++)
|
|
pos += Menus [i].TitleLength + (Menus [i].Help.ConsoleWidth > 0 ? Menus [i].Help.ConsoleWidth + 2 : 0) + leftPadding + rightPadding;
|
|
pos += Menus [i].TitleLength + (Menus [i].Help.ConsoleWidth > 0 ? Menus [i].Help.ConsoleWidth + 2 : 0) + leftPadding + rightPadding;
|
|
- var superView = SuperView == null ? Application.Top : SuperView;
|
|
|
|
- Point locationOffset;
|
|
|
|
- if (superView.BorderStyle != LineStyle.None) {
|
|
|
|
- locationOffset = new Point (superView.Frame.X + 1, superView.Frame.Y + 1);
|
|
|
|
- } else {
|
|
|
|
- locationOffset = new Point (superView.Frame.X, superView.Frame.Y);
|
|
|
|
|
|
+
|
|
|
|
+ var locationOffset = Point.Empty;
|
|
|
|
+ // if SuperView is null then it's from a ContextMenu
|
|
|
|
+ if (SuperView == null) {
|
|
|
|
+ locationOffset = GetScreenOffset ();
|
|
|
|
+ }
|
|
|
|
+ if (SuperView != null && SuperView != Application.Current) {
|
|
|
|
+ locationOffset.X += SuperView.Border.Thickness.Left;
|
|
|
|
+ locationOffset.Y += SuperView.Border.Thickness.Top;
|
|
}
|
|
}
|
|
openMenu = new Menu (this, Frame.X + pos + locationOffset.X, Frame.Y + 1 + locationOffset.Y, Menus [index], null, MenusBorderStyle);
|
|
openMenu = new Menu (this, Frame.X + pos + locationOffset.X, Frame.Y + 1 + locationOffset.Y, Menus [index], null, MenusBorderStyle);
|
|
openCurrentMenu = openMenu;
|
|
openCurrentMenu = openMenu;
|
|
openCurrentMenu.previousSubFocused = openMenu;
|
|
openCurrentMenu.previousSubFocused = openMenu;
|
|
|
|
|
|
- Application.Top.Add (openMenu);
|
|
|
|
|
|
+ Application.Current.Add (openMenu);
|
|
openMenu.SetFocus ();
|
|
openMenu.SetFocus ();
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
@@ -1417,21 +1460,21 @@ namespace Terminal.Gui {
|
|
openCurrentMenu = new Menu (this, last.Frame.Left + last.Frame.Width + locationOffset.X, last.Frame.Top + locationOffset.Y + last.current, subMenu, last, MenusBorderStyle);
|
|
openCurrentMenu = new Menu (this, last.Frame.Left + last.Frame.Width + locationOffset.X, last.Frame.Top + locationOffset.Y + last.current, subMenu, last, MenusBorderStyle);
|
|
} else {
|
|
} else {
|
|
var first = openSubMenu.Count > 0 ? openSubMenu.First () : openMenu;
|
|
var first = openSubMenu.Count > 0 ? openSubMenu.First () : openMenu;
|
|
|
|
+ // 2 is for the parent and the separator
|
|
var mbi = new MenuItem [2 + subMenu.Children.Length];
|
|
var mbi = new MenuItem [2 + subMenu.Children.Length];
|
|
mbi [0] = new MenuItem () { Title = subMenu.Title, Parent = subMenu };
|
|
mbi [0] = new MenuItem () { Title = subMenu.Title, Parent = subMenu };
|
|
mbi [1] = null;
|
|
mbi [1] = null;
|
|
for (int j = 0; j < subMenu.Children.Length; j++) {
|
|
for (int j = 0; j < subMenu.Children.Length; j++) {
|
|
mbi [j + 2] = subMenu.Children [j];
|
|
mbi [j + 2] = subMenu.Children [j];
|
|
}
|
|
}
|
|
- var newSubMenu = new MenuBarItem (mbi);
|
|
|
|
- ViewToScreen (first.Frame.Left, first.Frame.Top, out int rx, out int ry);
|
|
|
|
- openCurrentMenu = new Menu (this, rx, ry, newSubMenu, null, MenusBorderStyle);
|
|
|
|
|
|
+ var newSubMenu = new MenuBarItem (mbi) { Parent = subMenu };
|
|
|
|
+ openCurrentMenu = new Menu (this, first.Frame.Left, first.Frame.Top, newSubMenu, null, MenusBorderStyle);
|
|
last.Visible = false;
|
|
last.Visible = false;
|
|
Application.GrabMouse (openCurrentMenu);
|
|
Application.GrabMouse (openCurrentMenu);
|
|
}
|
|
}
|
|
openCurrentMenu.previousSubFocused = last.previousSubFocused;
|
|
openCurrentMenu.previousSubFocused = last.previousSubFocused;
|
|
openSubMenu.Add (openCurrentMenu);
|
|
openSubMenu.Add (openCurrentMenu);
|
|
- Application.Top.Add (openCurrentMenu);
|
|
|
|
|
|
+ Application.Current.Add (openCurrentMenu);
|
|
}
|
|
}
|
|
selectedSub = openSubMenu.Count - 1;
|
|
selectedSub = openSubMenu.Count - 1;
|
|
if (selectedSub > -1 && SelectEnabledItem (openCurrentMenu.barItems.Children, openCurrentMenu.current, out openCurrentMenu.current)) {
|
|
if (selectedSub > -1 && SelectEnabledItem (openCurrentMenu.barItems.Children, openCurrentMenu.current, out openCurrentMenu.current)) {
|
|
@@ -1562,7 +1605,7 @@ namespace Terminal.Gui {
|
|
switch (isSubMenu) {
|
|
switch (isSubMenu) {
|
|
case false:
|
|
case false:
|
|
if (openMenu != null) {
|
|
if (openMenu != null) {
|
|
- Application.Top.Remove (openMenu);
|
|
|
|
|
|
+ Application.Current.Remove (openMenu);
|
|
}
|
|
}
|
|
SetNeedsDisplay ();
|
|
SetNeedsDisplay ();
|
|
if (previousFocused != null && previousFocused is Menu && openMenu != null && previousFocused.ToString () != openCurrentMenu.ToString ())
|
|
if (previousFocused != null && previousFocused is Menu && openMenu != null && previousFocused.ToString () != openCurrentMenu.ToString ())
|
|
@@ -1578,6 +1621,14 @@ namespace Terminal.Gui {
|
|
if (!reopen) {
|
|
if (!reopen) {
|
|
selected = -1;
|
|
selected = -1;
|
|
}
|
|
}
|
|
|
|
+ if (openSubMenu != null) {
|
|
|
|
+ openSubMenu = null;
|
|
|
|
+ }
|
|
|
|
+ if (openCurrentMenu != null) {
|
|
|
|
+ Application.Current.Remove (openCurrentMenu);
|
|
|
|
+ openCurrentMenu.Dispose ();
|
|
|
|
+ openCurrentMenu = null;
|
|
|
|
+ }
|
|
LastFocused.SetFocus ();
|
|
LastFocused.SetFocus ();
|
|
} else if (openSubMenu == null || openSubMenu.Count == 0) {
|
|
} else if (openSubMenu == null || openSubMenu.Count == 0) {
|
|
CloseAllMenus ();
|
|
CloseAllMenus ();
|
|
@@ -1621,7 +1672,7 @@ namespace Terminal.Gui {
|
|
openCurrentMenu.SetFocus ();
|
|
openCurrentMenu.SetFocus ();
|
|
if (openSubMenu != null) {
|
|
if (openSubMenu != null) {
|
|
menu = openSubMenu [i];
|
|
menu = openSubMenu [i];
|
|
- Application.Top.Remove (menu);
|
|
|
|
|
|
+ Application.Current.Remove (menu);
|
|
openSubMenu.Remove (menu);
|
|
openSubMenu.Remove (menu);
|
|
menu.Dispose ();
|
|
menu.Dispose ();
|
|
}
|
|
}
|
|
@@ -1637,7 +1688,7 @@ namespace Terminal.Gui {
|
|
{
|
|
{
|
|
if (openSubMenu != null) {
|
|
if (openSubMenu != null) {
|
|
foreach (var item in openSubMenu) {
|
|
foreach (var item in openSubMenu) {
|
|
- Application.Top.Remove (item);
|
|
|
|
|
|
+ Application.Current.Remove (item);
|
|
item.Dispose ();
|
|
item.Dispose ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1646,7 +1697,7 @@ namespace Terminal.Gui {
|
|
internal void CloseAllMenus ()
|
|
internal void CloseAllMenus ()
|
|
{
|
|
{
|
|
if (!isMenuOpening && !isMenuClosing) {
|
|
if (!isMenuOpening && !isMenuClosing) {
|
|
- if (openSubMenu != null && !CloseMenu (false, true))
|
|
|
|
|
|
+ if (openSubMenu != null && !CloseMenu (false, true, true))
|
|
return;
|
|
return;
|
|
if (!CloseMenu (false))
|
|
if (!CloseMenu (false))
|
|
return;
|
|
return;
|
|
@@ -1923,7 +1974,12 @@ namespace Terminal.Gui {
|
|
(me.Flags == MouseFlags.ReportMousePosition && selected > -1) ||
|
|
(me.Flags == MouseFlags.ReportMousePosition && selected > -1) ||
|
|
(me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition) && selected > -1)) {
|
|
(me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition) && selected > -1)) {
|
|
int pos = xOrigin;
|
|
int pos = xOrigin;
|
|
- int cx = me.X;
|
|
|
|
|
|
+ Point locationOffset = default;
|
|
|
|
+ if (SuperView != null) {
|
|
|
|
+ locationOffset.X += SuperView.Border.Thickness.Left;
|
|
|
|
+ locationOffset.Y += SuperView.Border.Thickness.Top;
|
|
|
|
+ }
|
|
|
|
+ int cx = me.X - locationOffset.X;
|
|
for (int i = 0; i < Menus.Length; i++) {
|
|
for (int i = 0; i < Menus.Length; i++) {
|
|
if (cx >= pos && cx < pos + leftPadding + Menus [i].TitleLength + Menus [i].Help.ConsoleWidth + rightPadding) {
|
|
if (cx >= pos && cx < pos + leftPadding + Menus [i].TitleLength + Menus [i].Help.ConsoleWidth + rightPadding) {
|
|
if (me.Flags == MouseFlags.Button1Clicked) {
|
|
if (me.Flags == MouseFlags.Button1Clicked) {
|
|
@@ -1949,11 +2005,19 @@ namespace Terminal.Gui {
|
|
}
|
|
}
|
|
Activate (i);
|
|
Activate (i);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- if (IsMenuOpen)
|
|
|
|
|
|
+ } else if (IsMenuOpen) {
|
|
|
|
+ if (!UseSubMenusSingleFrame || (UseSubMenusSingleFrame && openCurrentMenu != null
|
|
|
|
+ && openCurrentMenu.barItems.Parent != null && openCurrentMenu.barItems.Parent.Parent != Menus [i])) {
|
|
|
|
+
|
|
Activate (i);
|
|
Activate (i);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
|
|
+ } else if (i == Menus.Length - 1 && me.Flags == MouseFlags.Button1Clicked) {
|
|
|
|
+ if (IsMenuOpen && !Menus [i].IsTopLevel) {
|
|
|
|
+ CloseAllMenus ();
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
pos += leftPadding + Menus [i].TitleLength + rightPadding;
|
|
pos += leftPadding + Menus [i].TitleLength + rightPadding;
|
|
}
|
|
}
|
|
@@ -2065,5 +2129,31 @@ namespace Terminal.Gui {
|
|
|
|
|
|
return base.OnEnter (view);
|
|
return base.OnEnter (view);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets the superview location offset relative to the <see cref="ConsoleDriver"/> location.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns>The location offset.</returns>
|
|
|
|
+ internal Point GetScreenOffset ()
|
|
|
|
+ {
|
|
|
|
+ var superViewFrame = SuperView == null ? new Rect (0, 0, Driver.Cols, Driver.Rows) : SuperView.Frame;
|
|
|
|
+ var sv = SuperView == null ? Application.Current : SuperView;
|
|
|
|
+ var boundsOffset = sv.GetBoundsOffset ();
|
|
|
|
+ return new Point (superViewFrame.X - sv.Frame.X - boundsOffset.X,
|
|
|
|
+ superViewFrame.Y - sv.Frame.Y - boundsOffset.Y);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets the <see cref="Application.Current"/> location offset relative to the <see cref="ConsoleDriver"/> location.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns>The location offset.</returns>
|
|
|
|
+ internal Point GetScreenOffsetFromCurrent ()
|
|
|
|
+ {
|
|
|
|
+ var screen = new Rect (0, 0, Driver.Cols, Driver.Rows);
|
|
|
|
+ var currentFrame = Application.Current.Frame;
|
|
|
|
+ var boundsOffset = Application.Top.GetBoundsOffset ();
|
|
|
|
+ return new Point (screen.X - currentFrame.X - boundsOffset.X
|
|
|
|
+ , screen.Y - currentFrame.Y - boundsOffset.Y);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|