📄 preferencespagelcdproc.cpp
字号:
psizerWidgetList->Add( new wxStaticText(this, -1, wxT("Widget List")), 1, wxALIGN_CENTER, 0 ); ////////////////////////////////////////////////////////////////////////// // Blank label ////////////////////////////////////////////////////////////////////////// psizerWidgetList->Add( new wxStaticText(this, -1, wxT("")), 1, wxALIGN_CENTER, 0 ); ////////////////////////////////////////////////////////////////////////// // "Widgets" list box ////////////////////////////////////////////////////////////////////////// m_pctlWidgetList = new wxListBox(this, idWidgetList, wxDefaultPosition, wxSize(100, 100), 0, NULL, wxLB_SINGLE); psizerWidgetList->Add( m_pctlWidgetList, 1, wxALIGN_CENTER | wxGROW, 0 ); ////////////////////////////////////////////////////////////////////////// // Widget list actions - add, update, delete ////////////////////////////////////////////////////////////////////////// psizerWidgetListActions = new wxBoxSizer(wxVERTICAL); psizerWidgetListActions->Add( new wxButton(this, idAdd, wxT("&Add")), 1, wxALL | wxGROW, 0 ); psizerWidgetListActions->Add( new wxButton(this, idUpdate, wxT("&Update")), 1, wxALL | wxGROW, 0 ); psizerWidgetListActions->Add( new wxButton(this, idDelete, wxT("&Delete")), 1, wxALL | wxGROW, 0 ); psizerWidgetList->Add(psizerWidgetListActions, 1, wxALL | wxGROW, 0); ////////////////////////////////////////////////////////////////////////// // Combine the sizers ////////////////////////////////////////////////////////////////////////// psizerBottom->Add(psizerWidgetSettings, 1, wxALL | wxGROW, 10); psizerBottom->Add(psizerWidgetList, 1, wxALL | wxGROW, 10); psizerWnd = new wxFlexGridSizer(1, 2, 10); psizerWnd->Add(psizerTop, 1, wxALL | wxGROW, 10); psizerWnd->Add(psizerBottom, 1, wxALL | wxGROW, 10); ////////////////////////////////////////////////////////////////////////// // Set up the sizer ////////////////////////////////////////////////////////////////////////// //m_pctlPositionFormat->SetFocus(); psizerWnd->Fit(this); SetSizer(psizerWnd); Layout(); psizerWnd->SetSizeHints(this); UpdateScreenList(); if (m_pctlScreenSelection->GetCount() > 0) { m_pctlScreenSelection->SetSelection(0); UpdateWidgetList(); }}//////////////////////////////////////////////////////////////////////////////////// \brief Update the list of screens in the m_pctlScreenSelection combo box./////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::UpdateScreenList(){ unsigned int iScreen; m_pctlScreenSelection->Clear(); for (iScreen = 0; iScreen < m_cActiveSettings.m_vScreens.size(); iScreen++) m_pctlScreenSelection->Append(m_cActiveSettings.m_vScreens[iScreen].m_strName);}//////////////////////////////////////////////////////////////////////////////////// \brief Update the list of widgets in the m_pctlWidgetList list box./////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::UpdateWidgetList(){ int iScreen; iScreen = m_pctlScreenSelection->FindString(m_pctlScreenSelection->GetValue()); m_pctlWidgetList->Clear(); if (iScreen != wxNOT_FOUND && iScreen >= 0) { unsigned int iWidget; for (iWidget = 0; iWidget < m_cActiveSettings.m_vScreens[iScreen].m_vWidgets.size(); iWidget++) m_pctlWidgetList->Append(m_cActiveSettings.m_vScreens[iScreen].m_vWidgets[iWidget].m_strValue); }}//////////////////////////////////////////////////////////////////////////////////// \brief Ok was pressed .. save the settings/////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::OnOk(wxCommandEvent& event){ m_cActiveSettings.m_strHostAndPort = m_pctlHostAndPort->GetValue(); m_cActiveSettings.m_bLCDprocEnabled = m_pctlEnableLCDproc->GetValue(); SetLCDprocSettings(m_cActiveSettings);}//////////////////////////////////////////////////////////////////////////////////// \brief Text was typed in the screen selection combo box - update the/// widget list accordingly./////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::OnScreenSelection(wxCommandEvent& event){ UpdateWidgetList();}//////////////////////////////////////////////////////////////////////////////////// \brief The user selected a widget from the list. Update the widget/// settings on the screen with the settings for that widget./////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::OnWidgetSelection(wxCommandEvent& event){ int iScreen; int iWidget; iScreen = m_pctlScreenSelection->FindString(m_pctlScreenSelection->GetValue()); iWidget = m_pctlWidgetList->GetSelection(); if (iWidget == wxNOT_FOUND || iWidget < 0 || iScreen == wxNOT_FOUND || iScreen < 0) { m_pctlWidgetRow->SetValue(wxT("")); m_pctlWidgetColumn->SetValue(wxT("")); m_pctlWidgetType->SetValue(wxT("Text")); m_pctlWidgetContents->SetValue(wxT("")); return; } m_pctlWidgetRow->SetValue(wxString::Format(wxT("%d"), m_cActiveSettings.m_vScreens[iScreen].m_vWidgets[iWidget].m_iRow)); m_pctlWidgetColumn->SetValue(wxString::Format(wxT("%d"), m_cActiveSettings.m_vScreens[iScreen].m_vWidgets[iWidget].m_iCol)); m_pctlWidgetType->SetValue(m_cActiveSettings.m_vScreens[iScreen].m_vWidgets[iWidget].m_strType); m_pctlWidgetContents->SetValue(m_cActiveSettings.m_vScreens[iScreen].m_vWidgets[iWidget].m_strValue);}//////////////////////////////////////////////////////////////////////////////////// \brief User clicked add - add the entered settings into a new widget./////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::OnWidgetAdd(wxCommandEvent& event){ LCDprocWidgetInfo cWidgetInfo; int iScreen; iScreen = m_pctlScreenSelection->FindString(m_pctlScreenSelection->GetValue()); if (iScreen == wxNOT_FOUND || iScreen < 0) { LCDprocScreenInfo cScreenInfo; cScreenInfo.m_strName = m_pctlScreenSelection->GetValue(); m_cActiveSettings.m_vScreens.push_back(cScreenInfo); iScreen = m_cActiveSettings.m_vScreens.size() - 1; UpdateScreenList(); m_pctlScreenSelection->SetSelection(iScreen); } cWidgetInfo.m_iCol = atoi(m_pctlWidgetColumn->GetValue().mb_str(*wxConvCurrent)); cWidgetInfo.m_iRow = atoi(m_pctlWidgetRow->GetValue().mb_str(*wxConvCurrent)); cWidgetInfo.m_strType = m_pctlWidgetType->GetValue(); cWidgetInfo.m_strValue = m_pctlWidgetContents->GetValue(); m_cActiveSettings.m_vScreens[iScreen].m_vWidgets.push_back(cWidgetInfo); UpdateWidgetList(); m_pctlWidgetList->SetSelection(m_pctlWidgetList->GetCount() - 1);}//////////////////////////////////////////////////////////////////////////////////// \brief User clicked update - update the settings in the selected widget/// with what's on the screen./////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::OnWidgetUpdate(wxCommandEvent& event){ LCDprocWidgetInfo cWidgetInfo; int iScreen; int iWidget; iScreen = m_pctlScreenSelection->FindString(m_pctlScreenSelection->GetValue()); iWidget = m_pctlWidgetList->GetSelection(); if (iWidget == wxNOT_FOUND || iWidget < 0 || iScreen == wxNOT_FOUND || iScreen < 0) return; cWidgetInfo.m_iCol = atoi(m_pctlWidgetColumn->GetValue().mb_str(*wxConvCurrent)); cWidgetInfo.m_iRow = atoi(m_pctlWidgetRow->GetValue().mb_str(*wxConvCurrent)); cWidgetInfo.m_strType = m_pctlWidgetType->GetValue(); cWidgetInfo.m_strValue = m_pctlWidgetContents->GetValue(); m_cActiveSettings.m_vScreens[iScreen].m_vWidgets[iWidget] = cWidgetInfo; UpdateWidgetList(); m_pctlWidgetList->SetSelection(iWidget);}//////////////////////////////////////////////////////////////////////////////////// \brief User clicked delete - delete the selected widget.////// Also, deletes the selected screen if there are no widgets left on it./////////////////////////////////////////////////////////////////////////////////void PreferencesPageLCDproc::OnWidgetDelete(wxCommandEvent& event){ int iScreen; int iWidget; iScreen = m_pctlScreenSelection->FindString(m_pctlScreenSelection->GetValue()); iWidget = m_pctlWidgetList->GetSelection(); if (iWidget == wxNOT_FOUND || iWidget < 0 || iScreen == wxNOT_FOUND || iScreen < 0) return; m_cActiveSettings.m_vScreens[iScreen].m_vWidgets.erase(m_cActiveSettings.m_vScreens[iScreen].m_vWidgets.begin() + iWidget); UpdateWidgetList(); // check if this was the last widget if (m_cActiveSettings.m_vScreens[iScreen].m_vWidgets.size() == 0) { // if so, remove the entire screen m_cActiveSettings.m_vScreens.erase(m_cActiveSettings.m_vScreens.begin() + iScreen); UpdateScreenList(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -