Mercurial > pidgin.yaz
annotate src/gtkimhtml.c @ 12833:cb2d493e1925
[gaim-migrate @ 15181]
Eliminate and empty (but not logically useless) if block by reworking the logic.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 11 Jan 2006 22:53:37 +0000 |
parents | e8db8f94a2db |
children | 339d61ebca8a |
rev | line source |
---|---|
1428 | 1 /* |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10243
diff
changeset
|
2 * @file gtkimhtml.c GTK+ IMHtml |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10243
diff
changeset
|
3 * @ingroup gtkui |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10243
diff
changeset
|
4 * |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10243
diff
changeset
|
5 * gaim |
1428 | 6 * |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
1428 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
26 | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
27 #ifdef HAVE_CONFIG_H |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
28 #include <config.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
29 #endif |
8526 | 30 #include "debug.h" |
8091 | 31 #include "util.h" |
1428 | 32 #include "gtkimhtml.h" |
7358 | 33 #include "gtksourceiter.h" |
1428 | 34 #include <gtk/gtk.h> |
4895 | 35 #include <glib/gerror.h> |
4046 | 36 #include <gdk/gdkkeysyms.h> |
1428 | 37 #include <string.h> |
38 #include <ctype.h> | |
39 #include <stdio.h> | |
4629 | 40 #include <stdlib.h> |
1428 | 41 #include <math.h> |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
42 #ifdef HAVE_LANGINFO_CODESET |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
43 #include <langinfo.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
44 #include <locale.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
45 #endif |
8692 | 46 #ifdef _WIN32 |
10901
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
47 #include <gdk/gdkwin32.h> |
8692 | 48 #include <windows.h> |
49 #endif | |
1428 | 50 |
4417 | 51 #ifdef ENABLE_NLS |
52 # include <libintl.h> | |
53 # define _(x) gettext(x) | |
54 # ifdef gettext_noop | |
55 # define N_(String) gettext_noop (String) | |
56 # else | |
57 # define N_(String) (String) | |
58 # endif | |
59 #else | |
60 # define N_(String) (String) | |
61 # define _(x) (x) | |
62 #endif | |
63 | |
4735 | 64 #include <pango/pango-font.h> |
65 | |
10062 | 66 /* GTK+ < 2.4.x hack, see gtkgaim.h for details. */ |
67 #if (!GTK_CHECK_VERSION(2,4,0)) | |
5105 | 68 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD |
69 #endif | |
70 | |
4735 | 71 #define TOOLTIP_TIMEOUT 500 |
72 | |
8786 | 73 /* GTK+ 2.0 hack */ |
74 #if (!GTK_CHECK_VERSION(2,2,0)) | |
75 #define gtk_widget_get_clipboard(x, y) gtk_clipboard_get(y) | |
76 #endif | |
77 | |
10100 | 78 static GtkTextViewClass *parent_class = NULL; |
79 | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
80 struct scalable_data { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
81 GtkIMHtmlScalable *scalable; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
82 GtkTextMark *mark; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
83 }; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
84 |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
85 |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
86 struct im_image_data { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
87 int id; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
88 GtkTextMark *mark; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
89 }; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
90 |
9300 | 91 static gboolean |
92 gtk_text_view_drag_motion (GtkWidget *widget, | |
93 GdkDragContext *context, | |
94 gint x, | |
95 gint y, | |
96 guint time); | |
97 | |
8677 | 98 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
8061 | 99 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
12673
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
100 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml); |
10169 | 101 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data); |
102 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end); | |
8505 | 103 static gboolean gtk_imhtml_is_amp_escape (const gchar *string, gchar **replace, gint *length); |
8698 | 104 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter); |
9300 | 105 static void gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data); |
8091 | 106 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); |
8677 | 107 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml); |
8931 | 108 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data); |
109 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data); | |
110 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data); | |
10901
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
111 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext); |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
112 static void imhtml_toggle_bold(GtkIMHtml *imhtml); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
113 static void imhtml_toggle_italic(GtkIMHtml *imhtml); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
114 static void imhtml_toggle_strike(GtkIMHtml *imhtml); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
115 static void imhtml_toggle_underline(GtkIMHtml *imhtml); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
116 static void imhtml_font_grow(GtkIMHtml *imhtml); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
117 static void imhtml_font_shrink(GtkIMHtml *imhtml); |
12672
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
118 static void imhtml_clear_formatting(GtkIMHtml *imhtml); |
8061 | 119 |
10899 | 120 /* POINT_SIZE converts from AIM font sizes to a point size scale factor. */ |
3922 | 121 #define MAX_FONT_SIZE 7 |
10900 | 122 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1]) |
8380 | 123 static gdouble _point_sizes [] = { .69444444, .8333333, 1, 1.2, 1.44, 1.728, 2.0736}; |
2349
60c716c32c40
[gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2348
diff
changeset
|
124 |
10184 | 125 enum { |
8677 | 126 TARGET_HTML, |
8061 | 127 TARGET_UTF8_STRING, |
128 TARGET_COMPOUND_TEXT, | |
129 TARGET_STRING, | |
130 TARGET_TEXT | |
131 }; | |
132 | |
8091 | 133 enum { |
8420 | 134 URL_CLICKED, |
135 BUTTONS_UPDATE, | |
136 TOGGLE_FORMAT, | |
8427 | 137 CLEAR_FORMAT, |
8506 | 138 UPDATE_FORMAT, |
10108 | 139 MESSAGE_SEND, |
8420 | 140 LAST_SIGNAL |
141 }; | |
142 static guint signals [LAST_SIGNAL] = { 0 }; | |
143 | |
10871 | 144 static GtkTargetEntry selection_targets[] = { |
8566 | 145 { "text/html", 0, TARGET_HTML }, |
8061 | 146 { "UTF8_STRING", 0, TARGET_UTF8_STRING }, |
147 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | |
148 { "STRING", 0, TARGET_STRING }, | |
149 { "TEXT", 0, TARGET_TEXT}}; | |
150 | |
10871 | 151 static GtkTargetEntry link_drag_drop_targets[] = { |
10145 | 152 GTK_IMHTML_DND_TARGETS |
153 }; | |
8091 | 154 |
8692 | 155 #ifdef _WIN32 |
156 /* Win32 clipboard format value, and functions to convert back and | |
157 * forth between HTML and the clipboard format. | |
158 */ | |
159 static UINT win_html_fmt; | |
160 | |
161 static gchar * | |
162 clipboard_win32_to_html(char *clipboard) { | |
9465 | 163 const char *header; |
8693 | 164 const char *begin, *end; |
10016
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
165 gint start = 0; |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
166 gint finish = 0; |
8692 | 167 gchar *html; |
10016
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
168 gchar **split; |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
169 int clipboard_length = 0; |
9465 | 170 |
171 #if 0 /* Debugging for Windows clipboard */ | |
9467 | 172 FILE *fd; |
173 | |
9465 | 174 gaim_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard); |
175 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10574
diff
changeset
|
176 fd = g_fopen("e:\\gaimcb.txt", "wb"); |
9465 | 177 fprintf(fd, "%s", clipboard); |
178 fclose(fd); | |
179 #endif | |
180 | |
10016
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
181 clipboard_length = strlen(clipboard); |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
182 |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
183 if (!(header = strstr(clipboard, "StartFragment:")) || (header - clipboard) >= clipboard_length) |
9465 | 184 return NULL; |
185 sscanf(header, "StartFragment:%d", &start); | |
186 | |
10016
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
187 if (!(header = strstr(clipboard, "EndFragment:")) || (header - clipboard) >= clipboard_length) |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
188 return NULL; |
9465 | 189 sscanf(header, "EndFragment:%d", &finish); |
190 | |
10016
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
191 if (finish > clipboard_length) |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
192 finish = clipboard_length; |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
193 |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
194 if (start > finish) |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
195 start = finish; |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
196 |
9465 | 197 begin = clipboard + start; |
198 | |
10016
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
199 end = clipboard + finish; |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
200 |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
201 html = g_strndup(begin, end - begin); |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
202 |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
203 /* any newlines in the string will now be \r\n, so we need to strip out the \r */ |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
204 split = g_strsplit(html, "\r\n", 0); |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
205 g_free(html); |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
206 html = g_strjoinv("\n", split); |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
207 g_strfreev(split); |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
208 |
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
209 html = g_strstrip(html); |
9465 | 210 |
211 #if 0 /* Debugging for Windows clipboard */ | |
10016
5b4a0af99bf7
[gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
212 gaim_debug_info("imhtml clipboard", "HTML fragment: '%s'\n", html); |
9465 | 213 #endif |
214 | |
8707 | 215 return html; |
8692 | 216 } |
217 | |
218 static gchar * | |
219 clipboard_html_to_win32(char *html) { | |
8693 | 220 int length; |
11240
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
221 GString *clipboard; |
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
222 gchar *tmp; |
8692 | 223 gchar *ret; |
224 | |
8693 | 225 if (html == NULL) |
226 return NULL; | |
8692 | 227 |
228 length = strlen(html); | |
9465 | 229 clipboard = g_string_new ("Version:1.0\r\n"); |
8692 | 230 g_string_append(clipboard, "StartHTML:0000000105\r\n"); |
11240
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
231 tmp = g_strdup_printf("EndHTML:%010d\r\n", 147 + length); |
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
232 g_string_append(clipboard, tmp); |
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
233 g_free(tmp); |
9465 | 234 g_string_append(clipboard, "StartFragment:0000000127\r\n"); |
11240
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
235 tmp = g_strdup_printf("EndFragment:%010d\r\n", 127 + length); |
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
236 g_string_append(clipboard, tmp); |
2ab2de8add8b
[gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents:
11234
diff
changeset
|
237 g_free(tmp); |
9465 | 238 g_string_append(clipboard, "<!--StartFragment-->\r\n"); |
8692 | 239 g_string_append(clipboard, html); |
9465 | 240 g_string_append(clipboard, "\r\n<!--EndFragment-->"); |
8692 | 241 ret = clipboard->str; |
242 g_string_free(clipboard, FALSE); | |
9465 | 243 |
244 #if 0 /* Debugging for Windows clipboard */ | |
245 gaim_debug_info("imhtml clipboard", "from gaim: %s\n", ret); | |
246 #endif | |
247 | |
8692 | 248 return ret; |
249 } | |
10901
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
250 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
251 static void clipboard_copy_html_win32(GtkIMHtml *imhtml) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
252 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
253 if (clipboard != NULL) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
254 HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
255 if (OpenClipboard(hwnd)) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
256 if (EmptyClipboard()) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
257 gint length = strlen(clipboard); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
258 HGLOBAL hdata = GlobalAlloc(GMEM_MOVEABLE, length); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
259 if (hdata != NULL) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
260 gchar *buffer = GlobalLock(hdata); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
261 memcpy(buffer, clipboard, length); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
262 GlobalUnlock(hdata); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
263 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
264 if (SetClipboardData(win_html_fmt, hdata) == NULL) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
265 gchar *err_msg = |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
266 g_win32_error_message(GetLastError()); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
267 gaim_debug_info("html clipboard", |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
268 "Unable to set clipboard data: %s\n", |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
269 err_msg ? err_msg : "Unknown Error"); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
270 g_free(err_msg); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
271 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
272 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
273 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
274 CloseClipboard(); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
275 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
276 g_free(clipboard); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
277 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
278 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
279 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
280 static gboolean clipboard_paste_html_win32(GtkIMHtml *imhtml) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
281 gboolean pasted = FALSE; |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
282 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
283 if (gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)) |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
284 && IsClipboardFormatAvailable(win_html_fmt)) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
285 gboolean error_reading_clipboard = FALSE; |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
286 HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
287 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
288 if (OpenClipboard(hwnd)) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
289 HGLOBAL hdata = GetClipboardData(win_html_fmt); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
290 if (hdata == NULL) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
291 error_reading_clipboard = TRUE; |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
292 } else { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
293 char *buffer = GlobalLock(hdata); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
294 if (buffer == NULL) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
295 error_reading_clipboard = TRUE; |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
296 } else { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
297 char *text = clipboard_win32_to_html( |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
298 buffer); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
299 imhtml_paste_insert(imhtml, text, |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
300 FALSE); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
301 g_free(text); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
302 pasted = TRUE; |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
303 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
304 GlobalUnlock(hdata); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
305 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
306 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
307 CloseClipboard(); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
308 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
309 } else { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
310 error_reading_clipboard = TRUE; |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
311 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
312 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
313 if (error_reading_clipboard) { |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
314 gchar *err_msg = g_win32_error_message(GetLastError()); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
315 gaim_debug_info("html clipboard", |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
316 "Unable to read clipboard data: %s\n", |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
317 err_msg ? err_msg : "Unknown Error"); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
318 g_free(err_msg); |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
319 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
320 } |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
321 |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
322 return pasted; |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
323 } |
8692 | 324 #endif |
325 | |
4032 | 326 static GtkSmileyTree* |
327 gtk_smiley_tree_new () | |
328 { | |
329 return g_new0 (GtkSmileyTree, 1); | |
330 } | |
331 | |
332 static void | |
333 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
4263 | 334 GtkIMHtmlSmiley *smiley) |
4032 | 335 { |
336 GtkSmileyTree *t = tree; | |
4263 | 337 const gchar *x = smiley->smile; |
4032 | 338 |
12229
18f0dadb29cf
[gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents:
12072
diff
changeset
|
339 if (!(*x)) |
4032 | 340 return; |
341 | |
12229
18f0dadb29cf
[gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents:
12072
diff
changeset
|
342 do { |
4032 | 343 gchar *pos; |
344 gint index; | |
345 | |
346 if (!t->values) | |
347 t->values = g_string_new (""); | |
348 | |
349 pos = strchr (t->values->str, *x); | |
350 if (!pos) { | |
351 t->values = g_string_append_c (t->values, *x); | |
352 index = t->values->len - 1; | |
353 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
354 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
355 } else | |
7386 | 356 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
8061 | 357 |
4032 | 358 t = t->children [index]; |
8061 | 359 |
4032 | 360 x++; |
12229
18f0dadb29cf
[gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents:
12072
diff
changeset
|
361 } while (*x); |
8061 | 362 |
4263 | 363 t->image = smiley; |
4032 | 364 } |
4041 | 365 |
4263 | 366 |
11677 | 367 static void |
368 gtk_smiley_tree_destroy (GtkSmileyTree *tree) | |
4032 | 369 { |
11701
5d7da4056644
[gaim-migrate @ 13992]
Richard Laager <rlaager@wiktel.com>
parents:
11677
diff
changeset
|
370 GSList *list = g_slist_prepend (NULL, tree); |
4032 | 371 |
372 while (list) { | |
373 GtkSmileyTree *t = list->data; | |
12229
18f0dadb29cf
[gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents:
12072
diff
changeset
|
374 gsize i; |
4032 | 375 list = g_slist_remove(list, t); |
7384 | 376 if (t && t->values) { |
4032 | 377 for (i = 0; i < t->values->len; i++) |
11701
5d7da4056644
[gaim-migrate @ 13992]
Richard Laager <rlaager@wiktel.com>
parents:
11677
diff
changeset
|
378 list = g_slist_prepend (list, t->children [i]); |
4032 | 379 g_string_free (t->values, TRUE); |
380 g_free (t->children); | |
381 } | |
382 g_free (t); | |
383 } | |
384 } | |
385 | |
11840
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
386 static void gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
5967 | 387 { |
388 GdkRectangle rect; | |
8726 | 389 int xminus; |
5967 | 390 |
391 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); | |
392 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ | |
393 GList *iter = GTK_IMHTML(widget)->scalables; | |
394 | |
8726 | 395 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) + |
396 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget)); | |
397 | |
5967 | 398 while(iter){ |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
399 struct scalable_data *sd = iter->data; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
400 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
8726 | 401 scale->scale(scale, rect.width - xminus, rect.height); |
5967 | 402 |
403 iter = iter->next; | |
404 } | |
405 } | |
406 | |
407 widget->old_rect = rect; | |
11840
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
408 return; |
5967 | 409 } |
410 | |
411 static gint | |
412 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
413 { | |
414 PangoLayout *layout; | |
415 | |
416 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
417 | |
418 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
419 | |
8061 | 420 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, |
5967 | 421 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, |
422 "tooltip", 0, 0, -1, -1); | |
423 | |
424 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
425 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
426 | |
427 g_object_unref(layout); | |
428 return FALSE; | |
429 } | |
430 | |
431 static gint | |
432 gtk_imhtml_tip (gpointer data) | |
433 { | |
434 GtkIMHtml *imhtml = data; | |
8526 | 435 PangoFontMetrics *font_metrics; |
5967 | 436 PangoLayout *layout; |
8526 | 437 PangoFont *font; |
5967 | 438 |
439 gint gap, x, y, h, w, scr_w, baseline_skip; | |
440 | |
441 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
442 | |
443 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
444 imhtml->tip_timer = 0; | |
445 return FALSE; | |
446 } | |
8061 | 447 |
5967 | 448 if (imhtml->tip_window){ |
449 gtk_widget_destroy (imhtml->tip_window); | |
450 imhtml->tip_window = NULL; | |
451 } | |
452 | |
453 imhtml->tip_timer = 0; | |
454 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
455 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
456 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
457 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
458 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
459 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
460 | |
461 gtk_widget_ensure_style (imhtml->tip_window); | |
462 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
8526 | 463 font = pango_context_load_font(pango_layout_get_context(layout), |
464 imhtml->tip_window->style->font_desc); | |
465 | |
466 if (font == NULL) { | |
467 char *tmp = pango_font_description_to_string( | |
468 imhtml->tip_window->style->font_desc); | |
469 | |
470 gaim_debug(GAIM_DEBUG_ERROR, "gtk_imhtml_tip", | |
471 "pango_context_load_font() couldn't load font: '%s'\n", | |
472 tmp); | |
473 g_free(tmp); | |
474 | |
475 return FALSE; | |
476 } | |
477 | |
478 font_metrics = pango_font_get_metrics(font, NULL); | |
5967 | 479 |
480 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
8526 | 481 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
482 pango_font_metrics_get_descent(font_metrics))/ 4); | |
5967 | 483 |
484 if (gap < 2) | |
485 gap = 2; | |
8526 | 486 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
487 pango_font_metrics_get_descent(font_metrics)); | |
5967 | 488 w = 8 + scr_w; |
489 h = 8 + baseline_skip; | |
490 | |
491 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
492 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
493 y += GTK_WIDGET(imhtml)->allocation.y; | |
494 | |
495 scr_w = gdk_screen_width(); | |
496 | |
497 x -= ((w >> 1) + 4); | |
498 | |
499 if ((x + w) > scr_w) | |
500 x -= (x + w) - scr_w; | |
501 else if (x < 0) | |
502 x = 0; | |
503 | |
8526 | 504 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
505 pango_font_metrics_get_descent(font_metrics)); | |
5967 | 506 |
507 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
508 gtk_widget_show (imhtml->tip_window); | |
509 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
510 | |
8526 | 511 pango_font_metrics_unref(font_metrics); |
5967 | 512 g_object_unref(layout); |
513 | |
514 return FALSE; | |
515 } | |
516 | |
11844 | 517 static gboolean |
518 gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) | |
8061 | 519 { |
5967 | 520 GtkTextIter iter; |
521 GdkWindow *win = event->window; | |
522 int x, y; | |
523 char *tip = NULL; | |
524 GSList *tags = NULL, *templist = NULL; | |
10799 | 525 GdkColor *norm, *pre; |
526 GtkTextTag *tag = NULL, *oldprelit_tag; | |
527 | |
528 oldprelit_tag = GTK_IMHTML(imhtml)->prelit_tag; | |
529 | |
5967 | 530 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); |
531 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
10799 | 532 event->x, event->y, &x, &y); |
5967 | 533 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); |
534 tags = gtk_text_iter_get_tags(&iter); | |
535 | |
536 templist = tags; | |
537 while (templist) { | |
10799 | 538 tag = templist->data; |
5967 | 539 tip = g_object_get_data(G_OBJECT(tag), "link_url"); |
540 if (tip) | |
541 break; | |
542 templist = templist->next; | |
543 } | |
8061 | 544 |
10799 | 545 if (tip) { |
546 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-prelight-color", &pre, NULL); | |
547 GTK_IMHTML(imhtml)->prelit_tag = tag; | |
548 if (tag != oldprelit_tag) { | |
549 if (pre) | |
550 g_object_set(G_OBJECT(tag), "foreground-gdk", pre, NULL); | |
551 else | |
12253 | 552 g_object_set(G_OBJECT(tag), "foreground", "#70a0ff", NULL); |
10799 | 553 } |
554 } else { | |
555 GTK_IMHTML(imhtml)->prelit_tag = NULL; | |
556 } | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
557 |
10834 | 558 if ((oldprelit_tag != NULL) && (GTK_IMHTML(imhtml)->prelit_tag != oldprelit_tag)) { |
10799 | 559 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &norm, NULL); |
560 if (norm) | |
561 g_object_set(G_OBJECT(oldprelit_tag), "foreground-gdk", norm, NULL); | |
562 else | |
563 g_object_set(G_OBJECT(oldprelit_tag), "foreground", "blue", NULL); | |
564 } | |
565 | |
5967 | 566 if (GTK_IMHTML(imhtml)->tip) { |
567 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
568 return FALSE; | |
569 } | |
570 /* We've left the cell. Remove the timeout and create a new one below */ | |
571 if (GTK_IMHTML(imhtml)->tip_window) { | |
572 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
573 GTK_IMHTML(imhtml)->tip_window = NULL; | |
574 } | |
8061 | 575 if (GTK_IMHTML(imhtml)->editable) |
576 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor); | |
577 else | |
578 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
5967 | 579 if (GTK_IMHTML(imhtml)->tip_timer) |
580 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
581 GTK_IMHTML(imhtml)->tip_timer = 0; | |
582 } | |
8061 | 583 |
10799 | 584 if (tip){ |
8061 | 585 if (!GTK_IMHTML(imhtml)->editable) |
586 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | |
587 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | |
5967 | 588 gtk_imhtml_tip, imhtml); |
589 } | |
8061 | 590 |
5967 | 591 GTK_IMHTML(imhtml)->tip = tip; |
592 g_slist_free(tags); | |
593 return FALSE; | |
594 } | |
595 | |
11677 | 596 static gboolean |
597 gtk_enter_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
10946
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
598 { |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
599 if (GTK_IMHTML(imhtml)->editable) |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
600 gdk_window_set_cursor( |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
601 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
602 GTK_TEXT_WINDOW_TEXT), |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
603 GTK_IMHTML(imhtml)->text_cursor); |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
604 else |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
605 gdk_window_set_cursor( |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
606 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
607 GTK_TEXT_WINDOW_TEXT), |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
608 GTK_IMHTML(imhtml)->arrow_cursor); |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
609 |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
610 /* propagate the event normally */ |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
611 return FALSE; |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
612 } |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
613 |
11677 | 614 static gboolean |
615 gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
5967 | 616 { |
617 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ | |
10799 | 618 if (GTK_IMHTML(imhtml)->prelit_tag) { |
619 GdkColor *norm; | |
620 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &norm, NULL); | |
621 if (norm) | |
622 g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground-gdk", norm, NULL); | |
623 else | |
624 g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground", "blue", NULL); | |
625 GTK_IMHTML(imhtml)->prelit_tag = NULL; | |
626 } | |
627 | |
5967 | 628 if (GTK_IMHTML(imhtml)->tip_window) { |
629 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
630 GTK_IMHTML(imhtml)->tip_window = NULL; | |
631 } | |
632 if (GTK_IMHTML(imhtml)->tip_timer) { | |
633 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
634 GTK_IMHTML(imhtml)->tip_timer = 0; | |
635 } | |
10946
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
636 gdk_window_set_cursor( |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
637 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
638 GTK_TEXT_WINDOW_TEXT), NULL); |
5967 | 639 |
8568 | 640 /* propagate the event normally */ |
5967 | 641 return FALSE; |
642 } | |
643 | |
10844 | 644 #if (!GTK_CHECK_VERSION(2,2,0)) |
6066 | 645 /* |
646 * XXX - This should be removed eventually. | |
647 * | |
8061 | 648 * This function exists to work around a gross bug in GtkTextView. |
649 * Basically, we short circuit ctrl+a and ctrl+end because they make | |
6066 | 650 * el program go boom. |
651 * | |
8061 | 652 * It's supposed to be fixed in gtk2.2. You can view the bug report at |
6066 | 653 * http://bugzilla.gnome.org/show_bug.cgi?id=107939 |
654 */ | |
10849 | 655 static gboolean |
656 gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data) | |
8677 | 657 { |
10844 | 658 if (event->state & GDK_CONTROL_MASK) { |
6066 | 659 switch (event->keyval) { |
10844 | 660 case 'a': |
661 case GDK_Home: | |
662 case GDK_End: | |
663 return TRUE; | |
6066 | 664 } |
10844 | 665 } |
6066 | 666 return FALSE; |
667 } | |
10844 | 668 #endif /* !(GTK+ >= 2.2.0) */ |
10692 | 669 |
670 static gint | |
671 gtk_imhtml_expose_event (GtkWidget *widget, | |
672 GdkEventExpose *event) | |
673 { | |
10776 | 674 GtkTextIter start, end, cur; |
675 int buf_x, buf_y; | |
676 GdkRectangle visible_rect; | |
10777 | 677 GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(event->window)); |
678 GdkColor gcolor; | |
10844 | 679 |
10776 | 680 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &visible_rect); |
681 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
682 GTK_TEXT_WINDOW_TEXT, | |
683 visible_rect.x, | |
684 visible_rect.y, | |
685 &visible_rect.x, | |
686 &visible_rect.y); | |
687 | |
688 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT, | |
689 event->area.x, event->area.y, &buf_x, &buf_y); | |
690 | |
10777 | 691 if (GTK_IMHTML(widget)->editable || GTK_IMHTML(widget)->wbfo) { |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
692 |
10777 | 693 if (GTK_IMHTML(widget)->edit.background) { |
694 gdk_color_parse(GTK_IMHTML(widget)->edit.background, &gcolor); | |
695 gdk_gc_set_rgb_fg_color(gc, &gcolor); | |
696 } else { | |
697 gdk_gc_set_rgb_fg_color(gc, &(widget->style->base[GTK_WIDGET_STATE(widget)])); | |
698 } | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
699 |
10777 | 700 gdk_draw_rectangle(event->window, |
701 gc, | |
702 TRUE, | |
703 visible_rect.x, visible_rect.y, visible_rect.width, visible_rect.height); | |
704 gdk_gc_unref(gc); | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
705 |
10777 | 706 if (GTK_WIDGET_CLASS (parent_class)->expose_event) |
707 return (* GTK_WIDGET_CLASS (parent_class)->expose_event) | |
708 (widget, event); | |
709 return FALSE; | |
710 | |
711 } | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
712 |
10776 | 713 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &start, buf_x, buf_y); |
714 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &end, | |
715 buf_x + event->area.width, buf_y + event->area.height); | |
716 | |
717 | |
718 | |
719 cur = start; | |
720 | |
721 while (gtk_text_iter_in_range(&cur, &start, &end)) { | |
10795 | 722 GSList *tags = gtk_text_iter_get_tags(&cur); |
723 GSList *l; | |
10776 | 724 |
725 for (l = tags; l; l = l->next) { | |
726 GtkTextTag *tag = l->data; | |
727 GdkRectangle rect; | |
728 GdkRectangle tag_area; | |
729 const char *color; | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
730 |
10776 | 731 if (strncmp(tag->name, "BACKGROUND ", 11)) |
732 continue; | |
733 | |
734 if (gtk_text_iter_ends_tag(&cur, tag)) | |
735 continue; | |
736 | |
737 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area); | |
738 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
739 GTK_TEXT_WINDOW_TEXT, | |
740 tag_area.x, | |
741 tag_area.y, | |
742 &tag_area.x, | |
743 &tag_area.y); | |
744 rect.x = visible_rect.x; | |
745 rect.y = tag_area.y; | |
11768
a9e9b76905b4
[gaim-migrate @ 14059]
Gary Kramlich <grim@reaperworld.com>
parents:
11760
diff
changeset
|
746 rect.width = visible_rect.width; |
10776 | 747 |
10795 | 748 do |
10776 | 749 gtk_text_iter_forward_to_tag_toggle(&cur, tag); |
10795 | 750 while (!gtk_text_iter_is_end(&cur) && gtk_text_iter_begins_tag(&cur, tag)); |
751 | |
10776 | 752 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area); |
753 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
754 GTK_TEXT_WINDOW_TEXT, | |
755 tag_area.x, | |
756 tag_area.y, | |
757 &tag_area.x, | |
758 &tag_area.y); | |
759 | |
11760 | 760 |
761 rect.height = tag_area.y + tag_area.height - rect.y | |
762 + gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(widget)); | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
763 |
10776 | 764 color = tag->name + 11; |
765 | |
10857 | 766 if (!gdk_color_parse(color, &gcolor)) { |
10858 | 767 gchar tmp[8]; |
768 tmp[0] = '#'; | |
769 strncpy(&tmp[1], color, 7); | |
770 tmp[7] = '\0'; | |
10857 | 771 if (!gdk_color_parse(tmp, &gcolor)) |
772 gdk_color_parse("white", &gcolor); | |
773 } | |
10776 | 774 gdk_gc_set_rgb_fg_color(gc, &gcolor); |
775 | |
776 gdk_draw_rectangle(event->window, | |
777 gc, | |
778 TRUE, | |
779 rect.x, rect.y, rect.width, rect.height); | |
10795 | 780 gtk_text_iter_backward_char(&cur); /* go back one, in case the end is the begining is the end |
781 * note that above, we always moved cur ahead by at least | |
782 * one character */ | |
10776 | 783 break; |
784 } | |
785 | |
786 g_slist_free(tags); | |
10795 | 787 |
788 /* loop until another tag begins, or no tag begins */ | |
789 while (gtk_text_iter_forward_to_tag_toggle(&cur, NULL) && | |
790 !gtk_text_iter_is_end(&cur) && | |
791 !gtk_text_iter_begins_tag(&cur, NULL)); | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
792 } |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
793 |
10777 | 794 gdk_gc_unref(gc); |
795 | |
10692 | 796 if (GTK_WIDGET_CLASS (parent_class)->expose_event) |
797 return (* GTK_WIDGET_CLASS (parent_class)->expose_event) | |
798 (widget, event); | |
10776 | 799 |
10692 | 800 return FALSE; |
801 } | |
802 | |
803 | |
8931 | 804 static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) |
805 { | |
806 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
807 | |
808 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); | |
809 | |
810 } | |
811 | |
12833
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
812 static void fix_popup_menu_item_cb(GtkWidget *widget, gpointer data) |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
813 { |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
814 gpointer *more_data = data; |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
815 int *count = more_data[0]; |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
816 GtkIMHtml *imhtml = more_data[1]; |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
817 |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
818 /* Destroy all items except Copy and Select All, if the text isn't editable. */ |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
819 if (!imhtml->editable && *count != 1 && *count != 5) |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
820 { |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
821 gtk_widget_destroy(widget); |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
822 } |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
823 else if (*count == 5 && gtk_text_buffer_get_char_count(imhtml->text_buffer) == 0) |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
824 { |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
825 /* There is no text in the buffer, so Select All should be insensitive. */ |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
826 gtk_widget_set_sensitive(widget, FALSE); |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
827 } |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
828 |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
829 (*count)++; |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
830 } |
10692 | 831 |
8931 | 832 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) |
833 { | |
12833
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
834 int count = 0; |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
835 gpointer more_data[2] = {&count, imhtml}; |
8931 | 836 GtkWidget *menuitem; |
837 | |
12833
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
838 gtk_container_foreach(GTK_CONTAINER(menu), fix_popup_menu_item_cb, more_data); |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
839 |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
840 if (!imhtml->editable) |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
841 return; |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
842 |
12635
8584cc19ee48
[gaim-migrate @ 14971]
Richard Laager <rlaager@wiktel.com>
parents:
12605
diff
changeset
|
843 menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text")); |
8931 | 844 gtk_widget_show(menuitem); |
845 gtk_widget_set_sensitive(menuitem, | |
12833
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
846 (gtk_clipboard_wait_is_text_available( |
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
847 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD)))); |
8931 | 848 /* put it after "Paste" */ |
849 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 3); | |
850 | |
851 g_signal_connect(G_OBJECT(menuitem), "activate", | |
852 G_CALLBACK(paste_unformatted_cb), imhtml); | |
853 } | |
854 | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
855 static char * |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
856 ucs2_order(gboolean swap) |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
857 { |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
858 gboolean be; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
859 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
860 be = G_BYTE_ORDER == G_BIG_ENDIAN; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
861 be = swap ? be : !be; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
862 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
863 if (be) |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
864 return "UCS-2BE"; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
865 else |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
866 return "UCS-2LE"; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
867 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
868 } |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
869 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
870 /* Convert from UCS-2 to UTF-8, stripping the BOM if one is present.*/ |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
871 static gchar * |
11586 | 872 ucs2_to_utf8_with_bom_check(gchar *data, guint len) { |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
873 char *fromcode = NULL; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
874 GError *error = NULL; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
875 guint16 c; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
876 gchar *utf8_ret; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
877 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
878 /* |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
879 * Unicode Techinical Report 20 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
880 * ( http://www.unicode.org/unicode/reports/tr20/ ) says to treat an |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
881 * initial 0xfeff (ZWNBSP) as a byte order indicator so that is |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
882 * what we do. If there is no indicator assume it is in the default |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
883 * order |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
884 */ |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
885 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
886 memcpy(&c, data, 2); |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
887 switch (c) { |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
888 case 0xfeff: |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
889 case 0xfffe: |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
890 fromcode = ucs2_order(c == 0xfeff); |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
891 data += 2; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
892 len -= 2; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
893 break; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
894 default: |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
895 fromcode = "UCS-2"; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
896 break; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
897 } |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
898 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
899 utf8_ret = g_convert(data, len, "UTF-8", fromcode, NULL, NULL, &error); |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
900 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
901 if (error) { |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
902 gaim_debug_warning("gtkimhtml", "g_convert error: %s\n", error->message); |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
903 g_error_free(error); |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
904 } |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
905 return utf8_ret; |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
906 } |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
907 |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
908 |
8061 | 909 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) { |
8681 | 910 char *text; |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8758
diff
changeset
|
911 gboolean primary; |
8061 | 912 GtkTextIter start, end; |
913 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
914 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
10013 | 915 |
8061 | 916 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); |
917 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8758
diff
changeset
|
918 primary = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY) == clipboard; |
8061 | 919 |
920 if (info == TARGET_HTML) { | |
8907 | 921 gsize len; |
8148 | 922 char *selection; |
8061 | 923 GString *str = g_string_new(NULL); |
8681 | 924 if (primary) { |
925 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
10013 | 926 } else |
8681 | 927 text = imhtml->clipboard_html_string; |
8061 | 928 |
929 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | |
930 str = g_string_append_unichar(str, 0xfeff); | |
931 str = g_string_append(str, text); | |
932 str = g_string_append_unichar(str, 0x0000); | |
8148 | 933 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); |
11143 | 934 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len); |
8061 | 935 g_string_free(str, TRUE); |
936 g_free(selection); | |
937 } else { | |
8681 | 938 if (primary) { |
939 text = gtk_imhtml_get_text(imhtml, &start, &end); | |
940 } else | |
941 text = imhtml->clipboard_text_string; | |
8061 | 942 gtk_selection_data_set_text(selection_data, text, strlen(text)); |
943 } | |
8681 | 944 if (primary) /* This was allocated here */ |
945 g_free(text); | |
946 } | |
8061 | 947 |
948 static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml) | |
7749 | 949 { |
8061 | 950 GtkTextIter insert; |
951 GtkTextIter selection_bound; | |
952 | |
953 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert, | |
954 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert")); | |
955 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound, | |
956 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound")); | |
957 | |
958 if (!gtk_text_iter_equal (&insert, &selection_bound)) | |
959 gtk_text_buffer_move_mark (imhtml->text_buffer, | |
960 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"), | |
961 &insert); | |
7749 | 962 } |
7742 | 963 |
8677 | 964 static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
7749 | 965 { |
8681 | 966 GtkTextIter start, end; |
967 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
968 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
969 | |
970 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
971 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
972 | |
8061 | 973 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), |
974 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
975 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
976 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | |
7346 | 977 |
8681 | 978 if (imhtml->clipboard_html_string) { |
979 g_free(imhtml->clipboard_html_string); | |
980 g_free(imhtml->clipboard_text_string); | |
981 } | |
982 | |
983 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
984 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); | |
985 | |
8692 | 986 #ifdef _WIN32 |
987 /* We're going to still copy plain text, but let's toss the "HTML Format" | |
988 we need into the windows clipboard now as well. */ | |
10901
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
989 clipboard_copy_html_win32(imhtml); |
8692 | 990 #endif |
991 | |
8061 | 992 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
993 } | |
994 | |
8698 | 995 static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
996 { | |
997 GtkTextIter start, end; | |
998 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
999 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
1000 | |
1001 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
1002 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
1003 | |
1004 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), | |
1005 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
1006 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
1007 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | |
1008 | |
1009 if (imhtml->clipboard_html_string) { | |
1010 g_free(imhtml->clipboard_html_string); | |
1011 g_free(imhtml->clipboard_text_string); | |
1012 } | |
1013 | |
1014 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
1015 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); | |
1016 | |
1017 #ifdef _WIN32 | |
1018 /* We're going to still copy plain text, but let's toss the "HTML Format" | |
1019 we need into the windows clipboard now as well. */ | |
10901
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
1020 clipboard_copy_html_win32(imhtml); |
8698 | 1021 #endif |
1022 | |
1023 if (imhtml->editable) | |
1024 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE); | |
1025 g_signal_stop_emission_by_name(imhtml, "cut-clipboard"); | |
1026 } | |
1027 | |
8931 | 1028 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext) |
1029 { | |
1030 GtkTextIter iter; | |
9465 | 1031 GtkIMHtmlOptions flags = plaintext ? 0 : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS); |
8931 | 1032 |
9028 | 1033 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
1034 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
1035 | |
8931 | 1036 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); |
1037 if (!imhtml->wbfo && !plaintext) | |
1038 gtk_imhtml_close_tags(imhtml, &iter); | |
1039 | |
1040 gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter); | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1041 if (!imhtml->wbfo && !plaintext) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1042 gtk_imhtml_close_tags(imhtml, &iter); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1043 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter); |
8931 | 1044 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer), |
1045 0, FALSE, 0.0, 0.0); | |
1046 } | |
1047 | |
1048 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data) | |
1049 { | |
1050 char *tmp; | |
1051 | |
1052 if (text == NULL) | |
1053 return; | |
1054 | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10699
diff
changeset
|
1055 tmp = g_markup_escape_text(text, -1); |
8931 | 1056 imhtml_paste_insert(data, tmp, TRUE); |
1057 g_free(tmp); | |
1058 } | |
1059 | |
8061 | 1060 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data) |
1061 { | |
1062 char *text; | |
1063 GtkIMHtml *imhtml = data; | |
7809 | 1064 |
8123 | 1065 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) |
8105 | 1066 return; |
1067 | |
8061 | 1068 if (selection_data->length < 0) { |
8931 | 1069 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); |
1070 return; | |
8061 | 1071 } else { |
8719 | 1072 #if 0 |
1073 /* Here's some debug code, for figuring out what sent to us over the clipboard. */ | |
1074 { | |
1075 int i; | |
1076 | |
1077 gaim_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t", | |
1078 selection_data->format, selection_data->length); | |
1079 | |
1080 for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) { | |
1081 if ((i % 70) == 0) | |
1082 printf("\n\t"); | |
1083 if (selection_data->data[i] == '\0') | |
1084 printf("."); | |
1085 else | |
1086 printf("%c", selection_data->data[i]); | |
1087 } | |
1088 printf("\n"); | |
1089 } | |
1090 #endif | |
1091 text = g_malloc(selection_data->length); | |
1092 memcpy(text, selection_data->data, selection_data->length); | |
7766 | 1093 } |
8061 | 1094 |
8869 | 1095 if (selection_data->length >= 2 && |
1096 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | |
1097 /* This is UCS-2 */ | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1098 char *utf8 = ucs2_to_utf8_with_bom_check(text, selection_data->length); |
8061 | 1099 g_free(text); |
1100 text = utf8; | |
8698 | 1101 if (!text) { |
8869 | 1102 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n"); |
8698 | 1103 return; |
1104 } | |
8061 | 1105 } |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1106 |
8698 | 1107 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
1108 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in paste_received_cb\n"); | |
1109 g_free(text); | |
1110 return; | |
1111 } | |
1112 | |
8931 | 1113 imhtml_paste_insert(imhtml, text, FALSE); |
8681 | 1114 g_free(text); |
8061 | 1115 } |
1116 | |
1117 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
1118 { | |
8931 | 1119 #ifdef _WIN32 |
1120 /* If we're on windows, let's see if we can get data from the HTML Format | |
10901
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
1121 clipboard before we try to paste from the GTK buffer */ |
0711078e0e2d
[gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10900
diff
changeset
|
1122 if (!clipboard_paste_html_win32(imhtml)) { |
8931 | 1123 #endif |
8061 | 1124 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
1125 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
1126 paste_received_cb, imhtml); | |
8931 | 1127 #ifdef _WIN32 |
1128 } | |
1129 #endif | |
8061 | 1130 g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); |
7766 | 1131 } |
1132 | |
8677 | 1133 static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused) |
1134 { | |
1135 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, | |
1136 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); | |
1137 | |
1138 } | |
1139 | |
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1140 static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused) |
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1141 { |
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1142 gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, |
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1143 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); |
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1144 } |
8677 | 1145 |
1146 static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml) | |
1147 { | |
1148 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) { | |
1149 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), | |
1150 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
1151 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
1152 (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml)); | |
1153 } | |
1154 } | |
1155 | |
1156 static gboolean gtk_imhtml_button_press_event(GtkIMHtml *imhtml, GdkEventButton *event, gpointer unused) | |
7346 | 1157 { |
8677 | 1158 if (event->button == 2) { |
1159 int x, y; | |
1160 GtkTextIter iter; | |
1161 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY); | |
1162 | |
1163 if (!imhtml->editable) | |
1164 return FALSE; | |
1165 | |
1166 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), | |
1167 GTK_TEXT_WINDOW_TEXT, | |
1168 event->x, | |
1169 event->y, | |
1170 &x, | |
1171 &y); | |
1172 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
1173 gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter); | |
1174 | |
1175 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
1176 paste_received_cb, imhtml); | |
1177 | |
1178 return TRUE; | |
1179 } | |
1180 | |
7346 | 1181 return FALSE; |
1182 } | |
4263 | 1183 |
10108 | 1184 static gboolean imhtml_message_send(GtkIMHtml *imhtml) |
1185 { | |
1186 return FALSE; | |
1187 } | |
1188 | |
10100 | 1189 static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) |
1190 { | |
10699 | 1191 /* since this function is the handler for the formatting keystrokes, |
1192 we need to check here that the formatting attempted is permitted */ | |
11275
ffc86d9ad8b7
[gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents:
11269
diff
changeset
|
1193 buttons &= imhtml->format_functions; |
10699 | 1194 |
10100 | 1195 switch (buttons) { |
1196 case GTK_IMHTML_BOLD: | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1197 imhtml_toggle_bold(imhtml); |
10100 | 1198 break; |
1199 case GTK_IMHTML_ITALIC: | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1200 imhtml_toggle_italic(imhtml); |
10100 | 1201 break; |
1202 case GTK_IMHTML_UNDERLINE: | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1203 imhtml_toggle_underline(imhtml); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1204 break; |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1205 case GTK_IMHTML_STRIKE: |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1206 imhtml_toggle_strike(imhtml); |
10100 | 1207 break; |
1208 case GTK_IMHTML_SHRINK: | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1209 imhtml_font_shrink(imhtml); |
10100 | 1210 break; |
1211 case GTK_IMHTML_GROW: | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
1212 imhtml_font_grow(imhtml); |
10100 | 1213 break; |
1214 default: | |
1215 break; | |
1216 } | |
1217 } | |
4032 | 1218 |
1219 static void | |
1220 gtk_imhtml_finalize (GObject *object) | |
1221 { | |
1222 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
4895 | 1223 GList *scalables; |
8962 | 1224 GSList *l; |
8061 | 1225 |
10798 | 1226 if (imhtml->scroll_src) |
1227 g_source_remove(imhtml->scroll_src); | |
1228 if (imhtml->scroll_time) | |
1229 g_timer_destroy(imhtml->scroll_time); | |
1230 | |
4138 | 1231 g_hash_table_destroy(imhtml->smiley_data); |
4032 | 1232 gtk_smiley_tree_destroy(imhtml->default_smilies); |
4138 | 1233 gdk_cursor_unref(imhtml->hand_cursor); |
1234 gdk_cursor_unref(imhtml->arrow_cursor); | |
8061 | 1235 gdk_cursor_unref(imhtml->text_cursor); |
8677 | 1236 |
4735 | 1237 if(imhtml->tip_window){ |
1238 gtk_widget_destroy(imhtml->tip_window); | |
1239 } | |
1240 if(imhtml->tip_timer) | |
1241 gtk_timeout_remove(imhtml->tip_timer); | |
1242 | |
4895 | 1243 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
1244 struct scalable_data *sd = scalables->data; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
1245 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
4895 | 1246 scale->free(scale); |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
1247 g_free(sd); |
4895 | 1248 } |
7991 | 1249 |
8962 | 1250 for (l = imhtml->im_images; l; l = l->next) { |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
1251 struct im_image_data *img_data = l->data; |
8962 | 1252 if (imhtml->funcs->image_unref) |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
1253 imhtml->funcs->image_unref(img_data->id); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
1254 g_free(img_data); |
8962 | 1255 } |
1256 | |
8681 | 1257 if (imhtml->clipboard_text_string) { |
1258 g_free(imhtml->clipboard_text_string); | |
1259 g_free(imhtml->clipboard_html_string); | |
1260 } | |
1261 | |
4895 | 1262 g_list_free(imhtml->scalables); |
8962 | 1263 g_slist_free(imhtml->im_images); |
9029 | 1264 if (imhtml->protocol_name) |
1265 g_free(imhtml->protocol_name); | |
10574 | 1266 if (imhtml->search_string) |
1267 g_free(imhtml->search_string); | |
4032 | 1268 G_OBJECT_CLASS(parent_class)->finalize (object); |
1269 } | |
1428 | 1270 |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10799
diff
changeset
|
1271 /* Boring GTK+ stuff */ |
8519 | 1272 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass) |
1428 | 1273 { |
9007 | 1274 GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; |
3922 | 1275 GtkObjectClass *object_class; |
10100 | 1276 GtkBindingSet *binding_set; |
4032 | 1277 GObjectClass *gobject_class; |
8519 | 1278 object_class = (GtkObjectClass*) klass; |
1279 gobject_class = (GObjectClass*) klass; | |
4032 | 1280 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); |
4417 | 1281 signals[URL_CLICKED] = g_signal_new("url_clicked", |
1282 G_TYPE_FROM_CLASS(gobject_class), | |
1283 G_SIGNAL_RUN_FIRST, | |
1284 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
1285 NULL, | |
1286 0, | |
1287 g_cclosure_marshal_VOID__POINTER, | |
1288 G_TYPE_NONE, 1, | |
1289 G_TYPE_POINTER); | |
8506 | 1290 signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update", |
8420 | 1291 G_TYPE_FROM_CLASS(gobject_class), |
1292 G_SIGNAL_RUN_FIRST, | |
1293 G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update), | |
1294 NULL, | |
1295 0, | |
10076 | 1296 g_cclosure_marshal_VOID__INT, |
8420 | 1297 G_TYPE_NONE, 1, |
1298 G_TYPE_INT); | |
1299 signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle", | |
1300 G_TYPE_FROM_CLASS(gobject_class), | |
10100 | 1301 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, |
8420 | 1302 G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format), |
1303 NULL, | |
1304 0, | |
10076 | 1305 g_cclosure_marshal_VOID__INT, |
1306 G_TYPE_NONE, 1, | |
8420 | 1307 G_TYPE_INT); |
8427 | 1308 signals[CLEAR_FORMAT] = g_signal_new("format_function_clear", |
1309 G_TYPE_FROM_CLASS(gobject_class), | |
11385
78cd70f4834c
[gaim-migrate @ 13612]
Luke Schierer <lschiere@pidgin.im>
parents:
11315
diff
changeset
|
1310 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
8427 | 1311 G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format), |
1312 NULL, | |
1313 0, | |
10100 | 1314 g_cclosure_marshal_VOID__VOID, |
1315 G_TYPE_NONE, 0); | |
8506 | 1316 signals[UPDATE_FORMAT] = g_signal_new("format_function_update", |
10100 | 1317 G_TYPE_FROM_CLASS(gobject_class), |
1318 G_SIGNAL_RUN_FIRST, | |
1319 G_STRUCT_OFFSET(GtkIMHtmlClass, update_format), | |
1320 NULL, | |
1321 0, | |
1322 g_cclosure_marshal_VOID__VOID, | |
1323 G_TYPE_NONE, 0); | |
10108 | 1324 signals[MESSAGE_SEND] = g_signal_new("message_send", |
1325 G_TYPE_FROM_CLASS(gobject_class), | |
1326 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, | |
1327 G_STRUCT_OFFSET(GtkIMHtmlClass, message_send), | |
1328 NULL, | |
1329 0, g_cclosure_marshal_VOID__VOID, | |
1330 G_TYPE_NONE, 0); | |
10100 | 1331 |
1332 klass->toggle_format = imhtml_toggle_format; | |
10108 | 1333 klass->message_send = imhtml_message_send; |
12672
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
1334 klass->clear_format = imhtml_clear_formatting; |
10184 | 1335 |
4032 | 1336 gobject_class->finalize = gtk_imhtml_finalize; |
10184 | 1337 widget_class->drag_motion = gtk_text_view_drag_motion; |
10692 | 1338 widget_class->expose_event = gtk_imhtml_expose_event; |
9007 | 1339 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", |
1340 _("Hyperlink color"), | |
1341 _("Color to draw hyperlinks."), | |
1342 GDK_TYPE_COLOR, G_PARAM_READABLE)); | |
10799 | 1343 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-prelight-color", |
1344 _("Hyperlink prelight color"), | |
1345 _("Color to draw hyperlinks when mouse is over them."), | |
1346 GDK_TYPE_COLOR, G_PARAM_READABLE)); | |
10100 | 1347 |
1348 binding_set = gtk_binding_set_by_class (parent_class); | |
10110 | 1349 gtk_binding_entry_add_signal (binding_set, GDK_b, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_BOLD); |
10100 | 1350 gtk_binding_entry_add_signal (binding_set, GDK_i, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_ITALIC); |
1351 gtk_binding_entry_add_signal (binding_set, GDK_u, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_UNDERLINE); | |
1352 gtk_binding_entry_add_signal (binding_set, GDK_plus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW); | |
1353 gtk_binding_entry_add_signal (binding_set, GDK_equal, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW); | |
1354 gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK); | |
10108 | 1355 binding_set = gtk_binding_set_by_class(klass); |
11385
78cd70f4834c
[gaim-migrate @ 13612]
Luke Schierer <lschiere@pidgin.im>
parents:
11315
diff
changeset
|
1356 gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0); |
10108 | 1357 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0); |
1358 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 0); | |
1428 | 1359 } |
1360 | |
3922 | 1361 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
1428 | 1362 { |
3922 | 1363 GtkTextIter iter; |
1364 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
1365 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
1366 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | |
5105 | 1367 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
3922 | 1368 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
8677 | 1369 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2); |
1370 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(imhtml), 2); | |
8061 | 1371 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ |
3922 | 1372 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
8061 | 1373 |
3922 | 1374 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
8932 | 1375 * other tags (color, size, face, etc.) will have to be created and applied dynamically |
9924 | 1376 * Note that even though we created SUB, SUP, and PRE tags here, we don't really |
8932 | 1377 * apply them anywhere yet. */ |
3922 | 1378 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
1379 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
1380 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
1381 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
1382 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
1383 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
1384 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
7295 | 1385 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
8677 | 1386 |
3922 | 1387 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
1388 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
1389 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
8061 | 1390 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
2993 | 1391 |
6124 | 1392 imhtml->show_comments = TRUE; |
4253 | 1393 |
4892 | 1394 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
4902 | 1395 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
4032 | 1396 imhtml->default_smilies = gtk_smiley_tree_new(); |
4735 | 1397 |
4944 | 1398 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
4735 | 1399 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
4944 | 1400 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
10946
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
1401 g_signal_connect(G_OBJECT(imhtml), "enter-notify-event", G_CALLBACK(gtk_enter_event_notify), NULL); |
10844 | 1402 #if (!GTK_CHECK_VERSION(2,2,0)) |
1403 /* See the comment for gtk_key_pressed_cb */ | |
6066 | 1404 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
10844 | 1405 #endif |
8677 | 1406 g_signal_connect(G_OBJECT(imhtml), "button_press_event", G_CALLBACK(gtk_imhtml_button_press_event), NULL); |
1407 g_signal_connect(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(preinsert_cb), imhtml); | |
12673
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
1408 g_signal_connect(G_OBJECT(imhtml->text_buffer), "delete_range", G_CALLBACK(delete_cb), imhtml); |
8061 | 1409 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
10169 | 1410 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-child-anchor", G_CALLBACK(insert_ca_cb), imhtml); |
8091 | 1411 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, |
1412 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), | |
1413 GDK_ACTION_COPY); | |
1414 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); | |
9300 | 1415 g_signal_connect(G_OBJECT(imhtml), "drag_drop", G_CALLBACK(gtk_imhtml_link_drop_cb), imhtml); |
8091 | 1416 |
7353 | 1417 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
8698 | 1418 g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL); |
8061 | 1419 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
8677 | 1420 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL); |
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1421 g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL); |
8677 | 1422 |
1423 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
1424 G_CALLBACK(mark_set_so_update_selection_cb), imhtml); | |
1425 | |
10946
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
1426 gtk_widget_add_events(GTK_WIDGET(imhtml), |
2d30f151146d
[gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10936
diff
changeset
|
1427 GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK); |
4735 | 1428 |
8681 | 1429 imhtml->clipboard_text_string = NULL; |
1430 imhtml->clipboard_html_string = NULL; | |
1431 | |
4735 | 1432 imhtml->tip = NULL; |
1433 imhtml->tip_timer = 0; | |
1434 imhtml->tip_window = NULL; | |
4895 | 1435 |
8677 | 1436 imhtml->edit.bold = FALSE; |
1437 imhtml->edit.italic = FALSE; | |
1438 imhtml->edit.underline = FALSE; | |
8061 | 1439 imhtml->edit.forecolor = NULL; |
1440 imhtml->edit.backcolor = NULL; | |
1441 imhtml->edit.fontface = NULL; | |
8677 | 1442 imhtml->edit.fontsize = 0; |
1443 imhtml->edit.link = NULL; | |
1444 | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1445 |
4895 | 1446 imhtml->scalables = NULL; |
8061 | 1447 |
1448 gtk_imhtml_set_editable(imhtml, FALSE); | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1449 g_signal_connect(G_OBJECT(imhtml), "populate-popup", |
8931 | 1450 G_CALLBACK(hijack_menu_cb), NULL); |
1451 | |
8692 | 1452 #ifdef _WIN32 |
1453 /* Register HTML Format as desired clipboard format */ | |
1454 win_html_fmt = RegisterClipboardFormat("HTML Format"); | |
1455 #endif | |
2993 | 1456 } |
1457 | |
3922 | 1458 GtkWidget *gtk_imhtml_new(void *a, void *b) |
1428 | 1459 { |
4635 | 1460 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
1428 | 1461 } |
1462 | |
9037 | 1463 GType gtk_imhtml_get_type() |
1428 | 1464 { |
9037 | 1465 static GType imhtml_type = 0; |
1428 | 1466 |
1467 if (!imhtml_type) { | |
9037 | 1468 static const GTypeInfo imhtml_info = { |
4635 | 1469 sizeof(GtkIMHtmlClass), |
1470 NULL, | |
1471 NULL, | |
1472 (GClassInitFunc) gtk_imhtml_class_init, | |
1473 NULL, | |
1474 NULL, | |
1428 | 1475 sizeof (GtkIMHtml), |
4635 | 1476 0, |
12600
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
12553
diff
changeset
|
1477 (GInstanceInitFunc) gtk_imhtml_init, |
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
12553
diff
changeset
|
1478 NULL |
1428 | 1479 }; |
4635 | 1480 |
1481 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
1482 "GtkIMHtml", &imhtml_info, 0); | |
1428 | 1483 } |
1484 | |
1485 return imhtml_type; | |
1486 } | |
1487 | |
4417 | 1488 struct url_data { |
1489 GObject *object; | |
1490 gchar *url; | |
1491 }; | |
1492 | |
8677 | 1493 static void url_data_destroy(gpointer mydata) |
1494 { | |
1495 struct url_data *data = mydata; | |
1496 g_object_unref(data->object); | |
1497 g_free(data->url); | |
1498 g_free(data); | |
1499 } | |
1500 | |
4417 | 1501 static void url_open(GtkWidget *w, struct url_data *data) { |
1502 if(!data) return; | |
8061 | 1503 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); |
7988 | 1504 |
4417 | 1505 } |
5582 | 1506 |
4417 | 1507 static void url_copy(GtkWidget *w, gchar *url) { |
1508 GtkClipboard *clipboard; | |
1509 | |
8931 | 1510 clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_PRIMARY); |
4417 | 1511 gtk_clipboard_set_text(clipboard, url, -1); |
5582 | 1512 |
8931 | 1513 clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_CLIPBOARD); |
5582 | 1514 gtk_clipboard_set_text(clipboard, url, -1); |
4417 | 1515 } |
1516 | |
1517 /* The callback for an event on a link tag. */ | |
10871 | 1518 static gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, gpointer unused) { |
4417 | 1519 GdkEventButton *event_button = (GdkEventButton *) event; |
8061 | 1520 if (GTK_IMHTML(imhtml)->editable) |
1521 return FALSE; | |
3922 | 1522 if (event->type == GDK_BUTTON_RELEASE) { |
8957 | 1523 if ((event_button->button == 1) || (event_button->button == 2)) { |
4417 | 1524 GtkTextIter start, end; |
1525 /* we shouldn't open a URL if the user has selected something: */ | |
8677 | 1526 if (gtk_text_buffer_get_selection_bounds( |
1527 gtk_text_iter_get_buffer(arg2), &start, &end)) | |
4417 | 1528 return FALSE; |
1529 | |
1530 /* A link was clicked--we emit the "url_clicked" signal | |
1531 * with the URL as the argument */ | |
8677 | 1532 g_object_ref(G_OBJECT(tag)); |
1533 g_signal_emit(imhtml, signals[URL_CLICKED], 0, g_object_get_data(G_OBJECT(tag), "link_url")); | |
1534 g_object_unref(G_OBJECT(tag)); | |
4417 | 1535 return FALSE; |
1536 } else if(event_button->button == 3) { | |
4745 | 1537 GtkWidget *img, *item, *menu; |
4417 | 1538 struct url_data *tempdata = g_new(struct url_data, 1); |
5091 | 1539 tempdata->object = g_object_ref(imhtml); |
8677 | 1540 tempdata->url = g_strdup(g_object_get_data(G_OBJECT(tag), "link_url")); |
4745 | 1541 |
5091 | 1542 /* Don't want the tooltip around if user right-clicked on link */ |
1543 if (GTK_IMHTML(imhtml)->tip_window) { | |
1544 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
1545 GTK_IMHTML(imhtml)->tip_window = NULL; | |
1546 } | |
1547 if (GTK_IMHTML(imhtml)->tip_timer) { | |
1548 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
1549 GTK_IMHTML(imhtml)->tip_timer = 0; | |
1550 } | |
8061 | 1551 if (GTK_IMHTML(imhtml)->editable) |
1552 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
1553 else | |
1554 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
4417 | 1555 menu = gtk_menu_new(); |
8677 | 1556 g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", tempdata, url_data_destroy); |
4745 | 1557 |
4417 | 1558 /* buttons and such */ |
1559 | |
8677 | 1560 if (!strncmp(tempdata->url, "mailto:", 7)) |
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1561 { |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1562 /* Copy E-Mail Address */ |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1563 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1564 GTK_ICON_SIZE_MENU); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1565 item = gtk_image_menu_item_new_with_mnemonic( |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1566 _("_Copy E-Mail Address")); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1567 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1568 g_signal_connect(G_OBJECT(item), "activate", |
8677 | 1569 G_CALLBACK(url_copy), tempdata->url + 7); |
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1570 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1571 } |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1572 else |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1573 { |
10936 | 1574 /* Open Link in Browser */ |
1575 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, | |
1576 GTK_ICON_SIZE_MENU); | |
1577 item = gtk_image_menu_item_new_with_mnemonic( | |
1578 _("_Open Link in Browser")); | |
1579 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
1580 g_signal_connect(G_OBJECT(item), "activate", | |
1581 G_CALLBACK(url_open), tempdata); | |
1582 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
1583 | |
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1584 /* Copy Link Location */ |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1585 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1586 GTK_ICON_SIZE_MENU); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1587 item = gtk_image_menu_item_new_with_mnemonic( |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1588 _("_Copy Link Location")); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1589 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1590 g_signal_connect(G_OBJECT(item), "activate", |
8677 | 1591 G_CALLBACK(url_copy), tempdata->url); |
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1592 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1593 } |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1594 |
4756 | 1595 |
4417 | 1596 gtk_widget_show_all(menu); |
4756 | 1597 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
1598 event_button->button, event_button->time); | |
4745 | 1599 |
4417 | 1600 return TRUE; |
1601 } | |
1428 | 1602 } |
4417 | 1603 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
1604 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
1605 be caught by the regular GtkTextView menu */ | |
1606 else | |
1607 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
1428 | 1608 } |
1609 | |
9300 | 1610 static gboolean |
1611 gtk_text_view_drag_motion (GtkWidget *widget, | |
1612 GdkDragContext *context, | |
1613 gint x, | |
1614 gint y, | |
1615 guint time) | |
1616 { | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1617 GdkDragAction suggested_action = 0; |
9300 | 1618 |
10145 | 1619 if (gtk_drag_dest_find_target (widget, context, NULL) == GDK_NONE) { |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1620 /* can't accept any of the offered targets */ |
9300 | 1621 } else { |
1622 GtkWidget *source_widget; | |
1623 suggested_action = context->suggested_action; | |
1624 source_widget = gtk_drag_get_source_widget (context); | |
1625 if (source_widget == widget) { | |
1626 /* Default to MOVE, unless the user has | |
1627 * pressed ctrl or alt to affect available actions | |
1628 */ | |
1629 if ((context->actions & GDK_ACTION_MOVE) != 0) | |
1630 suggested_action = GDK_ACTION_MOVE; | |
1631 } | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1632 } |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1633 |
10145 | 1634 gdk_drag_status (context, suggested_action, time); |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1635 |
9300 | 1636 /* TRUE return means don't propagate the drag motion to parent |
1637 * widgets that may also be drop sites. | |
1638 */ | |
1639 return TRUE; | |
1640 } | |
1641 | |
1642 static void | |
1643 gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) | |
1644 { | |
1645 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1646 |
9300 | 1647 if (target != GDK_NONE) |
1648 gtk_drag_get_data (widget, context, target, time); | |
1649 else | |
1650 gtk_drag_finish (context, FALSE, FALSE, time); | |
1651 | |
1652 return; | |
1653 } | |
1654 | |
8091 | 1655 static void |
1656 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
11143 | 1657 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) |
8091 | 1658 { |
9300 | 1659 gchar **links; |
1660 gchar *link; | |
11143 | 1661 char *text = (char *)sd->data; |
9300 | 1662 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
1663 GtkTextIter iter; | |
10782
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1664 gint i = 0; |
9300 | 1665 |
1666 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
1667 | |
8091 | 1668 if(gtk_imhtml_get_editable(imhtml) && sd->data){ |
9300 | 1669 switch (info) { |
10145 | 1670 case GTK_IMHTML_DRAG_URL: |
11143 | 1671 /* TODO: Is it really ok to change sd->data...? */ |
11920 | 1672 gaim_str_strip_char((char *)sd->data, '\r'); |
11143 | 1673 |
1674 links = g_strsplit((char *)sd->data, "\n", 0); | |
10782
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1675 while((link = links[i]) != NULL){ |
9300 | 1676 if(gaim_str_has_prefix(link, "http://") || |
1677 gaim_str_has_prefix(link, "https://") || | |
11820
2cf6d4cf2cb0
[gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents:
11814
diff
changeset
|
1678 gaim_str_has_prefix(link, "ftp://")) |
10782
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1679 { |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1680 gchar *label; |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1681 |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1682 if(links[i + 1]) |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1683 i++; |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1684 |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1685 label = links[i]; |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1686 |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1687 gtk_imhtml_insert_link(imhtml, mark, link, label); |
9300 | 1688 } else if (link=='\0') { |
1689 /* Ignore blank lines */ | |
1690 } else { | |
1691 /* Special reasons, aka images being put in via other tag, etc. */ | |
10345 | 1692 /* ... don't pretend we handled it if we didn't */ |
1693 gtk_drag_finish(dc, FALSE, FALSE, t); | |
10782
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1694 g_strfreev(links); |
10345 | 1695 return; |
9300 | 1696 } |
10782
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1697 |
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1698 i++; |
8091 | 1699 } |
10782
93fd90cbf45c
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1700 g_strfreev(links); |
9300 | 1701 break; |
10145 | 1702 case GTK_IMHTML_DRAG_HTML: |
10243 | 1703 { |
1704 char *utf8 = NULL; | |
1705 /* Ewww. This is all because mozilla thinks that text/html is 'for internal use only.' | |
1706 * as explained by this comment in gtkhtml: | |
1707 * | |
1708 * FIXME This hack decides the charset of the selection. It seems that | |
1709 * mozilla/netscape alway use ucs2 for text/html | |
1710 * and openoffice.org seems to always use utf8 so we try to validate | |
1711 * the string as utf8 and if that fails we assume it is ucs2 | |
1712 * | |
1713 * See also the comment on text/html here: | |
1714 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html | |
1715 */ | |
1716 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1717 utf8 = ucs2_to_utf8_with_bom_check(text, sd->length); |
10243 | 1718 |
1719 if (!utf8) { | |
9300 | 1720 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n"); |
1721 return; | |
1722 } | |
10243 | 1723 } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
9300 | 1724 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); |
1725 return; | |
1726 } | |
10243 | 1727 |
1728 gtk_imhtml_insert_html_at_iter(imhtml, utf8 ? utf8 : text, 0, &iter); | |
1729 g_free(utf8); | |
9300 | 1730 break; |
10243 | 1731 } |
10145 | 1732 case GTK_IMHTML_DRAG_TEXT: |
1733 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { | |
1734 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); | |
1735 return; | |
1736 } else { | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10699
diff
changeset
|
1737 char *tmp = g_markup_escape_text(text, -1); |
10145 | 1738 gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter); |
1739 g_free(tmp); | |
1740 } | |
1741 break; | |
9300 | 1742 default: |
10145 | 1743 gtk_drag_finish(dc, FALSE, FALSE, t); |
1744 return; | |
8091 | 1745 } |
1746 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
1747 } else { | |
1748 gtk_drag_finish(dc, FALSE, FALSE, t); | |
1749 } | |
1750 } | |
1751 | |
4298 | 1752 /* this isn't used yet |
9300 | 1753 static void gtk_smiley_tree_remove (GtkSmileyTree *tree, |
4263 | 1754 GtkIMHtmlSmiley *smiley) |
4032 | 1755 { |
1756 GtkSmileyTree *t = tree; | |
4263 | 1757 const gchar *x = smiley->smile; |
4032 | 1758 gint len = 0; |
1759 | |
1760 while (*x) { | |
1761 gchar *pos; | |
1762 | |
1763 if (!t->values) | |
1764 return; | |
1765 | |
1766 pos = strchr (t->values->str, *x); | |
1767 if (pos) | |
1768 t = t->children [(int) pos - (int) t->values->str]; | |
1769 else | |
1770 return; | |
1771 | |
1772 x++; len++; | |
1773 } | |
1774 | |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
1775 if (t->image) { |
4032 | 1776 t->image = NULL; |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
1777 } |
4032 | 1778 } |
4298 | 1779 */ |
1780 | |
4032 | 1781 |
1782 static gint | |
1783 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
1784 const gchar *text) | |
1785 { | |
1786 GtkSmileyTree *t = tree; | |
1787 const gchar *x = text; | |
1788 gint len = 0; | |
8505 | 1789 gchar *amp; |
1790 gint alen; | |
4032 | 1791 |
1792 while (*x) { | |
1793 gchar *pos; | |
1794 | |
1795 if (!t->values) | |
1796 break; | |
1797 | |
8505 | 1798 if(*x == '&' && gtk_imhtml_is_amp_escape(x, &, &alen)) { |
10865
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1799 gboolean matched = TRUE; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1800 /* Make sure all chars of the unescaped value match */ |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1801 while (*(amp + 1)) { |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1802 pos = strchr (t->values->str, *amp); |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1803 if (pos) |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1804 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1805 else { |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1806 matched = FALSE; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1807 break; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1808 } |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1809 amp++; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1810 } |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1811 if (!matched) |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1812 break; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1813 |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1814 pos = strchr (t->values->str, *amp); |
8505 | 1815 } |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1816 else if (*x == '<') /* Because we're all WYSIWYG now, a '<' |
9636 | 1817 * char should only appear as the start of a tag. Perhaps a safer (but costlier) |
1818 * check would be to call gtk_imhtml_is_tag on it */ | |
10600 | 1819 break; |
10865
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1820 else { |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1821 alen = 1; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1822 pos = strchr (t->values->str, *x); |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1823 } |
8505 | 1824 |
4032 | 1825 if (pos) |
7371 | 1826 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
4032 | 1827 else |
1828 break; | |
1829 | |
10865
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1830 x += alen; |
c28766b87f64
[gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10858
diff
changeset
|
1831 len += alen; |
4032 | 1832 } |
1833 | |
1834 if (t->image) | |
1835 return len; | |
1836 | |
1837 return 0; | |
1838 } | |
1839 | |
1840 void | |
4263 | 1841 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
10537 | 1842 const gchar *sml, |
4263 | 1843 GtkIMHtmlSmiley *smiley) |
4032 | 1844 { |
1845 GtkSmileyTree *tree; | |
1846 g_return_if_fail (imhtml != NULL); | |
1847 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
7371 | 1848 |
4032 | 1849 if (sml == NULL) |
1850 tree = imhtml->default_smilies; | |
12833
cb2d493e1925
[gaim-migrate @ 15181]
Richard Laager <rlaager@wiktel.com>
parents:
12796
diff
changeset
|
1851 else if (!(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { |
4032 | 1852 tree = gtk_smiley_tree_new(); |
4892 | 1853 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
4032 | 1854 } |
1855 | |
12335 | 1856 smiley->imhtml = imhtml; |
1857 | |
4263 | 1858 gtk_smiley_tree_insert (tree, smiley); |
4032 | 1859 } |
1860 | |
1861 static gboolean | |
1862 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
1863 GSList *fonts, | |
1864 const gchar *text, | |
1865 gint *len) | |
1866 { | |
1867 GtkSmileyTree *tree; | |
5967 | 1868 GtkIMHtmlFontDetail *font; |
4032 | 1869 char *sml = NULL; |
1870 | |
1871 if (fonts) { | |
1872 font = fonts->data; | |
1873 sml = font->sml; | |
1874 } | |
1875 | |
9029 | 1876 if (!sml) |
1877 sml = imhtml->protocol_name; | |
1878 | |
1879 if (!sml || !(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) | |
4032 | 1880 tree = imhtml->default_smilies; |
9029 | 1881 |
4032 | 1882 if (tree == NULL) |
1883 return FALSE; | |
7371 | 1884 |
8505 | 1885 *len = gtk_smiley_tree_lookup (tree, text); |
4032 | 1886 return (*len > 0); |
1887 } | |
1888 | |
10526 | 1889 GtkIMHtmlSmiley * |
1890 gtk_imhtml_smiley_get(GtkIMHtml *imhtml, | |
1891 const gchar *sml, | |
1892 const gchar *text) | |
4032 | 1893 { |
1894 GtkSmileyTree *t; | |
1895 const gchar *x = text; | |
1896 if (sml == NULL) | |
1897 t = imhtml->default_smilies; | |
7371 | 1898 else |
4032 | 1899 t = g_hash_table_lookup(imhtml->smiley_data, sml); |
7371 | 1900 |
4032 | 1901 |
1902 if (t == NULL) | |
10526 | 1903 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
4032 | 1904 |
1905 while (*x) { | |
1906 gchar *pos; | |
1907 | |
1908 if (!t->values) { | |
10526 | 1909 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
4032 | 1910 } |
7371 | 1911 |
4032 | 1912 pos = strchr (t->values->str, *x); |
1913 if (pos) { | |
7371 | 1914 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
4032 | 1915 } else { |
10526 | 1916 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
4032 | 1917 } |
1918 x++; | |
1919 } | |
1920 | |
10526 | 1921 return t->image; |
1922 } | |
1923 | |
11677 | 1924 static GdkPixbufAnimation * |
10526 | 1925 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
1926 const gchar *sml, | |
1927 const gchar *text) | |
1928 { | |
1929 | |
1930 GtkIMHtmlSmiley *smiley; | |
1931 | |
1932 smiley = gtk_imhtml_smiley_get(imhtml,sml,text); | |
1933 | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1934 if (!smiley) |
8890 | 1935 return NULL; |
1936 | |
10526 | 1937 if (!smiley->icon && smiley->file) { |
1938 smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL); | |
1939 } else if (!smiley->icon && smiley->loader) { | |
1940 smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader); | |
1941 if (smiley->icon) | |
1942 g_object_ref(G_OBJECT(smiley->icon)); | |
1943 } | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
1944 |
10526 | 1945 return smiley->icon; |
4032 | 1946 } |
8890 | 1947 |
4793 | 1948 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
3922 | 1949 *tag = g_strndup (string, strlen (x)); \ |
1950 *len = strlen (x) + 1; \ | |
1951 return TRUE; \ | |
1952 } \ | |
1953 (*type)++ | |
1428 | 1954 |
4793 | 1955 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
3922 | 1956 const gchar *c = string + strlen (x " "); \ |
1957 gchar e = '"'; \ | |
1958 gboolean quote = FALSE; \ | |
1959 while (*c) { \ | |
1960 if (*c == '"' || *c == '\'') { \ | |
1961 if (quote && (*c == e)) \ | |
1962 quote = !quote; \ | |
1963 else if (!quote) { \ | |
1964 quote = !quote; \ | |
1965 e = *c; \ | |
1966 } \ | |
1967 } else if (!quote && (*c == '>')) \ | |
1968 break; \ | |
1969 c++; \ | |
1970 } \ | |
1971 if (*c) { \ | |
1972 *tag = g_strndup (string, c - string); \ | |
1973 *len = c - string + 1; \ | |
1974 return TRUE; \ | |
1975 } \ | |
1976 } \ | |
1977 (*type)++ | |
1428 | 1978 |
1979 | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1980 static gboolean |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1981 gtk_imhtml_is_amp_escape (const gchar *string, |
7280 | 1982 gchar **replace, |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1983 gint *length) |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1984 { |
7287 | 1985 static char buf[7]; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1986 g_return_val_if_fail (string != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1987 g_return_val_if_fail (replace != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1988 g_return_val_if_fail (length != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1989 |
4793 | 1990 if (!g_ascii_strncasecmp (string, "&", 5)) { |
7280 | 1991 *replace = "&"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1992 *length = 5; |
4793 | 1993 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
7280 | 1994 *replace = "<"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1995 *length = 4; |
4793 | 1996 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
7280 | 1997 *replace = ">"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1998 *length = 4; |
4793 | 1999 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
7280 | 2000 *replace = " "; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2001 *length = 6; |
4793 | 2002 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
7280 | 2003 *replace = "©"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2004 *length = 6; |
4793 | 2005 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
7280 | 2006 *replace = "\""; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2007 *length = 6; |
4793 | 2008 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
7280 | 2009 *replace = "®"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2010 *length = 5; |
5093 | 2011 } else if (!g_ascii_strncasecmp (string, "'", 6)) { |
7280 | 2012 *replace = "\'"; |
5093 | 2013 *length = 6; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2014 } else if (*(string + 1) == '#') { |
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
2015 guint pound = 0; |
3004 | 2016 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
7287 | 2017 int buflen; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2018 if (*(string + 3 + (gint)log10 (pound)) != ';') |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2019 return FALSE; |
7287 | 2020 buflen = g_unichar_to_utf8((gunichar)pound, buf); |
2021 buf[buflen] = '\0'; | |
7280 | 2022 *replace = buf; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2023 *length = 2; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2024 while (isdigit ((gint) string [*length])) (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2025 if (string [*length] == ';') (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2026 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2027 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2028 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2029 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2030 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2031 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2032 |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2033 return TRUE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2034 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2035 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2036 static gboolean |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2037 gtk_imhtml_is_tag (const gchar *string, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2038 gchar **tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2039 gint *len, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2040 gint *type) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2041 { |
8061 | 2042 char *close; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2043 *type = 1; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2044 |
8118 | 2045 |
8061 | 2046 if (!(close = strchr (string, '>'))) |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2047 return FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2048 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2049 VALID_TAG ("B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2050 VALID_TAG ("BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2051 VALID_TAG ("/B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2052 VALID_TAG ("/BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2053 VALID_TAG ("I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2054 VALID_TAG ("ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2055 VALID_TAG ("/I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2056 VALID_TAG ("/ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2057 VALID_TAG ("U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2058 VALID_TAG ("UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2059 VALID_TAG ("/U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2060 VALID_TAG ("/UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2061 VALID_TAG ("S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2062 VALID_TAG ("STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2063 VALID_TAG ("/S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2064 VALID_TAG ("/STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2065 VALID_TAG ("SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2066 VALID_TAG ("/SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2067 VALID_TAG ("SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2068 VALID_TAG ("/SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2069 VALID_TAG ("PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2070 VALID_TAG ("/PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2071 VALID_TAG ("TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2072 VALID_TAG ("/TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2073 VALID_TAG ("BR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2074 VALID_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2075 VALID_TAG ("/FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2076 VALID_TAG ("/A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2077 VALID_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2078 VALID_TAG ("/P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2079 VALID_TAG ("H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2080 VALID_TAG ("/H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2081 VALID_TAG ("HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2082 VALID_TAG ("/HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2083 VALID_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2084 VALID_TAG ("/BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2085 VALID_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2086 VALID_TAG ("HEAD"); |
2993 | 2087 VALID_TAG ("/HEAD"); |
2088 VALID_TAG ("BINARY"); | |
2089 VALID_TAG ("/BINARY"); | |
5093 | 2090 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2091 VALID_OPT_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2092 VALID_OPT_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2093 VALID_OPT_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2094 VALID_OPT_TAG ("A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2095 VALID_OPT_TAG ("IMG"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2096 VALID_OPT_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2097 VALID_OPT_TAG ("H3"); |
5093 | 2098 VALID_OPT_TAG ("HTML"); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2099 |
5101 | 2100 VALID_TAG ("CITE"); |
2101 VALID_TAG ("/CITE"); | |
2102 VALID_TAG ("EM"); | |
2103 VALID_TAG ("/EM"); | |
2104 VALID_TAG ("STRONG"); | |
2105 VALID_TAG ("/STRONG"); | |
2106 | |
5104 | 2107 VALID_OPT_TAG ("SPAN"); |
2108 VALID_TAG ("/SPAN"); | |
5174 | 2109 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
6982 | 2110 VALID_TAG ("IMG"); |
8026 | 2111 VALID_TAG("SPAN"); |
8061 | 2112 VALID_OPT_TAG("BR"); |
7988 | 2113 |
4793 | 2114 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
2115 gchar *e = strstr (string + strlen("!--"), "-->"); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2116 if (e) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2117 *len = e - string + strlen ("-->"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2118 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2119 return TRUE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2120 } |
8118 | 2121 } |
2122 | |
8061 | 2123 *type = -1; |
2124 *len = close - string + 1; | |
2125 *tag = g_strndup(string, *len - 1); | |
2126 return TRUE; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2127 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2128 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2129 static gchar* |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2130 gtk_imhtml_get_html_opt (gchar *tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2131 const gchar *opt) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2132 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2133 gchar *t = tag; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2134 gchar *e, *a; |
5177 | 2135 gchar *val; |
2136 gint len; | |
7280 | 2137 gchar *c; |
5177 | 2138 GString *ret; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2139 |
4793 | 2140 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2141 gboolean quote = FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2142 if (*t == '\0') break; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2143 while (*t && !((*t == ' ') && !quote)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2144 if (*t == '\"') |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2145 quote = ! quote; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2146 t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2147 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2148 while (*t && (*t == ' ')) t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2149 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2150 |
4793 | 2151 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2152 t += strlen (opt); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2153 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2154 return NULL; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2155 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2156 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2157 if ((*t == '\"') || (*t == '\'')) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2158 e = a = ++t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2159 while (*e && (*e != *(t - 1))) e++; |
2993 | 2160 if (*e == '\0') { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2161 return NULL; |
5177 | 2162 } else |
2163 val = g_strndup(a, e - a); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2164 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2165 e = a = t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2166 while (*e && !isspace ((gint) *e)) e++; |
5177 | 2167 val = g_strndup(a, e - a); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2168 } |
5177 | 2169 |
2170 ret = g_string_new(""); | |
2171 e = val; | |
2172 while(*e) { | |
2173 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
7280 | 2174 ret = g_string_append(ret, c); |
5177 | 2175 e += len; |
2176 } else { | |
2177 ret = g_string_append_c(ret, *e); | |
2178 e++; | |
2179 } | |
2180 } | |
2181 | |
2182 g_free(val); | |
8568 | 2183 |
2184 return g_string_free(ret, FALSE); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2185 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2186 |
8118 | 2187 /* Inline CSS Support - Douglas Thrift */ |
2188 static gchar* | |
2189 gtk_imhtml_get_css_opt (gchar *style, | |
2190 const gchar *opt) | |
2191 { | |
2192 gchar *t = style; | |
2193 gchar *e, *a; | |
2194 gchar *val; | |
2195 gint len; | |
2196 gchar *c; | |
2197 GString *ret; | |
2198 | |
2199 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
8177 | 2200 /* gboolean quote = FALSE; */ |
8118 | 2201 if (*t == '\0') break; |
2202 while (*t && !((*t == ' ') /*&& !quote*/)) { | |
2203 /* if (*t == '\"') | |
8177 | 2204 quote = ! quote; */ |
8118 | 2205 t++; |
2206 } | |
2207 while (*t && (*t == ' ')) t++; | |
2208 } | |
2209 | |
2210 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
2211 t += strlen (opt); | |
10457 | 2212 while (*t && (*t == ' ')) t++; |
2213 if (!*t) | |
2214 return NULL; | |
8118 | 2215 } else { |
2216 return NULL; | |
2217 } | |
2218 | |
2219 /* if ((*t == '\"') || (*t == '\'')) { | |
2220 e = a = ++t; | |
2221 while (*e && (*e != *(t - 1))) e++; | |
2222 if (*e == '\0') { | |
2223 return NULL; | |
2224 } else | |
2225 val = g_strndup(a, e - a); | |
2226 } else { | |
2227 e = a = t; | |
2228 while (*e && !isspace ((gint) *e)) e++; | |
2229 val = g_strndup(a, e - a); | |
2230 }*/ | |
2231 | |
2232 e = a = t; | |
2233 while (*e && *e != ';') e++; | |
2234 val = g_strndup(a, e - a); | |
2235 | |
2236 ret = g_string_new(""); | |
2237 e = val; | |
2238 while(*e) { | |
2239 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
2240 ret = g_string_append(ret, c); | |
2241 e += len; | |
2242 } else { | |
2243 ret = g_string_append_c(ret, *e); | |
2244 e++; | |
2245 } | |
2246 } | |
2247 | |
2248 g_free(val); | |
2249 val = ret->str; | |
2250 g_string_free(ret, FALSE); | |
2251 return val; | |
2252 } | |
3922 | 2253 |
8334 | 2254 static const char *accepted_protocols[] = { |
2255 "http://", | |
2256 "https://", | |
2257 "ftp://" | |
2258 }; | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
2259 |
8334 | 2260 static const int accepted_protocols_size = 3; |
2261 | |
2262 /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so | |
2263 the caller knows how long the protocol string is. */ | |
12412
a88ca6da0b38
[gaim-migrate @ 14719]
Richard Laager <rlaager@wiktel.com>
parents:
12335
diff
changeset
|
2264 static int gtk_imhtml_is_protocol(const char *text) |
8334 | 2265 { |
2266 gint i; | |
2267 | |
2268 for(i=0; i<accepted_protocols_size; i++){ | |
2269 if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){ | |
2270 return strlen(accepted_protocols[i]); | |
2271 } | |
2272 } | |
2273 return 0; | |
2274 } | |
2275 | |
8677 | 2276 /* |
2277 <KingAnt> marv: The two IM image functions in oscar are gaim_odc_send_im and gaim_odc_incoming | |
2278 | |
2279 | |
2280 [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :) | |
2281 [19:59] <KingAnt> marv: I think the image tag used by the core is something like <img id="#"/> | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
2282 [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz |
8677 | 2283 [20:00] <KingAnt> marv: Where the ID is the what is returned when you add the image to the imgstore using gaim_imgstore_add |
2284 [20:00] <marv> Robot101: so how does the image get passed to serv_got_im() and serv_send_im()? just as the <img id="#" and then the prpl looks it up from the store? | |
2285 [20:00] <KingAnt> marv: Right | |
2286 [20:00] <marv> alright | |
2287 | |
2288 Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just | |
2289 gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a | |
2290 function for gaim to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that | |
2291 images can be looked up like that, instead of passing a GSList of them. | |
2292 */ | |
2293 | |
2294 void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, | |
2295 const gchar *text, | |
2296 GtkIMHtmlOptions options, | |
2297 GSList *unused) | |
1428 | 2298 { |
8677 | 2299 GtkTextIter iter, ins, sel; |
2300 GdkRectangle rect; | |
2301 int y, height, ins_offset = 0, sel_offset = 0; | |
2302 gboolean fixins = FALSE, fixsel = FALSE; | |
2303 | |
2304 g_return_if_fail (imhtml != NULL); | |
2305 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
2306 g_return_if_fail (text != NULL); | |
2307 | |
2308 | |
2309 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); | |
2310 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer)); | |
2311 if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
2312 fixins = TRUE; | |
2313 ins_offset = gtk_text_iter_get_offset(&ins); | |
2314 } | |
2315 | |
2316 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer)); | |
2317 if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
2318 fixsel = TRUE; | |
2319 sel_offset = gtk_text_iter_get_offset(&sel); | |
2320 } | |
2321 | |
2322 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
2323 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
2324 | |
2325 | |
2326 if(((y + height) - (rect.y + rect.height)) > height | |
2327 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
2328 options |= GTK_IMHTML_NO_SCROLL; | |
2329 } | |
2330 | |
2331 gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter); | |
2332 | |
2333 if (fixins) { | |
2334 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset); | |
2335 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins); | |
2336 } | |
2337 | |
2338 if (fixsel) { | |
2339 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset); | |
2340 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel); | |
2341 } | |
2342 | |
2343 if (!(options & GTK_IMHTML_NO_SCROLL)) { | |
12553 | 2344 gtk_imhtml_scroll_to_end(imhtml, (options & GTK_IMHTML_USE_SMOOTHSCROLLING)); |
8677 | 2345 } |
2346 } | |
2347 | |
11006 | 2348 #define MAX_SCROLL_TIME 0.4 /* seconds */ |
2349 #define SCROLL_DELAY 33 /* milliseconds */ | |
2350 | |
2351 /* | |
2352 * Smoothly scroll a GtkIMHtml. | |
2353 * | |
2354 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom. | |
2355 */ | |
10871 | 2356 static gboolean scroll_cb(gpointer data) |
10798 | 2357 { |
2358 GtkIMHtml *imhtml = data; | |
2359 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
11006 | 2360 gdouble max_val = adj->upper - adj->page_size; |
2361 | |
2362 g_return_val_if_fail(imhtml->scroll_time != NULL, FALSE); | |
2363 | |
2364 if (g_timer_elapsed(imhtml->scroll_time, NULL) > MAX_SCROLL_TIME) { | |
2365 /* time's up. jump to the end and kill the timer */ | |
2366 gtk_adjustment_set_value(adj, max_val); | |
10798 | 2367 g_timer_destroy(imhtml->scroll_time); |
2368 imhtml->scroll_time = NULL; | |
2369 return FALSE; | |
11006 | 2370 } |
2371 | |
2372 /* scroll by 1/3rd the remaining distance */ | |
2373 gtk_adjustment_set_value(adj, gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3)); | |
2374 return TRUE; | |
10798 | 2375 } |
2376 | |
12553 | 2377 static gboolean smooth_scroll_idle_cb(gpointer data) |
10797 | 2378 { |
10798 | 2379 GtkIMHtml *imhtml = data; |
11006 | 2380 imhtml->scroll_src = g_timeout_add(SCROLL_DELAY, scroll_cb, imhtml); |
10797 | 2381 return FALSE; |
2382 } | |
2383 | |
12553 | 2384 static gboolean scroll_idle_cb(gpointer data) |
2385 { | |
2386 GtkIMHtml *imhtml = data; | |
2387 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
2388 if(adj) { | |
2389 gtk_adjustment_set_value(adj, adj->upper - adj->page_size); | |
2390 } | |
2391 imhtml->scroll_src = 0; | |
2392 return FALSE; | |
2393 } | |
2394 | |
2395 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth) | |
8729 | 2396 { |
10798 | 2397 if (imhtml->scroll_time) |
2398 g_timer_destroy(imhtml->scroll_time); | |
2399 if (imhtml->scroll_src) | |
2400 g_source_remove(imhtml->scroll_src); | |
12553 | 2401 if(smooth) { |
2402 imhtml->scroll_time = g_timer_new(); | |
2403 imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, smooth_scroll_idle_cb, imhtml, NULL); | |
2404 } else { | |
2405 imhtml->scroll_time = NULL; | |
2406 imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL); | |
2407 } | |
8729 | 2408 } |
2409 | |
8677 | 2410 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, |
2411 const gchar *text, | |
2412 GtkIMHtmlOptions options, | |
2413 GtkTextIter *iter) | |
2414 { | |
8061 | 2415 GdkRectangle rect; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2416 gint pos = 0; |
3922 | 2417 gchar *ws; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2418 gchar *tag; |
3922 | 2419 gchar *bg = NULL; |
6982 | 2420 gint len; |
4032 | 2421 gint tlen, smilelen, wpos=0; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2422 gint type; |
3922 | 2423 const gchar *c; |
7280 | 2424 gchar *amp; |
8334 | 2425 gint len_protocol; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2426 |
1428 | 2427 guint bold = 0, |
2428 italics = 0, | |
2429 underline = 0, | |
2430 strike = 0, | |
2431 sub = 0, | |
2432 sup = 0, | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2433 title = 0, |
8061 | 2434 pre = 0; |
1428 | 2435 |
10217 | 2436 gboolean br = FALSE; |
2437 | |
3922 | 2438 GSList *fonts = NULL; |
8506 | 2439 GObject *object; |
8061 | 2440 GtkIMHtmlScalable *scalable = NULL; |
8677 | 2441 |
2442 g_return_if_fail (imhtml != NULL); | |
2443 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
2444 g_return_if_fail (text != NULL); | |
3922 | 2445 c = text; |
6982 | 2446 len = strlen(text); |
3922 | 2447 ws = g_malloc(len + 1); |
2448 ws[0] = 0; | |
1428 | 2449 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2450 while (pos < len) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2451 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2452 c++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2453 pos++; |
8061 | 2454 ws[wpos] = '\0'; |
10217 | 2455 br = FALSE; |
8061 | 2456 switch (type) |
3922 | 2457 { |
2458 case 1: /* B */ | |
2459 case 2: /* BOLD */ | |
5101 | 2460 case 54: /* STRONG */ |
11485
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2461 if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2462 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2463 |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2464 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD)) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2465 gtk_imhtml_toggle_bold(imhtml); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2466 bold++; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2467 ws[0] = '\0'; wpos = 0; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2468 } |
3922 | 2469 break; |
2470 case 3: /* /B */ | |
2471 case 4: /* /BOLD */ | |
5101 | 2472 case 55: /* /STRONG */ |
11485
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2473 if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2474 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2475 ws[0] = '\0'; wpos = 0; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2476 |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2477 if (bold) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2478 bold--; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2479 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2480 gtk_imhtml_toggle_bold(imhtml); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2481 } |
3922 | 2482 break; |
2483 case 5: /* I */ | |
2484 case 6: /* ITALIC */ | |
5101 | 2485 case 52: /* EM */ |
11485
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2486 if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2487 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2488 ws[0] = '\0'; wpos = 0; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2489 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC)) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2490 gtk_imhtml_toggle_italic(imhtml); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2491 italics++; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2492 } |
3922 | 2493 break; |
2494 case 7: /* /I */ | |
2495 case 8: /* /ITALIC */ | |
5101 | 2496 case 53: /* /EM */ |
11485
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2497 if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2498 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2499 ws[0] = '\0'; wpos = 0; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2500 if (italics) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2501 italics--; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2502 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2503 gtk_imhtml_toggle_italic(imhtml); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2504 } |
3922 | 2505 break; |
2506 case 9: /* U */ | |
2507 case 10: /* UNDERLINE */ | |
11485
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2508 if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2509 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2510 ws[0] = '\0'; wpos = 0; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2511 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2512 gtk_imhtml_toggle_underline(imhtml); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2513 underline++; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2514 } |
3922 | 2515 break; |
2516 case 11: /* /U */ | |
2517 case 12: /* /UNDERLINE */ | |
11485
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2518 if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2519 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2520 ws[0] = '\0'; wpos = 0; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2521 if (underline) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2522 underline--; |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2523 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2524 gtk_imhtml_toggle_underline(imhtml); |
16b0da1f376f
[gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents:
11385
diff
changeset
|
2525 } |
3922 | 2526 break; |
2527 case 13: /* S */ | |
2528 case 14: /* STRIKE */ | |
9924 | 2529 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2530 ws[0] = '\0'; wpos = 0; | |
2531 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE)) | |
2532 gtk_imhtml_toggle_strike(imhtml); | |
3922 | 2533 strike++; |
2534 break; | |
2535 case 15: /* /S */ | |
2536 case 16: /* /STRIKE */ | |
9924 | 2537 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2538 ws[0] = '\0'; wpos = 0; | |
3922 | 2539 if (strike) |
2540 strike--; | |
9924 | 2541 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo) |
2542 gtk_imhtml_toggle_strike(imhtml); | |
3922 | 2543 break; |
2544 case 17: /* SUB */ | |
8677 | 2545 /* FIXME: reimpliment this */ |
3922 | 2546 sub++; |
2547 break; | |
2548 case 18: /* /SUB */ | |
8677 | 2549 /* FIXME: reimpliment this */ |
3922 | 2550 if (sub) |
2551 sub--; | |
2552 break; | |
2553 case 19: /* SUP */ | |
8677 | 2554 /* FIXME: reimplement this */ |
3922 | 2555 sup++; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2556 break; |
3922 | 2557 case 20: /* /SUP */ |
8677 | 2558 /* FIXME: reimplement this */ |
3922 | 2559 if (sup) |
2560 sup--; | |
2561 break; | |
2562 case 21: /* PRE */ | |
8677 | 2563 /* FIXME: reimplement this */ |
3922 | 2564 pre++; |
2565 break; | |
2566 case 22: /* /PRE */ | |
8677 | 2567 /* FIXME: reimplement this */ |
3922 | 2568 if (pre) |
2569 pre--; | |
2570 break; | |
2571 case 23: /* TITLE */ | |
8677 | 2572 /* FIXME: what was this supposed to do anyway? */ |
3922 | 2573 title++; |
2574 break; | |
2575 case 24: /* /TITLE */ | |
8677 | 2576 /* FIXME: make this undo whatever 23 was supposed to do */ |
3922 | 2577 if (title) { |
2578 if (options & GTK_IMHTML_NO_TITLE) { | |
2579 wpos = 0; | |
2580 ws [wpos] = '\0'; | |
2581 } | |
2582 title--; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2583 } |
3922 | 2584 break; |
2585 case 25: /* BR */ | |
5174 | 2586 case 58: /* BR/ */ |
8061 | 2587 case 61: /* BR (opt) */ |
3922 | 2588 ws[wpos] = '\n'; |
2589 wpos++; | |
10217 | 2590 br = TRUE; |
6982 | 2591 break; |
3922 | 2592 case 26: /* HR */ |
2593 case 42: /* HR (opt) */ | |
8726 | 2594 { |
2595 int minus; | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
2596 struct scalable_data *sd = g_new(struct scalable_data, 1); |
8726 | 2597 |
3922 | 2598 ws[wpos++] = '\n'; |
8677 | 2599 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2600 | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
2601 sd->scalable = scalable = gtk_imhtml_hr_new(); |
11233
f08d22130bb2
[gaim-migrate @ 13373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11224
diff
changeset
|
2602 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
8061 | 2603 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
8677 | 2604 scalable->add_to(scalable, imhtml, iter); |
8726 | 2605 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
2606 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
2607 scalable->scale(scalable, rect.width - minus, rect.height); | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
2608 imhtml->scalables = g_list_append(imhtml->scalables, sd); |
8061 | 2609 ws[0] = '\0'; wpos = 0; |
7942 | 2610 ws[wpos++] = '\n'; |
8061 | 2611 |
3922 | 2612 break; |
8726 | 2613 } |
3922 | 2614 case 27: /* /FONT */ |
8677 | 2615 if (fonts && !imhtml->wbfo) { |
5967 | 2616 GtkIMHtmlFontDetail *font = fonts->data; |
8677 | 2617 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2618 ws[0] = '\0'; wpos = 0; |
8177 | 2619 /* NEW_BIT (NEW_TEXT_BIT); */ |
8677 | 2620 |
8698 | 2621 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) { |
8061 | 2622 gtk_imhtml_toggle_fontface(imhtml, NULL); |
3922 | 2623 g_free (font->face); |
8061 | 2624 } |
8698 | 2625 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
8061 | 2626 gtk_imhtml_toggle_forecolor(imhtml, NULL); |
3922 | 2627 g_free (font->fore); |
8061 | 2628 } |
8698 | 2629 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
8061 | 2630 gtk_imhtml_toggle_backcolor(imhtml, NULL); |
3922 | 2631 g_free (font->back); |
8061 | 2632 } |
4032 | 2633 if (font->sml) |
2634 g_free (font->sml); | |
8309 | 2635 |
8698 | 2636 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
8309 | 2637 gtk_imhtml_font_set_size(imhtml, 3); |
2638 | |
10761 | 2639 |
2640 fonts = g_slist_remove (fonts, font); | |
9245 | 2641 g_free(font); |
2642 | |
8309 | 2643 if (fonts) { |
2644 GtkIMHtmlFontDetail *font = fonts->data; | |
8677 | 2645 |
8698 | 2646 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) |
8309 | 2647 gtk_imhtml_toggle_fontface(imhtml, font->face); |
8698 | 2648 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
8309 | 2649 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
8698 | 2650 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
8309 | 2651 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
8698 | 2652 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
8309 | 2653 gtk_imhtml_font_set_size(imhtml, font->size); |
2654 } | |
3922 | 2655 } |
8309 | 2656 break; |
3922 | 2657 case 28: /* /A */ |
8677 | 2658 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2659 gtk_imhtml_toggle_link(imhtml, NULL); | |
2660 ws[0] = '\0'; wpos = 0; | |
8061 | 2661 break; |
8118 | 2662 |
3922 | 2663 case 29: /* P */ |
2664 case 30: /* /P */ | |
2665 case 31: /* H3 */ | |
2666 case 32: /* /H3 */ | |
2667 case 33: /* HTML */ | |
2668 case 34: /* /HTML */ | |
2669 case 35: /* BODY */ | |
10776 | 2670 break; |
3922 | 2671 case 36: /* /BODY */ |
10786 | 2672 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2673 ws[0] = '\0'; wpos = 0; | |
10776 | 2674 gtk_imhtml_toggle_background(imhtml, NULL); |
2675 break; | |
3922 | 2676 case 37: /* FONT */ |
2677 case 38: /* HEAD */ | |
2678 case 39: /* /HEAD */ | |
6982 | 2679 case 40: /* BINARY */ |
2680 case 41: /* /BINARY */ | |
3922 | 2681 break; |
2682 case 43: /* FONT (opt) */ | |
2683 { | |
4032 | 2684 gchar *color, *back, *face, *size, *sml; |
5967 | 2685 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
3922 | 2686 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
2687 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
2688 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
2689 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
4032 | 2690 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
2691 if (!(color || back || face || size || sml)) | |
3922 | 2692 break; |
8061 | 2693 |
8677 | 2694 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2695 ws[0] = '\0'; wpos = 0; |
2696 | |
5967 | 2697 font = g_new0 (GtkIMHtmlFontDetail, 1); |
3922 | 2698 if (fonts) |
2699 oldfont = fonts->data; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2700 |
8677 | 2701 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
3922 | 2702 font->fore = color; |
8061 | 2703 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
8677 | 2704 } |
2705 | |
2706 if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { | |
3922 | 2707 font->back = back; |
8061 | 2708 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
8309 | 2709 } |
8677 | 2710 |
2711 if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) { | |
3922 | 2712 font->face = face; |
8061 | 2713 gtk_imhtml_toggle_fontface(imhtml, font->face); |
8309 | 2714 } |
4032 | 2715 |
2716 if (sml) | |
2717 font->sml = sml; | |
2718 else if (oldfont && oldfont->sml) | |
2719 font->sml = g_strdup(oldfont->sml); | |
2720 | |
8677 | 2721 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) { |
3922 | 2722 if (*size == '+') { |
2723 sscanf (size + 1, "%hd", &font->size); | |
2724 font->size += 3; | |
2725 } else if (*size == '-') { | |
2726 sscanf (size + 1, "%hd", &font->size); | |
2727 font->size = MAX (0, 3 - font->size); | |
2728 } else if (isdigit (*size)) { | |
2729 sscanf (size, "%hd", &font->size); | |
8061 | 2730 } |
6042 | 2731 if (font->size > 100) |
2732 font->size = 100; | |
3922 | 2733 } else if (oldfont) |
2734 font->size = oldfont->size; | |
8309 | 2735 else |
2736 font->size = 3; | |
8698 | 2737 if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
2738 gtk_imhtml_font_set_size(imhtml, font->size); | |
3922 | 2739 g_free(size); |
2740 fonts = g_slist_prepend (fonts, font); | |
2741 } | |
2742 break; | |
2743 case 44: /* BODY (opt) */ | |
2744 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
2745 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
8677 | 2746 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
2747 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
8061 | 2748 ws[0] = '\0'; wpos = 0; |
8177 | 2749 /* NEW_BIT(NEW_TEXT_BIT); */ |
3922 | 2750 if (bg) |
2751 g_free(bg); | |
2752 bg = bgcolor; | |
10776 | 2753 gtk_imhtml_toggle_background(imhtml, bg); |
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
2754 } |
1428 | 2755 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2756 break; |
3922 | 2757 case 45: /* A (opt) */ |
2758 { | |
2759 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
8677 | 2760 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) { |
2761 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
8061 | 2762 ws[0] = '\0'; wpos = 0; |
8677 | 2763 gtk_imhtml_toggle_link(imhtml, href); |
3922 | 2764 } |
10504 | 2765 if (href) |
2766 g_free(href); | |
2993 | 2767 } |
3922 | 2768 break; |
4895 | 2769 case 46: /* IMG (opt) */ |
6982 | 2770 case 59: /* IMG */ |
4895 | 2771 { |
8962 | 2772 const char *id; |
2773 | |
2774 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
2775 ws[0] = '\0'; wpos = 0; | |
4895 | 2776 |
8677 | 2777 if (!(imhtml->format_functions & GTK_IMHTML_IMAGE)) |
2778 break; | |
2779 | |
8962 | 2780 id = gtk_imhtml_get_html_opt(tag, "ID="); |
9186 | 2781 if (!id) |
2782 break; | |
8962 | 2783 gtk_imhtml_insert_image_at_iter(imhtml, atoi(id), iter); |
2784 break; | |
4895 | 2785 } |
3922 | 2786 case 47: /* P (opt) */ |
2787 case 48: /* H3 (opt) */ | |
5093 | 2788 case 49: /* HTML (opt) */ |
5101 | 2789 case 50: /* CITE */ |
2790 case 51: /* /CITE */ | |
8026 | 2791 case 56: /* SPAN (opt) */ |
8118 | 2792 /* Inline CSS Support - Douglas Thrift |
2793 * | |
2794 * color | |
8686 | 2795 * background |
8118 | 2796 * font-family |
2797 * font-size | |
8686 | 2798 * text-decoration: underline |
10483 | 2799 * |
2800 * TODO: | |
2801 * background-color | |
2802 * font-style | |
2803 * font-weight | |
8118 | 2804 */ |
2805 { | |
8686 | 2806 gchar *style, *color, *background, *family, *size; |
2807 gchar *textdec; | |
8118 | 2808 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
2809 style = gtk_imhtml_get_html_opt (tag, "style="); | |
2810 | |
2811 if (!style) break; | |
2812 | |
10457 | 2813 color = gtk_imhtml_get_css_opt (style, "color:"); |
2814 background = gtk_imhtml_get_css_opt (style, "background:"); | |
8118 | 2815 family = gtk_imhtml_get_css_opt (style, |
10457 | 2816 "font-family:"); |
2817 size = gtk_imhtml_get_css_opt (style, "font-size:"); | |
2818 textdec = gtk_imhtml_get_css_opt (style, "text-decoration:"); | |
8686 | 2819 |
2820 if (!(color || family || size || background || textdec)) { | |
8120 | 2821 g_free(style); |
2822 break; | |
2823 } | |
8118 | 2824 |
8677 | 2825 |
2826 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
8118 | 2827 ws[0] = '\0'; wpos = 0; |
8177 | 2828 /* NEW_BIT (NEW_TEXT_BIT); */ |
8118 | 2829 |
2830 font = g_new0 (GtkIMHtmlFontDetail, 1); | |
2831 if (fonts) | |
2832 oldfont = fonts->data; | |
2833 | |
8677 | 2834 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
8686 | 2835 { |
8118 | 2836 font->fore = color; |
8686 | 2837 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
2838 } | |
8118 | 2839 else if (oldfont && oldfont->fore) |
2840 font->fore = g_strdup(oldfont->fore); | |
2841 | |
8686 | 2842 if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
2843 { | |
2844 font->back = background; | |
2845 gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
2846 } | |
2847 else if (oldfont && oldfont->back) | |
8118 | 2848 font->back = g_strdup(oldfont->back); |
2849 | |
8677 | 2850 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) |
8686 | 2851 { |
8118 | 2852 font->face = family; |
8686 | 2853 gtk_imhtml_toggle_fontface(imhtml, font->face); |
2854 } | |
8118 | 2855 else if (oldfont && oldfont->face) |
2856 font->face = g_strdup(oldfont->face); | |
2857 if (font->face && (atoi(font->face) > 100)) { | |
8677 | 2858 /* WTF is this? */ |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
2859 /* Maybe it sets a max size on the font face? I seem to |
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
2860 * remember bad things happening if the font size was |
9696 | 2861 * 2 billion */ |
8118 | 2862 g_free(font->face); |
2863 font->face = g_strdup("100"); | |
2864 } | |
2865 | |
2866 if (oldfont && oldfont->sml) | |
2867 font->sml = g_strdup(oldfont->sml); | |
2868 | |
8677 | 2869 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) { |
8686 | 2870 if (g_ascii_strcasecmp(size, "xx-small") == 0) |
2871 font->size = 1; | |
2872 else if (g_ascii_strcasecmp(size, "smaller") == 0 | |
2873 || g_ascii_strcasecmp(size, "x-small") == 0) | |
8118 | 2874 font->size = 2; |
8686 | 2875 else if (g_ascii_strcasecmp(size, "larger") == 0 |
2876 || g_ascii_strcasecmp(size, "medium") == 0) | |
8118 | 2877 font->size = 4; |
8686 | 2878 else if (g_ascii_strcasecmp(size, "large") == 0) |
2879 font->size = 5; | |
2880 else if (g_ascii_strcasecmp(size, "x-large") == 0) | |
2881 font->size = 6; | |
2882 else if (g_ascii_strcasecmp(size, "xx-large") == 0) | |
2883 font->size = 7; | |
8118 | 2884 else |
2885 font->size = 3; | |
8686 | 2886 gtk_imhtml_font_set_size(imhtml, font->size); |
2887 } | |
2888 else if (oldfont) | |
2889 { | |
2890 font->size = oldfont->size; | |
2891 } | |
2892 | |
2893 if (oldfont) | |
2894 { | |
2895 font->underline = oldfont->underline; | |
2896 } | |
2897 if (textdec && font->underline != 1 | |
9025 | 2898 && g_ascii_strcasecmp(textdec, "underline") == 0 |
8686 | 2899 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
2900 { | |
2901 gtk_imhtml_toggle_underline(imhtml); | |
2902 font->underline = 1; | |
2903 } | |
8118 | 2904 |
2905 g_free(style); | |
2906 g_free(size); | |
2907 fonts = g_slist_prepend (fonts, font); | |
2908 } | |
2909 break; | |
5104 | 2910 case 57: /* /SPAN */ |
8118 | 2911 /* Inline CSS Support - Douglas Thrift */ |
8677 | 2912 if (fonts && !imhtml->wbfo) { |
8686 | 2913 GtkIMHtmlFontDetail *oldfont = NULL; |
8118 | 2914 GtkIMHtmlFontDetail *font = fonts->data; |
8677 | 2915 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8118 | 2916 ws[0] = '\0'; wpos = 0; |
8177 | 2917 /* NEW_BIT (NEW_TEXT_BIT); */ |
8118 | 2918 fonts = g_slist_remove (fonts, font); |
8692 | 2919 if (fonts) |
2920 oldfont = fonts->data; | |
2921 | |
2922 if (!oldfont) { | |
2923 gtk_imhtml_font_set_size(imhtml, 3); | |
2924 if (font->underline) | |
2925 gtk_imhtml_toggle_underline(imhtml); | |
2926 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
2927 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
2928 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
8686 | 2929 } |
8692 | 2930 else |
8686 | 2931 { |
8692 | 2932 |
2933 if (font->size != oldfont->size) | |
2934 gtk_imhtml_font_set_size(imhtml, oldfont->size); | |
2935 | |
2936 if (font->underline != oldfont->underline) | |
2937 gtk_imhtml_toggle_underline(imhtml); | |
2938 | |
9286 | 2939 if (font->face && (!oldfont->face || strcmp(font->face, oldfont->face) != 0)) |
8692 | 2940 gtk_imhtml_toggle_fontface(imhtml, oldfont->face); |
2941 | |
9286 | 2942 if (font->fore && (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0)) |
8692 | 2943 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore); |
2944 | |
9286 | 2945 if (font->back && (!oldfont->back || strcmp(font->back, oldfont->back) != 0)) |
8692 | 2946 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back); |
8686 | 2947 } |
8692 | 2948 |
2949 g_free (font->face); | |
2950 g_free (font->fore); | |
2951 g_free (font->back); | |
2952 g_free (font->sml); | |
2953 | |
8118 | 2954 g_free (font); |
2955 } | |
2956 break; | |
8026 | 2957 case 60: /* SPAN */ |
2993 | 2958 break; |
8061 | 2959 case 62: /* comment */ |
8177 | 2960 /* NEW_BIT (NEW_TEXT_BIT); */ |
8317 | 2961 ws[wpos] = '\0'; |
9465 | 2962 |
8677 | 2963 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2964 | |
10815 | 2965 if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) { |
6124 | 2966 wpos = g_snprintf (ws, len, "%s", tag); |
10815 | 2967 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2968 } | |
2969 ws[0] = '\0'; wpos = 0; | |
2970 | |
8177 | 2971 /* NEW_BIT (NEW_COMMENT_BIT); */ |
3922 | 2972 break; |
2973 default: | |
6882 | 2974 break; |
2993 | 2975 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2976 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2977 pos += tlen; |
4138 | 2978 if(tag) |
2979 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
9029 | 2980 } else if (gtk_imhtml_is_smiley(imhtml, fonts, c, &smilelen)) { |
8473 | 2981 GtkIMHtmlFontDetail *fd; |
2982 | |
2983 gchar *sml = NULL; | |
2984 if (fonts) { | |
2985 fd = fonts->data; | |
2986 sml = fd->sml; | |
2987 } | |
9029 | 2988 if (!sml) |
2989 sml = imhtml->protocol_name; | |
2990 | |
8677 | 2991 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8505 | 2992 wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
8473 | 2993 |
8677 | 2994 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter); |
8473 | 2995 |
8505 | 2996 c += smilelen; |
2997 pos += smilelen; | |
8473 | 2998 wpos = 0; |
2999 ws[0] = 0; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
3000 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
7280 | 3001 while(*amp) { |
3002 ws [wpos++] = *amp++; | |
3003 } | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
3004 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
3005 pos += tlen; |
1428 | 3006 } else if (*c == '\n') { |
3007 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
3922 | 3008 ws[wpos] = '\n'; |
3009 wpos++; | |
8677 | 3010 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 3011 ws[0] = '\0'; |
3012 wpos = 0; | |
8177 | 3013 /* NEW_BIT (NEW_TEXT_BIT); */ |
10217 | 3014 } else if (!br) { /* Don't insert a space immediately after an HTML break */ |
9621 | 3015 /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary. |
3016 * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine | |
3017 * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert | |
3018 * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand? | |
3019 * Bu-wahaha! */ | |
3020 ws[wpos] = ' '; | |
3021 wpos++; | |
3022 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
3023 ws[0] = '\0'; | |
3024 wpos = 0; | |
1428 | 3025 } |
3026 c++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
3027 pos++; |
8334 | 3028 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ |
3029 while(len_protocol--){ | |
8677 | 3030 /* Skip the next len_protocol characters, but make sure they're |
8334 | 3031 copied into the ws array. |
3032 */ | |
3033 ws [wpos++] = *c++; | |
3034 pos++; | |
3035 } | |
8061 | 3036 } else if (*c) { |
1428 | 3037 ws [wpos++] = *c++; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
3038 pos++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
3039 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
3040 break; |
1428 | 3041 } |
3042 } | |
8677 | 3043 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 3044 ws[0] = '\0'; wpos = 0; |
3045 | |
8177 | 3046 /* NEW_BIT(NEW_TEXT_BIT); */ |
8061 | 3047 |
4032 | 3048 while (fonts) { |
5967 | 3049 GtkIMHtmlFontDetail *font = fonts->data; |
4032 | 3050 fonts = g_slist_remove (fonts, font); |
3051 if (font->face) | |
3052 g_free (font->face); | |
3053 if (font->fore) | |
3054 g_free (font->fore); | |
3055 if (font->back) | |
3056 g_free (font->back); | |
3057 if (font->sml) | |
3058 g_free (font->sml); | |
3059 g_free (font); | |
3060 } | |
8932 | 3061 |
3062 g_free(ws); | |
3063 if (bg) | |
4630 | 3064 g_free(bg); |
8677 | 3065 |
3066 if (!imhtml->wbfo) | |
8698 | 3067 gtk_imhtml_close_tags(imhtml, iter); |
8506 | 3068 |
3069 object = g_object_ref(G_OBJECT(imhtml)); | |
3070 g_signal_emit(object, signals[UPDATE_FORMAT], 0); | |
3071 g_object_unref(object); | |
3072 | |
3922 | 3073 } |
3074 | |
4892 | 3075 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
3076 { | |
4288 | 3077 g_hash_table_destroy(imhtml->smiley_data); |
3078 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
4892 | 3079 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
4902 | 3080 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
4288 | 3081 imhtml->default_smilies = gtk_smiley_tree_new(); |
3082 } | |
8481 | 3083 |
3922 | 3084 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, |
4253 | 3085 gboolean show) |
3086 { | |
6124 | 3087 imhtml->show_comments = show; |
4253 | 3088 } |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
3089 |
11814
fa17fc619f17
[gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents:
11768
diff
changeset
|
3090 const char * |
fa17fc619f17
[gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents:
11768
diff
changeset
|
3091 gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml) { |
fa17fc619f17
[gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents:
11768
diff
changeset
|
3092 return imhtml->protocol_name; |
fa17fc619f17
[gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents:
11768
diff
changeset
|
3093 } |
fa17fc619f17
[gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents:
11768
diff
changeset
|
3094 |
8962 | 3095 void |
9029 | 3096 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name) { |
3097 if (imhtml->protocol_name) | |
3098 g_free(imhtml->protocol_name); | |
3099 imhtml->protocol_name = protocol_name ? g_strdup(protocol_name) : NULL; | |
8456 | 3100 } |
3101 | |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
3102 void |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3103 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3104 GList *l; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3105 GSList *sl; |
11234
7d5e8bed8018
[gaim-migrate @ 13377]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11233
diff
changeset
|
3106 GtkTextIter i, i_s, i_e; |
8427 | 3107 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3108 |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3109 if (start == NULL) { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3110 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3111 start = &i_s; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3112 } |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3113 |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3114 if (end == NULL) { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3115 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3116 end = &i_e; |
7991 | 3117 } |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3118 |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3119 l = imhtml->scalables; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3120 while (l) { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3121 GList *next = l->next; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3122 struct scalable_data *sd = l->data; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3123 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3124 &i, sd->mark); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3125 if (gtk_text_iter_in_range(&i, start, end)) { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3126 GtkIMHtmlScalable *scale = sd->scalable; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3127 scale->free(scale); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3128 imhtml->scalables = g_list_remove_link(imhtml->scalables, l); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3129 } |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3130 l = next; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3131 } |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3132 |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3133 sl = imhtml->im_images; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3134 while (sl) { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3135 GSList *next = sl->next; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3136 struct im_image_data *img_data = sl->data; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3137 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3138 &i, img_data->mark); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3139 if (gtk_text_iter_in_range(&i, start, end)) { |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3140 if (imhtml->funcs->image_unref) |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3141 imhtml->funcs->image_unref(img_data->id); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3142 imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3143 g_free(img_data); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3144 } |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3145 sl = next; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3146 } |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
3147 gtk_text_buffer_delete(imhtml->text_buffer, start, end); |
8061 | 3148 |
8427 | 3149 g_object_unref(object); |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
3150 } |
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
3151 |
4046 | 3152 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
3153 { | |
5282 | 3154 GdkRectangle rect; |
3155 GtkTextIter iter; | |
4046 | 3156 |
5282 | 3157 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
3158 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
3159 rect.y - rect.height); | |
3160 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
8061 | 3161 |
4046 | 3162 } |
5282 | 3163 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
3164 { | |
3165 GdkRectangle rect; | |
3166 GtkTextIter iter; | |
3167 | |
3168 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
3169 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
3170 rect.y + rect.height); | |
3171 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
3172 } | |
4735 | 3173 |
5967 | 3174 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
8962 | 3175 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id) |
4735 | 3176 { |
5967 | 3177 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
5012 | 3178 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
4895 | 3179 |
5967 | 3180 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
3181 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
3182 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
5046 | 3183 |
3184 im_image->pixbuf = img; | |
5012 | 3185 im_image->image = image; |
4895 | 3186 im_image->width = gdk_pixbuf_get_width(img); |
3187 im_image->height = gdk_pixbuf_get_height(img); | |
3188 im_image->mark = NULL; | |
6982 | 3189 im_image->filename = filename ? g_strdup(filename) : NULL; |
8962 | 3190 im_image->id = id; |
9573 | 3191 im_image->filesel = NULL; |
4895 | 3192 |
5046 | 3193 g_object_ref(img); |
4895 | 3194 return GTK_IMHTML_SCALABLE(im_image); |
3195 } | |
3196 | |
5967 | 3197 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
4895 | 3198 { |
11867
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3199 GtkIMHtmlImage *im_image = (GtkIMHtmlImage *)scale; |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3200 |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3201 if (im_image->width > width || im_image->height > height) { |
11840
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
3202 double ratio_w, ratio_h, ratio; |
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
3203 int new_h, new_w; |
4895 | 3204 GdkPixbuf *new_image = NULL; |
11840
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
3205 |
11867
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3206 ratio_w = ((double)width - 2) / im_image->width; |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3207 ratio_h = ((double)height - 2) / im_image->height; |
11840
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
3208 |
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
3209 ratio = (ratio_w < ratio_h) ? ratio_w : ratio_h; |
047f85200139
[gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents:
11820
diff
changeset
|
3210 |
11867
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3211 new_w = (int)(im_image->width * ratio); |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3212 new_h = (int)(im_image->height * ratio); |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3213 |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3214 new_image = gdk_pixbuf_scale_simple(im_image->pixbuf, new_w, new_h, GDK_INTERP_BILINEAR); |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3215 gtk_image_set_from_pixbuf(im_image->image, new_image); |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3216 g_object_unref(G_OBJECT(new_image)); |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3217 } else if (gdk_pixbuf_get_width(gtk_image_get_pixbuf(im_image->image)) != im_image->width) { |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3218 /* Enough space to show the full-size of the image. */ |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3219 GdkPixbuf *new_image; |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3220 |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3221 new_image = gdk_pixbuf_scale_simple(im_image->pixbuf, im_image->width, im_image->height, GDK_INTERP_BILINEAR); |
ff02464a079f
[gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents:
11844
diff
changeset
|
3222 gtk_image_set_from_pixbuf(im_image->image, new_image); |
4895 | 3223 g_object_unref(G_OBJECT(new_image)); |
3224 } | |
3225 } | |
3226 | |
9573 | 3227 static void |
3228 image_save_yes_cb(GtkIMHtmlImage *image, const char *filename) | |
5012 | 3229 { |
3230 gchar *type = NULL; | |
5019 | 3231 GError *error = NULL; |
5015 | 3232 #if GTK_CHECK_VERSION(2,2,0) |
5012 | 3233 GSList *formats = gdk_pixbuf_get_formats(); |
6162 | 3234 #else |
3235 char *basename = g_path_get_basename(filename); | |
3236 char *ext = strrchr(basename, '.'); | |
5959 | 3237 #endif |
5012 | 3238 |
9573 | 3239 gtk_widget_destroy(image->filesel); |
3240 image->filesel = NULL; | |
5959 | 3241 |
3242 #if GTK_CHECK_VERSION(2,2,0) | |
9573 | 3243 while (formats) { |
5012 | 3244 GdkPixbufFormat *format = formats->data; |
3245 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
3246 gpointer p = extensions; | |
3247 | |
3248 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
3249 gchar *fmt_ext = extensions[0]; | |
3250 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
3251 | |
3252 if(!strcmp(fmt_ext, file_ext)){ | |
3253 type = gdk_pixbuf_format_get_name(format); | |
3254 break; | |
3255 } | |
3256 | |
3257 extensions++; | |
3258 } | |
3259 | |
3260 g_strfreev(p); | |
3261 | |
9573 | 3262 if (type) |
5012 | 3263 break; |
3264 | |
3265 formats = formats->next; | |
3266 } | |
3267 | |
5020 | 3268 g_slist_free(formats); |
3269 #else | |
3270 /* this is really ugly code, but I think it will work */ | |
9573 | 3271 if (ext) { |
5020 | 3272 ext++; |
9573 | 3273 if (!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) |
5020 | 3274 type = g_strdup("jpeg"); |
9573 | 3275 else if (!g_ascii_strcasecmp(ext, "png")) |
5020 | 3276 type = g_strdup("png"); |
3277 } | |
3278 | |
3279 g_free(basename); | |
3280 #endif | |
3281 | |
5012 | 3282 /* If I can't find a valid type, I will just tell the user about it and then assume |
3283 it's a png */ | |
9573 | 3284 if (!type){ |
11069
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3285 #if GTK_CHECK_VERSION(2,4,0) |
11019 | 3286 GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
3287 _("<span size='larger' weight='bold'>Unrecognized file type</span>\n\nDefaulting to PNG.")); | |
11069
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3288 #else |
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3289 GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3290 _("Unrecognized file type\n\nDefaulting to PNG.")); |
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3291 #endif |
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3292 |
11019 | 3293 g_signal_connect_swapped(dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); |
3294 gtk_widget_show(dialog); | |
9717 | 3295 type = g_strdup("png"); |
5012 | 3296 } |
3297 | |
5046 | 3298 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
5012 | 3299 |
9573 | 3300 if (error){ |
11069
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3301 #if GTK_CHECK_VERSION(2,4,0) |
11019 | 3302 GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
3303 _("<span size='larger' weight='bold'>Error saving image</span>\n\n%s"), error->message); | |
11069
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3304 #else |
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3305 GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3306 _("Error saving image\n\n%s"), error->message); |
65db26d0bc90
[gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents:
11019
diff
changeset
|
3307 #endif |
11019 | 3308 g_signal_connect_swapped(dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); |
3309 gtk_widget_show(dialog); | |
5012 | 3310 g_error_free(error); |
3311 } | |
3312 | |
3313 g_free(type); | |
3314 } | |
3315 | |
9573 | 3316 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
3317 static void | |
3318 image_save_check_if_exists_cb(GtkWidget *widget, gint response, GtkIMHtmlImage *image) | |
3319 { | |
3320 gchar *filename; | |
3321 | |
3322 if (response != GTK_RESPONSE_ACCEPT) { | |
3323 gtk_widget_destroy(widget); | |
3324 image->filesel = NULL; | |
3325 return; | |
3326 } | |
3327 | |
3328 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); | |
3329 #else /* FILECHOOSER */ | |
3330 static void | |
3331 image_save_check_if_exists_cb(GtkWidget *button, GtkIMHtmlImage *image) | |
5012 | 3332 { |
9573 | 3333 gchar *filename; |
3334 | |
3335 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(image->filesel))); | |
3336 | |
3337 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
3338 gchar *dirname; | |
3339 /* append a / is needed */ | |
3340 if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR) { | |
3341 dirname = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL); | |
3342 } else { | |
3343 dirname = g_strdup(filename); | |
3344 } | |
9574 | 3345 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), dirname); |
9573 | 3346 g_free(dirname); |
3347 g_free(filename); | |
3348 return; | |
3349 } | |
3350 #endif /* FILECHOOSER */ | |
3351 | |
3352 /* | |
3353 * XXX - We should probably prompt the user to determine if they really | |
3354 * want to overwrite the file or not. However, I don't feel like doing | |
3355 * that, so we're just always going to overwrite if the file exists. | |
3356 */ | |
3357 /* | |
3358 if (g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
3359 } else | |
3360 image_save_yes_cb(image, filename); | |
3361 */ | |
3362 | |
3363 image_save_yes_cb(image, filename); | |
3364 | |
3365 g_free(filename); | |
3366 } | |
3367 | |
3368 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
3369 static void | |
3370 image_save_cancel_cb(GtkIMHtmlImage *image) | |
3371 { | |
3372 gtk_widget_destroy(image->filesel); | |
3373 image->filesel = NULL; | |
3374 } | |
3375 #endif /* FILECHOOSER */ | |
3376 | |
3377 static void | |
3378 gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) | |
3379 { | |
3380 if (image->filesel != NULL) { | |
3381 gtk_window_present(GTK_WINDOW(image->filesel)); | |
3382 return; | |
3383 } | |
3384 | |
3385 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
3386 image->filesel = gtk_file_chooser_dialog_new(_("Save Image"), | |
3387 NULL, | |
3388 GTK_FILE_CHOOSER_ACTION_SAVE, | |
3389 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
3390 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | |
3391 NULL); | |
3392 gtk_dialog_set_default_response(GTK_DIALOG(image->filesel), GTK_RESPONSE_ACCEPT); | |
3393 if (image->filename != NULL) | |
3394 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(image->filesel), image->filename); | |
3395 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(image->filesel)), "response", | |
3396 G_CALLBACK(image_save_check_if_exists_cb), image); | |
3397 #else /* FILECHOOSER */ | |
3398 image->filesel = gtk_file_selection_new(_("Save Image")); | |
3399 if (image->filename != NULL) | |
3400 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), image->filename); | |
9574 | 3401 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)), "delete_event", |
3402 G_CALLBACK(image_save_cancel_cb), image); | |
3403 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->cancel_button), | |
3404 "clicked", G_CALLBACK(image_save_cancel_cb), image); | |
9573 | 3405 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->ok_button), "clicked", |
3406 G_CALLBACK(image_save_check_if_exists_cb), image); | |
3407 #endif /* FILECHOOSER */ | |
3408 | |
3409 gtk_widget_show(image->filesel); | |
5012 | 3410 } |
3411 | |
9815 | 3412 /* |
3413 * So, um, AIM Direct IM lets you send any file, not just images. You can | |
3414 * just insert a sound or a file or whatever in a conversation. It's | |
3415 * basically like file transfer, except there is an icon to open the file | |
3416 * embedded in the conversation. Someone should make the Gaim core handle | |
3417 * all of that. | |
3418 */ | |
5967 | 3419 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
5012 | 3420 { |
3421 GdkEventButton *event_button = (GdkEventButton *) event; | |
3422 | |
3423 if (event->type == GDK_BUTTON_RELEASE) { | |
3424 if(event_button->button == 3) { | |
3425 GtkWidget *img, *item, *menu; | |
3426 gchar *text = g_strdup_printf(_("_Save Image...")); | |
3427 menu = gtk_menu_new(); | |
3428 | |
3429 /* buttons and such */ | |
3430 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
3431 item = gtk_image_menu_item_new_with_mnemonic(text); | |
3432 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
5967 | 3433 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
5012 | 3434 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
3435 | |
3436 gtk_widget_show_all(menu); | |
3437 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
3438 event_button->button, event_button->time); | |
3439 | |
3440 g_free(text); | |
3441 return TRUE; | |
3442 } | |
3443 } | |
3444 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
3445 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
3446 be caught by the regular GtkTextView menu */ | |
3447 else | |
3448 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
3449 | |
3450 } | |
5967 | 3451 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
3452 { | |
3453 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
3454 | |
3455 g_object_unref(image->pixbuf); | |
6982 | 3456 if (image->filename) |
3457 g_free(image->filename); | |
9573 | 3458 if (image->filesel) |
3459 gtk_widget_destroy(image->filesel); | |
5967 | 3460 g_free(scale); |
3461 } | |
3462 | |
3463 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
3464 { | |
3465 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
3466 GtkWidget *box = gtk_event_box_new(); | |
8962 | 3467 char *tag; |
5967 | 3468 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
3469 | |
3470 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
9229 | 3471 |
3472 if(!gtk_check_version(2, 4, 0)) | |
3473 g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL); | |
5967 | 3474 |
3475 gtk_widget_show(GTK_WIDGET(image->image)); | |
3476 gtk_widget_show(box); | |
3477 | |
8962 | 3478 tag = g_strdup_printf("<IMG ID=\"%d\">", image->id); |
3479 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", tag, g_free); | |
3480 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "[Image]"); | |
3481 | |
5967 | 3482 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); |
3483 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
3484 } | |
3485 | |
3486 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
3487 { | |
3488 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
3489 | |
3490 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
3491 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
3492 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
3493 | |
3494 hr->sep = gtk_hseparator_new(); | |
3495 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
3496 gtk_widget_show(hr->sep); | |
3497 | |
3498 return GTK_IMHTML_SCALABLE(hr); | |
3499 } | |
3500 | |
3501 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
3502 { | |
8588 | 3503 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width - 2, 2); |
5967 | 3504 } |
3505 | |
3506 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
3507 { | |
3508 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
3509 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
8698 | 3510 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>"); |
3511 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n"); | |
5967 | 3512 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); |
3513 } | |
3514 | |
3515 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
3516 { | |
3517 g_free(scale); | |
3518 } | |
7295 | 3519 |
3520 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
3521 { | |
3522 GtkTextIter iter, start, end; | |
3523 gboolean new_search = TRUE; | |
3524 | |
3525 g_return_val_if_fail(imhtml != NULL, FALSE); | |
3526 g_return_val_if_fail(text != NULL, FALSE); | |
8061 | 3527 |
7295 | 3528 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) |
3529 new_search = FALSE; | |
8061 | 3530 |
7295 | 3531 if (new_search) { |
3532 gtk_imhtml_search_clear(imhtml); | |
3533 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
3534 } else { | |
3535 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
8061 | 3536 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); |
7295 | 3537 } |
10574 | 3538 g_free(imhtml->search_string); |
7295 | 3539 imhtml->search_string = g_strdup(text); |
3540 | |
7358 | 3541 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
3542 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
7295 | 3543 &start, &end, NULL)) { |
3544 | |
3545 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
3546 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
3547 if (new_search) { | |
3548 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
8061 | 3549 do |
7295 | 3550 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); |
8061 | 3551 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
3552 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
7358 | 3553 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
7295 | 3554 &start, &end, NULL)); |
3555 } | |
3556 return TRUE; | |
3557 } | |
8061 | 3558 |
3559 gtk_imhtml_search_clear(imhtml); | |
3560 | |
7295 | 3561 return FALSE; |
3562 } | |
3563 | |
3564 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
3565 { | |
3566 GtkTextIter start, end; | |
8061 | 3567 |
7295 | 3568 g_return_if_fail(imhtml != NULL); |
8061 | 3569 |
7295 | 3570 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
3571 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
3572 | |
3573 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
3574 if (imhtml->search_string) | |
3575 g_free(imhtml->search_string); | |
3576 imhtml->search_string = NULL; | |
3577 } | |
8061 | 3578 |
8677 | 3579 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color) |
3580 { | |
3581 gchar str[18]; | |
3582 GtkTextTag *tag; | |
3583 | |
3584 g_snprintf(str, sizeof(str), "FORECOLOR %s", color); | |
3585 | |
3586 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
10858 | 3587 if (!tag) { |
3588 GdkColor gcolor; | |
3589 if (!gdk_color_parse(color, &gcolor)) { | |
3590 gchar tmp[8]; | |
3591 tmp[0] = '#'; | |
3592 strncpy(&tmp[1], color, 7); | |
3593 tmp[7] = '\0'; | |
3594 if (!gdk_color_parse(tmp, &gcolor)) | |
3595 gdk_color_parse("black", &gcolor); | |
3596 } | |
3597 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", &gcolor, NULL); | |
3598 } | |
8677 | 3599 |
3600 return tag; | |
3601 } | |
3602 | |
3603 static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color) | |
3604 { | |
3605 gchar str[18]; | |
3606 GtkTextTag *tag; | |
3607 | |
3608 g_snprintf(str, sizeof(str), "BACKCOLOR %s", color); | |
3609 | |
3610 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
10858 | 3611 if (!tag) { |
3612 GdkColor gcolor; | |
3613 if (!gdk_color_parse(color, &gcolor)) { | |
3614 gchar tmp[8]; | |
3615 tmp[0] = '#'; | |
3616 strncpy(&tmp[1], color, 7); | |
3617 tmp[7] = '\0'; | |
3618 if (!gdk_color_parse(tmp, &gcolor)) | |
3619 gdk_color_parse("white", &gcolor); | |
3620 } | |
3621 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background-gdk", &gcolor, NULL); | |
3622 } | |
8677 | 3623 |
3624 return tag; | |
3625 } | |
3626 | |
10776 | 3627 static GtkTextTag *find_font_background_tag(GtkIMHtml *imhtml, gchar *color) |
3628 { | |
3629 gchar str[19]; | |
3630 GtkTextTag *tag; | |
3631 | |
3632 g_snprintf(str, sizeof(str), "BACKGROUND %s", color); | |
3633 | |
3634 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3635 if (!tag) | |
3636 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, NULL); | |
3637 | |
3638 return tag; | |
3639 } | |
3640 | |
8677 | 3641 static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face) |
8061 | 3642 { |
8677 | 3643 gchar str[256]; |
3644 GtkTextTag *tag; | |
3645 | |
3646 g_snprintf(str, sizeof(str), "FONT FACE %s", face); | |
3647 str[255] = '\0'; | |
3648 | |
3649 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3650 if (!tag) | |
3651 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL); | |
3652 | |
3653 return tag; | |
3654 } | |
3655 | |
3656 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) | |
3657 { | |
3658 gchar str[24]; | |
3659 GtkTextTag *tag; | |
3660 | |
3661 g_snprintf(str, sizeof(str), "FONT SIZE %d", size); | |
3662 str[23] = '\0'; | |
3663 | |
3664 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3665 if (!tag) { | |
10525
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3666 /* For reasons I don't understand, setting "scale" here scaled |
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3667 * based on some default size other than my theme's default |
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3668 * size. Our size 4 was actually smaller than our size 3 for |
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3669 * me. So this works around that oddity. |
8677 | 3670 */ |
10525
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3671 GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); |
8677 | 3672 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", |
10525
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3673 (gint) (pango_font_description_get_size(attr->font) * |
10899 | 3674 (double) POINT_SIZE(size)), NULL); |
10525
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3675 gtk_text_attributes_unref(attr); |
8061 | 3676 } |
3677 | |
8677 | 3678 return tag; |
3679 } | |
3680 | |
3681 static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e, | |
3682 const char *prefix, guint len, gboolean homo) | |
3683 { | |
3684 GSList *tags, *l; | |
3685 GtkTextIter iter; | |
3686 | |
3687 tags = gtk_text_iter_get_tags(i); | |
3688 | |
3689 for (l = tags; l; l = l->next) { | |
3690 GtkTextTag *tag = l->data; | |
3691 | |
3692 if (tag->name && !strncmp(tag->name, prefix, len)) | |
3693 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e); | |
8061 | 3694 } |
3695 | |
8677 | 3696 g_slist_free(tags); |
3697 | |
3698 if (homo) | |
3699 return; | |
3700 | |
3701 iter = *i; | |
3702 | |
3703 while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) { | |
3704 if (gtk_text_iter_begins_tag(&iter, NULL)) { | |
3705 tags = gtk_text_iter_get_toggled_tags(&iter, TRUE); | |
3706 | |
3707 for (l = tags; l; l = l->next) { | |
3708 GtkTextTag *tag = l->data; | |
3709 | |
3710 if (tag->name && !strncmp(tag->name, prefix, len)) | |
3711 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e); | |
3712 } | |
3713 | |
3714 g_slist_free(tags); | |
3715 } | |
8061 | 3716 } |
8677 | 3717 } |
3718 | |
3719 static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3720 { | |
3721 remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo); | |
3722 } | |
3723 | |
3724 static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3725 { | |
3726 remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo); | |
3727 } | |
3728 | |
3729 static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3730 { | |
3731 remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo); | |
3732 } | |
3733 | |
3734 static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3735 { | |
3736 remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo); | |
3737 } | |
3738 | |
10776 | 3739 static void remove_font_background(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
3740 { | |
3741 remove_tag_by_prefix(imhtml, i, e, "BACKGROUND ", 10, homo); | |
3742 } | |
3743 | |
8677 | 3744 static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
3745 { | |
3746 remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo); | |
3747 } | |
3748 | |
12672
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3749 static void |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3750 imhtml_clear_formatting(GtkIMHtml *imhtml) |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3751 { |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3752 GtkTextIter start, end; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3753 |
12796
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3754 if (!imhtml->editable) |
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3755 return; |
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3756 |
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3757 if (imhtml->wbfo) |
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3758 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3759 else |
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3760 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
e8db8f94a2db
[gaim-migrate @ 15143]
Richard Laager <rlaager@wiktel.com>
parents:
12673
diff
changeset
|
3761 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
12672
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3762 |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3763 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3764 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3765 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3766 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3767 remove_font_size(imhtml, &start, &end, TRUE); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3768 remove_font_face(imhtml, &start, &end, TRUE); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3769 remove_font_forecolor(imhtml, &start, &end, TRUE); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3770 remove_font_backcolor(imhtml, &start, &end, TRUE); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3771 remove_font_background(imhtml, &start, &end, TRUE); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3772 remove_font_link(imhtml, &start, &end, TRUE); |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3773 |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3774 imhtml->edit.bold = 0; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3775 imhtml->edit.italic = 0; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3776 imhtml->edit.underline = 0; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3777 imhtml->edit.strike = 0; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3778 imhtml->edit.fontsize = 0; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3779 imhtml->edit.forecolor = NULL; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3780 imhtml->edit.backcolor = NULL; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3781 imhtml->edit.background = NULL; |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3782 } |
4bd7e2ebb4cb
[gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents:
12635
diff
changeset
|
3783 |
8677 | 3784 /* Editable stuff */ |
3785 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
3786 { | |
3787 imhtml->insert_offset = gtk_text_iter_get_offset(iter); | |
3788 } | |
3789 | |
10169 | 3790 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data) |
3791 { | |
3792 GtkTextIter start; | |
3793 | |
3794 start = *arg1; | |
3795 gtk_text_iter_backward_char(&start); | |
3796 | |
3797 gtk_imhtml_apply_tags_on_insert(user_data, &start, arg1); | |
3798 } | |
3799 | |
8677 | 3800 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml) |
3801 { | |
3802 GtkTextIter start; | |
3803 | |
3804 if (!len) | |
3805 return; | |
3806 | |
3807 start = *end; | |
3808 gtk_text_iter_set_offset(&start, imhtml->insert_offset); | |
3809 | |
10169 | 3810 gtk_imhtml_apply_tags_on_insert(imhtml, &start, end); |
3811 } | |
3812 | |
12673
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3813 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, GtkIMHtml *imhtml) |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3814 { |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3815 GSList *tags, *l; |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3816 |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3817 tags = gtk_text_iter_get_tags(start); |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3818 for (l = tags; l != NULL; l = l->next) { |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3819 GtkTextTag *tag = GTK_TEXT_TAG(l->data); |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3820 |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3821 if (tag && /* Remove the formatting only if */ |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3822 gtk_text_iter_starts_word(start) && /* beginning of a word */ |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3823 gtk_text_iter_begins_tag(start, tag) && /* the tag starts with the selection */ |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3824 (!gtk_text_iter_has_tag(end, tag) || /* the tag ends within the selection */ |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3825 gtk_text_iter_ends_tag(end, tag))) { |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3826 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, start, end); |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3827 if (tag->name && |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3828 strncmp(tag->name, "LINK ", 5) == 0 && imhtml->edit.link) { |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3829 gtk_imhtml_toggle_link(imhtml, NULL); |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3830 } |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3831 } |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3832 } |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3833 g_slist_free(tags); |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3834 } |
de93d4988ad4
[gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents:
12672
diff
changeset
|
3835 |
10169 | 3836 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
3837 { | |
8677 | 3838 if (imhtml->edit.bold) |
10169 | 3839 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
8677 | 3840 else |
10169 | 3841 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
8677 | 3842 |
3843 if (imhtml->edit.italic) | |
10169 | 3844 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
8677 | 3845 else |
10169 | 3846 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
8677 | 3847 |
3848 if (imhtml->edit.underline) | |
10169 | 3849 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
8677 | 3850 else |
10169 | 3851 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
8677 | 3852 |
9924 | 3853 if (imhtml->edit.strike) |
10169 | 3854 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
9924 | 3855 else |
10169 | 3856 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
9924 | 3857 |
8677 | 3858 if (imhtml->edit.forecolor) { |
10169 | 3859 remove_font_forecolor(imhtml, start, end, TRUE); |
8677 | 3860 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3861 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
10169 | 3862 start, end); |
8061 | 3863 } |
3864 | |
8677 | 3865 if (imhtml->edit.backcolor) { |
10169 | 3866 remove_font_backcolor(imhtml, start, end, TRUE); |
8677 | 3867 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3868 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), | |
10169 | 3869 start, end); |
8677 | 3870 } |
3871 | |
10776 | 3872 if (imhtml->edit.background) { |
3873 remove_font_background(imhtml, start, end, TRUE); | |
3874 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3875 find_font_background_tag(imhtml, imhtml->edit.background), | |
3876 start, end); | |
3877 } | |
8677 | 3878 if (imhtml->edit.fontface) { |
10169 | 3879 remove_font_face(imhtml, start, end, TRUE); |
8677 | 3880 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3881 find_font_face_tag(imhtml, imhtml->edit.fontface), | |
10169 | 3882 start, end); |
8061 | 3883 } |
8677 | 3884 |
3885 if (imhtml->edit.fontsize) { | |
10169 | 3886 remove_font_size(imhtml, start, end, TRUE); |
8677 | 3887 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3888 find_font_size_tag(imhtml, imhtml->edit.fontsize), | |
10169 | 3889 start, end); |
8677 | 3890 } |
3891 | |
3892 if (imhtml->edit.link) { | |
10169 | 3893 remove_font_link(imhtml, start, end, TRUE); |
8677 | 3894 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3895 imhtml->edit.link, | |
10169 | 3896 start, end); |
8677 | 3897 } |
8061 | 3898 } |
3899 | |
3900 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
3901 { | |
3902 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
8177 | 3903 /* |
3904 * We need a visible caret for accessibility, so mouseless | |
3905 * people can highlight stuff. | |
3906 */ | |
3907 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ | |
8061 | 3908 imhtml->editable = editable; |
8677 | 3909 imhtml->format_functions = GTK_IMHTML_ALL; |
3910 | |
3911 if (editable) | |
3912 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
3913 G_CALLBACK(mark_set_cb), imhtml); | |
3914 } | |
3915 | |
3916 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo) | |
3917 { | |
3918 g_return_if_fail(imhtml != NULL); | |
3919 | |
3920 imhtml->wbfo = wbfo; | |
8420 | 3921 } |
3922 | |
3923 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | |
3924 { | |
3925 GObject *object = g_object_ref(G_OBJECT(imhtml)); | |
8677 | 3926 imhtml->format_functions = buttons; |
8420 | 3927 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
3928 g_object_unref(object); | |
8061 | 3929 } |
3930 | |
8788 | 3931 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml) |
3932 { | |
3933 return imhtml->format_functions; | |
3934 } | |
8516 | 3935 |
3936 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
3937 gboolean *italic, gboolean *underline) | |
8481 | 3938 { |
8677 | 3939 if (imhtml->edit.bold) |
3940 (*bold) = TRUE; | |
3941 if (imhtml->edit.italic) | |
3942 (*italic) = TRUE; | |
3943 if (imhtml->edit.underline) | |
3944 (*underline) = TRUE; | |
8481 | 3945 } |
3946 | |
9025 | 3947 char * |
3948 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml) | |
3949 { | |
3950 if (imhtml->edit.fontface) | |
3951 return g_strdup(imhtml->edit.fontface); | |
3952 else | |
3953 return NULL; | |
3954 } | |
3955 | |
3956 char * | |
3957 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml) | |
3958 { | |
3959 if (imhtml->edit.forecolor) | |
3960 return g_strdup(imhtml->edit.forecolor); | |
3961 else | |
3962 return NULL; | |
3963 } | |
3964 | |
3965 char * | |
3966 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml) | |
3967 { | |
3968 if (imhtml->edit.backcolor) | |
3969 return g_strdup(imhtml->edit.backcolor); | |
3970 else | |
3971 return NULL; | |
3972 } | |
3973 | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3974 char * |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3975 gtk_imhtml_get_current_background(GtkIMHtml *imhtml) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3976 { |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3977 if (imhtml->edit.background) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3978 return g_strdup(imhtml->edit.background); |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3979 else |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3980 return NULL; |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3981 } |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
3982 |
9025 | 3983 gint |
3984 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml) | |
3985 { | |
3986 return imhtml->edit.fontsize; | |
3987 } | |
3988 | |
8061 | 3989 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) |
3990 { | |
3991 return imhtml->editable; | |
3992 } | |
3993 | |
11269
1cbe76d30e81
[gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents:
11267
diff
changeset
|
3994 void |
1cbe76d30e81
[gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents:
11267
diff
changeset
|
3995 gtk_imhtml_clear_formatting(GtkIMHtml *imhtml) |
1cbe76d30e81
[gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents:
11267
diff
changeset
|
3996 { |
11275
ffc86d9ad8b7
[gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents:
11269
diff
changeset
|
3997 GObject *object; |
ffc86d9ad8b7
[gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents:
11269
diff
changeset
|
3998 |
ffc86d9ad8b7
[gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents:
11269
diff
changeset
|
3999 object = g_object_ref(G_OBJECT(imhtml)); |
ffc86d9ad8b7
[gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents:
11269
diff
changeset
|
4000 g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4001 |
11269
1cbe76d30e81
[gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents:
11267
diff
changeset
|
4002 gtk_widget_grab_focus(GTK_WIDGET(imhtml)); |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4003 |
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4004 g_object_unref(object); |
11269
1cbe76d30e81
[gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents:
11267
diff
changeset
|
4005 } |
1cbe76d30e81
[gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents:
11267
diff
changeset
|
4006 |
8677 | 4007 /* |
4008 * I had this crazy idea about changing the text cursor color to reflex the foreground color | |
4009 * of the text about to be entered. This is the place you'd do it, along with the place where | |
4010 * we actually set a new foreground color. | |
4011 * I may not do this, because people will bitch about Gaim overriding their gtk theme's cursor | |
4012 * colors. | |
4013 * | |
4014 * Just in case I do do this, I asked about what to set the secondary text cursor to. | |
4015 * | |
8719 | 4016 * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2 |
4017 * (12:45:55) ?? ???: understand? | |
8677 | 4018 * (12:46:14) Tim: yeah. i didn't know there was an exact formula |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8729
diff
changeset
|
4019 * (12:46:56) ?? ???: u might need to extract separate each color from RGB |
8677 | 4020 */ |
4021 | |
4022 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, | |
4023 GtkIMHtml *imhtml) | |
4024 { | |
4025 GSList *tags, *l; | |
4026 GtkTextIter iter; | |
4027 | |
4028 if (mark != gtk_text_buffer_get_insert(buffer)) | |
4029 return; | |
4030 | |
4031 if (!gtk_text_buffer_get_char_count(buffer)) | |
4032 return; | |
4033 | |
9924 | 4034 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE; |
8677 | 4035 if (imhtml->edit.forecolor) |
4036 g_free(imhtml->edit.forecolor); | |
4037 imhtml->edit.forecolor = NULL; | |
4038 if (imhtml->edit.backcolor) | |
4039 g_free(imhtml->edit.backcolor); | |
4040 imhtml->edit.backcolor = NULL; | |
4041 if (imhtml->edit.fontface) | |
4042 g_free(imhtml->edit.fontface); | |
4043 imhtml->edit.fontface = NULL; | |
4044 imhtml->edit.fontsize = 0; | |
4045 imhtml->edit.link = NULL; | |
4046 | |
4047 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
4048 | |
4049 | |
4050 if (gtk_text_iter_is_end(&iter)) | |
4051 tags = gtk_text_iter_get_toggled_tags(&iter, FALSE); | |
4052 else | |
4053 tags = gtk_text_iter_get_tags(&iter); | |
4054 | |
4055 for (l = tags; l != NULL; l = l->next) { | |
4056 GtkTextTag *tag = GTK_TEXT_TAG(l->data); | |
4057 | |
4058 if (tag->name) { | |
4059 if (strcmp(tag->name, "BOLD") == 0) | |
4060 imhtml->edit.bold = TRUE; | |
4061 if (strcmp(tag->name, "ITALICS") == 0) | |
4062 imhtml->edit.italic = TRUE; | |
4063 if (strcmp(tag->name, "UNDERLINE") == 0) | |
4064 imhtml->edit.underline = TRUE; | |
9924 | 4065 if (strcmp(tag->name, "STRIKE") == 0) |
4066 imhtml->edit.strike = TRUE; | |
8677 | 4067 if (strncmp(tag->name, "FORECOLOR ", 10) == 0) |
4068 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); | |
4069 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) | |
4070 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); | |
4071 if (strncmp(tag->name, "FONT FACE ", 10) == 0) | |
4072 imhtml->edit.fontface = g_strdup(&(tag->name)[10]); | |
4073 if (strncmp(tag->name, "FONT SIZE ", 10) == 0) | |
4074 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10); | |
8719 | 4075 if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter)) |
8677 | 4076 imhtml->edit.link = tag; |
4077 } | |
4078 } | |
4079 | |
4080 g_slist_free(tags); | |
4081 } | |
4082 | |
12605
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4083 static void imhtml_emit_signal_for_format(GtkIMHtml *imhtml, GtkIMHtmlButtons button) |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4084 { |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4085 GObject *object; |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4086 |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4087 g_return_if_fail(imhtml != NULL); |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4088 |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4089 object = g_object_ref(G_OBJECT(imhtml)); |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4090 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4091 g_object_unref(object); |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4092 } |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4093 |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4094 static void imhtml_toggle_bold(GtkIMHtml *imhtml) |
8061 | 4095 { |
8677 | 4096 GtkTextIter start, end; |
4097 | |
4098 imhtml->edit.bold = !imhtml->edit.bold; | |
4099 | |
4100 if (imhtml->wbfo) { | |
4101 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4102 if (imhtml->edit.bold) | |
4103 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
4104 else | |
4105 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4106 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
8677 | 4107 if (imhtml->edit.bold) |
4108 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
4109 else | |
4110 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4111 |
8061 | 4112 } |
4113 } | |
4114 | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4115 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
8061 | 4116 { |
12605
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4117 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_BOLD); |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4118 } |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4119 |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4120 static void imhtml_toggle_italic(GtkIMHtml *imhtml) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4121 { |
8677 | 4122 GtkTextIter start, end; |
4123 | |
4124 imhtml->edit.italic = !imhtml->edit.italic; | |
4125 | |
4126 if (imhtml->wbfo) { | |
4127 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4128 if (imhtml->edit.italic) | |
4129 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
4130 else | |
4131 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4132 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4133 if (imhtml->edit.italic) |
8677 | 4134 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
4135 else | |
4136 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
8061 | 4137 } |
4138 } | |
4139 | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4140 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) |
8061 | 4141 { |
12605
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4142 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_ITALIC); |
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4143 } |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4144 |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4145 static void imhtml_toggle_underline(GtkIMHtml *imhtml) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4146 { |
8677 | 4147 GtkTextIter start, end; |
4148 | |
4149 imhtml->edit.underline = !imhtml->edit.underline; | |
4150 | |
4151 if (imhtml->wbfo) { | |
4152 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4153 if (imhtml->edit.underline) | |
4154 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
4155 else | |
4156 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4157 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4158 if (imhtml->edit.underline) |
8677 | 4159 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4160 else | |
4161 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
8061 | 4162 } |
4163 } | |
4164 | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4165 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) |
9924 | 4166 { |
12605
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4167 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_UNDERLINE); |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4168 } |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4169 |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4170 static void imhtml_toggle_strike(GtkIMHtml *imhtml) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4171 { |
9924 | 4172 GtkTextIter start, end; |
4173 | |
4174 imhtml->edit.strike = !imhtml->edit.strike; | |
4175 | |
4176 if (imhtml->wbfo) { | |
4177 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4178 if (imhtml->edit.strike) | |
4179 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
4180 else | |
4181 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4182 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4183 if (imhtml->edit.strike) |
9924 | 4184 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4185 else | |
4186 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
4187 } | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4188 } |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4189 |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4190 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4191 { |
12605
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4192 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_STRIKE); |
9924 | 4193 } |
4194 | |
8061 | 4195 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) |
4196 { | |
9025 | 4197 GObject *object; |
8677 | 4198 GtkTextIter start, end; |
8061 | 4199 |
4200 imhtml->edit.fontsize = size; | |
4201 | |
8677 | 4202 if (imhtml->wbfo) { |
4203 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4204 remove_font_size(imhtml, &start, &end, TRUE); | |
4205 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
4206 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4207 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
8677 | 4208 remove_font_size(imhtml, &start, &end, FALSE); |
4209 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
4210 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
8061 | 4211 } |
8677 | 4212 |
9025 | 4213 object = g_object_ref(G_OBJECT(imhtml)); |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4214 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK | GTK_IMHTML_GROW); |
9025 | 4215 g_object_unref(object); |
8061 | 4216 } |
4217 | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4218 static void imhtml_font_shrink(GtkIMHtml *imhtml) |
8061 | 4219 { |
8677 | 4220 GtkTextIter start, end; |
4221 | |
8061 | 4222 if (imhtml->edit.fontsize == 1) |
4223 return; | |
4224 | |
8677 | 4225 if (!imhtml->edit.fontsize) |
4226 imhtml->edit.fontsize = 2; | |
4227 else | |
4228 imhtml->edit.fontsize--; | |
4229 | |
4230 if (imhtml->wbfo) { | |
4231 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4232 remove_font_size(imhtml, &start, &end, TRUE); | |
4233 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
4234 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4235 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
8677 | 4236 remove_font_size(imhtml, &start, &end, FALSE); |
4237 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
4238 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
8061 | 4239 } |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4240 } |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4241 |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4242 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4243 { |
12605
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4244 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_SHRINK); |
8061 | 4245 } |
4246 | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4247 static void imhtml_font_grow(GtkIMHtml *imhtml) |
8061 | 4248 { |
8677 | 4249 GtkTextIter start, end; |
4250 | |
8061 | 4251 if (imhtml->edit.fontsize == MAX_FONT_SIZE) |
4252 return; | |
4253 | |
8677 | 4254 if (!imhtml->edit.fontsize) |
4255 imhtml->edit.fontsize = 4; | |
4256 else | |
4257 imhtml->edit.fontsize++; | |
4258 | |
4259 if (imhtml->wbfo) { | |
4260 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4261 remove_font_size(imhtml, &start, &end, TRUE); | |
4262 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
4263 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4264 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
8677 | 4265 remove_font_size(imhtml, &start, &end, FALSE); |
4266 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
4267 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
8061 | 4268 } |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4269 } |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4270 |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4271 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) |
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4272 { |
12605
cd1d0131e07f
[gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
4273 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_GROW); |
8061 | 4274 } |
4275 | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4276 #define gtk_imhtml_toggle_str_tag(imhtml, color, edit_field, remove_func, find_func, button) { \ |
10776 | 4277 GObject *object; \ |
4278 GtkTextIter start, end; \ | |
4279 \ | |
4280 g_free(edit_field); \ | |
4281 edit_field = NULL; \ | |
4282 \ | |
4283 if (color && strcmp(color, "") != 0) { \ | |
4284 edit_field = g_strdup(color); \ | |
4285 \ | |
4286 if (imhtml->wbfo) { \ | |
4287 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \ | |
4288 remove_func(imhtml, &start, &end, TRUE); \ | |
4289 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ | |
4290 find_func(imhtml, edit_field), &start, &end); \ | |
4291 } else { \ | |
4292 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \ | |
4293 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \ | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4294 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { \ |
10776 | 4295 remove_func(imhtml, &start, &end, FALSE); \ |
4296 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ | |
4297 find_func(imhtml, \ | |
4298 edit_field), \ | |
4299 &start, &end); \ | |
4300 } \ | |
4301 } \ | |
4302 } else { \ | |
4303 if (imhtml->wbfo) { \ | |
4304 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \ | |
4305 remove_func(imhtml, &start, &end, TRUE); \ | |
11968 | 4306 } else { \ |
4307 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) \ | |
4308 remove_func(imhtml, &start, &end, TRUE); \ | |
10776 | 4309 } \ |
4310 } \ | |
4311 \ | |
4312 object = g_object_ref(G_OBJECT(imhtml)); \ | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4313 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); \ |
10776 | 4314 g_object_unref(object); \ |
4315 \ | |
4316 return edit_field != NULL; \ | |
4317 } | |
4318 | |
8061 | 4319 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) |
4320 { | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4321 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.forecolor, remove_font_forecolor, find_font_forecolor_tag, GTK_IMHTML_FORECOLOR); |
8061 | 4322 } |
4323 | |
4324 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
4325 { | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4326 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.backcolor, remove_font_backcolor, find_font_backcolor_tag, GTK_IMHTML_BACKCOLOR); |
10776 | 4327 } |
4328 | |
4329 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color) | |
4330 { | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4331 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.background, remove_font_background, find_font_background_tag, GTK_IMHTML_BACKGROUND); |
8061 | 4332 } |
4333 | |
4334 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) | |
4335 { | |
11267
477e5cca8287
[gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents:
11240
diff
changeset
|
4336 gtk_imhtml_toggle_str_tag(imhtml, face, imhtml->edit.fontface, remove_font_face, find_font_face_tag, GTK_IMHTML_FACE); |
8061 | 4337 } |
4338 | |
8677 | 4339 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url) |
8061 | 4340 { |
9025 | 4341 GObject *object; |
8677 | 4342 GtkTextIter start, end; |
4343 GtkTextTag *linktag; | |
4344 static guint linkno = 0; | |
4345 gchar str[48]; | |
9007 | 4346 GdkColor *color = NULL; |
8677 | 4347 |
4348 imhtml->edit.link = NULL; | |
4349 | |
4350 if (url) { | |
4351 g_snprintf(str, sizeof(str), "LINK %d", linkno++); | |
4352 str[47] = '\0'; | |
4353 | |
9007 | 4354 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &color, NULL); |
9008 | 4355 if (color) { |
9007 | 4356 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", color, "underline", PANGO_UNDERLINE_SINGLE, NULL); |
9008 | 4357 gdk_color_free(color); |
4358 } else { | |
9007 | 4359 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
9008 | 4360 } |
8677 | 4361 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); |
4362 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); | |
4363 | |
11276
17ebda61c6ce
[gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents:
11275
diff
changeset
|
4364 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
8677 | 4365 remove_font_link(imhtml, &start, &end, FALSE); |
4366 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); | |
4367 } | |
4368 } | |
9025 | 4369 |
4370 object = g_object_ref(G_OBJECT(imhtml)); | |
4371 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK); | |
4372 g_object_unref(object); | |
8677 | 4373 } |
4374 | |
4375 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text) | |
4376 { | |
8061 | 4377 GtkTextIter iter; |
8677 | 4378 |
9599 | 4379 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
4380 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
4381 | |
8677 | 4382 gtk_imhtml_toggle_link(imhtml, url); |
8061 | 4383 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); |
8677 | 4384 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1); |
4385 gtk_imhtml_toggle_link(imhtml, NULL); | |
8061 | 4386 } |
4387 | |
4388 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) | |
4389 { | |
8677 | 4390 GtkTextMark *mark; |
8061 | 4391 GtkTextIter iter; |
8677 | 4392 |
11750 | 4393 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
4394 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
4395 | |
8677 | 4396 mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
4397 | |
4398 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
4399 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter); | |
4400 } | |
4401 | |
4402 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) | |
4403 { | |
8061 | 4404 GdkPixbuf *pixbuf = NULL; |
4405 GdkPixbufAnimation *annipixbuf = NULL; | |
4406 GtkWidget *icon = NULL; | |
4407 GtkTextChildAnchor *anchor; | |
8505 | 4408 char *unescaped = gaim_unescape_html(smiley); |
11525 | 4409 GtkIMHtmlSmiley *imhtml_smiley = gtk_imhtml_smiley_get(imhtml, sml, unescaped); |
8061 | 4410 |
10526 | 4411 if (imhtml->format_functions & GTK_IMHTML_SMILEY) { |
10522 | 4412 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); |
10526 | 4413 if (annipixbuf) { |
4414 if (gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
10522 | 4415 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); |
10526 | 4416 if (pixbuf) |
10522 | 4417 icon = gtk_image_new_from_pixbuf(pixbuf); |
4418 } else { | |
4419 icon = gtk_image_new_from_animation(annipixbuf); | |
4420 } | |
8061 | 4421 } |
4422 } | |
4423 | |
4424 if (icon) { | |
8890 | 4425 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
4426 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free); | |
4427 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); | |
4428 | |
8061 | 4429 gtk_widget_show(icon); |
4430 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
11525 | 4431 } else if (imhtml_smiley != NULL && (imhtml->format_functions & GTK_IMHTML_SMILEY)) { |
4432 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
4433 imhtml_smiley->anchors = g_slist_append(imhtml_smiley->anchors, anchor); | |
8890 | 4434 } else { |
4435 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1); | |
8061 | 4436 } |
8890 | 4437 |
4438 g_free(unescaped); | |
8061 | 4439 } |
4440 | |
8962 | 4441 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter) |
4442 { | |
4443 GdkPixbuf *pixbuf = NULL; | |
4444 const char *filename = NULL; | |
4445 gpointer image; | |
4446 GdkRectangle rect; | |
4447 GtkIMHtmlScalable *scalable = NULL; | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
4448 struct scalable_data *sd; |
8962 | 4449 int minus; |
4450 | |
4451 if (!imhtml->funcs || !imhtml->funcs->image_get || | |
4452 !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data || | |
4453 !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref || | |
4454 !imhtml->funcs->image_unref) | |
4455 return; | |
4456 | |
4457 image = imhtml->funcs->image_get(id); | |
4458 | |
4459 if (image) { | |
4460 gpointer data; | |
4461 size_t len; | |
4462 | |
4463 data = imhtml->funcs->image_get_data(image); | |
4464 len = imhtml->funcs->image_get_size(image); | |
4465 | |
4466 if (data && len) { | |
4467 GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); | |
4468 gdk_pixbuf_loader_write(loader, data, len, NULL); | |
12230
423323aa0dbe
[gaim-migrate @ 14532]
Richard Laager <rlaager@wiktel.com>
parents:
12229
diff
changeset
|
4469 gdk_pixbuf_loader_close(loader, NULL); |
8962 | 4470 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); |
9337 | 4471 if (pixbuf) |
4472 g_object_ref(G_OBJECT(pixbuf)); | |
4473 g_object_unref(G_OBJECT(loader)); | |
8962 | 4474 } |
4475 | |
4476 } | |
4477 | |
4478 if (pixbuf) { | |
11299
421007f39e53
[gaim-migrate @ 13499]
Richard Laager <rlaager@wiktel.com>
parents:
11276
diff
changeset
|
4479 struct im_image_data *t = g_new(struct im_image_data, 1); |
8962 | 4480 filename = imhtml->funcs->image_get_filename(image); |
4481 imhtml->funcs->image_ref(id); | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
4482 t->id = id; |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
4483 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
4484 imhtml->im_images = g_slist_prepend(imhtml->im_images, t); |
8962 | 4485 } else { |
4486 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, | |
4487 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image"); | |
4488 } | |
4489 | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
4490 sd = g_new(struct scalable_data, 1); |
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
4491 sd->scalable = scalable = gtk_imhtml_image_new(pixbuf, filename, id); |
11233
f08d22130bb2
[gaim-migrate @ 13373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11224
diff
changeset
|
4492 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
8962 | 4493 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
4494 scalable->add_to(scalable, imhtml, iter); | |
4495 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + | |
4496 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
4497 scalable->scale(scalable, rect.width - minus, rect.height); | |
11224
409d6a11da51
[gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11143
diff
changeset
|
4498 imhtml->scalables = g_list_append(imhtml->scalables, sd); |
8962 | 4499 |
4500 g_object_unref(G_OBJECT(pixbuf)); | |
4501 } | |
4502 | |
8677 | 4503 static const gchar *tag_to_html_start(GtkTextTag *tag) |
8061 | 4504 { |
8677 | 4505 const gchar *name; |
4506 static gchar buf[1024]; | |
4507 | |
4508 name = tag->name; | |
4509 g_return_val_if_fail(name != NULL, ""); | |
4510 | |
4511 if (strcmp(name, "BOLD") == 0) { | |
4512 return "<b>"; | |
4513 } else if (strcmp(name, "ITALICS") == 0) { | |
4514 return "<i>"; | |
4515 } else if (strcmp(name, "UNDERLINE") == 0) { | |
4516 return "<u>"; | |
9924 | 4517 } else if (strcmp(name, "STRIKE") == 0) { |
4518 return "<s>"; | |
8677 | 4519 } else if (strncmp(name, "LINK ", 5) == 0) { |
4520 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); | |
4521 if (tmp) { | |
4522 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); | |
4523 buf[sizeof(buf)-1] = '\0'; | |
4524 return buf; | |
4525 } else { | |
4526 return ""; | |
4527 } | |
4528 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
4529 g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]); | |
4530 return buf; | |
4531 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
4532 g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]); | |
4533 return buf; | |
10776 | 4534 } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
4535 g_snprintf(buf, sizeof(buf), "<body bgcolor=\"%s\">", &name[11]); | |
4536 return buf; | |
8677 | 4537 } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
4538 g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]); | |
4539 return buf; | |
4540 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
4541 g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]); | |
4542 return buf; | |
4543 } else { | |
4544 return ""; | |
4545 } | |
8061 | 4546 } |
4547 | |
8677 | 4548 static const gchar *tag_to_html_end(GtkTextTag *tag) |
8061 | 4549 { |
8677 | 4550 const gchar *name; |
4551 | |
4552 name = tag->name; | |
4553 g_return_val_if_fail(name != NULL, ""); | |
4554 | |
4555 if (strcmp(name, "BOLD") == 0) { | |
4556 return "</b>"; | |
4557 } else if (strcmp(name, "ITALICS") == 0) { | |
4558 return "</i>"; | |
4559 } else if (strcmp(name, "UNDERLINE") == 0) { | |
4560 return "</u>"; | |
9924 | 4561 } else if (strcmp(name, "STRIKE") == 0) { |
4562 return "</s>"; | |
8677 | 4563 } else if (strncmp(name, "LINK ", 5) == 0) { |
4564 return "</a>"; | |
4565 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
4566 return "</font>"; | |
4567 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
4568 return "</font>"; | |
10776 | 4569 } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
4570 return "</body>"; | |
8677 | 4571 } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
4572 return "</font>"; | |
4573 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
4574 return "</font>"; | |
4575 } else { | |
4576 return ""; | |
4577 } | |
4578 } | |
4579 | |
4580 static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter) | |
4581 { | |
4582 return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) && | |
4583 !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) || | |
4584 gtk_text_iter_is_end(niter)); | |
8061 | 4585 } |
4586 | |
4587 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
4588 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
8677 | 4589 * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert |
4590 * the actual text. Then check for tags that are toggled off and insert them, after checking the queue. | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8729
diff
changeset
|
4591 * Finally, replace <, >, &, and " with their HTML equivalent. |
8677 | 4592 */ |
8061 | 4593 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
4594 { | |
4595 gunichar c; | |
8677 | 4596 GtkTextIter iter, nextiter; |
8061 | 4597 GString *str = g_string_new(""); |
8677 | 4598 GSList *tags, *sl; |
4599 GQueue *q, *r; | |
4600 GtkTextTag *tag; | |
4601 | |
4602 q = g_queue_new(); | |
4603 r = g_queue_new(); | |
4604 | |
8061 | 4605 |
4606 gtk_text_iter_order(start, end); | |
8677 | 4607 nextiter = iter = *start; |
4608 gtk_text_iter_forward_char(&nextiter); | |
4609 | |
9071 | 4610 /* First add the tags that are already in progress (we don't care about non-printing tags)*/ |
8677 | 4611 tags = gtk_text_iter_get_tags(start); |
4612 | |
4613 for (sl = tags; sl; sl = sl->next) { | |
4614 tag = sl->data; | |
4615 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) { | |
9071 | 4616 if (strlen(tag_to_html_end(tag)) > 0) |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
4617 g_string_append(str, tag_to_html_start(tag)); |
8677 | 4618 g_queue_push_tail(q, tag); |
8061 | 4619 } |
4620 } | |
8677 | 4621 g_slist_free(tags); |
8061 | 4622 |
4623 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { | |
8677 | 4624 |
4625 tags = gtk_text_iter_get_tags(&iter); | |
4626 | |
4627 for (sl = tags; sl; sl = sl->next) { | |
4628 tag = sl->data; | |
4629 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) { | |
9071 | 4630 if (strlen(tag_to_html_end(tag)) > 0) |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
4631 g_string_append(str, tag_to_html_start(tag)); |
8677 | 4632 g_queue_push_tail(q, tag); |
4633 } | |
4634 } | |
4635 | |
4636 | |
8061 | 4637 if (c == 0xFFFC) { |
4638 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
9071 | 4639 if (anchor) { |
4640 char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext"); | |
4641 if (text) | |
4642 str = g_string_append(str, text); | |
4643 } | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
4644 } else if (c == '<') { |
8677 | 4645 str = g_string_append(str, "<"); |
4646 } else if (c == '>') { | |
4647 str = g_string_append(str, ">"); | |
4648 } else if (c == '&') { | |
4649 str = g_string_append(str, "&"); | |
4650 } else if (c == '"') { | |
4651 str = g_string_append(str, """); | |
4652 } else if (c == '\n') { | |
4653 str = g_string_append(str, "<br>"); | |
8061 | 4654 } else { |
8677 | 4655 str = g_string_append_unichar(str, c); |
4656 } | |
4657 | |
4658 tags = g_slist_reverse(tags); | |
4659 for (sl = tags; sl; sl = sl->next) { | |
4660 tag = sl->data; | |
9071 | 4661 /** don't worry about non-printing tags ending */ |
4662 if (tag_ends_here(tag, &iter, &nextiter) && strlen(tag_to_html_end(tag)) > 0) { | |
8677 | 4663 |
4664 GtkTextTag *tmp; | |
4665 | |
4666 while ((tmp = g_queue_pop_tail(q)) != tag) { | |
4667 if (tmp == NULL) | |
4668 break; | |
4669 | |
9071 | 4670 if (!tag_ends_here(tmp, &iter, &nextiter) && strlen(tag_to_html_end(tmp)) > 0) |
8677 | 4671 g_queue_push_tail(r, tmp); |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
4672 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp))); |
8677 | 4673 } |
4674 | |
4675 if (tmp == NULL) | |
4676 gaim_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n"); | |
11572
7be60d01519f
[gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11525
diff
changeset
|
4677 else |
8677 | 4678 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); |
4679 | |
4680 while ((tmp = g_queue_pop_head(r))) { | |
4681 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tmp))); | |
4682 g_queue_push_tail(q, tmp); | |
8061 | 4683 } |
4684 } | |
4685 } | |
8677 | 4686 |
4687 g_slist_free(tags); | |
8061 | 4688 gtk_text_iter_forward_char(&iter); |
8677 | 4689 gtk_text_iter_forward_char(&nextiter); |
8061 | 4690 } |
8677 | 4691 |
4692 while ((tag = g_queue_pop_tail(q))) | |
4693 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
4694 | |
4695 g_queue_free(q); | |
4696 g_queue_free(r); | |
8061 | 4697 return g_string_free(str, FALSE); |
4698 } | |
4699 | |
8698 | 4700 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter) |
8061 | 4701 { |
4702 if (imhtml->edit.bold) | |
4703 gtk_imhtml_toggle_bold(imhtml); | |
4704 | |
4705 if (imhtml->edit.italic) | |
4706 gtk_imhtml_toggle_italic(imhtml); | |
4707 | |
4708 if (imhtml->edit.underline) | |
4709 gtk_imhtml_toggle_underline(imhtml); | |
4710 | |
9924 | 4711 if (imhtml->edit.strike) |
4712 gtk_imhtml_toggle_strike(imhtml); | |
4713 | |
8061 | 4714 if (imhtml->edit.forecolor) |
4715 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
4716 | |
4717 if (imhtml->edit.backcolor) | |
4718 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
4719 | |
4720 if (imhtml->edit.fontface) | |
4721 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
4722 | |
8677 | 4723 imhtml->edit.fontsize = 0; |
4724 | |
8719 | 4725 if (imhtml->edit.link) |
4726 gtk_imhtml_toggle_link(imhtml, NULL); | |
4727 | |
8698 | 4728 gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter); |
8061 | 4729 |
4730 } | |
4731 | |
4732 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
4733 { | |
4734 GtkTextIter start, end; | |
4735 | |
4736 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
4737 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
4738 return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
4739 } | |
4740 | |
8677 | 4741 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml) |
4742 { | |
4743 int i, j, lines; | |
4744 GtkTextIter start, end; | |
4745 char **ret; | |
4746 | |
4747 lines = gtk_text_buffer_get_line_count(imhtml->text_buffer); | |
4748 ret = g_new0(char *, lines + 1); | |
4749 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
4750 end = start; | |
4751 gtk_text_iter_forward_to_line_end(&end); | |
4752 | |
4753 for (i = 0, j = 0; i < lines; i++) { | |
9612 | 4754 if (gtk_text_iter_get_char(&start) != '\n') { |
4755 ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
4756 if (ret[j] != NULL) | |
4757 j++; | |
4758 } | |
4759 | |
8677 | 4760 gtk_text_iter_forward_line(&start); |
4761 end = start; | |
4762 gtk_text_iter_forward_to_line_end(&end); | |
4763 } | |
4764 | |
4765 return ret; | |
4766 } | |
4767 | |
4768 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop) | |
8061 | 4769 { |
8519 | 4770 GString *str = g_string_new(""); |
4771 GtkTextIter iter, end; | |
4772 gunichar c; | |
4773 | |
8677 | 4774 if (start == NULL) |
4775 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
4776 else | |
4777 iter = *start; | |
4778 | |
4779 if (stop == NULL) | |
4780 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
4781 else | |
4782 end = *stop; | |
4783 | |
4784 gtk_text_iter_order(&iter, &end); | |
8519 | 4785 |
4786 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) { | |
4787 if (c == 0xFFFC) { | |
8677 | 4788 GtkTextChildAnchor* anchor; |
4789 char *text = NULL; | |
4790 | |
4791 anchor = gtk_text_iter_get_child_anchor(&iter); | |
4792 if (anchor) | |
8698 | 4793 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); |
8677 | 4794 if (text) |
4795 str = g_string_append(str, text); | |
8519 | 4796 } else { |
4797 g_string_append_unichar(str, c); | |
4798 } | |
4799 gtk_text_iter_forward_char(&iter); | |
4800 } | |
4801 | |
4802 return g_string_free(str, FALSE); | |
8061 | 4803 } |
8962 | 4804 |
4805 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f) | |
4806 { | |
4807 g_return_if_fail(imhtml != NULL); | |
4808 imhtml->funcs = f; | |
4809 } |