int clip_GTK_ENTRYCOMPLETIONINSERTACTIONTEXT(ClipMachine * ClipMachineMemory) { C_object *ccompletion = _fetch_co_arg(ClipMachineMemory); gint index = _clip_parni(ClipMachineMemory, 2); gchar *text = _clip_parc(ClipMachineMemory, 3); CHECKCOBJ(ccompletion, GTK_IS_ENTRY_COMPLETION(ccompletion->object)); CHECKARG(2, NUMERIC_type_of_ClipVarType); CHECKARG(3, CHARACTER_type_of_ClipVarType); index--; LOCALE_TO_UTF(text); gtk_entry_completion_insert_action_text(GTK_ENTRY_COMPLETION(ccompletion->object), index, text); FREE_TEXT(text); return 0; err: return 1; }
int main (int argc, char *argv[]) { GtkWidget *vbox; GtkWidget *label; GtkWidget *entry; GtkEntryCompletion *completion; GtkTreeModel *completion_model; GtkCellRenderer *cell; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); g_signal_connect (window, "delete_event", gtk_main_quit, NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example."); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); /* Create our first entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); gtk_entry_completion_set_inline_completion (completion, TRUE); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = create_simple_completion_model (); gtk_entry_completion_set_model (completion, completion_model); g_object_unref (completion_model); /* Use model column 0 as the text column */ gtk_entry_completion_set_text_column (completion, 0); /* Create our second entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = create_completion_model (); gtk_entry_completion_set_model (completion, completion_model); gtk_entry_completion_set_minimum_key_length (completion, 2); g_object_unref (completion_model); /* Use model column 1 as the text column */ cell = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell, "pixbuf", 0, NULL); cell = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell, "text", 1, NULL); gtk_entry_completion_set_match_func (completion, match_func, NULL, NULL); g_signal_connect (completion, "match-selected", G_CALLBACK (match_selected_cb), NULL); gtk_entry_completion_insert_action_text (completion, 100, "action!"); gtk_entry_completion_insert_action_text (completion, 101, "'nother action!"); g_signal_connect (completion, "action_activated", G_CALLBACK (activated_cb), NULL); /* Create our third entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); gtk_entry_completion_set_model (completion, completion_model); g_object_unref (completion_model); /* Use model column 0 as the text column */ gtk_entry_completion_set_text_column (completion, 0); /* Fill the completion dynamically */ gdk_threads_add_timeout (1000, (GSourceFunc) animation_timer, completion); /* Fourth entry */ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Model-less entry completion"), FALSE, FALSE, 0); entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); gtk_widget_show_all (window); gtk_main (); return 0; }
static VALUE rg_insert_action_text(VALUE self, VALUE index, VALUE text) { gtk_entry_completion_insert_action_text(_SELF(self), NUM2INT(index), RVAL2CSTR(text)); return self; }