| 3545 imhtml->protocol_name = g_strdup(protocol_name); |
3545 imhtml->protocol_name = g_strdup(protocol_name); |
| 3546 } |
3546 } |
| 3547 |
3547 |
| 3548 void |
3548 void |
| 3549 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) { |
3549 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) { |
| 3550 GList *l; |
3550 GtkTextIter i_s, i_e; |
| 3551 GSList *sl; |
|
| 3552 GtkTextIter i, i_s, i_e; |
|
| 3553 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
3551 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
| 3554 |
3552 |
| 3555 if (start == NULL) { |
3553 if (start == NULL) { |
| 3556 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s); |
3554 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s); |
| 3557 start = &i_s; |
3555 start = &i_s; |
| 3560 if (end == NULL) { |
3558 if (end == NULL) { |
| 3561 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e); |
3559 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e); |
| 3562 end = &i_e; |
3560 end = &i_e; |
| 3563 } |
3561 } |
| 3564 |
3562 |
| 3565 l = imhtml->scalables; |
3563 /* This will cause the signal handler to get called which will call |
| 3566 while (l) { |
3564 * delete_cb and clean up everything else. */ |
| 3567 GList *next = l->next; |
|
| 3568 struct scalable_data *sd = l->data; |
|
| 3569 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
|
| 3570 &i, sd->mark); |
|
| 3571 if (gtk_text_iter_in_range(&i, start, end)) { |
|
| 3572 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
|
| 3573 scale->free(scale); |
|
| 3574 g_free(sd); |
|
| 3575 imhtml->scalables = g_list_delete_link(imhtml->scalables, l); |
|
| 3576 } |
|
| 3577 l = next; |
|
| 3578 } |
|
| 3579 |
|
| 3580 sl = imhtml->im_images; |
|
| 3581 while (sl) { |
|
| 3582 GSList *next = sl->next; |
|
| 3583 struct im_image_data *img_data = sl->data; |
|
| 3584 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
|
| 3585 &i, img_data->mark); |
|
| 3586 if (gtk_text_iter_in_range(&i, start, end)) { |
|
| 3587 if (imhtml->funcs->image_unref) |
|
| 3588 imhtml->funcs->image_unref(img_data->id); |
|
| 3589 imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl); |
|
| 3590 g_free(img_data); |
|
| 3591 } |
|
| 3592 sl = next; |
|
| 3593 } |
|
| 3594 gtk_text_buffer_delete(imhtml->text_buffer, start, end); |
3565 gtk_text_buffer_delete(imhtml->text_buffer, start, end); |
| 3595 |
3566 |
| |
3567 /* This is wrong, but i'm not trying to total what we actually removed. */ |
| 3596 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_total", GINT_TO_POINTER(0)); |
3568 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_total", GINT_TO_POINTER(0)); |
| 3597 |
3569 |
| 3598 g_object_unref(object); |
3570 g_object_unref(object); |
| 3599 } |
3571 } |
| 3600 |
3572 |
| 4371 gtk_imhtml_apply_tags_on_insert(imhtml, &start, end); |
4343 gtk_imhtml_apply_tags_on_insert(imhtml, &start, end); |
| 4372 } |
4344 } |
| 4373 |
4345 |
| 4374 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, GtkIMHtml *imhtml) |
4346 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, GtkIMHtml *imhtml) |
| 4375 { |
4347 { |
| 4376 GSList *tags, *l; |
4348 GList *l; |
| 4377 |
4349 GSList *tags, *sl; |
| |
4350 GtkTextIter i; |
| |
4351 |
| |
4352 /* clean up tags */ |
| 4378 tags = gtk_text_iter_get_tags(start); |
4353 tags = gtk_text_iter_get_tags(start); |
| 4379 for (l = tags; l != NULL; l = l->next) { |
4354 for (sl = tags; sl != NULL; sl = sl->next) { |
| 4380 GtkTextTag *tag = GTK_TEXT_TAG(l->data); |
4355 GtkTextTag *tag = GTK_TEXT_TAG(sl->data); |
| 4381 |
4356 |
| 4382 if (tag && /* Remove the formatting only if */ |
4357 if (tag && /* Remove the formatting only if */ |
| 4383 gtk_text_iter_starts_word(start) && /* beginning of a word */ |
4358 gtk_text_iter_starts_word(start) && /* beginning of a word */ |
| 4384 gtk_text_iter_begins_tag(start, tag) && /* the tag starts with the selection */ |
4359 gtk_text_iter_begins_tag(start, tag) && /* the tag starts with the selection */ |
| 4385 (!gtk_text_iter_has_tag(end, tag) || /* the tag ends within the selection */ |
4360 (!gtk_text_iter_has_tag(end, tag) || /* the tag ends within the selection */ |
| 4390 gtk_imhtml_toggle_link(imhtml, NULL); |
4365 gtk_imhtml_toggle_link(imhtml, NULL); |
| 4391 } |
4366 } |
| 4392 } |
4367 } |
| 4393 } |
4368 } |
| 4394 g_slist_free(tags); |
4369 g_slist_free(tags); |
| |
4370 |
| |
4371 /* remove scalables */ |
| |
4372 l = imhtml->scalables; |
| |
4373 while (l) { |
| |
4374 GList *next = l->next; |
| |
4375 struct scalable_data *sd = l->data; |
| |
4376 |
| |
4377 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &i, sd->mark); |
| |
4378 if (gtk_text_iter_in_range(&i, start, end)) { |
| |
4379 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
| |
4380 scale->free(scale); |
| |
4381 g_free(sd); |
| |
4382 imhtml->scalables = g_list_delete_link(imhtml->scalables, l); |
| |
4383 } |
| |
4384 l = next; |
| |
4385 } |
| |
4386 |
| |
4387 /* remove images */ |
| |
4388 sl = imhtml->im_images; |
| |
4389 while (sl) { |
| |
4390 GSList *next = sl->next; |
| |
4391 struct im_image_data *img_data = sl->data; |
| |
4392 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
| |
4393 &i, img_data->mark); |
| |
4394 if (gtk_text_iter_in_range(&i, start, end)) { |
| |
4395 if (imhtml->funcs->image_unref) |
| |
4396 imhtml->funcs->image_unref(img_data->id); |
| |
4397 imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl); |
| |
4398 g_free(img_data); |
| |
4399 } |
| |
4400 sl = next; |
| |
4401 } |
| 4395 } |
4402 } |
| 4396 |
4403 |
| 4397 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
4404 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 4398 { |
4405 { |
| 4399 if (imhtml->edit.bold) |
4406 if (imhtml->edit.bold) |