34#include <wx/html/htmlwin.h>
55#include "androidUTIL.h"
58extern ColorScheme global_color_scheme;
61extern int g_ais_alert_dialog_y;
62extern wxString g_default_wp_icon;
80OCPN_AlertDialog::~OCPN_AlertDialog() {}
82void OCPN_AlertDialog::Init() { m_pparent = NULL; }
84bool OCPN_AlertDialog::Create(wxWindow *parent, wxWindowID
id,
85 const wxString &caption,
const wxPoint &pos,
86 const wxSize &size,
long style)
89 long wstyle = wxDEFAULT_FRAME_STYLE;
91 wxSize size_min = size;
92 size_min.IncTo(wxSize(500, 600));
93 if (!wxDialog::Create(parent,
id, caption, pos, size_min, wstyle))
98 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
112EVT_CLOSE(AISTargetAlertDialog::OnClose)
113EVT_BUTTON(ID_ACKNOWLEDGE, AISTargetAlertDialog::OnIdAckClick)
114EVT_BUTTON(ID_SILENCE, AISTargetAlertDialog::OnIdSilenceClick)
115EVT_BUTTON(ID_JUMPTO, AISTargetAlertDialog::OnIdJumptoClick)
116EVT_BUTTON(ID_WPT_CREATE, AISTargetAlertDialog::OnIdCreateWPClick)
117EVT_MOVE(AISTargetAlertDialog::OnMove)
118EVT_SIZE(AISTargetAlertDialog::OnSize)
123AISTargetAlertDialog::~AISTargetAlertDialog() {}
125void AISTargetAlertDialog::Init() {
133bool AISTargetAlertDialog::Create(
int target_mmsi, wxWindow *parent,
135 bool b_createWP,
bool b_ack, wxWindowID
id,
136 const wxString &caption,
const wxPoint &pos,
137 const wxSize &size,
long style)
140 OCPN_AlertDialog::Create(parent,
id, caption, pos, size, style);
141 m_bjumpto = b_jumpto;
143 m_bcreateWP = b_createWP;
145 m_target_mmsi = target_mmsi;
146 m_pdecoder = pdecoder;
149 wxFont *dFont = FontMgr::Get().
GetFont(_(
"AISTargetAlert"), 0);
150 int font_size = wxMax(8, dFont->GetPointSize());
151 wxString face = dFont->GetFaceName();
156 font_size, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, dFont->GetWeight(),
162 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
164 wxColor bg = GetBackgroundColour();
165 m_pAlertTextCtl->SetBackgroundColour(bg);
166 SetBackgroundColour(bg);
171void AISTargetAlertDialog::CreateControls() {
172 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
174 long style = wxHW_SCROLLBAR_AUTO;
175 if (g_btouch) style |= wxHW_NO_SELECTION;
178 new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
180 m_pAlertTextCtl->GetHandle()->setStyleSheet(getQtStyleSheet());
183 m_pAlertTextCtl->SetBorders(5);
184 m_pAlertTextCtl->SetScrollRate(1, 1);
186 topSizer->Add(m_pAlertTextCtl, 1, wxALL | wxEXPAND, 5);
189 wxFlexGridSizer *AckBox =
new wxFlexGridSizer(2);
190 topSizer->Add(AckBox, 0, wxALL, 5);
193 if (g_bAIS_CPA_Alert_Audio) {
194 wxButton *silence =
new wxButton(
this, ID_SILENCE, _(
"&Silence Alert"),
195 wxDefaultPosition, wxDefaultSize, 0);
196 AckBox->Add(silence, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
200 wxButton *jumpto =
new wxButton(
this, ID_JUMPTO, _(
"&Jump To"),
201 wxDefaultPosition, wxDefaultSize, 0);
202 AckBox->Add(jumpto, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
206 wxButton *createWptBtn =
207 new wxButton(
this, ID_WPT_CREATE, _(
"Create Waypoint"),
208 wxDefaultPosition, wxDefaultSize, 0);
209 AckBox->Add(createWptBtn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
213 wxString acktext = _(
"&Acknowledge");
214 bool show_ack_button =
false;
215 if (m_bjumpto && m_bcreateWP) {
216 acktext = _(
"&Close Alert");
217 show_ack_button =
true;
219 if (m_back || show_ack_button) {
220 wxButton *ack =
new wxButton(
this, ID_ACKNOWLEDGE, acktext,
221 wxDefaultPosition, wxDefaultSize, 0);
222 AckBox->Add(ack, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
230bool AISTargetAlertDialog::GetAlertText() {
233 auto td_found = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
236 m_alert_text = td_found->BuildQueryResult();
244void AISTargetAlertDialog::UpdateText() {
245 if (GetAlertText()) {
248 m_pAlertTextCtl->GetViewStart(&x, &y);
250 wxFont *dFont = FontMgr::Get().
GetFont(_(
"AISTargetAlert"), 0);
251 wxString face = dFont->GetFaceName();
253 for (
int i = -2; i < 5; i++) {
254 sizes[i + 2] = dFont->GetPointSize() + i + (i > 0 ? i : 0);
258 wxColor bg = GetBackgroundColour();
259 wxColor fg = GetForegroundColour();
262 "<html><body bgcolor=#%02x%02x%02x><font "
263 "color=#%02x%02x%02x><center>",
264 bg.Red(), bg.Green(), bg.Blue(), fg.Red(), fg.Green(), fg.Blue());
266 html << m_alert_text;
267 html <<
"</center></font></body></html>";
269 m_pAlertTextCtl->SetFonts(face, face, sizes);
270 m_pAlertTextCtl->SetPage(html);
275 m_pAlertTextCtl->Scroll(x, y);
279 if (!g_bopengl && CanSetTransparent()) SetTransparent(192);
282void AISTargetAlertDialog::RecalculateSize() {
286 while (i < m_alert_text.Length()) {
287 if (m_alert_text[i] ==
'\n') nline++;
291 if (nline > m_max_nline) m_max_nline = nline;
294 esize.x = GetCharWidth() * 45;
295 esize.y = GetCharHeight() * (m_max_nline + 4);
298 int height = m_pAlertTextCtl->GetInternalRepresentation()->GetHeight();
299 int adj_height = height + (GetCharHeight() * 6);
300 m_adj_height = wxMax(m_adj_height, adj_height);
302 esize.y = wxMin(esize.y, m_adj_height);
308 int textWidth = m_pAlertTextCtl->GetInternalRepresentation()->GetWidth();
309 wxSize gSize = GetClientSize();
310 int adjustedWidth = wxMax(GetClientSize().x, textWidth + GetCharHeight() * 2);
311 SetClientSize(adjustedWidth, esize.y);
315 wxSize wsize = m_pParent->GetSize();
316 SetSize(-1, wxMin(esize.y, wsize.y));
319 g_Platform->PositionAISAlert(
this);
322void AISTargetAlertDialog::SetColorScheme() {
324 wxColor bg = GetBackgroundColour();
325 m_pAlertTextCtl->SetBackgroundColour(bg);
332 wxBitmap tbm(GetSize().x, GetSize().y, -1);
335 tdc.SetBackground(bg);
337 m_pAlertTextCtl->SetBackgroundImage(tbm);
341void AISTargetAlertDialog::OnClose(wxCloseEvent &event) {
344 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
346 if (AIS_ALERT_SET == td->n_alert_state) {
347 td->m_ack_time = wxDateTime::Now();
348 td->b_in_ack_timeout =
true;
350 if (td->b_isDSCtarget) {
351 td->b_isDSCtarget =
false;
352 if (td->n_alert_state) {
353 td->n_alert_state = AIS_NO_ALERT;
360 g_pais_alert_dialog_active = NULL;
363void AISTargetAlertDialog::OnIdAckClick(wxCommandEvent &event) {
366 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
368 if (AIS_ALERT_SET == td->n_alert_state) {
369 td->m_ack_time = wxDateTime::Now();
370 td->b_in_ack_timeout =
true;
372 if (td->b_isDSCtarget) {
373 td->b_isDSCtarget =
false;
374 if (td->n_alert_state) {
375 td->n_alert_state = AIS_NO_ALERT;
381 g_pais_alert_dialog_active = NULL;
383void AISTargetAlertDialog::OnIdCreateWPClick(wxCommandEvent &event) {
385 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
388 wxEmptyString, wxEmptyString);
390 pSelect->AddSelectableRoutePoint(td->Lat, td->Lon, pWP);
391 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
393 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
394 pRouteManagerDialog->UpdateWptListCtrl();
395 if (gFrame->GetPrimaryCanvas()) {
396 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
397 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
398 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
399 gFrame->InvalidateAllGL();
406void AISTargetAlertDialog::OnIdSilenceClick(wxCommandEvent &event) {
409 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
410 if (td) td->b_suppress_audio =
true;
414void AISTargetAlertDialog::OnIdJumptoClick(wxCommandEvent &event) {
416 auto td = m_pdecoder->Get_Target_Data_From_MMSI(Get_Dialog_MMSI());
418 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), td->Lat, td->Lon,
423void AISTargetAlertDialog::OnMove(wxMoveEvent &event) {
425 g_ais_alert_dialog_x = GetPosition().x;
426 g_ais_alert_dialog_y = GetPosition().y;
431void AISTargetAlertDialog::OnSize(wxSizeEvent &event) {
433 wxSize p =
event.GetSize();
434 g_ais_alert_dialog_sx = p.x;
435 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.
float GetVPScale()
Return the ViewPort scale factor, in physical pixels per meter.
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.
MySQL based storage for routes, tracks, etc.
Waypoint or mark abstraction.
Select * pSelect
Global instance.
Selected route, segment, waypoint, etc.