]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxTextEntry::AutoComplete() and implemented it for wxGTK
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 4 Nov 2007 22:39:54 +0000 (22:39 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 4 Nov 2007 22:39:54 +0000 (22:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49633 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/text.tex
include/wx/gtk/textentry.h
include/wx/textentry.h
src/gtk/textentry.cpp

index 45fcba561a8259bd516fd6c2354b236c1f9a5ba4..acacf85aa8ff2b5161376026cf303c2379614b7c 100644 (file)
@@ -185,6 +185,7 @@ All (Unix):
 
 All (GUI):
 
+- Added wxTextCtrl::AutoComplete()
 - Added wxH[V]ScrolledWindow (Brad Anderson, Bryan Petty).
 - Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron).
 - Added support for drop down toolbar buttons (Tim Kosse).
index ecdb62a0dbf6dfc23dfb36e6fdab7d9d7ae931c2..49dcf82973a5819463e72afde8f1af85b828441d 100644 (file)
@@ -328,6 +328,19 @@ the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoin
 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
 
 
+\membersection{wxTextCtrl::AutoComplete}\label{wxtextctrlautocomplete}
+
+\func{bool}{AutoComplete}{\param{const wxArrayString\& }{choices}}
+
+Call this function to enable auto-completion of the text typed in a single-line
+text control using the given \arg{choices}.
+
+Notice that currently this function is only implemented in wxGTK2 port and does
+nothing under the other platforms.
+
+\newsince{2.9.0}
+
+
 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
 
 \func{virtual bool}{CanCopy}{\void}
index 51cd3bd918ac10243d9bc13bca1ff80e5784d016..ec565facee242c1f293fc7429459ebd4960bb51e 100644 (file)
@@ -43,15 +43,13 @@ public:
     virtual void SetSelection(long from, long to);
     virtual void GetSelection(long *from, long *to) const;
 
-    // status
+    virtual void AutoComplete(const wxArrayString& choices);
+
     virtual bool IsEditable() const;
     virtual void SetEditable(bool editable);
 
-    // set the max number of characters which may be entered in a single line
-    // text control
     virtual void SetMaxLength(unsigned long len);
 
-
     // implementation only from now on
     void SendMaxLenEvent();
 
index d8482d42f066db3c6f981406b3ca4f7c90a48984..4ac40164d9ee4ee2e20195e3c96851f245e1eaee 100644 (file)
@@ -94,9 +94,16 @@ public:
     bool HasSelection() const;
     virtual wxString GetStringSelection() const;
 
+    
+    // auto-completion
+    // ---------------
+
+    virtual void AutoComplete(const wxArrayString& WXUNUSED(choices)) { }
+
 
     // status
     // ------
+
     virtual bool IsEditable() const = 0;
     virtual void SetEditable(bool editable) = 0;
 
index 18ca8fafc4380acf97f3a64319698c3faa24780e..c5a2fe89f5b25c4916fbfa13b2f63a6b740a0c7f 100644 (file)
@@ -217,6 +217,35 @@ void wxTextEntry::GetSelection(long *from, long *to) const
         *to = end;
 }
 
+// ----------------------------------------------------------------------------
+// auto completion
+// ----------------------------------------------------------------------------
+
+void wxTextEntry::AutoComplete(const wxArrayString& choices)
+{
+    GtkEntry * const entry = GTK_ENTRY(GetEditable());
+    wxCHECK_RET( entry, "auto completion doesn't work with this control" );
+
+    GtkListStore * const store = gtk_list_store_new(1, G_TYPE_STRING);
+    GtkTreeIter iter;
+
+    for ( wxArrayString::const_iterator i = choices.begin();
+          i != choices.end();
+          ++i )
+    {
+        gtk_list_store_append(store, &iter);
+        gtk_list_store_set(store, &iter,
+                           0, (const gchar *)i->utf8_str(),
+                           -1);
+    }
+
+    GtkEntryCompletion * const completion = gtk_entry_completion_new();
+    gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store));
+    gtk_entry_completion_set_text_column(completion, 0);
+    gtk_entry_set_completion(entry, completion);
+    g_object_unref(completion);
+}
+
 // ----------------------------------------------------------------------------
 // editable status
 // ----------------------------------------------------------------------------