2012-10-30 14:21:44 +00:00
|
|
|
/* GTK+ - accessibility implementations
|
2011-07-01 04:10:39 +00:00
|
|
|
* Copyright 2001, 2002, 2003 Sun Microsystems 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-07-01 04:10:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "gtknotebookpageaccessible.h"
|
|
|
|
|
|
|
|
|
2012-10-15 00:15:28 +00:00
|
|
|
struct _GtkNotebookPageAccessiblePrivate
|
|
|
|
{
|
|
|
|
GtkAccessible *notebook;
|
|
|
|
GtkWidget *child;
|
|
|
|
};
|
|
|
|
|
2011-07-01 04:10:39 +00:00
|
|
|
static void atk_component_interface_init (AtkComponentIface *iface);
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkNotebookPageAccessible, gtk_notebook_page_accessible, ATK_TYPE_OBJECT,
|
2013-06-24 18:13:44 +00:00
|
|
|
G_ADD_PRIVATE (GtkNotebookPageAccessible)
|
2011-07-01 04:10:39 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
2020-05-09 12:26:52 +00:00
|
|
|
find_label_child (GtkWidget *widget)
|
2011-07-01 04:10:39 +00:00
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
for (child = gtk_widget_get_first_child (widget);
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
2011-07-01 04:10:39 +00:00
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
if (GTK_IS_LABEL (child))
|
|
|
|
return child;
|
|
|
|
else
|
2011-07-01 04:10:39 +00:00
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
GtkWidget *w = find_label_child (child);
|
|
|
|
if (w)
|
|
|
|
return w;
|
2011-07-01 04:10:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
return NULL;
|
2011-07-01 04:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
get_label_from_notebook_page (GtkNotebookPageAccessible *page)
|
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
GtkNotebook *notebook;
|
|
|
|
|
2012-10-15 00:15:28 +00:00
|
|
|
notebook = GTK_NOTEBOOK (gtk_accessible_get_widget (page->priv->notebook));
|
2011-07-01 04:10:39 +00:00
|
|
|
if (!notebook)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gtk_notebook_get_show_tabs (notebook))
|
|
|
|
return NULL;
|
|
|
|
|
2012-10-15 00:15:28 +00:00
|
|
|
child = gtk_notebook_get_tab_label (notebook, page->priv->child);
|
2011-07-01 04:10:39 +00:00
|
|
|
|
|
|
|
if (GTK_IS_LABEL (child))
|
|
|
|
return child;
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
return find_label_child (child);
|
2011-07-01 04:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
gtk_notebook_page_accessible_get_name (AtkObject *accessible)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
if (accessible->name != NULL)
|
|
|
|
return accessible->name;
|
|
|
|
|
|
|
|
label = get_label_from_notebook_page (GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible));
|
|
|
|
if (GTK_IS_LABEL (label))
|
|
|
|
return gtk_label_get_text (GTK_LABEL (label));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_notebook_page_accessible_get_parent (AtkObject *accessible)
|
|
|
|
{
|
|
|
|
GtkNotebookPageAccessible *page;
|
|
|
|
|
|
|
|
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
|
|
|
|
|
2012-10-15 00:15:28 +00:00
|
|
|
return ATK_OBJECT (page->priv->notebook);
|
2011-07-01 04:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_notebook_page_accessible_get_n_children (AtkObject *accessible)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_notebook_page_accessible_ref_child (AtkObject *accessible,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
AtkObject *child_obj;
|
|
|
|
GtkNotebookPageAccessible *page = NULL;
|
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
|
2012-10-15 00:15:28 +00:00
|
|
|
if (!page->priv->child)
|
2011-07-01 04:10:39 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-10-15 00:15:28 +00:00
|
|
|
child_obj = gtk_widget_get_accessible (page->priv->child);
|
2011-07-01 04:10:39 +00:00
|
|
|
g_object_ref (child_obj);
|
|
|
|
|
|
|
|
return child_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkStateSet *
|
|
|
|
gtk_notebook_page_accessible_ref_state_set (AtkObject *accessible)
|
|
|
|
{
|
2012-12-18 04:59:23 +00:00
|
|
|
GtkNotebookPageAccessible *page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
|
2011-07-01 04:10:39 +00:00
|
|
|
AtkStateSet *state_set, *label_state_set, *merged_state_set;
|
|
|
|
AtkObject *atk_label;
|
|
|
|
GtkWidget *label;
|
2012-12-18 04:59:23 +00:00
|
|
|
AtkObject *selected;
|
2011-07-01 04:10:39 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
state_set = ATK_OBJECT_CLASS (gtk_notebook_page_accessible_parent_class)->ref_state_set (accessible);
|
2011-07-01 04:10:39 +00:00
|
|
|
|
2012-12-18 04:59:23 +00:00
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
|
|
|
|
|
|
|
|
selected = atk_selection_ref_selection (ATK_SELECTION (page->priv->notebook), 0);
|
2014-07-23 15:56:59 +00:00
|
|
|
if (selected)
|
|
|
|
{
|
|
|
|
if (selected == accessible)
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
|
|
|
|
|
|
|
|
g_object_unref (selected);
|
|
|
|
}
|
2012-12-18 04:59:23 +00:00
|
|
|
|
2011-07-01 04:10:39 +00:00
|
|
|
label = get_label_from_notebook_page (GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible));
|
|
|
|
if (label)
|
|
|
|
{
|
|
|
|
atk_label = gtk_widget_get_accessible (label);
|
|
|
|
label_state_set = atk_object_ref_state_set (atk_label);
|
|
|
|
merged_state_set = atk_state_set_or_sets (state_set, label_state_set);
|
|
|
|
g_object_unref (label_state_set);
|
|
|
|
g_object_unref (state_set);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AtkObject *child;
|
|
|
|
|
|
|
|
child = atk_object_ref_accessible_child (accessible, 0);
|
|
|
|
if (!child)
|
|
|
|
return state_set;
|
|
|
|
|
|
|
|
merged_state_set = state_set;
|
|
|
|
state_set = atk_object_ref_state_set (child);
|
|
|
|
if (atk_state_set_contains_state (state_set, ATK_STATE_VISIBLE))
|
|
|
|
{
|
|
|
|
atk_state_set_add_state (merged_state_set, ATK_STATE_VISIBLE);
|
|
|
|
if (atk_state_set_contains_state (state_set, ATK_STATE_ENABLED))
|
|
|
|
atk_state_set_add_state (merged_state_set, ATK_STATE_ENABLED);
|
|
|
|
if (atk_state_set_contains_state (state_set, ATK_STATE_SHOWING))
|
|
|
|
atk_state_set_add_state (merged_state_set, ATK_STATE_SHOWING);
|
|
|
|
|
|
|
|
}
|
|
|
|
g_object_unref (state_set);
|
|
|
|
g_object_unref (child);
|
|
|
|
}
|
|
|
|
return merged_state_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_notebook_page_accessible_get_index_in_parent (AtkObject *accessible)
|
|
|
|
{
|
|
|
|
GtkNotebookPageAccessible *page;
|
|
|
|
|
|
|
|
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
|
2012-10-15 00:15:28 +00:00
|
|
|
if (!page->priv->child)
|
2011-07-01 04:10:39 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-10-15 00:15:28 +00:00
|
|
|
return gtk_notebook_page_num (GTK_NOTEBOOK (gtk_accessible_get_widget (page->priv->notebook)),
|
|
|
|
page->priv->child);
|
2011-07-01 04:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_notebook_page_accessible_class_init (GtkNotebookPageAccessibleClass *klass)
|
2011-07-01 04:10:39 +00:00
|
|
|
{
|
|
|
|
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
class->get_name = gtk_notebook_page_accessible_get_name;
|
|
|
|
class->get_parent = gtk_notebook_page_accessible_get_parent;
|
|
|
|
class->get_n_children = gtk_notebook_page_accessible_get_n_children;
|
|
|
|
class->ref_child = gtk_notebook_page_accessible_ref_child;
|
|
|
|
class->ref_state_set = gtk_notebook_page_accessible_ref_state_set;
|
|
|
|
class->get_index_in_parent = gtk_notebook_page_accessible_get_index_in_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_notebook_page_accessible_init (GtkNotebookPageAccessible *page)
|
2011-07-01 04:10:39 +00:00
|
|
|
{
|
2013-06-24 18:13:44 +00:00
|
|
|
page->priv = gtk_notebook_page_accessible_get_instance_private (page);
|
2011-07-01 04:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notify_tab_label (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
AtkObject *atk_obj)
|
|
|
|
{
|
|
|
|
if (atk_obj->name == NULL)
|
|
|
|
g_object_notify (G_OBJECT (atk_obj), "accessible-name");
|
|
|
|
g_signal_emit_by_name (atk_obj, "visible-data-changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
AtkObject *
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_notebook_page_accessible_new (GtkNotebookAccessible *notebook,
|
|
|
|
GtkWidget *child)
|
2011-07-01 04:10:39 +00:00
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
AtkObject *atk_object;
|
|
|
|
GtkNotebookPageAccessible *page;
|
2019-05-07 02:20:29 +00:00
|
|
|
GtkNotebook *nb;
|
2011-07-01 04:10:39 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_NOTEBOOK_ACCESSIBLE (notebook), NULL);
|
|
|
|
g_return_val_if_fail (GTK_WIDGET (child), NULL);
|
|
|
|
|
|
|
|
object = g_object_new (GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE, NULL);
|
|
|
|
|
|
|
|
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (object);
|
2012-10-15 00:15:28 +00:00
|
|
|
page->priv->notebook = GTK_ACCESSIBLE (notebook);
|
|
|
|
page->priv->child = child;
|
2011-07-01 04:10:39 +00:00
|
|
|
|
|
|
|
atk_object = ATK_OBJECT (page);
|
|
|
|
atk_object->role = ATK_ROLE_PAGE_TAB;
|
|
|
|
atk_object->layer = ATK_LAYER_WIDGET;
|
|
|
|
|
2011-07-03 19:06:44 +00:00
|
|
|
atk_object_set_parent (gtk_widget_get_accessible (child), atk_object);
|
2019-05-07 02:20:29 +00:00
|
|
|
nb = GTK_NOTEBOOK (gtk_accessible_get_widget (page->priv->notebook));
|
2011-07-03 19:06:44 +00:00
|
|
|
|
2019-05-07 14:57:53 +00:00
|
|
|
g_signal_connect (gtk_notebook_get_page (nb, child),
|
2019-05-07 02:20:29 +00:00
|
|
|
"notify::tab-label",
|
2011-07-01 04:10:39 +00:00
|
|
|
G_CALLBACK (notify_tab_label), page);
|
|
|
|
|
|
|
|
return atk_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_notebook_page_accessible_invalidate (GtkNotebookPageAccessible *page)
|
2011-07-01 04:10:39 +00:00
|
|
|
{
|
|
|
|
AtkObject *obj = ATK_OBJECT (page);
|
|
|
|
GtkWidget *notebook;
|
|
|
|
|
2012-10-15 00:15:28 +00:00
|
|
|
notebook = gtk_accessible_get_widget (page->priv->notebook);
|
2011-07-01 04:10:39 +00:00
|
|
|
if (notebook)
|
|
|
|
g_signal_handlers_disconnect_by_func (notebook, notify_tab_label, page);
|
|
|
|
|
|
|
|
atk_object_notify_state_change (obj, ATK_STATE_DEFUNCT, TRUE);
|
|
|
|
atk_object_set_parent (obj, NULL);
|
2012-10-15 00:15:28 +00:00
|
|
|
page->priv->notebook = NULL;
|
|
|
|
atk_object_set_parent (gtk_widget_get_accessible (page->priv->child), NULL);
|
|
|
|
page->priv->child = NULL;
|
2011-07-01 04:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject*
|
|
|
|
gtk_notebook_page_accessible_ref_accessible_at_point (AtkComponent *component,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
AtkCoordType coord_type)
|
|
|
|
{
|
|
|
|
/* There is only one child so we return it */
|
|
|
|
AtkObject* child;
|
|
|
|
|
|
|
|
child = atk_object_ref_accessible_child (ATK_OBJECT (component), 0);
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_notebook_page_accessible_get_extents (AtkComponent *component,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
AtkCoordType coord_type)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
AtkObject *atk_label;
|
|
|
|
|
|
|
|
label = get_label_from_notebook_page (GTK_NOTEBOOK_PAGE_ACCESSIBLE (component));
|
|
|
|
if (!label)
|
|
|
|
{
|
|
|
|
AtkObject *child;
|
|
|
|
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
child = atk_object_ref_accessible_child (ATK_OBJECT (component), 0);
|
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
|
2014-03-29 20:48:43 +00:00
|
|
|
atk_component_get_extents (ATK_COMPONENT (child), x, y, NULL, NULL,
|
|
|
|
coord_type);
|
2011-07-01 04:10:39 +00:00
|
|
|
g_object_unref (child);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
atk_label = gtk_widget_get_accessible (label);
|
|
|
|
atk_component_get_extents (ATK_COMPONENT (atk_label),
|
|
|
|
x, y, width, height, coord_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
atk_component_interface_init (AtkComponentIface *iface)
|
|
|
|
{
|
|
|
|
/* We use the default implementations for contains, get_position, get_size */
|
|
|
|
iface->ref_accessible_at_point = gtk_notebook_page_accessible_ref_accessible_at_point;
|
|
|
|
iface->get_extents = gtk_notebook_page_accessible_get_extents;
|
|
|
|
}
|