Wed, 28 Feb 2024 00:11:14 -0600
use a globally unique id when creating new Pidgin::DisplayItem's
Use a globally unique id when creating new `Pidgin::DisplayItem`s as the doc demands and as discussed on [discourse](https://discourse.imfreedom.org/t/how-is-pidgin-id-supposed-to-be-unique/134/2)
Testing Done:
Ran Pidgin and opened a conversation.
Reviewed at https://reviews.imfreedom.org/r/2980/
|
42456
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Pidgin - Internet Messenger |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * Pidgin is the legal property of its developers, whose names are too numerous |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * source distribution. |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * This program is free software; you can redistribute it and/or modify |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * it under the terms of the GNU General Public License as published by |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * the Free Software Foundation; either version 2 of the License, or |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * (at your option) any later version. |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * This program is distributed in the hope that it will be useful, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | * GNU General Public License for more details. |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | * |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | #include <purple.h> |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | #include "pidgintextbuffer.h" |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | /****************************************************************************** |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | * Helpers |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | *****************************************************************************/ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | static void |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | pidgin_text_buffer_get_html_convert_tag(GtkTextTag *tag, gboolean start, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | GString *output) |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | /* In practice gtk_text_buffer_insert_markup seems to create a single tag |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 | * for each attribute, but we'll check everything anyways to be try and |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 | * work with any buffer. |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | gboolean strikethrough; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | gboolean strikethrough_set; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | PangoStyle style; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | gboolean style_set; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | PangoUnderline underline; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | gboolean underline_set; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 | int weight; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 | gboolean weight_set; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | const char *format = "<%s>"; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | if(!start) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | format = "</%s>"; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | g_object_get( |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | G_OBJECT(tag), |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | "strikethrough", &strikethrough, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | "strikethrough-set", &strikethrough_set, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | "style", &style, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | "style-set", &style_set, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | "underline", &underline, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | "underline-set", &underline_set, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | "weight", &weight, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | "weight-set", &weight_set, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | if(style_set && style != PANGO_STYLE_NORMAL) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | g_string_append_printf(output, format, "i"); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | if(weight_set && weight > PANGO_WEIGHT_NORMAL) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | g_string_append_printf(output, format, "b"); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | if(underline_set && underline != PANGO_UNDERLINE_NONE) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | g_string_append_printf(output, format, "u"); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | if(strikethrough_set && strikethrough) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | g_string_append_printf(output, format, "s"); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | static void |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | pidgin_text_buffer_get_html_start_tag(gpointer data, gpointer user_data) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | pidgin_text_buffer_get_html_convert_tag(data, TRUE, user_data); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | static void |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | pidgin_text_buffer_get_html_process_start_tags(GSList *tags, GString *output) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | g_slist_foreach(tags, pidgin_text_buffer_get_html_start_tag, output); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | static void |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | pidgin_text_buffer_get_html_end_tag(gpointer data, gpointer user_data) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | pidgin_text_buffer_get_html_convert_tag(data, FALSE, user_data); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | static void |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | pidgin_text_buffer_get_html_process_end_tags(GSList *tags, GString *output) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | g_slist_foreach(tags, pidgin_text_buffer_get_html_end_tag, output); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | /****************************************************************************** |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | * Public API |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 | *****************************************************************************/ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 | char * |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | pidgin_text_buffer_get_html(GtkTextBuffer *buffer) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 | GtkTextIter start; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 | GtkTextIter end; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
110 | g_return_val_if_fail(GTK_IS_TEXT_BUFFER(buffer), NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 | gtk_text_buffer_get_start_iter(buffer, &start); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | gtk_text_buffer_get_end_iter(buffer, &end); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 | return pidgin_text_buffer_get_html_range(buffer, &start, &end); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 | char * |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 | pidgin_text_buffer_get_html_range(GtkTextBuffer *buffer, GtkTextIter *start, |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | GtkTextIter *end) |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 | GSList *tags = NULL; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 | GString *output = NULL; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
124 | GtkTextIter real_start; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
125 | GtkTextIter real_end; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 | GtkTextIter next; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
127 | GtkTextIter position; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 | char *text = NULL; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 | g_return_val_if_fail(GTK_IS_TEXT_BUFFER(buffer), NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
131 | g_return_val_if_fail(start != NULL, NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
132 | g_return_val_if_fail(end != NULL, NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
133 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 | /* Copy start and end to not modify the caller's copies, then make sure |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 | * they're ordered correctly. |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
136 | */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
137 | real_start = *start; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
138 | real_end = *end; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
139 | gtk_text_iter_order(&real_start, &real_end); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
140 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
141 | /* Create our iterators that we use to walk the text. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
142 | position = real_start; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
143 | next = real_start; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
144 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
145 | output = g_string_new(""); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
146 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
147 | /* Process the tags at our starting position. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
148 | tags = gtk_text_iter_get_tags(&position); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 | pidgin_text_buffer_get_html_process_start_tags(tags, output); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
150 | g_clear_slist(&tags, NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
151 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
152 | /* Now walk the text looking for tags that are being toggled. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
153 | while(gtk_text_iter_forward_to_tag_toggle(&next, NULL)) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
154 | /* If next is past real_end, we need to bail. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
155 | if(gtk_text_iter_compare(&next, &real_end) >= 0) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
156 | break; |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
157 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
158 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
159 | /* Append the text in the range. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
160 | text = gtk_text_buffer_get_text(buffer, &position, &next, TRUE); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 | g_string_append(output, text); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 | g_clear_pointer(&text, g_free); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
163 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
164 | /* Process the closed tags. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
165 | tags = gtk_text_iter_get_toggled_tags(&next, FALSE); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
166 | pidgin_text_buffer_get_html_process_end_tags(tags, output); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
167 | g_clear_slist(&tags, NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
168 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
169 | /* Process the opened tags. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
170 | tags = gtk_text_iter_get_toggled_tags(&next, TRUE); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
171 | pidgin_text_buffer_get_html_process_start_tags(tags, output); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
172 | g_clear_slist(&tags, NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
173 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
174 | /* Increment our iterators. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
175 | gtk_text_iter_forward_to_tag_toggle(&position, NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
176 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 | /* Copy the remaining text. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 | text = gtk_text_buffer_get_text(buffer, &position, &real_end, TRUE); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 | if(text != NULL) { |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
181 | g_string_append(output, text); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 | g_clear_pointer(&text, g_free); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 | } |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 | /* Write out any final tags, we reverse them because they seem to be |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 | * prepended. This is more of a guess than anything really. */ |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 | tags = gtk_text_iter_get_tags(&position); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
188 | tags = g_slist_reverse(tags); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 | pidgin_text_buffer_get_html_process_end_tags(tags, output); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 | g_clear_slist(&tags, NULL); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 | |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 | return g_string_free(output, FALSE); |
|
73bb1fae628c
Create pidgin_text_buffer API for working with GtkTextBuffers
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
193 | } |