示例#1
0
void gtk_write_entry_string(GtkWidget *entry, char *value)
{

    gint r;
    if(!value) return;

    gtk_editable_delete_text(GTK_EDITABLE(entry), 0,-1);
    gtk_editable_insert_text(GTK_EDITABLE(entry), value, strlen(value), &r);
}
示例#2
0
static void
gdaui_numeric_entry_assume_delete (GdauiEntry *entry, gint virt_start_pos, gint virt_end_pos, gint offset)
{
	GdauiNumericEntry *fentry;
	GString *string;
	gchar *otext, *ntext = NULL;
	gint i, nlen, ndel, olen = 0;
	gint cursor_pos;

	fentry = (GdauiNumericEntry*) entry;
	ndel = virt_end_pos - virt_start_pos;
	otext = gdaui_entry_get_text (GDAUI_ENTRY (entry));
	cursor_pos = gtk_editable_get_position (GTK_EDITABLE (entry));

	if (otext) {
		if ((ndel == 1) && (otext[virt_start_pos] == fentry->priv->decimal_sep) &&
		    (fentry->priv->nb_decimals != G_MAXUINT16)) {
			gtk_editable_set_position (GTK_EDITABLE (entry), cursor_pos - 1);
			g_free (otext);
			return;
		}
		string = g_string_new (otext);
		olen = g_utf8_strlen (otext, -1);
		g_free (otext);
		g_string_erase (string, virt_start_pos, ndel);
	}
	else
		string = g_string_new (NULL);
	
	cursor_pos -= (virt_end_pos - virt_start_pos);
	/*g_print ("RAW: [%s]", string->str);*/
	text_unformat (fentry, string->str, &cursor_pos);
	/*g_print ("SANITIZED: [%s]", string->str);*/

	if (!test_text_validity (fentry, string->str)) {
		if ((string->str[0] == fentry->priv->decimal_sep) &&
		    string->str[1] == 0)
			ntext = g_strdup ("");
		g_string_free (string, TRUE);
		if (!ntext) {
			/*g_print ("ERROR!\n");*/
			return;
		}
	}
	else {
		ntext = text_reformat (fentry, string->str, &cursor_pos, FALSE);
		g_string_free (string, TRUE);
	}
	/*g_print ("NEW: [%s]\n", ntext);*/

	i = offset;
	nlen = strlen (ntext);
	gtk_editable_delete_text ((GtkEditable*) entry, offset, olen + offset);
	gtk_editable_insert_text ((GtkEditable*) entry, ntext, nlen, &i);
	g_free (ntext);	
	gtk_editable_set_position (GTK_EDITABLE (entry), cursor_pos);
}
示例#3
0
void gtk_write_entry_float(GtkWidget *entry, float value)
{

    gint r;
    char string[400];
    sprintf(string,"%f",value);
    gtk_editable_delete_text(GTK_EDITABLE(entry), 0,-1);
    gtk_editable_insert_text(GTK_EDITABLE(entry), string, strlen(string), &r);
}
示例#4
0
void dot(GtkWidget *widget, gpointer data)
{
	if (hasdot == 0) /* 没有小数点则添加一个小数点。*/
	{
		const gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
		gint pos = strlen(entry_text);
		gtk_editable_insert_text(GTK_EDITABLE(entry),
				gtk_button_get_label(GTK_BUTTON(widget)), -1, &pos);
		hasdot = 1;/*  表示有一个小数点。*/
	}
}
示例#5
0
static gboolean on_display_editable_map(GtkWidget *widget, gchar *display)
{
	gint position = 0;
	GtkEditable *editable = GTK_EDITABLE(widget);

	gtk_editable_delete_text(editable, 0, -1);
	gtk_editable_insert_text(editable, display ? display : "", -1, &position);
	gtk_editable_select_region(editable, -1, 0);
	g_free(display);
	return FALSE;
}
示例#6
0
static void
insert_blue (GtkWidget *widget, gpointer data)
{
	int pos;
	GtkWidget *entry;

	entry = GTK_WIDGET (data);

	pos = gtk_editable_get_position (GTK_EDITABLE (entry));
	gtk_editable_insert_text (GTK_EDITABLE (entry), "blue book ", strlen ("blue book "), &pos);
}
示例#7
0
static PyObject* ComposeWindow_save_message_to(clawsmail_ComposeWindowObject *self, PyObject *args)
{
  PyObject *arg;

  if(!PyArg_ParseTuple(args, "O", &arg))
    return NULL;

  if(PyString_Check(arg)) {
    GtkEditable *editable;
    gint pos;

    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->compose->savemsg_checkbtn), TRUE);

    editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(self->compose->savemsg_combo)));
    gtk_editable_delete_text(editable, 0, -1);
    gtk_editable_insert_text(editable, PyString_AsString(arg), -1, &pos);
  }
  else if(clawsmail_folder_check(arg)) {
    GtkEditable *editable;
    gint pos;

    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->compose->savemsg_checkbtn), TRUE);

    editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(self->compose->savemsg_combo)));
    gtk_editable_delete_text(editable, 0, -1);
    gtk_editable_insert_text(editable, folder_item_get_identifier(clawsmail_folder_get_item(arg)), -1, &pos);
  }
  else if (arg == Py_None){
    /* turn off checkbutton */
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->compose->savemsg_checkbtn), FALSE);
  }
  else {
    PyErr_SetString(PyExc_TypeError, "function takes exactly one argument which may be a folder object, a string, or None");
    return NULL;
  }

  flush_gtk_queue();

  Py_INCREF(Py_None);
  return Py_None;
}
示例#8
0
文件: combobox.cpp 项目: beanhome/dev
void wxComboBox::WriteText(const wxString& value)
{
    wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );

    GtkWidget *entry = GTK_COMBO(m_widget)->entry;
    GtkEditable * const edit = GTK_EDITABLE(entry);

    gtk_editable_delete_selection(edit);
    gint len = gtk_editable_get_position(edit);
    gtk_editable_insert_text(edit, wxGTK_CONV(value), -1, &len);
    gtk_editable_set_position(edit, len);
}
示例#9
0
文件: entry.c 项目: Alexis-D/luakit
static gint
luaH_entry_insert(lua_State *L)
{
    size_t len;
    widget_t *w = luaH_checkwidget(L, 1);
    gint pos = luaL_checknumber(L, 2);
    const gchar *text = luaL_checklstring(L, 3, &len);
    gtk_editable_insert_text(GTK_EDITABLE(w->widget),
        text, g_utf8_strlen(text, len), &pos);
    lua_pushnumber(L, pos);
    return 1;
}
示例#10
0
static int gtkListSetAppendAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->has_editbox)
  {
    GtkEntry* entry = (GtkEntry*)iupAttribGet(ih, "_IUPGTK_ENTRY");
    gint pos = strlen(gtk_entry_get_text(entry))+1;
    iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", "1"); /* disable callbacks */
    gtk_editable_insert_text(GTK_EDITABLE(entry), iupgtkStrConvertToUTF8(value), -1, &pos);
    iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", NULL);
  }
  return 0;
}
示例#11
0
文件: tools.c 项目: dimkr/beaver
void change_case (gint UpDown)
{	
  gint CurrentPage, l_min, l_max;
  gchar *buffer ;

  CurrentPage = gtk_notebook_get_current_page (GTK_NOTEBOOK(MainNotebook));
  l_min = min_from_selection (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
  l_max = max_from_selection (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
  buffer = gtk_editable_get_chars (GTK_EDITABLE(FPROPS(CurrentPage, Text)),
				   l_min, l_max);
  if (UpDown == 1) g_strup (buffer);
  else if (UpDown == 2) g_strdown (buffer);
  else if (UpDown == 3)
    {
      gint l_len, i, j;
      gchar *Delimiters = " \t\b\n\f\'\"{}()[]<>%^&*[email protected]#$\\|/:;,.?!";

      l_len = l_max - l_min;
      if ((buffer[0] >= 'a') && (buffer[0] <= 'z'))
	buffer[0] = buffer[0] - 'a' + 'A';
      for (i = 1; i < l_len; i++)
	{
	  for (j = 0; j <= (gint)strlen (Delimiters); j++)
	    {
	      if (buffer [i] == Delimiters[j])
		{
		  if ((buffer[i+1] >= 'a') && (buffer[i+1] <= 'z'))
		    buffer[i+1] = buffer[i+1] - 'a' + 'A';
		  break;
		}
	    }
	}
    }
  else if (UpDown == 4)
    {
      gint l_len, change_case, i;

      l_len = l_max - l_min;
      change_case = 'a' - 'A';
      for (i = 0; i <= l_len; i++)
	{
	  if ((buffer[i] >= 'A') && (buffer[i] <= 'Z'))
	    buffer[i] = buffer[i] + change_case;
	  else if ((buffer[i] >= 'a') && (buffer[i] <= 'z'))
	    buffer[i] = buffer[i] - change_case;
	}
    }
  gtk_editable_delete_selection (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
  gtk_editable_insert_text (GTK_EDITABLE(FPROPS(CurrentPage, Text)),
			    buffer, strlen(buffer), &l_min);
  g_free (buffer);
}
示例#12
0
/**
 * e_dialog_editable_set:
 * @widget: A #GtkEditable widget.
 * @value: String value.
 *
 * Sets the string value inside a #GtkEditable-derived widget.
 **/
void
e_dialog_editable_set (GtkWidget *widget,
                       const gchar *value)
{
	gint pos = 0;

	g_return_if_fail (GTK_IS_EDITABLE (widget));

	gtk_editable_delete_text (GTK_EDITABLE (widget), 0, -1);

	if (value)
		gtk_editable_insert_text (GTK_EDITABLE (widget), value, strlen (value), &pos);
}
示例#13
0
static void
insert_red (GtkWidget *widget, gpointer data)
{
	int pos;
	GtkWidget *entry;

	g_print ("in callback, data is: %p\n", data);
	
	entry = GTK_WIDGET (data);

	pos = gtk_editable_get_position (GTK_EDITABLE (entry));
	gtk_editable_insert_text (GTK_EDITABLE (entry), "red book ", strlen ("red book "), &pos);
}
示例#14
0
文件: entry.c 项目: bradparks/luakit
static gint
luaH_entry_append(lua_State *L)
{
    size_t len;
    widget_t *w = luaH_checkudata(L, 1, &widget_class);
    const gchar *text = luaL_checklstring(L, 2, &len);
    gint pos = -1;

    gtk_editable_insert_text(GTK_EDITABLE(w->widget),
        text, g_utf8_strlen(text, len), &pos);

    return pos + 1;
}
示例#15
0
static void location_cb (GtkMozEmbed *embed, WebBrowserObject *browser)
{
    browser->FireEvent("OnLocationChange");
    char *location = gtk_moz_embed_get_location(embed);
    if (location) {
        int pos = 0;
        systemObject->Log(0, "location: %s", location);
        gtk_editable_delete_text(GTK_EDITABLE(browser->urlEntry), 0, -1);
        gtk_editable_insert_text(GTK_EDITABLE(browser->urlEntry), location, strlen(location), &pos);
        g_free(location);
    }
    browser->BrowserButtons();
}
示例#16
0
//------------------------------------------------------------------------------
void on_settings_data_path_button_current_folder_changed (GtkFileChooser *filechooser,
																													gpointer user_data)
{
		gchar *data_folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(settings_data_path_button)) ;
		
		gtk_entry_set_editable (settings_data_path_entry, TRUE) ;
		gtk_entry_set_text (settings_data_path_entry, data_folder) ;
		int pos=-1 ;
		gtk_editable_insert_text  ((GtkEditable *)settings_data_path_entry,"/",1, &pos) ;
		gtk_entry_set_editable (settings_data_path_entry, FALSE) ;
		
		g_free(data_folder) ;
} ;
示例#17
0
文件: tools.c 项目: dimkr/beaver
void insert_time (gint CurrentPage)
{
  gint Position;
  time_t Time;

  if ((!OpenedFilesCnt) || FPROPS(CurrentPage, ReadOnly))
    return;
  Time = time (NULL);
  gtk_editable_delete_selection
    (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
  gtk_editable_insert_text (GTK_EDITABLE(FPROPS(CurrentPage, Text)),
		   ctime (&Time), 24, &Position);
  print_msg ("Insert Time...");
}
示例#18
0
void wxComboBox::Replace( long from, long to, const wxString& value )
{
    wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );

    GtkEntry *entry = NULL;
#ifdef __WXGTK24__
    if (!gtk_check_version(2,4,0))
        entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
    else
#endif
        entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );

    gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
    if (value.IsNull()) return;
    gint pos = (gint)to;

#if wxUSE_UNICODE
    wxCharBuffer buffer = wxConvUTF8.cWX2MB( value );
    gtk_editable_insert_text( GTK_EDITABLE(entry), (const char*) buffer, strlen( (const char*) buffer ), &pos );
#else
    gtk_editable_insert_text( GTK_EDITABLE(entry), value.c_str(), value.length(), &pos );
#endif
}
示例#19
0
void insert_text_handler (GtkEntry    *entry,
                          const gchar *text,
                          gint         length,
                          gint        *position,
                          gpointer     data)
{
	GtkWidget * button = (GtkWidget *) data;
	GtkEditable *editable = GTK_EDITABLE(entry);
	int i, count=0;
	int issensitive;
	int entrylen = gtk_entry_get_text_length(GTK_ENTRY(entry));
	gchar *result = g_new(gchar, length);
	static char prev;

	for (i=0; i < length; i++) {
		if(text[i] == '.' && *position > 0 && prev != '.')
		{
			result[count++] = text[i];
			prev = text[i];
			continue;
		}
		if (isalnum(text[i]))
		{
			result[count++] = text[i];
			prev = text[i];
			continue;
		}
	}
	
	if (count > 0) {
		g_signal_handlers_block_by_func (G_OBJECT (editable),
						 G_CALLBACK (insert_text_handler),
						 data);

		gtk_editable_insert_text (editable, result, count, position);

		g_signal_handlers_unblock_by_func (G_OBJECT (editable),
						   G_CALLBACK (insert_text_handler),
						   data);
	}
	g_signal_stop_emission_by_name (G_OBJECT (editable), "insert_text");
	
	g_free (result);
	
	issensitive = (!(entrylen < 5) && !(prev == '.'));
	gtk_widget_set_sensitive(button,issensitive);

		

}
示例#20
0
static gboolean midorator_entry_paste_clipboard_cb (MidoratorEntry* e, GtkWidget* web_view) {
	if (!midorator_string_to_bool(midorator_options("option", "paste_primary", NULL)))
		return false;
	g_signal_stop_emission_by_name(e, "paste-clipboard");
	char *text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
	if (!text)
		return true;
	gtk_editable_delete_selection(GTK_EDITABLE(e));
	int pos = gtk_editable_get_position(GTK_EDITABLE(e));
	gtk_editable_insert_text(GTK_EDITABLE(e), text, -1, &pos);
	gtk_editable_set_position(GTK_EDITABLE(e), pos);
	g_free(text);
	return true;
}
示例#21
0
文件: ascii.c 项目: dimkr/xchat
static void
ascii_click (GtkWidget * wid, int c)
{
	int tmp_pos;
	unsigned char str = c;

	if (menu_sess)
	{
		wid = menu_sess->gui->inputgad;
		tmp_pos = gtk_editable_get_position (GTK_EDITABLE (wid));
		gtk_editable_insert_text (GTK_EDITABLE (wid), &str, 1, &tmp_pos);
		gtk_entry_set_position (GTK_ENTRY (wid), tmp_pos);
	}
}
示例#22
0
static void foldersel_cb(GtkWidget *widget, gpointer data)
{
	GtkWidget *entry = (GtkWidget *) data;
	FolderItem *item;
	gchar *item_id;
	gint newpos = 0;
	
	item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE);
	if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
		gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
		gtk_editable_insert_text(GTK_EDITABLE(entry), item_id, strlen(item_id), &newpos);
		g_free(item_id);
	}
}
示例#23
0
void
InterfaceGtk::cmdline_update(const gchar *cmdline)
{
	gint pos = 1;

	if (!cmdline)
		/* widget automatically redrawn */
		return;

	gtk_entry_set_text(GTK_ENTRY(cmdline_widget), "*");
	gtk_editable_insert_text(GTK_EDITABLE(cmdline_widget),
				 cmdline, -1, &pos);
	gtk_editable_set_position(GTK_EDITABLE(cmdline_widget), pos);
}
示例#24
0
/**
 * Called when the user selects an entry from the autocomplete list.
 *
 * @param[in] widget
 * @param[in] model     Data structure containing autocomplete strings.
 * @param[in] iter      Pointer into data structure.
 * @param[in] user_data unused here
 *
 * @return Currently always true
 */
