32#include <wx/html/htmlwin.h>
35#include "ais_decoder.h"
36#include "AISTargetAlertDialog.h"
37#include "ais_target_data.h"
41#include "ocpn_frame.h"
42#include "OCPNPlatform.h"
43#include "ocpn_types.h"
44#include "ocpn_types.h"
45#include "routemanagerdialog.h"
46#include "route_point.h"
49#ifdef __OCPN__ANDROID__
50#include "androidUTIL.h"
53extern ColorScheme global_color_scheme;
57extern int g_ais_alert_dialog_x;
58extern int g_ais_alert_dialog_y;
59extern int g_ais_alert_dialog_sx;
60extern int g_ais_alert_dialog_sy;
61extern bool g_bAIS_CPA_Alert_Audio;
62extern wxString g_default_wp_icon;
81OCPN_AlertDialog::~OCPN_AlertDialog() {}
83void OCPN_AlertDialog::Init(
void) { m_pparent = NULL; }
85bool OCPN_AlertDialog::Create(wxWindow *parent, wxWindowID
id,
86 const wxString &caption,
const wxPoint &pos,
87 const wxSize &size,
long style)
96 long wstyle = wxDEFAULT_FRAME_STYLE;
97 if ((global_color_scheme != GLOBAL_COLOR_SCHEME_DAY) &&
98 (global_color_scheme != GLOBAL_COLOR_SCHEME_RGB))
99 wstyle |= (wxNO_BORDER);
101 wxSize size_min = size;
102 size_min.IncTo(wxSize(500, 600));
103 if (!wxDialog::Create(parent,
id, caption, pos, size_min, wstyle))
108 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
122EVT_CLOSE(AISTargetAlertDialog::OnClose)
123EVT_BUTTON(ID_ACKNOWLEDGE, AISTargetAlertDialog::OnIdAckClick)
124EVT_BUTTON(ID_SILENCE, AISTargetAlertDialog::OnIdSilenceClick)
125EVT_BUTTON(ID_JUMPTO, AISTargetAlertDialog::OnIdJumptoClick)
126EVT_BUTTON(ID_WPT_CREATE, AISTargetAlertDialog::OnIdCreateWPClick)
127EVT_MOVE(AISTargetAlertDialog::OnMove)
128EVT_SIZE(AISTargetAlertDialog::OnSize)
133AISTargetAlertDialog::~AISTargetAlertDialog() {}
135void AISTargetAlertDialog::Init() {
142bool AISTargetAlertDialog::Create(
int target_mmsi, wxWindow *parent,
144 bool b_createWP,
bool b_ack, wxWindowID
id,
145 const wxString &caption,
const wxPoint &pos,
146 const wxSize &size,
long style)
149 OCPN_AlertDialog::Create(parent,
id, caption, pos, size, style);
150 m_bjumpto = b_jumpto;
152 m_bcreateWP = b_createWP;
154 m_target_mmsi = target_mmsi;
155 m_pdecoder = pdecoder;
157 wxFont *dFont = FontMgr::Get().GetFont(_(
"AISTargetAlert"), 12);
158 int font_size = wxMax(8, dFont->GetPointSize());
159 wxString face = dFont->GetFaceName();
161 face = _T(
"Monospace");
163 wxFont *fp_font = FontMgr::Get().FindOrCreateFont(
164 font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, dFont->GetWeight(),
170 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
172 wxColor bg = GetBackgroundColour();
173 m_pAlertTextCtl->SetBackgroundColour(bg);
174 SetBackgroundColour(bg);
179void AISTargetAlertDialog::CreateControls() {
180 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
184 new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
185 wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION);
186#ifdef __OCPN__ANDROID__
187 m_pAlertTextCtl->GetHandle()->setStyleSheet(getQtStyleSheet());
190 m_pAlertTextCtl->SetBorders(5);
192 topSizer->Add(m_pAlertTextCtl, 1, wxALL | wxEXPAND, 5);
195 wxFlexGridSizer *AckBox =
new wxFlexGridSizer(2);
196 topSizer->Add(AckBox, 0, wxALL, 5);
199 if (g_bAIS_CPA_Alert_Audio) {
200 wxButton *silence =
new wxButton(
this, ID_SILENCE, _(
"&Silence Alert"),
201 wxDefaultPosition, wxDefaultSize, 0);
202 AckBox->Add(silence, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
206 wxButton *jumpto =
new wxButton(
this, ID_JUMPTO, _(
"&Jump To"),
207 wxDefaultPosition, wxDefaultSize, 0);
208 AckBox->Add(jumpto, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
212 wxButton *createWptBtn =
213 new wxButton(
this, ID_WPT_CREATE, _(
"Create Waypoint"),
214 wxDefaultPosition, wxDefaultSize, 0);
215 AckBox->Add(createWptBtn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
219 wxString acktext = _(
"&Acknowledge");
220 bool show_ack_button =
false;
221 if (m_bjumpto && m_bcreateWP) {
222 acktext = _(
"&Close Alert");
223 show_ack_button =
true;
225 if (m_back || show_ack_button) {
226 wxButton *ack =
new wxButton(
this, ID_ACKNOWLEDGE, acktext,
227 wxDefaultPosition, wxDefaultSize, 0);
228 AckBox->Add(ack, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
236bool AISTargetAlertDialog::GetAlertText() {
239 auto td_found = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
242 m_alert_text = td_found->BuildQueryResult();
250void AISTargetAlertDialog::UpdateText() {
251 if (GetAlertText()) {
252 wxFont *dFont = FontMgr::Get().GetFont(_(
"AISTargetAlert"), 12);
253 wxString face = dFont->GetFaceName();
255 for (
int i = -2; i < 5; i++) {
256 sizes[i + 2] = dFont->GetPointSize() + i + (i > 0 ? i : 0);
260 wxColor bg = GetBackgroundColour();
261 wxColor fg = GetForegroundColour();
264 _T(
"<html><body bgcolor=#%02x%02x%02x><font ")
265 _T(
"color=#%02x%02x%02x><center>"),
266 bg.Red(), bg.Green(), bg.Blue(), fg.Red(), fg.Green(), fg.Blue());
268 html << m_alert_text;
269 html << _T(
"</center></font></body></html>");
271 m_pAlertTextCtl->SetFonts(face, face, sizes);
272 m_pAlertTextCtl->SetPage(html);
278 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
281void AISTargetAlertDialog::RecalculateSize(
void) {
285 while (i < m_alert_text.Length()) {
286 if (m_alert_text[i] ==
'\n') nline++;
290 if (nline > m_max_nline) m_max_nline = nline;
293 esize.x = GetCharWidth() * 45;
294 esize.y = GetCharHeight() * (m_max_nline + 4);
297 int height = m_pAlertTextCtl->GetInternalRepresentation()->GetHeight();
298 int adj_height = height + (GetCharHeight() * 6);
299 m_adj_height = wxMax(m_adj_height, adj_height);
301 esize.y = wxMin(esize.y, m_adj_height);
307 int textWidth = m_pAlertTextCtl->GetInternalRepresentation()->GetWidth();
308 wxSize gSize = GetClientSize();
309 int adjustedWidth = wxMax(GetClientSize().x, textWidth + GetCharHeight() * 2);
310 SetClientSize(adjustedWidth, esize.y);
312 g_Platform->PositionAISAlert(
this);
315void AISTargetAlertDialog::SetColorScheme(
void) {
317 wxColor bg = GetBackgroundColour();
318 m_pAlertTextCtl->SetBackgroundColour(bg);
325 wxBitmap tbm(GetSize().x, GetSize().y, -1);
328 tdc.SetBackground(bg);
330 m_pAlertTextCtl->SetBackgroundImage(tbm);
334void AISTargetAlertDialog::OnClose(wxCloseEvent &event) {
337 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
339 if (AIS_ALERT_SET == td->n_alert_state) {
340 td->m_ack_time = wxDateTime::Now();
341 td->b_in_ack_timeout =
true;
343 if (td->b_isDSCtarget) {
344 td->b_isDSCtarget =
false;
345 if (td->n_alert_state) {
346 td->n_alert_state = AIS_NO_ALERT;
353 g_pais_alert_dialog_active = NULL;
356void AISTargetAlertDialog::OnIdAckClick(wxCommandEvent &event) {
359 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
361 if (AIS_ALERT_SET == td->n_alert_state ) {
362 td->m_ack_time = wxDateTime::Now();
363 td->b_in_ack_timeout =
true;
365 if (td->b_isDSCtarget) {
366 td->b_isDSCtarget =
false;
367 if (td->n_alert_state) {
368 td->n_alert_state = AIS_NO_ALERT;
374 g_pais_alert_dialog_active = NULL;
376void AISTargetAlertDialog::OnIdCreateWPClick(wxCommandEvent &event) {
378 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
381 wxEmptyString, wxEmptyString);
382 pWP->m_bIsolatedMark =
true;
383 pSelect->AddSelectableRoutePoint(td->Lat, td->Lon, pWP);
384 pConfig->AddNewWayPoint(pWP, -1);
386 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
387 pRouteManagerDialog->UpdateWptListCtrl();
388 if (gFrame->GetPrimaryCanvas()) {
389 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
390 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
391 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
392 gFrame->InvalidateAllGL();
399void AISTargetAlertDialog::OnIdSilenceClick(wxCommandEvent &event) {
403 m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
404 if (td) td->b_suppress_audio =
true;
408void AISTargetAlertDialog::OnIdJumptoClick(wxCommandEvent &event) {
411 m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
413 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), td->Lat, td->Lon,
414 gFrame->GetFocusCanvas()->GetVPScale());
418void AISTargetAlertDialog::OnMove(wxMoveEvent &event) {
420 g_ais_alert_dialog_x = GetPosition().x;
421 g_ais_alert_dialog_y = GetPosition().y;
426void AISTargetAlertDialog::OnSize(wxSizeEvent &event) {
428 wxSize p =
event.GetSize();
429 g_ais_alert_dialog_sx = p.x;
430 g_ais_alert_dialog_sy = p.y;