示例#1
0
文件: gaillabel.c 项目: 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;
}
示例#2
0
文件: reflect.c 项目: GNOME/vte
/*
 * Update the contents of the widget with the data from our contents array.
 */
static void
update_contents(AtkObject *obj, GtkWidget *widget)
{
	guint caret, i;
	GString *s;

	caret = (guint)atk_text_get_caret_offset(ATK_TEXT(obj));
	s = g_string_new(NULL);
	for (i = 0; i < contents->len; i++) {
		if (i == caret) {
			s = g_string_append(s, "[CARET]");
		}
		s = g_string_append_unichar(s,
					    g_array_index(contents,
							  gunichar,
							  i));
	}
	if (i == caret) {
		s = g_string_append(s, "[CARET]");
	}
	if (GTK_IS_LABEL(widget)) {
		gtk_label_set_text(GTK_LABEL(widget), s->str);
		gtk_label_set_selectable(GTK_LABEL(widget),
					 atk_text_get_n_selections(ATK_TEXT(obj)) > 0);
		if (gtk_label_get_selectable(GTK_LABEL(widget))) {
			int selection_start, selection_end;
			atk_text_get_selection(ATK_TEXT(obj), 0,
					       &selection_start,
					       &selection_end);
			gtk_label_select_region(GTK_LABEL(widget),
						selection_start, selection_end);
		}
	}
	g_string_free(s, TRUE);
}
示例#3
0
文件: gaillabel.c 项目: 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;
}
示例#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;
}
示例#5
0
文件: label.c 项目: Alexis-D/luakit
static gint
luaH_label_index(lua_State *L, luakit_token_t token)
{
    widget_t *w = luaH_checkwidget(L, 1);

    switch(token)
    {
      LUAKIT_WIDGET_INDEX_COMMON

      /* push class methods */
      PF_CASE(GET_ALIGNMENT,    luaH_label_get_alignment);
      PF_CASE(GET_PADDING,      luaH_label_get_padding);
      PF_CASE(SET_ALIGNMENT,    luaH_label_set_alignment);
      PF_CASE(SET_PADDING,      luaH_label_set_padding);
      PF_CASE(SET_WIDTH,        luaH_label_set_width);
      /* push string properties */
      PS_CASE(FG,               g_object_get_data(G_OBJECT(w->widget), "fg"))
      PS_CASE(FONT,             g_object_get_data(G_OBJECT(w->widget), "font"))
      PS_CASE(TEXT,             gtk_label_get_label(GTK_LABEL(w->widget)))
      /* push boolean properties */
      PB_CASE(SELECTABLE,       gtk_label_get_selectable(GTK_LABEL(w->widget)))

      default:
        break;
    }
    return 0;
}
示例#6
0
static gint
luaH_label_index(lua_State *L, widget_t *w, luakit_token_t token)
{
    switch(token) {
      LUAKIT_WIDGET_INDEX_COMMON(w)

      case L_TK_PADDING:
        return luaH_label_get_padding(L, w);

      case L_TK_ALIGN:
        return luaH_label_get_align(L, w);

      /* push string properties */
      PS_CASE(FG,               g_object_get_data(G_OBJECT(w->widget), "fg"))
      PS_CASE(FONT,             g_object_get_data(G_OBJECT(w->widget), "font"))
      PS_CASE(TEXT,             gtk_label_get_label(GTK_LABEL(w->widget)))
      /* push boolean properties */
      PB_CASE(SELECTABLE,       gtk_label_get_selectable(GTK_LABEL(w->widget)))
      /* push integer properties */
      PI_CASE(WIDTH,            gtk_label_get_width_chars(GTK_LABEL(w->widget)))

      default:
        break;
    }
    return 0;
}
示例#7
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;
}
示例#8
0
static int selectable_member(lua_State *L)
{
  lua_label label;
  luaA_to(L,lua_label,&label,1);
  if(lua_gettop(L) > 2) {
    gboolean selectable = lua_toboolean(L,3);
    gtk_label_set_selectable(GTK_LABEL(label->widget),selectable);
    return 0;
  }
  lua_pushboolean(L,gtk_label_get_selectable(GTK_LABEL(label->widget)));
  return 1;
}
示例#9
0
/* Edit->Copy */
void
action_copy(GtkAction *action, I7Document *document)
{
	GtkWidget *widget = gtk_window_get_focus(GTK_WINDOW(document));

	/* What actually happens depends on the type of widget that is focused */
	if(WEBKIT_IS_WEB_VIEW(widget))
		webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(widget));
	else if((GTK_IS_LABEL(widget) && gtk_label_get_selectable(GTK_LABEL(widget)))
		|| GTK_IS_ENTRY(widget) || GTK_IS_TEXT_VIEW(widget))
		g_signal_emit_by_name(widget, "copy-clipboard", NULL);
	else /* If we don't know how to copy from it, just copy from the source */
		g_signal_emit_by_name(i7_document_get_default_view(document), "copy-clipboard", NULL);
}
示例#10
0
/* Edit->Select All */
void
action_select_all(GtkAction *action, I7Document *document)
{
	GtkWidget *widget = gtk_window_get_focus(GTK_WINDOW(document));

	/* What actually happens depends on the type of widget that is focused */
	if(WEBKIT_IS_WEB_VIEW(widget))
		webkit_web_view_select_all(WEBKIT_WEB_VIEW(widget));
	else if(GTK_IS_LABEL(widget) && gtk_label_get_selectable(GTK_LABEL(widget)))
		gtk_label_select_region(GTK_LABEL(widget), 0, -1);
	else if(GTK_IS_EDITABLE(widget))
		gtk_editable_select_region(GTK_EDITABLE(widget), 0, -1);
	else if(GTK_IS_TEXT_VIEW(widget))
		g_signal_emit_by_name(widget, "select-all", TRUE, NULL);
	else /* If we don't know how to select it, just select all in the source */
		g_signal_emit_by_name(i7_document_get_default_view(document), "select-all", TRUE, NULL);
}
示例#11
0
static gboolean
gtk_label_accessible_set_caret_offset (AtkText *text,
                                       gint     offset)
{
  GtkWidget *widget;
  GtkLabel *label;

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

  label = GTK_LABEL (widget);

  if (!gtk_label_get_selectable (label))
    return FALSE;

  gtk_label_select_region (label, offset, offset);

  return TRUE;
}
示例#12
0
文件: gaillabel.c 项目: 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;
}
示例#13
0
文件: gaillabel.c 项目: BYC/gtk
static gboolean
gail_label_set_caret_offset (AtkText *text, 
                             gint    offset)
{
  GtkWidget *widget;
  GtkLabel  *label;

  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) &&
      offset >= 0 &&
      offset <= g_utf8_strlen (gtk_label_get_text (label), -1))
    {
      gtk_label_select_region (label, offset, offset);
      return TRUE;
    }
  else
    return FALSE;
}
示例#14
0
文件: gaillabel.c 项目: 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);
}
示例#15
0
void
gb_label_write_standard_source (GtkWidget * widget,
				GbWidgetWriteSourceData * data,
				const char *label_p,
				const char *use_underline_p,
				const char *use_markup_p,
				const char *justify_p,
				const char *wrap_p,
				const char *selectable_p,
				const char *xalign_p,
				const char *yalign_p,
				const char *xpad_p,
				const char *ypad_p,
				const char *focus_target_p)
{
  GtkWidget *accel_target = NULL;
  gint i;

  if (gtk_object_get_data (GTK_OBJECT (widget), use_markup_p))
    source_add (data, "  gtk_label_set_use_markup (GTK_LABEL (%s), TRUE);\n",
		data->wname);

  /* If there is an underlined accelerator, set up the accel signal.
     If the label is in a button or something similar, this is now setup
     automatically by GTK+. If the accelerator is being used to set focus
     to something like a GtkEntry, we need to set the mnemonic_widget. */
  if (gtk_label_get_use_underline (GTK_LABEL (widget))
      && !gb_label_find_mnemonic_widget (widget))
    {
      gchar *target_name = gtk_object_get_data (GTK_OBJECT (widget),
						focus_target_p);
      if (target_name)
	accel_target = glade_util_find_widget (gtk_widget_get_toplevel (widget), target_name);

      if (!accel_target)
	accel_target = glade_util_find_default_accelerator_target (widget);

      if (accel_target)
	{
	  target_name = (gchar*) gtk_widget_get_name (accel_target);
	  target_name = source_create_valid_identifier (target_name);
	  source_add_to_buffer (data, GLADE_ACCELERATORS,
		"  gtk_label_set_mnemonic_widget (GTK_LABEL (%s), %s);\n",
				data->wname, target_name);
	  g_free (target_name);
	}
    }

  if (GTK_LABEL (widget)->jtype != GTK_JUSTIFY_CENTER)
    {
      for (i = 0; i < sizeof (GbJustifyValues) / sizeof (GbJustifyValues[0]);
	   i++)
	{
	  if (GbJustifyValues[i] == GTK_LABEL (widget)->jtype)
	    source_add (data,
			"  gtk_label_set_justify (GTK_LABEL (%s), %s);\n",
			data->wname, GbJustifySymbols[i]);
	}
    }

  if (GTK_LABEL (widget)->wrap)
    source_add (data, "  gtk_label_set_line_wrap (GTK_LABEL (%s), TRUE);\n",
		data->wname);

  if (gtk_label_get_selectable (GTK_LABEL (widget)))
    source_add (data, "  gtk_label_set_selectable (GTK_LABEL (%s), TRUE);\n",
		data->wname);


  if (fabs (GTK_MISC (widget)->xalign - 0.5) > 0.0001
      || fabs (GTK_MISC (widget)->yalign - 0.5) > 0.0001)
    source_add (data, "  gtk_misc_set_alignment (GTK_MISC (%s), %g, %g);\n",
	 data->wname, GTK_MISC (widget)->xalign, GTK_MISC (widget)->yalign);

  if (GTK_MISC (widget)->xpad != 0 || GTK_MISC (widget)->ypad != 0)
    source_add (data, "  gtk_misc_set_padding (GTK_MISC (%s), %i, %i);\n",
	     data->wname, GTK_MISC (widget)->xpad, GTK_MISC (widget)->ypad);
}
示例#16
0
void
gb_label_get_standard_properties (GtkWidget * widget,
				  GbWidgetGetArgData * data,
				  const char *label_p,
				  const char *use_underline_p,
				  const char *use_markup_p,
				  const char *justify_p,
				  const char *wrap_p,
				  const char *selectable_p,
				  const char *xalign_p,
				  const char *yalign_p,
				  const char *xpad_p,
				  const char *ypad_p,
				  const char *focus_target_p)
{
  const gchar *label_text;
  gint i;

  label_text = gtk_label_get_label (GTK_LABEL (widget));
  gb_widget_output_translatable_text (data, label_p, label_text);

  gb_widget_output_bool (data, use_underline_p,
			 gtk_label_get_use_underline (GTK_LABEL (widget)));
  gb_widget_output_bool (data, use_markup_p,
			 GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), use_markup_p)));

  for (i = 0; i < sizeof (GbJustifyValues) / sizeof (GbJustifyValues[0]); i++)
    {
      if (GbJustifyValues[i] == GTK_LABEL (widget)->jtype)
	gb_widget_output_choice (data, justify_p, i, GbJustifySymbols[i]);
    }
  gb_widget_output_bool (data, wrap_p, GTK_LABEL (widget)->wrap);
  gb_widget_output_bool (data, selectable_p,
			 gtk_label_get_selectable (GTK_LABEL (widget)));
  gb_widget_output_float (data, xalign_p, GTK_MISC (widget)->xalign);
  gb_widget_output_float (data, yalign_p, GTK_MISC (widget)->yalign);
  gb_widget_output_int (data, xpad_p, GTK_MISC (widget)->xpad);
  gb_widget_output_int (data, ypad_p, GTK_MISC (widget)->ypad);

  /* Labels not in buttons may have a focus target widget. */
  if (!gb_label_find_mnemonic_widget (widget))
    {
      gchar *accel_target;

      accel_target = gtk_object_get_data (GTK_OBJECT (widget), focus_target_p);

      /* If we're showing we need to display the list of possible focus target
	 widgets. We walk the tree of widgets in this component, and if a
	 widget has CAN_FOCUS set, we add it to the list. */
      if (data->action == GB_SHOWING)
	{
	  GList *focus_targets = NULL, *standard_items = NULL;
	  GtkWidget *item, *combo;

	  property_set_visible (focus_target_p, TRUE);

	  gb_label_get_focus_targets (gtk_widget_get_toplevel (widget),
				      &focus_targets);
	  property_set_combo_strings (focus_target_p, focus_targets);
	  g_list_free (focus_targets);

	  combo = property_get_value_widget (focus_target_p);

	  item = gtk_list_item_new_with_label (_("Auto"));
	  gtk_widget_show (item);
	  standard_items = g_list_append (standard_items, item);

	  item = gtk_list_item_new ();
	  gtk_widget_set_sensitive (item, FALSE);
	  gtk_widget_show (item);
	  standard_items = g_list_append (standard_items, item);
	  gtk_combo_set_item_string (GTK_COMBO (combo), GTK_ITEM (item), "");

	  gtk_list_prepend_items (GTK_LIST (GTK_COMBO (combo)->list),
				  standard_items);

	  if (!accel_target)
	    {
	      accel_target = _("Auto");
	    }
	  gb_widget_output_combo (data, focus_target_p, accel_target);
	}
      else
	{
	  /* When saving, we only save the property if it has been set. */
	  if (accel_target)
	    {
	      /* First check that the widget is still there, and if it isn't
		 just skip it. */
	      if (glade_util_find_widget (gtk_widget_get_toplevel (widget),
					  accel_target))
		{
		  gb_widget_output_combo (data, focus_target_p, accel_target);
		}
	    }
	  else
	    {
	      /* If no target has been set, and the label has an underlined
		 key, we try to find a default target and save that. */
	      if (gtk_label_get_use_underline (GTK_LABEL (widget)))
		{
		  GtkWidget *accel_target;

		  accel_target = glade_util_find_default_accelerator_target (widget);
		  if (accel_target)
		    {
		      gb_widget_output_string (data, focus_target_p, gtk_widget_get_name (accel_target));
		    }
		}
	    }
	}
    }
  else
    {
      if (data->action == GB_SHOWING)
	{
	  property_set_visible (focus_target_p, FALSE);
	}
    }
}
示例#17
0
int _chisel_native_label_get_selectable( native_handle native ) {
	return gtk_label_get_selectable( GTK_LABEL(native) );
}
示例#18
0
Php::Value GtkLabel_::get_selectable()
{
	gboolean ret = gtk_label_get_selectable (GTK_LABEL(instance));

	return ret;
}