[Xfce4-commits] [xfce/libxfce4ui] 01/28: Switch XfceTitledDialog to headerbar layout

noreply at xfce.org noreply at xfce.org
Thu Jan 9 23:31:44 CET 2020


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/libxfce4ui.

commit 40743c4158f4f4d2357dd72326a915a969f20f94
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Mon Sep 16 01:39:33 2019 +0200

    Switch XfceTitledDialog to headerbar layout
    
    This means all dialogs (especially settings dialogs) using
    XfceTitledDialog will automatically use a GtkHeaderBar instead of the
    previous custom widgetry. The API for setting the dialog's subtitle
    remains, but is just a convenience function for
    gtk_header_bar_set_subtitle.
---
 glade/libxfce4ui-glade.c           |   2 +-
 libxfce4ui/Makefile.am             |   2 -
 libxfce4ui/libxfce4ui-dialog-ui.ui |  10 +
 libxfce4ui/xfce-heading.c          | 546 -------------------------------------
 libxfce4ui/xfce-heading.h          |  57 ----
 libxfce4ui/xfce-titled-dialog.c    | 109 ++++----
 6 files changed, 66 insertions(+), 660 deletions(-)

diff --git a/glade/libxfce4ui-glade.c b/glade/libxfce4ui-glade.c
index 4a64b14..4c2322c 100644
--- a/glade/libxfce4ui-glade.c
+++ b/glade/libxfce4ui-glade.c
@@ -63,7 +63,7 @@ glade_xfce_titled_dialog_post_create (GladeWidgetAdaptor *adaptor,
 
   if (XFCE_IS_TITLED_DIALOG (dialog))
     {
-      /* create the dialog vbxo */
+      /* create the dialog vbox */
       vbox = glade_widget_adaptor_create_internal (widget,
           G_OBJECT (gtk_dialog_get_content_area (dialog)),
           "vbox", "dialog", FALSE, reason);
diff --git a/libxfce4ui/Makefile.am b/libxfce4ui/Makefile.am
index 21bcf75..5b0032d 100644
--- a/libxfce4ui/Makefile.am
+++ b/libxfce4ui/Makefile.am
@@ -45,8 +45,6 @@ libxfce4ui_sources = \
 	xfce-dialogs.c \
 	xfce-gdk-extensions.c \
 	xfce-gtk-extensions.c \
-	xfce-heading.c \
-	xfce-heading.h \
 	xfce-sm-client.c \
 	xfce-spawn.c \
 	xfce-titled-dialog.c
diff --git a/libxfce4ui/libxfce4ui-dialog-ui.ui b/libxfce4ui/libxfce4ui-dialog-ui.ui
index b6a28a3..476ed60 100644
--- a/libxfce4ui/libxfce4ui-dialog-ui.ui
+++ b/libxfce4ui/libxfce4ui-dialog-ui.ui
@@ -5,6 +5,16 @@
   <object class="GtkDialog" id="xfce4ui-dialog">
     <property name="can_focus">False</property>
     <property name="type_hint">dialog</property>
+    <child type="titlebar">
+      <object class="GtkHeaderBar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">True</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
         <property name="can_focus">False</property>
diff --git a/libxfce4ui/xfce-heading.c b/libxfce4ui/xfce-heading.c
deleted file mode 100644
index fa00141..0000000
--- a/libxfce4ui/xfce-heading.c
+++ /dev/null
@@ -1,546 +0,0 @@
-/*
- * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>.
- *
- * 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
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_MEMORY_H
-#include <memory.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#include <libxfce4ui/xfce-heading.h>
-#include <libxfce4ui/libxfce4ui-private.h>
-#include <libxfce4ui/libxfce4ui-alias.h>
-
-
-
-#define XFCE_HEADING_BORDER      6
-#define XFCE_HEADING_SPACING    12
-#define XFCE_HEADING_ICON_SIZE  48
-
-
-static void         _xfce_heading_finalize             (GObject          *object);
-static void         _xfce_heading_realize              (GtkWidget        *widget);
-static void         _xfce_heading_size_request         (GtkWidget        *widget,
-                                                        GtkRequisition   *requisition);
-static void         _xfce_heading_get_preferred_width  (GtkWidget        *widget,
-                                                        gint             *min,
-                                                        gint             *natural);
-static void         _xfce_heading_get_preferred_height (GtkWidget        *widget,
-                                                        gint             *min,
-                                                        gint             *natural);
-static gboolean     _xfce_heading_draw                 (GtkWidget        *widget,
-                                                        cairo_t          *ctx);
-static AtkObject   *_xfce_heading_get_accessible       (GtkWidget        *widget);
-static PangoLayout *_xfce_heading_make_layout          (XfceHeading      *heading);
-static GdkPixbuf   *_xfce_heading_make_pixbuf          (XfceHeading      *heading);
-
-
-
-
-struct _XfceHeadingClass
-{
-  /*< private >*/
-  GtkWidgetClass __parent__;
-};
-
-struct _XfceHeading
-{
-  /*< private >*/
-  GtkWidget       __parent__;
-
-  GdkPixbuf       *icon;
-  gchar           *icon_name;
-  gchar           *subtitle;
-  gchar           *title;
-};
-
-
-
-G_DEFINE_TYPE (XfceHeading, _xfce_heading, GTK_TYPE_WIDGET)
-
-
-
-static void
-_xfce_heading_class_init (XfceHeadingClass *klass)
-{
-  GtkWidgetClass *gtkwidget_class;
-  GObjectClass   *gobject_class;
-
-  gobject_class = G_OBJECT_CLASS (klass);
-  gobject_class->finalize = _xfce_heading_finalize;
-
-  gtkwidget_class = GTK_WIDGET_CLASS (klass);
-  gtkwidget_class->realize = _xfce_heading_realize;
-  gtkwidget_class->get_accessible = _xfce_heading_get_accessible;
-  gtkwidget_class->get_preferred_width = _xfce_heading_get_preferred_width;
-  gtkwidget_class->get_preferred_height = _xfce_heading_get_preferred_height;
-  gtkwidget_class->draw = _xfce_heading_draw;
-}
-
-
-
-static void
-_xfce_heading_init (XfceHeading *heading)
-{
-  /* setup the widget parameters */
-  gtk_widget_set_has_window (GTK_WIDGET (heading), TRUE);
-}
-
-
-
-static void
-_xfce_heading_finalize (GObject *object)
-{
-  XfceHeading *heading = XFCE_HEADING (object);
-
-  /* release the private data */
-  if (G_UNLIKELY (heading->icon != NULL))
-    g_object_unref (G_OBJECT (heading->icon));
-
-  g_free (heading->icon_name);
-  g_free (heading->subtitle);
-  g_free (heading->title);
-
-  (*G_OBJECT_CLASS (_xfce_heading_parent_class)->finalize) (object);
-}
-
-
-
-static void
-_xfce_heading_realize (GtkWidget *widget)
-{
-  GdkWindowAttr  attributes;
-  GtkAllocation  allocation;
-  GdkWindow     *window;
-
-  /* mark the widget as realized */
-  gtk_widget_set_realized (widget, TRUE);
-  gtk_widget_get_allocation (widget, &allocation);
-
-  /* setup the window attributes */
-  attributes.x = allocation.x;
-  attributes.y = allocation.y;
-  attributes.width = allocation.width;
-  attributes.height = allocation.height;
-  attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.window_type = GDK_WINDOW_CHILD;
-  attributes.visual = gtk_widget_get_visual (widget);
-  attributes.event_mask = gtk_widget_get_events (widget)
-                        | GDK_EXPOSURE_MASK;
-
-  /* allocate the widget window */
-  window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
-                           GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL);
-  gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
-}
-
-
-
-static void
-_xfce_heading_get_preferred_width (GtkWidget *widget,
-                                   gint      *min,
-                                   gint      *natural)
-{
-  GtkRequisition requisition;
-
-  _xfce_heading_size_request (widget, &requisition);
-
-  *min = *natural = requisition.width;
-}
-
-
-
-static void
-_xfce_heading_get_preferred_height (GtkWidget *widget,
-                                    gint      *min,
-                                    gint      *natural)
-{
-
-  GtkRequisition requisition;
-
-  _xfce_heading_size_request (widget, &requisition);
-
-  *min = *natural = requisition.height;
-}
-
-
-
-static gboolean
-_xfce_heading_draw (GtkWidget *widget,
-                    cairo_t   *ctx)
-{
-  XfceHeading     *heading = XFCE_HEADING (widget);
-  PangoLayout     *layout;
-  GdkPixbuf       *pixbuf;
-  gboolean         rtl;
-  gint             width;
-  gint             height;
-  gint             x;
-  gint             y;
-  GtkAllocation    allocation;
-  GtkStyleContext *context;
-
-  gtk_widget_get_allocation (widget, &allocation);
-
-  context = gtk_widget_get_style_context (widget);
-
-  gtk_style_context_save (context);
-  /* Add "view" as default style class as that resembles the "base color" look of Gtk2 best */
-  gtk_style_context_add_class (context, "view");
-  gtk_style_context_add_class (context, "XfceHeading");
-
-  /* check if we should render from right to left */
-  rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
-
-  /* determine the initial horizontal position */
-  x = (rtl ? allocation.width - XFCE_HEADING_BORDER : XFCE_HEADING_BORDER);
-
-  gtk_render_background (context, ctx,
-                         allocation.x, allocation.y,
-                         allocation.x + allocation.width,
-                         allocation.y + allocation.height);
-
-  /* check if we have a pixbuf to render */
-  pixbuf = _xfce_heading_make_pixbuf (heading);
-  if (G_LIKELY (pixbuf != NULL))
-    {
-      /* determine the pixbuf dimensions */
-      width = gdk_pixbuf_get_width (pixbuf);
-      height = gdk_pixbuf_get_height (pixbuf);
-
-      /* determine the vertical position */
-      y = (allocation.height - height) / 2;
-
-      gtk_render_icon (context, ctx,
-                       pixbuf,
-                       rtl ? x - width : x,
-                       y);
-
-      /* release the pixbuf */
-      g_object_unref (G_OBJECT (pixbuf));
-
-      /* advance the horizontal position */
-      x += (rtl ? -1 : 1) * (width + XFCE_HEADING_SPACING);
-    }
-
-  /* generate the title layout */
-  layout = _xfce_heading_make_layout (heading);
-  pango_layout_get_pixel_size (layout, &width, &height);
-
-  /* determine the vertical position */
-  y = (allocation.height - height) / 2;
-
-  gtk_render_layout (context, ctx,
-                     rtl ? x - width : x, y,
-                     layout);
-
-  /* release the layout */
-  g_object_unref (G_OBJECT (layout));
-
-  gtk_style_context_restore (context);
-
-  return FALSE;
-}
-
-
-
-static void
-_xfce_heading_size_request (GtkWidget      *widget,
-                            GtkRequisition *requisition)
-{
-  XfceHeading *heading = XFCE_HEADING (widget);
-  PangoLayout *layout;
-  GdkPixbuf   *pixbuf;
-  gint         layout_width;
-  gint         layout_height;
-  gint         pixbuf_width = 0;
-  gint         pixbuf_height = 0;
-
-  /* determine the dimensions of the title text */
-  layout = _xfce_heading_make_layout (heading);
-  pango_layout_get_pixel_size (layout, &layout_width, &layout_height);
-  g_object_unref (G_OBJECT (layout));
-
-  /* determine the dimensions of the pixbuf */
-  pixbuf = _xfce_heading_make_pixbuf (heading);
-  if (G_LIKELY (pixbuf != NULL))
-    {
-      pixbuf_width = gdk_pixbuf_get_width (pixbuf);
-      pixbuf_height = gdk_pixbuf_get_height (pixbuf);
-      g_object_unref (G_OBJECT (pixbuf));
-    }
-
-  /* determine the base dimensions */
-  requisition->width = layout_width + pixbuf_width + ((pixbuf_width > 0) ? XFCE_HEADING_SPACING : 0);
-  requisition->height = MAX (XFCE_HEADING_ICON_SIZE, MAX (pixbuf_height, layout_height));
-
-  /* add border size */
-  requisition->width += 2 * XFCE_HEADING_BORDER;
-  requisition->height += 2 * XFCE_HEADING_BORDER;
-}
-
-
-
-static AtkObject*
-_xfce_heading_get_accessible (GtkWidget *widget)
-{
-  AtkObject *object;
-
-  object = (*GTK_WIDGET_CLASS (_xfce_heading_parent_class)->get_accessible) (widget);
-  atk_object_set_role (object, ATK_ROLE_HEADER);
-
-  return object;
-}
-
-
-
-static PangoLayout*
-_xfce_heading_make_layout (XfceHeading *heading)
-{
-  PangoAttribute *attribute;
-  PangoAttrList  *attr_list;
-  PangoLayout    *layout;
-  GString        *text;
-  gint            title_length = 0;
-
-  /* generate the full text */
-  text = g_string_sized_new (128);
-  if (G_LIKELY (heading->title != NULL))
-    {
-      /* add the main title */
-      title_length = strlen (heading->title);
-      g_string_append (text, heading->title);
-    }
-  if (heading->subtitle != NULL && *heading->subtitle != '\0')
-    {
-      /* add an empty line between the title and the subtitle */
-      if (G_LIKELY (heading->title != NULL))
-        g_string_append (text, "\n");
-
-      /* add the subtitle */
-      g_string_append (text, heading->subtitle);
-    }
-
-  /* allocate and setup a new layout from the widget's context */
-  layout = gtk_widget_create_pango_layout (GTK_WIDGET (heading), text->str);
-
-
-  /* allocate an attribute list (large bold title) */
-  attr_list = pango_attr_list_new ();
-  attribute = pango_attr_scale_new (PANGO_SCALE_LARGE); /* large title */
-  attribute->start_index = 0;
-  attribute->end_index = title_length;
-  pango_attr_list_insert (attr_list, attribute);
-  attribute = pango_attr_weight_new (PANGO_WEIGHT_BOLD); /* bold title */
-  attribute->start_index = 0;
-  attribute->end_index = title_length;
-  pango_attr_list_insert (attr_list, attribute);
-  pango_layout_set_attributes (layout, attr_list);
-  pango_attr_list_unref (attr_list);
-
-  /* cleanup */
-  g_string_free (text, TRUE);
-
-  return layout;
-}
-
-
-
-static GdkPixbuf*
-_xfce_heading_make_pixbuf (XfceHeading *heading)
-{
-  GtkIconTheme *icon_theme;
-  GdkPixbuf    *pixbuf = NULL;
-  GdkScreen    *screen;
-  GdkPixbuf    *scaled;
-
-  if (G_UNLIKELY (heading->icon != NULL))
-    {
-      /* just use the specified icon */
-      pixbuf = g_object_ref (G_OBJECT (heading->icon));
-    }
-  else if (G_LIKELY (heading->icon_name != NULL))
-    {
-      /* determine the icon theme for the current screen */
-      screen = gtk_widget_get_screen (GTK_WIDGET (heading));
-      icon_theme = gtk_icon_theme_get_for_screen (screen);
-
-      /* try to load the icon from the icon theme */
-      pixbuf = gtk_icon_theme_load_icon (icon_theme, heading->icon_name,
-                                         XFCE_HEADING_ICON_SIZE,
-                                         GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
-
-      if (pixbuf != NULL
-          && (gdk_pixbuf_get_height (pixbuf) > XFCE_HEADING_ICON_SIZE
-              || gdk_pixbuf_get_width (pixbuf) > XFCE_HEADING_ICON_SIZE))
-        {
-          /* this doesn't happen often, so be stupid
-           * and assume icons are always squared */
-          scaled = gdk_pixbuf_scale_simple (pixbuf,
-                                            XFCE_HEADING_ICON_SIZE,
-                                            XFCE_HEADING_ICON_SIZE,
-                                            GDK_INTERP_BILINEAR);
-          g_object_unref (pixbuf);
-          pixbuf = scaled;
-        }
-
-      /* cache the icon, this does not take theme changes in account,
-       * but because of the only use in the titled dialog, this works
-       * fine, since the window properties are emitted on icon changes */
-      if (heading->icon == NULL
-          && pixbuf != NULL)
-        heading->icon = g_object_ref (pixbuf);
-    }
-
-  return pixbuf;
-}
-
-
-
-/**
- * _xfce_heading_set_icon:
- * @heading : a #XfceHeading.
- * @icon    : the new icon or %NULL.
- *
- * If @icon is not %NULL, @heading will display the new @icon
- * aside the title. Else, if @icon is %NULL no icon is displayed
- * unless an icon name was set with _xfce_heading_set_icon_name().
- **/
-void
-_xfce_heading_set_icon (XfceHeading *heading,
-                        GdkPixbuf   *icon)
-{
-  _libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
-  _libxfce4ui_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon));
-
-  /* check if we have a new icon */
-  if (G_LIKELY (heading->icon != icon))
-    {
-      /* disconnect from the previous icon */
-      if (G_LIKELY (heading->icon != NULL))
-        g_object_unref (G_OBJECT (heading->icon));
-
-      if (icon != NULL)
-        {
-          if (gdk_pixbuf_get_height (icon) > XFCE_HEADING_ICON_SIZE
-              || gdk_pixbuf_get_width (icon) > XFCE_HEADING_ICON_SIZE)
-            {
-              /* this doesn't happen often, so be stupid
-               * and assume icons are always squared */
-              heading->icon = gdk_pixbuf_scale_simple (icon,
-                                                       XFCE_HEADING_ICON_SIZE,
-                                                       XFCE_HEADING_ICON_SIZE,
-                                                       GDK_INTERP_BILINEAR);
-            }
-          else
-            {
-              heading->icon = g_object_ref (icon);
-            }
-        }
-      else
-        {
-          heading->icon = NULL;
-        }
-
-      gtk_widget_queue_resize (GTK_WIDGET (heading));
-    }
-}
-
-
-
-/**
- * _xfce_heading_set_icon_name:
- * @heading   : a #XfceHeading.
- * @icon_name : the new icon name, or %NULL.
- *
- * If @icon_name is not %NULL and the "icon" property is set to
- * %NULL, see _xfce_heading_set_icon(), the @heading will display
- * the name icon identified by the @icon_name.
- **/
-void
-_xfce_heading_set_icon_name (XfceHeading *heading,
-                             const gchar *icon_name)
-{
-  _libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
-
-  /* activate the new icon name */
-  g_free (heading->icon_name);
-  heading->icon_name = g_strdup (icon_name);
-
-  gtk_widget_queue_resize (GTK_WIDGET (heading));
-}
-
-
-
-/**
- * _xfce_heading_set_subtitle:
- * @heading  : a #XfceHeading.
- * @subtitle : the new subtitle for @heading, or %NULL.
- *
- * If @subtitle is not %NULL and not the empty string, it
- * will be displayed by @heading below the main title.
- **/
-void
-_xfce_heading_set_subtitle (XfceHeading *heading,
-                            const gchar *subtitle)
-{
-  _libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
-  _libxfce4ui_return_if_fail (subtitle == NULL || g_utf8_validate (subtitle, -1, NULL));
-
-  /* activate the new subtitle */
-  g_free (heading->subtitle);
-  heading->subtitle = g_strdup (subtitle);
-
-  gtk_widget_queue_resize (GTK_WIDGET (heading));
-}
-
-
-
-/**
- * _xfce_heading_set_title:
- * @heading : a #XfceHeading.
- * @title   : the new title for the @heading.
- *
- * Sets the title displayed by the @heading to the
- * specified @title.
- **/
-void
-_xfce_heading_set_title (XfceHeading *heading,
-                         const gchar *title)
-{
-  _libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
-  _libxfce4ui_return_if_fail (title == NULL || g_utf8_validate (title, -1, NULL));
-
-  /* activate the new title */
-  g_free (heading->title);
-  heading->title = g_strdup (title);
-
-  gtk_widget_queue_resize (GTK_WIDGET (heading));
-}
-
-
-
-#define __XFCE_HEADING_C__
-#include <libxfce4ui/libxfce4ui-aliasdef.c>
diff --git a/libxfce4ui/xfce-heading.h b/libxfce4ui/xfce-heading.h
deleted file mode 100644
index 03bd379..0000000
--- a/libxfce4ui/xfce-heading.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>.
- *
- * 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
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301 USA
- */
-
-#if !defined (LIBXFCE4UI_INSIDE_LIBXFCE4UI_H) && !defined (LIBXFCE4UI_COMPILATION)
-#error "Only <libxfce4ui/libxfce4ui.h> can be included directly, this file is not part of the public API."
-#endif
-
-#ifndef __XFCE_HEADING_H__
-#define __XFCE_HEADING_H__
-
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS
-
-typedef struct _XfceHeadingClass   XfceHeadingClass;
-typedef struct _XfceHeading        XfceHeading;
-
-#define XFCE_TYPE_HEADING             (_xfce_heading_get_type ())
-#define XFCE_HEADING(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_HEADING, XfceHeading))
-#define XFCE_HEADING_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_HEADING, XfceHeadingClass))
-#define XFCE_IS_HEADING(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_HEADING))
-#define XFCE_IS_HEADING_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_HEADING))
-#define XFCE_HEADING_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_HEADING, XfceHeadingClass))
-
-GType      _xfce_heading_get_type      (void) G_GNUC_CONST;
-
-void       _xfce_heading_set_icon      (XfceHeading *heading,
-                                        GdkPixbuf   *icon);
-
-void       _xfce_heading_set_icon_name (XfceHeading *heading,
-                                        const gchar *icon_name);
-
-void       _xfce_heading_set_subtitle  (XfceHeading *heading,
-                                        const gchar *subtitle);
-
-void       _xfce_heading_set_title     (XfceHeading *heading,
-                                        const gchar *title);
-
-G_END_DECLS
-
-#endif /* !__XFCE_HEADING_H__ */
diff --git a/libxfce4ui/xfce-titled-dialog.c b/libxfce4ui/xfce-titled-dialog.c
index 15b41b9..a34b2b9 100644
--- a/libxfce4ui/xfce-titled-dialog.c
+++ b/libxfce4ui/xfce-titled-dialog.c
@@ -38,7 +38,6 @@
 
 #include <gdk/gdkkeysyms.h>
 
