annotate src/gtkimhtml.c @ 12694:ebed1bbedb04

[gaim-migrate @ 15037] SF Patch #1386297 from Lucio Maciel "Add per pounce options, to pounce only when away/not available. Add pounce when receive a new im message (received-im-msg signal) Fix (pounce != GAIM_POUNCE_NONE) in gaim_pounce_set_events()" I changed this patch so that you can't create a pounce that sends an IM in response to receiving an IM. Auto-reply is messy. I also cleaned up some little things that were bothering me in the pounce dialog. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 03 Jan 2006 11:42:51 +0000
parents de93d4988ad4
children e8db8f94a2db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
10297
ec140184437b [gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents: 10243
diff changeset
2 * @file gtkimhtml.c GTK+ IMHtml
ec140184437b [gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents: 10243
diff changeset
3 * @ingroup gtkui
ec140184437b [gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents: 10243
diff changeset
4 *
ec140184437b [gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents: 10243
diff changeset
5 * gaim
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8026
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8026
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8026
diff changeset
9 * source distribution.
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * under the terms of the GNU General Public License as published by
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * (at your option) any later version.
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 * GNU General Public License for more details.
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 */
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
27 #ifdef HAVE_CONFIG_H
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
28 #include <config.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
29 #endif
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
30 #include "debug.h"
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
31 #include "util.h"
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 #include "gtkimhtml.h"
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
33 #include "gtksourceiter.h"
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 #include <gtk/gtk.h>
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
35 #include <glib/gerror.h>
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
36 #include <gdk/gdkkeysyms.h>
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 #include <string.h>
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 #include <ctype.h>
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 #include <stdio.h>
4629
86fd0f6eaa1a [gaim-migrate @ 4920]
Mark Doliner <mark@kingant.net>
parents: 4612
diff changeset
40 #include <stdlib.h>
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 #include <math.h>
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
42 #ifdef HAVE_LANGINFO_CODESET
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
43 #include <langinfo.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
44 #include <locale.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
45 #endif
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
46 #ifdef _WIN32
10901
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
47 #include <gdk/gdkwin32.h>
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
48 #include <windows.h>
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
49 #endif
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
51 #ifdef ENABLE_NLS
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
52 # include <libintl.h>
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
53 # define _(x) gettext(x)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
54 # ifdef gettext_noop
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
55 # define N_(String) gettext_noop (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
56 # else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
57 # define N_(String) (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
58 # endif
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
59 #else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
60 # define N_(String) (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
61 # define _(x) (x)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
62 #endif
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
63
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
64 #include <pango/pango-font.h>
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
65
10062
b6178d85d132 [gaim-migrate @ 11037]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10016
diff changeset
66 /* GTK+ < 2.4.x hack, see gtkgaim.h for details. */
b6178d85d132 [gaim-migrate @ 11037]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10016
diff changeset
67 #if (!GTK_CHECK_VERSION(2,4,0))
5105
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
68 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
69 #endif
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
70
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
71 #define TOOLTIP_TIMEOUT 500
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
72
8786
f3d063680a45 [gaim-migrate @ 9548]
Ethan Blanton <elb@pidgin.im>
parents: 8782
diff changeset
73 /* GTK+ 2.0 hack */
f3d063680a45 [gaim-migrate @ 9548]
Ethan Blanton <elb@pidgin.im>
parents: 8782
diff changeset
74 #if (!GTK_CHECK_VERSION(2,2,0))
f3d063680a45 [gaim-migrate @ 9548]
Ethan Blanton <elb@pidgin.im>
parents: 8782
diff changeset
75 #define gtk_widget_get_clipboard(x, y) gtk_clipboard_get(y)
f3d063680a45 [gaim-migrate @ 9548]
Ethan Blanton <elb@pidgin.im>
parents: 8782
diff changeset
76 #endif
f3d063680a45 [gaim-migrate @ 9548]
Ethan Blanton <elb@pidgin.im>
parents: 8782
diff changeset
77
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
78 static GtkTextViewClass *parent_class = NULL;
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
79
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
80 struct scalable_data {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
81 GtkIMHtmlScalable *scalable;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
82 GtkTextMark *mark;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
83 };
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
84
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
85
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
86 struct im_image_data {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
87 int id;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
88 GtkTextMark *mark;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
89 };
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
90
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
91 static gboolean
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
92 gtk_text_view_drag_motion (GtkWidget *widget,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
93 GdkDragContext *context,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
94 gint x,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
95 gint y,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
96 guint time);
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
97
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
98 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
99 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
12673
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
100 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml);
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
101 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data);
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
102 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
103 static gboolean gtk_imhtml_is_amp_escape (const gchar *string, gchar **replace, gint *length);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
104 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter);
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
105 static void gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data);
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
106 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
107 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml);
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
108 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
109 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
110 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data);
10901
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
111 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext);
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
112 static void imhtml_toggle_bold(GtkIMHtml *imhtml);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
113 static void imhtml_toggle_italic(GtkIMHtml *imhtml);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
114 static void imhtml_toggle_strike(GtkIMHtml *imhtml);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
115 static void imhtml_toggle_underline(GtkIMHtml *imhtml);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
116 static void imhtml_font_grow(GtkIMHtml *imhtml);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
117 static void imhtml_font_shrink(GtkIMHtml *imhtml);
12672
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
118 static void imhtml_clear_formatting(GtkIMHtml *imhtml);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
119
10899
1e6bdc7175e9 [gaim-migrate @ 12619]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10871
diff changeset
120 /* POINT_SIZE converts from AIM font sizes to a point size scale factor. */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
121 #define MAX_FONT_SIZE 7
10900
d056acc96b30 [gaim-migrate @ 12621]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10899
diff changeset
122 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1])
8380
4a5b36510665 [gaim-migrate @ 9108]
Sean Egan <seanegan@gmail.com>
parents: 8367
diff changeset
123 static gdouble _point_sizes [] = { .69444444, .8333333, 1, 1.2, 1.44, 1.728, 2.0736};
2349
60c716c32c40 [gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2348
diff changeset
124
10184
f6918ab1624a [gaim-migrate @ 11299]
Mark Doliner <mark@kingant.net>
parents: 10169
diff changeset
125 enum {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
126 TARGET_HTML,
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
127 TARGET_UTF8_STRING,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
128 TARGET_COMPOUND_TEXT,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
129 TARGET_STRING,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
130 TARGET_TEXT
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
131 };
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
132
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
133 enum {
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
134 URL_CLICKED,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
135 BUTTONS_UPDATE,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
136 TOGGLE_FORMAT,
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
137 CLEAR_FORMAT,
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
138 UPDATE_FORMAT,
10108
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
139 MESSAGE_SEND,
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
140 LAST_SIGNAL
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
141 };
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
142 static guint signals [LAST_SIGNAL] = { 0 };
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
143
10871
6240d7fd5b2c [gaim-migrate @ 12558]
Mark Doliner <mark@kingant.net>
parents: 10865
diff changeset
144 static GtkTargetEntry selection_targets[] = {
8566
6eb60b70491e [gaim-migrate @ 9313]
Sean Egan <seanegan@gmail.com>
parents: 8548
diff changeset
145 { "text/html", 0, TARGET_HTML },
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
146 { "UTF8_STRING", 0, TARGET_UTF8_STRING },
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
147 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
148 { "STRING", 0, TARGET_STRING },
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
149 { "TEXT", 0, TARGET_TEXT}};
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
150
10871
6240d7fd5b2c [gaim-migrate @ 12558]
Mark Doliner <mark@kingant.net>
parents: 10865
diff changeset
151 static GtkTargetEntry link_drag_drop_targets[] = {
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
152 GTK_IMHTML_DND_TARGETS
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
153 };
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
154
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
155 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
156 /* Win32 clipboard format value, and functions to convert back and
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
157 * forth between HTML and the clipboard format.
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
158 */
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
159 static UINT win_html_fmt;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
160
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
161 static gchar *
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
162 clipboard_win32_to_html(char *clipboard) {
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
163 const char *header;
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
164 const char *begin, *end;
10016
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
165 gint start = 0;
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
166 gint finish = 0;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
167 gchar *html;
10016
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
168 gchar **split;
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
169 int clipboard_length = 0;
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
170
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
171 #if 0 /* Debugging for Windows clipboard */
9467
b6971539f7af [gaim-migrate @ 10292]
Tim Ringenbach <marv@pidgin.im>
parents: 9465
diff changeset
172 FILE *fd;
b6971539f7af [gaim-migrate @ 10292]
Tim Ringenbach <marv@pidgin.im>
parents: 9465
diff changeset
173
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
174 gaim_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard);
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
175
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10574
diff changeset
176 fd = g_fopen("e:\\gaimcb.txt", "wb");
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
177 fprintf(fd, "%s", clipboard);
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
178 fclose(fd);
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
179 #endif
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
180
10016
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
181 clipboard_length = strlen(clipboard);
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
182
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
183 if (!(header = strstr(clipboard, "StartFragment:")) || (header - clipboard) >= clipboard_length)
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
184 return NULL;
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
185 sscanf(header, "StartFragment:%d", &start);
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
186
10016
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
187 if (!(header = strstr(clipboard, "EndFragment:")) || (header - clipboard) >= clipboard_length)
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
188 return NULL;
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
189 sscanf(header, "EndFragment:%d", &finish);
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
190
10016
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
191 if (finish > clipboard_length)
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
192 finish = clipboard_length;
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
193
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
194 if (start > finish)
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
195 start = finish;
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
196
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
197 begin = clipboard + start;
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
198
10016
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
199 end = clipboard + finish;
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
200
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
201 html = g_strndup(begin, end - begin);
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
202
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
203 /* any newlines in the string will now be \r\n, so we need to strip out the \r */
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
204 split = g_strsplit(html, "\r\n", 0);
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
205 g_free(html);
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
206 html = g_strjoinv("\n", split);
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
207 g_strfreev(split);
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
208
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
209 html = g_strstrip(html);
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
210
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
211 #if 0 /* Debugging for Windows clipboard */
10016
5b4a0af99bf7 [gaim-migrate @ 10935]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
212 gaim_debug_info("imhtml clipboard", "HTML fragment: '%s'\n", html);
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
213 #endif
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
214
8707
4c7bc4b0f190 [gaim-migrate @ 9460]
Luke Schierer <lschiere@pidgin.im>
parents: 8698
diff changeset
215 return html;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
216 }
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
217
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
218 static gchar *
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
219 clipboard_html_to_win32(char *html) {
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
220 int length;
11240
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
221 GString *clipboard;
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
222 gchar *tmp;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
223 gchar *ret;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
224
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
225 if (html == NULL)
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
226 return NULL;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
227
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
228 length = strlen(html);
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
229 clipboard = g_string_new ("Version:1.0\r\n");
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
230 g_string_append(clipboard, "StartHTML:0000000105\r\n");
11240
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
231 tmp = g_strdup_printf("EndHTML:%010d\r\n", 147 + length);
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
232 g_string_append(clipboard, tmp);
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
233 g_free(tmp);
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
234 g_string_append(clipboard, "StartFragment:0000000127\r\n");
11240
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
235 tmp = g_strdup_printf("EndFragment:%010d\r\n", 127 + length);
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
236 g_string_append(clipboard, tmp);
2ab2de8add8b [gaim-migrate @ 13399]
Richard Laager <rlaager@wiktel.com>
parents: 11234
diff changeset
237 g_free(tmp);
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
238 g_string_append(clipboard, "<!--StartFragment-->\r\n");
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
239 g_string_append(clipboard, html);
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
240 g_string_append(clipboard, "\r\n<!--EndFragment-->");
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
241 ret = clipboard->str;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
242 g_string_free(clipboard, FALSE);
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
243
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
244 #if 0 /* Debugging for Windows clipboard */
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
245 gaim_debug_info("imhtml clipboard", "from gaim: %s\n", ret);
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
246 #endif
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
247
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
248 return ret;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
249 }
10901
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
250
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
251 static void clipboard_copy_html_win32(GtkIMHtml *imhtml) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
252 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
253 if (clipboard != NULL) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
254 HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
255 if (OpenClipboard(hwnd)) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
256 if (EmptyClipboard()) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
257 gint length = strlen(clipboard);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
258 HGLOBAL hdata = GlobalAlloc(GMEM_MOVEABLE, length);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
259 if (hdata != NULL) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
260 gchar *buffer = GlobalLock(hdata);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
261 memcpy(buffer, clipboard, length);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
262 GlobalUnlock(hdata);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
263
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
264 if (SetClipboardData(win_html_fmt, hdata) == NULL) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
265 gchar *err_msg =
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
266 g_win32_error_message(GetLastError());
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
267 gaim_debug_info("html clipboard",
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
268 "Unable to set clipboard data: %s\n",
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
269 err_msg ? err_msg : "Unknown Error");
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
270 g_free(err_msg);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
271 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
272 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
273 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
274 CloseClipboard();
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
275 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
276 g_free(clipboard);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
277 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
278 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
279
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
280 static gboolean clipboard_paste_html_win32(GtkIMHtml *imhtml) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
281 gboolean pasted = FALSE;
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
282
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
283 if (gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
284 && IsClipboardFormatAvailable(win_html_fmt)) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
285 gboolean error_reading_clipboard = FALSE;
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
286 HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
287
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
288 if (OpenClipboard(hwnd)) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
289 HGLOBAL hdata = GetClipboardData(win_html_fmt);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
290 if (hdata == NULL) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
291 error_reading_clipboard = TRUE;
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
292 } else {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
293 char *buffer = GlobalLock(hdata);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
294 if (buffer == NULL) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
295 error_reading_clipboard = TRUE;
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
296 } else {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
297 char *text = clipboard_win32_to_html(
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
298 buffer);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
299 imhtml_paste_insert(imhtml, text,
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
300 FALSE);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
301 g_free(text);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
302 pasted = TRUE;
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
303 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
304 GlobalUnlock(hdata);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
305 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
306
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
307 CloseClipboard();
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
308
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
309 } else {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
310 error_reading_clipboard = TRUE;
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
311 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
312
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
313 if (error_reading_clipboard) {
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
314 gchar *err_msg = g_win32_error_message(GetLastError());
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
315 gaim_debug_info("html clipboard",
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
316 "Unable to read clipboard data: %s\n",
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
317 err_msg ? err_msg : "Unknown Error");
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
318 g_free(err_msg);
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
319 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
320 }
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
321
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
322 return pasted;
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
323 }
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
324 #endif
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
325
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
326 static GtkSmileyTree*
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
327 gtk_smiley_tree_new ()
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
328 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
329 return g_new0 (GtkSmileyTree, 1);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
330 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
331
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
332 static void
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
333 gtk_smiley_tree_insert (GtkSmileyTree *tree,
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
334 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
335 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
336 GtkSmileyTree *t = tree;
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
337 const gchar *x = smiley->smile;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
338
12229
18f0dadb29cf [gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents: 12072
diff changeset
339 if (!(*x))
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
340 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
341
12229
18f0dadb29cf [gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents: 12072
diff changeset
342 do {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
343 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
344 gint index;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
345
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
346 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
347 t->values = g_string_new ("");
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
348
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
349 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
350 if (!pos) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
351 t->values = g_string_append_c (t->values, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
352 index = t->values->len - 1;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
353 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *));
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
354 t->children [index] = g_new0 (GtkSmileyTree, 1);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
355 } else
7386
414c701ef1ff [gaim-migrate @ 7981]
Luke Schierer <lschiere@pidgin.im>
parents: 7384
diff changeset
356 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
357
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
358 t = t->children [index];
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
359
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
360 x++;
12229
18f0dadb29cf [gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents: 12072
diff changeset
361 } while (*x);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
362
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
363 t->image = smiley;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
364 }
4041
3a36ec242415 [gaim-migrate @ 4249]
Sean Egan <seanegan@gmail.com>
parents: 4032
diff changeset
365
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
366
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11586
diff changeset
367 static void
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11586
diff changeset
368 gtk_smiley_tree_destroy (GtkSmileyTree *tree)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
369 {
11701
5d7da4056644 [gaim-migrate @ 13992]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
370 GSList *list = g_slist_prepend (NULL, tree);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
371
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
372 while (list) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
373 GtkSmileyTree *t = list->data;
12229
18f0dadb29cf [gaim-migrate @ 14531]
Richard Laager <rlaager@wiktel.com>
parents: 12072
diff changeset
374 gsize i;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
375 list = g_slist_remove(list, t);
7384
dc573236dc8b [gaim-migrate @ 7979]
Nathan Walp <nwalp@pidgin.im>
parents: 7371
diff changeset
376 if (t && t->values) {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
377 for (i = 0; i < t->values->len; i++)
11701
5d7da4056644 [gaim-migrate @ 13992]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
378 list = g_slist_prepend (list, t->children [i]);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
379 g_string_free (t->values, TRUE);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
380 g_free (t->children);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
381 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
382 g_free (t);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
383 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
384 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
385
11840
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
386 static void gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data)
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
387 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
388 GdkRectangle rect;
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
389 int xminus;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
390
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
391 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
392 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
393 GList *iter = GTK_IMHTML(widget)->scalables;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
394
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
395 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) +
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
396 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget));
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
397
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
398 while(iter){
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
399 struct scalable_data *sd = iter->data;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
400 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable);
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
401 scale->scale(scale, rect.width - xminus, rect.height);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
402
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
403 iter = iter->next;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
404 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
405 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
406
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
407 widget->old_rect = rect;
11840
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
408 return;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
409 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
410
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
411 static gint
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
412 gtk_imhtml_tip_paint (GtkIMHtml *imhtml)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
413 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
414 PangoLayout *layout;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
415
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
416 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
417
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
418 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
419
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
420 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window,
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
421 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
422 "tooltip", 0, 0, -1, -1);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
423
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
424 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
425 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
426
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
427 g_object_unref(layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
428 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
429 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
430
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
431 static gint
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
432 gtk_imhtml_tip (gpointer data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
433 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
434 GtkIMHtml *imhtml = data;
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
435 PangoFontMetrics *font_metrics;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
436 PangoLayout *layout;
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
437 PangoFont *font;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
438
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
439 gint gap, x, y, h, w, scr_w, baseline_skip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
440
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
441 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
442
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
443 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
444 imhtml->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
445 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
446 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
447
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
448 if (imhtml->tip_window){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
449 gtk_widget_destroy (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
450 imhtml->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
451 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
452
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
453 imhtml->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
454 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
455 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
456 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
457 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips");
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
458 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event",
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
459 G_CALLBACK (gtk_imhtml_tip_paint), imhtml);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
460
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
461 gtk_widget_ensure_style (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
462 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
463 font = pango_context_load_font(pango_layout_get_context(layout),
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
464 imhtml->tip_window->style->font_desc);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
465
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
466 if (font == NULL) {
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
467 char *tmp = pango_font_description_to_string(
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
468 imhtml->tip_window->style->font_desc);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
469
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
470 gaim_debug(GAIM_DEBUG_ERROR, "gtk_imhtml_tip",
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
471 "pango_context_load_font() couldn't load font: '%s'\n",
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
472 tmp);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
473 g_free(tmp);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
474
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
475 return FALSE;
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
476 }
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
477
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
478 font_metrics = pango_font_get_metrics(font, NULL);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
479
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
480 pango_layout_get_pixel_size(layout, &scr_w, NULL);
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
481 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) +
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
482 pango_font_metrics_get_descent(font_metrics))/ 4);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
483
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
484 if (gap < 2)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
485 gap = 2;
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
486 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) +
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
487 pango_font_metrics_get_descent(font_metrics));
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
488 w = 8 + scr_w;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
489 h = 8 + baseline_skip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
490
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
491 gdk_window_get_pointer (NULL, &x, &y, NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
492 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml)))
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
493 y += GTK_WIDGET(imhtml)->allocation.y;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
494
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
495 scr_w = gdk_screen_width();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
496
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
497 x -= ((w >> 1) + 4);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
498
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
499 if ((x + w) > scr_w)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
500 x -= (x + w) - scr_w;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
501 else if (x < 0)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
502 x = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
503
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
504 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) +
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
505 pango_font_metrics_get_descent(font_metrics));
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
506
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
507 gtk_widget_set_size_request (imhtml->tip_window, w, h);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
508 gtk_widget_show (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
509 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
510
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
511 pango_font_metrics_unref(font_metrics);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
512 g_object_unref(layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
513
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
514 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
515 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
516
11844
a0956e22fdde [gaim-migrate @ 14135]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11840
diff changeset
517 static gboolean
a0956e22fdde [gaim-migrate @ 14135]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11840
diff changeset
518 gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
519 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
520 GtkTextIter iter;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
521 GdkWindow *win = event->window;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
522 int x, y;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
523 char *tip = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
524 GSList *tags = NULL, *templist = NULL;
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
525 GdkColor *norm, *pre;
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
526 GtkTextTag *tag = NULL, *oldprelit_tag;
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
527
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
528 oldprelit_tag = GTK_IMHTML(imhtml)->prelit_tag;
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
529
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
530 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
531 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET,
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
532 event->x, event->y, &x, &y);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
533 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
534 tags = gtk_text_iter_get_tags(&iter);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
535
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
536 templist = tags;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
537 while (templist) {
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
538 tag = templist->data;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
539 tip = g_object_get_data(G_OBJECT(tag), "link_url");
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
540 if (tip)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
541 break;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
542 templist = templist->next;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
543 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
544
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
545 if (tip) {
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
546 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-prelight-color", &pre, NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
547 GTK_IMHTML(imhtml)->prelit_tag = tag;
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
548 if (tag != oldprelit_tag) {
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
549 if (pre)
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
550 g_object_set(G_OBJECT(tag), "foreground-gdk", pre, NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
551 else
12253
868220a1a1b2 [gaim-migrate @ 14555]
Mark Doliner <mark@kingant.net>
parents: 12230
diff changeset
552 g_object_set(G_OBJECT(tag), "foreground", "#70a0ff", NULL);
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
553 }
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
554 } else {
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
555 GTK_IMHTML(imhtml)->prelit_tag = NULL;
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
556 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
557
10834
76d85ccf7d90 [gaim-migrate @ 12505]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10826
diff changeset
558 if ((oldprelit_tag != NULL) && (GTK_IMHTML(imhtml)->prelit_tag != oldprelit_tag)) {
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
559 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &norm, NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
560 if (norm)
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
561 g_object_set(G_OBJECT(oldprelit_tag), "foreground-gdk", norm, NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
562 else
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
563 g_object_set(G_OBJECT(oldprelit_tag), "foreground", "blue", NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
564 }
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
565
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
566 if (GTK_IMHTML(imhtml)->tip) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
567 if ((tip == GTK_IMHTML(imhtml)->tip)) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
568 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
569 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
570 /* We've left the cell. Remove the timeout and create a new one below */
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
571 if (GTK_IMHTML(imhtml)->tip_window) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
572 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
573 GTK_IMHTML(imhtml)->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
574 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
575 if (GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
576 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
577 else
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
578 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
579 if (GTK_IMHTML(imhtml)->tip_timer)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
580 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
581 GTK_IMHTML(imhtml)->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
582 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
583
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
584 if (tip){
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
585 if (!GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
586 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
587 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT,
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
588 gtk_imhtml_tip, imhtml);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
589 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
590
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
591 GTK_IMHTML(imhtml)->tip = tip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
592 g_slist_free(tags);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
593 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
594 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
595
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11586
diff changeset
596 static gboolean
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11586
diff changeset
597 gtk_enter_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data)
10946
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
598 {
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
599 if (GTK_IMHTML(imhtml)->editable)
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
600 gdk_window_set_cursor(
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
601 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml),
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
602 GTK_TEXT_WINDOW_TEXT),
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
603 GTK_IMHTML(imhtml)->text_cursor);
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
604 else
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
605 gdk_window_set_cursor(
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
606 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml),
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
607 GTK_TEXT_WINDOW_TEXT),
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
608 GTK_IMHTML(imhtml)->arrow_cursor);
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
609
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
610 /* propagate the event normally */
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
611 return FALSE;
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
612 }
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
613
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11586
diff changeset
614 static gboolean
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11586
diff changeset
615 gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data)
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
616 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
617 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
618 if (GTK_IMHTML(imhtml)->prelit_tag) {
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
619 GdkColor *norm;
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
620 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &norm, NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
621 if (norm)
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
622 g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground-gdk", norm, NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
623 else
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
624 g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground", "blue", NULL);
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
625 GTK_IMHTML(imhtml)->prelit_tag = NULL;
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
626 }
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
627
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
628 if (GTK_IMHTML(imhtml)->tip_window) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
629 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
630 GTK_IMHTML(imhtml)->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
631 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
632 if (GTK_IMHTML(imhtml)->tip_timer) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
633 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
634 GTK_IMHTML(imhtml)->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
635 }
10946
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
636 gdk_window_set_cursor(
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
637 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml),
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
638 GTK_TEXT_WINDOW_TEXT), NULL);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
639
8568
88988327a4e0 [gaim-migrate @ 9316]
Mark Doliner <mark@kingant.net>
parents: 8566
diff changeset
640 /* propagate the event normally */
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
641 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
642 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
643
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
644 #if (!GTK_CHECK_VERSION(2,2,0))
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
645 /*
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
646 * XXX - This should be removed eventually.
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
647 *
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
648 * This function exists to work around a gross bug in GtkTextView.
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
649 * Basically, we short circuit ctrl+a and ctrl+end because they make
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
650 * el program go boom.
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
651 *
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
652 * It's supposed to be fixed in gtk2.2. You can view the bug report at
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
653 * http://bugzilla.gnome.org/show_bug.cgi?id=107939
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
654 */
10849
c203cd637f95 [gaim-migrate @ 12521]
Mark Doliner <mark@kingant.net>
parents: 10844
diff changeset
655 static gboolean
c203cd637f95 [gaim-migrate @ 12521]
Mark Doliner <mark@kingant.net>
parents: 10844
diff changeset
656 gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data)
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
657 {
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
658 if (event->state & GDK_CONTROL_MASK) {
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
659 switch (event->keyval) {
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
660 case 'a':
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
661 case GDK_Home:
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
662 case GDK_End:
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
663 return TRUE;
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
664 }
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
665 }
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
666 return FALSE;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
667 }
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
668 #endif /* !(GTK+ >= 2.2.0) */
10692
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
669
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
670 static gint
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
671 gtk_imhtml_expose_event (GtkWidget *widget,
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
672 GdkEventExpose *event)
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
673 {
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
674 GtkTextIter start, end, cur;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
675 int buf_x, buf_y;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
676 GdkRectangle visible_rect;
10777
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
677 GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(event->window));
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
678 GdkColor gcolor;
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
679
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
680 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &visible_rect);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
681 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget),
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
682 GTK_TEXT_WINDOW_TEXT,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
683 visible_rect.x,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
684 visible_rect.y,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
685 &visible_rect.x,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
686 &visible_rect.y);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
687
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
688 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
689 event->area.x, event->area.y, &buf_x, &buf_y);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
690
10777
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
691 if (GTK_IMHTML(widget)->editable || GTK_IMHTML(widget)->wbfo) {
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
692
10777
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
693 if (GTK_IMHTML(widget)->edit.background) {
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
694 gdk_color_parse(GTK_IMHTML(widget)->edit.background, &gcolor);
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
695 gdk_gc_set_rgb_fg_color(gc, &gcolor);
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
696 } else {
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
697 gdk_gc_set_rgb_fg_color(gc, &(widget->style->base[GTK_WIDGET_STATE(widget)]));
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
698 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
699
10777
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
700 gdk_draw_rectangle(event->window,
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
701 gc,
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
702 TRUE,
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
703 visible_rect.x, visible_rect.y, visible_rect.width, visible_rect.height);
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
704 gdk_gc_unref(gc);
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
705
10777
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
706 if (GTK_WIDGET_CLASS (parent_class)->expose_event)
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
707 return (* GTK_WIDGET_CLASS (parent_class)->expose_event)
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
708 (widget, event);
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
709 return FALSE;
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
710
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
711 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
712
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
713 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &start, buf_x, buf_y);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
714 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &end,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
715 buf_x + event->area.width, buf_y + event->area.height);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
716
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
717
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
718
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
719 cur = start;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
720
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
721 while (gtk_text_iter_in_range(&cur, &start, &end)) {
10795
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
722 GSList *tags = gtk_text_iter_get_tags(&cur);
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
723 GSList *l;
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
724
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
725 for (l = tags; l; l = l->next) {
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
726 GtkTextTag *tag = l->data;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
727 GdkRectangle rect;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
728 GdkRectangle tag_area;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
729 const char *color;
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
730
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
731 if (strncmp(tag->name, "BACKGROUND ", 11))
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
732 continue;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
733
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
734 if (gtk_text_iter_ends_tag(&cur, tag))
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
735 continue;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
736
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
737 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
738 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget),
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
739 GTK_TEXT_WINDOW_TEXT,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
740 tag_area.x,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
741 tag_area.y,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
742 &tag_area.x,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
743 &tag_area.y);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
744 rect.x = visible_rect.x;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
745 rect.y = tag_area.y;
11768
a9e9b76905b4 [gaim-migrate @ 14059]
Gary Kramlich <grim@reaperworld.com>
parents: 11760
diff changeset
746 rect.width = visible_rect.width;
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
747
10795
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
748 do
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
749 gtk_text_iter_forward_to_tag_toggle(&cur, tag);
10795
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
750 while (!gtk_text_iter_is_end(&cur) && gtk_text_iter_begins_tag(&cur, tag));
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
751
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
752 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
753 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget),
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
754 GTK_TEXT_WINDOW_TEXT,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
755 tag_area.x,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
756 tag_area.y,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
757 &tag_area.x,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
758 &tag_area.y);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
759
11760
c0fca40fd938 [gaim-migrate @ 14051]
Sean Egan <seanegan@gmail.com>
parents: 11750
diff changeset
760
c0fca40fd938 [gaim-migrate @ 14051]
Sean Egan <seanegan@gmail.com>
parents: 11750
diff changeset
761 rect.height = tag_area.y + tag_area.height - rect.y
c0fca40fd938 [gaim-migrate @ 14051]
Sean Egan <seanegan@gmail.com>
parents: 11750
diff changeset
762 + gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(widget));
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
763
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
764 color = tag->name + 11;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
765
10857
06e71aa662af [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
766 if (!gdk_color_parse(color, &gcolor)) {
10858
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
767 gchar tmp[8];
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
768 tmp[0] = '#';
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
769 strncpy(&tmp[1], color, 7);
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
770 tmp[7] = '\0';
10857
06e71aa662af [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
771 if (!gdk_color_parse(tmp, &gcolor))
06e71aa662af [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
772 gdk_color_parse("white", &gcolor);
06e71aa662af [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
773 }
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
774 gdk_gc_set_rgb_fg_color(gc, &gcolor);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
775
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
776 gdk_draw_rectangle(event->window,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
777 gc,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
778 TRUE,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
779 rect.x, rect.y, rect.width, rect.height);
10795
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
780 gtk_text_iter_backward_char(&cur); /* go back one, in case the end is the begining is the end
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
781 * note that above, we always moved cur ahead by at least
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
782 * one character */
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
783 break;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
784 }
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
785
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
786 g_slist_free(tags);
10795
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
787
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
788 /* loop until another tag begins, or no tag begins */
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
789 while (gtk_text_iter_forward_to_tag_toggle(&cur, NULL) &&
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
790 !gtk_text_iter_is_end(&cur) &&
096c8a65d3fc [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
791 !gtk_text_iter_begins_tag(&cur, NULL));
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
792 }
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
793
10777
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
794 gdk_gc_unref(gc);
ffa44a5159e0 [gaim-migrate @ 12392]
Sean Egan <seanegan@gmail.com>
parents: 10776
diff changeset
795
10692
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
796 if (GTK_WIDGET_CLASS (parent_class)->expose_event)
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
797 return (* GTK_WIDGET_CLASS (parent_class)->expose_event)
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
798 (widget, event);
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
799
10692
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
800 return FALSE;
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
801 }
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
802
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
803
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
804 static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml)
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
805 {
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
806 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
807
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
808 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
809
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
810 }
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
811
10692
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
812
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
813
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
814 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data)
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
815 {
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
816 GtkWidget *menuitem;
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
817
12635
8584cc19ee48 [gaim-migrate @ 14971]
Richard Laager <rlaager@wiktel.com>
parents: 12605
diff changeset
818 menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text"));
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
819 gtk_widget_show(menuitem);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
820 gtk_widget_set_sensitive(menuitem,
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
821 (imhtml->editable &&
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
822 gtk_clipboard_wait_is_text_available(
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
823 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD))));
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
824 /* put it after "Paste" */
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
825 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 3);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
826
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
827 g_signal_connect(G_OBJECT(menuitem), "activate",
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
828 G_CALLBACK(paste_unformatted_cb), imhtml);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
829 }
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
830
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
831 static char *
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
832 ucs2_order(gboolean swap)
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
833 {
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
834 gboolean be;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
835
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
836 be = G_BYTE_ORDER == G_BIG_ENDIAN;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
837 be = swap ? be : !be;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
838
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
839 if (be)
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
840 return "UCS-2BE";
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
841 else
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
842 return "UCS-2LE";
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
843
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
844 }
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
845
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
846 /* Convert from UCS-2 to UTF-8, stripping the BOM if one is present.*/
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
847 static gchar *
11586
03cd74ca2562 [gaim-migrate @ 13856]
Nathan Walp <nwalp@pidgin.im>
parents: 11572
diff changeset
848 ucs2_to_utf8_with_bom_check(gchar *data, guint len) {
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
849 char *fromcode = NULL;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
850 GError *error = NULL;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
851 guint16 c;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
852 gchar *utf8_ret;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
853
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
854 /*
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
855 * Unicode Techinical Report 20
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
856 * ( http://www.unicode.org/unicode/reports/tr20/ ) says to treat an
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
857 * initial 0xfeff (ZWNBSP) as a byte order indicator so that is
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
858 * what we do. If there is no indicator assume it is in the default
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
859 * order
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
860 */
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
861
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
862 memcpy(&c, data, 2);
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
863 switch (c) {
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
864 case 0xfeff:
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
865 case 0xfffe:
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
866 fromcode = ucs2_order(c == 0xfeff);
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
867 data += 2;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
868 len -= 2;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
869 break;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
870 default:
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
871 fromcode = "UCS-2";
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
872 break;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
873 }
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
874
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
875 utf8_ret = g_convert(data, len, "UTF-8", fromcode, NULL, NULL, &error);
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
876
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
877 if (error) {
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
878 gaim_debug_warning("gtkimhtml", "g_convert error: %s\n", error->message);
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
879 g_error_free(error);
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
880 }
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
881 return utf8_ret;
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
882 }
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
883
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
884
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
885 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) {
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
886 char *text;
8782
5a2b5e4abf3a [gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents: 8758
diff changeset
887 gboolean primary;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
888 GtkTextIter start, end;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
889 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
890 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
10013
f1f239fa8973 [gaim-migrate @ 10930]
Mark Doliner <mark@kingant.net>
parents: 9924
diff changeset
891
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
892 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
893 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
8782
5a2b5e4abf3a [gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents: 8758
diff changeset
894 primary = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY) == clipboard;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
895
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
896 if (info == TARGET_HTML) {
8907
00138e366ef8 [gaim-migrate @ 9677]
Luke Schierer <lschiere@pidgin.im>
parents: 8890
diff changeset
897 gsize len;
8148
c06b233aa84d [gaim-migrate @ 8859]
Nathan Walp <nwalp@pidgin.im>
parents: 8128
diff changeset
898 char *selection;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
899 GString *str = g_string_new(NULL);
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
900 if (primary) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
901 text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
10013
f1f239fa8973 [gaim-migrate @ 10930]
Mark Doliner <mark@kingant.net>
parents: 9924
diff changeset
902 } else
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
903 text = imhtml->clipboard_html_string;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
904
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
905 /* Mozilla asks that we start our text/html with the Unicode byte order mark */
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
906 str = g_string_append_unichar(str, 0xfeff);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
907 str = g_string_append(str, text);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
908 str = g_string_append_unichar(str, 0x0000);
8148
c06b233aa84d [gaim-migrate @ 8859]
Nathan Walp <nwalp@pidgin.im>
parents: 8128
diff changeset
909 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL);
11143
5c56223fa24f [gaim-migrate @ 13207]
Mark Doliner <mark@kingant.net>
parents: 11069
diff changeset
910 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
911 g_string_free(str, TRUE);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
912 g_free(selection);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
913 } else {
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
914 if (primary) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
915 text = gtk_imhtml_get_text(imhtml, &start, &end);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
916 } else
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
917 text = imhtml->clipboard_text_string;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
918 gtk_selection_data_set_text(selection_data, text, strlen(text));
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
919 }
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
920 if (primary) /* This was allocated here */
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
921 g_free(text);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
922 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
923
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
924 static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml)
7749
ddda7537918e [gaim-migrate @ 8394]
Sean Egan <seanegan@gmail.com>
parents: 7745
diff changeset
925 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
926 GtkTextIter insert;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
927 GtkTextIter selection_bound;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
928
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
929 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
930 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert"));
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
931 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
932 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"));
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
933
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
934 if (!gtk_text_iter_equal (&insert, &selection_bound))
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
935 gtk_text_buffer_move_mark (imhtml->text_buffer,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
936 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"),
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
937 &insert);
7749
ddda7537918e [gaim-migrate @ 8394]
Sean Egan <seanegan@gmail.com>
parents: 7745
diff changeset
938 }
7742
6cd69aa58253 [gaim-migrate @ 8387]
Sean Egan <seanegan@gmail.com>
parents: 7740
diff changeset
939
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
940 static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
7749
ddda7537918e [gaim-migrate @ 8394]
Sean Egan <seanegan@gmail.com>
parents: 7745
diff changeset
941 {
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
942 GtkTextIter start, end;
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
943 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
944 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
945
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
946 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
947 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
948
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
949 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD),
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
950 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
951 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
952 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
953
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
954 if (imhtml->clipboard_html_string) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
955 g_free(imhtml->clipboard_html_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
956 g_free(imhtml->clipboard_text_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
957 }
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
958
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
959 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
960 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
961
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
962 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
963 /* We're going to still copy plain text, but let's toss the "HTML Format"
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
964 we need into the windows clipboard now as well. */
10901
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
965 clipboard_copy_html_win32(imhtml);
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
966 #endif
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
967
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
968 g_signal_stop_emission_by_name(imhtml, "copy-clipboard");
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
969 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
970
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
971 static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
972 {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
973 GtkTextIter start, end;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
974 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
975 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
976
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
977 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
978 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
979
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
980 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD),
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
981 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
982 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
983 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
984
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
985 if (imhtml->clipboard_html_string) {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
986 g_free(imhtml->clipboard_html_string);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
987 g_free(imhtml->clipboard_text_string);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
988 }
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
989
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
990 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
991 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
992
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
993 #ifdef _WIN32
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
994 /* We're going to still copy plain text, but let's toss the "HTML Format"
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
995 we need into the windows clipboard now as well. */
10901
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
996 clipboard_copy_html_win32(imhtml);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
997 #endif
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
998
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
999 if (imhtml->editable)
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1000 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1001 g_signal_stop_emission_by_name(imhtml, "cut-clipboard");
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1002 }
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1003
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1004 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext)
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1005 {
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1006 GtkTextIter iter;
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
1007 GtkIMHtmlOptions flags = plaintext ? 0 : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS);
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1008
9028
6fd7de357672 [gaim-migrate @ 9804]
Tim Ringenbach <marv@pidgin.im>
parents: 9025
diff changeset
1009 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL))
6fd7de357672 [gaim-migrate @ 9804]
Tim Ringenbach <marv@pidgin.im>
parents: 9025
diff changeset
1010 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE);
6fd7de357672 [gaim-migrate @ 9804]
Tim Ringenbach <marv@pidgin.im>
parents: 9025
diff changeset
1011
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1012 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer));
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1013 if (!imhtml->wbfo && !plaintext)
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1014 gtk_imhtml_close_tags(imhtml, &iter);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1015
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1016 gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter);
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1017 if (!imhtml->wbfo && !plaintext)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1018 gtk_imhtml_close_tags(imhtml, &iter);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1019 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter);
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1020 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer),
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1021 0, FALSE, 0.0, 0.0);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1022 }
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1023
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1024 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data)
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1025 {
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1026 char *tmp;
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1027
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1028 if (text == NULL)
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1029 return;
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1030
10732
c4cb90065e1d [gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents: 10699
diff changeset
1031 tmp = g_markup_escape_text(text, -1);
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1032 imhtml_paste_insert(data, tmp, TRUE);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1033 g_free(tmp);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1034 }
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1035
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1036 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1037 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1038 char *text;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1039 GtkIMHtml *imhtml = data;
7809
533419ef5569 [gaim-migrate @ 8456]
Nathan Walp <nwalp@pidgin.im>
parents: 7808
diff changeset
1040
8123
0dc9fffb1e28 [gaim-migrate @ 8827]
Mark Doliner <mark@kingant.net>
parents: 8120
diff changeset
1041 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)))
8105
42c7227d6e4d [gaim-migrate @ 8805]
Mark Doliner <mark@kingant.net>
parents: 8091
diff changeset
1042 return;
42c7227d6e4d [gaim-migrate @ 8805]
Mark Doliner <mark@kingant.net>
parents: 8091
diff changeset
1043
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1044 if (selection_data->length < 0) {
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1045 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1046 return;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1047 } else {
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1048 #if 0
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1049 /* Here's some debug code, for figuring out what sent to us over the clipboard. */
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1050 {
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1051 int i;
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1052
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1053 gaim_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t",
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1054 selection_data->format, selection_data->length);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1055
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1056 for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) {
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1057 if ((i % 70) == 0)
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1058 printf("\n\t");
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1059 if (selection_data->data[i] == '\0')
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1060 printf(".");
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1061 else
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1062 printf("%c", selection_data->data[i]);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1063 }
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1064 printf("\n");
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1065 }
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1066 #endif
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1067 text = g_malloc(selection_data->length);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
1068 memcpy(text, selection_data->data, selection_data->length);
7766
9d6ba1c44cb7 [gaim-migrate @ 8411]
Sean Egan <seanegan@gmail.com>
parents: 7754
diff changeset
1069 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1070
8869
ab5a46dd132a [gaim-migrate @ 9637]
Ethan Blanton <elb@pidgin.im>
parents: 8858
diff changeset
1071 if (selection_data->length >= 2 &&
ab5a46dd132a [gaim-migrate @ 9637]
Ethan Blanton <elb@pidgin.im>
parents: 8858
diff changeset
1072 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) {
ab5a46dd132a [gaim-migrate @ 9637]
Ethan Blanton <elb@pidgin.im>
parents: 8858
diff changeset
1073 /* This is UCS-2 */
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1074 char *utf8 = ucs2_to_utf8_with_bom_check(text, selection_data->length);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1075 g_free(text);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1076 text = utf8;
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1077 if (!text) {
8869
ab5a46dd132a [gaim-migrate @ 9637]
Ethan Blanton <elb@pidgin.im>
parents: 8858
diff changeset
1078 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n");
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1079 return;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1080 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1081 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1082
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1083 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1084 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in paste_received_cb\n");
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1085 g_free(text);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1086 return;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1087 }
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1088
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1089 imhtml_paste_insert(imhtml, text, FALSE);
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1090 g_free(text);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1091 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1092
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1093 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1094 {
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1095 #ifdef _WIN32
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1096 /* If we're on windows, let's see if we can get data from the HTML Format
10901
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
1097 clipboard before we try to paste from the GTK buffer */
0711078e0e2d [gaim-migrate @ 12622]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10900
diff changeset
1098 if (!clipboard_paste_html_win32(imhtml)) {
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1099 #endif
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1100 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1101 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE),
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1102 paste_received_cb, imhtml);
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1103 #ifdef _WIN32
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1104 }
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1105 #endif
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1106 g_signal_stop_emission_by_name(imhtml, "paste-clipboard");
7766
9d6ba1c44cb7 [gaim-migrate @ 8411]
Sean Egan <seanegan@gmail.com>
parents: 7754
diff changeset
1107 }
9d6ba1c44cb7 [gaim-migrate @ 8411]
Sean Egan <seanegan@gmail.com>
parents: 7754
diff changeset
1108
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1109 static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1110 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1111 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1112 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1113
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1114 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1115
8740
61a090413b93 [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1116 static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused)
61a090413b93 [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1117 {
61a090413b93 [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1118 gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
61a090413b93 [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1119 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
61a090413b93 [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1120 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1121
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1122 static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1123 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1124 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1125 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1126 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1127 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1128 (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1129 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1130 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1131
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1132 static gboolean gtk_imhtml_button_press_event(GtkIMHtml *imhtml, GdkEventButton *event, gpointer unused)
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
1133 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1134 if (event->button == 2) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1135 int x, y;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1136 GtkTextIter iter;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1137 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1138
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1139 if (!imhtml->editable)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1140 return FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1141
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1142 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1143 GTK_TEXT_WINDOW_TEXT,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1144 event->x,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1145 event->y,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1146 &x,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1147 &y);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1148 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1149 gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1150
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1151 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1152 paste_received_cb, imhtml);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1153
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1154 return TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1155 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1156
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
1157 return FALSE;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
1158 }
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1159
10108
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1160 static gboolean imhtml_message_send(GtkIMHtml *imhtml)
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1161 {
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1162 return FALSE;
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1163 }
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1164
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1165 static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons)
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1166 {
10699
c8b4bf3bf9e5 [gaim-migrate @ 12256]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10695
diff changeset
1167 /* since this function is the handler for the formatting keystrokes,
c8b4bf3bf9e5 [gaim-migrate @ 12256]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10695
diff changeset
1168 we need to check here that the formatting attempted is permitted */
11275
ffc86d9ad8b7 [gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents: 11269
diff changeset
1169 buttons &= imhtml->format_functions;
10699
c8b4bf3bf9e5 [gaim-migrate @ 12256]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10695
diff changeset
1170
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1171 switch (buttons) {
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1172 case GTK_IMHTML_BOLD:
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1173 imhtml_toggle_bold(imhtml);
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1174 break;
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1175 case GTK_IMHTML_ITALIC:
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1176 imhtml_toggle_italic(imhtml);
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1177 break;
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1178 case GTK_IMHTML_UNDERLINE:
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1179 imhtml_toggle_underline(imhtml);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1180 break;
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1181 case GTK_IMHTML_STRIKE:
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1182 imhtml_toggle_strike(imhtml);
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1183 break;
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1184 case GTK_IMHTML_SHRINK:
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1185 imhtml_font_shrink(imhtml);
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1186 break;
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1187 case GTK_IMHTML_GROW:
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
1188 imhtml_font_grow(imhtml);
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1189 break;
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1190 default:
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1191 break;
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1192 }
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1193 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1194
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1195 static void
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1196 gtk_imhtml_finalize (GObject *object)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1197 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1198 GtkIMHtml *imhtml = GTK_IMHTML(object);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1199 GList *scalables;
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1200 GSList *l;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1201
10798
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1202 if (imhtml->scroll_src)
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1203 g_source_remove(imhtml->scroll_src);
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1204 if (imhtml->scroll_time)
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1205 g_timer_destroy(imhtml->scroll_time);
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1206
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
1207 g_hash_table_destroy(imhtml->smiley_data);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1208 gtk_smiley_tree_destroy(imhtml->default_smilies);
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
1209 gdk_cursor_unref(imhtml->hand_cursor);
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
1210 gdk_cursor_unref(imhtml->arrow_cursor);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1211 gdk_cursor_unref(imhtml->text_cursor);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1212
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1213 if(imhtml->tip_window){
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1214 gtk_widget_destroy(imhtml->tip_window);
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1215 }
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1216 if(imhtml->tip_timer)
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1217 gtk_timeout_remove(imhtml->tip_timer);
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1218
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1219 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) {
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
1220 struct scalable_data *sd = scalables->data;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
1221 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1222 scale->free(scale);
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
1223 g_free(sd);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1224 }
7991
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
1225
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1226 for (l = imhtml->im_images; l; l = l->next) {
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
1227 struct im_image_data *img_data = l->data;
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1228 if (imhtml->funcs->image_unref)
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
1229 imhtml->funcs->image_unref(img_data->id);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
1230 g_free(img_data);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1231 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1232
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1233 if (imhtml->clipboard_text_string) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1234 g_free(imhtml->clipboard_text_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1235 g_free(imhtml->clipboard_html_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1236 }
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1237
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1238 g_list_free(imhtml->scalables);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1239 g_slist_free(imhtml->im_images);
9029
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
1240 if (imhtml->protocol_name)
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
1241 g_free(imhtml->protocol_name);
10574
77ef3f2f0df8 [gaim-migrate @ 11966]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10537
diff changeset
1242 if (imhtml->search_string)
77ef3f2f0df8 [gaim-migrate @ 11966]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10537
diff changeset
1243 g_free(imhtml->search_string);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1244 G_OBJECT_CLASS(parent_class)->finalize (object);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1245 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1246
10814
364a2ef907ae [gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents: 10799
diff changeset
1247 /* Boring GTK+ stuff */
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
1248 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1249 {
9007
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1250 GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1251 GtkObjectClass *object_class;
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1252 GtkBindingSet *binding_set;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1253 GObjectClass *gobject_class;
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
1254 object_class = (GtkObjectClass*) klass;
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
1255 gobject_class = (GObjectClass*) klass;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1256 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1257 signals[URL_CLICKED] = g_signal_new("url_clicked",
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1258 G_TYPE_FROM_CLASS(gobject_class),
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1259 G_SIGNAL_RUN_FIRST,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1260 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked),
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1261 NULL,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1262 0,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1263 g_cclosure_marshal_VOID__POINTER,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1264 G_TYPE_NONE, 1,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1265 G_TYPE_POINTER);
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
1266 signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update",
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1267 G_TYPE_FROM_CLASS(gobject_class),
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1268 G_SIGNAL_RUN_FIRST,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1269 G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update),
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1270 NULL,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1271 0,
10076
fbab7f05b054 [gaim-migrate @ 11057]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10062
diff changeset
1272 g_cclosure_marshal_VOID__INT,
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1273 G_TYPE_NONE, 1,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1274 G_TYPE_INT);
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1275 signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle",
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1276 G_TYPE_FROM_CLASS(gobject_class),
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1277 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1278 G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format),
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1279 NULL,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1280 0,
10076
fbab7f05b054 [gaim-migrate @ 11057]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10062
diff changeset
1281 g_cclosure_marshal_VOID__INT,
fbab7f05b054 [gaim-migrate @ 11057]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10062
diff changeset
1282 G_TYPE_NONE, 1,
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
1283 G_TYPE_INT);
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
1284 signals[CLEAR_FORMAT] = g_signal_new("format_function_clear",
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
1285 G_TYPE_FROM_CLASS(gobject_class),
11385
78cd70f4834c [gaim-migrate @ 13612]
Luke Schierer <lschiere@pidgin.im>
parents: 11315
diff changeset
1286 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
1287 G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format),
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
1288 NULL,
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
1289 0,
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1290 g_cclosure_marshal_VOID__VOID,
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1291 G_TYPE_NONE, 0);
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
1292 signals[UPDATE_FORMAT] = g_signal_new("format_function_update",
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1293 G_TYPE_FROM_CLASS(gobject_class),
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1294 G_SIGNAL_RUN_FIRST,
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1295 G_STRUCT_OFFSET(GtkIMHtmlClass, update_format),
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1296 NULL,
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1297 0,
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1298 g_cclosure_marshal_VOID__VOID,
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1299 G_TYPE_NONE, 0);
10108
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1300 signals[MESSAGE_SEND] = g_signal_new("message_send",
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1301 G_TYPE_FROM_CLASS(gobject_class),
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1302 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1303 G_STRUCT_OFFSET(GtkIMHtmlClass, message_send),
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1304 NULL,
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1305 0, g_cclosure_marshal_VOID__VOID,
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1306 G_TYPE_NONE, 0);
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1307
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1308 klass->toggle_format = imhtml_toggle_format;
10108
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1309 klass->message_send = imhtml_message_send;
12672
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
1310 klass->clear_format = imhtml_clear_formatting;
10184
f6918ab1624a [gaim-migrate @ 11299]
Mark Doliner <mark@kingant.net>
parents: 10169
diff changeset
1311
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1312 gobject_class->finalize = gtk_imhtml_finalize;
10184
f6918ab1624a [gaim-migrate @ 11299]
Mark Doliner <mark@kingant.net>
parents: 10169
diff changeset
1313 widget_class->drag_motion = gtk_text_view_drag_motion;
10692
533060d9a2c6 [gaim-migrate @ 12243]
Sean Egan <seanegan@gmail.com>
parents: 10666
diff changeset
1314 widget_class->expose_event = gtk_imhtml_expose_event;
9007
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1315 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color",
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1316 _("Hyperlink color"),
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1317 _("Color to draw hyperlinks."),
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1318 GDK_TYPE_COLOR, G_PARAM_READABLE));
10799
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1319 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-prelight-color",
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1320 _("Hyperlink prelight color"),
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1321 _("Color to draw hyperlinks when mouse is over them."),
6f67d4088da0 [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1322 GDK_TYPE_COLOR, G_PARAM_READABLE));
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1323
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1324 binding_set = gtk_binding_set_by_class (parent_class);
10110
4b276d2e5589 [gaim-migrate @ 11143]
Sean Egan <seanegan@gmail.com>
parents: 10108
diff changeset
1325 gtk_binding_entry_add_signal (binding_set, GDK_b, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_BOLD);
10100
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1326 gtk_binding_entry_add_signal (binding_set, GDK_i, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_ITALIC);
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1327 gtk_binding_entry_add_signal (binding_set, GDK_u, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_UNDERLINE);
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1328 gtk_binding_entry_add_signal (binding_set, GDK_plus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW);
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1329 gtk_binding_entry_add_signal (binding_set, GDK_equal, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW);
fad5d3354cc1 [gaim-migrate @ 11123]
Sean Egan <seanegan@gmail.com>
parents: 10076
diff changeset
1330 gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK);
10108
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1331 binding_set = gtk_binding_set_by_class(klass);
11385
78cd70f4834c [gaim-migrate @ 13612]
Luke Schierer <lschiere@pidgin.im>
parents: 11315
diff changeset
1332 gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0);
10108
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1333 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0);
f0100b414d98 [gaim-migrate @ 11141]
Sean Egan <seanegan@gmail.com>
parents: 10100
diff changeset
1334 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 0);
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1335 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1336
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1337 static void gtk_imhtml_init (GtkIMHtml *imhtml)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1338 {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1339 GtkTextIter iter;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1340 imhtml->text_buffer = gtk_text_buffer_new(NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1341 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1342 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer);
5105
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
1343 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1344 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1345 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1346 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(imhtml), 2);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1347 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1348 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1349
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1350 /* These tags will be used often and can be reused--we create them on init and then apply them by name
8932
849507541e86 [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
1351 * other tags (color, size, face, etc.) will have to be created and applied dynamically
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
1352 * Note that even though we created SUB, SUP, and PRE tags here, we don't really
8932
849507541e86 [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
1353 * apply them anywhere yet. */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1354 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1355 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1356 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1357 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1358 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1359 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1360 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL);
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1361 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1362
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1363 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1364 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1365 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1366 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM);
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1367
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
1368 imhtml->show_comments = TRUE;
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1369
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
1370 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
4902
0bbccc88bc67 [gaim-migrate @ 5236]
Nathan Walp <nwalp@pidgin.im>
parents: 4895
diff changeset
1371 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1372 imhtml->default_smilies = gtk_smiley_tree_new();
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1373
4944
5fe846b7603f [gaim-migrate @ 5278]
Sean Egan <seanegan@gmail.com>
parents: 4926
diff changeset
1374 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL);
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1375 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL);
4944
5fe846b7603f [gaim-migrate @ 5278]
Sean Egan <seanegan@gmail.com>
parents: 4926
diff changeset
1376 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL);
10946
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
1377 g_signal_connect(G_OBJECT(imhtml), "enter-notify-event", G_CALLBACK(gtk_enter_event_notify), NULL);
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
1378 #if (!GTK_CHECK_VERSION(2,2,0))
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
1379 /* See the comment for gtk_key_pressed_cb */
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
1380 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL);
10844
d1f7821c09f4 [gaim-migrate @ 12516]
Mark Doliner <mark@kingant.net>
parents: 10834
diff changeset
1381 #endif
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1382 g_signal_connect(G_OBJECT(imhtml), "button_press_event", G_CALLBACK(gtk_imhtml_button_press_event), NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1383 g_signal_connect(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(preinsert_cb), imhtml);
12673
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
1384 g_signal_connect(G_OBJECT(imhtml->text_buffer), "delete_range", G_CALLBACK(delete_cb), imhtml);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1385 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml);
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
1386 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-child-anchor", G_CALLBACK(insert_ca_cb), imhtml);
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1387 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0,
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1388 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry),
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1389 GDK_ACTION_COPY);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1390 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml);
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1391 g_signal_connect(G_OBJECT(imhtml), "drag_drop", G_CALLBACK(gtk_imhtml_link_drop_cb), imhtml);
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1392
7353
dc35b4a42fea [gaim-migrate @ 7944]
Sean Egan <seanegan@gmail.com>
parents: 7346
diff changeset
1393 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1394 g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1395 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1396 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL);
8740
61a090413b93 [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1397 g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1398
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1399 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set",
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1400 G_CALLBACK(mark_set_so_update_selection_cb), imhtml);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1401
10946
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
1402 gtk_widget_add_events(GTK_WIDGET(imhtml),
2d30f151146d [gaim-migrate @ 12742]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10936
diff changeset
1403 GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK);
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1404
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1405 imhtml->clipboard_text_string = NULL;
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1406 imhtml->clipboard_html_string = NULL;
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
1407
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1408 imhtml->tip = NULL;
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1409 imhtml->tip_timer = 0;
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1410 imhtml->tip_window = NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1411
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1412 imhtml->edit.bold = FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1413 imhtml->edit.italic = FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1414 imhtml->edit.underline = FALSE;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1415 imhtml->edit.forecolor = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1416 imhtml->edit.backcolor = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1417 imhtml->edit.fontface = NULL;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1418 imhtml->edit.fontsize = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1419 imhtml->edit.link = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1420
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1421
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1422 imhtml->scalables = NULL;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1423
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1424 gtk_imhtml_set_editable(imhtml, FALSE);
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1425 g_signal_connect(G_OBJECT(imhtml), "populate-popup",
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1426 G_CALLBACK(hijack_menu_cb), NULL);
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1427
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1428 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1429 /* Register HTML Format as desired clipboard format */
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1430 win_html_fmt = RegisterClipboardFormat("HTML Format");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1431 #endif
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1432 }
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1433
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1434 GtkWidget *gtk_imhtml_new(void *a, void *b)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1435 {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1436 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL));
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1437 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1438
9037
960bb3bd9ba6 [gaim-migrate @ 9813]
Luke Schierer <lschiere@pidgin.im>
parents: 9034
diff changeset
1439 GType gtk_imhtml_get_type()
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1440 {
9037
960bb3bd9ba6 [gaim-migrate @ 9813]
Luke Schierer <lschiere@pidgin.im>
parents: 9034
diff changeset
1441 static GType imhtml_type = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1442
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1443 if (!imhtml_type) {
9037
960bb3bd9ba6 [gaim-migrate @ 9813]
Luke Schierer <lschiere@pidgin.im>
parents: 9034
diff changeset
1444 static const GTypeInfo imhtml_info = {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1445 sizeof(GtkIMHtmlClass),
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1446 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1447 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1448 (GClassInitFunc) gtk_imhtml_class_init,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1449 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1450 NULL,
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1451 sizeof (GtkIMHtml),
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1452 0,
12600
e856f985a0b9 [gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents: 12553
diff changeset
1453 (GInstanceInitFunc) gtk_imhtml_init,
e856f985a0b9 [gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents: 12553
diff changeset
1454 NULL
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1455 };
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1456
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1457 imhtml_type = g_type_register_static(gtk_text_view_get_type(),
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1458 "GtkIMHtml", &imhtml_info, 0);
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1459 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1460
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1461 return imhtml_type;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1462 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1463
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1464 struct url_data {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1465 GObject *object;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1466 gchar *url;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1467 };
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1468
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1469 static void url_data_destroy(gpointer mydata)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1470 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1471 struct url_data *data = mydata;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1472 g_object_unref(data->object);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1473 g_free(data->url);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1474 g_free(data);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1475 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1476
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1477 static void url_open(GtkWidget *w, struct url_data *data) {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1478 if(!data) return;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1479 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url);
7988
d9e831876c28 [gaim-migrate @ 8665]
Nathan Walp <nwalp@pidgin.im>
parents: 7961
diff changeset
1480
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1481 }
5582
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
1482
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1483 static void url_copy(GtkWidget *w, gchar *url) {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1484 GtkClipboard *clipboard;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1485
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1486 clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_PRIMARY);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1487 gtk_clipboard_set_text(clipboard, url, -1);
5582
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
1488
8931
73223e21b943 [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1489 clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_CLIPBOARD);
5582
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
1490 gtk_clipboard_set_text(clipboard, url, -1);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1491 }
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1492
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1493 /* The callback for an event on a link tag. */
10871
6240d7fd5b2c [gaim-migrate @ 12558]
Mark Doliner <mark@kingant.net>
parents: 10865
diff changeset
1494 static gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, gpointer unused) {
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1495 GdkEventButton *event_button = (GdkEventButton *) event;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1496 if (GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1497 return FALSE;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1498 if (event->type == GDK_BUTTON_RELEASE) {
8957
97a1f314b051 [gaim-migrate @ 9731]
Tim Ringenbach <marv@pidgin.im>
parents: 8932
diff changeset
1499 if ((event_button->button == 1) || (event_button->button == 2)) {
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1500 GtkTextIter start, end;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1501 /* we shouldn't open a URL if the user has selected something: */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1502 if (gtk_text_buffer_get_selection_bounds(
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1503 gtk_text_iter_get_buffer(arg2), &start, &end))
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1504 return FALSE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1505
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1506 /* A link was clicked--we emit the "url_clicked" signal
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1507 * with the URL as the argument */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1508 g_object_ref(G_OBJECT(tag));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1509 g_signal_emit(imhtml, signals[URL_CLICKED], 0, g_object_get_data(G_OBJECT(tag), "link_url"));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1510 g_object_unref(G_OBJECT(tag));
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1511 return FALSE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1512 } else if(event_button->button == 3) {
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1513 GtkWidget *img, *item, *menu;
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1514 struct url_data *tempdata = g_new(struct url_data, 1);
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1515 tempdata->object = g_object_ref(imhtml);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1516 tempdata->url = g_strdup(g_object_get_data(G_OBJECT(tag), "link_url"));
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1517
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1518 /* Don't want the tooltip around if user right-clicked on link */
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1519 if (GTK_IMHTML(imhtml)->tip_window) {
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1520 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1521 GTK_IMHTML(imhtml)->tip_window = NULL;
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1522 }
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1523 if (GTK_IMHTML(imhtml)->tip_timer) {
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1524 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1525 GTK_IMHTML(imhtml)->tip_timer = 0;
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1526 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1527 if (GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1528 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1529 else
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1530 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1531 menu = gtk_menu_new();
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1532 g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", tempdata, url_data_destroy);
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1533
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1534 /* buttons and such */
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1535
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1536 if (!strncmp(tempdata->url, "mailto:", 7))
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1537 {
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1538 /* Copy E-Mail Address */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1539 img = gtk_image_new_from_stock(GTK_STOCK_COPY,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1540 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1541 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1542 _("_Copy E-Mail Address"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1543 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1544 g_signal_connect(G_OBJECT(item), "activate",
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1545 G_CALLBACK(url_copy), tempdata->url + 7);
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1546 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1547 }
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1548 else
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1549 {
10936
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1550 /* Open Link in Browser */
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1551 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO,
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1552 GTK_ICON_SIZE_MENU);
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1553 item = gtk_image_menu_item_new_with_mnemonic(
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1554 _("_Open Link in Browser"));
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1555 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1556 g_signal_connect(G_OBJECT(item), "activate",
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1557 G_CALLBACK(url_open), tempdata);
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1558 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
ea9e65f52b4b [gaim-migrate @ 12720]
Mark Doliner <mark@kingant.net>
parents: 10901
diff changeset
1559
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1560 /* Copy Link Location */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1561 img = gtk_image_new_from_stock(GTK_STOCK_COPY,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1562 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1563 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1564 _("_Copy Link Location"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1565 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1566 g_signal_connect(G_OBJECT(item), "activate",
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1567 G_CALLBACK(url_copy), tempdata->url);
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1568 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1569 }
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1570
4756
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
1571
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1572 gtk_widget_show_all(menu);
4756
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
1573 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
1574 event_button->button, event_button->time);
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1575
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1576 return TRUE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1577 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1578 }
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1579 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1580 return TRUE; /* Clicking the right mouse button on a link shouldn't
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1581 be caught by the regular GtkTextView menu */
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1582 else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1583 return FALSE; /* Let clicks go through if we didn't catch anything */
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1584 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1585
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1586 static gboolean
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1587 gtk_text_view_drag_motion (GtkWidget *widget,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1588 GdkDragContext *context,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1589 gint x,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1590 gint y,
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1591 guint time)
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1592 {
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1593 GdkDragAction suggested_action = 0;
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1594
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1595 if (gtk_drag_dest_find_target (widget, context, NULL) == GDK_NONE) {
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1596 /* can't accept any of the offered targets */
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1597 } else {
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1598 GtkWidget *source_widget;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1599 suggested_action = context->suggested_action;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1600 source_widget = gtk_drag_get_source_widget (context);
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1601 if (source_widget == widget) {
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1602 /* Default to MOVE, unless the user has
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1603 * pressed ctrl or alt to affect available actions
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1604 */
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1605 if ((context->actions & GDK_ACTION_MOVE) != 0)
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1606 suggested_action = GDK_ACTION_MOVE;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1607 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1608 }
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1609
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1610 gdk_drag_status (context, suggested_action, time);
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1611
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1612 /* TRUE return means don't propagate the drag motion to parent
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1613 * widgets that may also be drop sites.
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1614 */
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1615 return TRUE;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1616 }
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1617
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1618 static void
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1619 gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data)
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1620 {
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1621 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1622
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1623 if (target != GDK_NONE)
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1624 gtk_drag_get_data (widget, context, target, time);
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1625 else
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1626 gtk_drag_finish (context, FALSE, FALSE, time);
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1627
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1628 return;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1629 }
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1630
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1631 static void
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1632 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y,
11143
5c56223fa24f [gaim-migrate @ 13207]
Mark Doliner <mark@kingant.net>
parents: 11069
diff changeset
1633 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml)
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1634 {
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1635 gchar **links;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1636 gchar *link;
11143
5c56223fa24f [gaim-migrate @ 13207]
Mark Doliner <mark@kingant.net>
parents: 11069
diff changeset
1637 char *text = (char *)sd->data;
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1638 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer);
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1639 GtkTextIter iter;
10782
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1640 gint i = 0;
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1641
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1642 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1643
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1644 if(gtk_imhtml_get_editable(imhtml) && sd->data){
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1645 switch (info) {
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1646 case GTK_IMHTML_DRAG_URL:
11143
5c56223fa24f [gaim-migrate @ 13207]
Mark Doliner <mark@kingant.net>
parents: 11069
diff changeset
1647 /* TODO: Is it really ok to change sd->data...? */
11920
52f27ffe68a5 [gaim-migrate @ 14211]
Mark Doliner <mark@kingant.net>
parents: 11867
diff changeset
1648 gaim_str_strip_char((char *)sd->data, '\r');
11143
5c56223fa24f [gaim-migrate @ 13207]
Mark Doliner <mark@kingant.net>
parents: 11069
diff changeset
1649
5c56223fa24f [gaim-migrate @ 13207]
Mark Doliner <mark@kingant.net>
parents: 11069
diff changeset
1650 links = g_strsplit((char *)sd->data, "\n", 0);
10782
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1651 while((link = links[i]) != NULL){
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1652 if(gaim_str_has_prefix(link, "http://") ||
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1653 gaim_str_has_prefix(link, "https://") ||
11820
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11814
diff changeset
1654 gaim_str_has_prefix(link, "ftp://"))
10782
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1655 {
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1656 gchar *label;
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1657
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1658 if(links[i + 1])
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1659 i++;
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1660
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1661 label = links[i];
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1662
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1663 gtk_imhtml_insert_link(imhtml, mark, link, label);
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1664 } else if (link=='\0') {
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1665 /* Ignore blank lines */
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1666 } else {
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1667 /* Special reasons, aka images being put in via other tag, etc. */
10345
2e01c503aa4f [gaim-migrate @ 11556]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10297
diff changeset
1668 /* ... don't pretend we handled it if we didn't */
2e01c503aa4f [gaim-migrate @ 11556]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10297
diff changeset
1669 gtk_drag_finish(dc, FALSE, FALSE, t);
10782
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1670 g_strfreev(links);
10345
2e01c503aa4f [gaim-migrate @ 11556]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10297
diff changeset
1671 return;
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1672 }
10782
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1673
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1674 i++;
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1675 }
10782
93fd90cbf45c [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1676 g_strfreev(links);
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1677 break;
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1678 case GTK_IMHTML_DRAG_HTML:
10243
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1679 {
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1680 char *utf8 = NULL;
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1681 /* Ewww. This is all because mozilla thinks that text/html is 'for internal use only.'
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1682 * as explained by this comment in gtkhtml:
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1683 *
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1684 * FIXME This hack decides the charset of the selection. It seems that
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1685 * mozilla/netscape alway use ucs2 for text/html
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1686 * and openoffice.org seems to always use utf8 so we try to validate
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1687 * the string as utf8 and if that fails we assume it is ucs2
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1688 *
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1689 * See also the comment on text/html here:
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1690 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1691 */
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1692 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) {
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1693 utf8 = ucs2_to_utf8_with_bom_check(text, sd->length);
10243
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1694
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1695 if (!utf8) {
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1696 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n");
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1697 return;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1698 }
10243
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1699 } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1700 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n");
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1701 return;
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1702 }
10243
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1703
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1704 gtk_imhtml_insert_html_at_iter(imhtml, utf8 ? utf8 : text, 0, &iter);
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1705 g_free(utf8);
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1706 break;
10243
e450f24d1fe1 [gaim-migrate @ 11383]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10217
diff changeset
1707 }
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1708 case GTK_IMHTML_DRAG_TEXT:
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1709 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1710 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n");
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1711 return;
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1712 } else {
10732
c4cb90065e1d [gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents: 10699
diff changeset
1713 char *tmp = g_markup_escape_text(text, -1);
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1714 gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter);
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1715 g_free(tmp);
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1716 }
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1717 break;
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1718 default:
10145
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1719 gtk_drag_finish(dc, FALSE, FALSE, t);
4d484e455839 [gaim-migrate @ 11218]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10110
diff changeset
1720 return;
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1721 }
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1722 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1723 } else {
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1724 gtk_drag_finish(dc, FALSE, FALSE, t);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1725 }
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1726 }
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1727
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
1728 /* this isn't used yet
9300
98f01c233a40 [gaim-migrate @ 10104]
Sean Egan <seanegan@gmail.com>
parents: 9287
diff changeset
1729 static void gtk_smiley_tree_remove (GtkSmileyTree *tree,
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1730 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1731 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1732 GtkSmileyTree *t = tree;
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1733 const gchar *x = smiley->smile;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1734 gint len = 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1735
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1736 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1737 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1738
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1739 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1740 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1741
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1742 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1743 if (pos)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1744 t = t->children [(int) pos - (int) t->values->str];
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1745 else
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1746 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1747
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1748 x++; len++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1749 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1750
4141
ccec4fde84f4 [gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents: 4140
diff changeset
1751 if (t->image) {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1752 t->image = NULL;
4141
ccec4fde84f4 [gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents: 4140
diff changeset
1753 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1754 }
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
1755 */
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
1756
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1757
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1758 static gint
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1759 gtk_smiley_tree_lookup (GtkSmileyTree *tree,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1760 const gchar *text)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1761 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1762 GtkSmileyTree *t = tree;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1763 const gchar *x = text;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1764 gint len = 0;
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1765 gchar *amp;
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1766 gint alen;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1767
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1768 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1769 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1770
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1771 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1772 break;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1773
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1774 if(*x == '&' && gtk_imhtml_is_amp_escape(x, &amp, &alen)) {
10865
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1775 gboolean matched = TRUE;
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1776 /* Make sure all chars of the unescaped value match */
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1777 while (*(amp + 1)) {
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1778 pos = strchr (t->values->str, *amp);
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1779 if (pos)
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1780 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1781 else {
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1782 matched = FALSE;
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1783 break;
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1784 }
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1785 amp++;
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1786 }
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1787 if (!matched)
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1788 break;
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1789
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1790 pos = strchr (t->values->str, *amp);
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1791 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1792 else if (*x == '<') /* Because we're all WYSIWYG now, a '<'
9636
53e3c74b3628 [gaim-migrate @ 10480]
Sean Egan <seanegan@gmail.com>
parents: 9621
diff changeset
1793 * char should only appear as the start of a tag. Perhaps a safer (but costlier)
53e3c74b3628 [gaim-migrate @ 10480]
Sean Egan <seanegan@gmail.com>
parents: 9621
diff changeset
1794 * check would be to call gtk_imhtml_is_tag on it */
10600
9887014b7390 [gaim-migrate @ 12022]
Tim Ringenbach <marv@pidgin.im>
parents: 10589
diff changeset
1795 break;
10865
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1796 else {
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1797 alen = 1;
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1798 pos = strchr (t->values->str, *x);
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1799 }
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1800
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1801 if (pos)
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1802 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1803 else
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1804 break;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1805
10865
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1806 x += alen;
c28766b87f64 [gaim-migrate @ 12549]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10858
diff changeset
1807 len += alen;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1808 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1809
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1810 if (t->image)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1811 return len;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1812
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1813 return 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1814 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1815
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1816 void
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1817 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
10537
74180743304a [gaim-migrate @ 11890]
Mark Doliner <mark@kingant.net>
parents: 10526
diff changeset
1818 const gchar *sml,
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1819 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1820 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1821 GtkSmileyTree *tree;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1822 g_return_if_fail (imhtml != NULL);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1823 g_return_if_fail (GTK_IS_IMHTML (imhtml));
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1824
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1825 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1826 tree = imhtml->default_smilies;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1827 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1828 } else {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1829 tree = gtk_smiley_tree_new();
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
1830 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1831 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1832
12335
3726ff9022f3 [gaim-migrate @ 14639]
Tim Ringenbach <marv@pidgin.im>
parents: 12253
diff changeset
1833 smiley->imhtml = imhtml;
3726ff9022f3 [gaim-migrate @ 14639]
Tim Ringenbach <marv@pidgin.im>
parents: 12253
diff changeset
1834
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1835 gtk_smiley_tree_insert (tree, smiley);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1836 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1837
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1838 static gboolean
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1839 gtk_imhtml_is_smiley (GtkIMHtml *imhtml,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1840 GSList *fonts,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1841 const gchar *text,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1842 gint *len)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1843 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1844 GtkSmileyTree *tree;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1845 GtkIMHtmlFontDetail *font;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1846 char *sml = NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1847
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1848 if (fonts) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1849 font = fonts->data;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1850 sml = font->sml;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1851 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1852
9029
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
1853 if (!sml)
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
1854 sml = imhtml->protocol_name;
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
1855
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
1856 if (!sml || !(tree = g_hash_table_lookup(imhtml->smiley_data, sml)))
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1857 tree = imhtml->default_smilies;
9029
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
1858
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1859 if (tree == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1860 return FALSE;
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1861
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1862 *len = gtk_smiley_tree_lookup (tree, text);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1863 return (*len > 0);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1864 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1865
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1866 GtkIMHtmlSmiley *
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1867 gtk_imhtml_smiley_get(GtkIMHtml *imhtml,
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1868 const gchar *sml,
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1869 const gchar *text)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1870 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1871 GtkSmileyTree *t;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1872 const gchar *x = text;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1873 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1874 t = imhtml->default_smilies;
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1875 else
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1876 t = g_hash_table_lookup(imhtml->smiley_data, sml);
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1877
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1878
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1879 if (t == NULL)
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1880 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1881
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1882 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1883 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1884
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1885 if (!t->values) {
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1886 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1887 }
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1888
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1889 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1890 if (pos) {
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1891 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1892 } else {
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1893 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1894 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1895 x++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1896 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1897
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1898 return t->image;
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1899 }
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1900
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11586
diff changeset
1901 static GdkPixbufAnimation *
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1902 gtk_smiley_tree_image (GtkIMHtml *imhtml,
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1903 const gchar *sml,
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1904 const gchar *text)
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1905 {
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1906
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1907 GtkIMHtmlSmiley *smiley;
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1908
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1909 smiley = gtk_imhtml_smiley_get(imhtml,sml,text);
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1910
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1911 if (!smiley)
8890
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
1912 return NULL;
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
1913
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1914 if (!smiley->icon && smiley->file) {
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1915 smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL);
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1916 } else if (!smiley->icon && smiley->loader) {
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1917 smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader);
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1918 if (smiley->icon)
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1919 g_object_ref(G_OBJECT(smiley->icon));
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1920 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
1921
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
1922 return smiley->icon;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1923 }
8890
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
1924
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1925 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1926 *tag = g_strndup (string, strlen (x)); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1927 *len = strlen (x) + 1; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1928 return TRUE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1929 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1930 (*type)++
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1931
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1932 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1933 const gchar *c = string + strlen (x " "); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1934 gchar e = '"'; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1935 gboolean quote = FALSE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1936 while (*c) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1937 if (*c == '"' || *c == '\'') { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1938 if (quote && (*c == e)) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1939 quote = !quote; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1940 else if (!quote) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1941 quote = !quote; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1942 e = *c; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1943 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1944 } else if (!quote && (*c == '>')) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1945 break; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1946 c++; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1947 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1948 if (*c) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1949 *tag = g_strndup (string, c - string); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1950 *len = c - string + 1; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1951 return TRUE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1952 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1953 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1954 (*type)++
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1955
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1956
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1957 static gboolean
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1958 gtk_imhtml_is_amp_escape (const gchar *string,
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1959 gchar **replace,
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1960 gint *length)
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1961 {
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1962 static char buf[7];
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1963 g_return_val_if_fail (string != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1964 g_return_val_if_fail (replace != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1965 g_return_val_if_fail (length != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1966
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1967 if (!g_ascii_strncasecmp (string, "&amp;", 5)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1968 *replace = "&";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1969 *length = 5;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1970 } else if (!g_ascii_strncasecmp (string, "&lt;", 4)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1971 *replace = "<";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1972 *length = 4;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1973 } else if (!g_ascii_strncasecmp (string, "&gt;", 4)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1974 *replace = ">";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1975 *length = 4;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1976 } else if (!g_ascii_strncasecmp (string, "&nbsp;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1977 *replace = " ";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1978 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1979 } else if (!g_ascii_strncasecmp (string, "&copy;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1980 *replace = "©";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1981 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1982 } else if (!g_ascii_strncasecmp (string, "&quot;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1983 *replace = "\"";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1984 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1985 } else if (!g_ascii_strncasecmp (string, "&reg;", 5)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1986 *replace = "®";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1987 *length = 5;
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
1988 } else if (!g_ascii_strncasecmp (string, "&apos;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1989 *replace = "\'";
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
1990 *length = 6;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1991 } else if (*(string + 1) == '#') {
2022
199ba82faacb [gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2002
diff changeset
1992 guint pound = 0;
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 3000
diff changeset
1993 if ((sscanf (string, "&#%u;", &pound) == 1) && pound != 0) {
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1994 int buflen;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1995 if (*(string + 3 + (gint)log10 (pound)) != ';')
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1996 return FALSE;
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1997 buflen = g_unichar_to_utf8((gunichar)pound, buf);
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1998 buf[buflen] = '\0';
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1999 *replace = buf;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2000 *length = 2;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2001 while (isdigit ((gint) string [*length])) (*length)++;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2002 if (string [*length] == ';') (*length)++;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2003 } else {
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2004 return FALSE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2005 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2006 } else {
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2007 return FALSE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2008 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2009
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2010 return TRUE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2011 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
2012
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2013 static gboolean
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2014 gtk_imhtml_is_tag (const gchar *string,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2015 gchar **tag,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2016 gint *len,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2017 gint *type)
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2018 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2019 char *close;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2020 *type = 1;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2021
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2022
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2023 if (!(close = strchr (string, '>')))
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2024 return FALSE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2025
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2026 VALID_TAG ("B");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2027 VALID_TAG ("BOLD");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2028 VALID_TAG ("/B");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2029 VALID_TAG ("/BOLD");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2030 VALID_TAG ("I");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2031 VALID_TAG ("ITALIC");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2032 VALID_TAG ("/I");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2033 VALID_TAG ("/ITALIC");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2034 VALID_TAG ("U");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2035 VALID_TAG ("UNDERLINE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2036 VALID_TAG ("/U");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2037 VALID_TAG ("/UNDERLINE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2038 VALID_TAG ("S");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2039 VALID_TAG ("STRIKE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2040 VALID_TAG ("/S");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2041 VALID_TAG ("/STRIKE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2042 VALID_TAG ("SUB");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2043 VALID_TAG ("/SUB");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2044 VALID_TAG ("SUP");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2045 VALID_TAG ("/SUP");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2046 VALID_TAG ("PRE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2047 VALID_TAG ("/PRE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2048 VALID_TAG ("TITLE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2049 VALID_TAG ("/TITLE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2050 VALID_TAG ("BR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2051 VALID_TAG ("HR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2052 VALID_TAG ("/FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2053 VALID_TAG ("/A");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2054 VALID_TAG ("P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2055 VALID_TAG ("/P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2056 VALID_TAG ("H3");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2057 VALID_TAG ("/H3");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2058 VALID_TAG ("HTML");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2059 VALID_TAG ("/HTML");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2060 VALID_TAG ("BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2061 VALID_TAG ("/BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2062 VALID_TAG ("FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2063 VALID_TAG ("HEAD");
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2064 VALID_TAG ("/HEAD");
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2065 VALID_TAG ("BINARY");
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2066 VALID_TAG ("/BINARY");
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
2067
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2068 VALID_OPT_TAG ("HR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2069 VALID_OPT_TAG ("FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2070 VALID_OPT_TAG ("BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2071 VALID_OPT_TAG ("A");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2072 VALID_OPT_TAG ("IMG");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2073 VALID_OPT_TAG ("P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2074 VALID_OPT_TAG ("H3");
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
2075 VALID_OPT_TAG ("HTML");
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2076
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2077 VALID_TAG ("CITE");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2078 VALID_TAG ("/CITE");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2079 VALID_TAG ("EM");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2080 VALID_TAG ("/EM");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2081 VALID_TAG ("STRONG");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2082 VALID_TAG ("/STRONG");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2083
5104
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
2084 VALID_OPT_TAG ("SPAN");
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
2085 VALID_TAG ("/SPAN");
5174
376349b04123 [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
2086 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2087 VALID_TAG ("IMG");
8026
17b90334f3cc [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
2088 VALID_TAG("SPAN");
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2089 VALID_OPT_TAG("BR");
7988
d9e831876c28 [gaim-migrate @ 8665]
Nathan Walp <nwalp@pidgin.im>
parents: 7961
diff changeset
2090
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
2091 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) {
2954
f6c4f2187c08 [gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents: 2898
diff changeset
2092 gchar *e = strstr (string + strlen("!--"), "-->");
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2093 if (e) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2094 *len = e - string + strlen ("-->");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2095 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->"));
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2096 return TRUE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2097 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2098 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2099
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2100 *type = -1;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2101 *len = close - string + 1;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2102 *tag = g_strndup(string, *len - 1);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2103 return TRUE;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2104 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2105
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2106 static gchar*
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2107 gtk_imhtml_get_html_opt (gchar *tag,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2108 const gchar *opt)
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2109 {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2110 gchar *t = tag;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2111 gchar *e, *a;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2112 gchar *val;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2113 gint len;
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2114 gchar *c;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2115 GString *ret;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2116
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
2117 while (g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2118 gboolean quote = FALSE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2119 if (*t == '\0') break;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2120 while (*t && !((*t == ' ') && !quote)) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2121 if (*t == '\"')
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2122 quote = ! quote;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2123 t++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2124 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2125 while (*t && (*t == ' ')) t++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2126 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2127
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
2128 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2129 t += strlen (opt);
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2130 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2131 return NULL;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2132 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2133
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2134 if ((*t == '\"') || (*t == '\'')) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2135 e = a = ++t;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2136 while (*e && (*e != *(t - 1))) e++;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2137 if (*e == '\0') {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2138 return NULL;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2139 } else
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2140 val = g_strndup(a, e - a);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2141 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2142 e = a = t;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2143 while (*e && !isspace ((gint) *e)) e++;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2144 val = g_strndup(a, e - a);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2145 }
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2146
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2147 ret = g_string_new("");
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2148 e = val;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2149 while(*e) {
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2150 if(gtk_imhtml_is_amp_escape(e, &c, &len)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2151 ret = g_string_append(ret, c);
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2152 e += len;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2153 } else {
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2154 ret = g_string_append_c(ret, *e);
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2155 e++;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2156 }
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2157 }
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2158
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2159 g_free(val);
8568
88988327a4e0 [gaim-migrate @ 9316]
Mark Doliner <mark@kingant.net>
parents: 8566
diff changeset
2160
88988327a4e0 [gaim-migrate @ 9316]
Mark Doliner <mark@kingant.net>
parents: 8566
diff changeset
2161 return g_string_free(ret, FALSE);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2162 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2163
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2164 /* Inline CSS Support - Douglas Thrift */
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2165 static gchar*
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2166 gtk_imhtml_get_css_opt (gchar *style,
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2167 const gchar *opt)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2168 {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2169 gchar *t = style;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2170 gchar *e, *a;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2171 gchar *val;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2172 gint len;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2173 gchar *c;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2174 GString *ret;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2175
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2176 while (g_ascii_strncasecmp (t, opt, strlen (opt))) {
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2177 /* gboolean quote = FALSE; */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2178 if (*t == '\0') break;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2179 while (*t && !((*t == ' ') /*&& !quote*/)) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2180 /* if (*t == '\"')
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2181 quote = ! quote; */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2182 t++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2183 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2184 while (*t && (*t == ' ')) t++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2185 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2186
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2187 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2188 t += strlen (opt);
10457
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2189 while (*t && (*t == ' ')) t++;
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2190 if (!*t)
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2191 return NULL;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2192 } else {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2193 return NULL;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2194 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2195
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2196 /* if ((*t == '\"') || (*t == '\'')) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2197 e = a = ++t;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2198 while (*e && (*e != *(t - 1))) e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2199 if (*e == '\0') {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2200 return NULL;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2201 } else
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2202 val = g_strndup(a, e - a);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2203 } else {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2204 e = a = t;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2205 while (*e && !isspace ((gint) *e)) e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2206 val = g_strndup(a, e - a);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2207 }*/
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2208
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2209 e = a = t;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2210 while (*e && *e != ';') e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2211 val = g_strndup(a, e - a);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2212
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2213 ret = g_string_new("");
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2214 e = val;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2215 while(*e) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2216 if(gtk_imhtml_is_amp_escape(e, &c, &len)) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2217 ret = g_string_append(ret, c);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2218 e += len;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2219 } else {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2220 ret = g_string_append_c(ret, *e);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2221 e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2222 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2223 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2224
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2225 g_free(val);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2226 val = ret->str;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2227 g_string_free(ret, FALSE);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2228 return val;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2229 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2230
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2231 static const char *accepted_protocols[] = {
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2232 "http://",
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2233 "https://",
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2234 "ftp://"
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2235 };
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
2236
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2237 static const int accepted_protocols_size = 3;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2238
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2239 /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2240 the caller knows how long the protocol string is. */
12412
a88ca6da0b38 [gaim-migrate @ 14719]
Richard Laager <rlaager@wiktel.com>
parents: 12335
diff changeset
2241 static int gtk_imhtml_is_protocol(const char *text)
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2242 {
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2243 gint i;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2244
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2245 for(i=0; i<accepted_protocols_size; i++){
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2246 if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2247 return strlen(accepted_protocols[i]);
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2248 }
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2249 }
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2250 return 0;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2251 }
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2252
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2253 /*
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2254 <KingAnt> marv: The two IM image functions in oscar are gaim_odc_send_im and gaim_odc_incoming
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2255
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2256
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2257 [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2258 [19:59] <KingAnt> marv: I think the image tag used by the core is something like <img id="#"/>
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
2259 [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2260 [20:00] <KingAnt> marv: Where the ID is the what is returned when you add the image to the imgstore using gaim_imgstore_add
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2261 [20:00] <marv> Robot101: so how does the image get passed to serv_got_im() and serv_send_im()? just as the <img id="#" and then the prpl looks it up from the store?
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2262 [20:00] <KingAnt> marv: Right
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2263 [20:00] <marv> alright
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2264
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2265 Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2266 gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2267 function for gaim to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2268 images can be looked up like that, instead of passing a GSList of them.
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2269 */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2270
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2271 void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2272 const gchar *text,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2273 GtkIMHtmlOptions options,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2274 GSList *unused)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2275 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2276 GtkTextIter iter, ins, sel;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2277 GdkRectangle rect;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2278 int y, height, ins_offset = 0, sel_offset = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2279 gboolean fixins = FALSE, fixsel = FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2280
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2281 g_return_if_fail (imhtml != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2282 g_return_if_fail (GTK_IS_IMHTML (imhtml));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2283 g_return_if_fail (text != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2284
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2285
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2286 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2287 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2288 if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2289 fixins = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2290 ins_offset = gtk_text_iter_get_offset(&ins);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2291 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2292
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2293 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2294 if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2295 fixsel = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2296 sel_offset = gtk_text_iter_get_offset(&sel);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2297 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2298
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2299 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2300 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2301
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2302
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2303 if(((y + height) - (rect.y + rect.height)) > height
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2304 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2305 options |= GTK_IMHTML_NO_SCROLL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2306 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2307
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2308 gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2309
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2310 if (fixins) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2311 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2312 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2313 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2314
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2315 if (fixsel) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2316 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2317 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2318 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2319
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2320 if (!(options & GTK_IMHTML_NO_SCROLL)) {
12553
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2321 gtk_imhtml_scroll_to_end(imhtml, (options & GTK_IMHTML_USE_SMOOTHSCROLLING));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2322 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2323 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2324
11006
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2325 #define MAX_SCROLL_TIME 0.4 /* seconds */
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2326 #define SCROLL_DELAY 33 /* milliseconds */
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2327
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2328 /*
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2329 * Smoothly scroll a GtkIMHtml.
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2330 *
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2331 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom.
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2332 */
10871
6240d7fd5b2c [gaim-migrate @ 12558]
Mark Doliner <mark@kingant.net>
parents: 10865
diff changeset
2333 static gboolean scroll_cb(gpointer data)
10798
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2334 {
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2335 GtkIMHtml *imhtml = data;
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2336 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment;
11006
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2337 gdouble max_val = adj->upper - adj->page_size;
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2338
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2339 g_return_val_if_fail(imhtml->scroll_time != NULL, FALSE);
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2340
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2341 if (g_timer_elapsed(imhtml->scroll_time, NULL) > MAX_SCROLL_TIME) {
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2342 /* time's up. jump to the end and kill the timer */
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2343 gtk_adjustment_set_value(adj, max_val);
10798
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2344 g_timer_destroy(imhtml->scroll_time);
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2345 imhtml->scroll_time = NULL;
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2346 return FALSE;
11006
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2347 }
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2348
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2349 /* scroll by 1/3rd the remaining distance */
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2350 gtk_adjustment_set_value(adj, gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3));
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2351 return TRUE;
10798
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2352 }
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2353
12553
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2354 static gboolean smooth_scroll_idle_cb(gpointer data)
10797
5335eb2b8b95 [gaim-migrate @ 12440]
Tim Ringenbach <marv@pidgin.im>
parents: 10795
diff changeset
2355 {
10798
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2356 GtkIMHtml *imhtml = data;
11006
5d3b0a920d83 [gaim-migrate @ 12866]
Mark Doliner <mark@kingant.net>
parents: 10946
diff changeset
2357 imhtml->scroll_src = g_timeout_add(SCROLL_DELAY, scroll_cb, imhtml);
10797
5335eb2b8b95 [gaim-migrate @ 12440]
Tim Ringenbach <marv@pidgin.im>
parents: 10795
diff changeset
2358 return FALSE;
5335eb2b8b95 [gaim-migrate @ 12440]
Tim Ringenbach <marv@pidgin.im>
parents: 10795
diff changeset
2359 }
5335eb2b8b95 [gaim-migrate @ 12440]
Tim Ringenbach <marv@pidgin.im>
parents: 10795
diff changeset
2360
12553
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2361 static gboolean scroll_idle_cb(gpointer data)
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2362 {
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2363 GtkIMHtml *imhtml = data;
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2364 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment;
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2365 if(adj) {
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2366 gtk_adjustment_set_value(adj, adj->upper - adj->page_size);
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2367 }
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2368 imhtml->scroll_src = 0;
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2369 return FALSE;
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2370 }
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2371
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2372 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth)
8729
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
2373 {
10798
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2374 if (imhtml->scroll_time)
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2375 g_timer_destroy(imhtml->scroll_time);
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2376 if (imhtml->scroll_src)
08981462ebbb [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2377 g_source_remove(imhtml->scroll_src);
12553
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2378 if(smooth) {
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2379 imhtml->scroll_time = g_timer_new();
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2380 imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, smooth_scroll_idle_cb, imhtml, NULL);
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2381 } else {
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2382 imhtml->scroll_time = NULL;
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2383 imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL);
9d7fb0b21d9f [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2384 }
8729
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
2385 }
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
2386
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2387 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2388 const gchar *text,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2389 GtkIMHtmlOptions options,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2390 GtkTextIter *iter)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2391 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2392 GdkRectangle rect;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2393 gint pos = 0;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2394 gchar *ws;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2395 gchar *tag;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2396 gchar *bg = NULL;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2397 gint len;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2398 gint tlen, smilelen, wpos=0;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2399 gint type;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2400 const gchar *c;
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2401 gchar *amp;
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2402 gint len_protocol;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2403
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2404 guint bold = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2405 italics = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2406 underline = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2407 strike = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2408 sub = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2409 sup = 0,
1691
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
2410 title = 0,
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2411 pre = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2412
10217
6f49ce1d394d [gaim-migrate @ 11345]
Tim Ringenbach <marv@pidgin.im>
parents: 10184
diff changeset
2413 gboolean br = FALSE;
6f49ce1d394d [gaim-migrate @ 11345]
Tim Ringenbach <marv@pidgin.im>
parents: 10184
diff changeset
2414
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2415 GSList *fonts = NULL;
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
2416 GObject *object;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2417 GtkIMHtmlScalable *scalable = NULL;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2418
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2419 g_return_if_fail (imhtml != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2420 g_return_if_fail (GTK_IS_IMHTML (imhtml));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2421 g_return_if_fail (text != NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2422 c = text;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2423 len = strlen(text);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2424 ws = g_malloc(len + 1);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2425 ws[0] = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2426
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2427 while (pos < len) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2428 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2429 c++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2430 pos++;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2431 ws[wpos] = '\0';
10217
6f49ce1d394d [gaim-migrate @ 11345]
Tim Ringenbach <marv@pidgin.im>
parents: 10184
diff changeset
2432 br = FALSE;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2433 switch (type)
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2434 {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2435 case 1: /* B */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2436 case 2: /* BOLD */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2437 case 54: /* STRONG */
11485
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2438 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2439 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2440
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2441 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD))
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2442 gtk_imhtml_toggle_bold(imhtml);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2443 bold++;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2444 ws[0] = '\0'; wpos = 0;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2445 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2446 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2447 case 3: /* /B */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2448 case 4: /* /BOLD */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2449 case 55: /* /STRONG */
11485
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2450 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2451 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2452 ws[0] = '\0'; wpos = 0;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2453
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2454 if (bold)
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2455 bold--;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2456 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo)
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2457 gtk_imhtml_toggle_bold(imhtml);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2458 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2459 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2460 case 5: /* I */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2461 case 6: /* ITALIC */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2462 case 52: /* EM */
11485
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2463 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2464 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2465 ws[0] = '\0'; wpos = 0;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2466 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC))
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2467 gtk_imhtml_toggle_italic(imhtml);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2468 italics++;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2469 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2470 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2471 case 7: /* /I */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2472 case 8: /* /ITALIC */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2473 case 53: /* /EM */
11485
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2474 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2475 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2476 ws[0] = '\0'; wpos = 0;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2477 if (italics)
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2478 italics--;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2479 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo)
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2480 gtk_imhtml_toggle_italic(imhtml);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2481 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2482 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2483 case 9: /* U */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2484 case 10: /* UNDERLINE */
11485
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2485 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2486 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2487 ws[0] = '\0'; wpos = 0;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2488 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2489 gtk_imhtml_toggle_underline(imhtml);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2490 underline++;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2491 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2492 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2493 case 11: /* /U */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2494 case 12: /* /UNDERLINE */
11485
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2495 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2496 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2497 ws[0] = '\0'; wpos = 0;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2498 if (underline)
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2499 underline--;
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2500 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo)
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2501 gtk_imhtml_toggle_underline(imhtml);
16b0da1f376f [gaim-migrate @ 13727]
Richard Laager <rlaager@wiktel.com>
parents: 11385
diff changeset
2502 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2503 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2504 case 13: /* S */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2505 case 14: /* STRIKE */
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2506 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2507 ws[0] = '\0'; wpos = 0;
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2508 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE))
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2509 gtk_imhtml_toggle_strike(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2510 strike++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2511 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2512 case 15: /* /S */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2513 case 16: /* /STRIKE */
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2514 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2515 ws[0] = '\0'; wpos = 0;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2516 if (strike)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2517 strike--;
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2518 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo)
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2519 gtk_imhtml_toggle_strike(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2520 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2521 case 17: /* SUB */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2522 /* FIXME: reimpliment this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2523 sub++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2524 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2525 case 18: /* /SUB */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2526 /* FIXME: reimpliment this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2527 if (sub)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2528 sub--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2529 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2530 case 19: /* SUP */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2531 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2532 sup++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2533 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2534 case 20: /* /SUP */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2535 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2536 if (sup)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2537 sup--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2538 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2539 case 21: /* PRE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2540 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2541 pre++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2542 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2543 case 22: /* /PRE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2544 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2545 if (pre)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2546 pre--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2547 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2548 case 23: /* TITLE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2549 /* FIXME: what was this supposed to do anyway? */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2550 title++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2551 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2552 case 24: /* /TITLE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2553 /* FIXME: make this undo whatever 23 was supposed to do */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2554 if (title) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2555 if (options & GTK_IMHTML_NO_TITLE) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2556 wpos = 0;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2557 ws [wpos] = '\0';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2558 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2559 title--;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2560 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2561 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2562 case 25: /* BR */
5174
376349b04123 [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
2563 case 58: /* BR/ */
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2564 case 61: /* BR (opt) */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2565 ws[wpos] = '\n';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2566 wpos++;
10217
6f49ce1d394d [gaim-migrate @ 11345]
Tim Ringenbach <marv@pidgin.im>
parents: 10184
diff changeset
2567 br = TRUE;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2568 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2569 case 26: /* HR */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2570 case 42: /* HR (opt) */
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
2571 {
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
2572 int minus;
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
2573 struct scalable_data *sd = g_new(struct scalable_data, 1);
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
2574
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2575 ws[wpos++] = '\n';
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2576 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2577
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
2578 sd->scalable = scalable = gtk_imhtml_hr_new();
11233
f08d22130bb2 [gaim-migrate @ 13373]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11224
diff changeset
2579 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2580 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2581 scalable->add_to(scalable, imhtml, iter);
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
2582 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) +
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
2583 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml));
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
2584 scalable->scale(scalable, rect.width - minus, rect.height);
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
2585 imhtml->scalables = g_list_append(imhtml->scalables, sd);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2586 ws[0] = '\0'; wpos = 0;
7942
3e268e113bf1 [gaim-migrate @ 8613]
Mark Doliner <mark@kingant.net>
parents: 7914
diff changeset
2587 ws[wpos++] = '\n';
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2588
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2589 break;
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
2590 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2591 case 27: /* /FONT */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2592 if (fonts && !imhtml->wbfo) {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2593 GtkIMHtmlFontDetail *font = fonts->data;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2594 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2595 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2596 /* NEW_BIT (NEW_TEXT_BIT); */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2597
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2598 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2599 gtk_imhtml_toggle_fontface(imhtml, NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2600 g_free (font->face);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2601 }
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2602 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2603 gtk_imhtml_toggle_forecolor(imhtml, NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2604 g_free (font->fore);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2605 }
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2606 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2607 gtk_imhtml_toggle_backcolor(imhtml, NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2608 g_free (font->back);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2609 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2610 if (font->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2611 g_free (font->sml);
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2612
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2613 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK)))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2614 gtk_imhtml_font_set_size(imhtml, 3);
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2615
10761
7c6b69eb82f2 [gaim-migrate @ 12365]
Nathan Walp <nwalp@pidgin.im>
parents: 10732
diff changeset
2616
7c6b69eb82f2 [gaim-migrate @ 12365]
Nathan Walp <nwalp@pidgin.im>
parents: 10732
diff changeset
2617 fonts = g_slist_remove (fonts, font);
9245
9b138ebf9ca8 [gaim-migrate @ 10044]
Tim Ringenbach <marv@pidgin.im>
parents: 9229
diff changeset
2618 g_free(font);
9b138ebf9ca8 [gaim-migrate @ 10044]
Tim Ringenbach <marv@pidgin.im>
parents: 9229
diff changeset
2619
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2620 if (fonts) {
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2621 GtkIMHtmlFontDetail *font = fonts->data;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2622
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2623 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2624 gtk_imhtml_toggle_fontface(imhtml, font->face);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2625 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2626 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2627 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2628 gtk_imhtml_toggle_backcolor(imhtml, font->back);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2629 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK)))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2630 gtk_imhtml_font_set_size(imhtml, font->size);
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2631 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2632 }
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2633 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2634 case 28: /* /A */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2635 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2636 gtk_imhtml_toggle_link(imhtml, NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2637 ws[0] = '\0'; wpos = 0;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2638 break;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2639
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2640 case 29: /* P */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2641 case 30: /* /P */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2642 case 31: /* H3 */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2643 case 32: /* /H3 */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2644 case 33: /* HTML */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2645 case 34: /* /HTML */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2646 case 35: /* BODY */
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
2647 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2648 case 36: /* /BODY */
10786
7638c282b1d3 [gaim-migrate @ 12426]
Tim Ringenbach <marv@pidgin.im>
parents: 10782
diff changeset
2649 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
7638c282b1d3 [gaim-migrate @ 12426]
Tim Ringenbach <marv@pidgin.im>
parents: 10782
diff changeset
2650 ws[0] = '\0'; wpos = 0;
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
2651 gtk_imhtml_toggle_background(imhtml, NULL);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
2652 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2653 case 37: /* FONT */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2654 case 38: /* HEAD */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2655 case 39: /* /HEAD */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2656 case 40: /* BINARY */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2657 case 41: /* /BINARY */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2658 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2659 case 43: /* FONT (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2660 {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2661 gchar *color, *back, *face, *size, *sml;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2662 GtkIMHtmlFontDetail *font, *oldfont = NULL;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2663 color = gtk_imhtml_get_html_opt (tag, "COLOR=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2664 back = gtk_imhtml_get_html_opt (tag, "BACK=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2665 face = gtk_imhtml_get_html_opt (tag, "FACE=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2666 size = gtk_imhtml_get_html_opt (tag, "SIZE=");
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2667 sml = gtk_imhtml_get_html_opt (tag, "SML=");
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2668 if (!(color || back || face || size || sml))
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2669 break;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2670
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2671 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2672 ws[0] = '\0'; wpos = 0;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2673
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2674 font = g_new0 (GtkIMHtmlFontDetail, 1);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2675 if (fonts)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2676 oldfont = fonts->data;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2677
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2678 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2679 font->fore = color;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2680 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2681 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2682
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2683 if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2684 font->back = back;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2685 gtk_imhtml_toggle_backcolor(imhtml, font->back);
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2686 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2687
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2688 if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2689 font->face = face;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2690 gtk_imhtml_toggle_fontface(imhtml, font->face);
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2691 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2692
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2693 if (sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2694 font->sml = sml;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2695 else if (oldfont && oldfont->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2696 font->sml = g_strdup(oldfont->sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2697
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2698 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2699 if (*size == '+') {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2700 sscanf (size + 1, "%hd", &font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2701 font->size += 3;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2702 } else if (*size == '-') {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2703 sscanf (size + 1, "%hd", &font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2704 font->size = MAX (0, 3 - font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2705 } else if (isdigit (*size)) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2706 sscanf (size, "%hd", &font->size);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2707 }
6042
460b4ba2d452 [gaim-migrate @ 6492]
Mark Doliner <mark@kingant.net>
parents: 5967
diff changeset
2708 if (font->size > 100)
460b4ba2d452 [gaim-migrate @ 6492]
Mark Doliner <mark@kingant.net>
parents: 5967
diff changeset
2709 font->size = 100;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2710 } else if (oldfont)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2711 font->size = oldfont->size;
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2712 else
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2713 font->size = 3;
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2714 if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK)))
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2715 gtk_imhtml_font_set_size(imhtml, font->size);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2716 g_free(size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2717 fonts = g_slist_prepend (fonts, font);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2718 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2719 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2720 case 44: /* BODY (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2721 if (!(options & GTK_IMHTML_NO_COLOURS)) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2722 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR=");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2723 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2724 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2725 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2726 /* NEW_BIT(NEW_TEXT_BIT); */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2727 if (bg)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2728 g_free(bg);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2729 bg = bgcolor;
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
2730 gtk_imhtml_toggle_background(imhtml, bg);
2885
f72efa29c109 [gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2871
diff changeset
2731 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2732 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2733 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2734 case 45: /* A (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2735 {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2736 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF=");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2737 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2738 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2739 ws[0] = '\0'; wpos = 0;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2740 gtk_imhtml_toggle_link(imhtml, href);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2741 }
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
2742 if (href)
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
2743 g_free(href);
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2744 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2745 break;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2746 case 46: /* IMG (opt) */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2747 case 59: /* IMG */
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2748 {
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
2749 const char *id;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
2750
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
2751 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
2752 ws[0] = '\0'; wpos = 0;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2753
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2754 if (!(imhtml->format_functions & GTK_IMHTML_IMAGE))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2755 break;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2756
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
2757 id = gtk_imhtml_get_html_opt(tag, "ID=");
9186
a9f97d5258f8 [gaim-migrate @ 9981]
Tim Ringenbach <marv@pidgin.im>
parents: 9078
diff changeset
2758 if (!id)
a9f97d5258f8 [gaim-migrate @ 9981]
Tim Ringenbach <marv@pidgin.im>
parents: 9078
diff changeset
2759 break;
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
2760 gtk_imhtml_insert_image_at_iter(imhtml, atoi(id), iter);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
2761 break;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2762 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2763 case 47: /* P (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2764 case 48: /* H3 (opt) */
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
2765 case 49: /* HTML (opt) */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2766 case 50: /* CITE */
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2767 case 51: /* /CITE */
8026
17b90334f3cc [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
2768 case 56: /* SPAN (opt) */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2769 /* Inline CSS Support - Douglas Thrift
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2770 *
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2771 * color
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2772 * background
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2773 * font-family
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2774 * font-size
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2775 * text-decoration: underline
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
2776 *
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
2777 * TODO:
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
2778 * background-color
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
2779 * font-style
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
2780 * font-weight
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2781 */
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2782 {
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2783 gchar *style, *color, *background, *family, *size;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2784 gchar *textdec;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2785 GtkIMHtmlFontDetail *font, *oldfont = NULL;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2786 style = gtk_imhtml_get_html_opt (tag, "style=");
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2787
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2788 if (!style) break;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2789
10457
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2790 color = gtk_imhtml_get_css_opt (style, "color:");
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2791 background = gtk_imhtml_get_css_opt (style, "background:");
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2792 family = gtk_imhtml_get_css_opt (style,
10457
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2793 "font-family:");
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2794 size = gtk_imhtml_get_css_opt (style, "font-size:");
0c020a10d5da [gaim-migrate @ 11725]
Tim Ringenbach <marv@pidgin.im>
parents: 10345
diff changeset
2795 textdec = gtk_imhtml_get_css_opt (style, "text-decoration:");
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2796
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2797 if (!(color || family || size || background || textdec)) {
8120
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
2798 g_free(style);
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
2799 break;
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
2800 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2801
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2802
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2803 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2804 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2805 /* NEW_BIT (NEW_TEXT_BIT); */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2806
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2807 font = g_new0 (GtkIMHtmlFontDetail, 1);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2808 if (fonts)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2809 oldfont = fonts->data;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2810
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2811 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR))
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2812 {
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2813 font->fore = color;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2814 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2815 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2816 else if (oldfont && oldfont->fore)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2817 font->fore = g_strdup(oldfont->fore);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2818
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2819 if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR))
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2820 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2821 font->back = background;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2822 gtk_imhtml_toggle_backcolor(imhtml, font->back);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2823 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2824 else if (oldfont && oldfont->back)
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2825 font->back = g_strdup(oldfont->back);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2826
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2827 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE))
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2828 {
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2829 font->face = family;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2830 gtk_imhtml_toggle_fontface(imhtml, font->face);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2831 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2832 else if (oldfont && oldfont->face)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2833 font->face = g_strdup(oldfont->face);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2834 if (font->face && (atoi(font->face) > 100)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2835 /* WTF is this? */
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
2836 /* Maybe it sets a max size on the font face? I seem to
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
2837 * remember bad things happening if the font size was
9696
a57fa78e5752 [gaim-migrate @ 10555]
Mark Doliner <mark@kingant.net>
parents: 9636
diff changeset
2838 * 2 billion */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2839 g_free(font->face);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2840 font->face = g_strdup("100");
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2841 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2842
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2843 if (oldfont && oldfont->sml)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2844 font->sml = g_strdup(oldfont->sml);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2845
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2846 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) {
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2847 if (g_ascii_strcasecmp(size, "xx-small") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2848 font->size = 1;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2849 else if (g_ascii_strcasecmp(size, "smaller") == 0
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2850 || g_ascii_strcasecmp(size, "x-small") == 0)
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2851 font->size = 2;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2852 else if (g_ascii_strcasecmp(size, "larger") == 0
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2853 || g_ascii_strcasecmp(size, "medium") == 0)
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2854 font->size = 4;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2855 else if (g_ascii_strcasecmp(size, "large") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2856 font->size = 5;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2857 else if (g_ascii_strcasecmp(size, "x-large") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2858 font->size = 6;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2859 else if (g_ascii_strcasecmp(size, "xx-large") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2860 font->size = 7;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2861 else
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2862 font->size = 3;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2863 gtk_imhtml_font_set_size(imhtml, font->size);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2864 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2865 else if (oldfont)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2866 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2867 font->size = oldfont->size;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2868 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2869
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2870 if (oldfont)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2871 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2872 font->underline = oldfont->underline;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2873 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2874 if (textdec && font->underline != 1
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
2875 && g_ascii_strcasecmp(textdec, "underline") == 0
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2876 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2877 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2878 gtk_imhtml_toggle_underline(imhtml);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2879 font->underline = 1;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2880 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2881
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2882 g_free(style);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2883 g_free(size);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2884 fonts = g_slist_prepend (fonts, font);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2885 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2886 break;
5104
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
2887 case 57: /* /SPAN */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2888 /* Inline CSS Support - Douglas Thrift */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2889 if (fonts && !imhtml->wbfo) {
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2890 GtkIMHtmlFontDetail *oldfont = NULL;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2891 GtkIMHtmlFontDetail *font = fonts->data;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2892 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2893 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2894 /* NEW_BIT (NEW_TEXT_BIT); */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2895 fonts = g_slist_remove (fonts, font);
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2896 if (fonts)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2897 oldfont = fonts->data;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2898
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2899 if (!oldfont) {
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2900 gtk_imhtml_font_set_size(imhtml, 3);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2901 if (font->underline)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2902 gtk_imhtml_toggle_underline(imhtml);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2903 gtk_imhtml_toggle_fontface(imhtml, NULL);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2904 gtk_imhtml_toggle_forecolor(imhtml, NULL);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2905 gtk_imhtml_toggle_backcolor(imhtml, NULL);
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2906 }
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2907 else
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2908 {
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2909
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2910 if (font->size != oldfont->size)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2911 gtk_imhtml_font_set_size(imhtml, oldfont->size);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2912
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2913 if (font->underline != oldfont->underline)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2914 gtk_imhtml_toggle_underline(imhtml);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2915
9286
46cfbd17ce3e [gaim-migrate @ 10089]
Tim Ringenbach <marv@pidgin.im>
parents: 9245
diff changeset
2916 if (font->face && (!oldfont->face || strcmp(font->face, oldfont->face) != 0))
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2917 gtk_imhtml_toggle_fontface(imhtml, oldfont->face);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2918
9286
46cfbd17ce3e [gaim-migrate @ 10089]
Tim Ringenbach <marv@pidgin.im>
parents: 9245
diff changeset
2919 if (font->fore && (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0))
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2920 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2921
9286
46cfbd17ce3e [gaim-migrate @ 10089]
Tim Ringenbach <marv@pidgin.im>
parents: 9245
diff changeset
2922 if (font->back && (!oldfont->back || strcmp(font->back, oldfont->back) != 0))
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2923 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back);
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2924 }
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2925
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2926 g_free (font->face);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2927 g_free (font->fore);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2928 g_free (font->back);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2929 g_free (font->sml);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2930
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2931 g_free (font);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2932 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2933 break;
8026
17b90334f3cc [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
2934 case 60: /* SPAN */
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2935 break;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2936 case 62: /* comment */
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2937 /* NEW_BIT (NEW_TEXT_BIT); */
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
2938 ws[wpos] = '\0';
9465
8a4797a608ae [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
2939
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2940 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2941
10815
65c818fb218e [gaim-migrate @ 12470]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10814
diff changeset
2942 if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) {
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
2943 wpos = g_snprintf (ws, len, "%s", tag);
10815
65c818fb218e [gaim-migrate @ 12470]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10814
diff changeset
2944 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
65c818fb218e [gaim-migrate @ 12470]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10814
diff changeset
2945 }
65c818fb218e [gaim-migrate @ 12470]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10814
diff changeset
2946 ws[0] = '\0'; wpos = 0;
65c818fb218e [gaim-migrate @ 12470]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10814
diff changeset
2947
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2948 /* NEW_BIT (NEW_COMMENT_BIT); */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2949 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2950 default:
6882
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
2951 break;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2952 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2953 c += tlen;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2954 pos += tlen;
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
2955 if(tag)
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
2956 g_free(tag); /* This was allocated back in VALID_TAG() */
9029
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2957 } else if (gtk_imhtml_is_smiley(imhtml, fonts, c, &smilelen)) {
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2958 GtkIMHtmlFontDetail *fd;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2959
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2960 gchar *sml = NULL;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2961 if (fonts) {
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2962 fd = fonts->data;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2963 sml = fd->sml;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2964 }
9029
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2965 if (!sml)
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2966 sml = imhtml->protocol_name;
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2967
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2968 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
2969 wpos = g_snprintf (ws, smilelen + 1, "%s", c);
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2970
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2971 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter);
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2972
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
2973 c += smilelen;
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
2974 pos += smilelen;
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2975 wpos = 0;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2976 ws[0] = 0;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2977 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2978 while(*amp) {
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2979 ws [wpos++] = *amp++;
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2980 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2981 c += tlen;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2982 pos += tlen;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2983 } else if (*c == '\n') {
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2984 if (!(options & GTK_IMHTML_NO_NEWLINE)) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2985 ws[wpos] = '\n';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2986 wpos++;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2987 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2988 ws[0] = '\0';
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2989 wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2990 /* NEW_BIT (NEW_TEXT_BIT); */
10217
6f49ce1d394d [gaim-migrate @ 11345]
Tim Ringenbach <marv@pidgin.im>
parents: 10184
diff changeset
2991 } else if (!br) { /* Don't insert a space immediately after an HTML break */
9621
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2992 /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary.
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2993 * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2994 * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2995 * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand?
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2996 * Bu-wahaha! */
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2997 ws[wpos] = ' ';
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2998 wpos++;
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
2999 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
3000 ws[0] = '\0';
de9c4dc072b5 [gaim-migrate @ 10465]
Sean Egan <seanegan@gmail.com>
parents: 9612
diff changeset
3001 wpos = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3002 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3003 c++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
3004 pos++;
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
3005 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
3006 while(len_protocol--){
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3007 /* Skip the next len_protocol characters, but make sure they're
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
3008 copied into the ws array.
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
3009 */
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
3010 ws [wpos++] = *c++;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
3011 pos++;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
3012 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3013 } else if (*c) {
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3014 ws [wpos++] = *c++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
3015 pos++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
3016 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
3017 break;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3018 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3019 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3020 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3021 ws[0] = '\0'; wpos = 0;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3022
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3023 /* NEW_BIT(NEW_TEXT_BIT); */
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3024
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3025 while (fonts) {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3026 GtkIMHtmlFontDetail *font = fonts->data;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3027 fonts = g_slist_remove (fonts, font);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3028 if (font->face)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3029 g_free (font->face);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3030 if (font->fore)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3031 g_free (font->fore);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3032 if (font->back)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3033 g_free (font->back);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3034 if (font->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3035 g_free (font->sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3036 g_free (font);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
3037 }
8932
849507541e86 [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
3038
849507541e86 [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
3039 g_free(ws);
849507541e86 [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
3040 if (bg)
4630
5cdfd20daa07 [gaim-migrate @ 4921]
Sean Egan <seanegan@gmail.com>
parents: 4629
diff changeset
3041 g_free(bg);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3042
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3043 if (!imhtml->wbfo)
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3044 gtk_imhtml_close_tags(imhtml, iter);
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
3045
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
3046 object = g_object_ref(G_OBJECT(imhtml));
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
3047 g_signal_emit(object, signals[UPDATE_FORMAT], 0);
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
3048 g_object_unref(object);
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
3049
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
3050 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
3051
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
3052 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml)
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
3053 {
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
3054 g_hash_table_destroy(imhtml->smiley_data);
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
3055 gtk_smiley_tree_destroy(imhtml->default_smilies);
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
3056 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
4902
0bbccc88bc67 [gaim-migrate @ 5236]
Nathan Walp <nwalp@pidgin.im>
parents: 4895
diff changeset
3057 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
3058 imhtml->default_smilies = gtk_smiley_tree_new();
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
3059 }
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3060
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
3061 void gtk_imhtml_show_comments (GtkIMHtml *imhtml,
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
3062 gboolean show)
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
3063 {
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
3064 imhtml->show_comments = show;
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
3065 }
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
3066
11814
fa17fc619f17 [gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents: 11768
diff changeset
3067 const char *
fa17fc619f17 [gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents: 11768
diff changeset
3068 gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml) {
fa17fc619f17 [gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents: 11768
diff changeset
3069 return imhtml->protocol_name;
fa17fc619f17 [gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents: 11768
diff changeset
3070 }
fa17fc619f17 [gaim-migrate @ 14105]
Richard Laager <rlaager@wiktel.com>
parents: 11768
diff changeset
3071
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3072 void
9029
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3073 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name) {
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3074 if (imhtml->protocol_name)
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3075 g_free(imhtml->protocol_name);
697e169dac12 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3076 imhtml->protocol_name = protocol_name ? g_strdup(protocol_name) : NULL;
8456
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
3077 }
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
3078
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
3079 void
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3080 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3081 GList *l;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3082 GSList *sl;
11234
7d5e8bed8018 [gaim-migrate @ 13377]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11233
diff changeset
3083 GtkTextIter i, i_s, i_e;
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
3084 GObject *object = g_object_ref(G_OBJECT(imhtml));
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3085
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3086 if (start == NULL) {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3087 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3088 start = &i_s;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3089 }
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3090
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3091 if (end == NULL) {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3092 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3093 end = &i_e;
7991
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
3094 }
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3095
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3096 l = imhtml->scalables;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3097 while (l) {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3098 GList *next = l->next;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3099 struct scalable_data *sd = l->data;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3100 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer,
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3101 &i, sd->mark);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3102 if (gtk_text_iter_in_range(&i, start, end)) {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3103 GtkIMHtmlScalable *scale = sd->scalable;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3104 scale->free(scale);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3105 imhtml->scalables = g_list_remove_link(imhtml->scalables, l);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3106 }
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3107 l = next;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3108 }
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3109
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3110 sl = imhtml->im_images;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3111 while (sl) {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3112 GSList *next = sl->next;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3113 struct im_image_data *img_data = sl->data;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3114 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer,
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3115 &i, img_data->mark);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3116 if (gtk_text_iter_in_range(&i, start, end)) {
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3117 if (imhtml->funcs->image_unref)
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3118 imhtml->funcs->image_unref(img_data->id);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3119 imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3120 g_free(img_data);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3121 }
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3122 sl = next;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3123 }
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
3124 gtk_text_buffer_delete(imhtml->text_buffer, start, end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3125
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
3126 g_object_unref(object);
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
3127 }
2363
08c66712364c [gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2349
diff changeset
3128
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
3129 void gtk_imhtml_page_up (GtkIMHtml *imhtml)
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
3130 {
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3131 GdkRectangle rect;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3132 GtkTextIter iter;
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
3133
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3134 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3135 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x,
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3136 rect.y - rect.height);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3137 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3138
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
3139 }
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3140 void gtk_imhtml_page_down (GtkIMHtml *imhtml)
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3141 {
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3142 GdkRectangle rect;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3143 GtkTextIter iter;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3144
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3145 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3146 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x,
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3147 rect.y + rect.height);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3148 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
3149 }
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
3150
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3151 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3152 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id)
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
3153 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3154 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage));
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3155 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img));
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3156
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3157 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3158 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3159 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free;
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
3160
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
3161 im_image->pixbuf = img;
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3162 im_image->image = image;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3163 im_image->width = gdk_pixbuf_get_width(img);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3164 im_image->height = gdk_pixbuf_get_height(img);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3165 im_image->mark = NULL;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
3166 im_image->filename = filename ? g_strdup(filename) : NULL;
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3167 im_image->id = id;
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3168 im_image->filesel = NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3169
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
3170 g_object_ref(img);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3171 return GTK_IMHTML_SCALABLE(im_image);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3172 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3173
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3174 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height)
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3175 {
11867
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3176 GtkIMHtmlImage *im_image = (GtkIMHtmlImage *)scale;
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3177
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3178 if (im_image->width > width || im_image->height > height) {
11840
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
3179 double ratio_w, ratio_h, ratio;
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
3180 int new_h, new_w;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3181 GdkPixbuf *new_image = NULL;
11840
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
3182
11867
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3183 ratio_w = ((double)width - 2) / im_image->width;
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3184 ratio_h = ((double)height - 2) / im_image->height;
11840
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
3185
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
3186 ratio = (ratio_w < ratio_h) ? ratio_w : ratio_h;
047f85200139 [gaim-migrate @ 14131]
Richard Laager <rlaager@wiktel.com>
parents: 11820
diff changeset
3187
11867
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3188 new_w = (int)(im_image->width * ratio);
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3189 new_h = (int)(im_image->height * ratio);
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3190
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3191 new_image = gdk_pixbuf_scale_simple(im_image->pixbuf, new_w, new_h, GDK_INTERP_BILINEAR);
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3192 gtk_image_set_from_pixbuf(im_image->image, new_image);
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3193 g_object_unref(G_OBJECT(new_image));
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3194 } else if (gdk_pixbuf_get_width(gtk_image_get_pixbuf(im_image->image)) != im_image->width) {
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3195 /* Enough space to show the full-size of the image. */
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3196 GdkPixbuf *new_image;
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3197
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3198 new_image = gdk_pixbuf_scale_simple(im_image->pixbuf, im_image->width, im_image->height, GDK_INTERP_BILINEAR);
ff02464a079f [gaim-migrate @ 14158]
Richard Laager <rlaager@wiktel.com>
parents: 11844
diff changeset
3199 gtk_image_set_from_pixbuf(im_image->image, new_image);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3200 g_object_unref(G_OBJECT(new_image));
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3201 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3202 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
3203
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3204 static void
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3205 image_save_yes_cb(GtkIMHtmlImage *image, const char *filename)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3206 {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3207 gchar *type = NULL;
5019
eb1d45bffe66 [gaim-migrate @ 5355]
Luke Schierer <lschiere@pidgin.im>
parents: 5015
diff changeset
3208 GError *error = NULL;
5015
a17a84895585 [gaim-migrate @ 5351]
Nathan Walp <nwalp@pidgin.im>
parents: 5012
diff changeset
3209 #if GTK_CHECK_VERSION(2,2,0)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3210 GSList *formats = gdk_pixbuf_get_formats();
6162
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
3211 #else
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
3212 char *basename = g_path_get_basename(filename);
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
3213 char *ext = strrchr(basename, '.');
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
3214 #endif
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3215
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3216 gtk_widget_destroy(image->filesel);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3217 image->filesel = NULL;
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
3218
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
3219 #if GTK_CHECK_VERSION(2,2,0)
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3220 while (formats) {
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3221 GdkPixbufFormat *format = formats->data;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3222 gchar **extensions = gdk_pixbuf_format_get_extensions(format);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3223 gpointer p = extensions;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3224
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3225 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3226 gchar *fmt_ext = extensions[0];
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3227 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3228
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3229 if(!strcmp(fmt_ext, file_ext)){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3230 type = gdk_pixbuf_format_get_name(format);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3231 break;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3232 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3233
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3234 extensions++;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3235 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3236
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3237 g_strfreev(p);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3238
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3239 if (type)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3240 break;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3241
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3242 formats = formats->next;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3243 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3244
5020
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3245 g_slist_free(formats);
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3246 #else
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3247 /* this is really ugly code, but I think it will work */
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3248 if (ext) {
5020
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3249 ext++;
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3250 if (!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg"))
5020
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3251 type = g_strdup("jpeg");
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3252 else if (!g_ascii_strcasecmp(ext, "png"))
5020
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3253 type = g_strdup("png");
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3254 }
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3255
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3256 g_free(basename);
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3257 #endif
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3258
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3259 /* If I can't find a valid type, I will just tell the user about it and then assume
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3260 it's a png */
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3261 if (!type){
11069
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3262 #if GTK_CHECK_VERSION(2,4,0)
11019
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3263 GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3264 _("<span size='larger' weight='bold'>Unrecognized file type</span>\n\nDefaulting to PNG."));
11069
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3265 #else
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3266 GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3267 _("Unrecognized file type\n\nDefaulting to PNG."));
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3268 #endif
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3269
11019
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3270 g_signal_connect_swapped(dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog);
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3271 gtk_widget_show(dialog);
9717
f105bc0270c7 [gaim-migrate @ 10578]
Mark Doliner <mark@kingant.net>
parents: 9709
diff changeset
3272 type = g_strdup("png");
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3273 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3274
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
3275 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3276
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3277 if (error){
11069
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3278 #if GTK_CHECK_VERSION(2,4,0)
11019
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3279 GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3280 _("<span size='larger' weight='bold'>Error saving image</span>\n\n%s"), error->message);
11069
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3281 #else
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3282 GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3283 _("Error saving image\n\n%s"), error->message);
65db26d0bc90 [gaim-migrate @ 13065]
Richard Laager <rlaager@wiktel.com>
parents: 11019
diff changeset
3284 #endif
11019
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3285 g_signal_connect_swapped(dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog);
86725cfe0550 [gaim-migrate @ 12890]
Mark Doliner <mark@kingant.net>
parents: 11006
diff changeset
3286 gtk_widget_show(dialog);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3287 g_error_free(error);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3288 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3289
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3290 g_free(type);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3291 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3292
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3293 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3294 static void
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3295 image_save_check_if_exists_cb(GtkWidget *widget, gint response, GtkIMHtmlImage *image)
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3296 {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3297 gchar *filename;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3298
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3299 if (response != GTK_RESPONSE_ACCEPT) {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3300 gtk_widget_destroy(widget);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3301 image->filesel = NULL;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3302 return;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3303 }
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3304
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3305 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3306 #else /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3307 static void
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3308 image_save_check_if_exists_cb(GtkWidget *button, GtkIMHtmlImage *image)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3309 {
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3310 gchar *filename;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3311
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3312 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(image->filesel)));
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3313
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3314 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3315 gchar *dirname;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3316 /* append a / is needed */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3317 if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR) {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3318 dirname = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3319 } else {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3320 dirname = g_strdup(filename);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3321 }
9574
fd32ae5ee373 [gaim-migrate @ 10417]
Mark Doliner <mark@kingant.net>
parents: 9573
diff changeset
3322 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), dirname);
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3323 g_free(dirname);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3324 g_free(filename);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3325 return;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3326 }
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3327 #endif /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3328
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3329 /*
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3330 * XXX - We should probably prompt the user to determine if they really
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3331 * want to overwrite the file or not. However, I don't feel like doing
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3332 * that, so we're just always going to overwrite if the file exists.
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3333 */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3334 /*
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3335 if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3336 } else
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3337 image_save_yes_cb(image, filename);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3338 */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3339
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3340 image_save_yes_cb(image, filename);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3341
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3342 g_free(filename);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3343 }
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3344
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3345 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3346 static void
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3347 image_save_cancel_cb(GtkIMHtmlImage *image)
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3348 {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3349 gtk_widget_destroy(image->filesel);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3350 image->filesel = NULL;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3351 }
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3352 #endif /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3353
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3354 static void
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3355 gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image)
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3356 {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3357 if (image->filesel != NULL) {
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3358 gtk_window_present(GTK_WINDOW(image->filesel));
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3359 return;
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3360 }
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3361
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3362 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3363 image->filesel = gtk_file_chooser_dialog_new(_("Save Image"),
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3364 NULL,
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3365 GTK_FILE_CHOOSER_ACTION_SAVE,
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3366 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3367 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3368 NULL);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3369 gtk_dialog_set_default_response(GTK_DIALOG(image->filesel), GTK_RESPONSE_ACCEPT);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3370 if (image->filename != NULL)
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3371 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(image->filesel), image->filename);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3372 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(image->filesel)), "response",
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3373 G_CALLBACK(image_save_check_if_exists_cb), image);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3374 #else /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3375 image->filesel = gtk_file_selection_new(_("Save Image"));
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3376 if (image->filename != NULL)
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3377 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), image->filename);
9574
fd32ae5ee373 [gaim-migrate @ 10417]
Mark Doliner <mark@kingant.net>
parents: 9573
diff changeset
3378 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)), "delete_event",
fd32ae5ee373 [gaim-migrate @ 10417]
Mark Doliner <mark@kingant.net>
parents: 9573
diff changeset
3379 G_CALLBACK(image_save_cancel_cb), image);
fd32ae5ee373 [gaim-migrate @ 10417]
Mark Doliner <mark@kingant.net>
parents: 9573
diff changeset
3380 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->cancel_button),
fd32ae5ee373 [gaim-migrate @ 10417]
Mark Doliner <mark@kingant.net>
parents: 9573
diff changeset
3381 "clicked", G_CALLBACK(image_save_cancel_cb), image);
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3382 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->ok_button), "clicked",
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3383 G_CALLBACK(image_save_check_if_exists_cb), image);
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3384 #endif /* FILECHOOSER */
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3385
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3386 gtk_widget_show(image->filesel);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3387 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3388
9815
650ea0a0d55e [gaim-migrate @ 10686]
Mark Doliner <mark@kingant.net>
parents: 9726
diff changeset
3389 /*
650ea0a0d55e [gaim-migrate @ 10686]
Mark Doliner <mark@kingant.net>
parents: 9726
diff changeset
3390 * So, um, AIM Direct IM lets you send any file, not just images. You can
650ea0a0d55e [gaim-migrate @ 10686]
Mark Doliner <mark@kingant.net>
parents: 9726
diff changeset
3391 * just insert a sound or a file or whatever in a conversation. It's
650ea0a0d55e [gaim-migrate @ 10686]
Mark Doliner <mark@kingant.net>
parents: 9726
diff changeset
3392 * basically like file transfer, except there is an icon to open the file
650ea0a0d55e [gaim-migrate @ 10686]
Mark Doliner <mark@kingant.net>
parents: 9726
diff changeset
3393 * embedded in the conversation. Someone should make the Gaim core handle
650ea0a0d55e [gaim-migrate @ 10686]
Mark Doliner <mark@kingant.net>
parents: 9726
diff changeset
3394 * all of that.
650ea0a0d55e [gaim-migrate @ 10686]
Mark Doliner <mark@kingant.net>
parents: 9726
diff changeset
3395 */
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3396 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3397 {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3398 GdkEventButton *event_button = (GdkEventButton *) event;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3399
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3400 if (event->type == GDK_BUTTON_RELEASE) {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3401 if(event_button->button == 3) {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3402 GtkWidget *img, *item, *menu;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3403 gchar *text = g_strdup_printf(_("_Save Image..."));
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3404 menu = gtk_menu_new();
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3405
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3406 /* buttons and such */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3407 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3408 item = gtk_image_menu_item_new_with_mnemonic(text);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3409 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3410 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3411 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3412
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3413 gtk_widget_show_all(menu);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3414 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3415 event_button->button, event_button->time);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3416
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3417 g_free(text);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3418 return TRUE;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3419 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3420 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3421 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3422 return TRUE; /* Clicking the right mouse button on a link shouldn't
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3423 be caught by the regular GtkTextView menu */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3424 else
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3425 return FALSE; /* Let clicks go through if we didn't catch anything */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3426
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
3427 }
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3428 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3429 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3430 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3431
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3432 g_object_unref(image->pixbuf);
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
3433 if (image->filename)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
3434 g_free(image->filename);
9573
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3435 if (image->filesel)
c8e0426c63ed [gaim-migrate @ 10416]
Mark Doliner <mark@kingant.net>
parents: 9467
diff changeset
3436 gtk_widget_destroy(image->filesel);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3437 g_free(scale);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3438 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3439
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3440 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3441 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3442 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3443 GtkWidget *box = gtk_event_box_new();
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3444 char *tag;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3445 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3446
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3447 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image));
9229
395e62cf7bf6 [gaim-migrate @ 10025]
Tim Ringenbach <marv@pidgin.im>
parents: 9186
diff changeset
3448
395e62cf7bf6 [gaim-migrate @ 10025]
Tim Ringenbach <marv@pidgin.im>
parents: 9186
diff changeset
3449 if(!gtk_check_version(2, 4, 0))
395e62cf7bf6 [gaim-migrate @ 10025]
Tim Ringenbach <marv@pidgin.im>
parents: 9186
diff changeset
3450 g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3451
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3452 gtk_widget_show(GTK_WIDGET(image->image));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3453 gtk_widget_show(box);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3454
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3455 tag = g_strdup_printf("<IMG ID=\"%d\">", image->id);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3456 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", tag, g_free);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3457 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "[Image]");
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3458
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3459 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3460 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3461 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3462
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3463 GtkIMHtmlScalable *gtk_imhtml_hr_new()
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3464 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3465 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3466
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3467 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3468 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3469 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3470
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3471 hr->sep = gtk_hseparator_new();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3472 gtk_widget_set_size_request(hr->sep, 5000, 2);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3473 gtk_widget_show(hr->sep);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3474
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3475 return GTK_IMHTML_SCALABLE(hr);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3476 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3477
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3478 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3479 {
8588
7f7679853f7b [gaim-migrate @ 9339]
Mark Doliner <mark@kingant.net>
parents: 8568
diff changeset
3480 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width - 2, 2);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3481 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3482
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3483 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3484 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3485 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3486 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3487 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>");
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3488 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n");
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3489 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3490 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3491
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3492 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3493 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3494 g_free(scale);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
3495 }
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3496
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3497 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3498 {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3499 GtkTextIter iter, start, end;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3500 gboolean new_search = TRUE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3501
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3502 g_return_val_if_fail(imhtml != NULL, FALSE);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3503 g_return_val_if_fail(text != NULL, FALSE);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3504
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3505 if (imhtml->search_string && !strcmp(text, imhtml->search_string))
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3506 new_search = FALSE;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3507
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3508 if (new_search) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3509 gtk_imhtml_search_clear(imhtml);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3510 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3511 } else {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3512 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter,
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3513 gtk_text_buffer_get_mark(imhtml->text_buffer, "search"));
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3514 }
10574
77ef3f2f0df8 [gaim-migrate @ 11966]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10537
diff changeset
3515 g_free(imhtml->search_string);
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3516 imhtml->search_string = g_strdup(text);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3517
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
3518 if (gtk_source_iter_forward_search(&iter, imhtml->search_string,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
3519 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3520 &start, &end, NULL)) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3521
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3522 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3523 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3524 if (new_search) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3525 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3526 do
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3527 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3528 while (gtk_source_iter_forward_search(&end, imhtml->search_string,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3529 GTK_SOURCE_SEARCH_VISIBLE_ONLY |
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
3530 GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3531 &start, &end, NULL));
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3532 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3533 return TRUE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3534 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3535
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3536 gtk_imhtml_search_clear(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3537
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3538 return FALSE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3539 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3540
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3541 void gtk_imhtml_search_clear(GtkIMHtml *imhtml)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3542 {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3543 GtkTextIter start, end;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3544
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3545 g_return_if_fail(imhtml != NULL);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3546
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3547 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3548 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3549
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3550 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3551 if (imhtml->search_string)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3552 g_free(imhtml->search_string);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3553 imhtml->search_string = NULL;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
3554 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3555
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3556 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3557 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3558 gchar str[18];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3559 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3560
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3561 g_snprintf(str, sizeof(str), "FORECOLOR %s", color);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3562
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3563 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
10858
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3564 if (!tag) {
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3565 GdkColor gcolor;
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3566 if (!gdk_color_parse(color, &gcolor)) {
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3567 gchar tmp[8];
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3568 tmp[0] = '#';
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3569 strncpy(&tmp[1], color, 7);
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3570 tmp[7] = '\0';
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3571 if (!gdk_color_parse(tmp, &gcolor))
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3572 gdk_color_parse("black", &gcolor);
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3573 }
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3574 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", &gcolor, NULL);
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3575 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3576
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3577 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3578 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3579
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3580 static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3581 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3582 gchar str[18];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3583 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3584
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3585 g_snprintf(str, sizeof(str), "BACKCOLOR %s", color);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3586
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3587 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
10858
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3588 if (!tag) {
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3589 GdkColor gcolor;
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3590 if (!gdk_color_parse(color, &gcolor)) {
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3591 gchar tmp[8];
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3592 tmp[0] = '#';
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3593 strncpy(&tmp[1], color, 7);
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3594 tmp[7] = '\0';
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3595 if (!gdk_color_parse(tmp, &gcolor))
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3596 gdk_color_parse("white", &gcolor);
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3597 }
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3598 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background-gdk", &gcolor, NULL);
a29815b897c0 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
3599 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3600
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3601 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3602 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3603
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3604 static GtkTextTag *find_font_background_tag(GtkIMHtml *imhtml, gchar *color)
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3605 {
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3606 gchar str[19];
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3607 GtkTextTag *tag;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3608
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3609 g_snprintf(str, sizeof(str), "BACKGROUND %s", color);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3610
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3611 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3612 if (!tag)
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3613 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, NULL);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3614
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3615 return tag;
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3616 }
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3617
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3618 static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3619 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3620 gchar str[256];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3621 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3622
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3623 g_snprintf(str, sizeof(str), "FONT FACE %s", face);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3624 str[255] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3625
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3626 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3627 if (!tag)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3628 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3629
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3630 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3631 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3632
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3633 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3634 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3635 gchar str[24];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3636 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3637
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3638 g_snprintf(str, sizeof(str), "FONT SIZE %d", size);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3639 str[23] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3640
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3641 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3642 if (!tag) {
10525
ddea15f4cbc2 [gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10524
diff changeset
3643 /* For reasons I don't understand, setting "scale" here scaled
ddea15f4cbc2 [gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10524
diff changeset
3644 * based on some default size other than my theme's default
ddea15f4cbc2 [gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10524
diff changeset
3645 * size. Our size 4 was actually smaller than our size 3 for
ddea15f4cbc2 [gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10524
diff changeset
3646 * me. So this works around that oddity.
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3647 */
10525
ddea15f4cbc2 [gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10524
diff changeset
3648 GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3649 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size",
10525
ddea15f4cbc2 [gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10524
diff changeset
3650 (gint) (pango_font_description_get_size(attr->font) *
10899
1e6bdc7175e9 [gaim-migrate @ 12619]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10871
diff changeset
3651 (double) POINT_SIZE(size)), NULL);
10525
ddea15f4cbc2 [gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10524
diff changeset
3652 gtk_text_attributes_unref(attr);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3653 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3654
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3655 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3656 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3657
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3658 static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3659 const char *prefix, guint len, gboolean homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3660 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3661 GSList *tags, *l;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3662 GtkTextIter iter;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3663
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3664 tags = gtk_text_iter_get_tags(i);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3665
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3666 for (l = tags; l; l = l->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3667 GtkTextTag *tag = l->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3668
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3669 if (tag->name && !strncmp(tag->name, prefix, len))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3670 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3671 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3672
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3673 g_slist_free(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3674
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3675 if (homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3676 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3678 iter = *i;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3679
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3680 while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3681 if (gtk_text_iter_begins_tag(&iter, NULL)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3682 tags = gtk_text_iter_get_toggled_tags(&iter, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3683
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3684 for (l = tags; l; l = l->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3685 GtkTextTag *tag = l->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3686
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3687 if (tag->name && !strncmp(tag->name, prefix, len))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3688 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3689 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3690
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3691 g_slist_free(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3692 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3693 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3694 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3695
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3696 static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3697 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3698 remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3699 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3700
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3701 static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3702 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3703 remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3704 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3705
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3706 static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3707 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3708 remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3709 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3710
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3711 static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3712 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3713 remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3714 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3715
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3716 static void remove_font_background(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3717 {
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3718 remove_tag_by_prefix(imhtml, i, e, "BACKGROUND ", 10, homo);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3719 }
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3720
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3721 static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3722 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3723 remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3724 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3725
12672
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3726 static void
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3727 imhtml_clear_formatting(GtkIMHtml *imhtml)
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3728 {
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3729 GtkTextIter start, end;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3730
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3731 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3732
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3733 /* Move the selection bounds (to select everything), so the format functions
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3734 * will know we want to manipulate the formatting on the entire buffer. */
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3735 #if GTK_CHECK_VERSION(2,4,0)
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3736 gtk_text_buffer_select_range(imhtml->text_buffer, &end, &start);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3737 #else
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3738 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3739 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "selection_bound", &start);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3740 #endif
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3741
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3742 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3743 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3744 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3745 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3746 remove_font_size(imhtml, &start, &end, TRUE);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3747 remove_font_face(imhtml, &start, &end, TRUE);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3748 remove_font_forecolor(imhtml, &start, &end, TRUE);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3749 remove_font_backcolor(imhtml, &start, &end, TRUE);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3750 remove_font_background(imhtml, &start, &end, TRUE);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3751 remove_font_link(imhtml, &start, &end, TRUE);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3752
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3753 imhtml->edit.bold = 0;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3754 imhtml->edit.italic = 0;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3755 imhtml->edit.underline = 0;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3756 imhtml->edit.strike = 0;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3757 imhtml->edit.fontsize = 0;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3758 imhtml->edit.forecolor = NULL;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3759 imhtml->edit.backcolor = NULL;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3760 imhtml->edit.background = NULL;
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3761
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3762 /* Remove the selection, placing the cursor at the end. */
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3763 #if GTK_CHECK_VERSION(2,4,0)
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3764 gtk_text_buffer_select_range(imhtml->text_buffer, &end, &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3765 #else
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3766 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3767 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "selection_bound", &end);
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3768 #endif
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3769 }
4bd7e2ebb4cb [gaim-migrate @ 15015]
Richard Laager <rlaager@wiktel.com>
parents: 12635
diff changeset
3770
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3771 /* Editable stuff */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3772 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3773 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3774 imhtml->insert_offset = gtk_text_iter_get_offset(iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3775 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3776
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3777 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data)
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3778 {
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3779 GtkTextIter start;
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3780
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3781 start = *arg1;
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3782 gtk_text_iter_backward_char(&start);
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3783
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3784 gtk_imhtml_apply_tags_on_insert(user_data, &start, arg1);
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3785 }
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3786
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3787 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3788 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3789 GtkTextIter start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3790
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3791 if (!len)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3792 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3793
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3794 start = *end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3795 gtk_text_iter_set_offset(&start, imhtml->insert_offset);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3796
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3797 gtk_imhtml_apply_tags_on_insert(imhtml, &start, end);
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3798 }
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3799
12673
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3800 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, GtkIMHtml *imhtml)
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3801 {
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3802 GSList *tags, *l;
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3803
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3804 tags = gtk_text_iter_get_tags(start);
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3805 for (l = tags; l != NULL; l = l->next) {
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3806 GtkTextTag *tag = GTK_TEXT_TAG(l->data);
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3807
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3808 if (tag && /* Remove the formatting only if */
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3809 gtk_text_iter_starts_word(start) && /* beginning of a word */
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3810 gtk_text_iter_begins_tag(start, tag) && /* the tag starts with the selection */
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3811 (!gtk_text_iter_has_tag(end, tag) || /* the tag ends within the selection */
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3812 gtk_text_iter_ends_tag(end, tag))) {
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3813 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, start, end);
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3814 if (tag->name &&
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3815 strncmp(tag->name, "LINK ", 5) == 0 && imhtml->edit.link) {
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3816 gtk_imhtml_toggle_link(imhtml, NULL);
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3817 }
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3818 }
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3819 }
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3820 g_slist_free(tags);
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3821 }
de93d4988ad4 [gaim-migrate @ 15016]
Richard Laager <rlaager@wiktel.com>
parents: 12672
diff changeset
3822
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3823 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end)
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3824 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3825 if (imhtml->edit.bold)
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3826 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3827 else
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3828 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3829
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3830 if (imhtml->edit.italic)
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3831 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3832 else
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3833 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3834
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3835 if (imhtml->edit.underline)
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3836 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3837 else
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3838 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3839
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
3840 if (imhtml->edit.strike)
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3841 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", start, end);
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
3842 else
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3843 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", start, end);
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
3844
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3845 if (imhtml->edit.forecolor) {
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3846 remove_font_forecolor(imhtml, start, end, TRUE);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3847 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3848 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor),
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3849 start, end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3850 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3851
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3852 if (imhtml->edit.backcolor) {
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3853 remove_font_backcolor(imhtml, start, end, TRUE);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3854 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3855 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor),
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3856 start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3857 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3858
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3859 if (imhtml->edit.background) {
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3860 remove_font_background(imhtml, start, end, TRUE);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3861 gtk_text_buffer_apply_tag(imhtml->text_buffer,
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3862 find_font_background_tag(imhtml, imhtml->edit.background),
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3863 start, end);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3864 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3865 if (imhtml->edit.fontface) {
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3866 remove_font_face(imhtml, start, end, TRUE);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3867 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3868 find_font_face_tag(imhtml, imhtml->edit.fontface),
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3869 start, end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3870 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3871
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3872 if (imhtml->edit.fontsize) {
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3873 remove_font_size(imhtml, start, end, TRUE);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3874 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3875 find_font_size_tag(imhtml, imhtml->edit.fontsize),
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3876 start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3877 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3878
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3879 if (imhtml->edit.link) {
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3880 remove_font_link(imhtml, start, end, TRUE);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3881 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3882 imhtml->edit.link,
10169
a0529cf29ad4 [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
3883 start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3884 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3885 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3886
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3887 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3888 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3889 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable);
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3890 /*
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3891 * We need a visible caret for accessibility, so mouseless
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3892 * people can highlight stuff.
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3893 */
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3894 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3895 imhtml->editable = editable;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3896 imhtml->format_functions = GTK_IMHTML_ALL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3897
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3898 if (editable)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3899 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set",
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3900 G_CALLBACK(mark_set_cb), imhtml);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3901 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3902
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3903 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3904 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3905 g_return_if_fail(imhtml != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3906
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3907 imhtml->wbfo = wbfo;
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3908 }
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3909
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3910 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons)
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3911 {
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3912 GObject *object = g_object_ref(G_OBJECT(imhtml));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3913 imhtml->format_functions = buttons;
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3914 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons);
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3915 g_object_unref(object);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3916 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3917
8788
262f81346c0a [gaim-migrate @ 9550]
Mark Doliner <mark@kingant.net>
parents: 8786
diff changeset
3918 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml)
262f81346c0a [gaim-migrate @ 9550]
Mark Doliner <mark@kingant.net>
parents: 8786
diff changeset
3919 {
262f81346c0a [gaim-migrate @ 9550]
Mark Doliner <mark@kingant.net>
parents: 8786
diff changeset
3920 return imhtml->format_functions;
262f81346c0a [gaim-migrate @ 9550]
Mark Doliner <mark@kingant.net>
parents: 8786
diff changeset
3921 }
8516
5b25f72c4723 [gaim-migrate @ 9254]
Luke Schierer <lschiere@pidgin.im>
parents: 8515
diff changeset
3922
5b25f72c4723 [gaim-migrate @ 9254]
Luke Schierer <lschiere@pidgin.im>
parents: 8515
diff changeset
3923 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold,
5b25f72c4723 [gaim-migrate @ 9254]
Luke Schierer <lschiere@pidgin.im>
parents: 8515
diff changeset
3924 gboolean *italic, gboolean *underline)
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3925 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3926 if (imhtml->edit.bold)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3927 (*bold) = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3928 if (imhtml->edit.italic)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3929 (*italic) = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3930 if (imhtml->edit.underline)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3931 (*underline) = TRUE;
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3932 }
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3933
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3934 char *
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3935 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml)
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3936 {
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3937 if (imhtml->edit.fontface)
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3938 return g_strdup(imhtml->edit.fontface);
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3939 else
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3940 return NULL;
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3941 }
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3942
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3943 char *
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3944 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml)
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3945 {
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3946 if (imhtml->edit.forecolor)
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3947 return g_strdup(imhtml->edit.forecolor);
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3948 else
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3949 return NULL;
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3950 }
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3951
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3952 char *
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3953 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml)
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3954 {
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3955 if (imhtml->edit.backcolor)
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3956 return g_strdup(imhtml->edit.backcolor);
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3957 else
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3958 return NULL;
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3959 }
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3960
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3961 char *
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3962 gtk_imhtml_get_current_background(GtkIMHtml *imhtml)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3963 {
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3964 if (imhtml->edit.background)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3965 return g_strdup(imhtml->edit.background);
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3966 else
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3967 return NULL;
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3968 }
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
3969
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3970 gint
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3971 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml)
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3972 {
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3973 return imhtml->edit.fontsize;
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3974 }
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3975
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3976 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3977 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3978 return imhtml->editable;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3979 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3980
11269
1cbe76d30e81 [gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents: 11267
diff changeset
3981 void
1cbe76d30e81 [gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents: 11267
diff changeset
3982 gtk_imhtml_clear_formatting(GtkIMHtml *imhtml)
1cbe76d30e81 [gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents: 11267
diff changeset
3983 {
11275
ffc86d9ad8b7 [gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents: 11269
diff changeset
3984 GObject *object;
ffc86d9ad8b7 [gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents: 11269
diff changeset
3985
ffc86d9ad8b7 [gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents: 11269
diff changeset
3986 object = g_object_ref(G_OBJECT(imhtml));
ffc86d9ad8b7 [gaim-migrate @ 13461]
Richard Laager <rlaager@wiktel.com>
parents: 11269
diff changeset
3987 g_signal_emit(object, signals[CLEAR_FORMAT], 0);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
3988
11269
1cbe76d30e81 [gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents: 11267
diff changeset
3989 gtk_widget_grab_focus(GTK_WIDGET(imhtml));
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
3990
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
3991 g_object_unref(object);
11269
1cbe76d30e81 [gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents: 11267
diff changeset
3992 }
1cbe76d30e81 [gaim-migrate @ 13451]
Richard Laager <rlaager@wiktel.com>
parents: 11267
diff changeset
3993
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3994 /*
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3995 * I had this crazy idea about changing the text cursor color to reflex the foreground color
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3996 * of the text about to be entered. This is the place you'd do it, along with the place where
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3997 * we actually set a new foreground color.
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3998 * I may not do this, because people will bitch about Gaim overriding their gtk theme's cursor
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3999 * colors.
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4000 *
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4001 * Just in case I do do this, I asked about what to set the secondary text cursor to.
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4002 *
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
4003 * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
4004 * (12:45:55) ?? ???: understand?
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4005 * (12:46:14) Tim: yeah. i didn't know there was an exact formula
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8729
diff changeset
4006 * (12:46:56) ?? ???: u might need to extract separate each color from RGB
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4007 */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4008
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4009 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4010 GtkIMHtml *imhtml)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4011 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4012 GSList *tags, *l;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4013 GtkTextIter iter;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4014
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4015 if (mark != gtk_text_buffer_get_insert(buffer))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4016 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4017
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4018 if (!gtk_text_buffer_get_char_count(buffer))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4019 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4020
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4021 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4022 if (imhtml->edit.forecolor)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4023 g_free(imhtml->edit.forecolor);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4024 imhtml->edit.forecolor = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4025 if (imhtml->edit.backcolor)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4026 g_free(imhtml->edit.backcolor);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4027 imhtml->edit.backcolor = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4028 if (imhtml->edit.fontface)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4029 g_free(imhtml->edit.fontface);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4030 imhtml->edit.fontface = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4031 imhtml->edit.fontsize = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4032 imhtml->edit.link = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4033
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4034 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4035
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4036
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4037 if (gtk_text_iter_is_end(&iter))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4038 tags = gtk_text_iter_get_toggled_tags(&iter, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4039 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4040 tags = gtk_text_iter_get_tags(&iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4041
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4042 for (l = tags; l != NULL; l = l->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4043 GtkTextTag *tag = GTK_TEXT_TAG(l->data);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4044
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4045 if (tag->name) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4046 if (strcmp(tag->name, "BOLD") == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4047 imhtml->edit.bold = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4048 if (strcmp(tag->name, "ITALICS") == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4049 imhtml->edit.italic = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4050 if (strcmp(tag->name, "UNDERLINE") == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4051 imhtml->edit.underline = TRUE;
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4052 if (strcmp(tag->name, "STRIKE") == 0)
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4053 imhtml->edit.strike = TRUE;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4054 if (strncmp(tag->name, "FORECOLOR ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4055 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4056 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4057 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4058 if (strncmp(tag->name, "FONT FACE ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4059 imhtml->edit.fontface = g_strdup(&(tag->name)[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4060 if (strncmp(tag->name, "FONT SIZE ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4061 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10);
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
4062 if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter))
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4063 imhtml->edit.link = tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4064 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4065 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4066
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4067 g_slist_free(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4068 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4069
12605
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4070 static void imhtml_emit_signal_for_format(GtkIMHtml *imhtml, GtkIMHtmlButtons button)
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4071 {
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4072 GObject *object;
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4073
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4074 g_return_if_fail(imhtml != NULL);
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4075
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4076 object = g_object_ref(G_OBJECT(imhtml));
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4077 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button);
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4078 g_object_unref(object);
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4079 }
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4080
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4081 static void imhtml_toggle_bold(GtkIMHtml *imhtml)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4082 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4083 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4084
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4085 imhtml->edit.bold = !imhtml->edit.bold;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4086
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4087 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4088 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4089 if (imhtml->edit.bold)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4090 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4091 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4092 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4093 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4094 if (imhtml->edit.bold)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4095 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4096 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4097 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4098
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4099 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4100 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4101
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4102 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4103 {
12605
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4104 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_BOLD);
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4105 }
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4106
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4107 static void imhtml_toggle_italic(GtkIMHtml *imhtml)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4108 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4109 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4110
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4111 imhtml->edit.italic = !imhtml->edit.italic;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4112
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4113 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4114 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4115 if (imhtml->edit.italic)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4116 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4117 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4118 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4119 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4120 if (imhtml->edit.italic)
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4121 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4122 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4123 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4124 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4125 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4126
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4127 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4128 {
12605
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4129 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_ITALIC);
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4130 }
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4131
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4132 static void imhtml_toggle_underline(GtkIMHtml *imhtml)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4133 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4134 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4135
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4136 imhtml->edit.underline = !imhtml->edit.underline;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4137
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4138 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4139 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4140 if (imhtml->edit.underline)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4141 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4142 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4143 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4144 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4145 if (imhtml->edit.underline)
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4146 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4147 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4148 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4149 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4150 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4151
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4152 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml)
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4153 {
12605
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4154 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_UNDERLINE);
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4155 }
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4156
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4157 static void imhtml_toggle_strike(GtkIMHtml *imhtml)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4158 {
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4159 GtkTextIter start, end;
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4160
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4161 imhtml->edit.strike = !imhtml->edit.strike;
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4162
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4163 if (imhtml->wbfo) {
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4164 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4165 if (imhtml->edit.strike)
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4166 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4167 else
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4168 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4169 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4170 if (imhtml->edit.strike)
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4171 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4172 else
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4173 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4174 }
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4175 }
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4176
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4177 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4178 {
12605
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4179 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_STRIKE);
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4180 }
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4181
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4182 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4183 {
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4184 GObject *object;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4185 GtkTextIter start, end;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4186
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4187 imhtml->edit.fontsize = size;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4188
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4189 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4190 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4191 remove_font_size(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4192 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4193 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4194 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4195 remove_font_size(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4196 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4197 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4198 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4199
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4200 object = g_object_ref(G_OBJECT(imhtml));
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4201 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK | GTK_IMHTML_GROW);
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4202 g_object_unref(object);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4203 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4204
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4205 static void imhtml_font_shrink(GtkIMHtml *imhtml)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4206 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4207 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4208
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4209 if (imhtml->edit.fontsize == 1)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4210 return;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4211
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4212 if (!imhtml->edit.fontsize)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4213 imhtml->edit.fontsize = 2;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4214 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4215 imhtml->edit.fontsize--;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4216
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4217 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4218 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4219 remove_font_size(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4220 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4221 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4222 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4223 remove_font_size(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4224 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4225 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4226 }
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4227 }
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4228
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4229 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4230 {
12605
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4231 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_SHRINK);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4232 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4233
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4234 static void imhtml_font_grow(GtkIMHtml *imhtml)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4235 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4236 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4237
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4238 if (imhtml->edit.fontsize == MAX_FONT_SIZE)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4239 return;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4240
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4241 if (!imhtml->edit.fontsize)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4242 imhtml->edit.fontsize = 4;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4243 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4244 imhtml->edit.fontsize++;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4245
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4246 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4247 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4248 remove_font_size(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4249 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4250 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4251 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4252 remove_font_size(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4253 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4254 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4255 }
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4256 }
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4257
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4258 void gtk_imhtml_font_grow(GtkIMHtml *imhtml)
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4259 {
12605
cd1d0131e07f [gaim-migrate @ 14940]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
4260 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_GROW);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4261 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4262
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4263 #define gtk_imhtml_toggle_str_tag(imhtml, color, edit_field, remove_func, find_func, button) { \
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4264 GObject *object; \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4265 GtkTextIter start, end; \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4266 \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4267 g_free(edit_field); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4268 edit_field = NULL; \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4269 \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4270 if (color && strcmp(color, "") != 0) { \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4271 edit_field = g_strdup(color); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4272 \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4273 if (imhtml->wbfo) { \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4274 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4275 remove_func(imhtml, &start, &end, TRUE); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4276 gtk_text_buffer_apply_tag(imhtml->text_buffer, \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4277 find_func(imhtml, edit_field), &start, &end); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4278 } else { \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4279 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4280 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4281 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { \
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4282 remove_func(imhtml, &start, &end, FALSE); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4283 gtk_text_buffer_apply_tag(imhtml->text_buffer, \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4284 find_func(imhtml, \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4285 edit_field), \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4286 &start, &end); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4287 } \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4288 } \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4289 } else { \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4290 if (imhtml->wbfo) { \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4291 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4292 remove_func(imhtml, &start, &end, TRUE); \
11968
53d8536c82f6 [gaim-migrate @ 14260]
Mark Doliner <mark@kingant.net>
parents: 11920
diff changeset
4293 } else { \
53d8536c82f6 [gaim-migrate @ 14260]
Mark Doliner <mark@kingant.net>
parents: 11920
diff changeset
4294 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) \
53d8536c82f6 [gaim-migrate @ 14260]
Mark Doliner <mark@kingant.net>
parents: 11920
diff changeset
4295 remove_func(imhtml, &start, &end, TRUE); \
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4296 } \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4297 } \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4298 \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4299 object = g_object_ref(G_OBJECT(imhtml)); \
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4300 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); \
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4301 g_object_unref(object); \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4302 \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4303 return edit_field != NULL; \
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4304 }
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4305
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4306 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4307 {
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4308 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.forecolor, remove_font_forecolor, find_font_forecolor_tag, GTK_IMHTML_FORECOLOR);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4309 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4310
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4311 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4312 {
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4313 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.backcolor, remove_font_backcolor, find_font_backcolor_tag, GTK_IMHTML_BACKCOLOR);
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4314 }
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4315
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4316 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color)
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4317 {
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4318 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.background, remove_font_background, find_font_background_tag, GTK_IMHTML_BACKGROUND);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4319 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4320
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4321 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4322 {
11267
477e5cca8287 [gaim-migrate @ 13449]
Richard Laager <rlaager@wiktel.com>
parents: 11240
diff changeset
4323 gtk_imhtml_toggle_str_tag(imhtml, face, imhtml->edit.fontface, remove_font_face, find_font_face_tag, GTK_IMHTML_FACE);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4324 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4325
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4326 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4327 {
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4328 GObject *object;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4329 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4330 GtkTextTag *linktag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4331 static guint linkno = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4332 gchar str[48];
9007
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4333 GdkColor *color = NULL;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4334
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4335 imhtml->edit.link = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4336
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4337 if (url) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4338 g_snprintf(str, sizeof(str), "LINK %d", linkno++);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4339 str[47] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4340
9007
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4341 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &color, NULL);
9008
6dc1f052edc0 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4342 if (color) {
9007
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4343 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", color, "underline", PANGO_UNDERLINE_SINGLE, NULL);
9008
6dc1f052edc0 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4344 gdk_color_free(color);
6dc1f052edc0 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4345 } else {
9007
0a08f671b591 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4346 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL);
9008
6dc1f052edc0 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4347 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4348 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4349 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4350
11276
17ebda61c6ce [gaim-migrate @ 13463]
Richard Laager <rlaager@wiktel.com>
parents: 11275
diff changeset
4351 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4352 remove_font_link(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4353 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4354 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4355 }
9025
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4356
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4357 object = g_object_ref(G_OBJECT(imhtml));
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4358 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK);
b24967757d46 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4359 g_object_unref(object);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4360 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4361
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4362 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4363 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4364 GtkTextIter iter;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4365
9599
a1029432ae4a [gaim-migrate @ 10442]
Tim Ringenbach <marv@pidgin.im>
parents: 9574
diff changeset
4366 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL))
a1029432ae4a [gaim-migrate @ 10442]
Tim Ringenbach <marv@pidgin.im>
parents: 9574
diff changeset
4367 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE);
a1029432ae4a [gaim-migrate @ 10442]
Tim Ringenbach <marv@pidgin.im>
parents: 9574
diff changeset
4368
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4369 gtk_imhtml_toggle_link(imhtml, url);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4370 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4371 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4372 gtk_imhtml_toggle_link(imhtml, NULL);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4373 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4374
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4375 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4376 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4377 GtkTextMark *mark;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4378 GtkTextIter iter;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4379
11750
21aff66af1e7 [gaim-migrate @ 14041]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11701
diff changeset
4380 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL))
21aff66af1e7 [gaim-migrate @ 14041]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11701
diff changeset
4381 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE);
21aff66af1e7 [gaim-migrate @ 14041]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11701
diff changeset
4382
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4383 mark = gtk_text_buffer_get_insert(imhtml->text_buffer);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4384
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4385 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4386 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4387 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4388
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4389 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4390 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4391 GdkPixbuf *pixbuf = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4392 GdkPixbufAnimation *annipixbuf = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4393 GtkWidget *icon = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4394 GtkTextChildAnchor *anchor;
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
4395 char *unescaped = gaim_unescape_html(smiley);
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11485
diff changeset
4396 GtkIMHtmlSmiley *imhtml_smiley = gtk_imhtml_smiley_get(imhtml, sml, unescaped);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4397
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4398 if (imhtml->format_functions & GTK_IMHTML_SMILEY) {
10522
e8b160971254 [gaim-migrate @ 11838]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
4399 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped);
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4400 if (annipixbuf) {
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4401 if (gdk_pixbuf_animation_is_static_image(annipixbuf)) {
10522
e8b160971254 [gaim-migrate @ 11838]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
4402 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf);
10526
55e7d72fc09a [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4403 if (pixbuf)
10522
e8b160971254 [gaim-migrate @ 11838]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
4404 icon = gtk_image_new_from_pixbuf(pixbuf);
e8b160971254 [gaim-migrate @ 11838]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
4405 } else {
e8b160971254 [gaim-migrate @ 11838]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
4406 icon = gtk_image_new_from_animation(annipixbuf);
e8b160971254 [gaim-migrate @ 11838]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
4407 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4408 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4409 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4410
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4411 if (icon) {
8890
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4412 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4413 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free);
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4414 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free);
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4415
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4416 gtk_widget_show(icon);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4417 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor);
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11485
diff changeset
4418 } else if (imhtml_smiley != NULL && (imhtml->format_functions & GTK_IMHTML_SMILEY)) {
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11485
diff changeset
4419 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11485
diff changeset
4420 imhtml_smiley->anchors = g_slist_append(imhtml_smiley->anchors, anchor);
8890
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4421 } else {
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4422 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4423 }
8890
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4424
6c98b883580a [gaim-migrate @ 9659]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
4425 g_free(unescaped);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4426 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4427
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4428 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter)
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4429 {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4430 GdkPixbuf *pixbuf = NULL;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4431 const char *filename = NULL;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4432 gpointer image;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4433 GdkRectangle rect;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4434 GtkIMHtmlScalable *scalable = NULL;
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
4435 struct scalable_data *sd;
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4436 int minus;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4437
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4438 if (!imhtml->funcs || !imhtml->funcs->image_get ||
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4439 !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data ||
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4440 !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref ||
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4441 !imhtml->funcs->image_unref)
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4442 return;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4443
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4444 image = imhtml->funcs->image_get(id);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4445
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4446 if (image) {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4447 gpointer data;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4448 size_t len;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4449
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4450 data = imhtml->funcs->image_get_data(image);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4451 len = imhtml->funcs->image_get_size(image);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4452
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4453 if (data && len) {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4454 GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4455 gdk_pixbuf_loader_write(loader, data, len, NULL);
12230
423323aa0dbe [gaim-migrate @ 14532]
Richard Laager <rlaager@wiktel.com>
parents: 12229
diff changeset
4456 gdk_pixbuf_loader_close(loader, NULL);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4457 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
9337
d0380151c6d1 [gaim-migrate @ 10145]
Tim Ringenbach <marv@pidgin.im>
parents: 9335
diff changeset
4458 if (pixbuf)
d0380151c6d1 [gaim-migrate @ 10145]
Tim Ringenbach <marv@pidgin.im>
parents: 9335
diff changeset
4459 g_object_ref(G_OBJECT(pixbuf));
d0380151c6d1 [gaim-migrate @ 10145]
Tim Ringenbach <marv@pidgin.im>
parents: 9335
diff changeset
4460 g_object_unref(G_OBJECT(loader));
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4461 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4462
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4463 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4464
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4465 if (pixbuf) {
11299
421007f39e53 [gaim-migrate @ 13499]
Richard Laager <rlaager@wiktel.com>
parents: 11276
diff changeset
4466 struct im_image_data *t = g_new(struct im_image_data, 1);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4467 filename = imhtml->funcs->image_get_filename(image);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4468 imhtml->funcs->image_ref(id);
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
4469 t->id = id;
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
4470 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
4471 imhtml->im_images = g_slist_prepend(imhtml->im_images, t);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4472 } else {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4473 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE,
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4474 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image");
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4475 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4476
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
4477 sd = g_new(struct scalable_data, 1);
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
4478 sd->scalable = scalable = gtk_imhtml_image_new(pixbuf, filename, id);
11233
f08d22130bb2 [gaim-migrate @ 13373]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11224
diff changeset
4479 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4480 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4481 scalable->add_to(scalable, imhtml, iter);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4482 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) +
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4483 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml));
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4484 scalable->scale(scalable, rect.width - minus, rect.height);
11224
409d6a11da51 [gaim-migrate @ 13360]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11143
diff changeset
4485 imhtml->scalables = g_list_append(imhtml->scalables, sd);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4486
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4487 g_object_unref(G_OBJECT(pixbuf));
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4488 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4489
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4490 static const gchar *tag_to_html_start(GtkTextTag *tag)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4491 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4492 const gchar *name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4493 static gchar buf[1024];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4494
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4495 name = tag->name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4496 g_return_val_if_fail(name != NULL, "");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4497
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4498 if (strcmp(name, "BOLD") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4499 return "<b>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4500 } else if (strcmp(name, "ITALICS") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4501 return "<i>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4502 } else if (strcmp(name, "UNDERLINE") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4503 return "<u>";
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4504 } else if (strcmp(name, "STRIKE") == 0) {
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4505 return "<s>";
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4506 } else if (strncmp(name, "LINK ", 5) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4507 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4508 if (tmp) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4509 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4510 buf[sizeof(buf)-1] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4511 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4512 } else {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4513 return "";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4514 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4515 } else if (strncmp(name, "FORECOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4516 g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4517 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4518 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4519 g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4520 return buf;
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4521 } else if (strncmp(name, "BACKGROUND ", 10) == 0) {
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4522 g_snprintf(buf, sizeof(buf), "<body bgcolor=\"%s\">", &name[11]);
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4523 return buf;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4524 } else if (strncmp(name, "FONT FACE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4525 g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4526 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4527 } else if (strncmp(name, "FONT SIZE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4528 g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4529 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4530 } else {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4531 return "";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4532 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4533 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4534
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4535 static const gchar *tag_to_html_end(GtkTextTag *tag)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4536 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4537 const gchar *name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4538
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4539 name = tag->name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4540 g_return_val_if_fail(name != NULL, "");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4541
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4542 if (strcmp(name, "BOLD") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4543 return "</b>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4544 } else if (strcmp(name, "ITALICS") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4545 return "</i>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4546 } else if (strcmp(name, "UNDERLINE") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4547 return "</u>";
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4548 } else if (strcmp(name, "STRIKE") == 0) {
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4549 return "</s>";
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4550 } else if (strncmp(name, "LINK ", 5) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4551 return "</a>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4552 } else if (strncmp(name, "FORECOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4553 return "</font>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4554 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4555 return "</font>";
10776
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4556 } else if (strncmp(name, "BACKGROUND ", 10) == 0) {
b640d066eb51 [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4557 return "</body>";
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4558 } else if (strncmp(name, "FONT FACE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4559 return "</font>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4560 } else if (strncmp(name, "FONT SIZE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4561 return "</font>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4562 } else {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4563 return "";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4564 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4565 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4566
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4567 static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4568 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4569 return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) &&
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4570 !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) ||
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4571 gtk_text_iter_is_end(niter));
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4572 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4573
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4574 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4575 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4576 * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4577 * the actual text. Then check for tags that are toggled off and insert them, after checking the queue.
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8729
diff changeset
4578 * Finally, replace <, >, &, and " with their HTML equivalent.
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4579 */
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4580 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4581 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4582 gunichar c;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4583 GtkTextIter iter, nextiter;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4584 GString *str = g_string_new("");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4585 GSList *tags, *sl;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4586 GQueue *q, *r;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4587 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4588
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4589 q = g_queue_new();
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4590 r = g_queue_new();
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4591
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4592
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4593 gtk_text_iter_order(start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4594 nextiter = iter = *start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4595 gtk_text_iter_forward_char(&nextiter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4596
9071
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4597 /* First add the tags that are already in progress (we don't care about non-printing tags)*/
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4598 tags = gtk_text_iter_get_tags(start);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4599
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4600 for (sl = tags; sl; sl = sl->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4601 tag = sl->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4602 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) {
9071
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4603 if (strlen(tag_to_html_end(tag)) > 0)
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
4604 g_string_append(str, tag_to_html_start(tag));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4605 g_queue_push_tail(q, tag);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4606 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4607 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4608 g_slist_free(tags);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4609
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4610 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4611
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4612 tags = gtk_text_iter_get_tags(&iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4613
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4614 for (sl = tags; sl; sl = sl->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4615 tag = sl->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4616 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) {
9071
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4617 if (strlen(tag_to_html_end(tag)) > 0)
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
4618 g_string_append(str, tag_to_html_start(tag));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4619 g_queue_push_tail(q, tag);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4620 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4621 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4622
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4623
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4624 if (c == 0xFFFC) {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4625 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter);
9071
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4626 if (anchor) {
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4627 char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext");
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4628 if (text)
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4629 str = g_string_append(str, text);
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4630 }
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
4631 } else if (c == '<') {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4632 str = g_string_append(str, "&lt;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4633 } else if (c == '>') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4634 str = g_string_append(str, "&gt;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4635 } else if (c == '&') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4636 str = g_string_append(str, "&amp;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4637 } else if (c == '"') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4638 str = g_string_append(str, "&quot;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4639 } else if (c == '\n') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4640 str = g_string_append(str, "<br>");
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4641 } else {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4642 str = g_string_append_unichar(str, c);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4643 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4644
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4645 tags = g_slist_reverse(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4646 for (sl = tags; sl; sl = sl->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4647 tag = sl->data;
9071
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4648 /** don't worry about non-printing tags ending */
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4649 if (tag_ends_here(tag, &iter, &nextiter) && strlen(tag_to_html_end(tag)) > 0) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4650
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4651 GtkTextTag *tmp;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4652
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4653 while ((tmp = g_queue_pop_tail(q)) != tag) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4654 if (tmp == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4655 break;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4656
9071
2233d33b2285 [gaim-migrate @ 9847]
Tim Ringenbach <marv@pidgin.im>
parents: 9037
diff changeset
4657 if (!tag_ends_here(tmp, &iter, &nextiter) && strlen(tag_to_html_end(tmp)) > 0)
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4658 g_queue_push_tail(r, tmp);
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
4659 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp)));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4660 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4661
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4662 if (tmp == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4663 gaim_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n");
11572
7be60d01519f [gaim-migrate @ 13840]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11525
diff changeset
4664 else
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4665 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag)));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4666
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4667 while ((tmp = g_queue_pop_head(r))) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4668 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tmp)));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4669 g_queue_push_tail(q, tmp);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4670 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4671 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4672 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4673
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4674 g_slist_free(tags);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4675 gtk_text_iter_forward_char(&iter);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4676 gtk_text_iter_forward_char(&nextiter);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4677 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4678
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4679 while ((tag = g_queue_pop_tail(q)))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4680 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag)));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4681
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4682 g_queue_free(q);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4683 g_queue_free(r);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4684 return g_string_free(str, FALSE);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4685 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4686
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
4687 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4688 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4689 if (imhtml->edit.bold)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4690 gtk_imhtml_toggle_bold(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4691
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4692 if (imhtml->edit.italic)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4693 gtk_imhtml_toggle_italic(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4694
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4695 if (imhtml->edit.underline)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4696 gtk_imhtml_toggle_underline(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4697
9924
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4698 if (imhtml->edit.strike)
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4699 gtk_imhtml_toggle_strike(imhtml);
872c4d8c1192 [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4700
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4701 if (imhtml->edit.forecolor)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4702 gtk_imhtml_toggle_forecolor(imhtml, NULL);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4703
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4704 if (imhtml->edit.backcolor)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4705 gtk_imhtml_toggle_backcolor(imhtml, NULL);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4706
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4707 if (imhtml->edit.fontface)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4708 gtk_imhtml_toggle_fontface(imhtml, NULL);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4709
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4710 imhtml->edit.fontsize = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4711
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
4712 if (imhtml->edit.link)
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
4713 gtk_imhtml_toggle_link(imhtml, NULL);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
4714
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
4715 gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4716
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4717 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4718
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4719 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4720 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4721 GtkTextIter start, end;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4722
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4723 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4724 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4725 return gtk_imhtml_get_markup_range(imhtml, &start, &end);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4726 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4727
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4728 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4729 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4730 int i, j, lines;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4731 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4732 char **ret;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4733
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4734 lines = gtk_text_buffer_get_line_count(imhtml->text_buffer);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4735 ret = g_new0(char *, lines + 1);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4736 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4737 end = start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4738 gtk_text_iter_forward_to_line_end(&end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4739
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4740 for (i = 0, j = 0; i < lines; i++) {
9612
a11bc3f5c3e3 [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
4741 if (gtk_text_iter_get_char(&start) != '\n') {
a11bc3f5c3e3 [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
4742 ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end);
a11bc3f5c3e3 [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
4743 if (ret[j] != NULL)
a11bc3f5c3e3 [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
4744 j++;
a11bc3f5c3e3 [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
4745 }
a11bc3f5c3e3 [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
4746
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4747 gtk_text_iter_forward_line(&start);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4748 end = start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4749 gtk_text_iter_forward_to_line_end(&end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4750 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4751
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4752 return ret;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4753 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4754
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4755 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4756 {
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4757 GString *str = g_string_new("");
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4758 GtkTextIter iter, end;
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4759 gunichar c;
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4760
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4761 if (start == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4762 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4763 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4764 iter = *start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4765
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4766 if (stop == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4767 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4768 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4769 end = *stop;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4770
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4771 gtk_text_iter_order(&iter, &end);
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4772
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4773 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) {
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4774 if (c == 0xFFFC) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4775 GtkTextChildAnchor* anchor;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4776 char *text = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4777
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4778 anchor = gtk_text_iter_get_child_anchor(&iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4779 if (anchor)
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
4780 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4781 if (text)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
4782 str = g_string_append(str, text);
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4783 } else {
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4784 g_string_append_unichar(str, c);
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4785 }
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4786 gtk_text_iter_forward_char(&iter);
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4787 }
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4788
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
4789 return g_string_free(str, FALSE);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4790 }
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4791
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4792 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f)
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4793 {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4794 g_return_if_fail(imhtml != NULL);
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4795 imhtml->funcs = f;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
4796 }