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