@@ -73,7 +73,7 @@ public MenuBar ()
73
73
Y = 0 ;
74
74
Width = Dim . Fill ( ) ;
75
75
Height = 1 ; // BUGBUG: Views should avoid setting Height as doing so implies Frame.Size == GetContentSize ().
76
- Menus = new MenuBarItem [ ] { } ;
76
+ Menus = [ ] ;
77
77
78
78
//CanFocus = true;
79
79
_selected = - 1 ;
@@ -111,9 +111,14 @@ public MenuBar ()
111
111
Command . Cancel ,
112
112
( ) =>
113
113
{
114
- CloseMenuBar ( ) ;
114
+ if ( IsMenuOpen )
115
+ {
116
+ CloseMenuBar ( ) ;
115
117
116
- return true ;
118
+ return true ;
119
+ }
120
+
121
+ return false ;
117
122
}
118
123
) ;
119
124
@@ -556,10 +561,10 @@ internal void CloseAllMenus ()
556
561
557
562
private void CloseOtherOpenedMenuBar ( )
558
563
{
559
- if ( Application . Top is { } )
564
+ if ( SuperView is { } )
560
565
{
561
566
// Close others menu bar opened
562
- Menu ? menu = Application . Top . SubViews . FirstOrDefault ( v => v is Menu m && m . Host != this && m . Host . IsMenuOpen ) as Menu ;
567
+ Menu ? menu = SuperView . SubViews . FirstOrDefault ( v => v is Menu m && m . Host != this && m . Host . IsMenuOpen ) as Menu ;
563
568
menu ? . Host . CleanUp ( ) ;
564
569
}
565
570
}
@@ -595,7 +600,7 @@ internal bool CloseMenu (bool reopen, bool isSubMenu, bool ignoreUseSubMenusSing
595
600
case false :
596
601
if ( _openMenu is { } )
597
602
{
598
- Application . Top ? . Remove ( _openMenu ) ;
603
+ SuperView ? . Remove ( _openMenu ) ;
599
604
}
600
605
601
606
SetNeedsDraw ( ) ;
@@ -634,7 +639,7 @@ internal bool CloseMenu (bool reopen, bool isSubMenu, bool ignoreUseSubMenusSing
634
639
635
640
if ( OpenCurrentMenu is { } )
636
641
{
637
- Application . Top ? . Remove ( OpenCurrentMenu ) ;
642
+ SuperView ? . Remove ( OpenCurrentMenu ) ;
638
643
if ( Application . MouseGrabView == OpenCurrentMenu )
639
644
{
640
645
Application . UngrabMouse ( ) ;
@@ -822,7 +827,7 @@ internal void OpenMenu (int index, int sIndex = -1, MenuBarItem? subMenu = null!
822
827
823
828
if ( _openMenu is { } )
824
829
{
825
- Application . Top ? . Remove ( _openMenu ) ;
830
+ SuperView ? . Remove ( _openMenu ) ;
826
831
if ( Application . MouseGrabView == _openMenu )
827
832
{
828
833
Application . UngrabMouse ( ) ;
@@ -838,34 +843,23 @@ internal void OpenMenu (int index, int sIndex = -1, MenuBarItem? subMenu = null!
838
843
pos += Menus [ i ] . TitleLength + ( Menus [ i ] . Help . GetColumns ( ) > 0 ? Menus [ i ] . Help . GetColumns ( ) + 2 : 0 ) + _leftPadding + _rightPadding ;
839
844
}
840
845
841
- var locationOffset = Point . Empty ;
842
846
843
- // if SuperView is null then it's from a ContextMenu
844
- if ( SuperView is null )
845
- {
846
- locationOffset = GetScreenOffset ( ) ;
847
- }
848
847
849
- if ( SuperView is { } && SuperView != Application . Top )
850
- {
851
- locationOffset . X += SuperView . Border . Thickness . Left ;
852
- locationOffset . Y += SuperView . Border . Thickness . Top ;
853
- }
854
848
855
849
_openMenu = new ( )
856
850
{
857
851
Host = this ,
858
- X = Frame . X + pos + locationOffset . X ,
859
- Y = Frame . Y + 1 + locationOffset . Y ,
852
+ X = Frame . X + pos ,
853
+ Y = Frame . Y + 1 ,
860
854
BarItems = Menus [ index ] ,
861
855
Parent = null
862
856
} ;
863
857
OpenCurrentMenu = _openMenu ;
864
858
OpenCurrentMenu . _previousSubFocused = _openMenu ;
865
859
866
- if ( Application . Top is { } )
860
+ if ( SuperView is { } )
867
861
{
868
- Application . Top . Add ( _openMenu ) ;
862
+ SuperView . Add ( _openMenu ) ;
869
863
// _openMenu.SetRelativeLayout (Application.Screen.Size);
870
864
}
871
865
else
@@ -894,13 +888,11 @@ internal void OpenMenu (int index, int sIndex = -1, MenuBarItem? subMenu = null!
894
888
895
889
if ( ! UseSubMenusSingleFrame )
896
890
{
897
- locationOffset = GetLocationOffset ( ) ;
898
-
899
891
OpenCurrentMenu = new ( )
900
892
{
901
893
Host = this ,
902
- X = last ! . Frame . Left + last . Frame . Width + locationOffset . X ,
903
- Y = last . Frame . Top + locationOffset . Y + last . _currentChild ,
894
+ X = last ! . Frame . Left + last . Frame . Width ,
895
+ Y = last . Frame . Top + last . _currentChild + 1 ,
904
896
BarItems = subMenu ,
905
897
Parent = last
906
898
} ;
@@ -931,7 +923,7 @@ internal void OpenMenu (int index, int sIndex = -1, MenuBarItem? subMenu = null!
931
923
932
924
OpenCurrentMenu . _previousSubFocused = last . _previousSubFocused ;
933
925
_openSubMenu . Add ( OpenCurrentMenu ) ;
934
- Application . Top ? . Add ( OpenCurrentMenu ) ;
926
+ SuperView ? . Add ( OpenCurrentMenu ) ;
935
927
936
928
if ( ! OpenCurrentMenu . IsInitialized )
937
929
{
@@ -1014,7 +1006,7 @@ internal void RemoveAllOpensSubMenus ()
1014
1006
{
1015
1007
foreach ( Menu item in _openSubMenu )
1016
1008
{
1017
- Application . Top ! . Remove ( item ) ;
1009
+ SuperView ? . Remove ( item ) ;
1018
1010
if ( Application . MouseGrabView == item )
1019
1011
{
1020
1012
Application . UngrabMouse ( ) ;
@@ -1263,7 +1255,7 @@ private void RemoveSubMenu (int index, bool ignoreUseSubMenusSingleFrame = false
1263
1255
if ( _openSubMenu is { } )
1264
1256
{
1265
1257
menu = _openSubMenu [ i ] ;
1266
- Application . Top ! . Remove ( menu ) ;
1258
+ SuperView ! . Remove ( menu ) ;
1267
1259
_openSubMenu . Remove ( menu ) ;
1268
1260
1269
1261
if ( Application . MouseGrabView == menu )
@@ -1544,8 +1536,14 @@ internal bool HandleGrabView (MouseEventArgs me, View current)
1544
1536
1545
1537
if ( me . View != current )
1546
1538
{
1539
+ View v = current ;
1547
1540
Application . UngrabMouse ( ) ;
1548
- View v = me . View ;
1541
+
1542
+ if ( ( ( Menu ) me . View ) . Host . SuperView is { } && ( ( Menu ) me . View ) . Host . SuperView ! . InternalSubViews . Contains ( me . View ) )
1543
+ {
1544
+ v = me . View ;
1545
+ }
1546
+
1549
1547
Application . GrabMouse ( v ) ;
1550
1548
MouseEventArgs nme ;
1551
1549
0 commit comments