调整继承属性和Windows触摸消息

This commit is contained in:
小红帽 2023-11-24 14:11:17 +08:00
parent 0bcf915d00
commit 5805df4d65
9 changed files with 171 additions and 67 deletions

View File

@ -657,6 +657,7 @@ namespace CPF.Windows
WM_USER = 0x0400, WM_USER = 0x0400,
WM_DISPATCH_WORK_ITEM = WM_USER, WM_DISPATCH_WORK_ITEM = WM_USER,
WM_TOUCH = 0x0240, WM_TOUCH = 0x0240,
WM_GESTURE = 0x0119,
//WM_PARENTNOTIFY = 0x0210, //WM_PARENTNOTIFY = 0x0210,
WM_NCPOINTERUPDATE = 0x0241, WM_NCPOINTERUPDATE = 0x0241,
WM_NCPOINTERDOWN = 0x0242, WM_NCPOINTERDOWN = 0x0242,

View File

@ -74,6 +74,7 @@ namespace CPF.Windows
} }
WNDCLASSEX wc = new WNDCLASSEX(); WNDCLASSEX wc = new WNDCLASSEX();
bool touchMsg;
public WindowImpl() public WindowImpl()
{ {
if (Window == null) if (Window == null)
@ -89,6 +90,10 @@ namespace CPF.Windows
{ {
isLayered = true; isLayered = true;
} }
if ((v.Major == 6 && v.Minor < 2))
{
touchMsg = RegisterTouchWindow(handle, RegisterTouchFlags.TWF_NONE);
}
_className = "CPFWindow-" + Guid.NewGuid(); _className = "CPFWindow-" + Guid.NewGuid();
// 初始化窗口类结构 // 初始化窗口类结构
wc.cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)); wc.cbSize = Marshal.SizeOf(typeof(WNDCLASSEX));
@ -707,6 +712,8 @@ namespace CPF.Windows
case WindowsMessage.WM_POINTERDOWN: case WindowsMessage.WM_POINTERDOWN:
case WindowsMessage.WM_POINTERUP: case WindowsMessage.WM_POINTERUP:
case WindowsMessage.WM_POINTERUPDATE: case WindowsMessage.WM_POINTERUPDATE:
if (!touchMsg)
{
var id = GetPointerId(wParam); var id = GetPointerId(wParam);
var position = GetPointerLocation(lParam); var position = GetPointerLocation(lParam);
position = PointToClient(position); position = PointToClient(position);
@ -731,36 +738,57 @@ namespace CPF.Windows
break; break;
} }
} }
}
break; break;
case WindowsMessage.WM_POINTERWHEEL: case WindowsMessage.WM_POINTERWHEEL:
Debug.WriteLine("WM_POINTERWHEEL"); Debug.WriteLine("WM_POINTERWHEEL");
break; break;
//case WindowsMessage.WM_TOUCH: case WindowsMessage.WM_GESTURE:
// { Debug.WriteLine("WM_GESTURE");
// var touchInputCount = wParam.ToInt32(); break;
// var pTouchInputs = stackalloc TOUCHINPUT[touchInputCount]; case WindowsMessage.WM_TOUCH:
// if (GetTouchInputInfo(lParam, (uint)touchInputCount, pTouchInputs, Marshal.SizeOf(typeof(TOUCHINPUT)))) if (touchMsg)
// { {
// for (int i = 0; i < touchInputCount; i++) var touchInputCount = wParam.ToInt32();
// { var pTouchInputs = stackalloc TOUCHINPUT[touchInputCount];
// var touchInput = pTouchInputs[i]; if (GetTouchInputInfo(lParam, (uint)touchInputCount, pTouchInputs, Marshal.SizeOf(typeof(TOUCHINPUT))))
{
for (int i = 0; i < touchInputCount; i++)
{
var input = pTouchInputs[i];
// //Input?.Invoke(new RawTouchEventArgs(_touchDevice, touchInput.Time, if ((input.Flags & TouchInputFlags.TOUCHEVENTF_DOWN) > 0)
// // _owner, {
// // touchInput.Flags.HasAllFlags(TouchInputFlags.TOUCHEVENTF_UP) ? Root.InputManager.TouchDevice.ProcessEvent(new TouchEventArgs(new TouchPoint
// // RawPointerEventType.TouchEnd : {
// // touchInput.Flags.HasAllFlags(TouchInputFlags.TOUCHEVENTF_DOWN) ? Id = (int)input.Id,
// // RawPointerEventType.TouchBegin : Position = new Point((float)(input.X * 0.01), (float)(input.Y * 0.01))
// // RawPointerEventType.TouchUpdate, }, Root.InputManager.TouchDevice, Root), Root.LayoutManager.VisibleUIElements, EventType.TouchDown);
// // PointToClient(new PixelPoint(touchInput.X / 100, touchInput.Y / 100)),
// // WindowsKeyboardDevice.Instance.Modifiers, }
// // touchInput.Id)); else if ((input.Flags & TouchInputFlags.TOUCHEVENTF_UP) > 0)
// } {
// CloseTouchInputHandle(lParam); Root.InputManager.TouchDevice.ProcessEvent(new TouchEventArgs(new TouchPoint
// return IntPtr.Zero; {
// } Id = (int)input.Id,
// break; Position = new Point((float)(input.X * 0.01), (float)(input.Y * 0.01))
// } }, Root.InputManager.TouchDevice, Root), Root.LayoutManager.VisibleUIElements, EventType.TouchUp);
}
else if ((input.Flags & TouchInputFlags.TOUCHEVENTF_MOVE) > 0)
{
Root.InputManager.TouchDevice.ProcessEvent(new TouchEventArgs(new TouchPoint
{
Id = (int)input.Id,
Position = new Point((float)(input.X * 0.01), (float)(input.Y * 0.01))
}, Root.InputManager.TouchDevice, Root), Root.LayoutManager.VisibleUIElements, EventType.TouchMove);
}
}
CloseTouchInputHandle(lParam);
return IntPtr.Zero;
}
}
break;
case UnmanagedMethods.WindowsMessage.WM_CLOSE: case UnmanagedMethods.WindowsMessage.WM_CLOSE:
bool? preventClosing = Closing?.Invoke(); bool? preventClosing = Closing?.Invoke();
if (preventClosing == true) if (preventClosing == true)
@ -1692,7 +1720,6 @@ namespace CPF.Windows
public void SetVisible(bool visible) public void SetVisible(bool visible)
{ {
//var v = IsWindowVisible(handle); //var v = IsWindowVisible(handle);
root.InputManager.TouchDevice.ClearPoints();
if (visible) if (visible)
{ {
if (windowState == WindowState.Normal) if (windowState == WindowState.Normal)

View File

@ -330,7 +330,14 @@ namespace CPF
} }
return b; return b;
} }
//public static BindingDescribe operator *(BindingDescribe property1, string property2)
//{
// return null;
//}
//public static BindingDescribe operator *(BindingDescribe property1, BindingDescribe property2)
//{
// return null;
//}
public BindingMode BindingMode { get; set; } = BindingMode.OneWay; public BindingMode BindingMode { get; set; } = BindingMode.OneWay;
public object Source { get; set; } public object Source { get; set; }