-#include <libxfce4ui/xfce-heading.h>
 #include <libxfce4ui/xfce-titled-dialog.h>
 #include <libxfce4ui/libxfce4ui-private.h>
 #include <libxfce4ui/libxfce4ui-alias.h>
@@ -57,24 +56,27 @@ enum
 };
 
 
-
-static void xfce_titled_dialog_finalize       (GObject                *object);
-static void xfce_titled_dialog_get_property   (GObject                *object,
-                                               guint                   prop_id,
-                                               GValue                 *value,
-                                               GParamSpec             *pspec);
-static void xfce_titled_dialog_set_property   (GObject                *object,
-                                               guint                   prop_id,
-                                               const GValue           *value,
-                                               GParamSpec             *pspec);
-static void xfce_titled_dialog_close          (GtkDialog              *dialog);
-static void xfce_titled_dialog_update_heading (XfceTitledDialog       *titled_dialog);
+static GObject *xfce_titled_dialog_constructor    (GType                   type,
+                                                   guint                   n_construct_params,
+                                                   GObjectConstructParam  *construct_params);
+static void     xfce_titled_dialog_finalize       (GObject                *object);
+static void     xfce_titled_dialog_get_property   (GObject                *object,
+                                                   guint                   prop_id,
+                                                   GValue                 *value,
+                                                   GParamSpec             *pspec);
+static void     xfce_titled_dialog_set_property   (GObject                *object,
+                                                   guint                   prop_id,
+                                                   const GValue           *value,
+                                                   GParamSpec             *pspec);
+static void     xfce_titled_dialog_close          (GtkDialog              *dialog);
+static void     xfce_titled_dialog_update_icon    (XfceTitledDialog       *titled_dialog);
 
 
 
 struct _XfceTitledDialogPrivate
 {
-  GtkWidget *heading;
+  GtkWidget *headerbar;
+  GtkWidget *icon;
   gchar     *subtitle;
 };
 
