FIX: [STUDIO-3217] hide dropdown when combobox move by scroll

Change-Id: I8d8e9ec4a54f6418843463f1bf4f1f46fd4af3df
This commit is contained in:
chunmao.guo 2023-06-20 15:13:10 +08:00 committed by Lane.Wei
parent cbb69c415a
commit 869a3046aa
2 changed files with 21 additions and 1 deletions

View file

@ -19,7 +19,18 @@ END_EVENT_TABLE()
* calling Refresh()/Update().
*/
ComboBox::ComboBox(wxWindow * parent,
static wxWindow *GetScrollParent(wxWindow *pWindow)
{
wxWindow *pWin = pWindow;
while (pWin->GetParent()) {
auto pWin2 = pWin->GetParent();
if (auto top = dynamic_cast<wxScrollHelper *>(pWin2)) return dynamic_cast<wxWindow *>(pWin);
pWin = pWin2;
}
return pWin;
}
ComboBox::ComboBox(wxWindow *parent,
wxWindowID id,
const wxString &value,
const wxPoint & pos,
@ -50,6 +61,8 @@ ComboBox::ComboBox(wxWindow * parent,
} else {
GetTextCtrl()->Bind(wxEVT_KEY_DOWN, &ComboBox::keyDown, this);
}
if (auto scroll = GetScrollParent(this))
scroll->Bind(wxEVT_MOVE, &ComboBox::onMove, this);
drop.Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
SetSelection(e.GetInt());
e.SetEventObject(this);
@ -281,6 +294,12 @@ void ComboBox::keyDown(wxKeyEvent& event)
}
}
void ComboBox::onMove(wxMoveEvent &event)
{
event.Skip();
drop.Hide();
}
void ComboBox::OnEdit()
{
auto value = GetTextCtrl()->GetValue();