Factor out this function from wxTextCtrl to allow its reuse in wxComboBox in the upcoming commit. No real changes, this is a pure refactoring.