summaryrefslogtreecommitdiff
path: root/src/gui/widgets/textfield.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/textfield.h')
-rw-r--r--src/gui/widgets/textfield.h68
1 files changed, 63 insertions, 5 deletions
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index 1e6df9d6..6e50f1e9 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -24,9 +24,48 @@
#include <guichan/widgets/textfield.hpp>
+#include <vector>
+
class ImageRect;
class TextField;
+typedef std::list<std::string> TextHistoryList;
+typedef TextHistoryList::iterator TextHistoryIterator;
+
+struct TextHistory {
+ TextHistoryList history; /**< Command history. */
+ TextHistoryIterator current; /**< History iterator. */
+
+ TextHistory()
+ { current = history.end(); }
+
+ bool empty() const
+ { return history.empty(); }
+
+ bool atBegining() const
+ { return current == history.begin(); }
+
+ bool atEnd() const
+ { return current == history.end(); }
+
+ void toBegining()
+ { current = history.begin(); }
+
+ void toEnd()
+ { current = history.end(); }
+
+ void addEntry(const std::string &text)
+ { history.push_back(text); }
+
+ bool matchesEntry(const std::string &text)
+ { return (*current) == text; }
+};
+
+class AutoCompleteLister {
+public:
+ virtual void getAutoCompleteList(std::vector<std::string>&) const {}
+};
+
/**
* A text field.
*
@@ -91,16 +130,32 @@ class TextField : public gcn::TextField
int getValue() const;
/**
- * Set if the tabulator key causes auto complete
+ * Sets the TextField's source of autocomplete. Passing null will
+ * disable autocomplete.
+ */
+ void setAutoComplete(AutoCompleteLister *lister)
+ { mAutoComplete = lister; }
+
+ /**
+ * Returns the TextField's source of autocomplete.
*/
- void setAutoComplete(bool b ) {mAutoComplete = b;}
+ AutoCompleteLister *getAutoComplete() const
+ { return mAutoComplete; }
/**
- * Returns if the tabulator key causes auto complete
+ * Sets the TextField's source of input history.
*/
- bool getAutoComplete() {return mAutoComplete;}
+ void setHistory(TextHistory *history)
+ { mHistory = history; }
+
+ /**
+ * Returns the TextField's source of input history.
+ */
+ TextHistory *getHistory() const
+ { return mHistory; }
private:
+ void autoComplete();
void handlePaste();
static int instances;
@@ -110,7 +165,10 @@ class TextField : public gcn::TextField
int mMinimum;
int mMaximum;
bool mLoseFocusOnTab;
- bool mAutoComplete;
+
+ AutoCompleteLister *mAutoComplete;
+
+ TextHistory *mHistory; /**< Text history. */
};
#endif