Skip to content

Commit f491c97

Browse files
committed
feat: ComboBox.IsEditable
1 parent bb05811 commit f491c97

File tree

6 files changed

+65
-33
lines changed

6 files changed

+65
-33
lines changed

src/Uno.UI/DirectUI/XboxUtility.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Windows.System;
7+
8+
namespace DirectUI;
9+
10+
internal static class XboxUtility
11+
{
12+
internal static bool IsGamepadNavigationInput(VirtualKey key)
13+
{
14+
return (int)key >= (int)VirtualKey.GamepadA && (int)key <= (int)VirtualKey.GamepadRightThumbstickLeft;
15+
}
16+
}

src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.Properties.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ public object Header
4949
typeof(ComboBox),
5050
new FrameworkPropertyMetadata(
5151
defaultValue: null,
52-
options: FrameworkPropertyMetadataOptions.None,
53-
propertyChangedCallback: (s, e) => ((ComboBox)s)?.UpdateHeaderVisibility()
54-
)
55-
);
52+
options: FrameworkPropertyMetadataOptions.None));
5653

5754
/// <summary>
5855
/// Gets or sets the DataTemplate used to display the content of the control's header.
@@ -73,10 +70,7 @@ public DataTemplate HeaderTemplate
7370
typeof(ComboBox),
7471
new FrameworkPropertyMetadata(
7572
defaultValue: null,
76-
options: FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext,
77-
propertyChangedCallback: (s, e) => ((ComboBox)s)?.UpdateHeaderVisibility()
78-
)
79-
);
73+
options: FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext));
8074

8175
/// <summary>
8276
/// Gets or sets a value that indicates whether the user can

src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public partial class ComboBox : Selector
5454
private int m_indexForcedToUnselectedVisual = -1;
5555
private int m_indexForcedToSelectedVisual = -1;
5656

57-
private bool _wasPointerPressed;
58-
5957
/// <summary>
6058
/// The 'inline' parent view of the selected item within the dropdown list. This is only set if SelectedItem is a view type.
6159
/// </summary>

src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.partial.h.mux.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ namespace Microsoft.UI.Xaml.Controls;
1212

1313
partial class ComboBox
1414
{
15-
private bool m_isInSearchingMode;
15+
#pragma warning disable CS0649 // never assigned to, and will always have its default value false
16+
#pragma warning disable CS0414 // never assigned to, and will always have its default value false
17+
private bool m_handledGamepadOrRemoteKeyDown;
1618
private bool m_ignoreCancelKeyDowns;
1719
private bool m_isEditModeConfigured;
20+
private bool m_isInSearchingMode;
1821

1922
// On pointer released we perform some actions depending on control. We decide to whether to perform them
2023
// depending on some parameters including but not limited to whether released is followed by a pressed, which

src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.partial.mux.cs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
using System;
44
using System.Collections.Generic;
5-
using System.Linq;
65
using DirectUI;
76
using Microsoft.UI.Input;
87
using Microsoft.UI.Xaml.Controls.Primitives;
@@ -70,10 +69,10 @@ private void SetupEditableMode()
7069
if (m_tpDropDownOverlayPart is not null)
7170
{
7271
m_tpDropDownOverlayPart.PointerEntered += OnDropDownOverlayPointerEntered;
73-
m_spDropDownOverlayPointerEnteredHandler.Disposable = Disposable.Create(() => m_tpContentPresenterPart.PointerEntered -= OnDropDownOverlayPointerEntered);
72+
m_spDropDownOverlayPointerEnteredHandler.Disposable = Disposable.Create(() => m_tpDropDownOverlayPart.PointerEntered -= OnDropDownOverlayPointerEntered);
7473

7574
m_tpDropDownOverlayPart.PointerExited += OnDropDownOverlayPointerExited;
76-
m_spDropDownOverlayPointerExitedHandler.Disposable = Disposable.Create(() => m_tpContentPresenterPart.PointerExited -= OnDropDownOverlayPointerExited);
75+
m_spDropDownOverlayPointerExitedHandler.Disposable = Disposable.Create(() => m_tpDropDownOverlayPart.PointerExited -= OnDropDownOverlayPointerExited);
7776

7877
m_tpDropDownOverlayPart.Visibility = Visibility.Visible;
7978
}
@@ -86,13 +85,14 @@ private void SetupEditableMode()
8685
ResetSearch();
8786
ResetSearchString();
8887

89-
wrl::ComPtr<xaml_controls::IInputValidationContext> context;
90-
get_ValidationContext(&context));
91-
pEditableTextPartAsTextBox.ValidationContext(context.Get()));
88+
// TODO Uno: Input validation support #4839
89+
//wrl::ComPtr<xaml_controls::IInputValidationContext> context;
90+
//get_ValidationContext(&context));
91+
//pEditableTextPartAsTextBox.ValidationContext(context.Get()));
9292

93-
wrl::ComPtr<xaml_controls::IInputValidationCommand> command;
94-
get_ValidationCommand(&command));
95-
pEditableTextPartAsTextBox->put_ValidationCommand(command.Get()));
93+
//wrl::ComPtr<xaml_controls::IInputValidationCommand> command;
94+
//get_ValidationCommand(&command));
95+
//pEditableTextPartAsTextBox->put_ValidationCommand(command.Get()));
9696

