Convert GailNotebookPage to GtkNotebookPageAccessible

At the same time, drop the AtkText implementation, and simplify
accordingly. Test output has been updated to match.
This commit is contained in:
Matthias Clasen 2011-07-01 00:10:39 -04:00
parent 8bb24a936f
commit 9a0fd43df2
10 changed files with 393 additions and 935 deletions

View File

@ -26,7 +26,7 @@ gail_c_sources = \
gailmenushell.c \
gailmenuitem.c \
gtknotebookaccessible.c \
gailnotebookpage.c \
gtknotebookpageaccessible.c \
gtkpanedaccessible.c \
gtkprogressbaraccessible.c \
gtkradiobuttonaccessible.c \
@ -77,7 +77,7 @@ gail_private_h_sources = \
gailmenushell.h \
gailmenuitem.h \
gtknotebookaccessible.h \
gailnotebookpage.h \
gtknotebookpageaccessible.h \
gtkpanedaccessible.h \
gtkprogressbaraccessible.h \
gtkradiobuttonaccessible.h \

View File

@ -1,792 +0,0 @@
/* GAIL - The GNOME Accessibility Implementation Library
* 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
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "gailnotebookpage.h"
#include <libgail-util/gailmisc.h>
static void gail_notebook_page_class_init (GailNotebookPageClass *klass);
static void gail_notebook_page_init (GailNotebookPage *page);
static void gail_notebook_page_finalize (GObject *object);
static void gail_notebook_page_label_map_gtk (GtkWidget *widget,
gpointer data);
static const gchar* gail_notebook_page_get_name (AtkObject *accessible);
static AtkObject* gail_notebook_page_get_parent (AtkObject *accessible);
static gint gail_notebook_page_get_n_children (AtkObject *accessible);
static AtkObject* gail_notebook_page_ref_child (AtkObject *accessible,
gint i);
static gint gail_notebook_page_get_index_in_parent
(AtkObject *accessible);
static AtkStateSet* gail_notebook_page_ref_state_set (AtkObject *accessible);
static gint gail_notebook_page_notify (GObject *obj,
GParamSpec *pspec,
gpointer user_data);
static void gail_notebook_page_init_textutil (GailNotebookPage *notebook_page,
GtkWidget *label);
static void atk_component_interface_init (AtkComponentIface *iface);
static AtkObject* gail_notebook_page_ref_accessible_at_point
(AtkComponent *component,
gint x,
gint y,
AtkCoordType coord_type);
static void gail_notebook_page_get_extents (AtkComponent *component,
gint *x,
gint *y,
gint *width,
gint *height,
AtkCoordType coord_type);
static AtkObject* _gail_notebook_page_get_tab_label (GailNotebookPage *page);
/* atktext.h */
static void atk_text_interface_init (AtkTextIface *iface);
static gchar* gail_notebook_page_get_text (AtkText *text,
gint start_pos,
gint end_pos);
static gunichar gail_notebook_page_get_character_at_offset
(AtkText *text,
gint offset);
static gchar* gail_notebook_page_get_text_before_offset
(AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
static gchar* gail_notebook_page_get_text_at_offset
(AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
static gchar* gail_notebook_page_get_text_after_offset
(AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset);
static gint gail_notebook_page_get_character_count (AtkText *text);
static void gail_notebook_page_get_character_extents
(AtkText *text,
gint offset,
gint *x,
gint *y,
gint *width,
gint *height,
AtkCoordType coords);
static gint gail_notebook_page_get_offset_at_point
(AtkText *text,
gint x,
gint y,
AtkCoordType coords);
static AtkAttributeSet* gail_notebook_page_get_run_attributes
(AtkText *text,
gint offset,
gint *start_offset,
gint *end_offset);
static AtkAttributeSet* gail_notebook_page_get_default_attributes
(AtkText *text);
static GtkWidget* get_label_from_notebook_page (GailNotebookPage *page);
static GtkWidget* find_label_child (GtkContainer *container);
/* FIXME: not GAIL_TYPE_OBJECT? */
G_DEFINE_TYPE_WITH_CODE (GailNotebookPage, gail_notebook_page, ATK_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init))
static void
gail_notebook_page_class_init (GailNotebookPageClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
class->get_name = gail_notebook_page_get_name;
class->get_parent = gail_notebook_page_get_parent;
class->get_n_children = gail_notebook_page_get_n_children;
class->ref_child = gail_notebook_page_ref_child;
class->ref_state_set = gail_notebook_page_ref_state_set;
class->get_index_in_parent = gail_notebook_page_get_index_in_parent;
gobject_class->finalize = gail_notebook_page_finalize;
}
static void
gail_notebook_page_init (GailNotebookPage *page)
{
}
AtkObject*
gail_notebook_page_new (GtkNotebookAccessible *notebook,
GtkWidget *child)
{
GObject *object;
AtkObject *atk_object;
GailNotebookPage *page;
GtkWidget *label;
g_return_val_if_fail (GTK_IS_NOTEBOOK_ACCESSIBLE (notebook), NULL);
g_return_val_if_fail (GTK_WIDGET (child), NULL);
object = g_object_new (GAIL_TYPE_NOTEBOOK_PAGE, NULL);
page = GAIL_NOTEBOOK_PAGE (object);
page->notebook = GTK_ACCESSIBLE (notebook);
page->child = child;
page->textutil = NULL;
atk_object = ATK_OBJECT (page);
atk_object->role = ATK_ROLE_PAGE_TAB;
atk_object->layer = ATK_LAYER_WIDGET;
/*
* We get notified of changes to the label
*/
label = get_label_from_notebook_page (page);
if (GTK_IS_LABEL (label))
{
if (gtk_widget_get_mapped (label))
gail_notebook_page_init_textutil (page, label);
else
g_signal_connect (label,
"map",
G_CALLBACK (gail_notebook_page_label_map_gtk),
page);
}
return atk_object;
}
void
gail_notebook_page_invalidate (GailNotebookPage *page)
{
g_return_if_fail (GAIL_IS_NOTEBOOK_PAGE (page));
atk_object_notify_state_change (ATK_OBJECT (page),
ATK_STATE_DEFUNCT,
TRUE);
atk_object_set_parent (ATK_OBJECT (page), NULL);
page->notebook = NULL;
page->child = NULL;
}
static void
gail_notebook_page_label_map_gtk (GtkWidget *widget,
gpointer data)
{
GailNotebookPage *page;
page = GAIL_NOTEBOOK_PAGE (data);
gail_notebook_page_init_textutil (page, widget);
}
static void
gail_notebook_page_init_textutil (GailNotebookPage *page,
GtkWidget *label)
{
const gchar *label_text;
if (page->textutil == NULL)
{
page->textutil = gail_text_util_new ();
g_signal_connect (label,
"notify",
(GCallback) gail_notebook_page_notify,
page);
}
label_text = gtk_label_get_text (GTK_LABEL (label));
gail_text_util_text_setup (page->textutil, label_text);
}
static gint
gail_notebook_page_notify (GObject *obj,
GParamSpec *pspec,
gpointer user_data)
{
AtkObject *atk_obj = ATK_OBJECT (user_data);
GtkLabel *label;
GailNotebookPage *page;
if (strcmp (pspec->name, "label") == 0)
{
const gchar* label_text;
label = GTK_LABEL (obj);
label_text = gtk_label_get_text (label);
page = GAIL_NOTEBOOK_PAGE (atk_obj);
gail_text_util_text_setup (page->textutil, label_text);
if (atk_obj->name == NULL)
{
/*
* The label has changed so notify a change in accessible-name
*/
g_object_notify (G_OBJECT (atk_obj), "accessible-name");
}
/*
* The label is the only property which can be changed
*/
g_signal_emit_by_name (atk_obj, "visible_data_changed");
}
return 1;
}
static void
gail_notebook_page_finalize (GObject *object)
{
GailNotebookPage *page = GAIL_NOTEBOOK_PAGE (object);
if (page->textutil)
g_object_unref (page->textutil);
G_OBJECT_CLASS (gail_notebook_page_parent_class)->finalize (object);
}
static const gchar*
gail_notebook_page_get_name (AtkObject *accessible)
{
g_return_val_if_fail (GAIL_IS_NOTEBOOK_PAGE (accessible), NULL);
if (accessible->name != NULL)
return accessible->name;
else
{
GtkWidget *label;
label = get_label_from_notebook_page (GAIL_NOTEBOOK_PAGE (accessible));
if (GTK_IS_LABEL (label))
return gtk_label_get_text (GTK_LABEL (label));
else
return NULL;
}
}
static AtkObject*
gail_notebook_page_get_parent (AtkObject *accessible)
{
GailNotebookPage *page;
g_return_val_if_fail (GAIL_IS_NOTEBOOK_PAGE (accessible), NULL);
page = GAIL_NOTEBOOK_PAGE (accessible);
return ATK_OBJECT (page->notebook);
}
static gint
gail_notebook_page_get_n_children (AtkObject *accessible)
{
/* Notebook page has only one child */
g_return_val_if_fail (GAIL_IS_NOTEBOOK_PAGE (accessible), 0);
return 1;
}
static AtkObject*
gail_notebook_page_ref_child (AtkObject *accessible,
gint i)
{
AtkObject *child_obj;
GailNotebookPage *page = NULL;
g_return_val_if_fail (GAIL_IS_NOTEBOOK_PAGE (accessible), NULL);
if (i != 0)
return NULL;
page = GAIL_NOTEBOOK_PAGE (accessible);
if (!page->child)
return NULL;
child_obj = gtk_widget_get_accessible (page->child);
g_object_ref (child_obj);
return child_obj;
}
static gint
gail_notebook_page_get_index_in_parent (AtkObject *accessible)
{
GailNotebookPage *page;
page = GAIL_NOTEBOOK_PAGE (accessible);
if (!page->child)
return -1;
return gtk_notebook_page_num (GTK_NOTEBOOK (gtk_accessible_get_widget (page->notebook)),
page->child);
}
static AtkStateSet*
gail_notebook_page_ref_state_set (AtkObject *accessible)
{
AtkStateSet *state_set, *label_state_set, *merged_state_set;
AtkObject *atk_label;
g_return_val_if_fail (GAIL_NOTEBOOK_PAGE (accessible), NULL);
state_set = ATK_OBJECT_CLASS (gail_notebook_page_parent_class)->ref_state_set (accessible);
atk_label = _gail_notebook_page_get_tab_label (GAIL_NOTEBOOK_PAGE (accessible));
if (atk_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 void
atk_component_interface_init (AtkComponentIface *iface)
{
/*
* We use the default implementations for contains, get_position, get_size
*/
iface->ref_accessible_at_point = gail_notebook_page_ref_accessible_at_point;
iface->get_extents = gail_notebook_page_get_extents;
}
static AtkObject*
gail_notebook_page_ref_accessible_at_point (AtkComponent *component,
gint x,
gint y,
AtkCoordType coord_type)
{
/*
* There is only one child so we return it.
*/
AtkObject* child;
g_return_val_if_fail (ATK_IS_OBJECT (component), NULL);
child = atk_object_ref_accessible_child (ATK_OBJECT (component), 0);
return child;
}
static void
gail_notebook_page_get_extents (AtkComponent *component,
gint *x,
gint *y,
gint *width,
gint *height,
AtkCoordType coord_type)
{
AtkObject *atk_label;
g_return_if_fail (GAIL_IS_NOTEBOOK_PAGE (component));
atk_label = _gail_notebook_page_get_tab_label (GAIL_NOTEBOOK_PAGE (component));
if (!atk_label)
{
AtkObject *child;
*width = 0;
*height = 0;
child = atk_object_ref_accessible_child (ATK_OBJECT (component), 0);
if (!child)
return;
atk_component_get_position (ATK_COMPONENT (child), x, y, coord_type);
g_object_unref (child);
}
else
{
atk_component_get_extents (ATK_COMPONENT (atk_label),
x, y, width, height, coord_type);
}
return;
}
static AtkObject*
_gail_notebook_page_get_tab_label (GailNotebookPage *page)
{
GtkWidget *label;
label = get_label_from_notebook_page (page);
if (label)
return gtk_widget_get_accessible (label);
else
return NULL;
}
/* atktext.h */
static void
atk_text_interface_init (AtkTextIface *iface)
{
iface->get_text = gail_notebook_page_get_text;
iface->get_character_at_offset = gail_notebook_page_get_character_at_offset;
iface->get_text_before_offset = gail_notebook_page_get_text_before_offset;
iface->get_text_at_offset = gail_notebook_page_get_text_at_offset;
iface->get_text_after_offset = gail_notebook_page_get_text_after_offset;
iface->get_character_count = gail_notebook_page_get_character_count;
iface->get_character_extents = gail_notebook_page_get_character_extents;
iface->get_offset_at_point = gail_notebook_page_get_offset_at_point;
iface->get_run_attributes = gail_notebook_page_get_run_attributes;
iface->get_default_attributes = gail_notebook_page_get_default_attributes;
}
static gchar*
gail_notebook_page_get_text (AtkText *text,
gint start_pos,
gint end_pos)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
const gchar *label_text;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL (label))
return NULL;
if (!notebook_page->textutil)
gail_notebook_page_init_textutil (notebook_page, label);
label_text = gtk_label_get_text (GTK_LABEL (label));
if (label_text == NULL)
return NULL;
else
{
return gail_text_util_get_substring (notebook_page->textutil,
start_pos, end_pos);
}
}
static gchar*
gail_notebook_page_get_text_before_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return NULL;
if (!notebook_page->textutil)
gail_notebook_page_init_textutil (notebook_page, label);
return gail_text_util_get_text (notebook_page->textutil,
gtk_label_get_layout (GTK_LABEL (label)), GAIL_BEFORE_OFFSET,
boundary_type, offset, start_offset, end_offset);
}
static gchar*
gail_notebook_page_get_text_at_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return NULL;
if (!notebook_page->textutil)
gail_notebook_page_init_textutil (notebook_page, label);
return gail_text_util_get_text (notebook_page->textutil,
gtk_label_get_layout (GTK_LABEL (label)), GAIL_AT_OFFSET,
boundary_type, offset, start_offset, end_offset);
}
static gchar*
gail_notebook_page_get_text_after_offset (AtkText *text,
gint offset,
AtkTextBoundary boundary_type,
gint *start_offset,
gint *end_offset)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return NULL;
if (!notebook_page->textutil)
gail_notebook_page_init_textutil (notebook_page, label);
return gail_text_util_get_text (notebook_page->textutil,
gtk_label_get_layout (GTK_LABEL (label)), GAIL_AFTER_OFFSET,
boundary_type, offset, start_offset, end_offset);
}
static gint
gail_notebook_page_get_character_count (AtkText *text)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return 0;
return g_utf8_strlen (gtk_label_get_text (GTK_LABEL (label)), -1);
}
static void
gail_notebook_page_get_character_extents (AtkText *text,
gint offset,
gint *x,
gint *y,
gint *width,
gint *height,
AtkCoordType coords)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
PangoRectangle char_rect;
gint index, x_layout, y_layout;
const gchar *label_text;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return;
gtk_label_get_layout_offsets (GTK_LABEL (label), &x_layout, &y_layout);
label_text = gtk_label_get_text (GTK_LABEL (label));
index = g_utf8_offset_to_pointer (label_text, offset) - label_text;
pango_layout_index_to_pos (gtk_label_get_layout (GTK_LABEL (label)), index, &char_rect);
gail_misc_get_extents_from_pango_rectangle (label, &char_rect,
x_layout, y_layout, x, y, width, height, coords);
}
static gint
gail_notebook_page_get_offset_at_point (AtkText *text,
gint x,
gint y,
AtkCoordType coords)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
gint index, x_layout, y_layout;
const gchar *label_text;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return -1;
gtk_label_get_layout_offsets (GTK_LABEL (label), &x_layout, &y_layout);
index = gail_misc_get_index_at_point_in_layout (label,
gtk_label_get_layout (GTK_LABEL (label)),
x_layout, y_layout, x, y, coords);
label_text = gtk_label_get_text (GTK_LABEL (label));
if (index == -1)
{
if (coords == ATK_XY_WINDOW || coords == ATK_XY_SCREEN)
return g_utf8_strlen (label_text, -1);
return index;
}
else
return g_utf8_pointer_to_offset (label_text, label_text + index);
}
static AtkAttributeSet*
gail_notebook_page_get_run_attributes (AtkText *text,
gint offset,
gint *start_offset,
gint *end_offset)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
AtkAttributeSet *at_set = NULL;
GtkJustification justify;
GtkTextDirection dir;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return NULL;
/* Get values set for entire label, if any */
justify = gtk_label_get_justify (GTK_LABEL (label));
if (justify != GTK_JUSTIFY_CENTER)
{
at_set = gail_misc_add_attribute (at_set,
ATK_TEXT_ATTR_JUSTIFICATION,
g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_JUSTIFICATION, justify)));
}
dir = gtk_widget_get_direction (label);
if (dir == GTK_TEXT_DIR_RTL)
{
at_set = gail_misc_add_attribute (at_set,
ATK_TEXT_ATTR_DIRECTION,
g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, dir)));
}
at_set = gail_misc_layout_get_run_attributes (at_set,
gtk_label_get_layout (GTK_LABEL (label)),
(gchar *) gtk_label_get_text (GTK_LABEL (label)),
offset,
start_offset,
end_offset);
return at_set;
}
static AtkAttributeSet*
gail_notebook_page_get_default_attributes (AtkText *text)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
AtkAttributeSet *at_set = NULL;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return NULL;
at_set = gail_misc_get_default_attributes (at_set,
gtk_label_get_layout (GTK_LABEL (label)),
label);
return at_set;
}
static gunichar
gail_notebook_page_get_character_at_offset (AtkText *text,
gint offset)
{
GtkWidget *label;
GailNotebookPage *notebook_page;
const gchar *string;
gchar *index;
notebook_page = GAIL_NOTEBOOK_PAGE (text);
label = get_label_from_notebook_page (notebook_page);
if (!GTK_IS_LABEL(label))
return '\0';
string = gtk_label_get_text (GTK_LABEL (label));
if (offset >= g_utf8_strlen (string, -1))
return '\0';
index = g_utf8_offset_to_pointer (string, offset);
return g_utf8_get_char (index);
}
static GtkWidget*
get_label_from_notebook_page (GailNotebookPage *page)
{
GtkWidget *child;
GtkNotebook *notebook;
notebook = GTK_NOTEBOOK (gtk_accessible_get_widget (page->notebook));
if (!notebook)
return NULL;
if (!gtk_notebook_get_show_tabs (notebook))
return NULL;
child = gtk_notebook_get_tab_label (notebook, page->child);
if (GTK_IS_LABEL (child))
return child;
if (GTK_IS_CONTAINER (child))
child = find_label_child (GTK_CONTAINER (child));
return child;
}
static GtkWidget*
find_label_child (GtkContainer *container)
{
GList *children, *tmp_list;
GtkWidget *child;
children = gtk_container_get_children (container);
child = NULL;
for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next)
{
if (GTK_IS_LABEL (tmp_list->data))
{
child = GTK_WIDGET (tmp_list->data);
break;
}
else if (GTK_IS_CONTAINER (tmp_list->data))
{
child = find_label_child (GTK_CONTAINER (tmp_list->data));
if (child)
break;
}
}
g_list_free (children);
return child;
}

