📄 proplist.cpp
字号:
m_cancelButton = new wxButton(panel, wxID_PROP_CROSS, _T("X"), wxDefaultPosition, smallButtonSize ); } topsizer->Add( m_confirmButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); topsizer->Add( m_cancelButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); } m_valueText = new wxPropertyTextEdit(this, panel, wxID_PROP_TEXT, wxEmptyString, wxDefaultPosition, wxSize(wxDefaultCoord, smallButtonSize.y), wxTE_PROCESS_ENTER); m_valueText->Disable(); topsizer->Add( m_valueText, 1, wxALL | wxEXPAND, buttonborder ); if (m_buttonFlags & wxPROP_PULLDOWN) { m_editButton = new wxButton(panel, wxID_PROP_EDIT, _T("..."), wxDefaultPosition, smallButtonSize); m_editButton->Disable(); topsizer->Add( m_editButton, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); } mainsizer->Add( topsizer, 0, wxEXPAND ); // middle section with two list boxes m_middleSizer = new wxBoxSizer( wxVERTICAL ); m_valueList = new wxListBox(panel, wxID_PROP_VALUE_SELECT, wxDefaultPosition, wxSize(wxDefaultCoord, 60)); m_valueList->Show(false); m_propertyScrollingList = new wxListBox(panel, wxID_PROP_SELECT, wxDefaultPosition, wxSize(100, 100)); m_propertyScrollingList->SetFont(* boringFont); m_middleSizer->Add( m_propertyScrollingList, 1, wxALL|wxEXPAND, buttonborder ); mainsizer->Add( m_middleSizer, 1, wxEXPAND ); // bottom row with buttons if ((m_buttonFlags & wxPROP_BUTTON_OK) || (m_buttonFlags & wxPROP_BUTTON_CLOSE) || (m_buttonFlags & wxPROP_BUTTON_CANCEL) || (m_buttonFlags & wxPROP_BUTTON_HELP)) { wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL ); buttonborder = 5; if (m_buttonFlags & wxPROP_BUTTON_OK) { m_windowCloseButton = new wxButton(panel, wxID_OK, _("OK"), wxDefaultPosition, largeButtonSize ); m_windowCloseButton->SetDefault(); m_windowCloseButton->SetFocus(); bottomsizer->Add( m_windowCloseButton, 0, wxALL, buttonborder ); } else if (m_buttonFlags & wxPROP_BUTTON_CLOSE) { m_windowCloseButton = new wxButton(panel, wxID_OK, _("Close"), wxDefaultPosition, largeButtonSize ); bottomsizer->Add( m_windowCloseButton, 0, wxALL, buttonborder ); } if (m_buttonFlags & wxPROP_BUTTON_CANCEL) { m_windowCancelButton = new wxButton(panel, wxID_CANCEL, _("Cancel"), wxDefaultPosition, largeButtonSize ); bottomsizer->Add( m_windowCancelButton, 0, wxALL, buttonborder ); } if (m_buttonFlags & wxPROP_BUTTON_HELP) { m_windowHelpButton = new wxButton(panel, wxID_HELP, _("Help"), wxDefaultPosition, largeButtonSize ); bottomsizer->Add( m_windowHelpButton, 0, wxALL, buttonborder ); } mainsizer->Add( bottomsizer, 0, wxALIGN_RIGHT | wxEXPAND ); } panel->SetSizer( mainsizer ); return true;}void wxPropertyListView::ShowTextControl(bool show){ if (m_valueText) m_valueText->Show(show);}void wxPropertyListView::ShowListBoxControl(bool show){ if (!m_valueList) return; m_valueList->Show(show); if (m_buttonFlags & wxPROP_DYNAMIC_VALUE_FIELD) { if (show) m_middleSizer->Prepend( m_valueList, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 3 ); else m_middleSizer->Remove( 0 ); m_propertyWindow->Layout(); }}void wxPropertyListView::EnableCheck(bool show){ if (m_confirmButton) m_confirmButton->Enable(show);}void wxPropertyListView::EnableCross(bool show){ if (m_cancelButton) m_cancelButton->Enable(show);}bool wxPropertyListView::OnClose(){ // Retrieve the value if any wxCommandEvent event; OnCheck(event); delete this; return true;}void wxPropertyListView::OnValueListSelect(wxCommandEvent& WXUNUSED(event)){ if (m_currentProperty && m_currentValidator) { if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) return; wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; listValidator->OnValueListSelect(m_currentProperty, this, m_propertyWindow); }}void wxPropertyListView::OnOk(wxCommandEvent& event){ // Retrieve the value if any OnCheck(event); m_managedWindow->Close(true); sm_dialogCancelled = false;}void wxPropertyListView::OnCancel(wxCommandEvent& WXUNUSED(event)){// SetReturnCode(wxID_CANCEL); m_managedWindow->Close(true); sm_dialogCancelled = true;}void wxPropertyListView::OnHelp(wxCommandEvent& WXUNUSED(event)){}void wxPropertyListView::OnCheck(wxCommandEvent& WXUNUSED(event)){ if (m_currentProperty) { RetrieveProperty(m_currentProperty); }}void wxPropertyListView::OnCross(wxCommandEvent& WXUNUSED(event)){ if (m_currentProperty && m_currentValidator) { if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) return; wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; // Revert to old value listValidator->OnDisplayValue(m_currentProperty, this, m_propertyWindow); }}void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent& WXUNUSED(event)){ if (m_currentProperty && m_currentValidator) { if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) return; wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; // Revert to old value listValidator->OnDoubleClick(m_currentProperty, this, m_propertyWindow); }}void wxPropertyListView::OnEdit(wxCommandEvent& WXUNUSED(event)){ if (m_currentProperty && m_currentValidator) { if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) return; wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; listValidator->OnEdit(m_currentProperty, this, m_propertyWindow); }}void wxPropertyListView::OnText(wxCommandEvent& event){ if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) { OnCheck(event); }}// ----------------------------------------------------------------------------// Property dialog box// ----------------------------------------------------------------------------IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog, wxDialog)BEGIN_EVENT_TABLE(wxPropertyListDialog, wxDialog) EVT_BUTTON(wxID_CANCEL, wxPropertyListDialog::OnCancel) EVT_CLOSE(wxPropertyListDialog::OnCloseWindow)END_EVENT_TABLE()wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name): wxDialog(parent, wxID_ANY, title, pos, size, style, name){ m_view = v; m_view->AssociatePanel( ((wxPanel*)this) ); m_view->SetManagedWindow(this); SetAutoLayout(true);}void wxPropertyListDialog::OnCloseWindow(wxCloseEvent& event){ if (m_view) { SetReturnCode(wxID_CANCEL); m_view->OnClose(); m_view = NULL; this->Destroy(); } else { event.Veto(); }}void wxPropertyListDialog::OnCancel(wxCommandEvent& WXUNUSED(event)){ SetReturnCode(wxID_CANCEL); this->Close();}void wxPropertyListDialog::OnDefaultAction(wxControl *WXUNUSED(item)){/* if (item == m_view->GetPropertyScrollingList()) view->OnDoubleClick();*/}// Extend event processing to search the view's event tablebool wxPropertyListDialog::ProcessEvent(wxEvent& event){ if ( !m_view || ! m_view->ProcessEvent(event) ) return wxEvtHandler::ProcessEvent(event); else return true;}// ----------------------------------------------------------------------------// Property panel// ----------------------------------------------------------------------------IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel, wxPanel)BEGIN_EVENT_TABLE(wxPropertyListPanel, wxPanel) EVT_SIZE(wxPropertyListPanel::OnSize)END_EVENT_TABLE()wxPropertyListPanel::~wxPropertyListPanel(){}void wxPropertyListPanel::OnDefaultAction(wxControl *WXUNUSED(item)){/* if (item == view->GetPropertyScrollingList()) view->OnDoubleClick();*/}// Extend event processing to search the view's event tablebool wxPropertyListPanel::ProcessEvent(wxEvent& event){ if ( !m_view || ! m_view->ProcessEvent(event) ) return wxEvtHandler::ProcessEvent(event); else return true;}void wxPropertyListPanel::OnSize(wxSizeEvent& WXUNUSED(event)){ Layout();}// ----------------------------------------------------------------------------// Property frame// ----------------------------------------------------------------------------IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame, wxFrame)BEGIN_EVENT_TABLE(wxPropertyListFrame, wxFrame) EVT_CLOSE(wxPropertyListFrame::OnCloseWindow)END_EVENT_TABLE()void wxPropertyListFrame::OnCloseWindow(wxCloseEvent& event){ if (m_view) { if (m_propertyPanel) m_propertyPanel->SetView(NULL); m_view->OnClose(); m_view = NULL; this->Destroy(); } else { event.Veto(); }}wxPropertyListPanel *wxPropertyListFrame::OnCreatePanel(wxFrame *parent, wxPropertyListView *v){ return new wxPropertyListPanel(v, parent);}bool wxPropertyListFrame::Initialize(){ m_propertyPanel = OnCreatePanel(this, m_view); if (m_propertyPanel) { m_view->AssociatePanel(m_propertyPanel); m_view->SetManagedWindow(this); m_propertyPanel->SetAutoLayout(true); return true; } else return false;}// ----------------------------------------------------------------------------// Property list specific validator// ----------------------------------------------------------------------------IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator, wxPropertyValidator)bool wxPropertyListValidator::OnSelect(bool select, wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow){// view->GetValueText()->Show(true); if (select) OnDisplayValue(property, view, parentWindow); return true;}bool wxPropertyListValidator::OnValueListSelect(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)){ wxString s(view->GetValueList()->GetStringSelection()); if ( !s.empty() ) { view->GetValueText()->SetValue(s); view->RetrieveProperty(property); } return true;}bool wxPropertyListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)){// view->GetValueText()->Show(true); wxString str(property->GetValue().GetStringRepresentation()); view->GetValueText()->SetValue(str); return true;}// Called when TICK is pressed or focus is lost or view wants to update// the property list.// Does the transferance from the property editing area to the property itselfbool wxPropertyListValidator::OnRetrieveValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)){ if (!view->GetValueText()) return false; return false;}void wxPropertyListValidator::OnEdit(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)){ if (view->GetDetailedEditing()) view->EndDetailedEditing(); else view->BeginDetailedEditing();}bool wxPropertyListValidator::OnClearControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)){ if (view->GetConfirmButton()) view->GetConfirmButton()->Disable(); if (view->GetCancelButton()) view->GetCancelButton()->Disable(); if (view->GetEditButton()) view->GetEditButton()->Disable(); return true;}// ----------------------------------------------------------------------------// Default validators// ----------------------------------------------------------------------------IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator, wxPropertyListValidator)////// Real number validator///bool wxRealListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow){ if (m_realMin == 0.0 && m_realMax == 0.0) return true; if (!view->GetValueText()) return false; wxString value(view->GetValueText()->GetValue()); float val = 0.0; if (!StringToFloat(WXSTRINGCAST value, &val)) { wxChar buf[200]; wxSprintf(buf, wxT("Value %s is not a valid real number!"), value.GetData()); wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); return false; } if (val < m_realMin || val > m_realMax) { wxChar buf[200]; wxSprintf(buf, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin, m_realMax); wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); return false; } return true;}// Called when TICK is pressed or focus is lost or view wants to update// the property list.// Does the transferance from the property editing area to the property itself
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -