| 468 gdk_color_parse(styles[i].def, &defcolor); |
468 gdk_color_parse(styles[i].def, &defcolor); |
| 469 g_object_set(tag, "foreground-gdk", &defcolor, NULL); |
469 g_object_set(tag, "foreground-gdk", &defcolor, NULL); |
| 470 } |
470 } |
| 471 } |
471 } |
| 472 parent_style_set(widget, prev_style); |
472 parent_style_set(widget, prev_style); |
| |
473 } |
| |
474 |
| |
475 static gboolean |
| |
476 imhtml_get_iter_bounds(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| |
477 { |
| |
478 if (imhtml->wbfo) { |
| |
479 gtk_text_buffer_get_bounds(imhtml->text_buffer, start, end); |
| |
480 return TRUE; |
| |
481 } else if (imhtml->editable) { |
| |
482 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, start, end)) { |
| |
483 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| |
484 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, start, mark); |
| |
485 *end = *start; |
| |
486 } |
| |
487 return TRUE; |
| |
488 } |
| |
489 |
| |
490 return FALSE; |
| 473 } |
491 } |
| 474 |
492 |
| 475 static void |
493 static void |
| 476 gtk_imhtml_set_link_color(GtkIMHtml *imhtml, GtkTextTag *tag) |
494 gtk_imhtml_set_link_color(GtkIMHtml *imhtml, GtkTextTag *tag) |
| 477 { |
495 { |
| 4302 GtkTextIter start, end; |
4320 GtkTextIter start, end; |
| 4303 |
4321 |
| 4304 if (!imhtml->editable) |
4322 if (!imhtml->editable) |
| 4305 return; |
4323 return; |
| 4306 |
4324 |
| 4307 if (imhtml->wbfo) |
4325 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4308 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4326 return; |
| 4309 else if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
|
| 4310 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
|
| 4311 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, mark); |
|
| 4312 end = start; |
|
| 4313 } |
|
| 4314 |
4327 |
| 4315 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
4328 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
| 4316 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
4329 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
| 4317 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4330 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
| 4318 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4331 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
| 4651 { |
4664 { |
| 4652 GtkTextIter start, end; |
4665 GtkTextIter start, end; |
| 4653 |
4666 |
| 4654 imhtml->edit.bold = !imhtml->edit.bold; |
4667 imhtml->edit.bold = !imhtml->edit.bold; |
| 4655 |
4668 |
| 4656 if (imhtml->wbfo) { |
4669 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4657 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4670 return; |
| 4658 if (imhtml->edit.bold) |
4671 |
| 4659 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
4672 if (imhtml->edit.bold) |
| 4660 else |
4673 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
| 4661 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
4674 else |
| 4662 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
4675 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
| 4663 if (imhtml->edit.bold) |
|
| 4664 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
|
| 4665 else |
|
| 4666 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
|
| 4667 |
|
| 4668 } |
|
| 4669 } |
4676 } |
| 4670 |
4677 |
| 4671 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
4678 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
| 4672 { |
4679 { |
| 4673 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_BOLD); |
4680 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_BOLD); |
| 4677 { |
4684 { |
| 4678 GtkTextIter start, end; |
4685 GtkTextIter start, end; |
| 4679 |
4686 |
| 4680 imhtml->edit.italic = !imhtml->edit.italic; |
4687 imhtml->edit.italic = !imhtml->edit.italic; |
| 4681 |
4688 |
| 4682 if (imhtml->wbfo) { |
4689 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4683 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4690 return; |
| 4684 if (imhtml->edit.italic) |
4691 |
| 4685 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
4692 if (imhtml->edit.italic) |
| 4686 else |
4693 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
| 4687 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
4694 else |
| 4688 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
4695 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
| 4689 if (imhtml->edit.italic) |
|
| 4690 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
|
| 4691 else |
|
| 4692 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
|
| 4693 } |
|
| 4694 } |
4696 } |
| 4695 |
4697 |
| 4696 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) |
4698 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) |
| 4697 { |
4699 { |
| 4698 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_ITALIC); |
4700 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_ITALIC); |
| 4702 { |
4704 { |
| 4703 GtkTextIter start, end; |
4705 GtkTextIter start, end; |
| 4704 |
4706 |
| 4705 imhtml->edit.underline = !imhtml->edit.underline; |
4707 imhtml->edit.underline = !imhtml->edit.underline; |
| 4706 |
4708 |
| 4707 if (imhtml->wbfo) { |
4709 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4708 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4710 return; |
| 4709 if (imhtml->edit.underline) |
4711 |
| 4710 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4712 if (imhtml->edit.underline) |
| 4711 else |
4713 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
| 4712 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4714 else |
| 4713 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
4715 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
| 4714 if (imhtml->edit.underline) |
|
| 4715 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
|
| 4716 else |
|
| 4717 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
|
| 4718 } |
|
| 4719 } |
4716 } |
| 4720 |
4717 |
| 4721 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) |
4718 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) |
| 4722 { |
4719 { |
| 4723 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_UNDERLINE); |
4720 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_UNDERLINE); |
| 4727 { |
4724 { |
| 4728 GtkTextIter start, end; |
4725 GtkTextIter start, end; |
| 4729 |
4726 |
| 4730 imhtml->edit.strike = !imhtml->edit.strike; |
4727 imhtml->edit.strike = !imhtml->edit.strike; |
| 4731 |
4728 |
| 4732 if (imhtml->wbfo) { |
4729 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4733 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4730 return; |
| 4734 if (imhtml->edit.strike) |
4731 |
| 4735 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4732 if (imhtml->edit.strike) |
| 4736 else |
4733 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
| 4737 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4734 else |
| 4738 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
4735 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
| 4739 if (imhtml->edit.strike) |
|
| 4740 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
|
| 4741 else |
|
| 4742 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
|
| 4743 } |
|
| 4744 } |
4736 } |
| 4745 |
4737 |
| 4746 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml) |
4738 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml) |
| 4747 { |
4739 { |
| 4748 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_STRIKE); |
4740 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_STRIKE); |
| 4753 GObject *object; |
4745 GObject *object; |
| 4754 GtkTextIter start, end; |
4746 GtkTextIter start, end; |
| 4755 |
4747 |
| 4756 imhtml->edit.fontsize = size; |
4748 imhtml->edit.fontsize = size; |
| 4757 |
4749 |
| 4758 if (imhtml->wbfo) { |
4750 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4759 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4751 return; |
| 4760 remove_font_size(imhtml, &start, &end, TRUE); |
4752 |
| 4761 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4753 remove_font_size(imhtml, &start, &end, imhtml->wbfo); |
| 4762 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4754 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4763 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
4755 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
| 4764 remove_font_size(imhtml, &start, &end, FALSE); |
|
| 4765 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
|
| 4766 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
|
| 4767 } |
|
| 4768 |
4756 |
| 4769 object = g_object_ref(G_OBJECT(imhtml)); |
4757 object = g_object_ref(G_OBJECT(imhtml)); |
| 4770 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK | GTK_IMHTML_GROW); |
4758 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK | GTK_IMHTML_GROW); |
| 4771 g_object_unref(object); |
4759 g_object_unref(object); |
| 4772 } |
4760 } |
| 4781 if (!imhtml->edit.fontsize) |
4769 if (!imhtml->edit.fontsize) |
| 4782 imhtml->edit.fontsize = 2; |
4770 imhtml->edit.fontsize = 2; |
| 4783 else |
4771 else |
| 4784 imhtml->edit.fontsize--; |
4772 imhtml->edit.fontsize--; |
| 4785 |
4773 |
| 4786 if (imhtml->wbfo) { |
4774 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4787 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4775 return; |
| 4788 remove_font_size(imhtml, &start, &end, TRUE); |
4776 remove_font_size(imhtml, &start, &end, imhtml->wbfo); |
| 4789 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4777 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4790 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4778 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
| 4791 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
|
| 4792 remove_font_size(imhtml, &start, &end, FALSE); |
|
| 4793 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
|
| 4794 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
|
| 4795 } |
|
| 4796 } |
4779 } |
| 4797 |
4780 |
| 4798 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) |
4781 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) |
| 4799 { |
4782 { |
| 4800 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_SHRINK); |
4783 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_SHRINK); |
| 4810 if (!imhtml->edit.fontsize) |
4793 if (!imhtml->edit.fontsize) |
| 4811 imhtml->edit.fontsize = 4; |
4794 imhtml->edit.fontsize = 4; |
| 4812 else |
4795 else |
| 4813 imhtml->edit.fontsize++; |
4796 imhtml->edit.fontsize++; |
| 4814 |
4797 |
| 4815 if (imhtml->wbfo) { |
4798 if (!imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4816 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4799 return; |
| 4817 remove_font_size(imhtml, &start, &end, TRUE); |
4800 remove_font_size(imhtml, &start, &end, imhtml->wbfo); |
| 4818 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4801 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4819 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4802 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
| 4820 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
|
| 4821 remove_font_size(imhtml, &start, &end, FALSE); |
|
| 4822 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
|
| 4823 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
|
| 4824 } |
|
| 4825 } |
4803 } |
| 4826 |
4804 |
| 4827 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) |
4805 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) |
| 4828 { |
4806 { |
| 4829 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_GROW); |
4807 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_GROW); |
| 4842 |
4820 |
| 4843 if (value && strcmp(value, "") != 0) |
4821 if (value && strcmp(value, "") != 0) |
| 4844 { |
4822 { |
| 4845 *edit_field = g_strdup(value); |
4823 *edit_field = g_strdup(value); |
| 4846 |
4824 |
| 4847 if (imhtml->wbfo) |
4825 if (imhtml_get_iter_bounds(imhtml, &start, &end)) { |
| 4848 { |
4826 remove_func(imhtml, &start, &end, imhtml->wbfo); |
| 4849 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
| 4850 remove_func(imhtml, &start, &end, TRUE); |
|
| 4851 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4827 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4852 find_func(imhtml, *edit_field), &start, &end); |
4828 find_func(imhtml, *edit_field), &start, &end); |
| 4853 } |
|
| 4854 else |
|
| 4855 { |
|
| 4856 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, |
|
| 4857 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); |
|
| 4858 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
|
| 4859 { |
|
| 4860 remove_func(imhtml, &start, &end, FALSE); |
|
| 4861 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
|
| 4862 find_func(imhtml, |
|
| 4863 *edit_field), |
|
| 4864 &start, &end); |
|
| 4865 } |
|
| 4866 } |
4829 } |
| 4867 } |
4830 } |
| 4868 else |
4831 else |
| 4869 { |
4832 { |
| 4870 if (imhtml->wbfo) |
4833 if (imhtml_get_iter_bounds(imhtml, &start, &end)) |
| 4871 { |
4834 remove_func(imhtml, &start, &end, TRUE); /* 'TRUE' or 'imhtml->wbfo'? */ |
| 4872 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
| 4873 remove_func(imhtml, &start, &end, TRUE); |
|
| 4874 } |
|
| 4875 else |
|
| 4876 { |
|
| 4877 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
|
| 4878 remove_func(imhtml, &start, &end, TRUE); |
|
| 4879 } |
|
| 4880 } |
4835 } |
| 4881 |
4836 |
| 4882 object = g_object_ref(G_OBJECT(imhtml)); |
4837 object = g_object_ref(G_OBJECT(imhtml)); |
| 4883 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); |
4838 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); |
| 4884 g_object_unref(object); |
4839 g_object_unref(object); |