Skip to content

Commit f145cdf

Browse files
authored
Merge branch 'master' into upgrade_skia_packages
2 parents 020fa30 + 2747384 commit f145cdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1330
-656
lines changed

Avalonia.sln

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Props", "Props", "{F3AC8BC1
9797
build\DevAnalyzers.props = build\DevAnalyzers.props
9898
build\EmbedXaml.props = build\EmbedXaml.props
9999
build\HarfBuzzSharp.props = build\HarfBuzzSharp.props
100+
build\ImageSharp.props = build\ImageSharp.props
100101
build\JetBrains.Annotations.props = build\JetBrains.Annotations.props
101102
build\JetBrains.dotMemoryUnit.props = build\JetBrains.dotMemoryUnit.props
102103
build\Microsoft.CSharp.props = build\Microsoft.CSharp.props
@@ -117,7 +118,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Props", "Props", "{F3AC8BC1
117118
build\System.Memory.props = build\System.Memory.props
118119
build\UnitTests.NetFX.props = build\UnitTests.NetFX.props
119120
build\XUnit.props = build\XUnit.props
120-
build\ImageSharp.props = build\ImageSharp.props
121121
EndProjectSection
122122
EndProject
123123
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Targets", "Targets", "{4D6FAF79-58B4-482F-9122-0668C346364C}"
@@ -179,8 +179,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.FreeDesktop", "src
179179
EndProject
180180
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Controls.DataGrid.UnitTests", "tests\Avalonia.Controls.DataGrid.UnitTests\Avalonia.Controls.DataGrid.UnitTests.csproj", "{351337F5-D66F-461B-A957-4EF60BDB4BA6}"
181181
EndProject
182-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeEmbedSample", "samples\interop\NativeEmbedSample\NativeEmbedSample.csproj", "{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}"
183-
EndProject
184182
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Themes.Fluent", "src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj", "{C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}"
185183
EndProject
186184
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Headless", "src\Avalonia.Headless\Avalonia.Headless.csproj", "{8C89950F-F5D9-47FC-8066-CBC1EC3DF8FC}"
@@ -1413,6 +1411,30 @@ Global
14131411
{AF915D5C-AB00-4EA0-B5E6-001F4AE84E68}.Release|iPhone.Build.0 = Release|Any CPU
14141412
{AF915D5C-AB00-4EA0-B5E6-001F4AE84E68}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
14151413
{AF915D5C-AB00-4EA0-B5E6-001F4AE84E68}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
1414+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
1415+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
1416+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
1417+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
1418+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1419+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
1420+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
1421+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|Any CPU.Build.0 = Debug|Any CPU
1422+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
1423+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhone.Build.0 = Debug|Any CPU
1424+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1425+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
1426+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1427+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|Any CPU.Build.0 = Debug|Any CPU
1428+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhone.ActiveCfg = Debug|Any CPU
1429+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhone.Build.0 = Debug|Any CPU
1430+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1431+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
1432+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|Any CPU.ActiveCfg = Release|Any CPU
1433+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|Any CPU.Build.0 = Release|Any CPU
1434+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhone.ActiveCfg = Release|Any CPU
1435+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhone.Build.0 = Release|Any CPU
1436+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
1437+
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
14161438
{3278F3A9-9509-4A3F-A15B-BDC8B5BFF632}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
14171439
{3278F3A9-9509-4A3F-A15B-BDC8B5BFF632}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
14181440
{3278F3A9-9509-4A3F-A15B-BDC8B5BFF632}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
@@ -1509,30 +1531,6 @@ Global
15091531
{351337F5-D66F-461B-A957-4EF60BDB4BA6}.Release|iPhone.Build.0 = Release|Any CPU
15101532
{351337F5-D66F-461B-A957-4EF60BDB4BA6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
15111533
{351337F5-D66F-461B-A957-4EF60BDB4BA6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
1512-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
1513-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
1514-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
1515-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
1516-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1517-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
1518-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
1519-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.AppStore|Any CPU.Build.0 = Debug|Any CPU
1520-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
1521-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.AppStore|iPhone.Build.0 = Debug|Any CPU
1522-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1523-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
1524-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1525-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
1526-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Debug|iPhone.ActiveCfg = Debug|Any CPU
1527-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Debug|iPhone.Build.0 = Debug|Any CPU
1528-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1529-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
1530-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
1531-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Release|Any CPU.Build.0 = Release|Any CPU
1532-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Release|iPhone.ActiveCfg = Release|Any CPU
1533-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Release|iPhone.Build.0 = Release|Any CPU
1534-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
1535-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
15361534
{C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
15371535
{C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
15381536
{C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
@@ -1965,30 +1963,6 @@ Global
19651963
{2B390431-288C-435C-BB6B-A374033BD8D1}.Release|iPhone.Build.0 = Release|Any CPU
19661964
{2B390431-288C-435C-BB6B-A374033BD8D1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
19671965
{2B390431-288C-435C-BB6B-A374033BD8D1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
1968-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
1969-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
1970-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
1971-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
1972-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1973-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
1974-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
1975-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|Any CPU.Build.0 = Debug|Any CPU
1976-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
1977-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhone.Build.0 = Debug|Any CPU
1978-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1979-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
1980-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1981-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|Any CPU.Build.0 = Debug|Any CPU
1982-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhone.ActiveCfg = Debug|Any CPU
1983-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhone.Build.0 = Debug|Any CPU
1984-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1985-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
1986-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|Any CPU.ActiveCfg = Release|Any CPU
1987-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|Any CPU.Build.0 = Release|Any CPU
1988-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhone.ActiveCfg = Release|Any CPU
1989-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhone.Build.0 = Release|Any CPU
1990-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
1991-
{1ECC012A-8837-4AE2-9BDA-3E2857898727}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
19921966
EndGlobalSection
19931967
GlobalSection(SolutionProperties) = preSolution
19941968
HideSolutionNode = FALSE
@@ -2035,7 +2009,6 @@ Global
20352009
{D775DECB-4E00-4ED5-A75A-5FCE58ADFF0B} = {9B9E3891-2366-4253-A952-D08BCEB71098}
20362010
{AF915D5C-AB00-4EA0-B5E6-001F4AE84E68} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
20372011
{351337F5-D66F-461B-A957-4EF60BDB4BA6} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
2038-
{3C84E04B-36CF-4D0D-B965-C26DD649D1F3} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9}
20392012
{909A8CBD-7D0E-42FD-B841-022AD8925820} = {8B6A8209-894F-4BA1-B880-965FD453982C}
20402013
{11BE52AF-E2DD-4CF0-B19A-05285ACAF571} = {9B9E3891-2366-4253-A952-D08BCEB71098}
20412014
{BC594FD5-4AF2-409E-A1E6-04123F54D7C5} = {9B9E3891-2366-4253-A952-D08BCEB71098}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using Avalonia.Platform;
3+
using Avalonia.Android;
4+
using ControlCatalog.Pages;
5+
6+
namespace ControlCatalog.Android;
7+
8+
public class EmbedSampleAndroid : INativeDemoControl
9+
{
10+
public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault)
11+
{
12+
var parentContext = (parent as AndroidViewControlHandle)?.View.Context
13+
?? global::Android.App.Application.Context;
14+
15+
if (isSecond)
16+
{
17+
var webView = new global::Android.Webkit.WebView(parentContext);
18+
webView.LoadUrl("https://www.android.com/");
19+
20+
return new AndroidViewControlHandle(webView);
21+
}
22+
else
23+
{
24+
var button = new global::Android.Widget.Button(parentContext) { Text = "Hello world" };
25+
var clickCount = 0;
26+
button.Click += (sender, args) =>
27+
{
28+
clickCount++;
29+
button.Text = $"Click count {clickCount}";
30+
};
31+
32+
return new AndroidViewControlHandle(button);
33+
}
34+
}
35+
}

samples/ControlCatalog.Android/MainActivity.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ public class MainActivity : AvaloniaActivity<App>
1010
{
1111
protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
1212
{
13-
return base.CustomizeAppBuilder(builder);
13+
return base.CustomizeAppBuilder(builder)
14+
.AfterSetup(_ =>
15+
{
16+
Pages.EmbedSample.Implementation = new EmbedSampleAndroid();
17+
});
1418
}
1519
}
1620
}

samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<OutputType>WinExe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
66
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
78
</PropertyGroup>
89

910
<PropertyGroup Condition="'$(RunNativeAotCompilation)' == 'true'">
@@ -12,6 +13,16 @@
1213
<NativeAotCompilerVersion>7.0.0-*</NativeAotCompilerVersion>
1314
</PropertyGroup>
1415

16+
<ItemGroup>
17+
<Compile Include="..\..\src\Avalonia.X11\NativeDialogs\Gtk.cs" Link="NativeControls\Gtk\Gtk.cs" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Content Include="NativeControls\Gtk\nodes.mp4">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</Content>
24+
</ItemGroup>
25+
1526
<ItemGroup>
1627
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
1728
<ProjectReference Include="..\..\src\Avalonia.Headless.Vnc\Avalonia.Headless.Vnc.csproj" />
@@ -20,6 +31,8 @@
2031
<ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" />
2132
<ProjectReference Include="..\..\src\Avalonia.X11\Avalonia.X11.csproj" />
2233
<PackageReference Include="Avalonia.Angle.Windows.Natives" Version="2.1.0.2020091801" />
34+
<!-- For native controls test -->
35+
<PackageReference Include="MonoMac.NetStandard" Version="0.0.4" />
2336
</ItemGroup>
2437

2538
<ItemGroup Condition="'$(RunNativeAotCompilation)' == 'true'">
@@ -32,6 +45,7 @@
3245
<PropertyGroup>
3346
<!-- For Microsoft.CodeAnalysis -->
3447
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
48+
<ApplicationManifest>app.manifest</ApplicationManifest>
3549
</PropertyGroup>
3650

3751
<Import Project="..\..\build\SampleApp.props" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.IO;
2+
using System.Diagnostics;
3+
using Avalonia.Platform;
4+
using Avalonia.Controls.Platform;
5+
using System;
6+
using ControlCatalog.Pages;
7+
8+
namespace ControlCatalog.NetCore;
9+
10+
public class EmbedSampleGtk : INativeDemoControl
11+
{
12+
private Process _mplayer;
13+
14+
public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault)
15+
{
16+
if (isSecond)
17+
{
18+
var chooser = GtkHelper.CreateGtkFileChooser(parent.Handle);
19+
if (chooser != null)
20+
return chooser;
21+
}
22+
23+
var control = createDefault();
24+
var nodes = Path.GetFullPath(Path.Combine(typeof(EmbedSample).Assembly.GetModules()[0].FullyQualifiedName,
25+
"..",
26+
"nodes.mp4"));
27+
_mplayer = Process.Start(new ProcessStartInfo("mplayer",
28+
$"-vo x11 -zoom -loop 0 -wid {control.Handle.ToInt64()} \"{nodes}\"")
29+
{
30+
UseShellExecute = false,
31+
32+
});
33+
return control;
34+
}
35+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Avalonia.Controls.Platform;
4+
using Avalonia.Platform.Interop;
5+
using Avalonia.X11.NativeDialogs;
6+
using static Avalonia.X11.NativeDialogs.Gtk;
7+
using static Avalonia.X11.NativeDialogs.Glib;
8+
9+
namespace ControlCatalog.NetCore;
10+
11+
internal class GtkHelper
12+
{
13+
private static Task<bool> s_gtkTask;
14+
15+
class FileChooser : INativeControlHostDestroyableControlHandle
16+
{
17+
private readonly IntPtr _widget;
18+
19+
public FileChooser(IntPtr widget, IntPtr xid)
20+
{
21+
_widget = widget;
22+
Handle = xid;
23+
}
24+
25+
public IntPtr Handle { get; }
26+
public string HandleDescriptor => "XID";
27+
28+
public void Destroy()
29+
{
30+
RunOnGlibThread(() =>
31+
{
32+
gtk_widget_destroy(_widget);
33+
return 0;
34+
}).Wait();
35+
}
36+
}
37+
38+
39+
public static INativeControlHostDestroyableControlHandle CreateGtkFileChooser(IntPtr parentXid)
40+
{
41+
if (s_gtkTask == null)
42+
s_gtkTask = StartGtk();
43+
if (!s_gtkTask.Result)
44+
return null;
45+
return RunOnGlibThread(() =>
46+
{
47+
using (var title = new Utf8Buffer("Embedded"))
48+
{
49+
var widget = gtk_file_chooser_dialog_new(title, IntPtr.Zero, GtkFileChooserAction.SelectFolder,
50+
IntPtr.Zero);
51+
gtk_widget_realize(widget);
52+
var xid = gdk_x11_window_get_xid(gtk_widget_get_window(widget));
53+
gtk_window_present(widget);
54+
return new FileChooser(widget, xid);
55+
}
56+
}).Result;
57+
}
58+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
using Avalonia.Platform;
4+
using Avalonia.Threading;
5+
6+
using ControlCatalog.Pages;
7+
8+
using MonoMac.Foundation;
9+
using MonoMac.WebKit;
10+
11+
namespace ControlCatalog.NetCore;
12+
13+
public class EmbedSampleMac : INativeDemoControl
14+
{
15+
public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault)
16+
{
17+
// Note: We are using MonoMac for example purposes
18+
// It shouldn't be used in production apps
19+
MacHelper.EnsureInitialized();
20+
21+
var webView = new WebView();
22+
Dispatcher.UIThread.Post(() =>
23+
{
24+
webView.MainFrame.LoadRequest(new NSUrlRequest(new NSUrl(
25+
isSecond ? "https://bing.com" : "https://google.com/")));
26+
});
27+
return new MacOSViewHandle(webView);
28+
}
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
3+
using Avalonia.Controls.Platform;
4+
using MonoMac.AppKit;
5+
6+
namespace ControlCatalog.NetCore;
7+
8+
internal class MacHelper
9+
{
10+
private static bool _isInitialized;
11+
12+
public static void EnsureInitialized()
13+
{
14+
if (_isInitialized)
15+
return;
16+
_isInitialized = true;
17+
NSApplication.Init();
18+
}
19+
}
20+
21+
internal class MacOSViewHandle : INativeControlHostDestroyableControlHandle
22+
{
23+
private NSView _view;
24+
25+
public MacOSViewHandle(NSView view)
26+
{
27+
_view = view;
28+
}
29+
30+
public IntPtr Handle => _view?.Handle ?? IntPtr.Zero;
31+
public string HandleDescriptor => "NSView";
32+
33+
public void Destroy()
34+
{
35+
_view.Dispose();
36+
_view = null;
37+
}
38+
}

0 commit comments

Comments
 (0)