annotate src/gtkimhtml.c @ 8735:92cbf9713795

[gaim-migrate @ 9490] Patch by Jonathan Champ to corect the vairous speling mistakes we hav e in the coments and documentaion. Thansk Jonathan! committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 21 Apr 2004 01:34:26 +0000
parents 7024b9145357
children 61a090413b93
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 /*
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * GtkIMHtml
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8026
diff changeset
4 * 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
5 * 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
6 * source distribution.
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * (at your option) any later version.
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * GNU General Public License for more details.
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 */
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
24 #ifdef HAVE_CONFIG_H
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
25 #include <config.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
26 #endif
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
27 #include "debug.h"
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
28 #include "util.h"
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 #include "gtkimhtml.h"
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
30 #include "gtksourceiter.h"
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 #include <gtk/gtk.h>
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
32 #include <glib/gerror.h>
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
33 #include <gdk/gdkkeysyms.h>
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 #include <string.h>
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 #include <ctype.h>
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 #include <stdio.h>
4629
86fd0f6eaa1a [gaim-migrate @ 4920]
Mark Doliner <mark@kingant.net>
parents: 4612
diff changeset
37 #include <stdlib.h>
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 #include <math.h>
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
39 #ifdef HAVE_LANGINFO_CODESET
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
40 #include <langinfo.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
41 #include <locale.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
42 #endif
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
43 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
44 #include <windows.h>
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
45 #endif
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
47 #ifdef ENABLE_NLS
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
48 # include <libintl.h>
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
49 # define _(x) gettext(x)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
50 # ifdef gettext_noop
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
51 # define N_(String) gettext_noop (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
52 # else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
53 # define N_(String) (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
54 # endif
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
55 #else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
56 # define N_(String) (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
57 # define _(x) (x)
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
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
60 #include <pango/pango-font.h>
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
61
5105
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
62 /* GTK+ < 2.2.2 hack, see ui.h for details. */
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
63 #ifndef GTK_WRAP_WORD_CHAR
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
64 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
65 #endif
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
66
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
67 #define TOOLTIP_TIMEOUT 500
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
68
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
69 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
70 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
71 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
72 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter);
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
73 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
74 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
75
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
76 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
77 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
78 #define MAX_FONT_SIZE 7
5367
fc0441fbf159 [gaim-migrate @ 5743]
Luke Schierer <lschiere@pidgin.im>
parents: 5293
diff changeset
79 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1])
8380
4a5b36510665 [gaim-migrate @ 9108]
Sean Egan <seanegan@gmail.com>
parents: 8367
diff changeset
80 static gdouble _point_sizes [] = { .69444444, .8333333, 1, 1.2, 1.44, 1.728, 2.0736};
2349
60c716c32c40 [gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2348
diff changeset
81
8498
0a9b591278bc [gaim-migrate @ 9234]
Sean Egan <seanegan@gmail.com>
parents: 8497
diff changeset
82 enum {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
83 TARGET_HTML,
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
84 TARGET_UTF8_STRING,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
85 TARGET_COMPOUND_TEXT,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
86 TARGET_STRING,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
87 TARGET_TEXT
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
88 };
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
89
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
90 enum {
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
91 DRAG_URL
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
92 };
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
93
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
94 enum {
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
95 URL_CLICKED,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
96 BUTTONS_UPDATE,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
97 TOGGLE_FORMAT,
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
98 CLEAR_FORMAT,
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
99 UPDATE_FORMAT,
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
100 LAST_SIGNAL
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
101 };
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
102 static guint signals [LAST_SIGNAL] = { 0 };
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
103
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
104 GtkTargetEntry selection_targets[] = {
8566
6eb60b70491e [gaim-migrate @ 9313]
Sean Egan <seanegan@gmail.com>
parents: 8548
diff changeset
105 { "text/html", 0, TARGET_HTML },
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
106 { "UTF8_STRING", 0, TARGET_UTF8_STRING },
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
107 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
108 { "STRING", 0, TARGET_STRING },
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
109 { "TEXT", 0, TARGET_TEXT}};
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
110
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
111 GtkTargetEntry link_drag_drop_targets[] = {
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
112 {"x-url/ftp", 0, DRAG_URL},
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
113 {"x-url/http", 0, DRAG_URL},
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
114 {"text/uri-list", 0, DRAG_URL},
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
115 {"_NETSCAPE_URL", 0, DRAG_URL}};
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
116
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
117 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
118 /* Win32 clipboard format value, and functions to convert back and
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
119 * forth between HTML and the clipboard format.
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
120 */
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
121 static UINT win_html_fmt;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
122
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
123 static gchar *
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
124 clipboard_win32_to_html(char *clipboard) {
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
125 const char *begin, *end;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
126 gchar *html;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
127
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
128 begin = strstr(clipboard, "<!--StartFragment");
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
129 while(*begin++ != '>');
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
130 end = strstr(clipboard, "<!--EndFragment");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
131 html = g_strstrip(g_strndup(begin, (end ? (end - begin) : strlen(begin))));
8707
4c7bc4b0f190 [gaim-migrate @ 9460]
Luke Schierer <lschiere@pidgin.im>
parents: 8698
diff changeset
132 return html;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
133 }
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
134
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
135 static gchar *
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
136 clipboard_html_to_win32(char *html) {
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
137 int length;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
138 gchar *ret;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
139 GString *clipboard;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
140
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
141 if (html == NULL)
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
142 return NULL;
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
143
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
144 length = strlen(html);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
145 clipboard = g_string_new ("Version:0.9\r\n");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
146 g_string_append(clipboard, "StartHTML:0000000105\r\n");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
147 g_string_append(clipboard, g_strdup_printf("EndHTML:%010d\r\n", 143 + length));
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
148 g_string_append(clipboard, "StartFragment:0000000105\r\n");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
149 g_string_append(clipboard, g_strdup_printf("EndFragment:%010d\r\n", 143 + length));
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
150 g_string_append(clipboard, "<!--StartFragment-->");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
151 g_string_append(clipboard, html);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
152 g_string_append(clipboard, "<!--EndFragment-->");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
153 ret = clipboard->str;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
154 g_string_free(clipboard, FALSE);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
155 return ret;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
156 }
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
157 #endif
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
158
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
159 static GtkSmileyTree*
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
160 gtk_smiley_tree_new ()
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
161 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
162 return g_new0 (GtkSmileyTree, 1);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
163 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
164
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
165 static void
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
166 gtk_smiley_tree_insert (GtkSmileyTree *tree,
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
167 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
168 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
169 GtkSmileyTree *t = tree;
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
170 const gchar *x = smiley->smile;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
171
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
172 if (!strlen (x))
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
173 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
174
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
175 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
176 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
177 gint index;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
178
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
179 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
180 t->values = g_string_new ("");
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
181
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
182 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
183 if (!pos) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
184 t->values = g_string_append_c (t->values, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
185 index = t->values->len - 1;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
186 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *));
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
187 t->children [index] = g_new0 (GtkSmileyTree, 1);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
188 } else
7386
414c701ef1ff [gaim-migrate @ 7981]
Luke Schierer <lschiere@pidgin.im>
parents: 7384
diff changeset
189 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
190
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
191 t = t->children [index];
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
192
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
193 x++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
194 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
195
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
196 t->image = smiley;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
197 }
4041
3a36ec242415 [gaim-migrate @ 4249]
Sean Egan <seanegan@gmail.com>
parents: 4032
diff changeset
198
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
199
4264
f1876640e568 [gaim-migrate @ 4515]
Sean Egan <seanegan@gmail.com>
parents: 4263
diff changeset
200 void gtk_smiley_tree_destroy (GtkSmileyTree *tree)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
201 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
202 GSList *list = g_slist_append (NULL, tree);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
203
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
204 while (list) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
205 GtkSmileyTree *t = list->data;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
206 gint i;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
207 list = g_slist_remove(list, t);
7384
dc573236dc8b [gaim-migrate @ 7979]
Nathan Walp <nwalp@pidgin.im>
parents: 7371
diff changeset
208 if (t && t->values) {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
209 for (i = 0; i < t->values->len; i++)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
210 list = g_slist_append (list, t->children [i]);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
211 g_string_free (t->values, TRUE);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
212 g_free (t->children);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
213 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
214 g_free (t);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
215 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
216 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
217
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
218 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
219 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
220 GdkRectangle rect;
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
221 int xminus;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
222
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
223 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
224 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
225 GList *iter = GTK_IMHTML(widget)->scalables;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
226
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
227 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) +
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
228 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget));
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
229
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
230 while(iter){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
231 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data);
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
232 scale->scale(scale, rect.width - xminus, rect.height);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
233
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
234 iter = iter->next;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
235 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
236 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
237
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
238 widget->old_rect = rect;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
239 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
240 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
241
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
242 static gint
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
243 gtk_imhtml_tip_paint (GtkIMHtml *imhtml)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
244 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
245 PangoLayout *layout;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
246
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
247 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
248
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
249 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
250
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
251 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
252 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
253 "tooltip", 0, 0, -1, -1);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
254
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
255 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
256 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
257
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
258 g_object_unref(layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
259 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
260 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
261
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
262 static gint
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
263 gtk_imhtml_tip (gpointer data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
264 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
265 GtkIMHtml *imhtml = data;
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
266 PangoFontMetrics *font_metrics;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
267 PangoLayout *layout;
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
268 PangoFont *font;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
269
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
270 gint gap, x, y, h, w, scr_w, baseline_skip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
271
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
272 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
273
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
274 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
275 imhtml->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
276 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
277 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
278
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
279 if (imhtml->tip_window){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
280 gtk_widget_destroy (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
281 imhtml->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
282 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
283
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
284 imhtml->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
285 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
286 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
287 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
288 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips");
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
289 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event",
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
290 G_CALLBACK (gtk_imhtml_tip_paint), imhtml);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
291
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
292 gtk_widget_ensure_style (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
293 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
294 font = pango_context_load_font(pango_layout_get_context(layout),
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
295 imhtml->tip_window->style->font_desc);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
296
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
297 if (font == NULL) {
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
298 char *tmp = pango_font_description_to_string(
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
299 imhtml->tip_window->style->font_desc);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
300
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
301 gaim_debug(GAIM_DEBUG_ERROR, "gtk_imhtml_tip",
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
302 "pango_context_load_font() couldn't load font: '%s'\n",
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
303 tmp);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
304 g_free(tmp);
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
305
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
306 return FALSE;
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
307
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
308 }
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
309
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
310 font_metrics = pango_font_get_metrics(font, NULL);
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
311
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
312
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
313 pango_layout_get_pixel_size(layout, &scr_w, NULL);
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
314 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) +
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
315 pango_font_metrics_get_descent(font_metrics))/ 4);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
316
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
317 if (gap < 2)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
318 gap = 2;
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
319 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) +
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
320 pango_font_metrics_get_descent(font_metrics));
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
321 w = 8 + scr_w;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
322 h = 8 + baseline_skip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
323
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
324 gdk_window_get_pointer (NULL, &x, &y, NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
325 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml)))
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
326 y += GTK_WIDGET(imhtml)->allocation.y;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
327
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
328 scr_w = gdk_screen_width();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
329
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
330 x -= ((w >> 1) + 4);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
331
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
332 if ((x + w) > scr_w)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
333 x -= (x + w) - scr_w;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
334 else if (x < 0)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
335 x = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
336
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
337 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) +
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
338 pango_font_metrics_get_descent(font_metrics));
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
339
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
340 gtk_widget_set_size_request (imhtml->tip_window, w, h);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
341 gtk_widget_show (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
342 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
343
8526
2f81f6478bae [gaim-migrate @ 9265]
Luke Schierer <lschiere@pidgin.im>
parents: 8519
diff changeset
344 pango_font_metrics_unref(font_metrics);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
345 g_object_unref(layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
346
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
347 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
348 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
349
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
350 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
351 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
352 GtkTextIter iter;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
353 GdkWindow *win = event->window;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
354 int x, y;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
355 char *tip = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
356 GSList *tags = NULL, *templist = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
357 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
358 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
359 event->x, event->y, &x, &y);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
360 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
361 tags = gtk_text_iter_get_tags(&iter);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
362
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
363 templist = tags;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
364 while (templist) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
365 GtkTextTag *tag = templist->data;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
366 tip = g_object_get_data(G_OBJECT(tag), "link_url");
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
367 if (tip)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
368 break;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
369 templist = templist->next;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
370 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
371
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
372 if (GTK_IMHTML(imhtml)->tip) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
373 if ((tip == GTK_IMHTML(imhtml)->tip)) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
374 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
375 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
376 /* 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
377 if (GTK_IMHTML(imhtml)->tip_window) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
378 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
379 GTK_IMHTML(imhtml)->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
380 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
381 if (GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
382 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
383 else
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
384 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
385 if (GTK_IMHTML(imhtml)->tip_timer)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
386 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
387 GTK_IMHTML(imhtml)->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
388 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
389
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
390 if(tip){
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
391 if (!GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
392 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
393 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT,
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
394 gtk_imhtml_tip, imhtml);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
395 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
396
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
397 GTK_IMHTML(imhtml)->tip = tip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
398 g_slist_free(tags);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
399 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
400 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
401
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
402 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
403 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
404 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
405 if (GTK_IMHTML(imhtml)->tip_window) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
406 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
407 GTK_IMHTML(imhtml)->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
408 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
409 if (GTK_IMHTML(imhtml)->tip_timer) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
410 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
411 GTK_IMHTML(imhtml)->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
412 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
413 if (GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
414 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->text_cursor);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
415 else
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
416 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
417
8568
88988327a4e0 [gaim-migrate @ 9316]
Mark Doliner <mark@kingant.net>
parents: 8566
diff changeset
418 /* propagate the event normally */
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
419 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
420 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
421
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
422 /*
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
423 * XXX - This should be removed eventually.
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
424 *
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
425 * This function exists to work around a gross bug in GtkTextView.
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
426 * 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
427 * el program go boom.
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
428 *
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
429 * 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
430 * http://bugzilla.gnome.org/show_bug.cgi?id=107939
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
431 */
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
432
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
433 /*
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
434 * I'm adding some keyboard shortcuts too.
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
435 */
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
436
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
437 gboolean gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data)
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
438 {
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
439 char buf[7];
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
440 buf[0] = '\0';
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
441
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
442 if (event->state & GDK_CONTROL_MASK)
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
443 switch (event->keyval) {
8539
e0f659e4323e [gaim-migrate @ 9280]
Ethan Blanton <elb@pidgin.im>
parents: 8526
diff changeset
444 #if (!GTK_CHECK_VERSION(2,2,0))
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
445 case 'a':
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
446 return TRUE;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
447 break;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
448
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
449 case GDK_Home:
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
450 return TRUE;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
451 break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
452
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
453 case GDK_End:
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
454 return TRUE;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
455 break;
8539
e0f659e4323e [gaim-migrate @ 9280]
Ethan Blanton <elb@pidgin.im>
parents: 8526
diff changeset
456 #endif /* Gtk+ >= 2.2.0 */
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
457
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
458 case 'b': /* ctrl-b is GDK_Left, which moves backwards. */
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
459 case 'B':
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
460 if (imhtml->format_functions & GTK_IMHTML_BOLD) {
8456
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
461 if(imhtml->html_shortcuts) {
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
462 gtk_imhtml_toggle_bold(imhtml);
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
463 return TRUE;
8456
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
464 }
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
465 }
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
466 return FALSE;
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
467 break;
8654
44d6285a87af [gaim-migrate @ 9406]
Ethan Blanton <elb@pidgin.im>
parents: 8588
diff changeset
468
44d6285a87af [gaim-migrate @ 9406]
Ethan Blanton <elb@pidgin.im>
parents: 8588
diff changeset
469 #ifdef LAY_OFF_MY_FRIGGIN_KEYBINDINGS
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
470 case 'f':
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
471 case 'F':
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
472 /*set_toggle(gtkconv->toolbar.font,
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
473 !gtk_toggle_button_get_active(
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
474 GTK_TOGGLE_BUTTON(gtkconv->toolbar.font)));*/
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
475
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
476 return TRUE;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
477 break;
8654
44d6285a87af [gaim-migrate @ 9406]
Ethan Blanton <elb@pidgin.im>
parents: 8588
diff changeset
478 #endif /* this doesn't even DO anything */
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
479
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
480 case 'i':
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
481 case 'I':
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
482 if (imhtml->format_functions & GTK_IMHTML_ITALIC) {
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
483 if(imhtml->html_shortcuts) {
8456
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
484 gtk_imhtml_toggle_italic(imhtml);
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
485 return TRUE;
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
486 }
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
487 }
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
488 return FALSE;
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
489 break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
490
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
491 case 'u': /* ctrl-u is GDK_Clear, which clears the line. */
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
492 case 'U':
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
493 if (imhtml->format_functions & GTK_IMHTML_UNDERLINE) {
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
494 if(imhtml->html_shortcuts) {
8456
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
495 gtk_imhtml_toggle_underline(imhtml);
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
496 return TRUE;
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
497 }
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
498 }
8466
5562e8a74c94 [gaim-migrate @ 9196]
Luke Schierer <lschiere@pidgin.im>
parents: 8457
diff changeset
499 return FALSE;
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
500 break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
501
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
502 case '-':
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
503 if (imhtml->format_functions & GTK_IMHTML_SHRINK)
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
504 gtk_imhtml_font_shrink(imhtml);
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
505 return TRUE;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
506 break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
507
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
508 case '=':
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
509 case '+':
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
510 if (imhtml->format_functions & GTK_IMHTML_GROW)
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
511 gtk_imhtml_font_grow(imhtml);
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
512 return TRUE;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
513 break;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
514
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
515 case '1': strcpy(buf, ":-)"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
516 case '2': strcpy(buf, ":-("); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
517 case '3': strcpy(buf, ";-)"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
518 case '4': strcpy(buf, ":-P"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
519 case '5': strcpy(buf, "=-O"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
520 case '6': strcpy(buf, ":-*"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
521 case '7': strcpy(buf, ">:o"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
522 case '8': strcpy(buf, "8-)"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
523 case '!': strcpy(buf, ":-$"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
524 case '@': strcpy(buf, ":-!"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
525 case '#': strcpy(buf, ":-["); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
526 case '$': strcpy(buf, "O:-)"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
527 case '%': strcpy(buf, ":-/"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
528 case '^': strcpy(buf, ":'("); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
529 case '&': strcpy(buf, ":-X"); break;
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
530 case '*': strcpy(buf, ":-D"); break;
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
531 }
8456
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
532 if (*buf && imhtml->smiley_shortcuts) {
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
533 gtk_imhtml_insert_smiley(imhtml, imhtml->protocol_name, buf);
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
534 return TRUE;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
535 }
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
536 return FALSE;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
537 }
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
538
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
539 #if GTK_CHECK_VERSION(2,2,0)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
540 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
541 char *text;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
542 GtkTextIter start, end;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
543 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
544 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
545
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
546 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
547 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
548 gboolean 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
549
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
550 if (info == TARGET_HTML) {
8149
eb2a420060f8 [gaim-migrate @ 8860]
Mark Doliner <mark@kingant.net>
parents: 8148
diff changeset
551 int len;
8148
c06b233aa84d [gaim-migrate @ 8859]
Nathan Walp <nwalp@pidgin.im>
parents: 8128
diff changeset
552 char *selection;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
553 GString *str = g_string_new(NULL);
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
554 if (primary) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
555 text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
556 } else
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
557 text = imhtml->clipboard_html_string;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
558
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
559 /* 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
560 str = g_string_append_unichar(str, 0xfeff);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
561 str = g_string_append(str, text);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
562 str = g_string_append_unichar(str, 0x0000);
8148
c06b233aa84d [gaim-migrate @ 8859]
Nathan Walp <nwalp@pidgin.im>
parents: 8128
diff changeset
563 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL);
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
564 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
565 g_string_free(str, TRUE);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
566 g_free(selection);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
567 } else {
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
568 if (primary) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
569 text = gtk_imhtml_get_text(imhtml, &start, &end);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
570 } else
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
571 text = imhtml->clipboard_text_string;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
572 gtk_selection_data_set_text(selection_data, text, strlen(text));
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
573 }
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
574 if (primary) /* This was allocated here */
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
575 g_free(text);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
576 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
577
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
578 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
579 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
580 GtkTextIter insert;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
581 GtkTextIter selection_bound;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
582
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
583 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
584 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert"));
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
585 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
586 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"));
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
587
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
588 if (!gtk_text_iter_equal (&insert, &selection_bound))
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
589 gtk_text_buffer_move_mark (imhtml->text_buffer,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
590 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"),
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
591 &insert);
7749
ddda7537918e [gaim-migrate @ 8394]
Sean Egan <seanegan@gmail.com>
parents: 7745
diff changeset
592 }
7742
6cd69aa58253 [gaim-migrate @ 8387]
Sean Egan <seanegan@gmail.com>
parents: 7740
diff changeset
593
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
594 static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
7749
ddda7537918e [gaim-migrate @ 8394]
Sean Egan <seanegan@gmail.com>
parents: 7745
diff changeset
595 {
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
596 GtkTextIter start, end;
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
597 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
598 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
599
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
600 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
601 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
602
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
603 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
604 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
605 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
606 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
607
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
608 if (imhtml->clipboard_html_string) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
609 g_free(imhtml->clipboard_html_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
610 g_free(imhtml->clipboard_text_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
611 }
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
612
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
613 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
614 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
615
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
616 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
617 /* 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
618 we need into the windows clipboard now as well. */
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
619 HGLOBAL hdata;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
620 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
621 gchar *buffer;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
622 gint length = strlen(clipboard);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
623 if(clipboard != NULL) {
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
624 OpenClipboard(NULL);
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
625 hdata = GlobalAlloc(GMEM_MOVEABLE, length);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
626 buffer = GlobalLock(hdata);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
627 memcpy(buffer, clipboard, length);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
628 GlobalUnlock(hdata);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
629 SetClipboardData(win_html_fmt, hdata);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
630 CloseClipboard();
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
631 g_free(clipboard);
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
632 }
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
633 #endif
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
634
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
635 g_signal_stop_emission_by_name(imhtml, "copy-clipboard");
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
636 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
637
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
638 static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
639 {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
640 GtkTextIter start, end;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
641 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
642 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
643
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
644 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
645 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
646
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
647 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
648 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
649 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
650 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
651
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
652 if (imhtml->clipboard_html_string) {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
653 g_free(imhtml->clipboard_html_string);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
654 g_free(imhtml->clipboard_text_string);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
655 }
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
656
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
657 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
658 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
659
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
660 #ifdef _WIN32
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
661 /* 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
662 we need into the windows clipboard now as well. */
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
663 HGLOBAL hdata;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
664 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
665 gchar *buffer;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
666 gint length = strlen(clipboard);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
667 if(clipboard != NULL) {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
668 OpenClipboard(NULL);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
669 hdata = GlobalAlloc(GMEM_MOVEABLE, length);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
670 buffer = GlobalLock(hdata);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
671 memcpy(buffer, clipboard, length);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
672 GlobalUnlock(hdata);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
673 SetClipboardData(win_html_fmt, hdata);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
674 CloseClipboard();
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
675 g_free(clipboard);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
676 }
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
677 #endif
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
678
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
679 if (imhtml->editable)
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
680 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
681 g_signal_stop_emission_by_name(imhtml, "cut-clipboard");
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
682 }
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
683
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
684 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
685 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
686 char *text;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
687 guint16 c;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
688 GtkIMHtml *imhtml = data;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
689 GtkTextIter iter;
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
690 GtkIMHtmlOptions flags = GTK_IMHTML_NO_NEWLINE;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
691 gboolean plaintext = FALSE;
7809
533419ef5569 [gaim-migrate @ 8456]
Nathan Walp <nwalp@pidgin.im>
parents: 7808
diff changeset
692
8123
0dc9fffb1e28 [gaim-migrate @ 8827]
Mark Doliner <mark@kingant.net>
parents: 8120
diff changeset
693 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)))
8105
42c7227d6e4d [gaim-migrate @ 8805]
Mark Doliner <mark@kingant.net>
parents: 8091
diff changeset
694 return;
42c7227d6e4d [gaim-migrate @ 8805]
Mark Doliner <mark@kingant.net>
parents: 8091
diff changeset
695
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
696 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
697 /* If we're on windows, let's see if we can get data from the HTML Format
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
698 clipboard before we try to paste from the GTK buffer */
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
699 HGLOBAL hdata;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
700 DWORD err;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
701 char *buffer;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
702 if (IsClipboardFormatAvailable(win_html_fmt)) {
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
703 OpenClipboard(NULL);
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
704 hdata = GetClipboardData(win_html_fmt);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
705 if (hdata == NULL) {
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
706 err = GetLastError();
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
707 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
708 CloseClipboard();
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
709 return;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
710 }
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
711 buffer = GlobalLock(hdata);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
712 if (buffer == NULL) {
8693
f83de0baf171 [gaim-migrate @ 9446]
Luke Schierer <lschiere@pidgin.im>
parents: 8692
diff changeset
713 err = GetLastError();
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
714 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
715 CloseClipboard();
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
716 return;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
717 }
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
718 text = clipboard_win32_to_html(buffer);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
719 GlobalUnlock(hdata);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
720 CloseClipboard();
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
721 } else
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
722 #endif
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
723 if (selection_data->length < 0) {
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
724 char *tmp;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
725 text = gtk_clipboard_wait_for_text(clipboard);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
726 flags = 0;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
727 plaintext = TRUE;
8128
9aafd344230d [gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents: 8123
diff changeset
728
9aafd344230d [gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents: 8123
diff changeset
729 if (text == NULL)
9aafd344230d [gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents: 8123
diff changeset
730 return;
9aafd344230d [gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents: 8123
diff changeset
731
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
732 tmp = gaim_escape_html(text);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
733 g_free(text);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
734 text = tmp;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
735 } else {
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
736 #if 0
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
737 /* 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
738 {
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
739 int i;
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
740
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
741 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
742 selection_data->format, selection_data->length);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
743
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
744 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
745 if ((i % 70) == 0)
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
746 printf("\n\t");
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
747 if (selection_data->data[i] == '\0')
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
748 printf(".");
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
749 else
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
750 printf("%c", selection_data->data[i]);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
751 }
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
752 printf("\n");
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
753 }
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
754 #endif
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
755 text = g_malloc(selection_data->length);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
756 memcpy(text, selection_data->data, selection_data->length);
7766
9d6ba1c44cb7 [gaim-migrate @ 8411]
Sean Egan <seanegan@gmail.com>
parents: 7754
diff changeset
757 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
758
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
759 memcpy (&c, text, 2);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
760 if (c == 0xfeff) {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
761 /* This is UCS2 */
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
762 char *utf8 = g_convert(text+2, selection_data->length - 2, "UTF-8", "UCS-2", NULL, NULL, NULL);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
763 g_free(text);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
764 text = utf8;
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
765 if (!text) {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
766 gaim_debug_warning("gtkimhtml", "g_convert failed in paste_received_cb\n");
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
767 return;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
768 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
769 }
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
770
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
771 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
772 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
773 g_free(text);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
774 return;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
775 }
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
776
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
777 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer));
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
778 if (!imhtml->wbfo && !plaintext)
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
779 gtk_imhtml_close_tags(imhtml, &iter);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
780 gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
781 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
782 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer),
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
783 0, FALSE, 0.0, 0.0);
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
784 g_free(text);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
785 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
786
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
787 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
788 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
789
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
790 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
791 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE),
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
792 paste_received_cb, imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
793 g_signal_stop_emission_by_name(imhtml, "paste-clipboard");
7766
9d6ba1c44cb7 [gaim-migrate @ 8411]
Sean Egan <seanegan@gmail.com>
parents: 7754
diff changeset
794 }
9d6ba1c44cb7 [gaim-migrate @ 8411]
Sean Egan <seanegan@gmail.com>
parents: 7754
diff changeset
795
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
796 static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
797 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
798 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
799 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
800
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
801 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
802
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
803 #endif
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
804
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
805 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
806 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
807 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
808 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
809 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
810 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
811 (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
812 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
813 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
814
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
815 /* does this go in the #ifdef too? I need to keep track of which functions are 2.2 only */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
816 /* adapted from gtktextview.c */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
817 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
818 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
819 if (event->button == 2) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
820 int x, y;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
821 GtkTextIter iter;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
822 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
823
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
824 if (!imhtml->editable)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
825 return FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
826
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
827 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
828 GTK_TEXT_WINDOW_TEXT,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
829 event->x,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
830 event->y,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
831 &x,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
832 &y);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
833 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
834 gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
835
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
836 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
837 paste_received_cb, imhtml);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
838
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
839 return TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
840 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
841
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
842 return FALSE;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
843 }
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
844
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
845 static GtkTextViewClass *parent_class = NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
846
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
847 static void
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
848 gtk_imhtml_finalize (GObject *object)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
849 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
850 GtkIMHtml *imhtml = GTK_IMHTML(object);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
851 GList *scalables;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
852
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
853 g_hash_table_destroy(imhtml->smiley_data);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
854 gtk_smiley_tree_destroy(imhtml->default_smilies);
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
855 gdk_cursor_unref(imhtml->hand_cursor);
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
856 gdk_cursor_unref(imhtml->arrow_cursor);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
857 gdk_cursor_unref(imhtml->text_cursor);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
858
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
859 if(imhtml->tip_window){
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
860 gtk_widget_destroy(imhtml->tip_window);
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
861 }
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
862 if(imhtml->tip_timer)
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
863 gtk_timeout_remove(imhtml->tip_timer);
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
864
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
865 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) {
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
866 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
867 scale->free(scale);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
868 }
7991
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
869
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
870 if (imhtml->clipboard_text_string) {
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
871 g_free(imhtml->clipboard_text_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
872 g_free(imhtml->clipboard_html_string);
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
873 }
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
874
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
875
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
876 g_list_free(imhtml->scalables);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
877 G_OBJECT_CLASS(parent_class)->finalize (object);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
878 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
879
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
880 /* Boring GTK stuff */
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
881 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
882 {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
883 GtkObjectClass *object_class;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
884 GObjectClass *gobject_class;
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
885 object_class = (GtkObjectClass*) klass;
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
886 gobject_class = (GObjectClass*) klass;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
887 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
888 signals[URL_CLICKED] = g_signal_new("url_clicked",
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
889 G_TYPE_FROM_CLASS(gobject_class),
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
890 G_SIGNAL_RUN_FIRST,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
891 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked),
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
892 NULL,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
893 0,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
894 g_cclosure_marshal_VOID__POINTER,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
895 G_TYPE_NONE, 1,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
896 G_TYPE_POINTER);
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
897 signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update",
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
898 G_TYPE_FROM_CLASS(gobject_class),
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
899 G_SIGNAL_RUN_FIRST,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
900 G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update),
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
901 NULL,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
902 0,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
903 g_cclosure_marshal_VOID__POINTER,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
904 G_TYPE_NONE, 1,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
905 G_TYPE_INT);
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
906 signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle",
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
907 G_TYPE_FROM_CLASS(gobject_class),
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
908 G_SIGNAL_RUN_FIRST,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
909 G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format),
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
910 NULL,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
911 0,
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
912 g_cclosure_marshal_VOID__POINTER,
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
913 G_TYPE_NONE, 1,
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
914 G_TYPE_INT);
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
915 signals[CLEAR_FORMAT] = g_signal_new("format_function_clear",
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
916 G_TYPE_FROM_CLASS(gobject_class),
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
917 G_SIGNAL_RUN_FIRST,
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
918 G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format),
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
919 NULL,
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
920 0,
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
921 g_cclosure_marshal_VOID__VOID,
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
922 G_TYPE_NONE, 0);
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
923 signals[UPDATE_FORMAT] = g_signal_new("format_function_update",
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
924 G_TYPE_FROM_CLASS(gobject_class),
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
925 G_SIGNAL_RUN_FIRST,
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
926 G_STRUCT_OFFSET(GtkIMHtmlClass, update_format),
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
927 NULL,
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
928 0,
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
929 g_cclosure_marshal_VOID__VOID,
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
930 G_TYPE_NONE, 0);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
931 gobject_class->finalize = gtk_imhtml_finalize;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
932 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
933
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
934 static void gtk_imhtml_init (GtkIMHtml *imhtml)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
935 {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
936 GtkTextIter iter;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
937 imhtml->text_buffer = gtk_text_buffer_new(NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
938 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
939 imhtml->scrollpoint = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
940 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
941 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
942 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
943 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
944 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
945 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
946 /*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
947
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
948 /* These tags will be used often and can be reused--we create them on init and then apply them by name
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
949 * other tags (color, size, face, etc.) will have to be created and applied dynamically */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
950 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
951 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
952 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
953 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
954 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
955 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
956 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
957 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
958
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
959 /* 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
960 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
961 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
962 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM);
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
963
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
964 imhtml->show_smileys = TRUE;
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
965 imhtml->show_comments = TRUE;
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
966
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
967 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
968 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
969 imhtml->default_smilies = gtk_smiley_tree_new();
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
970
4944
5fe846b7603f [gaim-migrate @ 5278]
Sean Egan <seanegan@gmail.com>
parents: 4926
diff changeset
971 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
972 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
973 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL);
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
974 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
975 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
976 g_signal_connect(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(preinsert_cb), imhtml);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
977 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml);
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
978
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
979 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0,
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
980 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry),
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
981 GDK_ACTION_COPY);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
982 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
983
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
984 #if GTK_CHECK_VERSION(2,2,0)
7353
dc35b4a42fea [gaim-migrate @ 7944]
Sean Egan <seanegan@gmail.com>
parents: 7346
diff changeset
985 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
986 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
987 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
988 //g_signal_connect_after(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
989 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL);
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
990 #endif
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
991
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
992 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
993 G_CALLBACK(mark_set_so_update_selection_cb), imhtml);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
994
4944
5fe846b7603f [gaim-migrate @ 5278]
Sean Egan <seanegan@gmail.com>
parents: 4926
diff changeset
995 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK);
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
996
8681
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
997 imhtml->clipboard_text_string = NULL;
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
998 imhtml->clipboard_html_string = NULL;
e2e56231023c [gaim-migrate @ 9434]
Sean Egan <seanegan@gmail.com>
parents: 8677
diff changeset
999
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1000 imhtml->tip = NULL;
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1001 imhtml->tip_timer = 0;
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1002 imhtml->tip_window = NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1003
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1004 imhtml->edit.bold = FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1005 imhtml->edit.italic = FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1006 imhtml->edit.underline = FALSE;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1007 imhtml->edit.forecolor = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1008 imhtml->edit.backcolor = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1009 imhtml->edit.fontface = NULL;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1010 imhtml->edit.fontsize = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1011 imhtml->edit.link = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1012
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1013
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1014 imhtml->scalables = NULL;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1015
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1016 gtk_imhtml_set_editable(imhtml, FALSE);
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1017
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1018 #ifdef _WIN32
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1019 /* Register HTML Format as desired clipboard format */
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1020 win_html_fmt = RegisterClipboardFormat("HTML Format");
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
1021 #endif
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1022 }
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1023
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1024 GtkWidget *gtk_imhtml_new(void *a, void *b)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1025 {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1026 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL));
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1027 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1028
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1029 GType gtk_imhtml_get_type()
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1030 {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1031 static GType imhtml_type = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1032
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1033 if (!imhtml_type) {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1034 static const GTypeInfo imhtml_info = {
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1035 sizeof(GtkIMHtmlClass),
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1036 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1037 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1038 (GClassInitFunc) gtk_imhtml_class_init,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1039 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1040 NULL,
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1041 sizeof (GtkIMHtml),
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1042 0,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1043 (GInstanceInitFunc) gtk_imhtml_init
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1044 };
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1045
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1046 imhtml_type = g_type_register_static(gtk_text_view_get_type(),
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1047 "GtkIMHtml", &imhtml_info, 0);
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1048 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1049
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1050 return imhtml_type;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1051 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1052
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1053 struct url_data {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1054 GObject *object;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1055 gchar *url;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1056 };
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1057
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1058 static void url_data_destroy(gpointer mydata)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1059 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1060 struct url_data *data = mydata;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1061 g_object_unref(data->object);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1062 g_free(data->url);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1063 g_free(data);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1064 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1065
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1066 static void url_open(GtkWidget *w, struct url_data *data) {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1067 if(!data) return;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1068 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
1069
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1070 }
5582
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
1071
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1072 static void url_copy(GtkWidget *w, gchar *url) {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1073 GtkClipboard *clipboard;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1074
5293
ead927e2543f [gaim-migrate @ 5665]
Christian Hammond <chipx86@chipx86.com>
parents: 5282
diff changeset
1075 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1076 gtk_clipboard_set_text(clipboard, url, -1);
5582
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
1077
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
1078 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
1079 gtk_clipboard_set_text(clipboard, url, -1);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1080 }
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1081
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1082 /* The callback for an event on a link tag. */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1083 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
1084 GdkEventButton *event_button = (GdkEventButton *) event;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1085 if (GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1086 return FALSE;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1087 if (event->type == GDK_BUTTON_RELEASE) {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1088 if (event_button->button == 1) {
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1089 GtkTextIter start, end;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1090 /* 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
1091 if (gtk_text_buffer_get_selection_bounds(
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1092 gtk_text_iter_get_buffer(arg2), &start, &end))
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1093 return FALSE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1094
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1095 /* A link was clicked--we emit the "url_clicked" signal
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1096 * with the URL as the argument */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1097 g_object_ref(G_OBJECT(tag));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1098 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
1099 g_object_unref(G_OBJECT(tag));
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1100 return FALSE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1101 } else if(event_button->button == 3) {
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1102 GtkWidget *img, *item, *menu;
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1103 struct url_data *tempdata = g_new(struct url_data, 1);
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1104 tempdata->object = g_object_ref(imhtml);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1105 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
1106
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1107 /* 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
1108 if (GTK_IMHTML(imhtml)->tip_window) {
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1109 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1110 GTK_IMHTML(imhtml)->tip_window = NULL;
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1111 }
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1112 if (GTK_IMHTML(imhtml)->tip_timer) {
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1113 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1114 GTK_IMHTML(imhtml)->tip_timer = 0;
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
1115 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1116 if (GTK_IMHTML(imhtml)->editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1117 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
1118 else
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1119 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
1120 menu = gtk_menu_new();
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1121 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
1122
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1123 /* buttons and such */
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1124
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1125 if (!strncmp(tempdata->url, "mailto:", 7))
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1126 {
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1127 /* Copy E-Mail Address */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1128 img = gtk_image_new_from_stock(GTK_STOCK_COPY,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1129 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1130 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1131 _("_Copy E-Mail Address"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1132 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1133 g_signal_connect(G_OBJECT(item), "activate",
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1134 G_CALLBACK(url_copy), tempdata->url + 7);
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1135 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1136 }
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1137 else
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1138 {
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1139 /* Copy Link Location */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1140 img = gtk_image_new_from_stock(GTK_STOCK_COPY,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1141 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1142 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1143 _("_Copy Link Location"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1144 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1145 g_signal_connect(G_OBJECT(item), "activate",
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1146 G_CALLBACK(url_copy), tempdata->url);
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1147 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1148
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1149 /* Open Link in Browser */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1150 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1151 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1152 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1153 _("_Open Link in Browser"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1154 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1155 g_signal_connect(G_OBJECT(item), "activate",
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1156 G_CALLBACK(url_open), tempdata);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1157 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1158 }
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1159
4756
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
1160
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1161 gtk_widget_show_all(menu);
4756
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
1162 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
1163 event_button->button, event_button->time);
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1164
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1165 return TRUE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1166 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1167 }
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1168 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1169 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
1170 be caught by the regular GtkTextView menu */
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1171 else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
1172 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
1173 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1174
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1175 static void
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1176 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y,
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1177 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml)
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1178 {
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1179 if(gtk_imhtml_get_editable(imhtml) && sd->data){
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1180 gchar **links;
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1181 gchar *link;
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1182
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1183 gaim_str_strip_cr(sd->data);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1184
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1185 links = g_strsplit(sd->data, "\n", 0);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1186 while((link = *links++) != NULL){
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1187 if(gaim_str_has_prefix(link, "http://") ||
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1188 gaim_str_has_prefix(link, "https://") ||
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1189 gaim_str_has_prefix(link, "ftp://")){
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1190 gtk_imhtml_insert_link(imhtml, gtk_text_buffer_get_insert(imhtml->text_buffer), link, link);
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1191 } else if (link=='\0') {
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
1192 /* Ignore blank lines */
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1193 } else {
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
1194 /* Special reasons, aka images being put in via other tag, etc. */
8091
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1195 }
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1196 }
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1197
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1198 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1199 } else {
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1200 gtk_drag_finish(dc, FALSE, FALSE, t);
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1201 }
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1202 }
56b74730715f [gaim-migrate @ 8790]
Sean Egan <seanegan@gmail.com>
parents: 8061
diff changeset
1203
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
1204 /* this isn't used yet
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1205 static void
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1206 gtk_smiley_tree_remove (GtkSmileyTree *tree,
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1207 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1208 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1209 GtkSmileyTree *t = tree;
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1210 const gchar *x = smiley->smile;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1211 gint len = 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1212
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1213 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1214 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1215
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1216 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1217 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1218
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1219 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1220 if (pos)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1221 t = t->children [(int) pos - (int) t->values->str];
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1222 else
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1223 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1224
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1225 x++; len++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1226 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1227
4141
ccec4fde84f4 [gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents: 4140
diff changeset
1228 if (t->image) {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1229 t->image = NULL;
4141
ccec4fde84f4 [gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents: 4140
diff changeset
1230 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1231 }
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
1232 */
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
1233
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1234
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1235 static gint
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1236 gtk_smiley_tree_lookup (GtkSmileyTree *tree,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1237 const gchar *text)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1238 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1239 GtkSmileyTree *t = tree;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1240 const gchar *x = text;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1241 gint len = 0;
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1242 gchar *amp;
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1243 gint alen;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1244
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1245 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1246 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1247
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1248 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1249 break;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1250
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1251 if(*x == '&' && gtk_imhtml_is_amp_escape(x, &amp, &alen)) {
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1252 len += alen - strlen(amp);
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1253 x += alen - strlen(amp);
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1254 pos = strchr (t->values->str, *amp);
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1255 }
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1256 else
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1257 pos = strchr (t->values->str, *x);
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1258
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1259 if (pos)
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1260 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
1261 else
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1262 break;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1263
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1264 x++; len++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1265 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1266
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1267 if (t->image)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1268 return len;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1269
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1270 return 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1271 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1272
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1273 void
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1274 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1275 gchar *sml,
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1276 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1277 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1278 GtkSmileyTree *tree;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1279 g_return_if_fail (imhtml != NULL);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1280 g_return_if_fail (GTK_IS_IMHTML (imhtml));
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1281
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1282 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1283 tree = imhtml->default_smilies;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1284 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1285 } else {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1286 tree = gtk_smiley_tree_new();
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
1287 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
1288 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1289
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1290 gtk_smiley_tree_insert (tree, smiley);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1291 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1292
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1293 static gboolean
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1294 gtk_imhtml_is_smiley (GtkIMHtml *imhtml,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1295 GSList *fonts,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1296 const gchar *text,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1297 gint *len)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1298 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1299 GtkSmileyTree *tree;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1300 GtkIMHtmlFontDetail *font;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1301 char *sml = NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1302
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1303 if (fonts) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1304 font = fonts->data;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1305 sml = font->sml;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1306 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1307
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1308 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1309 tree = imhtml->default_smilies;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1310 else {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1311 tree = g_hash_table_lookup(imhtml->smiley_data, sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1312 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1313 if (tree == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1314 return FALSE;
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1315
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
1316 *len = gtk_smiley_tree_lookup (tree, text);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1317 return (*len > 0);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1318 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1319
6814
782907a6ae65 [gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents: 6648
diff changeset
1320 GdkPixbufAnimation *
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1321 gtk_smiley_tree_image (GtkIMHtml *imhtml,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1322 const gchar *sml,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1323 const gchar *text)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1324 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1325 GtkSmileyTree *t;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1326 const gchar *x = text;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1327 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1328 t = imhtml->default_smilies;
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1329 else
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1330 t = g_hash_table_lookup(imhtml->smiley_data, sml);
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1331
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1332
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1333 if (t == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1334 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1335
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1336 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1337 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1338
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1339 if (!t->values) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1340 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1341 }
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1342
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1343 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1344 if (pos) {
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
1345 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
1346 } else {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1347 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1348 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1349 x++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1350 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1351
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1352 if (!t->image->icon)
6814
782907a6ae65 [gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents: 6648
diff changeset
1353 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL);
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1354
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
1355 return t->image->icon;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1356 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1357 #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
1358 *tag = g_strndup (string, strlen (x)); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1359 *len = strlen (x) + 1; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1360 return TRUE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1361 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1362 (*type)++
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1363
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1364 #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
1365 const gchar *c = string + strlen (x " "); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1366 gchar e = '"'; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1367 gboolean quote = FALSE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1368 while (*c) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1369 if (*c == '"' || *c == '\'') { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1370 if (quote && (*c == e)) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1371 quote = !quote; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1372 else if (!quote) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1373 quote = !quote; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1374 e = *c; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1375 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1376 } else if (!quote && (*c == '>')) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1377 break; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1378 c++; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1379 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1380 if (*c) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1381 *tag = g_strndup (string, c - string); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1382 *len = c - string + 1; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1383 return TRUE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1384 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1385 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1386 (*type)++
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1387
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1388
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1389 static gboolean
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1390 gtk_imhtml_is_amp_escape (const gchar *string,
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1391 gchar **replace,
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1392 gint *length)
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1393 {
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1394 static char buf[7];
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1395 g_return_val_if_fail (string != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1396 g_return_val_if_fail (replace != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1397 g_return_val_if_fail (length != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1398
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1399 if (!g_ascii_strncasecmp (string, "&amp;", 5)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1400 *replace = "&";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1401 *length = 5;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1402 } else if (!g_ascii_strncasecmp (string, "&lt;", 4)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1403 *replace = "<";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1404 *length = 4;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1405 } else if (!g_ascii_strncasecmp (string, "&gt;", 4)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1406 *replace = ">";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1407 *length = 4;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1408 } else if (!g_ascii_strncasecmp (string, "&nbsp;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1409 *replace = " ";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1410 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1411 } else if (!g_ascii_strncasecmp (string, "&copy;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1412 *replace = "©";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1413 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1414 } else if (!g_ascii_strncasecmp (string, "&quot;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1415 *replace = "\"";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1416 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1417 } else if (!g_ascii_strncasecmp (string, "&reg;", 5)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1418 *replace = "®";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1419 *length = 5;
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
1420 } else if (!g_ascii_strncasecmp (string, "&apos;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1421 *replace = "\'";
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
1422 *length = 6;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1423 } else if (*(string + 1) == '#') {
2022
199ba82faacb [gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2002
diff changeset
1424 guint pound = 0;
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 3000
diff changeset
1425 if ((sscanf (string, "&#%u;", &pound) == 1) && pound != 0) {
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1426 int buflen;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1427 if (*(string + 3 + (gint)log10 (pound)) != ';')
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1428 return FALSE;
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1429 buflen = g_unichar_to_utf8((gunichar)pound, buf);
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
1430 buf[buflen] = '\0';
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1431 *replace = buf;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1432 *length = 2;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1433 while (isdigit ((gint) string [*length])) (*length)++;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1434 if (string [*length] == ';') (*length)++;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1435 } else {
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1436 return FALSE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1437 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1438 } else {
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1439 return FALSE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1440 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1441
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1442 return TRUE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1443 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
1444
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1445 static gboolean
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1446 gtk_imhtml_is_tag (const gchar *string,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1447 gchar **tag,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1448 gint *len,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1449 gint *type)
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1450 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1451 char *close;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1452 *type = 1;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1453
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1454
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1455 if (!(close = strchr (string, '>')))
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1456 return FALSE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1457
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1458 VALID_TAG ("B");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1459 VALID_TAG ("BOLD");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1460 VALID_TAG ("/B");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1461 VALID_TAG ("/BOLD");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1462 VALID_TAG ("I");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1463 VALID_TAG ("ITALIC");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1464 VALID_TAG ("/I");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1465 VALID_TAG ("/ITALIC");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1466 VALID_TAG ("U");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1467 VALID_TAG ("UNDERLINE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1468 VALID_TAG ("/U");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1469 VALID_TAG ("/UNDERLINE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1470 VALID_TAG ("S");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1471 VALID_TAG ("STRIKE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1472 VALID_TAG ("/S");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1473 VALID_TAG ("/STRIKE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1474 VALID_TAG ("SUB");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1475 VALID_TAG ("/SUB");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1476 VALID_TAG ("SUP");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1477 VALID_TAG ("/SUP");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1478 VALID_TAG ("PRE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1479 VALID_TAG ("/PRE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1480 VALID_TAG ("TITLE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1481 VALID_TAG ("/TITLE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1482 VALID_TAG ("BR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1483 VALID_TAG ("HR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1484 VALID_TAG ("/FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1485 VALID_TAG ("/A");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1486 VALID_TAG ("P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1487 VALID_TAG ("/P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1488 VALID_TAG ("H3");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1489 VALID_TAG ("/H3");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1490 VALID_TAG ("HTML");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1491 VALID_TAG ("/HTML");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1492 VALID_TAG ("BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1493 VALID_TAG ("/BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1494 VALID_TAG ("FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1495 VALID_TAG ("HEAD");
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1496 VALID_TAG ("/HEAD");
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1497 VALID_TAG ("BINARY");
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1498 VALID_TAG ("/BINARY");
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
1499
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1500 VALID_OPT_TAG ("HR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1501 VALID_OPT_TAG ("FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1502 VALID_OPT_TAG ("BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1503 VALID_OPT_TAG ("A");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1504 VALID_OPT_TAG ("IMG");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1505 VALID_OPT_TAG ("P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1506 VALID_OPT_TAG ("H3");
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
1507 VALID_OPT_TAG ("HTML");
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1508
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1509 VALID_TAG ("CITE");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1510 VALID_TAG ("/CITE");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1511 VALID_TAG ("EM");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1512 VALID_TAG ("/EM");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1513 VALID_TAG ("STRONG");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1514 VALID_TAG ("/STRONG");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1515
5104
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
1516 VALID_OPT_TAG ("SPAN");
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
1517 VALID_TAG ("/SPAN");
5174
376349b04123 [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
1518 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1519 VALID_TAG ("IMG");
8026
17b90334f3cc [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
1520 VALID_TAG("SPAN");
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1521 VALID_OPT_TAG("BR");
7988
d9e831876c28 [gaim-migrate @ 8665]
Nathan Walp <nwalp@pidgin.im>
parents: 7961
diff changeset
1522
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1523 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) {
2954
f6c4f2187c08 [gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents: 2898
diff changeset
1524 gchar *e = strstr (string + strlen("!--"), "-->");
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1525 if (e) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1526 *len = e - string + strlen ("-->");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1527 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->"));
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1528 return TRUE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1529 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1530 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1531
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1532 *type = -1;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1533 *len = close - string + 1;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1534 *tag = g_strndup(string, *len - 1);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1535 return TRUE;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1536 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1537
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1538 static gchar*
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1539 gtk_imhtml_get_html_opt (gchar *tag,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1540 const gchar *opt)
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1541 {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1542 gchar *t = tag;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1543 gchar *e, *a;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1544 gchar *val;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1545 gint len;
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1546 gchar *c;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1547 GString *ret;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1548
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1549 while (g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1550 gboolean quote = FALSE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1551 if (*t == '\0') break;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1552 while (*t && !((*t == ' ') && !quote)) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1553 if (*t == '\"')
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1554 quote = ! quote;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1555 t++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1556 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1557 while (*t && (*t == ' ')) t++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1558 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1559
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
1560 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1561 t += strlen (opt);
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1562 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1563 return NULL;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1564 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1565
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1566 if ((*t == '\"') || (*t == '\'')) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1567 e = a = ++t;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1568 while (*e && (*e != *(t - 1))) e++;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1569 if (*e == '\0') {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1570 return NULL;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1571 } else
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1572 val = g_strndup(a, e - a);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1573 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1574 e = a = t;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1575 while (*e && !isspace ((gint) *e)) e++;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1576 val = g_strndup(a, e - a);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1577 }
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1578
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1579 ret = g_string_new("");
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1580 e = val;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1581 while(*e) {
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1582 if(gtk_imhtml_is_amp_escape(e, &c, &len)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1583 ret = g_string_append(ret, c);
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1584 e += len;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1585 } else {
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1586 ret = g_string_append_c(ret, *e);
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1587 e++;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1588 }
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1589 }
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1590
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1591 g_free(val);
8568
88988327a4e0 [gaim-migrate @ 9316]
Mark Doliner <mark@kingant.net>
parents: 8566
diff changeset
1592
88988327a4e0 [gaim-migrate @ 9316]
Mark Doliner <mark@kingant.net>
parents: 8566
diff changeset
1593 return g_string_free(ret, FALSE);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1594 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1595
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1596 /* Inline CSS Support - Douglas Thrift */
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1597 static gchar*
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1598 gtk_imhtml_get_css_opt (gchar *style,
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1599 const gchar *opt)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1600 {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1601 gchar *t = style;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1602 gchar *e, *a;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1603 gchar *val;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1604 gint len;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1605 gchar *c;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1606 GString *ret;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1607
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1608 while (g_ascii_strncasecmp (t, opt, strlen (opt))) {
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
1609 /* gboolean quote = FALSE; */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1610 if (*t == '\0') break;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1611 while (*t && !((*t == ' ') /*&& !quote*/)) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1612 /* if (*t == '\"')
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
1613 quote = ! quote; */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1614 t++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1615 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1616 while (*t && (*t == ' ')) t++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1617 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1618
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1619 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1620 t += strlen (opt);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1621 } else {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1622 return NULL;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1623 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1624
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1625 /* if ((*t == '\"') || (*t == '\'')) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1626 e = a = ++t;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1627 while (*e && (*e != *(t - 1))) e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1628 if (*e == '\0') {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1629 return NULL;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1630 } else
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1631 val = g_strndup(a, e - a);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1632 } else {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1633 e = a = t;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1634 while (*e && !isspace ((gint) *e)) e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1635 val = g_strndup(a, e - a);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1636 }*/
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1637
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1638 e = a = t;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1639 while (*e && *e != ';') e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1640 val = g_strndup(a, e - a);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1641
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1642 ret = g_string_new("");
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1643 e = val;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1644 while(*e) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1645 if(gtk_imhtml_is_amp_escape(e, &c, &len)) {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1646 ret = g_string_append(ret, c);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1647 e += len;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1648 } else {
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1649 ret = g_string_append_c(ret, *e);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1650 e++;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1651 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1652 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1653
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1654 g_free(val);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1655 val = ret->str;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1656 g_string_free(ret, FALSE);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1657 return val;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1658 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1659
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1660 static const char *accepted_protocols[] = {
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1661 "http://",
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1662 "https://",
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1663 "ftp://"
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1664 };
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1665
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1666 static const int accepted_protocols_size = 3;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1667
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1668 /* 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
1669 the caller knows how long the protocol string is. */
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1670 int gtk_imhtml_is_protocol(const char *text)
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1671 {
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1672 gint i;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1673
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1674 for(i=0; i<accepted_protocols_size; i++){
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1675 if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1676 return strlen(accepted_protocols[i]);
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1677 }
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1678 }
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1679 return 0;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1680 }
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1681
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1682 /*
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1683 <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
1684
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1685
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1686 [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
1687 [19:59] <KingAnt> marv: I think the image tag used by the core is something like <img id="#"/>
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1688 [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1689 [20:00] <KingAnt> marv: Where the ID is the what is returned when you add the image to the imgstore using gaim_imgstore_add
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1690 [20:00] <marv> Robot101: so how does the image get passed to serv_got_im() and serv_send_im()? just as the <img id="#" and then the prpl looks it up from the store?
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1691 [20:00] <KingAnt> marv: Right
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1692 [20:00] <marv> alright
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1693
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1694 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
1695 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
1696 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
1697 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
1698 */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1699
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1700 void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1701 const gchar *text,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1702 GtkIMHtmlOptions options,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1703 GSList *unused)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1704 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1705 GtkTextIter iter, ins, sel;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1706 GdkRectangle rect;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1707 int y, height, ins_offset = 0, sel_offset = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1708 gboolean fixins = FALSE, fixsel = FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1709
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1710 g_return_if_fail (imhtml != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1711 g_return_if_fail (GTK_IS_IMHTML (imhtml));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1712 g_return_if_fail (text != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1713
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1714
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1715 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1716 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
1717 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
1718 fixins = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1719 ins_offset = gtk_text_iter_get_offset(&ins);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1720 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1721
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1722 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
1723 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
1724 fixsel = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1725 sel_offset = gtk_text_iter_get_offset(&sel);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1726 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1727
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1728 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1729 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
1730
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1731
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1732 if(((y + height) - (rect.y + rect.height)) > height
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1733 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1734 options |= GTK_IMHTML_NO_SCROLL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1735 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1736
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1737 gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1738
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1739 if (fixins) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1740 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
1741 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
1742 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1743
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1744 if (fixsel) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1745 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
1746 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
1747 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1748
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1749 if (!(options & GTK_IMHTML_NO_SCROLL)) {
8729
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1750 gtk_imhtml_scroll_to_end(imhtml);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1751 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1752 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1753
8729
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1754 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml)
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1755 {
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1756 GtkTextIter iter;
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1757 /* If this seems backwards at first glance, well it's not.
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1758 * It means scroll such that the mark is closest to the top,
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1759 * and closest to the right as possible. Remember kids, you have
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1760 * to scroll left to move a given spot closest to the right,
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1761 * and scroll down to move a spot closest to the top.
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1762 */
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1763 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1764 gtk_text_iter_set_line_offset(&iter, 0);
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1765 gtk_text_buffer_move_mark(imhtml->text_buffer, imhtml->scrollpoint, &iter);
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1766 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), imhtml->scrollpoint,
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1767 0, TRUE, 1.0, 0.0);
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1768 }
7024b9145357 [gaim-migrate @ 9484]
Luke Schierer <lschiere@pidgin.im>
parents: 8726
diff changeset
1769
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1770 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1771 const gchar *text,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1772 GtkIMHtmlOptions options,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1773 GtkTextIter *iter)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1774 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1775 GdkRectangle rect;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1776 gint pos = 0;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1777 gchar *ws;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1778 gchar *tag;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1779 gchar *bg = NULL;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1780 gint len;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1781 gint tlen, smilelen, wpos=0;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1782 gint type;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1783 const gchar *c;
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1784 gchar *amp;
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
1785 gint len_protocol;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1786
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1787 guint bold = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1788 italics = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1789 underline = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1790 strike = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1791 sub = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1792 sup = 0,
1691
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
1793 title = 0,
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1794 pre = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1795
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1796 GSList *fonts = NULL;
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
1797 GObject *object;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1798 GtkIMHtmlScalable *scalable = NULL;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1799
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1800 g_return_if_fail (imhtml != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1801 g_return_if_fail (GTK_IS_IMHTML (imhtml));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1802 g_return_if_fail (text != NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1803 c = text;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1804 len = strlen(text);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1805 ws = g_malloc(len + 1);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1806 ws[0] = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1807
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1808 while (pos < len) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1809 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1810 c++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1811 pos++;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1812 ws[wpos] = '\0';
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1813 switch (type)
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1814 {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1815 case 1: /* B */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1816 case 2: /* BOLD */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1817 case 54: /* STRONG */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1818
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1819 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1820
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1821 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD))
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1822 gtk_imhtml_toggle_bold(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1823 bold++;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1824 ws[0] = '\0'; wpos = 0;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1825 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1826 case 3: /* /B */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1827 case 4: /* /BOLD */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1828 case 55: /* /STRONG */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1829 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1830 ws[0] = '\0'; wpos = 0;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1831
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1832 if (bold)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1833 bold--;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1834 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1835 gtk_imhtml_toggle_bold(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1836 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1837 case 5: /* I */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1838 case 6: /* ITALIC */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1839 case 52: /* EM */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1840 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1841 ws[0] = '\0'; wpos = 0;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1842 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC))
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1843 gtk_imhtml_toggle_italic(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1844 italics++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1845 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1846 case 7: /* /I */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1847 case 8: /* /ITALIC */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1848 case 53: /* /EM */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1849 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1850 ws[0] = '\0'; wpos = 0;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1851 if (italics)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1852 italics--;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1853 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1854 gtk_imhtml_toggle_italic(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1855 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1856 case 9: /* U */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1857 case 10: /* UNDERLINE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1858 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1859 ws[0] = '\0'; wpos = 0;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1860 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1861 gtk_imhtml_toggle_underline(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1862 underline++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1863 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1864 case 11: /* /U */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1865 case 12: /* /UNDERLINE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1866 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1867 ws[0] = '\0'; wpos = 0;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1868 if (underline)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1869 underline--;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1870 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1871 gtk_imhtml_toggle_underline(imhtml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1872 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1873 case 13: /* S */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1874 case 14: /* STRIKE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1875 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1876 strike++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1877 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1878 case 15: /* /S */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1879 case 16: /* /STRIKE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1880 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1881 if (strike)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1882 strike--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1883 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1884 case 17: /* SUB */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1885 /* FIXME: reimpliment this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1886 sub++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1887 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1888 case 18: /* /SUB */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1889 /* FIXME: reimpliment this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1890 if (sub)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1891 sub--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1892 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1893 case 19: /* SUP */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1894 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1895 sup++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1896 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1897 case 20: /* /SUP */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1898 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1899 if (sup)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1900 sup--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1901 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1902 case 21: /* PRE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1903 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1904 pre++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1905 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1906 case 22: /* /PRE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1907 /* FIXME: reimplement this */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1908 if (pre)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1909 pre--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1910 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1911 case 23: /* TITLE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1912 /* FIXME: what was this supposed to do anyway? */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1913 title++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1914 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1915 case 24: /* /TITLE */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1916 /* FIXME: make this undo whatever 23 was supposed to do */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1917 if (title) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1918 if (options & GTK_IMHTML_NO_TITLE) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1919 wpos = 0;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1920 ws [wpos] = '\0';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1921 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1922 title--;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1923 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1924 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1925 case 25: /* BR */
5174
376349b04123 [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
1926 case 58: /* BR/ */
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1927 case 61: /* BR (opt) */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1928 ws[wpos] = '\n';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1929 wpos++;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1930 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1931 case 26: /* HR */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1932 case 42: /* HR (opt) */
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
1933 {
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
1934 int minus;
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
1935
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1936 ws[wpos++] = '\n';
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1937 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1938
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1939 scalable = gtk_imhtml_hr_new();
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1940 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
1941 scalable->add_to(scalable, imhtml, iter);
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
1942 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) +
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
1943 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml));
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
1944 scalable->scale(scalable, rect.width - minus, rect.height);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1945 imhtml->scalables = g_list_append(imhtml->scalables, scalable);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1946 ws[0] = '\0'; wpos = 0;
7942
3e268e113bf1 [gaim-migrate @ 8613]
Mark Doliner <mark@kingant.net>
parents: 7914
diff changeset
1947 ws[wpos++] = '\n';
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1948
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1949 break;
8726
3ac178eedac2 [gaim-migrate @ 9481]
Ethan Blanton <elb@pidgin.im>
parents: 8719
diff changeset
1950 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1951 case 27: /* /FONT */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1952 if (fonts && !imhtml->wbfo) {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1953 GtkIMHtmlFontDetail *font = fonts->data;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1954 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1955 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
1956 /* NEW_BIT (NEW_TEXT_BIT); */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1957
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1958 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1959 gtk_imhtml_toggle_fontface(imhtml, NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1960 g_free (font->face);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1961 }
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1962 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1963 gtk_imhtml_toggle_forecolor(imhtml, NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1964 g_free (font->fore);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1965 }
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1966 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1967 gtk_imhtml_toggle_backcolor(imhtml, NULL);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1968 g_free (font->back);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1969 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1970 if (font->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1971 g_free (font->sml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1972 g_free (font);
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1973
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1974 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
1975 gtk_imhtml_font_set_size(imhtml, 3);
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1976
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1977 fonts = fonts->next;
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1978 if (fonts) {
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1979 GtkIMHtmlFontDetail *font = fonts->data;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1980
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1981 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1982 gtk_imhtml_toggle_fontface(imhtml, font->face);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1983 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1984 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1985 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR))
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1986 gtk_imhtml_toggle_backcolor(imhtml, font->back);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
1987 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
1988 gtk_imhtml_font_set_size(imhtml, font->size);
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1989 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1990 }
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
1991 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1992 case 28: /* /A */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1993 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1994 gtk_imhtml_toggle_link(imhtml, NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
1995 ws[0] = '\0'; wpos = 0;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1996 break;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
1997
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1998 case 29: /* P */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1999 case 30: /* /P */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2000 case 31: /* H3 */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2001 case 32: /* /H3 */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2002 case 33: /* HTML */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2003 case 34: /* /HTML */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2004 case 35: /* BODY */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2005 case 36: /* /BODY */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2006 case 37: /* FONT */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2007 case 38: /* HEAD */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2008 case 39: /* /HEAD */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2009 case 40: /* BINARY */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2010 case 41: /* /BINARY */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2011 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2012 case 43: /* FONT (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2013 {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2014 gchar *color, *back, *face, *size, *sml;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2015 GtkIMHtmlFontDetail *font, *oldfont = NULL;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2016 color = gtk_imhtml_get_html_opt (tag, "COLOR=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2017 back = gtk_imhtml_get_html_opt (tag, "BACK=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2018 face = gtk_imhtml_get_html_opt (tag, "FACE=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2019 size = gtk_imhtml_get_html_opt (tag, "SIZE=");
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2020 sml = gtk_imhtml_get_html_opt (tag, "SML=");
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2021 if (!(color || back || face || size || sml))
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2022 break;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2023
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2024 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2025 ws[0] = '\0'; wpos = 0;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2026
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2027 font = g_new0 (GtkIMHtmlFontDetail, 1);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2028 if (fonts)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2029 oldfont = fonts->data;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2030
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2031 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
2032 font->fore = color;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2033 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2034 }
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2035 //else if (oldfont && oldfont->fore)
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2036 // font->fore = g_strdup(oldfont->fore);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2037
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2038 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
2039 font->back = back;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2040 gtk_imhtml_toggle_backcolor(imhtml, font->back);
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2041 }
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2042 //else if (oldfont && oldfont->back)
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2043 // font->back = g_strdup(oldfont->back);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2044
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2045 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
2046 font->face = face;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2047 gtk_imhtml_toggle_fontface(imhtml, font->face);
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2048 }
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2049 //else if (oldfont && oldfont->face)
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2050 // font->face = g_strdup(oldfont->face);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2051
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2052 if (sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2053 font->sml = sml;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2054 else if (oldfont && oldfont->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2055 font->sml = g_strdup(oldfont->sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2056
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2057 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
2058 if (*size == '+') {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2059 sscanf (size + 1, "%hd", &font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2060 font->size += 3;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2061 } else if (*size == '-') {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2062 sscanf (size + 1, "%hd", &font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2063 font->size = MAX (0, 3 - font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2064 } else if (isdigit (*size)) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2065 sscanf (size, "%hd", &font->size);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2066 }
6042
460b4ba2d452 [gaim-migrate @ 6492]
Mark Doliner <mark@kingant.net>
parents: 5967
diff changeset
2067 if (font->size > 100)
460b4ba2d452 [gaim-migrate @ 6492]
Mark Doliner <mark@kingant.net>
parents: 5967
diff changeset
2068 font->size = 100;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2069 } else if (oldfont)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2070 font->size = oldfont->size;
8309
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2071 else
f694277e8341 [gaim-migrate @ 9033]
Sean Egan <seanegan@gmail.com>
parents: 8250
diff changeset
2072 font->size = 3;
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2073 if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK)))
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2074 gtk_imhtml_font_set_size(imhtml, font->size);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2075 g_free(size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2076 fonts = g_slist_prepend (fonts, font);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2077 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2078 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2079 case 44: /* BODY (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2080 if (!(options & GTK_IMHTML_NO_COLOURS)) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2081 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR=");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2082 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2083 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2084 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2085 /* NEW_BIT(NEW_TEXT_BIT); */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2086 if (bg)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2087 g_free(bg);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2088 bg = bgcolor;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2089 gtk_imhtml_toggle_backcolor(imhtml, bg);
2885
f72efa29c109 [gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2871
diff changeset
2090 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2091 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2092 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2093 case 45: /* A (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2094 {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2095 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF=");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2096 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2097 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2098 ws[0] = '\0'; wpos = 0;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2099 gtk_imhtml_toggle_link(imhtml, href);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2100 }
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2101 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2102 break;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2103 case 46: /* IMG (opt) */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2104 case 59: /* IMG */
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2105 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2106 #if 0
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2107 /* disabling this for now, it's easy to add it back... */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2108 GdkPixbuf *img = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2109 const gchar *filename = NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2110
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2111 if (!(imhtml->format_functions & GTK_IMHTML_IMAGE))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2112 break;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2113
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2114 if (images && images->data) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2115 img = images->data;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2116 images = images->next;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2117 filename = g_object_get_data(G_OBJECT(img), "filename");
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2118 g_object_ref(G_OBJECT(img));
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2119 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2120 img = gtk_widget_render_icon(GTK_WIDGET(imhtml),
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2121 GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON,
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2122 "gtkimhtml-missing-image");
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2123 }
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2124
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2125 scalable = gtk_imhtml_image_new(img, filename);
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2126 /* NEW_BIT(NEW_SCALABLE_BIT); */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2127 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2128 scalable->add_to(scalable, imhtml, iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2129 scalable->scale(scalable, rect.width, rect.height);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2130 imhtml->scalables = g_list_append(imhtml->scalables, scalable);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2131
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2132 g_object_unref(G_OBJECT(img));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2133 #endif
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2134 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2135 case 47: /* P (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2136 case 48: /* H3 (opt) */
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
2137 case 49: /* HTML (opt) */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2138 case 50: /* CITE */
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2139 case 51: /* /CITE */
8026
17b90334f3cc [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
2140 case 56: /* SPAN (opt) */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2141 /* Inline CSS Support - Douglas Thrift
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2142 *
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2143 * color
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2144 * background
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2145 * font-family
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2146 * font-size
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2147 * text-decoration: underline
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2148 */
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2149 {
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2150 gchar *style, *color, *background, *family, *size;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2151 gchar *textdec;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2152 GtkIMHtmlFontDetail *font, *oldfont = NULL;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2153 style = gtk_imhtml_get_html_opt (tag, "style=");
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2154
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2155 if (!style) break;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2156
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2157 color = gtk_imhtml_get_css_opt (style, "color: ");
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2158 background = gtk_imhtml_get_css_opt (style, "background: ");
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2159 family = gtk_imhtml_get_css_opt (style,
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2160 "font-family: ");
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2161 size = gtk_imhtml_get_css_opt (style, "font-size: ");
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2162 textdec = gtk_imhtml_get_css_opt (style, "text-decoration: ");
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2163
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2164 if (!(color || family || size || background || textdec)) {
8120
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
2165 g_free(style);
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
2166 break;
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
2167 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2168
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2169
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2170 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2171 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2172 /* NEW_BIT (NEW_TEXT_BIT); */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2173
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2174 font = g_new0 (GtkIMHtmlFontDetail, 1);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2175 if (fonts)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2176 oldfont = fonts->data;
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2177
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2178 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
2179 {
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2180 font->fore = color;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2181 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2182 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2183 else if (oldfont && oldfont->fore)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2184 font->fore = g_strdup(oldfont->fore);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2185
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2186 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
2187 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2188 font->back = background;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2189 gtk_imhtml_toggle_backcolor(imhtml, font->back);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2190 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2191 else if (oldfont && oldfont->back)
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2192 font->back = g_strdup(oldfont->back);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2193
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2194 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
2195 {
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2196 font->face = family;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2197 gtk_imhtml_toggle_fontface(imhtml, font->face);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2198 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2199 else if (oldfont && oldfont->face)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2200 font->face = g_strdup(oldfont->face);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2201 if (font->face && (atoi(font->face) > 100)) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2202 /* WTF is this? */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2203 g_free(font->face);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2204 font->face = g_strdup("100");
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2205 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2206
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2207 if (oldfont && oldfont->sml)
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2208 font->sml = g_strdup(oldfont->sml);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2209
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2210 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
2211 if (g_ascii_strcasecmp(size, "xx-small") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2212 font->size = 1;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2213 else if (g_ascii_strcasecmp(size, "smaller") == 0
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2214 || g_ascii_strcasecmp(size, "x-small") == 0)
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2215 font->size = 2;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2216 else if (g_ascii_strcasecmp(size, "larger") == 0
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2217 || g_ascii_strcasecmp(size, "medium") == 0)
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2218 font->size = 4;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2219 else if (g_ascii_strcasecmp(size, "large") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2220 font->size = 5;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2221 else if (g_ascii_strcasecmp(size, "x-large") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2222 font->size = 6;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2223 else if (g_ascii_strcasecmp(size, "xx-large") == 0)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2224 font->size = 7;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2225 else
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2226 font->size = 3;
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2227 gtk_imhtml_font_set_size(imhtml, font->size);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2228 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2229 else if (oldfont)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2230 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2231 font->size = oldfont->size;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2232 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2233
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2234 if (oldfont)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2235 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2236 font->underline = oldfont->underline;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2237 }
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2238 if (textdec && font->underline != 1
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2239 && g_ascii_strcasecmp(size, "underline") == 0
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2240 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2241 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2242 gtk_imhtml_toggle_underline(imhtml);
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2243 font->underline = 1;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2244 }
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2245
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2246 g_free(style);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2247 g_free(size);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2248 fonts = g_slist_prepend (fonts, font);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2249 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2250 break;
5104
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
2251 case 57: /* /SPAN */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2252 /* Inline CSS Support - Douglas Thrift */
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2253 if (fonts && !imhtml->wbfo) {
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2254 GtkIMHtmlFontDetail *oldfont = NULL;
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2255 GtkIMHtmlFontDetail *font = fonts->data;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2256 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2257 ws[0] = '\0'; wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2258 /* NEW_BIT (NEW_TEXT_BIT); */
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2259 fonts = g_slist_remove (fonts, font);
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2260 if (fonts)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2261 oldfont = fonts->data;
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2262
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2263 if (!oldfont) {
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2264 gtk_imhtml_font_set_size(imhtml, 3);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2265 if (font->underline)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2266 gtk_imhtml_toggle_underline(imhtml);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2267 gtk_imhtml_toggle_fontface(imhtml, NULL);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2268 gtk_imhtml_toggle_forecolor(imhtml, NULL);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2269 gtk_imhtml_toggle_backcolor(imhtml, NULL);
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2270 }
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2271 else
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2272 {
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2273
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2274 if (font->size != oldfont->size)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2275 gtk_imhtml_font_set_size(imhtml, oldfont->size);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2276
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2277 if (font->underline != oldfont->underline)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2278 gtk_imhtml_toggle_underline(imhtml);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2279
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2280 if (!oldfont->face || strcmp(font->face, oldfont->face) != 0)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2281 gtk_imhtml_toggle_fontface(imhtml, oldfont->face);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2282
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2283 if (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2284 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2285
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2286 if (!oldfont->back || strcmp(font->back, oldfont->back) != 0)
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2287 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back);
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8681
diff changeset
2288 }
8692
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2289
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2290 g_free (font->face);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2291 g_free (font->fore);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2292 g_free (font->back);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2293 g_free (font->sml);
0680ca680e92 [gaim-migrate @ 9445]
Luke Schierer <lschiere@pidgin.im>
parents: 8686
diff changeset
2294
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2295 g_free (font);
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2296 }
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8105
diff changeset
2297 break;
8026
17b90334f3cc [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
2298 case 60: /* SPAN */
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2299 break;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2300 case 62: /* comment */
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2301 /* NEW_BIT (NEW_TEXT_BIT); */
8317
6f549c1d0829 [gaim-migrate @ 9041]
Sean Egan <seanegan@gmail.com>
parents: 8309
diff changeset
2302 ws[wpos] = '\0';
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2303 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2304
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
2305 if (imhtml->show_comments)
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
2306 wpos = g_snprintf (ws, len, "%s", tag);
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2307 /* NEW_BIT (NEW_COMMENT_BIT); */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2308 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2309 default:
6882
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
2310 break;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2311 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2312 c += tlen;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2313 pos += tlen;
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
2314 if(tag)
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
2315 g_free(tag); /* This was allocated back in VALID_TAG() */
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2316 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) {
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2317 GtkIMHtmlFontDetail *fd;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2318
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2319 gchar *sml = NULL;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2320 if (fonts) {
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2321 fd = fonts->data;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2322 sml = fd->sml;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2323 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2324 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
2325 wpos = g_snprintf (ws, smilelen + 1, "%s", c);
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2326
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2327 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter);
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2328
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
2329 c += smilelen;
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
2330 pos += smilelen;
8473
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2331 wpos = 0;
12fe38c195a6 [gaim-migrate @ 9206]
Luke Schierer <lschiere@pidgin.im>
parents: 8466
diff changeset
2332 ws[0] = 0;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2333 } 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
2334 while(*amp) {
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2335 ws [wpos++] = *amp++;
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2336 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2337 c += tlen;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2338 pos += tlen;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2339 } else if (*c == '\n') {
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2340 if (!(options & GTK_IMHTML_NO_NEWLINE)) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2341 ws[wpos] = '\n';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2342 wpos++;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2343 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2344 ws[0] = '\0';
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2345 wpos = 0;
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2346 /* NEW_BIT (NEW_TEXT_BIT); */
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2347 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2348 c++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2349 pos++;
8334
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2350 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2351 while(len_protocol--){
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2352 /* 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
2353 copied into the ws array.
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2354 */
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2355 ws [wpos++] = *c++;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2356 pos++;
0d1e5870d328 [gaim-migrate @ 9058]
Luke Schierer <lschiere@pidgin.im>
parents: 8317
diff changeset
2357 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2358 } else if (*c) {
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2359 ws [wpos++] = *c++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2360 pos++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2361 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
2362 break;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2363 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2364 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2365 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2366 ws[0] = '\0'; wpos = 0;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2367
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
2368 /* NEW_BIT(NEW_TEXT_BIT); */
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2369
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2370 while (fonts) {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2371 GtkIMHtmlFontDetail *font = fonts->data;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2372 fonts = g_slist_remove (fonts, font);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2373 if (font->face)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2374 g_free (font->face);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2375 if (font->fore)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2376 g_free (font->fore);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2377 if (font->back)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2378 g_free (font->back);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2379 if (font->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2380 g_free (font->sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2381 g_free (font);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2382 //if (str)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2383 // str = g_string_append (str, "</FONT>");
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2384 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2385 #if 0
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2386 if (str) {
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2387 while (bold) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2388 // str = g_string_append (str, "</B>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2389 bold--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2390 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2391 while (italics) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2392 // str = g_string_append (str, "</I>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2393 italics--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2394 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2395 while (underline) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2396 //str = g_string_append (str, "</U>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2397 underline--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2398 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2399 while (strike) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2400 //str = g_string_append (str, "</S>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2401 strike--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2402 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2403 while (sub) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2404 //str = g_string_append (str, "</SUB>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2405 sub--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2406 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2407 while (sup) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2408 //str = g_string_append (str, "</SUP>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2409 sup--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2410 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2411 while (title) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2412 //str = g_string_append (str, "</TITLE>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2413 title--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2414 }
1691
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
2415 while (pre) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2416 //str = g_string_append (str, "</PRE>");
1691
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
2417 pre--;
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
2418 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2419 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2420 #endif
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
2421 g_free (ws);
4630
5cdfd20daa07 [gaim-migrate @ 4921]
Sean Egan <seanegan@gmail.com>
parents: 4629
diff changeset
2422 if(bg)
5cdfd20daa07 [gaim-migrate @ 4921]
Sean Egan <seanegan@gmail.com>
parents: 4629
diff changeset
2423 g_free(bg);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2424
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2425 if (!imhtml->wbfo)
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2426 gtk_imhtml_close_tags(imhtml, iter);
8506
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
2427
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
2428 object = g_object_ref(G_OBJECT(imhtml));
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
2429 g_signal_emit(object, signals[UPDATE_FORMAT], 0);
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
2430 g_object_unref(object);
887c0259b47b [gaim-migrate @ 9242]
Luke Schierer <lschiere@pidgin.im>
parents: 8505
diff changeset
2431
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2432 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2433
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
2434 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml)
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
2435 {
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
2436 g_hash_table_destroy(imhtml->smiley_data);
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
2437 gtk_smiley_tree_destroy(imhtml->default_smilies);
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
2438 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
2439 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
2440 imhtml->default_smilies = gtk_smiley_tree_new();
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
2441 }
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
2442
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2443 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml,
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
2444 gboolean show)
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
2445 {
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
2446 imhtml->show_smileys = show;
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
2447 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2448
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2449 void gtk_imhtml_show_comments (GtkIMHtml *imhtml,
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
2450 gboolean show)
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
2451 {
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
2452 imhtml->show_comments = show;
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
2453 }
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
2454
8456
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2455 void gtk_imhtml_html_shortcuts (GtkIMHtml *imhtml,
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2456 gboolean allow)
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2457 {
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2458 imhtml->html_shortcuts = allow;
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2459 }
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2460
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2461 void gtk_imhtml_smiley_shortcuts (GtkIMHtml *imhtml,
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2462 gboolean allow)
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2463 {
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2464 imhtml->smiley_shortcuts = allow;
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2465 }
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2466
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2467 void
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2468 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, gchar *protocol_name) {
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2469 imhtml->protocol_name = protocol_name;
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2470 }
5f8d4ab6d375 [gaim-migrate @ 9186]
Luke Schierer <lschiere@pidgin.im>
parents: 8439
diff changeset
2471
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
2472 void
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
2473 gtk_imhtml_clear (GtkIMHtml *imhtml)
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
2474 {
7991
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2475 GList *del;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2476 GtkTextIter start, end;
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
2477 GObject *object = g_object_ref(G_OBJECT(imhtml));
7991
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2478
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2479 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2480 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
2481 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end);
7991
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2482
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2483 for(del = imhtml->scalables; del; del = del->next) {
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2484 GtkIMHtmlScalable *scale = del->data;
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2485 scale->free(scale);
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2486 }
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2487 g_list_free(imhtml->scalables);
096562205906 [gaim-migrate @ 8668]
Nathan Walp <nwalp@pidgin.im>
parents: 7988
diff changeset
2488 imhtml->scalables = NULL;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2489
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
2490 gtk_imhtml_close_tags(imhtml, &start);
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
2491
8427
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
2492 g_signal_emit(object, signals[CLEAR_FORMAT], 0);
2e18099ded93 [gaim-migrate @ 9157]
Sean Egan <seanegan@gmail.com>
parents: 8420
diff changeset
2493 g_object_unref(object);
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
2494 }
2363
08c66712364c [gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2349
diff changeset
2495
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
2496 void gtk_imhtml_page_up (GtkIMHtml *imhtml)
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
2497 {
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2498 GdkRectangle rect;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2499 GtkTextIter iter;
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
2500
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2501 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2502 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
2503 rect.y - rect.height);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2504 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
2505
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
2506 }
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2507 void gtk_imhtml_page_down (GtkIMHtml *imhtml)
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2508 {
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2509 GdkRectangle rect;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2510 GtkTextIter iter;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2511
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2512 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2513 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
2514 rect.y + rect.height);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
2515 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
2516 }
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
2517
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2518 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2519 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename)
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
2520 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2521 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage));
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2522 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img));
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2523
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2524 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2525 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
2526 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free;
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
2527
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
2528 im_image->pixbuf = img;
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2529 im_image->image = image;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2530 im_image->width = gdk_pixbuf_get_width(img);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2531 im_image->height = gdk_pixbuf_get_height(img);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2532 im_image->mark = NULL;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2533 im_image->filename = filename ? g_strdup(filename) : NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2534
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
2535 g_object_ref(img);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2536 return GTK_IMHTML_SCALABLE(im_image);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2537 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2538
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2539 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
2540 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2541 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2542
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2543 if(image->width > width || image->height > height){
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2544 GdkPixbuf *new_image = NULL;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2545 float factor;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2546 int new_width = image->width, new_height = image->height;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2547
8588
7f7679853f7b [gaim-migrate @ 9339]
Mark Doliner <mark@kingant.net>
parents: 8568
diff changeset
2548 if(image->width > (width - 2)){
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2549 factor = (float)(width)/image->width;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2550 new_width = width;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2551 new_height = image->height * factor;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2552 }
8588
7f7679853f7b [gaim-migrate @ 9339]
Mark Doliner <mark@kingant.net>
parents: 8568
diff changeset
2553 if(new_height >= (height - 2)){
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2554 factor = (float)(height)/new_height;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2555 new_height = height;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2556 new_width = new_width * factor;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2557 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2558
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
2559 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2560 gtk_image_set_from_pixbuf(image->image, new_image);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2561 g_object_unref(G_OBJECT(new_image));
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2562 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2563 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
2564
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2565 static void write_img_to_file(GtkWidget *w, GtkFileSelection *sel)
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2566 {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2567 const gchar *filename = gtk_file_selection_get_filename(sel);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2568 gchar *dirname;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2569 GtkIMHtmlImage *image = g_object_get_data(G_OBJECT(sel), "GtkIMHtmlImage");
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2570 gchar *type = NULL;
5019
eb1d45bffe66 [gaim-migrate @ 5355]
Luke Schierer <lschiere@pidgin.im>
parents: 5015
diff changeset
2571 GError *error = NULL;
5015
a17a84895585 [gaim-migrate @ 5351]
Nathan Walp <nwalp@pidgin.im>
parents: 5012
diff changeset
2572 #if GTK_CHECK_VERSION(2,2,0)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2573 GSList *formats = gdk_pixbuf_get_formats();
6162
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
2574 #else
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
2575 char *basename = g_path_get_basename(filename);
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
2576 char *ext = strrchr(basename, '.');
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
2577 #endif
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2578
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2579 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2580 /* append a / if needed */
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2581 if (filename[strlen(filename) - 1] != '/') {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2582 dirname = g_strconcat(filename, "/", NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2583 } else {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2584 dirname = g_strdup(filename);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2585 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2586 gtk_file_selection_set_filename(sel, dirname);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2587 g_free(dirname);
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
2588 return;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2589 }
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
2590
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
2591 #if GTK_CHECK_VERSION(2,2,0)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2592 while(formats){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2593 GdkPixbufFormat *format = formats->data;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2594 gchar **extensions = gdk_pixbuf_format_get_extensions(format);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2595 gpointer p = extensions;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2596
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2597 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2598 gchar *fmt_ext = extensions[0];
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2599 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2600
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2601 if(!strcmp(fmt_ext, file_ext)){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2602 type = gdk_pixbuf_format_get_name(format);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2603 break;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2604 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2605
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2606 extensions++;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2607 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2608
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2609 g_strfreev(p);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2610
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2611 if(type)
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2612 break;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2613
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2614 formats = formats->next;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2615 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2616
5020
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2617 g_slist_free(formats);
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2618 #else
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2619 /* this is really ugly code, but I think it will work */
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2620 if(ext) {
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2621 ext++;
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2622 if(!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg"))
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2623 type = g_strdup("jpeg");
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2624 else if(!g_ascii_strcasecmp(ext, "png"))
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2625 type = g_strdup("png");
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2626 }
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2627
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2628 g_free(basename);
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2629 #endif
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
2630
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2631 /* 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
2632 it's a png */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2633 if(!type){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2634 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2635 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG."));
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2636 type = g_strdup("png");
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2637 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2638
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
2639 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2640
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2641 if(error){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2642 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2643 _("Error saving image: %s"), error->message);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2644 g_error_free(error);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2645 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2646
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2647 g_free(type);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2648 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2649
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2650 static void gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2651 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2652 GtkWidget *sel = gtk_file_selection_new(_("Save Image"));
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2653
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2654 if (image->filename)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2655 gtk_file_selection_set_filename(GTK_FILE_SELECTION(sel), image->filename);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2656 g_object_set_data(G_OBJECT(sel), "GtkIMHtmlImage", image);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2657 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked",
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2658 G_CALLBACK(write_img_to_file), sel);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2659
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2660 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked",
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2661 G_CALLBACK(gtk_widget_destroy), sel);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2662 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->cancel_button), "clicked",
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2663 G_CALLBACK(gtk_widget_destroy), sel);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2664
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2665 gtk_widget_show(sel);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2666 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2667
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2668 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
2669 {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2670 GdkEventButton *event_button = (GdkEventButton *) event;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2671
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2672 if (event->type == GDK_BUTTON_RELEASE) {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2673 if(event_button->button == 3) {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2674 GtkWidget *img, *item, *menu;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2675 gchar *text = g_strdup_printf(_("_Save Image..."));
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2676 menu = gtk_menu_new();
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2677
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2678 /* buttons and such */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2679 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
2680 item = gtk_image_menu_item_new_with_mnemonic(text);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2681 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
2682 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
2683 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2684
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2685 gtk_widget_show_all(menu);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2686 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2687 event_button->button, event_button->time);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2688
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2689 g_free(text);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2690 return TRUE;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2691 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2692 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2693 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2694 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
2695 be caught by the regular GtkTextView menu */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2696 else
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2697 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
2698
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
2699 }
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2700 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2701 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2702 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2703
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2704 g_object_unref(image->pixbuf);
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2705 if (image->filename)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
2706 g_free(image->filename);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2707 g_free(scale);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2708 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2709
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2710 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
2711 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2712 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2713 GtkWidget *box = gtk_event_box_new();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2714 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
2715
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2716 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2717
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2718 gtk_widget_show(GTK_WIDGET(image->image));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2719 gtk_widget_show(box);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2720
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2721 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
2722 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
2723 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2724
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2725 GtkIMHtmlScalable *gtk_imhtml_hr_new()
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2726 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2727 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2728
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2729 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2730 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2731 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2732
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2733 hr->sep = gtk_hseparator_new();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2734 gtk_widget_set_size_request(hr->sep, 5000, 2);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2735 gtk_widget_show(hr->sep);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2736
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2737 return GTK_IMHTML_SCALABLE(hr);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2738 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2739
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2740 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2741 {
8588
7f7679853f7b [gaim-migrate @ 9339]
Mark Doliner <mark@kingant.net>
parents: 8568
diff changeset
2742 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
2743 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2744
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2745 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
2746 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2747 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2748 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
2749 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>");
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
2750 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
2751 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
2752 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2753
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2754 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2755 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2756 g_free(scale);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
2757 }
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2758
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2759 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2760 {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2761 GtkTextIter iter, start, end;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2762 gboolean new_search = TRUE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2763
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2764 g_return_val_if_fail(imhtml != NULL, FALSE);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2765 g_return_val_if_fail(text != NULL, FALSE);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2766
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2767 if (imhtml->search_string && !strcmp(text, imhtml->search_string))
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2768 new_search = FALSE;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2769
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2770 if (new_search) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2771 gtk_imhtml_search_clear(imhtml);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2772 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2773 } else {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2774 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
2775 gtk_text_buffer_get_mark(imhtml->text_buffer, "search"));
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2776 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2777 imhtml->search_string = g_strdup(text);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2778
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
2779 if (gtk_source_iter_forward_search(&iter, imhtml->search_string,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
2780 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2781 &start, &end, NULL)) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2782
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2783 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
2784 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2785 if (new_search) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2786 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
2787 do
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2788 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
2789 while (gtk_source_iter_forward_search(&end, imhtml->search_string,
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2790 GTK_SOURCE_SEARCH_VISIBLE_ONLY |
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
2791 GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2792 &start, &end, NULL));
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2793 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2794 return TRUE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2795 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2796
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2797 gtk_imhtml_search_clear(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2798
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2799 return FALSE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2800 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2801
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2802 void gtk_imhtml_search_clear(GtkIMHtml *imhtml)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2803 {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2804 GtkTextIter start, end;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2805
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2806 g_return_if_fail(imhtml != NULL);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2807
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2808 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2809 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2810
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2811 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
2812 if (imhtml->search_string)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2813 g_free(imhtml->search_string);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2814 imhtml->search_string = NULL;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
2815 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2816
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2817 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2818 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2819 gchar str[18];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2820 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2821
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2822 g_snprintf(str, sizeof(str), "FORECOLOR %s", color);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2823
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2824 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
2825 if (!tag)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2826 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", color, NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2827
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2828 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2829 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2830
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2831 static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2832 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2833 gchar str[18];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2834 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2835
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2836 g_snprintf(str, sizeof(str), "BACKCOLOR %s", color);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2837
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2838 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
2839 if (!tag)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2840 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background", color, NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2841
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2842 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2843 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2844
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2845 static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2846 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2847 gchar str[256];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2848 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2849
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2850 g_snprintf(str, sizeof(str), "FONT FACE %s", face);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2851 str[255] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2852
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2853 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
2854 if (!tag)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2855 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
2856
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2857 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2858 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2859
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2860 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2861 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2862 gchar str[24];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2863 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2864
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2865 g_snprintf(str, sizeof(str), "FONT SIZE %d", size);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2866 str[23] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2867
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2868 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
2869 if (!tag) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2870 /* For reasons I don't understand, setting "scale" here scaled based on some default
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2871 * size other than my theme's default size. Our size 4 was actually smaller than
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2872 * our size 3 for me. So this works around that oddity.
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2873 */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2874 GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2875 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size",
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2876 (gint) (pango_font_description_get_size(attr->font) *
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2877 (double) _point_sizes[size-1]), NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2878 gtk_text_attributes_unref(attr);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2879 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2880
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2881 return tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2882 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2883
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2884 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
2885 const char *prefix, guint len, gboolean homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2886 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2887 GSList *tags, *l;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2888 GtkTextIter iter;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2889
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2890 tags = gtk_text_iter_get_tags(i);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2891
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2892 for (l = tags; l; l = l->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2893 GtkTextTag *tag = l->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2894
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2895 if (tag->name && !strncmp(tag->name, prefix, len))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2896 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
2897 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2898
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2899 g_slist_free(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2900
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2901 if (homo)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2902 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2903
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2904 iter = *i;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2905
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2906 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
2907 if (gtk_text_iter_begins_tag(&iter, NULL)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2908 tags = gtk_text_iter_get_toggled_tags(&iter, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2909
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2910 for (l = tags; l; l = l->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2911 GtkTextTag *tag = l->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2912
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2913 if (tag->name && !strncmp(tag->name, prefix, len))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2914 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2915 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2916
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2917 g_slist_free(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2918 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2919 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2920 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2921
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2922 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
2923 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2924 remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2925 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2926
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2927 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
2928 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2929 remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2930 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2931
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2932 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
2933 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2934 remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2935 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2936
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2937 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
2938 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2939 remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2940 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2941
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2942 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
2943 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2944 remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2945 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2946
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2947 /* Editable stuff */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2948 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
2949 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2950 imhtml->insert_offset = gtk_text_iter_get_offset(iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2951 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2952
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2953 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
2954 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2955 GtkTextIter start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2956
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2957 if (!len)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2958 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2959
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2960 start = *end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2961 gtk_text_iter_set_offset(&start, imhtml->insert_offset);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2962
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2963 if (imhtml->edit.bold)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2964 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
2965 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2966 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2967
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2968 if (imhtml->edit.italic)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2969 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
2970 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2971 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2972
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2973 if (imhtml->edit.underline)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2974 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
2975 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2976 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2977
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2978 if (imhtml->edit.forecolor) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2979 remove_font_forecolor(imhtml, &start, end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2980 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2981 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2982 &start, end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2983 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2984
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2985 if (imhtml->edit.backcolor) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2986 remove_font_backcolor(imhtml, &start, end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2987 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2988 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2989 &start, end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2990 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2991
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2992 if (imhtml->edit.fontface) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2993 remove_font_face(imhtml, &start, end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2994 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2995 find_font_face_tag(imhtml, imhtml->edit.fontface),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2996 &start, end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2997 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2998
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
2999 if (imhtml->edit.fontsize) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3000 remove_font_size(imhtml, &start, end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3001 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3002 find_font_size_tag(imhtml, imhtml->edit.fontsize),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3003 &start, end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3004 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3005
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3006 if (imhtml->edit.link) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3007 remove_font_link(imhtml, &start, end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3008 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3009 imhtml->edit.link,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3010 &start, end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3011 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3012
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3013 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3014
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3015 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3016 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3017 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable);
8177
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3018 /*
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3019 * We need a visible caret for accessibility, so mouseless
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3020 * people can highlight stuff.
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3021 */
4e68644a47f6 [gaim-migrate @ 8891]
Mark Doliner <mark@kingant.net>
parents: 8149
diff changeset
3022 /* 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
3023 imhtml->editable = editable;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3024 imhtml->format_functions = GTK_IMHTML_ALL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3025
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3026 if (editable)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3027 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
3028 G_CALLBACK(mark_set_cb), imhtml);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3029 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3030
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3031 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
3032 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3033 g_return_if_fail(imhtml != NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3034
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3035 imhtml->wbfo = wbfo;
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3036 }
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3037
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3038 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons)
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3039 {
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3040 GObject *object = g_object_ref(G_OBJECT(imhtml));
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3041 imhtml->format_functions = buttons;
8420
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3042 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons);
c25c697525b7 [gaim-migrate @ 9150]
Sean Egan <seanegan@gmail.com>
parents: 8380
diff changeset
3043 g_object_unref(object);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3044 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3045
8516
5b25f72c4723 [gaim-migrate @ 9254]
Luke Schierer <lschiere@pidgin.im>
parents: 8515
diff changeset
3046
5b25f72c4723 [gaim-migrate @ 9254]
Luke Schierer <lschiere@pidgin.im>
parents: 8515
diff changeset
3047 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold,
5b25f72c4723 [gaim-migrate @ 9254]
Luke Schierer <lschiere@pidgin.im>
parents: 8515
diff changeset
3048 gboolean *italic, gboolean *underline)
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3049 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3050 if (imhtml->edit.bold)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3051 (*bold) = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3052 if (imhtml->edit.italic)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3053 (*italic) = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3054 if (imhtml->edit.underline)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3055 (*underline) = TRUE;
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3056 }
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3057
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3058 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3059 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3060 return imhtml->editable;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3061 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3062
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3063 /*
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3064 * 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
3065 * 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
3066 * we actually set a new foreground color.
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3067 * 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
3068 * colors.
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3069 *
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3070 * 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
3071 *
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
3072 * (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
3073 * (12:45:55) ?? ???: understand?
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3074 * (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
3075 * (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
3076 */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3077
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3078 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3079 GtkIMHtml *imhtml)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3080 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3081 GSList *tags, *l;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3082 GtkTextIter iter;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3083
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3084 if (mark != gtk_text_buffer_get_insert(buffer))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3085 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3086
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3087 if (!gtk_text_buffer_get_char_count(buffer))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3088 return;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3089
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3090 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = FALSE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3091 if (imhtml->edit.forecolor)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3092 g_free(imhtml->edit.forecolor);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3093 imhtml->edit.forecolor = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3094 if (imhtml->edit.backcolor)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3095 g_free(imhtml->edit.backcolor);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3096 imhtml->edit.backcolor = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3097 if (imhtml->edit.fontface)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3098 g_free(imhtml->edit.fontface);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3099 imhtml->edit.fontface = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3100 imhtml->edit.fontsize = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3101 imhtml->edit.link = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3102
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3103 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
3104
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3105
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3106 if (gtk_text_iter_is_end(&iter))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3107 tags = gtk_text_iter_get_toggled_tags(&iter, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3108 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3109 tags = gtk_text_iter_get_tags(&iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3110
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3111 for (l = tags; l != NULL; l = l->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3112 GtkTextTag *tag = GTK_TEXT_TAG(l->data);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3113
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3114 if (tag->name) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3115 if (strcmp(tag->name, "BOLD") == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3116 imhtml->edit.bold = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3117 if (strcmp(tag->name, "ITALICS") == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3118 imhtml->edit.italic = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3119 if (strcmp(tag->name, "UNDERLINE") == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3120 imhtml->edit.underline = TRUE;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3121 if (strncmp(tag->name, "FORECOLOR ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3122 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3123 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3124 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3125 if (strncmp(tag->name, "FONT FACE ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3126 imhtml->edit.fontface = g_strdup(&(tag->name)[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3127 if (strncmp(tag->name, "FONT SIZE ", 10) == 0)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3128 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10);
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
3129 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
3130 imhtml->edit.link = tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3131 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3132 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3133
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3134 g_slist_free(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3135 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3136
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3137 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3138 {
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3139 GObject *object;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3140 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3141
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3142 imhtml->edit.bold = !imhtml->edit.bold;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3143
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3144 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3145 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3146 if (imhtml->edit.bold)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3147 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
3148 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3149 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3150 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3151 if (imhtml->edit.bold)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3152 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
3153 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3154 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3155
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3156 }
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3157 object = g_object_ref(G_OBJECT(imhtml));
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3158 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD);
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3159 g_object_unref(object);
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3160
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3161 return (imhtml->edit.bold != FALSE);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3162 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3163
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3164 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3165 {
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3166 GObject *object;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3167 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3168
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3169 imhtml->edit.italic = !imhtml->edit.italic;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3170
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3171 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3172 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3173 if (imhtml->edit.italic)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3174 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
3175 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3176 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3177 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3178 if (imhtml->edit.italic)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3179 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
3180 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3181 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
3182 }
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3183 object = g_object_ref(G_OBJECT(imhtml));
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3184 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_ITALIC);
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3185 g_object_unref(object);
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3186
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3187 return imhtml->edit.italic != FALSE;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3188 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3189
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3190 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3191 {
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3192 GObject *object;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3193 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3194
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3195 imhtml->edit.underline = !imhtml->edit.underline;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3196
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3197 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3198 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3199 if (imhtml->edit.underline)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3200 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
3201 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3202 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3203 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3204 if (imhtml->edit.underline)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3205 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
3206 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3207 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
3208 }
8481
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3209 object = g_object_ref(G_OBJECT(imhtml));
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3210 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE);
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3211 g_object_unref(object);
6d0869404696 [gaim-migrate @ 9214]
Luke Schierer <lschiere@pidgin.im>
parents: 8473
diff changeset
3212
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3213 return imhtml->edit.underline != FALSE;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3214 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3215
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3216 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3217 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3218 GtkTextIter start, end;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3219
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3220 imhtml->edit.fontsize = size;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3221
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3222
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3223 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3224 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3225 remove_font_size(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3226 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3227 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3228 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3229 remove_font_size(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3230 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3231 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3232 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3233
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3234 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3235
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3236 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3237 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3238 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3239
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3240 if (imhtml->edit.fontsize == 1)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3241 return;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3242
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3243 if (!imhtml->edit.fontsize)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3244 imhtml->edit.fontsize = 2;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3245 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3246 imhtml->edit.fontsize--;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3247
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3248 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3249 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3250 remove_font_size(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3251 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3252 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3253 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3254 remove_font_size(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3255 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3256 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3257 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3258 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3259
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3260 void gtk_imhtml_font_grow(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3261 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3262 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3263
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3264 if (imhtml->edit.fontsize == MAX_FONT_SIZE)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3265 return;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3266
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3267 if (!imhtml->edit.fontsize)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3268 imhtml->edit.fontsize = 4;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3269 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3270 imhtml->edit.fontsize++;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3271
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3272 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3273 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3274 remove_font_size(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3275 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3276 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3277 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3278 remove_font_size(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3279 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3280 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3281 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3282 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3283
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3284 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3285 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3286 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3287
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3288 if (imhtml->edit.forecolor != NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3289 g_free(imhtml->edit.forecolor);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3290
8429
1b6c43246cf6 [gaim-migrate @ 9159]
Sean Egan <seanegan@gmail.com>
parents: 8428
diff changeset
3291 if (color) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3292 imhtml->edit.forecolor = g_strdup(color);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3293 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3294 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3295 remove_font_forecolor(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3296 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3297 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3298 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3299 remove_font_forecolor(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3300 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3301 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3302 &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3303 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3304 } else {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3305 imhtml->edit.forecolor = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3306 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3307
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3308 return imhtml->edit.forecolor != NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3309 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3310
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3311 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3312 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3313 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3314
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3315 if (imhtml->edit.backcolor != NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3316 g_free(imhtml->edit.backcolor);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3317
8429
1b6c43246cf6 [gaim-migrate @ 9159]
Sean Egan <seanegan@gmail.com>
parents: 8428
diff changeset
3318 if (color) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3319 imhtml->edit.backcolor = g_strdup(color);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3320
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3321 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3322 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3323 remove_font_backcolor(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3324 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3325 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3326 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3327 remove_font_backcolor(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3328 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3329 find_font_backcolor_tag(imhtml,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3330 imhtml->edit.backcolor), &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3331 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3332 } else {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3333 imhtml->edit.backcolor = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3334 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3335
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3336 return imhtml->edit.backcolor != NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3337 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3338
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3339 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3340 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3341 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3342
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3343 if (imhtml->edit.fontface != NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3344 g_free(imhtml->edit.fontface);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3345
8429
1b6c43246cf6 [gaim-migrate @ 9159]
Sean Egan <seanegan@gmail.com>
parents: 8428
diff changeset
3346 if (face) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3347 imhtml->edit.fontface = g_strdup(face);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3348
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3349 if (imhtml->wbfo) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3350 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3351 remove_font_face(imhtml, &start, &end, TRUE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3352 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3353 find_font_face_tag(imhtml, imhtml->edit.fontface), &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3354 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3355 remove_font_face(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3356 gtk_text_buffer_apply_tag(imhtml->text_buffer,
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3357 find_font_face_tag(imhtml, imhtml->edit.fontface),
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3358 &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3359 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3360 } else {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3361 imhtml->edit.fontface = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3362 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3363
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3364 return imhtml->edit.fontface != NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3365 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3366
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3367 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3368 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3369 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3370 GtkTextTag *linktag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3371 static guint linkno = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3372 gchar str[48];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3373
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3374 imhtml->edit.link = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3375
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3376
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3377
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3378 if (url) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3379 g_snprintf(str, sizeof(str), "LINK %d", linkno++);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3380 str[47] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3381
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3382 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3383 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
3384 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
3385
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3386 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3387 remove_font_link(imhtml, &start, &end, FALSE);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3388 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3389 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3390 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3391 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3392
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3393 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
3394 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3395 GtkTextIter iter;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3396
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3397 gtk_imhtml_toggle_link(imhtml, url);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3398 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
3399 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3400 gtk_imhtml_toggle_link(imhtml, NULL);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3401 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3402
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3403 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
3404 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3405 GtkTextMark *mark;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3406 GtkTextIter iter;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3407
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3408 mark = gtk_text_buffer_get_insert(imhtml->text_buffer);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3409
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3410 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
3411 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3412 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3413
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3414 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
3415 {
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3416 GdkPixbuf *pixbuf = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3417 GdkPixbufAnimation *annipixbuf = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3418 GtkWidget *icon = NULL;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3419 GtkTextChildAnchor *anchor;
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
3420 char *unescaped = gaim_unescape_html(smiley);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3421
8515
0b0d70464cad [gaim-migrate @ 9253]
Luke Schierer <lschiere@pidgin.im>
parents: 8506
diff changeset
3422 if (!imhtml->show_smileys) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3423 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, strlen(smiley));
8515
0b0d70464cad [gaim-migrate @ 9253]
Luke Schierer <lschiere@pidgin.im>
parents: 8506
diff changeset
3424 return;
0b0d70464cad [gaim-migrate @ 9253]
Luke Schierer <lschiere@pidgin.im>
parents: 8506
diff changeset
3425 }
0b0d70464cad [gaim-migrate @ 9253]
Luke Schierer <lschiere@pidgin.im>
parents: 8506
diff changeset
3426
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3427 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
3428 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", unescaped, g_free);
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3429 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free);
8505
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
3430
112f5762a41a [gaim-migrate @ 9241]
Luke Schierer <lschiere@pidgin.im>
parents: 8498
diff changeset
3431 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3432 if(annipixbuf) {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3433 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3434 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3435 if(pixbuf)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3436 icon = gtk_image_new_from_pixbuf(pixbuf);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3437 } else {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3438 icon = gtk_image_new_from_animation(annipixbuf);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3439 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3440 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3441
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3442 if (icon) {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3443 gtk_widget_show(icon);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3444 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3445 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3446 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3447
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3448 static const gchar *tag_to_html_start(GtkTextTag *tag)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3449 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3450 const gchar *name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3451 static gchar buf[1024];
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3452
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3453 name = tag->name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3454 g_return_val_if_fail(name != NULL, "");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3455
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3456 if (strcmp(name, "BOLD") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3457 return "<b>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3458 } else if (strcmp(name, "ITALICS") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3459 return "<i>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3460 } else if (strcmp(name, "UNDERLINE") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3461 return "<u>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3462 } else if (strncmp(name, "LINK ", 5) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3463 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3464 if (tmp) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3465 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3466 buf[sizeof(buf)-1] = '\0';
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3467 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3468 } else {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3469 return "";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3470 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3471 } else if (strncmp(name, "FORECOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3472 g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3473 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3474 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3475 g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3476 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3477 } else if (strncmp(name, "FONT FACE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3478 g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3479 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3480 } else if (strncmp(name, "FONT SIZE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3481 g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3482 return buf;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3483 } else {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3484 return "";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3485 }
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3486 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3487
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3488 static const gchar *tag_to_html_end(GtkTextTag *tag)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3489 {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3490 const gchar *name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3491
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3492 name = tag->name;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3493 g_return_val_if_fail(name != NULL, "");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3494
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3495 if (strcmp(name, "BOLD") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3496 return "</b>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3497 } else if (strcmp(name, "ITALICS") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3498 return "</i>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3499 } else if (strcmp(name, "UNDERLINE") == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3500 return "</u>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3501 } else if (strncmp(name, "LINK ", 5) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3502 return "</a>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3503 } else if (strncmp(name, "FORECOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3504 return "</font>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3505 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3506 return "</font>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3507 } else if (strncmp(name, "FONT FACE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3508 return "</font>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3509 } else if (strncmp(name, "FONT SIZE ", 10) == 0) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3510 return "</font>";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3511 } else {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3512 return "";
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3513 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3514 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3515
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3516 static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3517 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3518 return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) &&
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3519 !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) ||
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3520 gtk_text_iter_is_end(niter));
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3521 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3522
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3523 /* 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
3524 * 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
3525 * 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
3526 * 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
3527 * Finally, replace <, >, &, and " with their HTML equivalent.
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3528 */
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3529 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
3530 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3531 gunichar c;
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3532 GtkTextIter iter, nextiter;
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3533 GString *str = g_string_new("");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3534 GSList *tags, *sl;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3535 GQueue *q, *r;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3536 GtkTextTag *tag;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3537
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3538 q = g_queue_new();
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3539 r = g_queue_new();
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3540
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3541
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3542 gtk_text_iter_order(start, end);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3543 nextiter = iter = *start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3544 gtk_text_iter_forward_char(&nextiter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3545
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3546 /* First add the tags that are already in progress */
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3547 tags = gtk_text_iter_get_tags(start);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3548
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3549 for (sl = tags; sl; sl = sl->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3550 tag = sl->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3551 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3552 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tag)));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3553 g_queue_push_tail(q, tag);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3554 }
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 g_slist_free(tags);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3557
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3558 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
3559
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3560 tags = gtk_text_iter_get_tags(&iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3561
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3562 for (sl = tags; sl; sl = sl->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3563 tag = sl->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3564 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3565 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tag)));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3566 g_queue_push_tail(q, tag);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3567 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3568 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3569
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3570
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3571 if (c == 0xFFFC) {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3572 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter);
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3573 char *text = NULL;
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3574 if (anchor)
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3575 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext");
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3576 if (text)
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3577 str = g_string_append(str, text);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3578 } else if (c == '<') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3579 str = g_string_append(str, "&lt;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3580 } else if (c == '>') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3581 str = g_string_append(str, "&gt;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3582 } else if (c == '&') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3583 str = g_string_append(str, "&amp;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3584 } else if (c == '"') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3585 str = g_string_append(str, "&quot;");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3586 } else if (c == '\n') {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3587 str = g_string_append(str, "<br>");
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3588 } else {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3589 str = g_string_append_unichar(str, c);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3590 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3591
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3592 tags = g_slist_reverse(tags);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3593 for (sl = tags; sl; sl = sl->next) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3594 tag = sl->data;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3595 if (tag_ends_here(tag, &iter, &nextiter)) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3596
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3597 GtkTextTag *tmp;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3598
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3599 while ((tmp = g_queue_pop_tail(q)) != tag) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3600 if (tmp == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3601 break;
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 if (!tag_ends_here(tmp, &iter, &nextiter))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3604 g_queue_push_tail(r, tmp);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3605 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp)));
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3606 }
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3607
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3608 if (tmp == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3609 gaim_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n");
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3610 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3611 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
3612
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3613 while ((tmp = g_queue_pop_head(r))) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3614 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
3615 g_queue_push_tail(q, tmp);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3616 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3617 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3618 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3619
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3620 g_slist_free(tags);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3621 gtk_text_iter_forward_char(&iter);
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3622 gtk_text_iter_forward_char(&nextiter);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3623 }
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3624
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3625 while ((tag = g_queue_pop_tail(q)))
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3626 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
3627
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3628 g_queue_free(q);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3629 g_queue_free(r);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3630 return g_string_free(str, FALSE);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3631 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3632
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3633 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter)
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3634 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3635 if (imhtml->edit.bold)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3636 gtk_imhtml_toggle_bold(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3637
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3638 if (imhtml->edit.italic)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3639 gtk_imhtml_toggle_italic(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3640
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3641 if (imhtml->edit.underline)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3642 gtk_imhtml_toggle_underline(imhtml);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3643
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3644 if (imhtml->edit.forecolor)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3645 gtk_imhtml_toggle_forecolor(imhtml, NULL);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3646
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3647 if (imhtml->edit.backcolor)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3648 gtk_imhtml_toggle_backcolor(imhtml, NULL);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3649
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3650 if (imhtml->edit.fontface)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3651 gtk_imhtml_toggle_fontface(imhtml, NULL);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3652
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3653 imhtml->edit.fontsize = 0;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3654
8719
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
3655 if (imhtml->edit.link)
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
3656 gtk_imhtml_toggle_link(imhtml, NULL);
513b8bbcc104 [gaim-migrate @ 9474]
Luke Schierer <lschiere@pidgin.im>
parents: 8707
diff changeset
3657
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3658 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
3659
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3660 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3661
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3662 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml)
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3663 {
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3664 GtkTextIter start, end;
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3665
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3666 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3667 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3668 return gtk_imhtml_get_markup_range(imhtml, &start, &end);
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3669 }
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3670
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3671 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3672 {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3673 int i, j, lines;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3674 GtkTextIter start, end;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3675 char **ret;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3676
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3677 lines = gtk_text_buffer_get_line_count(imhtml->text_buffer);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3678 ret = g_new0(char *, lines + 1);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3679 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3680 end = start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3681 gtk_text_iter_forward_to_line_end(&end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3682
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3683 for (i = 0, j = 0; i < lines; i++) {
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3684 ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3685 if (ret[j] != NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3686 j++;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3687 gtk_text_iter_forward_line(&start);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3688 end = start;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3689 gtk_text_iter_forward_to_line_end(&end);
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
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3692 return ret;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3693 }
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 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
3696 {
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3697 GString *str = g_string_new("");
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3698 GtkTextIter iter, end;
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3699 gunichar c;
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3700
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3701 if (start == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3702 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3703 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3704 iter = *start;
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 if (stop == NULL)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3707 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3708 else
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3709 end = *stop;
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 gtk_text_iter_order(&iter, &end);
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3712
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3713 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
3714 if (c == 0xFFFC) {
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3715 GtkTextChildAnchor* anchor;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3716 char *text = NULL;
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3717
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3718 anchor = gtk_text_iter_get_child_anchor(&iter);
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3719 if (anchor)
8698
f36eee61c85f [gaim-migrate @ 9451]
Luke Schierer <lschiere@pidgin.im>
parents: 8693
diff changeset
3720 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext");
8677
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3721 if (text)
cc2ce209cc46 [gaim-migrate @ 9430]
Sean Egan <seanegan@gmail.com>
parents: 8654
diff changeset
3722 str = g_string_append(str, text);
8519
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3723 } else {
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3724 g_string_append_unichar(str, c);
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3725 }
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3726 gtk_text_iter_forward_char(&iter);
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3727 }
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3728
f8ab826e11ad [gaim-migrate @ 9258]
Luke Schierer <lschiere@pidgin.im>
parents: 8516
diff changeset
3729 return g_string_free(str, FALSE);
8061
ea073d234191 [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3730 }