[tepl/wip/tab] Tab: add ::pack_info_bar vfunc
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl/wip/tab] Tab: add ::pack_info_bar vfunc
- Date: Wed, 21 Jun 2017 14:06:35 +0000 (UTC)
commit 76b9b86b1759bfcfe4418a8f05012c85aff08ffe
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Jun 21 15:41:28 2017 +0200
Tab: add ::pack_info_bar vfunc
tepl/tepl-tab.c | 87 +++++++++++++++++++++++++++++++------------------------
tepl/tepl-tab.h | 16 +++++++--
2 files changed, 61 insertions(+), 42 deletions(-)
---
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index 7825740..80c8fb9 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -30,7 +30,8 @@
* #GtkOrientation.
*
* The way that the #TeplView is packed into the #TeplTab is customizable with
- * the ::pack_view virtual function.
+ * the ::pack_view virtual function. Similarly, the way that #GtkInfoBar's are
+ * added can be customized with ::pack_info_bar.
*/
struct _TeplTabPrivate
@@ -87,6 +88,45 @@ tepl_tab_pack_view_default (TeplTab *tab,
}
static void
+tepl_tab_pack_info_bar_default (TeplTab *tab,
+ GtkInfoBar *info_bar)
+{
+ GList *children;
+ GList *l;
+ GtkWidget *sibling = NULL;
+
+ children = gtk_container_get_children (GTK_CONTAINER (tab));
+
+ for (l = children; l != NULL; l = l->next)
+ {
+ GtkWidget *child = l->data;
+
+ if (!GTK_IS_INFO_BAR (child))
+ {
+ sibling = child;
+ break;
+ }
+ }
+
+ g_list_free (children);
+
+ if (sibling != NULL)
+ {
+ gtk_grid_insert_next_to (GTK_GRID (tab), sibling, GTK_POS_TOP);
+
+ gtk_grid_attach_next_to (GTK_GRID (tab),
+ GTK_WIDGET (info_bar),
+ sibling,
+ GTK_POS_TOP,
+ 1, 1);
+ }
+ else
+ {
+ gtk_container_add (GTK_CONTAINER (tab), GTK_WIDGET (info_bar));
+ }
+}
+
+static void
set_view (TeplTab *tab,
TeplView *view)
{
@@ -160,6 +200,7 @@ tepl_tab_class_init (TeplTabClass *klass)
object_class->dispose = tepl_tab_dispose;
klass->pack_view = tepl_tab_pack_view_default;
+ klass->pack_info_bar = tepl_tab_pack_info_bar_default;
/**
* TeplTab:view:
@@ -225,11 +266,13 @@ tepl_tab_get_view (TeplTab *tab)
* @tab: a #TeplTab.
* @info_bar: a #GtkInfoBar.
*
- * Attaches @info_bar to @tab, above the main widget.
+ * Attaches @info_bar to @tab.
+ *
+ * This function calls the ::pack_info_bar virtual function.
*
- * If several info bars are added, the first one will be at the top, the second
- * one below the first info bar, etc. With the main widget of @tab at the
- * bottom.
+ * By default: if several info bars are added, the first one will be at the top,
+ * the second one below the first info bar, etc. With the main widget of @tab
+ * (containing the #TeplView) at the bottom.
*
* Since: 1.0
*/
@@ -237,40 +280,8 @@ void
tepl_tab_add_info_bar (TeplTab *tab,
GtkInfoBar *info_bar)
{
- GList *children;
- GList *l;
- GtkWidget *sibling = NULL;
-
g_return_if_fail (TEPL_IS_TAB (tab));
g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
- children = gtk_container_get_children (GTK_CONTAINER (tab));
-
- for (l = children; l != NULL; l = l->next)
- {
- GtkWidget *child = l->data;
-
- if (!GTK_IS_INFO_BAR (child))
- {
- sibling = child;
- break;
- }
- }
-
- g_list_free (children);
-
- if (sibling != NULL)
- {
- gtk_grid_insert_next_to (GTK_GRID (tab), sibling, GTK_POS_TOP);
-
- gtk_grid_attach_next_to (GTK_GRID (tab),
- GTK_WIDGET (info_bar),
- sibling,
- GTK_POS_TOP,
- 1, 1);
- }
- else
- {
- gtk_container_add (GTK_CONTAINER (tab), GTK_WIDGET (info_bar));
- }
+ TEPL_TAB_GET_CLASS (tab)->pack_info_bar (tab, info_bar);
}
diff --git a/tepl/tepl-tab.h b/tepl/tepl-tab.h
index de83a1f..55c83c2 100644
--- a/tepl/tepl-tab.h
+++ b/tepl/tepl-tab.h
@@ -50,10 +50,15 @@ struct _TeplTab
* 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().
+ * 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().
+ * @pack_info_bar: Virtual function pointer to add a #GtkInfoBar in the #TeplTab
+ * container. By default the #GtkInfoBar is inserted above the first
+ * non-#GtkInfoBar child widget of #TeplTab (so by default it is inserted
+ * below other #GtkInfoBar's, but above the #GtkScrolledWindow containing the
+ * #TeplView).
*/
struct _TeplTabClass
{
@@ -62,6 +67,9 @@ struct _TeplTabClass
void (* pack_view) (TeplTab *tab,
TeplView *view);
+ void (* pack_info_bar) (TeplTab *tab,
+ GtkInfoBar *info_bar);
+
/*< private >*/
gpointer padding[12];
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]