[Monodevelop-patches-list] r477 - in trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src: Document Document/HighlightingStrategy Document/LineManager Gui Util

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Mon Jan 12 22:52:41 EST 2004


Author: benm
Date: 2004-01-12 22:52:41 -0500 (Mon, 12 Jan 2004)
New Revision: 477

Modified:
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/TextWord.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/LineManager/DefaultLineManager.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextArea.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextView.cs
   trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Util/RtfWriter.cs
Log:
you know what

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs	2004-01-13 03:50:16 UTC (rev 476)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/DefaultDocument.cs	2004-01-13 03:52:41 UTC (rev 477)
@@ -216,17 +216,17 @@
 				return;
 			}
 			OnDocumentAboutToBeChanged(new DocumentEventArgs(this, offset, -1, text));
-			DateTime time = DateTime.Now;
+			//DateTime time = DateTime.Now;
 			textBufferStrategy.Insert(offset, text);
 			
-			time = DateTime.Now;
+			//time = DateTime.Now;
 			lineTrackingStrategy.Insert(offset, text);
 			
-			time = DateTime.Now;
+			//time = DateTime.Now;
 			
 			undoStack.Push(new UndoableInsert(this, offset, text));
 			
-			time = DateTime.Now;
+			//time = DateTime.Now;
 			OnDocumentChanged(new DocumentEventArgs(this, offset, -1, text));
 		}
 		

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs	2004-01-13 03:50:16 UTC (rev 476)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs	2004-01-13 03:52:41 UTC (rev 477)
@@ -612,7 +612,7 @@
 								}
 							}
 							
-							words.Add(new TextWord(document, currentLine, currentOffset, currentLength, DigitColor, false));
+							words.Add(new TextWord(currentOffset, currentLength, DigitColor, false));
 							currentOffset += currentLength;
 							currentLength = 0;
 							continue;
@@ -625,7 +625,7 @@
 									PushCurWord(document, ref markNext, words);
 									string regex = currentLine.GetRegString(activeSpan.End, i, document);
 									currentLength += regex.Length;
-									words.Add(new TextWord(document, currentLine, currentOffset, currentLength, activeSpan.EndColor, false));
+									words.Add(new TextWord(currentOffset, currentLength, activeSpan.EndColor, false));
 									currentOffset += currentLength;
 									currentLength = 0;
 									i += regex.Length - 1;
