#include <gtk/gtk.h>

#define N_BUTTONS 3

static const char* styles[] = { "GTK_BUTTONBOX_DEFAULT_STYLE",
				"GTK_BUTTONBOX_SPREAD",
				"GTK_BUTTONBOX_EDGE",
				"GTK_BUTTONBOX_START",
				"GTK_BUTTONBOX_END",
				"GTK_BUTTONBOX_CENTER"};

static void
populate_combo (GtkComboBox *combo)
{
  int i;

  for (i = 0; i < G_N_ELEMENTS (styles); i++) {
    gtk_combo_box_append_text (combo, styles[i]);
  }
}

static void
combo_changed_cb (GtkComboBox *combo,
		  GtkButtonBox *bbox)
{
  char *text;
  int i;

  text = gtk_combo_box_get_active_text (combo);

  for (i = 0; i < G_N_ELEMENTS (styles); i++) {
    if (g_str_equal (text, styles[i])) {
      gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), (GtkButtonBoxStyle)i);
    }
  }
}

GtkWidget *bbox = NULL;

static void
option_cb (GtkToggleButton *option,
	   GtkWidget *button)
{
  gboolean active = gtk_toggle_button_get_active (option);

  gtk_button_box_set_child_secondary (bbox, button, active);
}

static const char* strings[] = { "Ok", "Cancel", "Help" };

int main (int argc, char **argv)
{
  GtkWidget *window, *buttons[N_BUTTONS];
  GtkWidget *vbox, *hbox, *combo, *option;
  int i;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  bbox = gtk_hbutton_box_new ();

  gtk_box_pack_start (GTK_BOX (vbox), bbox, TRUE, TRUE, 5);

  for (i = 0; i < N_BUTTONS; i++) {
    buttons[i] = gtk_button_new_with_label (strings[i]);
    gtk_container_add (GTK_CONTAINER (bbox), buttons[i]);
  }

  hbox = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

  combo = gtk_combo_box_new_text ();
  populate_combo (GTK_COMBO_BOX (combo));
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);

  g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (combo_changed_cb), bbox);

  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);

  option = gtk_check_button_new_with_label ("Help is secondary");
  g_signal_connect (G_OBJECT (option), "toggled", G_CALLBACK (option_cb), buttons[N_BUTTONS - 1]);

  gtk_box_pack_start (GTK_BOX (hbox), option, FALSE, FALSE, 0);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}
