Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / Windows Forms

GMarkupLabel - A C# Windows Forms control to display XML-formatted text

Rate me:
Please Sign up or sign in to vote.
4.95/5 (77 votes)
25 Nov 2008CPOL9 min read 130.6K   1.1K   166  
A framework, and a WinForms control which enables .NET 2.0 users to visualize XML-formatted rich text.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Telerik Corp.
Bulgaria Bulgaria
.NET & C# addicted. Win8 & WinRT enthusiast and researcher @Telerik.

Comments and Discussions