1
2
3
4
5
6 using System;
7 using System.Collections;
8 using System.Windows.API;
9
10 namespace System.Windows
11 {
12 public nothrow ControlCreateParams& LogViewControlCreateParams(ControlCreateParams& controlCreateParams)
13 {
14 return controlCreateParams.SetWindowClassName("System.Windows.LogView").SetWindowClassStyle(DoubleClickWindowClassStyle()).
15 SetWindowStyle(cast<WindowStyle>(DefaultChildWindowStyle() | WindowStyle.WS_TABSTOP)).
16 SetWindowClassBackgroundColor(SystemColor.COLOR_WINDOW).SetBackgroundColor(Color.White());
17 }
18
19 public nothrow TextViewCreateParams& LogViewTextViewCreateParams(TextViewCreateParams& textViewCreateParams)
20 {
21 return textViewCreateParams.SetFontSize(9.0f);
22 }
23
24 public class LogViewCreateParams
25 {
26 public nothrow LogViewCreateParams(TextViewCreateParams& textViewCreateParams_) : textViewCreateParams(textViewCreateParams_)
27 {
28 }
29 public nothrow LogViewCreateParams& Defaults()
30 {
31 return *this;
32 }
33 public TextViewCreateParams& textViewCreateParams;
34 }
35
36 public class LogView : TextView
37 {
38 public LogView(const FontFamily& fontFamily, float fontSize, const Color& backgroundColor, const Color& textColor, const Point& location,
39 const Size& size, Dock dock, Anchors anchors) :
40 base(fontFamily, fontSize, backgroundColor, textColor, location, size, dock, anchors)
41 {
42 SetReadOnly();
43 }
44 public LogView(const Point& location, const Size& size, Dock dock, Anchors anchors) :
45 this(FontFamily("Consolas"), 9.0f, Color.White(), Color.Black(), location, size, dock, anchors)
46 {
47 }
48 public LogView() : this(Point(0, 0), Size(0, 0), Dock.bottom, Anchors.none)
49 {
50 }
51 public LogView(LogViewCreateParams& createParams) : base(createParams.textViewCreateParams)
52 {
53 SetReadOnly();
54 }
55 public virtual void WriteLine(const string& text)
56 {
57 int startLineNumber = cast<int>(Lines().Count() - 1);
58 List<ustring> lines = SplitTextIntoLines(ToUtf32(text));
59 for (const ustring& line : lines)
60 {
61 AddLine(line);
62 }
63 SetCaretLineCol(cast<int>(Lines().Count()), 1);
64 SetTextExtent();
65 ScrollToCaret();
66 SetChanged();
67 InvalidateLines(startLineNumber, cast<int>(startLineNumber + lines.Count()));
68 }
69 protected override void OnPaint(PaintEventArgs& args)
70 {
71 base->OnPaint(args);
72 }
73 protected override void OnMouseDown(MouseEventArgs& args)
74 {
75 base->OnMouseDown(args);
76 }
77 protected override void OnKeyDown(KeyEventArgs& args)
78 {
79 base->OnKeyDown(args);
80 if (CaretLine() == Lines().Count())
81 {
82 Invalidate();
83 }
84 }
85 }
86 }