summaryrefslogtreecommitdiff
path: root/demos/gtk-demo/panes.c
blob: 8c1537bc90e2532507cb0f6a6f64664e1330dedc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Paned Widgets
 *
 * The GtkPaned Widget divides its content area into two panes
 * with a divider in between that the user can adjust. A separate
 * child is placed into each pane. GtkPaned widgets can be split
 * horizontally or vertically. This test contains both a horizontal
 * and a vertical GtkPaned widget.
 *
 * There are a number of options that can be set for each pane.
 * You can use the Inspector to adjust the options for each side
 * of each widget.
 */

#include <gtk/gtk.h>

GtkWidget *
do_panes (GtkWidget *do_widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *frame;
  GtkWidget *hpaned;
  GtkWidget *vpaned;
  GtkWidget *label;
  GtkWidget *vbox;

  if (!window)
    {
      window = gtk_window_new ();
      gtk_window_set_title (GTK_WINDOW (window), "Paned Widgets");
      gtk_window_set_default_size (GTK_WINDOW (window), 330, 250);
      gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
      gtk_window_set_display (GTK_WINDOW (window),
                              gtk_widget_get_display (do_widget));
      g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);

      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
      gtk_widget_set_margin_start (vbox, 8);
      gtk_widget_set_margin_end (vbox, 8);
      gtk_widget_set_margin_top (vbox, 8);
      gtk_widget_set_margin_bottom (vbox, 8);
      gtk_window_set_child (GTK_WINDOW (window), vbox);

      frame = gtk_frame_new (NULL);
      gtk_box_append (GTK_BOX (vbox), frame);

      vpaned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
      gtk_frame_set_child (GTK_FRAME (frame), vpaned);

      hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
      gtk_paned_set_start_child (GTK_PANED (vpaned), hpaned);
      gtk_paned_set_shrink_start_child (GTK_PANED (vpaned), FALSE);

      label = gtk_label_new ("Hi there");
      gtk_widget_set_margin_start (label, 4);
      gtk_widget_set_margin_end (label, 4);
      gtk_widget_set_margin_top (label, 4);
      gtk_widget_set_margin_bottom (label, 4);
      gtk_widget_set_hexpand (label, TRUE);
      gtk_widget_set_vexpand (label, TRUE);
      gtk_paned_set_start_child (GTK_PANED (hpaned), label);
      gtk_paned_set_shrink_start_child (GTK_PANED (hpaned), FALSE);

      label = gtk_label_new ("Hello");
      gtk_widget_set_margin_start (label, 4);
      gtk_widget_set_margin_end (label, 4);
      gtk_widget_set_margin_top (label, 4);
      gtk_widget_set_margin_bottom (label, 4);
      gtk_widget_set_hexpand (label, TRUE);
      gtk_widget_set_vexpand (label, TRUE);
      gtk_paned_set_end_child (GTK_PANED (hpaned), label);
      gtk_paned_set_shrink_end_child (GTK_PANED (hpaned), FALSE);

      label = gtk_label_new ("Goodbye");
      gtk_widget_set_margin_start (label, 4);
      gtk_widget_set_margin_end (label, 4);
      gtk_widget_set_margin_top (label, 4);
      gtk_widget_set_margin_bottom (label, 4);
      gtk_widget_set_hexpand (label, TRUE);
      gtk_widget_set_vexpand (label, TRUE);
      gtk_paned_set_end_child (GTK_PANED (vpaned), label);
      gtk_paned_set_shrink_end_child (GTK_PANED (vpaned), FALSE);
    }

  if (!gtk_widget_get_visible (window))
    gtk_widget_set_visible (window, TRUE);
  else
    gtk_window_destroy (GTK_WINDOW (window));

  return window;
}