/*
 * Simple test of GtkFlowBox. Build with the following command:
 *
 * gcc flowboxtest.c -o flowboxtest -g `pkg-config --cflags --libs gtk+-3.0`
 */

#include <gtk/gtk.h>

static void insert_widgets(GtkWidget *window) {
	GtkWidget *scrolled_window;
	GtkWidget *flow_box;
	GtkWidget *button;
	int i;
	char caption[16];

	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
		GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_widget_show (scrolled_window);
	gtk_container_add (GTK_CONTAINER (window), scrolled_window);

	flow_box = gtk_flow_box_new();
	gtk_flow_box_set_selection_mode (GTK_FLOW_BOX (flow_box),
		GTK_SELECTION_NONE);

	/* This does not change anything:
	gtk_widget_set_can_focus (flow_box, FALSE);
	*/

	gtk_widget_show (flow_box);
	gtk_container_add (GTK_CONTAINER (scrolled_window), flow_box);

	for (i = 1; i <= 24; i++) {
		sprintf(caption, "Button %d", i);
		button = gtk_button_new_with_label (caption);
		gtk_widget_show (button);
		gtk_container_add (GTK_CONTAINER (flow_box), button);
		/* This makes the buttons never receive the focus:
		gtk_widget_set_can_focus (gtk_widget_get_parent (button),
			FALSE);
		*/
		/* This helps but only for the first tab stop:
		gtk_container_set_focus_child (
			GTK_CONTAINER (gtk_widget_get_parent(button)), button);
		*/
	}
}

int main(int argc, char *argv[])
{
	GtkWidget *window;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (window, "delete-event",
			G_CALLBACK (gtk_false), NULL);
	g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_main_quit), NULL);

	insert_widgets (window);

	gtk_window_set_default_size (GTK_WINDOW (window), 400, 200);
	gtk_widget_show (window);

	gtk_main ();

	return 0;
}