@@ -98,6 +100,7 @@ xfce_titled_dialog_class_init (XfceTitledDialogClass *klass)
   gobject_class->finalize = xfce_titled_dialog_finalize;
   gobject_class->get_property = xfce_titled_dialog_get_property;
   gobject_class->set_property = xfce_titled_dialog_set_property;
+  gobject_class->constructor = xfce_titled_dialog_constructor;
 
   gtkdialog_class = GTK_DIALOG_CLASS (klass);
   gtkdialog_class->close = xfce_titled_dialog_close;
@@ -123,47 +126,41 @@ xfce_titled_dialog_class_init (XfceTitledDialogClass *klass)
 }
 
 
+static GObject *
+xfce_titled_dialog_constructor (GType                  type,
+                                guint                  n_construct_params,
+                                GObjectConstructParam *construct_params)
+{
+  GObject *object;
+
+  object = G_OBJECT_CLASS (xfce_titled_dialog_parent_class)->constructor (type,
+                                                           n_construct_params,
+                                                           construct_params);
+  g_object_set (G_OBJECT (object), "use-header-bar", TRUE, NULL);
+
+  return object;
+}
 
 static void
 xfce_titled_dialog_init (XfceTitledDialog *titled_dialog)
 {
-  GtkWidget *line;
-  GtkWidget *vbox;
-  GtkWidget *content_area;
-
   /* connect the private data */
   titled_dialog->priv = XFCE_TITLED_DIALOG_GET_PRIVATE (titled_dialog);
 
-  /* remove the main dialog box from the window */
-  content_area = gtk_dialog_get_content_area (GTK_DIALOG (titled_dialog));
-  g_object_ref (G_OBJECT (content_area));
-  gtk_container_remove (GTK_CONTAINER (titled_dialog), content_area);
-
-  /* add a new vbox w/o border to the main window */
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-  gtk_container_add (GTK_CONTAINER (titled_dialog), vbox);
-  gtk_widget_show (vbox);
-
-  /* add the heading to the window */
-  titled_dialog->priv->heading = g_object_new (XFCE_TYPE_HEADING, NULL);
-  gtk_box_pack_start (GTK_BOX (vbox), titled_dialog->priv->heading, FALSE, FALSE, 0);
-  gtk_widget_show (titled_dialog->priv->heading);
-
-  /* add the separator between header and content */
-  line = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
-  gtk_box_pack_start (GTK_BOX (vbox), line, FALSE, FALSE, 0);
-  gtk_widget_show (line);
-
-  /* add the main dialog box to the new vbox */
-  gtk_box_pack_start (GTK_BOX (vbox), content_area, TRUE, TRUE, 0);
-  g_object_unref (G_OBJECT(content_area));
-
-  /* make sure to update the heading whenever one of the relevant window properties changes */
-  g_signal_connect (G_OBJECT (titled_dialog), "notify::icon", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
-  g_signal_connect (G_OBJECT (titled_dialog), "notify::icon-name", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
-  g_signal_connect (G_OBJECT (titled_dialog), "notify::title", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
-}
+  /* Get the headerbar of the dialog */
+  titled_dialog->priv->headerbar = gtk_dialog_get_header_bar (GTK_DIALOG (titled_dialog));
+  g_return_if_fail (GTK_IS_HEADER_BAR (titled_dialog->priv->headerbar));
+
+  /* Pack the window icon into the headerbar */
+  titled_dialog->priv->icon = gtk_image_new ();
+  gtk_header_bar_pack_start (GTK_HEADER_BAR (titled_dialog->priv->headerbar), titled_dialog->priv->icon);
+  gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (titled_dialog->priv->headerbar), TRUE);
+  gtk_widget_show (titled_dialog->priv->icon);
 
+  /* make sure to update the icon whenever one of the relevant window properties changes */
+  g_signal_connect (G_OBJECT (titled_dialog), "notify::icon", G_CALLBACK (xfce_titled_dialog_update_icon), NULL);
+  g_signal_connect (G_OBJECT (titled_dialog), "notify::icon-name", G_CALLBACK (xfce_titled_dialog_update_icon), NULL);
+}
 
 
 
@@ -244,12 +241,15 @@ xfce_titled_dialog_close (GtkDialog *dialog)
 
 
 static void
-xfce_titled_dialog_update_heading (XfceTitledDialog *titled_dialog)
+xfce_titled_dialog_update_icon (XfceTitledDialog *titled_dialog)
 {
-  /* update the heading properties using the window property values */
-  _xfce_heading_set_icon (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_icon (GTK_WINDOW (titled_dialog)));
-  _xfce_heading_set_icon_name (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_icon_name (GTK_WINDOW (titled_dialog)));
-  _xfce_heading_set_title (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_title (GTK_WINDOW (titled_dialog)));
+  const gchar *icon_name = gtk_window_get_icon_name (GTK_WINDOW (titled_dialog));
+
+  g_return_if_fail (GTK_IS_HEADER_BAR (titled_dialog->priv->headerbar));
+  _libxfce4ui_return_if_fail (icon_name == NULL);
+
+  gtk_image_set_from_icon_name (GTK_IMAGE (titled_dialog->priv->icon), icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR);
+  gtk_image_set_pixel_size (GTK_IMAGE (titled_dialog->priv->icon), 24);
 }
 
 
@@ -437,8 +437,9 @@ xfce_titled_dialog_set_subtitle (XfceTitledDialog *titled_dialog,
   /* activate the new subtitle */
   titled_dialog->priv->subtitle = g_strdup (subtitle);
 
-  /* update the subtitle for the heading */
-  _xfce_heading_set_subtitle (XFCE_HEADING (titled_dialog->priv->heading), subtitle);
+  /* update the subtitle of the headerbar */
+  gtk_header_bar_set_subtitle (GTK_HEADER_BAR (titled_dialog->priv->headerbar),
+                               titled_dialog->priv->subtitle);
 
   /* notify listeners */
   g_object_notify (G_OBJECT (titled_dialog), "subtitle");

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list