Exemple #1
0
static gunichar 
gail_item_get_character_at_offset (AtkText *text,
                                   gint	   offset)
{
  GtkWidget *widget;
  GtkWidget *label;
  const gchar *string;
  gchar *index;

  widget = GTK_ACCESSIBLE (text)->widget;
  if (widget == NULL)
    /* State is defunct */
    return '\0';

  label = get_label_from_container (widget);

  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);
}
Exemple #2
0
static GtkWidget *
get_label_from_container (GtkWidget *container)
{
  GtkWidget *label;
  GList *children, *tmp_list;

  if (!GTK_IS_CONTAINER (container))
    return NULL;

  children = gtk_container_get_children (GTK_CONTAINER (container));
  label = NULL;

  for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next)
    {
      if (GTK_IS_LABEL (tmp_list->data))
        {
          label = tmp_list->data;
          break;
        }
      else if (GTK_IS_CELL_VIEW (tmp_list->data))
        {
          label = tmp_list->data;
          break;
        }
      else if (GTK_IS_BOX (tmp_list->data))
        {
          label = get_label_from_container (GTK_WIDGET (tmp_list->data));
          if (label)
            break;
        }
    }
  g_list_free (children);

  return label;
}
Exemple #3
0
static GtkWidget*
get_label_from_container (GtkWidget *container)
{
  GtkWidget *label;
  GList *children, *tmp_list;

  if (!GTK_IS_CONTAINER (container))
    return NULL;
 
  children = gtk_container_get_children (GTK_CONTAINER (container));
  label = NULL;

  for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next) 
    {
      if (GTK_IS_LABEL (tmp_list->data))
	{
           label = tmp_list->data;
           break;
	}
      /*
       * Get label from menu item in desktop background preferences
       * option menu. See bug #144084.
       */
      else if (GTK_IS_BOX (tmp_list->data))
        {
           label = get_label_from_container (GTK_WIDGET (tmp_list->data));
           if (label)
             break;
        }
    }
  g_list_free (children);

  return label;
}
Exemple #4
0
static void
gail_item_get_character_extents (AtkText      *text,
				 gint         offset,
		                 gint         *x,
                    		 gint 	      *y,
                                 gint 	      *width,
                                 gint 	      *height,
			         AtkCoordType coords)
{
  GtkWidget *widget;
  GtkWidget *label;
  PangoRectangle char_rect;
  gint index, x_layout, y_layout;
  const gchar *label_text;
 
  widget = GTK_ACCESSIBLE (text)->widget;

  if (widget == NULL)
    /* State is defunct */
    return;

  label = get_label_from_container (widget);

  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);
} 
Exemple #5
0
static gchar*
gail_item_get_text_after_offset (AtkText         *text,
				 gint            offset,
				 AtkTextBoundary boundary_type,
				 gint            *start_offset,
				 gint            *end_offset)
{
  GtkWidget *widget;
  GtkWidget *label;
  GailItem *item;

  widget = GTK_ACCESSIBLE (text)->widget;
  
  if (widget == NULL)
  {
    /* State is defunct */
    return NULL;
  }
  
  /* Get label */
  label = get_label_from_container (widget);

  if (!GTK_IS_LABEL(label))
    return NULL;

  item = GAIL_ITEM (text);
  if (!item->textutil)
    gail_item_init_textutil (item, label);

  return gail_text_util_get_text (item->textutil,
                           gtk_label_get_layout (GTK_LABEL (label)), GAIL_AFTER_OFFSET, 
                           boundary_type, offset, start_offset, end_offset);
}
Exemple #6
0
static gchar*
gail_item_get_text (AtkText *text,
                    gint    start_pos,
                    gint    end_pos)
{
  GtkWidget *widget;
  GtkWidget *label;
  GailItem *item;
  const gchar *label_text;

  widget = GTK_ACCESSIBLE (text)->widget;
  if (widget == NULL)
    /* State is defunct */
    return NULL;

  label = get_label_from_container (widget);

  if (!GTK_IS_LABEL (label))
    return NULL;

  item = GAIL_ITEM (text);
  if (!item->textutil) 
    gail_item_init_textutil (item, label);

  label_text = gtk_label_get_text (GTK_LABEL (label));

  if (label_text == NULL)
    return NULL;
  else
  {
    return gail_text_util_get_substring (item->textutil, 
                                         start_pos, end_pos);
  }
}
Exemple #7
0
static void
gail_item_real_initialize (AtkObject *obj,
                           gpointer	data)
{
  GailItem *item = GAIL_ITEM (obj);
  GtkWidget  *label;

  ATK_OBJECT_CLASS (parent_class)->initialize (obj, data);

  item->textutil = NULL;
  item->text = NULL;

  label = get_label_from_container (GTK_WIDGET (data));
  if (GTK_IS_LABEL (label))
    {
      if (GTK_WIDGET_MAPPED (label))
        gail_item_init_textutil (item, label);
      else
        g_signal_connect (label,
                          "map",
                          G_CALLBACK (gail_item_label_map_gtk),
                          item);
    }

  obj->role = ATK_ROLE_LIST_ITEM;
}
Exemple #8
0
static AtkAttributeSet*
gail_item_get_run_attributes (AtkText *text,
                              gint    offset,
                              gint    *start_offset,
	                      gint    *end_offset)
{
  GtkWidget *widget;
  GtkWidget *label;
  AtkAttributeSet *at_set = NULL;
  GtkJustification justify;
  GtkTextDirection dir;

  widget = GTK_ACCESSIBLE (text)->widget;
  if (widget == NULL)
    /* State is defunct */
    return NULL;

  label = get_label_from_container (widget);

  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;
}
Exemple #9
0
static gint
gail_item_get_character_count (AtkText *text)
{
  GtkWidget *widget;
  GtkWidget *label;

  widget = GTK_ACCESSIBLE (text)->widget;
  if (widget == NULL)
    /* State is defunct */
    return 0;

  label = get_label_from_container (widget);

  if (!GTK_IS_LABEL(label))
    return 0;

  return g_utf8_strlen (gtk_label_get_text (GTK_LABEL (label)), -1);
}
Exemple #10
0
static AtkAttributeSet*
gail_item_get_default_attributes (AtkText *text)
{
  GtkWidget *widget;
  GtkWidget *label;
  AtkAttributeSet *at_set = NULL;

  widget = GTK_ACCESSIBLE (text)->widget;
  if (widget == NULL)
    /* State is defunct */
    return NULL;

  label = get_label_from_container (widget);

  if (!GTK_IS_LABEL(label))
    return NULL;

  at_set = gail_misc_get_default_attributes (at_set,
                                             gtk_label_get_layout (GTK_LABEL (label)),
                                             widget);
  return at_set;
}
Exemple #11
0
static gint 
gail_item_get_offset_at_point (AtkText      *text,
                               gint         x,
                               gint         y,
			       AtkCoordType coords)
{ 
  GtkWidget *widget;
  GtkWidget *label;
  gint index, x_layout, y_layout;
  const gchar *label_text;

  widget = GTK_ACCESSIBLE (text)->widget;
  if (widget == NULL)
    /* State is defunct */
    return -1;

  label = get_label_from_container (widget);

  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);  
}
Exemple #12
0
static const gchar *
gtk_menu_item_accessible_get_name (AtkObject *obj)
{
  const gchar *name;
  GtkWidget *widget;
  GtkWidget *label;
  GtkMenuItemAccessible *accessible;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
  if (widget == NULL)
    return NULL;

  name = ATK_OBJECT_CLASS (_gtk_menu_item_accessible_parent_class)->get_name (obj);
  if (name)
    return name;

  accessible = GTK_MENU_ITEM_ACCESSIBLE (obj);
  label = get_label_from_container (widget);

  g_free (accessible->text);
  accessible->text = get_text_from_label_widget (label);

  return accessible->text;
}
Exemple #13
0
static G_CONST_RETURN gchar*
gail_item_get_name (AtkObject *obj)
{
  G_CONST_RETURN gchar* name;

  g_return_val_if_fail (GAIL_IS_ITEM (obj), NULL);

  name = ATK_OBJECT_CLASS (parent_class)->get_name (obj);
  if (name == NULL)
    {
      /*
       * Get the label child
       */
      GtkWidget *widget;
      GtkWidget *label;

      widget = GTK_ACCESSIBLE (obj)->widget;
      if (widget == NULL)
        /*
         * State is defunct
         */
        return NULL;

      label = get_label_from_container (widget);
      if (GTK_IS_LABEL (label))
	return gtk_label_get_text (GTK_LABEL(label));
      /*
       * If we have a menu item in a menu attached to a GtkOptionMenu
       * the label of the selected item is detached from the menu item
       */
      else if (GTK_IS_MENU_ITEM (widget))
        {
          GtkWidget *parent;
          GtkWidget *attach;
          GList *list;
          AtkObject *parent_obj;
          gint index;

          parent = gtk_widget_get_parent (widget);
          if (GTK_IS_MENU (parent))
            {
              attach = gtk_menu_get_attach_widget (GTK_MENU (parent)); 

              if (GTK_IS_OPTION_MENU (attach))
                {
                  label = get_label_from_container (attach);
                  if (GTK_IS_LABEL (label))
	            return gtk_label_get_text (GTK_LABEL(label));
                }
              list = gtk_container_get_children (GTK_CONTAINER (parent));
              index = g_list_index (list, widget);

              if (index < 0 || index > g_list_length (list))
                {
                  g_list_free (list);
                  return NULL;
                }
              g_list_free (list);

              parent_obj = atk_object_get_parent (gtk_widget_get_accessible (parent));
              if (GTK_IS_ACCESSIBLE (parent_obj))
                {
                  parent = GTK_ACCESSIBLE (parent_obj)->widget;
                  if (GTK_IS_COMBO_BOX (parent))
                    {
                      GtkTreeModel *model;
                      GtkTreeIter iter;
                      GailItem *item;
                      gint n_columns, i;

                      model = gtk_combo_box_get_model (GTK_COMBO_BOX (parent));                       
                      item = GAIL_ITEM (obj);
                      if (gtk_tree_model_iter_nth_child (model, &iter, NULL, index))
                        {
                          n_columns = gtk_tree_model_get_n_columns (model);
                          for (i = 0; i < n_columns; i++)
                            {
                              GValue value = { 0, };

                               gtk_tree_model_get_value (model, &iter, i, &value);
                               if (G_VALUE_HOLDS_STRING (&value))
                                 {
				   g_free (item->text);
                                   item->text =  (gchar *) g_value_dup_string (&value);
                                   g_value_unset (&value);
                                   break;
                                 }
                            }
                        }
                      name = item->text;
                    }
                }
            }
        }
    }
  return name;
}