Browse Source

set menu on per window basis.

pull/2978/head
Dan Walmsley 7 years ago
parent
commit
448b549034
  1. 2
      native/Avalonia.Native/inc/avalonia-native.h
  2. 17
      src/Avalonia.Native/AvaloniaNativeMenuExporter.cs
  3. 2
      src/Avalonia.Native/WindowImpl.cs

2
native/Avalonia.Native/inc/avalonia-native.h

@ -208,7 +208,7 @@ AVNCOM(IAvnWindowBase, 02) : IUnknown
virtual HRESULT CreateGlRenderTarget(IAvnGlSurfaceRenderTarget** ret) = 0; virtual HRESULT CreateGlRenderTarget(IAvnGlSurfaceRenderTarget** ret) = 0;
virtual HRESULT GetSoftwareFramebuffer(AvnFramebuffer*ret) = 0; virtual HRESULT GetSoftwareFramebuffer(AvnFramebuffer*ret) = 0;
virtual HRESULT SetMainMenu(IAvnAppMenu* menu) = 0; virtual HRESULT SetMainMenu(IAvnAppMenu* menu) = 0;
virtual HRESULT GetMainMenu(IAvnAppMenu** ret) = 0; virtual HRESULT ObtainMainMenu(IAvnAppMenu** retOut) = 0;
virtual bool TryLock() = 0; virtual bool TryLock() = 0;
virtual void Unlock() = 0; virtual void Unlock() = 0;
}; };

17
src/Avalonia.Native/AvaloniaNativeMenuExporter.cs

@ -49,10 +49,12 @@ namespace Avalonia.Native
private Dictionary<NativeMenuItem, int> _itemsToIds = new Dictionary<NativeMenuItem, int>(); private Dictionary<NativeMenuItem, int> _itemsToIds = new Dictionary<NativeMenuItem, int>();
private uint _revision = 1; private uint _revision = 1;
private bool _exported = false; private bool _exported = false;
private IAvnWindow _nativeWindow;
public AvaloniaNativeMenuExporter(IAvaloniaNativeFactory factory) public AvaloniaNativeMenuExporter(IAvnWindow nativeWindow, IAvaloniaNativeFactory factory)
{ {
_factory = factory; _factory = factory;
_nativeWindow = nativeWindow;
} }
public bool IsNativeMenuExported => _exported; public bool IsNativeMenuExported => _exported;
@ -113,8 +115,7 @@ namespace Avalonia.Native
LayoutUpdated?.Invoke((_revision, 0)); LayoutUpdated?.Invoke((_revision, 0));
SetMenu(_menu.Items); SetMenu(_nativeWindow, _menu.Items);
_exported = true; _exported = true;
} }
@ -231,8 +232,14 @@ namespace Avalonia.Native
private void SetMenu(IAvnWindow avnWindow, ICollection<NativeMenuItem> menuItems) private void SetMenu(IAvnWindow avnWindow, ICollection<NativeMenuItem> menuItems)
{ {
var appMenu = avnWindow.ObtainMainMenu();
var appMenu = _factory.ObtainAppMenu();
if(appMenu is null)
{
appMenu = _factory.CreateMenu();
avnWindow.SetMainMenu(appMenu);
}
appMenu.Clear(); appMenu.Clear();

2
src/Avalonia.Native/WindowImpl.cs

@ -24,7 +24,7 @@ namespace Avalonia.Native
Init(_native = factory.CreateWindow(e), factory.CreateScreens()); Init(_native = factory.CreateWindow(e), factory.CreateScreens());
} }
NativeMenuExporter = new AvaloniaNativeMenuExporter(factory); NativeMenuExporter = new AvaloniaNativeMenuExporter(_native, factory);
} }
class WindowEvents : WindowBaseEvents, IAvnWindowEvents class WindowEvents : WindowBaseEvents, IAvnWindowEvents

Loading…
Cancel
Save