Skip to content

Commit

Permalink
Merge branch 'master' into feature/window-integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys authored Jun 20, 2022
2 parents 76e98ca + 99b4530 commit 60ecdcc
Show file tree
Hide file tree
Showing 158 changed files with 2,330 additions and 2,397 deletions.
1,490 changes: 13 additions & 1,477 deletions Avalonia.sln

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion build/CoreLibraries.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup/Avalonia.Markup.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.MicroCom/Avalonia.MicroCom.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)/../src/Avalonia.PlatformSupport/Avalonia.PlatformSupport.csproj" />
</ItemGroup>
</Project>
7 changes: 6 additions & 1 deletion native/Avalonia.Native/src/OSX/AvnView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,12 @@ - (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type

if(_parent != nullptr)
{
_lastKeyHandled = _parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key);
auto handled = _parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key);
if (key != LeftCtrl && key != RightCtrl) {
_lastKeyHandled = handled;
} else {
_lastKeyHandled = false;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions native/Avalonia.Native/src/OSX/AvnWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ -(void)becomeKeyWindow
- (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification
{
_parent->BringToFront();

dispatch_async(dispatch_get_main_queue(), ^{
@try {
[self invalidateShadow];
}
@finally{
}
});
}

- (void)windowDidMiniaturize:(NSNotification *_Nonnull)notification
Expand Down
1 change: 0 additions & 1 deletion native/Avalonia.Native/src/OSX/WindowBaseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ BEGIN_INTERFACE_MAP()
private:
void CreateNSWindow (bool isDialog);
void CleanNSWindow ();
void InitialiseNSWindow ();

NSCursor *cursor;
ComPtr<IAvnGlContext> _glContext;
Expand Down
58 changes: 23 additions & 35 deletions native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@
lastMenu = nullptr;

CreateNSWindow(usePanel);
InitialiseNSWindow();

[Window setContentView:StandardContainer];
[Window setStyleMask:NSWindowStyleMaskBorderless];
[Window setBackingType:NSBackingStoreBuffered];

[Window setContentMinSize:lastMinSize];
[Window setContentMaxSize:lastMaxSize];

[Window setOpaque:false];
[Window setHasShadow:true];
}

HRESULT WindowBaseImpl::ObtainNSViewHandle(void **ret) {
Expand Down Expand Up @@ -90,6 +99,8 @@
START_COM_CALL;

@autoreleasepool {
[Window setContentSize:lastSize];

if(hasPosition)
{
SetPosition(lastPositionSet);
Expand All @@ -99,6 +110,8 @@
}

UpdateStyle();

[Window invalidateShadow];

if (ShouldTakeFocusOnShow() && activate) {
[Window orderFront:Window];
Expand Down Expand Up @@ -285,15 +298,15 @@
}

@try {
lastSize = NSSize {x, y};

if (!_shown) {
BaseEvents->Resized(AvnSize{x, y}, reason);
}

if(Window != nullptr) {
[Window setContentSize:lastSize];
[Window invalidateShadow];
if(x != lastSize.width || y != lastSize.height) {
lastSize = NSSize{x, y};

if (!_shown) {
BaseEvents->Resized(AvnSize{x, y}, reason);
} else if (Window != nullptr) {
[Window setContentSize:lastSize];
[Window invalidateShadow];
}
}
}
@finally {
Expand Down Expand Up @@ -567,31 +580,6 @@
}
}

void WindowBaseImpl::InitialiseNSWindow() {
if(Window != nullptr) {
[Window setContentView:StandardContainer];
[Window setStyleMask:NSWindowStyleMaskBorderless];
[Window setBackingType:NSBackingStoreBuffered];

[Window setContentSize:lastSize];
[Window setContentMinSize:lastMinSize];
[Window setContentMaxSize:lastMaxSize];

[Window setOpaque:false];

[Window setHasShadow:true];
[Window invalidateShadow];

if (lastMenu != nullptr) {
[GetWindowProtocol() applyMenu:lastMenu];

if ([Window isKeyWindow]) {
[GetWindowProtocol() showWindowMenuWithAppMenu];
}
}
}
}

id <AvnWindowProtocol> WindowBaseImpl::GetWindowProtocol() {
if(Window == nullptr)
{
Expand Down
5 changes: 0 additions & 5 deletions native/Avalonia.Native/src/OSX/WindowImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
[GetWindowProtocol() setIsExtended:true];
SetExtendClientArea(true);
}

if(_parent != nullptr)
{
SetParent(_parent);
}
}

HRESULT WindowImpl::Show(bool activate, bool isDialog) {
Expand Down
11 changes: 11 additions & 0 deletions native/Avalonia.Native/src/OSX/app.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ - (void)sendEvent:(NSEvent *)event
_isHandlingSendEvent = oldHandling;
}
}

// This is needed for certain embedded controls DO NOT REMOVE..
- (BOOL) isHandlingSendEvent
{
return _isHandlingSendEvent;
}

- (void)setHandlingSendEvent:(BOOL)handlingSendEvent
{
_isHandlingSendEvent = handlingSendEvent;
}
@end

extern void InitializeAvnApp(IAvnApplicationEvents* events)
Expand Down
1 change: 0 additions & 1 deletion nukebuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ void RunCoreTest(string projectName)
RunCoreTest("Avalonia.Markup.Xaml.UnitTests");
RunCoreTest("Avalonia.Skia.UnitTests");
RunCoreTest("Avalonia.ReactiveUI.UnitTests");
RunCoreTest("Avalonia.PlatformSupport.UnitTests");
});

