diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 81a387980..31d7a58a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,6 +41,8 @@ set(FREEDV_SOURCES ongui.cpp freedv_interface.cpp freedv_interface.h + wxListViewComboPopup.cpp + wxListViewComboPopup.h ) set(FREEDV_SOURCES_OSX diff --git a/src/main.cpp b/src/main.cpp index 4356a3009..0257a9671 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1437,12 +1437,18 @@ void MainFrame::OnTimer(wxTimerEvent &evt) std::string pendingCallsign = rxCallsign.ToStdString(); auto pendingSnr = (int)(g_snr + 0.5); - if (m_cboLastReportedCallsigns->GetCount() == 0 || m_cboLastReportedCallsigns->GetString(0) != rxCallsign) + if (m_lastReportedCallsignListView->GetItemCount() == 0 || m_lastReportedCallsignListView->GetItemText(0, 0) != rxCallsign) { - m_cboLastReportedCallsigns->Insert(rxCallsign, 0); + auto currentTime = wxDateTime::Now(); + wxString currentTimeAsString = ""; + + currentTimeAsString.Printf(wxT("%s %s"), currentTime.FormatISODate(), currentTime.FormatISOTime()); + + auto index = m_lastReportedCallsignListView->InsertItem(0, rxCallsign, 0); + m_lastReportedCallsignListView->SetItem(index, 1, currentTimeAsString); } - m_cboLastReportedCallsigns->SetSelection(0); - m_cboLastReportedCallsigns->SetValue(rxCallsign); + + m_cboLastReportedCallsigns->SetText(rxCallsign); if (wxGetApp().m_boolHamlibUseForPTT) { @@ -1844,7 +1850,9 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) m_timeSinceSyncLoss = 0; m_txtCtrlCallSign->SetValue(wxT("")); - m_cboLastReportedCallsigns->Clear(); + m_lastReportedCallsignListView->DeleteAllItems(); + + m_cboLastReportedCallsigns->SetText(wxT("")); memset(m_callsign, 0, MAX_CALLSIGN); m_pcallsign = m_callsign; diff --git a/src/topFrame.cpp b/src/topFrame.cpp index d2fb3f850..cb509d835 100644 --- a/src/topFrame.cpp +++ b/src/topFrame.cpp @@ -274,8 +274,13 @@ TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const m_txtCtrlCallSign->SetToolTip(_("Call Sign of transmitting station will appear here")); m_txtCtrlCallSign->SetSizeHints(wxSize(100,-1)); - m_cboLastReportedCallsigns = new wxComboBox(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); + m_cboLastReportedCallsigns = new wxComboCtrl(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCB_READONLY); + m_lastReportedCallsignListView = new wxListViewComboPopup(); + m_cboLastReportedCallsigns->SetPopupControl(m_lastReportedCallsignListView); m_cboLastReportedCallsigns->SetSizeHints(wxSize(100,-1)); + + m_lastReportedCallsignListView->InsertColumn(0, wxT("Callsign"), wxLIST_FORMAT_LEFT, 125); + m_lastReportedCallsignListView->InsertColumn(1, wxT("Date/Time"), wxLIST_FORMAT_LEFT, 250); bSizer15->Add(m_txtCtrlCallSign, 1, wxALL|wxEXPAND, 5); bSizer15->Add(m_cboLastReportedCallsigns, 1, wxALL|wxEXPAND, 5); diff --git a/src/topFrame.h b/src/topFrame.h index a5cc7cea9..6b18da4d7 100644 --- a/src/topFrame.h +++ b/src/topFrame.h @@ -56,7 +56,9 @@ #include #include #include -#include +#include + +#include "wxListViewComboPopup.h" #include "freedv_api.h" // for FREEDV_MODE_* @@ -74,6 +76,8 @@ #define ID_MODE_COLLAPSE 1100 +class wxListViewComboPopup; + /////////////////////////////////////////////////////////////////////////////// /// Class TopFrame /////////////////////////////////////////////////////////////////////////////// @@ -96,7 +100,10 @@ class TopFrame : public wxFrame wxButton* m_BtnCallSignReset; wxTextCtrl* m_txtCtrlCallSign; - wxComboBox* m_cboLastReportedCallsigns; + + wxComboCtrl* m_cboLastReportedCallsigns; + wxListViewComboPopup* m_lastReportedCallsignListView; + wxStaticText* m_txtModeStatus; wxStaticText* m_txtTxLevelNum; diff --git a/src/wxListViewComboPopup.cpp b/src/wxListViewComboPopup.cpp new file mode 100644 index 000000000..b79e16cc1 --- /dev/null +++ b/src/wxListViewComboPopup.cpp @@ -0,0 +1,53 @@ +#include "wxListViewComboPopup.h" + +#include +#include + +void wxListViewComboPopup::Init() +{ + m_value = -1; +} + +// Create popup control +bool wxListViewComboPopup::Create(wxWindow* parent) +{ + return wxListView::Create(parent,1,wxPoint(0,0),wxDefaultSize,wxLC_REPORT | wxLC_SINGLE_SEL); +} + +// Return pointer to the created control +wxWindow *wxListViewComboPopup::GetControl() { return this; } + +// Translate string into a list selection +void wxListViewComboPopup::SetStringValue(const wxString& s) +{ + int n = wxListView::FindItem(-1,s); + if ( n >= 0 && n < wxListView::GetItemCount() ) + wxListView::Select(n); +} + +// Get list selection as a string +wxString wxListViewComboPopup::GetStringValue() const +{ + if ( m_value >= 0 ) + return wxListView::GetItemText(m_value); + return wxEmptyString; +} + +// Do mouse hot-tracking (which is typical in list popups) +void wxListViewComboPopup::OnMouseMove(wxMouseEvent& event) +{ + // TODO: Move selection to cursor +} + +// On mouse left up, set the value and close the popup +void wxListViewComboPopup::OnMouseClick(wxMouseEvent& WXUNUSED(event)) +{ + m_value = wxListView::GetFirstSelected(); + // TODO: Send event as well + Dismiss(); +} + +wxBEGIN_EVENT_TABLE(wxListViewComboPopup, wxListView) + EVT_MOTION(wxListViewComboPopup::OnMouseMove) + EVT_LEFT_UP(wxListViewComboPopup::OnMouseClick) +wxEND_EVENT_TABLE() \ No newline at end of file diff --git a/src/wxListViewComboPopup.h b/src/wxListViewComboPopup.h new file mode 100644 index 000000000..a94e57c42 --- /dev/null +++ b/src/wxListViewComboPopup.h @@ -0,0 +1,37 @@ +#ifndef WX_LIST_VIEW_COMBO_POPUP_H +#define WX_LIST_VIEW_COMBO_POPUP_H + +#include +#include + +class wxListViewComboPopup : public wxListView, public wxComboPopup +{ +public: + // Initialize member variables + virtual void Init(); + + // Create popup control + virtual bool Create(wxWindow* parent); + + // Return pointer to the created control + virtual wxWindow *GetControl(); + + // Translate string into a list selection + virtual void SetStringValue(const wxString& s); + + // Get list selection as a string + virtual wxString GetStringValue() const; + + // Do mouse hot-tracking (which is typical in list popups) + void OnMouseMove(wxMouseEvent& event); + + // On mouse left up, set the value and close the popup + void OnMouseClick(wxMouseEvent& WXUNUSED(event)); + +protected: + int m_value; // current item index +private: + wxDECLARE_EVENT_TABLE(); +}; + +#endif // WX_LIST_VIEW_COMBO_POPUP_H \ No newline at end of file