Mercurial > pidgin
annotate src/gtkimhtml.c @ 8726:3ac178eedac2
[gaim-migrate @ 9481]
Tim tells me this fixes some horizontal scrollbar-age
committer: Tailor Script <tailor@pidgin.im>
| author | Ethan Blanton <elb@pidgin.im> |
|---|---|
| date | Tue, 20 Apr 2004 15:04:42 +0000 |
| parents | 513b8bbcc104 |
| children | 7024b9145357 |
| rev | line source |
|---|---|
| 1428 | 1 /* |
| 2 * GtkIMHtml | |
| 3 * | |
| 8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 1428 | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
| 23 | |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
25 #include <config.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
26 #endif |
| 8526 | 27 #include "debug.h" |
| 8091 | 28 #include "util.h" |
| 1428 | 29 #include "gtkimhtml.h" |
| 7358 | 30 #include "gtksourceiter.h" |
| 1428 | 31 #include <gtk/gtk.h> |
| 4895 | 32 #include <glib/gerror.h> |
| 4046 | 33 #include <gdk/gdkkeysyms.h> |
| 1428 | 34 #include <string.h> |
| 35 #include <ctype.h> | |
| 36 #include <stdio.h> | |
| 4629 | 37 #include <stdlib.h> |
| 1428 | 38 #include <math.h> |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
39 #ifdef HAVE_LANGINFO_CODESET |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
40 #include <langinfo.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
41 #include <locale.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
42 #endif |
| 8692 | 43 #ifdef _WIN32 |
| 44 #include <windows.h> | |
| 45 #endif | |
| 1428 | 46 |
| 4417 | 47 #ifdef ENABLE_NLS |
| 48 # include <libintl.h> | |
| 49 # define _(x) gettext(x) | |
| 50 # ifdef gettext_noop | |
| 51 # define N_(String) gettext_noop (String) | |
| 52 # else | |
| 53 # define N_(String) (String) | |
| 54 # endif | |
| 55 #else | |
| 56 # define N_(String) (String) | |
| 57 # define _(x) (x) | |
| 58 #endif | |
| 59 | |
| 4735 | 60 #include <pango/pango-font.h> |
| 61 | |
| 5105 | 62 /* GTK+ < 2.2.2 hack, see ui.h for details. */ |
| 63 #ifndef GTK_WRAP_WORD_CHAR | |
| 64 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD | |
| 65 #endif | |
| 66 | |
| 4735 | 67 #define TOOLTIP_TIMEOUT 500 |
| 68 | |
| 8677 | 69 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 8061 | 70 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 8505 | 71 static gboolean gtk_imhtml_is_amp_escape (const gchar *string, gchar **replace, gint *length); |
| 8698 | 72 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter); |
| 8091 | 73 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 | 74 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml); |
| 8061 | 75 |
| 3922 | 76 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
| 77 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
| 78 #define MAX_FONT_SIZE 7 | |
| 5367 | 79 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
| 8380 | 80 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
|
81 |
| 8498 | 82 enum { |
| 8677 | 83 TARGET_HTML, |
| 8061 | 84 TARGET_UTF8_STRING, |
| 85 TARGET_COMPOUND_TEXT, | |
| 86 TARGET_STRING, | |
| 87 TARGET_TEXT | |
| 88 }; | |
| 89 | |
| 8091 | 90 enum { |
| 91 DRAG_URL | |
| 92 }; | |
| 93 | |
| 8420 | 94 enum { |
| 95 URL_CLICKED, | |
| 96 BUTTONS_UPDATE, | |
| 97 TOGGLE_FORMAT, | |
| 8427 | 98 CLEAR_FORMAT, |
| 8506 | 99 UPDATE_FORMAT, |
| 8420 | 100 LAST_SIGNAL |
| 101 }; | |
| 102 static guint signals [LAST_SIGNAL] = { 0 }; | |
| 103 | |
| 8061 | 104 GtkTargetEntry selection_targets[] = { |
| 8566 | 105 { "text/html", 0, TARGET_HTML }, |
| 8061 | 106 { "UTF8_STRING", 0, TARGET_UTF8_STRING }, |
| 107 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | |
| 108 { "STRING", 0, TARGET_STRING }, | |
| 109 { "TEXT", 0, TARGET_TEXT}}; | |
| 110 | |
| 8091 | 111 GtkTargetEntry link_drag_drop_targets[] = { |
| 112 {"x-url/ftp", 0, DRAG_URL}, | |
| 113 {"x-url/http", 0, DRAG_URL}, | |
| 114 {"text/uri-list", 0, DRAG_URL}, | |
| 115 {"_NETSCAPE_URL", 0, DRAG_URL}}; | |
| 116 | |
| 8692 | 117 #ifdef _WIN32 |
| 118 /* Win32 clipboard format value, and functions to convert back and | |
| 119 * forth between HTML and the clipboard format. | |
| 120 */ | |
| 121 static UINT win_html_fmt; | |
| 122 | |
| 123 static gchar * | |
| 124 clipboard_win32_to_html(char *clipboard) { | |
| 8693 | 125 const char *begin, *end; |
| 8692 | 126 gchar *html; |
| 127 | |
| 8693 | 128 begin = strstr(clipboard, "<!--StartFragment"); |
| 129 while(*begin++ != '>'); | |
| 8692 | 130 end = strstr(clipboard, "<!--EndFragment"); |
| 131 html = g_strstrip(g_strndup(begin, (end ? (end - begin) : strlen(begin)))); | |
| 8707 | 132 return html; |
| 8692 | 133 } |
| 134 | |
| 135 static gchar * | |
| 136 clipboard_html_to_win32(char *html) { | |
| 8693 | 137 int length; |
| 8692 | 138 gchar *ret; |
| 139 GString *clipboard; | |
| 140 | |
| 8693 | 141 if (html == NULL) |
| 142 return NULL; | |
| 8692 | 143 |
| 144 length = strlen(html); | |
| 145 clipboard = g_string_new ("Version:0.9\r\n"); | |
| 146 g_string_append(clipboard, "StartHTML:0000000105\r\n"); | |
| 147 g_string_append(clipboard, g_strdup_printf("EndHTML:%010d\r\n", 143 + length)); | |
| 148 g_string_append(clipboard, "StartFragment:0000000105\r\n"); | |
| 149 g_string_append(clipboard, g_strdup_printf("EndFragment:%010d\r\n", 143 + length)); | |
| 150 g_string_append(clipboard, "<!--StartFragment-->"); | |
| 151 g_string_append(clipboard, html); | |
| 152 g_string_append(clipboard, "<!--EndFragment-->"); | |
| 153 ret = clipboard->str; | |
| 154 g_string_free(clipboard, FALSE); | |
| 155 return ret; | |
| 156 } | |
| 157 #endif | |
| 158 | |
| 4032 | 159 static GtkSmileyTree* |
| 160 gtk_smiley_tree_new () | |
| 161 { | |
| 162 return g_new0 (GtkSmileyTree, 1); | |
| 163 } | |
| 164 | |
| 165 static void | |
| 166 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
| 4263 | 167 GtkIMHtmlSmiley *smiley) |
| 4032 | 168 { |
| 169 GtkSmileyTree *t = tree; | |
| 4263 | 170 const gchar *x = smiley->smile; |
| 4032 | 171 |
| 172 if (!strlen (x)) | |
| 173 return; | |
| 174 | |
| 175 while (*x) { | |
| 176 gchar *pos; | |
| 177 gint index; | |
| 178 | |
| 179 if (!t->values) | |
| 180 t->values = g_string_new (""); | |
| 181 | |
| 182 pos = strchr (t->values->str, *x); | |
| 183 if (!pos) { | |
| 184 t->values = g_string_append_c (t->values, *x); | |
| 185 index = t->values->len - 1; | |
| 186 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
| 187 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
| 188 } else | |
| 7386 | 189 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
| 8061 | 190 |
| 4032 | 191 t = t->children [index]; |
| 8061 | 192 |
| 4032 | 193 x++; |
| 194 } | |
| 8061 | 195 |
| 4263 | 196 t->image = smiley; |
| 4032 | 197 } |
| 4041 | 198 |
| 4263 | 199 |
| 4264 | 200 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
| 4032 | 201 { |
| 202 GSList *list = g_slist_append (NULL, tree); | |
| 203 | |
| 204 while (list) { | |
| 205 GtkSmileyTree *t = list->data; | |
| 206 gint i; | |
| 207 list = g_slist_remove(list, t); | |
| 7384 | 208 if (t && t->values) { |
| 4032 | 209 for (i = 0; i < t->values->len; i++) |
| 210 list = g_slist_append (list, t->children [i]); | |
| 211 g_string_free (t->values, TRUE); | |
| 212 g_free (t->children); | |
| 213 } | |
| 214 g_free (t); | |
| 215 } | |
| 216 } | |
| 217 | |
| 5967 | 218 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
| 219 { | |
| 220 GdkRectangle rect; | |
| 8726 | 221 int xminus; |
| 5967 | 222 |
| 223 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); | |
| 224 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ | |
| 225 GList *iter = GTK_IMHTML(widget)->scalables; | |
| 226 | |
| 8726 | 227 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) + |
| 228 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget)); | |
| 229 | |
| 5967 | 230 while(iter){ |
| 231 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | |
| 8726 | 232 scale->scale(scale, rect.width - xminus, rect.height); |
| 5967 | 233 |
| 234 iter = iter->next; | |
| 235 } | |
| 236 } | |
| 237 | |
| 238 widget->old_rect = rect; | |
| 239 return FALSE; | |
| 240 } | |
| 241 | |
| 242 static gint | |
| 243 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
| 244 { | |
| 245 PangoLayout *layout; | |
| 246 | |
| 247 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 248 | |
| 249 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 250 | |
| 8061 | 251 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, |
| 5967 | 252 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, |
| 253 "tooltip", 0, 0, -1, -1); | |
| 254 | |
| 255 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
| 256 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
| 257 | |
| 258 g_object_unref(layout); | |
| 259 return FALSE; | |
| 260 } | |
| 261 | |
| 262 static gint | |
| 263 gtk_imhtml_tip (gpointer data) | |
| 264 { | |
| 265 GtkIMHtml *imhtml = data; | |
| 8526 | 266 PangoFontMetrics *font_metrics; |
| 5967 | 267 PangoLayout *layout; |
| 8526 | 268 PangoFont *font; |
| 5967 | 269 |
| 270 gint gap, x, y, h, w, scr_w, baseline_skip; | |
| 271 | |
| 272 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 273 | |
| 274 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
| 275 imhtml->tip_timer = 0; | |
| 276 return FALSE; | |
| 277 } | |
| 8061 | 278 |
| 5967 | 279 if (imhtml->tip_window){ |
| 280 gtk_widget_destroy (imhtml->tip_window); | |
| 281 imhtml->tip_window = NULL; | |
| 282 } | |
| 283 | |
| 284 imhtml->tip_timer = 0; | |
| 285 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
| 286 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
| 287 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
| 288 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
| 289 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
| 290 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
| 291 | |
| 292 gtk_widget_ensure_style (imhtml->tip_window); | |
| 293 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 8526 | 294 font = pango_context_load_font(pango_layout_get_context(layout), |
| 295 imhtml->tip_window->style->font_desc); | |
| 296 | |
| 297 if (font == NULL) { | |
| 298 char *tmp = pango_font_description_to_string( | |
| 299 imhtml->tip_window->style->font_desc); | |
| 300 | |
| 301 gaim_debug(GAIM_DEBUG_ERROR, "gtk_imhtml_tip", | |
| 302 "pango_context_load_font() couldn't load font: '%s'\n", | |
| 303 tmp); | |
| 304 g_free(tmp); | |
| 305 | |
| 306 return FALSE; | |
| 307 | |
| 308 } | |
| 309 | |
| 310 font_metrics = pango_font_get_metrics(font, NULL); | |
| 8309 | 311 |
| 5967 | 312 |
| 313 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
| 8526 | 314 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
| 315 pango_font_metrics_get_descent(font_metrics))/ 4); | |
| 5967 | 316 |
| 317 if (gap < 2) | |
| 318 gap = 2; | |
| 8526 | 319 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 320 pango_font_metrics_get_descent(font_metrics)); | |
| 5967 | 321 w = 8 + scr_w; |
| 322 h = 8 + baseline_skip; | |
| 323 | |
| 324 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
| 325 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
| 326 y += GTK_WIDGET(imhtml)->allocation.y; | |
| 327 | |
| 328 scr_w = gdk_screen_width(); | |
| 329 | |
| 330 x -= ((w >> 1) + 4); | |
| 331 | |
| 332 if ((x + w) > scr_w) | |
| 333 x -= (x + w) - scr_w; | |
| 334 else if (x < 0) | |
| 335 x = 0; | |
| 336 | |
| 8526 | 337 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 338 pango_font_metrics_get_descent(font_metrics)); | |
| 5967 | 339 |
| 340 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
| 341 gtk_widget_show (imhtml->tip_window); | |
| 342 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
| 343 | |
| 8526 | 344 pango_font_metrics_unref(font_metrics); |
| 5967 | 345 g_object_unref(layout); |
| 346 | |
| 347 return FALSE; | |
| 348 } | |
| 349 | |
| 350 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) | |
| 8061 | 351 { |
| 5967 | 352 GtkTextIter iter; |
| 353 GdkWindow *win = event->window; | |
| 354 int x, y; | |
| 355 char *tip = NULL; | |
| 356 GSList *tags = NULL, *templist = NULL; | |
| 357 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); | |
| 358 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
| 359 event->x, event->y, &x, &y); | |
| 360 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 361 tags = gtk_text_iter_get_tags(&iter); | |
| 362 | |
| 363 templist = tags; | |
| 364 while (templist) { | |
| 365 GtkTextTag *tag = templist->data; | |
| 366 tip = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 367 if (tip) | |
| 368 break; | |
| 369 templist = templist->next; | |
| 370 } | |
| 8061 | 371 |
| 5967 | 372 if (GTK_IMHTML(imhtml)->tip) { |
| 373 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
| 374 return FALSE; | |
| 375 } | |
| 376 /* We've left the cell. Remove the timeout and create a new one below */ | |
| 377 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 378 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 379 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 380 } | |
| 8061 | 381 if (GTK_IMHTML(imhtml)->editable) |
| 382 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor); | |
| 383 else | |
| 384 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 385 if (GTK_IMHTML(imhtml)->tip_timer) |
| 386 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 387 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 388 } | |
| 8061 | 389 |
| 5967 | 390 if(tip){ |
| 8061 | 391 if (!GTK_IMHTML(imhtml)->editable) |
| 392 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | |
| 393 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | |
| 5967 | 394 gtk_imhtml_tip, imhtml); |
| 395 } | |
| 8061 | 396 |
| 5967 | 397 GTK_IMHTML(imhtml)->tip = tip; |
| 398 g_slist_free(tags); | |
| 399 return FALSE; | |
| 400 } | |
| 401 | |
| 402 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
| 403 { | |
| 404 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ | |
| 405 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 406 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 407 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 408 } | |
| 409 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 410 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 411 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 412 } | |
| 8061 | 413 if (GTK_IMHTML(imhtml)->editable) |
| 414 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 415 else | |
| 416 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 417 |
| 8568 | 418 /* propagate the event normally */ |
| 5967 | 419 return FALSE; |
| 420 } | |
| 421 | |
| 6066 | 422 /* |
| 423 * XXX - This should be removed eventually. | |
| 424 * | |
| 8061 | 425 * This function exists to work around a gross bug in GtkTextView. |
| 426 * Basically, we short circuit ctrl+a and ctrl+end because they make | |
| 6066 | 427 * el program go boom. |
| 428 * | |
| 8061 | 429 * It's supposed to be fixed in gtk2.2. You can view the bug report at |
| 6066 | 430 * http://bugzilla.gnome.org/show_bug.cgi?id=107939 |
| 431 */ | |
| 8317 | 432 |
| 433 /* | |
| 434 * I'm adding some keyboard shortcuts too. | |
| 435 */ | |
| 436 | |
| 437 gboolean gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data) | |
| 8677 | 438 { |
| 8317 | 439 char buf[7]; |
| 440 buf[0] = '\0'; | |
| 441 | |
| 6066 | 442 if (event->state & GDK_CONTROL_MASK) |
| 443 switch (event->keyval) { | |
| 8539 | 444 #if (!GTK_CHECK_VERSION(2,2,0)) |
| 8317 | 445 case 'a': |
| 446 return TRUE; | |
| 447 break; | |
| 8677 | 448 |
| 8317 | 449 case GDK_Home: |
| 450 return TRUE; | |
| 451 break; | |
| 452 | |
| 453 case GDK_End: | |
| 454 return TRUE; | |
| 455 break; | |
| 8539 | 456 #endif /* Gtk+ >= 2.2.0 */ |
| 8317 | 457 |
| 458 case 'b': /* ctrl-b is GDK_Left, which moves backwards. */ | |
| 459 case 'B': | |
| 8420 | 460 if (imhtml->format_functions & GTK_IMHTML_BOLD) { |
| 8456 | 461 if(imhtml->html_shortcuts) { |
| 462 gtk_imhtml_toggle_bold(imhtml); | |
| 8466 | 463 return TRUE; |
| 8456 | 464 } |
| 8420 | 465 } |
| 8466 | 466 return FALSE; |
| 8317 | 467 break; |
| 8654 | 468 |
| 469 #ifdef LAY_OFF_MY_FRIGGIN_KEYBINDINGS | |
| 8317 | 470 case 'f': |
| 471 case 'F': | |
| 472 /*set_toggle(gtkconv->toolbar.font, | |
| 473 !gtk_toggle_button_get_active( | |
| 474 GTK_TOGGLE_BUTTON(gtkconv->toolbar.font)));*/ | |
| 475 | |
| 476 return TRUE; | |
| 477 break; | |
| 8654 | 478 #endif /* this doesn't even DO anything */ |
| 8317 | 479 |
| 480 case 'i': | |
| 481 case 'I': | |
| 8481 | 482 if (imhtml->format_functions & GTK_IMHTML_ITALIC) { |
| 8466 | 483 if(imhtml->html_shortcuts) { |
| 8456 | 484 gtk_imhtml_toggle_italic(imhtml); |
| 8466 | 485 return TRUE; |
| 486 } | |
| 8481 | 487 } |
| 8466 | 488 return FALSE; |
| 8317 | 489 break; |
| 490 | |
| 491 case 'u': /* ctrl-u is GDK_Clear, which clears the line. */ | |
| 492 case 'U': | |
| 8481 | 493 if (imhtml->format_functions & GTK_IMHTML_UNDERLINE) { |
| 8466 | 494 if(imhtml->html_shortcuts) { |
| 8456 | 495 gtk_imhtml_toggle_underline(imhtml); |
| 8466 | 496 return TRUE; |
| 497 } | |
| 8481 | 498 } |
| 8466 | 499 return FALSE; |
| 8317 | 500 break; |
| 501 | |
| 502 case '-': | |
| 8420 | 503 if (imhtml->format_functions & GTK_IMHTML_SHRINK) |
| 504 gtk_imhtml_font_shrink(imhtml); | |
| 8317 | 505 return TRUE; |
| 506 break; | |
| 507 | |
| 508 case '=': | |
| 509 case '+': | |
| 8420 | 510 if (imhtml->format_functions & GTK_IMHTML_GROW) |
| 511 gtk_imhtml_font_grow(imhtml); | |
| 8317 | 512 return TRUE; |
| 513 break; | |
| 8677 | 514 |
| 8317 | 515 case '1': strcpy(buf, ":-)"); break; |
| 516 case '2': strcpy(buf, ":-("); break; | |
| 517 case '3': strcpy(buf, ";-)"); break; | |
| 518 case '4': strcpy(buf, ":-P"); break; | |
| 519 case '5': strcpy(buf, "=-O"); break; | |
| 520 case '6': strcpy(buf, ":-*"); break; | |
| 521 case '7': strcpy(buf, ">:o"); break; | |
| 522 case '8': strcpy(buf, "8-)"); break; | |
| 523 case '!': strcpy(buf, ":-$"); break; | |
| 524 case '@': strcpy(buf, ":-!"); break; | |
| 525 case '#': strcpy(buf, ":-["); break; | |
| 526 case '$': strcpy(buf, "O:-)"); break; | |
| 527 case '%': strcpy(buf, ":-/"); break; | |
| 528 case '^': strcpy(buf, ":'("); break; | |
| 529 case '&': strcpy(buf, ":-X"); break; | |
| 530 case '*': strcpy(buf, ":-D"); break; | |
| 6066 | 531 } |
| 8456 | 532 if (*buf && imhtml->smiley_shortcuts) { |
| 533 gtk_imhtml_insert_smiley(imhtml, imhtml->protocol_name, buf); | |
| 8317 | 534 return TRUE; |
| 8677 | 535 } |
| 6066 | 536 return FALSE; |
| 537 } | |
| 538 | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
539 #if GTK_CHECK_VERSION(2,2,0) |
| 8061 | 540 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) { |
| 8681 | 541 char *text; |
| 8061 | 542 GtkTextIter start, end; |
| 543 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 544 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 8681 | 545 |
| 8061 | 546 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); |
| 547 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 8681 | 548 gboolean primary = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY) == clipboard; |
| 8061 | 549 |
| 550 if (info == TARGET_HTML) { | |
| 8149 | 551 int len; |
| 8148 | 552 char *selection; |
| 8061 | 553 GString *str = g_string_new(NULL); |
| 8681 | 554 if (primary) { |
| 555 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 556 } else | |
| 557 text = imhtml->clipboard_html_string; | |
| 8061 | 558 |
| 559 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | |
| 560 str = g_string_append_unichar(str, 0xfeff); | |
| 561 str = g_string_append(str, text); | |
| 562 str = g_string_append_unichar(str, 0x0000); | |
| 8148 | 563 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); |
| 8719 | 564 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); |
| 8061 | 565 g_string_free(str, TRUE); |
| 566 g_free(selection); | |
| 567 } else { | |
| 8681 | 568 if (primary) { |
| 569 text = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 570 } else | |
| 571 text = imhtml->clipboard_text_string; | |
| 8061 | 572 gtk_selection_data_set_text(selection_data, text, strlen(text)); |
| 573 } | |
| 8681 | 574 if (primary) /* This was allocated here */ |
| 575 g_free(text); | |
| 576 } | |
| 8061 | 577 |
| 578 static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml) | |
| 7749 | 579 { |
| 8061 | 580 GtkTextIter insert; |
| 581 GtkTextIter selection_bound; | |
| 582 | |
| 583 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert, | |
| 584 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert")); | |
| 585 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound, | |
| 586 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound")); | |
| 587 | |
| 588 if (!gtk_text_iter_equal (&insert, &selection_bound)) | |
| 589 gtk_text_buffer_move_mark (imhtml->text_buffer, | |
| 590 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"), | |
| 591 &insert); | |
| 7749 | 592 } |
| 7742 | 593 |
| 8677 | 594 static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 7749 | 595 { |
| 8681 | 596 GtkTextIter start, end; |
| 597 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 598 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 599 | |
| 600 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
| 601 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 602 | |
| 8061 | 603 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), |
| 604 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 605 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 606 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | |
| 7346 | 607 |
| 8681 | 608 if (imhtml->clipboard_html_string) { |
| 609 g_free(imhtml->clipboard_html_string); | |
| 610 g_free(imhtml->clipboard_text_string); | |
| 611 } | |
| 612 | |
| 613 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 614 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 615 | |
| 8692 | 616 #ifdef _WIN32 |
| 617 /* We're going to still copy plain text, but let's toss the "HTML Format" | |
| 618 we need into the windows clipboard now as well. */ | |
| 619 HGLOBAL hdata; | |
| 620 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); | |
| 621 gchar *buffer; | |
| 622 gint length = strlen(clipboard); | |
| 623 if(clipboard != NULL) { | |
| 8693 | 624 OpenClipboard(NULL); |
| 8692 | 625 hdata = GlobalAlloc(GMEM_MOVEABLE, length); |
| 626 buffer = GlobalLock(hdata); | |
| 627 memcpy(buffer, clipboard, length); | |
| 628 GlobalUnlock(hdata); | |
| 629 SetClipboardData(win_html_fmt, hdata); | |
| 630 CloseClipboard(); | |
| 8693 | 631 g_free(clipboard); |
| 8692 | 632 } |
| 633 #endif | |
| 634 | |
| 8061 | 635 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
| 636 } | |
| 637 | |
| 8698 | 638 static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 639 { | |
| 640 GtkTextIter start, end; | |
| 641 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 642 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 643 | |
| 644 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
| 645 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 646 | |
| 647 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), | |
| 648 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 649 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 650 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | |
| 651 | |
| 652 if (imhtml->clipboard_html_string) { | |
| 653 g_free(imhtml->clipboard_html_string); | |
| 654 g_free(imhtml->clipboard_text_string); | |
| 655 } | |
| 656 | |
| 657 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 658 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 659 | |
| 660 #ifdef _WIN32 | |
| 661 /* We're going to still copy plain text, but let's toss the "HTML Format" | |
| 662 we need into the windows clipboard now as well. */ | |
| 663 HGLOBAL hdata; | |
| 664 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); | |
| 665 gchar *buffer; | |
| 666 gint length = strlen(clipboard); | |
| 667 if(clipboard != NULL) { | |
| 668 OpenClipboard(NULL); | |
| 669 hdata = GlobalAlloc(GMEM_MOVEABLE, length); | |
| 670 buffer = GlobalLock(hdata); | |
| 671 memcpy(buffer, clipboard, length); | |
| 672 GlobalUnlock(hdata); | |
| 673 SetClipboardData(win_html_fmt, hdata); | |
| 674 CloseClipboard(); | |
| 675 g_free(clipboard); | |
| 676 } | |
| 677 #endif | |
| 678 | |
| 679 if (imhtml->editable) | |
| 680 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE); | |
| 681 g_signal_stop_emission_by_name(imhtml, "cut-clipboard"); | |
| 682 } | |
| 683 | |
| 8061 | 684 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data) |
| 685 { | |
| 686 char *text; | |
| 687 guint16 c; | |
| 688 GtkIMHtml *imhtml = data; | |
| 8677 | 689 GtkTextIter iter; |
| 8698 | 690 GtkIMHtmlOptions flags = GTK_IMHTML_NO_NEWLINE; |
| 691 gboolean plaintext = FALSE; | |
| 7809 | 692 |
| 8123 | 693 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) |
| 8105 | 694 return; |
| 695 | |
| 8692 | 696 #ifdef _WIN32 |
| 697 /* If we're on windows, let's see if we can get data from the HTML Format | |
| 698 clipboard before we try to paste from the GTK buffer */ | |
| 699 HGLOBAL hdata; | |
| 700 DWORD err; | |
| 701 char *buffer; | |
| 702 if (IsClipboardFormatAvailable(win_html_fmt)) { | |
| 8693 | 703 OpenClipboard(NULL); |
| 8692 | 704 hdata = GetClipboardData(win_html_fmt); |
| 705 if (hdata == NULL) { | |
| 706 err = GetLastError(); | |
| 707 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err); | |
| 708 CloseClipboard(); | |
| 709 return; | |
| 710 } | |
| 711 buffer = GlobalLock(hdata); | |
| 712 if (buffer == NULL) { | |
| 8693 | 713 err = GetLastError(); |
| 8692 | 714 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err); |
| 715 CloseClipboard(); | |
| 716 return; | |
| 717 } | |
| 718 text = clipboard_win32_to_html(buffer); | |
| 719 GlobalUnlock(hdata); | |
| 720 CloseClipboard(); | |
| 721 } else | |
| 722 #endif | |
| 8061 | 723 if (selection_data->length < 0) { |
| 8698 | 724 char *tmp; |
| 8061 | 725 text = gtk_clipboard_wait_for_text(clipboard); |
| 8698 | 726 flags = 0; |
| 727 plaintext = TRUE; | |
|
8128
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
728 |
|
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
729 if (text == NULL) |
|
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
730 return; |
|
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
731 |
| 8698 | 732 tmp = gaim_escape_html(text); |
| 733 g_free(text); | |
| 734 text = tmp; | |
| 8061 | 735 } else { |
| 8719 | 736 #if 0 |
| 737 /* Here's some debug code, for figuring out what sent to us over the clipboard. */ | |
| 738 { | |
| 739 int i; | |
| 740 | |
| 741 gaim_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t", | |
| 742 selection_data->format, selection_data->length); | |
| 743 | |
| 744 for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) { | |
| 745 if ((i % 70) == 0) | |
| 746 printf("\n\t"); | |
| 747 if (selection_data->data[i] == '\0') | |
| 748 printf("."); | |
| 749 else | |
| 750 printf("%c", selection_data->data[i]); | |
| 751 } | |
| 752 printf("\n"); | |
| 753 } | |
| 754 #endif | |
| 755 text = g_malloc(selection_data->length); | |
| 756 memcpy(text, selection_data->data, selection_data->length); | |
| 7766 | 757 } |
| 8061 | 758 |
| 759 memcpy (&c, text, 2); | |
| 760 if (c == 0xfeff) { | |
| 761 /* This is UCS2 */ | |
| 8719 | 762 char *utf8 = g_convert(text+2, selection_data->length - 2, "UTF-8", "UCS-2", NULL, NULL, NULL); |
| 8061 | 763 g_free(text); |
| 764 text = utf8; | |
| 8698 | 765 if (!text) { |
| 766 gaim_debug_warning("gtkimhtml", "g_convert failed in paste_received_cb\n"); | |
| 767 return; | |
| 768 } | |
| 8061 | 769 } |
| 8698 | 770 |
| 771 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { | |
| 772 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in paste_received_cb\n"); | |
| 773 g_free(text); | |
| 774 return; | |
| 775 } | |
| 776 | |
| 8677 | 777 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); |
| 8698 | 778 if (!imhtml->wbfo && !plaintext) |
| 779 gtk_imhtml_close_tags(imhtml, &iter); | |
| 780 gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter); | |
| 8677 | 781 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter); |
| 8698 | 782 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer), |
| 783 0, FALSE, 0.0, 0.0); | |
| 8681 | 784 g_free(text); |
| 8061 | 785 } |
| 786 | |
| 787 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
| 788 { | |
| 789 | |
| 790 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
| 791 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 792 paste_received_cb, imhtml); | |
| 793 g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); | |
| 7766 | 794 } |
| 795 | |
| 8677 | 796 static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused) |
| 797 { | |
| 798 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, | |
| 799 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); | |
| 800 | |
| 801 } | |
| 802 | |
| 803 #endif | |
| 804 | |
| 805 static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml) | |
| 806 { | |
| 807 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) { | |
| 808 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), | |
| 809 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 810 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 811 (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml)); | |
| 812 } | |
| 813 } | |
| 814 | |
| 815 /* does this go in the #ifdef too? I need to keep track of which functions are 2.2 only */ | |
| 816 /* adapted from gtktextview.c */ | |
| 817 static gboolean gtk_imhtml_button_press_event(GtkIMHtml *imhtml, GdkEventButton *event, gpointer unused) | |
| 7346 | 818 { |
| 8677 | 819 if (event->button == 2) { |
| 820 int x, y; | |
| 821 GtkTextIter iter; | |
| 822 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY); | |
| 823 | |
| 824 if (!imhtml->editable) | |
| 825 return FALSE; | |
| 826 | |
| 827 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), | |
| 828 GTK_TEXT_WINDOW_TEXT, | |
| 829 event->x, | |
| 830 event->y, | |
| 831 &x, | |
| 832 &y); | |
| 833 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 834 gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter); | |
| 835 | |
| 836 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 837 paste_received_cb, imhtml); | |
| 838 | |
| 839 return TRUE; | |
| 840 } | |
| 841 | |
| 7346 | 842 return FALSE; |
| 843 } | |
| 4263 | 844 |
| 4032 | 845 static GtkTextViewClass *parent_class = NULL; |
| 846 | |
| 847 static void | |
| 848 gtk_imhtml_finalize (GObject *object) | |
| 849 { | |
| 850 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
| 4895 | 851 GList *scalables; |
| 8061 | 852 |
| 4138 | 853 g_hash_table_destroy(imhtml->smiley_data); |
| 4032 | 854 gtk_smiley_tree_destroy(imhtml->default_smilies); |
| 4138 | 855 gdk_cursor_unref(imhtml->hand_cursor); |
| 856 gdk_cursor_unref(imhtml->arrow_cursor); | |
| 8061 | 857 gdk_cursor_unref(imhtml->text_cursor); |
| 8677 | 858 |
| 4735 | 859 if(imhtml->tip_window){ |
| 860 gtk_widget_destroy(imhtml->tip_window); | |
| 861 } | |
| 862 if(imhtml->tip_timer) | |
| 863 gtk_timeout_remove(imhtml->tip_timer); | |
| 864 | |
| 4895 | 865 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
| 866 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | |
| 867 scale->free(scale); | |
| 868 } | |
| 7991 | 869 |
| 8681 | 870 if (imhtml->clipboard_text_string) { |
| 871 g_free(imhtml->clipboard_text_string); | |
| 872 g_free(imhtml->clipboard_html_string); | |
| 873 } | |
| 874 | |
| 875 | |
| 4895 | 876 g_list_free(imhtml->scalables); |
| 4032 | 877 G_OBJECT_CLASS(parent_class)->finalize (object); |
| 878 } | |
| 1428 | 879 |
| 3922 | 880 /* Boring GTK stuff */ |
| 8519 | 881 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass) |
| 1428 | 882 { |
| 3922 | 883 GtkObjectClass *object_class; |
| 4032 | 884 GObjectClass *gobject_class; |
| 8519 | 885 object_class = (GtkObjectClass*) klass; |
| 886 gobject_class = (GObjectClass*) klass; | |
| 4032 | 887 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); |
| 4417 | 888 signals[URL_CLICKED] = g_signal_new("url_clicked", |
| 889 G_TYPE_FROM_CLASS(gobject_class), | |
| 890 G_SIGNAL_RUN_FIRST, | |
| 891 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
| 892 NULL, | |
| 893 0, | |
| 894 g_cclosure_marshal_VOID__POINTER, | |
| 895 G_TYPE_NONE, 1, | |
| 896 G_TYPE_POINTER); | |
| 8506 | 897 signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update", |
| 8420 | 898 G_TYPE_FROM_CLASS(gobject_class), |
| 899 G_SIGNAL_RUN_FIRST, | |
| 900 G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update), | |
| 901 NULL, | |
| 902 0, | |
| 903 g_cclosure_marshal_VOID__POINTER, | |
| 904 G_TYPE_NONE, 1, | |
| 905 G_TYPE_INT); | |
| 906 signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle", | |
| 907 G_TYPE_FROM_CLASS(gobject_class), | |
| 908 G_SIGNAL_RUN_FIRST, | |
| 909 G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format), | |
| 910 NULL, | |
| 911 0, | |
| 912 g_cclosure_marshal_VOID__POINTER, | |
| 8427 | 913 G_TYPE_NONE, 1, |
| 8420 | 914 G_TYPE_INT); |
| 8427 | 915 signals[CLEAR_FORMAT] = g_signal_new("format_function_clear", |
| 916 G_TYPE_FROM_CLASS(gobject_class), | |
| 917 G_SIGNAL_RUN_FIRST, | |
| 918 G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format), | |
| 919 NULL, | |
| 920 0, | |
| 8481 | 921 g_cclosure_marshal_VOID__VOID, |
| 922 G_TYPE_NONE, 0); | |
| 8506 | 923 signals[UPDATE_FORMAT] = g_signal_new("format_function_update", |
| 924 G_TYPE_FROM_CLASS(gobject_class), | |
| 925 G_SIGNAL_RUN_FIRST, | |
| 926 G_STRUCT_OFFSET(GtkIMHtmlClass, update_format), | |
| 927 NULL, | |
| 928 0, | |
| 929 g_cclosure_marshal_VOID__VOID, | |
| 930 G_TYPE_NONE, 0); | |
| 4032 | 931 gobject_class->finalize = gtk_imhtml_finalize; |
| 1428 | 932 } |
| 933 | |
| 3922 | 934 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
| 1428 | 935 { |
| 3922 | 936 GtkTextIter iter; |
| 937 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
| 938 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
| 8677 | 939 imhtml->scrollpoint = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); |
| 3922 | 940 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); |
| 5105 | 941 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
| 3922 | 942 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
| 8677 | 943 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2); |
| 944 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(imhtml), 2); | |
| 8061 | 945 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ |
| 3922 | 946 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
| 8061 | 947 |
| 3922 | 948 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
| 8061 | 949 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ |
| 3922 | 950 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
| 951 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
| 952 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 953 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
| 954 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
| 955 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
| 956 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
| 7295 | 957 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
| 8677 | 958 |
| 3922 | 959 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
| 960 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 961 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 8061 | 962 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
| 2993 | 963 |
| 4253 | 964 imhtml->show_smileys = TRUE; |
| 6124 | 965 imhtml->show_comments = TRUE; |
| 4253 | 966 |
| 4892 | 967 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 968 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4032 | 969 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 4735 | 970 |
| 4944 | 971 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
| 4735 | 972 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
| 4944 | 973 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
| 6066 | 974 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
| 8677 | 975 g_signal_connect(G_OBJECT(imhtml), "button_press_event", G_CALLBACK(gtk_imhtml_button_press_event), NULL); |
| 976 g_signal_connect(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(preinsert_cb), imhtml); | |
| 8061 | 977 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
| 8091 | 978 |
| 979 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, | |
| 980 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), | |
| 981 GDK_ACTION_COPY); | |
| 982 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); | |
| 983 | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
984 #if GTK_CHECK_VERSION(2,2,0) |
| 7353 | 985 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
| 8698 | 986 g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL); |
| 8061 | 987 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
| 8677 | 988 //g_signal_connect_after(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); |
| 989 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL); | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
990 #endif |
| 8677 | 991 |
| 992 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 993 G_CALLBACK(mark_set_so_update_selection_cb), imhtml); | |
| 994 | |
| 4944 | 995 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); |
| 4735 | 996 |
| 8681 | 997 imhtml->clipboard_text_string = NULL; |
| 998 imhtml->clipboard_html_string = NULL; | |
| 999 | |
| 4735 | 1000 imhtml->tip = NULL; |
| 1001 imhtml->tip_timer = 0; | |
| 1002 imhtml->tip_window = NULL; | |
| 4895 | 1003 |
| 8677 | 1004 imhtml->edit.bold = FALSE; |
| 1005 imhtml->edit.italic = FALSE; | |
| 1006 imhtml->edit.underline = FALSE; | |
| 8061 | 1007 imhtml->edit.forecolor = NULL; |
| 1008 imhtml->edit.backcolor = NULL; | |
| 1009 imhtml->edit.fontface = NULL; | |
| 8677 | 1010 imhtml->edit.fontsize = 0; |
| 1011 imhtml->edit.link = NULL; | |
| 1012 | |
| 8061 | 1013 |
| 4895 | 1014 imhtml->scalables = NULL; |
| 8061 | 1015 |
| 1016 gtk_imhtml_set_editable(imhtml, FALSE); | |
| 8692 | 1017 |
| 1018 #ifdef _WIN32 | |
| 1019 /* Register HTML Format as desired clipboard format */ | |
| 1020 win_html_fmt = RegisterClipboardFormat("HTML Format"); | |
| 1021 #endif | |
| 2993 | 1022 } |
| 1023 | |
| 3922 | 1024 GtkWidget *gtk_imhtml_new(void *a, void *b) |
| 1428 | 1025 { |
| 4635 | 1026 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
| 1428 | 1027 } |
| 1028 | |
| 4635 | 1029 GType gtk_imhtml_get_type() |
| 1428 | 1030 { |
| 4635 | 1031 static GType imhtml_type = 0; |
| 1428 | 1032 |
| 1033 if (!imhtml_type) { | |
| 4635 | 1034 static const GTypeInfo imhtml_info = { |
| 1035 sizeof(GtkIMHtmlClass), | |
| 1036 NULL, | |
| 1037 NULL, | |
| 1038 (GClassInitFunc) gtk_imhtml_class_init, | |
| 1039 NULL, | |
| 1040 NULL, | |
| 1428 | 1041 sizeof (GtkIMHtml), |
| 4635 | 1042 0, |
| 1043 (GInstanceInitFunc) gtk_imhtml_init | |
| 1428 | 1044 }; |
| 4635 | 1045 |
| 1046 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
| 1047 "GtkIMHtml", &imhtml_info, 0); | |
| 1428 | 1048 } |
| 1049 | |
| 1050 return imhtml_type; | |
| 1051 } | |
| 1052 | |
| 4417 | 1053 struct url_data { |
| 1054 GObject *object; | |
| 1055 gchar *url; | |
| 1056 }; | |
| 1057 | |
| 8677 | 1058 static void url_data_destroy(gpointer mydata) |
| 1059 { | |
| 1060 struct url_data *data = mydata; | |
| 1061 g_object_unref(data->object); | |
| 1062 g_free(data->url); | |
| 1063 g_free(data); | |
| 1064 } | |
| 1065 | |
| 4417 | 1066 static void url_open(GtkWidget *w, struct url_data *data) { |
| 1067 if(!data) return; | |
| 8061 | 1068 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); |
| 7988 | 1069 |
| 4417 | 1070 } |
| 5582 | 1071 |
| 4417 | 1072 static void url_copy(GtkWidget *w, gchar *url) { |
| 1073 GtkClipboard *clipboard; | |
| 1074 | |
|
5293
ead927e2543f
[gaim-migrate @ 5665]
Christian Hammond <chipx86@chipx86.com>
parents:
5282
diff
changeset
|
1075 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 4417 | 1076 gtk_clipboard_set_text(clipboard, url, -1); |
| 5582 | 1077 |
| 1078 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | |
| 1079 gtk_clipboard_set_text(clipboard, url, -1); | |
| 4417 | 1080 } |
| 1081 | |
| 1082 /* The callback for an event on a link tag. */ | |
| 8677 | 1083 gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, gpointer unused) { |
| 4417 | 1084 GdkEventButton *event_button = (GdkEventButton *) event; |
| 8061 | 1085 if (GTK_IMHTML(imhtml)->editable) |
| 1086 return FALSE; | |
| 3922 | 1087 if (event->type == GDK_BUTTON_RELEASE) { |
| 8061 | 1088 if (event_button->button == 1) { |
| 4417 | 1089 GtkTextIter start, end; |
| 1090 /* we shouldn't open a URL if the user has selected something: */ | |
| 8677 | 1091 if (gtk_text_buffer_get_selection_bounds( |
| 1092 gtk_text_iter_get_buffer(arg2), &start, &end)) | |
| 4417 | 1093 return FALSE; |
| 1094 | |
| 1095 /* A link was clicked--we emit the "url_clicked" signal | |
| 1096 * with the URL as the argument */ | |
| 8677 | 1097 g_object_ref(G_OBJECT(tag)); |
| 1098 g_signal_emit(imhtml, signals[URL_CLICKED], 0, g_object_get_data(G_OBJECT(tag), "link_url")); | |
| 1099 g_object_unref(G_OBJECT(tag)); | |
| 4417 | 1100 return FALSE; |
| 1101 } else if(event_button->button == 3) { | |
| 4745 | 1102 GtkWidget *img, *item, *menu; |
| 4417 | 1103 struct url_data *tempdata = g_new(struct url_data, 1); |
| 5091 | 1104 tempdata->object = g_object_ref(imhtml); |
| 8677 | 1105 tempdata->url = g_strdup(g_object_get_data(G_OBJECT(tag), "link_url")); |
| 4745 | 1106 |
| 5091 | 1107 /* Don't want the tooltip around if user right-clicked on link */ |
| 1108 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 1109 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 1110 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 1111 } | |
| 1112 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 1113 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 1114 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 1115 } | |
| 8061 | 1116 if (GTK_IMHTML(imhtml)->editable) |
| 1117 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 1118 else | |
| 1119 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 4417 | 1120 menu = gtk_menu_new(); |
| 8677 | 1121 g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", tempdata, url_data_destroy); |
| 4745 | 1122 |
| 4417 | 1123 /* buttons and such */ |
| 1124 | |
| 8677 | 1125 if (!strncmp(tempdata->url, "mailto:", 7)) |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1126 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1127 /* Copy E-Mail Address */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1128 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1129 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1130 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1131 _("_Copy E-Mail Address")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1132 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
|
1133 g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1134 G_CALLBACK(url_copy), tempdata->url + 7); |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1135 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1136 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1137 else |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1138 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1139 /* Copy Link Location */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1140 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1141 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1142 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1143 _("_Copy Link Location")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1144 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
|
1145 g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1146 G_CALLBACK(url_copy), tempdata->url); |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1147 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1148 |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1149 /* Open Link in Browser */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1150 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1151 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1152 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1153 _("_Open Link in Browser")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1154 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
|
1155 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1156 G_CALLBACK(url_open), tempdata); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1157 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1158 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1159 |
| 4756 | 1160 |
| 4417 | 1161 gtk_widget_show_all(menu); |
| 4756 | 1162 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
| 1163 event_button->button, event_button->time); | |
| 4745 | 1164 |
| 4417 | 1165 return TRUE; |
| 1166 } | |
| 1428 | 1167 } |
| 4417 | 1168 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 1169 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 1170 be caught by the regular GtkTextView menu */ | |
| 1171 else | |
| 1172 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 1173 } |
| 1174 | |
| 8091 | 1175 static void |
| 1176 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
| 1177 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) | |
| 1178 { | |
| 1179 if(gtk_imhtml_get_editable(imhtml) && sd->data){ | |
| 1180 gchar **links; | |
| 1181 gchar *link; | |
| 1182 | |
| 1183 gaim_str_strip_cr(sd->data); | |
| 1184 | |
| 1185 links = g_strsplit(sd->data, "\n", 0); | |
| 1186 while((link = *links++) != NULL){ | |
| 1187 if(gaim_str_has_prefix(link, "http://") || | |
| 1188 gaim_str_has_prefix(link, "https://") || | |
| 1189 gaim_str_has_prefix(link, "ftp://")){ | |
| 8677 | 1190 gtk_imhtml_insert_link(imhtml, gtk_text_buffer_get_insert(imhtml->text_buffer), link, link); |
| 8091 | 1191 } else if (link=='\0') { |
| 8177 | 1192 /* Ignore blank lines */ |
| 8091 | 1193 } else { |
| 8177 | 1194 /* Special reasons, aka images being put in via other tag, etc. */ |
| 8091 | 1195 } |
| 1196 } | |
| 1197 | |
| 1198 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
| 1199 } else { | |
| 1200 gtk_drag_finish(dc, FALSE, FALSE, t); | |
| 1201 } | |
| 1202 } | |
| 1203 | |
| 4298 | 1204 /* this isn't used yet |
| 4032 | 1205 static void |
| 4263 | 1206 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 1207 GtkIMHtmlSmiley *smiley) | |
| 4032 | 1208 { |
| 1209 GtkSmileyTree *t = tree; | |
| 4263 | 1210 const gchar *x = smiley->smile; |
| 4032 | 1211 gint len = 0; |
| 1212 | |
| 1213 while (*x) { | |
| 1214 gchar *pos; | |
| 1215 | |
| 1216 if (!t->values) | |
| 1217 return; | |
| 1218 | |
| 1219 pos = strchr (t->values->str, *x); | |
| 1220 if (pos) | |
| 1221 t = t->children [(int) pos - (int) t->values->str]; | |
| 1222 else | |
| 1223 return; | |
| 1224 | |
| 1225 x++; len++; | |
| 1226 } | |
| 1227 | |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
1228 if (t->image) { |
| 4032 | 1229 t->image = NULL; |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
1230 } |
| 4032 | 1231 } |
| 4298 | 1232 */ |
| 1233 | |
| 4032 | 1234 |
| 1235 static gint | |
| 1236 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 1237 const gchar *text) | |
| 1238 { | |
| 1239 GtkSmileyTree *t = tree; | |
| 1240 const gchar *x = text; | |
| 1241 gint len = 0; | |
| 8505 | 1242 gchar *amp; |
| 1243 gint alen; | |
| 4032 | 1244 |
| 1245 while (*x) { | |
| 1246 gchar *pos; | |
| 1247 | |
| 1248 if (!t->values) | |
| 1249 break; | |
| 1250 | |
| 8505 | 1251 if(*x == '&' && gtk_imhtml_is_amp_escape(x, &, &alen)) { |
| 1252 len += alen - strlen(amp); | |
| 1253 x += alen - strlen(amp); | |
| 1254 pos = strchr (t->values->str, *amp); | |
| 1255 } | |
| 1256 else | |
| 1257 pos = strchr (t->values->str, *x); | |
| 1258 | |
| 4032 | 1259 if (pos) |
| 7371 | 1260 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1261 else |
| 1262 break; | |
| 1263 | |
| 1264 x++; len++; | |
| 1265 } | |
| 1266 | |
| 1267 if (t->image) | |
| 1268 return len; | |
| 1269 | |
| 1270 return 0; | |
| 1271 } | |
| 1272 | |
| 1273 void | |
| 4263 | 1274 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
| 1275 gchar *sml, | |
| 1276 GtkIMHtmlSmiley *smiley) | |
| 4032 | 1277 { |
| 1278 GtkSmileyTree *tree; | |
| 1279 g_return_if_fail (imhtml != NULL); | |
| 1280 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 7371 | 1281 |
| 4032 | 1282 if (sml == NULL) |
| 1283 tree = imhtml->default_smilies; | |
| 1284 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
| 1285 } else { | |
| 1286 tree = gtk_smiley_tree_new(); | |
| 4892 | 1287 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
| 4032 | 1288 } |
| 1289 | |
| 4263 | 1290 gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 1291 } |
| 1292 | |
| 1293 static gboolean | |
| 1294 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 1295 GSList *fonts, | |
| 1296 const gchar *text, | |
| 1297 gint *len) | |
| 1298 { | |
| 1299 GtkSmileyTree *tree; | |
| 5967 | 1300 GtkIMHtmlFontDetail *font; |
| 4032 | 1301 char *sml = NULL; |
| 1302 | |
| 1303 if (fonts) { | |
| 1304 font = fonts->data; | |
| 1305 sml = font->sml; | |
| 1306 } | |
| 1307 | |
| 1308 if (sml == NULL) | |
| 1309 tree = imhtml->default_smilies; | |
| 1310 else { | |
| 1311 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
| 1312 } | |
| 1313 if (tree == NULL) | |
| 1314 return FALSE; | |
| 7371 | 1315 |
| 8505 | 1316 *len = gtk_smiley_tree_lookup (tree, text); |
| 4032 | 1317 return (*len > 0); |
| 1318 } | |
| 1319 | |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1320 GdkPixbufAnimation * |
| 4032 | 1321 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
| 1322 const gchar *sml, | |
| 1323 const gchar *text) | |
| 1324 { | |
| 1325 GtkSmileyTree *t; | |
| 1326 const gchar *x = text; | |
| 1327 if (sml == NULL) | |
| 1328 t = imhtml->default_smilies; | |
| 7371 | 1329 else |
| 4032 | 1330 t = g_hash_table_lookup(imhtml->smiley_data, sml); |
| 7371 | 1331 |
| 4032 | 1332 |
| 1333 if (t == NULL) | |
| 1334 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1335 | |
| 1336 while (*x) { | |
| 1337 gchar *pos; | |
| 1338 | |
| 1339 if (!t->values) { | |
| 1340 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1341 } | |
| 7371 | 1342 |
| 4032 | 1343 pos = strchr (t->values->str, *x); |
| 1344 if (pos) { | |
| 7371 | 1345 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1346 } else { |
| 1347 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1348 } | |
| 1349 x++; | |
| 1350 } | |
| 1351 | |
| 4263 | 1352 if (!t->image->icon) |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1353 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL); |
| 4263 | 1354 |
| 1355 return t->image->icon; | |
| 4032 | 1356 } |
| 4793 | 1357 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 3922 | 1358 *tag = g_strndup (string, strlen (x)); \ |
| 1359 *len = strlen (x) + 1; \ | |
| 1360 return TRUE; \ | |
| 1361 } \ | |
| 1362 (*type)++ | |
| 1428 | 1363 |
| 4793 | 1364 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 3922 | 1365 const gchar *c = string + strlen (x " "); \ |
| 1366 gchar e = '"'; \ | |
| 1367 gboolean quote = FALSE; \ | |
| 1368 while (*c) { \ | |
| 1369 if (*c == '"' || *c == '\'') { \ | |
| 1370 if (quote && (*c == e)) \ | |
| 1371 quote = !quote; \ | |
| 1372 else if (!quote) { \ | |
| 1373 quote = !quote; \ | |
| 1374 e = *c; \ | |
| 1375 } \ | |
| 1376 } else if (!quote && (*c == '>')) \ | |
| 1377 break; \ | |
| 1378 c++; \ | |
| 1379 } \ | |
| 1380 if (*c) { \ | |
| 1381 *tag = g_strndup (string, c - string); \ | |
| 1382 *len = c - string + 1; \ | |
| 1383 return TRUE; \ | |
| 1384 } \ | |
| 1385 } \ | |
| 1386 (*type)++ | |
| 1428 | 1387 |
| 1388 | |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1389 static gboolean |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1390 gtk_imhtml_is_amp_escape (const gchar *string, |
| 7280 | 1391 gchar **replace, |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1392 gint *length) |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1393 { |
| 7287 | 1394 static char buf[7]; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1395 g_return_val_if_fail (string != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1396 g_return_val_if_fail (replace != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1397 g_return_val_if_fail (length != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1398 |
| 4793 | 1399 if (!g_ascii_strncasecmp (string, "&", 5)) { |
| 7280 | 1400 *replace = "&"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1401 *length = 5; |
| 4793 | 1402 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
| 7280 | 1403 *replace = "<"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1404 *length = 4; |
| 4793 | 1405 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
| 7280 | 1406 *replace = ">"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1407 *length = 4; |
| 4793 | 1408 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
| 7280 | 1409 *replace = " "; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1410 *length = 6; |
| 4793 | 1411 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
| 7280 | 1412 *replace = "©"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1413 *length = 6; |
| 4793 | 1414 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
| 7280 | 1415 *replace = "\""; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1416 *length = 6; |
| 4793 | 1417 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
| 7280 | 1418 *replace = "®"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1419 *length = 5; |
| 5093 | 1420 } else if (!g_ascii_strncasecmp (string, "'", 6)) { |
| 7280 | 1421 *replace = "\'"; |
| 5093 | 1422 *length = 6; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1423 } else if (*(string + 1) == '#') { |
|
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
1424 guint pound = 0; |
| 3004 | 1425 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
| 7287 | 1426 int buflen; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1427 if (*(string + 3 + (gint)log10 (pound)) != ';') |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1428 return FALSE; |
| 7287 | 1429 buflen = g_unichar_to_utf8((gunichar)pound, buf); |
| 1430 buf[buflen] = '\0'; | |
| 7280 | 1431 *replace = buf; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1432 *length = 2; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1433 while (isdigit ((gint) string [*length])) (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1434 if (string [*length] == ';') (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1435 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1436 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1437 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1438 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1439 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1440 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1441 |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1442 return TRUE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1443 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1444 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1445 static gboolean |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1446 gtk_imhtml_is_tag (const gchar *string, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1447 gchar **tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1448 gint *len, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1449 gint *type) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1450 { |
| 8061 | 1451 char *close; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1452 *type = 1; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1453 |
| 8118 | 1454 |
| 8061 | 1455 if (!(close = strchr (string, '>'))) |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1456 return FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1457 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1458 VALID_TAG ("B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1459 VALID_TAG ("BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1460 VALID_TAG ("/B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1461 VALID_TAG ("/BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1462 VALID_TAG ("I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1463 VALID_TAG ("ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1464 VALID_TAG ("/I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1465 VALID_TAG ("/ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1466 VALID_TAG ("U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1467 VALID_TAG ("UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1468 VALID_TAG ("/U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1469 VALID_TAG ("/UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1470 VALID_TAG ("S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1471 VALID_TAG ("STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1472 VALID_TAG ("/S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1473 VALID_TAG ("/STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1474 VALID_TAG ("SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1475 VALID_TAG ("/SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1476 VALID_TAG ("SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1477 VALID_TAG ("/SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1478 VALID_TAG ("PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1479 VALID_TAG ("/PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1480 VALID_TAG ("TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1481 VALID_TAG ("/TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1482 VALID_TAG ("BR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1483 VALID_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1484 VALID_TAG ("/FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1485 VALID_TAG ("/A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1486 VALID_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1487 VALID_TAG ("/P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1488 VALID_TAG ("H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1489 VALID_TAG ("/H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1490 VALID_TAG ("HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1491 VALID_TAG ("/HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1492 VALID_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1493 VALID_TAG ("/BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1494 VALID_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1495 VALID_TAG ("HEAD"); |
| 2993 | 1496 VALID_TAG ("/HEAD"); |
| 1497 VALID_TAG ("BINARY"); | |
| 1498 VALID_TAG ("/BINARY"); | |
| 5093 | 1499 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1500 VALID_OPT_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1501 VALID_OPT_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1502 VALID_OPT_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1503 VALID_OPT_TAG ("A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1504 VALID_OPT_TAG ("IMG"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1505 VALID_OPT_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1506 VALID_OPT_TAG ("H3"); |
| 5093 | 1507 VALID_OPT_TAG ("HTML"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1508 |
| 5101 | 1509 VALID_TAG ("CITE"); |
| 1510 VALID_TAG ("/CITE"); | |
| 1511 VALID_TAG ("EM"); | |
| 1512 VALID_TAG ("/EM"); | |
| 1513 VALID_TAG ("STRONG"); | |
| 1514 VALID_TAG ("/STRONG"); | |
| 1515 | |
| 5104 | 1516 VALID_OPT_TAG ("SPAN"); |
| 1517 VALID_TAG ("/SPAN"); | |
| 5174 | 1518 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
| 6982 | 1519 VALID_TAG ("IMG"); |
| 8026 | 1520 VALID_TAG("SPAN"); |
| 8061 | 1521 VALID_OPT_TAG("BR"); |
| 7988 | 1522 |
| 4793 | 1523 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
1524 gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1525 if (e) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1526 *len = e - string + strlen ("-->"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1527 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1528 return TRUE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1529 } |
| 8118 | 1530 } |
| 1531 | |
| 8061 | 1532 *type = -1; |
| 1533 *len = close - string + 1; | |
| 1534 *tag = g_strndup(string, *len - 1); | |
| 1535 return TRUE; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1536 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1537 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1538 static gchar* |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1539 gtk_imhtml_get_html_opt (gchar *tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1540 const gchar *opt) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1541 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1542 gchar *t = tag; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1543 gchar *e, *a; |
| 5177 | 1544 gchar *val; |
| 1545 gint len; | |
| 7280 | 1546 gchar *c; |
| 5177 | 1547 GString *ret; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1548 |
| 4793 | 1549 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1550 gboolean quote = FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1551 if (*t == '\0') break; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1552 while (*t && !((*t == ' ') && !quote)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1553 if (*t == '\"') |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1554 quote = ! quote; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1555 t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1556 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1557 while (*t && (*t == ' ')) t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1558 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1559 |
| 4793 | 1560 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1561 t += strlen (opt); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1562 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1563 return NULL; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1564 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1565 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1566 if ((*t == '\"') || (*t == '\'')) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1567 e = a = ++t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1568 while (*e && (*e != *(t - 1))) e++; |
| 2993 | 1569 if (*e == '\0') { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1570 return NULL; |
| 5177 | 1571 } else |
| 1572 val = g_strndup(a, e - a); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1573 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1574 e = a = t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1575 while (*e && !isspace ((gint) *e)) e++; |
| 5177 | 1576 val = g_strndup(a, e - a); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1577 } |
| 5177 | 1578 |
| 1579 ret = g_string_new(""); | |
| 1580 e = val; | |
| 1581 while(*e) { | |
| 1582 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 7280 | 1583 ret = g_string_append(ret, c); |
| 5177 | 1584 e += len; |
| 1585 } else { | |
| 1586 ret = g_string_append_c(ret, *e); | |
| 1587 e++; | |
| 1588 } | |
| 1589 } | |
| 1590 | |
| 1591 g_free(val); | |
| 8568 | 1592 |
| 1593 return g_string_free(ret, FALSE); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1594 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1595 |
| 8118 | 1596 /* Inline CSS Support - Douglas Thrift */ |
| 1597 static gchar* | |
| 1598 gtk_imhtml_get_css_opt (gchar *style, | |
| 1599 const gchar *opt) | |
| 1600 { | |
| 1601 gchar *t = style; | |
| 1602 gchar *e, *a; | |
| 1603 gchar *val; | |
| 1604 gint len; | |
| 1605 gchar *c; | |
| 1606 GString *ret; | |
| 1607 | |
| 1608 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
| 8177 | 1609 /* gboolean quote = FALSE; */ |
| 8118 | 1610 if (*t == '\0') break; |
| 1611 while (*t && !((*t == ' ') /*&& !quote*/)) { | |
| 1612 /* if (*t == '\"') | |
| 8177 | 1613 quote = ! quote; */ |
| 8118 | 1614 t++; |
| 1615 } | |
| 1616 while (*t && (*t == ' ')) t++; | |
| 1617 } | |
| 1618 | |
| 1619 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
| 1620 t += strlen (opt); | |
| 1621 } else { | |
| 1622 return NULL; | |
| 1623 } | |
| 1624 | |
| 1625 /* if ((*t == '\"') || (*t == '\'')) { | |
| 1626 e = a = ++t; | |
| 1627 while (*e && (*e != *(t - 1))) e++; | |
| 1628 if (*e == '\0') { | |
| 1629 return NULL; | |
| 1630 } else | |
| 1631 val = g_strndup(a, e - a); | |
| 1632 } else { | |
| 1633 e = a = t; | |
| 1634 while (*e && !isspace ((gint) *e)) e++; | |
| 1635 val = g_strndup(a, e - a); | |
| 1636 }*/ | |
| 1637 | |
| 1638 e = a = t; | |
| 1639 while (*e && *e != ';') e++; | |
| 1640 val = g_strndup(a, e - a); | |
| 1641 | |
| 1642 ret = g_string_new(""); | |
| 1643 e = val; | |
| 1644 while(*e) { | |
| 1645 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 1646 ret = g_string_append(ret, c); | |
| 1647 e += len; | |
| 1648 } else { | |
| 1649 ret = g_string_append_c(ret, *e); | |
| 1650 e++; | |
| 1651 } | |
| 1652 } | |
| 1653 | |
| 1654 g_free(val); | |
| 1655 val = ret->str; | |
| 1656 g_string_free(ret, FALSE); | |
| 1657 return val; | |
| 1658 } | |
| 3922 | 1659 |
| 8334 | 1660 static const char *accepted_protocols[] = { |
| 1661 "http://", | |
| 1662 "https://", | |
| 1663 "ftp://" | |
| 1664 }; | |
| 1665 | |
| 1666 static const int accepted_protocols_size = 3; | |
| 1667 | |
| 1668 /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so | |
| 1669 the caller knows how long the protocol string is. */ | |
| 1670 int gtk_imhtml_is_protocol(const char *text) | |
| 1671 { | |
| 1672 gint i; | |
| 1673 | |
| 1674 for(i=0; i<accepted_protocols_size; i++){ | |
| 1675 if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){ | |
| 1676 return strlen(accepted_protocols[i]); | |
| 1677 } | |
| 1678 } | |
| 1679 return 0; | |
| 1680 } | |
| 1681 | |
| 8677 | 1682 /* |
| 1683 <KingAnt> marv: The two IM image functions in oscar are gaim_odc_send_im and gaim_odc_incoming | |
| 1684 | |
| 1685 | |
| 1686 [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :) | |
| 1687 [19:59] <KingAnt> marv: I think the image tag used by the core is something like <img id="#"/> | |
| 1688 [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz | |
| 1689 [20:00] <KingAnt> marv: Where the ID is the what is returned when you add the image to the imgstore using gaim_imgstore_add | |
| 1690 [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? | |
| 1691 [20:00] <KingAnt> marv: Right | |
| 1692 [20:00] <marv> alright | |
| 1693 | |
| 1694 Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just | |
| 1695 gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a | |
| 1696 function for gaim to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that | |
| 1697 images can be looked up like that, instead of passing a GSList of them. | |
| 1698 */ | |
| 1699 | |
| 1700 void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, | |
| 1701 const gchar *text, | |
| 1702 GtkIMHtmlOptions options, | |
| 1703 GSList *unused) | |
| 1428 | 1704 { |
| 8677 | 1705 GtkTextIter iter, ins, sel; |
| 1706 GdkRectangle rect; | |
| 1707 int y, height, ins_offset = 0, sel_offset = 0; | |
| 1708 gboolean fixins = FALSE, fixsel = FALSE; | |
| 1709 | |
| 1710 g_return_if_fail (imhtml != NULL); | |
| 1711 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1712 g_return_if_fail (text != NULL); | |
| 1713 | |
| 1714 | |
| 1715 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); | |
| 1716 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer)); | |
| 1717 if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 1718 fixins = TRUE; | |
| 1719 ins_offset = gtk_text_iter_get_offset(&ins); | |
| 1720 } | |
| 1721 | |
| 1722 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer)); | |
| 1723 if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 1724 fixsel = TRUE; | |
| 1725 sel_offset = gtk_text_iter_get_offset(&sel); | |
| 1726 } | |
| 1727 | |
| 1728 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 1729 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
| 1730 | |
| 1731 | |
| 1732 if(((y + height) - (rect.y + rect.height)) > height | |
| 1733 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
| 1734 options |= GTK_IMHTML_NO_SCROLL; | |
| 1735 } | |
| 1736 | |
| 1737 gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter); | |
| 1738 | |
| 1739 if (fixins) { | |
| 1740 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset); | |
| 1741 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins); | |
| 1742 } | |
| 1743 | |
| 1744 if (fixsel) { | |
| 1745 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset); | |
| 1746 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel); | |
| 1747 } | |
| 1748 | |
| 1749 if (!(options & GTK_IMHTML_NO_SCROLL)) { | |
| 1750 /* If this seems backwards at first glance, well it's not. | |
| 1751 * It means scroll such that the mark is closest to the top, | |
| 1752 * and closest to the right as possible. Remember kids, you have | |
| 1753 * to scroll left to move a given spot closest to the right, | |
| 1754 * and scroll down to move a spot closest to the top. | |
| 1755 */ | |
| 1756 gtk_text_iter_set_line_offset(&iter, 0); | |
| 1757 gtk_text_buffer_move_mark(imhtml->text_buffer, imhtml->scrollpoint, &iter); | |
| 1758 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), imhtml->scrollpoint, | |
| 1759 0, TRUE, 1.0, 0.0); | |
| 1760 } | |
| 1761 } | |
| 1762 | |
| 1763 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, | |
| 1764 const gchar *text, | |
| 1765 GtkIMHtmlOptions options, | |
| 1766 GtkTextIter *iter) | |
| 1767 { | |
| 8061 | 1768 GdkRectangle rect; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1769 gint pos = 0; |
| 3922 | 1770 gchar *ws; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1771 gchar *tag; |
| 3922 | 1772 gchar *bg = NULL; |
| 6982 | 1773 gint len; |
| 4032 | 1774 gint tlen, smilelen, wpos=0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1775 gint type; |
| 3922 | 1776 const gchar *c; |
| 7280 | 1777 gchar *amp; |
| 8334 | 1778 gint len_protocol; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1779 |
| 1428 | 1780 guint bold = 0, |
| 1781 italics = 0, | |
| 1782 underline = 0, | |
| 1783 strike = 0, | |
| 1784 sub = 0, | |
| 1785 sup = 0, | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1786 title = 0, |
| 8061 | 1787 pre = 0; |
| 1428 | 1788 |
| 3922 | 1789 GSList *fonts = NULL; |
| 8506 | 1790 GObject *object; |
| 8061 | 1791 GtkIMHtmlScalable *scalable = NULL; |
| 8677 | 1792 |
| 1793 g_return_if_fail (imhtml != NULL); | |
| 1794 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1795 g_return_if_fail (text != NULL); | |
| 3922 | 1796 c = text; |
| 6982 | 1797 len = strlen(text); |
| 3922 | 1798 ws = g_malloc(len + 1); |
| 1799 ws[0] = 0; | |
| 1428 | 1800 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1801 while (pos < len) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1802 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1803 c++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1804 pos++; |
| 8061 | 1805 ws[wpos] = '\0'; |
| 1806 switch (type) | |
| 3922 | 1807 { |
| 1808 case 1: /* B */ | |
| 1809 case 2: /* BOLD */ | |
| 5101 | 1810 case 54: /* STRONG */ |
| 8677 | 1811 |
| 1812 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 1813 | |
| 1814 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD)) | |
| 8061 | 1815 gtk_imhtml_toggle_bold(imhtml); |
| 3922 | 1816 bold++; |
| 8061 | 1817 ws[0] = '\0'; wpos = 0; |
| 3922 | 1818 break; |
| 1819 case 3: /* /B */ | |
| 1820 case 4: /* /BOLD */ | |
| 5101 | 1821 case 55: /* /STRONG */ |
| 8677 | 1822 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 1823 ws[0] = '\0'; wpos = 0; |
| 1824 | |
| 3922 | 1825 if (bold) |
| 1826 bold--; | |
| 8677 | 1827 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo) |
| 8061 | 1828 gtk_imhtml_toggle_bold(imhtml); |
| 3922 | 1829 break; |
| 1830 case 5: /* I */ | |
| 1831 case 6: /* ITALIC */ | |
| 5101 | 1832 case 52: /* EM */ |
| 8677 | 1833 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 1834 ws[0] = '\0'; wpos = 0; |
| 8677 | 1835 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC)) |
| 8061 | 1836 gtk_imhtml_toggle_italic(imhtml); |
| 3922 | 1837 italics++; |
| 1838 break; | |
| 1839 case 7: /* /I */ | |
| 1840 case 8: /* /ITALIC */ | |
| 5101 | 1841 case 53: /* /EM */ |
| 8677 | 1842 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 1843 ws[0] = '\0'; wpos = 0; |
| 3922 | 1844 if (italics) |
| 1845 italics--; | |
| 8677 | 1846 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo) |
| 8061 | 1847 gtk_imhtml_toggle_italic(imhtml); |
| 3922 | 1848 break; |
| 1849 case 9: /* U */ | |
| 1850 case 10: /* UNDERLINE */ | |
| 8677 | 1851 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 1852 ws[0] = '\0'; wpos = 0; |
| 8677 | 1853 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
| 8061 | 1854 gtk_imhtml_toggle_underline(imhtml); |
| 3922 | 1855 underline++; |
| 1856 break; | |
| 1857 case 11: /* /U */ | |
| 1858 case 12: /* /UNDERLINE */ | |
| 8677 | 1859 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 1860 ws[0] = '\0'; wpos = 0; |
| 3922 | 1861 if (underline) |
| 1862 underline--; | |
| 8677 | 1863 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) |
| 8061 | 1864 gtk_imhtml_toggle_underline(imhtml); |
| 3922 | 1865 break; |
| 1866 case 13: /* S */ | |
| 1867 case 14: /* STRIKE */ | |
| 8677 | 1868 /* FIXME: reimplement this */ |
| 3922 | 1869 strike++; |
| 1870 break; | |
| 1871 case 15: /* /S */ | |
| 1872 case 16: /* /STRIKE */ | |
| 8677 | 1873 /* FIXME: reimplement this */ |
| 3922 | 1874 if (strike) |
| 1875 strike--; | |
| 1876 break; | |
| 1877 case 17: /* SUB */ | |
| 8677 | 1878 /* FIXME: reimpliment this */ |
| 3922 | 1879 sub++; |
| 1880 break; | |
| 1881 case 18: /* /SUB */ | |
| 8677 | 1882 /* FIXME: reimpliment this */ |
| 3922 | 1883 if (sub) |
| 1884 sub--; | |
| 1885 break; | |
| 1886 case 19: /* SUP */ | |
| 8677 | 1887 /* FIXME: reimplement this */ |
| 3922 | 1888 sup++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1889 break; |
| 3922 | 1890 case 20: /* /SUP */ |
| 8677 | 1891 /* FIXME: reimplement this */ |
| 3922 | 1892 if (sup) |
| 1893 sup--; | |
| 1894 break; | |
| 1895 case 21: /* PRE */ | |
| 8677 | 1896 /* FIXME: reimplement this */ |
| 3922 | 1897 pre++; |
| 1898 break; | |
| 1899 case 22: /* /PRE */ | |
| 8677 | 1900 /* FIXME: reimplement this */ |
| 3922 | 1901 if (pre) |
| 1902 pre--; | |
| 1903 break; | |
| 1904 case 23: /* TITLE */ | |
| 8677 | 1905 /* FIXME: what was this supposed to do anyway? */ |
| 3922 | 1906 title++; |
| 1907 break; | |
| 1908 case 24: /* /TITLE */ | |
| 8677 | 1909 /* FIXME: make this undo whatever 23 was supposed to do */ |
| 3922 | 1910 if (title) { |
| 1911 if (options & GTK_IMHTML_NO_TITLE) { | |
| 1912 wpos = 0; | |
| 1913 ws [wpos] = '\0'; | |
| 1914 } | |
| 1915 title--; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1916 } |
| 3922 | 1917 break; |
| 1918 case 25: /* BR */ | |
| 5174 | 1919 case 58: /* BR/ */ |
| 8061 | 1920 case 61: /* BR (opt) */ |
| 3922 | 1921 ws[wpos] = '\n'; |
| 1922 wpos++; | |
| 6982 | 1923 break; |
| 3922 | 1924 case 26: /* HR */ |
| 1925 case 42: /* HR (opt) */ | |
| 8726 | 1926 { |
| 1927 int minus; | |
| 1928 | |
| 3922 | 1929 ws[wpos++] = '\n'; |
| 8677 | 1930 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 1931 | |
| 5967 | 1932 scalable = gtk_imhtml_hr_new(); |
| 8061 | 1933 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 8677 | 1934 scalable->add_to(scalable, imhtml, iter); |
| 8726 | 1935 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
| 1936 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
| 1937 scalable->scale(scalable, rect.width - minus, rect.height); | |
| 8061 | 1938 imhtml->scalables = g_list_append(imhtml->scalables, scalable); |
| 1939 ws[0] = '\0'; wpos = 0; | |
| 7942 | 1940 ws[wpos++] = '\n'; |
| 8061 | 1941 |
| 3922 | 1942 break; |
| 8726 | 1943 } |
| 3922 | 1944 case 27: /* /FONT */ |
| 8677 | 1945 if (fonts && !imhtml->wbfo) { |
| 5967 | 1946 GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 1947 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 1948 ws[0] = '\0'; wpos = 0; |
| 8177 | 1949 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8677 | 1950 |
| 8698 | 1951 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) { |
| 8061 | 1952 gtk_imhtml_toggle_fontface(imhtml, NULL); |
| 3922 | 1953 g_free (font->face); |
| 8061 | 1954 } |
| 8698 | 1955 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 8061 | 1956 gtk_imhtml_toggle_forecolor(imhtml, NULL); |
| 3922 | 1957 g_free (font->fore); |
| 8061 | 1958 } |
| 8698 | 1959 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 8061 | 1960 gtk_imhtml_toggle_backcolor(imhtml, NULL); |
| 3922 | 1961 g_free (font->back); |
| 8061 | 1962 } |
| 4032 | 1963 if (font->sml) |
| 1964 g_free (font->sml); | |
| 3922 | 1965 g_free (font); |
| 8309 | 1966 |
| 8698 | 1967 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 1968 gtk_imhtml_font_set_size(imhtml, 3); |
| 1969 | |
| 1970 fonts = fonts->next; | |
| 1971 if (fonts) { | |
| 1972 GtkIMHtmlFontDetail *font = fonts->data; | |
| 8677 | 1973 |
| 8698 | 1974 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) |
| 8309 | 1975 gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 8698 | 1976 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
| 8309 | 1977 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 8698 | 1978 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
| 8309 | 1979 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
| 8698 | 1980 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 1981 gtk_imhtml_font_set_size(imhtml, font->size); |
| 1982 } | |
| 3922 | 1983 } |
| 8309 | 1984 break; |
| 3922 | 1985 case 28: /* /A */ |
| 8677 | 1986 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 1987 gtk_imhtml_toggle_link(imhtml, NULL); | |
| 1988 ws[0] = '\0'; wpos = 0; | |
| 8061 | 1989 break; |
| 8118 | 1990 |
| 3922 | 1991 case 29: /* P */ |
| 1992 case 30: /* /P */ | |
| 1993 case 31: /* H3 */ | |
| 1994 case 32: /* /H3 */ | |
| 1995 case 33: /* HTML */ | |
| 1996 case 34: /* /HTML */ | |
| 1997 case 35: /* BODY */ | |
| 1998 case 36: /* /BODY */ | |
| 1999 case 37: /* FONT */ | |
| 2000 case 38: /* HEAD */ | |
| 2001 case 39: /* /HEAD */ | |
| 6982 | 2002 case 40: /* BINARY */ |
| 2003 case 41: /* /BINARY */ | |
| 3922 | 2004 break; |
| 2005 case 43: /* FONT (opt) */ | |
| 2006 { | |
| 4032 | 2007 gchar *color, *back, *face, *size, *sml; |
| 5967 | 2008 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 3922 | 2009 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
| 2010 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 2011 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 2012 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 2013 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 2014 if (!(color || back || face || size || sml)) | |
| 3922 | 2015 break; |
| 8061 | 2016 |
| 8677 | 2017 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2018 ws[0] = '\0'; wpos = 0; |
| 2019 | |
| 5967 | 2020 font = g_new0 (GtkIMHtmlFontDetail, 1); |
| 3922 | 2021 if (fonts) |
| 2022 oldfont = fonts->data; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2023 |
| 8677 | 2024 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 3922 | 2025 font->fore = color; |
| 8061 | 2026 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 8677 | 2027 } |
| 8309 | 2028 //else if (oldfont && oldfont->fore) |
| 2029 // font->fore = g_strdup(oldfont->fore); | |
| 8677 | 2030 |
| 2031 if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { | |
| 3922 | 2032 font->back = back; |
| 8061 | 2033 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
| 8309 | 2034 } |
| 2035 //else if (oldfont && oldfont->back) | |
| 2036 // font->back = g_strdup(oldfont->back); | |
| 8677 | 2037 |
| 2038 if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) { | |
| 3922 | 2039 font->face = face; |
| 8061 | 2040 gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 8309 | 2041 } |
| 2042 //else if (oldfont && oldfont->face) | |
| 2043 // font->face = g_strdup(oldfont->face); | |
| 4032 | 2044 |
| 2045 if (sml) | |
| 2046 font->sml = sml; | |
| 2047 else if (oldfont && oldfont->sml) | |
| 2048 font->sml = g_strdup(oldfont->sml); | |
| 2049 | |
| 8677 | 2050 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) { |
| 3922 | 2051 if (*size == '+') { |
| 2052 sscanf (size + 1, "%hd", &font->size); | |
| 2053 font->size += 3; | |
| 2054 } else if (*size == '-') { | |
| 2055 sscanf (size + 1, "%hd", &font->size); | |
| 2056 font->size = MAX (0, 3 - font->size); | |
| 2057 } else if (isdigit (*size)) { | |
| 2058 sscanf (size, "%hd", &font->size); | |
| 8061 | 2059 } |
| 6042 | 2060 if (font->size > 100) |
| 2061 font->size = 100; | |
| 3922 | 2062 } else if (oldfont) |
| 2063 font->size = oldfont->size; | |
| 8309 | 2064 else |
| 2065 font->size = 3; | |
| 8698 | 2066 if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 2067 gtk_imhtml_font_set_size(imhtml, font->size); | |
| 3922 | 2068 g_free(size); |
| 2069 fonts = g_slist_prepend (fonts, font); | |
| 2070 } | |
| 2071 break; | |
| 2072 case 44: /* BODY (opt) */ | |
| 2073 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 2074 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 8677 | 2075 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 2076 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2077 ws[0] = '\0'; wpos = 0; |
| 8177 | 2078 /* NEW_BIT(NEW_TEXT_BIT); */ |
| 3922 | 2079 if (bg) |
| 2080 g_free(bg); | |
| 2081 bg = bgcolor; | |
| 8061 | 2082 gtk_imhtml_toggle_backcolor(imhtml, bg); |
|
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
2083 } |
| 1428 | 2084 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2085 break; |
| 3922 | 2086 case 45: /* A (opt) */ |
| 2087 { | |
| 2088 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 8677 | 2089 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) { |
| 2090 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2091 ws[0] = '\0'; wpos = 0; |
| 8677 | 2092 gtk_imhtml_toggle_link(imhtml, href); |
| 3922 | 2093 } |
| 2993 | 2094 } |
| 3922 | 2095 break; |
| 4895 | 2096 case 46: /* IMG (opt) */ |
| 6982 | 2097 case 59: /* IMG */ |
| 4895 | 2098 { |
| 8677 | 2099 #if 0 |
| 2100 /* disabling this for now, it's easy to add it back... */ | |
| 6982 | 2101 GdkPixbuf *img = NULL; |
| 2102 const gchar *filename = NULL; | |
| 4895 | 2103 |
| 8677 | 2104 if (!(imhtml->format_functions & GTK_IMHTML_IMAGE)) |
| 2105 break; | |
| 2106 | |
| 6982 | 2107 if (images && images->data) { |
| 2108 img = images->data; | |
| 2109 images = images->next; | |
| 2110 filename = g_object_get_data(G_OBJECT(img), "filename"); | |
| 2111 g_object_ref(G_OBJECT(img)); | |
| 2112 } else { | |
| 2113 img = gtk_widget_render_icon(GTK_WIDGET(imhtml), | |
| 2114 GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON, | |
| 2115 "gtkimhtml-missing-image"); | |
| 2116 } | |
| 4895 | 2117 |
| 6982 | 2118 scalable = gtk_imhtml_image_new(img, filename); |
| 8177 | 2119 /* NEW_BIT(NEW_SCALABLE_BIT); */ |
| 8677 | 2120 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 2121 scalable->add_to(scalable, imhtml, iter); | |
| 2122 scalable->scale(scalable, rect.width, rect.height); | |
| 2123 imhtml->scalables = g_list_append(imhtml->scalables, scalable); | |
| 2124 | |
| 6982 | 2125 g_object_unref(G_OBJECT(img)); |
| 8677 | 2126 #endif |
| 4895 | 2127 } |
| 3922 | 2128 case 47: /* P (opt) */ |
| 2129 case 48: /* H3 (opt) */ | |
| 5093 | 2130 case 49: /* HTML (opt) */ |
| 5101 | 2131 case 50: /* CITE */ |
| 2132 case 51: /* /CITE */ | |
| 8026 | 2133 case 56: /* SPAN (opt) */ |
| 8118 | 2134 /* Inline CSS Support - Douglas Thrift |
| 2135 * | |
| 2136 * color | |
| 8686 | 2137 * background |
| 8118 | 2138 * font-family |
| 2139 * font-size | |
| 8686 | 2140 * text-decoration: underline |
| 8118 | 2141 */ |
| 2142 { | |
| 8686 | 2143 gchar *style, *color, *background, *family, *size; |
| 2144 gchar *textdec; | |
| 8118 | 2145 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 2146 style = gtk_imhtml_get_html_opt (tag, "style="); | |
| 2147 | |
| 2148 if (!style) break; | |
| 2149 | |
| 2150 color = gtk_imhtml_get_css_opt (style, "color: "); | |
| 8686 | 2151 background = gtk_imhtml_get_css_opt (style, "background: "); |
| 8118 | 2152 family = gtk_imhtml_get_css_opt (style, |
| 2153 "font-family: "); | |
| 2154 size = gtk_imhtml_get_css_opt (style, "font-size: "); | |
| 8686 | 2155 textdec = gtk_imhtml_get_css_opt (style, "text-decoration: "); |
| 2156 | |
| 2157 if (!(color || family || size || background || textdec)) { | |
| 8120 | 2158 g_free(style); |
| 2159 break; | |
| 2160 } | |
| 8118 | 2161 |
| 8677 | 2162 |
| 2163 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8118 | 2164 ws[0] = '\0'; wpos = 0; |
| 8177 | 2165 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8118 | 2166 |
| 2167 font = g_new0 (GtkIMHtmlFontDetail, 1); | |
| 2168 if (fonts) | |
| 2169 oldfont = fonts->data; | |
| 2170 | |
| 8677 | 2171 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
| 8686 | 2172 { |
| 8118 | 2173 font->fore = color; |
| 8686 | 2174 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 2175 } | |
| 8118 | 2176 else if (oldfont && oldfont->fore) |
| 2177 font->fore = g_strdup(oldfont->fore); | |
| 2178 | |
| 8686 | 2179 if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
| 2180 { | |
| 2181 font->back = background; | |
| 2182 gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
| 2183 } | |
| 2184 else if (oldfont && oldfont->back) | |
| 8118 | 2185 font->back = g_strdup(oldfont->back); |
| 2186 | |
| 8677 | 2187 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) |
| 8686 | 2188 { |
| 8118 | 2189 font->face = family; |
| 8686 | 2190 gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 2191 } | |
| 8118 | 2192 else if (oldfont && oldfont->face) |
| 2193 font->face = g_strdup(oldfont->face); | |
| 2194 if (font->face && (atoi(font->face) > 100)) { | |
| 8677 | 2195 /* WTF is this? */ |
| 8118 | 2196 g_free(font->face); |
| 2197 font->face = g_strdup("100"); | |
| 2198 } | |
| 2199 | |
| 2200 if (oldfont && oldfont->sml) | |
| 2201 font->sml = g_strdup(oldfont->sml); | |
| 2202 | |
| 8677 | 2203 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) { |
| 8686 | 2204 if (g_ascii_strcasecmp(size, "xx-small") == 0) |
| 2205 font->size = 1; | |
| 2206 else if (g_ascii_strcasecmp(size, "smaller") == 0 | |
| 2207 || g_ascii_strcasecmp(size, "x-small") == 0) | |
| 8118 | 2208 font->size = 2; |
| 8686 | 2209 else if (g_ascii_strcasecmp(size, "larger") == 0 |
| 2210 || g_ascii_strcasecmp(size, "medium") == 0) | |
| 8118 | 2211 font->size = 4; |
| 8686 | 2212 else if (g_ascii_strcasecmp(size, "large") == 0) |
| 2213 font->size = 5; | |
| 2214 else if (g_ascii_strcasecmp(size, "x-large") == 0) | |
| 2215 font->size = 6; | |
| 2216 else if (g_ascii_strcasecmp(size, "xx-large") == 0) | |
| 2217 font->size = 7; | |
| 8118 | 2218 else |
| 2219 font->size = 3; | |
| 8686 | 2220 gtk_imhtml_font_set_size(imhtml, font->size); |
| 2221 } | |
| 2222 else if (oldfont) | |
| 2223 { | |
| 2224 font->size = oldfont->size; | |
| 2225 } | |
| 2226 | |
| 2227 if (oldfont) | |
| 2228 { | |
| 2229 font->underline = oldfont->underline; | |
| 2230 } | |
| 2231 if (textdec && font->underline != 1 | |
| 2232 && g_ascii_strcasecmp(size, "underline") == 0 | |
| 2233 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) | |
| 2234 { | |
| 2235 gtk_imhtml_toggle_underline(imhtml); | |
| 2236 font->underline = 1; | |
| 2237 } | |
| 8118 | 2238 |
| 2239 g_free(style); | |
| 2240 g_free(size); | |
| 2241 fonts = g_slist_prepend (fonts, font); | |
| 2242 } | |
| 2243 break; | |
| 5104 | 2244 case 57: /* /SPAN */ |
| 8118 | 2245 /* Inline CSS Support - Douglas Thrift */ |
| 8677 | 2246 if (fonts && !imhtml->wbfo) { |
| 8686 | 2247 GtkIMHtmlFontDetail *oldfont = NULL; |
| 8118 | 2248 GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 2249 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8118 | 2250 ws[0] = '\0'; wpos = 0; |
| 8177 | 2251 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8118 | 2252 fonts = g_slist_remove (fonts, font); |
| 8692 | 2253 if (fonts) |
| 2254 oldfont = fonts->data; | |
| 2255 | |
| 2256 if (!oldfont) { | |
| 2257 gtk_imhtml_font_set_size(imhtml, 3); | |
| 2258 if (font->underline) | |
| 2259 gtk_imhtml_toggle_underline(imhtml); | |
| 2260 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 2261 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 2262 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 8686 | 2263 } |
| 8692 | 2264 else |
| 8686 | 2265 { |
| 8692 | 2266 |
| 2267 if (font->size != oldfont->size) | |
| 2268 gtk_imhtml_font_set_size(imhtml, oldfont->size); | |
| 2269 | |
| 2270 if (font->underline != oldfont->underline) | |
| 2271 gtk_imhtml_toggle_underline(imhtml); | |
| 2272 | |
| 2273 if (!oldfont->face || strcmp(font->face, oldfont->face) != 0) | |
| 2274 gtk_imhtml_toggle_fontface(imhtml, oldfont->face); | |
| 2275 | |
| 2276 if (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0) | |
| 2277 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore); | |
| 2278 | |
| 2279 if (!oldfont->back || strcmp(font->back, oldfont->back) != 0) | |
| 2280 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back); | |
| 8686 | 2281 } |
| 8692 | 2282 |
| 2283 g_free (font->face); | |
| 2284 g_free (font->fore); | |
| 2285 g_free (font->back); | |
| 2286 g_free (font->sml); | |
| 2287 | |
| 8118 | 2288 g_free (font); |
| 2289 } | |
| 2290 break; | |
| 8026 | 2291 case 60: /* SPAN */ |
| 2993 | 2292 break; |
| 8061 | 2293 case 62: /* comment */ |
| 8177 | 2294 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8317 | 2295 ws[wpos] = '\0'; |
| 8677 | 2296 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2297 | |
| 6124 | 2298 if (imhtml->show_comments) |
| 2299 wpos = g_snprintf (ws, len, "%s", tag); | |
| 8177 | 2300 /* NEW_BIT (NEW_COMMENT_BIT); */ |
| 3922 | 2301 break; |
| 2302 default: | |
| 6882 | 2303 break; |
| 2993 | 2304 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2305 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2306 pos += tlen; |
| 4138 | 2307 if(tag) |
| 2308 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
| 8473 | 2309 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
| 2310 GtkIMHtmlFontDetail *fd; | |
| 2311 | |
| 2312 gchar *sml = NULL; | |
| 2313 if (fonts) { | |
| 2314 fd = fonts->data; | |
| 2315 sml = fd->sml; | |
| 2316 } | |
| 8677 | 2317 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8505 | 2318 wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
| 8473 | 2319 |
| 8677 | 2320 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter); |
| 8473 | 2321 |
| 8505 | 2322 c += smilelen; |
| 2323 pos += smilelen; | |
| 8473 | 2324 wpos = 0; |
| 2325 ws[0] = 0; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2326 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
| 7280 | 2327 while(*amp) { |
| 2328 ws [wpos++] = *amp++; | |
| 2329 } | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2330 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2331 pos += tlen; |
| 1428 | 2332 } else if (*c == '\n') { |
| 2333 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 2334 ws[wpos] = '\n'; |
| 2335 wpos++; | |
| 8677 | 2336 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2337 ws[0] = '\0'; |
| 2338 wpos = 0; | |
| 8177 | 2339 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 1428 | 2340 } |
| 2341 c++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2342 pos++; |
| 8334 | 2343 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ |
| 2344 while(len_protocol--){ | |
| 8677 | 2345 /* Skip the next len_protocol characters, but make sure they're |
| 8334 | 2346 copied into the ws array. |
| 2347 */ | |
| 2348 ws [wpos++] = *c++; | |
| 2349 pos++; | |
| 2350 } | |
| 8061 | 2351 } else if (*c) { |
| 1428 | 2352 ws [wpos++] = *c++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2353 pos++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2354 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2355 break; |
| 1428 | 2356 } |
| 2357 } | |
| 8677 | 2358 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2359 ws[0] = '\0'; wpos = 0; |
| 2360 | |
| 8177 | 2361 /* NEW_BIT(NEW_TEXT_BIT); */ |
| 8061 | 2362 |
| 4032 | 2363 while (fonts) { |
| 5967 | 2364 GtkIMHtmlFontDetail *font = fonts->data; |
| 4032 | 2365 fonts = g_slist_remove (fonts, font); |
| 2366 if (font->face) | |
| 2367 g_free (font->face); | |
| 2368 if (font->fore) | |
| 2369 g_free (font->fore); | |
| 2370 if (font->back) | |
| 2371 g_free (font->back); | |
| 2372 if (font->sml) | |
| 2373 g_free (font->sml); | |
| 2374 g_free (font); | |
| 8677 | 2375 //if (str) |
| 2376 // str = g_string_append (str, "</FONT>"); | |
| 4032 | 2377 } |
| 8677 | 2378 #if 0 |
| 3922 | 2379 if (str) { |
| 1428 | 2380 while (bold) { |
| 8677 | 2381 // str = g_string_append (str, "</B>"); |
| 1428 | 2382 bold--; |
| 2383 } | |
| 2384 while (italics) { | |
| 8677 | 2385 // str = g_string_append (str, "</I>"); |
| 1428 | 2386 italics--; |
| 2387 } | |
| 2388 while (underline) { | |
| 8677 | 2389 //str = g_string_append (str, "</U>"); |
| 1428 | 2390 underline--; |
| 2391 } | |
| 2392 while (strike) { | |
| 8677 | 2393 //str = g_string_append (str, "</S>"); |
| 1428 | 2394 strike--; |
| 2395 } | |
| 2396 while (sub) { | |
| 8677 | 2397 //str = g_string_append (str, "</SUB>"); |
| 1428 | 2398 sub--; |
| 2399 } | |
| 2400 while (sup) { | |
| 8677 | 2401 //str = g_string_append (str, "</SUP>"); |
| 1428 | 2402 sup--; |
| 2403 } | |
| 2404 while (title) { | |
| 8677 | 2405 //str = g_string_append (str, "</TITLE>"); |
| 1428 | 2406 title--; |
| 2407 } | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2408 while (pre) { |
| 8677 | 2409 //str = g_string_append (str, "</PRE>"); |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2410 pre--; |
|
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2411 } |
| 1428 | 2412 } |
| 8677 | 2413 #endif |
| 4032 | 2414 g_free (ws); |
| 4630 | 2415 if(bg) |
| 2416 g_free(bg); | |
| 8677 | 2417 |
| 2418 if (!imhtml->wbfo) | |
| 8698 | 2419 gtk_imhtml_close_tags(imhtml, iter); |
| 8506 | 2420 |
| 2421 object = g_object_ref(G_OBJECT(imhtml)); | |
| 2422 g_signal_emit(object, signals[UPDATE_FORMAT], 0); | |
| 2423 g_object_unref(object); | |
| 2424 | |
| 3922 | 2425 } |
| 2426 | |
| 4892 | 2427 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 2428 { | |
| 4288 | 2429 g_hash_table_destroy(imhtml->smiley_data); |
| 2430 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 4892 | 2431 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 2432 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4288 | 2433 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 2434 } | |
| 8481 | 2435 |
| 3922 | 2436 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
| 4253 | 2437 gboolean show) |
| 2438 { | |
| 2439 imhtml->show_smileys = show; | |
| 2440 } | |
| 3922 | 2441 |
| 2442 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 4253 | 2443 gboolean show) |
| 2444 { | |
| 6124 | 2445 imhtml->show_comments = show; |
| 4253 | 2446 } |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2447 |
| 8456 | 2448 void gtk_imhtml_html_shortcuts (GtkIMHtml *imhtml, |
| 2449 gboolean allow) | |
| 2450 { | |
| 2451 imhtml->html_shortcuts = allow; | |
| 2452 } | |
| 2453 | |
| 2454 void gtk_imhtml_smiley_shortcuts (GtkIMHtml *imhtml, | |
| 2455 gboolean allow) | |
| 2456 { | |
| 2457 imhtml->smiley_shortcuts = allow; | |
| 2458 } | |
| 2459 | |
| 2460 void | |
| 2461 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, gchar *protocol_name) { | |
| 2462 imhtml->protocol_name = protocol_name; | |
| 2463 } | |
| 2464 | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2465 void |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2466 gtk_imhtml_clear (GtkIMHtml *imhtml) |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2467 { |
| 7991 | 2468 GList *del; |
| 3922 | 2469 GtkTextIter start, end; |
| 8427 | 2470 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
| 7991 | 2471 |
| 3922 | 2472 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 2473 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 2474 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
| 7991 | 2475 |
| 2476 for(del = imhtml->scalables; del; del = del->next) { | |
| 2477 GtkIMHtmlScalable *scale = del->data; | |
| 2478 scale->free(scale); | |
| 2479 } | |
| 2480 g_list_free(imhtml->scalables); | |
| 2481 imhtml->scalables = NULL; | |
| 8061 | 2482 |
| 8719 | 2483 gtk_imhtml_close_tags(imhtml, &start); |
| 8481 | 2484 |
| 8427 | 2485 g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
| 2486 g_object_unref(object); | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2487 } |
|
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
2488 |
| 4046 | 2489 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 2490 { | |
| 5282 | 2491 GdkRectangle rect; |
| 2492 GtkTextIter iter; | |
| 4046 | 2493 |
| 5282 | 2494 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 2495 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 2496 rect.y - rect.height); | |
| 2497 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 8061 | 2498 |
| 4046 | 2499 } |
| 5282 | 2500 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
| 2501 { | |
| 2502 GdkRectangle rect; | |
| 2503 GtkTextIter iter; | |
| 2504 | |
| 2505 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 2506 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 2507 rect.y + rect.height); | |
| 2508 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 2509 } | |
| 4735 | 2510 |
| 5967 | 2511 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
| 6982 | 2512 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename) |
| 4735 | 2513 { |
| 5967 | 2514 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
| 5012 | 2515 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
| 4895 | 2516 |
| 5967 | 2517 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
| 2518 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
| 2519 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
| 5046 | 2520 |
| 2521 im_image->pixbuf = img; | |
| 5012 | 2522 im_image->image = image; |
| 4895 | 2523 im_image->width = gdk_pixbuf_get_width(img); |
| 2524 im_image->height = gdk_pixbuf_get_height(img); | |
| 2525 im_image->mark = NULL; | |
| 6982 | 2526 im_image->filename = filename ? g_strdup(filename) : NULL; |
| 4895 | 2527 |
| 5046 | 2528 g_object_ref(img); |
| 4895 | 2529 return GTK_IMHTML_SCALABLE(im_image); |
| 2530 } | |
| 2531 | |
| 5967 | 2532 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
| 4895 | 2533 { |
| 5967 | 2534 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
| 4895 | 2535 |
| 2536 if(image->width > width || image->height > height){ | |
| 2537 GdkPixbuf *new_image = NULL; | |
| 2538 float factor; | |
| 2539 int new_width = image->width, new_height = image->height; | |
| 2540 | |
| 8588 | 2541 if(image->width > (width - 2)){ |
| 4895 | 2542 factor = (float)(width)/image->width; |
| 2543 new_width = width; | |
| 2544 new_height = image->height * factor; | |
| 2545 } | |
| 8588 | 2546 if(new_height >= (height - 2)){ |
| 4895 | 2547 factor = (float)(height)/new_height; |
| 2548 new_height = height; | |
| 2549 new_width = new_width * factor; | |
| 2550 } | |
| 2551 | |
| 5046 | 2552 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); |
| 5012 | 2553 gtk_image_set_from_pixbuf(image->image, new_image); |
| 4895 | 2554 g_object_unref(G_OBJECT(new_image)); |
| 2555 } | |
| 2556 } | |
| 2557 | |
| 5012 | 2558 static void write_img_to_file(GtkWidget *w, GtkFileSelection *sel) |
| 2559 { | |
| 2560 const gchar *filename = gtk_file_selection_get_filename(sel); | |
| 5967 | 2561 gchar *dirname; |
| 2562 GtkIMHtmlImage *image = g_object_get_data(G_OBJECT(sel), "GtkIMHtmlImage"); | |
| 5012 | 2563 gchar *type = NULL; |
| 5019 | 2564 GError *error = NULL; |
| 5015 | 2565 #if GTK_CHECK_VERSION(2,2,0) |
| 5012 | 2566 GSList *formats = gdk_pixbuf_get_formats(); |
| 6162 | 2567 #else |
| 2568 char *basename = g_path_get_basename(filename); | |
| 2569 char *ext = strrchr(basename, '.'); | |
| 5959 | 2570 #endif |
| 5012 | 2571 |
| 5967 | 2572 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { |
| 2573 /* append a / if needed */ | |
| 2574 if (filename[strlen(filename) - 1] != '/') { | |
| 2575 dirname = g_strconcat(filename, "/", NULL); | |
| 2576 } else { | |
| 2577 dirname = g_strdup(filename); | |
| 2578 } | |
| 2579 gtk_file_selection_set_filename(sel, dirname); | |
| 2580 g_free(dirname); | |
| 5959 | 2581 return; |
| 5967 | 2582 } |
| 5959 | 2583 |
| 2584 #if GTK_CHECK_VERSION(2,2,0) | |
| 5012 | 2585 while(formats){ |
| 2586 GdkPixbufFormat *format = formats->data; | |
| 2587 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
| 2588 gpointer p = extensions; | |
| 2589 | |
| 2590 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
| 2591 gchar *fmt_ext = extensions[0]; | |
| 2592 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
| 2593 | |
| 2594 if(!strcmp(fmt_ext, file_ext)){ | |
| 2595 type = gdk_pixbuf_format_get_name(format); | |
| 2596 break; | |
| 2597 } | |
| 2598 | |
| 2599 extensions++; | |
| 2600 } | |
| 2601 | |
| 2602 g_strfreev(p); | |
| 2603 | |
| 2604 if(type) | |
| 2605 break; | |
| 2606 | |
| 2607 formats = formats->next; | |
| 2608 } | |
| 2609 | |
| 5020 | 2610 g_slist_free(formats); |
| 2611 #else | |
| 2612 /* this is really ugly code, but I think it will work */ | |
| 2613 if(ext) { | |
| 2614 ext++; | |
| 2615 if(!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) | |
| 2616 type = g_strdup("jpeg"); | |
| 2617 else if(!g_ascii_strcasecmp(ext, "png")) | |
| 2618 type = g_strdup("png"); | |
| 2619 } | |
| 2620 | |
| 2621 g_free(basename); | |
| 2622 #endif | |
| 2623 | |
| 5012 | 2624 /* If I can't find a valid type, I will just tell the user about it and then assume |
| 2625 it's a png */ | |
| 2626 if(!type){ | |
| 2627 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 5967 | 2628 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG.")); |
| 5012 | 2629 type = g_strdup("png"); |
| 2630 } | |
| 2631 | |
| 5046 | 2632 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
| 5012 | 2633 |
| 2634 if(error){ | |
| 2635 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 2636 _("Error saving image: %s"), error->message); | |
| 2637 g_error_free(error); | |
| 2638 } | |
| 2639 | |
| 2640 g_free(type); | |
| 2641 } | |
| 2642 | |
| 5967 | 2643 static void gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) |
| 5012 | 2644 { |
| 5967 | 2645 GtkWidget *sel = gtk_file_selection_new(_("Save Image")); |
| 5012 | 2646 |
| 6982 | 2647 if (image->filename) |
| 2648 gtk_file_selection_set_filename(GTK_FILE_SELECTION(sel), image->filename); | |
| 5967 | 2649 g_object_set_data(G_OBJECT(sel), "GtkIMHtmlImage", image); |
| 5012 | 2650 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", |
| 2651 G_CALLBACK(write_img_to_file), sel); | |
| 2652 | |
| 2653 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", | |
| 2654 G_CALLBACK(gtk_widget_destroy), sel); | |
| 2655 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->cancel_button), "clicked", | |
| 8061 | 2656 G_CALLBACK(gtk_widget_destroy), sel); |
| 5012 | 2657 |
| 2658 gtk_widget_show(sel); | |
| 2659 } | |
| 2660 | |
| 5967 | 2661 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
| 5012 | 2662 { |
| 2663 GdkEventButton *event_button = (GdkEventButton *) event; | |
| 2664 | |
| 2665 if (event->type == GDK_BUTTON_RELEASE) { | |
| 2666 if(event_button->button == 3) { | |
| 2667 GtkWidget *img, *item, *menu; | |
| 2668 gchar *text = g_strdup_printf(_("_Save Image...")); | |
| 2669 menu = gtk_menu_new(); | |
| 2670 | |
| 2671 /* buttons and such */ | |
| 2672 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
| 2673 item = gtk_image_menu_item_new_with_mnemonic(text); | |
| 2674 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 5967 | 2675 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
| 5012 | 2676 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
| 2677 | |
| 2678 gtk_widget_show_all(menu); | |
| 2679 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 2680 event_button->button, event_button->time); | |
| 2681 | |
| 2682 g_free(text); | |
| 2683 return TRUE; | |
| 2684 } | |
| 2685 } | |
| 2686 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
| 2687 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 2688 be caught by the regular GtkTextView menu */ | |
| 2689 else | |
| 2690 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 2691 | |
| 2692 } | |
| 5967 | 2693 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
| 2694 { | |
| 2695 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 2696 | |
| 2697 g_object_unref(image->pixbuf); | |
| 6982 | 2698 if (image->filename) |
| 2699 g_free(image->filename); | |
| 5967 | 2700 g_free(scale); |
| 2701 } | |
| 2702 | |
| 2703 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 2704 { | |
| 2705 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 2706 GtkWidget *box = gtk_event_box_new(); | |
| 2707 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 2708 | |
| 2709 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
| 2710 | |
| 2711 gtk_widget_show(GTK_WIDGET(image->image)); | |
| 2712 gtk_widget_show(box); | |
| 2713 | |
| 2714 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); | |
| 2715 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
| 2716 } | |
| 2717 | |
| 2718 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
| 2719 { | |
| 2720 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
| 2721 | |
| 2722 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
| 2723 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
| 2724 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
| 2725 | |
| 2726 hr->sep = gtk_hseparator_new(); | |
| 2727 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
| 2728 gtk_widget_show(hr->sep); | |
| 2729 | |
| 2730 return GTK_IMHTML_SCALABLE(hr); | |
| 2731 } | |
| 2732 | |
| 2733 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
| 2734 { | |
| 8588 | 2735 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width - 2, 2); |
| 5967 | 2736 } |
| 2737 | |
| 2738 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 2739 { | |
| 2740 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
| 2741 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 8698 | 2742 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>"); |
| 2743 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n"); | |
| 5967 | 2744 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); |
| 2745 } | |
| 2746 | |
| 2747 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
| 2748 { | |
| 2749 g_free(scale); | |
| 2750 } | |
| 7295 | 2751 |
| 2752 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
| 2753 { | |
| 2754 GtkTextIter iter, start, end; | |
| 2755 gboolean new_search = TRUE; | |
| 2756 | |
| 2757 g_return_val_if_fail(imhtml != NULL, FALSE); | |
| 2758 g_return_val_if_fail(text != NULL, FALSE); | |
| 8061 | 2759 |
| 7295 | 2760 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) |
| 2761 new_search = FALSE; | |
| 8061 | 2762 |
| 7295 | 2763 if (new_search) { |
| 2764 gtk_imhtml_search_clear(imhtml); | |
| 2765 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 2766 } else { | |
| 2767 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
| 8061 | 2768 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); |
| 7295 | 2769 } |
| 2770 imhtml->search_string = g_strdup(text); | |
| 2771 | |
| 7358 | 2772 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
| 2773 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
| 7295 | 2774 &start, &end, NULL)) { |
| 2775 | |
| 2776 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
| 2777 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
| 2778 if (new_search) { | |
| 2779 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
| 8061 | 2780 do |
| 7295 | 2781 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); |
| 8061 | 2782 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
| 2783 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
| 7358 | 2784 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
| 7295 | 2785 &start, &end, NULL)); |
| 2786 } | |
| 2787 return TRUE; | |
| 2788 } | |
| 8061 | 2789 |
| 2790 gtk_imhtml_search_clear(imhtml); | |
| 2791 | |
| 7295 | 2792 return FALSE; |
| 2793 } | |
| 2794 | |
| 2795 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
| 2796 { | |
| 2797 GtkTextIter start, end; | |
| 8061 | 2798 |
| 7295 | 2799 g_return_if_fail(imhtml != NULL); |
| 8061 | 2800 |
| 7295 | 2801 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 2802 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 2803 | |
| 2804 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
| 2805 if (imhtml->search_string) | |
| 2806 g_free(imhtml->search_string); | |
| 2807 imhtml->search_string = NULL; | |
| 2808 } | |
| 8061 | 2809 |
| 8677 | 2810 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color) |
| 2811 { | |
| 2812 gchar str[18]; | |
| 2813 GtkTextTag *tag; | |
| 2814 | |
| 2815 g_snprintf(str, sizeof(str), "FORECOLOR %s", color); | |
| 2816 | |
| 2817 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 2818 if (!tag) | |
| 2819 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", color, NULL); | |
| 2820 | |
| 2821 return tag; | |
| 2822 } | |
| 2823 | |
| 2824 static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color) | |
| 2825 { | |
| 2826 gchar str[18]; | |
| 2827 GtkTextTag *tag; | |
| 2828 | |
| 2829 g_snprintf(str, sizeof(str), "BACKCOLOR %s", color); | |
| 2830 | |
| 2831 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 2832 if (!tag) | |
| 2833 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background", color, NULL); | |
| 2834 | |
| 2835 return tag; | |
| 2836 } | |
| 2837 | |
| 2838 static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face) | |
| 8061 | 2839 { |
| 8677 | 2840 gchar str[256]; |
| 2841 GtkTextTag *tag; | |
| 2842 | |
| 2843 g_snprintf(str, sizeof(str), "FONT FACE %s", face); | |
| 2844 str[255] = '\0'; | |
| 2845 | |
| 2846 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 2847 if (!tag) | |
| 2848 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL); | |
| 2849 | |
| 2850 return tag; | |
| 2851 } | |
| 2852 | |
| 2853 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) | |
| 2854 { | |
| 2855 gchar str[24]; | |
| 2856 GtkTextTag *tag; | |
| 2857 | |
| 2858 g_snprintf(str, sizeof(str), "FONT SIZE %d", size); | |
| 2859 str[23] = '\0'; | |
| 2860 | |
| 2861 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 2862 if (!tag) { | |
| 2863 /* For reasons I don't understand, setting "scale" here scaled based on some default | |
| 2864 * size other than my theme's default size. Our size 4 was actually smaller than | |
| 2865 * our size 3 for me. So this works around that oddity. | |
| 2866 */ | |
| 2867 GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); | |
| 2868 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", | |
| 2869 (gint) (pango_font_description_get_size(attr->font) * | |
| 2870 (double) _point_sizes[size-1]), NULL); | |
| 2871 gtk_text_attributes_unref(attr); | |
| 8061 | 2872 } |
| 2873 | |
| 8677 | 2874 return tag; |
| 2875 } | |
| 2876 | |
| 2877 static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e, | |
| 2878 const char *prefix, guint len, gboolean homo) | |
| 2879 { | |
| 2880 GSList *tags, *l; | |
| 2881 GtkTextIter iter; | |
| 2882 | |
| 2883 tags = gtk_text_iter_get_tags(i); | |
| 2884 | |
| 2885 for (l = tags; l; l = l->next) { | |
| 2886 GtkTextTag *tag = l->data; | |
| 2887 | |
| 2888 if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 2889 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e); | |
| 8061 | 2890 } |
| 2891 | |
| 8677 | 2892 g_slist_free(tags); |
| 2893 | |
| 2894 if (homo) | |
| 2895 return; | |
| 2896 | |
| 2897 iter = *i; | |
| 2898 | |
| 2899 while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) { | |
| 2900 if (gtk_text_iter_begins_tag(&iter, NULL)) { | |
| 2901 tags = gtk_text_iter_get_toggled_tags(&iter, TRUE); | |
| 2902 | |
| 2903 for (l = tags; l; l = l->next) { | |
| 2904 GtkTextTag *tag = l->data; | |
| 2905 | |
| 2906 if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 2907 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e); | |
| 2908 } | |
| 2909 | |
| 2910 g_slist_free(tags); | |
| 2911 } | |
| 8061 | 2912 } |
| 8677 | 2913 } |
| 2914 | |
| 2915 static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 2916 { | |
| 2917 remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo); | |
| 2918 } | |
| 2919 | |
| 2920 static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 2921 { | |
| 2922 remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo); | |
| 2923 } | |
| 2924 | |
| 2925 static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 2926 { | |
| 2927 remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo); | |
| 2928 } | |
| 2929 | |
| 2930 static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 2931 { | |
| 2932 remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo); | |
| 2933 } | |
| 2934 | |
| 2935 static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 2936 { | |
| 2937 remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo); | |
| 2938 } | |
| 2939 | |
| 2940 /* Editable stuff */ | |
| 2941 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 2942 { | |
| 2943 imhtml->insert_offset = gtk_text_iter_get_offset(iter); | |
| 2944 } | |
| 2945 | |
| 2946 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 2947 { | |
| 2948 GtkTextIter start; | |
| 2949 | |
| 2950 if (!len) | |
| 2951 return; | |
| 2952 | |
| 2953 start = *end; | |
| 2954 gtk_text_iter_set_offset(&start, imhtml->insert_offset); | |
| 2955 | |
| 2956 if (imhtml->edit.bold) | |
| 2957 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, end); | |
| 2958 else | |
| 2959 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, end); | |
| 2960 | |
| 2961 if (imhtml->edit.italic) | |
| 2962 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, end); | |
| 2963 else | |
| 2964 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, end); | |
| 2965 | |
| 2966 if (imhtml->edit.underline) | |
| 2967 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); | |
| 2968 else | |
| 2969 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); | |
| 2970 | |
| 2971 if (imhtml->edit.forecolor) { | |
| 2972 remove_font_forecolor(imhtml, &start, end, TRUE); | |
| 2973 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 2974 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
| 2975 &start, end); | |
| 8061 | 2976 } |
| 2977 | |
| 8677 | 2978 if (imhtml->edit.backcolor) { |
| 2979 remove_font_backcolor(imhtml, &start, end, TRUE); | |
| 2980 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 2981 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), | |
| 2982 &start, end); | |
| 2983 } | |
| 2984 | |
| 2985 if (imhtml->edit.fontface) { | |
| 2986 remove_font_face(imhtml, &start, end, TRUE); | |
| 2987 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 2988 find_font_face_tag(imhtml, imhtml->edit.fontface), | |
| 2989 &start, end); | |
| 8061 | 2990 } |
| 8677 | 2991 |
| 2992 if (imhtml->edit.fontsize) { | |
| 2993 remove_font_size(imhtml, &start, end, TRUE); | |
| 2994 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 2995 find_font_size_tag(imhtml, imhtml->edit.fontsize), | |
| 2996 &start, end); | |
| 2997 } | |
| 2998 | |
| 2999 if (imhtml->edit.link) { | |
| 3000 remove_font_link(imhtml, &start, end, TRUE); | |
| 3001 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3002 imhtml->edit.link, | |
| 3003 &start, end); | |
| 3004 } | |
| 3005 | |
| 8061 | 3006 } |
| 3007 | |
| 3008 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
| 3009 { | |
| 3010 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
| 8177 | 3011 /* |
| 3012 * We need a visible caret for accessibility, so mouseless | |
| 3013 * people can highlight stuff. | |
| 3014 */ | |
| 3015 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ | |
| 8061 | 3016 imhtml->editable = editable; |
| 8677 | 3017 imhtml->format_functions = GTK_IMHTML_ALL; |
| 3018 | |
| 3019 if (editable) | |
| 3020 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 3021 G_CALLBACK(mark_set_cb), imhtml); | |
| 3022 } | |
| 3023 | |
| 3024 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo) | |
| 3025 { | |
| 3026 g_return_if_fail(imhtml != NULL); | |
| 3027 | |
| 3028 imhtml->wbfo = wbfo; | |
| 8420 | 3029 } |
| 3030 | |
| 3031 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | |
| 3032 { | |
| 3033 GObject *object = g_object_ref(G_OBJECT(imhtml)); | |
| 8677 | 3034 imhtml->format_functions = buttons; |
| 8420 | 3035 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
| 3036 g_object_unref(object); | |
| 8061 | 3037 } |
| 3038 | |
| 8516 | 3039 |
| 3040 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
| 3041 gboolean *italic, gboolean *underline) | |
| 8481 | 3042 { |
| 8677 | 3043 if (imhtml->edit.bold) |
| 3044 (*bold) = TRUE; | |
| 3045 if (imhtml->edit.italic) | |
| 3046 (*italic) = TRUE; | |
| 3047 if (imhtml->edit.underline) | |
| 3048 (*underline) = TRUE; | |
| 8481 | 3049 } |
| 3050 | |
| 8061 | 3051 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) |
| 3052 { | |
| 3053 return imhtml->editable; | |
| 3054 } | |
| 3055 | |
| 8677 | 3056 /* |
| 3057 * I had this crazy idea about changing the text cursor color to reflex the foreground color | |
| 3058 * of the text about to be entered. This is the place you'd do it, along with the place where | |
| 3059 * we actually set a new foreground color. | |
| 3060 * I may not do this, because people will bitch about Gaim overriding their gtk theme's cursor | |
| 3061 * colors. | |
| 3062 * | |
| 3063 * Just in case I do do this, I asked about what to set the secondary text cursor to. | |
| 3064 * | |
| 8719 | 3065 * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2 |
| 3066 * (12:45:55) ?? ???: understand? | |
| 8677 | 3067 * (12:46:14) Tim: yeah. i didn't know there was an exact formula |
| 8719 | 3068 * (12:46:56) ?? ???: u might need to exactract separate each color from RGB |
| 8677 | 3069 */ |
| 3070 | |
| 3071 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, | |
| 3072 GtkIMHtml *imhtml) | |
| 3073 { | |
| 3074 GSList *tags, *l; | |
| 3075 GtkTextIter iter; | |
| 3076 | |
| 3077 if (mark != gtk_text_buffer_get_insert(buffer)) | |
| 3078 return; | |
| 3079 | |
| 3080 if (!gtk_text_buffer_get_char_count(buffer)) | |
| 3081 return; | |
| 3082 | |
| 3083 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = FALSE; | |
| 3084 if (imhtml->edit.forecolor) | |
| 3085 g_free(imhtml->edit.forecolor); | |
| 3086 imhtml->edit.forecolor = NULL; | |
| 3087 if (imhtml->edit.backcolor) | |
| 3088 g_free(imhtml->edit.backcolor); | |
| 3089 imhtml->edit.backcolor = NULL; | |
| 3090 if (imhtml->edit.fontface) | |
| 3091 g_free(imhtml->edit.fontface); | |
| 3092 imhtml->edit.fontface = NULL; | |
| 3093 imhtml->edit.fontsize = 0; | |
| 3094 imhtml->edit.link = NULL; | |
| 3095 | |
| 3096 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 3097 | |
| 3098 | |
| 3099 if (gtk_text_iter_is_end(&iter)) | |
| 3100 tags = gtk_text_iter_get_toggled_tags(&iter, FALSE); | |
| 3101 else | |
| 3102 tags = gtk_text_iter_get_tags(&iter); | |
| 3103 | |
| 3104 for (l = tags; l != NULL; l = l->next) { | |
| 3105 GtkTextTag *tag = GTK_TEXT_TAG(l->data); | |
| 3106 | |
| 3107 if (tag->name) { | |
| 3108 if (strcmp(tag->name, "BOLD") == 0) | |
| 3109 imhtml->edit.bold = TRUE; | |
| 3110 if (strcmp(tag->name, "ITALICS") == 0) | |
| 3111 imhtml->edit.italic = TRUE; | |
| 3112 if (strcmp(tag->name, "UNDERLINE") == 0) | |
| 3113 imhtml->edit.underline = TRUE; | |
| 3114 if (strncmp(tag->name, "FORECOLOR ", 10) == 0) | |
| 3115 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); | |
| 3116 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) | |
| 3117 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); | |
| 3118 if (strncmp(tag->name, "FONT FACE ", 10) == 0) | |
| 3119 imhtml->edit.fontface = g_strdup(&(tag->name)[10]); | |
| 3120 if (strncmp(tag->name, "FONT SIZE ", 10) == 0) | |
| 3121 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10); | |
| 8719 | 3122 if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter)) |
| 8677 | 3123 imhtml->edit.link = tag; |
| 3124 } | |
| 3125 } | |
| 3126 | |
| 3127 g_slist_free(tags); | |
| 3128 } | |
| 3129 | |
| 8061 | 3130 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
| 3131 { | |
| 8481 | 3132 GObject *object; |
| 8677 | 3133 GtkTextIter start, end; |
| 3134 | |
| 3135 imhtml->edit.bold = !imhtml->edit.bold; | |
| 3136 | |
| 3137 if (imhtml->wbfo) { | |
| 3138 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3139 if (imhtml->edit.bold) | |
| 3140 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3141 else | |
| 3142 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3143 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3144 if (imhtml->edit.bold) | |
| 3145 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3146 else | |
| 3147 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3148 | |
| 8061 | 3149 } |
| 8481 | 3150 object = g_object_ref(G_OBJECT(imhtml)); |
| 3151 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD); | |
| 3152 g_object_unref(object); | |
| 3153 | |
| 8677 | 3154 return (imhtml->edit.bold != FALSE); |
| 8061 | 3155 } |
| 3156 | |
| 3157 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) | |
| 3158 { | |
| 8481 | 3159 GObject *object; |
| 8677 | 3160 GtkTextIter start, end; |
| 3161 | |
| 3162 imhtml->edit.italic = !imhtml->edit.italic; | |
| 3163 | |
| 3164 if (imhtml->wbfo) { | |
| 3165 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3166 if (imhtml->edit.italic) | |
| 3167 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 3168 else | |
| 3169 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 3170 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3171 if (imhtml->edit.italic) | |
| 3172 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 3173 else | |
| 3174 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 8061 | 3175 } |
| 8481 | 3176 object = g_object_ref(G_OBJECT(imhtml)); |
| 3177 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_ITALIC); | |
| 3178 g_object_unref(object); | |
| 3179 | |
| 8677 | 3180 return imhtml->edit.italic != FALSE; |
| 8061 | 3181 } |
| 3182 | |
| 3183 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) | |
| 3184 { | |
| 8481 | 3185 GObject *object; |
| 8677 | 3186 GtkTextIter start, end; |
| 3187 | |
| 3188 imhtml->edit.underline = !imhtml->edit.underline; | |
| 3189 | |
| 3190 if (imhtml->wbfo) { | |
| 3191 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3192 if (imhtml->edit.underline) | |
| 3193 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 3194 else | |
| 3195 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 3196 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3197 if (imhtml->edit.underline) | |
| 3198 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 3199 else | |
| 3200 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 8061 | 3201 } |
| 8481 | 3202 object = g_object_ref(G_OBJECT(imhtml)); |
| 3203 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE); | |
| 3204 g_object_unref(object); | |
| 3205 | |
| 8677 | 3206 return imhtml->edit.underline != FALSE; |
| 8061 | 3207 } |
| 3208 | |
| 3209 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) | |
| 3210 { | |
| 8677 | 3211 GtkTextIter start, end; |
| 8061 | 3212 |
| 3213 imhtml->edit.fontsize = size; | |
| 3214 | |
| 8677 | 3215 |
| 3216 if (imhtml->wbfo) { | |
| 3217 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3218 remove_font_size(imhtml, &start, &end, TRUE); | |
| 3219 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3220 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 3221 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3222 remove_font_size(imhtml, &start, &end, FALSE); | |
| 3223 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3224 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 3225 } |
| 8677 | 3226 |
| 8061 | 3227 } |
| 3228 | |
| 3229 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) | |
| 3230 { | |
| 8677 | 3231 GtkTextIter start, end; |
| 3232 | |
| 8061 | 3233 if (imhtml->edit.fontsize == 1) |
| 3234 return; | |
| 3235 | |
| 8677 | 3236 if (!imhtml->edit.fontsize) |
| 3237 imhtml->edit.fontsize = 2; | |
| 3238 else | |
| 3239 imhtml->edit.fontsize--; | |
| 3240 | |
| 3241 if (imhtml->wbfo) { | |
| 3242 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3243 remove_font_size(imhtml, &start, &end, TRUE); | |
| 3244 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3245 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 3246 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3247 remove_font_size(imhtml, &start, &end, FALSE); | |
| 3248 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3249 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 3250 } |
| 3251 } | |
| 3252 | |
| 3253 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) | |
| 3254 { | |
| 8677 | 3255 GtkTextIter start, end; |
| 3256 | |
| 8061 | 3257 if (imhtml->edit.fontsize == MAX_FONT_SIZE) |
| 3258 return; | |
| 3259 | |
| 8677 | 3260 if (!imhtml->edit.fontsize) |
| 3261 imhtml->edit.fontsize = 4; | |
| 3262 else | |
| 3263 imhtml->edit.fontsize++; | |
| 3264 | |
| 3265 if (imhtml->wbfo) { | |
| 3266 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3267 remove_font_size(imhtml, &start, &end, TRUE); | |
| 3268 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3269 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 3270 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3271 remove_font_size(imhtml, &start, &end, FALSE); | |
| 3272 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3273 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 3274 } |
| 3275 } | |
| 3276 | |
| 3277 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) | |
| 3278 { | |
| 8677 | 3279 GtkTextIter start, end; |
| 3280 | |
| 3281 if (imhtml->edit.forecolor != NULL) | |
| 3282 g_free(imhtml->edit.forecolor); | |
| 3283 | |
| 8429 | 3284 if (color) { |
| 8677 | 3285 imhtml->edit.forecolor = g_strdup(color); |
| 3286 if (imhtml->wbfo) { | |
| 3287 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3288 remove_font_forecolor(imhtml, &start, &end, TRUE); | |
| 3289 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3290 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), &start, &end); | |
| 3291 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3292 remove_font_forecolor(imhtml, &start, &end, FALSE); | |
| 3293 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3294 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
| 3295 &start, &end); | |
| 3296 } | |
| 8061 | 3297 } else { |
| 3298 imhtml->edit.forecolor = NULL; | |
| 3299 } | |
| 3300 | |
| 3301 return imhtml->edit.forecolor != NULL; | |
| 3302 } | |
| 3303 | |
| 3304 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
| 3305 { | |
| 8677 | 3306 GtkTextIter start, end; |
| 3307 | |
| 3308 if (imhtml->edit.backcolor != NULL) | |
| 3309 g_free(imhtml->edit.backcolor); | |
| 3310 | |
| 8429 | 3311 if (color) { |
| 8677 | 3312 imhtml->edit.backcolor = g_strdup(color); |
| 3313 | |
| 3314 if (imhtml->wbfo) { | |
| 3315 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3316 remove_font_backcolor(imhtml, &start, &end, TRUE); | |
| 3317 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3318 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), &start, &end); | |
| 3319 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3320 remove_font_backcolor(imhtml, &start, &end, FALSE); | |
| 3321 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3322 find_font_backcolor_tag(imhtml, | |
| 3323 imhtml->edit.backcolor), &start, &end); | |
| 3324 } | |
| 8061 | 3325 } else { |
| 3326 imhtml->edit.backcolor = NULL; | |
| 3327 } | |
| 8677 | 3328 |
| 8061 | 3329 return imhtml->edit.backcolor != NULL; |
| 3330 } | |
| 3331 | |
| 3332 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) | |
| 3333 { | |
| 8677 | 3334 GtkTextIter start, end; |
| 3335 | |
| 3336 if (imhtml->edit.fontface != NULL) | |
| 3337 g_free(imhtml->edit.fontface); | |
| 3338 | |
| 8429 | 3339 if (face) { |
| 8677 | 3340 imhtml->edit.fontface = g_strdup(face); |
| 3341 | |
| 3342 if (imhtml->wbfo) { | |
| 3343 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3344 remove_font_face(imhtml, &start, &end, TRUE); | |
| 3345 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3346 find_font_face_tag(imhtml, imhtml->edit.fontface), &start, &end); | |
| 3347 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3348 remove_font_face(imhtml, &start, &end, FALSE); | |
| 3349 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3350 find_font_face_tag(imhtml, imhtml->edit.fontface), | |
| 3351 &start, &end); | |
| 3352 } | |
| 8061 | 3353 } else { |
| 3354 imhtml->edit.fontface = NULL; | |
| 3355 } | |
| 8677 | 3356 |
| 8061 | 3357 return imhtml->edit.fontface != NULL; |
| 3358 } | |
| 3359 | |
| 8677 | 3360 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url) |
| 8061 | 3361 { |
| 8677 | 3362 GtkTextIter start, end; |
| 3363 GtkTextTag *linktag; | |
| 3364 static guint linkno = 0; | |
| 3365 gchar str[48]; | |
| 3366 | |
| 3367 imhtml->edit.link = NULL; | |
| 3368 | |
| 3369 | |
| 3370 | |
| 3371 if (url) { | |
| 3372 g_snprintf(str, sizeof(str), "LINK %d", linkno++); | |
| 3373 str[47] = '\0'; | |
| 3374 | |
| 3375 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 3376 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); | |
| 3377 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); | |
| 3378 | |
| 3379 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3380 remove_font_link(imhtml, &start, &end, FALSE); | |
| 3381 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); | |
| 3382 } | |
| 3383 } | |
| 3384 } | |
| 3385 | |
| 3386 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text) | |
| 3387 { | |
| 8061 | 3388 GtkTextIter iter; |
| 8677 | 3389 |
| 3390 gtk_imhtml_toggle_link(imhtml, url); | |
| 8061 | 3391 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); |
| 8677 | 3392 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1); |
| 3393 gtk_imhtml_toggle_link(imhtml, NULL); | |
| 8061 | 3394 } |
| 3395 | |
| 3396 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) | |
| 3397 { | |
| 8677 | 3398 GtkTextMark *mark; |
| 8061 | 3399 GtkTextIter iter; |
| 8677 | 3400 |
| 3401 mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 3402 | |
| 3403 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 3404 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter); | |
| 3405 } | |
| 3406 | |
| 3407 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) | |
| 3408 { | |
| 8061 | 3409 GdkPixbuf *pixbuf = NULL; |
| 3410 GdkPixbufAnimation *annipixbuf = NULL; | |
| 3411 GtkWidget *icon = NULL; | |
| 3412 GtkTextChildAnchor *anchor; | |
| 8505 | 3413 char *unescaped = gaim_unescape_html(smiley); |
| 8061 | 3414 |
| 8515 | 3415 if (!imhtml->show_smileys) { |
| 8677 | 3416 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, strlen(smiley)); |
| 8515 | 3417 return; |
| 3418 } | |
| 3419 | |
| 8677 | 3420 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
| 8698 | 3421 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", unescaped, g_free); |
| 3422 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); | |
| 8505 | 3423 |
| 3424 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); | |
| 8061 | 3425 if(annipixbuf) { |
| 3426 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
| 3427 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | |
| 3428 if(pixbuf) | |
| 3429 icon = gtk_image_new_from_pixbuf(pixbuf); | |
| 3430 } else { | |
| 3431 icon = gtk_image_new_from_animation(annipixbuf); | |
| 3432 } | |
| 3433 } | |
| 3434 | |
| 3435 if (icon) { | |
| 3436 gtk_widget_show(icon); | |
| 3437 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
| 3438 } | |
| 3439 } | |
| 3440 | |
| 8677 | 3441 static const gchar *tag_to_html_start(GtkTextTag *tag) |
| 8061 | 3442 { |
| 8677 | 3443 const gchar *name; |
| 3444 static gchar buf[1024]; | |
| 3445 | |
| 3446 name = tag->name; | |
| 3447 g_return_val_if_fail(name != NULL, ""); | |
| 3448 | |
| 3449 if (strcmp(name, "BOLD") == 0) { | |
| 3450 return "<b>"; | |
| 3451 } else if (strcmp(name, "ITALICS") == 0) { | |
| 3452 return "<i>"; | |
| 3453 } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 3454 return "<u>"; | |
| 3455 } else if (strncmp(name, "LINK ", 5) == 0) { | |
| 3456 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 3457 if (tmp) { | |
| 3458 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); | |
| 3459 buf[sizeof(buf)-1] = '\0'; | |
| 3460 return buf; | |
| 3461 } else { | |
| 3462 return ""; | |
| 3463 } | |
| 3464 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 3465 g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]); | |
| 3466 return buf; | |
| 3467 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 3468 g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]); | |
| 3469 return buf; | |
| 3470 } else if (strncmp(name, "FONT FACE ", 10) == 0) { | |
| 3471 g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]); | |
| 3472 return buf; | |
| 3473 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 3474 g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]); | |
| 3475 return buf; | |
| 3476 } else { | |
| 3477 return ""; | |
| 3478 } | |
| 8061 | 3479 } |
| 3480 | |
| 8677 | 3481 static const gchar *tag_to_html_end(GtkTextTag *tag) |
| 8061 | 3482 { |
| 8677 | 3483 const gchar *name; |
| 3484 | |
| 3485 name = tag->name; | |
| 3486 g_return_val_if_fail(name != NULL, ""); | |
| 3487 | |
| 3488 if (strcmp(name, "BOLD") == 0) { | |
| 3489 return "</b>"; | |
| 3490 } else if (strcmp(name, "ITALICS") == 0) { | |
| 3491 return "</i>"; | |
| 3492 } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 3493 return "</u>"; | |
| 3494 } else if (strncmp(name, "LINK ", 5) == 0) { | |
| 3495 return "</a>"; | |
| 3496 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 3497 return "</font>"; | |
| 3498 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 3499 return "</font>"; | |
| 3500 } else if (strncmp(name, "FONT FACE ", 10) == 0) { | |
| 3501 return "</font>"; | |
| 3502 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 3503 return "</font>"; | |
| 3504 } else { | |
| 3505 return ""; | |
| 3506 } | |
| 3507 } | |
| 3508 | |
| 3509 static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter) | |
| 3510 { | |
| 3511 return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) && | |
| 3512 !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) || | |
| 3513 gtk_text_iter_is_end(niter)); | |
| 8061 | 3514 } |
| 3515 | |
| 3516 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
| 3517 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
| 8677 | 3518 * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert |
| 3519 * the actual text. Then check for tags that are toggled off and insert them, after checking the queue. | |
| 3520 * Finally, replace <, >, &, and " with their HTML equivilent. | |
| 3521 */ | |
| 8061 | 3522 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 3523 { | |
| 3524 gunichar c; | |
| 8677 | 3525 GtkTextIter iter, nextiter; |
| 8061 | 3526 GString *str = g_string_new(""); |
| 8677 | 3527 GSList *tags, *sl; |
| 3528 GQueue *q, *r; | |
| 3529 GtkTextTag *tag; | |
| 3530 | |
| 3531 q = g_queue_new(); | |
| 3532 r = g_queue_new(); | |
| 3533 | |
| 8061 | 3534 |
| 3535 gtk_text_iter_order(start, end); | |
| 8677 | 3536 nextiter = iter = *start; |
| 3537 gtk_text_iter_forward_char(&nextiter); | |
| 3538 | |
| 3539 /* First add the tags that are already in progress */ | |
| 3540 tags = gtk_text_iter_get_tags(start); | |
| 3541 | |
| 3542 for (sl = tags; sl; sl = sl->next) { | |
| 3543 tag = sl->data; | |
| 3544 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) { | |
| 3545 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tag))); | |
| 3546 g_queue_push_tail(q, tag); | |
| 8061 | 3547 } |
| 3548 } | |
| 8677 | 3549 g_slist_free(tags); |
| 8061 | 3550 |
| 3551 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { | |
| 8677 | 3552 |
| 3553 tags = gtk_text_iter_get_tags(&iter); | |
| 3554 | |
| 3555 for (sl = tags; sl; sl = sl->next) { | |
| 3556 tag = sl->data; | |
| 3557 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) { | |
| 3558 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tag))); | |
| 3559 g_queue_push_tail(q, tag); | |
| 3560 } | |
| 3561 } | |
| 3562 | |
| 3563 | |
| 8061 | 3564 if (c == 0xFFFC) { |
| 3565 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 8698 | 3566 char *text = NULL; |
| 3567 if (anchor) | |
| 3568 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext"); | |
| 3569 if (text) | |
| 3570 str = g_string_append(str, text); | |
| 8677 | 3571 } else if (c == '<') { |
| 3572 str = g_string_append(str, "<"); | |
| 3573 } else if (c == '>') { | |
| 3574 str = g_string_append(str, ">"); | |
| 3575 } else if (c == '&') { | |
| 3576 str = g_string_append(str, "&"); | |
| 3577 } else if (c == '"') { | |
| 3578 str = g_string_append(str, """); | |
| 3579 } else if (c == '\n') { | |
| 3580 str = g_string_append(str, "<br>"); | |
| 8061 | 3581 } else { |
| 8677 | 3582 str = g_string_append_unichar(str, c); |
| 3583 } | |
| 3584 | |
| 3585 tags = g_slist_reverse(tags); | |
| 3586 for (sl = tags; sl; sl = sl->next) { | |
| 3587 tag = sl->data; | |
| 3588 if (tag_ends_here(tag, &iter, &nextiter)) { | |
| 3589 | |
| 3590 GtkTextTag *tmp; | |
| 3591 | |
| 3592 while ((tmp = g_queue_pop_tail(q)) != tag) { | |
| 3593 if (tmp == NULL) | |
| 3594 break; | |
| 3595 | |
| 3596 if (!tag_ends_here(tmp, &iter, &nextiter)) | |
| 3597 g_queue_push_tail(r, tmp); | |
| 3598 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp))); | |
| 3599 } | |
| 3600 | |
| 3601 if (tmp == NULL) | |
| 3602 gaim_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n"); | |
| 3603 else | |
| 3604 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
| 3605 | |
| 3606 while ((tmp = g_queue_pop_head(r))) { | |
| 3607 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tmp))); | |
| 3608 g_queue_push_tail(q, tmp); | |
| 8061 | 3609 } |
| 3610 } | |
| 3611 } | |
| 8677 | 3612 |
| 3613 g_slist_free(tags); | |
| 8061 | 3614 gtk_text_iter_forward_char(&iter); |
| 8677 | 3615 gtk_text_iter_forward_char(&nextiter); |
| 8061 | 3616 } |
| 8677 | 3617 |
| 3618 while ((tag = g_queue_pop_tail(q))) | |
| 3619 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
| 3620 | |
| 3621 g_queue_free(q); | |
| 3622 g_queue_free(r); | |
| 8061 | 3623 return g_string_free(str, FALSE); |
| 3624 } | |
| 3625 | |
| 8698 | 3626 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter) |
| 8061 | 3627 { |
| 3628 if (imhtml->edit.bold) | |
| 3629 gtk_imhtml_toggle_bold(imhtml); | |
| 3630 | |
| 3631 if (imhtml->edit.italic) | |
| 3632 gtk_imhtml_toggle_italic(imhtml); | |
| 3633 | |
| 3634 if (imhtml->edit.underline) | |
| 3635 gtk_imhtml_toggle_underline(imhtml); | |
| 3636 | |
| 3637 if (imhtml->edit.forecolor) | |
| 3638 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 3639 | |
| 3640 if (imhtml->edit.backcolor) | |
| 3641 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 3642 | |
| 3643 if (imhtml->edit.fontface) | |
| 3644 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 3645 | |
| 8677 | 3646 imhtml->edit.fontsize = 0; |
| 3647 | |
| 8719 | 3648 if (imhtml->edit.link) |
| 3649 gtk_imhtml_toggle_link(imhtml, NULL); | |
| 3650 | |
| 8698 | 3651 gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter); |
| 8061 | 3652 |
| 3653 } | |
| 3654 | |
| 3655 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
| 3656 { | |
| 3657 GtkTextIter start, end; | |
| 3658 | |
| 3659 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 3660 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 3661 return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 3662 } | |
| 3663 | |
| 8677 | 3664 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml) |
| 3665 { | |
| 3666 int i, j, lines; | |
| 3667 GtkTextIter start, end; | |
| 3668 char **ret; | |
| 3669 | |
| 3670 lines = gtk_text_buffer_get_line_count(imhtml->text_buffer); | |
| 3671 ret = g_new0(char *, lines + 1); | |
| 3672 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 3673 end = start; | |
| 3674 gtk_text_iter_forward_to_line_end(&end); | |
| 3675 | |
| 3676 for (i = 0, j = 0; i < lines; i++) { | |
| 3677 ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 3678 if (ret[j] != NULL) | |
| 3679 j++; | |
| 3680 gtk_text_iter_forward_line(&start); | |
| 3681 end = start; | |
| 3682 gtk_text_iter_forward_to_line_end(&end); | |
| 3683 } | |
| 3684 | |
| 3685 return ret; | |
| 3686 } | |
| 3687 | |
| 3688 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop) | |
| 8061 | 3689 { |
| 8519 | 3690 GString *str = g_string_new(""); |
| 3691 GtkTextIter iter, end; | |
| 3692 gunichar c; | |
| 3693 | |
| 8677 | 3694 if (start == NULL) |
| 3695 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 3696 else | |
| 3697 iter = *start; | |
| 3698 | |
| 3699 if (stop == NULL) | |
| 3700 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 3701 else | |
| 3702 end = *stop; | |
| 3703 | |
| 3704 gtk_text_iter_order(&iter, &end); | |
| 8519 | 3705 |
| 3706 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) { | |
| 3707 if (c == 0xFFFC) { | |
| 8677 | 3708 GtkTextChildAnchor* anchor; |
| 3709 char *text = NULL; | |
| 3710 | |
| 3711 anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 3712 if (anchor) | |
| 8698 | 3713 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); |
| 8677 | 3714 if (text) |
| 3715 str = g_string_append(str, text); | |
| 8519 | 3716 } else { |
| 3717 g_string_append_unichar(str, c); | |
| 3718 } | |
| 3719 gtk_text_iter_forward_char(&iter); | |
| 3720 } | |
| 3721 | |
| 3722 return g_string_free(str, FALSE); | |
| 8061 | 3723 } |
