-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c45d58d
commit b0ec12c
Showing
10 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Avalonia.Automation.Peers; | ||
using Avalonia.Automation.Provider; | ||
using Avalonia.Controls; | ||
|
||
namespace DataBox.Automation.Peers; | ||
|
||
public class DataBoxAutomationPeer : ControlAutomationPeer, IScrollProvider | ||
{ | ||
private bool _searchedForScrollable; | ||
private IScrollProvider? _scroller; | ||
|
||
public DataBoxAutomationPeer(DataBox owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
public new DataBox Owner => (DataBox)base.Owner; | ||
public bool HorizontallyScrollable => _scroller?.HorizontallyScrollable ?? false; | ||
public double HorizontalScrollPercent => _scroller?.HorizontalScrollPercent ?? -1; | ||
public double HorizontalViewSize => _scroller?.HorizontalViewSize ?? 0; | ||
public bool VerticallyScrollable => _scroller?.VerticallyScrollable ?? false; | ||
public double VerticalScrollPercent => _scroller?.VerticalScrollPercent ?? -1; | ||
public double VerticalViewSize => _scroller?.VerticalViewSize ?? 0; | ||
|
||
protected virtual IScrollProvider? Scroller | ||
{ | ||
get | ||
{ | ||
if (!_searchedForScrollable) | ||
{ | ||
if (Owner.RowsPresenter?.GetValue(ListBox.ScrollProperty) is Control scrollable) | ||
_scroller = GetOrCreate(scrollable).GetProvider<IScrollProvider>(); | ||
_searchedForScrollable = true; | ||
} | ||
|
||
return _scroller; | ||
} | ||
} | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.DataGrid; | ||
} | ||
|
||
public void Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount) | ||
{ | ||
_scroller?.Scroll(horizontalAmount, verticalAmount); | ||
} | ||
|
||
public void SetScrollPercent(double horizontalPercent, double verticalPercent) | ||
{ | ||
_scroller?.SetScrollPercent(horizontalPercent, verticalPercent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Avalonia.Automation.Peers; | ||
|
||
namespace DataBox.Automation.Peers; | ||
|
||
public class DataBoxCellAutomationPeer : ContentControlAutomationPeer | ||
{ | ||
public DataBoxCellAutomationPeer(DataBoxCell owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
public new DataBoxCell Owner => (DataBoxCell)base.Owner; | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.Custom; | ||
} | ||
|
||
protected override bool IsContentElementCore() => true; | ||
|
||
protected override bool IsControlElementCore() => true; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/DataBox/Automation/Peers/DataBoxColumnHeaderAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Avalonia.Automation.Peers; | ||
|
||
namespace DataBox.Automation.Peers; | ||
|
||
public class DataBoxColumnHeaderAutomationPeer : ContentControlAutomationPeer | ||
{ | ||
public DataBoxColumnHeaderAutomationPeer(DataBoxColumnHeader owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
public new DataBoxColumnHeader Owner => (DataBoxColumnHeader)base.Owner; | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.HeaderItem; | ||
} | ||
|
||
protected override bool IsContentElementCore() => false; | ||
|
||
protected override bool IsControlElementCore() => true; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/DataBox/Automation/Peers/DataBoxColumnHeadersPresenterAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Avalonia.Automation.Peers; | ||
using DataBox.Primitives; | ||
|
||
namespace DataBox.Automation.Peers; | ||
|
||
public class DataBoxColumnHeadersPresenterAutomationPeer : ControlAutomationPeer | ||
{ | ||
public DataBoxColumnHeadersPresenterAutomationPeer(DataBoxColumnHeadersPresenter owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
public new DataBoxColumnHeadersPresenter Owner => (DataBoxColumnHeadersPresenter)base.Owner; | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.Header; | ||
} | ||
|
||
protected override bool IsContentElementCore() => false; | ||
|
||
protected override bool IsControlElementCore() => true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Avalonia.Automation.Peers; | ||
using Avalonia.Automation.Provider; | ||
using Avalonia.Controls; | ||
|
||
namespace DataBox.Automation.Peers; | ||
|
||
public class DataBoxRowAutomationPeer : ContentControlAutomationPeer, | ||
ISelectionItemProvider | ||
{ | ||
public DataBoxRowAutomationPeer(ContentControl owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
public bool IsSelected => Owner.GetValue(ListBoxItem.IsSelectedProperty); | ||
|
||
public ISelectionProvider? SelectionContainer | ||
{ | ||
get | ||
{ | ||
if (Owner.Parent is DataBox parent) | ||
{ | ||
var parentPeer = GetOrCreate(parent); | ||
return parentPeer.GetProvider<ISelectionProvider>(); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public void Select() | ||
{ | ||
EnsureEnabled(); | ||
|
||
if (Owner.Parent is DataBox parent && parent.RowsPresenter is not null) | ||
{ | ||
var index = parent.RowsPresenter.IndexFromContainer(Owner); | ||
|
||
if (index != -1) | ||
parent.RowsPresenter.SelectedIndex = index; | ||
} | ||
} | ||
|
||
void ISelectionItemProvider.AddToSelection() | ||
{ | ||
EnsureEnabled(); | ||
|
||
if (Owner.Parent is DataBox parent | ||
&& parent.RowsPresenter is not null | ||
&& parent.RowsPresenter.GetValue(ListBox.SelectionProperty) is { } selectionModel) | ||
{ | ||
var index = parent.RowsPresenter.IndexFromContainer(Owner); | ||
|
||
if (index != -1) | ||
selectionModel.Select(index); | ||
} | ||
} | ||
|
||
void ISelectionItemProvider.RemoveFromSelection() | ||
{ | ||
EnsureEnabled(); | ||
|
||
if (Owner.Parent is DataBox parent | ||
&& parent.RowsPresenter is not null | ||
&& parent.GetValue(ListBox.SelectionProperty) is { } selectionModel) | ||
{ | ||
var index = parent.RowsPresenter.IndexFromContainer(Owner); | ||
|
||
if (index != -1) | ||
selectionModel.Deselect(index); | ||
} | ||
} | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.DataItem; | ||
} | ||
|
||
protected override bool IsContentElementCore() => true; | ||
protected override bool IsControlElementCore() => true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters