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"
37#include "ocpn_plugin.h"
40IMPLEMENT_DYNAMIC_CLASS(
TTYWindow, wxFrame)
43EVT_CLOSE(TTYWindow::OnCloseWindow)
48TTYWindow::TTYWindow(wxWindow* parent,
int n_lines,
50 : m_window_destroy_listener(listener), m_pScroll(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_tFilter =
new wxTextCtrl(
this, wxID_ANY);
60 m_pScroll =
new TTYScroll(
this, n_lines, *m_tFilter);
61 m_pScroll->Scroll(-1, 1000);
63 bSizerOuterContainer->Add(m_pScroll, 1, wxEXPAND, 5);
65 wxStaticBox* psbf =
new wxStaticBox(
this, wxID_ANY, _(
"Filter"));
66 wxStaticBoxSizer* sbSizer2 =
new wxStaticBoxSizer(psbf, wxVERTICAL);
67 sbSizer2->Add(m_tFilter, 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);
77 wxBitmapButton* bb =
new wxBitmapButton(
this, wxID_ANY, m_bm_legend);
78 sbSizer1->Add(bb, 1, wxALL | wxEXPAND, 5);
79 bSizerBottomContainer->Add(sbSizer1, 0, wxALIGN_LEFT | wxALL, 5);
81 wxStaticBox* buttonBox =
new wxStaticBox(
this, wxID_ANY, wxEmptyString);
82 wxStaticBoxSizer* bbSizer1 =
new wxStaticBoxSizer(buttonBox, wxVERTICAL);
84 m_buttonPause =
new wxButton(
this, wxID_ANY, _(
"Pause"), wxDefaultPosition,
86 m_buttonCopy =
new wxButton(
this, wxID_ANY, _(
"Copy"), wxDefaultPosition,
88 m_buttonCopy->SetToolTip(_(
"Copy NMEA Debug window to clipboard."));
90 bbSizer1->Add(m_buttonPause, 0, wxALL, 5);
91 bbSizer1->Add(m_buttonCopy, 0, wxALL, 5);
92 bSizerBottomContainer->Add(bbSizer1, 1, wxALL | wxEXPAND, 5);
94 m_buttonCopy->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
95 wxCommandEventHandler(TTYWindow::OnCopyClick), NULL,
97 m_buttonPause->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
98 wxCommandEventHandler(TTYWindow::OnPauseClick), NULL,
104TTYWindow::~TTYWindow() {
111void TTYWindow::CreateLegendBitmap() {
112 double dip_factor = OCPN_GetWinDIPScaleFactor();
114 wxFont *pmetricFont = FontMgr::Get().GetFont(_(
"Dialog"));
117 dcs.GetTextExtent(
"M", &width, &height, NULL, NULL, pmetricFont);
118 double ref_dim = height * dip_factor;
120 m_bm_legend.Create(25 * ref_dim, 6.5 * ref_dim);
122 dc.SelectObject(m_bm_legend);
123 if (m_bm_legend.IsOk()) {
124 dc.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)));
127 wxFont f(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
130 int yp = ref_dim * 1.25;
131 int y = ref_dim * .25;
133 int text_x = ref_dim * 1.5;
134 int boff = ref_dim *.25;
136 wxBrush b1(wxColour(_T(
"DARK GREEN")));
138 dc.DrawRectangle(boff, y, bsize, bsize);
139 dc.SetTextForeground(wxColour(_T(
"DARK GREEN")));
140 dc.DrawText(_(
"Message accepted"), text_x, y);
143 wxBrush b2(wxColour(_T(
"CORAL")));
145 dc.DrawRectangle(boff, y, bsize, bsize);
146 dc.SetTextForeground(wxColour(_T(
"CORAL")));
148 _(
"Input message filtered, output message filtered and dropped"), text_x,
152 wxBrush b3(wxColour(_T(
"MAROON")));
154 dc.DrawRectangle(boff, y, bsize, bsize);
155 dc.SetTextForeground(wxColour(_T(
"MAROON")));
156 dc.DrawText(_(
"Input Message filtered and dropped"), text_x, y);
159 wxBrush b4(wxColour(_T(
"BLUE")));
161 dc.DrawRectangle(boff, y, bsize, bsize);
162 dc.SetTextForeground(wxColour(_T(
"BLUE")));
163 dc.DrawText(_(
"Output Message"), text_x, y);
166 wxBrush b5(wxColour(_T(
"RED")));
168 dc.DrawRectangle(boff, y, bsize, bsize);
169 dc.SetTextForeground(wxColour(_T(
"RED")));
170 dc.DrawText(_(
"Information Message or Message with errors"), text_x, y);
172 dc.SelectObject(wxNullBitmap);
175void TTYWindow::OnPauseClick(wxCommandEvent& event) {
178 m_pScroll->Pause(
true);
179 m_buttonPause->SetLabel(_(
"Resume"));
182 m_pScroll->Pause(
false);
184 m_buttonPause->SetLabel(_(
"Pause"));
188void TTYWindow::OnCopyClick(wxCommandEvent& event) { m_pScroll->Copy(); }
190void TTYWindow::OnCloseWindow(wxCloseEvent& event) {
191 if (m_window_destroy_listener) {
192 m_window_destroy_listener->DestroyWindow();
198void TTYWindow::Add(
const wxString& line) {
199 if (m_pScroll) m_pScroll->Add(line);