Update with recovered code from VM binaries (Jan 1)

Recovered from decompiled OpenMaui.Controls.Linux.dll:
- SkiaShell.cs: FlyoutHeader, FlyoutFooter, scroll support (918 -> 1325 lines)
- X11Window.cs: Cursor support (XCreateFontCursor, XDefineCursor)
- All handlers with dark mode support
- All services with latest implementations
- LinuxApplication with theme change handling
This commit is contained in:
2026-01-01 06:22:48 -05:00
parent 1e84c6168a
commit 1f096c38dc
254 changed files with 49359 additions and 38457 deletions

View File

@@ -1,198 +1,153 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Handlers;
using System;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using SkiaSharp;
namespace Microsoft.Maui.Platform.Linux.Handlers;
/// <summary>
/// Handler for Button on Linux using Skia rendering.
/// Maps IButton interface to SkiaButton platform view.
/// </summary>
public partial class ButtonHandler : ViewHandler<IButton, SkiaButton>
public class ButtonHandler : ViewHandler<IButton, SkiaButton>
{
public static IPropertyMapper<IButton, ButtonHandler> Mapper = new PropertyMapper<IButton, ButtonHandler>(ViewHandler.ViewMapper)
{
[nameof(IButtonStroke.StrokeColor)] = MapStrokeColor,
[nameof(IButtonStroke.StrokeThickness)] = MapStrokeThickness,
[nameof(IButtonStroke.CornerRadius)] = MapCornerRadius,
[nameof(IView.Background)] = MapBackground,
[nameof(IPadding.Padding)] = MapPadding,
[nameof(IView.IsEnabled)] = MapIsEnabled,
};
public static IPropertyMapper<IButton, ButtonHandler> Mapper = (IPropertyMapper<IButton, ButtonHandler>)(object)new PropertyMapper<IButton, ButtonHandler>((IPropertyMapper[])(object)new IPropertyMapper[1] { (IPropertyMapper)ViewHandler.ViewMapper })
{
["StrokeColor"] = MapStrokeColor,
["StrokeThickness"] = MapStrokeThickness,
["CornerRadius"] = MapCornerRadius,
["Background"] = MapBackground,
["Padding"] = MapPadding,
["IsEnabled"] = MapIsEnabled
};
public static CommandMapper<IButton, ButtonHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
{
};
public static CommandMapper<IButton, ButtonHandler> CommandMapper = new CommandMapper<IButton, ButtonHandler>((CommandMapper)(object)ViewHandler.ViewCommandMapper);
public ButtonHandler() : base(Mapper, CommandMapper)
{
}
public ButtonHandler()
: base((IPropertyMapper)(object)Mapper, (CommandMapper)(object)CommandMapper)
{
}
public ButtonHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
{
}
public ButtonHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
: base((IPropertyMapper)(((object)mapper) ?? ((object)Mapper)), (CommandMapper)(((object)commandMapper) ?? ((object)CommandMapper)))
{
}
protected override SkiaButton CreatePlatformView()
{
var button = new SkiaButton();
return button;
}
protected override SkiaButton CreatePlatformView()
{
return new SkiaButton();
}
protected override void ConnectHandler(SkiaButton platformView)
{
base.ConnectHandler(platformView);
platformView.Clicked += OnClicked;
platformView.Pressed += OnPressed;
platformView.Released += OnReleased;
protected override void ConnectHandler(SkiaButton platformView)
{
base.ConnectHandler(platformView);
platformView.Clicked += OnClicked;
platformView.Pressed += OnPressed;
platformView.Released += OnReleased;
if (base.VirtualView != null)
{
MapStrokeColor(this, base.VirtualView);
MapStrokeThickness(this, base.VirtualView);
MapCornerRadius(this, base.VirtualView);
MapBackground(this, base.VirtualView);
MapPadding(this, base.VirtualView);
MapIsEnabled(this, base.VirtualView);
}
}
// Manually map all properties on connect since MAUI may not trigger updates
// for properties that were set before handler connection
if (VirtualView != null)
{
MapStrokeColor(this, VirtualView);
MapStrokeThickness(this, VirtualView);
MapCornerRadius(this, VirtualView);
MapBackground(this, VirtualView);
MapPadding(this, VirtualView);
MapIsEnabled(this, VirtualView);
}
}
protected override void DisconnectHandler(SkiaButton platformView)
{
platformView.Clicked -= OnClicked;
platformView.Pressed -= OnPressed;
platformView.Released -= OnReleased;
base.DisconnectHandler(platformView);
}
protected override void DisconnectHandler(SkiaButton platformView)
{
platformView.Clicked -= OnClicked;
platformView.Pressed -= OnPressed;
platformView.Released -= OnReleased;
base.DisconnectHandler(platformView);
}
private void OnClicked(object? sender, EventArgs e)
{
IButton virtualView = base.VirtualView;
if (virtualView != null)
{
virtualView.Clicked();
}
}
private void OnClicked(object? sender, EventArgs e) => VirtualView?.Clicked();
private void OnPressed(object? sender, EventArgs e) => VirtualView?.Pressed();
private void OnReleased(object? sender, EventArgs e) => VirtualView?.Released();
private void OnPressed(object? sender, EventArgs e)
{
IButton virtualView = base.VirtualView;
if (virtualView != null)
{
virtualView.Pressed();
}
}
public static void MapStrokeColor(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
private void OnReleased(object? sender, EventArgs e)
{
IButton virtualView = base.VirtualView;
if (virtualView != null)
{
virtualView.Released();
}
}
var strokeColor = button.StrokeColor;
if (strokeColor is not null)
handler.PlatformView.BorderColor = strokeColor.ToSKColor();
}
public static void MapStrokeColor(ButtonHandler handler, IButton button)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if (((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView != null)
{
Color strokeColor = ((IButtonStroke)button).StrokeColor;
if (strokeColor != null)
{
((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.BorderColor = strokeColor.ToSKColor();
}
}
}
public static void MapStrokeThickness(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
handler.PlatformView.BorderWidth = (float)button.StrokeThickness;
}
public static void MapStrokeThickness(ButtonHandler handler, IButton button)
{
if (((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView != null)
{
((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.BorderWidth = (float)((IButtonStroke)button).StrokeThickness;
}
}
public static void MapCornerRadius(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
handler.PlatformView.CornerRadius = button.CornerRadius;
}
public static void MapCornerRadius(ButtonHandler handler, IButton button)
{
if (((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView != null)
{
((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.CornerRadius = ((IButtonStroke)button).CornerRadius;
}
}
public static void MapBackground(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
public static void MapBackground(ButtonHandler handler, IButton button)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
if (((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView != null)
{
Paint background = ((IView)button).Background;
SolidPaint val = (SolidPaint)(object)((background is SolidPaint) ? background : null);
if (val != null && val.Color != null)
{
((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.ButtonBackgroundColor = val.Color.ToSKColor();
}
}
}
if (button.Background is SolidPaint solidPaint && solidPaint.Color is not null)
{
// Set ButtonBackgroundColor (used for rendering) not base BackgroundColor
handler.PlatformView.ButtonBackgroundColor = solidPaint.Color.ToSKColor();
}
}
public static void MapPadding(ButtonHandler handler, IButton button)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView != null)
{
Thickness padding = ((IPadding)button).Padding;
((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.Padding = new SKRect((float)((Thickness)(ref padding)).Left, (float)((Thickness)(ref padding)).Top, (float)((Thickness)(ref padding)).Right, (float)((Thickness)(ref padding)).Bottom);
}
}
public static void MapPadding(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
var padding = button.Padding;
handler.PlatformView.Padding = new SKRect(
(float)padding.Left,
(float)padding.Top,
(float)padding.Right,
(float)padding.Bottom);
}
public static void MapIsEnabled(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
Console.WriteLine($"[ButtonHandler] MapIsEnabled - Text='{handler.PlatformView.Text}', IsEnabled={button.IsEnabled}");
handler.PlatformView.IsEnabled = button.IsEnabled;
handler.PlatformView.Invalidate();
}
}
/// <summary>
/// Handler for TextButton on Linux - extends ButtonHandler with text support.
/// Maps ITextButton interface (which includes IText properties).
/// </summary>
public partial class TextButtonHandler : ButtonHandler
{
public static new IPropertyMapper<ITextButton, TextButtonHandler> Mapper =
new PropertyMapper<ITextButton, TextButtonHandler>(ButtonHandler.Mapper)
{
[nameof(IText.Text)] = MapText,
[nameof(ITextStyle.TextColor)] = MapTextColor,
[nameof(ITextStyle.Font)] = MapFont,
[nameof(ITextStyle.CharacterSpacing)] = MapCharacterSpacing,
};
public TextButtonHandler() : base(Mapper)
{
}
protected override void ConnectHandler(SkiaButton platformView)
{
base.ConnectHandler(platformView);
// Manually map text properties on connect since MAUI may not trigger updates
// for properties that were set before handler connection
if (VirtualView is ITextButton textButton)
{
MapText(this, textButton);
MapTextColor(this, textButton);
MapFont(this, textButton);
MapCharacterSpacing(this, textButton);
}
}
public static void MapText(TextButtonHandler handler, ITextButton button)
{
if (handler.PlatformView is null) return;
handler.PlatformView.Text = button.Text ?? string.Empty;
}
public static void MapTextColor(TextButtonHandler handler, ITextButton button)
{
if (handler.PlatformView is null) return;
if (button.TextColor is not null)
handler.PlatformView.TextColor = button.TextColor.ToSKColor();
}
public static void MapFont(TextButtonHandler handler, ITextButton button)
{
if (handler.PlatformView is null) return;
var font = button.Font;
if (font.Size > 0)
handler.PlatformView.FontSize = (float)font.Size;
if (!string.IsNullOrEmpty(font.Family))
handler.PlatformView.FontFamily = font.Family;
handler.PlatformView.IsBold = font.Weight >= FontWeight.Bold;
handler.PlatformView.IsItalic = font.Slant == FontSlant.Italic || font.Slant == FontSlant.Oblique;
}
public static void MapCharacterSpacing(TextButtonHandler handler, ITextButton button)
{
if (handler.PlatformView is null) return;
handler.PlatformView.CharacterSpacing = (float)button.CharacterSpacing;
}
public static void MapIsEnabled(ButtonHandler handler, IButton button)
{
if (((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView != null)
{
Console.WriteLine($"[ButtonHandler] MapIsEnabled - Text='{((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.Text}', IsEnabled={((IView)button).IsEnabled}");
((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.IsEnabled = ((IView)button).IsEnabled;
((ViewHandler<IButton, SkiaButton>)(object)handler).PlatformView.Invalidate();
}
}
}