View File

@ -1,63 +0,0 @@
/* GAIL - The GNOME Accessibility Implementation Library
* 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 Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GAIL_NOTEBOOK_PAGE_H__
#define __GAIL_NOTEBOOK_PAGE_H__
#include "gtknotebookaccessible.h"
#include "gailtextutil.h"
G_BEGIN_DECLS
#define GAIL_TYPE_NOTEBOOK_PAGE (gail_notebook_page_get_type ())
#define GAIL_NOTEBOOK_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),GAIL_TYPE_NOTEBOOK_PAGE, GailNotebookPage))
#define GAIL_NOTEBOOK_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_NOTEBOOK_PAGE, GailNotebookPageClass))
#define GAIL_IS_NOTEBOOK_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_NOTEBOOK_PAGE))
#define GAIL_IS_NOTEBOOK_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_NOTEBOOK_PAGE))
#define GAIL_NOTEBOOK_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_NOTEBOOK_PAGE, GailNotebookPageClass))
typedef struct _GailNotebookPage GailNotebookPage;
typedef struct _GailNotebookPageClass GailNotebookPageClass;
struct _GailNotebookPage
{
AtkObject parent;
GtkAccessible *notebook;
GtkWidget *child;
GailTextUtil *textutil;
};
struct _GailNotebookPageClass
{
AtkObjectClass parent_class;
};
GType gail_notebook_page_get_type (void);
AtkObject *gail_notebook_page_new (GtkNotebookAccessible *notebook,
GtkWidget *child);
void gail_notebook_page_invalidate (GailNotebookPage *page);
G_END_DECLS
#endif /* __GAIL_NOTEBOOK_PAGE_H__ */

