示例#1
0
int
im_uim_delete_primary_text(IMUIMContext *uic, enum UTextOrigin origin,
			   int former_req_len, int latter_req_len)
{
  gboolean success;
  gint offset, n_chars;

  /* specific widgets handling */
  if (GTK_IS_ENTRY(uic->widget))
    return delete_text_in_gtk_entry(GTK_ENTRY(uic->widget), origin,
				    former_req_len, latter_req_len);
  else if (GTK_IS_TEXT_VIEW(uic->widget))
    return delete_text_in_gtk_text_view(GTK_TEXT_VIEW(uic->widget), origin,
					former_req_len, latter_req_len);
  /*
   * For the rest of widget, we use delete_surrounding, which  means explicit
   * value for former_len and latter_len is required and its origin must be the
   * cursor.
   */
  offset = n_chars = 0;

  switch (origin) {
  case UTextOrigin_Cursor:
    if (former_req_len >= 0) {
      offset = -former_req_len;
      n_chars = former_req_len;
    } else {
	return -1;
    }

    if (latter_req_len >= 0)
      n_chars += latter_req_len;
    else
      return -1;
    break;

  case UTextOrigin_Beginning:
  case UTextOrigin_End:
  case UTextOrigin_Unspecified:
  default:
    return -1;
  }

  success = gtk_im_context_delete_surrounding(GTK_IM_CONTEXT(uic), offset,
					      n_chars);
  return success ? 0 : -1;
}
示例#2
0
void
enqueue(char *string)
{
  /* fprintf(stderr, "enqueueing [%s]\n", string); */
  while (*string == '\b')
    {
      gtk_im_context_delete_surrounding(myContext, -1, 1);
      string += 1;
    }
  if (*string == 0)
    {
      return;
    }
  else if (*string == '\r')
    {
      /* fprintf(stderr, "saw cr, suppressing\n"); */
    }
  else
    {
      g_signal_emit_by_name (myContext, "commit", string);
    }
} /* enqueue */
boolean scim_bridge_client_imcontext_delete_surrounding_text (ScimBridgeClientIMContext *imcontext, int offset, int length)
{
    boolean retval = gtk_im_context_delete_surrounding (GTK_IM_CONTEXT (imcontext), offset, length);
    return retval;
}
示例#4
0
static VALUE
rg_delete_surrounding(VALUE self, VALUE offset, VALUE n_chars)
{
    return CBOOL2RVAL(gtk_im_context_delete_surrounding(_SELF(self), NUM2INT(offset),
                                                        NUM2INT(n_chars)));
}
示例#5
0
static gboolean
sinhala_transliterated_filter_keypress(GtkIMContext *context,
                        GdkEventKey  *event)
{
	int c, c1, l1;
	guchar *u = NULL;
	gchar *text;
	gint cursor, has_surrounding;

	if (event->keyval == 0) return FALSE;

	if (event->type == GDK_KEY_RELEASE) {
		if (event->keyval == GDK_Shift_L) shift_l = 0;
		if (event->keyval == GDK_Shift_R) shift_r = 0;
		if (event->keyval == GDK_Control_L) ctrl_l = 0;
		if (event->keyval == GDK_Control_R) ctrl_r = 0;
		return FALSE;
	}

	if (event->keyval == GDK_Shift_L) {
		shift_l = 1;
		return FALSE;
	}
	if (event->keyval == GDK_Shift_R) {
		shift_r = 1;
		return FALSE;
	}
	if (event->keyval == GDK_Control_L) {
		ctrl_l = 1;
		return FALSE;
	}
	if (event->keyval == GDK_Control_R) {
		ctrl_r = 1;
		return FALSE;
	}

	if ((event->keyval == GDK_space) && (shift_l || shift_r)) {
		/* FIXME: add non breaking space */
		return TRUE;
	}

	if ((event->keyval == GDK_space) && (ctrl_l || ctrl_r)) {
		sinhala_input = !sinhala_input;
		return TRUE;
	}

	if (event->state & (gtk_accelerator_get_default_mod_mask() & ~GDK_SHIFT_MASK))
		return FALSE;

	if (!sinhala_input && (event->keyval < 128)) {
		u = malloc(2);
		u[0] = event->keyval;
		u[1] = 0;

		g_signal_emit_by_name (context, "commit", u);

		free(u);
		return TRUE;
	}

	has_surrounding = gtk_im_context_get_surrounding(context, &text, &cursor);
	c = find_consonent_by_key(event->keyval);

	if (c >= 0) { /* a consonent is pressed. */

		/* do modifiers first. */
		if (has_surrounding && (cursor >= 3)) {
			c1 = get_known_lsb_character(text + cursor - 3);
			l1 = find_consonent(c1);
			/* do modifiers only if there is a valid character before */
			if (l1 >= 0) {
				if (event->keyval == GDK_w) {
					u = create_unicode_character_from_lsb(0xca);
					g_signal_emit_by_name (context, "commit", u);
					free(u);
					free(text);
					return TRUE;
				}
				if (event->keyval == GDK_W) {
					/* bandi hal kireema */
					u = malloc(7);
					u[0] = 0xe0; u[1] = 0xb7; u[2] = 0x8a;
					u[3] = 0xe2; u[4] = 0x80; u[5] = 0x8d;
					u[6] = 0;

					g_signal_emit_by_name (context, "commit", u);

					free(u);
					free(text);
					return TRUE;
				}
				if ((event->keyval == GDK_H) && (consonents[l1].mahaprana)) {
					gtk_im_context_delete_surrounding(context, -1, 1);
					u = create_unicode_character_from_lsb(consonents[l1].mahaprana);
					g_signal_emit_by_name (context, "commit", u);
					free(u);
					free(text);
					return TRUE;
				}
				if ((event->keyval == GDK_G) && (consonents[l1].sagngnaka)) {
					gtk_im_context_delete_surrounding(context, -1, 1);
					u = create_unicode_character_from_lsb(consonents[l1].sagngnaka);
					g_signal_emit_by_name (context, "commit", u);
					free(u);
					free(text);
					return TRUE;
				}
				if (event->keyval == GDK_R) {
					/* rakaraanshaya */
					u = malloc(10);
					u[0] = 0xe0; u[1] = 0xb7; u[2] = 0x8a;
					u[3] = 0xe2; u[4] = 0x80; u[5] = 0x8d;
					u[6] = 0xe0; u[7] = 0xb6; u[8] = 0xbb;
					u[9] = 0;

					g_signal_emit_by_name (context, "commit", u);

					free(u);
					free(text);
					return TRUE;
				}
				if (event->keyval == GDK_Y) {
					/* yansaya */
					u = malloc(10);
					u[0] = 0xe0; u[1] = 0xb7; u[2] = 0x8a;
					u[3] = 0xe2; u[4] = 0x80; u[5] = 0x8d;
					u[6] = 0xe0; u[7] = 0xb6; u[8] = 0xba;
					u[9] = 0;

					g_signal_emit_by_name (context, "commit", u);

					free(u);
					free(text);
					return TRUE;
				}
			}
		}

		u = create_unicode_character_from_lsb(consonents[c].character);
         	g_signal_emit_by_name (context, "commit", u);
		free(u);
		if (has_surrounding) free(text);
		return TRUE;
		/* end of consonent handling. */
	}

	c = find_vowel_by_key(event->keyval);
	if (c >= 0) {
		/* a vowel is pressed. */

		/* look for a previous character first. */
		u = NULL;
		if (has_surrounding && (cursor >= 3)) {
			c1 = get_known_lsb_character(text + cursor - 3);
			if (is_consonent(c1)) {
				u = create_unicode_character_from_lsb(vowels[c].single1);
			}
			else if (c1 == vowels[c].single0) {
				gtk_im_context_delete_surrounding(context, -1, 1);
				u = create_unicode_character_from_lsb(vowels[c].double0);
			}
			else if (c1 == vowels[c].single1) {
				gtk_im_context_delete_surrounding(context, -1, 1);
				u = create_unicode_character_from_lsb(vowels[c].double1);
			}
		}

		if (u == NULL)
			u = create_unicode_character_from_lsb(vowels[c].single0);

		g_signal_emit_by_name (context, "commit", u);

		free(u);
		if (has_surrounding) free(text);
		return TRUE;
		/* end of vowel handling. */
	}
	if (event->keyval < 128) {
		u = malloc(2);
		u[0] = event->keyval;
		u[1] = 0;
		g_signal_emit_by_name (context, "commit", u);
		free(u);
		if (has_surrounding) free(text);
		return TRUE;
	}
	if (event->keyval == GDK_BackSpace) {
	    gtk_im_context_delete_surrounding(context, -1, 1);
	    if (has_surrounding) free(text);
	    return TRUE;
	}
	if (has_surrounding) free(text);

	return FALSE;
}