Target RunRenderTests => _ => _
Expand Down
30 changes: 14 additions & 16 deletions samples/ControlCatalog.Android/ControlCatalog.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,37 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<AndroidPackageFormat>apk</AndroidPackageFormat>
<MSBuildEnableWorkloadResolver>true</MSBuildEnableWorkloadResolver>
<RuntimeIdentifiers>android-arm64;android-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<None Remove="Assets\AboutAssets.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="..\..\build\Assets\Icon.png">
<Link>Resources\drawable\Icon.png</Link>
</AndroidResource>
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release' and '$(TF_BUILD)' == ''">
<DebugSymbols>True</DebugSymbols>
<PropertyGroup Condition="'$(RunAOTCompilation)'=='' and '$(Configuration)'=='Release' and '$(TF_BUILD)'==''">
<RunAOTCompilation>True</RunAOTCompilation>
<EnableLLVM>True</EnableLLVM>
<AndroidEnableProfiledAot>True</AndroidEnableProfiledAot>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
<RunAOTCompilation>False</RunAOTCompilation>

<PropertyGroup Condition="'$(RunAOTCompilation)'=='True'">
<EnableLLVM>True</EnableLLVM>
<AndroidAotAdditionalArguments>no-write-symbols,nodebug</AndroidAotAdditionalArguments>
<AndroidAotMode>Hybrid</AndroidAotMode>
<AndroidGenerateJniMarshalMethods>True</AndroidGenerateJniMarshalMethods>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
<PropertyGroup Condition="'$(AndroidEnableProfiler)'=='True'">
<IsEmulator Condition="'$(IsEmulator)' == ''">True</IsEmulator>
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.3.1.3" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModel" Version="2.3.1.3" />
<AndroidEnvironment Condition="'$(IsEmulator)'=='True'" Include="environment.emulator.txt" />
<AndroidEnvironment Condition="'$(IsEmulator)'!='True'" Include="environment.device.txt" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Android\Avalonia.Android\Avalonia.Android.csproj" />
<ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<application android:label="ControlCatalog.Android" android:icon="@drawable/Icon"></application>
<application android:label="ControlCatalog.Android" android:icon="@drawable/Icon"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
1 change: 1 addition & 0 deletions samples/ControlCatalog.Android/environment.device.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOTNET_DiagnosticPorts=127.0.0.1:9000,suspend
1 change: 1 addition & 0 deletions samples/ControlCatalog.Android/environment.emulator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOTNET_DiagnosticPorts=10.0.2.2:9001,suspend
10 changes: 7 additions & 3 deletions samples/ControlCatalog/Converter/MathSubtractConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ namespace ControlCatalog.Converter;

public class MathSubtractConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return (double)value - (double)parameter;
if (value is double dv && parameter is double dp)
{
return dv - dp;
}
return double.NaN;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
Expand Down
10 changes: 5 additions & 5 deletions samples/ControlCatalog/DecoratedWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DecoratedWindow()

