[tepl/wip/tab] Tab: add ::pack_view vfunc



commit 8c870a93fc815ff284f359c34919df64b12680aa
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Jun 21 14:18:12 2017 +0200

    Tab: add ::pack_view vfunc
    
    Some text editors and IDEs have more complex needs and need to pack the
    view differently. For example gedit has the following widget hierarchy:
    
    GeditTab -> GeditViewFrame -> GeditViewCentering -> GtkScrolledWindow ->
    GeditView.

 docs/reference/tepl-3.0-sections.txt |    2 +-
 tepl/tepl-tab.c                      |   25 +++++++++++++++++--------
 tepl/tepl-tab.h                      |   13 +++++++++++++
 3 files changed, 31 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index 3496147..573f379 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -344,6 +344,7 @@ tepl_metadata_manager_shutdown
 <SECTION>
 <FILE>tab</FILE>
 TeplTab
+TeplTabClass
 tepl_tab_new
 tepl_tab_get_view
 tepl_tab_add_info_bar
@@ -354,7 +355,6 @@ TEPL_TAB
 TEPL_TAB_CLASS
 TEPL_TAB_GET_CLASS
 TEPL_TYPE_TAB
-TeplTabClass
 TeplTabPrivate
 tepl_tab_get_type
 </SECTION>
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index 8c00451..8a4bcde 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -68,22 +68,29 @@ create_scrolled_window (void)
 }
 
 static void
+tepl_tab_pack_view_default (TeplTab  *tab,
+                           TeplView *view)
+{
+       g_return_if_fail (tab->priv->scrolled_window == NULL);
+       tab->priv->scrolled_window = create_scrolled_window ();
+
+       gtk_container_add (GTK_CONTAINER (tab->priv->scrolled_window),
+                          GTK_WIDGET (view));
+
+       gtk_container_add (GTK_CONTAINER (tab),
+                          GTK_WIDGET (tab->priv->scrolled_window));
+}
+
+static void
 set_view (TeplTab  *tab,
          TeplView *view)
 {
        g_return_if_fail (TEPL_IS_VIEW (view));
 
        g_assert (tab->priv->view == NULL);
-       g_assert (tab->priv->scrolled_window == NULL);
-
        tab->priv->view = g_object_ref_sink (view);
-       tab->priv->scrolled_window = create_scrolled_window ();
-
-       gtk_container_add (GTK_CONTAINER (tab->priv->scrolled_window),
-                          GTK_WIDGET (tab->priv->view));
 
-       gtk_container_add (GTK_CONTAINER (tab),
-                          GTK_WIDGET (tab->priv->scrolled_window));
+       TEPL_TAB_GET_CLASS (tab)->pack_view (tab, view);
 
        g_object_notify_by_pspec (G_OBJECT (tab), properties[PROP_VIEW]);
 }
@@ -147,6 +154,8 @@ tepl_tab_class_init (TeplTabClass *klass)
        object_class->set_property = tepl_tab_set_property;
        object_class->dispose = tepl_tab_dispose;
 
+       klass->pack_view = tepl_tab_pack_view_default;
+
        /**
         * TeplTab:view:
         *
diff --git a/tepl/tepl-tab.h b/tepl/tepl-tab.h
index a0f4046..de83a1f 100644
--- a/tepl/tepl-tab.h
+++ b/tepl/tepl-tab.h
@@ -46,10 +46,23 @@ struct _TeplTab
        TeplTabPrivate *priv;
 };
 
+/**
+ * TeplTabClass:
+ * @parent_class: The parent class.
+ * @pack_view: Virtual function pointer to add the #TeplView in the #TeplTab
+ * container. Called only once at object construction time, when the
+ * #TeplTab:view property is set. By default the #TeplView is added to a
+ * #GtkScrolledWindow and the #GtkScrolledWindow is added to the #TeplTab with
+ * gtk_container_add().
+ */
 struct _TeplTabClass
 {
        GtkGridClass parent_class;
 
+       void    (* pack_view)           (TeplTab  *tab,
+                                        TeplView *view);
+
+       /*< private >*/
        gpointer padding[12];
 };
 


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