示例#1
0
		/// <summary>
		/// Get the object, which was inserted under the keyword (line, at offset, with length length),
		/// returns null, if no such keyword was inserted.
		/// </summary>
		public object this[SyntaxDocument document, Word line, int offset, int length] {
			get {
				if(length == 0) {
					return null;
				}
                //Node next = root;
				
                //int wordOffset = line.Offset + offset;
                //if (casesensitive) {
                //    for (int i = 0; i < length; ++i) {
                //        int index = ((int)document.GetCharAt(wordOffset + i)) % 256;
                //        next = next.leaf[index];
						
                //        if (next == null) {
                //            return null;
                //        }
						
                //        if (next.color != null && TextUtility.RegionMatches(document, wordOffset, length, next.word)) {
                //            return next.color;
                //        }
                //    }
                //} else {
                //    for (int i = 0; i < length; ++i) {
                //        int index = ((int)Char.ToUpper(document.GetCharAt(wordOffset + i))) % 256;
						
                //        next = next.leaf[index];
						
                //        if (next == null) {
                //            return null;
                //        }
						
                //        if (next.color != null && TextUtility.RegionMatches(document, casesensitive, wordOffset, length, next.word)) {
                //            return next.color;
                //        }
                //    }
                //}
				return null;
			}
		}
示例#2
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++;
				}

			}
		}
示例#3
0
		public Word GetEndBracketWord(Word Start, Pattern End, Segment FindIn)
		{
			if (Start == null || Start.Pattern == null || Start.Segment == null)
				return null;

			int CurrentRow = Start.Row.Index;

			int LastRow = this.Count - 1;
			if (FindIn.EndRow != null)
				LastRow = FindIn.EndRow.Index;


			int x = Start.Index;
			int count = 0;
			while (CurrentRow <= LastRow)
			{
				for (int i = x; i < this[CurrentRow].Count; i++)
				{
					Word w = this[CurrentRow][i];
					if (w.Segment == FindIn && w.Type == WordType.xtWord)
					{
						if (w.Pattern == Start.Pattern)
							count++;
						if (w.Pattern == End)
							count--;

						if (count == 0)
							return w;
					}
				}

				if (!Start.Pattern.IsMultiLineBracket)
					break;

				CurrentRow++;
				x = 0;
			}
			return null;
		}
示例#4
0
		public Word GetStartBracketWord(Word Start, Pattern End, Segment FindIn)
		{
			if (Start == null || Start.Pattern == null || Start.Segment == null)
				return null;

			int CurrentRow = Start.Row.Index;
			int FirstRow = FindIn.StartRow.Index;
			int x = Start.Index;
			int count = 0;
			while (CurrentRow >= FirstRow)
			{
				for (int i = x; i >= 0; i--)
				{
					Word w = this[CurrentRow][i];
					if (w.Segment == FindIn && w.Type == WordType.xtWord)
					{
						if (w.Pattern == Start.Pattern)
							count++;
						if (w.Pattern == End)
							count--;

						if (count == 0)
							return w;
					}
				}

				if (!Start.Pattern.IsMultiLineBracket)
					break;

				CurrentRow--;
				if (CurrentRow >= 0)
					x = this[CurrentRow].Count - 1;
			}
			return null;
		}
示例#5
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;
		}
        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.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;

                WordCollection wordCollection = xtr.FormattedWords;

                Word w = null;

                for (int i = 0; i < wordCollection.Count;i++)
                {
                    w = wordCollection[i];

                    if (StartDraw)
                    {
                        if (w.Segment == xtr.Expansion_StartSegment &&
                            xtr.Expansion_StartSegment != null)
                            if (xtr.Expansion_StartSegment.Expanded == false)
                            {
                                RenderCollapsedText(RowIndex, xpos);
                                HasExpansion = true;
                                break;
                            }

                        if ((w.Type == WordType.xtSpace || w.Type == WordType.xtTab) &&
                            !DrawBreakpoint && Control.ShowTabGuides)
                        {
                            int xtab = xpos - (Control.View.TextMargin -
                                Control.View.ClientAreaStart + XOffset);
                            if (((double)xtab / (double)Control.PixelTabSize) == (xtab /
                                Control.PixelTabSize))
                                bbuff.FillRect(Control.TabGuideColor, xpos, 0, 1,
                                               this.Control.View.RowHeight);
                        }

                        if (w.Type == WordType.xtWord || 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.xtWord)
                                DrawBreakpoint = true;

                            if (xtr.Breakpoint && DrawBreakpoint)
                            {
                                bbuff.TextForeColor = Control.BreakPointForeColor;
                                bbuff.TextBackColor = Control.BreakPointBackColor;
                                bbuff.FontTransparent = false;
                            }


                            if (Control.BracketMatching && (w == this.BracketEnd || w ==
                                this.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, 0, wdh,
                                                   Control.View.RowHeight - 1);
                                }
                            }
                            else
                            {
                                wdh = bbuff.DrawTabbedString(w.Text, xpos, 0, taborig,
                                                             Control.PixelTabSize).Width;
                            }


                            //render errors
                            if (w.HasError || w.HasWarning)
                            {
                                //bbuff.FillRect (Color.Red,xpos,Control.View.RowHeight-2,wdh,2);
                                int ey = Control.View.RowHeight - 1;

                                Color c;
                                if (w.HasError)
                                    c = w.ErrorColor;
                                else
                                    c = w.WarningColor;

                                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.TextForeColor = this.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.xtTab && ws)
                        {
                            bbuff.Font = GFX.FontNormal;
                            bbuff.TextForeColor = this.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(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._CodeEditor.ShowEOLMarker && !HasExpansion)
                {
                    bbuff.Font = GFX.FontNormal;
                    bbuff.TextForeColor = this.Control._CodeEditor.EOLMarkerColor;
                    bbuff.FontTransparent = true;
                    bbuff.DrawTabbedString("?", xpos, 0, taborig, Control.PixelTabSize);
                }
            }
            else
            {
                //bbuff.TextForeColor =Color.Red;
                //bbuff.DrawTabbedString ("",Control.View.TextMargin ,1,0,Control.PixelTabSize);
            }


        }
        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);
                    //}
                }
            }
        }
示例#8
0
文件: Row.cs 项目: bartKam/hardek
		/// <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;
		}
示例#9
0
文件: Row.cs 项目: bartKam/hardek
		/// <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;
		}
示例#10
0
文件: Row.cs 项目: bartKam/hardek
		/// <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 mWords.IndexOf(word);
		}
示例#11
0
文件: Row.cs 项目: bartKam/hardek
		/// <summary>
		/// Adds a word object to this row
		/// </summary>
		/// <param name="word">Word object</param>
		public void Add(Word word)
		{
			this.mWords.Add(word);
		}
示例#12
0
文件: Row.cs 项目: bartKam/hardek
		public Word Add(string text)
		{
			Word xw = new Word();
			xw.Row = this;
			xw.Text = text;
			mWords.Add(xw);
			return xw;
		}
示例#13
0
文件: Row.cs 项目: bartKam/hardek
		/// <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;
		}
示例#14
0
文件: Row.cs 项目: bartKam/hardek
		/// <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;
		}