View File

@ -149,6 +149,25 @@ namespace CPF.Controls
{ {
base.OnOverrideMetadata(overridePropertys); base.OnOverrideMetadata(overridePropertys);
overridePropertys.Override(nameof(Height), new UIPropertyMetadataAttribute((FloatField)"100%", UIPropertyOptions.AffectsMeasure)); overridePropertys.Override(nameof(Height), new UIPropertyMetadataAttribute((FloatField)"100%", UIPropertyOptions.AffectsMeasure));
} //overridePropertys.Override(nameof(DataContext), new UIPropertyMetadataAttribute(null, false));
}
//protected override void OnLayoutUpdated()
//{
// base.OnLayoutUpdated();
// if (Root.LayoutManager.IsVisible(this))
// {
// DataContext = Row.DataContext;
// }
//}
//protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
//{
// if (propertyName == nameof(DataContext))
// {
// }
// base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
//}
} }
} }

View File

@ -860,6 +860,7 @@ namespace CPF.Controls
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata); base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
if (propertyName == nameof(Visibility)) if (propertyName == nameof(Visibility))
{ {
InputManager.TouchDevice.ClearPoints();
viewImpl.SetVisible((Visibility)newValue == Visibility.Visible); viewImpl.SetVisible((Visibility)newValue == Visibility.Visible);
} }
if (!onChecked && radioButtonGroupProperty != null && radiobuttons != null && radioButtonGroupProperty.TryGetValue(propertyName, out var group)) if (!onChecked && radioButtonGroupProperty != null && radiobuttons != null && radioButtonGroupProperty.TryGetValue(propertyName, out var group))

