Browse Source

Removed Preview* tunneling events.

You need to call AddHandler to get to them now.
pull/39/head
Steven Kirk 11 years ago
parent
commit
01e97aec7e
  1. 9
      Perspex.Controls/Popup.cs
  2. 6
      Perspex.Diagnostics/DevTools.cs
  3. 43
      Perspex.Input/InputElement.cs
  4. 4
      Perspex.Input/KeyboardDevice.cs
  5. 4
      Perspex.Input/MouseDevice.cs
  6. 13
      Perspex.Interactivity/Interactive.cs

9
Perspex.Controls/Popup.cs

@ -92,8 +92,13 @@ namespace Perspex.Controls
this.popupRoot.SetPosition(this.GetPosition()); this.popupRoot.SetPosition(this.GetPosition());
this.popupRoot.PointerPressed += this.MaybeClose; this.popupRoot.PointerPressed += this.MaybeClose;
this.topLevel.PreviewPointerPressed += this.MaybeClose;
this.topLevel.Deactivated += this.MaybeClose; this.topLevel.Deactivated += this.MaybeClose;
this.topLevel.AddHandler(
TopLevel.PointerPressedEvent,
(EventHandler<RoutedEventArgs>)this.MaybeClose,
RoutingStrategies.Tunnel);
this.popupRoot.Show(); this.popupRoot.Show();
} }
@ -102,7 +107,7 @@ namespace Perspex.Controls
if (this.popupRoot != null) if (this.popupRoot != null)
{ {
this.popupRoot.PointerPressed -= this.MaybeClose; this.popupRoot.PointerPressed -= this.MaybeClose;
this.topLevel.PreviewPointerPressed -= this.MaybeClose; this.topLevel.RemoveHandler(TopLevel.PointerPressedEvent, (EventHandler<RoutedEventArgs>)this.MaybeClose);
this.topLevel.Deactivated -= this.MaybeClose; this.topLevel.Deactivated -= this.MaybeClose;
this.popupRoot.Hide(); this.popupRoot.Hide();
} }

6
Perspex.Diagnostics/DevTools.cs

@ -108,8 +108,10 @@ namespace Perspex.Diagnostics
public static IDisposable Attach(Window w) public static IDisposable Attach(Window w)
{ {
w.PreviewKeyDown += WindowPreviewKeyDown; return w.AddHandler(
return Disposable.Create(() => w.PreviewKeyDown -= WindowPreviewKeyDown); Window.KeyDownEvent,
(EventHandler<KeyEventArgs>)WindowPreviewKeyDown,
Interactivity.RoutingStrategies.Tunnel);
} }
private static void WindowPreviewKeyDown(object sender, KeyEventArgs e) private static void WindowPreviewKeyDown(object sender, KeyEventArgs e)

43
Perspex.Input/InputElement.cs

