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