|
using System;
namespace GFramework
{
public abstract class GNode : GDisposableObject, IGEventListener, IComparable
{
#region Constructor
public GNode()
{
}
#endregion
#region Interface Implementation
#region IGEventListener
void IGEventListener.PreviewEvent(GEventArgs e)
{
OnPreviewEvent(e);
}
#endregion
#region IComparable
public int CompareTo(object obj)
{
GNode node = obj as GNode;
if (node == null)
{
throw new ArgumentException("May compare to GNode instances only.");
}
return CompareCore(node);
}
#endregion
#endregion
#region Public Methods
public GNode GetAncestor(int level)
{
if (level <= 0)
{
return null;
}
GNode parent = m_Parent;
level--;
while (level > 0)
{
parent = parent.m_Parent;
level--;
}
return parent;
}
#endregion
#region Public Overrides
public override bool GetCanRaiseEvents()
{
if (m_Root != null && m_Root.m_InitializeLock > 0)
{
return false;
}
return base.GetCanRaiseEvents();
}
#endregion
#region Protected Overridables
protected internal virtual void OnParentChanged(GElement parent)
{
m_Parent = parent;
if (m_Parent == null)
{
SetRoot(null);
}
}
protected internal virtual void SetRoot(GRootElement root)
{
m_Root = root;
}
protected internal virtual void BubbleEvent(GEventArgs e)
{
//no parent to bubble to
if (m_Parent == null)
{
return;
}
//bubble process has been explicitly canceled
if ((e.m_Result & EventResult.Cancel) == EventResult.Cancel)
{
return;
}
e.m_Sender = this;
m_Parent.OnBubbleEvent(e);
}
protected internal virtual void TunnelEvent(GEventArgs e)
{
}
protected internal virtual void OnBubbleEvent(GEventArgs e)
{
BubbleEvent(e);
}
protected internal virtual void OnTunnelEvent(GEventArgs e)
{
TunnelEvent(e);
}
protected virtual void OnPreviewEvent(GEventArgs e)
{
}
protected virtual int CompareCore(GNode node)
{
return 0;
}
#endregion
#region Protected Overrides
protected override void RaiseEvent(GEventArgs args)
{
if ((args.m_Propagation & EventPropagation.Bubble) == EventPropagation.Bubble)
{
//notify parent chain fo an event
BubbleEvent(args);
if ((args.m_Result & EventResult.Cancel) == EventResult.Cancel)
{
return;
}
}
if ((args.m_Propagation & EventPropagation.Tunnel) == EventPropagation.Tunnel)
{
//notify parent chain fo an event
TunnelEvent(args);
if ((args.m_Result & EventResult.Cancel) == EventResult.Cancel)
{
return;
}
}
base.RaiseEvent(args);
}
#endregion
#region Properties
public GNode Parent
{
get
{
return m_Parent;
}
}
public GRootElement Root
{
get
{
return m_Root;
}
}
#endregion
#region Fields
[NonSerialized]
internal GNode m_Parent;
[NonSerialized]
internal GRootElement m_Root;
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
.NET & C# addicted. Win8 & WinRT enthusiast and researcher @Telerik.