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