#include <gtk/gtk.h>

static void run_dialog( GtkWindow *parent, const char *title, GtkDialogFlags flags)
{
   GtkWidget *dialog  = gtk_dialog_new_with_buttons (
	 title,
     parent,
     flags,
	 "OK", GTK_RESPONSE_OK, 
     "Cancel", GTK_RESPONSE_CANCEL,
	 NULL);
     
   gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
   gtk_window_set_position (GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);

 g_signal_connect_swapped (dialog,
                           "response",
                           G_CALLBACK (gtk_widget_destroy),
                           dialog);
                           
   gtk_dialog_run(GTK_DIALOG(dialog));
}

static void dlg_without_hb( GtkWidget *widget, GtkWindow *parent )
{
    run_dialog(parent, "without", (GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT));
}

static void dlg_with_hb( GtkWidget *widget, GtkWindow *parent )
{
    run_dialog(parent, "with", (GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_USE_HEADER_BAR));
}


static void
activate (GApplication *app,
          gpointer      user_data)
{
  GtkWidget *widget;
  GtkWidget *button1;
  GtkWidget *button2;
  GtkWidget *box;

  widget = gtk_application_window_new (GTK_APPLICATION (app));

  button1 = gtk_button_new_with_label ("without GTK_DIALOG_USE_HEADER_BAR");
  button2 = gtk_button_new_with_label ("with GTK_DIALOG_USE_HEADER_BAR");
    
  g_signal_connect (button1, "clicked", G_CALLBACK (dlg_without_hb), widget);
  g_signal_connect (button2, "clicked", G_CALLBACK (dlg_with_hb), widget);

  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
             
  gtk_container_add (GTK_CONTAINER (box), button1);
  gtk_container_add (GTK_CONTAINER (box), button2);
  gtk_container_add (GTK_CONTAINER (widget), box);
  gtk_widget_show_all (widget);
}

int
main (int argc, char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gnome.reproducer_764730", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