View File

@ -24,17 +24,20 @@ namespace CPF
static ConcurrentDictionary<Type, ObjInfo> typeCache = new ConcurrentDictionary<Type, ObjInfo>(); static ConcurrentDictionary<Type, ObjInfo> typeCache = new ConcurrentDictionary<Type, ObjInfo>();
static ConcurrentDictionary<Type, PropertyMetadataAttribute[]> typePropertyCache = new ConcurrentDictionary<Type, PropertyMetadataAttribute[]>(); static ConcurrentDictionary<Type, PropertyMetadataAttribute[]> typePropertyCache = new ConcurrentDictionary<Type, PropertyMetadataAttribute[]>();
static ConcurrentDictionary<Type, HashSet<string>> inheritsProperties = new ConcurrentDictionary<Type, HashSet<string>>(); static ConcurrentDictionary<Type, HashSet<string>> inheritsProperties = new ConcurrentDictionary<Type, HashSet<string>>();
static ConcurrentDictionary<Type, HashSet<string>> breakInheritsProperties = new ConcurrentDictionary<Type, HashSet<string>>();
static ConcurrentDictionary<Type, List<MethodInfo>> propertyChangedMethods = new ConcurrentDictionary<Type, List<MethodInfo>>(); static ConcurrentDictionary<Type, List<MethodInfo>> propertyChangedMethods = new ConcurrentDictionary<Type, List<MethodInfo>>();
static KeyValuePair<Type, ObjInfo>[] saveTypeCache; static KeyValuePair<Type, ObjInfo>[] saveTypeCache;
static KeyValuePair<Type, PropertyMetadataAttribute[]>[] saveTypePropertyCache; static KeyValuePair<Type, PropertyMetadataAttribute[]>[] saveTypePropertyCache;
static KeyValuePair<Type, HashSet<string>>[] saveInheritsProperties; static KeyValuePair<Type, HashSet<string>>[] saveInheritsProperties;
static KeyValuePair<Type, HashSet<string>>[] saveBreakInheritsProperties;
static KeyValuePair<Type, List<MethodInfo>>[] savePropertyChangedMethods; static KeyValuePair<Type, List<MethodInfo>>[] savePropertyChangedMethods;
public static void SetTypeCache() public static void SetTypeCache()
{ {
saveTypeCache = typeCache.ToArray(); saveTypeCache = typeCache.ToArray();
saveTypePropertyCache = typePropertyCache.ToArray(); saveTypePropertyCache = typePropertyCache.ToArray();
saveInheritsProperties = inheritsProperties.ToArray(); saveInheritsProperties = inheritsProperties.ToArray();
saveBreakInheritsProperties = breakInheritsProperties.ToArray();
FastReflectionExtensions.SetTypeCache(); FastReflectionExtensions.SetTypeCache();
savePropertyChangedMethods = propertyChangedMethods.ToArray(); savePropertyChangedMethods = propertyChangedMethods.ToArray();
} }
@ -67,6 +70,15 @@ namespace CPF
} }
saveInheritsProperties = null; saveInheritsProperties = null;
} }
if (saveBreakInheritsProperties != null)
{
breakInheritsProperties.Clear();
foreach (var item in saveBreakInheritsProperties)
{
breakInheritsProperties.TryAdd(item.Key, item.Value);
}
saveBreakInheritsProperties = null;
}
if (savePropertyChangedMethods != null) if (savePropertyChangedMethods != null)
{ {
propertyChangedMethods.Clear(); propertyChangedMethods.Clear();
@ -87,9 +99,13 @@ namespace CPF
internal HybridDictionary<string, object> attachedValues; internal HybridDictionary<string, object> attachedValues;
/// <summary> /// <summary>
/// 继承属性的特性 /// 继承属性不同继承类型分支下来的属性名可能相同但是属性ID不同只能保存属性名
/// </summary> /// </summary>
internal HashSet<string> inheritsPropertyName; internal HashSet<string> inheritsPropertyName;
/// <summary>
/// 终止继承属性不同继承类型分支下来的属性名可能相同但是属性ID不同只能保存属性名
/// </summary>
internal HashSet<string> breakInheritsPropertyName;
AttachedProperties attached; AttachedProperties attached;
/// <summary> /// <summary>
@ -326,18 +342,31 @@ namespace CPF
typePropertyCache.TryAdd(type, propertyList.ToArray()); typePropertyCache.TryAdd(type, propertyList.ToArray());
var l = new HashSet<string>(); var l = new HashSet<string>();
var b = new HashSet<string>();
foreach (var item in objInfo) foreach (var item in objInfo)
{ {
if (item.Value is UIPropertyMetadataAttribute attribute && attribute.Inherits) if (item.Value is UIPropertyMetadataAttribute attribute)
{
if (attribute.Inherits)
{ {
l.Add(attribute.PropertyName); l.Add(attribute.PropertyName);
} }
else
{
b.Add(attribute.PropertyName);
}
}
} }
if (l.Count == 0) if (l.Count == 0)
{ {
l = null; l = null;
} }
if (b.Count == 0)
{
b = null;
}
inheritsProperties.TryAdd(type, l); inheritsProperties.TryAdd(type, l);
breakInheritsProperties.TryAdd(type, b);
//Type tt = typeof(PropertyChangedAttribute); //Type tt = typeof(PropertyChangedAttribute);
//var ms = type.FindMembers(MemberTypes.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, (a, b) => a.CustomAttributes.Any(c => c.AttributeType == tt), null); //var ms = type.FindMembers(MemberTypes.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, (a, b) => a.CustomAttributes.Any(c => c.AttributeType == tt), null);
@ -443,6 +472,8 @@ namespace CPF
//valueIndexs = new ByteArray((byte)objInfo.Count); //valueIndexs = new ByteArray((byte)objInfo.Count);
valueIndexs = new byte[objInfo.Count]; valueIndexs = new byte[objInfo.Count];
inheritsPropertyName = inheritsProperties[type]; inheritsPropertyName = inheritsProperties[type];
breakInheritsPropertyName = breakInheritsProperties[type];
if (objInfo.Computed != null) if (objInfo.Computed != null)
{ {
foreach (var item in objInfo.Computed) foreach (var item in objInfo.Computed)

View File

@ -213,7 +213,6 @@ namespace CPF.Design
public void SetVisible(bool visible) public void SetVisible(bool visible)
{ {
root.InputManager.TouchDevice.ClearPoints();
root.LayoutManager.ExecuteLayoutPass(); root.LayoutManager.ExecuteLayoutPass();
root.Invalidate(); root.Invalidate();
} }

View File

@ -99,7 +99,7 @@ namespace CPF
{ {
if (item.IsDisposed) if (item.IsDisposed)
{ {
break; continue;
} }
var rect = GetRect(item.Parent, item.GetContentBounds(), item); var rect = GetRect(item.Parent, item.GetContentBounds(), item);
rect.Intersect(new Rect(new Point(), item.ActualSize)); rect.Intersect(new Rect(new Point(), item.ActualSize));

View File

@ -1372,29 +1372,41 @@ namespace CPF
} }
} }
} }
/// <summary>
/// 继承属性需要一级级传递,直到没有元素或者取消继承为止
/// </summary>
/// <param name="element"></param>
/// <param name="propertyName"></param>
/// <param name="oldValue"></param>
/// <param name="newValue"></param>
void Inherits(UIElement element, string propertyName, object oldValue, object newValue) void Inherits(UIElement element, string propertyName, object oldValue, object newValue)
{ {
if (!element.HasLocalOrStyleValue(propertyName, out var p)) if (!element.HasLocalOrStyleValue(propertyName, out var p))
{ {
element.inheritsSet = true;
//var p = element.GetPropertyMetadata(propertyName); //var p = element.GetPropertyMetadata(propertyName);
if (p != null)
{ var ui = p as UIPropertyMetadataAttribute;
if (p is UIPropertyMetadataAttribute ui && ui.Inherits) if (ui != null && ui.Inherits)
{ {
element.inheritsSet = true;
element.inheritsValues.Remove(propertyName); element.inheritsValues.Remove(propertyName);
element.inheritsValues.Add(propertyName, new InheritsValue { Value = newValue, ValueForm = ValueFrom.Property }); element.inheritsValues.Add(propertyName, new InheritsValue { Value = newValue, ValueForm = ValueFrom.Property });
}
element.OnPropertyChanged(propertyName, oldValue, newValue, p); element.OnPropertyChanged(propertyName, oldValue, newValue, p);
}
element.inheritsSet = false; element.inheritsSet = false;
//if (propertyName != nameof(DataContext) || !element.HasLocalOrStyleValue(propertyName, out p))
//{
for (int i = 0; i < element.Children.Count; i++) for (int i = 0; i < element.Children.Count; i++)
{ {
Inherits(element.children[i], propertyName, oldValue, newValue); Inherits(element.children[i], propertyName, oldValue, newValue);
} }
}
else if (ui == null)
{
for (int i = 0; i < element.Children.Count; i++)
{
Inherits(element.children[i], propertyName, oldValue, newValue);
}
}
//if (propertyName != nameof(DataContext) || !element.HasLocalOrStyleValue(propertyName, out p))
//{
//} //}
} }
} }
@ -2480,6 +2492,9 @@ namespace CPF
viewRenderRect = true; viewRenderRect = true;
} }
} }
/// <summary>
/// 是否需要更新渲染区域
/// </summary>
[NotCpfProperty] [NotCpfProperty]
internal bool viewRenderRect { get { return GetFlag(CoreFlags.viewRenderRect); } set { SetFlag(CoreFlags.viewRenderRect, value); } } internal bool viewRenderRect { get { return GetFlag(CoreFlags.viewRenderRect); } set { SetFlag(CoreFlags.viewRenderRect, value); } }
//protected virtual void ArrangeCore(in Rect finalRect) //protected virtual void ArrangeCore(in Rect finalRect)
@ -3441,7 +3456,7 @@ namespace CPF
} }
break; break;
} }
else if (p.HasLocalOrStyleValue(item, out _)) else if (p.HasLocalOrStyleValue(item, out var pa))
{ {
var value = p.GetValue(item); var value = p.GetValue(item);
var old = GetValue(item); var old = GetValue(item);
@ -3457,6 +3472,10 @@ namespace CPF
} }
} }
} }
if (p.breakInheritsPropertyName != null && p.breakInheritsPropertyName.Contains(item))
{
break;
}
p = p.Parent; p = p.Parent;
} }
} }