+2008-02-02 Luke Page <luke.a.page@gmail.com>
+
+ * Line.cs, LineTag.cs, RichTextBox.cs, TextControl.cs
+ Fixes bug 351938 - caret is positioned correctly when drawn
+ and when calculating textual position of caret, no longer
+ has a NRE in certain situations.
+
2008-02-01 Geoff Norton <gnorton@novell.com>
* Hwnd.cs: Ensure that windows moved into -'ve coordinate space
bool wrapped;\r
Line line;\r
int wrap_pos;\r
+ int prev_height;\r
+ int prev_ascent;\r
\r
pos = 0;\r
len = this.text.Length;\r
tag = this.tags;\r
prev_offset = this.offset; // For drawing optimization calculations\r
+ prev_height = this.height;\r
+ prev_ascent = this.ascent;\r
this.height = 0; // Reset line height\r
this.ascent = 0; // Reset the ascent for the line\r
tag.Shift = 0;\r
wrap_pos = 0;\r
\r
while (pos < len) {\r
+\r
while (tag.Length == 0) { // We should always have tags after a tag.length==0 unless len==0\r
//tag.Ascent = 0;\r
- tag.Shift = 0;\r
+ tag.Shift = tag.Line.ascent - tag.Ascent;\r
tag = tag.Next;\r
}\r
\r
}\r
}\r
\r
+ while (tag != null) { \r
+ tag.Shift = tag.Line.ascent - tag.Ascent;\r
+ tag = tag.Next;\r
+ }\r
+\r
if (this.height == 0) {\r
this.height = tags.Font.Height;\r
- tag.Height = this.height;\r
+ tags.Height = this.height;\r
+ tags.Shift = 0;\r
}\r
\r
- if (prev_offset != offset)\r
+ if (prev_offset != offset || prev_height != this.height || prev_ascent != this.ascent)\r
retval = true;\r
\r
return retval;\r
return tag; // Not sure if we should get the final tag here\r
\r
while (tag != null) {\r
- if ((tag.start <= pos) && (pos <= tag.End))\r
+ // [H e][l][l o _ W][o r] Text\r
+ // [1 2][3][4 5 6 7][8 9] Start\r
+ // 3 4 8 10 End\r
+ // 0 1 2 3 4 5 6 7 8 9 Pos\r
+ if ((tag.start <= pos) && (pos < tag.End))\r
return GetFinalTag (tag);\r
\r
tag = tag.next;\r
return retval;\r
}\r
\r
- start_tag = FindTag (line, formatStart);\r
+ start_tag = FindTag (line, formatStart - 1);\r
\r
// we are at an empty tag already!\r
// e.g. [Tag 0 - "He"][Tag 1 = 0 length][Tag 2 "llo world"]\r
return retval;\r
\r
/// Now do the last tag\r
- end_tag = FindTag (line, end);\r
+ end_tag = FindTag (line, end-1);\r
\r
if (end_tag != null) {\r
end_tag.Break (end);\r
int length_no_ending = line.TextLengthWithoutEnding ();\r
\r
if (Length == 0)\r
- return start;\r
+ return low-1;\r
\r
if (length_no_ending == 0)\r
return 0;\r
- \r
- if (x < line.widths[low])\r
+\r
+ if (x < line.widths [low]) {\r
+ if (low == 1 && x > (line.widths [1] / 2))\r
+ return low;\r
return low - 1;\r
+ }\r
\r
if (x > line.widths[length_no_ending])\r
return length_no_ending;\r
\r
private static void SetFormat (LineTag tag, Font font, Color color, Color back_color, FormatSpecified specified)\r
{\r
- if ((FormatSpecified.Font & specified) == FormatSpecified.Font)\r
+ if ((FormatSpecified.Font & specified) == FormatSpecified.Font) {\r
tag.Font = font;\r
+ }\r
if ((FormatSpecified.Color & specified) == FormatSpecified.Color)\r
tag.color = color;\r
if ((FormatSpecified.BackColor & specified) == FormatSpecified.BackColor) {\r
remove { base.QueryContinueDrag -= value; }
}
+ [MonoTODO("Currently does not ever fire")]
public event EventHandler SelectionChanged {
add { Events.AddHandler (SelectionChangedEvent, value); }
remove { Events.RemoveHandler (SelectionChangedEvent, value); }
MoveCaretToTextTag ();
}
- caret.height = caret.tag.Height;
+ // if the caret has had SelectionFont changed to a
+ // different height, we reflect changes unless the new
+ // font is larger than the line (line recalculations
+ // ignore empty tags) in which case we make it equal
+ // the line height and then when text is entered
+ if (caret.tag.Height > caret.tag.Line.Height) {
+ caret.height = caret.line.height;
+ } else {
+ caret.height = caret.tag.Height;
+ }
if (owner.Focused) {
XplatUI.CreateCaret(owner.Handle, caret_width, caret.height);
- XplatUI.SetCaretPos(owner.Handle, (int)caret.tag.Line.widths[caret.pos] + caret.line.X - viewport_x, caret.line.Y + caret.tag.Shift - viewport_y + caret_shift);
+ XplatUI.SetCaretPos (owner.Handle, (int) caret.tag.Line.widths [caret.pos] + caret.line.X - viewport_x, caret.line.Y + viewport_y + caret_shift);
DisplayCaret ();
}
// Inserts a character at the current caret position
internal void InsertCharAtCaret (char ch, bool move_caret)
{
- caret.line.InsertString (caret.pos, ch.ToString ());
+ caret.line.InsertString (caret.pos, ch.ToString(), caret.tag);
undo.RecordTyping (caret.line, caret.pos, ch);