示例#1
0
        //public static char[] Parse(string text,string separators)
        //{
        //    //string Result="";
        //    System.Text.StringBuilder Result=new System.Text.StringBuilder ();
        //    text= " " + text +" ";

        //    char c;

        //    for(int i = 0; i <text.Length;i++)
        //    {
        //        c = text[i];
        //        if (separators.IndexOf (c)>=0 )
        //            Result.Append (' ');
        //        else
        //            Result.Append ('.');
        //    }

        //    return Result.ToString().ToCharArray ();
        //}



        public static void AddPatternString(string text, Row row, Pattern pattern, TextStyle style, Segment segment, bool hasError)
        {
            Word x = row.Add(text);
            x.Style = style;
            x.Pattern = pattern;
            x.HasError = hasError;
            x.Segment = segment;
        }
示例#2
0
		public bool RowContainsFormats(Row row)
		{
			foreach (FormatRange frang in this)
			{
				if (frang.Bounds.FirstRow <= row.Index && frang.Bounds.LastRow >= row.Index)
					return true;
			}

			return false;
		}
 /// <summary>
 /// Implementation of the IPainter MeasureRow method.
 /// </summary>
 /// <param name="xtr">Row to measure</param>
 /// <param name="Count">Last char index</param>
 /// <returns>The size of the row in pixels</returns>
 public Size MeasureRow(Row xtr, int Count)
 {
     return MeasureRow(xtr, Count, 0);
 }
示例#4
0
		/// <summary>
		/// Forces a row to be parsed
		/// </summary>
		/// <param name="r">Row to parse</param>
		/// <param name="ParseKeywords">true if keywords and operators should be parsed</param>
		public void ParseRow(Row r, bool ParseKeywords)
		{
			int index = this.IndexOf(r);
			if (index >= 0)
			{
				if (index > 0)
					if (this[index - 1].InQueue)
						ParseRow(this[index - 1]);

				Parser.ParseLine(index, false);
				if (ParseKeywords)
					Parser.ParseLine(index, true);
			}

			int i = this.ParseQueue.IndexOf(r);
			if (i >= 0)
				this.ParseQueue.RemoveAt(i);

			r.InQueue = false;
		}
示例#5
0
		private int ParseRows(Row r)
		{
			return ParseRows(r, false);
		}
示例#6
0
		/// <summary>
		/// Add a new row with the specified text to the bottom of the document
		/// </summary>
		/// <param name="Text">Text to add</param>
		/// <param name="StoreUndo">true if and undo action should be added to the undo stack</param>
		/// <returns>The row that was added</returns>
		public Row Add(string Text, bool StoreUndo)
		{
			Row xtl = new Row();
			mDocument.Add(xtl);
			xtl.Document = this;
			xtl.Text = Text;
			return xtl;
		}
示例#7
0
		protected internal void OnApplyFormatRanges(Row row)
		{
			if (this.FormatRanges == null)
				return;


			if (!this.FormatRanges.RowContainsFormats(row) || row.RowState != RowState.AllParsed)
			{
				row.FormattedWords = row.mWords;
			}
			else
			{
				row.FormattedWords = new WordCollection();
				int i = 0;
				int l = 0;
				int x = 0;
				int ri = row.Index;
				foreach (char c in row.Text)
				{
					Word w = row[i];
					FormatRange fr = FormatRanges.MergeFormats(x, ri);
					Word wn = new Word();
					wn.Text = c.ToString();


					if (fr == null)
					{
						wn.Style = w.Style;
					}
					else
					{
						wn.Style = new TextStyle();
						if (w.Style == null)
							w.Style = new TextStyle();

						wn.Style.BackColor = (fr.BackColor == Color.Empty) ? w.Style.BackColor : fr.BackColor;
						wn.Style.ForeColor = (fr.ForeColor == Color.Empty) ? w.Style.ForeColor : fr.ForeColor;
						wn.InfoTip = fr.InfoTip;
						/*wn.Style.Bold = false;
						wn.Style.Italic = true;
						wn.Style.Underline = false;*/
						if (fr.WaveColor != Color.Empty)
						{
							wn.HasError = true;
							wn.ErrorColor = fr.WaveColor;
                            
						}

					}
					wn.Type = w.Type;
					wn.Segment = w.Segment;
					row.FormattedWords.Add(wn);


					l++;
					if (l == row[i].Text.Length)
					{
						i++;
						l = 0;
					}
					x++;
				}

			}
		}
