#include <gtk/gtk.h>

void on_click(GtkWidget* button, GtkWidget** dialog_ptr)
{
	if(!*dialog_ptr)
	{
		*dialog_ptr = gtk_window_new(GTK_WINDOW_TOPLEVEL);

		gtk_window_set_resizable(GTK_WINDOW(*dialog_ptr), FALSE);

		GtkWidget* entry = gtk_entry_new();
		gtk_container_add(GTK_CONTAINER(*dialog_ptr), entry);

		gtk_window_present(GTK_WINDOW(*dialog_ptr));
	}
	else
	{
		if(GTK_WIDGET_VISIBLE(*dialog_ptr))
		{
			gtk_widget_hide(*dialog_ptr);
		}
		else
		{
			gtk_widget_show(gtk_container_get_children(GTK_CONTAINER(*dialog_ptr))->data);
			gtk_window_present(GTK_WINDOW(*dialog_ptr));
		}
	}

}


int main(int argc, char* argv[])
{
	gtk_init(&argc, &argv);

	GtkWidget* window;
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	GtkWidget* button;
	button = gtk_button_new_from_stock(GTK_STOCK_QUIT);

	gtk_container_add(GTK_CONTAINER(window), button);
	gtk_widget_show(button);

	GtkWidget* dialog = NULL;
	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_click), &dialog);
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	gtk_window_set_default_size(GTK_WINDOW(window), 100, 100);
	gtk_widget_show(window);
	gtk_main();

	//if(dialog) gtk_widget_destroy(dialog);
}
