summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.co.uk>2013-10-09 11:47:30 -0400
committerXavier Claessens <xavier.claessens@collabora.co.uk>2013-10-10 14:48:12 -0400
commit8e9dd8c3aa3408ad50207eb5cbb16cf1daf3dc98 (patch)
tree65e52861e133518db3b228d565001bea3b21a0c1 /examples
parentf979c3d7a23b67539e895bd6e3ee798c9c6ea1e5 (diff)
downloadgtk+-8e9dd8c3aa3408ad50207eb5cbb16cf1daf3dc98.tar.gz
Add example app for GtkSearchBar
https://bugzilla.gnome.org/show_bug.cgi?id=709745
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am3
-rw-r--r--examples/search-bar.c58
2 files changed, 60 insertions, 1 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 88166b5933..14f145077c 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -26,7 +26,8 @@ noinst_PROGRAMS = \
action-namespace \
grid-packing \
drawing \
- builder
+ builder \
+ search-bar
EXTRA_DIST = builder.ui
diff --git a/examples/search-bar.c b/examples/search-bar.c
new file mode 100644
index 0000000000..16cacdbddb
--- /dev/null
+++ b/examples/search-bar.c
@@ -0,0 +1,58 @@
+#include <gtk/gtk.h>
+
+static gboolean
+window_key_press_event_cb (GtkWidget *window,
+ GdkEvent *event,
+ GtkSearchBar *search_bar)
+{
+ return gtk_search_bar_handle_event (search_bar, event);
+}
+
+static void
+activate_cb (GtkApplication *app,
+ gpointer user_data)
+{
+ GtkWidget *window;
+ GtkWidget *search_bar;
+ GtkWidget *box;
+ GtkWidget *entry;
+ GtkWidget *menu_button;
+
+ window = gtk_application_window_new (app);
+ gtk_widget_show (window);
+
+ search_bar = gtk_search_bar_new ();
+ gtk_container_add (GTK_CONTAINER (window), search_bar);
+ gtk_widget_show (search_bar);
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_container_add (GTK_CONTAINER (search_bar), box);
+ gtk_widget_show (box);
+
+ entry = gtk_search_entry_new ();
+ gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0);
+ gtk_widget_show (entry);
+
+ menu_button = gtk_menu_button_new ();
+ gtk_box_pack_start (GTK_BOX (box), menu_button, FALSE, FALSE, 0);
+ gtk_widget_show (menu_button);
+
+ gtk_search_bar_connect_entry (GTK_SEARCH_BAR (search_bar), GTK_ENTRY (entry));
+
+ g_signal_connect (window, "key-press-event",
+ G_CALLBACK (window_key_press_event_cb), search_bar);
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ GtkApplication *app;
+
+ app = gtk_application_new ("org.gtk.Example.GtkSearchBar",
+ G_APPLICATION_FLAGS_NONE);
+ g_signal_connect (app, "activate",
+ G_CALLBACK (activate_cb), NULL);
+
+ return g_application_run (G_APPLICATION (app), argc, argv);
+}