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