Blame modules/other/gail/gailnotebook.c

Packit 98cdb6
/* GAIL - The GNOME Accessibility Implementation Library
Packit 98cdb6
 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Lesser General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
Packit 98cdb6
#include <string.h>
Packit 98cdb6
#include <gtk/gtk.h>
Packit 98cdb6
#include "gailnotebook.h"
Packit 98cdb6
#include "gailnotebookpage.h"
Packit 98cdb6
#include "gail-private-macros.h"
Packit 98cdb6
Packit 98cdb6
static void         gail_notebook_class_init          (GailNotebookClass *klass);
Packit 98cdb6
static void         gail_notebook_init                (GailNotebook      *notebook);
Packit 98cdb6
static void         gail_notebook_finalize            (GObject           *object);
Packit 98cdb6
static void         gail_notebook_real_initialize     (AtkObject         *obj,
Packit 98cdb6
                                                       gpointer          data);
Packit 98cdb6
Packit 98cdb6
static void         gail_notebook_real_notify_gtk     (GObject           *obj,
Packit 98cdb6
                                                       GParamSpec        *pspec);
Packit 98cdb6
Packit 98cdb6
static AtkObject*   gail_notebook_ref_child           (AtkObject      *obj,
Packit 98cdb6
                                                       gint           i);
Packit 98cdb6
static gint         gail_notebook_real_remove_gtk     (GtkContainer   *container,
Packit 98cdb6
                                                       GtkWidget      *widget,
Packit 98cdb6
                                                       gpointer       data);    
Packit 98cdb6
static void         atk_selection_interface_init      (AtkSelectionIface *iface);
Packit 98cdb6
static gboolean     gail_notebook_add_selection       (AtkSelection   *selection,
Packit 98cdb6
                                                       gint           i);
Packit 98cdb6
static AtkObject*   gail_notebook_ref_selection       (AtkSelection   *selection,
Packit 98cdb6
                                                       gint           i);
Packit 98cdb6
static gint         gail_notebook_get_selection_count (AtkSelection   *selection);
Packit 98cdb6
static gboolean     gail_notebook_is_child_selected   (AtkSelection   *selection,
Packit 98cdb6
                                                       gint           i);
Packit 98cdb6
static AtkObject*   find_child_in_list                (GList          *list,
Packit 98cdb6
                                                       gint           index);
Packit 98cdb6
static void         check_cache                       (GailNotebook   *gail_notebook,
Packit 98cdb6
                                                       GtkNotebook    *notebook);
Packit 98cdb6
static void         reset_cache                       (GailNotebook   *gail_notebook,
Packit 98cdb6
                                                       gint           index);
Packit 98cdb6
static void         create_notebook_page_accessible   (GailNotebook   *gail_notebook,
Packit 98cdb6
                                                       GtkNotebook    *notebook,
Packit 98cdb6
                                                       gint           index,
Packit 98cdb6
                                                       gboolean       insert_before,
Packit 98cdb6
                                                       GList          *list);
Packit 98cdb6
static void         gail_notebook_child_parent_set    (GtkWidget      *widget,
Packit 98cdb6
                                                       GtkWidget      *old_parent,
Packit 98cdb6
                                                       gpointer       data);
Packit 98cdb6
static gboolean     gail_notebook_focus_cb            (GtkWidget      *widget,
Packit 98cdb6
                                                       GtkDirectionType type);
Packit 98cdb6
static gboolean     gail_notebook_check_focus_tab     (gpointer       data);
Packit 98cdb6
static void         gail_notebook_destroyed           (gpointer       data);
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE_WITH_CODE (GailNotebook, gail_notebook, GAIL_TYPE_CONTAINER,
Packit 98cdb6
                         G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_class_init (GailNotebookClass *klass)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit 98cdb6
  AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
Packit 98cdb6
  GailWidgetClass *widget_class;
Packit 98cdb6
  GailContainerClass *container_class;
Packit 98cdb6
Packit 98cdb6
  widget_class = (GailWidgetClass*)klass;
Packit 98cdb6
  container_class = (GailContainerClass*)klass;
Packit 98cdb6
Packit 98cdb6
  gobject_class->finalize = gail_notebook_finalize;
Packit 98cdb6
Packit 98cdb6
  widget_class->notify_gtk = gail_notebook_real_notify_gtk;
Packit 98cdb6
Packit 98cdb6
  class->ref_child = gail_notebook_ref_child;
Packit 98cdb6
  class->initialize = gail_notebook_real_initialize;
Packit 98cdb6
  /*
Packit 98cdb6
   * We do not provide an implementation of get_n_children
Packit 98cdb6
   * as the implementation in GailContainer returns the correct
Packit 98cdb6
   * number of children.
Packit 98cdb6
   */
