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