示例#8
0
		/// <summary>
		/// Expand a given row
		/// </summary>
		/// <param name="r">Row to expand</param>
		private void ExpandRow(Row r)
		{
			//add rows to visible list...
			Row start = r.Expansion_StartRow;
			Row end = r.Expansion_EndRow;
			int count = end.Index - start.Index - 1;
			int startIndex = start.Index + 1;

			int visIndex = start.VisibleIndex + 1;
			int i = 0;
			while (i <= count)
			{
				Row tmpRow = this[startIndex + i];
				this.VisibleRows.Insert(visIndex, tmpRow);
				if (tmpRow.Expansion_StartSegment != null)
					if (tmpRow.Expansion_StartSegment.Expanded == false)
					{
						tmpRow = tmpRow.Expansion_StartSegment.EndRow;
						i = tmpRow.Index - startIndex;
					}
				visIndex++;
				i++;
			}

			//ResetVisibleRows ();
		}
示例#9
0
		/// <summary>
		/// Collapse a given row
		/// </summary>
		/// <param name="r">Row to collapse</param>
		private void CollapseRow(Row r)
		{
			//remove rows from visible list
			Row start = r.Expansion_StartRow;
			Row end = r.Expansion_EndRow;
			int count = end.VisibleIndex - start.VisibleIndex - 1;
			int startIndex = start.VisibleIndex + 1;
			for (int i = 0; i <= count; i++)
			{
				this.VisibleRows.RemoveAt(startIndex);
			}
		}
示例#10
0
		/// <summary>
		/// Returns the index of a given row
		/// </summary>
		/// <param name="xtr">row to find</param>
		/// <returns>Index of the given row</returns>
		public int IndexOf(Row xtr)
		{
			return mDocument.IndexOf(xtr);
		}
示例#11
0
        private ScanResult_Segment GetNextChildSegment(Row Row, Segment CurrentSegment, int StartPos)
        {
            //this row has no text , just bail out...
            if (StartPos >= Row.Text.Length)
                return new ScanResult_Segment();



            ScanResult_Segment Result = new ScanResult_Segment();
            Result.HasContent = false; //make sure we have no content in this object
            Result.IsEndSegment = false; //nope , were looking for start blocks here

            BlockType ChildBlock;
            //foreach (BlockType ChildBlock in CurrentSegment.BlockType.ChildBlocks)

            BlockTypeCollection blocks = CurrentSegment.BlockType.ChildBlocks;

            for (int i = 0; i < blocks.Count; i++)
            {
                ChildBlock = blocks[i];
                //scan each scope in each childblock
                //foreach (Scope Scope in ChildBlock.ScopePatterns)
                Scope Scope;
                ScopeCollection scopeColl = ChildBlock.ScopePatterns;
                for (int j = 0; j < scopeColl.Count; j++)
                {
                    Scope = scopeColl[j];

                    PatternScanResult psr = Scope.Start.IndexIn(Row.Text, StartPos, Scope.CaseSensitive, Separators);
                    int CurrentPosition = psr.Index;
                    if ((!Result.HasContent || CurrentPosition < Result.Position) && psr.Token != "")
                    {
                        //we found a better match
                        //store this new match
                        Result.Pattern = Scope.Start;
                        Result.Position = CurrentPosition;
                        Result.Token = psr.Token;
                        Result.HasContent = true;
                        Result.BlockType = ChildBlock;
                        Result.Scope = Scope;

                        if (Scope.NormalizeCase)
                            if (!Scope.Start.IsComplex)
                                Result.Token = Scope.Start.StringPattern;
                    }
                }
            }






            //no result ,  new ScanResult_Segment();
            if (!Result.HasContent)
                return new ScanResult_Segment();

            return Result;
        }
