textcompleter.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/textcompleter.h
  3. // Purpose: Declaration of wxTextCompleter class.
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-04-13
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_TEXTCOMPLETER_H_
  10. #define _WX_TEXTCOMPLETER_H_
  11. // ----------------------------------------------------------------------------
  12. // wxTextCompleter: used by wxTextEnter::AutoComplete()
  13. // ----------------------------------------------------------------------------
  14. class WXDLLIMPEXP_CORE wxTextCompleter
  15. {
  16. public:
  17. wxTextCompleter() { }
  18. // The virtual functions to be implemented by the derived classes: the
  19. // first one is called to start preparing for completions for the given
  20. // prefix and, if it returns true, GetNext() is called until it returns an
  21. // empty string indicating that there are no more completions.
  22. virtual bool Start(const wxString& prefix) = 0;
  23. virtual wxString GetNext() = 0;
  24. virtual ~wxTextCompleter();
  25. private:
  26. wxDECLARE_NO_COPY_CLASS(wxTextCompleter);
  27. };
  28. // ----------------------------------------------------------------------------
  29. // wxTextCompleterSimple: returns the entire set of completions at once
  30. // ----------------------------------------------------------------------------
  31. class WXDLLIMPEXP_CORE wxTextCompleterSimple : public wxTextCompleter
  32. {
  33. public:
  34. wxTextCompleterSimple() { }
  35. // Must be implemented to return all the completions for the given prefix.
  36. virtual void GetCompletions(const wxString& prefix, wxArrayString& res) = 0;
  37. virtual bool Start(const wxString& prefix);
  38. virtual wxString GetNext();
  39. private:
  40. wxArrayString m_completions;
  41. unsigned m_index;
  42. wxDECLARE_NO_COPY_CLASS(wxTextCompleterSimple);
  43. };
  44. // ----------------------------------------------------------------------------
  45. // wxTextCompleterFixed: Trivial wxTextCompleter implementation which always
  46. // returns the same fixed array of completions.
  47. // ----------------------------------------------------------------------------
  48. // NB: This class is private and intentionally not documented as it is
  49. // currently used only for implementation of completion with the fixed list
  50. // of strings only by wxWidgets itself, do not use it outside of wxWidgets.
  51. class wxTextCompleterFixed : public wxTextCompleterSimple
  52. {
  53. public:
  54. void SetCompletions(const wxArrayString& strings)
  55. {
  56. m_strings = strings;
  57. }
  58. virtual void GetCompletions(const wxString& WXUNUSED(prefix),
  59. wxArrayString& res)
  60. {
  61. res = m_strings;
  62. }
  63. private:
  64. wxArrayString m_strings;
  65. };
  66. #endif // _WX_TEXTCOMPLETER_H_