Skip to content

Commit 65bb445

Browse files
authored
Merge pull request #638 from drowe67/ms-reporter-col-size
Fix issue preventing proper FreeDV Reporter column sizing on Windows.
2 parents e9b7dad + 6123977 commit 65bb445

File tree

2 files changed

+121
-44
lines changed

2 files changed

+121
-44
lines changed

USER_MANUAL.md

+1
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
921921
* Fix intermittent crash resulting from object thread starting before object is fully initialized. (PR #630)
922922
* Prevent creation of filters if not enabled. (PR #631)
923923
* Fix issue preventing Start button from reenabling itself on audio device errors. (PR #636)
924+
* Fix issue preventing proper FreeDV Reporter column sizing on Windows. (PR #638)
924925
2. Enhancements:
925926
* Allow user to refresh status message even if it hasn't been changed. (PR #632)
926927
* Increase priority of status message highlight. (PR #632)

src/freedv_reporter.cpp

+120-44
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
extern FreeDVInterface freedvInterface;
2929

3030
#define UNKNOWN_STR "--"
31+
#if defined(WIN32)
32+
#define NUM_COLS (14) /* Note: need empty column 0 to work around callsign truncation issue. */
33+
#else
3134
#define NUM_COLS (13)
35+
#endif // defined(WIN32)
3236
#define RX_ONLY_STATUS "RX Only"
3337
#define RX_COLORING_TIMEOUT_SEC (20)
3438
#define MSG_COLORING_TIMEOUT_SEC (5)
@@ -59,24 +63,33 @@ FreeDVReporterDialog::FreeDVReporterDialog(wxWindow* parent, wxWindowID id, cons
5963

6064
// Main list box
6165
// =============================
66+
int col = 0;
6267
m_listSpots = new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL | wxLC_REPORT | wxLC_HRULES);
63-
m_listSpots->InsertColumn(0, wxT("Callsign"), wxLIST_FORMAT_CENTER, 80);
64-
m_listSpots->InsertColumn(1, wxT("Locator"), wxLIST_FORMAT_CENTER, 80);
65-
m_listSpots->InsertColumn(2, wxT("KM"), wxLIST_FORMAT_CENTER, 80);
66-
m_listSpots->InsertColumn(3, wxT("Version"), wxLIST_FORMAT_CENTER, 80);
67-
m_listSpots->InsertColumn(4, wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz ? wxT("KHz") : wxT("MHz"), wxLIST_FORMAT_CENTER, 80);
68-
m_listSpots->InsertColumn(5, wxT("Status"), wxLIST_FORMAT_CENTER, 80);
69-
m_listSpots->InsertColumn(6, wxT("Msg"), wxLIST_FORMAT_CENTER, 20);
70-
m_listSpots->InsertColumn(7, wxT("Last TX"), wxLIST_FORMAT_CENTER, 80);
71-
m_listSpots->InsertColumn(8, wxT("Mode"), wxLIST_FORMAT_CENTER, 80);
72-
m_listSpots->InsertColumn(9, wxT("RX Call"), wxLIST_FORMAT_CENTER, 120);
73-
m_listSpots->InsertColumn(10, wxT("Mode"), wxLIST_FORMAT_CENTER, 120);
74-
m_listSpots->InsertColumn(11, wxT("SNR"), wxLIST_FORMAT_CENTER, 40);
75-
m_listSpots->InsertColumn(12, wxT("Last Update"), wxLIST_FORMAT_CENTER, 120);
68+
69+
#if defined(WIN32)
70+
// Create "hidden" column at the beginning. The column logic in wxWidgets
71+
// seems to want to add an image to column 0, which affects
72+
// autosizing.
73+
m_listSpots->InsertColumn(col++, wxT(""), wxLIST_FORMAT_CENTER, 1);
74+
#endif // defined(WIN32)
75+
76+
m_listSpots->InsertColumn(col++, wxT("Callsign"), wxLIST_FORMAT_CENTER, 80);
77+
m_listSpots->InsertColumn(col++, wxT("Locator"), wxLIST_FORMAT_CENTER, 80);
78+
m_listSpots->InsertColumn(col++, wxT("KM"), wxLIST_FORMAT_CENTER, 80);
79+
m_listSpots->InsertColumn(col++, wxT("Version"), wxLIST_FORMAT_CENTER, 80);
80+
m_listSpots->InsertColumn(col++, wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz ? wxT("KHz") : wxT("MHz"), wxLIST_FORMAT_CENTER, 80);
81+
m_listSpots->InsertColumn(col++, wxT("Status"), wxLIST_FORMAT_CENTER, 80);
82+
m_listSpots->InsertColumn(col++, wxT("Msg"), wxLIST_FORMAT_CENTER, 20);
83+
m_listSpots->InsertColumn(col++, wxT("Last TX"), wxLIST_FORMAT_CENTER, 80);
84+
m_listSpots->InsertColumn(col++, wxT("Mode"), wxLIST_FORMAT_CENTER, 80);
85+
m_listSpots->InsertColumn(col++, wxT("RX Call"), wxLIST_FORMAT_CENTER, 120);
86+
m_listSpots->InsertColumn(col++, wxT("Mode"), wxLIST_FORMAT_CENTER, 120);
87+
m_listSpots->InsertColumn(col++, wxT("SNR"), wxLIST_FORMAT_CENTER, 40);
88+
m_listSpots->InsertColumn(col++, wxT("Last Update"), wxLIST_FORMAT_CENTER, 120);
7689

7790
// On Windows, the last column will end up taking a lot more space than desired regardless
7891
// of the space we actually need. Create a "dummy" column to take that space instead.
79-
m_listSpots->InsertColumn(13, wxT(""), wxLIST_FORMAT_CENTER, 1);
92+
m_listSpots->InsertColumn(col++, wxT(""), wxLIST_FORMAT_CENTER, 1);
8093

8194
sectionSizer->Add(m_listSpots, 0, wxALL | wxEXPAND, 2);
8295

@@ -275,8 +288,15 @@ FreeDVReporterDialog::~FreeDVReporterDialog()
275288

276289
void FreeDVReporterDialog::refreshLayout()
277290
{
291+
int colOffset = 0;
292+
293+
#if defined(WIN32)
294+
// Column 0 is hidden, so everything is shifted by 1 column.
295+
colOffset++;
296+
#endif // defined(WIN32)
297+
278298
wxListItem item;
279-
m_listSpots->GetColumn(2, item);
299+
m_listSpots->GetColumn(2 + colOffset, item);
280300

281301
if (wxGetApp().appConfiguration.reportingConfiguration.useMetricDistances)
282302
{
@@ -287,10 +307,10 @@ void FreeDVReporterDialog::refreshLayout()
287307
item.SetText("Miles");
288308
}
289309

290-
m_listSpots->SetColumn(2, item);
310+
m_listSpots->SetColumn(2 + colOffset, item);
291311

292312
// Refresh frequency units as appropriate.
293-
m_listSpots->GetColumn(4, item);
313+
m_listSpots->GetColumn(4 + colOffset, item);
294314
if (wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz)
295315
{
296316
item.SetText("KHz");
@@ -299,7 +319,7 @@ void FreeDVReporterDialog::refreshLayout()
299319
{
300320
item.SetText("MHz");
301321
}
302-
m_listSpots->SetColumn(4, item);
322+
m_listSpots->SetColumn(4 + colOffset, item);
303323

304324
std::map<int, int> colResizeList;
305325
for (auto& kvp : allReporterData_)
@@ -451,6 +471,15 @@ void FreeDVReporterDialog::OnSortColumn(wxListEvent& event)
451471
{
452472
int col = event.GetColumn();
453473

474+
#if defined(WIN32)
475+
// The "hidden" column 0 is new as of 1.9.7. Automatically
476+
// assume the user is sorting by callsign.
477+
if (col == 0)
478+
{
479+
col = 1;
480+
}
481+
#endif // defined(WIN32)
482+
454483
if (col > 12)
455484
{
456485
// Don't allow sorting by "fake" columns.
@@ -704,6 +733,15 @@ void FreeDVReporterDialog::sortColumn_(int col)
704733

705734
void FreeDVReporterDialog::sortColumn_(int col, bool direction)
706735
{
736+
#if defined(WIN32)
737+
// The hidden column 0 is new in 1.9.7. Assume sort by the "old" column 0
738+
// (callsign).
739+
if (col == 0)
740+
{
741+
col = 1;
742+
}
743+
#endif // defined(WIN32)
744+
707745
if (currentSortColumn_ != -1)
708746
{
709747
m_listSpots->ClearColumnImage(currentSortColumn_);
@@ -745,6 +783,14 @@ void FreeDVReporterDialog::clearAllEntries_(bool clearForAllBands)
745783
// Reset lengths to force auto-resize on (re)connect.
746784
for (int col = 0; col < NUM_COLS; col++)
747785
{
786+
#if defined(WIN32)
787+
// First column is hidden, so don't auto-size.
788+
if (col == 0)
789+
{
790+
continue;
791+
}
792+
#endif // defined(WIN32)
793+
748794
columnLengths_[col] = 0;
749795
m_listSpots->SetColumnWidth(col, wxLIST_AUTOSIZE_USEHEADER);
750796
}
@@ -1315,6 +1361,14 @@ void FreeDVReporterDialog::resizeChangedColumns_(std::map<int, int>& colResizeLi
13151361
{
13161362
for (auto& kvp : colResizeList)
13171363
{
1364+
#if defined(WIN32)
1365+
// The first column on Windows is hidden, so don't resize.
1366+
if (kvp.first == 0)
1367+
{
1368+
continue;
1369+
}
1370+
#endif // defined(WIN32)
1371+
13181372
m_listSpots->SetColumnWidth(kvp.first, wxLIST_AUTOSIZE_USEHEADER);
13191373
}
13201374

@@ -1360,40 +1414,62 @@ void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data, std
13601414
}
13611415
else if (itemIndex == -1 && !filtered)
13621416
{
1363-
itemIndex = m_listSpots->InsertItem(m_listSpots->GetItemCount(), data->callsign);
1417+
itemIndex = m_listSpots->InsertItem(m_listSpots->GetItemCount(), _(""));
13641418
m_listSpots->SetItemPtrData(itemIndex, (wxUIntPtr)new std::string(data->sid));
1365-
needResort = currentSortColumn_ == 0;
13661419
}
13671420
else if (filtered)
13681421
{
13691422
// Don't add for now as it's not supposed to display.
13701423
return;
13711424
}
13721425

1373-
bool changed = setColumnForRow_(itemIndex, 1, data->gridSquare, colResizeList);
1374-
needResort |= changed && currentSortColumn_ == 1;
1375-
changed = setColumnForRow_(itemIndex, 2, data->distance, colResizeList);
1376-
needResort |= changed && currentSortColumn_ == 2;
1377-
changed = setColumnForRow_(itemIndex, 3, data->version, colResizeList);
1378-
needResort |= changed && currentSortColumn_ == 3;
1379-
changed = setColumnForRow_(itemIndex, 4, data->freqString, colResizeList);
1380-
needResort |= changed && currentSortColumn_ == 4;
1381-
changed = setColumnForRow_(itemIndex, 5, data->status, colResizeList);
1382-
needResort |= changed && currentSortColumn_ == 5;
1383-
changed = setColumnForRow_(itemIndex, 6, data->userMessage, colResizeList);
1384-
needResort |= changed && currentSortColumn_ == 6;
1385-
changed = setColumnForRow_(itemIndex, 7, data->lastTx, colResizeList);
1386-
needResort |= changed && currentSortColumn_ == 7;
1387-
changed = setColumnForRow_(itemIndex, 8, data->txMode, colResizeList);
1388-
needResort |= changed && currentSortColumn_ == 8;
1389-
changed = setColumnForRow_(itemIndex, 9, data->lastRxCallsign, colResizeList);
1390-
needResort |= changed && currentSortColumn_ == 9;
1391-
changed = setColumnForRow_(itemIndex, 10, data->lastRxMode, colResizeList);
1392-
needResort |= changed && currentSortColumn_ == 10;
1393-
changed = setColumnForRow_(itemIndex, 11, data->snr, colResizeList);
1394-
needResort |= changed && currentSortColumn_ == 11;
1395-
changed = setColumnForRow_(itemIndex, 12, data->lastUpdate, colResizeList);
1396-
needResort |= changed && currentSortColumn_ == 12;
1426+
int col = 0;
1427+
#if defined(WIN32)
1428+
// Column 0 is "hidden" to avoid column autosize issue. Callsign should be in column 1 instead.
1429+
// Also, clear the item image for good measure as wxWidgets for Windows will set one for some
1430+
// reason.
1431+
m_listSpots->SetItemColumnImage(itemIndex, 0, -1);
1432+
col = 1;
1433+
#endif // defined(WIN32)
1434+
1435+
bool changed = setColumnForRow_(itemIndex, col++, data->callsign, colResizeList);
1436+
needResort |= changed && currentSortColumn_ == (col - 1);
1437+
1438+
changed = setColumnForRow_(itemIndex, col++, data->gridSquare, colResizeList);
1439+
needResort |= changed && currentSortColumn_ == (col - 1);
1440+
1441+
changed = setColumnForRow_(itemIndex, col++, data->distance, colResizeList);
1442+
needResort |= changed && currentSortColumn_ == (col - 1);
1443+
1444+
changed = setColumnForRow_(itemIndex, col++, data->version, colResizeList);
1445+
needResort |= changed && currentSortColumn_ == (col - 1);
1446+
1447+
changed = setColumnForRow_(itemIndex, col++, data->freqString, colResizeList);
1448+
needResort |= changed && currentSortColumn_ == (col - 1);
1449+
1450+
changed = setColumnForRow_(itemIndex, col++, data->status, colResizeList);
1451+
needResort |= changed && currentSortColumn_ == (col - 1);
1452+
1453+
changed = setColumnForRow_(itemIndex, col++, data->userMessage, colResizeList);
1454+
needResort |= changed && currentSortColumn_ == (col - 1);
1455+
1456+
changed = setColumnForRow_(itemIndex, col++, data->lastTx, colResizeList);
1457+
needResort |= changed && currentSortColumn_ == (col - 1);
1458+
1459+
changed = setColumnForRow_(itemIndex, col++, data->txMode, colResizeList);
1460+
needResort |= changed && currentSortColumn_ == (col - 1);
1461+
1462+
changed = setColumnForRow_(itemIndex, col++, data->lastRxCallsign, colResizeList);
1463+
needResort |= changed && currentSortColumn_ == (col - 1);
1464+
1465+
changed = setColumnForRow_(itemIndex, col++, data->lastRxMode, colResizeList);
1466+
needResort |= changed && currentSortColumn_ == (col - 1);
1467+
1468+
changed = setColumnForRow_(itemIndex, col++, data->snr, colResizeList);
1469+
needResort |= changed && currentSortColumn_ == (col - 1);
1470+
1471+
changed = setColumnForRow_(itemIndex, col++, data->lastUpdate, colResizeList);
1472+
needResort |= changed && currentSortColumn_ == (col - 1);
13971473

13981474
// Messaging updates take highest priority.
13991475
auto curDate = wxDateTime::Now().ToUTC();

0 commit comments

Comments
 (0)