Currently it handles only the alpha numeric characters, if you have a suggestion for filtering a broad set of keyboard accessible characters, please let me know.
Thanks,
Guru Kathiresan
Edit 1 : I replaced the alpha numeric check code. Currently a wide range of acceptable chars are allowed to be part of the auto invoke text.
wxAutoComboBox.h
Code: Select all
///////////////////////////////////////////////////////////////////////////////
// Name: wxAutoComboBox.h
// Purpose: wxAutoComboBox class declaration.
// Author: Guru Kathiresan
// Modified by:
// Created: 03/24/2006
// Copyright: (c) Guru Kathiresan
// Licence: BSD licence
///////////////////////////////////////////////////////////////////////////////
#pragma once
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#if wxUSE_COMBOBOX
class wxAutoComboBox : public wxComboBox
{
DECLARE_DYNAMIC_CLASS(wxAutoComboBox)
public:
wxAutoComboBox();
/**
* Constructor
* \param parent Parent window pointer
* \param id Control ID
* \param value Text control value
* \param pos Position of the control
* \param size Size of the control
* \param choices List of String Items
* \param style Style values for the text control
* \param validator Validator for validating the user input
* \param name Name of the control.
*/
wxAutoComboBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, const wxArrayString& choices = NULL, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxT("Auto Text Control"));
/**
* Default Destructor.
*/
virtual ~wxAutoComboBox(void);
protected:
/**
* Event handler for key Up.
* \detail For the alpha numeric characters the partial match of the combo items will be done.
* \param &event
*/
void OnKeyUp(wxKeyEvent &event);
private:
// Any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE()
};
#endif // wxUSE_TEXTCTRL
wxAutoComboBox.cpp
Code: Select all
///////////////////////////////////////////////////////////////////////////////
// Name: wxAutoComboBox.cpp
// Purpose: wxAutoComboBox class implementation.
// Author: Guru Kathiresan
// Modified by:
// Created: 03/24/2006
// Copyright: (c) Guru Kathiresan
// Licence: BSD licence
///////////////////////////////////////////////////////////////////////////////
#include "wxAutoCombobox.h"
#if wxUSE_COMBOBOX
IMPLEMENT_DYNAMIC_CLASS(wxAutoComboBox, wxComboBox)
BEGIN_EVENT_TABLE(wxAutoComboBox, wxComboBox)
EVT_KEY_UP(wxAutoComboBox::OnKeyUp)
END_EVENT_TABLE()
wxAutoComboBox::wxAutoComboBox()
{
}
wxAutoComboBox::wxAutoComboBox(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, const wxArrayString& choices, long style, const wxValidator& validator, const wxString& name)
: wxComboBox(parent, id, value, pos, size, choices, style, validator, name)
{
}
wxAutoComboBox::~wxAutoComboBox(void)
{
}
void wxAutoComboBox::OnKeyUp(wxKeyEvent &event)
{
int nKeyCode = event.GetKeyCode();
if ( ((nKeyCode >= 32) && (nKeyCode <= 126)) || ((nKeyCode >= 128) && (nKeyCode <= 254)))
{
wxString txtValue = GetValue();
long start=-1, end=-1;
GetSelection(&start, &end);
wxString EnteredValue = txtValue.Left(start);
int Idx = -1;
for( size_t i=0; i<this->GetCount(); i++ )
{
if (this->GetString(i).Left(EnteredValue.Length()).CmpNoCase(EnteredValue) == 0)
{
Idx = i;
break;
}
}
if (Idx != -1)
{
SetSelection(Idx);
SetSelection(start,GetValue().Length());
return;
}
}
event.Skip(true);
}
#endif // wxUSE_COMBOBOX