9797
if (m_tpPopupPart is not null)
9898
{
@@ -129,10 +129,8 @@ private void DisableEditableMode()
129129

130130
if (m_tpDropDownOverlayPart is not null)
131131
{
132-
var pDropDownOverlayPartAsI = iinspectable_cast(m_tpDropDownOverlayPart.Cast<Border>());
133-
134-
m_spDropDownOverlayPointerEnteredHandler.DetachEventHandler(pDropDownOverlayPartAsI));
135-
m_spDropDownOverlayPointerExitedHandler.DetachEventHandler(pDropDownOverlayPartAsI));
132+
m_spDropDownOverlayPointerEnteredHandler.Disposable = null;
133+
m_spDropDownOverlayPointerExitedHandler.Disposable = null;
136134

137135
m_tpDropDownOverlayPart.Visibility = Visibility.Collapsed;
138136
}
@@ -621,7 +619,7 @@ private void UpdateEditableContentPresenterTextBlock(object item)
621619
}
622620

623621
EnsurePropertyPathListener();
624-
var itemString = TryGetStringValue(item) //, m_spPropertyPathListener); TODO Uno: Missing PropertyPathListener support
622+
var itemString = TryGetStringValue(item); //, m_spPropertyPathListener); TODO Uno: Missing PropertyPathListener support
625623
UpdateEditableContentPresenterTextBlock(itemString);
626624
}
627625

@@ -699,17 +697,15 @@ private void CommitRevertEditableSearch(bool restoreValue)
699697

700698
if (m_customValueRef is not null)
701699
{
702-
wrl_wrappers::HString storedString;
703-
IValueBoxer::UnboxValue(m_customValueRef.Get(), storedString.GetAddressOf());
700+
var storedString = m_customValueRef as string;
704701

705702
// Prevent sending the event if the custom value is the same.
706703
sendEvent = !AreStringsEqual(storedString, searchString);
707704
}
708705

709706
if (sendEvent)
710707
{
711-
ctl::ComPtr<IInspectable> spInspectable;
712-
PropertyValue::CreateFromString(searchString, &spInspectable));
708+
var spInspectable = searchString;
713709

714710
bool isHandled = RaiseTextSubmittedEvent(searchString);
715711

@@ -845,7 +841,6 @@ private void OnKeyDownPrivate(object pSender, KeyRoutedEventArgs pArgs)
845841
m_handledGamepadOrRemoteKeyDown = eventHandled && XboxUtility.IsGamepadNavigationInput(originalKey);
846842
}
847843

848-
849844
private void OnTextBoxTextChanged(object sender, TextChangedEventArgs args)
850845
{
851846
//DEAD_CODE_REMOVAL
@@ -893,7 +888,7 @@ protected override void OnPointerEntered(PointerRoutedEventArgs e)
893888

894889
if (isEventSourceTarget)
895890
{
896-
m_isPointerOverMain = true;
891+
m_IsPointerOverMain = true;
897892
m_bIsPressed = false;
898893
UpdateVisualState();
899894
}
@@ -1434,7 +1429,7 @@ private bool StartsWithIgnoreLinguisticSemantics(string strSource, string strPre
14341429
return strSource.StartsWith(strPrefix, StringComparison.InvariantCultureIgnoreCase);
14351430
}
14361431

1437-
private bool AreStringsEqual(string str1, string str2) => string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase);
1432+
private bool AreStringsEqual(string? str1, string? str2) => string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase);
14381433

14391434
private bool IsSearchStringValid(string str)
14401435
{
@@ -1628,7 +1623,7 @@ private bool IsChildOfTarget(
16281623
return result;
16291624
}
16301625

1631-
private InputDeviceType GetInputDeviceTypeUsedToOpen() => m_inputDeviceTypeUsedToOpen;
1626+
internal InputDeviceType GetInputDeviceTypeUsedToOpen() => m_inputDeviceTypeUsedToOpen;
16321627

16331628
private void OverrideSelectedIndexForVisualStates(int selectedIndexOverride)
16341629
{
@@ -1736,4 +1731,21 @@ private void CreateEditableContentPresenterTextBlock()
17361731
m_tpEditableContentPresenterTextBlock = spTextBlock;
17371732
}
17381733
}
1734+
1735+
1736+
#if HAS_UNO // Not ported yet
1737+
private void SetContentPresenter(int value) { }
1738+
1739+
private void PopupKeyDown(KeyRoutedEventArgs args) { }
1740+
1741+
private void MainKeyDown(KeyRoutedEventArgs args) { }
1742+
1743+
private void ArrangePopup(bool value) { }
1744+
1745+
private void EnsurePresenterReadyForFullMode() { }
1746+
1747+
private void EnsurePresenterReadyForInlineMode() { }
1748+
1749+
private void ForceApplyInlineLayoutUpdate() { }
1750+
#endif
17391751
}

src/Uno.UI/UI/Xaml/Controls/Popup/Popup.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ public PopupPlacementMode DesiredPlacement
218218
typeof(Popup),
219219
new FrameworkPropertyMetadata(PopupPlacementMode.Auto, FrameworkPropertyMetadataOptions.AffectsArrange));
220220

221+
internal DependencyObject OverlayInputPassThroughElement
222+
{
223+
get => (DependencyObject)GetValue(OverlayInputPassThroughElementProperty);
224+
set => SetValue(OverlayInputPassThroughElementProperty, value);
225+
}
226+
227+
internal static DependencyProperty OverlayInputPassThroughElementProperty { get; } =
228+
DependencyProperty.Register(nameof(OverlayInputPassThroughElement), typeof(DependencyObject), typeof(Popup), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext));
229+
221230
/// <summary>
222231
/// Gets the actual placement of the popup, in relation to its placement target.
223232
/// </summary>

0 commit comments

Comments
 (0)