gtkwindow: Have a separate "titlebar" pointer for decorations we create ourselves

This cleans up the code a bit.

https://bugzilla.gnome.org/show_bug.cgi?id=706529
This commit is contained in:
Jasper St. Pierre 2013-08-21 14:59:44 -04:00
parent cae2b697ef
commit a95cabd787

View File

@ -148,6 +148,7 @@ struct _GtkWindowPrivate
gint title_height;
GtkWidget *title_box;
GtkWidget *titlebar;
GtkWidget *titlebar_icon;
GtkWidget *titlebar_min_button;
GtkWidget *titlebar_max_button;
@ -1805,8 +1806,8 @@ gtk_window_set_title (GtkWindow *window,
if (gtk_widget_get_realized (widget))
gdk_window_set_title (gtk_widget_get_window (widget), priv->title);
if (GTK_IS_HEADER_BAR (priv->title_box) && !priv->custom_title)
gtk_header_bar_set_title (GTK_HEADER_BAR (priv->title_box), priv->title);
if (priv->titlebar != NULL)
gtk_header_bar_set_title (GTK_HEADER_BAR (priv->titlebar), priv->title);
g_object_notify (G_OBJECT (window), "title");
}
@ -3463,6 +3464,7 @@ unset_titlebar (GtkWindow *window)
{
gtk_widget_unparent (priv->title_box);
priv->title_box = NULL;
priv->titlebar = NULL;
priv->titlebar_icon = NULL;
priv->titlebar_min_button = NULL;
priv->titlebar_max_button = NULL;
@ -5050,6 +5052,10 @@ update_window_buttons (GtkWindow *window)
GtkWindowPrivate *priv = window->priv;
gboolean maximized;
GtkTextDirection direction;
gchar *layout_desc;
gchar **tokens, **t;
gint i, j;
GdkPixbuf *icon = NULL;
if (priv->title_box == NULL)
return;
@ -5068,17 +5074,9 @@ update_window_buttons (GtkWindow *window)
gtk_widget_show (priv->title_box);
}
if (priv->custom_title)
if (priv->titlebar == NULL)
return;
if (priv->decorated &&
priv->client_decorated)
{
gchar *layout_desc;
gchar **tokens, **t;
gint i, j;
GdkPixbuf *icon = NULL;
if (priv->titlebar_icon)
{
icon = gtk_image_get_pixbuf (GTK_IMAGE (priv->titlebar_icon));
@ -5209,6 +5207,38 @@ update_window_buttons (GtkWindow *window)
}
g_free (layout_desc);
}
static GtkWidget *
create_titlebar (GtkWindow *window)
{
GtkWindowPrivate *priv = window->priv;
GtkWidget *label;
GtkWidget *titlebar;
GtkStyleContext *context;
gchar *title;
titlebar = gtk_header_bar_new ();
g_object_set (titlebar,
"spacing", 0,
"hpadding", 0,
"vpadding", 0,
NULL);
context = gtk_widget_get_style_context (titlebar);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TITLEBAR);
title = g_markup_printf_escaped ("<b>%s</b>",
priv->title ? priv->title : get_default_title ());
label = gtk_label_new (title);
g_free (title);
g_object_set (label,
"use-markup", TRUE,
"ellipsize", PANGO_ELLIPSIZE_END,
"margin", 6,
NULL);
gtk_header_bar_set_custom_title (GTK_HEADER_BAR (titlebar), label);
return titlebar;
}
static void
@ -5216,9 +5246,6 @@ create_decoration (GtkWidget *widget)
{
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
GtkStyleContext *context;
gchar *title;
GtkWidget *label;
/* Client decorations already created */
if (priv->client_decorated)
@ -5254,29 +5281,10 @@ create_decoration (GtkWidget *widget)
if (priv->title_box == NULL)
{
priv->title_box = gtk_header_bar_new ();
g_object_set (priv->title_box,
"spacing", 0,
"hpadding", 0,
"vpadding", 0,
NULL);
context = gtk_widget_get_style_context (priv->title_box);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TITLEBAR);
gtk_widget_set_parent (priv->title_box, widget);
title = g_markup_printf_escaped ("<b>%s</b>",
priv->title ? priv->title : get_default_title ());
label = gtk_label_new (title);
g_free (title);
g_object_set (label,
"use-markup", TRUE,
"ellipsize", PANGO_ELLIPSIZE_END,
"margin", 6,
NULL);
gtk_header_bar_set_custom_title (GTK_HEADER_BAR (priv->title_box), label);
gtk_widget_show_all (priv->title_box);
priv->titlebar = create_titlebar (window);
gtk_widget_set_parent (priv->titlebar, widget);
gtk_widget_show_all (priv->titlebar);
priv->title_box = priv->titlebar;
}
update_window_buttons (window);
@ -7364,7 +7372,7 @@ gtk_window_forall (GtkContainer *container,
(* callback) (child, callback_data);
if (priv->title_box != NULL &&
(priv->custom_title || include_internals))
(priv->titlebar == NULL || include_internals))
(* callback) (priv->title_box, callback_data);
}