Version: 3.1.0
wxTextCompleterSimple Class Referenceabstract

#include <wx/textcompleter.h>

+ Inheritance diagram for wxTextCompleterSimple:

Detailed Description

A simpler base class for custom completer objects.

This class may be simpler to use than the base wxTextCompleter as it allows to implement only a single virtual method instead of two of them (at the price of storing all completions in a temporary array).

Here is a simple example of a custom completer that completes the names of some chess pieces. Of course, as the total list here has only four items it would have been much simpler to just specify the array containing all the completions in this example but the same approach could be used when the total number of completions is much higher provided the number of possibilities for each word is still relatively small:

class MyTextCompleter : public wxTextCompleterSimple
{
public:
virtual void GetCompletions(const wxString& prefix, wxArrayString& res)
{
const wxString firstWord = prefix.BeforeFirst(' ');
if ( firstWord == "white" )
{
res.push_back("white pawn");
res.push_back("white rook");
}
else if ( firstWord == "black" )
{
res.push_back("black king");
res.push_back("black queen");
}
else
{
res.push_back("white");
res.push_back("black");
}
}
};
...
wxTextCtrl *text = ...;
text->AutoComplete(new MyTextCompleter);

Library:  wxCore
Since
2.9.2

Public Member Functions

virtual void GetCompletions (const wxString &prefix, wxArrayString &res)=0
 Pure virtual method returning all possible completions for the given prefix.
 
- Public Member Functions inherited from wxTextCompleter
virtual bool Start (const wxString &prefix)=0
 Function called to start iteration over the completions for the given prefix.
 
virtual wxString GetNext ()=0
 Called to retrieve the next completion.
 

Member Function Documentation

virtual void wxTextCompleterSimple::GetCompletions ( const wxString prefix,
wxArrayString res 
)
pure virtual

Pure virtual method returning all possible completions for the given prefix.

The custom completer should examine the provided prefix and return all the possible completions for it in the output array res.

Please notice that the returned values should start with the prefix, otherwise they will be simply ignored, making adding them to the array in the first place useless.

Notice that this function may be called from thread other than main one (this is currently always the case under MSW) so the appropriate synchronization mechanism should be used to protect the shared data.

Parameters
prefixThe possibly empty prefix that the user had already entered.
resInitially empty array that should be filled with all possible completions (possibly none if there are no valid possibilities starting with the given prefix).