/*
https://bugzilla.gnome.org/show_bug.cgi?id=715163

gcc -o testcase_border_width testcase_border_width.c `pkg-config --cflags --libs gtk+-3.0`

*/
#include <gtk/gtk.h>


void print_toolbar_border(GtkWidget *widget, const char *message)
{
	GtkStyleContext *context;
	GtkBorder border;

	context = gtk_widget_get_style_context (widget);
	gtk_style_context_get_border (context,
				      gtk_style_context_get_state (context),
				      &border);
	g_print("%-15s get_border: %d %d %d %d\n", message,
						   border.left,
						   border.top,
						   border.right,
						   border.bottom);
}


void print_allocated_size(GtkWidget *widget, const char *message)
{
	GtkAllocation allocation;
	gtk_widget_get_allocation (widget, &allocation);
	g_print("%-15s get_allocation: %d %d %d %d\n", message,
						       allocation.x,
						       allocation.y,
						       allocation.width,
						       allocation.height);
}

void window_size_allocate_cb(GtkWidget *widget, GdkRectangle *rectangle, gpointer user)
{
	print_allocated_size (widget, "WINDOW size-allocate");
}

int main(int argc, char **argv)
{
	GtkWidget *window;
	GtkWidget *vbox;
	GtkWidget *toolbar;
	GtkToolItem *toolitem;
	GtkWidget *frame;
	GtkWidget *button;
	GtkAllocation allocation;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "testcase border-width");
	g_signal_connect (window, "destroy", gtk_main_quit, NULL);

	vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
	gtk_container_add (GTK_CONTAINER (window), vbox);
	gtk_widget_show (vbox);

	toolbar = gtk_toolbar_new();
	gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
	gtk_widget_show (toolbar);

	toolitem = gtk_tool_button_new(NULL, "ToolButton");
	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, 0);
	gtk_widget_show(GTK_WIDGET (toolitem));

	frame = gtk_frame_new ("Frame");
	gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
	gtk_widget_show(frame);

	button = gtk_button_new_with_label("Button");
	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
	gtk_widget_show(button);
	


	gtk_window_set_default_size(GTK_WINDOW (window), 400, -1);
	gtk_widget_realize (window);
	print_toolbar_border(toolbar, "AFTER REALIZE");
	print_allocated_size(window, "AFTER REALIZE");

	gtk_widget_show (window);
	print_toolbar_border(toolbar, "AFTER SHOW");
	print_allocated_size(window, "AFTER SHOW");

	g_signal_connect (window, "size-allocate", G_CALLBACK (window_size_allocate_cb), NULL);
	g_print("GTK_MAIN\n");
	gtk_main ();
	return 0;
}
