using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Input;
namespace Titano.Ui.Controls;
///
/// 40-px strip under the title bar: current job, progress, time left and a stop (or pause) button (DESIGN §4). Screen
/// readers see a status bar; its name is AutomationProperties.Name (the owner keeps it to the job's state, so
/// it can be a live region that does not speak every progress tick), else .
///
public class JobBar : Control
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(JobBar));
public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register(nameof(Progress), typeof(double), typeof(JobBar), new PropertyMetadata(0.0));
public static readonly DependencyProperty IsIndeterminateProperty = DependencyProperty.Register(nameof(IsIndeterminate), typeof(bool), typeof(JobBar));
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(JobBar));
public static readonly DependencyProperty StopCommandProperty = DependencyProperty.Register(nameof(StopCommand), typeof(ICommand), typeof(JobBar));
public static readonly DependencyProperty StopToolTipProperty = DependencyProperty.Register(nameof(StopToolTip), typeof(object), typeof(JobBar));
public static readonly DependencyProperty StopNameProperty = DependencyProperty.Register(nameof(StopName), typeof(string), typeof(JobBar));
public static readonly DependencyProperty ActionGlyphProperty = DependencyProperty.Register(nameof(ActionGlyph), typeof(IconData), typeof(JobBar));
static JobBar()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(JobBar), new FrameworkPropertyMetadata(typeof(JobBar)));
}
public string? Text { get => (string?)GetValue(TextProperty); set => SetValue(TextProperty, value); }
/// 0..1.
public double Progress { get => (double)GetValue(ProgressProperty); set => SetValue(ProgressProperty, value); }
public bool IsIndeterminate { get => (bool)GetValue(IsIndeterminateProperty); set => SetValue(IsIndeterminateProperty, value); }
/// A job is running: shows the progress fill and the stop button.
public bool IsActive { get => (bool)GetValue(IsActiveProperty); set => SetValue(IsActiveProperty, value); }
public ICommand? StopCommand { get => (ICommand?)GetValue(StopCommandProperty); set => SetValue(StopCommandProperty, value); }
public object? StopToolTip { get => GetValue(StopToolTipProperty); set => SetValue(StopToolTipProperty, value); }
/// Short accessible name of the stop (or pause) button; the tooltip sentence becomes its help text.
public string? StopName { get => (string?)GetValue(StopNameProperty); set => SetValue(StopNameProperty, value); }
/// Glyph of the action button: stop by default; the client shows pause (DESIGN §4 job bar).
public IconData? ActionGlyph { get => (IconData?)GetValue(ActionGlyphProperty); set => SetValue(ActionGlyphProperty, value); }
protected override AutomationPeer OnCreateAutomationPeer() => new JobBarAutomationPeer(this);
}
/// The job bar seen by UI Automation: a status bar holding the progress bar and the pause button.
public sealed class JobBarAutomationPeer(JobBar owner) : FrameworkElementAutomationPeer(owner)
{
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.StatusBar;
protected override string GetClassNameCore() => nameof(JobBar);
protected override string GetNameCore()
{
var name = base.GetNameCore();
return string.IsNullOrEmpty(name) ? ((JobBar)Owner).Text ?? string.Empty : name;
}
}