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