示例#12
0
        private ScanResult_Segment GetEndSegment(Row Row, Segment CurrentSegment, int StartPos)
        {
            //this row has no text , just bail out...
            if (StartPos >= Row.Text.Length || CurrentSegment.Scope == null)
                return new ScanResult_Segment();

            ScanResult_Segment Result = new ScanResult_Segment();
            Result.HasContent = false; //make sure we have no content in this object
            Result.IsEndSegment = false; //nope , were looking for start blocks here


            //--------------------------------------------------------------------------------
            //scan for childblocks
            //scan each scope in each childblock

            Segment seg = CurrentSegment;

            while (seg != null)
            {
                if (seg == CurrentSegment || seg.BlockType.TerminateChildren)
                {
                    foreach (Pattern end in seg.Scope.EndPatterns)
                    {
                        PatternScanResult psr = end.IndexIn(Row.Text, StartPos, seg.Scope.CaseSensitive, Separators);
                        int CurrentPosition = psr.Index;
                        if (psr.Token != "")
                        {
                            if ((psr.Index < Result.Position && Result.HasContent) || !Result.HasContent)
                            {
                                //we found a better match
                                //store this new match
                                Result.Pattern = end;
                                Result.Position = CurrentPosition;
                                Result.Token = psr.Token;
                                Result.HasContent = true;
                                Result.Segment = seg;
                                Result.Scope = null;


                                if (!end.IsComplex)
                                {
                                    if (seg.Scope.NormalizeCase)
                                        if (!seg.Scope.Start.IsComplex)
                                            Result.Token = end.StringPattern;
                                }
                            }
                        }
                    }
                }
                seg = seg.Parent;
            }

            //no result , return new ScanResult_Segment();
            if (!Result.HasContent)
                return new ScanResult_Segment();

            return Result;
        }
示例#13
0
        private void ParseText(Row Row, Segment CurrentSegment, string Text)
        {
            int CurrentPosition = 0;
            bool HasComplex = true;
            while (true)
            {
                ScanResult_Word Word = GetNextWord(Text, CurrentSegment, CurrentPosition, ref HasComplex);

                if (!Word.HasContent)
                {
                    ParseTools.AddString(Text.Substring(CurrentPosition), Row, CurrentSegment.BlockType.Style, CurrentSegment);
                    break;
                }
                else
                {
                    ParseTools.AddString(Text.Substring(CurrentPosition, Word.Position - CurrentPosition), Row, CurrentSegment.BlockType.Style, CurrentSegment);
                    ParseTools.AddPatternString(Word.Token, Row, Word.Pattern, Word.ParentList.Style, CurrentSegment, false);
                    CurrentPosition = Word.Position + Word.Token.Length;
                }
            }
        }
示例#14
0
		//Override the OnPrintPage to provide the printing logic for the document
		protected override void OnPrintPage(PrintPageEventArgs ev)
		{
			float lpp = 0;
			float yPos = 0;
			int count = 0;
			float leftMargin = ev.MarginBounds.Left;
			float rightMargin = ev.MarginBounds.Right;
			float topMargin = ev.MarginBounds.Top;
			//ev.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

			if (rc == null)
			{
				Document.ParseAll();
				Document.ParseAll(true);


				rc = new RowCollection();
				foreach (Row r in Document)
				{
					bool hasbreak = false;
					float x = leftMargin;
					Row newRow = new Row();
					rc.Add(newRow);
					foreach (Word w in r)
					{
						Font f = fontNormal;
						if (w.Style != null)
						{
							FontStyle fs = 0;

							if (w.Style.Bold)
								fs |= FontStyle.Bold;

							if (w.Style.Italic)
								fs |= FontStyle.Italic;

							if (w.Style.Underline)
								fs |= FontStyle.Underline;

							f = new Font("Courier new", 8, fs);
						}
						SizeF sf = ev.Graphics.MeasureString(w.Text, f);
						if (x + sf.Width > rightMargin)
						{
							char chr = (char) 0xbf;
							Word br = new Word();
							br.Text = chr + "";
							br.InfoTip = "break char";
							newRow.Add(br);
							hasbreak = true;


							newRow = new Row();
							rc.Add(newRow);
							x = leftMargin;
						}
						x += sf.Width;
						newRow.Add(w);


					}
					if (hasbreak)
					{
						rc.Add(new Row());
					}
				}
			}
			//------------------------------------------------------

			base.OnPrintPage(ev);


			lpp = ev.MarginBounds.Height/fontNormal.GetHeight(ev.Graphics);


			while (count < lpp && (RowIndex < rc.Count))
			{
				float x = leftMargin;
				yPos = topMargin + (count*fontNormal.GetHeight(ev.Graphics));

				Row r = rc[RowIndex];

				foreach (Word w in r)
				{
					if (w.InfoTip != null && w.InfoTip == "break char")
					{
						ev.Graphics.DrawString(w.Text, fontBreak, Brushes.Black, x, yPos, new StringFormat());
					}
					else
					{
						SizeF sf = ev.Graphics.MeasureString(w.Text, fontNormal);

						if (w.Text != null && (".,:;".IndexOf(w.Text) >= 0))
						{
							sf.Width = 6;
							x -= 4;
						}
						if (w.Text == "\t")
						{
							sf.Width = ev.Graphics.MeasureString("...", fontNormal).Width;
						}


						Color c = Color.Black;
						Font f = fontNormal;
						if (w.Style != null)
						{
							c = w.Style.ForeColor;
							FontStyle fs = 0;

							if (w.Style.Bold)
								fs |= FontStyle.Bold;

							if (w.Style.Italic)
								fs |= FontStyle.Italic;

							if (w.Style.Underline)
								fs |= FontStyle.Underline;

							f = new Font("Courier new", 8, fs);

							if (!w.Style.Transparent)
							{
								Color bg = w.Style.BackColor;
								ev.Graphics.FillRectangle(new SolidBrush(bg), x, yPos, sf.Width, fontNormal.GetHeight(ev.Graphics));


							}

						}

						c = Color.FromArgb(c.R, c.G, c.B);


						ev.Graphics.DrawString(w.Text, f, new SolidBrush(c), x, yPos, new StringFormat());
						x += sf.Width;
					}
				}

				count++;
				RowIndex++;
			}

			//If we have more lines then print another page
			if (RowIndex < rc.Count)
				ev.HasMorePages = true;
			else
				ev.HasMorePages = false;
		}
