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