static GtkWidget * create_complex_popover (GtkWidget *parent, GtkPositionType pos) { GtkWidget *popover, *window, *content; GtkBuilder *builder; builder = gtk_builder_new (); gtk_builder_add_from_resource (builder, "/popover/popover.ui", NULL); window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); content = gtk_bin_get_child (GTK_BIN (window)); g_object_ref (content); gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (content)), content); gtk_widget_destroy (window); g_object_unref (builder); popover = create_popover (parent, content, GTK_POS_BOTTOM); g_object_unref (content); gtk_widget_set_size_request (popover, 200, -1); gtk_widget_set_vexpand (popover, TRUE); gtk_widget_set_margin_start (popover, 10); gtk_widget_set_margin_end (popover, 10); gtk_widget_set_margin_bottom (popover, 10); return popover; }
static void day_selected_cb (GtkCalendar *calendar, gpointer user_data) { cairo_rectangle_int_t rect; GtkAllocation allocation; GtkWidget *popover; GdkEvent *event; event = gtk_get_current_event (); if (event->type != GDK_BUTTON_PRESS) return; gdk_window_coords_to_parent (event->button.window, event->button.x, event->button.y, &event->button.x, &event->button.y); gtk_widget_get_allocation (GTK_WIDGET (calendar), &allocation); rect.x = event->button.x - allocation.x; rect.y = event->button.y - allocation.y; rect.width = rect.height = 1; popover = create_popover (GTK_WIDGET (calendar), gtk_entry_new (), GTK_POS_BOTTOM); gtk_popover_set_pointing_to (GTK_POPOVER (popover), &rect); gtk_widget_show (popover); gdk_event_free (event); }
GtkWidget * do_popover (GtkWidget *do_widget) { static GtkWidget *window = NULL; GtkWidget *popover, *box, *widget; if (!window) { window = gtk_window_new (GTK_WINDOW_TOPLEVEL); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 24); gtk_container_set_border_width (GTK_CONTAINER (box), 24); gtk_container_add (GTK_CONTAINER (window), box); g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); widget = gtk_toggle_button_new_with_label ("Button"); popover = create_popover (widget, gtk_label_new ("This popover does not grab input"), GTK_POS_TOP); gtk_popover_set_modal (GTK_POPOVER (popover), FALSE); g_signal_connect (widget, "toggled", G_CALLBACK (toggle_changed_cb), popover); gtk_container_add (GTK_CONTAINER (box), widget); widget = gtk_entry_new (); popover = create_complex_popover (widget, GTK_POS_TOP); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY, "edit-find"); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY, "edit-clear"); g_signal_connect (widget, "icon-press", G_CALLBACK (entry_icon_press_cb), popover); g_signal_connect (widget, "size-allocate", G_CALLBACK (entry_size_allocate_cb), popover); gtk_container_add (GTK_CONTAINER (box), widget); widget = gtk_calendar_new (); g_signal_connect (widget, "day-selected", G_CALLBACK (day_selected_cb), NULL); gtk_container_add (GTK_CONTAINER (box), widget); } if (!gtk_widget_get_visible (window)) gtk_widget_show_all (window); else { gtk_widget_destroy (window); window = NULL; } return window; }
static void fsearch_application_window_init (FsearchApplicationWindow *self) { g_assert (FSEARCH_WINDOW_IS_WINDOW (self)); gtk_widget_init_template (GTK_WIDGET (self)); GtkCssProvider *provider = gtk_css_provider_new (); gtk_css_provider_load_from_resource (provider, "/org/fsearch/fsearch/shared.css"); gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref (provider); create_view_and_model (self); //self->selection_popover = create_popover (self->selection_toggle_button); //g_signal_connect (self->selection_popover, // "closed", // G_CALLBACK (set_toggle_button), // (gpointer)self->selection_toggle_button); self->database_popover = create_popover (self->database_toggle_button); fill_database_popover (self->database_popover); g_signal_connect (self->database_popover, "closed", G_CALLBACK (set_toggle_button), (gpointer)self->database_toggle_button); FsearchApplication *app = FSEARCH_APPLICATION_DEFAULT; g_signal_connect (app, "database-update", G_CALLBACK (update_database_cb), self); g_signal_connect (app, "database-updated", G_CALLBACK (updated_database_cb), self); g_signal_connect (gtk_icon_theme_get_default (), "changed", G_CALLBACK (icon_theme_changed_cb), self); GtkBuilder *builder = gtk_builder_new_from_resource ("/org/fsearch/fsearch/overlay.ui"); // Overlay when no search results are found self->no_search_results_overlay = GTK_WIDGET (gtk_builder_get_object (builder, "no_search_results")); gtk_overlay_add_overlay (GTK_OVERLAY (self->search_overlay), self->no_search_results_overlay); // Overlay when database is empty self->empty_database_overlay = GTK_WIDGET (gtk_builder_get_object (builder, "empty_database")); gtk_overlay_add_overlay (GTK_OVERLAY (self->search_overlay), self->empty_database_overlay); // Overlay when search query is empty self->empty_search_query_overlay = GTK_WIDGET (gtk_builder_get_object (builder, "empty_search_query")); gtk_overlay_add_overlay (GTK_OVERLAY (self->search_overlay), self->empty_search_query_overlay); // Overlay when database is updating self->database_updating_overlay = GTK_WIDGET (gtk_builder_get_object (builder, "database_updating")); gtk_overlay_add_overlay (GTK_OVERLAY (self->search_overlay), self->database_updating_overlay); self->database_updating_label = GTK_WIDGET (gtk_builder_get_object (builder, "database_updating_label")); g_object_unref (builder); }