diff options
author | Matthias Clasen <mclasen@redhat.com> | 2013-09-29 13:43:27 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2013-10-06 23:31:17 -0400 |
commit | 943d575ec3a99a5715de8552006ec2079e17c85a (patch) | |
tree | ac30153a1acde857d1b103e3b4b4736bb009f7b6 /gtk/a11y | |
parent | 8a85371901a4f76fff1298da072615f149b83439 (diff) | |
download | gtk+-943d575ec3a99a5715de8552006ec2079e17c85a.tar.gz |
Add GtkFlowBox
GtkFlowBox is a container that its children in a reflowing
grid, which can be oriented horizontally or vertically.
It is similar to GtkListBox in that the children can
be sorted and filtered, and by requiring a dedicated child
widget type, GtkFlowBoxChild. It is similar to GtkTreeView
in that is supports a full set of selection modes, including
rubberband selection.
This is the culmination of work that has happened in the
egg-list-box module, and earlier in libegg. The origins of
this code are the EggSpreadTable in libegg, which was written
by Tristan van Berkom. It was moved to egg-list-box and
renamed EggFlowBox by Jon McCann, and I gave it some finishing
touched in the flowbox-improvements branch of that module.
Diffstat (limited to 'gtk/a11y')
-rw-r--r-- | gtk/a11y/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/a11y/gtkflowboxaccessible.c | 254 | ||||
-rw-r--r-- | gtk/a11y/gtkflowboxaccessible.h | 58 | ||||
-rw-r--r-- | gtk/a11y/gtkflowboxaccessibleprivate.h | 30 | ||||
-rw-r--r-- | gtk/a11y/gtkflowboxchildaccessible.c | 70 | ||||
-rw-r--r-- | gtk/a11y/gtkflowboxchildaccessible.h | 55 |
6 files changed, 469 insertions, 0 deletions
diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am index 25205b3f30..2be4c99ca9 100644 --- a/gtk/a11y/Makefile.am +++ b/gtk/a11y/Makefile.am @@ -18,6 +18,8 @@ gtka11y_c_sources = \ gtkcontainercellaccessible.c \ gtkentryaccessible.c \ gtkexpanderaccessible.c \ + gtkflowboxaccessible.c \ + gtkflowboxchildaccessible.c \ gtkframeaccessible.c \ gtkiconviewaccessible.c \ gtkimageaccessible.c \ diff --git a/gtk/a11y/gtkflowboxaccessible.c b/gtk/a11y/gtkflowboxaccessible.c new file mode 100644 index 0000000000..d32a7f2db0 --- /dev/null +++ b/gtk/a11y/gtkflowboxaccessible.c @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. + * + * This library 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 library 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 library. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "config.h" + +#include "gtkflowboxaccessibleprivate.h" + +#include "gtk/gtkflowbox.h" + +static void atk_selection_interface_init (AtkSelectionIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkFlowBoxAccessible, gtk_flow_box_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE, + G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)) + +static void +gtk_flow_box_accessible_init (GtkFlowBoxAccessible *accessible) +{ +} + +static void +gtk_flow_box_accessible_initialize (AtkObject *obj, + gpointer data) +{ + ATK_OBJECT_CLASS (gtk_flow_box_accessible_parent_class)->initialize (obj, data); + + obj->role = ATK_ROLE_TABLE; +} + +static AtkStateSet* +gtk_flow_box_accessible_ref_state_set (AtkObject *obj) +{ + AtkStateSet *state_set; + GtkWidget *widget; + + state_set = ATK_OBJECT_CLASS (gtk_flow_box_accessible_parent_class)->ref_state_set (obj); + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); + + if (widget != NULL) + atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS); + + return state_set; +} + +static void +gtk_flow_box_accessible_class_init (GtkFlowBoxAccessibleClass *klass) +{ + AtkObjectClass *object_class = ATK_OBJECT_CLASS (klass); + + object_class->initialize = gtk_flow_box_accessible_initialize; + object_class->ref_state_set = gtk_flow_box_accessible_ref_state_set; +} + +static gboolean +gtk_flow_box_accessible_add_selection (AtkSelection *selection, + gint idx) +{ + GtkWidget *box; + GList *children; + GtkWidget *child; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return FALSE; + + children = gtk_container_get_children (GTK_CONTAINER (box)); + child = g_list_nth_data (children, idx); + g_list_free (children); + if (child) + { + gtk_flow_box_select_child (GTK_FLOW_BOX (box), GTK_FLOW_BOX_CHILD (child)); + return TRUE; + } + return FALSE; +} + +static gboolean +gtk_flow_box_accessible_remove_selection (AtkSelection *selection, + gint idx) +{ + GtkWidget *box; + GList *children; + GtkWidget *child; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return FALSE; + + children = gtk_container_get_children (GTK_CONTAINER (box)); + child = g_list_nth_data (children, idx); + g_list_free (children); + if (child) + { + gtk_flow_box_unselect_child (GTK_FLOW_BOX (box), GTK_FLOW_BOX_CHILD (child)); + return TRUE; + } + return FALSE; +} + +static gboolean +gtk_flow_box_accessible_clear_selection (AtkSelection *selection) +{ + GtkWidget *box; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return FALSE; + + gtk_flow_box_unselect_all (GTK_FLOW_BOX (box)); + return TRUE; +} + +static gboolean +gtk_flow_box_accessible_select_all (AtkSelection *selection) +{ + GtkWidget *box; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return FALSE; + + gtk_flow_box_select_all (GTK_FLOW_BOX (box)); + return TRUE; +} + +typedef struct +{ + gint idx; + GtkWidget *child; +} FindSelectedData; + +static void +find_selected_child (GtkFlowBox *box, + GtkFlowBoxChild *child, + gpointer data) +{ + FindSelectedData *d = data; + + if (d->idx == 0) + { + if (d->child == NULL) + d->child = GTK_WIDGET (child); + } + else + d->idx -= 1; +} + +static AtkObject * +gtk_flow_box_accessible_ref_selection (AtkSelection *selection, + gint idx) +{ + GtkWidget *box; + AtkObject *accessible; + FindSelectedData data; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return NULL; + + data.idx = idx; + data.child = NULL; + gtk_flow_box_selected_foreach (GTK_FLOW_BOX (box), find_selected_child, &data); + + if (data.child == NULL) + return NULL; + + accessible = gtk_widget_get_accessible (data.child); + g_object_ref (accessible); + return accessible; +} + +static void +count_selected (GtkFlowBox *box, + GtkFlowBoxChild *child, + gpointer data) +{ + gint *count = data; + *count += 1; +} + +static gint +gtk_flow_box_accessible_get_selection_count (AtkSelection *selection) +{ + GtkWidget *box; + gint count; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return 0; + + count = 0; + gtk_flow_box_selected_foreach (GTK_FLOW_BOX (box), count_selected, &count); + + return count; +} + +static gboolean +gtk_flow_box_accessible_is_child_selected (AtkSelection *selection, + gint idx) +{ + GtkWidget *box; + GtkFlowBoxChild *child; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return FALSE; + + child = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (box), idx); + + return gtk_flow_box_child_is_selected (child); +} + +static void atk_selection_interface_init (AtkSelectionIface *iface) +{ + iface->add_selection = gtk_flow_box_accessible_add_selection; + iface->remove_selection = gtk_flow_box_accessible_remove_selection; + iface->clear_selection = gtk_flow_box_accessible_clear_selection; + iface->ref_selection = gtk_flow_box_accessible_ref_selection; + iface->get_selection_count = gtk_flow_box_accessible_get_selection_count; + iface->is_child_selected = gtk_flow_box_accessible_is_child_selected; + iface->select_all_selection = gtk_flow_box_accessible_select_all; +} + +void +_gtk_flow_box_accessible_selection_changed (GtkWidget *box) +{ + AtkObject *accessible; + accessible = gtk_widget_get_accessible (box); + g_signal_emit_by_name (accessible, "selection-changed"); +} + +void +_gtk_flow_box_accessible_update_cursor (GtkWidget *box, + GtkWidget *child) +{ + AtkObject *accessible; + AtkObject *descendant; + accessible = gtk_widget_get_accessible (box); + descendant = child ? gtk_widget_get_accessible (child) : NULL; + g_signal_emit_by_name (accessible, "active-descendant-changed", descendant); +} diff --git a/gtk/a11y/gtkflowboxaccessible.h b/gtk/a11y/gtkflowboxaccessible.h new file mode 100644 index 0000000000..51945721e3 --- /dev/null +++ b/gtk/a11y/gtkflowboxaccessible.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. + * + * This library 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 library 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 library. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __GTK_FLOW_BOX_ACCESSIBLE_H__ +#define __GTK_FLOW_BOX_ACCESSIBLE_H__ + +#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk-a11y.h> can be included directly." +#endif + +#include <gtk/gtk.h> +#include <gtk/a11y/gtkcontaineraccessible.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_FLOW_BOX_ACCESSIBLE (gtk_flow_box_accessible_get_type ()) +#define GTK_FLOW_BOX_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FLOW_BOX_ACCESSIBLE, GtkFlowBoxAccessible)) +#define GTK_FLOW_BOX_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FLOW_BOX_ACCESSIBLE, GtkFlowBoxAccessibleClass)) +#define GTK_IS_FLOW_BOX_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FLOW_BOX_ACCESSIBLE)) +#define GTK_IS_FLOW_BOX_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FLOW_BOX_ACCESSIBLE)) +#define GTK_FLOW_BOX_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FLOW_BOX_ACCESSIBLE, GtkFlowBoxAccessibleClass)) + +typedef struct _GtkFlowBoxAccessible GtkFlowBoxAccessible; +typedef struct _GtkFlowBoxAccessibleClass GtkFlowBoxAccessibleClass; +typedef struct _GtkFlowBoxAccessiblePrivate GtkFlowBoxAccessiblePrivate; + +struct _GtkFlowBoxAccessible +{ + GtkContainerAccessible parent; + + GtkFlowBoxAccessiblePrivate *priv; +}; + +struct _GtkFlowBoxAccessibleClass +{ + GtkContainerAccessibleClass parent_class; +}; + +GDK_AVAILABLE_IN_3_12 +GType gtk_flow_box_accessible_get_type (void); + +G_END_DECLS + +#endif /* __GTK_FLOW_BOX_ACCESSIBLE_H__ */ diff --git a/gtk/a11y/gtkflowboxaccessibleprivate.h b/gtk/a11y/gtkflowboxaccessibleprivate.h new file mode 100644 index 0000000000..df19ba782a --- /dev/null +++ b/gtk/a11y/gtkflowboxaccessibleprivate.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. + * + * This library 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 library 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 library. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __GTK_FLOW_BOX_ACCESSIBLE_PRIVATE_H__ +#define __GTK_FLOW_BOX_ACCESSIBLE_PRIVATE_H__ + +#include <gtk/a11y/gtkflowboxaccessible.h> + +G_BEGIN_DECLS + +void _gtk_flow_box_accessible_selection_changed (GtkWidget *box); +void _gtk_flow_box_accessible_update_cursor (GtkWidget *box, + GtkWidget *child); +G_END_DECLS + +#endif /* __GTK_FLOW_BOX_ACCESSIBLE_PRIVATE_H__ */ diff --git a/gtk/a11y/gtkflowboxchildaccessible.c b/gtk/a11y/gtkflowboxchildaccessible.c new file mode 100644 index 0000000000..2476f97ab0 --- /dev/null +++ b/gtk/a11y/gtkflowboxchildaccessible.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. + * + * This library 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 library 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 library. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "config.h" + +#include "gtkflowboxchildaccessible.h" + +#include "gtk/gtkflowbox.h" + + +G_DEFINE_TYPE (GtkFlowBoxChildAccessible, gtk_flow_box_child_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE) + +static void +gtk_flow_box_child_accessible_init (GtkFlowBoxChildAccessible *accessible) +{ +} + +static void +gtk_flow_box_child_accessible_initialize (AtkObject *obj, + gpointer data) +{ + ATK_OBJECT_CLASS (gtk_flow_box_child_accessible_parent_class)->initialize (obj, data); + + obj->role = ATK_ROLE_TABLE_CELL; +} + +static AtkStateSet * +gtk_flow_box_child_accessible_ref_state_set (AtkObject *obj) +{ + AtkStateSet *state_set; + GtkWidget *widget, *parent; + + state_set = ATK_OBJECT_CLASS (gtk_flow_box_child_accessible_parent_class)->ref_state_set (obj); + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); + if (widget != NULL) + { + parent = gtk_widget_get_parent (widget); + if (gtk_flow_box_get_selection_mode (GTK_FLOW_BOX (parent)) != GTK_SELECTION_NONE) + atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE); + + if (gtk_flow_box_child_is_selected (GTK_FLOW_BOX_CHILD (widget))) + atk_state_set_add_state (state_set, ATK_STATE_SELECTED); + } + + return state_set; +} + +static void +gtk_flow_box_child_accessible_class_init (GtkFlowBoxChildAccessibleClass *klass) +{ + AtkObjectClass *object_class = ATK_OBJECT_CLASS (klass); + + object_class->initialize = gtk_flow_box_child_accessible_initialize; + object_class->ref_state_set = gtk_flow_box_child_accessible_ref_state_set; +} diff --git a/gtk/a11y/gtkflowboxchildaccessible.h b/gtk/a11y/gtkflowboxchildaccessible.h new file mode 100644 index 0000000000..0a52d3366d --- /dev/null +++ b/gtk/a11y/gtkflowboxchildaccessible.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. + * + * This library 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 library 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 library. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __GTK_FLOW_BOX_CHILD_ACCESSIBLE_H__ +#define __GTK_FLOW_BOX_CHILD_ACCESSIBLE_H__ + +#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk-a11y.h> can be included directly." +#endif + +#include <gtk/gtk.h> +#include <gtk/a11y/gtkcontaineraccessible.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_FLOW_BOX_CHILD_ACCESSIBLE (gtk_flow_box_child_accessible_get_type ()) +#define GTK_FLOW_BOX_CHILD_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FLOW_BOX_CHILD_ACCESSIBLE, GtkFlowBoxChildAccessible)) +#define GTK_FLOW_BOX_CHILD_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FLOW_BOX_CHILD_ACCESSIBLE, GtkFlowBoxChildAccessibleClass)) +#define GTK_IS_FLOW_BOX_CHILD_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FLOW_BOX_CHILD_ACCESSIBLE)) +#define GTK_IS_FLOW_BOX_CHILD_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FLOW_BOX_CHILD_ACCESSIBLE)) +#define GTK_FLOW_BOX_CHILD_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FLOW_BOX_CHILD_ACCESSIBLE, GtkFlowBoxChildAccessibleClass)) + +typedef struct _GtkFlowBoxChildAccessible GtkFlowBoxChildAccessible; +typedef struct _GtkFlowBoxChildAccessibleClass GtkFlowBoxChildAccessibleClass; + +struct _GtkFlowBoxChildAccessible +{ + GtkContainerAccessible parent; +}; + +struct _GtkFlowBoxChildAccessibleClass +{ + GtkContainerAccessibleClass parent_class; +}; + +GDK_AVAILABLE_IN_3_12 +GType gtk_flow_box_child_accessible_get_type (void); + +G_END_DECLS + +#endif /* __GTK_FLOW_BOX_CHILD_ACCESSIBLE_H__ */ |