word_wrap = true;
richtext = false;
document = new Document(this);
+ document.WidthChanged += new EventHandler(document_WidthChanged);
//document.CaretMoved += new EventHandler(CaretMoved);
document.Wrap = true;
requested_height = -1;
int pos;
if (e.Button == MouseButtons.Left) {
- document.PositionCaret(e.X, e.Y);
+ document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
document.SetSelectionToCaret(true);
this.grabbed = true;
this.Capture = true;
this.Capture = false;
this.grabbed = false;
if (e.Button == MouseButtons.Left) {
- document.PositionCaret(e.X, e.Y);
+ document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
document.SetSelectionToCaret(false);
document.DisplayCaret();
return;
}
if (hscroll.Visible) {
- vscroll.Maximum += hscroll.Height * 2;
- canvas_height = this.Height - hscroll.Height * 2;
+ vscroll.Maximum += hscroll.Height;
+ canvas_height = this.Height - hscroll.Height;
}
if (vscroll.Visible) {
}
}
+ private void document_WidthChanged(object sender, EventArgs e) {\r
+ CalculateScrollBars();\r
+ }\r
+
private void hscroll_ValueChanged(object sender, EventArgs e) {
XplatUI.ScrollWindow(this.Handle, document.ViewPortX-this.hscroll.Value, 0, false);
document.ViewPortX = this.hscroll.Value;
document.UpdateCaret();
- Console.WriteLine("Dude scrolled horizontal");
+ //Console.WriteLine("Dude scrolled horizontal");
}
private void vscroll_ValueChanged(object sender, EventArgs e) {\r
XplatUI.ScrollWindow(this.Handle, 0, document.ViewPortY-this.vscroll.Value, false);
- document.ViewPortX = this.vscroll.Value;
+ document.ViewPortY = this.vscroll.Value;
document.UpdateCaret();
- Console.WriteLine("Dude scrolled vertical");
+ //Console.WriteLine("Dude scrolled vertical");
}\r
private void TextBoxBase_MouseMove(object sender, MouseEventArgs e) {
// FIXME - handle auto-scrolling if mouse is to the right/left of the window
if (grabbed) {
- document.PositionCaret(e.X, e.Y);
+ document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
document.SetSelectionToCaret(false);
document.DisplayCaret();
}
/// <summary>Ensure the caret is always visible</summary>\r
internal void CaretMoved(object sender, EventArgs e) {\r
Point pos;\r
+ int height;\r
\r
pos = document.Caret;\r
- Console.WriteLine("Caret now at {0} (Thumb: {1}x{2}, Canvas: {3}x{4}, Document {5}x{6})", pos, hscroll.Value, vscroll.Value, canvas_width, canvas_height, document.Width, document.Height);\r
+ //Console.WriteLine("Caret now at {0} (Thumb: {1}x{2}, Canvas: {3}x{4}, Document {5}x{6})", pos, hscroll.Value, vscroll.Value, canvas_width, canvas_height, document.Width, document.Height);\r
\r
// Handle horizontal scrolling\r
if (pos.X < (document.ViewPortX + track_width)) {\r
- if ((hscroll.Value - track_width) >= hscroll.Minimum) {\r
- hscroll.Value -= track_width;\r
- } else {\r
- hscroll.Value = hscroll.Minimum;\r
- }\r
+ do {\r
+ if ((hscroll.Value - track_width) >= hscroll.Minimum) {\r
+ hscroll.Value -= track_width;\r
+ } else {\r
+ hscroll.Value = hscroll.Minimum;\r
+ }\r
+ } while (hscroll.Value > pos.X);\r
}\r
\r
- if ((pos.X > (this.Width + document.ViewPortX - track_width)) && (hscroll.Value != hscroll.Maximum)) {\r
- if ((hscroll.Value + track_width) <= hscroll.Maximum) {\r
- hscroll.Value += track_width;\r
- } else {\r
- hscroll.Value = hscroll.Maximum;\r
- }\r
+ if ((pos.X > (this.canvas_width + document.ViewPortX - track_width)) && (hscroll.Value != hscroll.Maximum)) {\r
+ do {\r
+ if ((hscroll.Value + track_width) <= hscroll.Maximum) {\r
+ hscroll.Value += track_width;\r
+ } else {\r
+ hscroll.Value = hscroll.Maximum;\r
+ }\r
+ } while (pos.X > (hscroll.Value + this.canvas_width));\r
}\r
\r
if (!multiline) {\r
return;\r
}\r
-#if not\r
- // Handle vertical scrolling\r
- if (pos.Y < (document.ViewPortY + track_width)) {\r
- if ((hscroll.Value - track_width) >= hscroll.Minimum) {\r
- hscroll.Value -= track_width;\r
- } else {\r
- hscroll.Value = hscroll.Minimum;\r
- }\r
\r
- if (pos.X > this.Width + document.ViewPortX) {\r
- hscroll.Value = hscroll.Minimum;\r
- }\r
- }\r
+ // Handle vertical scrolling\r
+ height = document.CaretLine.Height;\r
\r
- if (pos.X > (this.Width + document.ViewPortX - track_width)) {\r
- if ((hscroll.Value + track_width) <= hscroll.Maximum) {\r
- hscroll.Value += track_width;\r
- } else {\r
- hscroll.Value = hscroll.Maximum;\r
- }\r
+ if (pos.Y < document.ViewPortY) {\r
+ vscroll.Value = pos.Y;\r
}\r
\r
- if (pos.X < document.ViewPortX) {\r
- hscroll.Value = hscroll.Minimum;\r
+ if ((pos.Y + height) > (document.ViewPortY + canvas_height)) {\r
+ vscroll.Value = pos.Y - canvas_height + height;\r
}\r
-#endif\r
}\r
}
}
internal Point Caret {
get {
- return new Point((int)caret.tag.line.widths[caret.pos] + caret.line.align_shift, caret.line.Y + caret.tag.shift);
+ return new Point((int)caret.tag.line.widths[caret.pos] + caret.line.align_shift, caret.line.Y);
}
}
}
internal void PositionCaret(int x, int y) {
- caret.tag = FindCursor(x + viewport_x, y + viewport_y, out caret.pos);
+ caret.tag = FindCursor(x, y, out caret.pos);
caret.line = caret.tag.line;
caret.height = caret.tag.height;
Brush hilight_text;
// First, figure out from what line to what line we need to draw
- start = GetLineByPixel(clip.Top - viewport_y, false).line_no;
- end = GetLineByPixel(clip.Bottom - viewport_y, false).line_no;
+ start = GetLineByPixel(clip.Top + viewport_y, false).line_no;
+ end = GetLineByPixel(clip.Bottom + viewport_y, false).line_no;
+Console.WriteLine("Starting drawing at line {0}, ending at line {1} (clip-bottom:{2})", start, end, clip.Bottom);
// Now draw our elements; try to only draw those that are visible
line_no = start;
Line line;
int line_no;
int Y;
+ int new_width;
Y = GetLine(start).Y;
line_no = start;
+ new_width = 0;
+
if (optimize) {
bool changed;
bool alignment_recalc;
end = this.lines;
}
- if (line.widths[line.text.Length] > this.document_x) {
- this.document_x = (int)line.widths[line.text.Length];
- alignment_recalc = true;
+ if (line.widths[line.text.Length] > new_width) {
+ new_width = (int)line.widths[line.text.Length];
}
// Calculate alignment
}
}
+ if (document_x < new_width) {
+ document_x = new_width;
+ alignment_recalc = true;
+ if (WidthChanged != null) {
+ WidthChanged(this, null);
+ }
+ }
+
if (alignment_recalc) {
RecalculateAlignments();
}
line = GetLine(lines);
- document_y = line.Y + line.height;
+ if (document_y != line.Y + line.height) {
+ document_y = line.Y + line.height;
+ if (HeightChanged != null) {
+ HeightChanged(this, null);
+ }
+ }
return changed;
} else {
shift = 0;
}
- if (line.widths[line.text.Length] > this.document_x) {
- this.document_x = (int)line.widths[line.text.Length];
+ if (line.widths[line.text.Length] > new_width) {
+ new_width = (int)line.widths[line.text.Length];
}
// Calculate alignment
break;
}
}
+
+ if (document_x != new_width) {
+ document_x = new_width;
+ if (WidthChanged != null) {
+ WidthChanged(this, null);
+ }
+ }
+
RecalculateAlignments();
line = GetLine(lines);
- document_y = line.Y + line.height;
+
+ if (document_y != line.Y + line.height) {
+ document_y = line.Y + line.height;
+ if (HeightChanged != null) {
+ HeightChanged(this, null);
+ }
+ }
return true;
}
#region Events
internal event EventHandler CaretMoved;
+ internal event EventHandler WidthChanged;
+ internal event EventHandler HeightChanged;
#endregion // Events
#region Administrative