示例#15
0
		public unsafe static void AddString(string text,Row row,TextStyle style,Segment segment)
		{
            if (text == "")
                return;

            string[] spl = WordSplitter.Split(text);

            string w = null;

            for (int i = 0; i < spl.Length; i++)
            {
                w = spl[i];
                Word word = row.Add(w);
                word.Style = style;
                word.Segment = segment;

                if (w == " ")
                {
                    word.Type = WordType.xtSpace;
                }
                else if (w == "\t")
                {
                    word.Type = WordType.xtTab;
                }
            }

			/*if (Text=="")
				return;

			System.Text.StringBuilder CurrentWord=new System.Text.StringBuilder();

			char[] Buff=Text.ToCharArray();

			fixed (char* c = &Buff[0])
			{
				for (int i=0;i<Text.Length;i++)
				{
					if (c[i]==' ' || c[i]=='\t')
					{

						if (CurrentWord.Length != 0)
						{
							Word word = Row.Add (CurrentWord.ToString ());
							word.Style =Style;
							word.Segment =Segment;
							CurrentWord =new System.Text.StringBuilder();
						}

						Word ws=Row.Add (c[i].ToString ());
						if (c[i]==' ')
							ws.Type= WordType.xtSpace;
						else
							ws.Type= WordType.xtTab;
						ws.Style = Style ;
						ws.Segment = Segment;					
					}
					else
						CurrentWord.Append (c[i].ToString ());					
				}
				if (CurrentWord.Length  != 0)
				{
					Word word=Row.Add (CurrentWord.ToString ());
					word.Style =Style;
					word.Segment =Segment;				
				}	
			}*/
		}
示例#16
0
		/// <summary>
		/// Toggle expansion of a given row
		/// </summary>
		/// <param name="r"></param>
		public void ToggleRow(Row r)
		{
			if (!mFolding)
				return;

			if (r.Expansion_EndRow == null || r.Expansion_StartRow == null)
				return;


//			if (r.IsCollapsed)
//			{
//				r.Expansion_StartSegment.Expanded =	true;
//				ExpandRow(r);
//			}
//			else
//			{
//				r.Expansion_StartSegment.Expanded =	false;
//				CollapseRow(r);
//			}

			if (r.CanFold)
				r.Expanded = !r.Expanded;
			ResetVisibleRows();

			OnChange();
		}
示例#17
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="row"></param>
		public RowEventArgs(Row row)
		{
			this.Row = row;
		}