static gboolean
on_match_select(GtkEntryCompletion *widget,
                GtkTreeModel *model,
                GtkTreeIter *iter,
                gpointer user_data)
{

  const gchar *varname;
  GtkEditable *e = (GtkEditable*) gtk_entry_completion_get_entry(widget);
  gchar *s = gtk_editable_get_chars(e, 0, -1);
  gint cur_pos = gtk_editable_get_position(e);
  gint p = cur_pos;
  gchar *end;
  gint del_end_pos = -1;

  GValue value = {0, };
  gtk_tree_model_get_value(model, iter, COMPL_VARNAME, &value);
  varname = g_value_get_string(&value);

  for (p = cur_pos; p - 2 > 0; p--)
  {
    if (strncmp(s + p - 2, "$(", 2) == 0)
    {
      break;
    }
  }

  end = s + cur_pos;

  if (end)
  {
    del_end_pos = end - s + 1;
  }
  else
  {
    del_end_pos = cur_pos;
  }

  size_t text_len = strlen(varname) + 2;
  gchar *addtext = (gchar*) g_malloc(text_len);
  snprintf(addtext, text_len, "%s)", varname);

  gtk_editable_delete_text(e, p, del_end_pos);
  gtk_editable_insert_text(e, addtext, -1, &p);
  gtk_editable_set_position(e, p);
  g_value_unset(&value);
  g_free(addtext);
  return TRUE;
}
示例#25
0
void wxTextCtrl::WriteText( const wxString &text )
{
    wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );

    if ( text.empty() )
        return;

    // gtk_text_changed_callback() will set m_modified to true but m_modified
    // shouldn't be changed by the program writing to the text control itself,
    // so save the old value and restore when we're done
    bool oldModified = m_modified;

    if ( m_windowStyle & wxTE_MULTILINE )
    {
        // After cursor movements, gtk_text_get_point() is wrong by one.
        gtk_text_set_point( GTK_TEXT(m_text), GET_EDITABLE_POS(m_text) );

        // always use m_defaultStyle, even if it is empty as otherwise
        // resetting the style and appending some more text wouldn't work: if
        // we don't specify the style explicitly, the old style would be used
        gtk_editable_delete_selection( GTK_EDITABLE(m_text) );
        wxGtkTextInsert(m_text, m_defaultStyle, text.c_str(), text.length());

        // we called wxGtkTextInsert with correct font, no need to do anything
        // in UpdateFontIfNeeded() any longer
        if ( !text.empty() )
        {
            SetUpdateFont(false);
        }

        // Bring editable's cursor back uptodate.
        SET_EDITABLE_POS(m_text, gtk_text_get_point( GTK_TEXT(m_text) ));
    }
    else // single line
    {
        // First remove the selection if there is one
        gtk_editable_delete_selection( GTK_EDITABLE(m_text) );

        // This moves the cursor pos to behind the inserted text.
        gint len = GET_EDITABLE_POS(m_text);

        gtk_editable_insert_text( GTK_EDITABLE(m_text), text.c_str(), text.length(), &len );

        // Bring entry's cursor uptodate.
        gtk_entry_set_position( GTK_ENTRY(m_text), len );
    }

    m_modified = oldModified;
}
示例#26
0
文件: entry.c 项目: bradparks/luakit
static gint
luaH_entry_insert(lua_State *L)
{
    size_t len;
    widget_t *w = luaH_checkudata(L, 1, &widget_class);
    gint pos = luaL_checknumber(L, 2);
    /* lua table indexes start at 1 */
    if (pos > 0) pos--;
    const gchar *text = luaL_checklstring(L, 3, &len);

    gtk_editable_insert_text(GTK_EDITABLE(w->widget),
        text, g_utf8_strlen(text, len), &pos);

    return pos + 1;
}
示例#27
0
void GeCurveGtk::open_minmax( int idx)
{
  char min_value_str[80];
  char max_value_str[80];
  gint pos = 0;

  create_minmax_dialog();

  if ( idx < cd->cols) {
    sprintf( min_value_str, "%f", cd->y_min_value_axis[idx]);
    sprintf( max_value_str, "%f", cd->y_max_value_axis[idx]);
  }
  else {
    sprintf( min_value_str, "%f", cd->x_min_value_axis[idx - cd->cols]);
    sprintf( max_value_str, "%f", cd->x_max_value_axis[idx - cd->cols]);
  }
  gtk_editable_delete_text( GTK_EDITABLE(minmax_textmin_widget), 0, -1);
  gtk_editable_insert_text( GTK_EDITABLE(minmax_textmin_widget), 
			    min_value_str, strlen(min_value_str), &pos);
  gtk_editable_delete_text( GTK_EDITABLE(minmax_textmax_widget), 0, -1);
  gtk_editable_insert_text( GTK_EDITABLE(minmax_textmax_widget), 
			    max_value_str, strlen(max_value_str), &pos);
  minmax_idx = idx;
}
示例#28
0
static gint
luaH_entry_insert(lua_State *L)
{
    widget_t *w = luaH_checkwidget(L, 1);

    /* get insert position (or append text) */
    gint pos = -1, idx = 2;
    if (lua_gettop(L) > 2) {
        pos = luaL_checknumber(L, idx++);
        if (pos > 0) pos--; /* correct lua index */
    }

    gtk_editable_insert_text(GTK_EDITABLE(w->widget),
        luaL_checkstring(L, idx), -1, &pos);
    return 0;
}
示例#29
0
void my_int_listener (PluginParam *param) {
  GtkEditable *editable;

  if (sdlGoom->config_win == 0) return;
  editable = GTK_EDITABLE(param->user_data);

  if (editable) {
    int pos = 0;
    char str[256];
    sprintf (str, "%d", IVAL(*param));
    if (strcmp(str,gtk_editable_get_chars(editable,0,-1))) {
      gtk_editable_delete_text (editable,0,-1);
      gtk_editable_insert_text (editable,str,strlen(str),&pos);
    }
  }
}
示例#30
0
/**************************************************************************
  Make a text tag for the selected text.
**************************************************************************/
void inputline_make_tag(GtkEntry *entry, enum text_tag_type type)
{
  char buf[MAX_LEN_MSG];
  GtkEditable *editable = GTK_EDITABLE(entry);
  gint start_pos, end_pos;
  gchar *selection;

  if (!gtk_editable_get_selection_bounds(editable, &start_pos, &end_pos)) {
    /* Let's say the selection starts and ends at the current position. */
    start_pos = end_pos = gtk_editable_get_position(editable);
  }

  selection = gtk_editable_get_chars(editable, start_pos, end_pos);

  if (type == TTT_COLOR) {
    /* Get the color arguments. */
    char fg_color_text[32], bg_color_text[32];
    GdkColor *fg_color = g_object_get_data(G_OBJECT(entry), "fg_color");
    GdkColor *bg_color = g_object_get_data(G_OBJECT(entry), "bg_color");

    if (!fg_color && !bg_color) {
      goto CLEAN_UP;
    }

    color_to_string(fg_color, fg_color_text, sizeof(fg_color_text));
    color_to_string(bg_color, bg_color_text, sizeof(bg_color_text));

    if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
                                     TTT_COLOR, 0, FT_OFFSET_UNSET,
                                     ft_color(fg_color_text,
                                              bg_color_text))) {
      goto CLEAN_UP;
    }
  } else if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
                                          type, 0, FT_OFFSET_UNSET)) {
    goto CLEAN_UP;
  }

  /* Replace the selection. */
  gtk_editable_delete_text(editable, start_pos, end_pos);
  end_pos = start_pos;
  gtk_editable_insert_text(editable, buf, -1, &end_pos);
  gtk_editable_select_region(editable, start_pos, end_pos);

CLEAN_UP:
  g_free(selection);
}