[gtk+] Add more tests to testheaderbar
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add more tests to testheaderbar
- Date: Sun, 26 May 2013 01:04:39 +0000 (UTC)
commit 530edd0d9be7ccc69c30d05c4ac067cb443a68b7
Author: Matthias Clasen <mclasen redhat com>
Date: Sat May 25 20:56:14 2013 -0400
Add more tests to testheaderbar
Check that one can use widgets other than GtkHeaderBar as
titlebars.
tests/testheaderbar.c | 104 +++++++++++++++++++++++++++++++++----------------
1 files changed, 70 insertions(+), 34 deletions(-)
---
diff --git a/tests/testheaderbar.c b/tests/testheaderbar.c
index a04be6f..7fc640a 100644
--- a/tests/testheaderbar.c
+++ b/tests/testheaderbar.c
@@ -5,10 +5,9 @@ static const gchar css[] =
" background-image: -gtk-gradient (linear, center top, center bottom, "
" from (red), "
" to (blue)); "
- " border-radius: 10px 10px 0px 0px; "
" border-width: 0px; "
"}"
- ".titlebar:backdrop { "
+ ".titlebar.backdrop { "
" background-image: none; "
" background-color: @bg_color; "
" border-radius: 10px 10px 0px 0px; "
@@ -42,31 +41,34 @@ on_bookmark_clicked (GtkButton *button, gpointer data)
static void
change_title (GtkButton *button, gpointer data)
{
- GtkWidget *headerbar = GTK_WIDGET (data);
+ GtkWidget *header = GTK_WIDGET (data);
- if (gtk_header_bar_get_custom_title (GTK_HEADER_BAR (headerbar)) == NULL)
+ if (gtk_header_bar_get_custom_title (GTK_HEADER_BAR (header)) == NULL)
{
- gtk_header_bar_set_custom_title (GTK_HEADER_BAR (headerbar), gtk_check_button_new_with_label
("Middle"));
+ gtk_header_bar_set_custom_title (GTK_HEADER_BAR (header), gtk_check_button_new_with_label ("Middle"));
}
else
{
- gtk_header_bar_set_custom_title (GTK_HEADER_BAR (headerbar), NULL);
- gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), "Middle");
+ gtk_header_bar_set_custom_title (GTK_HEADER_BAR (header), NULL);
+ gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Middle");
}
}
+static GtkWidget *header;
+
static void
change_subtitle (GtkButton *button, gpointer data)
{
- GtkWidget *headerbar = GTK_WIDGET (data);
+ if (!GTK_IS_HEADER_BAR (header))
+ return;
- if (gtk_header_bar_get_subtitle (GTK_HEADER_BAR (headerbar)) == NULL)
+ if (gtk_header_bar_get_subtitle (GTK_HEADER_BAR (header)) == NULL)
{
- gtk_header_bar_set_subtitle (GTK_HEADER_BAR (headerbar), "(subtle subtitle)");
+ gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header), "(subtle subtitle)");
}
else
{
- gtk_header_bar_set_subtitle (GTK_HEADER_BAR (headerbar), NULL);
+ gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header), NULL);
}
}
@@ -88,15 +90,61 @@ toggle_fullscreen (GtkButton *button, gpointer data)
}
}
+static void
+change_header (GtkButton *button, gpointer data)
+{
+ GtkWidget *window = GTK_WIDGET (data);
+ GtkWidget *label;
+ GtkWidget *widget;
+ GtkWidget *image;
+ GtkWidget *box;
+
+ if (button && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+ {
+ header = gtk_event_box_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (header), "titlebar");
+ gtk_style_context_add_class (gtk_widget_get_style_context (header), "header-bar");
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ g_object_set (box, "margin", 10, NULL);
+ gtk_container_add (GTK_CONTAINER (header), box);
+ label = gtk_label_new ("Label");
+ gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0);
+ widget = gtk_level_bar_new ();
+ gtk_level_bar_set_value (GTK_LEVEL_BAR (widget), 0.4);
+ gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 0);
+ gtk_widget_show_all (header);
+ }
+ else
+ {
+ header = gtk_header_bar_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (header), "titlebar");
+ gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Example header");
+
+ widget = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
+ gtk_style_context_add_class (gtk_widget_get_style_context (widget), "suggested-action");
+ g_signal_connect (widget, "clicked", G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (header), widget);
+
+ widget= gtk_button_new ();
+ image = gtk_image_new_from_icon_name ("bookmark-new-symbolic", GTK_ICON_SIZE_BUTTON);
+ g_signal_connect (widget, "clicked", G_CALLBACK (on_bookmark_clicked), window);
+ gtk_container_add (GTK_CONTAINER (widget), image);
+
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (header), widget);
+ gtk_widget_show_all (header);
+ }
+
+ gtk_window_set_titlebar (GTK_WINDOW (window), header);
+}
+
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *box;
- GtkWidget *header;
GtkWidget *footer;
GtkWidget *button;
- GtkWidget *image;
GtkWidget *content;
GtkCssProvider *provider;
@@ -105,43 +153,31 @@ main (int argc, char *argv[])
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_style_context_add_class (gtk_widget_get_style_context (window), "main");
- header = gtk_header_bar_new ();
- gtk_style_context_add_class (gtk_widget_get_style_context (header), "titlebar");
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider, css, -1, NULL);
gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (window),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Example header");
- button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
- gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
- g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
-
- gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
-
- button = gtk_button_new ();
- image = gtk_image_new_from_icon_name ("bookmark-new-symbolic", GTK_ICON_SIZE_BUTTON);
- g_signal_connect (button, "clicked", G_CALLBACK (on_bookmark_clicked), window);
- gtk_container_add (GTK_CONTAINER (button), image);
-
- gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);
-
- gtk_window_set_titlebar (GTK_WINDOW (window), header);
+ change_header (NULL, window);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), box);
footer = gtk_header_bar_new ();
- button = gtk_button_new_with_label ("Start");
+ button = gtk_button_new_with_label ("Title");
g_signal_connect (button, "clicked", G_CALLBACK (change_title), footer);
gtk_header_bar_pack_start (GTK_HEADER_BAR (footer), button);
gtk_header_bar_set_custom_title (GTK_HEADER_BAR (footer), gtk_check_button_new_with_label ("Middle"));
- button = gtk_button_new_with_label ("End 1");
- g_signal_connect (button, "clicked", G_CALLBACK (change_subtitle), header);
+ button = gtk_toggle_button_new_with_label ("Custom");
+ g_signal_connect (button, "clicked", G_CALLBACK (change_header), window);
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (footer), button);
+ gtk_header_bar_set_custom_title (GTK_HEADER_BAR (footer), gtk_check_button_new_with_label ("Middle"));
+ button = gtk_button_new_with_label ("Subtitle");
+ g_signal_connect (button, "clicked", G_CALLBACK (change_subtitle), NULL);
gtk_header_bar_pack_end (GTK_HEADER_BAR (footer), button);
- button = gtk_button_new_with_label ("End 2");
+ button = gtk_button_new_with_label ("Fullscreen");
gtk_header_bar_pack_end (GTK_HEADER_BAR (footer), button);
g_signal_connect (button, "clicked", G_CALLBACK (toggle_fullscreen), window);
gtk_box_pack_end (GTK_BOX (box), footer, FALSE, FALSE, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]