<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:9pt;font-family:Helvetica">
<p>main purpose of the code below is  when putting some characters such as to ,oa,and so on, the list of completion will show all strings  that contains the characters ,but when I tip Tab  key on the keyboard , it moves through all the match items in the list ,But what signal should I  connect to show current string on the entry when  tipping Tab continuous in the matching list ?</p>
<p>/* Entry Completion</p>
<p>gcc entry_completion.c `pkg-config gtk+-2.0 --cflags --libs`</p>
<p>*/</p>
<p></p>
<p>#include &lt;gtk/gtk.h&gt;</p>
<p>#include &lt;gdk/gdkkeysyms.h&gt;</p>
<p>gboolean match_selected_cb(GtkEntryCompletion *completion,</p>
<p>                        GtkTreeModel * model , GtkTreeIter * iter,void * data)</p>
<p></p>
<p>{</p>
<p>        char * select = 0;</p>
<p>        gtk_tree_model_get(model,iter,0,&amp;select,-1);</p>
<p>        gtk_entry_set_text(data,select);</p>
<p>}</p>
<p></p>
<p></p>
<p>gboolean  action_cb(GtkEntryCompletion* completion, int index,void * data)</p>
<p>{</p>
<p>        printf(&quot;SSSS %d\n&quot;,index);</p>
<p>        return TRUE;</p>
<p>}</p>
<p>gboolean match_rule(GtkEntryCompletion* completion , const char * key,GtkTreeIter * iter  , void * usr_data)</p>
<p>{</p>
<p>        GtkTreeModel *model;</p>
<p></p>
<p>        model = gtk_entry_completion_get_model (completion);</p>
<p>        char * context = NULL ;</p>
<p>        gtk_tree_model_get(model,iter,0,&amp;context,-1);</p>
<p>        if(strstr(context,key)) return TRUE;</p>
<p>        else return FALSE;</p>
<p>}</p>
<p></p>
<p></p>
<p>static GtkWidget *window = NULL;</p>
<p>GdkEvent* synthesize_gdk_event(GdkEventType evtType, GtkWidget *widget, guint keyVal)</p>
<p>{</p>
<p>        GdkEvent *evt = NULL;</p>
<p>        GdkKeymapKey *keys;</p>
<p>        gint n_keys;</p>
<p>        GtkWidget *temp_widget;</p>
<p>        guint16 hardware_keycode;</p>
<p></p>
<p>        if (gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (),</p>
<p>                                keyVal, &amp;keys, &amp;n_keys))</p>
<p>        {</p>
<p>                temp_widget = GTK_WIDGET(widget);</p>
<p>                hardware_keycode = keys[0].keycode;</p>
<p></p>
<p>                g_free (keys);</p>
<p>                evt = gdk_event_new (evtType);</p>
<p>                evt-&gt;key.window = g_object_ref(temp_widget-&gt;window);</p>
<p>                evt-&gt;key.hardware_keycode = hardware_keycode;</p>
<p></p>
<p>                /* these are optional but possibly nice to have */</p>
<p>                //toevt-&gt;key.keyval = gdk_unicode_to_keyval (keyVal);</p>
<p>                evt-&gt;key.keyval = keyVal;</p>
<p></p>
<p>                /* the rest are no-ops */</p>
<p>                evt-&gt;key.send_event = FALSE;   /* seems unused except for dnd */</p>
<p>                evt-&gt;key.time = GDK_CURRENT_TIME;</p>
<p>        }</p>
<p></p>
<p>        return evt;</p>
<p>}</p>
<p></p>
<p>tab_cb(GtkWidget *window, GdkEventKey *ev,gpointer data)</p>
<p>{</p>
<p>        if(ev-&gt;keyval == GDK_Tab)</p>
<p>        {</p>
<p>                GdkEvent * fake = synthesize_gdk_event(GDK_KEY_PRESS, GTK_WIDGET(data), GDK_Down);</p>
<p>        //      GdkEvent * fake1 = synthesize_gdk_event(GDK_KEY_PRESS, GTK_WIDGET(window), GDK_Return);</p>
<p>                gtk_main_do_event(fake);</p>
<p>        //      gtk_main_do_event(fake1);</p>
<p>                return 1;</p>
<p>        }</p>
<p></p>
<p></p>
<p>        return 0;</p>
<p></p>
<p>}</p>
<p>/* Creates a tree model containing the completions */</p>
<p>GtkTreeModel *</p>
<p>create_completion_model (void)</p>
<p>{</p>
<p>        GtkListStore *store;</p>
<p>        GtkTreeIter iter;</p>
<p></p>
<p>        store = gtk_list_store_new (1, G_TYPE_STRING);</p>
<p></p>
<p>        /* Append one word */</p>
<p>        gtk_list_store_append (store, &amp;iter);</p>
<p>        gtk_list_store_set (store, &amp;iter, 0, &quot;GNOME&quot;, -1);</p>
<p></p>
<p>        /* Append another word */</p>
<p>        gtk_list_store_append (store, &amp;iter);</p>
<p>        gtk_list_store_set (store, &amp;iter, 0, &quot;total&quot;, -1);</p>
<p></p>
<p>        /* And another word */</p>
<p>        gtk_list_store_append (store, &amp;iter);</p>
<p>        gtk_list_store_set (store, &amp;iter, 0, &quot;totally&quot;, -1);</p>
<p></p>
<p>        gtk_list_store_append (store, &amp;iter);</p>
<p>        gtk_list_store_set (store, &amp;iter, 0, &quot;totallly&quot;, -1);</p>
<p></p>
<p>        gtk_list_store_append (store, &amp;iter);</p>
<p>        gtk_list_store_set (store, &amp;iter, 0, &quot;totalllly&quot;, -1);</p>
<p></p>
<p>        return GTK_TREE_MODEL (store);</p>
<p>}</p>
<p></p>
<p></p>
<p>GtkWidget *</p>
<p>do_entry_completion (GtkWidget *do_widget)</p>
<p>{</p>
<p>        GtkWidget *vbox;</p>
<p>        GtkWidget *label;</p>
<p>        GtkWidget *entry;</p>
<p>        GtkEntryCompletion *completion;</p>
<p>        GtkTreeModel *completion_model;</p>
<p></p>
<p>        if (!window)</p>
<p>        {</p>
<p>                window = gtk_dialog_new_with_buttons (&quot;GtkEntryCompletion&quot;,</p>
<p>                                GTK_WINDOW (do_widget),</p>
<p>                                0,</p>
<p>                                GTK_STOCK_CLOSE,</p>
<p>                                GTK_RESPONSE_NONE,</p>
<p>                                NULL);</p>
<p>                gtk_window_set_resizable (GTK_WINDOW (window), FALSE);</p>
<p></p>
<p>                g_signal_connect (window, &quot;response&quot;,</p>
<p>                                G_CALLBACK (gtk_widget_destroy), NULL);</p>
<p>                g_signal_connect (window, &quot;destroy&quot;,</p>
<p>                                G_CALLBACK (gtk_widget_destroyed), &amp;window);</p>
<p></p>
<p>                vbox = gtk_vbox_new (FALSE, 5);</p>
<p>                gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)-&gt;vbox), vbox, TRUE, TRUE, 0);</p>
<p>                gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);</p>
<p></p>
<p>                label = gtk_label_new (NULL);</p>
<p>                gtk_label_set_markup (GTK_LABEL (label), &quot;Completion demo, try writing &lt;b&gt;total&lt;/b&gt; or &lt;b&gt;gnome&lt;/b&gt; for example.&quot;);</p>
<p>                gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);</p>
<p></p>
<p>                /* Create our entry */</p>
<p>                entry = gtk_entry_new ();</p>
<p>                g_signal_connect(entry,&quot;key_press_event&quot;,tab_cb,entry);</p>
<p>                gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);</p>
<p></p>
<p>                /* Create the completion object */</p>
<p>                completion = gtk_entry_completion_new ();</p>
<p></p>
<p>                /* Assign the completion to the entry */</p>
<p>                gtk_entry_set_completion (GTK_ENTRY (entry), completion);</p>
<p>                g_object_unref (completion);</p>
<p></p>
<p>                /* Create a tree model and use it as the completion model */</p>
<p>                completion_model = create_completion_model ();</p>
<p>                gtk_entry_completion_set_model (completion, completion_model);</p>
<p>                g_object_unref (completion_model);</p>
<p>                gtk_entry_completion_set_match_func(completion,match_rule,NULL,NULL);</p>
<p>                g_signal_connect (completion, &quot;match_selected&quot;,          G_CALLBACK (match_selected_cb),entry);</p>
<p>        //      g_signal_connect (completion, &quot;action_activated&quot; ,       G_CALLBACK (action_cb),entry);</p>
<p>                /* Use model column 0 as the text column */</p>
<p>                gtk_entry_completion_set_text_column (completion, 0);</p>
<p>        }</p>
<p></p>
<p>        if (!GTK_WIDGET_VISIBLE (window))</p>
<p>                gtk_widget_show_all (window);</p>
<p>        else</p>
<p>                gtk_widget_destroy (window);</p>
<p></p>
<p>        return window;</p>
<p>}</p>
<p></p>
<p>main(int argc,char ** argv)</p>
<p>{</p>
<p>        gtk_init(&amp;argc,&amp;argv);</p>
<p>        GtkWidget * gg =do_entry_completion(NULL);</p>
<p>        gtk_widget_show_all(gg);</p>
<p>        gtk_main();</p>
<p>        return 0;</p>
<p>}</p>
<p></p>
</body></html>