/// <summary> /// For public use only /// </summary> /// <param name="spanDefinition"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindLeftWordByBlockType(SpanDefinition spanDefinition, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i--; while (i >= 0) { Word w = this[i]; if (w.Span.spanDefinition == spanDefinition && w.Type != WordType.Space && w.Type != WordType.Tab) { return w; } i--; } return null; }
/// <summary> /// For public use only /// </summary> /// <param name="PatternList"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindLeftWordByPatternList(PatternList PatternList, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i--; while (i >= 0) { Word w = this[i]; if (w.Pattern != null) { if (w.Pattern.Parent != null) { if (w.Pattern.Parent == PatternList && w.Type != WordType.Space && w.Type != WordType.Tab) { return w; } } } i--; } return null; }
public Word Add(string text) { var xw = new Word {Row = this, Text = text}; words.Add(xw); return xw; }
/// <summary> /// Adds a word object to this row /// </summary> /// <param name="word">Word object</param> public void Add(Word word) { word.Row = this; words.Add(word); }
/// <summary> /// Adds a word object to this row /// </summary> /// <param name="word">Word object</param> public void Add(Word word) { this.mWords.Add(word); }
private void SetBrackets() { Span currentSpan; BracketEnd = null; BracketStart = null; Word CurrWord = Control.Caret.CurrentWord; if (CurrWord != null) { currentSpan = CurrWord.Span; if (currentSpan != null) { if (CurrWord == currentSpan.StartWord || CurrWord == currentSpan.EndWord) { if (currentSpan.EndWord != null) { BracketEnd = currentSpan.EndWord; BracketStart = currentSpan.StartWord; } } try { if (CurrWord.Pattern == null) return; if (CurrWord.Pattern.BracketType == BracketType.EndBracket) { Word w = Control.Document.GetStartBracketWord(CurrWord, CurrWord.Pattern.MatchingBracket, CurrWord.Span); BracketEnd = CurrWord; BracketStart = w; } if (CurrWord.Pattern.BracketType == BracketType.StartBracket) { Word w = Control.Document.GetEndBracketWord(CurrWord, CurrWord.Pattern.MatchingBracket, CurrWord.Span); // if(w!=null) // { BracketEnd = w; BracketStart = CurrWord; // } } } catch { } } } }
private void SetBrackets() { Segment CurrentSegment = null; this.BracketEnd = null; this.BracketStart = null; Word CurrWord = Control.Caret.CurrentWord; if (CurrWord != null) { CurrentSegment = CurrWord.Segment; if (CurrentSegment != null) { if (CurrWord == CurrentSegment.StartWord || CurrWord == CurrentSegment.EndWord) { if (CurrentSegment.EndWord != null) { // if(w!=null) // { this.BracketEnd = CurrentSegment.EndWord; this.BracketStart = CurrentSegment.StartWord; // } } } //ROGER STÖDA HÄR!!! try { if (CurrWord == null || CurrWord.Pattern == null) return; if (CurrWord.Pattern.BracketType == BracketType.EndBracket) { Word w = this.Control.Document.GetStartBracketWord(CurrWord, CurrWord.Pattern.MatchingBracket, CurrWord.Segment); this.BracketEnd = CurrWord; this.BracketStart = w; } if (CurrWord.Pattern.BracketType == BracketType.StartBracket) { Word w = this.Control.Document.GetEndBracketWord(CurrWord, CurrWord.Pattern.MatchingBracket, CurrWord.Segment); // if(w!=null) // { this.BracketEnd = w; this.BracketStart = CurrWord; // } } } catch { // System.Windows.Forms.MessageBox.Show (x.Message + "\n\n\n" + x.StackTrace); } } } }
/// <summary> /// Returns the index of a specific Word object /// </summary> /// <param name="word">Word object to find</param> /// <returns>index of the word in the row</returns> public int IndexOf(Word word) { return words.IndexOf(word); }
/// <summary> /// For public use only /// </summary> /// <param name="PatternList"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindRightWordByPatternList(PatternList PatternList, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i++; Word w = null; while (i < mWords.Count) { w = this[i]; if (w.Pattern != null) { if (w.Pattern.Parent != null) { if (w.Pattern.Parent == PatternList && w.Type != WordType.xtSpace && w.Type != WordType.xtTab) { return w; } } } i++; } return null; }
private void RenderSelectedText(int RowIndex, int XOffset, Word StartWord) { GDISurface bbuff = GFX.SelectionBuffer; bbuff.Font = GFX.FontNormal; bbuff.FontTransparent = true; if (RowIndex <= Control.Document.Count - 1) { if (this.Control.ContainsFocus) bbuff.TextForeColor = Control.SelectionForeColor; else bbuff.TextForeColor = Control.InactiveSelectionForeColor; Row xtr = Control.Document[RowIndex]; //if (xtr.StartSegment != null) // bbuff.DrawTabbedString (xtr.StartSegment.GetHashCode ().ToString (System.Globalization.CultureInfo.InvariantCulture),100,0,0,0); //bbuff.TextForeColor = Color.Black; //bbuff.DrawTabbedString (xtr.Text,(int)(Control.View.TextMargin -Control.View.ClientAreaStart),1,-Control.View.FirstVisibleColumn*Control.View.CharWidth+Control.View.TextMargin,Control.PixelTabSize); int xpos = Control.View.TextMargin - Control.View.ClientAreaStart + XOffset; int wdh = 0; int taborig = - Control.View.FirstVisibleColumn* Control.View.CharWidth + Control.View.TextMargin; bool ws = Control.ShowWhitespace; bool StartDraw = false; if (StartWord == null) StartDraw = true; xtr.Expansion_StartChar = 0; xtr.Expansion_EndChar = 0; bool HasExpansion = false; foreach (Word w in xtr.FormattedWords) { if (StartDraw) { if (w.Segment == xtr.Expansion_StartSegment && xtr.Expansion_StartSegment != null) if (xtr.Expansion_StartSegment.Expanded == false) { RenderCollapsedSelectedText(RowIndex, xpos); HasExpansion = true; break; } if (w.Type == WordType.xtWord || ws == false) { if (w.Style != null) { SetFont(w.Style.Bold, w.Style.Italic, w.Style.Underline, bbuff); } else { bbuff.Font = GFX.FontNormal; } wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig, Control.PixelTabSize).Width; //render errors if (w.HasError) { //bbuff.FillRect (Color.Red,xpos,Control.View.RowHeight-2,wdh,2); int ey = Control.View.RowHeight - 1; Color c = w.ErrorColor; for (int x = 0; x < wdh + 3; x += 4) { bbuff.DrawLine(c, new Point(xpos + x, ey), new Point(xpos + x + 2, ey - 2)); bbuff.DrawLine(c, new Point(xpos + x + 2, ey - 2), new Point (xpos + x + 4, ey)); } } } else if (w.Type == WordType.xtSpace && ws) { bbuff.Font = GFX.FontNormal; bbuff.DrawTabbedString("·", xpos, 0, taborig, Control.PixelTabSize); wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig, Control.PixelTabSize).Width; } else if (w.Type == WordType.xtTab && ws) { bbuff.Font = GFX.FontNormal; bbuff.DrawTabbedString("»", xpos, 0, taborig, Control.PixelTabSize); wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig, Control.PixelTabSize).Width; } if (w.Pattern != null) if (w.Pattern.IsSeparator) { bbuff.FillRect(this.Control.SeparatorColor, Control.View.TextMargin - 4, Control.View.RowHeight - 1, Control.View.ClientAreaWidth, 1); } xpos += wdh; } if (!StartDraw) xtr.Expansion_StartChar += w.Text.Length; if (w == StartWord) StartDraw = true; xtr.Expansion_EndChar += w.Text.Length; } if (this.Control._SyntaxBox.ShowEOLMarker && !HasExpansion) { bbuff.Font = GFX.FontNormal; bbuff.TextForeColor = this.Control.SelectionForeColor; bbuff.FontTransparent = true; bbuff.DrawTabbedString("¶", xpos, 0, taborig, Control.PixelTabSize); } } else { //bbuff.TextForeColor =Color.Red; //bbuff.DrawTabbedString ("",Control.View.TextMargin ,1,0,Control.PixelTabSize); } }
/// <summary> /// For public use only /// </summary> /// <param name="BlockTypeName"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindRightWordByBlockTypeName(string BlockTypeName, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i++; Word w = null; while (i < mWords.Count) { w = this[i]; if (w.Segment.BlockType.Name == BlockTypeName && w.Type != WordType.xtSpace && w.Type != WordType.xtTab) { return w; } i++; } return null; }
/// <summary> /// For public use only /// </summary> /// <param name="PatternListName"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindLeftWordByPatternListName(string PatternListName, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i--; Word w = null; while (i >= 0) { w = this[i]; if (w.Pattern != null) { if (w.Pattern.Parent != null) { if (w.Pattern.Parent.Name == PatternListName && w.Type != WordType.xtSpace && w.Type != WordType.xtTab) { return w; } } } i--; } return null; }
/// <summary> /// For public use only /// </summary> /// <param name="BlockType"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindLeftWordByBlockType(BlockType BlockType, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i--; Word w = null; while (i >= 0) { w = this[i]; if (w.Segment.BlockType == BlockType && w.Type != WordType.xtSpace && w.Type != WordType.xtTab) { return w; } i--; } return null; }
/// <summary> /// For public use only /// </summary> /// <param name="BlockTypeName"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindRightWordByBlockTypeName(string BlockTypeName, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i++; while (i < words.Count) { Word w = this[i]; if (w.Span.spanDefinition.Name == BlockTypeName && w.Type != WordType.Space && w.Type != WordType.Tab) { return w; } i++; } return null; }
//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; }
/// <summary> /// For public use only /// </summary> /// <param name="PatternListName"></param> /// <param name="StartWord"></param> /// <param name="IgnoreStartWord"></param> /// <returns></returns> public Word FindRightWordByPatternListName(string PatternListName, Word StartWord, bool IgnoreStartWord) { int i = StartWord.Index; if (IgnoreStartWord) i++; while (i < words.Count) { Word w = this[i]; if (w.Pattern != null) { if (w.Pattern.Parent != null) { if (w.Pattern.Parent.Name == PatternListName && w.Type != WordType.Space && w.Type != WordType.Tab) { return w; } } } i++; } return null; }
private void RenderText(int RowIndex, int XOffset, Word StartWord) { GDISurface bbuff = GFX.BackBuffer; bbuff.Font = GFX.FontNormal; bbuff.FontTransparent = true; bool DrawBreakpoint = false; if (RowIndex <= Control.Document.Count - 1) { bbuff.TextForeColor = Color.Black; Row xtr = Control.Document[RowIndex]; //if (xtr.startSpan != null) // bbuff.DrawTabbedString (xtr.startSpan.GetHashCode ().ToString (System.Globalization.CultureInfo.InvariantCulture),100,0,0,0); //bbuff.TextForeColor = Color.Black; //bbuff.DrawTabbedString (xtr.Text,(int)(Control.View.TextMargin -Control.View.ClientAreaStart),1,-Control.View.FirstVisibleColumn*Control.View.CharWidth+Control.View.TextMargin,Control.PixelTabSize); int xpos = Control.View.TextMargin - Control.View.ClientAreaStart + XOffset; int wdh = 0; int taborig = -Control.View.FirstVisibleColumn*Control.View.CharWidth + Control.View.TextMargin; bool ws = Control.ShowWhitespace; bool StartDraw = false; if (StartWord == null) StartDraw = true; xtr.Expansion_StartChar = 0; xtr.Expansion_EndChar = 0; bool HasExpansion = false; foreach (Word w in xtr.FormattedWords) { if (StartDraw) { if (w.Span == xtr.expansion_StartSpan && xtr.expansion_StartSpan != null) if (xtr.expansion_StartSpan.Expanded == false) { RenderCollapsedText(RowIndex, xpos); HasExpansion = true; break; } if ((w.Type == WordType.Space || w.Type == WordType.Tab) && !DrawBreakpoint && Control.ShowTabGuides) { int xtab = xpos - (Control.View.TextMargin - Control.View.ClientAreaStart + XOffset); if ((xtab/(double) Control.PixelTabSize) == (xtab/Control.PixelTabSize)) bbuff.FillRect(Control.TabGuideColor, xpos, 0, 1, Control.View.RowHeight); } if (w.Type == WordType.Word || ws == false) { if (w.Style != null) { SetFont(w.Style.Bold, w.Style.Italic, w.Style.Underline, bbuff); bbuff.TextBackColor = w.Style.BackColor; bbuff.TextForeColor = w.Style.ForeColor; bbuff.FontTransparent = w.Style.Transparent; } else { bbuff.Font = GFX.FontNormal; bbuff.TextForeColor = Color.Black; bbuff.FontTransparent = true; } if (w.Type == WordType.Word) DrawBreakpoint = true; if (xtr.Breakpoint && DrawBreakpoint) { bbuff.TextForeColor = Control.BreakPointForeColor; bbuff.TextBackColor = Control.BreakPointBackColor; bbuff.FontTransparent = false; } if (Control.BracketMatching && (w == BracketEnd || w == BracketStart)) { bbuff.TextForeColor = Control.BracketForeColor; if (Control.BracketBackColor != Color.Transparent) { bbuff.TextBackColor = Control.BracketBackColor; bbuff.FontTransparent = false; } wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig, Control.PixelTabSize).Width; if (Control.BracketBorderColor != Color.Transparent) { bbuff.DrawRect(Control.BracketBorderColor, xpos - 1, 0, wdh, Control.View.RowHeight - 1); } } else { wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig, Control.PixelTabSize).Width; } //render errors if (w.HasError) { //bbuff.FillRect (Color.Red,xpos,Control.View.RowHeight-2,wdh,2); int ey = Control.View.RowHeight - 1; Color c = w.ErrorColor; for (int x = 0; x < wdh + 3; x += 4) { bbuff.DrawLine(c, new Point(xpos + x, ey), new Point(xpos + x + 2, ey - 2)); bbuff.DrawLine(c, new Point(xpos + x + 2, ey - 2), new Point(xpos + x + 4, ey)); } } } else if (w.Type == WordType.Space) { bbuff.Font = GFX.FontNormal; bbuff.TextForeColor = Control.WhitespaceColor; bbuff.FontTransparent = true; if (xtr.Breakpoint && DrawBreakpoint) { bbuff.TextForeColor = Control.BreakPointForeColor; bbuff.TextBackColor = Control.BreakPointBackColor; bbuff.FontTransparent = false; } bbuff.DrawTabbedString("·", xpos, 0, taborig, Control.PixelTabSize); wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig, Control.PixelTabSize).Width; } else if (w.Type == WordType.Tab) { bbuff.Font = GFX.FontNormal; bbuff.TextForeColor = Control.WhitespaceColor; bbuff.FontTransparent = true; if (xtr.Breakpoint && DrawBreakpoint) { bbuff.TextForeColor = Control.BreakPointForeColor; bbuff.TextBackColor = Control.BreakPointBackColor; bbuff.FontTransparent = false; } bbuff.DrawTabbedString("»", xpos, 0, taborig, Control.PixelTabSize); wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig, Control.PixelTabSize).Width; } if (w.Pattern != null) if (w.Pattern.IsSeparator) { bbuff.FillRect(Control.SeparatorColor, Control.View.TextMargin - 4, Control.View.RowHeight - 1, Control.View.ClientAreaWidth, 1); } xpos += wdh; } if (!StartDraw) xtr.Expansion_StartChar += w.Text.Length; if (w == StartWord) StartDraw = true; xtr.Expansion_EndChar += w.Text.Length; } if (xtr.IsCollapsed) {} else if (xtr.endSpan != null && xtr.endSpan.spanDefinition != null && xtr.endSpan.spanDefinition.Style != null) { bbuff.FillRect(xtr.endSpan.spanDefinition.Style.BackColor, xpos, 0, Control.Width - xpos, Control.View.RowHeight); } if (Control._SyntaxBox.ShowEOLMarker && !HasExpansion) { bbuff.Font = GFX.FontNormal; bbuff.TextForeColor = Control._SyntaxBox.EOLMarkerColor; bbuff.FontTransparent = true; bbuff.DrawTabbedString("¶", xpos, 0, taborig, Control.PixelTabSize); } } }
//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; } }
public Word Add(string text) { Word xw = new Word(); xw.Row = this; xw.Text = text; mWords.Add(xw); return xw; }