Commit a84c6739 authored by Guido Gunther's avatar Guido Gunther Committed by Guido Gunther

HdyHeaderGroup: Allow to get and remove the headerbars

parent f48c58fb
......@@ -57,6 +57,7 @@ contains (HdyHeaderGroup *self,
return FALSE;
}
static void
update_decoration_layouts (HdyHeaderGroup *self)
{
......@@ -165,6 +166,54 @@ hdy_header_group_add_header_bar (HdyHeaderGroup *self,
update_decoration_layouts (self);
}
/**
* hdy_header_group_remove_header_bar:
* @self: a #HdyHeaderGroup
* @header_bar: the #GtkHeaderBar to remove
*
* Removes a widget from a #HdyHeaderGroup
**/
void
hdy_header_group_remove_header_bar (HdyHeaderGroup *self,
GtkHeaderBar *header_bar)
{
HdyHeaderGroupPrivate *priv;
g_return_if_fail (HDY_IS_HEADER_GROUP (self));
g_return_if_fail (GTK_IS_HEADER_BAR (header_bar));
g_return_if_fail (contains (self, header_bar));
priv = hdy_header_group_get_instance_private (self);
priv->header_bars = g_slist_remove (priv->header_bars, header_bar);
if (priv->focus == header_bar)
hdy_header_group_set_focus (self, NULL);
g_object_unref (header_bar);
}
/**
* hdy_header_group_get_header_bars:
* @self: a #HdyHeaderGroup
*
* Returns the list of headerbars associated with @self.
*
* Returns: (element-type GtkHeaderBar) (transfer none): a #GSList of
* headerbars. The list is owned by libhandy and should not be modified.
**/
GSList *
hdy_header_group_get_header_bars (HdyHeaderGroup *self)
{
HdyHeaderGroupPrivate *priv;
g_return_val_if_fail (HDY_IS_HEADER_GROUP (self), NULL);
priv = hdy_header_group_get_instance_private (self);
return priv->header_bars;
}
/**
* hdy_header_group_set_focus:
* @self: a #HdyHeaderGroup
......@@ -211,6 +260,7 @@ hdy_header_group_get_focus (HdyHeaderGroup *self)
return priv->focus;
}
typedef struct {
gchar *name;
gint line;
......@@ -432,6 +482,7 @@ header_group_start_element (GMarkupParseContext *context,
}
}
/* This has been copied and modified from gtksizegroup.c. */
static const GMarkupParser header_group_parser =
{
......
......@@ -33,9 +33,13 @@ HdyHeaderGroup *hdy_header_group_new (void);
void hdy_header_group_add_header_bar (HdyHeaderGroup *self,
GtkHeaderBar *header_bar);
GtkHeaderBar *hdy_header_group_get_focus (HdyHeaderGroup *self);
void hdy_header_group_set_focus (HdyHeaderGroup *self,
GtkHeaderBar *header_bar);
GtkHeaderBar *hdy_header_group_get_focus (HdyHeaderGroup *self);
void hdy_header_group_set_focus (HdyHeaderGroup *self,
GtkHeaderBar *header_bar);
GSList * hdy_header_group_get_header_bars (HdyHeaderGroup *self);
void hdy_header_group_remove_header_bar (HdyHeaderGroup *self,
GtkHeaderBar *header_bar);
G_END_DECLS
......
......@@ -33,6 +33,37 @@ test_hdy_header_group_focus (void)
}
static void
test_hdy_header_group_add_remove (void)
{
HdyHeaderGroup *hg;
GtkHeaderBar *bar1, *bar2;
hg = HDY_HEADER_GROUP (hdy_header_group_new ());
bar1 = GTK_HEADER_BAR (gtk_header_bar_new ());
bar2 = GTK_HEADER_BAR (gtk_header_bar_new ());
g_assert_cmpint (g_slist_length (hdy_header_group_get_header_bars (hg)), ==, 0);
hdy_header_group_add_header_bar (hg, GTK_HEADER_BAR (bar1));
g_assert_cmpint (g_slist_length (hdy_header_group_get_header_bars (hg)), ==, 1);
hdy_header_group_add_header_bar (hg, GTK_HEADER_BAR (bar2));
g_assert_cmpint (g_slist_length (hdy_header_group_get_header_bars (hg)), ==, 2);
hdy_header_group_set_focus (hg, GTK_HEADER_BAR (bar2));
hdy_header_group_remove_header_bar (hg, GTK_HEADER_BAR (bar2));
g_assert_cmpint (g_slist_length (hdy_header_group_get_header_bars (hg)), ==, 1);
g_assert_null (hdy_header_group_get_focus (hg));
hdy_header_group_remove_header_bar (hg, GTK_HEADER_BAR (bar1));
g_assert_cmpint (g_slist_length (hdy_header_group_get_header_bars (hg)), ==, 0);
g_object_unref (hg);
}
gint
main (gint argc,
gchar *argv[])
......@@ -40,5 +71,6 @@ main (gint argc,
gtk_test_init (&argc, &argv, NULL);
g_test_add_func("/Handy/HeaderGroup/focus", test_hdy_header_group_focus);
g_test_add_func("/Handy/HeaderGroup/add_remove", test_hdy_header_group_add_remove);
return g_test_run();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment