Please help with GtkFlowBox

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everybody,

This is my first post to this list so I'm sorry for any mistake I could make.
I like how GtkFlowBox arranges the items inside and I'd like to use it
as a container for a set of GtkButtons. The placement of the buttons is
fine but I don't like the way that the keyboard focus moves when I press
Tab or Shift+Tab: first the GtkFlowBoxChild receives focus, then GtkButton.
I would like GtkButton only to receive focus like in GtkGrid or GtkBox. Please
see the attachment for my effort so far. There are some comments explaining what
I tried and why it did not work. Am I using GtkFlowBox incorrectly? Is
GtkFlowBox
not suitable for this application? Is it a bug or a missing feature in
GtkFlowBox?

If you wonder why I need this solution, it is for this bug:
https://bugzilla.gnome.org/show_bug.cgi?id=735994

Best regards,

Rafal
/*
 * 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;
}

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux