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