void SetupSide(string name, StandardCursorType cursor, WindowEdge edge)
{
var ctl = this.FindControl<Control>(name);
var ctl = this.Get<Control>(name);
ctl.Cursor = new Cursor(cursor);
ctl.PointerPressed += (i, e) =>
{
Expand All @@ -26,7 +26,7 @@ void SetupSide(string name, StandardCursorType cursor, WindowEdge edge)
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
this.FindControl<Control>("TitleBar").PointerPressed += (i, e) =>
this.Get<Control>("TitleBar").PointerPressed += (i, e) =>
{
PlatformImpl?.BeginMoveDrag(e);
};
Expand All @@ -38,12 +38,12 @@ private void InitializeComponent()
SetupSide("TopRight", StandardCursorType.TopRightCorner, WindowEdge.NorthEast);
SetupSide("BottomLeft", StandardCursorType.BottomLeftCorner, WindowEdge.SouthWest);
SetupSide("BottomRight", StandardCursorType.BottomRightCorner, WindowEdge.SouthEast);
this.FindControl<Button>("MinimizeButton").Click += delegate { this.WindowState = WindowState.Minimized; };
this.FindControl<Button>("MaximizeButton").Click += delegate
this.Get<Button>("MinimizeButton").Click += delegate { this.WindowState = WindowState.Minimized; };
this.Get<Button>("MaximizeButton").Click += delegate
{
WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
};
this.FindControl<Button>("CloseButton").Click += delegate
this.Get<Button>("CloseButton").Click += delegate
{
Close();
};
Expand Down
16 changes: 8 additions & 8 deletions samples/ControlCatalog/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public MainView()
{
AvaloniaXamlLoader.Load(this);

var sideBar = this.FindControl<TabControl>("Sidebar");
var sideBar = this.Get<TabControl>("Sidebar");

if (AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().IsDesktop)
if (AvaloniaLocator.Current?.GetService<IRuntimePlatform>()?.GetRuntimeInfo().IsDesktop == true)
{
IList tabItems = ((IList)sideBar.Items);
tabItems.Add(new TabItem()
Expand All @@ -36,7 +36,7 @@ public MainView()

}

var themes = this.Find<ComboBox>("Themes");
var themes = this.Get<ComboBox>("Themes");
themes.SelectionChanged += (sender, e) =>
{
if (themes.SelectedItem is CatalogTheme theme)
Expand Down Expand Up @@ -80,7 +80,7 @@ public MainView()
}
};

var flowDirections = this.Find<ComboBox>("FlowDirection");
var flowDirections = this.Get<ComboBox>("FlowDirection");
flowDirections.SelectionChanged += (sender, e) =>
{
if (flowDirections.SelectedItem is FlowDirection flowDirection)
Expand All @@ -89,7 +89,7 @@ public MainView()
}
};

var decorations = this.Find<ComboBox>("Decorations");
var decorations = this.Get<ComboBox>("Decorations");
decorations.SelectionChanged += (sender, e) =>
{
if (VisualRoot is Window window
Expand All @@ -99,8 +99,8 @@ public MainView()
}
};

var transparencyLevels = this.Find<ComboBox>("TransparencyLevels");
IDisposable backgroundSetter = null, paneBackgroundSetter = null;
var transparencyLevels = this.Get<ComboBox>("TransparencyLevels");
IDisposable? backgroundSetter = null, paneBackgroundSetter = null;
transparencyLevels.SelectionChanged += (sender, e) =>
{
backgroundSetter?.Dispose();
Expand All @@ -118,7 +118,7 @@ public MainView()
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
var decorations = this.Find<ComboBox>("Decorations");
var decorations = this.Get<ComboBox>("Decorations");
if (VisualRoot is Window window)
decorations.SelectedIndex = (int)window.SystemDecorations;
}
Expand Down
6 changes: 3 additions & 3 deletions samples/ControlCatalog/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ControlCatalog
public class MainWindow : Window
{
private WindowNotificationManager _notificationArea;
private NativeMenu _recentMenu;
private NativeMenu? _recentMenu;

public MainWindow()
{
Expand All @@ -28,7 +28,7 @@ public MainWindow()
};

DataContext = new MainWindowViewModel(_notificationArea);
_recentMenu = ((NativeMenu.GetMenu(this).Items[0] as NativeMenuItem).Menu.Items[2] as NativeMenuItem).Menu;
_recentMenu = ((NativeMenu.GetMenu(this)?.Items[0] as NativeMenuItem)?.Menu?.Items[2] as NativeMenuItem)?.Menu;
}

public static string MenuQuitHeader => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "Quit Avalonia" : "E_xit";
Expand All @@ -39,7 +39,7 @@ public MainWindow()

public void OnOpenClicked(object sender, EventArgs args)
{
_recentMenu.Items.Insert(0, new NativeMenuItem("Item " + (_recentMenu.Items.Count + 1)));
_recentMenu?.Items.Insert(0, new NativeMenuItem("Item " + (_recentMenu.Items.Count + 1)));
}

public void OnCloseClicked(object sender, EventArgs args)
Expand Down
4 changes: 2 additions & 2 deletions samples/ControlCatalog/Models/Countries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static IEnumerable<Country> GetCountries()
yield return new Country("Zimbabwe", "SUB-SAHARAN AFRICA", 12236805, 390580, 31.3, 0, 0, 67.69, 1900, 90.7, 26.8, 28.01, 21.84);
}

static IReadOnlyList<Country> _all;
static IReadOnlyList<Country>? _all;

public static IReadOnlyList<Country> All
{
Expand All @@ -253,4 +253,4 @@ public static IReadOnlyList<Country> All

}
}
}
}
Loading

0 comments on commit 60ecdcc

Please sign in to comment.