32#include <wx/html/htmlwin.h>
51#include "user_colors.h"
55#include "androidUTIL.h"
65OCPN_AlertDialog::~OCPN_AlertDialog() {}
67void OCPN_AlertDialog::Init() { m_pparent = NULL; }
69bool OCPN_AlertDialog::Create(wxWindow *parent, wxWindowID
id,
70 const wxString &caption,
const wxPoint &pos,
71 const wxSize &size,
long style)
74 long wstyle = wxDEFAULT_FRAME_STYLE;
76 wxSize size_min = size;
77 size_min.IncTo(wxSize(500, 600));
78 if (!wxDialog::Create(parent,
id, caption, pos, size_min, wstyle))
83 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
97EVT_CLOSE(AISTargetAlertDialog::OnClose)
98EVT_BUTTON(ID_ACKNOWLEDGE, AISTargetAlertDialog::OnIdAckClick)
99EVT_BUTTON(ID_SILENCE, AISTargetAlertDialog::OnIdSilenceClick)
100EVT_BUTTON(ID_JUMPTO, AISTargetAlertDialog::OnIdJumptoClick)
101EVT_BUTTON(ID_WPT_CREATE, AISTargetAlertDialog::OnIdCreateWPClick)
102EVT_MOVE(AISTargetAlertDialog::OnMove)
103EVT_SIZE(AISTargetAlertDialog::OnSize)
108AISTargetAlertDialog::~AISTargetAlertDialog() {}
110void AISTargetAlertDialog::Init() {
118bool AISTargetAlertDialog::Create(
int target_mmsi, wxWindow *parent,
120 bool b_createWP,
bool b_ack, wxWindowID
id,
121 const wxString &caption,
const wxPoint &pos,
122 const wxSize &size,
long style)
125 OCPN_AlertDialog::Create(parent,
id, caption, pos, size, style);
126 m_bjumpto = b_jumpto;
128 m_bcreateWP = b_createWP;
130 m_target_mmsi = target_mmsi;
131 m_pdecoder = pdecoder;
134 wxFont *dFont = FontMgr::Get().
GetFont(_(
"AISTargetAlert"), 0);
135 int font_size = wxMax(8, dFont->GetPointSize());
136 wxString face = dFont->GetFaceName();
141 font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, dFont->GetWeight(),
147 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
149 wxColor bg = GetBackgroundColour();
150 m_pAlertTextCtl->SetBackgroundColour(bg);
151 SetBackgroundColour(bg);
156void AISTargetAlertDialog::CreateControls() {
157 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
159 long style = wxHW_SCROLLBAR_AUTO;
160 if (g_btouch) style |= wxHW_NO_SELECTION;
163 new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
165 m_pAlertTextCtl->GetHandle()->setStyleSheet(getQtStyleSheet());
168 m_pAlertTextCtl->SetBorders(5);
169 m_pAlertTextCtl->SetScrollRate(1, 1);
171 topSizer->Add(m_pAlertTextCtl, 1, wxALL | wxEXPAND, 5);
174 wxFlexGridSizer *AckBox =
new wxFlexGridSizer(2);
175 topSizer->Add(AckBox, 0, wxALL, 5);
178 if (g_bAIS_CPA_Alert_Audio) {
179 wxButton *silence =
new wxButton(
this, ID_SILENCE, _(
"&Silence Alert"),
180 wxDefaultPosition, wxDefaultSize, 0);
181 AckBox->Add(silence, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
185 wxButton *jumpto =
new wxButton(
this, ID_JUMPTO, _(
"&Jump To"),
186 wxDefaultPosition, wxDefaultSize, 0);
187 AckBox->Add(jumpto, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
191 wxButton *createWptBtn =
192 new wxButton(
this, ID_WPT_CREATE, _(
"Create Waypoint"),
193 wxDefaultPosition, wxDefaultSize, 0);
194 AckBox->Add(createWptBtn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
198 wxString acktext = _(
"&Acknowledge");
199 bool show_ack_button =
false;
200 if (m_bjumpto && m_bcreateWP) {
201 acktext = _(
"&Close Alert");
202 show_ack_button =
true;
204 if (m_back || show_ack_button) {
205 wxButton *ack =
new wxButton(
this, ID_ACKNOWLEDGE, acktext,
206 wxDefaultPosition, wxDefaultSize, 0);
207 AckBox->Add(ack, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
215bool AISTargetAlertDialog::GetAlertText() {
218 auto td_found = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
221 m_alert_text = td_found->BuildQueryResult();
229void AISTargetAlertDialog::UpdateText() {
230 if (GetAlertText()) {
233 m_pAlertTextCtl->GetViewStart(&x, &y);
235 wxFont *dFont = FontMgr::Get().
GetFont(_(
"AISTargetAlert"), 0);
236 wxString face = dFont->GetFaceName();
238 for (
int i = -2; i < 5; i++) {
239 sizes[i + 2] = dFont->GetPointSize() + i + (i > 0 ? i : 0);
243 wxColor bg = GetBackgroundColour();
244 wxColor fg = GetForegroundColour();
247 "<html><body bgcolor=#%02x%02x%02x><font "
248 "color=#%02x%02x%02x><center>",
249 bg.Red(), bg.Green(), bg.Blue(), fg.Red(), fg.Green(), fg.Blue());
251 html << m_alert_text;
252 html <<
"</center></font></body></html>";
254 m_pAlertTextCtl->SetFonts(face, face, sizes);
255 m_pAlertTextCtl->SetPage(html);
260 m_pAlertTextCtl->Scroll(x, y);
264 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
267void AISTargetAlertDialog::RecalculateSize() {
271 while (i < m_alert_text.Length()) {
272 if (m_alert_text[i] ==
'\n') nline++;
276 if (nline > m_max_nline) m_max_nline = nline;
279 esize.x = GetCharWidth() * 45;
280 esize.y = GetCharHeight() * (m_max_nline + 4);
283 int height = m_pAlertTextCtl->GetInternalRepresentation()->GetHeight();
284 int adj_height = height + (GetCharHeight() * 6);
285 m_adj_height = wxMax(m_adj_height, adj_height);
287 esize.y = wxMin(esize.y, m_adj_height);
293 int textWidth = m_pAlertTextCtl->GetInternalRepresentation()->GetWidth();
294 wxSize gSize = GetClientSize();
295 int adjustedWidth = wxMax(GetClientSize().x, textWidth + GetCharHeight() * 2);
296 SetClientSize(adjustedWidth, esize.y);
300 wxSize wsize = m_pParent->GetSize();
301 SetSize(-1, wxMin(esize.y, wsize.y));
304 g_Platform->PositionAISAlert(
this);
307void AISTargetAlertDialog::SetColorScheme() {
309 wxColor bg = GetBackgroundColour();
310 m_pAlertTextCtl->SetBackgroundColour(bg);
317 wxBitmap tbm(GetSize().x, GetSize().y, -1);
320 tdc.SetBackground(bg);
322 m_pAlertTextCtl->SetBackgroundImage(tbm);
326void AISTargetAlertDialog::OnClose(wxCloseEvent &event) {
329 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
331 if (AIS_ALERT_SET == td->n_alert_state) {
332 td->m_ack_time = wxDateTime::Now();
333 td->b_in_ack_timeout =
true;
335 if (td->b_isDSCtarget) {
336 td->b_isDSCtarget =
false;
337 if (td->n_alert_state) {
338 td->n_alert_state = AIS_NO_ALERT;
345 g_pais_alert_dialog_active = NULL;
348void AISTargetAlertDialog::OnIdAckClick(wxCommandEvent &event) {
351 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
353 if (AIS_ALERT_SET == td->n_alert_state) {
354 td->m_ack_time = wxDateTime::Now();
355 td->b_in_ack_timeout =
true;
357 if (td->b_isDSCtarget) {
358 td->b_isDSCtarget =
false;
359 if (td->n_alert_state) {
360 td->n_alert_state = AIS_NO_ALERT;
366 g_pais_alert_dialog_active = NULL;
368void AISTargetAlertDialog::OnIdCreateWPClick(wxCommandEvent &event) {
370 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
373 wxEmptyString, wxEmptyString);
375 pSelect->AddSelectableRoutePoint(td->Lat, td->Lon, pWP);
376 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
380 if (top_frame::Get()->GetAbstractPrimaryCanvas()) {
381 top_frame::Get()->BeforeUndoableAction(Undo_CreateWaypoint, pWP,
382 Undo_HasParent, NULL);
383 top_frame::Get()->AfterUndoableAction(NULL);
384 top_frame::Get()->InvalidateAllGL();
391void AISTargetAlertDialog::OnIdSilenceClick(wxCommandEvent &event) {
394 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
395 if (td) td->b_suppress_audio =
true;
399void AISTargetAlertDialog::OnIdJumptoClick(wxCommandEvent &event) {
401 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
403 top_frame::Get()->JumpToPosition(
404 top_frame::Get()->GetAbstractFocusCanvas(), td->Lat, td->Lon);
409void AISTargetAlertDialog::OnMove(wxMoveEvent &event) {
411 g_ais_alert_dialog_x = GetPosition().x;
412 g_ais_alert_dialog_y = GetPosition().y;
417void AISTargetAlertDialog::OnSize(wxSizeEvent &event) {
419 wxSize p =
event.GetSize();
420 g_ais_alert_dialog_sx = p.x;
421 g_ais_alert_dialog_sy = p.y;
Class AisDecoder and helpers.
Global state for AIS decoder.
Class AISTargetAlertDialog and helpers.
Generic Chart canvas base.
Dialog for displaying AIS target alerts.
wxFont * FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &facename=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
Creates or finds a matching font in the font cache.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Get a font object for a UI element.
Represents a waypoint or mark within the navigation system.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
MySQL based storage for routes, tracks, etc.
Waypoint or mark abstraction.
RouteManagerDialog * pRouteManagerDialog
Global instance.
Select * pSelect
Global instance.
Selected route, segment, waypoint, etc.
Abstract gFrame/MyFrame interface.