Example #1
0
static VALUE
label_get_selection_bounds(VALUE self)
{
    gint start, end;
    gboolean ret = gtk_label_get_selection_bounds(_SELF(self), &start, &end);
    return ret ? rb_ary_new3(2, INT2NUM(start), INT2NUM(end)) : Qnil;
}
Example #2
0
File: gaillabel.c Project: BYC/gtk
static gchar*
gail_label_get_selection (AtkText *text,
			  gint    selection_num,
                          gint    *start_pos,
                          gint    *end_pos)
{
  GtkWidget *widget;
  GtkLabel  *label;

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

  label = GTK_LABEL (widget);

 /* Only let the user get the selection if one is set, and if the
  * selection_num is 0.
  */
  if (!gtk_label_get_selectable( label) || selection_num != 0)
     return NULL;

  if (gtk_label_get_selection_bounds (label, start_pos, end_pos))
    {
      const gchar* label_text = gtk_label_get_text (label);
    
      if (label_text == NULL)
        return 0;
      else
        return gail_text_util_get_substring (GAIL_LABEL (text)->textutil, 
                                             *start_pos, *end_pos);
    }
  else 
    return NULL;
}
Example #3
0
File: gaillabel.c Project: BYC/gtk
static gboolean
gail_label_set_selection (AtkText *text,
			  gint	  selection_num,
                          gint    start_pos,
                          gint    end_pos)
{
  GtkWidget *widget;
  GtkLabel  *label;
  gint start, end;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
  if (widget == NULL)
    /* State is defunct */
    return FALSE;

  if (selection_num != 0)
     return FALSE;

  label = GTK_LABEL (widget);

  if (!gtk_label_get_selectable (label))
     return FALSE;

  if (gtk_label_get_selection_bounds (label, &start, &end))
    {
      gtk_label_select_region (label, start_pos, end_pos);
      return TRUE;
    }
  else
    return FALSE;
}
Example #4
0
static gboolean
gail_label_remove_selection (AtkText *text,
                             gint    selection_num)
{
  GtkWidget *widget;
  GtkLabel  *label;
  gint start, end;

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

  if (selection_num != 0)
     return FALSE;

  label = GTK_LABEL (widget);

  if (!gtk_label_get_selectable (label))
     return FALSE;

  if (gtk_label_get_selection_bounds (label, &start, &end))
    {
      gtk_label_select_region (label, 0, 0);
      return TRUE;
    }
  else
    return FALSE;
}
Example #5
0
static gboolean
gtk_label_accessible_remove_selection (AtkText *text,
                                       gint     selection_num)
{
  GtkWidget *widget;
  GtkLabel  *label;
  gint start, end;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
  if (widget == NULL)
    return FALSE;

  if (selection_num != 0)
     return FALSE;

  label = GTK_LABEL (widget);

  if (!gtk_label_get_selectable (label))
     return FALSE;

  if (gtk_label_get_selection_bounds (label, &start, &end))
    {
      gtk_label_select_region (label, end, end);
      return TRUE;
    }
  else
    return FALSE;
}
Example #6
0
static gchar *
gtk_label_accessible_get_selection (AtkText *atk_text,
                                    gint     selection_num,
                                    gint    *start_pos,
                                    gint    *end_pos)
{
  GtkWidget *widget;
  GtkLabel  *label;

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

  if (selection_num != 0)
    return NULL;

  label = GTK_LABEL (widget);

  if (gtk_label_get_selection_bounds (label, start_pos, end_pos))
    {
      const gchar *text;

      text = gtk_label_get_text (label);

      if (text)
        return g_utf8_substring (text, *start_pos, *end_pos);
    }

  return NULL;
}
Example #7
0
CAMLprim value ml_gtk_label_get_selection_bounds (value label)
{
  gint s, e;
  value r;
  if (gtk_label_get_selection_bounds (GtkLabel_val(label), &s, &e)) {
    r = alloc_small(2, 0);
    Field(r, 0) = Val_int(s);
    Field(r, 1) = Val_int(e);
    r = ml_some(r);
  }
  else
    r = Val_unit;
  return r;
}
Example #8
0
static gint
gtk_label_accessible_get_n_selections (AtkText *text)
{
  GtkWidget *widget;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
  if (widget == NULL)
    return 0;

  if (gtk_label_get_selection_bounds (GTK_LABEL (widget), NULL, NULL))
    return 1;

  return 0;
}
Example #9
0
File: gaillabel.c Project: BYC/gtk
static gint
gail_label_get_n_selections (AtkText *text)
{
  GtkWidget *widget;
  GtkLabel  *label;
  gint start, end;

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

  label = GTK_LABEL (widget);

  if (!gtk_label_get_selectable (label))
     return 0;

  if (gtk_label_get_selection_bounds (label, &start, &end))
     return 1;
  else 
     return 0;
}
Example #10
0
static gboolean
check_for_selection_change (GtkLabelAccessible *accessible,
                            GtkLabel           *label)
{
  gboolean ret_val = FALSE;
  gint start, end;

  if (gtk_label_get_selection_bounds (label, &start, &end))
    {
      if (end != accessible->cursor_position ||
          start != accessible->selection_bound)
        ret_val = TRUE;
    }
  else
    {
      ret_val = (accessible->cursor_position != accessible->selection_bound);
    }

  accessible->cursor_position = end;
  accessible->selection_bound = start;

  return ret_val;
}
Example #11
0
File: gaillabel.c Project: BYC/gtk
static void
gail_label_real_notify_gtk (GObject           *obj,
                            GParamSpec        *pspec)
{
  GtkWidget *widget = GTK_WIDGET (obj);
  AtkObject* atk_obj = gtk_widget_get_accessible (widget);
  GtkLabel *label;
  GailLabel *gail_label;
  GObject *gail_obj;
  AtkObject *top_level;
  AtkObject *temp_obj;

  gail_label = GAIL_LABEL (atk_obj);

  if (strcmp (pspec->name, "label") == 0)
    {
     /* 
      * We may get a label change for a label which is not attached to an
      * application. We wait until the toplevel window is created before
      * emitting the notification.
      *
      * This happens when [Ctrl+]Alt+Tab is pressed in metacity
      */
      if (!gail_label->has_top_level)
        {
          temp_obj = atk_obj;
          top_level = NULL;
          while (temp_obj)
            {
              top_level = temp_obj;
              temp_obj = atk_object_get_parent (top_level);
            }
          if (atk_object_get_role (top_level) != ATK_ROLE_APPLICATION)
            {
              if (gail_label->window_create_handler == 0 && 
                  GAIL_IS_WINDOW (top_level))
                gail_label->window_create_handler = g_signal_connect_after (top_level, "create", G_CALLBACK (window_created), atk_obj);
            }
          else
            gail_label->has_top_level = TRUE;
        }
      if (gail_label->has_top_level)
        notify_name_change (atk_obj);
    }
  else if (strcmp (pspec->name, "cursor-position") == 0)
    {
      gint start, end, tmp;
      gboolean text_caret_moved = FALSE;
      gboolean selection_changed = FALSE;

      gail_obj = G_OBJECT (atk_obj);
      label = GTK_LABEL (widget);

      if (gail_label->selection_bound != -1 && gail_label->selection_bound < gail_label->cursor_position)
        {
          tmp = gail_label->selection_bound;
          gail_label->selection_bound = gail_label->cursor_position;
          gail_label->cursor_position = tmp;
        }

      if (gtk_label_get_selection_bounds (label, &start, &end))
        {
          if (start != gail_label->cursor_position ||
              end != gail_label->selection_bound)
            {
              if (end != gail_label->selection_bound)
                {
                  gail_label->selection_bound = start;
                  gail_label->cursor_position = end;
                }
              else
                {
                  gail_label->selection_bound = end;
                  gail_label->cursor_position = start;
                }
              text_caret_moved = TRUE;
              if (start != end)
                selection_changed = TRUE;
            }
        }
      else 
        {
          if (gail_label->cursor_position != gail_label->selection_bound)
            selection_changed = TRUE;
          if (gtk_label_get_selectable (label))
            {
              if (gail_label->cursor_position != -1 && start != gail_label->cursor_position)
                text_caret_moved = TRUE;
              if (gail_label->selection_bound != -1 && end != gail_label->selection_bound)
                {
                  text_caret_moved = TRUE;
                  gail_label->cursor_position = end;
                  gail_label->selection_bound = start;
                }
              else
                {
                  gail_label->cursor_position = start;
                  gail_label->selection_bound = end;
                }
            }
          else
            {
              /* GtkLabel has become non selectable */

              gail_label->cursor_position = 0;
              gail_label->selection_bound = 0;
              text_caret_moved = TRUE;
            }

        }
        if (text_caret_moved)
          g_signal_emit_by_name (gail_obj, "text_caret_moved", 
                                 gail_label->cursor_position);
        if (selection_changed)
          g_signal_emit_by_name (gail_obj, "text_selection_changed");

    }
  else
    GAIL_WIDGET_CLASS (gail_label_parent_class)->notify_gtk (obj, pspec);
}