2025-12-19 09:30:16 +00:00
|
|
|
// 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 Microsoft.Maui.Graphics;
|
|
|
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
using Microsoft.Maui.Platform;
|
2025-12-21 13:26:56 -05:00
|
|
|
using System.Collections.Specialized;
|
2025-12-19 09:30:16 +00:00
|
|
|
|
|
|
|
|
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handler for Picker on Linux using Skia rendering.
|
2026-01-16 05:10:40 +00:00
|
|
|
/// Maps IPicker interface to SkiaPicker platform view.
|
2025-12-19 09:30:16 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public partial class PickerHandler : ViewHandler<IPicker, SkiaPicker>
|
|
|
|
|
{
|
|
|
|
|
public static IPropertyMapper<IPicker, PickerHandler> Mapper =
|
|
|
|
|
new PropertyMapper<IPicker, PickerHandler>(ViewHandler.ViewMapper)
|
|
|
|
|
{
|
|
|
|
|
[nameof(IPicker.Title)] = MapTitle,
|
|
|
|
|
[nameof(IPicker.TitleColor)] = MapTitleColor,
|
|
|
|
|
[nameof(IPicker.SelectedIndex)] = MapSelectedIndex,
|
|
|
|
|
[nameof(IPicker.TextColor)] = MapTextColor,
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
[nameof(ITextStyle.Font)] = MapFont,
|
2025-12-19 09:30:16 +00:00
|
|
|
[nameof(IPicker.CharacterSpacing)] = MapCharacterSpacing,
|
|
|
|
|
[nameof(IPicker.HorizontalTextAlignment)] = MapHorizontalTextAlignment,
|
|
|
|
|
[nameof(IPicker.VerticalTextAlignment)] = MapVerticalTextAlignment,
|
|
|
|
|
[nameof(IView.Background)] = MapBackground,
|
2026-01-16 05:10:40 +00:00
|
|
|
[nameof(IView.IsEnabled)] = MapIsEnabled,
|
2025-12-21 13:26:56 -05:00
|
|
|
[nameof(Picker.ItemsSource)] = MapItemsSource,
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static CommandMapper<IPicker, PickerHandler> CommandMapper =
|
|
|
|
|
new(ViewHandler.ViewCommandMapper)
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
private INotifyCollectionChanged? _itemsCollection;
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public PickerHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PickerHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
|
|
|
|
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaPicker CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaPicker();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ConnectHandler(SkiaPicker platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
|
|
|
|
platformView.SelectedIndexChanged += OnSelectedIndexChanged;
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
// Subscribe to items collection changes
|
|
|
|
|
if (VirtualView is Picker picker && picker.Items is INotifyCollectionChanged items)
|
|
|
|
|
{
|
|
|
|
|
_itemsCollection = items;
|
|
|
|
|
_itemsCollection.CollectionChanged += OnItemsCollectionChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 05:10:40 +00:00
|
|
|
// Load items and sync properties
|
2025-12-19 09:30:16 +00:00
|
|
|
ReloadItems();
|
2026-01-16 05:10:40 +00:00
|
|
|
|
|
|
|
|
if (VirtualView != null)
|
|
|
|
|
{
|
|
|
|
|
MapTitle(this, VirtualView);
|
|
|
|
|
MapTitleColor(this, VirtualView);
|
|
|
|
|
MapTextColor(this, VirtualView);
|
|
|
|
|
MapSelectedIndex(this, VirtualView);
|
|
|
|
|
MapIsEnabled(this, VirtualView);
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DisconnectHandler(SkiaPicker platformView)
|
|
|
|
|
{
|
|
|
|
|
platformView.SelectedIndexChanged -= OnSelectedIndexChanged;
|
2025-12-21 13:26:56 -05:00
|
|
|
|
|
|
|
|
if (_itemsCollection != null)
|
|
|
|
|
{
|
|
|
|
|
_itemsCollection.CollectionChanged -= OnItemsCollectionChanged;
|
|
|
|
|
_itemsCollection = null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
base.DisconnectHandler(platformView);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
private void OnItemsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ReloadItems();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 05:10:40 +00:00
|
|
|
private void OnSelectedIndexChanged(object? sender, SelectedIndexChangedEventArgs e)
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
|
|
|
|
if (VirtualView is null || PlatformView is null) return;
|
|
|
|
|
|
2026-01-16 05:10:40 +00:00
|
|
|
if (VirtualView.SelectedIndex != e.NewIndex)
|
|
|
|
|
{
|
|
|
|
|
VirtualView.SelectedIndex = e.NewIndex;
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReloadItems()
|
|
|
|
|
{
|
|
|
|
|
if (PlatformView is null || VirtualView is null) return;
|
|
|
|
|
|
|
|
|
|
var items = VirtualView.GetItemsAsArray();
|
|
|
|
|
PlatformView.SetItems(items.Select(i => i?.ToString() ?? ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapTitle(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.Title = picker.Title ?? "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapTitleColor(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
if (picker.TitleColor is not null)
|
|
|
|
|
{
|
2026-01-16 05:10:40 +00:00
|
|
|
handler.PlatformView.TitleColor = picker.TitleColor;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapSelectedIndex(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
2026-01-16 05:10:40 +00:00
|
|
|
|
|
|
|
|
if (handler.PlatformView.SelectedIndex != picker.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.SelectedIndex = picker.SelectedIndex;
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapTextColor(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
if (picker.TextColor is not null)
|
|
|
|
|
{
|
2026-01-16 05:10:40 +00:00
|
|
|
handler.PlatformView.TextColor = picker.TextColor;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
public static void MapFont(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
var font = picker.Font;
|
|
|
|
|
if (!string.IsNullOrEmpty(font.Family))
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.FontFamily = font.Family;
|
|
|
|
|
}
|
|
|
|
|
if (font.Size > 0)
|
|
|
|
|
{
|
2026-01-16 05:10:40 +00:00
|
|
|
handler.PlatformView.FontSize = font.Size;
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
}
|
2026-01-16 05:38:45 +00:00
|
|
|
|
|
|
|
|
// Map FontAttributes from the Font weight
|
|
|
|
|
var attrs = FontAttributes.None;
|
|
|
|
|
if (font.Weight >= FontWeight.Bold)
|
|
|
|
|
attrs |= FontAttributes.Bold;
|
|
|
|
|
handler.PlatformView.FontAttributes = attrs;
|
|
|
|
|
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public static void MapCharacterSpacing(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
2026-01-16 05:38:45 +00:00
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.CharacterSpacing = picker.CharacterSpacing;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapHorizontalTextAlignment(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
2026-01-16 05:38:45 +00:00
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.HorizontalTextAlignment = picker.HorizontalTextAlignment;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapVerticalTextAlignment(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
2026-01-16 05:38:45 +00:00
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.VerticalTextAlignment = picker.VerticalTextAlignment;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackground(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (picker.Background is SolidPaint solidPaint && solidPaint.Color is not null)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-21 13:26:56 -05:00
|
|
|
|
2026-01-16 05:10:40 +00:00
|
|
|
public static void MapIsEnabled(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.IsEnabled = picker.IsEnabled;
|
|
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
public static void MapItemsSource(PickerHandler handler, IPicker picker)
|
|
|
|
|
{
|
|
|
|
|
handler.ReloadItems();
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|