View File

@ -26,7 +26,7 @@
#include <gdk/x11/gdkx.h>
#endif
#include "gailwidget.h"
#include "gailnotebookpage.h"
#include "gtknotebookpageaccessible.h"
extern GtkWidget *focus_widget;
@ -525,7 +525,7 @@ gail_widget_get_index_in_parent (AtkObject *accessible)
parent = accessible->accessible_parent;
if (GAIL_IS_NOTEBOOK_PAGE (parent))
if (GTK_IS_NOTEBOOK_PAGE_ACCESSIBLE (parent))
return 0;
else
{

View File

@ -22,7 +22,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include "gtknotebookaccessible.h"
#include "gailnotebookpage.h"
#include "gtknotebookpageaccessible.h"
static void atk_selection_interface_init (AtkSelectionIface *iface);
@ -92,7 +92,7 @@ create_notebook_page_accessible (GtkNotebookAccessible *accessible,
{
AtkObject *obj;
obj = gail_notebook_page_new (accessible, child);
obj = gtk_notebook_page_accessible_new (accessible, child);
g_hash_table_insert (accessible->pages, child, obj);
atk_object_set_parent (obj, ATK_OBJECT (accessible));
g_signal_emit_by_name (accessible, "children_changed::add", page_num, obj, NULL);
@ -127,7 +127,7 @@ page_removed_cb (GtkNotebook *notebook,
g_return_if_fail (obj);
g_signal_emit_by_name (accessible, "children_changed::remove",
page_num, obj, NULL);
gail_notebook_page_invalidate (GAIL_NOTEBOOK_PAGE (obj));
gtk_notebook_page_accessible_invalidate (GTK_NOTEBOOK_PAGE_ACCESSIBLE (obj));
g_hash_table_remove (accessible->pages, widget);
}

View File

@ -0,0 +1,318 @@
/* GAIL - The GNOME Accessibility Implementation Library
* 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
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "gtknotebookpageaccessible.h"
static void atk_component_interface_init (AtkComponentIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkNotebookPageAccessible, gtk_notebook_page_accessible, ATK_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
static GtkWidget *
find_label_child (GtkContainer *container)
{
GList *children, *tmp_list;
GtkWidget *child;
children = gtk_container_get_children (container);
child = NULL;
for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next)
{
if (GTK_IS_LABEL (tmp_list->data))
{
child = GTK_WIDGET (tmp_list->data);
break;
}
else if (GTK_IS_CONTAINER (tmp_list->data))
{
child = find_label_child (GTK_CONTAINER (tmp_list->data));
if (child)
break;
}
}
g_list_free (children);
return child;
}
static GtkWidget *
get_label_from_notebook_page (GtkNotebookPageAccessible *page)
{
GtkWidget *child;
GtkNotebook *notebook;
notebook = GTK_NOTEBOOK (gtk_accessible_get_widget (page->notebook));
if (!notebook)
return NULL;
if (!gtk_notebook_get_show_tabs (notebook))
return NULL;
child = gtk_notebook_get_tab_label (notebook, page->child);
if (GTK_IS_LABEL (child))
return child;
if (GTK_IS_CONTAINER (child))
child = find_label_child (GTK_CONTAINER (child));
return child;
}
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);
return ATK_OBJECT (page->notebook);
}
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);
if (!page->child)
return NULL;
child_obj = gtk_widget_get_accessible (page->child);
g_object_ref (child_obj);
return child_obj;
}
static AtkStateSet *
gtk_notebook_page_accessible_ref_state_set (AtkObject *accessible)
{
AtkStateSet *state_set, *label_state_set, *merged_state_set;
AtkObject *atk_label;
GtkWidget *label;
state_set = ATK_OBJECT_CLASS (gtk_notebook_page_accessible_parent_class)->ref_state_set (accessible);
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);
if (!page->child)
return -1;
return gtk_notebook_page_num (GTK_NOTEBOOK (gtk_accessible_get_widget (page->notebook)),
page->child);
}
static void
gtk_notebook_page_accessible_class_init (GtkNotebookPageAccessibleClass *klass)
{
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
gtk_notebook_page_accessible_init (GtkNotebookPageAccessible *page)
{
}
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 *
gtk_notebook_page_accessible_new (GtkNotebookAccessible *notebook,
GtkWidget *child)
{
GObject *object;
AtkObject *atk_object;
GtkNotebookPageAccessible *page;
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);
page->notebook = GTK_ACCESSIBLE (notebook);
page->child = child;
atk_object = ATK_OBJECT (page);
atk_object->role = ATK_ROLE_PAGE_TAB;
atk_object->layer = ATK_LAYER_WIDGET;
g_signal_connect (gtk_accessible_get_widget (page->notebook),
"child-notify::tab-label",
G_CALLBACK (notify_tab_label), page);
return atk_object;
}
void
gtk_notebook_page_accessible_invalidate (GtkNotebookPageAccessible *page)
{
AtkObject *obj = ATK_OBJECT (page);
GtkWidget *notebook;
notebook = gtk_accessible_get_widget (page->notebook);
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);
page->notebook = NULL;
page->child = NULL;
}
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;
atk_component_get_position (ATK_COMPONENT (child), x, y, coord_type);
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;
}

View File

@ -0,0 +1,61 @@
/* GAIL - The GNOME Accessibility Implementation Library
* 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 Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_NOTEBOOK_PAGE_ACCESSIBLE_H__
#define __GTK_NOTEBOOK_PAGE_ACCESSIBLE_H__
#include "gtknotebookaccessible.h"
#include "gailtextutil.h"
G_BEGIN_DECLS
#define GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE (gtk_notebook_page_accessible_get_type ())
#define GTK_NOTEBOOK_PAGE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE, GtkNotebookPageAccessible))
#define GTK_NOTEBOOK_PAGE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE, GtkNotebookPageAccessibleClass))
#define GTK_IS_NOTEBOOK_PAGE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE))
#define GTK_IS_NOTEBOOK_PAGE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE))
#define GTK_NOTEBOOK_PAGE_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE, GtkNotebookPageAccessibleClass))
typedef struct _GtkNotebookPageAccessible GtkNotebookPageAccessible;
typedef struct _GtkNotebookPageAccessibleClass GtkNotebookPageAccessibleClass;
struct _GtkNotebookPageAccessible
{
AtkObject parent;
GtkAccessible *notebook;
GtkWidget *child;
};
struct _GtkNotebookPageAccessibleClass
{
AtkObjectClass parent_class;
};
GType gtk_notebook_page_accessible_get_type (void);
AtkObject *gtk_notebook_page_accessible_new (GtkNotebookAccessible *notebook,
GtkWidget *child);
void gtk_notebook_page_accessible_invalidate (GtkNotebookPageAccessible *page);
G_END_DECLS
#endif /* __GTK_NOTEBOOK_PAGE_ACCESSIBLE_H__ */

View File

@ -86,8 +86,8 @@ window1
layer: widget
alpha: 1
<AtkSelection>
selected children: unnamed-GailNotebookPage-4
unnamed-GailNotebookPage-4
selected children: unnamed-GtkNotebookPageAccessible-4
unnamed-GtkNotebookPageAccessible-4
"page tab"
parent: unnamed-GtkNotebookAccessible-3
index: 0
@ -95,10 +95,6 @@ window1
<AtkComponent>
layer: widget
alpha: 1
<AtkText>
text: (null)
character count: 0
caret offset: 0
unnamed-GailContainer-5
"filler"
index: 0

View File

@ -16,8 +16,8 @@ window1
layer: widget
alpha: 1
<AtkSelection>
selected children: Tab 1
Tab 1
selected children: unnamed-GtkNotebookPageAccessible-0
unnamed-GtkNotebookPageAccessible-0
"page tab"
parent: notebook1
index: 0
@ -26,37 +26,6 @@ window1
<AtkComponent>
layer: widget
alpha: 1
<AtkText>
text: Tab 1
character count: 5
caret offset: 0
default attributes: bg-color: <omitted>
bg-full-height: 0
bg-stipple: false
direction: <omitted>
editable: false
family-name: <omitted>
fg-color: <omitted>
fg-stipple: false
indent: 0
invisible: false
justification: left
language: <omitted>
left-margin: 0
pixels-above-lines: 0
pixels-below-lines: 0
pixels-inside-wrap: 0
right-margin: 0
rise: 0
scale: 1
size: <omitted>
stretch: <omitted>
strikethrough: false
style: <omitted>
underline: none
variant: <omitted>
weight: <omitted>
wrap-mode: word
page1
"push button"
index: 0
@ -103,7 +72,7 @@ window1
<AtkAction>
action 0 name: click
action 0 keybinding: <Alt>y
Tab 2
unnamed-GtkNotebookPageAccessible-1
"page tab"
parent: notebook1
index: 1
@ -112,37 +81,6 @@ window1
<AtkComponent>
layer: widget
alpha: 1
<AtkText>
text: Tab 2
character count: 5
caret offset: 0
default attributes: bg-color: <omitted>
bg-full-height: 0
bg-stipple: false
direction: <omitted>
editable: false
family-name: <omitted>
fg-color: <omitted>
fg-stipple: false
indent: 0
invisible: false
justification: left
language: <omitted>
left-margin: 0
pixels-above-lines: 0
pixels-below-lines: 0
pixels-inside-wrap: 0
right-margin: 0
rise: 0
scale: 1
size: <omitted>
stretch: <omitted>
strikethrough: false
style: <omitted>
underline: none
variant: <omitted>
weight: <omitted>
wrap-mode: word
page2
"push button"
index: 1

View File

@ -70,7 +70,7 @@ window1
image description: (null)
<AtkAction>
action 0 name: click
unnamed-GailComboBox-0
unnamed-GtkComboBoxAccessible-0
"combo box"
parent: button4
index: 1
@ -84,7 +84,7 @@ window1
<AtkSelection>
unnamed-GailMenu-1
"menu"
parent: unnamed-GailComboBox-0
parent: unnamed-GtkComboBoxAccessible-0
index: 0
state: enabled selectable sensitive
toolkit: gail