2014-02-08 20:27:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 - 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 Lesser General Public
|
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkactionbar.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkaccessible.h"
|
|
|
|
#include "gtkbuildable.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
2014-02-17 04:02:05 +00:00
|
|
|
#include "gtkbox.h"
|
2014-02-08 20:27:13 +00:00
|
|
|
#include "gtkrevealer.h"
|
2015-12-06 04:10:52 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2017-01-08 13:52:34 +00:00
|
|
|
#include "gtkprivate.h"
|
2017-06-02 00:56:32 +00:00
|
|
|
#include "gtkcenterbox.h"
|
2020-02-14 17:00:48 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2014-02-08 20:27:13 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkactionbar
|
|
|
|
* @Short_description: A full width bar for presenting contextual actions
|
|
|
|
* @Title: GtkActionBar
|
|
|
|
* @See_also: #GtkBox
|
|
|
|
*
|
|
|
|
* GtkActionBar is designed to present contextual actions. It is
|
|
|
|
* expected to be displayed below the content and expand horizontally
|
|
|
|
* to fill the area.
|
|
|
|
*
|
|
|
|
* It allows placing children at the start or the end. In addition, it
|
|
|
|
* contains an internal centered box which is centered with respect to
|
|
|
|
* the full width of the box, even if the children at either side take
|
|
|
|
* up different amounts of space.
|
2015-10-29 11:08:15 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
|
|
|
* GtkActionBar has a single CSS node with name actionbar.
|
2014-02-08 20:27:13 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-27 01:57:42 +00:00
|
|
|
typedef struct _GtkActionBarClass GtkActionBarClass;
|
|
|
|
|
|
|
|
struct _GtkActionBar
|
|
|
|
{
|
2020-05-07 03:54:11 +00:00
|
|
|
GtkWidget parent;
|
2019-05-27 01:57:42 +00:00
|
|
|
|
2017-04-22 18:18:17 +00:00
|
|
|
GtkWidget *center_box;
|
|
|
|
GtkWidget *start_box;
|
|
|
|
GtkWidget *end_box;
|
2014-02-08 20:27:13 +00:00
|
|
|
GtkWidget *revealer;
|
|
|
|
};
|
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
struct _GtkActionBarClass
|
|
|
|
{
|
2020-05-07 03:54:11 +00:00
|
|
|
GtkWidgetClass parent_class;
|
2020-03-28 13:59:12 +00:00
|
|
|
};
|
|
|
|
|
2017-01-08 13:52:34 +00:00
|
|
|
enum {
|
2017-07-24 08:19:05 +00:00
|
|
|
PROP_0,
|
2017-01-08 13:52:34 +00:00
|
|
|
PROP_REVEALED,
|
|
|
|
LAST_PROP
|
|
|
|
};
|
|
|
|
static GParamSpec *props[LAST_PROP] = { NULL, };
|
|
|
|
|
2015-12-06 04:10:52 +00:00
|
|
|
static void gtk_action_bar_buildable_interface_init (GtkBuildableIface *iface);
|
2014-02-08 20:27:13 +00:00
|
|
|
|
2020-05-07 03:54:11 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkActionBar, gtk_action_bar, GTK_TYPE_WIDGET,
|
2014-02-08 20:27:13 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
gtk_action_bar_buildable_interface_init))
|
|
|
|
|
2017-01-08 13:52:34 +00:00
|
|
|
static void
|
|
|
|
gtk_action_bar_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2020-03-28 13:59:12 +00:00
|
|
|
GtkActionBar *self = GTK_ACTION_BAR (object);
|
2017-01-08 13:52:34 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_REVEALED:
|
2020-03-28 13:59:12 +00:00
|
|
|
gtk_action_bar_set_revealed (self, g_value_get_boolean (value));
|
2017-01-08 13:52:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_action_bar_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2020-03-28 13:59:12 +00:00
|
|
|
GtkActionBar *self = GTK_ACTION_BAR (object);
|
2017-01-08 13:52:34 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_REVEALED:
|
2020-03-28 13:59:12 +00:00
|
|
|
g_value_set_boolean (value, gtk_action_bar_get_revealed (self));
|
2017-01-08 13:52:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 18:18:17 +00:00
|
|
|
static void
|
2020-05-05 19:49:30 +00:00
|
|
|
gtk_action_bar_dispose (GObject *object)
|
2017-04-22 18:18:17 +00:00
|
|
|
{
|
2020-05-05 19:49:30 +00:00
|
|
|
GtkActionBar *self = GTK_ACTION_BAR (object);
|
2017-04-22 18:18:17 +00:00
|
|
|
|
2020-05-07 03:54:11 +00:00
|
|
|
g_clear_pointer (&self->revealer, gtk_widget_unparent);
|
2017-04-22 18:18:17 +00:00
|
|
|
|
2020-05-07 03:54:11 +00:00
|
|
|
self->center_box = NULL;
|
2020-03-28 13:59:12 +00:00
|
|
|
self->start_box = NULL;
|
|
|
|
self->end_box = NULL;
|
2017-04-22 18:18:17 +00:00
|
|
|
|
2020-05-05 19:49:30 +00:00
|
|
|
G_OBJECT_CLASS (gtk_action_bar_parent_class)->dispose (object);
|
2017-04-22 18:18:17 +00:00
|
|
|
}
|
|
|
|
|
2014-02-08 20:27:13 +00:00
|
|
|
static void
|
|
|
|
gtk_action_bar_class_init (GtkActionBarClass *klass)
|
|
|
|
{
|
2015-12-06 04:10:52 +00:00
|
|
|
GObjectClass *object_class;
|
2014-02-08 20:27:13 +00:00
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
2015-12-06 04:10:52 +00:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2014-02-08 20:27:13 +00:00
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2017-01-08 13:52:34 +00:00
|
|
|
object_class->set_property = gtk_action_bar_set_property;
|
|
|
|
object_class->get_property = gtk_action_bar_get_property;
|
2020-05-05 19:49:30 +00:00
|
|
|
object_class->dispose = gtk_action_bar_dispose;
|
2015-12-06 04:10:52 +00:00
|
|
|
|
2020-05-07 03:54:11 +00:00
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
2014-02-08 20:27:13 +00:00
|
|
|
|
2017-01-08 13:52:34 +00:00
|
|
|
props[PROP_REVEALED] =
|
|
|
|
g_param_spec_boolean ("revealed",
|
|
|
|
P_("Reveal"),
|
|
|
|
P_("Controls whether the action bar shows its contents or not"),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2017-07-24 08:19:05 +00:00
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, props);
|
|
|
|
|
2014-02-08 20:27:13 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_PANEL);
|
2020-02-14 17:00:48 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("actionbar"));
|
2014-02-08 20:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-03-28 13:59:12 +00:00
|
|
|
gtk_action_bar_init (GtkActionBar *self)
|
2014-02-08 20:27:13 +00:00
|
|
|
{
|
2020-03-28 13:59:12 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (self);
|
2014-02-08 20:27:13 +00:00
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
self->revealer = gtk_revealer_new ();
|
|
|
|
gtk_widget_set_parent (self->revealer, widget);
|
2014-02-08 20:27:13 +00:00
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (self->revealer), TRUE);
|
|
|
|
gtk_revealer_set_transition_type (GTK_REVEALER (self->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
|
2015-12-06 04:10:52 +00:00
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
self->start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
self->end_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2017-04-22 18:18:17 +00:00
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
self->center_box = gtk_center_box_new ();
|
|
|
|
gtk_center_box_set_start_widget (GTK_CENTER_BOX (self->center_box), self->start_box);
|
|
|
|
gtk_center_box_set_end_widget (GTK_CENTER_BOX (self->center_box), self->end_box);
|
2017-04-22 18:18:17 +00:00
|
|
|
|
2020-05-02 21:02:42 +00:00
|
|
|
gtk_revealer_set_child (GTK_REVEALER (self->revealer), self->center_box);
|
2015-12-06 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 02:13:57 +00:00
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
2014-02-08 20:27:13 +00:00
|
|
|
static void
|
|
|
|
gtk_action_bar_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
|
|
|
const gchar *type)
|
|
|
|
{
|
2020-03-28 13:59:12 +00:00
|
|
|
GtkActionBar *self = GTK_ACTION_BAR (buildable);
|
2014-02-08 20:27:13 +00:00
|
|
|
|
2020-05-07 03:54:11 +00:00
|
|
|
if (g_strcmp0 (type, "start") == 0)
|
2020-03-28 13:59:12 +00:00
|
|
|
gtk_action_bar_pack_start (self, GTK_WIDGET (child));
|
2020-05-07 03:54:11 +00:00
|
|
|
else if (g_strcmp0 (type, "center") == 0)
|
|
|
|
gtk_action_bar_set_center_widget (self, GTK_WIDGET (child));
|
2019-03-27 17:16:07 +00:00
|
|
|
else if (g_strcmp0 (type, "end") == 0)
|
2020-03-28 13:59:12 +00:00
|
|
|
gtk_action_bar_pack_end (self, GTK_WIDGET (child));
|
2020-05-07 03:54:11 +00:00
|
|
|
else if (type == NULL && GTK_IS_WIDGET (child))
|
|
|
|
gtk_action_bar_pack_start (self, GTK_WIDGET (child));
|
2014-02-08 20:27:13 +00:00
|
|
|
else
|
2018-03-08 02:13:57 +00:00
|
|
|
parent_buildable_iface->add_child (buildable, builder, child, type);
|
2014-02-08 20:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_action_bar_buildable_interface_init (GtkBuildableIface *iface)
|
|
|
|
{
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
iface->add_child = gtk_action_bar_buildable_add_child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_action_bar_pack_start:
|
|
|
|
* @action_bar: A #GtkActionBar
|
|
|
|
* @child: the #GtkWidget to be added to @action_bar
|
|
|
|
*
|
|
|
|
* Adds @child to @action_bar, packed with reference to the
|
|
|
|
* start of the @action_bar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_action_bar_pack_start (GtkActionBar *action_bar,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (action_bar->start_box), child);
|
2014-02-08 20:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_action_bar_pack_end:
|
|
|
|
* @action_bar: A #GtkActionBar
|
|
|
|
* @child: the #GtkWidget to be added to @action_bar
|
|
|
|
*
|
|
|
|
* Adds @child to @action_bar, packed with reference to the
|
|
|
|
* end of the @action_bar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_action_bar_pack_end (GtkActionBar *action_bar,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
2020-03-28 13:59:12 +00:00
|
|
|
gtk_box_insert_child_after (GTK_BOX (action_bar->end_box), child, NULL);
|
2014-02-08 20:27:13 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 03:42:32 +00:00
|
|
|
/**
|
|
|
|
* gtk_action_bar_remove:
|
|
|
|
* @action_bar: a #GtkActionBar
|
|
|
|
* @child: the #GtkWidget to be removed
|
|
|
|
*
|
|
|
|
* Removes a child from @action_bar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_action_bar_remove (GtkActionBar *action_bar,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
2020-05-07 03:54:11 +00:00
|
|
|
if (gtk_widget_get_parent (child) == action_bar->start_box)
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (action_bar->start_box), child);
|
2020-05-07 03:54:11 +00:00
|
|
|
else if (gtk_widget_get_parent (child) == action_bar->end_box)
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (action_bar->end_box), child);
|
2020-05-07 03:54:11 +00:00
|
|
|
else if (child == gtk_center_box_get_center_widget (GTK_CENTER_BOX (action_bar->center_box)))
|
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (action_bar->center_box), NULL);
|
|
|
|
else
|
|
|
|
g_warning ("Can't remove non-child %s %p from GtkActionBar %p",
|
|
|
|
G_OBJECT_TYPE_NAME (child), child, action_bar);
|
2020-05-07 03:42:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-08 20:27:13 +00:00
|
|
|
/**
|
|
|
|
* gtk_action_bar_set_center_widget:
|
|
|
|
* @action_bar: a #GtkActionBar
|
|
|
|
* @center_widget: (allow-none): a widget to use for the center
|
|
|
|
*
|
|
|
|
* Sets the center widget for the #GtkActionBar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_action_bar_set_center_widget (GtkActionBar *action_bar,
|
|
|
|
GtkWidget *center_widget)
|
|
|
|
{
|
2020-03-28 13:59:12 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (action_bar->center_box), center_widget);
|
2014-02-08 20:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_action_bar_get_center_widget:
|
|
|
|
* @action_bar: a #GtkActionBar
|
|
|
|
*
|
|
|
|
* Retrieves the center bar widget of the bar.
|
|
|
|
*
|
2015-12-01 12:36:21 +00:00
|
|
|
* Returns: (transfer none) (nullable): the center #GtkWidget or %NULL.
|
2014-02-08 20:27:13 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_action_bar_get_center_widget (GtkActionBar *action_bar)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ACTION_BAR (action_bar), NULL);
|
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
return gtk_center_box_get_center_widget (GTK_CENTER_BOX (action_bar->center_box));
|
2014-02-08 20:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_action_bar_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkActionBar widget.
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkActionBar
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_action_bar_new (void)
|
|
|
|
{
|
|
|
|
return GTK_WIDGET (g_object_new (GTK_TYPE_ACTION_BAR, NULL));
|
|
|
|
}
|
2017-01-08 13:52:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_action_bar_set_revealed:
|
|
|
|
* @action_bar: a #GtkActionBar
|
|
|
|
* @revealed: The new value of the property
|
|
|
|
*
|
2017-09-05 20:31:42 +00:00
|
|
|
* Sets the #GtkActionBar:revealed property to @revealed. Changing this will
|
|
|
|
* make @action_bar reveal (%TRUE) or conceal (%FALSE) itself via a sliding
|
|
|
|
* transition.
|
2017-01-08 13:52:34 +00:00
|
|
|
*
|
2017-09-05 20:31:42 +00:00
|
|
|
* Note: this does not show or hide @action_bar in the #GtkWidget:visible sense,
|
|
|
|
* so revealing has no effect if #GtkWidget:visible is %FALSE.
|
2017-01-08 13:52:34 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_action_bar_set_revealed (GtkActionBar *action_bar,
|
|
|
|
gboolean revealed)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ACTION_BAR (action_bar));
|
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
if (revealed == gtk_revealer_get_reveal_child (GTK_REVEALER (action_bar->revealer)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (action_bar->revealer), revealed);
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (action_bar), props[PROP_REVEALED]);
|
2017-01-08 13:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_action_bar_get_revealed:
|
|
|
|
* @action_bar: a #GtkActionBar
|
|
|
|
*
|
2017-12-01 23:01:57 +00:00
|
|
|
* Gets the value of the #GtkActionBar:revealed property.
|
|
|
|
*
|
2017-09-05 20:31:42 +00:00
|
|
|
* Returns: the current value of the #GtkActionBar:revealed property.
|
2017-01-08 13:52:34 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_action_bar_get_revealed (GtkActionBar *action_bar)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ACTION_BAR (action_bar), FALSE);
|
|
|
|
|
2020-03-28 13:59:12 +00:00
|
|
|
return gtk_revealer_get_reveal_child (GTK_REVEALER (action_bar->revealer));
|
2017-01-08 13:52:34 +00:00
|
|
|
}
|