1/* Header Bar
2 * #Keywords: GtkWindowHandle, GtkWindowControls
3 *
4 * GtkHeaderBar is a container that is suitable for implementing
5 * window titlebars. One of its features is that it can position
6 * a title centered with regard to the full width, regardless of
7 * variable-width content at the left or right.
8 *
9 * It is commonly used with gtk_window_set_titlebar()
10 */
11
12#include <gtk/gtk.h>
13
14GtkWidget *
15do_headerbar (GtkWidget *do_widget)
16{
17 static GtkWidget *window = NULL;
18 GtkWidget *header;
19 GtkWidget *button;
20 GtkWidget *box;
21
22 if (!window)
23 {
24 window = gtk_window_new ();
25 gtk_window_set_display (GTK_WINDOW (window), display: gtk_widget_get_display (widget: do_widget));
26 gtk_window_set_title (GTK_WINDOW (window), title: "Welcome to Facebook - Log in, sign up or learn more");
27 g_object_add_weak_pointer (G_OBJECT (window), weak_pointer_location: (gpointer *)&window);
28
29 gtk_window_set_default_size (GTK_WINDOW (window), width: 600, height: 400);
30
31 header = gtk_header_bar_new ();
32
33 button = gtk_button_new_from_icon_name (icon_name: "mail-send-receive-symbolic");
34 gtk_header_bar_pack_end (GTK_HEADER_BAR (header), child: button);
35
36 box = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 0);
37 gtk_widget_add_css_class (widget: box, css_class: "linked");
38 button = gtk_button_new_from_icon_name (icon_name: "go-previous-symbolic");
39 gtk_box_append (GTK_BOX (box), child: button);
40 button = gtk_button_new_from_icon_name (icon_name: "go-next-symbolic");
41 gtk_box_append (GTK_BOX (box), child: button);
42
43 gtk_header_bar_pack_start (GTK_HEADER_BAR (header), child: box);
44 gtk_header_bar_pack_start (GTK_HEADER_BAR (header), child: gtk_switch_new ());
45
46 gtk_window_set_titlebar (GTK_WINDOW (window), titlebar: header);
47
48 gtk_window_set_child (GTK_WINDOW (window), child: gtk_text_view_new ());
49 }
50
51 if (!gtk_widget_get_visible (widget: window))
52 gtk_widget_show (widget: window);
53 else
54 gtk_window_destroy (GTK_WINDOW (window));
55
56 return window;
57}
58

source code of gtk/demos/gtk-demo/headerbar.c