pidgin/gtkimhtml.c

branch
next.minor
changeset 25007
ef8bc1f4a6ba
parent 24698
f9dd7117ade0
child 25008
f52b9372eb19
equal deleted inserted replaced
25006:5d0817148b73 25007:ef8bc1f4a6ba
2639 g_return_if_fail (GTK_IS_IMHTML (imhtml)); 2639 g_return_if_fail (GTK_IS_IMHTML (imhtml));
2640 g_return_if_fail (text != NULL); 2640 g_return_if_fail (text != NULL);
2641 c = text; 2641 c = text;
2642 len = strlen(text); 2642 len = strlen(text);
2643 ws = g_malloc(len + 1); 2643 ws = g_malloc(len + 1);
2644 ws[0] = 0; 2644 ws[0] = '\0';
2645 2645
2646 gtk_text_buffer_begin_user_action(imhtml->text_buffer); 2646 gtk_text_buffer_begin_user_action(imhtml->text_buffer);
2647 while (pos < len) { 2647 while (pos < len) {
2648 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { 2648 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) {
2649 c++; 2649 c++;
3285 } else if (*c == '\n') { 3285 } else if (*c == '\n') {
3286 if (!(options & GTK_IMHTML_NO_NEWLINE)) { 3286 if (!(options & GTK_IMHTML_NO_NEWLINE)) {
3287 ws[wpos] = '\n'; 3287 ws[wpos] = '\n';
3288 wpos++; 3288 wpos++;
3289 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); 3289 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
3290 ws[0] = '\0'; 3290 ws[0] = '\0'; wpos = 0;
3291 wpos = 0;
3292 /* NEW_BIT (NEW_TEXT_BIT); */ 3291 /* NEW_BIT (NEW_TEXT_BIT); */
3293 } else if (!br) { /* Don't insert a space immediately after an HTML break */ 3292 } else if (!br) { /* Don't insert a space immediately after an HTML break */
3294 /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary. 3293 /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary.
3295 * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine 3294 * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine
3296 * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert 3295 * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert
3297 * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand? 3296 * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand?
3298 * Bu-wahaha! */ 3297 * Bu-wahaha! */
3299 ws[wpos] = ' '; 3298 ws[wpos] = ' ';
3300 wpos++; 3299 wpos++;
3301 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); 3300 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
3302 ws[0] = '\0'; 3301 ws[0] = '\0'; wpos = 0;
3303 wpos = 0;
3304 } 3302 }
3305 c++; 3303 c++;
3306 pos++; 3304 pos++;
3307 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ 3305 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){
3308 br = FALSE; 3306 br = FALSE;
3309 if (wpos > 0) { 3307 if (wpos > 0) {
3310 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); 3308 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
3311 ws[0] = '\0'; 3309 ws[0] = '\0'; wpos = 0;
3312 wpos = 0;
3313 } 3310 }
3314 while(len_protocol--){ 3311 while (len_protocol--) {
3315 /* Skip the next len_protocol characters, but make sure they're 3312 /* Skip the next len_protocol characters, but
3316 copied into the ws array. 3313 * make sure they're copied into the ws array.
3317 */ 3314 */
3318 ws [wpos++] = *c++; 3315 ws [wpos++] = *c++;
3319 pos++; 3316 pos++;
3320 } 3317 }
3321 if (!imhtml->edit.link) { 3318 if (!imhtml->edit.link) {
3322 while (*c && *c != ' ') { 3319 while (*c && *c != ' ') {
3323 ws [wpos++] = *c++; 3320 ws [wpos++] = *c++;
3324 pos++; 3321 pos++;
3362 } 3359 }
3363 3360
3364 ws[wpos] = '\0'; 3361 ws[wpos] = '\0';
3365 gtk_text_buffer_insert(imhtml->text_buffer, &line_iter, ws, wpos); 3362 gtk_text_buffer_insert(imhtml->text_buffer, &line_iter, ws, wpos);
3366 gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(&line_iter), iter); 3363 gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(&line_iter), iter);
3367 ws[0] = '\0'; 3364 ws[0] = '\0'; wpos = 0;
3368 wpos = 0;
3369 } 3365 }
3370 3366
3371 while (fonts) { 3367 while (fonts) {
3372 GtkIMHtmlFontDetail *font = fonts->data; 3368 GtkIMHtmlFontDetail *font = fonts->data;
3373 fonts = g_slist_remove (fonts, font); 3369 fonts = g_slist_remove (fonts, font);
5751 gboolean (*activate)(GtkIMHtml *imhtml, GtkIMHtmlLink *link), 5747 gboolean (*activate)(GtkIMHtml *imhtml, GtkIMHtmlLink *link),
5752 gboolean (*context_menu)(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu)) 5748 gboolean (*context_menu)(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu))
5753 { 5749 {
5754 GtkIMHtmlClass *klass; 5750 GtkIMHtmlClass *klass;
5755 GtkIMHtmlProtocol *proto; 5751 GtkIMHtmlProtocol *proto;
5752 char *protocol;
5756 5753
5757 g_return_val_if_fail(name, FALSE); 5754 g_return_val_if_fail(name, FALSE);
5758 5755
5759 klass = g_type_class_ref(GTK_TYPE_IMHTML); 5756 klass = g_type_class_ref(GTK_TYPE_IMHTML);
5760 g_return_val_if_fail(klass, FALSE); 5757 g_return_val_if_fail(klass, FALSE);
5761 5758
5762 if ((proto = imhtml_find_protocol(name))) { 5759 protocol = g_strdup_printf("%s:", name);
5760 if ((proto = imhtml_find_protocol(protocol))) {
5761 g_free(protocol);
5763 g_return_val_if_fail(!activate, FALSE); 5762 g_return_val_if_fail(!activate, FALSE);
5764 g_free(proto->name); 5763 g_free(proto->name);
5765 g_free(proto); 5764 g_free(proto);
5766 klass->protocols = g_list_remove(klass->protocols, proto); 5765 klass->protocols = g_list_remove(klass->protocols, proto);
5767 return TRUE; 5766 return TRUE;
5768 } else { 5767 } else {
5769 g_return_val_if_fail(activate, FALSE); 5768 g_return_val_if_fail(activate, FALSE);
5770 } 5769 }
5771 5770
5772 proto = g_new0(GtkIMHtmlProtocol, 1); 5771 proto = g_new0(GtkIMHtmlProtocol, 1);
5773 proto->name = g_strdup(name); 5772 proto->name = protocol;
5774 proto->length = strlen(name); 5773 proto->length = strlen(protocol);
5775 proto->activate = activate; 5774 proto->activate = activate;
5776 proto->context_menu = context_menu; 5775 proto->context_menu = context_menu;
5777 klass->protocols = g_list_prepend(klass->protocols, proto); 5776 klass->protocols = g_list_prepend(klass->protocols, proto);
5778 5777
5779 return TRUE; 5778 return TRUE;

mercurial