Skip to content

Commit

Permalink
Merge branch 'ms-display-multiple-callsigns' into ms-2020c
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Apr 14, 2023
2 parents 9867eeb + 4e11e73 commit 6cce8ee
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ set(FREEDV_SOURCES
ongui.cpp
freedv_interface.cpp
freedv_interface.h
wxListViewComboPopup.cpp
wxListViewComboPopup.h
)

set(FREEDV_SOURCES_OSX
Expand Down
18 changes: 13 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down
7 changes: 6 additions & 1 deletion src/topFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/topFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
#include <wx/notebook.h>
#include <wx/listctrl.h>
#include <wx/collpane.h>
#include <wx/combobox.h>
#include <wx/combo.h>

#include "wxListViewComboPopup.h"

#include "freedv_api.h" // for FREEDV_MODE_*

Expand All @@ -74,6 +76,8 @@

#define ID_MODE_COLLAPSE 1100

class wxListViewComboPopup;

///////////////////////////////////////////////////////////////////////////////
/// Class TopFrame
///////////////////////////////////////////////////////////////////////////////
Expand All @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions src/wxListViewComboPopup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "wxListViewComboPopup.h"

#include <wx/combo.h>
#include <wx/listctrl.h>

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()
37 changes: 37 additions & 0 deletions src/wxListViewComboPopup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef WX_LIST_VIEW_COMBO_POPUP_H
#define WX_LIST_VIEW_COMBO_POPUP_H

#include <wx/combo.h>
#include <wx/listctrl.h>

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

0 comments on commit 6cce8ee

Please sign in to comment.