All pastes #84015 Raw Edit

_layout_with_preedit

public c v1 · immutable
·published 2006-07-10 12:10 UTC
rendered paste body
static PangoLayout *layout_with_preedit_old (ECellTextView *text_view, int row, const char *text, gint width){	CellEdit *edit = text_view->edit;	PangoAttrList *attrs ;	PangoLayout *layout;	GString *tmp_string = g_string_new (NULL);	PangoAttrList *preedit_attrs = NULL;	gchar *preedit_string = NULL;	gint preedit_length = 0;	gint text_length = strlen (text);	gint mlen = MIN(edit->selection_start,text_length);		gtk_im_context_get_preedit_string (edit->im_context, &preedit_string,&preedit_attrs, NULL);	preedit_length = edit->preedit_length = strlen (preedit_string);	layout = edit->layout;	g_string_prepend_len (tmp_string, text,text_length); 	if (preedit_length) {				/* mlen is the text_length in bytes, not chars		 * check whether we are not inserting into		 * the middle of a utf8 character		 */		if (mlen < text_length) {			if (!g_utf8_validate (text+mlen, -1, NULL)) {				gchar *tc;				tc = g_utf8_find_next_char (text+mlen,NULL);				if (tc) {					mlen = (gint) (tc - text);				}			}		}		g_string_insert (tmp_string, mlen, preedit_string);	} 	pango_layout_set_text (layout, tmp_string->str, tmp_string->len);	attrs = (PangoAttrList *) build_attr_list (text_view, row, text_length);	if (preedit_length)		pango_attr_list_splice (attrs, preedit_attrs, mlen, preedit_length);	pango_layout_set_attributes (layout, attrs);	g_string_free (tmp_string, TRUE);	if (preedit_string)		g_free (preedit_string);	if (preedit_attrs)		pango_attr_list_unref (preedit_attrs);	pango_attr_list_unref (attrs);		update_im_cursor_location (text_view);		return layout;}