2017-01-02 21:07:43 -05:00
|
|
|
// Copyright (c) Charles J. Cliffe
|
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
2016-06-11 04:08:12 -04:00
|
|
|
#include "DemodLabelDialog.h"
|
|
|
|
|
|
|
|
#include "wx/clipbrd.h"
|
|
|
|
#include <sstream>
|
|
|
|
#include "CubicSDR.h"
|
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(DemodLabelDialog, wxDialog)
|
|
|
|
EVT_CHAR_HOOK(DemodLabelDialog::OnChar)
|
|
|
|
EVT_SHOW(DemodLabelDialog::OnShow)
|
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
DemodLabelDialog::DemodLabelDialog(wxWindow * parent, wxWindowID id, const wxString & title,
|
|
|
|
DemodulatorInstance *demod, const wxPoint & position,
|
|
|
|
const wxSize & size, long style) :
|
|
|
|
wxDialog(parent, id, title, position, size, style) {
|
|
|
|
|
|
|
|
wxString labelStr;
|
|
|
|
|
|
|
|
//by construction, is allways != nullptr
|
|
|
|
activeDemod = demod;
|
|
|
|
|
|
|
|
labelStr = activeDemod->getDemodulatorUserLabel();
|
|
|
|
|
|
|
|
if (labelStr.empty()) {
|
|
|
|
//propose a default value...
|
|
|
|
labelStr = activeDemod->getDemodulatorType();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dialogText = new wxTextCtrl(this, wxID_LABEL_INPUT, labelStr, wxPoint(6, 1), wxSize(size.GetWidth() - 20, size.GetHeight() - 70),
|
|
|
|
wxTE_PROCESS_ENTER);
|
|
|
|
dialogText->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
|
|
|
|
Centre();
|
|
|
|
|
|
|
|
dialogText->SetValue(labelStr);
|
|
|
|
dialogText->SetSelection(-1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DemodLabelDialog::OnChar(wxKeyEvent& event) {
|
|
|
|
int c = event.GetKeyCode();
|
|
|
|
|
2016-06-12 09:31:55 -04:00
|
|
|
//we support 16 bit strings for user labels internally.
|
2016-06-14 13:41:19 -04:00
|
|
|
wxString strValue = dialogText->GetValue();
|
2016-06-11 04:08:12 -04:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case WXK_RETURN:
|
|
|
|
case WXK_NUMPAD_ENTER:
|
|
|
|
|
2016-06-14 13:41:19 -04:00
|
|
|
//No need to display the demodulator type twice if the user do not change the default value...
|
|
|
|
//when comparing getDemodulatorType() std::string, take care of "upgrading" it to wxString which will
|
|
|
|
//try to its best...
|
|
|
|
if (strValue != wxString(activeDemod->getDemodulatorType())) {
|
|
|
|
activeDemod->setDemodulatorUserLabel(strValue.ToStdWstring());
|
2016-06-11 04:08:12 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-06-12 09:31:55 -04:00
|
|
|
activeDemod->setDemodulatorUserLabel(L"");
|
2016-06-11 04:08:12 -04:00
|
|
|
}
|
2016-11-14 23:52:50 -05:00
|
|
|
wxGetApp().getBookmarkMgr().updateActiveList();
|
2016-06-11 04:08:12 -04:00
|
|
|
Close();
|
|
|
|
break;
|
|
|
|
case WXK_ESCAPE:
|
|
|
|
Close();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.ControlDown() && c == 'V') {
|
|
|
|
// Alter clipboard contents to remove unwanted chars
|
|
|
|
wxTheClipboard->Open();
|
|
|
|
wxTextDataObject data;
|
|
|
|
wxTheClipboard->GetData(data);
|
2016-06-12 09:31:55 -04:00
|
|
|
std::wstring clipText = data.GetText().ToStdWstring();
|
2016-06-11 04:08:12 -04:00
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(clipText));
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
else if (c == WXK_RIGHT || c == WXK_LEFT || event.ControlDown()) {
|
|
|
|
event.Skip();
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef __linux__
|
|
|
|
dialogText->OnChar(event);
|
|
|
|
event.Skip();
|
|
|
|
#else
|
|
|
|
event.DoAllowNextEvent();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodLabelDialog::OnShow(wxShowEvent &event) {
|
|
|
|
|
|
|
|
dialogText->SetFocus();
|
|
|
|
dialogText->SetSelection(-1, -1);
|
|
|
|
event.Skip();
|
|
|
|
}
|