26#include <wx/statbox.h>
27#include <wx/bmpbuttn.h>
28#include <wx/dcmemory.h>
30#include <wx/settings.h>
31#include <wx/dcscreen.h>
35#include "WindowDestroyListener.h"
36#include "color_handler.h"
41EVT_CLOSE(TTYWindow::OnCloseWindow)
46TTYWindow::TTYWindow(wxWindow* parent,
int n_lines,
48 : m_window_destroy_listener(listener), m_tty_scroll(NULL) {
50 parent, -1, _T(
"Title"), wxDefaultPosition, wxDefaultSize,
51 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFRAME_FLOAT_ON_PARENT,
54 wxBoxSizer* bSizerOuterContainer =
new wxBoxSizer(wxVERTICAL);
55 SetSizer(bSizerOuterContainer);
57 m_filter =
new wxTextCtrl(
this, wxID_ANY);
59 m_tty_scroll =
new TtyScroll(
this, n_lines, *m_filter);
60 m_tty_scroll->Scroll(-1, 1000);
62 bSizerOuterContainer->Add(m_tty_scroll, 1, wxEXPAND, 5);
64 wxStaticBox* psbf =
new wxStaticBox(
this, wxID_ANY, _(
"Filter"));
65 wxStaticBoxSizer* sbSizer2 =
new wxStaticBoxSizer(psbf, wxVERTICAL);
66 sbSizer2->Add(m_filter, 1, wxALL | wxEXPAND, 5);
67 bSizerOuterContainer->Add(sbSizer2, 0, wxEXPAND, 5);
69 wxBoxSizer* bSizerBottomContainer =
new wxBoxSizer(wxHORIZONTAL);
70 bSizerOuterContainer->Add(bSizerBottomContainer, 0, wxEXPAND, 5);
72 wxStaticBox* psb =
new wxStaticBox(
this, wxID_ANY, _(
"Legend"));
73 wxStaticBoxSizer* sbSizer1 =
new wxStaticBoxSizer(psb, wxVERTICAL);
74 bSizerBottomContainer->Add(sbSizer1, 0, wxALIGN_LEFT | wxALL, 5);
77 wxBitmapButton* bb =
new wxBitmapButton(
this, wxID_ANY, m_bm_legend);
78 sbSizer1->Add(bb, 1, wxALL | wxEXPAND, 5);
80 wxStaticBox* buttonBox =
new wxStaticBox(
this, wxID_ANY,
"Tools");
81 wxStaticBoxSizer* bbSizer1 =
new wxStaticBoxSizer(buttonBox, wxVERTICAL);
83 m_btn_pause =
new wxButton(
this, wxID_ANY, _(
"Pause"), wxDefaultPosition,
85 m_btn_copy =
new wxButton(
this, wxID_ANY, _(
"Copy all"), wxDefaultPosition,
87 m_btn_copy->SetToolTip(_(
"Copy all NMEA Debug window to clipboard."));
88 m_btn_copy_N0183 =
new wxButton(
this, wxID_ANY, _(
"Copy NMEA 0183"),
89 wxDefaultPosition, wxDefaultSize, 0);
90 m_btn_copy_N0183->SetToolTip(
91 _(
"Copy only pure NMEA 0183 sentences to clipboard."));
93 bbSizer1->Add(m_btn_pause, 0, wxALL, 5);
94 bbSizer1->Add(m_btn_copy, 0, wxALL, 5);
95 bbSizer1->Add(m_btn_copy_N0183, 0, wxALL, 5);
96 bSizerBottomContainer->Add(bbSizer1, 1, wxALL | wxEXPAND, 5);
98 m_btn_copy->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
99 wxCommandEventHandler(TTYWindow::OnCopyClick), NULL,
101 m_btn_copy_N0183->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
102 wxCommandEventHandler(TTYWindow::OnCopyN0183Click),
104 m_btn_pause->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
105 wxCommandEventHandler(TTYWindow::OnPauseClick), NULL,
111TTYWindow::~TTYWindow() {
118void TTYWindow::CreateLegendBitmap() {
119 double dip_factor = OCPN_GetWinDIPScaleFactor();
121 wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
122 wxFONTWEIGHT_NORMAL);
124 dcs.GetTextExtent(
"M", &width, &height, NULL, NULL, &font);
125 double ref_dim = height * dip_factor;
127 m_bm_legend.Create(36 * width * dip_factor, 6.5 * ref_dim);
129 dc.SelectObject(m_bm_legend);
130 if (m_bm_legend.IsOk()) {
131 dc.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)));
135 int yp = ref_dim * 1.25;
136 int y = ref_dim * .25;
138 int text_x = ref_dim * 1.5;
139 int boff = ref_dim * .25;
141 wxBrush b1(wxColour(_T(
"DARK GREEN")));
143 dc.DrawRectangle(boff, y, bsize, bsize);
144 dc.SetTextForeground(wxColour(_T(
"DARK GREEN")));
145 dc.DrawText(_(
"Message accepted"), text_x, y);
148 wxBrush b2(wxColour(_T(
"CORAL")));
150 dc.DrawRectangle(boff, y, bsize, bsize);
151 dc.SetTextForeground(wxColour(_T(
"CORAL")));
156 _(
"Input message filtered, output message filtered and dropped"),
160 wxBrush b3(wxColour(_T(
"MAROON")));
162 dc.DrawRectangle(boff, y, bsize, bsize);
163 dc.SetTextForeground(wxColour(_T(
"MAROON")));
164 dc.DrawText(_(
"Input Message filtered and dropped"), text_x, y);
167 wxBrush b4(wxColour(_T(
"BLUE")));
169 dc.DrawRectangle(boff, y, bsize, bsize);
171 dc.SetTextForeground(wxColour(_T(
"BLUE")));
172 dc.DrawText(_(
"Output Message"), text_x, y);
175 wxBrush b5(wxColour(_T(
"RED")));
177 dc.DrawRectangle(boff, y, bsize, bsize);
178 dc.SetTextForeground(wxColour(_T(
"RED")));
181 dc.DrawText(_(
"Message with errors"), text_x, y);
183 dc.SelectObject(wxNullBitmap);
186void TTYWindow::OnPauseClick(wxCommandEvent&) {
189 m_tty_scroll->
Pause(
true);
190 m_btn_pause->SetLabel(_(
"Resume"));
193 m_tty_scroll->
Pause(
false);
195 m_btn_pause->SetLabel(_(
"Pause"));
199void TTYWindow::OnCopyClick(wxCommandEvent&) { m_tty_scroll->
Copy(
false); }
201void TTYWindow::OnCopyN0183Click(wxCommandEvent&) { m_tty_scroll->
Copy(
true); }
203void TTYWindow::OnCloseWindow(wxCloseEvent&) {
204 if (m_window_destroy_listener) {
205 m_window_destroy_listener->DestroyWindow();
211void TTYWindow::Add(
const wxString& line) {
212 if (m_tty_scroll) m_tty_scroll->
Add(line);
PlugIn Object Definition/API.