[devhelp] Sidebar: subclass GtkGrid, not GtkBox



commit d64e8485dd6923c4211af089fa9f8cbb4a25a2cb
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Dec 31 22:46:45 2017 +0100

    Sidebar: subclass GtkGrid, not GtkBox
    
    It will ease the port to GTK+ 4.

 docs/reference/api-breaks.xml |    7 +++++++
 src/dh-sidebar.c              |   19 ++++++++++++-------
 src/dh-sidebar.h              |    5 +++--
 3 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/api-breaks.xml b/docs/reference/api-breaks.xml
index 37c5fb7..b617df4 100644
--- a/docs/reference/api-breaks.xml
+++ b/docs/reference/api-breaks.xml
@@ -212,6 +212,13 @@
           removed (dead code).
         </para>
       </listitem>
+      <listitem>
+        <para>
+          <link linkend="DhSidebar">DhSidebar</link> is now a subclass of
+          <link linkend="GtkGrid">GtkGrid</link>, not
+          <link linkend="GtkBox">GtkBox</link>.
+        </para>
+      </listitem>
     </itemizedlist>
   </refsect1>
 </part>
diff --git a/src/dh-sidebar.c b/src/dh-sidebar.c
index 2fe24b1..eefb68e 100644
--- a/src/dh-sidebar.c
+++ b/src/dh-sidebar.c
@@ -74,7 +74,7 @@ enum {
 
 static guint signals[N_SIGNALS] = { 0 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (DhSidebar, dh_sidebar, GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (DhSidebar, dh_sidebar, GTK_TYPE_GRID)
 
 static void
 dh_sidebar_dispose (GObject *object)
@@ -480,13 +480,16 @@ dh_sidebar_init (DhSidebar *sidebar)
 
         priv = dh_sidebar_get_instance_private (sidebar);
 
+        gtk_orientable_set_orientation (GTK_ORIENTABLE (sidebar),
+                                        GTK_ORIENTATION_VERTICAL);
+
         /* Setup the search entry */
         priv->entry = GTK_ENTRY (gtk_search_entry_new ());
         gtk_widget_set_hexpand (GTK_WIDGET (priv->entry), TRUE);
         g_object_set (priv->entry,
                       "margin", 6,
                       NULL);
-        gtk_box_pack_start (GTK_BOX (sidebar), GTK_WIDGET (priv->entry), FALSE, FALSE, 0);
+        gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (priv->entry));
 
         g_signal_connect (priv->entry, "key-press-event",
                           G_CALLBACK (entry_key_press_event_cb),
@@ -535,7 +538,9 @@ dh_sidebar_init (DhSidebar *sidebar)
                                         GTK_POLICY_AUTOMATIC);
         gtk_container_add (GTK_CONTAINER (priv->sw_hitlist),
                            GTK_WIDGET (priv->hitlist_view));
-        gtk_box_pack_start (GTK_BOX (sidebar), GTK_WIDGET (priv->sw_hitlist), TRUE, TRUE, 0);
+        gtk_widget_set_hexpand (GTK_WIDGET (priv->sw_hitlist), TRUE);
+        gtk_widget_set_vexpand (GTK_WIDGET (priv->sw_hitlist), TRUE);
+        gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (priv->sw_hitlist));
 
         /* Setup book manager */
         book_manager = dh_book_manager_get_singleton ();
@@ -579,7 +584,9 @@ dh_sidebar_init (DhSidebar *sidebar)
                           G_CALLBACK (book_tree_link_selected_cb),
                           sidebar);
         gtk_container_add (GTK_CONTAINER (priv->sw_book_tree), GTK_WIDGET (priv->book_tree));
-        gtk_box_pack_end (GTK_BOX (sidebar), GTK_WIDGET (priv->sw_book_tree), TRUE, TRUE, 0);
+        gtk_widget_set_hexpand (GTK_WIDGET (priv->sw_book_tree), TRUE);
+        gtk_widget_set_vexpand (GTK_WIDGET (priv->sw_book_tree), TRUE);
+        gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (priv->sw_book_tree));
 
         completion_populate (sidebar);
 
@@ -596,9 +603,7 @@ dh_sidebar_init (DhSidebar *sidebar)
 GtkWidget *
 dh_sidebar_new (DhBookManager *book_manager)
 {
-        return GTK_WIDGET (g_object_new (DH_TYPE_SIDEBAR,
-                                         "orientation", GTK_ORIENTATION_VERTICAL,
-                                         NULL));
+        return g_object_new (DH_TYPE_SIDEBAR, NULL);
 }
 
 /**
diff --git a/src/dh-sidebar.h b/src/dh-sidebar.h
index 09289d9..d0972ea 100644
--- a/src/dh-sidebar.h
+++ b/src/dh-sidebar.h
@@ -3,6 +3,7 @@
  * Copyright (C) 2001-2002 CodeFactory AB
  * Copyright (C) 2001-2002 Mikael Hallendal <micke imendio com>
  * Copyright (C) 2013 Aleksander Morgado <aleksander gnu org>
+ * Copyright (C) 2017 Sébastien Wilmet <swilmet gnome org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -37,11 +38,11 @@ typedef struct _DhSidebar        DhSidebar;
 typedef struct _DhSidebarClass   DhSidebarClass;
 
 struct _DhSidebar {
-        GtkBox parent_instance;
+        GtkGrid parent_instance;
 };
 
 struct _DhSidebarClass {
-        GtkBoxClass parent_class;
+        GtkGridClass parent_class;
 
         /* Signals */
         void (*link_selected) (DhSidebar *sidebar,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]