context: /*
   
   * Author:	Bob Limnor (info@limnor.com)
   * Project: Limnor Studio
   * Item:	Visual Expression Display and Edit
   * License: GNU General Public License v3.0
   
   */
  /*
   * All rights reserved by Longflow Enterprises Ltd
   * 
   * Formula Editor
   */
  using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Drawing;
  using System.CodeDom;
  using System.ComponentModel;
  using System.Xml;
  using MathExp.RaisTypes;
  using VPL;
  using XmlUtility;
  using System.Collections.Specialized;
  using System.Globalization;
  using System.Drawing.Design;
  
  namespace MathExp
  {
  	public abstract class MathNodeString : MathNode
  	{
  		private RaisDataType _dataType;
  		public MathNodeString(MathNode parent)
  			: base(parent)
  		{
  
  		}
  		public override RaisDataType DataType
  		{
  			get
  			{
  				if (_dataType == null)
  				{
  					_dataType = new RaisDataType();
  					_dataType.LibType = typeof(string);
  				}
  				return _dataType;
  			}
  		}
  		[Browsable(false)]
  		protected override void OnCloneDataType(MathNode cloned)
  		{
  		}
  	}
  	public abstract class MathNodeConstString : MathNodeString
  	{
  		public MathNodeConstString(MathNode parent)
  			: base(parent)
  		{
  		}
  		protected abstract string ConstStringDisplay { get; }
  		protected abstract string ConstStringValue { get; }
  		protected abstract string ConstStringValuePhp { get; }
  		protected abstract string ConstStringValueJs { get; }
  		[Browsable(false)]
  		public override bool CanBeNull { get { return false; } }
  		public override SizeF OnCalculateDrawSize(Graphics g)
  		{
  			return g.MeasureString(ConstStringDisplay, TextFont);
  		}
  		public override void OnDraw(Graphics g)
  		{
  			if (IsFocused)
  			{
  				g.FillRectangle(TextBrushBKFocus, (float)0, (float)0, DrawSize.Width, DrawSize.Height);
  				g.DrawString(ConstStringDisplay, TextFont, TextBrushFocus, (float)0, (float)0);
  			}
  			else
  			{
  				g.DrawString(ConstStringDisplay, TextFont, TextBrush, (float)0, (float)0);
  			}
  		}
  		public override string TraceInfo
  		{
  			get { return ConstStringDisplay; }
  		}
  
  		protected override void InitializeChildren()
  		{
  			ChildNodeCount = 0;
  		}
  		public override CodeExpression ExportCode(IMethodCompile method)
  		{
  			return new CodePrimitiveExpression(ConstStringValue);
  		}
  
  		public override string CreateJavaScript(StringCollection method)
  		{
  			return ConstStringValueJs;
  		}
  
  		public override string CreatePhpScript(StringCollection method)
  		{
  			return ConstStringValuePhp;
  		}
  
  		public override void OnReplaceNode(MathNode replaced)
  		{
  
  		}
  	}
  
  	[MathNodeCategoryAttribute(enumOperatorCategory.String)]
  	[Description("It represents an ASCII character. Usually it is used for unprintable characters.")]
  	[ToolboxBitmapAttribute(typeof(MathNodeChar), "Resources.str_char.bmp")]
  	public class MathNodeChar : MathNodeConstString
  	{
  		private byte _b;
  		private RaisDataType _dataType;
  		public MathNodeChar(MathNode parent)
  			: base(parent)
  		{
  		}
  		public override RaisDataType DataType
  		{
  			get
  			{
  				if (_dataType == null)
  				{
  					_dataType = new RaisDataType();
  					_dataType.LibType = typeof(char);
  				}
  				return _dataType;
  			}
  		}
  		[Description("Gets and sets a byte value representing an ASCII value")]
  		public byte Ascii
  		{
  			get
  			{
  				return _b;
  			}
  			set
  			{
  				_b = value;
  			}
  		}
  		[Browsable(false)]
  		protected override void OnCloneDataType(MathNode cloned)
  		{
  		}
  		protected override string ConstStringDisplay
  		{
  			get { return string.Format(CultureInfo.InvariantCulture, "0x{0}", _b.ToString("x", CultureInfo.InvariantCulture)); }
  		}
  		protected override string ConstStringValue
  		{
  			get { return new string((char)(_b), 1); }
  		}
  		protected override string ConstStringValuePhp
  		{
  			get { return string.Format(CultureInfo.InvariantCulture, "chr({0})", _b); }
  		}
  		protected override string ConstStringValueJs
  		{
  			get { return string.Format(CultureInfo.InvariantCulture, "String.fromCharCode({0})", _b); }
  		}
  		protected override void OnSave(XmlNode node)
  		{
  			XmlUtil.SetAttribute(node, "ascii", _b);
  		}
  		protected override void OnLoad(XmlNode node)
  		{
  			_b = XmlUtil.GetAttributeByte(node, "ascii");
  		}
  		public override CodeExpression ExportCode(IMethodCompile method)
  		{
  			return new CodeCastExpression(typeof(char), new CodePrimitiveExpression(_b));
  		}
  		public override string ToString()
  		{
  			return ConstStringDisplay;
  		}
  		public override object CloneExp(MathNode parent)
  		{
  			MathNodeChar node = (MathNodeChar)base.CloneExp(parent);
  			node._b = _b;
  			return node;
  		}
  	}
  	[MathNodeCategoryAttribute(enumOperatorCategory.String)]
  	[Description("It represents a Line Feed character. It is ASCII character 0x0A.")]
  	[ToolboxBitmapAttribute(typeof(MathNodeLineFeed), "Resources.str_lf.bmp")]
  	public class MathNodeLineFeed : MathNodeConstString
  	{
  		public MathNodeLineFeed(MathNode parent)
  			: base(parent)
  		{
  		}
  		protected override string ConstStringDisplay
  		{
  			get { return "LF"; }
  		}
  		protected override string ConstStringValue
  		{
  			get { return "\n"; }
  		}
  		protected override string ConstStringValuePhp
  		{
  			get { return "\"\\n\""; }
  		}
  		protected override string ConstStringValueJs
  		{
  			get { return "'\\n'"; }
  		}
  	}
  	[MathNodeCategoryAttribute(enumOperatorCategory.String)]
  	[Description("It represents a Carriage Return character. It is ASCII character 0x0D.")]
  	[ToolboxBitmapAttribute(typeof(MathNodeCarriageReturn), "Resources.str_cr.bmp")]
  	public class MathNodeCarriageReturn : MathNodeConstString
  	{
  		public MathNodeCarriageReturn(MathNode parent)
  			: base(parent)
  		{
  		}
  		protected override string ConstStringDisplay
  		{
  			get { return "CR"; }
  		}
  		protected override string ConstStringValue
  		{
  			get { return "\r"; }
  		}
  		protected override string ConstStringValuePhp
  		{
  			get { return "\"\\r\""; }
  		}
  		protected override string ConstStringValueJs
  		{
  			get { return "'\\r'"; }
  		}
  	}
  	[MathNodeCategoryAttribute(enumOperatorCategory.String)]
  	[Description("It represents a Carriage Return character and a Line Feed character. It is a pair of ASCII characters 0x0D0A. Windows text files usually use it as line separator.")]
  	[ToolboxBitmapAttribute(typeof(MathNodeCarriageReturnLineFeed), "Resources.str_cl.bmp")]
  	public class MathNodeCarriageReturnLineFeed : MathNodeConstString
  	{
  		public MathNodeCarriageReturnLineFeed(MathNode parent)
  			: base(parent)
  		{
  		}
  		protected override string ConstStringDisplay
  		{
  			get { return "CL"; }
  		}
  		protected override string ConstStringValue
  		{
  			get { return "\r\n"; }
  		}
  		protected override string ConstStringValuePhp
  		{
  			get { return "\"\\r\\n\""; }
  		}
  		protected override string ConstStringValueJs
  		{
  			get { return "'\\r\\n'"; }
  		}
  	}
  	[MathNodeCategoryAttribute(enumOperatorCategory.String)]
  	[Description("It represents a tab character. It is ASCII character 0x09.")]
  	[ToolboxBitmapAttribute(typeof(MathNodeTab), "Resources.str_tab.bmp")]
  	public class MathNodeTab : MathNodeConstString
  	{
  		public MathNodeTab(MathNode parent)
  			: base(parent)
  		{
  		}
  		protected override string ConstStringDisplay
  		{
  			get { return "Tab"; }
  		}
  		protected override string ConstStringValue
  		{
  			get { return "\t"; }
  		}
  		protected override string ConstStringValuePhp
  		{
  			get { return "\"\\t\""; }
  		}
  		protected override string ConstStringValueJs
  		{
  			get { return "'\\t'"; }
  		}
  	}
  	[MathNodeCategoryAttribute(enumOperatorCategory.String)]
  	[Description("tests whether the string is null or empty")]
  	[ToolboxBitmapAttribute(typeof(MathNodeStringIsEmpty), "Resources.MathNodeStringIsEmpty.bmp")]
  	public class MathNodeStringIsEmpty : MathNode
  	{
  		const string function = "IsEmpty";
  		private RaisDataType _dataType;
  		public MathNodeStringIsEmpty(MathNode parent)
  			: base(parent)
  		{
  
  		}
  		public override RaisDataType DataType
  		{
  			get
  			{
  				if (_dataType == null)
  				{
  					_dataType = new RaisDataType();
  					_dataType.LibType = typeof(bool);
  				}
  				return _dataType;
  			}
  		}
  		public override string TraceInfo
  		{
  			get { return XmlSerialization.FormatString("IsEmpty({0})", this[0].TraceInfo); }
  		}
  		[Browsable(false)]
  		protected override void OnCloneDataType(MathNode cloned)
  		{
  
  		}
  		protected override void InitializeChildren()
  		{
  			ChildNodeCount = 1;
  		}
  		public override string ToString()
  		{
  			return XmlSerialization.FormatString("IsEmpty({0})", this[0].ToString());
  		}
  		public override SizeF OnCalculateDrawSize(Graphics g)
  		{
  			SizeF size0 = g.MeasureString(function, TextFont);
  			SizeF size1 = g.MeasureString("(", TextFont);
  			float w = size0.Width + size1.Width + size1.Width;
  			float h = size0.Height;
  			if (h < size1.Height)
  				h = size1.Height;
  
  
gt: 			SizeF size = this[0].CalculateDrawSize(g);