25#include <wx/textctrl.h>
26#include <wx/dcclient.h>
27#include <wx/clipbrd.h>
31TTYScroll::TTYScroll(wxWindow *parent,
int n_lines, wxTextCtrl &tFilter)
32 : wxScrolledWindow(parent), m_nLines(n_lines), m_tFilter(tFilter) {
35 dc.GetTextExtent(_T(
"Line Height"), NULL, &m_hLine);
37 SetScrollRate(0, m_hLine);
38 SetVirtualSize(-1, (m_nLines + 1) * m_hLine);
39 m_plineArray =
new wxArrayString;
40 for (
unsigned int i = 0; i < m_nLines; i++) m_plineArray->Add(_T(
""));
43TTYScroll::~TTYScroll() {
delete m_plineArray; }
45void TTYScroll::Add(
const wxString &line) {
46 wxString filter = m_tFilter.GetValue();
47 if (!bpause && (filter.IsEmpty() || line.Contains(filter))) {
48 if (m_plineArray->GetCount() > m_nLines - 1) {
49 wxArrayString *p_newArray =
new wxArrayString;
51 for (
unsigned int i = 1; i < m_plineArray->GetCount(); i++)
52 p_newArray->Add(m_plineArray->Item(i));
55 m_plineArray = p_newArray;
58 m_plineArray->Add(line);
63void TTYScroll::OnDraw(wxDC &dc) {
65 wxRect rectUpdate = GetUpdateRegion().GetBox();
66 CalcUnscrolledPosition(rectUpdate.x, rectUpdate.y, &rectUpdate.x,
69 size_t lineFrom = rectUpdate.y / m_hLine,
70 lineTo = rectUpdate.GetBottom() / m_hLine;
72 if (lineTo > m_nLines - 1) lineTo = m_nLines - 1;
74 wxCoord y = lineFrom * m_hLine;
76 for (
size_t line = lineFrom; line <= lineTo; line++) {
78 CalcScrolledPosition(0, y, NULL, &yPhys);
80 wxString ls = m_plineArray->Item(line);
81 if (ls.Mid(0, 7) == _T(
"<GREEN>")) {
82 dc.SetTextForeground(wxColour(_T(
"DARK GREEN")));
84 }
else if (ls.Mid(0, 7) == _T(
"<GOLD>")) {
85 dc.SetTextForeground(wxColour(_T(
"GOLD")));
87 }
else if (ls.Mid(0, 6) == _T(
"<BLUE>")) {
88 dc.SetTextForeground(wxColour(_T(
"BLUE")));
90 }
else if (ls.Mid(0, 5) == _T(
"<RED>")) {
91 dc.SetTextForeground(wxColour(_T(
"RED")));
93 }
else if (ls.Mid(0, 7) == _T(
"<BROWN>")) {
94 dc.SetTextForeground(wxColour(_T(
"BROWN")));
96 }
else if (ls.Mid(0, 8) == _T(
"<SIENNA>")) {
97 dc.SetTextForeground(wxColour(_T(
"SIENNA")));
99 }
else if (ls.Mid(0, 8) == _T(
"<MAROON>")) {
100 dc.SetTextForeground(wxColour(_T(
"MAROON")));
102 }
else if (ls.Mid(0, 7) == _T(
"<CORAL>")) {
103 dc.SetTextForeground(wxColour(_T(
"CORAL")));
106 dc.DrawText(lss, 0, y);
111void TTYScroll::Copy() {
113 for (
unsigned int i = 0; i < m_plineArray->GetCount(); i++) {
114 theText.append(m_plineArray->Item(i));
115 theText.append(
"\n");
118 if (wxTheClipboard->Open()) {
119 wxTheClipboard->SetData(
new wxTextDataObject(theText));
120 wxTheClipboard->Close();