]> Pileus Git - ~andy/gtk/blobdiff - tests/testentrycompletion.c
Replace a lot of idle and timeout calls by the new gdk_threads api.
[~andy/gtk] / tests / testentrycompletion.c
index 18dbb32df572fcd175d68e9c7e3b88cddf11cae2..483010b1f966ba3292797d14c87b9ab138c5efeb 100644 (file)
@@ -1,9 +1,30 @@
+/* testentrycompletion.c
+ * Copyright (C) 2004  Red Hat, Inc.
+ * Author: Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
 
 #include <config.h>
 #include <stdlib.h>
 #include <string.h>
 #include <gtk/gtk.h>
 
+#include "prop-editor.h"
+
 /* Don't copy this bad example; inline RGB data is always a better
  * idea than inline XPMs.
  */
@@ -92,6 +113,12 @@ create_simple_completion_model (void)
   gtk_list_store_set (store, &iter, 0, "Totipalmi", -1);
   gtk_list_store_append (store, &iter);
   gtk_list_store_set (store, &iter, 0, "zombie", -1);
+  gtk_list_store_append (store, &iter);
+  gtk_list_store_set (store, &iter, 0, "a\303\246x", -1);
+  gtk_list_store_append (store, &iter);
+  gtk_list_store_set (store, &iter, 0, "a\303\246y", -1);
+  gtk_list_store_append (store, &iter);
+  gtk_list_store_set (store, &iter, 0, "a\303\246z", -1);
  
   return GTK_TREE_MODEL (store);
 }
@@ -263,6 +290,27 @@ match_selected_cb (GtkEntryCompletion *completion,
   return TRUE;
 }
 
+static void
+new_prop_editor (GObject *object)
+{
+       gtk_widget_show (create_prop_editor (object, G_OBJECT_TYPE (object)));
+}
+
+static void
+add_with_prop_edit_button (GtkWidget *vbox, GtkWidget *entry, GtkEntryCompletion *completion)
+{
+       GtkWidget *hbox, *button;
+
+       hbox = gtk_hbox_new (FALSE, 12);
+       gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+       gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+
+       button = gtk_button_new_with_label ("Properties");
+       g_signal_connect_swapped (button, "clicked", G_CALLBACK (new_prop_editor), completion);
+       gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+}
+
 int 
 main (int argc, char *argv[])
 {
@@ -291,15 +339,17 @@ main (int argc, char *argv[])
 
   /* Create our first entry */
   entry = gtk_entry_new ();
-  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
   
   /* 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);
@@ -310,7 +360,6 @@ main (int argc, char *argv[])
 
   /* Create our second entry */
   entry = gtk_entry_new ();
-  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
 
   /* Create the completion object */
   completion = gtk_entry_completion_new ();
@@ -319,6 +368,8 @@ main (int argc, char *argv[])
   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);
@@ -346,7 +397,6 @@ main (int argc, char *argv[])
 
   /* Create our third entry */
   entry = gtk_entry_new ();
-  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
 
   /* Create the completion object */
   completion = gtk_entry_completion_new ();
@@ -355,6 +405,8 @@ main (int argc, char *argv[])
   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));
 
@@ -365,13 +417,12 @@ main (int argc, char *argv[])
   gtk_entry_completion_set_text_column (completion, 0);
 
   /* Fill the completion dynamically */
-  g_timeout_add (1000, (GSourceFunc) animation_timer, completion);
+  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 ();
-  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
 
   /* Create the completion object */
   completion = gtk_entry_completion_new ();
@@ -380,6 +431,8 @@ main (int argc, char *argv[])
   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 ();