Packit 98cdb6
  container_class->remove_gtk = gail_notebook_real_remove_gtk;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_init (GailNotebook      *notebook)
Packit 98cdb6
{
Packit 98cdb6
  notebook->page_cache = NULL;
Packit 98cdb6
  notebook->selected_page = -1;
Packit 98cdb6
  notebook->focus_tab_page = -1;
Packit 98cdb6
  notebook->remove_index = -1;
Packit 98cdb6
  notebook->idle_focus_id = 0;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static AtkObject*
Packit 98cdb6
gail_notebook_ref_child (AtkObject      *obj,
Packit 98cdb6
                         gint           i)
Packit 98cdb6
{
Packit 98cdb6
  AtkObject *accessible = NULL;
Packit 98cdb6
  GailNotebook *gail_notebook;
Packit 98cdb6
  GtkNotebook *gtk_notebook;
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
 
Packit 98cdb6
  widget = GTK_ACCESSIBLE (obj)->widget;
Packit 98cdb6
  if (widget == NULL)
Packit 98cdb6
    /*
Packit 98cdb6
     * State is defunct
Packit 98cdb6
     */
Packit 98cdb6
    return NULL;
Packit 98cdb6
Packit 98cdb6
  gail_notebook = GAIL_NOTEBOOK (obj);
Packit 98cdb6
  
Packit 98cdb6
  gtk_notebook = GTK_NOTEBOOK (widget);
Packit 98cdb6
  
Packit 98cdb6
  if (gail_notebook->page_count < g_list_length (gtk_notebook->children))
Packit 98cdb6
    check_cache (gail_notebook, gtk_notebook);
Packit 98cdb6
Packit 98cdb6
  accessible = find_child_in_list (gail_notebook->page_cache, i);
Packit 98cdb6
Packit 98cdb6
  if (accessible != NULL)
Packit 98cdb6
    g_object_ref (accessible);
Packit 98cdb6
Packit 98cdb6
  return accessible;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_page_added (GtkNotebook *gtk_notebook,
Packit 98cdb6
                          GtkWidget   *child,
Packit 98cdb6
                          guint        page_num,
Packit 98cdb6
                          gpointer     data)
Packit 98cdb6
{
Packit 98cdb6
  AtkObject *atk_obj;
Packit 98cdb6
  GailNotebook *notebook;
Packit 98cdb6
Packit 98cdb6
  atk_obj = gtk_widget_get_accessible (GTK_WIDGET (gtk_notebook));
Packit 98cdb6
  notebook = GAIL_NOTEBOOK (atk_obj);
Packit 98cdb6
  create_notebook_page_accessible (notebook, gtk_notebook, page_num, FALSE, NULL);
Packit 98cdb6
  notebook->page_count++;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_real_initialize (AtkObject *obj,
Packit 98cdb6
                               gpointer  data)
Packit 98cdb6
{
Packit 98cdb6
  GailNotebook *notebook;
Packit 98cdb6
  GtkNotebook *gtk_notebook;
Packit 98cdb6
  gint i;
Packit 98cdb6
Packit 98cdb6
  ATK_OBJECT_CLASS (gail_notebook_parent_class)->initialize (obj, data);
Packit 98cdb6
Packit 98cdb6
  notebook = GAIL_NOTEBOOK (obj);
Packit 98cdb6
  gtk_notebook = GTK_NOTEBOOK (data);
Packit 98cdb6
  for (i = 0; i < g_list_length (gtk_notebook->children); i++)
Packit 98cdb6
    {
Packit 98cdb6
      create_notebook_page_accessible (notebook, gtk_notebook, i, FALSE, NULL);
Packit 98cdb6
    }
Packit 98cdb6
  notebook->page_count = i;
Packit 98cdb6
  notebook->selected_page = gtk_notebook_get_current_page (gtk_notebook);
Packit 98cdb6
  if (gtk_notebook->focus_tab && gtk_notebook->focus_tab->data)
Packit 98cdb6
    {
Packit 98cdb6
      notebook->focus_tab_page = g_list_index (gtk_notebook->children, gtk_notebook->focus_tab->data);
Packit 98cdb6
    }
Packit 98cdb6
  g_signal_connect (gtk_notebook,
Packit 98cdb6
                    "focus",
Packit 98cdb6
                    G_CALLBACK (gail_notebook_focus_cb),
Packit 98cdb6
                    NULL);
Packit 98cdb6
  g_signal_connect (gtk_notebook,
Packit 98cdb6
                    "page-added",
Packit 98cdb6
                    G_CALLBACK (gail_notebook_page_added),
Packit 98cdb6
                    NULL);
Packit 98cdb6
  g_object_weak_ref (G_OBJECT(gtk_notebook),
Packit 98cdb6
                     (GWeakNotify) gail_notebook_destroyed,
Packit 98cdb6
                     obj);                     
Packit 98cdb6
Packit 98cdb6
  obj->role = ATK_ROLE_PAGE_TAB_LIST;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_real_notify_gtk (GObject           *obj,
Packit 98cdb6
                               GParamSpec        *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
  AtkObject* atk_obj;
Packit 98cdb6
Packit 98cdb6
  widget = GTK_WIDGET (obj);
Packit 98cdb6
  atk_obj = gtk_widget_get_accessible (widget);
Packit 98cdb6
Packit 98cdb6
  if (strcmp (pspec->name, "page") == 0)
Packit 98cdb6
    {
Packit 98cdb6
      gint page_num, old_page_num;
Packit 98cdb6
      gint focus_page_num = 0;
Packit 98cdb6
      gint old_focus_page_num;
Packit 98cdb6
      GailNotebook *gail_notebook;
Packit 98cdb6
      GtkNotebook *gtk_notebook;
Packit 98cdb6
     
Packit 98cdb6
      gail_notebook = GAIL_NOTEBOOK (atk_obj);
Packit 98cdb6
      gtk_notebook = GTK_NOTEBOOK (widget);
Packit 98cdb6
     
Packit 98cdb6
      if (gail_notebook->page_count < g_list_length (gtk_notebook->children))
Packit 98cdb6
       check_cache (gail_notebook, gtk_notebook);
Packit 98cdb6
      /*
Packit 98cdb6
       * Notify SELECTED state change for old and new page
Packit 98cdb6
       */
Packit 98cdb6
      old_page_num = gail_notebook->selected_page;
Packit 98cdb6
      page_num = gtk_notebook_get_current_page (gtk_notebook);
Packit 98cdb6
      gail_notebook->selected_page = page_num;
Packit 98cdb6
      old_focus_page_num = gail_notebook->focus_tab_page;
Packit 98cdb6
      if (gtk_notebook->focus_tab && gtk_notebook->focus_tab->data)
Packit 98cdb6
        {
Packit 98cdb6
          focus_page_num = g_list_index (gtk_notebook->children, gtk_notebook->focus_tab->data);
Packit 98cdb6
          gail_notebook->focus_tab_page = focus_page_num;
Packit 98cdb6
        }
Packit 98cdb6
    
Packit 98cdb6
      if (page_num != old_page_num)
Packit 98cdb6
        {
Packit 98cdb6
          AtkObject *obj;
Packit 98cdb6
Packit 98cdb6
          if (old_page_num != -1)
Packit 98cdb6
            {
Packit 98cdb6
              obj = gail_notebook_ref_child (atk_obj, old_page_num);
Packit 98cdb6
              if (obj)
Packit 98cdb6
                {
Packit 98cdb6
                  atk_object_notify_state_change (obj,
Packit 98cdb6
                                                  ATK_STATE_SELECTED,
Packit 98cdb6
                                                  FALSE);
Packit 98cdb6
                  g_object_unref (obj);
Packit 98cdb6
                }
Packit 98cdb6
            }
Packit 98cdb6
          obj = gail_notebook_ref_child (atk_obj, page_num);
Packit 98cdb6
          if (obj)
Packit 98cdb6
            {
Packit 98cdb6
              atk_object_notify_state_change (obj,
Packit 98cdb6
                                              ATK_STATE_SELECTED,
Packit 98cdb6
                                              TRUE);
Packit 98cdb6
              g_object_unref (obj);
Packit 98cdb6
              /*
Packit 98cdb6
               * The page which is being displayed has changed but there is
Packit 98cdb6
               * no need to tell the focus tracker as the focus page will also 
Packit 98cdb6
               * change or a widget in the page will receive focus if the
Packit 98cdb6
               * Notebook does not have tabs.
Packit 98cdb6
               */
Packit 98cdb6
            }
Packit 98cdb6
          g_signal_emit_by_name (atk_obj, "selection_changed");
Packit 98cdb6
          g_signal_emit_by_name (atk_obj, "visible_data_changed");
Packit 98cdb6
        }
Packit 98cdb6
      if (gtk_notebook_get_show_tabs (gtk_notebook) &&
Packit 98cdb6
         (focus_page_num != old_focus_page_num))
Packit 98cdb6
        {
Packit 98cdb6
          if (gail_notebook->idle_focus_id)
Packit 98cdb6
            g_source_remove (gail_notebook->idle_focus_id);
Packit 98cdb6
          gail_notebook->idle_focus_id = gdk_threads_add_idle (gail_notebook_check_focus_tab, atk_obj);
Packit 98cdb6
        }
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    GAIL_WIDGET_CLASS (gail_notebook_parent_class)->notify_gtk (obj, pspec);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_finalize (GObject            *object)
Packit 98cdb6
{
Packit 98cdb6
  GailNotebook *notebook = GAIL_NOTEBOOK (object);
Packit 98cdb6
  GList *list;
Packit 98cdb6
Packit 98cdb6
  /*
Packit 98cdb6
   * Get rid of the GailNotebookPage objects which we have cached.
Packit 98cdb6
   */
Packit 98cdb6
  list = notebook->page_cache;
Packit 98cdb6
  if (list != NULL)
Packit 98cdb6
    {
Packit 98cdb6
      while (list)
Packit 98cdb6
        {
Packit 98cdb6
          g_object_unref (list->data);
Packit 98cdb6
          list = list->next;
Packit 98cdb6
        }
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  g_list_free (notebook->page_cache);
Packit 98cdb6
Packit 98cdb6
  if (notebook->idle_focus_id)
Packit 98cdb6
    g_source_remove (notebook->idle_focus_id);
Packit 98cdb6
Packit 98cdb6
  G_OBJECT_CLASS (gail_notebook_parent_class)->finalize (object);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
atk_selection_interface_init (AtkSelectionIface *iface)
Packit 98cdb6
{
Packit 98cdb6
  iface->add_selection = gail_notebook_add_selection;
Packit 98cdb6
  iface->ref_selection = gail_notebook_ref_selection;
Packit 98cdb6
  iface->get_selection_count = gail_notebook_get_selection_count;
Packit 98cdb6
  iface->is_child_selected = gail_notebook_is_child_selected;
Packit 98cdb6
  /*
Packit 98cdb6
   * The following don't make any sense for GtkNotebook widgets.
Packit 98cdb6
   * Unsupported AtkSelection interfaces:
Packit 98cdb6
   * clear_selection();
Packit 98cdb6
   * remove_selection();
Packit 98cdb6
   * select_all_selection();
Packit 98cdb6
   */
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * GtkNotebook only supports the selection of one page at a time. 
Packit 98cdb6
 * Selecting a page unselects any previous selection, so this 
Packit 98cdb6
 * changes the current selection instead of adding to it.
Packit 98cdb6
 */
Packit 98cdb6
static gboolean
Packit 98cdb6
gail_notebook_add_selection (AtkSelection *selection,
Packit 98cdb6
                             gint         i)
Packit 98cdb6
{
Packit 98cdb6
  GtkNotebook *notebook;
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
  
Packit 98cdb6
  widget =  GTK_ACCESSIBLE (selection)->widget;
Packit 98cdb6
  if (widget == NULL)
Packit 98cdb6
    /*
Packit 98cdb6
     * State is defunct
Packit 98cdb6
     */
Packit 98cdb6
    return FALSE;
Packit 98cdb6
  
Packit 98cdb6
  notebook = GTK_NOTEBOOK (widget);
Packit 98cdb6
  gtk_notebook_set_current_page (notebook, i);
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static AtkObject*
Packit 98cdb6
gail_notebook_ref_selection (AtkSelection *selection,
Packit 98cdb6
                             gint i)
Packit 98cdb6
{
Packit 98cdb6
  AtkObject *accessible;
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
  GtkNotebook *notebook;
Packit 98cdb6
  gint pagenum;
Packit 98cdb6
  
Packit 98cdb6
  /*
Packit 98cdb6
   * A note book can have only one selection.
Packit 98cdb6
   */
Packit 98cdb6
  gail_return_val_if_fail (i == 0, NULL);
Packit 98cdb6
  g_return_val_if_fail (GAIL_IS_NOTEBOOK (selection), NULL);
Packit 98cdb6
  
Packit 98cdb6
  widget = GTK_ACCESSIBLE (selection)->widget;
Packit 98cdb6
  if (widget == NULL)
Packit 98cdb6
    /* State is defunct */
Packit 98cdb6
	return NULL;
Packit 98cdb6
  
Packit 98cdb6
  notebook = GTK_NOTEBOOK (widget);
Packit 98cdb6
  pagenum = gtk_notebook_get_current_page (notebook);
Packit 98cdb6
  gail_return_val_if_fail (pagenum != -1, NULL);
Packit 98cdb6
  accessible = gail_notebook_ref_child (ATK_OBJECT (selection), pagenum);
Packit 98cdb6
Packit 98cdb6
  return accessible;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * Always return 1 because there can only be one page
Packit 98cdb6
 * selected at any time
Packit 98cdb6
 */
Packit 98cdb6
static gint
Packit 98cdb6
gail_notebook_get_selection_count (AtkSelection *selection)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
  GtkNotebook *notebook;
Packit 98cdb6
  
Packit 98cdb6
  widget = GTK_ACCESSIBLE (selection)->widget;
Packit 98cdb6
  if (widget == NULL)
Packit 98cdb6
    /*
Packit 98cdb6
     * State is defunct
Packit 98cdb6
     */
Packit 98cdb6
    return 0;
Packit 98cdb6
Packit 98cdb6
  notebook = GTK_NOTEBOOK (widget);
Packit 98cdb6
  if (notebook == NULL || gtk_notebook_get_current_page (notebook) == -1)
Packit 98cdb6
    return 0;
Packit 98cdb6
  else
Packit 98cdb6
    return 1;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gail_notebook_is_child_selected (AtkSelection *selection,
Packit 98cdb6
                                 gint i)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
  GtkNotebook *notebook;
Packit 98cdb6
  gint pagenumber;
Packit 98cdb6
Packit 98cdb6
  widget = GTK_ACCESSIBLE (selection)->widget;
Packit 98cdb6
  if (widget == NULL)
Packit 98cdb6
    /* 
Packit 98cdb6
     * State is defunct
Packit 98cdb6
     */
Packit 98cdb6
    return FALSE;
Packit 98cdb6
Packit 98cdb6
  
Packit 98cdb6
  notebook = GTK_NOTEBOOK (widget);
Packit 98cdb6
  pagenumber = gtk_notebook_get_current_page(notebook);
Packit 98cdb6
Packit 98cdb6
  if (pagenumber == i)
Packit 98cdb6
    return TRUE;
Packit 98cdb6
  else
Packit 98cdb6
    return FALSE; 
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static AtkObject*
Packit 98cdb6
find_child_in_list (GList *list,
Packit 98cdb6
                    gint  index)
Packit 98cdb6
{
Packit 98cdb6
  AtkObject *obj = NULL;
Packit 98cdb6
Packit 98cdb6
  while (list)
Packit 98cdb6
    {
Packit 98cdb6
      if (GAIL_NOTEBOOK_PAGE (list->data)->index == index)
Packit 98cdb6
        {
Packit 98cdb6
          obj = ATK_OBJECT (list->data);
Packit 98cdb6
          break;
Packit 98cdb6
        }
Packit 98cdb6
      list = list->next;
Packit 98cdb6
    }
Packit 98cdb6
  return obj;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
check_cache (GailNotebook *gail_notebook,
Packit 98cdb6
             GtkNotebook  *notebook)
Packit 98cdb6
{
Packit 98cdb6
  GList *gtk_list;
Packit 98cdb6
  GList *gail_list;
Packit 98cdb6
  gint i;
Packit 98cdb6
Packit 98cdb6
  gtk_list = notebook->children;
Packit 98cdb6
  gail_list = gail_notebook->page_cache;
Packit 98cdb6
Packit 98cdb6
  i = 0;
Packit 98cdb6
  while (gtk_list)
Packit 98cdb6
    {
Packit 98cdb6
      if (!gail_list)
Packit 98cdb6
        {
Packit 98cdb6
          create_notebook_page_accessible (gail_notebook, notebook, i, FALSE, NULL);
Packit 98cdb6
        }
Packit 98cdb6
      else if (GAIL_NOTEBOOK_PAGE (gail_list->data)->page != gtk_list->data)
Packit 98cdb6
        {
Packit 98cdb6
          create_notebook_page_accessible (gail_notebook, notebook, i, TRUE, gail_list);
Packit 98cdb6
        }
Packit 98cdb6
      else
Packit 98cdb6
        {
Packit 98cdb6
          gail_list = gail_list->next;
Packit 98cdb6
        }
Packit 98cdb6
      i++;
Packit 98cdb6
      gtk_list = gtk_list->next;
Packit 98cdb6
    }
Packit 98cdb6
  gail_notebook->page_count = i;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
reset_cache (GailNotebook *gail_notebook,
Packit 98cdb6
             gint         index)
Packit 98cdb6
{
Packit 98cdb6
  GList *l;
Packit 98cdb6
Packit 98cdb6
  for (l = gail_notebook->page_cache; l; l = l->next)
Packit 98cdb6
    {
Packit 98cdb6
      if (GAIL_NOTEBOOK_PAGE (l->data)->index > index)
Packit 98cdb6
        GAIL_NOTEBOOK_PAGE (l->data)->index -= 1;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
create_notebook_page_accessible (GailNotebook *gail_notebook,
Packit 98cdb6
                                 GtkNotebook  *notebook,
Packit 98cdb6
                                 gint         index,
Packit 98cdb6
                                 gboolean     insert_before,
Packit 98cdb6
                                 GList        *list)
Packit 98cdb6
{
Packit 98cdb6
  AtkObject *obj;
Packit 98cdb6
Packit 98cdb6
  obj = gail_notebook_page_new (notebook, index);
Packit 98cdb6
  g_object_ref (obj);
Packit 98cdb6
  if (insert_before)
Packit 98cdb6
    gail_notebook->page_cache = g_list_insert_before (gail_notebook->page_cache, list, obj);
Packit 98cdb6
  else
Packit 98cdb6
    gail_notebook->page_cache = g_list_append (gail_notebook->page_cache, obj);
Packit 98cdb6
  g_signal_connect (gtk_notebook_get_nth_page (notebook, index), 
Packit 98cdb6
                    "parent_set",
Packit 98cdb6
                    G_CALLBACK (gail_notebook_child_parent_set),
Packit 98cdb6
                    obj);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_child_parent_set (GtkWidget *widget,
Packit 98cdb6
                                GtkWidget *old_parent,
Packit 98cdb6
                                gpointer   data)
Packit 98cdb6
{
Packit 98cdb6
  GailNotebook *gail_notebook;
Packit 98cdb6
Packit 98cdb6
  gail_return_if_fail (old_parent != NULL);
Packit 98cdb6
  gail_notebook = GAIL_NOTEBOOK (gtk_widget_get_accessible (old_parent));
Packit 98cdb6
  gail_notebook->remove_index = GAIL_NOTEBOOK_PAGE (data)->index;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gint
Packit 98cdb6
gail_notebook_real_remove_gtk (GtkContainer *container,
Packit 98cdb6
                               GtkWidget    *widget,
Packit 98cdb6
                               gpointer      data)    
Packit 98cdb6
{
Packit 98cdb6
  GailNotebook *gail_notebook;
Packit 98cdb6
  AtkObject *obj;
Packit 98cdb6
  gint index;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (container != NULL, 1);
Packit 98cdb6
  gail_notebook = GAIL_NOTEBOOK (gtk_widget_get_accessible (GTK_WIDGET (container)));
Packit 98cdb6
  index = gail_notebook->remove_index;
Packit 98cdb6
  gail_notebook->remove_index = -1;
Packit 98cdb6
Packit 98cdb6
  obj = find_child_in_list (gail_notebook->page_cache, index);
Packit 98cdb6
  g_return_val_if_fail (obj, 1);
Packit 98cdb6
  gail_notebook->page_cache = g_list_remove (gail_notebook->page_cache, obj);
Packit 98cdb6
  gail_notebook->page_count -= 1;
Packit 98cdb6
  reset_cache (gail_notebook, index);
Packit 98cdb6
  g_signal_emit_by_name (gail_notebook,
Packit 98cdb6
                         "children_changed::remove",
Packit 98cdb6
                          GAIL_NOTEBOOK_PAGE (obj)->index, 
Packit 98cdb6
                          obj, NULL);
Packit 98cdb6
  g_object_unref (obj);
Packit 98cdb6
  return 1;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gail_notebook_focus_cb (GtkWidget      *widget,
Packit 98cdb6
                        GtkDirectionType type)
Packit 98cdb6
{
Packit 98cdb6
  AtkObject *atk_obj = gtk_widget_get_accessible (widget);
Packit 98cdb6
  GailNotebook *gail_notebook = GAIL_NOTEBOOK (atk_obj);
Packit 98cdb6
Packit 98cdb6
  switch (type)
Packit 98cdb6
    {
Packit 98cdb6
    case GTK_DIR_LEFT:
Packit 98cdb6
    case GTK_DIR_RIGHT:
Packit 98cdb6
      if (gail_notebook->idle_focus_id == 0)
Packit 98cdb6
        gail_notebook->idle_focus_id = gdk_threads_add_idle (gail_notebook_check_focus_tab, atk_obj);
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gail_notebook_check_focus_tab (gpointer data)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
  AtkObject *atk_obj;
Packit 98cdb6
  gint focus_page_num, old_focus_page_num;
Packit 98cdb6
  GailNotebook *gail_notebook;
Packit 98cdb6
  GtkNotebook *gtk_notebook;
Packit 98cdb6
Packit 98cdb6
  atk_obj = ATK_OBJECT (data);
Packit 98cdb6
  gail_notebook = GAIL_NOTEBOOK (atk_obj);
Packit 98cdb6
  widget = GTK_ACCESSIBLE (atk_obj)->widget;
Packit 98cdb6
Packit 98cdb6
  gtk_notebook = GTK_NOTEBOOK (widget);
Packit 98cdb6
Packit 98cdb6
  gail_notebook->idle_focus_id = 0;
Packit 98cdb6
Packit 98cdb6
  if (!gtk_notebook->focus_tab)
Packit 98cdb6
    return FALSE;
Packit 98cdb6
Packit 98cdb6
  old_focus_page_num = gail_notebook->focus_tab_page;
Packit 98cdb6
  focus_page_num = g_list_index (gtk_notebook->children, gtk_notebook->focus_tab->data);
Packit 98cdb6
  gail_notebook->focus_tab_page = focus_page_num;
Packit 98cdb6
  if (old_focus_page_num != focus_page_num)
Packit 98cdb6
    {
Packit 98cdb6
      AtkObject *obj;
Packit 98cdb6
Packit 98cdb6
      obj = atk_object_ref_accessible_child (atk_obj, focus_page_num);
Packit 98cdb6
      atk_focus_tracker_notify (obj);
Packit 98cdb6
      g_object_unref (obj);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_notebook_destroyed (gpointer data)
Packit 98cdb6
{
Packit 98cdb6
  GailNotebook *gail_notebook = GAIL_NOTEBOOK (data);
Packit 98cdb6
Packit 98cdb6
  if (gail_notebook->idle_focus_id)
Packit 98cdb6
    {
Packit 98cdb6
      g_source_remove (gail_notebook->idle_focus_id);
Packit 98cdb6
      gail_notebook->idle_focus_id = 0;
Packit 98cdb6
    }
Packit 98cdb6
}