#include <gtk/gtk.h>

/* Minimal test case for GTK bug 710909,
   http://bugzilla.gnome.org/show_bug.cgi?id=710909

   When built against GTK 2 the buttons are drawn correctly.

   When built against GTK 3 the bottom of the Cancel and
   OK buttons is cut off. If the -w option is given to 
   this program the workaround below is activated: this
   prevents the cutoff but the vertical size of the buttons
   differs, which does not look great.

   Allin Cottrell <cottrell@wfu.edu>, 2014-03-04
*/

GtkWidget *add_help_button (GtkWidget *hbox, int workaround)
{
    GtkWidget *button;

    button = gtk_button_new_from_stock(GTK_STOCK_HELP);
    gtk_container_add(GTK_CONTAINER(hbox), button);
    gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(hbox),
				       button, TRUE);

#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 2
    if (workaround) {
	gtk_button_box_set_child_non_homogeneous(GTK_BUTTON_BOX(hbox),
						 button, TRUE);
    }
#endif
    
    return button;
}

int test_dialog (int show_help, int workaround)
{
    GtkWidget *dialog, *vbox, *hbox;
    GtkWidget *label;

    dialog = 
	gtk_dialog_new_with_buttons("Test",
				    NULL,
				    0,
				    GTK_STOCK_CANCEL,
				    GTK_RESPONSE_REJECT,
				    GTK_STOCK_OK,
				    GTK_RESPONSE_ACCEPT,
				    NULL);

    label = gtk_label_new("Some stuff should go here");
    vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
    gtk_container_add(GTK_CONTAINER(vbox), label);

    if (show_help) {
	hbox = gtk_dialog_get_action_area(GTK_DIALOG(dialog));
	add_help_button(hbox, workaround);
    }

    gtk_widget_show_all(dialog);
    
    return gtk_dialog_run(GTK_DIALOG(dialog));
}

static gboolean no_help_button = FALSE;
static gboolean workaround = FALSE;

static GOptionEntry options[] = {
    { "no-help", 'n', 0, G_OPTION_ARG_NONE, &no_help_button, 
      "Don't show a Help button", NULL },
    { "workaround", 'w', 0, G_OPTION_ARG_NONE, &workaround, 
      "Add a GTK 3 workaround", NULL },
    { NULL },
};

int main (int argc, char **argv)
{
    GError *err = NULL;

    gtk_init_with_args(&argc, &argv, NULL, options, NULL, &err);
    test_dialog(!no_help_button, workaround);

    return 0;
}
