static void colsel_ok_clicked_lcb(GtkWidget *widget, Tcolsel *csd) { gchar *tmpstr; GdkColor gcolor; /* only on a OK click we do the setcolor thing */ gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(csd->csel), &gcolor); tmpstr = gdk_color_to_hexstring(&gcolor, FALSE); if (csd->bfwin) { csd->bfwin->session->colorlist = add_to_stringlist(csd->bfwin->session->colorlist, tmpstr); } if (csd->is_modal) { g_free(csd->returnval); csd->returnval = tmpstr; gtk_main_quit(); } else { if (string_is_color(tmpstr)) { if (csd->startpos || csd->endpos) { DEBUG_MSG("colsel_ok_clicked_lcb, replacing with %s\n", tmpstr); doc_replace_text(csd->bfwin->current_document, tmpstr, csd->startpos, csd->endpos); } else { DEBUG_MSG("colsel_ok_clicked_lcb, inserting %s\n", tmpstr); doc_insert_two_strings(csd->bfwin->current_document,tmpstr, NULL); } } g_free(tmpstr); window_destroy(csd->win); } }
void sel_colour_cb(GtkWidget *widget, Tbfwin *bfwin) { gchar *tmpstr=NULL; gint startpos=0; gint endpos=0; if (doc_get_selection(bfwin->current_document,&startpos , &endpos)) { DEBUG_MSG("sel_colour_cb, selection found\n"); if (startpos > endpos) { gint tmpint; tmpint = startpos; startpos = endpos; endpos = tmpint; } if ((endpos - startpos) == 7) { tmpstr = doc_get_chars(bfwin->current_document,startpos,endpos); if (!string_is_color(tmpstr)) { startpos = endpos = 0; } DEBUG_MSG("sel_colour_cb, tmpstr = %s (startpos=%d, endpos=%d)\n", tmpstr, startpos, endpos); } else { DEBUG_MSG("sel_colour_cb, startpos=%d, endpos=%d\n", startpos, endpos); startpos = endpos = 0; } } else { DEBUG_MSG("sel_colour_cb, NO selection found\n"); } colsel_dialog(bfwin, tmpstr, 0, startpos, endpos); if (tmpstr) g_free(tmpstr); }
static gboolean locate_color(Tdocument *doc, const GtkTextIter *iter) { Tin_html_tag iht; gboolean retval=FALSE; GtkTextIter leftiter=*iter, rightiter, maxiter = *iter; DEBUG_MSG("locate_color, started\n"); rec_color.found = FALSE; gtk_text_iter_backward_chars(&maxiter, 8); /* first we look to the left for a #, and we look back at max. 8 chars (7 would be good enough) */ iht.findchar = '#'; iht.prevchar = '\n'; iht.ignore_if_prevchar = '\0'; if (gtk_text_iter_backward_find_char(&leftiter, (GtkTextCharPredicate)iter_char_search_lcb,&iht,&maxiter)) { gchar *text; rightiter = leftiter; gtk_text_iter_forward_chars(&rightiter, 7); text = gtk_text_buffer_get_text(doc->buffer,&leftiter,&rightiter,FALSE); DEBUG_MSG("locate_color,is '%s' a color?\n",text); if (text) { retval = string_is_color(text); if (retval) { rec_color.so = gtk_text_iter_get_offset(&leftiter); rec_color.eo = gtk_text_iter_get_offset(&rightiter); rec_color.found = TRUE; rec_color.doc = doc; DEBUG_MSG("found color from so=%d to eo=%d\n",rec_color.so, rec_color.eo); } g_free(text); } } return retval; }