示例#18
0
		private void OnRowParsed(Row r)
		{
			if (RowParsed != null)
				RowParsed(this, new RowEventArgs(r));

			this.OnApplyFormatRanges(r);
		}
示例#19
0
		public virtual void InvokeBookmarkAdded(Row r)
		{
			OnBookmarkAdded(r);
		}
示例#20
0
		//		private void OnRowAdded(Row r)
		//		{
		//			if (RowAdded != null)
		//				RowAdded(this,new RowEventArgs(r));
		//		}
		private void OnRowDeleted(Row r)
		{
			if (RowDeleted != null)
				RowDeleted(this, new RowEventArgs(r));
		}
示例#21
0
		public virtual void InvokeBookmarkRemoved(Row r)
		{
			OnBookmarkRemoved(r);
		}
示例#22
0
		protected virtual void OnBreakPointRemoved(Row r)
		{
			if (BreakPointRemoved != null)
				BreakPointRemoved(this, new RowEventArgs(r));
		}
示例#23
0
		/// <summary>
		/// Call this method to ensure that a specific row is fully parsed
		/// </summary>
		/// <param name="Row"></param>
		public void EnsureParsed(Row Row)
		{
			this.ParseAll();
			Parser.ParseLine(Row.Index, true);
		}
示例#24
0
		protected virtual void OnBookmarkRemoved(Row r)
		{
			if (BookmarkRemoved != null)
				BookmarkRemoved(this, new RowEventArgs(r));
		}
示例#25
0
		/// <summary>
		/// Insert a text at the specified row index
		/// </summary>
		/// <param name="Text">Text to insert</param>
		/// <param name="index">Row index where the text should be inserted</param>
		/// <param name="StoreUndo">true if and undo action should be added to the undo stack</param>
		/// <returns>The row that was inserted</returns>
		public Row Insert(string Text, int index, bool StoreUndo)
		{
			Row xtl = new Row();
			xtl.Document = this;
			mDocument.Insert(index, xtl);
			xtl.Text = Text;
			if (StoreUndo)
			{
				UndoBlock undo = new UndoBlock();
				undo.Text = Text;
				undo.Position.Y = this.IndexOf(xtl);
				AddToUndoList(undo);
			}

			//this.ResetVisibleRows ();
			return xtl;
		}
示例#26
0
		/// <summary>
		/// Call this method to make the document raise the RowParsed event
		/// </summary>
		/// <param name="row"></param>
		public void InvokeRowParsed(Row row)
		{
			this.OnRowParsed(row);
		}
示例#27
0
		private int ParseRows(Row r, bool Keywords)
		{
			if (!Keywords)
			{
				int index = this.IndexOf(r);
				int count = 0;
                //try
                //{
					while (r.InQueue && count < 100)
					{
						if (index >= 0)
						{
							if (index > 0)
								if (this[index - 1].InQueue)
									ParseRow(this[index - 1]);

							Parser.ParseLine(index, false);
						}

						int i = this.ParseQueue.IndexOf(r);
						if (i >= 0)
							this.ParseQueue.RemoveAt(i);
						r.InQueue = false;
						index++;
						count++;
						r = this[index];

						if (r == null)
							break;
					}
                //}
                //catch
                //{
                //}

				return count;
			}
			else
			{
				int index = this.IndexOf(r);
				if (index == -1 || r.InKeywordQueue == false)
				{
					this.KeywordQueue.Remove(r);
					return 0;
				}
				int count = 0;
                //try
                //{
					while (r.InKeywordQueue && count < 100)
					{
						if (index >= 0)
						{
							if (index > 0)
								if (this[index - 1].InQueue)
									ParseRow(this[index - 1]);

							Parser.ParseLine(index, true);
						}
						index++;
						count++;
						r = this[index];

						if (r == null)
							break;
					}
                //}
                //catch
                //{
                //}

				return count;
			}
		}
示例#28
0
		public virtual void InvokeBreakPointAdded(Row r)
		{
			OnBreakPointAdded(r);
		}
示例#29
0
		/// <summary>
		/// Forces a row to be parsed
		/// </summary>
		/// <param name="r">Row to parse</param>
		public void ParseRow(Row r)
		{
			ParseRow(r, false);
		}
示例#30
0
		public virtual void InvokeBreakPointRemoved(Row r)
		{
			OnBreakPointRemoved(r);
		}