Click here to Skip to main content
15,881,852 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;
using System.Collections;
using System.ComponentModel;

namespace GFramework
{
    /// <summary>
    /// Represents the root of the element hierachy.
    /// </summary>
    public class GRootElement : GElement, IGServiceManager
    {
        #region Constructor

        public GRootElement()
        {
            m_Services = new Hashtable();
            m_EventListeners = new GNodeCollection(this);
        }

        #endregion

        #region Interface Implementation

        #region IGServiceManager

        public void RegisterService(object key, GService service)
        {
            if (m_Services.ContainsKey(key))
            {
                m_Services[key] = service;
            }
            else
            {
                m_Services.Add(key, service);
            }
        }
        public void UnRegisterService(object key)
        {
            if (m_Services.ContainsKey(key))
            {
                m_Services.Remove(key);
            }
        }
        public GService GetService(object key)
        {
            return (GService)m_Services[key];
        }

        #endregion

        #endregion

        #region Public Overridables

        public virtual void BeginInit()
        {
            m_InitializeLock++;
        }
        public virtual void EndInit()
        {
            m_InitializeLock--;
            m_InitializeLock = Math.Max(0, m_InitializeLock);

            if (m_InitializeLock > 0)
            {
                return;
            }

            OnEndInit();
        }

        #endregion

        #region Protected Overridables

        protected virtual void OnEndInit()
        {
            int count = m_Children.Count;
            for (int i = 0; i < count; i++)
            {
                m_Children[i].SetRoot(this);
            }
        }

        #endregion

        #region Protected Overrides

        protected internal override void OnCollectionNotification(GEventArgs e)
        {
            base.OnCollectionNotification(e);

            if (m_InitializeLock > 0)
            {
                return;
            }

            GCollectionEventData data = (GCollectionEventData)e.m_Data;

            switch (data.m_Notification)
            {
                case CollectionNotification.ElementAdded:
                case CollectionNotification.ElementInserted:
                    ((GNode)data.m_Element).SetRoot(this);
                    break;
                case CollectionNotification.ElementRemoved:
                    ((GNode)data.m_Element).SetRoot(null);
                    break;
            }
        }

        #endregion

        #region Properties

        public GNodeCollection EventListeners
        {
            get
            {
                return m_EventListeners;
            }
        }

        #endregion

        #region Fields

        [NonSerialized]
        internal int m_InitializeLock;
        [NonSerialized]
        internal GNodeCollection m_EventListeners;
        [NonSerialized]
        internal Hashtable m_Services;

        #endregion

        #region BiState Constants
        #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