Allow using custom main window in wxComboCtrl

Add wxComboCtrl::SetMainControl() which can be used to use some other
window instead of the default wxTextCtrl as the main window of the
combo control.

Update the sample and the documentation to show the new function.
This commit is contained in:
Vadim Zeitlin
2021-09-08 19:38:28 +01:00
parent 13c6c619ac
commit 573e4fa0ec
4 changed files with 137 additions and 32 deletions

View File

@@ -884,7 +884,7 @@ MyFrame::MyFrame(const wxString& title)
//
rowSizer = new wxBoxSizer( wxHORIZONTAL );
rowSizer->Add( new wxStaticText(panel,wxID_ANY,
"wxComboCtrl with custom button action:"), 1,
"wxComboCtrl with custom button and custom main control:"), 1,
wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
@@ -898,7 +898,31 @@ MyFrame::MyFrame(const wxString& title)
(long)0
);
// This is a perfectly useless control, as the popup and main control
// don't interact with each other, but it shows that we can use something
// other than wxTextCtrl for the main part of wxComboCtrl too.
//
// In a real program, custom popup and main control would work together,
// i.e. changing selection in one of them would update the other one.
//
// Also note the complicated dance we need to go through to create the
// controls in the right order: we want to create the custom main control
// before actually creating the wxComboCtrl window, as otherwise it would
// unnecessarily create a wxTextCtrl by default, forcing us to use its
// default ctor and Create() later, but this, in turn, also requires using
// default ctor for the main control and creating it later too, as it can't
// be created before its parent window is.
wxComboCtrl* comboCustom = new wxComboCtrl();
wxCheckBox* cbox = new wxCheckBox();
comboCustom->SetMainControl(cbox);
comboCustom->Create(panel, wxID_ANY, wxEmptyString);
cbox->Create(comboCustom, wxID_ANY, "Checkbox as main control");
cbox->SetBackgroundColour(*wxWHITE);
comboCustom->SetPopupControl(new ListViewComboPopup());
rowSizer->Add( fsc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
rowSizer->Add( comboCustom, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );