/*
Test code for a GTK+ crash with the MS-Windows theme. Conditions that cause the
crash are: a GtkNotebook with tab position set to GTK_POS_LEFT or GTK_POS_RIGHT,
packed in a GtkFrame or GtkExpander, which is packed in a VBox with at least
one other widget. It does not happen with the default GTK+ theme.

Run the program, then decrease the size of the Window. It crashes with

(gtk-crash.exe:2184): Gdk-WARNING **: gdkpixmap-win32.c:302: CreateDIBSection failed: Not enough storage is available to process this command.

(gtk-crash.exe:2184): Gdk-WARNING **: gdkpixmap-win32.c:114: DeleteObject failed: The system could not find the environment option that was entered.
**
Gdk:ERROR:gdkgc-win32.c:748:get_impl_drawable: code should not be reached

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
*/

/*
The widget containment hierarchy is
GtkWindow
	GtkVBox
		GtkLabel (dummy widget, others may work)
		GtkFrame or GtkExpander
			GtkNotebook with tabs on the left or right
*/

#include <stdio.h>
#include <gtk/gtk.h>

static void destroy(GtkWidget *widget, gpointer data)
{
	gtk_main_quit();
}

int main(int argc, char *argv[])
{
	GtkWidget *window;
	GtkWidget *box;
	GtkWidget *container;
	GtkWidget *notebook;
	GtkWidget *label;
	GtkWidget *dummy;

	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
	g_signal_connect(G_OBJECT(window), "destroy",
		G_CALLBACK(destroy), NULL);

	box = gtk_vbox_new(FALSE, 0);

	container = gtk_frame_new("Frame");
	/* Using a GtkExpander as the container also causes the crash. */
	/*
	container = gtk_expander_new("Expander");
	gtk_expander_set_expanded(GTK_EXPANDER(container), TRUE);
	*/

	dummy = gtk_label_new("Dummy");
	/* If dummy is packed with TRUE, TRUE, the program fails immediately
	   with
(gtk-crash.exe:3108): Gdk-CRITICAL **: gdk_pixmap_new: assertion `(width != 0) && (height != 0)' failed
**
Gdk:ERROR:gdkgc-win32.c:748:get_impl_drawable: code should not be reached
	*/
	gtk_box_pack_start(GTK_BOX(box), dummy, FALSE, FALSE, 0);

	notebook = gtk_notebook_new();
	/* GTK_POS_RIGHT also causes the crash. */
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_LEFT);

	/* The notebook has to have at least one page for the crash to occur. */
	label = gtk_label_new("Label 1");
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
		GTK_WIDGET(label), NULL);

	gtk_container_add(GTK_CONTAINER(container), notebook);

	gtk_box_pack_start(GTK_BOX(box), container, TRUE, TRUE, 0);

	gtk_container_add(GTK_CONTAINER(window), box);

	gtk_widget_show_all(window);

	gtk_main();

	return 0;
}
