testorientable.c 3.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* testorientable.c
 * Copyright (C) 2004  Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardon's avatar
Javier Jardon committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 */

#include <gtk/gtk.h>

static void
orient_toggled (GtkToggleButton *button, gpointer user_data)
{
  GList *orientables = (GList *) user_data, *ptr;
  gboolean state = gtk_toggle_button_get_active (button);
  GtkOrientation orientation;

  if (state)
    {
      orientation = GTK_ORIENTATION_VERTICAL;
      gtk_button_set_label (GTK_BUTTON (button), "Vertical");
    }
  else
    {
      orientation = GTK_ORIENTATION_HORIZONTAL;
      gtk_button_set_label (GTK_BUTTON (button), "Horizontal");
    }

  for (ptr = orientables; ptr; ptr = ptr->next)
    {
      GtkOrientable *orientable = GTK_ORIENTABLE (ptr->data);

      gtk_orientable_set_orientation (orientable, orientation);
    }
}

int
main (int argc, char **argv)
{
  GtkWidget *window;
50
  GtkWidget *grid;
51 52 53 54 55 56
  GtkWidget *box, *button;
  GList *orientables = NULL;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
57 58 59
  grid= gtk_grid_new ();
  gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
60 61

  /* GtkBox */
62
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
63
  orientables = g_list_prepend (orientables, box);
64
  gtk_grid_attach (GTK_GRID (grid), box, 0, 1, 1, 1);
65 66 67 68 69 70 71 72 73 74 75
  gtk_box_pack_start (GTK_BOX (box),
                  gtk_button_new_with_label ("GtkBox 1"),
                  TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (box),
                  gtk_button_new_with_label ("GtkBox 2"),
                  TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (box),
                  gtk_button_new_with_label ("GtkBox 3"),
                  TRUE, TRUE, 0);

  /* GtkButtonBox */
76
  box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
77
  orientables = g_list_prepend (orientables, box);
78
  gtk_grid_attach (GTK_GRID (grid), box, 1, 1, 1, 1);
79 80 81 82 83 84 85 86 87 88 89
  gtk_box_pack_start (GTK_BOX (box),
                  gtk_button_new_with_label ("GtkButtonBox 1"),
                  TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (box),
                  gtk_button_new_with_label ("GtkButtonBox 2"),
                  TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (box),
                  gtk_button_new_with_label ("GtkButtonBox 3"),
                  TRUE, TRUE, 0);

  /* GtkSeparator */
90
  box = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
91
  orientables = g_list_prepend (orientables, box);
92
  gtk_grid_attach (GTK_GRID (grid), box, 2, 1, 1, 1);
93 94

  button = gtk_toggle_button_new_with_label ("Horizontal");
95
  gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
96 97 98
  g_signal_connect (button, "toggled",
                  G_CALLBACK (orient_toggled), orientables);

99
  gtk_container_add (GTK_CONTAINER (window), grid);
100 101 102 103 104 105 106 107 108
  gtk_widget_show_all (window);

  g_signal_connect (window, "destroy",
                  G_CALLBACK (gtk_main_quit), NULL);

  gtk_main ();

  return 0;
}