26 #include <wx/statbox.h>
27 #include <wx/bmpbuttn.h>
28 #include <wx/dcmemory.h>
29 #include <wx/dialog.h>
30 #include <wx/settings.h>
31 #include <wx/dcscreen.h>
33 #include "TTYWindow.h"
34 #include "TTYScroll.h"
35 #include "WindowDestroyListener.h"
36 #include "color_handler.h"
40 IMPLEMENT_DYNAMIC_CLASS(
TTYWindow, wxFrame)
43 EVT_CLOSE(TTYWindow::OnCloseWindow)
48 TTYWindow::TTYWindow(wxWindow* parent,
int n_lines,
50 : m_window_destroy_listener(listener), m_tty_scroll(NULL) {
52 parent, -1, _T(
"Title"), wxDefaultPosition, wxDefaultSize,
53 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFRAME_FLOAT_ON_PARENT);
55 wxBoxSizer* bSizerOuterContainer =
new wxBoxSizer(wxVERTICAL);
56 SetSizer(bSizerOuterContainer);
58 m_filter =
new wxTextCtrl(
this, wxID_ANY);
60 m_tty_scroll =
new TTYScroll(
this, n_lines, *m_filter);
61 m_tty_scroll->Scroll(-1, 1000);
63 bSizerOuterContainer->Add(m_tty_scroll, 1, wxEXPAND, 5);
65 wxStaticBox* psbf =
new wxStaticBox(
this, wxID_ANY, _(
"Filter"));
66 wxStaticBoxSizer* sbSizer2 =
new wxStaticBoxSizer(psbf, wxVERTICAL);
67 sbSizer2->Add(m_filter, 1, wxALL | wxEXPAND, 5);
68 bSizerOuterContainer->Add(sbSizer2, 0, wxEXPAND, 5);
70 wxBoxSizer* bSizerBottomContainer =
new wxBoxSizer(wxHORIZONTAL);
71 bSizerOuterContainer->Add(bSizerBottomContainer, 0, wxEXPAND, 5);
73 wxStaticBox* psb =
new wxStaticBox(
this, wxID_ANY, _(
"Legend"));
74 wxStaticBoxSizer* sbSizer1 =
new wxStaticBoxSizer(psb, wxVERTICAL);
75 bSizerBottomContainer->Add(sbSizer1, 0, wxALIGN_LEFT | wxALL, 5);
78 wxBitmapButton* bb =
new wxBitmapButton(
this, wxID_ANY, m_bm_legend);
79 sbSizer1->Add(bb, 1, wxALL | wxEXPAND, 5);
81 wxStaticBox* buttonBox =
new wxStaticBox(
this, wxID_ANY, wxEmptyString);
82 wxStaticBoxSizer* bbSizer1 =
new wxStaticBoxSizer(buttonBox, wxVERTICAL);
84 m_btn_pause =
new wxButton(
this, wxID_ANY, _(
"Pause"), wxDefaultPosition,
86 m_btn_copy =
new wxButton(
this, wxID_ANY, _(
"Copy"), wxDefaultPosition,
88 m_btn_copy->SetToolTip(_(
"Copy NMEA Debug window to clipboard."));
90 bbSizer1->Add(m_btn_pause, 0, wxALL, 5);
91 bbSizer1->Add(m_btn_copy, 0, wxALL, 5);
92 bSizerBottomContainer->Add(bbSizer1, 1, wxALL | wxEXPAND, 5);
94 m_btn_copy->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
95 wxCommandEventHandler(TTYWindow::OnCopyClick), NULL,
97 m_btn_pause->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
98 wxCommandEventHandler(TTYWindow::OnPauseClick), NULL,
104 TTYWindow::~TTYWindow() {
111 void TTYWindow::CreateLegendBitmap() {
112 double dip_factor = OCPN_GetWinDIPScaleFactor();
114 wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
116 dcs.GetTextExtent(
"M", &width, &height, NULL, NULL, &font);
117 double ref_dim = height * dip_factor;
119 m_bm_legend.Create(36 * width * dip_factor, 6.5 * ref_dim);
121 dc.SelectObject(m_bm_legend);
122 if (m_bm_legend.IsOk()) {
123 dc.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)));
127 int yp = ref_dim * 1.25;
128 int y = ref_dim * .25;
130 int text_x = ref_dim * 1.5;
131 int boff = ref_dim *.25;
133 wxBrush b1(wxColour(_T(
"DARK GREEN")));
135 dc.DrawRectangle(boff, y, bsize, bsize);
136 dc.SetTextForeground(wxColour(_T(
"DARK GREEN")));
137 dc.DrawText(_(
"Message accepted"), text_x, y);
140 wxBrush b2(wxColour(_T(
"CORAL")));
142 dc.DrawRectangle(boff, y, bsize, bsize);
143 dc.SetTextForeground(wxColour(_T(
"CORAL")));
145 _(
"Input message filtered, output message filtered and dropped"), text_x,
149 wxBrush b3(wxColour(_T(
"MAROON")));
151 dc.DrawRectangle(boff, y, bsize, bsize);
152 dc.SetTextForeground(wxColour(_T(
"MAROON")));
153 dc.DrawText(_(
"Input Message filtered and dropped"), text_x, y);
156 wxBrush b4(wxColour(_T(
"BLUE")));
158 dc.DrawRectangle(boff, y, bsize, bsize);
159 dc.SetTextForeground(wxColour(_T(
"BLUE")));
160 dc.DrawText(_(
"Output Message"), text_x, y);
163 wxBrush b5(wxColour(_T(
"RED")));
165 dc.DrawRectangle(boff, y, bsize, bsize);
166 dc.SetTextForeground(wxColour(_T(
"RED")));
167 dc.DrawText(_(
"Information Message or Message with errors"), text_x, y);
169 dc.SelectObject(wxNullBitmap);
172 void TTYWindow::OnPauseClick(wxCommandEvent&) {
175 m_tty_scroll->Pause(
true);
176 m_btn_pause->SetLabel(_(
"Resume"));
179 m_tty_scroll->Pause(
false);
181 m_btn_pause->SetLabel(_(
"Pause"));
185 void TTYWindow::OnCopyClick(wxCommandEvent&) { m_tty_scroll->Copy(); }
187 void TTYWindow::OnCloseWindow(wxCloseEvent&) {
188 if (m_window_destroy_listener) {
189 m_window_destroy_listener->DestroyWindow();
195 void TTYWindow::Add(
const wxString& line) {
196 if (m_tty_scroll) m_tty_scroll->Add(line);