2013-10-09 15:47:30 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static gboolean
|
2018-02-08 00:54:11 +00:00
|
|
|
window_key_pressed (GtkEventController *controller,
|
|
|
|
guint keyval,
|
|
|
|
guint keycode,
|
|
|
|
GdkModifierType state,
|
|
|
|
GtkSearchBar *search_bar)
|
2013-10-09 15:47:30 +00:00
|
|
|
{
|
2018-02-08 00:54:11 +00:00
|
|
|
return gtk_search_bar_handle_event (search_bar,
|
|
|
|
gtk_get_current_event ());
|
2013-10-09 15:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activate_cb (GtkApplication *app,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *search_bar;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *menu_button;
|
2018-02-08 00:54:11 +00:00
|
|
|
GtkEventController *controller;
|
2013-10-09 15:47:30 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
entry = gtk_search_entry_new ();
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (entry, TRUE);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), entry);
|
2013-10-09 15:47:30 +00:00
|
|
|
|
|
|
|
menu_button = gtk_menu_button_new ();
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), menu_button);
|
2013-10-09 15:47:30 +00:00
|
|
|
|
|
|
|
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (search_bar), GTK_ENTRY (entry));
|
|
|
|
|
2018-02-08 00:54:11 +00:00
|
|
|
controller = gtk_event_controller_key_new (window);
|
|
|
|
g_object_set_data_full (G_OBJECT (window), "controller", controller, g_object_unref);
|
|
|
|
g_signal_connect (controller, "key-pressed",
|
|
|
|
G_CALLBACK (window_key_pressed), search_bar);
|
2013-10-09 15:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|