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