@ -36,13 +36,9 @@ namespace Perspex.Input
RoutedEvent.Register<InputElement, RoutedEventArgs>("LostFocus", RoutingStrategies.Bubble); RoutedEvent.Register<InputElement, RoutedEventArgs>("LostFocus", RoutingStrategies.Bubble);
public static readonly RoutedEvent<KeyEventArgs> KeyDownEvent = public static readonly RoutedEvent<KeyEventArgs> KeyDownEvent =
RoutedEvent.Register<InputElement, KeyEventArgs>("KeyDown", RoutingStrategies.Bubble); RoutedEvent.Register<InputElement, KeyEventArgs>(
"KeyDown",
public static readonly RoutedEvent<KeyEventArgs> PreviewKeyDownEvent = RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
RoutedEvent.Register<InputElement, KeyEventArgs>("PreviewKeyDown", RoutingStrategies.Tunnel);
public static readonly RoutedEvent<PointerPressEventArgs> PreviewPointerPressedEvent =
RoutedEvent.Register<InputElement, PointerPressEventArgs>("PreviewPointerPressed", RoutingStrategies.Tunnel);
public static readonly RoutedEvent<PointerEventArgs> PointerEnterEvent = public static readonly RoutedEvent<PointerEventArgs> PointerEnterEvent =
RoutedEvent.Register<InputElement, PointerEventArgs>("PointerEnter", RoutingStrategies.Direct); RoutedEvent.Register<InputElement, PointerEventArgs>("PointerEnter", RoutingStrategies.Direct);
@ -51,16 +47,24 @@ namespace Perspex.Input
RoutedEvent.Register<InputElement, PointerEventArgs>("PointerLeave", RoutingStrategies.Direct); RoutedEvent.Register<InputElement, PointerEventArgs>("PointerLeave", RoutingStrategies.Direct);
public static readonly RoutedEvent<PointerEventArgs> PointerMovedEvent = public static readonly RoutedEvent<PointerEventArgs> PointerMovedEvent =
RoutedEvent.Register<InputElement, PointerEventArgs>("PointerMove", RoutingStrategies.Bubble); RoutedEvent.Register<InputElement, PointerEventArgs>(
"PointerMove",
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
public static readonly RoutedEvent<PointerPressEventArgs> PointerPressedEvent = public static readonly RoutedEvent<PointerPressEventArgs> PointerPressedEvent =
RoutedEvent.Register<InputElement, PointerPressEventArgs>("PointerPressed", RoutingStrategies.Bubble); RoutedEvent.Register<InputElement, PointerPressEventArgs>(
"PointerPressed",
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
public static readonly RoutedEvent<PointerEventArgs> PointerReleasedEvent = public static readonly RoutedEvent<PointerEventArgs> PointerReleasedEvent =
RoutedEvent.Register<InputElement, PointerEventArgs>("PointerReleased", RoutingStrategies.Bubble); RoutedEvent.Register<InputElement, PointerEventArgs>(
"PointerReleased",
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
public static readonly RoutedEvent<PointerWheelEventArgs> PointerWheelChangedEvent = public static readonly RoutedEvent<PointerWheelEventArgs> PointerWheelChangedEvent =
RoutedEvent.Register<InputElement, PointerWheelEventArgs>("PointerWheelChanged", RoutingStrategies.Bubble); RoutedEvent.Register<InputElement, PointerWheelEventArgs>(
"PointerWheelChanged",
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
static InputElement() static InputElement()
{ {
@ -69,7 +73,6 @@ namespace Perspex.Input
GotFocusEvent.AddClassHandler<InputElement>(x => x.OnGotFocus, RoutingStrategies.Bubble); GotFocusEvent.AddClassHandler<InputElement>(x => x.OnGotFocus, RoutingStrategies.Bubble);
LostFocusEvent.AddClassHandler<InputElement>(x => x.OnLostFocus, RoutingStrategies.Bubble); LostFocusEvent.AddClassHandler<InputElement>(x => x.OnLostFocus, RoutingStrategies.Bubble);
KeyDownEvent.AddClassHandler<InputElement>(x => x.OnKeyDown, RoutingStrategies.Bubble); KeyDownEvent.AddClassHandler<InputElement>(x => x.OnKeyDown, RoutingStrategies.Bubble);
PreviewKeyDownEvent.AddClassHandler<InputElement>(x => x.OnPreviewKeyDown, RoutingStrategies.Tunnel);
PointerEnterEvent.AddClassHandler<InputElement>(x => x.OnPointerEnter, RoutingStrategies.Direct); PointerEnterEvent.AddClassHandler<InputElement>(x => x.OnPointerEnter, RoutingStrategies.Direct);
PointerLeaveEvent.AddClassHandler<InputElement>(x => x.OnPointerLeave, RoutingStrategies.Direct); PointerLeaveEvent.AddClassHandler<InputElement>(x => x.OnPointerLeave, RoutingStrategies.Direct);
PointerMovedEvent.AddClassHandler<InputElement>(x => x.OnPointerMoved, RoutingStrategies.Bubble); PointerMovedEvent.AddClassHandler<InputElement>(x => x.OnPointerMoved, RoutingStrategies.Bubble);
@ -96,18 +99,6 @@ namespace Perspex.Input
remove { this.RemoveHandler(KeyDownEvent, value); } remove { this.RemoveHandler(KeyDownEvent, value); }
} }
public event EventHandler<KeyEventArgs> PreviewKeyDown
{
add { this.AddHandler(PreviewKeyDownEvent, value); }
remove { this.RemoveHandler(PreviewKeyDownEvent, value); }
}
public event EventHandler<PointerPressEventArgs> PreviewPointerPressed
{
add { this.AddHandler(PreviewPointerPressedEvent, value); }
remove { this.RemoveHandler(PreviewPointerPressedEvent, value); }
}
public event EventHandler<PointerEventArgs> PointerEnter public event EventHandler<PointerEventArgs> PointerEnter
{ {
add { this.AddHandler(PointerEnterEvent, value); } add { this.AddHandler(PointerEnterEvent, value); }
@ -211,10 +202,6 @@ namespace Perspex.Input
{ {
} }
protected virtual void OnPreviewKeyDown(KeyEventArgs e)
{
}
protected virtual void OnPointerEnter(PointerEventArgs e) protected virtual void OnPointerEnter(PointerEventArgs e)
{ {
this.IsPointerOver = true; this.IsPointerOver = true;

4
Perspex.Input/KeyboardDevice.cs

@ -51,7 +51,7 @@ namespace Perspex.Input
case RawKeyEventType.KeyDown: case RawKeyEventType.KeyDown:
KeyEventArgs ev = new KeyEventArgs KeyEventArgs ev = new KeyEventArgs
{ {
RoutedEvent = InputElement.PreviewKeyDownEvent, RoutedEvent = InputElement.KeyDownEvent,
Device = this, Device = this,
Key = e.Key, Key = e.Key,
Text = e.Text, Text = e.Text,
@ -59,8 +59,6 @@ namespace Perspex.Input
OriginalSource = element, OriginalSource = element,
}; };
element.RaiseEvent(ev);
ev.RoutedEvent = InputElement.KeyDownEvent;
element.RaiseEvent(ev); element.RaiseEvent(ev);
break; break;
} }

4
Perspex.Input/MouseDevice.cs

@ -131,15 +131,13 @@ namespace Perspex.Input
var e = new PointerPressEventArgs var e = new PointerPressEventArgs
{ {
Device = this, Device = this,
RoutedEvent = InputElement.PreviewPointerPressedEvent, RoutedEvent = InputElement.PointerPressedEvent,
OriginalSource = source, OriginalSource = source,
Source = source, Source = source,
ClickCount = this.clickCount, ClickCount = this.clickCount,
}; };
source.RaiseEvent(e); source.RaiseEvent(e);
e.RoutedEvent = InputElement.PointerPressedEvent;
source.RaiseEvent(e);
} }
IInputElement focusable = this.GetFocusable(hit); IInputElement focusable = this.GetFocusable(hit);

13
Perspex.Interactivity/Interactive.cs

@ -10,6 +10,7 @@ namespace Perspex.Interactivity
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using Perspex.Layout; using Perspex.Layout;
using Perspex.VisualTree; using Perspex.VisualTree;
@ -19,7 +20,7 @@ namespace Perspex.Interactivity
private Dictionary<RoutedEvent, List<EventSubscription>> eventHandlers = private Dictionary<RoutedEvent, List<EventSubscription>> eventHandlers =
new Dictionary<RoutedEvent, List<EventSubscription>>(); new Dictionary<RoutedEvent, List<EventSubscription>>();
public void AddHandler( public IDisposable AddHandler(
RoutedEvent routedEvent, RoutedEvent routedEvent,
Delegate handler, Delegate handler,
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
@ -36,12 +37,16 @@ namespace Perspex.Interactivity
this.eventHandlers.Add(routedEvent, subscriptions); this.eventHandlers.Add(routedEvent, subscriptions);
} }
subscriptions.Add(new EventSubscription var sub = new EventSubscription
{ {
Handler = handler, Handler = handler,
Routes = routes, Routes = routes,
AlsoIfHandled = handledEventsToo, AlsoIfHandled = handledEventsToo,
}); };
subscriptions.Add(sub);
return Disposable.Create(() => subscriptions.Remove(sub));
} }
public IObservable<EventPattern<T>> GetObservable<T>(RoutedEvent<T> routedEvent) where T : RoutedEventArgs public IObservable<EventPattern<T>> GetObservable<T>(RoutedEvent<T> routedEvent) where T : RoutedEventArgs
@ -125,7 +130,7 @@ namespace Perspex.Interactivity
if (this.eventHandlers.TryGetValue(e.RoutedEvent, out subscriptions)) if (this.eventHandlers.TryGetValue(e.RoutedEvent, out subscriptions))
{ {
foreach (var sub in subscriptions) foreach (var sub in subscriptions.ToList())
{ {
bool correctRoute = bool correctRoute =
(e.Route == RoutingStrategies.Direct && sub.Routes == RoutingStrategies.Direct) || (e.Route == RoutingStrategies.Direct && sub.Routes == RoutingStrategies.Direct) ||

Loading…
Cancel
Save