@@ -638,12 +638,15 @@
 						
 						// check for SPAN BEGIN
 						if (activeRuleSet != null) {
-							foreach (Span span in activeRuleSet.Spans) {
+							ArrayList spans = activeRuleSet.Spans;
+							int c = spans.Count;
+							for (int j = 0; j < c; j ++) { Span span = (Span) spans [j];
+								
 								if (currentLine.MatchExpr(span.Begin, i, document)) {
 									PushCurWord(document, ref markNext, words);
 									string regex = currentLine.GetRegString(span.Begin, i, document);
 									currentLength += regex.Length;
-									words.Add(new TextWord(document, currentLine, currentOffset, currentLength, span.BeginColor, false));
+									words.Add(new TextWord(currentOffset, currentLength, span.BeginColor, false));
 									currentOffset += currentLength;
 									currentLength = 0;
 									
@@ -724,13 +727,13 @@
 						}
 						hasDefaultColor = true;
 					}
-					words.Add(new TextWord(document, currentLine, currentOffset, currentLength, markNext != null ? markNext : c, hasDefaultColor));
+					words.Add(new TextWord(currentOffset, currentLength, markNext != null ? markNext : c, hasDefaultColor));
 				} else {
 					HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
 					if (c == null) {
-						words.Add(new TextWord(document, currentLine, currentOffset, currentLength, defaultColor, true));
+						words.Add(new TextWord(currentOffset, currentLength, defaultColor, true));
 					} else {
-						words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false));
+						words.Add(new TextWord(currentOffset, currentLength, c, false));
 					}
 				}
 				

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/TextWord.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/TextWord.cs	2004-01-13 03:50:16 UTC (rev 476)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/TextWord.cs	2004-01-13 03:52:41 UTC (rev 477)
@@ -25,18 +25,13 @@
 	public class TextWord
 	{
 		HighlightColor  color;
-		LineSegment     word;
-		IDocument       document;
 		
 		int          offset;
 		int          length;
-		TextWordType type;
 		
-		static TextWord spaceWord = new TextWord(TextWordType.Space);
-		static TextWord tabWord   = new TextWord(TextWordType.Tab);
+		static TextWord spaceWord = new TextWord (TextWordType.Space);
+		static TextWord tabWord   = new TextWord (TextWordType.Tab);
 		
-		public bool hasDefaultColor;
-		
 		static public TextWord Space {
 			get {
 				return spaceWord;
@@ -51,34 +46,33 @@
 		
 		public int  Length {
 			get {
-				if (type == TextWordType.Word) {
-					return length;
-				} 
-				return 1;
+				return length;
 			}
 		}
 		
 		public bool HasDefaultColor {
 			get {
-				return hasDefaultColor;
+				return  offset & ~(1 << 31) != 0;
 			}
 		}
 		
 		public TextWordType Type {
 			get {
-				return type;
+				return 
+					this == spaceWord ? TextWordType.Space :
+					this == tabWord   ? TextWordType.Tab   :
+					                    TextWordType.Word  ;
 			}
 		}
 		
 //		string       myword = null;
-		public string Word {
-			get {
-				return document.GetText(word.Offset + offset, length);
+		public string GetWord (IDocument d, LineSegment l)
+		{
+			return d.GetText (l.Offset + offset, length);
 //				if (myword == null) {
 //					myword = document.GetText(word.Offset + offset, length);
 //				}
 //				return myword;
-			}
 		}
 		
 		public Pango.FontDescription Font {
@@ -104,29 +98,25 @@
 		
 		public bool IsWhiteSpace {
 			get {
-				return type == TextWordType.Space || type == TextWordType.Tab;
+				return this == spaceWord || this == tabWord;
 			}
 		}
 		
 		// TAB
 		private TextWord(TextWordType type)
-		{
-			this.type = type;
+		{
+			length = 1;
 		}
 		
-		public TextWord(IDocument document, LineSegment word, int offset, int length, HighlightColor color, bool hasDefaultColor)
+		public TextWord(int offset, int length, HighlightColor color, bool hasDefaultColor)
 		{
-			Debug.Assert(document != null);
-			Debug.Assert(word != null);
-			Debug.Assert(color != null);
+			Debug.Assert(color != null);
 			
-			this.document = document;
-			this.word  = word;
 			this.offset = offset;
 			this.length = length;
 			this.color = color;
-			this.hasDefaultColor = hasDefaultColor;
-			this.type  = TextWordType.Word;
+			if (hasDefaultColor)
+				this.offset |= (1 << 31);
 		}
 		
 		/// <summary>
@@ -134,7 +124,7 @@
 		/// </summary>
 		public override string ToString()
 		{
-			return "[TextWord: Word = " + Word + ", Font = " + Font.Family + ", Color = " + Color + "]";
+			return "[TextWord: , Font = " + Font.Family + ", Color = " + Color + "]";
 		}
 	}
 }

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/LineManager/DefaultLineManager.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/LineManager/DefaultLineManager.cs	2004-01-13 03:50:16 UTC (rev 476)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Document/LineManager/DefaultLineManager.cs	2004-01-13 03:52:41 UTC (rev 477)
@@ -295,7 +295,7 @@
 		
 		void RunHighlighter()
 		{
-			DateTime time = DateTime.Now;
+			//DateTime time = DateTime.Now;
 			if (highlightingStrategy != null) {
 				highlightingStrategy.MarkTokens(document, markLines);
 			}

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextArea.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextArea.cs	2004-01-13 03:50:16 UTC (rev 476)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextArea.cs	2004-01-13 03:52:41 UTC (rev 477)
@@ -798,11 +798,10 @@
 
 		public void Invalidate() 
 		{
-			if (GdkWindow == null) {
+			if (GdkWindow == null)
 				return;
-			}
-		
-			Invalidate (new System.Drawing.Rectangle(0, 0, GdkWindow.Size.Width, GdkWindow.Size.Height));
+			
+			Invalidate (new System.Drawing.Rectangle(0, 0, -1, -1));
 		}
 		
 		internal void Invalidate (System.Drawing.Rectangle rect) 
@@ -811,19 +810,21 @@
 			// FIXME Improve this
 			
 			try {
-				int x = Math.Max(rect.X, 0);
-				int y = Math.Max(rect.Y, 0);
-				int width = Math.Max(rect.Width, 0);
-				if (rect.Width < 0) {
-					width = GdkWindow.Size.Width;
-				}
-				int height = Math.Max(rect.Height, 0);
-				if (rect.Height < 0) {
-					height = GdkWindow.Size.Height;
-				}
+				Gdk.Window w = GdkWindow;
+				
+				int x = Math.Max (rect.X, 0);
+				int y = Math.Max (rect.Y, 0);
+				int width = Math.Max (rect.Width, 0);
+				int height = Math.Max (rect.Height, 0);
+				
+				if (rect.Width < 0)
+					width = w.Size.Width;
+				
+				if (rect.Height < 0)
+					height = w.Size.Height;
 
 				//Console.WriteLine ("{0} {1} {2} {3}", x, y, width, height);
-				GdkWindow.InvalidateRect(new Gdk.Rectangle(x, y, width, height), false);
+				w.InvalidateRect(new Gdk.Rectangle(x, y, width, height), false);
 			} catch {
 				//This try/catch seems to fix a bug when creating files
 			}

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextView.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextView.cs	2004-01-13 03:50:16 UTC (rev 476)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/TextView.cs	2004-01-13 03:52:41 UTC (rev 477)
@@ -223,7 +223,7 @@
 							break;
 						
 						case TextWordType.Word:
-							string word    = currentWord.Word;
+							string word    = currentWord.GetWord (textArea.Document, currentLine);
 							float  lastPos = physicalXPos;
 							
 							if (ColumnRange.WholeColumn.Equals(selectionRange) || selectionRange.EndColumn - 1  >= word.Length + logicalColumn &&
@@ -348,7 +348,19 @@
 
 		public float GetWidth(char ch)
 		{
-			return GetWidth(TextArea.GdkWindow, ch);
+			if (ch == ' ') {
+				return GetWidth('w'); // Hack! FIXME PEDRO
+			}		
+			object width = charWitdh[ch];
+			if (width == null) {
+				//Pango.Layout ly = new Pango.Layout(TextArea.PangoContext);
+				Pango.Layout ly = _layout;
+				ly.SetText(ch.ToString());
+				
+				charWitdh[ch] = (float) (ly.Size.Width/1024.0f - 1); // Hack! I don't know why it works substracting 1. FIXME PEDRO
+				return (float)charWitdh[ch];
+			}
+			return (float)width;
 		}
 		
 		public float GetWidth(Gdk.Drawable g, char ch)
@@ -442,7 +454,7 @@
 						break;
 
 					case TextWordType.Word:
-						string word    = currentWord.Word;
+						string word    = currentWord.GetWord (textArea.Document, currentLine);
 						
 						if (physicalXPos + MeasureString(FontContainer.DefaultFont, word) > xPos + spaceWidth/2) {
 							do {
@@ -494,7 +506,7 @@
 						break;
 
 					case TextWordType.Word:
-						string word    = currentWord.Word;
+						string word    = currentWord.GetWord (textArea.Document, currentLine);
 						if (currentColumn + word.Length > logicalColumn) {
 							word = word.Substring(0, logicalColumn - currentColumn);
 						}

Modified: trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Util/RtfWriter.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Util/RtfWriter.cs	2004-01-13 03:50:16 UTC (rev 476)
+++ trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Util/RtfWriter.cs	2004-01-13 03:52:41 UTC (rev 477)
@@ -98,8 +98,9 @@
 							
 							case TextWordType.Word:
 								Color c = word.Color;
+								string word_word = word.GetWord (textArea.Document, line);
 								
-								if (offset + word.Word.Length > selectionOffset && offset < selectionEndOffset) {
+								if (offset + word_word.Length > selectionOffset && offset < selectionEndOffset) {
 									string colorstr = c.R + ", " + c.G + ", " + c.B;
 									
 									if (colors[colorstr] == null) {
@@ -142,11 +143,11 @@
 									}
 									string printWord;
 									if (offset < selectionOffset) {
-										printWord = word.Word.Substring(selectionOffset - offset);
-									} else if (offset + word.Word.Length > selectionEndOffset) {
-										printWord = word.Word.Substring(0, (offset + word.Word.Length) - selectionEndOffset);
+										printWord = word_word.Substring(selectionOffset - offset);
+									} else if (offset + word_word.Length > selectionEndOffset) {
+										printWord = word_word.Substring(0, (offset + word_word.Length) - selectionEndOffset);
 									} else {
-										printWord = word.Word;
+										printWord = word_word;
 									}
 									
 									rtf.Append(printWord.Replace("{", "\\{").Replace("}", "\\}"));




More information about the Monodevelop-patches-list mailing list