internal int viewport_x;
internal int viewport_y; // The visible area of the document
+ internal int offset_x;
+ internal int offset_y;
internal int viewport_width;
internal int viewport_height;
internal int document_x; // Width of the document
internal int document_y; // Height of the document
- internal Rectangle invalid;
-
internal int crlf_size; // 1 or 2, depending on whether we use \r\n or just \n
internal TextBoxBase owner; // Who's owning us?
viewport_x = 0;
viewport_y = 0;
+ offset_x = 0;
+ offset_y = 0;
+
crlf_size = 2;
// Default selection is empty
}
}
+ // UIA: Method used via reflection in TextRangeProvider
internal int Lines {
get {
return lines;
}
}
+ internal int OffsetX
+ {
+ get
+ {
+ return offset_x;
+ }
+
+ set
+ {
+ offset_x = value;
+ }
+ }
+
+ internal int OffsetY
+ {
+ get
+ {
+ return offset_y;
+ }
+
+ set
+ {
+ offset_y = value;
+ }
+ }
+
internal int ViewPortWidth {
get {
return viewport_width;
private void SetSelectionVisible (bool value)
{
+ bool old_selection_visible = selection_visible;
selection_visible = value;
// cursor and selection are enemies, we can't have both in the same room at the same time
if (owner.IsHandleCreated && !owner.show_caret_w_selection)
XplatUI.CaretVisible (owner.Handle, !selection_visible);
+ if (UIASelectionChanged != null && (selection_visible || old_selection_visible))
+ UIASelectionChanged (this, EventArgs.Empty);
}
private void DecrementLines(int line_no) {
// Lineheight changed, invalidate the rest of the document
if ((line.Y - viewport_y) >=0 ) {
// We formatted something that's in view, only draw parts of the screen
- owner.Invalidate(new Rectangle(0, line.Y - viewport_y, viewport_width, owner.Height - line.Y - viewport_y));
+ owner.Invalidate(new Rectangle(
+ offset_x,
+ line.Y - viewport_y + offset_y,
+ viewport_width,
+ owner.Height - (line.Y - viewport_y)));
} else {
// The tag was above the visible area, draw everything
owner.Invalidate();
} else {
switch(line.alignment) {
case HorizontalAlignment.Left: {
- owner.Invalidate(new Rectangle(line.X + (int)line.widths[pos] - viewport_x - 1, line.Y - viewport_y, viewport_width, line.height + 1));
+ owner.Invalidate(new Rectangle(
+ line.X + ((int)line.widths[pos] - viewport_x - 1) + offset_x,
+ line.Y - viewport_y + offset_y,
+ viewport_width,
+ line.height + 1));
break;
}
case HorizontalAlignment.Center: {
- owner.Invalidate(new Rectangle(line.X, line.Y - viewport_y, viewport_width, line.height + 1));
+ owner.Invalidate(new Rectangle(
+ line.X + offset_x,
+ line.Y - viewport_y + offset_y,
+ viewport_width,
+ line.height + 1));
break;
}
case HorizontalAlignment.Right: {
- owner.Invalidate(new Rectangle(line.X, line.Y - viewport_y, (int)line.widths[pos + 1] - viewport_x + line.X, line.height + 1));
+ owner.Invalidate(new Rectangle(
+ line.X + offset_x,
+ line.Y - viewport_y + offset_y,
+ (int)line.widths[pos + 1] - viewport_x + line.X,
+ line.height + 1));
break;
}
}
int start_line_top = line.Y;
- int end_line_bottom;
- Line end_line;
-
- end_line = GetLine (line.line_no + line_count);
+ Line end_line = GetLine (line.line_no + line_count);
if (end_line == null)
end_line = GetLine (lines);
-
- end_line_bottom = end_line.Y + end_line.height;
+ if (end_line == null)
+ return;
+
+ int end_line_bottom = end_line.Y + end_line.height;
if (RecalculateDocument(owner.CreateGraphicsInternal(), line.line_no, line.line_no + line_count, true)) {
// Lineheight changed, invalidate the rest of the document
if ((line.Y - viewport_y) >=0 ) {
// We formatted something that's in view, only draw parts of the screen
- owner.Invalidate(new Rectangle(0, line.Y - viewport_y, viewport_width, owner.Height - line.Y - viewport_y));
+ owner.Invalidate(new Rectangle(
+ offset_x,
+ line.Y - viewport_y + offset_y,
+ viewport_width,
+ owner.Height - (line.Y - viewport_y)));
} else {
// The tag was above the visible area, draw everything
owner.Invalidate();
}
} else {
- int x = 0 - viewport_x;
+ int x = 0 - viewport_x + offset_x;
int w = viewport_width;
- int y = Math.Min (start_line_top - viewport_y, line.Y - viewport_y);
+ int y = Math.Min (start_line_top - viewport_y, line.Y - viewport_y) + offset_y;
int h = Math.Max (end_line_bottom - y, end_line.Y + end_line.height - y);
owner.Invalidate (new Rectangle (x, y, w, h));
}
} else {
if (char.IsLetterOrDigit (line_no_breaks_string [i]) == false &&
- "@-/:~.?=".IndexOf (line_no_breaks_string [i].ToString ()) == -1) {
+ "@-/:~.?=_&".IndexOf (line_no_breaks_string [i].ToString ()) == -1) {
link_end = i - 1;
line_no_breaks_index = i;
break;
int best_index = -1;
for (int i = 0; i < needles.Length; i++) {
-#if NET_2_0
int index = haystack.IndexOf (needles [i], start_index, StringComparison.InvariantCultureIgnoreCase);
-#else
- int index = haystack.ToLower().IndexOf(needles[i], start_index);
-#endif
if (index > -1) {
if (term_found > -1) {
if (owner.Focused) {
if (caret.height != caret.tag.Height)
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,
+ offset_x + (int)caret.tag.Line.widths[caret.pos] + caret.line.X - viewport_x,
+ offset_y + caret.line.Y + caret.tag.Shift - viewport_y + caret_shift);
}
if (CaretMoved != null) CaretMoved(this, EventArgs.Empty);
if (owner.ShowSelection && (!selection_visible || owner.show_caret_w_selection)) {
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 + offset_x,
+ offset_y + caret.line.Y + caret.tag.Shift - viewport_y + caret_shift);
}
if (CaretMoved != null) CaretMoved(this, EventArgs.Empty);
internal void CaretHasFocus() {
if ((caret.tag != null) && owner.IsHandleCreated) {
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,
+ offset_x + (int)caret.tag.Line.widths[caret.pos] + caret.line.X - viewport_x,
+ offset_y + caret.line.Y + caret.tag.Shift - viewport_y + caret_shift);
DisplayCaret ();
}
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,
+ offset_x + (int) caret.tag.Line.widths [caret.pos] + caret.line.X - viewport_x,
+ offset_y + caret.line.Y + viewport_y + caret_shift);
DisplayCaret ();
}
}
if (owner.Focused) {
- 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,
+ offset_x + (int)caret.tag.Line.widths[caret.pos] + caret.line.X - viewport_x,
+ offset_y + caret.line.Y + caret.tag.Shift - viewport_y + caret_shift);
DisplayCaret ();
}
case CaretDirection.PgUp: {
- if (viewport_y == 0 && owner.richtext) {
+ if (caret.line.line_no == 1 && owner.richtext) {
owner.vscroll.Value = 0;
Line line = GetLine (1);
PositionCaret (line, 0);
case CaretDirection.PgDn: {
- if (viewport_y + viewport_height >= document_y && owner.richtext) {
+ if (caret.line.line_no == lines && owner.richtext) {
owner.vscroll.Value = owner.vscroll.Maximum - viewport_height + 1;
Line line = GetLine (lines);
- PositionCaret (line, line.Text.Length);
+ PositionCaret (line, line.TextLengthWithoutEnding());
}
int y_offset = caret.line.Y - viewport_y;
Console.WriteLine ("</doc>");
}
+ // UIA: Used via reflection by TextProviderBehavior
+ internal void GetVisibleLineIndexes (Rectangle clip, out int start, out int end)
+ {
+ if (multiline) {
+ /* Expand the region slightly to be sure to
+ * paint the full extent of the line of text.
+ * See bug 464464.
+ */
+ start = GetLineByPixel(clip.Top + viewport_y - offset_y - 1, false).line_no;
+ end = GetLineByPixel(clip.Bottom + viewport_y - offset_y + 1, false).line_no;
+ } else {
+ start = GetLineByPixel(clip.Left + viewport_x - offset_x, false).line_no;
+ end = GetLineByPixel(clip.Right + viewport_x - offset_x, false).line_no;
+ }
+ }
+
internal void Draw (Graphics g, Rectangle clip)
{
Line line; // Current line being drawn
Color current_color;
// First, figure out from what line to what line we need to draw
-
- if (multiline) {
- start = GetLineByPixel(clip.Top + viewport_y, false).line_no;
- end = GetLineByPixel(clip.Bottom + viewport_y, false).line_no;
- } else {
- start = GetLineByPixel(clip.Left + viewport_x, false).line_no;
- end = GetLineByPixel(clip.Right + viewport_x, false).line_no;
- }
+ GetVisibleLineIndexes (clip, out start, out end);
// remove links in the list (used for mouse down events) that are within the clip area.
InvalidateLinks (clip);
/// Make sure that we aren't drawing one more line then we need to
line = GetLine (end - 1);
- if (line != null && clip.Bottom == line.Y + line.height - viewport_y)
+ if (line != null && clip.Bottom == offset_y + line.Y + line.height - viewport_y)
end--;
line_no = start;
// Non multiline selection can be handled outside of the loop
if (!multiline && selection_visible && owner.ShowSelection) {
g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
- selection_start.line.widths [selection_start.pos] +
+ offset_x + selection_start.line.widths [selection_start.pos] +
selection_start.line.X - viewport_x,
- selection_start.line.Y,
+ offset_y + selection_start.line.Y,
(selection_end.line.X + selection_end.line.widths [selection_end.pos]) -
(selection_start.line.X + selection_start.line.widths [selection_start.pos]),
selection_start.line.height);
while (line_no <= end) {
line = GetLine (line_no);
- float line_y = line.Y - viewport_y;
+ float line_y = line.Y - viewport_y + offset_y;
tag = line.tags;
if (!calc_pass) {
} else if (multiline) {
// lets draw some selection baby!! (non multiline selection is drawn outside the loop)
g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
- line.widths [line_selection_start - 1] + line.X - viewport_x,
+ offset_x + line.widths [line_selection_start - 1] + line.X - viewport_x,
line_y, line.widths [line_selection_end - 1] - line.widths [line_selection_start - 1],
line.height);
}
continue;
}
- if (((tag.X + tag.Width) < (clip.Left - viewport_x)) && (tag.X > (clip.Right - viewport_x))) {
+ if (((tag.X + tag.Width) < (clip.Left - viewport_x - offset_x)) &&
+ (tag.X > (clip.Right - viewport_x - offset_x))) {
tag = tag.Next;
continue;
}
if (tag.BackColor != Color.Empty) {
- g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (tag.BackColor), tag.X + line.X - viewport_x,
+ g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (tag.BackColor),
+ offset_x + tag.X + line.X - viewport_x,
line_y + tag.Shift, tag.Width, line.height);
}
Rectangle text_size;
tag.Draw (g, current_color,
- line.X - viewport_x,
+ offset_x + line.X - viewport_x,
line_y + tag.Shift,
old_tag_pos - 1, Math.Min (tag.Start + tag.Length, tag_pos) - 1,
text.ToString (), out text_size, tag.IsLink);
return string.Empty;
}
+ internal LineEnding StringToLineEnding (string ending)
+ {
+ switch (ending) {
+ case "\r":
+ return LineEnding.Limp;
+ case "\r\n":
+ return LineEnding.Hard;
+ case "\r\r\n":
+ return LineEnding.Soft;
+ case "\n":
+ return LineEnding.Rich;
+ default:
+ return LineEnding.None;
+ }
+ }
+
internal void Insert (Line line, int pos, bool update_caret, string s)
{
Insert (line, pos, update_caret, s, line.FindTag (pos));
base_line = line.line_no;
old_line_count = lines;
+ // Discard chars after any possible -unlikely- end of file
+ int eof_index = s.IndexOf ('\0');
+ if (eof_index != -1)
+ s = s.Substring (0, eof_index);
+
break_index = GetLineEnding (s, 0, out ending, LineEnding.Hard | LineEnding.Rich);
// There are no line feeds in our text to be pasted
// Allow the document to recalculate things
ResumeRecalc (false);
+ // Update our character count
+ CharCount += s.Length;
+
UpdateView (line, lines - old_line_count + 1, pos);
// Move the caret to the end of the inserted text if requested
// 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);
+ // Update our character count
+ CharCount++;
+
undo.RecordTyping (caret.line, caret.pos, ch);
UpdateView (caret.line, caret.pos);
if ((pos == 0 && forward == false) || (pos == line.text.Length && forward == true))
return;
- if (forward)
+ undo.BeginUserAction ("Delete");
+
+ if (forward) {
+ undo.RecordDeleteString (line, pos, line, pos + 1);
DeleteChars (line, pos, 1);
- else
+ } else {
+ undo.RecordDeleteString (line, pos - 1, line, pos);
DeleteChars (line, pos - 1, 1);
+ }
+
+ undo.EndUserAction ();
}
// Combine two lines
caret.line = new_line;
caret.tag = new_line.tags;
caret.pos = 0;
+
+ if (selection_visible == false) {
+ SetSelectionToCaret (true);
+ }
}
if (move_sel_start) {
caret.line = new_line;
caret.pos = caret.pos - pos;
caret.tag = caret.line.FindTag(caret.pos);
+
+ if (selection_visible == false) {
+ SetSelectionToCaret (true);
+ }
}
if (move_sel_start) {
#endif
owner.Invalidate(new Rectangle (
- (int)l1.widths[p1] + l1.X - viewport_x,
- l1.Y - viewport_y,
- endpoint - (int)l1.widths[p1] + 1,
+ offset_x + (int)l1.widths[p1] + l1.X - viewport_x,
+ offset_y + l1.Y - viewport_y,
+ endpoint - (int) l1.widths [p1] + 1,
l1.height));
return;
}
// Three invalidates:
// First line from start
- owner.Invalidate(new Rectangle((int)l1.widths[p1] + l1.X - viewport_x, l1.Y - viewport_y, viewport_width, l1.height));
+ owner.Invalidate(new Rectangle(
+ offset_x + (int)l1.widths[p1] + l1.X - viewport_x,
+ offset_y + l1.Y - viewport_y,
+ viewport_width,
+ l1.height));
// lines inbetween
int y;
y = GetLine(l1.line_no + 1).Y;
- owner.Invalidate(new Rectangle(0, y - viewport_y, viewport_width, l2.Y - y));
+ owner.Invalidate(new Rectangle(
+ offset_x,
+ offset_y + y - viewport_y,
+ viewport_width,
+ l2.Y - y));
#if Debug
Console.WriteLine("Invaliding from {0}:{1} to {2}:{3} Middle => x={4}, y={5}, {6}x{7}", l1.line_no, p1, l2.line_no, p2, 0, y - viewport_y, viewport_width, l2.Y - y);
// Last line to end
- owner.Invalidate(new Rectangle((int)l2.widths[0] + l2.X - viewport_x, l2.Y - viewport_y, (int)l2.widths[p2] + 1, l2.height));
+ owner.Invalidate(new Rectangle(
+ offset_x + (int)l2.widths[0] + l2.X - viewport_x,
+ offset_y + l2.Y - viewport_y,
+ (int)l2.widths[p2] + 1,
+ l2.height));
+
#if Debug
Console.WriteLine("Invaliding from {0}:{1} to {2}:{3} End => x={4}, y={5}, {6}x{7}", l1.line_no, p1, l2.line_no, p2, (int)l2.widths[0] + l2.X - viewport_x, l2.Y - viewport_y, (int)l2.widths[p2] + 1, l2.height);
-
#endif
}
start = selection_start.line.line_no;
end = selection_end.line.line_no;
- sb.Append(selection_start.line.text.ToString(selection_start.pos, selection_start.line.text.Length - selection_start.pos) + Environment.NewLine);
+ sb.Append(selection_start.line.text.ToString(selection_start.pos, selection_start.line.text.Length - selection_start.pos));
if ((start + 1) < end) {
for (i = start + 1; i < end; i++) {
- sb.Append(GetLine(i).text.ToString() + Environment.NewLine);
+ sb.Append(GetLine(i).text.ToString());
}
}
internal void ReplaceSelection(string s, bool select_new) {
int i;
- int selection_pos_on_line = selection_start.pos;
int selection_start_pos = LineTagToCharIndex (selection_start.line, selection_start.pos);
SuspendRecalc ();
}
+ // UIA: Method used via reflection in TextRangeProvider
+
/// <summary>Give it a Line number and it returns the Line object at with that line number</summary>
internal Line GetLine(int LineNo) {
Line line = document;
}
internal Line ParagraphStart(Line line) {
- while (line.ending == LineEnding.Wrap) {
- line = GetLine(line.line_no - 1);
- }
+ Line lastline = line;
+ do {
+ if (line.line_no <= 1)
+ break;
+
+ line = lastline;
+ lastline = GetLine (line.line_no - 1);
+ } while (lastline.ending == LineEnding.Wrap);
+
return line;
}
return last;
}
+ // UIA: Method used via reflection in TextProviderBehavior
+
// Give it x/y pixel coordinates and it returns the Tag at that position
internal LineTag FindCursor (int x, int y, out int index)
{
Line line;
+ x -= offset_x;
+ y -= offset_y;
+
line = GetLineByPixel (multiline ? y : x, false);
- LineTag tag = line.GetTag (x - line.align_shift);
+ LineTag tag = line.GetTag (x);
if (tag.Length == 0 && tag.Start == 1)
index = 0;
internal event EventHandler WidthChanged;
internal event EventHandler HeightChanged;
internal event EventHandler LengthChanged;
+ internal event EventHandler UIASelectionChanged;
#endregion // Events
#region Administrative
redo_actions.Clear();
}
- internal void Undo ()
+ internal bool Undo ()
{
Action action;
bool user_action_finished = false;
if (undo_actions.Count == 0)
- return;
-
- // Nuke the redo queue
- redo_actions.Clear ();
+ return false;
locked = true;
do {
} while (!user_action_finished && undo_actions.Count > 0);
locked = false;
+
+ return true;
}
- internal void Redo ()
+ internal bool Redo ()
{
Action action;
bool user_action_finished = false;
if (redo_actions.Count == 0)
- return;
-
- // You can't undo anything after redoing
- undo_actions.Clear ();
+ return false;
locked = true;
do {
int start_index;
action = (Action) redo_actions.Pop ();
+ undo_actions.Push (action);
switch (action.type) {
} while (!user_action_finished && redo_actions.Count > 0);
locked = false;
+
+ return true;
}
#endregion // Internal Methods
if (locked)
return;
+ // Nuke the redo queue
+ redo_actions.Clear ();
+
Action ua = new Action ();
ua.type = ActionType.UserActionBegin;
ua.data = name;
if (locked)
return;
+ // Nuke the redo queue
+ redo_actions.Clear ();
+
Action a = new Action ();
// We cant simply store the string, because then formatting would be lost
if (locked || str.Length == 0)
return;
+ // Nuke the redo queue
+ redo_actions.Clear ();
+
Action a = new Action ();
a.type = ActionType.InsertString;
if (locked)
return;
+ // Nuke the redo queue
+ redo_actions.Clear ();
+
Action a = null;
if (undo_actions.Count > 0)