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