/// <summary> /// Parse content of the container element. /// </summary> /// <param name="parent">Parent control.</param> public void ParseContainerContent(Gwen.Net.Control.ControlBase parent) { foreach (string elementName in NextElement()) { ParseElement(parent); } }
private static Gwen.Net.Control.ControlBase DefaultElementHandler(Parser parser, Type type, Gwen.Net.Control.ControlBase parent) { Gwen.Net.Control.ControlBase element = Activator.CreateInstance(type, parent) as Gwen.Net.Control.ControlBase; parser.ParseAttributes(element); if (parser.MoveToContent()) { parser.ParseContainerContent(element); } return(element); }
/// <summary> /// Parse element and call it's handler. /// </summary> /// <param name="parent">Parent control.</param> /// <returns>Control.</returns> public Gwen.Net.Control.ControlBase ParseElement(Gwen.Net.Control.ControlBase parent) { ElementDef elementDef; if (m_ElementHandlers.TryGetValue(m_Reader.Name, out elementDef)) { m_CurrentElement = elementDef; return(elementDef.Handler(this, elementDef.Type, parent)); } return(null); }
/// <summary> /// Parse XML. /// </summary> /// <param name="parent">Parent control.</param> /// <returns>XML root control.</returns> public Gwen.Net.Control.ControlBase Parse(Gwen.Net.Control.ControlBase parent) { Gwen.Net.Control.ControlBase container = null; while (m_Reader.Read()) { switch (m_Reader.NodeType) { case XmlNodeType.Element: container = ParseElement(parent); break; } } return(container); }
/// <summary> /// Parse attributes. /// </summary> /// <param name="element">Control.</param> public void ParseAttributes(Gwen.Net.Control.ControlBase element) { if (m_Reader.HasAttributes) { while (m_Reader.MoveToNextAttribute()) { if (m_CurrentElement != null) { if (!SetAttributeValue(m_CurrentElement, element, m_Reader.Name, m_Reader.Value)) { throw new XmlException(String.Format("Attribute '{0}' not found.", m_Reader.Name)); } } else { throw new XmlException("Trying to set an attribute value without an element."); } } m_Reader.MoveToElement(); } }
/// <summary> /// Parse typed element and call it's handler. /// </summary> /// <typeparam name="T">Control type to be created.</typeparam> /// <param name="parent">Parent control.</param> /// <returns>Control.</returns> public T ParseElement <T>(Gwen.Net.Control.ControlBase parent) where T : Gwen.Net.Control.ControlBase { Type type = typeof(T); XmlControlAttribute attrib = null; object[] attribs = type.GetCustomAttributes(typeof(XmlControlAttribute), false); if (attribs.Length > 0) { attrib = attribs[0] as XmlControlAttribute; } ElementDef elementDef; if (m_ElementHandlers.TryGetValue(attrib != null && attrib.ElementName != null ? attrib.ElementName : type.Name, out elementDef)) { if (elementDef.Type == type) { m_CurrentElement = elementDef; return(elementDef.Handler(this, elementDef.Type, parent) as T); } } return(null); }
public void OnEvent(Gwen.Net.Control.ControlBase sender, T args) { Gwen.Net.Control.ControlBase handlerElement = sender.Parent; if (sender is Gwen.Net.Control.Window) { handlerElement = sender; } else if (sender is Gwen.Net.Control.TreeNode) { handlerElement = ((Gwen.Net.Control.TreeNode)sender).TreeControl.Parent; } while (handlerElement != null) { if (handlerElement.Component != null) { if (handlerElement.Component.HandleEvent(m_eventName, m_handlerName, sender, args)) { break; } else { Type type = handlerElement.Component.GetType(); MethodInfo methodInfo = null; do { MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo mi in methods) { if (mi.Name != m_handlerName) { continue; } ParameterInfo[] parameters = mi.GetParameters(); if (parameters.Length != 2) { continue; } if (parameters[0].ParameterType != typeof(Gwen.Net.Control.ControlBase) || (parameters[1].ParameterType != typeof(T) && parameters[1].ParameterType != typeof(T).BaseType)) { continue; } methodInfo = mi; break; } if (methodInfo != null) { break; } type = type.BaseType; }while (type != null); if (methodInfo != null) { methodInfo.Invoke(handlerElement.Component, new object[] { sender, args }); break; } } } if (handlerElement is Gwen.Net.Control.Menu) { Gwen.Net.Control.Menu menu = handlerElement as Gwen.Net.Control.Menu; if (menu.ParentMenuItem != null) { handlerElement = menu.ParentMenuItem; } else { handlerElement = handlerElement.Parent; } } else { handlerElement = handlerElement.Parent; } } }